diff --git a/data/themes/classic/style.css b/data/themes/classic/style.css index 1cf9375bce9..a952e81dcce 100644 --- a/data/themes/classic/style.css +++ b/data/themes/classic/style.css @@ -123,6 +123,7 @@ PianoRoll { qproperty-backgroundShade: rgba( 255, 255, 255, 10 ); qproperty-noteModeColor: rgb( 255, 255, 255 ); qproperty-noteColor: rgb( 119, 199, 216 ); + qproperty-noteTextColor: rgb( 255, 255, 255 ); qproperty-noteOpacity: 128; qproperty-noteBorders: true; /* boolean property, set false to have borderless notes */ qproperty-selectedNoteColor: rgb( 0, 125, 255 ); diff --git a/data/themes/default/style.css b/data/themes/default/style.css index a4a31ab6b1a..a0ddd3b41ae 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -142,6 +142,7 @@ PianoRoll { qproperty-backgroundShade: rgba(255, 255, 255, 10); qproperty-noteModeColor: #0bd556; qproperty-noteColor: #0bd556; + qproperty-noteTextColor: #ffffff; qproperty-noteOpacity: 165; qproperty-noteBorders: false; /* boolean property, set false to have borderless notes */ qproperty-selectedNoteColor: #064d79; diff --git a/include/PianoRoll.h b/include/PianoRoll.h index 9167804ae43..8b0f1babfba 100644 --- a/include/PianoRoll.h +++ b/include/PianoRoll.h @@ -59,6 +59,7 @@ class PianoRoll : public QWidget Q_PROPERTY( QColor lineColor READ lineColor WRITE setLineColor ) Q_PROPERTY( QColor noteModeColor READ noteModeColor WRITE setNoteModeColor ) Q_PROPERTY( QColor noteColor READ noteColor WRITE setNoteColor ) + Q_PROPERTY( QColor noteTextColor READ noteTextColor WRITE setNoteTextColor ) Q_PROPERTY( QColor barColor READ barColor WRITE setBarColor ) Q_PROPERTY( QColor selectedNoteColor READ selectedNoteColor WRITE setSelectedNoteColor ) Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor ) @@ -122,6 +123,8 @@ class PianoRoll : public QWidget void setNoteModeColor( const QColor & c ); QColor noteColor() const; void setNoteColor( const QColor & c ); + QColor noteTextColor() const; + void setNoteTextColor( const QColor & c ); QColor barColor() const; void setBarColor( const QColor & c ); QColor selectedNoteColor() const; @@ -157,8 +160,8 @@ class PianoRoll : public QWidget int getKey( int y ) const; static void drawNoteRect( QPainter & p, int x, int y, - int width, const Note * n, const QColor & noteCol, - const QColor & selCol, const int noteOpc, const bool borderless ); + int width, const Note * n, const QColor & noteCol, const QColor & noteTextColor, + const QColor & selCol, const int noteOpc, const bool borderless, bool drawNoteName ); void removeSelection(); void selectAll(); NoteVector getSelectedNotes(); @@ -384,6 +387,7 @@ protected slots: QColor m_lineColor; QColor m_noteModeColor; QColor m_noteColor; + QColor m_noteTextColor; QColor m_barColor; QColor m_selectedNoteColor; QColor m_textColor; diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index ffcc10c1a0e..7a38777e732 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -751,6 +751,12 @@ QColor PianoRoll::noteColor() const void PianoRoll::setNoteColor( const QColor & c ) { m_noteColor = c; } +QColor PianoRoll::noteTextColor() const +{ return m_noteTextColor; } + +void PianoRoll::setNoteTextColor( const QColor & c ) +{ m_noteTextColor = c; } + QColor PianoRoll::barColor() const { return m_barColor; } @@ -810,8 +816,8 @@ void PianoRoll::setBackgroundShade( const QColor & c ) void PianoRoll::drawNoteRect( QPainter & p, int x, int y, - int width, const Note * n, const QColor & noteCol, - const QColor & selCol, const int noteOpc, const bool borders ) + int width, const Note * n, const QColor & noteCol, const QColor & noteTextColor, + const QColor & selCol, const int noteOpc, const bool borders, bool drawNoteName ) { ++x; ++y; @@ -822,15 +828,19 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, width = 2; } - int volVal = qMin( 255, 100 + (int) ( ( (float)( n->getVolume() - MinVolume ) ) / - ( (float)( MaxVolume - MinVolume ) ) * 155.0f) ); - float rightPercent = qMin( 1.0f, - ( (float)( n->getPanning() - PanningLeft ) ) / - ( (float)( PanningRight - PanningLeft ) ) * 2.0f ); + // Volume + float const volumeRange = static_cast(MaxVolume - MinVolume); + float const volumeSpan = static_cast(n->getVolume() - MinVolume); + float const volumeRatio = volumeSpan / volumeRange; + int volVal = qMin( 255, 100 + static_cast( volumeRatio * 155.0f) ); - float leftPercent = qMin( 1.0f, - ( (float)( PanningRight - n->getPanning() ) ) / - ( (float)( PanningRight - PanningLeft ) ) * 2.0f ); + // Panning + float const panningRange = static_cast(PanningRight - PanningLeft); + float const leftPanSpan = static_cast(PanningRight - n->getPanning()); + float const rightPanSpan = static_cast(n->getPanning() - PanningLeft); + + float leftPercent = qMin( 1.0f, leftPanSpan / panningRange * 2.0f ); + float rightPercent = qMin( 1.0f, rightPanSpan / panningRange * 2.0f ); QColor col = QColor( noteCol ); QPen pen; @@ -848,9 +858,9 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, // adjust note to make it a bit faded if it has a lower volume // in stereo using gradients QColor lcol = QColor::fromHsv( col.hue(), col.saturation(), - volVal * leftPercent, noteOpc ); + static_cast(volVal * leftPercent), noteOpc ); QColor rcol = QColor::fromHsv( col.hue(), col.saturation(), - volVal * rightPercent, noteOpc ); + static_cast(volVal * rightPercent), noteOpc ); QLinearGradient gradient( x, y, x, y + noteHeight ); gradient.setColorAt( 0, rcol ); @@ -868,6 +878,36 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, p.drawRect( x, y, noteWidth, noteHeight ); + // Draw note key text + if (drawNoteName) + { + p.save(); + int const noteTextHeight = static_cast(noteHeight * 0.8); + if (noteTextHeight > 6) + { + QString noteKeyString = getNoteString(n->key()); + + QFont noteFont(p.font()); + noteFont.setPixelSize(noteTextHeight); + QFontMetrics fontMetrics(noteFont); + QSize textSize = fontMetrics.size(Qt::TextSingleLine, noteKeyString); + + int const distanceToBorder = 2; + int const xOffset = borderWidth + distanceToBorder; + int const yOffset = (noteHeight + noteTextHeight) / 2; + + if (textSize.width() < noteWidth - xOffset) + { + p.setPen(noteTextColor); + p.setFont(noteFont); + QPoint textStart(x + xOffset, y + yOffset); + + p.drawText(textStart, noteKeyString); + } + } + p.restore(); + } + // draw the note endmark, to hint the user to resize p.setBrush( col ); if( width > 2 ) @@ -3022,8 +3062,8 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // note drawNoteRect( p, x + WHITE_KEY_WIDTH, y_base - key * KEY_LINE_HEIGHT, - note_width, note, noteColor(), selectedNoteColor(), - noteOpacity(), noteBorders() ); + note_width, note, noteColor(), noteTextColor(), selectedNoteColor(), + noteOpacity(), noteBorders(), drawNoteNames ); } // draw note editing stuff