Skip to content

Commit

Permalink
Glow effect on the virtual keyboard
Browse files Browse the repository at this point in the history
Fixes #3
A glow effect confirms that the keyboard has been focused with the
combination ctrl+K


Former-commit-id: ab902a435e3ce197c16db9f5254734e757e8ec75 [formerly 3d6c441]
Former-commit-id: 148745e0457d03d066042f81cad243c277730a8a
Former-commit-id: f3faaa0661ad87bcc29e965ead84c75e19d91a8b [formerly bf5e5a9ecc4dbc2594fec2f633dcd8e7f7719a35]
Former-commit-id: 048a08e07ab274f594a75ca1a7b35c43f43ab0d3
  • Loading branch information
davy7125 committed Mar 9, 2017
1 parent 53b8e4d commit 6b43b09
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions trunk/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions trunk/clavier/pianokey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions trunk/clavier/pianokey.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,13 +48,16 @@ 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;
QBrush m_brush;
int m_note;
bool m_black;
PianoKeybd::MarkerType m_markerType;

static double s_glowEffect;
};

#endif /*PIANOKEY_H_*/
5 changes: 5 additions & 0 deletions trunk/clavier/pianokeybd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,8 @@ void PianoKeybd::triggerNote(int key, int velocity)
else
m_scene->keyNoteOff(key);
}

void PianoKeybd::triggerGlowEffect()
{
this->m_scene->triggerGlowEffect();
}
1 change: 1 addition & 0 deletions trunk/clavier/pianokeybd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 25 additions & 1 deletion trunk/clavier/pianoscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QPalette>
#include <QGraphicsSceneMouseEvent>
#include <QKeyEvent>
#include <QTimer>
#include <qmath.h>

int PianoScene::MIN_NOTE = 0;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
7 changes: 7 additions & 0 deletions trunk/clavier/pianoscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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_*/
1 change: 1 addition & 0 deletions trunk/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ void MainWindow::keyPressEvent(QKeyEvent * event)
if (_dialKeyboard.isVisible())
_dialKeyboard.activateWindow();
ui->widgetKeyboard->setFocus();
ui->widgetKeyboard->triggerGlowEffect();
}
QMainWindow::keyPressEvent(event);
}
Expand Down

0 comments on commit 6b43b09

Please sign in to comment.