#include <boost/foreach.hpp>
+#include <QApplication>
#include <QColorDialog>
#include <QInputDialog>
#include <QMenu>
this, SLOT(on_action_set_colour_triggered()));
}
+boost::shared_ptr<pv::view::Signal> Header::get_mouse_over_signal(
+ const QPoint &pt)
+{
+ const int w = width();
+ const vector< shared_ptr<Signal> > &sigs =
+ _view.session().get_signals();
+
+ const int v_offset = _view.v_offset();
+ BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+ {
+ assert(s);
+
+ const QRect signal_heading_rect(
+ 0, s->get_v_offset() - v_offset,
+ w, View::SignalHeight);
+
+ if(s->pt_in_label_rect(signal_heading_rect, pt))
+ return s;
+ }
+
+ return shared_ptr<Signal>();
+}
+
void Header::paintEvent(QPaintEvent *event)
{
const int w = width();
painter.end();
}
+void Header::mousePressEvent(QMouseEvent *event)
+{
+ assert(event);
+
+ const vector< shared_ptr<Signal> > &sigs =
+ _view.session().get_signals();
+
+ if(~QApplication::keyboardModifiers() & Qt::ControlModifier) {
+ // Unselect all other signals because the Ctrl is not
+ // pressed
+ BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+ s->select(false);
+ }
+
+ // Select the signal if it has been clicked
+ const shared_ptr<Signal> mouse_over_signal =
+ get_mouse_over_signal(event->pos());
+ if(mouse_over_signal)
+ mouse_over_signal->select(!mouse_over_signal->selected());
+
+ update();
+}
+
void Header::mouseMoveEvent(QMouseEvent *event)
{
assert(event);
void Header::contextMenuEvent(QContextMenuEvent *event)
{
- const int w = width();
- const vector< shared_ptr<Signal> > &sigs =
- _view.session().get_signals();
+ const shared_ptr<Signal> s = get_mouse_over_signal(_mouse_point);
- const int v_offset = _view.v_offset();
- BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
- {
- assert(s);
-
- const QRect signal_heading_rect(
- 0, s->get_v_offset() - v_offset,
- w, View::SignalHeight);
-
- if(s->pt_in_label_rect(signal_heading_rect, _mouse_point)) {
- QMenu menu(this);
- menu.addAction(_action_set_name);
- menu.addAction(_action_set_colour);
+ if(!s)
+ return;
- _context_signal = s;
- menu.exec(event->globalPos());
- _context_signal.reset();
+ QMenu menu(this);
+ menu.addAction(_action_set_name);
+ menu.addAction(_action_set_colour);
- break;
- }
- }
+ _context_signal = s;
+ menu.exec(event->globalPos());
+ _context_signal.reset();
}
void Header::on_action_set_name_triggered()
#include <extdef.h>
+#include <QApplication>
+
#include "signal.h"
#include "view.h"
namespace view {
const int Signal::LabelHitPadding = 2;
+const int Signal::LabelHighlightRadius = 6;
Signal::Signal(QString name) :
_name(name),
- _v_offset(0)
+ _v_offset(0),
+ _selected(false)
{
}
_v_offset = v_offset;
}
+bool Signal::selected() const
+{
+ return _selected;
+}
+
+void Signal::select(bool select)
+{
+ _selected = select;
+}
+
void Signal::paint_label(QPainter &p, const QRect &rect, bool hover)
{
p.setBrush(_colour);
QPointF(label_rect.left() + 1, label_rect.bottom() - 1)
};
+ if(_selected) {
+ p.setPen(QPen(QApplication::palette().brush(
+ QPalette::Highlight), LabelHighlightRadius,
+ Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+ p.setBrush(Qt::transparent);
+ p.drawPolygon(points, countof(points));
+ }
+
p.setPen(Qt::transparent);
p.setBrush(hover ? colour.lighter() : colour);
p.drawPolygon(points, countof(points));