Implement customizable cursor fill color
authorSoeren Apel <soeren@apelpie.net>
Sat, 27 Oct 2018 12:27:45 +0000 (14:27 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Sat, 27 Oct 2018 19:17:52 +0000 (21:17 +0200)
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/views/trace/cursorpair.cpp
pv/views/trace/cursorpair.hpp
pv/views/trace/timeitem.hpp
pv/views/trace/viewitem.hpp

index 1119b8f..6878cad 100644 (file)
@@ -319,6 +319,13 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const
                SLOT(on_view_snapDistance_changed(int)));
        trace_view_layout->addRow(tr("Maximum distance from edges before cursors snap to them"), snap_distance_sb);
 
+       ColorButton* cursor_fill_cb = new ColorButton(parent);
+       cursor_fill_cb->set_color(QColor::fromRgba(
+               settings.value(GlobalSettings::Key_View_CursorFillColor).value<uint32_t>()));
+       connect(cursor_fill_cb, SIGNAL(selected(QColor)),
+               this, SLOT(on_view_cursorFillColor_changed(QColor)));
+       trace_view_layout->addRow(tr("Color to fill cursor area with"), cursor_fill_cb);
+
        QComboBox *thr_disp_mode_cb = new QComboBox();
        thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
        thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
@@ -671,6 +678,12 @@ void Settings::on_view_snapDistance_changed(int value)
        settings.setValue(GlobalSettings::Key_View_SnapDistance, value);
 }
 
+void Settings::on_view_cursorFillColor_changed(QColor color)
+{
+       GlobalSettings settings;
+       settings.setValue(GlobalSettings::Key_View_CursorFillColor, color.rgba());
+}
+
 void Settings::on_view_conversionThresholdDispMode_changed(int state)
 {
        GlobalSettings settings;
index 4aa5458..43988fe 100644 (file)
@@ -71,6 +71,7 @@ private Q_SLOTS:
        void on_view_showAnalogMinorGrid_changed(int state);
        void on_view_showHoverMarker_changed(int state);
        void on_view_snapDistance_changed(int value);
+       void on_view_cursorFillColor_changed(QColor color);
        void on_view_conversionThresholdDispMode_changed(int state);
        void on_view_defaultDivHeight_changed(int value);
        void on_view_defaultLogicHeight_changed(int value);
index 1cd6566..34dbc83 100644 (file)
@@ -58,6 +58,7 @@ const QString GlobalSettings::Key_View_DefaultDivHeight = "View_DefaultDivHeight
 const QString GlobalSettings::Key_View_DefaultLogicHeight = "View_DefaultLogicHeight";
 const QString GlobalSettings::Key_View_ShowHoverMarker = "View_ShowHoverMarker";
 const QString GlobalSettings::Key_View_SnapDistance = "View_SnapDistance";
+const QString GlobalSettings::Key_View_CursorFillColor = "View_CursorFillColor";
 const QString GlobalSettings::Key_Dec_InitialStateConfigurable = "Dec_InitialStateConfigurable";
 const QString GlobalSettings::Key_Dec_ExportFormat = "Dec_ExportFormat";
 const QString GlobalSettings::Key_Log_BufferSize = "Log_BufferSize";
@@ -134,20 +135,27 @@ void GlobalSettings::set_defaults_where_needed()
        if (!contains(Key_Log_NotifyOfStacktrace))
                setValue(Key_Log_NotifyOfStacktrace, true);
 
-       // Default theme is bright, so use its color scheme
-       set_bright_theme_default_colors();
+       // Default theme is bright, so use its color scheme if undefined
+       if (!contains(Key_View_CursorFillColor))
+               set_bright_theme_default_colors();
 }
 
 void GlobalSettings::set_bright_theme_default_colors()
 {
        setValue(Key_View_FillSignalHighAreaColor,
                QColor(0, 0, 0, 5 * 256 / 100).rgba());
+
+       setValue(Key_View_CursorFillColor,
+               QColor(220, 231, 243).rgba());
 }
 
 void GlobalSettings::set_dark_theme_default_colors()
 {
        setValue(Key_View_FillSignalHighAreaColor,
                QColor(188, 188, 188, 9 * 256 / 100).rgba());
+
+       setValue(Key_View_CursorFillColor,
+               QColor(60, 60, 60).rgba());
 }
 
 bool GlobalSettings::current_theme_is_dark()
index 6f32bf0..e890a80 100644 (file)
@@ -67,6 +67,7 @@ public:
        static const QString Key_View_DefaultLogicHeight;
        static const QString Key_View_ShowHoverMarker;
        static const QString Key_View_SnapDistance;
