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