File indexing completed on 2022-09-27 13:43:07

0001 /* ============================================================
0002  *
0003  * This file is a part of KDE project
0004  *
0005  *
0006  * Date        : 2009-07-05
0007  * Description : A combobox delegate to display in image lists.
0008  *
0009  * Copyright (C) 2009 by Pieter Edelman <pieter dot edelman at gmx dot net>
0010  *
0011  * This program is free software; you can redistribute it
0012  * and/or modify it under the terms of the GNU General
0013  * Public License as published by the Free Software Foundation;
0014  * either version 2, or (at your option) any later version.
0015  *
0016  * This program is distributed in the hope that it will be useful,
0017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0019  * GNU General Public License for more details.
0020  *
0021  * ============================================================ */
0022 
0023 #ifndef COMBOBOXDELEGATE_H
0024 #define COMBOBOXDELEGATE_H
0025 
0026 // Qt includes
0027 
0028 #include <QAbstractItemDelegate>
0029 #include <QAbstractItemModel>
0030 #include <QMap>
0031 #include <QModelIndex>
0032 #include <QPainter>
0033 #include <QSize>
0034 #include <QString>
0035 #include <QStyleOptionViewItem>
0036 #include <QWidget>
0037 
0038 // Local includes
0039 
0040 #include "kpimageslist.h"
0041 
0042 using namespace KIPIPlugins;
0043 
0044 namespace KIPIFlickrPlugin
0045 {
0046 
0047 class ComboBoxDelegate : public QAbstractItemDelegate
0048 {
0049     Q_OBJECT
0050 
0051 public:
0052 
0053     ComboBoxDelegate(KPImagesList* const, const QMap<int, QString>&);
0054 
0055     /* Whenever an element needs to be edited, this method should be called.
0056      * It's actually a hack to prevent the item text shining through whenever
0057      * editing occurs.
0058      */
0059     void startEditing(QTreeWidgetItem*, int);
0060 
0061     /* Overloaded functions to provide the delegate functionality.
0062      */
0063     void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const override;
0064     QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const override;
0065     QWidget* createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const override;
0066     void setEditorData(QWidget*, const QModelIndex&) const override;
0067     void setModelData(QWidget*, QAbstractItemModel*, const QModelIndex&) const override;
0068 
0069 private Q_SLOTS:
0070 
0071     void slotCommitAndCloseEditor(int);
0072     void slotResetEditedState(QObject*);
0073 
0074 private:
0075 
0076     KPImagesList*      m_parent;
0077     QMap<int, QString> m_items;
0078 
0079     /* The row in the view that is currently being edited. Should be -1 to
0080      * indicate that no row is edited. */
0081     int                m_rowEdited;
0082 
0083     QSize              m_size;
0084 };
0085 
0086 } // namespace KIPIFlickrPlugin
0087 
0088 #endif /* COMBOBOXDELEGATE_H */