GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
led-indicator.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2013-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <QColor>
31 
32 #include "gui-utils.h"
33 #include "led-indicator.h"
34 
36 
38 : QLabel (p)
39 {
40  setFixedSize(12, 12);
41  set_state (initial_state);
42 }
43 
45 {
46  QColor col (Qt::gray);
47 
48  switch (state)
49  {
50  case LED_STATE_NO:
51  break;
52 
53  case LED_STATE_INACTIVE:
54  col = QColor (Qt::darkGray);
55  col.setRedF (col.redF () * 1.25);
56  break;
57 
58  case LED_STATE_ACTIVE:
59  col = QColor (Qt::red);
60  break;
61  }
62 
63  setStyleSheet (style_sheet (col));
64 }
65 
66 QString led_indicator::style_sheet (const QColor& col)
67 {
68  QColor col_light = interpolate_color (col, QColor (Qt::white), 0.25, 0.9);
69 
70  const QString style = QString (
71  "border-radius: %1; background-color: "
72  "qlineargradient(spread:pad, x1:0.2, y1:0.2, x2:1, y2:1, stop:0 "
73  "%2, stop:1 %3);"
74  ).arg (width ()/2).arg (col_light.name ()).arg (col.name ());
75 
76  return style;
77 }
78 
OCTAVE_END_NAMESPACE(octave)
void set_state(led_state state)
QString style_sheet(const QColor &col)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTGUI_API QColor interpolate_color(const QColor &col1, const QColor &col2, double fs, double fv)
Definition: gui-utils.cc:39
static uint32_t state[624]
Definition: randmtzig.cc:193