Skip to content

Commit

Permalink
PianoRollEditor: fixes, color theme + octaveRowColor
Browse files Browse the repository at this point in the history
PianoRollEditor::createBackground() did not paint the actual pattern. This causes selection to not become inactive in case the focus leaves the widget

In addition, the alternate background color for a different octave was exposed in the preferences and the widget does now use the colors for the color theme. The design was a little bit simplified. The base octave hhad a slightly different color compared to the other octave highlights. At least I did only notice this in the code and since the base pitch default notes will be initialized with is highlighted, the base octave does now share the same color as all others.
  • Loading branch information
theGreatWhiteShark committed Mar 16, 2022
1 parent dc5dd56 commit d7d43cc
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 109 deletions.
9 changes: 5 additions & 4 deletions data/themes/default.h2theme
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
<stackedModeOffNextColor>247,100,100</stackedModeOffNextColor>
</songEditor>
<patternEditor>
<backgroundColor>167,168,163</backgroundColor>
<alternateRowColor>147,148,143</alternateRowColor>
<selectedRowColor>207,208,200</selectedRowColor>
<textColor>240,240,240</textColor>
<backgroundColor>165,166,160</backgroundColor>
<alternateRowColor>133,134,129</alternateRowColor>
<selectedRowColor>194,195,187</selectedRowColor>
<octaveRowColor>193,194,186</octaveRowColor>
<textColor>255,255,255</textColor>
<noteVelocityFullColor>247,100,100</noteVelocityFullColor>
<noteVelocityDefaultColor>40,40,40</noteVelocityDefaultColor>
<noteVelocityHalfColor>89,131,175</noteVelocityHalfColor>
Expand Down
15 changes: 12 additions & 3 deletions src/core/Preferences/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ ColorTheme::ColorTheme()
, m_songEditor_stackedModeOnColor( QColor( 127, 159, 127 ) )
, m_songEditor_stackedModeOnNextColor( QColor( 240, 223, 175 ) )
, m_songEditor_stackedModeOffNextColor( QColor( 247, 100, 100 ) )
, m_patternEditor_backgroundColor( QColor(167, 168, 163) )
, m_patternEditor_alternateRowColor( QColor( 147, 148, 143 ) )
, m_patternEditor_selectedRowColor( QColor( 207, 208, 200 ) )
, m_patternEditor_backgroundColor( QColor( 165, 166, 160 ) )
, m_patternEditor_alternateRowColor( QColor( 133, 134, 129 ) )
, m_patternEditor_selectedRowColor( QColor( 194, 195, 187 ) )
, m_patternEditor_octaveRowColor( QColor( 193, 194, 186 ) )
, m_patternEditor_textColor( QColor( 255, 255, 255 ) )
, m_patternEditor_noteVelocityFullColor( QColor( 247, 100, 100 ) )
, m_patternEditor_noteVelocityDefaultColor( QColor( 40, 40, 40 ) )
Expand Down Expand Up @@ -102,6 +103,7 @@ ColorTheme::ColorTheme( const std::shared_ptr<ColorTheme> pOther )
, m_patternEditor_backgroundColor( pOther->m_patternEditor_backgroundColor )
, m_patternEditor_alternateRowColor( pOther->m_patternEditor_alternateRowColor )
, m_patternEditor_selectedRowColor( pOther->m_patternEditor_selectedRowColor )
, m_patternEditor_octaveRowColor( pOther->m_patternEditor_octaveRowColor )
, m_patternEditor_textColor( pOther->m_patternEditor_textColor )
, m_patternEditor_noteVelocityFullColor( pOther->m_patternEditor_noteVelocityFullColor )
, m_patternEditor_noteVelocityDefaultColor( pOther->m_patternEditor_noteVelocityDefaultColor )
Expand Down Expand Up @@ -227,6 +229,8 @@ void Theme::setTheme( const std::shared_ptr<Theme> pOther ) {
m_pColorTheme->m_patternEditor_backgroundColor = pOther->getColorTheme()->m_patternEditor_backgroundColor;
m_pColorTheme->m_patternEditor_alternateRowColor = pOther->getColorTheme()->m_patternEditor_alternateRowColor;
m_pColorTheme->m_patternEditor_selectedRowColor = pOther->getColorTheme()->m_patternEditor_selectedRowColor;
m_pColorTheme->m_patternEditor_octaveRowColor =
pOther->getColorTheme()->m_patternEditor_octaveRowColor;
m_pColorTheme->m_patternEditor_textColor = pOther->getColorTheme()->m_patternEditor_textColor;
m_pColorTheme->m_patternEditor_noteVelocityFullColor =
pOther->getColorTheme()->m_patternEditor_noteVelocityFullColor;
Expand Down Expand Up @@ -325,6 +329,8 @@ void Theme::writeColorTheme( QDomNode* parent, std::shared_ptr<Theme> pTheme )
LocalFileMng::writeXmlColor( patternEditorNode, "backgroundColor", pTheme->getColorTheme()->m_patternEditor_backgroundColor );
LocalFileMng::writeXmlColor( patternEditorNode, "alternateRowColor", pTheme->getColorTheme()->m_patternEditor_alternateRowColor );
LocalFileMng::writeXmlColor( patternEditorNode, "selectedRowColor", pTheme->getColorTheme()->m_patternEditor_selectedRowColor );
LocalFileMng::writeXmlColor( patternEditorNode, "octaveRowColor",
pTheme->getColorTheme()->m_patternEditor_octaveRowColor );
LocalFileMng::writeXmlColor( patternEditorNode, "textColor", pTheme->getColorTheme()->m_patternEditor_textColor );
LocalFileMng::writeXmlColor( patternEditorNode, "noteVelocityFullColor",
pTheme->getColorTheme()->m_patternEditor_noteVelocityFullColor );
Expand Down Expand Up @@ -422,6 +428,9 @@ void Theme::readColorTheme( QDomNode parent, std::shared_ptr<Theme> pTheme )
pTheme->getColorTheme()->m_patternEditor_backgroundColor = LocalFileMng::readXmlColor( pPatternEditorNode, "backgroundColor", pTheme->getColorTheme()->m_patternEditor_backgroundColor );
pTheme->getColorTheme()->m_patternEditor_alternateRowColor = LocalFileMng::readXmlColor( pPatternEditorNode, "alternateRowColor", pTheme->getColorTheme()->m_patternEditor_alternateRowColor );
pTheme->getColorTheme()->m_patternEditor_selectedRowColor = LocalFileMng::readXmlColor( pPatternEditorNode, "selectedRowColor", pTheme->getColorTheme()->m_patternEditor_selectedRowColor );
pTheme->getColorTheme()->m_patternEditor_octaveRowColor =
LocalFileMng::readXmlColor( pPatternEditorNode, "octaveRowColor",
pTheme->getColorTheme()->m_patternEditor_octaveRowColor );
pTheme->getColorTheme()->m_patternEditor_textColor = LocalFileMng::readXmlColor( pPatternEditorNode, "textColor", pTheme->getColorTheme()->m_patternEditor_textColor );
pTheme->getColorTheme()->m_patternEditor_noteVelocityFullColor =
LocalFileMng::readXmlColor( pPatternEditorNode, "noteVelocityFullColor",
Expand Down
1 change: 1 addition & 0 deletions src/core/Preferences/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ColorTheme : public H2Core::Object<ColorTheme>
QColor m_patternEditor_backgroundColor;
QColor m_patternEditor_alternateRowColor;
QColor m_patternEditor_selectedRowColor;
QColor m_patternEditor_octaveRowColor;
QColor m_patternEditor_textColor;
QColor m_patternEditor_noteVelocityFullColor;
QColor m_patternEditor_noteVelocityDefaultColor;
Expand Down
102 changes: 36 additions & 66 deletions src/gui/src/PatternEditor/PianoRollEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ void PianoRollEditor::finishUpdateEditor()

if ( m_bNeedsBackgroundUpdate ) {
createBackground();
} else {
drawPattern();
}
drawPattern();

// ERRORLOG(QString("update editor %1").arg(m_nEditorWidth));
m_bNeedsUpdate = false;
m_bNeedsBackgroundUpdate = false;
Expand Down Expand Up @@ -220,16 +222,12 @@ void PianoRollEditor::createBackground()
{
auto pPref = H2Core::Preferences::get_instance();

//INFOLOG( "(re)creating the background" );

QColor backgroundColor( 250, 250, 250 );

QColor octaveColor( 230, 230, 230 );
QColor octaveAlternateColor( 200, 200, 200 );
QColor baseOctaveColor( 245, 245, 245 );
QColor baseNoteColor( 255, 255, 255 );

QColor fbk( 160, 160, 160 );
QColor backgroundColor = pPref->getColorTheme()->m_patternEditor_backgroundColor;
QColor alternateRowColor = pPref->getColorTheme()->m_patternEditor_alternateRowColor;
QColor octaveColor = pPref->getColorTheme()->m_patternEditor_octaveRowColor;
// The line corresponding to the default pitch set to new notes
// will be highlighted.
QColor baseNoteColor = octaveColor.lighter( 119 );

unsigned start_x = 0;
unsigned end_x = width();
Expand All @@ -248,61 +246,33 @@ void PianoRollEditor::createBackground()

QPainter p( m_pBackgroundPixmap );

for ( uint octave = 0; octave < m_nOctaves; ++octave ) {
unsigned start_y = octave * 12 * m_nGridHeight;

if ( octave % 2 ) {


if ( octave == 3 ){

// p.fillRect( start_x, start_y, end_x - start_x, 12 * m_nGridHeight, baseOctaveColor );
p.fillRect( start_x, start_y, end_x - start_x, start_y + 1 * m_nGridHeight, baseOctaveColor );
p.fillRect( start_x, start_y + 1 * m_nGridHeight, end_x - start_x, start_y + 2 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 2 * m_nGridHeight, end_x - start_x, start_y + 3 * m_nGridHeight, baseOctaveColor );
p.fillRect( start_x, start_y + 3 * m_nGridHeight, end_x - start_x, start_y + 4 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 4 * m_nGridHeight, end_x - start_x, start_y + 5 * m_nGridHeight, baseOctaveColor );
p.fillRect( start_x, start_y + 5 * m_nGridHeight, end_x - start_x, start_y + 6 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 6 * m_nGridHeight, end_x - start_x, start_y + 7 * m_nGridHeight, baseOctaveColor );
p.fillRect( start_x, start_y + 7 * m_nGridHeight, end_x - start_x, start_y + 8 * m_nGridHeight, baseOctaveColor );
p.fillRect( start_x, start_y + 8 * m_nGridHeight, end_x - start_x, start_y + 9 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 9 * m_nGridHeight, end_x - start_x, start_y + 10 * m_nGridHeight, baseOctaveColor );
p.fillRect( start_x, start_y + 10 * m_nGridHeight, end_x - start_x, start_y + 11 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 11 * m_nGridHeight, end_x - start_x, start_y + 12 * m_nGridHeight, baseNoteColor );
}
else
{
// p.fillRect( start_x, start_y, end_x - start_x, 12 * m_nGridHeight, octaveColor );
p.fillRect( start_x, start_y, end_x - start_x, start_y + 1 * m_nGridHeight, octaveColor );
p.fillRect( start_x, start_y + 1 * m_nGridHeight, end_x - start_x, start_y + 2 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 2 * m_nGridHeight, end_x - start_x, start_y + 3 * m_nGridHeight, octaveColor );
p.fillRect( start_x, start_y + 3 * m_nGridHeight, end_x - start_x, start_y + 4 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 4 * m_nGridHeight, end_x - start_x, start_y + 5 * m_nGridHeight, octaveColor );
p.fillRect( start_x, start_y + 5 * m_nGridHeight, end_x - start_x, start_y + 6 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 6 * m_nGridHeight, end_x - start_x, start_y + 7 * m_nGridHeight, octaveColor );
p.fillRect( start_x, start_y + 7 * m_nGridHeight, end_x - start_x, start_y + 8 * m_nGridHeight, octaveColor );
p.fillRect( start_x, start_y + 8 * m_nGridHeight, end_x - start_x, start_y + 9 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 9 * m_nGridHeight, end_x - start_x, start_y + 10 * m_nGridHeight, octaveColor );
p.fillRect( start_x, start_y + 10 * m_nGridHeight, end_x - start_x, start_y + 11 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 11 * m_nGridHeight, end_x - start_x, start_y + 12 * m_nGridHeight, octaveColor );

for ( uint ooctave = 0; ooctave < m_nOctaves; ++ooctave ) {
unsigned start_y = ooctave * 12 * m_nGridHeight;

for ( int ii = 0; ii < 12; ++ii ) {
if ( ii == 0 || ii == 2 || ii == 4 || ii == 6 || ii == 7 ||
ii == 9 || ii == 11 ) {
if ( ooctave % 2 != 0 ) {
p.fillRect( start_x, start_y + ii * m_nGridHeight,
end_x - start_x, start_y + ( ii + 1 ) * m_nGridHeight,
octaveColor );
} else {
p.fillRect( start_x, start_y + ii * m_nGridHeight,
end_x - start_x, start_y + ( ii + 1 ) * m_nGridHeight,
backgroundColor );
}
} else {
p.fillRect( start_x, start_y + ii * m_nGridHeight,
end_x - start_x, start_y + ( ii + 1 ) * m_nGridHeight,
alternateRowColor );
}
}
else {
// p.fillRect( start_x, start_y, end_x - start_x, 12 * m_nGridHeight, octaveAlternateColor );
p.fillRect( start_x, start_y, end_x - start_x, start_y + 1 * m_nGridHeight, octaveAlternateColor );
p.fillRect( start_x, start_y + 1 * m_nGridHeight, end_x - start_x, start_y + 2 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 2 * m_nGridHeight, end_x - start_x, start_y + 3 * m_nGridHeight, octaveAlternateColor );
p.fillRect( start_x, start_y + 3 * m_nGridHeight, end_x - start_x, start_y + 4 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 4 * m_nGridHeight, end_x - start_x, start_y + 5 * m_nGridHeight, octaveAlternateColor );
p.fillRect( start_x, start_y + 5 * m_nGridHeight, end_x - start_x, start_y + 6 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 6 * m_nGridHeight, end_x - start_x, start_y + 7 * m_nGridHeight, octaveAlternateColor );
p.fillRect( start_x, start_y + 7 * m_nGridHeight, end_x - start_x, start_y + 8 * m_nGridHeight, octaveAlternateColor );
p.fillRect( start_x, start_y + 8 * m_nGridHeight, end_x - start_x, start_y + 9 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 9 * m_nGridHeight, end_x - start_x, start_y + 10 * m_nGridHeight, octaveAlternateColor );
p.fillRect( start_x, start_y + 10 * m_nGridHeight, end_x - start_x, start_y + 11 * m_nGridHeight, fbk );
p.fillRect( start_x, start_y + 11 * m_nGridHeight, end_x - start_x, start_y + 12 * m_nGridHeight, octaveAlternateColor );


// Highlight base note pitch
if ( ooctave == 3 ) {
p.fillRect( start_x, start_y + 11 * m_nGridHeight,
end_x - start_x, start_y + 12 * m_nGridHeight,
baseNoteColor );
}
}

Expand All @@ -315,9 +285,8 @@ void PianoRollEditor::createBackground()

//draw text
QFont font( pPref->getApplicationFontFamily(), getPointSize( pPref->getFontSize() ) );
// font.setWeight( 63 );
p.setFont( font );
p.setPen( QColor(10, 10, 10 ) );
p.setPen( pPref->getColorTheme()->m_patternEditor_textColor );

int offset = 0;
int insertx = 3;
Expand Down Expand Up @@ -355,6 +324,7 @@ void PianoRollEditor::createBackground()
}

drawGridLines( p, Qt::DashLine );
drawPattern();
}


Expand Down
76 changes: 40 additions & 36 deletions src/gui/src/PreferencesDialog/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,18 +589,19 @@ PreferencesDialog::PreferencesDialog(QWidget* parent)
new ColorTreeItem( 0x400, pTopLevelItem, tr( "Background" ) );
new ColorTreeItem( 0x401, pTopLevelItem, tr( "Alternate Row" ) );
new ColorTreeItem( 0x402, pTopLevelItem, tr( "Selected Row" ) );
new ColorTreeItem( 0x403, pTopLevelItem, tr( "Text" ) );
new ColorTreeItem( 0x404, pTopLevelItem, tr( "Note (Full Velocity)" ) );
new ColorTreeItem( 0x405, pTopLevelItem, tr( "Note (Default Velocity)" ) );
new ColorTreeItem( 0x406, pTopLevelItem, tr( "Note (Half Velocity)" ) );
new ColorTreeItem( 0x407, pTopLevelItem, tr( "Note (Zero Velocity)" ) );
new ColorTreeItem( 0x408, pTopLevelItem, tr( "Note Off" ) );
new ColorTreeItem( 0x409, pTopLevelItem, tr( "Line" ) );
new ColorTreeItem( 0x40a, pTopLevelItem, tr( "Line 1" ) );
new ColorTreeItem( 0x40b, pTopLevelItem, tr( "Line 2" ) );
new ColorTreeItem( 0x40c, pTopLevelItem, tr( "Line 3" ) );
new ColorTreeItem( 0x40d, pTopLevelItem, tr( "Line 4" ) );
new ColorTreeItem( 0x40e, pTopLevelItem, tr( "Line 5" ) );
new ColorTreeItem( 0x403, pTopLevelItem, tr( "Octave Row" ) );
new ColorTreeItem( 0x404, pTopLevelItem, tr( "Text" ) );
new ColorTreeItem( 0x405, pTopLevelItem, tr( "Note (Full Velocity)" ) );
new ColorTreeItem( 0x406, pTopLevelItem, tr( "Note (Default Velocity)" ) );
new ColorTreeItem( 0x407, pTopLevelItem, tr( "Note (Half Velocity)" ) );
new ColorTreeItem( 0x408, pTopLevelItem, tr( "Note (Zero Velocity)" ) );
new ColorTreeItem( 0x409, pTopLevelItem, tr( "Note Off" ) );
new ColorTreeItem( 0x40a, pTopLevelItem, tr( "Grid Line 1" ) );
new ColorTreeItem( 0x40b, pTopLevelItem, tr( "Grid Line 2" ) );
new ColorTreeItem( 0x40c, pTopLevelItem, tr( "Grid Line 3" ) );
new ColorTreeItem( 0x40d, pTopLevelItem, tr( "Grid Line 4" ) );
new ColorTreeItem( 0x40e, pTopLevelItem, tr( "Grid Line 5" ) );
new ColorTreeItem( 0x40f, pTopLevelItem, tr( "Grid Line 6" ) );

colorButton->setEnabled( false );

Expand Down Expand Up @@ -1543,18 +1544,19 @@ QColor* PreferencesDialog::getColorById( int nId, std::shared_ptr<H2Core::ColorT
case 0x400: return &pColorTheme->m_patternEditor_backgroundColor;
case 0x401: return &pColorTheme->m_patternEditor_alternateRowColor;
case 0x402: return &pColorTheme->m_patternEditor_selectedRowColor;
case 0x403: return &pColorTheme->m_patternEditor_textColor;
case 0x404: return &pColorTheme->m_patternEditor_noteVelocityFullColor;
case 0x405: return &pColorTheme->m_patternEditor_noteVelocityDefaultColor;
case 0x406: return &pColorTheme->m_patternEditor_noteVelocityHalfColor;
case 0x407: return &pColorTheme->m_patternEditor_noteVelocityZeroColor;
case 0x408: return &pColorTheme->m_patternEditor_noteOffColor;
case 0x409: return &pColorTheme->m_patternEditor_lineColor;
case 0x40a: return &pColorTheme->m_patternEditor_line1Color;
case 0x40b: return &pColorTheme->m_patternEditor_line2Color;
case 0x40c: return &pColorTheme->m_patternEditor_line3Color;
case 0x40d: return &pColorTheme->m_patternEditor_line4Color;
case 0x40e: return &pColorTheme->m_patternEditor_line5Color;
case 0x403: return &pColorTheme->m_patternEditor_octaveRowColor;
case 0x404: return &pColorTheme->m_patternEditor_textColor;
case 0x405: return &pColorTheme->m_patternEditor_noteVelocityFullColor;
case 0x406: return &pColorTheme->m_patternEditor_noteVelocityDefaultColor;
case 0x407: return &pColorTheme->m_patternEditor_noteVelocityHalfColor;
case 0x408: return &pColorTheme->m_patternEditor_noteVelocityZeroColor;
case 0x409: return &pColorTheme->m_patternEditor_noteOffColor;
case 0x40a: return &pColorTheme->m_patternEditor_lineColor;
case 0x40b: return &pColorTheme->m_patternEditor_line1Color;
case 0x40c: return &pColorTheme->m_patternEditor_line2Color;
case 0x40d: return &pColorTheme->m_patternEditor_line3Color;
case 0x40e: return &pColorTheme->m_patternEditor_line4Color;
case 0x40f: return &pColorTheme->m_patternEditor_line5Color;
default: return nullptr;
}

Expand Down Expand Up @@ -1648,29 +1650,31 @@ void PreferencesDialog::setColorById( int nId, const QColor& color,
break;
case 0x402: pColorTheme->m_patternEditor_selectedRowColor = color;
break;
case 0x403: pColorTheme->m_patternEditor_textColor = color;
case 0x403: pColorTheme->m_patternEditor_octaveRowColor = color;
break;
case 0x404: pColorTheme->m_patternEditor_noteVelocityFullColor = color;
case 0x404: pColorTheme->m_patternEditor_textColor = color;
break;
case 0x405: pColorTheme->m_patternEditor_noteVelocityDefaultColor = color;
case 0x405: pColorTheme->m_patternEditor_noteVelocityFullColor = color;
break;
case 0x406: pColorTheme->m_patternEditor_noteVelocityHalfColor = color;
case 0x406: pColorTheme->m_patternEditor_noteVelocityDefaultColor = color;
break;
case 0x407: pColorTheme->m_patternEditor_noteVelocityZeroColor = color;
case 0x407: pColorTheme->m_patternEditor_noteVelocityHalfColor = color;
break;
case 0x408: pColorTheme->m_patternEditor_noteOffColor = color;
case 0x408: pColorTheme->m_patternEditor_noteVelocityZeroColor = color;
break;
case 0x409: pColorTheme->m_patternEditor_lineColor = color;
case 0x409: pColorTheme->m_patternEditor_noteOffColor = color;
break;
case 0x40a: pColorTheme->m_patternEditor_line1Color = color;
case 0x40a: pColorTheme->m_patternEditor_lineColor = color;
break;
case 0x40b: pColorTheme->m_patternEditor_line2Color = color;
case 0x40b: pColorTheme->m_patternEditor_line1Color = color;
break;
case 0x40c: pColorTheme->m_patternEditor_line3Color = color;
case 0x40c: pColorTheme->m_patternEditor_line2Color = color;
break;
case 0x40d: pColorTheme->m_patternEditor_line4Color = color;
case 0x40d: pColorTheme->m_patternEditor_line3Color = color;
break;
case 0x40e: pColorTheme->m_patternEditor_line5Color = color;
case 0x40e: pColorTheme->m_patternEditor_line4Color = color;
break;
case 0x40f: pColorTheme->m_patternEditor_line5Color = color;
break;
default: DEBUGLOG( "Unknown ID" );
}
Expand Down

0 comments on commit d7d43cc

Please sign in to comment.