Mercurial > jwe > octave
changeset 27036:c76dd670a7a5
automatic selection of foreground color in worspace view (bug #53995)
* workspace-model.cc (workspace_model): initialize the color list extended
by the foreground colors;
(data): return the related foreground color when the foreground role
id requested;
(notice_settings): get suitable foreground colors for special storage
classes based on the given background colors from the preferences by
means of QPalette
* workspace-view.cc (notice_settings): also take determined foreground
colors of special storage classes for building the tool tip
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sun, 07 Apr 2019 20:16:27 +0200 |
parents | 0ee0bb5eb381 |
children | bf28de59a843 |
files | libgui/src/workspace-model.cc libgui/src/workspace-view.cc |
diffstat | 2 files changed, 26 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/workspace-model.cc Sat Apr 06 18:39:32 2019 -0700 +++ b/libgui/src/workspace-model.cc Sun Apr 07 20:16:27 2019 +0200 @@ -48,7 +48,12 @@ m_columnNames.append (tr ("Value")); m_columnNames.append (tr ("Attribute")); - for (int i = 0; i < resource_manager::storage_class_chars ().length (); i++) + // Initialize the bachground and foreground colors of special + // classes in the workspace view. The structure is + // m_storage_class_colors(1,2,...,colors): background colors + // m_storage_class_colors(colors+1,...,2*colors): foreground colors + int colors = resource_manager::storage_class_chars ().length (); + for (int i = 0; i < 2*colors; i++) m_storage_class_colors.append (QColor (Qt::white)); } @@ -128,13 +133,21 @@ if (idx.isValid ()) { - if (role == Qt::BackgroundColorRole && m_enable_colors) + if ((role == Qt::BackgroundColorRole || role == Qt::ForegroundRole) + && m_enable_colors) { QString class_chars = resource_manager::storage_class_chars (); int actual_class = class_chars.indexOf (m_scopes[idx.row ()].toLatin1 ()); if (actual_class >= 0) - return QVariant (m_storage_class_colors.at (actual_class)); + { + // Valid class: Get backgorund (normal indexes) or foreground + // color (indexes with offset) + if (role == Qt::ForegroundRole) + actual_class += class_chars.length (); + + return QVariant (m_storage_class_colors.at (actual_class)); + } else return retval; } @@ -260,7 +273,13 @@ QColor setting_color = settings->value ("workspaceview/color_" + class_chars.mid (i,1), default_var).value<QColor> (); + + QPalette p (setting_color); m_storage_class_colors.replace (i,setting_color); + + QColor fg_color = p.color (QPalette::WindowText); + m_storage_class_colors.replace (i + class_chars.length (), fg_color); + } }
--- a/libgui/src/workspace-view.cc Sat Apr 06 18:39:32 2019 -0700 +++ b/libgui/src/workspace-view.cc Sun Apr 07 20:16:27 2019 +0200 @@ -199,11 +199,13 @@ { tool_tip = QString (tr ("View the variables in the active workspace.<br>")); tool_tip += QString (tr ("Colors for variable attributes:")); - for (i = 0; i < resource_manager::storage_class_chars ().length (); i++) + int colors = resource_manager::storage_class_chars ().length (); + for (i = 0; i < colors; i++) { tool_tip += - QString (R"(<div style="background-color:%1;color:#000000">%2</div>)") + QString (R"(<div style="background-color:%1;color:%2">%3</div>)") .arg (m_model->storage_class_color (i).name ()) + .arg (m_model->storage_class_color (i + colors).name ()) .arg (resource_manager::storage_class_names ().at (i)); } }