Mercurial > octave
changeset 29220:ab8aa1bb3c2f
add gui utilities with first function for color interpolation
* gui-utils.cc: new file;
(interpolate_color): new function for deteriming a color similar to a
first color but with less contrast to a second one
* gui-utils.h: new file with declaration of interpolate_color
* file-editor-tab.cc (update_lexer_settings): use new utility function
for computing margin colors from given editor colors
* led-indicator.cc (style_sheet): use new utility function for computing
the colors for the led indicator
* module.mk: added source gui.utils.cc with header gui-utils.h
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sun, 27 Dec 2020 19:07:32 +0100 |
parents | c2f3a0832cf0 |
children | c7b27a4a6b43 |
files | libgui/src/gui-utils.cc libgui/src/gui-utils.h libgui/src/led-indicator.cc libgui/src/m-editor/file-editor-tab.cc libgui/src/module.mk |
diffstat | 5 files changed, 120 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-utils.cc Sun Dec 27 19:07:32 2020 +0100 @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2000-2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or <https://octave.org/copyright/>. +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// <https://www.gnu.org/licenses/>. +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-utils.h" + +namespace octave +{ + OCTGUI_API QColor + interpolate_color (const QColor& col1, const QColor& col2, + double fs, double fv) + { + qreal h1, s1, v1, h2, s2, v2; + + col1.getHsvF (&h1, &s1, &v1); + col2.getHsvF (&h2, &s2, &v2); + + return QColor::fromHsvF (h1, s1*fs, v1 + fv*(v2 - v1)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-utils.h Sun Dec 27 19:07:32 2020 +0100 @@ -0,0 +1,58 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 1993-2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or <https://octave.org/copyright/>. +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// <https://www.gnu.org/licenses/>. +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_gui_utils_h) +#define octave_gui_utils_h 1 + +#include <QColor> + +namespace octave +{ + + /*! + Deterimine an alternative color to @p col1 with less contrast + to @p col2. The HSV representation of the new color is calculated by + \f{eqnarray*}{ + H &=& H_1\\ + S &=& f_s S_1\\ + V &=& V_1 + f_s (V_2 - V_1) + \f} + + @param col1 Base color to which the alternative has to be computed + @param col2 Color to which the the new color should have less contrast + @param fs Factor for changing the saturation \f$(0\ldots\infty)\f$ + @param fv Factor for interpolating the brightness \f$(0\ldots 1)\f$. + For 0, \f$V = V_1\f$ and for 1, \f$V = V_2\f$. + + @return New color as QColor + */ + + extern OCTGUI_API QColor + interpolate_color (const QColor& col1, const QColor& col2, + double fs, double fv); + +} + +#endif
--- a/libgui/src/led-indicator.cc Fri Dec 25 17:13:14 2020 +0100 +++ b/libgui/src/led-indicator.cc Sun Dec 27 19:07:32 2020 +0100 @@ -28,6 +28,8 @@ #endif #include <QColor> + +#include "gui-utils.h" #include "led-indicator.h" namespace octave @@ -63,13 +65,7 @@ QString led_indicator::style_sheet (const QColor& col) { - int h, s, v; - - col.getHsv (&h, &s, &v); - s = s/4; - v = 232; - - QColor col_light = QColor::fromHsv (h,s,v); + QColor col_light = interpolate_color (col, QColor (Qt::white), 0.25, 0.9); const QString style = QString ( "border-radius: %1; background-color: "
--- a/libgui/src/m-editor/file-editor-tab.cc Fri Dec 25 17:13:14 2020 +0100 +++ b/libgui/src/m-editor/file-editor-tab.cc Sun Dec 27 19:07:32 2020 +0100 @@ -70,6 +70,7 @@ #include "gui-preferences-cs.h" #include "gui-preferences-ed.h" #include "gui-preferences-global.h" +#include "gui-utils.h" #include "marker.h" #include "octave-qobject.h" #include "octave-txt-lexer.h" @@ -875,27 +876,19 @@ QColor bg = lexer->paper (0); QColor fg = lexer->color (0); - int bh, bs, bv, fh, fs, fv, h, s, v; - bg.getHsv (&bh,&bs,&bv); - fg.getHsv (&fh,&fs,&fv); - // margin colors - h = bh; - s = bs/2; - v = bv + (fv - bv)/5; - - bg.setHsv (h,s,v); - m_edit_area->setEdgeColor (bg); - - v = bv + (fv - bv)/8; - bg.setHsv (h,s,v); - v = bv + (fv - bv)/4; - fg.setHsv (h,s,v); + QColor bgm, fgm; + + bgm = interpolate_color (bg, fg, 0.5, 0.2); + m_edit_area->setEdgeColor (bgm); m_edit_area->setMarkerForegroundColor (lexer->color (0)); m_edit_area->setMarginsForegroundColor (lexer->color (0)); - m_edit_area->setMarginsBackgroundColor (bg); - m_edit_area->setFoldMarginColors (bg,fg); + + bgm = interpolate_color (bg, fg, 0.5, 0.125); + fgm = interpolate_color (bg, fg, 0.5, 0.25); + m_edit_area->setMarginsBackgroundColor (bgm); + m_edit_area->setFoldMarginColors (bgm, fgm); // color indicator for highlighting all occurrences: // applications highlight color with more transparency
--- a/libgui/src/module.mk Fri Dec 25 17:13:14 2020 +0100 +++ b/libgui/src/module.mk Sun Dec 27 19:07:32 2020 +0100 @@ -239,7 +239,8 @@ %reldir%/variable-editor.h \ %reldir%/variable-editor-model.h \ %reldir%/set-path-dialog.h \ - %reldir%/set-path-model.h + %reldir%/set-path-model.h \ + %reldir%/gui-utils.h %canon_reldir%_%canon_reldir%_la_SOURCES = \ @@ -280,7 +281,8 @@ %reldir%/variable-editor.cc \ %reldir%/variable-editor-model.cc \ %reldir%/set-path-dialog.cc \ - %reldir%/set-path-model.cc + %reldir%/set-path-model.cc \ + %reldir%/gui-utils.cc nodist_%canon_reldir%_%canon_reldir%_la_SOURCES = \ $(octave_gui_MOC) \