diff --git a/trunk/changelog b/trunk/changelog index f7e47196..92a45565 100644 --- a/trunk/changelog +++ b/trunk/changelog @@ -2,6 +2,7 @@ polyphone (1.9) unstable; urgency=low * (new) portuguese translation * (new) tool to export the preset list in a text format + * (improvement) Glow effect when the virtual keyboard is focused with ctrl+K * (fix) crash with a drag & drop in the tree * (fix) release bug when using loop + end mode * (fix) the progress bar sometimes remains when loading a small soundfont diff --git a/trunk/clavier/pianokey.cpp b/trunk/clavier/pianokey.cpp index 012c6afe..18a1df15 100644 --- a/trunk/clavier/pianokey.cpp +++ b/trunk/clavier/pianokey.cpp @@ -26,7 +26,7 @@ QBrush PianoKey::BLACK_BRUSH = QBrush(Qt::black); QBrush PianoKey::WHITE_BRUSH = QBrush(Qt::white); - +double PianoKey::s_glowEffect = 0; PianoKey::PianoKey(const QRectF &rect, const bool black, const int note) : QGraphicsRectItem(rect), @@ -43,8 +43,11 @@ PianoKey::PianoKey(const QRectF &rect, const bool black, const int note) void PianoKey::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { - const QPen blackPen(Qt::black, 1); - const QPen grayPen(QBrush(Qt::gray), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + // Mix between black and gray with the glow color + QColor glowColor = QApplication::palette().color(QPalette::Highlight); + const QPen blackPen(mergeColor(Qt::black, glowColor, s_glowEffect), 1); + const QPen grayPen(QBrush(mergeColor(Qt::gray, glowColor, s_glowEffect)), + 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); if (m_pressed) { if (m_selectedBrush.style() != Qt::NoBrush) @@ -88,6 +91,13 @@ void PianoKey::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge } } +QColor PianoKey::mergeColor(QColor color1, QColor color2, double fade) +{ + return QColor((1. - fade) * color1.red() + fade * color2.red(), + (1. - fade) * color1.green() + fade * color2.green(), + (1. - fade) * color1.blue() + fade * color2.blue()); +} + void PianoKey::setPressed(bool p) { if (p != m_pressed) diff --git a/trunk/clavier/pianokey.h b/trunk/clavier/pianokey.h index e0ef88da..b7ced44d 100644 --- a/trunk/clavier/pianokey.h +++ b/trunk/clavier/pianokey.h @@ -38,6 +38,7 @@ class PianoKey : public QGraphicsRectItem void setPressed(bool p); void setMarker(PianoKeybd::MarkerType type); int isBlack() const { return m_black; } + static void setGlowEffect(double glowEffect) { s_glowEffect = glowEffect; } static QBrush BLACK_BRUSH; static QBrush WHITE_BRUSH; @@ -47,6 +48,7 @@ class PianoKey : public QGraphicsRectItem static QColor getBorderColor(PianoKeybd::MarkerType type); static QColor getFillColor(PianoKeybd::MarkerType type); void flipPainter(QPainter * painter, QRectF &rect); + QColor mergeColor(QColor color1, QColor color2, double fade); bool m_pressed; QBrush m_selectedBrush; @@ -54,6 +56,8 @@ class PianoKey : public QGraphicsRectItem int m_note; bool m_black; PianoKeybd::MarkerType m_markerType; + + static double s_glowEffect; }; #endif /*PIANOKEY_H_*/ diff --git a/trunk/clavier/pianokeybd.cpp b/trunk/clavier/pianokeybd.cpp index 2ea60c19..f38de2aa 100644 --- a/trunk/clavier/pianokeybd.cpp +++ b/trunk/clavier/pianokeybd.cpp @@ -309,3 +309,8 @@ void PianoKeybd::triggerNote(int key, int velocity) else m_scene->keyNoteOff(key); } + +void PianoKeybd::triggerGlowEffect() +{ + this->m_scene->triggerGlowEffect(); +} diff --git a/trunk/clavier/pianokeybd.h b/trunk/clavier/pianokeybd.h index 63a94e61..46fe5627 100644 --- a/trunk/clavier/pianokeybd.h +++ b/trunk/clavier/pianokeybd.h @@ -178,6 +178,7 @@ class /*QDESIGNER_WIDGET_EXPORT*/ PianoKeybd : public QGraphicsView double ratio() const; void triggerNote(int key, int velocity); + void triggerGlowEffect(); signals: void noteOn(int midiNote, int vel); diff --git a/trunk/clavier/pianoscene.cpp b/trunk/clavier/pianoscene.cpp index c43d0cc6..512f61bc 100644 --- a/trunk/clavier/pianoscene.cpp +++ b/trunk/clavier/pianoscene.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include int PianoScene::MIN_NOTE = 0; @@ -71,8 +72,12 @@ PianoScene::PianoScene (const int startKey, const int numKeys, PianoScene *previ m_startKey(startKey), m_minNote(0), m_maxNote(127), - m_ratio((double)width() / (double)height()) + m_ratio((double)width() / (double)height()), + _glowEffect(0) { + _timer = new QTimer(this); + connect(_timer, SIGNAL(timeout()), this, SLOT(updateGlowEffect())); + // Initialisation initConfiguration(previousScene); initLabels(); @@ -867,3 +872,22 @@ void PianoScene::resetCustomization(int key, PianoKeybd::CustomizationType type) } refreshKeys(); } + + +void PianoScene::triggerGlowEffect() +{ + PianoKey::setGlowEffect(1); + _glowEffect = 1; + _timer->start(30); +} + +void PianoScene::updateGlowEffect() +{ + _glowEffect -= .1; + if (_glowEffect < 0) { + _glowEffect = 0; + _timer->stop(); + } + PianoKey::setGlowEffect(_glowEffect); + this->update(); +} diff --git a/trunk/clavier/pianoscene.h b/trunk/clavier/pianoscene.h index 3d210279..a76ecea7 100644 --- a/trunk/clavier/pianoscene.h +++ b/trunk/clavier/pianoscene.h @@ -45,6 +45,7 @@ class PianoScene : public QGraphicsScene PianoKeybd::ColorationType getColorationType() { return m_colorationType; } void setColor(int num, QColor color); QColor getColor(int num) { return m_palette.value(num); } + void triggerGlowEffect(); // Customization void addCustomColor(int key, QColor color); @@ -105,6 +106,9 @@ class PianoScene : public QGraphicsScene void keyReleaseEvent(QKeyEvent * keyEvent ); bool event(QEvent *event); +protected slots: + void updateGlowEffect(); + private: void initConfiguration(PianoScene *previousScene); void initLabels(); @@ -149,6 +153,9 @@ class PianoScene : public QGraphicsScene static int MIN_NOTE, MAX_NOTE, KEYWIDTH, KEYHEIGHT; static KeyboardMap* m_keybdMap; + + QTimer *_timer; + double _glowEffect; }; #endif /*PIANOSCENE_H_*/ diff --git a/trunk/mainwindow.cpp b/trunk/mainwindow.cpp index 120ee76a..7c2a08f2 100644 --- a/trunk/mainwindow.cpp +++ b/trunk/mainwindow.cpp @@ -367,6 +367,7 @@ void MainWindow::keyPressEvent(QKeyEvent * event) if (_dialKeyboard.isVisible()) _dialKeyboard.activateWindow(); ui->widgetKeyboard->setFocus(); + ui->widgetKeyboard->triggerGlowEffect(); } QMainWindow::keyPressEvent(event); }