1 /***************************************************************************
2 **                                                                        **
3 **  Polyphone, a soundfont editor                                         **
4 **  Copyright (C) 2013-2020 Davy Triponney                                **
5 **                2014      Andrea Celani                                 **
6 **                                                                        **
7 **  This program is free software: you can redistribute it and/or modify  **
8 **  it under the terms of the GNU General Public License as published by  **
9 **  the Free Software Foundation, either version 3 of the License, or     **
10 **  (at your option) any later version.                                   **
11 **                                                                        **
12 **  This program is distributed in the hope that it will be useful,       **
13 **  but WITHOUT ANY WARRANTY; without even the implied warranty of        **
14 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          **
15 **  GNU General Public License for more details.                          **
16 **                                                                        **
17 **  You should have received a copy of the GNU General Public License     **
18 **  along with this program. If not, see http://www.gnu.org/licenses/.    **
19 **                                                                        **
20 ****************************************************************************
21 **           Author: Davy Triponney                                       **
22 **  Website/Contact: https://www.polyphone-soundfonts.com                 **
23 **             Date: 01.01.2013                                           **
24 ***************************************************************************/
25 
26 #ifndef TABLEWIDGET_H
27 #define TABLEWIDGET_H
28 
29 #include <QTableWidget>
30 #include <QTimer>
31 #include "soundfontmanager.h"
32 class TableDelegate;
33 
34 // QTableWidget an id by column, double click triggers an event and blue effect on the header
35 class TableWidget : public QTableWidget
36 {
37     Q_OBJECT
38 
39 public:
40     TableWidget(QWidget *parent = nullptr);
~TableWidget()41     ~TableWidget() { delete this->itemDelegate(); }
42     void clear();
43     void addColumn(int column, QString title, EltID id);
44     EltID getID(int column);
45     void setEnlighted(int colonne, bool isEnlighted);
46     void setColumnCount(int columns);
47     void removeColumn(int column);
48     void resetModDisplay();
49     void updateModDisplay(int column, QList<int> rows);
50     void selectCells(EltID id, QList<AttributeType> attributes);
51 
52     // Set the image corresponding to the loop mode value
53     // -1 will remove the image
54     void setLoopModeImage(int row, int column, int loopModeValue);
55 
56     // Association champ - ligne
57     virtual AttributeType getChamp(int row) = 0;
58     virtual int getRow(AttributeType champ) = 0;
59 
60     static QPixmap getPixMap(QColor backgroundColor, QColor dotColor);
61 
62 signals:
63     void actionBegin();
64     void actionFinished();
65     void openElement(EltID id);
66 
67 protected:
68     void keyPressEvent(QKeyEvent *event);
69     void wheelEvent(QWheelEvent * event);
70 
71 protected slots:
72     // Function reimplemented to fill all selected cells in the same time
73     virtual void commitData(QWidget *editor);
74     void onSectionDoubleClicked(int index);
75     void onItemSelectionChanged();
76 
77 private slots:
78     void updateColors();
79 
80 private:
81     QTimer *_timer;
82     QList<QColor> _listColors;
83     TableDelegate * _tableDelegate;
84 
85     void copy();
86     void paste();
87     void deleteCells();
88     QList<EltID> _columnIds;
89 };
90 
91 #endif // TABLEWIDGET_H
92