From: Joel Holdsworth Date: Sat, 3 Nov 2012 08:46:09 +0000 (+0000) Subject: Added a label colour chooser dialog X-Git-Tag: pulseview-0.1.0~222 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b3b57abc4fcfea1471529e9d116eaf11905f6639;p=pulseview.git Added a label colour chooser dialog --- diff --git a/pv/logicsignal.cpp b/pv/logicsignal.cpp index a0dabe4a..0c1933d5 100644 --- a/pv/logicsignal.cpp +++ b/pv/logicsignal.cpp @@ -58,6 +58,8 @@ LogicSignal::LogicSignal(QString name, shared_ptr data, _data(data) { assert(_probe_index >= 0); + _colour = LogicSignalColours[ + _probe_index % countof(LogicSignalColours)]; } void LogicSignal::paint(QPainter &p, const QRect &rect, double scale, @@ -145,11 +147,6 @@ void LogicSignal::paint_caps(QPainter &p, QLineF *const lines, p.drawLines(lines, line - lines); } -QColor LogicSignal::get_colour() const -{ - return LogicSignalColours[_probe_index % countof(LogicSignalColours)]; -} - int LogicSignal::get_nominal_offset(const QRect &rect) const { return rect.bottom() - Margin; diff --git a/pv/logicsignal.h b/pv/logicsignal.h index 5c527206..b1ef777a 100644 --- a/pv/logicsignal.h +++ b/pv/logicsignal.h @@ -63,11 +63,6 @@ private: bool level, double samples_per_pixel, double pixels_offset, float x_offset, float y_offset); - /** - * Get the colour of the logic signal - */ - QColor get_colour() const; - /** * When painting into the rectangle, calculate the y * offset of the zero point. diff --git a/pv/signal.cpp b/pv/signal.cpp index 9bc44d9d..04c57923 100644 --- a/pv/signal.cpp +++ b/pv/signal.cpp @@ -42,9 +42,19 @@ void Signal::set_name(QString name) _name = name; } +QColor Signal::get_colour() const +{ + return _colour; +} + +void Signal::set_colour(QColor colour) +{ + _colour = colour; +} + void Signal::paint_label(QPainter &p, const QRect &rect, bool hover) { - p.setBrush(get_colour()); + p.setBrush(_colour); const QColor colour = get_colour(); const float nominal_offset = get_nominal_offset(rect); diff --git a/pv/signal.h b/pv/signal.h index 951ae317..2afe9528 100644 --- a/pv/signal.h +++ b/pv/signal.h @@ -23,6 +23,7 @@ #include +#include #include #include #include @@ -52,6 +53,16 @@ public: */ void set_name(QString name); + /** + * Get the colour of the signal. + */ + QColor get_colour() const; + + /** + * Set the colour of the signal. + */ + void set_colour(QColor colour); + /** * Paints the signal with a QPainter * @param p the QPainter to paint into. @@ -96,11 +107,6 @@ private: QRectF get_label_rect(const QRect &rect); protected: - /** - * Get the colour of the logic signal - */ - virtual QColor get_colour() const = 0; - /** * When painting into the rectangle, calculate the y * offset of the zero point. @@ -109,6 +115,8 @@ protected: protected: QString _name; + QColor _colour; + QSizeF _text_size; }; diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 1c7903db..284bb372 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -28,6 +28,7 @@ #include +#include #include #include #include @@ -43,12 +44,15 @@ namespace view { Header::Header(View &parent) : QWidget(&parent), _view(parent), - _action_set_name(new QAction(tr("Set &Name..."), this)) + _action_set_name(new QAction(tr("Set &Name..."), this)), + _action_set_colour(new QAction(tr("Set &Colour..."), this)) { setMouseTracking(true); connect(_action_set_name, SIGNAL(triggered()), this, SLOT(on_action_set_name_triggered())); + connect(_action_set_colour, SIGNAL(triggered()), + this, SLOT(on_action_set_colour_triggered())); } void Header::paintEvent(QPaintEvent *event) @@ -107,6 +111,7 @@ void Header::contextMenuEvent(QContextMenuEvent *event) if(s->pt_in_label_rect(signal_heading_rect, _mouse_point)) { QMenu menu(this); menu.addAction(_action_set_name); + menu.addAction(_action_set_colour); _context_signal = s; menu.exec(event->globalPos()); @@ -132,5 +137,18 @@ void Header::on_action_set_name_triggered() context_signal->set_name(new_label); } +void Header::on_action_set_colour_triggered() +{ + boost::shared_ptr context_signal = _context_signal; + if(!context_signal) + return; + + const QColor new_colour = QColorDialog::getColor( + context_signal->get_colour(), this, tr("Set Colour")); + + if(new_colour.isValid()) + context_signal->set_colour(new_colour); +} + } // namespace view } // namespace pv diff --git a/pv/view/header.h b/pv/view/header.h index 6b97c4af..b9cf8da3 100644 --- a/pv/view/header.h +++ b/pv/view/header.h @@ -53,6 +53,8 @@ private: private slots: void on_action_set_name_triggered(); + void on_action_set_colour_triggered(); + private: View &_view; @@ -60,6 +62,7 @@ private: boost::shared_ptr _context_signal; QAction *_action_set_name; + QAction *_action_set_colour; }; } // namespace view