X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;ds=inline;f=pv%2Fview%2Fsignal.cpp;h=0ee89a1f23a403df763ae56a33319fb07fc439a7;hb=efdec55aec1a137460fa362a381ed1904182bfed;hp=bb86d8cb6d0add9c3585c8690dee22c60d06579a;hpb=9e40e83daf6a2851f4883468a4237849f984b336;p=pulseview.git
diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp
index bb86d8c..0ee89a1 100644
--- a/pv/view/signal.cpp
+++ b/pv/view/signal.cpp
@@ -14,35 +14,42 @@
* 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
+ * along with this program; if not, see .
*/
#include
#include
-#include
+#include
#include
+#include
+#include
+#include
+#include
-#include "signal.h"
-#include "view.h"
+#include
-namespace pv {
-namespace view {
+#include "pv/data/signalbase.hpp"
+
+#include "signal.hpp"
+#include "view.hpp"
-const int Signal::LabelHitPadding = 2;
+using std::shared_ptr;
+using std::make_shared;
-const QPen Signal::SignalAxisPen(QColor(128, 128, 128, 64));
+namespace pv {
+namespace views {
+namespace TraceView {
-const char *const ProbeNames[] = {
+const char *const ChannelNames[] = {
"CLK",
"DATA",
"IN",
"OUT",
"RST",
- "Tx",
- "Rx",
+ "TX",
+ "RX",
"EN",
"SCLK",
"MOSI",
@@ -52,157 +59,130 @@ const char *const ProbeNames[] = {
"SCL"
};
-Signal::Signal(const sr_probe *const probe) :
- _probe(probe),
- _name(probe->name),
- _v_offset(0),
- _name_action(NULL),
- _name_widget(),
- _updating_name_widget(false)
+Signal::Signal(pv::Session &session,
+ std::shared_ptr channel) :
+ Trace(channel),
+ session_(session),
+ scale_handle_(make_shared(*this)),
+ items_({scale_handle_}),
+ name_widget_(nullptr)
{
- assert(_probe);
+ assert(base_);
- _name_action.setDefaultWidget(&_name_widget);
+ connect(base_.get(), SIGNAL(enabled_changed(bool)),
+ this, SLOT(on_enabled_changed(bool)));
+}
- _name_widget.setEditable(true);
- for(unsigned int i = 0; i < countof(ProbeNames); i++)
- _name_widget.insertItem(i, ProbeNames[i]);
- _name_widget.setEditText(probe->name);
+void Signal::set_name(QString name)
+{
+ Trace::set_name(name);
- connect(&_name_widget, SIGNAL(editTextChanged(const QString&)),
- this, SLOT(on_text_changed(const QString&)));
+ if (name != name_widget_->currentText())
+ name_widget_->setEditText(name);
}
-QString Signal::get_name() const
+bool Signal::enabled() const
{
- return _name;
+ return base_->enabled();
}
-void Signal::set_name(QString name)
+shared_ptr Signal::base() const
{
- _name = name;
- _updating_name_widget = true;
- _name_widget.setEditText(name);
- _updating_name_widget = false;
+ return base_;
}
-QColor Signal::get_colour() const
+void Signal::save_settings(QSettings &settings) const
{
- return _colour;
+ (void)settings;
}
-void Signal::set_colour(QColor colour)
+void Signal::restore_settings(QSettings &settings)
{
- _colour = colour;
+ (void)settings;
}
-int Signal::get_v_offset() const
+const ViewItemOwner::item_list& Signal::child_items() const
{
- return _v_offset;
+ return items_;
}
-void Signal::set_v_offset(int v_offset)
+void Signal::paint_back(QPainter &p, const ViewItemPaintParams &pp)
{
- _v_offset = v_offset;
+ if (base_->enabled())
+ Trace::paint_back(p, pp);
}
-void Signal::paint_label(QPainter &p, int y, int right, bool hover)
+void Signal::populate_popup_form(QWidget *parent, QFormLayout *form)
{
- p.setBrush(_colour);
+ name_widget_ = new QComboBox(parent);
+ name_widget_->setEditable(true);
+ name_widget_->setCompleter(nullptr);
- if (!_probe->enabled)
- return;
+ for (unsigned int i = 0; i < countof(ChannelNames); i++)
+ name_widget_->insertItem(i, ChannelNames[i]);
- const QColor colour = get_colour();
-
- compute_text_size(p);
- const QRectF label_rect = get_label_rect(y, right);
-
- // Paint the label
- const QPointF points[] = {
- label_rect.topLeft(),
- label_rect.topRight(),
- QPointF(right, y),
- label_rect.bottomRight(),
- label_rect.bottomLeft()
- };
-
- const QPointF highlight_points[] = {
- QPointF(label_rect.left() + 1, label_rect.top() + 1),
- QPointF(label_rect.right(), label_rect.top() + 1),
- QPointF(right - 1, y),
- QPointF(label_rect.right(), label_rect.bottom() - 1),
- QPointF(label_rect.left() + 1, label_rect.bottom() - 1)
- };
-
- if (selected()) {
- p.setPen(highlight_pen());
- p.setBrush(Qt::transparent);
- p.drawPolygon(points, countof(points));
- }
+ const int index = name_widget_->findText(base_->name(), Qt::MatchExactly);
- p.setPen(Qt::transparent);
- p.setBrush(hover ? colour.lighter() : colour);
- p.drawPolygon(points, countof(points));
+ if (index == -1) {
+ name_widget_->insertItem(0, base_->name());
+ name_widget_->setCurrentIndex(0);
+ } else {
+ name_widget_->setCurrentIndex(index);
+ }
- p.setPen(colour.lighter());
- p.setBrush(Qt::transparent);
- p.drawPolygon(highlight_points, countof(highlight_points));
+ connect(name_widget_, SIGNAL(editTextChanged(const QString&)),
+ this, SLOT(on_nameedit_changed(const QString&)));
- p.setPen(colour.darker());
- p.setBrush(Qt::transparent);
- p.drawPolygon(points, countof(points));
+ form->addRow(tr("Name"), name_widget_);
- // Paint the text
- p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white);
- p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name);
+ add_colour_option(parent, form);
}
-bool Signal::pt_in_label_rect(int y, int left, int right,
- const QPoint &point)
+QMenu* Signal::create_context_menu(QWidget *parent)
{
- (void)left;
-
- const QRectF label = get_label_rect(y, right);
- return QRectF(
- QPointF(label.left() - LabelHitPadding,
- label.top() - LabelHitPadding),
- QPointF(right, label.bottom() + LabelHitPadding)
- ).contains(point);
+ QMenu *const menu = Trace::create_context_menu(parent);
+
+ menu->addSeparator();
+
+ QAction *const disable = new QAction(tr("Disable"), this);
+ disable->setShortcuts(QKeySequence::Delete);
+ connect(disable, SIGNAL(triggered()), this, SLOT(on_disable()));
+ menu->addAction(disable);
+
+ return menu;
}
-void Signal::paint_axis(QPainter &p, int y, int left, int right)
+void Signal::delete_pressed()
{
- p.setPen(SignalAxisPen);
- p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f));
+ on_disable();
}
-void Signal::compute_text_size(QPainter &p)
+void Signal::on_name_changed(const QString &text)
{
- _text_size = QSize(
- p.boundingRect(QRectF(), 0, _name).width(),
- p.boundingRect(QRectF(), 0, "Tg").height());
+ // On startup, this event is fired when a session restores signal
+ // names. However, the name widget hasn't yet been created.
+ if (!name_widget_)
+ return;
+
+ if (text != name_widget_->currentText())
+ name_widget_->setEditText(text);
+
+ Trace::on_name_changed(text);
}
-QRectF Signal::get_label_rect(int y, int right)
+void Signal::on_disable()
{
- using pv::view::View;
-
- const QSizeF label_size(
- _text_size.width() + View::LabelPadding.width() * 2,
- ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2);
- const float label_arrow_length = label_size.height() / 2;
- return QRectF(
- right - label_arrow_length - label_size.width() - 0.5,
- y + 0.5f - label_size.height() / 2,
- label_size.width(), label_size.height());
+ base_->set_enabled(false);
}
-void Signal::on_text_changed(const QString &text)
+void Signal::on_enabled_changed(bool enabled)
{
- _name = text;
- text_changed();
+ (void)enabled;
+
+ if (owner_)
+ owner_->extents_changed(true, true);
}
-} // namespace view
+} // namespace TraceView
+} // namespace views
} // namespace pv