1 /* This file is part of the KDE libraries
2 Copyright (C) 2006,2007 Andreas Hartmetz (ahartmetz@gmail.com)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #ifndef KEXTENDABLEITEMDELEGATE_H
22 #define KEXTENDABLEITEMDELEGATE_H
24 #include <QItemDelegate>
28 This delegate makes it possible to display an arbitrary QWidget ("extender") that spans all columns below a line of items.
29 The extender will logically belong to a column in the row above it.
32 It is your responsibility to devise a way to trigger extension and contraction of items, by calling
33 extendItem() and contractItem(). You can e.g. reimplement itemActivated() and similar functions.
37 class QAbstractItemView
;
38 class KExtendableItemDelegatePrivate
;
40 class KExtendableItemDelegate
: public QItemDelegate
{
44 enum auxDataRoles
{ShowExtensionIndicatorRole
= Qt::UserRole
+ 200};
47 * Create a new KExtendableItemDelegate that belongs to @p parent. In contrast to generic
48 * QAbstractItemDelegates, an instance of this class can only ever be the delegate for one
49 * instance of af QAbstractItemView subclass.
51 KExtendableItemDelegate(QAbstractItemView
*parent
);
52 virtual ~KExtendableItemDelegate();
54 //reimplemented from QItemDelegate
55 virtual QSize
sizeHint(const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const;
56 virtual void paint(QPainter
*painter
, const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const;
59 * Insert the @p extender that logically belongs to @p index into the view.
60 * If you need a parent for the extender at construction time, use the itemview's viewport().
61 * The extender will be reparented and resized to the viewport by this function.
63 void extendItem(QWidget
*extender
, const QModelIndex
&index
);
66 * Remove the extender that logically belongs to @p index from the view.
68 void contractItem(const QModelIndex
&index
);
71 * Return whether there is an extender that belongs to @p index.
73 bool isExtended(const QModelIndex
&index
) const;
76 * Reimplement this function to adjust the internal geometry of the extender.
77 * The external geometry of the extender will be set by the delegate.
79 virtual void updateExtenderGeometry(QWidget
*extender
, const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const;
83 * This signal indicates that the item at @p index was extended with @p extender.
85 void extenderCreated(QWidget
*extender
, const QModelIndex
&index
);
88 * This signal indicates that the @p extender belonging to @p index has emitted the destroyed() signal.
90 void extenderDestroyed(QWidget
*extender
, const QModelIndex
&index
);
94 * Reimplement this function to fine-tune the position of the extender. @p option.rect will be a rectangle
95 * that is as wide as the viewport and as high as the usual item height plus the extender size hint's height.
96 * Its upper left corner will be at the upper left corner of the usual item.
97 * You can place the returned rectangle of this function anywhere inside that area.
99 QRect
extenderRect(QWidget
*extender
, const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const;
100 //these two must have the same (screen) size!
101 void setExtendIcon(const QPixmap
&);
102 void setContractIcon(const QPixmap
&);
103 QPixmap
extendIcon();
104 QPixmap
contractIcon();
107 void extenderDestructionHandler(QObject
*destroyed
);
110 inline QSize
maybeExtendedSize(const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const;
111 QModelIndex
indexOfExtendedColumnInSameRow(const QModelIndex
&index
) const;
112 inline void scheduleUpdateViewLayout() const;
114 KExtendableItemDelegatePrivate
*const d
;
116 #endif // KEXTENDABLEITEMDELEGATE_H