+       static const QString Key_View_CursorFillColor;
        static const QString Key_Dec_InitialStateConfigurable;
        static const QString Key_Dec_ExportFormat;
        static const QString Key_Log_BufferSize;
index 0135c45..933eb8f 100644 (file)
 #include <algorithm>
 #include <cassert>
 
-#include <QDebug>
+#include <QColor>
 #include <QToolTip>
 
 #include "cursorpair.hpp"
 
+#include "pv/globalsettings.hpp"
 #include "pv/util.hpp"
 #include "ruler.hpp"
 #include "view.hpp"
@@ -40,17 +41,27 @@ namespace views {
 namespace trace {
 
 const int CursorPair::DeltaPadding = 8;
-const QColor CursorPair::ViewportFillColor(220, 231, 243);
 
 CursorPair::CursorPair(View &view) :
        TimeItem(view),
        first_(new Cursor(view, 0.0)),
        second_(new Cursor(view, 1.0))
 {
+       GlobalSettings::add_change_handler(this);
+
+       GlobalSettings settings;
+       fill_color_ = QColor::fromRgba(settings.value(
+               GlobalSettings::Key_View_CursorFillColor).value<uint32_t>());
+
        connect(&view_, SIGNAL(hover_point_changed(const QWidget*, QPoint)),
                this, SLOT(on_hover_point_changed(const QWidget*, QPoint)));
 }
 
+CursorPair::~CursorPair()
+{
+       GlobalSettings::remove_change_handler(this);
+}
+
 bool CursorPair::enabled() const
 {
        return view_.cursors_shown();
@@ -158,7 +169,7 @@ void CursorPair::paint_back(QPainter &p, ViewItemPaintParams &pp)
                return;
 
        p.setPen(Qt::NoPen);
-       p.setBrush(QBrush(ViewportFillColor));
+       p.setBrush(fill_color_);
 
        const pair<float, float> offsets(get_cursor_offsets());
        const int l = (int)max(min(offsets.first, offsets.second), 0.0f);
@@ -188,6 +199,12 @@ pair<float, float> CursorPair::get_cursor_offsets() const
        return pair<float, float>(first_->get_x(), second_->get_x());
 }
 
+void CursorPair::on_setting_changed(const QString &key, const QVariant &value)
+{
+       if (key == GlobalSettings::Key_View_CursorFillColor)
+               fill_color_ = QColor::fromRgba(value.value<uint32_t>());
+}
+
 void CursorPair::on_hover_point_changed(const QWidget* widget, const QPoint& hp)
 {
        if (widget != view_.ruler())
index 6728268..9d450df 100644 (file)
 #define PULSEVIEW_PV_VIEWS_TRACEVIEW_CURSORPAIR_HPP
 
 #include "cursor.hpp"
+#include "pv/globalsettings.hpp"
 
 #include <memory>
 
+#include <QColor>
 #include <QPainter>
 #include <QRect>
 
@@ -38,13 +40,12 @@ namespace trace {
 
 class View;
 
-class CursorPair : public TimeItem
+class CursorPair : public TimeItem, public GlobalSettingsInterface
 {
        Q_OBJECT
 
 private:
        static const int DeltaPadding;
-       static const QColor ViewportFillColor;
 
 public:
        /**
@@ -53,6 +54,8 @@ public:
         */
        CursorPair(View &view);
 
+       ~CursorPair();
+
        /**
         * Returns true if the item is visible and enabled.
         */
@@ -79,7 +82,6 @@ public:
 
        pv::widgets::Popup* create_popup(QWidget *parent) override;
 
-public:
        QRectF label_rect(const QRectF &rect) const override;
 
        /**
@@ -104,11 +106,14 @@ public:
 
        pair<float, float> get_cursor_offsets() const;
 
+       virtual void on_setting_changed(const QString &key, const QVariant &value) override;
+
 public Q_SLOTS:
        void on_hover_point_changed(const QWidget* widget, const QPoint &hp);
 
 private:
        shared_ptr<Cursor> first_, second_;
+       QColor fill_color_;
 
        QSizeF text_size_;
        QRectF label_area_;
index a9b21c7..ba85825 100644 (file)
@@ -33,7 +33,6 @@ class View;
  * nature, not making assumptions about the kind of item shown.
  */
 class TimeItem : public ViewItem
-
 {
        Q_OBJECT
 
index 53ed2a6..5ce3bb6 100644 (file)
@@ -53,7 +53,6 @@ public:
 public:
        ViewItem();
 
-public:
        /**
         * Returns true if the item is visible and enabled.
         */
@@ -151,7 +150,6 @@ public:
         */
        virtual void paint_fore(QPainter &p, ViewItemPaintParams &pp);
 
-public:
        /**
         * Gets the text color.
         * @remarks This color is computed by comparing the lightness