From aec5e972e8968255e8843eb22314b96a8f23b041 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Tue, 10 Sep 2019 23:55:48 +0800 Subject: We refactorin', eh? Hell yeah. (Almost) Completely rewritten qmpChannelsWindow, one of the oldest component, now with a dedicated data model. Removed dumb design (CMidiPlayer::getChstates). Now QMidiPlayer requires C++14 to build. More refactoring like this coming up soon. --- qmidiplayer-desktop/qmpchannelswindow.hpp | 50 ++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'qmidiplayer-desktop/qmpchannelswindow.hpp') diff --git a/qmidiplayer-desktop/qmpchannelswindow.hpp b/qmidiplayer-desktop/qmpchannelswindow.hpp index 207ee8d..ab3227f 100644 --- a/qmidiplayer-desktop/qmpchannelswindow.hpp +++ b/qmidiplayer-desktop/qmpchannelswindow.hpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "qmppresetselect.hpp" #include "qmpchanneleditor.hpp" #include "../core/qmpmidiplay.hpp" @@ -60,6 +62,42 @@ class qmpChannelFunc:public qmpFuncBaseIntf void close(); }; +class qmpChannelsModel:public QAbstractTableModel +{ + Q_OBJECT + public: + explicit qmpChannelsModel(QObject*parent=nullptr); + int columnCount(const QModelIndex&parent=QModelIndex())const override; + int rowCount(const QModelIndex&parent=QModelIndex())const override; + QModelIndex parent(const QModelIndex&child)const override; + QVariant data(const QModelIndex&index,int role=Qt::ItemDataRole::DisplayRole)const override; + QVariant headerData(int section,Qt::Orientation orientation,int role=Qt::ItemDataRole::DisplayRole)const override; + Qt::ItemFlags flags(const QModelIndex&idx)const override; + public slots: + void updateChannelActivity(); + void channelMSClicked(const QModelIndex&idx); + void channelMSClearAll(int type); + private: + int evh; + bool updatequeued; + bool mute[16],solo[16]; +}; + +class qmpDeviceItemDelegate:public QStyledItemDelegate +{ + Q_OBJECT + public: + explicit qmpDeviceItemDelegate(QWidget*parent=nullptr); + void paint(QPainter*painter,const QStyleOptionViewItem&option,const QModelIndex&index)const override; + QSize sizeHint(const QStyleOptionViewItem&option,const QModelIndex&index)const override; + QWidget* createEditor(QWidget*parent,const QStyleOptionViewItem&option,const QModelIndex&index)const override; + void setEditorData(QWidget*editor,const QModelIndex&index)const override; + void setModelData(QWidget*editor,QAbstractItemModel*model,const QModelIndex&index)const override; + void updateEditorGeometry(QWidget*editor,const QStyleOptionViewItem&option,const QModelIndex&index)const override; + private: + QWidget *par; +}; + class qmpChannelsWindow:public QWidget { Q_OBJECT @@ -69,32 +107,22 @@ class qmpChannelsWindow:public QWidget ~qmpChannelsWindow(); void showEvent(QShowEvent *event); void closeEvent(QCloseEvent *event); - void resetAcitivity(); public slots: - void channelWindowsUpdate(); - void updateChannelActivity(); - void channelMSChanged(); - void showPresetWindow(int chid,int col); void showChannelEditorWindow(int chid); - void changeMidiMapping(int chid,int idx); void on_pbUnmute_clicked(); void on_pbUnsolo_clicked(); signals: void noteOn(); - protected: - bool eventFilter(QObject *o,QEvent *e); - private: Ui::qmpChannelsWindow *ui; qmpPresetSelector *pselectw; qmpChannelEditor *ceditw; + qmpChannelsModel *chmodel; QIcon *cha,*chi; qmpChannelFunc *chnlf; int eh; - //callback fuse... (avoid black midi blocking the main thread) - int callbacksc,cbcnt,fused; }; #endif // QMPCHANNELSWINDOW_H -- cgit v1.2.3