#include <boost/foreach.hpp>
#include <QApplication>
-#include <QColorDialog>
-#include <QInputDialog>
#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
namespace view {
Header::Header(View &parent) :
- MarginWidget(parent),
- _action_set_name(new QAction(tr("Set &Name..."), this)),
- _action_set_colour(new QAction(tr("Set &Colour..."), this))
+ MarginWidget(parent)
{
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()));
-
connect(&_view.session(), SIGNAL(signals_changed()),
this, SLOT(on_signals_changed()));
{
const shared_ptr<Trace> t = get_mouse_over_trace(_mouse_point);
- if (!t)
- return;
-
- QMenu menu(this);
- menu.addAction(_action_set_name);
- menu.addAction(_action_set_colour);
-
- _context_trace = t;
- menu.exec(event->globalPos());
- _context_trace.reset();
-}
-
-void Header::on_action_set_name_triggered()
-{
- bool ok = false;
-
- shared_ptr<view::Trace> context_trace = _context_trace;
- if (!context_trace)
- return;
-
- const QString new_label = QInputDialog::getText(this, tr("Set Name"),
- tr("Name"), QLineEdit::Normal, context_trace->get_name(), &ok);
-
- if (ok)
- context_trace->set_name(new_label);
-}
-
-void Header::on_action_set_colour_triggered()
-{
- shared_ptr<view::Trace> context_trace = _context_trace;
- if (!context_trace)
- return;
-
- const QColor new_colour = QColorDialog::getColor(
- context_trace->get_colour(), this, tr("Set Colour"));
-
- if (new_colour.isValid())
- context_trace->set_colour(new_colour);
+ if (t)
+ t->create_context_menu(this)->exec(event->globalPos());
}
void Header::on_signals_changed()
private slots:
void on_signals_changed();
- void on_action_set_name_triggered();
-
- void on_action_set_colour_triggered();
-
void on_signals_moved();
signals:
std::list<std::pair<boost::weak_ptr<Trace>, int> >
_drag_traces;
-
- boost::shared_ptr<Trace> _context_trace;
- QAction *_action_set_name;
- QAction *_action_set_colour;
};
} // namespace view
#include "selectableitem.h"
#include <QApplication>
+#include <QMenu>
#include <QPalette>
namespace pv {
const int SelectableItem::HighlightRadius = 6;
SelectableItem::SelectableItem() :
+ _context_parent(NULL),
_selected(false)
{
}
_selected = select;
}
+QMenu* SelectableItem::create_context_menu(QWidget *parent)
+{
+ _context_parent = parent;
+ return new QMenu(parent);
+}
+
QPen SelectableItem::highlight_pen()
{
return QPen(QApplication::palette().brush(
#include <QPen>
class QAction;
+class QMenu;
+class QWidget;
namespace pv {
namespace view {
virtual const std::list<QAction*> get_context_bar_actions() = 0;
+ virtual QMenu* create_context_menu(QWidget *parent);
+
protected:
static QPen highlight_pen();
+protected:
+ QWidget *_context_parent;
+
private:
bool _selected;
};
#include <assert.h>
#include <math.h>
+#include <QColorDialog>
+#include <QInputDialog>
+
#include "trace.h"
#include "view.h"
).contains(point);
}
+QMenu* Trace::create_context_menu(QWidget *parent)
+{
+ QMenu *const menu = SelectableItem::create_context_menu(parent);
+
+ QAction *const set_name = new QAction(tr("Set &Name..."), this);
+ connect(set_name, SIGNAL(triggered()),
+ this, SLOT(on_action_set_name_triggered()));
+ menu->addAction(set_name);
+
+ QAction *const set_colour = new QAction(tr("Set &Colour..."), this);
+ connect(set_colour, SIGNAL(triggered()),
+ this, SLOT(on_action_set_colour_triggered()));
+ menu->addAction(set_colour);
+
+ return menu;
+}
+
int Trace::get_y() const
{
return _v_offset - _view->v_offset();
label_size.width(), label_size.height());
}
+void Trace::on_action_set_name_triggered()
+{
+ bool ok = false;
+
+ const QString new_label = QInputDialog::getText(_context_parent,
+ tr("Set Name"), tr("Name"), QLineEdit::Normal, get_name(),
+ &ok);
+
+ if (ok)
+ set_name(new_label);
+}
+
+void Trace::on_action_set_colour_triggered()
+{
+ const QColor new_colour = QColorDialog::getColor(
+ get_colour(), _context_parent, tr("Set Colour"));
+
+ if (new_colour.isValid())
+ set_colour(new_colour);
+}
+
+
} // namespace view
} // namespace pv
*/
bool pt_in_label_rect(int left, int right, const QPoint &point);
+ virtual QMenu* create_context_menu(QWidget *parent);
+
protected:
/**
* Gets the y-offset of the axis.
*/
QRectF get_label_rect(int right);
+private slots:
+ void on_action_set_name_triggered();
+
+ void on_action_set_colour_triggered();
+
signals:
void text_changed();