MuseScore  3.4
Music composition and notation
importmidi_view.h
Go to the documentation of this file.
1 #ifndef IMPORTMIDI_VIEW_H
2 #define IMPORTMIDI_VIEW_H
3 
4 #include <QTableView>
5 
6 
7 class SeparatorDelegate : public QStyledItemDelegate
8  {
9  public:
10  SeparatorDelegate(QObject *parent = 0)
11  : QStyledItemDelegate(parent)
12  , _frozenRowIndex(-1)
13  , _frozenColIndex(-1)
14  {}
15 
16  void setFrozenRowIndex(int index)
17  {
18  _frozenRowIndex = index;
19  }
20 
21  void setFrozenColIndex(int index)
22  {
23  _frozenColIndex = index;
24  }
25 
26  void paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
27  {
28  this->QStyledItemDelegate::paint(painter, option, index);
29 
30  if (index.row() == _frozenRowIndex) {
31  painter->save();
32  painter->setPen(option.palette.foreground().color());
33  painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
34  painter->restore();
35  }
36  if (index.column() == _frozenColIndex) {
37  painter->save();
38  painter->setPen(option.palette.foreground().color());
39  // use -1 padding to create double-line effect
40  const int x = option.rect.right() - 1;
41  painter->drawLine(x, option.rect.top(), x, option.rect.bottom());
42  painter->restore();
43  }
44  }
45  private:
48  };
49 
50 
51 class TracksView : public QTableView
52  {
53  Q_OBJECT
54 
55  public:
56  TracksView(QWidget *parent);
57  ~TracksView();
58 
59  void setModel(QAbstractItemModel *model);
60 
61  void setFrozenRowCount(int count);
62  void setFrozenColCount(int count);
63  void setItemDelegate(SeparatorDelegate *delegate);
64 
65  void restoreHHeaderState(const QByteArray &data);
66  void restoreVHeaderState(const QByteArray &data);
67  void setHHeaderResizeMode(QHeaderView::ResizeMode mode);
68  void setVHeaderDefaultSectionSize(int size);
69  void resetHHeader();
70  void resetVHeader();
71 
72  protected:
73  void resizeEvent(QResizeEvent *event);
74  bool viewportEvent(QEvent *event);
75  void wheelEvent(QWheelEvent *event);
76 
77  private slots:
78  void currentChanged(const QModelIndex &, const QModelIndex &);
79 
80  void updateMainViewSectionWidth(int,int,int);
81  void updateMainViewSectionHeight(int,int,int);
82  void updateFrozenSectionWidth(int,int,int);
83  void updateFrozenSectionHeight(int,int,int);
84  void onHSectionMove(int,int,int);
85  void onVSectionMove(int,int,int);
86 
87  private:
88  void initHorizontalView();
89  void initVerticalView();
90  void initCornerView();
91  void initMainView();
92  void initConnections();
93  void setupEditTriggers();
94  void updateFrozenTableGeometry();
95 
96  void keepVisible(const QModelIndex &previous, const QModelIndex &current);
97 
98  int frozenRowHeight();
99  int frozenColWidth();
100 
101  int frozenVTableWidth();
102  int frozenHTableHeight();
103 
104  void updateFocus(int currentRow, int currentColumn);
105 
106  QTableView *_frozenHTableView;
107  QTableView *_frozenVTableView;
112  };
113 
114 
115 #endif // IMPORTMIDI_VIEW_H
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: importmidi_view.h:26
QTableView * _frozenVTableView
Definition: importmidi_view.h:107
SeparatorDelegate * _delegate
Definition: importmidi_view.h:109
SeparatorDelegate(QObject *parent=0)
Definition: importmidi_view.h:10
int _frozenColCount
Definition: importmidi_view.h:111
int _frozenColIndex
Definition: importmidi_view.h:47
int _frozenRowIndex
Definition: importmidi_view.h:46
int _frozenRowCount
Definition: importmidi_view.h:110
Definition: importmidi_view.h:7
QTableView * _frozenCornerTableView
Definition: importmidi_view.h:108
void setFrozenRowIndex(int index)
Definition: importmidi_view.h:16
Definition: importmidi_view.h:51
QTableView * _frozenHTableView
Definition: importmidi_view.h:106
void setFrozenColIndex(int index)
Definition: importmidi_view.h:21