From 048e57b723c946d96aca260e26ba60dd380fde90 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Thu, 7 Nov 2019 01:20:03 +0800 Subject: Colorful keyboards. --- simple-visualization/qmpkeyboardwindow.cpp | 4 ++++ simple-visualization/qmppianowidget.cpp | 25 ++++++++++++++++++++++++- simple-visualization/qmppianowidget.hpp | 2 ++ simple-visualization/simplevisualization.cpp | 5 +++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/simple-visualization/qmpkeyboardwindow.cpp b/simple-visualization/qmpkeyboardwindow.cpp index 8fe0e6f..91b7a61 100644 --- a/simple-visualization/qmpkeyboardwindow.cpp +++ b/simple-visualization/qmpkeyboardwindow.cpp @@ -16,6 +16,10 @@ qmpKeyboardWindow::qmpKeyboardWindow(qmpPluginAPI *_api,QWidget *parent): grid->addWidget(lb[ch]=new QLabel,ch,0); grid->addWidget(pw[ch]=new qmpPianoWidget(this),ch,1); pw[ch]->setSizePolicy(QSizePolicy::Policy::Expanding,QSizePolicy::Policy::Preferred); + QPalette p=palette(); + p.setColor(QPalette::ColorRole::Highlight,api->getOptionUint("Keyboard/acolor"+std::to_string(ch))); + p.setColor(QPalette::ColorRole::Base,api->getOptionUint("Keyboard/bcolor"+std::to_string(ch))); + pw[ch]->setPalette(p); } hide(); eh=api->registerEventHandler( diff --git a/simple-visualization/qmppianowidget.cpp b/simple-visualization/qmppianowidget.cpp index febd90f..daeff25 100644 --- a/simple-visualization/qmppianowidget.cpp +++ b/simple-visualization/qmppianowidget.cpp @@ -5,6 +5,10 @@ qmpPianoWidget::qmpPianoWidget(QWidget *parent) : QWidget(parent) { memset(keystates,0,sizeof(keystates)); + QPalette p=palette(); + p.setColor(QPalette::ColorRole::Highlight,0xff66cc); + p.setColor(QPalette::ColorRole::Base,0x66ccff); + setPalette(p); } void qmpPianoWidget::setKeyState(int key,bool state) { @@ -21,13 +25,32 @@ QSize qmpPianoWidget::minimumSizeHint()const return QSize(320,22); } +bool qmpPianoWidget::hasHeightForWidth()const +{ + return true; +} + +int qmpPianoWidget::heightForWidth(int w)const +{ + return w*22/320; +} + void qmpPianoWidget::paintEvent(QPaintEvent *event) { Q_UNUSED(event) for(int i=0;i<128;++i) { QRectF r=getKeyRect(i); - paintKey(r,QColor(keystates[i]?0xff66cc:0x66ccff)); + QColor activeColor=palette().color(QPalette::ColorRole::Highlight); + QColor inactiveColor=palette().color(QPalette::ColorRole::Base); + if(i/12%2) + { + if(inactiveColor.valueF()>0.5) + inactiveColor=inactiveColor.darker(112); + else + inactiveColor=inactiveColor.lighter(112); + } + paintKey(r,keystates[i]?activeColor:inactiveColor); } } diff --git a/simple-visualization/qmppianowidget.hpp b/simple-visualization/qmppianowidget.hpp index 22af6ce..cca643c 100644 --- a/simple-visualization/qmppianowidget.hpp +++ b/simple-visualization/qmppianowidget.hpp @@ -12,6 +12,8 @@ class qmpPianoWidget : public QWidget void setKeyState(int key,bool state); void reset(); QSize minimumSizeHint()const override; + bool hasHeightForWidth()const override; + int heightForWidth(int w)const override; protected: void paintEvent(QPaintEvent *event)override; diff --git a/simple-visualization/simplevisualization.cpp b/simple-visualization/simplevisualization.cpp index d24db67..d45d101 100644 --- a/simple-visualization/simplevisualization.cpp +++ b/simple-visualization/simplevisualization.cpp @@ -7,6 +7,11 @@ void qmpSimpleVisualization::close(){p->close();} void qmpSimpleVisualization::init() { api->registerFunctionality(this,"Keyboard","Keyboard",api->isDarkTheme()?":/img/visualization_i.svg":":/img/visualization.svg",0,true); + for(int i=0;i<16;++i) + { + api->registerOptionUint("","","Keyboard/acolor"+std::to_string(i),0,0xffffff,0xffff66cc); + api->registerOptionUint("","","Keyboard/bcolor"+std::to_string(i),0,0xffffff,0xff66ccff); + } p=new qmpKeyboardWindow(api,(QWidget*)api->getMainWindow()); uihs=api->registerUIHook("main.stop",[this](const void*,void*){this->p->resetAll();},nullptr); } -- cgit v1.2.3