File indexing completed on 2025-01-19 03:55:41
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-07-05 0007 * Description : A combobox delegate to display in Web service image lists. 0008 * 0009 * SPDX-FileCopyrightText: 2009 by Pieter Edelman <pieter dot edelman at gmx dot net> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_WS_COMBO_BOX_DELEGATE_H 0016 #define DIGIKAM_WS_COMBO_BOX_DELEGATE_H 0017 0018 // Qt includes 0019 0020 #include <QAbstractItemDelegate> 0021 #include <QAbstractItemModel> 0022 #include <QMap> 0023 #include <QModelIndex> 0024 #include <QPainter> 0025 #include <QSize> 0026 #include <QString> 0027 #include <QStyleOptionViewItem> 0028 #include <QWidget> 0029 0030 // Local includes 0031 0032 #include "digikam_export.h" 0033 #include "ditemslist.h" 0034 0035 namespace Digikam 0036 { 0037 0038 class DIGIKAM_EXPORT ComboBoxDelegate : public QAbstractItemDelegate 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 0044 explicit ComboBoxDelegate(DItemsList* const, const QMap<int, QString>&); 0045 ~ComboBoxDelegate() override; 0046 0047 /** 0048 * Whenever an element needs to be edited, this method should be called. 0049 * It's actually a hack to prevent the item text shining through whenever 0050 * editing occurs. 0051 */ 0052 void startEditing(QTreeWidgetItem*, int); 0053 0054 ///@{ 0055 /** 0056 * Overloaded functions to provide the delegate functionality. 0057 */ 0058 void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const override; 0059 QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const override; 0060 QWidget* createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const override; 0061 void setEditorData(QWidget*, const QModelIndex&) const override; 0062 void setModelData(QWidget*, QAbstractItemModel*, const QModelIndex&) const override; 0063 ///@} 0064 0065 private Q_SLOTS: 0066 0067 void slotCommitAndCloseEditor(int); 0068 void slotResetEditedState(QObject*); 0069 0070 private: 0071 0072 class Private; 0073 Private* const d; 0074 }; 0075 0076 } // namespace Digikam 0077 0078 #endif // DIGIKAM_WS_COMBO_BOX_DELEGATE_H