changeset 29061:8a425e771aa7

use a led like indicator for the prfiler state * led-indicator.cc: implememntation od class led_indicator; (led_indicator): sete size and initial state; (style_sheet): set the style sheet, where the led is emulated by a color gradient * led-indicator.h: class led_indicator derived from QLabel, enum with possible states, new ctor, new method for generating the required style sheet * main-window.cc (main_window): change the status indicaotr fomr QLabel to the new led_indicator and add it to the status bar (handle_profiler_status_update): set the led state accordingly * main-window.h: include led-indicator.h, change profiler indicator from QLabel to led_indicator * module.mk: add the files for the new led_indicator
author Torsten Lilge <ttl-octave@mailbox.org>
date Fri, 13 Nov 2020 20:50:37 +0100
parents b1b09b88585a
children c170ff385070
files libgui/src/led-indicator.cc libgui/src/led-indicator.h libgui/src/main-window.cc libgui/src/main-window.h libgui/src/module.mk
diffstat 5 files changed, 155 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/src/led-indicator.cc	Fri Nov 13 20:50:37 2020 +0100
@@ -0,0 +1,83 @@
+////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2013-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 <QColor>
+#include "led-indicator.h"
+
+namespace octave
+{
+
+  led_indicator::led_indicator (led_state initial_state, QWidget *p)
+    : QLabel (p)
+  {
+    setFixedSize(12,12);
+    set_state (initial_state);
+  }
+
+  void led_indicator::set_state (led_state state)
+  {
+    QColor col (Qt::gray);
+
+    switch (state)
+      {
+        case LED_STATE_NO:
+          break;
+
+        case LED_STATE_INACTIVE:
+          col = QColor (Qt::darkRed);
+          break;
+
+        case LED_STATE_ACTIVE:
+          col = QColor (Qt::darkGreen);
+          break;
+      }
+
+    setStyleSheet (style_sheet (col));
+  }
+
+  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);
+
+    const QString style = QString (
+        "border-radius: %1; background-color: "
+        "qlineargradient(spread:pad, x1:0.2, y1:0.2, x2:1, y2:1, stop:0 "
+        "%2, stop:1 %3);"
+      ).arg (width ()/2).arg (col_light.name ()).arg (col.name ());
+
+    return style;
+  }
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/src/led-indicator.h	Fri Nov 13 20:50:37 2020 +0100
@@ -0,0 +1,61 @@
+////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2013-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 (led_indicator_h)
+#define led_indicator_h 1
+
+#include <QLabel>
+
+namespace octave
+{
+
+  class led_indicator: public QLabel
+  {
+    Q_OBJECT
+
+  public:
+
+    enum led_state
+    {
+      LED_STATE_NO = -1,
+      LED_STATE_INACTIVE,
+      LED_STATE_ACTIVE
+    };
+
+    led_indicator (led_state initial_state = LED_STATE_INACTIVE,
+                   QWidget *parent = 0);
+
+  public slots:
+
+    void set_state (led_state state);
+
+  private:
+
+    QString style_sheet (const QColor& col);
+
+  };
+}
+
+#endif
\ No newline at end of file
--- a/libgui/src/main-window.cc	Fri Nov 13 08:31:12 2020 +0100
+++ b/libgui/src/main-window.cc	Fri Nov 13 20:50:37 2020 +0100
@@ -169,7 +169,9 @@
     construct_central_widget ();
 
     m_status_bar = new QStatusBar ();
-    m_profiler_status_indicator = new QLabel (tr ("Profiler OFF"));
+    m_profiler_status_indicator = new led_indicator ();
+    QLabel *text = new QLabel (tr ("Profiler"));
+    m_status_bar->addPermanentWidget (text);
     m_status_bar->addPermanentWidget (m_profiler_status_indicator);
 
     m_command_window = new terminal_dock_widget (this, m_octave_qobj);
@@ -1978,10 +1980,10 @@
     m_profiler_resume->setEnabled (! active);
     m_profiler_stop->setEnabled (active);
 
-    QString status = tr ("Profiler OFF");
+    led_indicator::led_state state = led_indicator::LED_STATE_INACTIVE;
     if (active)
-      status = tr ("Profiler ON");
-    m_profiler_status_indicator->setText (status);
+      state = led_indicator::LED_STATE_ACTIVE;
+    m_profiler_status_indicator->set_state (state);
   }
 
   void main_window::profiler_show (void)
--- a/libgui/src/main-window.h	Fri Nov 13 08:31:12 2020 +0100
+++ b/libgui/src/main-window.h	Fri Nov 13 20:50:37 2020 +0100
@@ -53,6 +53,7 @@
 #include "find-files-dialog.h"
 #include "history-dock-widget.h"
 #include "interpreter-qobject.h"
+#include "led-indicator.h"
 #include "octave-dock-widget.h"
 #include "octave-qobject.h"
 #include "qt-interpreter-events.h"
@@ -319,7 +320,7 @@
     //! Toolbar.
 
     QStatusBar *m_status_bar;
-    QLabel *m_profiler_status_indicator;
+    led_indicator *m_profiler_status_indicator;
 
     //! Dock widgets.
     //!@{
--- a/libgui/src/module.mk	Fri Nov 13 08:31:12 2020 +0100
+++ b/libgui/src/module.mk	Fri Nov 13 20:50:37 2020 +0100
@@ -140,6 +140,7 @@
   %reldir%/moc-gui-settings.cc \
   %reldir%/moc-history-dock-widget.cc \
   %reldir%/moc-interpreter-qobject.cc \
+  %reldir%/moc-led-indicator.cc \
   %reldir%/moc-main-window.cc \
   %reldir%/moc-news-reader.cc \
   %reldir%/moc-octave-qobject.cc \
@@ -210,6 +211,7 @@
   %reldir%/graphics-init.h \
   %reldir%/history-dock-widget.h \
   %reldir%/interpreter-qobject.h \
+  %reldir%/led-indicator.h \
   %reldir%/m-editor/file-editor-interface.h \
   %reldir%/m-editor/file-editor-tab.h \
   %reldir%/m-editor/file-editor.h \
@@ -251,6 +253,7 @@
   %reldir%/gui-settings.cc \
   %reldir%/history-dock-widget.cc \
   %reldir%/interpreter-qobject.cc \
+  %reldir%/led-indicator.cc \
   %reldir%/m-editor/file-editor-tab.cc \
   %reldir%/m-editor/file-editor.cc \
   %reldir%/m-editor/find-dialog.cc \