]> sigrok.org Git - pulseview.git/commitdiff
Added a label colour chooser dialog
authorJoel Holdsworth <redacted>
Sat, 3 Nov 2012 08:46:09 +0000 (08:46 +0000)
committerJoel Holdsworth <redacted>
Sat, 3 Nov 2012 09:50:34 +0000 (09:50 +0000)
pv/logicsignal.cpp
pv/logicsignal.h
pv/signal.cpp
pv/signal.h
pv/view/header.cpp
pv/view/header.h

index a0dabe4a00ed1c39bf1d68c51a950238afc448f4..0c1933d5ae8ed50d408344631cd0def0f63dd5ac 100644 (file)
@@ -58,6 +58,8 @@ LogicSignal::LogicSignal(QString name, shared_ptr<LogicData> 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;
index 5c527206d521faf915345aa3940a949ae937cb68..b1ef777ad47ced54fa30b9cc6183aa56c49e0c76 100644 (file)
@@ -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.
index 9bc44d9d161d2fbe6316d6b291ba1bb0f3530158..04c579232e4c6a2966680b0ad68a39ddf796aacf 100644 (file)
@@ -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);
index 951ae3172bc576cd12e76dd9ccf349d937584cd4..2afe9528dfe8cceac605d38c6600977f7381b61c 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <boost/shared_ptr.hpp>
 
+#include <QColor>
 #include <QPainter>
 #include <QRect>
 #include <QString>
@@ -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;
 };
 
index 1c7903dbc372d38d55366b771c49fe3854de9bdf..284bb37284cfe7e1a49ce6b11d8662f28d387df8 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <boost/foreach.hpp>
 
+#include <QColorDialog>
 #include <QInputDialog>
 #include <QMenu>
 #include <QMouseEvent>
@@ -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<Signal> 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
index 6b97c4af307df7b362e022262a9679d2cafe9bab..b9cf8da3e76560bc21b0ded392ab85417458acc8 100644 (file)
@@ -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<pv::Signal> _context_signal;
        QAction *_action_set_name;
+       QAction *_action_set_colour;
 };
 
 } // namespace view