+QColor Trace::get_text_colour() const
+{
+ return (_colour.lightness() > 64) ? Qt::black : Qt::white;
+}
+
+void Trace::paint_axis(QPainter &p, int y, int left, int right)
+{
+ p.setPen(AxisPen);
+ p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f));
+}
+
+void Trace::add_colour_option(QWidget *parent, QFormLayout *form)
+{
+ using pv::widgets::ColourButton;
+
+ ColourButton *const colour_button = new ColourButton(
+ TracePalette::Rows, TracePalette::Cols, parent);
+ colour_button->set_palette(TracePalette::Colours);
+ colour_button->set_colour(_colour);
+ connect(colour_button, SIGNAL(selected(const QColor&)),
+ this, SLOT(on_colour_changed(const QColor&)));
+
+ form->addRow(tr("Colour"), colour_button);
+}
+
+void Trace::create_popup_form()
+{
+ // Clear the layout
+
+ // Transfer the layout and the child widgets to a temporary widget
+ // which then goes out of scope destroying the layout and all the child
+ // widgets.
+ if (_popup_form)
+ QWidget().setLayout(_popup_form);
+
+ // Repopulate the popup
+ _popup_form = new QFormLayout(_popup);
+ _popup->setLayout(_popup_form);
+ populate_popup_form(_popup, _popup_form);
+}
+
+void Trace::populate_popup_form(QWidget *parent, QFormLayout *form)
+{
+ QLineEdit *const name_edit = new QLineEdit(parent);
+ name_edit->setText(_name);
+ connect(name_edit, SIGNAL(textChanged(const QString&)),
+ this, SLOT(on_text_changed(const QString&)));
+ form->addRow(tr("Name"), name_edit);
+
+ add_colour_option(parent, form);
+}
+
+void Trace::on_popup_closed()
+{
+ _popup = NULL;
+ _popup_form = NULL;
+}
+
+void Trace::on_text_changed(const QString &text)
+{
+ set_name(text);
+ text_changed();
+}
+
+void Trace::on_colour_changed(const QColor &colour)
+{
+ set_colour(colour);
+ colour_changed();
+}
+