1 /*************************************************************************** 2 ** ** 3 ** Polyphone, a soundfont editor ** 4 ** Copyright (C) 2013-2020 Davy Triponney ** 5 ** ** 6 ** This program is free software: you can redistribute it and/or modify ** 7 ** it under the terms of the GNU General Public License as published by ** 8 ** the Free Software Foundation, either version 3 of the License, or ** 9 ** (at your option) any later version. ** 10 ** ** 11 ** This program is distributed in the hope that it will be useful, ** 12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 14 ** GNU General Public License for more details. ** 15 ** ** 16 ** You should have received a copy of the GNU General Public License ** 17 ** along with this program. If not, see http://www.gnu.org/licenses/. ** 18 ** ** 19 **************************************************************************** 20 ** Author: Davy Triponney ** 21 ** Website/Contact: https://www.polyphone-soundfonts.com ** 22 ** Date: 01.01.2013 ** 23 ***************************************************************************/ 24 25 #ifndef TABLEDELEGATE_H 26 #define TABLEDELEGATE_H 27 28 #include <QStyledItemDelegate> 29 class QTableWidget; 30 31 // Editors within the table 32 class TableDelegate : public QStyledItemDelegate 33 { 34 Q_OBJECT 35 36 public: 37 TableDelegate(QTableWidget * table, QObject * parent = nullptr); isEditing()38 bool isEditing() { return _isEditing; } 39 void resetModDisplay(); 40 void updateModDisplay(int column, QList<int> rows); 41 42 protected: 43 QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; 44 void setEditorData(QWidget *editor, const QModelIndex &index) const; 45 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; 46 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; 47 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 48 void destroyEditor(QWidget * editor, const QModelIndex & index) const; 49 #endif 50 51 private: 52 void getType(bool &isNumeric, bool &isKey, int &nbDecimales, int numRow, bool &isLoop, 53 bool &isFixed, bool &isAttenuation) const; 54 QTableWidget * _table; 55 56 static const char * DECO_PROPERTY; 57 mutable bool _isEditing; 58 QMap<int, QList<int> > _modDisplay; 59 QColor _modBorderColor, _modBorderColor2; 60 }; 61 62 #endif // TABLEDELEGATE_H 63