1 /* ============================================================ 2 * 3 * This file is a part of digiKam project 4 * https://www.digikam.org 5 * 6 * Date : 2009-07-05 7 * Description : A combobox delegate to display in Web service image lists. 8 * 9 * Copyright (C) 2009 by Pieter Edelman <pieter dot edelman at gmx dot net> 10 * 11 * This program is free software; you can redistribute it 12 * and/or modify it under the terms of the GNU General 13 * Public License as published by the Free Software Foundation; 14 * either version 2, or (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * ============================================================ */ 22 23 #ifndef DIGIKAM_WS_COMBO_BOX_DELEGATE_H 24 #define DIGIKAM_WS_COMBO_BOX_DELEGATE_H 25 26 // Qt includes 27 28 #include <QAbstractItemDelegate> 29 #include <QAbstractItemModel> 30 #include <QMap> 31 #include <QModelIndex> 32 #include <QPainter> 33 #include <QSize> 34 #include <QString> 35 #include <QStyleOptionViewItem> 36 #include <QWidget> 37 38 // Local includes 39 40 #include "digikam_export.h" 41 #include "ditemslist.h" 42 43 namespace Digikam 44 { 45 46 class DIGIKAM_EXPORT ComboBoxDelegate : public QAbstractItemDelegate 47 { 48 Q_OBJECT 49 50 public: 51 52 explicit ComboBoxDelegate(DItemsList* const, const QMap<int, QString>&); 53 ~ComboBoxDelegate() override; 54 55 /** 56 * Whenever an element needs to be edited, this method should be called. 57 * It's actually a hack to prevent the item text shining through whenever 58 * editing occurs. 59 */ 60 void startEditing(QTreeWidgetItem*, int); 61 62 ///@{ 63 /** 64 * Overloaded functions to provide the delegate functionality. 65 */ 66 void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const override; 67 QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const override; 68 QWidget* createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const override; 69 void setEditorData(QWidget*, const QModelIndex&) const override; 70 void setModelData(QWidget*, QAbstractItemModel*, const QModelIndex&) const override; 71 ///@} 72 73 private Q_SLOTS: 74 75 void slotCommitAndCloseEditor(int); 76 void slotResetEditedState(QObject*); 77 78 private: 79 80 class Private; 81 Private* const d; 82 }; 83 84 } // namespace Digikam 85 86 #endif // DIGIKAM_WS_COMBO_BOX_DELEGATE_H 87