From: Joel Holdsworth Date: Sun, 12 May 2013 17:56:13 +0000 (+0100) Subject: Moved Signal selection behaviour into SelectableItem X-Git-Tag: pulseview-0.2.0~356 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f1283456ae0859990ccd914f8c147064345df13f;p=pulseview.git Moved Signal selection behaviour into SelectableItem --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6552df17..60644e16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,7 @@ set(pulseview_SOURCES pv/view/header.cpp pv/view/logicsignal.cpp pv/view/ruler.cpp + pv/view/selectableitem.cpp pv/view/signal.cpp pv/view/timemarker.cpp pv/view/view.cpp diff --git a/pv/view/selectableitem.cpp b/pv/view/selectableitem.cpp new file mode 100644 index 00000000..517b6879 --- /dev/null +++ b/pv/view/selectableitem.cpp @@ -0,0 +1,42 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "selectableitem.h" + +namespace pv { +namespace view { + +SelectableItem::SelectableItem() : + _selected(false) +{ +} + +bool SelectableItem::selected() const +{ + return _selected; +} + +void SelectableItem::select(bool select) +{ + _selected = select; +} + +} // namespace view +} // namespace pv diff --git a/pv/view/selectableitem.h b/pv/view/selectableitem.h index d5449137..69204b29 100644 --- a/pv/view/selectableitem.h +++ b/pv/view/selectableitem.h @@ -34,6 +34,22 @@ class SelectableItem : public QObject { Q_OBJECT +public: + SelectableItem(); + +public: + /** + * Returns true if the signal has been selected by the user. + */ + bool selected() const; + + /** + * Selects or deselects the signal. + */ + void select(bool select = true); + +private: + bool _selected; }; } // namespace view diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index cdbb65b1..dd50243a 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -39,8 +39,7 @@ const QPen Signal::SignalAxisPen(QColor(128, 128, 128, 64)); Signal::Signal(const sr_probe *const probe) : _probe(probe), _name(probe->name), - _v_offset(0), - _selected(false) + _v_offset(0) { assert(_probe); } @@ -75,16 +74,6 @@ void Signal::set_v_offset(int v_offset) _v_offset = v_offset; } -bool Signal::selected() const -{ - return _selected; -} - -void Signal::select(bool select) -{ - _selected = select; -} - void Signal::paint_label(QPainter &p, int y, int right, bool hover) { p.setBrush(_colour); @@ -114,7 +103,7 @@ void Signal::paint_label(QPainter &p, int y, int right, bool hover) QPointF(label_rect.left() + 1, label_rect.bottom() - 1) }; - if (_selected) { + if (selected()) { p.setPen(QPen(QApplication::palette().brush( QPalette::Highlight), LabelHighlightRadius, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); diff --git a/pv/view/signal.h b/pv/view/signal.h index 69c1f09c..4f16e3a7 100644 --- a/pv/view/signal.h +++ b/pv/view/signal.h @@ -87,16 +87,6 @@ public: */ void set_v_offset(int v_offset); - /** - * Returns true if the signal has been selected by the user. - */ - bool selected() const; - - /** - * Selects or deselects the signal. - */ - void select(bool select = true); - /** * Paints the signal with a QPainter * @param p the QPainter to paint into. @@ -168,8 +158,6 @@ protected: QColor _colour; int _v_offset; - bool _selected; - QSizeF _text_size; };