From: Soeren Apel Date: Sat, 27 Oct 2018 12:27:45 +0000 (+0200) Subject: Implement customizable cursor fill color X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c04f5a29b805e2aa7afa06d80363bad1f5b705f6;p=pulseview.git Implement customizable cursor fill color --- diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index 1119b8fa..6878cadc 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -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())); + 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; diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index 4aa54580..43988fec 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -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); diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index 1cd65665..34dbc832 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -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() diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index 6f32bf01..e890a800 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -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; diff --git a/pv/views/trace/cursorpair.cpp b/pv/views/trace/cursorpair.cpp index 0135c457..933eb8ff 100644 --- a/pv/views/trace/cursorpair.cpp +++ b/pv/views/trace/cursorpair.cpp @@ -20,11 +20,12 @@ #include #include -#include +#include #include #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()); + 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 offsets(get_cursor_offsets()); const int l = (int)max(min(offsets.first, offsets.second), 0.0f); @@ -188,6 +199,12 @@ pair CursorPair::get_cursor_offsets() const return pair(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()); +} + void CursorPair::on_hover_point_changed(const QWidget* widget, const QPoint& hp) { if (widget != view_.ruler()) diff --git a/pv/views/trace/cursorpair.hpp b/pv/views/trace/cursorpair.hpp index 67282680..9d450df6 100644 --- a/pv/views/trace/cursorpair.hpp +++ b/pv/views/trace/cursorpair.hpp @@ -21,9 +21,11 @@ #define PULSEVIEW_PV_VIEWS_TRACEVIEW_CURSORPAIR_HPP #include "cursor.hpp" +#include "pv/globalsettings.hpp" #include +#include #include #include @@ -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 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 first_, second_; + QColor fill_color_; QSizeF text_size_; QRectF label_area_; diff --git a/pv/views/trace/timeitem.hpp b/pv/views/trace/timeitem.hpp index a9b21c72..ba858254 100644 --- a/pv/views/trace/timeitem.hpp +++ b/pv/views/trace/timeitem.hpp @@ -33,7 +33,6 @@ class View; * nature, not making assumptions about the kind of item shown. */ class TimeItem : public ViewItem - { Q_OBJECT diff --git a/pv/views/trace/viewitem.hpp b/pv/views/trace/viewitem.hpp index 53ed2a60..5ce3bb60 100644 --- a/pv/views/trace/viewitem.hpp +++ b/pv/views/trace/viewitem.hpp @@ -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