File indexing completed on 2024-04-28 05:11:30
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0005 */ 0006 0007 #pragma once 0008 0009 #include <QIcon> 0010 #include <QModelIndex> 0011 #include <QString> 0012 #include <QStyledItemDelegate> 0013 0014 namespace IncidenceEditorNG 0015 { 0016 /** 0017 * class to show a Icon and Text for an Attendee 0018 * you have to set the Items via addItem to have a list to choose from. 0019 * saves the option as int in the model 0020 */ 0021 class AttendeeComboBoxDelegate : public QStyledItemDelegate 0022 { 0023 Q_OBJECT 0024 public: 0025 explicit AttendeeComboBoxDelegate(QObject *parent = nullptr); 0026 0027 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0028 void setEditorData(QWidget *editor, const QModelIndex &index) const override; 0029 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; 0030 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0031 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0032 0033 bool eventFilter(QObject *editor, QEvent *event) override; 0034 0035 virtual void addItem(const QIcon &, const QString &); 0036 virtual void clear(); 0037 0038 virtual void setToolTip(const QString &); 0039 virtual void setWhatsThis(const QString &); 0040 0041 /** choose this index, if the item in the model is unknown 0042 */ 0043 void setStandardIndex(int); 0044 0045 public Q_SLOTS: 0046 bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) override; 0047 0048 private Q_SLOTS: 0049 void doCloseEditor(QWidget *editor); 0050 void rightPressed(); 0051 void leftPressed(); 0052 0053 private: 0054 /** all entries to choose from */ 0055 QList<QPair<QIcon, QString>> mEntries; 0056 QString mToolTip; 0057 QString mWhatsThis; 0058 /**fallback index */ 0059 int mStandardIndex = 0; 0060 }; 0061 }