KFileItemDelegate Class
Header: | #include <KFileItemDelegate> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS KIOWidgets) target_link_libraries(mytarget PRIVATE Qt6::KIOWidgets) |
Public Types
enum | Information { NoInformation, Size, Permissions, OctalPermissions, Owner, …, Comment } |
Public Functions
KFileItemDelegate(QObject *parent = nullptr) | |
virtual | ~KFileItemDelegate() override |
QRect | iconRect(const QStyleOptionViewItem &option, const QModelIndex &index) const |
bool | jobTransfersVisible() const |
QSize | maximumSize() const |
void | setJobTransfersVisible(bool jobTransfersVisible) |
void | setMaximumSize(const QSize &size) |
void | setShadowBlur(qreal radius) |
void | setShadowColor(const QColor &color) |
void | setShadowOffset(const QPointF &offset) |
void | setShowInformation(KFileItemDelegate::Information information) |
void | setShowInformation(const KFileItemDelegate::InformationList &list) |
void | setShowToolTipWhenElided(bool showToolTip) |
void | setWrapMode(QTextOption::WrapMode wrapMode) |
qreal | shadowBlur() const |
QColor | shadowColor() const |
QPointF | shadowOffset() const |
KFileItemDelegate::InformationList | showInformation() const |
bool | showToolTipWhenElided() const |
QTextOption::WrapMode | wrapMode() const |
Reimplemented Public Functions
virtual QWidget * | createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override |
virtual bool | editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override |
virtual bool | eventFilter(QObject *object, QEvent *event) override |
virtual void | paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override |
virtual void | setEditorData(QWidget *editor, const QModelIndex &index) const override |
virtual void | setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override |
virtual QSize | sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override |
virtual void | updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override |
Public Slots
virtual bool | helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) override |
QRegion | shape(const QStyleOptionViewItem &option, const QModelIndex &index) |
Detailed Description
@class KFileItemDelegate kfileitemdelegate.h <KFileItemDelegate>
KFileItemDelegate is intended to be used to provide a KDE file system view, when using one of the standard item views in Qt with KDirModel.
While primarily intended to be used with KDirModel, it uses Qt::DecorationRole and Qt::DisplayRole for the icons and text labels, just like QItemDelegate, and can thus be used with any standard model.
When used with KDirModel however, KFileItemDelegate can change the way the display and/or decoration roles are drawn, based on properties of the file items. For example, if the file item is a symbolic link, it will use an italic font to draw the file name.
KFileItemDelegate also supports showing additional information about the file items below the icon labels.
Which information should be shown, if any, is controlled by the @ref information property, which is a list that can be set by calling setShowInformation(), and read by calling showInformation(). By default this list is empty.
To use KFileItemDelegate, instantiate an object from the delegate, and call setItemDelegate() in one of the standard item views in Qt:
@code QListView *listview = new QListView(this); KFileItemDelegate *delegate = new KFileItemDelegate(this); listview->setItemDelegate(delegate); @endcode
Member Type Documentation
enum KFileItemDelegate::Information
This enum defines the additional information that can be displayed below item labels in icon views.
The information will only be shown for indexes for which the model provides a valid value for KDirModel::FileItemRole, and only when there's sufficient vertical space to display at least one line of the information, along with the display label.
For the number of items to be shown for folders, the model must provide a valid value for KDirMode::ChildCountRole, in addition to KDirModel::FileItemRole.
Note that KFileItemDelegate will not call KFileItem::determineMimeType() if KFileItem::isMimeTypeKnown() returns false, so if you want to display MIME types you should use a KMimeTypeResolver with the model and the view, to ensure that MIME types are resolved. If the MIME type isn't known, "Unknown" will be displayed until the MIME type has been successfully resolved.
@see setShowInformation() @see showInformation() @see information
Member Function Documentation
[explicit]
KFileItemDelegate::KFileItemDelegate(QObject *parent = nullptr)
Constructs a new KFileItemDelegate.
@param parent The parent object for the delegate.
[override virtual noexcept]
KFileItemDelegate::~KFileItemDelegate()
Destroys the item delegate.
[override virtual]
QWidget *KFileItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Reimplemented from @ref QAbstractItemDelegate.
[override virtual]
bool KFileItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
Reimplemented from @ref QAbstractItemDelegate.
[override virtual]
bool KFileItemDelegate::eventFilter(QObject *object, QEvent *event)
Reimplemented from @ref QAbstractItemDelegate.
[override virtual slot]
bool KFileItemDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
Reimplemented from @ref QAbstractItemDelegate.
QRect KFileItemDelegate::iconRect(const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the rectangle of the icon that is aligned inside the decoration rectangle.
bool KFileItemDelegate::jobTransfersVisible() const
Returns whether or not the displaying of job transfers is enabled. @see setJobTransfersVisible()
Note: Getter function for property jobTransfersVisible.
See also setJobTransfersVisible().
QSize KFileItemDelegate::maximumSize() const
Returns the maximum size for KFileItemDelegate::sizeHint().
@see setMaximumSize()
Note: Getter function for property maximumSize.
See also setMaximumSize().
[override virtual]
void KFileItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Paints the item indicated by @p index, using @p painter.
The item will be drawn in the rectangle specified by option.rect. The correct size for that rectangle can be obtained by calling @ref sizeHint().
This function will use the following data values if the model provides them for the item, in place of the values in @p option:
@li Qt::FontRole The font that should be used for the display role. @li Qt::TextAlignmentRole The alignment of the display role. @li Qt::ForegroundRole The text color for the display role. @li Qt::BackgroundRole The background color for the item.
This function is reimplemented from @ref QAbstractItemDelegate.
@param painter The painter with which to draw the item. @param option The style options that should be used when painting the item. @param index The index to the item that should be painted.
[override virtual]
void KFileItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
Reimplemented from @ref QAbstractItemDelegate.
void KFileItemDelegate::setJobTransfersVisible(bool jobTransfersVisible)
Enable/Disable the displaying of an animated overlay that is shown for any destination urls (in the view). When enabled, the animations (if any) will be drawn automatically.
Only the files/folders that are visible and have jobs associated with them will display the animation. You would likely not want this enabled if you perform some kind of custom painting that takes up a whole item, and will just make this(and what you paint) look funky.
Default is disabled.
Note: The model (KDirModel) needs to have it's method called with the same value, when you make the call to this method.
Note: Setter function for property jobTransfersVisible.
See also jobTransfersVisible().
void KFileItemDelegate::setMaximumSize(const QSize &size)
Sets the maximum size for KFileItemDelegate::sizeHint().
@see maximumSize()
Note: Setter function for property maximumSize.
See also maximumSize().
[override virtual]
void KFileItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Reimplemented from @ref QAbstractItemDelegate.
void KFileItemDelegate::setShadowBlur(qreal radius)
Sets the blur radius for the text shadow.
@see shadowBlur()
Note: Setter function for property shadowBlur.
See also shadowBlur().
void KFileItemDelegate::setShadowColor(const QColor &color)
Sets the color used for drawing the text shadow.
To enable text shadows, set the shadow color to a non-transparent color. To disable text shadows, set the color to Qt::transparent.
@see shadowColor()
Note: Setter function for property shadowColor.
See also shadowColor().
void KFileItemDelegate::setShadowOffset(const QPointF &offset)
Sets the horizontal and vertical offset for the text shadow.
@see shadowOffset()
Note: Setter function for property shadowOffset.
See also shadowOffset().
void KFileItemDelegate::setShowInformation(KFileItemDelegate::Information information)
Sets a single information line that is shown below the icon label in list views.
This is a convenience function for when you only want to show a single line of information.
@param information The information that should be shown
Note: Setter function for property information.
See also showInformation().
void KFileItemDelegate::setShowInformation(const KFileItemDelegate::InformationList &list)
Sets the list of information lines that are shown below the icon label in list views.
You will typically construct the list like this: @code KFileItemDelegate::InformationList list; list << KFileItemDelegate::FriendlyMimeType << KFileItemDelegate::Size; delegate->setShowInformation(list); @endcode
The information lines will be displayed in the list order. The delegate will first draw the item label, and then as many information lines as will fit in the available space.
@param list A list of information items that should be shown
Note: Setter function for property information.
void KFileItemDelegate::setShowToolTipWhenElided(bool showToolTip)
Sets whether a tooltip should be shown if the display role is elided containing the full display role information.
@note The tooltip will only be shown if the Qt::ToolTipRole differs from Qt::DisplayRole, or if they match, showToolTipWhenElided flag is set and the display role information is elided. @see showToolTipWhenElided()
Note: Setter function for property showToolTipWhenElided.
See also showToolTipWhenElided().
void KFileItemDelegate::setWrapMode(QTextOption::WrapMode wrapMode)
When the contents text needs to be wrapped, @p wrapMode strategy will be followed.
See also wrapMode().
qreal KFileItemDelegate::shadowBlur() const
Returns the blur radius for the text shadow.
@see setShadowBlur()
Note: Getter function for property shadowBlur.
See also setShadowBlur().
QColor KFileItemDelegate::shadowColor() const
Returns the color used for the text shadow.
@see setShadowColor()
Note: Getter function for property shadowColor.
See also setShadowColor().
QPointF KFileItemDelegate::shadowOffset() const
Returns the offset used for the text shadow.
@see setShadowOffset()
Note: Getter function for property shadowOffset.
See also setShadowOffset().
[slot]
QRegion KFileItemDelegate::shape(const QStyleOptionViewItem &option, const QModelIndex &index)
Returns the shape of the item as a region. The returned region can be used for precise hit testing of the item.
KFileItemDelegate::InformationList KFileItemDelegate::showInformation() const
Returns the file item information that should be shown below item labels in list views.
Note: Getter function for property information.
See also setShowInformation().
bool KFileItemDelegate::showToolTipWhenElided() const
Returns whether a tooltip should be shown if the display role is elided containing the full display role information.
@note The tooltip will only be shown if the Qt::ToolTipRole differs from Qt::DisplayRole, or if they match, showToolTipWhenElided flag is set and the display role information is elided. @see setShowToolTipWhenElided()
Note: Getter function for property showToolTipWhenElided.
See also setShowToolTipWhenElided().
[override virtual]
QSize KFileItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the nominal size for the item referred to by @p index, given the provided options.
If the model provides a valid Qt::FontRole and/or Qt::TextAlignmentRole for the item, those will be used instead of the ones specified in the style options.
This function is reimplemented from @ref QAbstractItemDelegate.
@param option The style options that should be used when painting the item. @param index The index to the item for which to return the size hint.
[override virtual]
void KFileItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Reimplemented from @ref QAbstractItemDelegate.
QTextOption::WrapMode KFileItemDelegate::wrapMode() const
Returns the wrapping strategy followed to show text when it needs wrapping.
See also setWrapMode().