diff options
author | Chris Xiong <chirs241097@gmail.com> | 2019-11-07 01:20:03 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2019-11-07 01:20:03 +0800 |
commit | 048e57b723c946d96aca260e26ba60dd380fde90 (patch) | |
tree | f8fe6d361e33235d81248105a63fc568b7c956d8 /simple-visualization/qmppianowidget.cpp | |
parent | b2ef363f49db70219ac1eaebb7d69dcdade8d60b (diff) | |
download | QMidiPlayer-048e57b723c946d96aca260e26ba60dd380fde90.tar.xz |
Colorful keyboards.
Diffstat (limited to 'simple-visualization/qmppianowidget.cpp')
-rw-r--r-- | simple-visualization/qmppianowidget.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
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); } } |