Signal(QString name);
public:
+ /**
+ * Gets the name of this signal.
+ */
QString get_name() const;
+ /**
+ * Sets the name of the signal.
+ */
+ void set_name(QString name);
+
/**
* Paints the signal with a QPainter
* @param p the QPainter to paint into.
#include <boost/foreach.hpp>
+#include <QInputDialog>
+#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
#include <QRect>
Header::Header(View &parent) :
QWidget(&parent),
- _view(parent)
+ _view(parent),
+ _action_set_name(new QAction(tr("Set &Name..."), this))
{
setMouseTracking(true);
+
+ connect(_action_set_name, SIGNAL(triggered()),
+ this, SLOT(on_action_set_name_triggered()));
}
void Header::paintEvent(QPaintEvent *event)
update();
}
+void Header::contextMenuEvent(QContextMenuEvent *event)
+{
+ const int w = width();
+ const vector< shared_ptr<Signal> > &sigs =
+ _view.session().get_signals();
+
+ int offset = -_view.v_offset();
+ BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+ {
+ assert(s);
+
+ const QRect signal_heading_rect(
+ 0, offset, w, View::SignalHeight);
+
+ if(s->pt_in_label_rect(signal_heading_rect, _mouse_point)) {
+ QMenu menu(this);
+ menu.addAction(_action_set_name);
+
+ _context_signal = s;
+ menu.exec(event->globalPos());
+ _context_signal.reset();
+
+ break;
+ }
+
+ offset += View::SignalHeight;
+ }
+}
+
+void Header::on_action_set_name_triggered()
+{
+ boost::shared_ptr<Signal> context_signal = _context_signal;
+ if(!context_signal)
+ return;
+
+ const QString new_label = QInputDialog::getText(this, tr("Set Name"),
+ tr("Name"), QLineEdit::Normal, context_signal->get_name());
+
+ if(!new_label.isEmpty())
+ context_signal->set_name(new_label);
+}
+
} // namespace view
} // namespace pv
#ifndef PV_VIEW_HEADER_H
#define PV_VIEW_HEADER_H
+#include <boost/shared_ptr.hpp>
+
#include <QWidget>
namespace pv {
+
+class Signal;
+
namespace view {
class View;
void leaveEvent(QEvent *event);
+ void contextMenuEvent(QContextMenuEvent *event);
+
+private slots:
+ void on_action_set_name_triggered();
+
private:
View &_view;
QPoint _mouse_point;
+
+ boost::shared_ptr<pv::Signal> _context_signal;
+ QAction *_action_set_name;
};
} // namespace view