pv/toolbars/samplingbar.cpp
pv/view/analogsignal.cpp
pv/view/cursor.cpp
- pv/view/cursorheader.cpp
pv/view/cursorpair.cpp
pv/view/flag.cpp
pv/view/header.cpp
pv/prop/binding/deviceoptions.hpp
pv/toolbars/samplingbar.hpp
pv/view/cursor.hpp
- pv/view/cursorheader.hpp
pv/view/flag.hpp
pv/view/header.hpp
pv/view/logicsignal.hpp
+++ /dev/null
-/*
- * This file is part of the PulseView project.
- *
- * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * 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
- */
-
-#include "cursorheader.hpp"
-
-#include "ruler.hpp"
-#include "view.hpp"
-
-#include <QApplication>
-#include <QFontMetrics>
-#include <QMouseEvent>
-
-#include <pv/widgets/popup.hpp>
-
-using std::shared_ptr;
-using std::vector;
-
-namespace pv {
-namespace view {
-
-const int CursorHeader::Padding = 20;
-const int CursorHeader::BaselineOffset = 5;
-
-int CursorHeader::calculateTextHeight()
-{
- QFontMetrics fm(font());
- return fm.boundingRect(0, 0, INT_MAX, INT_MAX,
- Qt::AlignLeft | Qt::AlignTop, "8").height();
-}
-
-CursorHeader::CursorHeader(View &parent) :
- MarginWidget(parent),
- textHeight_(calculateTextHeight())
-{
-}
-
-QSize CursorHeader::sizeHint() const
-{
- return QSize(0, textHeight_ + Padding + BaselineOffset);
-}
-
-void CursorHeader::clear_selection()
-{
- const vector< shared_ptr<TimeItem> > items(view_.time_items());
- for (auto &i : items)
- i->select(false);
- update();
-}
-
-void CursorHeader::paintEvent(QPaintEvent*)
-{
- QPainter p(this);
- p.setRenderHint(QPainter::Antialiasing);
-
- // The cursor labels are not drawn with the arrows exactly on the
- // bottom line of the widget, because then the selection shadow
- // would be clipped away.
- const QRect r = rect().adjusted(0, 0, 0, -BaselineOffset);
-
- // Draw the items
- const vector< shared_ptr<TimeItem> > items(view_.time_items());
- for (auto &m : items)
- m->paint_label(p, r);
-}
-
-void CursorHeader::mouseMoveEvent(QMouseEvent *e)
-{
- mouse_point_ = e->pos();
-
- if (!(e->buttons() & Qt::LeftButton))
- return;
-
- if ((e->pos() - mouse_down_point_).manhattanLength() <
- QApplication::startDragDistance())
- return;
-
- // Do the drag
- dragging_ = true;
-
- const int delta = e->pos().x() - mouse_down_point_.x();
- const vector< shared_ptr<TimeItem> > items(view_.time_items());
- for (auto &i : items)
- if (i->dragging())
- i->set_time(view_.offset() +
- (i->drag_point().x() + delta - 0.5) *
- view_.scale());
-}
-
-void CursorHeader::mousePressEvent(QMouseEvent *e)
-{
- if (e->buttons() & Qt::LeftButton) {
- mouse_down_point_ = e->pos();
-
- mouse_down_item_.reset();
-
- clear_selection();
-
- const vector< shared_ptr<TimeItem> > items(view_.time_items());
- for (auto i = items.rbegin(); i != items.rend(); i++)
- if ((*i)->label_rect(rect()).contains(e->pos())) {
- mouse_down_item_ = (*i);
- break;
- }
-
- if (mouse_down_item_) {
- mouse_down_item_->select();
- mouse_down_item_->drag();
- }
-
- selection_changed();
- }
-}
-
-void CursorHeader::mouseReleaseEvent(QMouseEvent *)
-{
- using pv::widgets::Popup;
-
- if (!dragging_ && mouse_down_item_) {
- Popup *const p = mouse_down_item_->create_popup(&view_);
- if (p) {
- const QPoint arrpos(mouse_down_item_->get_x(),
- height() - BaselineOffset);
- p->set_position(mapToGlobal(arrpos), Popup::Bottom);
- p->show();
- }
- }
-
- dragging_ = false;
- mouse_down_item_.reset();
-
- const vector< shared_ptr<TimeItem> > items(view_.time_items());
- for (auto &i : items)
- i->drag_release();
-}
-
-void CursorHeader::leaveEvent(QEvent*)
-{
- mouse_point_ = QPoint(-1, -1);
- update();
-}
-
-void CursorHeader::mouseDoubleClickEvent(QMouseEvent *e)
-{
- view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale());
-}
-
-void CursorHeader::keyPressEvent(QKeyEvent *e)
-{
- assert(e);
-
- if (e->key() == Qt::Key_Delete)
- {
- const vector< shared_ptr<TimeItem> > items(view_.time_items());
- for (auto &i : items)
- if (i->selected())
- i->delete_pressed();
- }
-}
-
-} // namespace view
-} // namespace pv
+++ /dev/null
-/*
- * This file is part of the PulseView project.
- *
- * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * 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
- */
-
-#ifndef PULSEVIEW_PV_VIEW_CURSORHEADER_H
-#define PULSEVIEW_PV_VIEW_CURSORHEADER_H
-
-#include <memory>
-
-#include "marginwidget.hpp"
-
-namespace pv {
-namespace view {
-
-class TimeItem;
-
-/**
- * Widget to hold the labels over the cursors.
- */
-class CursorHeader : public MarginWidget
-{
- Q_OBJECT
-
- static const int Padding;
-
- /**
- * The vertical offset, relative to the bottom line of the widget,
- * where the arrows of the cursor labels end.
- */
- static const int BaselineOffset;
-
-public:
- CursorHeader(View &parent);
-
- QSize sizeHint() const;
-
- void clear_selection();
-
-private:
- void paintEvent(QPaintEvent *event);
-
- void mouseMoveEvent(QMouseEvent *e);
- void mousePressEvent(QMouseEvent *e);
- void mouseReleaseEvent(QMouseEvent *);
- void leaveEvent(QEvent*);
-
- void mouseDoubleClickEvent(QMouseEvent *e);
-
- void keyPressEvent(QKeyEvent *e);
-
-private:
- int calculateTextHeight();
-
- std::shared_ptr<TimeItem> mouse_down_item_;
- const int textHeight_;
-};
-
-} // namespace view
-} // namespace pv
-
-#endif // PULSEVIEW_PV_VIEW_CURSORHEADER_H
return QSize(max_rect.width() + Padding + BaselineOffset, 0);
}
+QSize Header::extended_size_hint() const
+{
+ return sizeHint() + QSize(ViewItem::HighlightRadius, 0);
+}
+
shared_ptr<RowItem> Header::get_mouse_over_row_item(const QPoint &pt)
{
const QRect r(0, 0, width() - BaselineOffset, height());
QSize sizeHint() const;
+ /**
+ * The extended area that the header widget would like to be sized to.
+ * @remarks This area is the area specified by sizeHint, extended by
+ * the area to overlap the viewport.
+ */
+ QSize extended_size_hint() const;
+
/**
* The horizontal offset, relative to the left edge of the widget,
* where the arrows of the trace labels end.
public:
MarginWidget(pv::view::View &parent);
+ /**
+ * The extended area that the margin widget would like to be sized to.
+ * @remarks This area is the area specified by sizeHint, extended by
+ * the area to overlap the viewport.
+ */
+ virtual QSize extended_size_hint() const = 0;
+
public Q_SLOTS:
virtual void clear_selection();
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "ruler.hpp"
+#include <extdef.h>
+#include <QApplication>
+#include <QFontMetrics>
+#include <QMouseEvent>
+
+#include "ruler.hpp"
#include "view.hpp"
-#include "pv/util.hpp"
-#include <extdef.h>
+#include <pv/util.hpp>
+#include <pv/widgets/popup.hpp>
using namespace Qt;
+using std::shared_ptr;
+using std::vector;
+
namespace pv {
namespace view {
const int Ruler::HoverArrowSize = 5;
+const int Ruler::Padding = 20;
+const int Ruler::BaselineOffset = 5;
+
Ruler::Ruler(View &parent) :
- MarginWidget(parent)
+ MarginWidget(parent),
+ text_height_(calculate_text_height())
{
setMouseTracking(true);
this, SLOT(hover_point_changed()));
}
+void Ruler::clear_selection()
+{
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items)
+ i->select(false);
+ update();
+}
+
QSize Ruler::sizeHint() const
{
return QSize(0, RulerHeight);
}
+QSize Ruler::extended_size_hint() const
+{
+ return QSize(0, RulerHeight +
+ (text_height_ + Padding + BaselineOffset) / 2);
+}
+
void Ruler::paintEvent(QPaintEvent*)
{
const int ValueMargin = 3;
const double tick_period = view_.tick_period();
const unsigned int prefix = view_.tick_prefix();
- const int text_height = p.boundingRect(0, 0, INT_MAX, INT_MAX,
- AlignLeft | AlignTop, "8").height();
-
// Draw the tick marks
p.setPen(palette().color(foregroundRole()));
int division = (int)round(first_minor_division -
first_major_division * MinorTickSubdivision) - 1;
- const int major_tick_y1 = text_height + ValueMargin * 2;
- const int tick_y2 = height();
+ const int major_tick_y1 = text_height_ + ValueMargin * 2;
+ const int tick_y2 = RulerHeight;
const int minor_tick_y1 = (major_tick_y1 + tick_y2) / 2;
double x;
if (division % MinorTickSubdivision == 0)
{
// Draw a major tick
- p.drawText(x, ValueMargin, 0, text_height,
+ p.drawText(x, ValueMargin, 0, text_height_,
AlignCenter | AlignTop | TextDontClip,
pv::util::format_time(t, prefix));
p.drawLine(QPointF(x, major_tick_y1),
// Draw the hover mark
draw_hover_mark(p);
+
+ // The cursor labels are not drawn with the arrows exactly on the
+ // bottom line of the widget, because then the selection shadow
+ // would be clipped away.
+ const QRect r = rect().adjusted(0, 0, 0, -BaselineOffset);
+
+ // Draw the items
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items)
+ i->paint_label(p, r);
+}
+
+void Ruler::mouseMoveEvent(QMouseEvent *e)
+{
+ mouse_point_ = e->pos();
+
+ if (!(e->buttons() & Qt::LeftButton))
+ return;
+
+ if ((e->pos() - mouse_down_point_).manhattanLength() <
+ QApplication::startDragDistance())
+ return;
+
+ // Do the drag
+ dragging_ = true;
+
+ const int delta = e->pos().x() - mouse_down_point_.x();
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items)
+ if (i->dragging())
+ i->set_time(view_.offset() +
+ (i->drag_point().x() + delta - 0.5) *
+ view_.scale());
+}
+
+void Ruler::mousePressEvent(QMouseEvent *e)
+{
+ if (e->buttons() & Qt::LeftButton) {
+ mouse_down_point_ = e->pos();
+
+ mouse_down_item_.reset();
+
+ clear_selection();
+
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto i = items.rbegin(); i != items.rend(); i++)
+ if ((*i)->label_rect(rect()).contains(e->pos())) {
+ mouse_down_item_ = (*i);
+ break;
+ }
+
+ if (mouse_down_item_) {
+ mouse_down_item_->select();
+ mouse_down_item_->drag();
+ }
+
+ selection_changed();
+ }
+}
+
+void Ruler::mouseReleaseEvent(QMouseEvent *)
+{
+ using pv::widgets::Popup;
+
+ if (!dragging_ && mouse_down_item_) {
+ Popup *const p = mouse_down_item_->create_popup(&view_);
+ if (p) {
+ const QPoint arrpos(mouse_down_item_->get_x(),
+ height() - BaselineOffset);
+ p->set_position(mapToGlobal(arrpos), Popup::Bottom);
+ p->show();
+ }
+ }
+
+ dragging_ = false;
+ mouse_down_item_.reset();
+
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items)
+ i->drag_release();
+}
+
+void Ruler::leaveEvent(QEvent*)
+{
+ mouse_point_ = QPoint(-1, -1);
+ update();
+}
+
+void Ruler::mouseDoubleClickEvent(QMouseEvent *e)
+{
+ view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale());
+}
+
+void Ruler::keyPressEvent(QKeyEvent *e)
+{
+ assert(e);
+
+ if (e->key() == Qt::Key_Delete)
+ {
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items)
+ if (i->selected())
+ i->delete_pressed();
+ }
}
void Ruler::draw_hover_mark(QPainter &p)
p.setPen(QPen(Qt::NoPen));
p.setBrush(QBrush(palette().color(foregroundRole())));
- const int b = height() - 1;
+ const int b = RulerHeight;
const QPointF points[] = {
QPointF(x, b),
QPointF(x - HoverArrowSize, b - HoverArrowSize),
p.drawPolygon(points, countof(points));
}
+int Ruler::calculate_text_height()
+{
+ QFontMetrics fm(font());
+ return fm.boundingRect(0, 0, INT_MAX, INT_MAX,
+ Qt::AlignLeft | Qt::AlignTop, "8").height();
+}
+
void Ruler::hover_point_changed()
{
update();
namespace pv {
namespace view {
+class TimeItem;
+
class Ruler : public MarginWidget
{
Q_OBJECT
static const int HoverArrowSize;
+ static const int Padding;
+
+ /**
+ * The vertical offset, relative to the bottom line of the widget,
+ * where the arrows of the cursor labels end.
+ */
+ static const int BaselineOffset;
+
public:
Ruler(View &parent);
+public:
+ void clear_selection();
+
public:
QSize sizeHint() const;
+ /**
+ * The extended area that the header widget would like to be sized to.
+ * @remarks This area is the area specified by sizeHint, extended by
+ * the area to overlap the viewport.
+ */
+ QSize extended_size_hint() const;
+
private:
void paintEvent(QPaintEvent *event);
+ void mouseMoveEvent(QMouseEvent *e);
+ void mousePressEvent(QMouseEvent *e);
+ void mouseReleaseEvent(QMouseEvent *);
+ void leaveEvent(QEvent*);
+
+ void mouseDoubleClickEvent(QMouseEvent *e);
+
+ void keyPressEvent(QKeyEvent *e);
+
private:
/**
* Draw a hover arrow under the cursor position.
*/
void draw_hover_mark(QPainter &p);
+ int calculate_text_height();
+
+private:
+ std::shared_ptr<TimeItem> mouse_down_item_;
+ const int text_height_;
+
private Q_SLOTS:
void hover_point_changed();
};
#include <libsigrok/libsigrok.hpp>
-#include "cursorheader.hpp"
#include "decodetrace.hpp"
#include "header.hpp"
#include "logicsignal.hpp"
session_(session),
viewport_(new Viewport(*this)),
ruler_(new Ruler(*this)),
- cursorheader_(new CursorHeader(*this)),
header_(new Header(*this)),
scale_(1e-6),
offset_(0),
this, SLOT(on_signals_moved()));
connect(header_, SIGNAL(selection_changed()),
- cursorheader_, SLOT(clear_selection()));
- connect(cursorheader_, SIGNAL(selection_changed()),
+ ruler_, SLOT(clear_selection()));
+ connect(ruler_, SIGNAL(selection_changed()),
header_, SLOT(clear_selection()));
connect(header_, SIGNAL(selection_changed()),
this, SIGNAL(selection_changed()));
- connect(cursorheader_, SIGNAL(selection_changed()),
+ connect(ruler_, SIGNAL(selection_changed()),
this, SIGNAL(selection_changed()));
connect(this, SIGNAL(hover_point_changed()),
viewport_->installEventFilter(this);
ruler_->installEventFilter(this);
- cursorheader_->installEventFilter(this);
header_->installEventFilter(this);
// Trigger the initial event manually. The default device has signals
signals_changed();
// make sure the transparent widgets are on the top
- cursorheader_->raise();
+ ruler_->raise();
header_->raise();
// Update the zoom state
update_scroll();
ruler_->update();
- cursorheader_->update();
viewport_->update();
scale_offset_changed();
}
void View::show_cursors(bool show)
{
show_cursors_ = show;
- cursorheader_->update();
+ ruler_->update();
viewport_->update();
}
const double time_width = scale_ * viewport_->width();
cursors_->first()->set_time(offset_ + time_width * 0.4);
cursors_->second()->set_time(offset_ + time_width * 0.6);
- cursorheader_->update();
+ ruler_->update();
viewport_->update();
}
header_->sizeHint().width() - pv::view::Header::BaselineOffset,
ruler_->sizeHint().height(), 0, 0);
ruler_->setGeometry(viewport_->x(), 0,
- viewport_->width(), viewport_->y());
- cursorheader_->setGeometry(
- viewport_->x(),
- ruler_->sizeHint().height() - cursorheader_->sizeHint().height() / 2,
- viewport_->width(), cursorheader_->sizeHint().height());
+ viewport_->width(), ruler_->extended_size_hint().height());
header_->setGeometry(0, viewport_->y(),
- header_->sizeHint().width(), viewport_->height());
+ header_->extended_size_hint().width(), viewport_->height());
update_scroll();
}
const QMouseEvent *const mouse_event = (QMouseEvent*)event;
if (object == viewport_)
hover_point_ = mouse_event->pos();
- else if (object == ruler_ || object == cursorheader_)
+ else if (object == ruler_)
hover_point_ = QPoint(mouse_event->x(), 0);
else if (object == header_)
hover_point_ = QPoint(0, mouse_event->y());
void View::time_item_appearance_changed(bool label, bool content)
{
if (label)
- cursorheader_->update();
+ ruler_->update();
if (content)
viewport_->update();
}
}
ruler_->update();
- cursorheader_->update();
viewport_->update();
}
Viewport *viewport_;
Ruler *ruler_;
- CursorHeader *cursorheader_;
Header *header_;
/// The view time scale in seconds per pixel.
{
Q_OBJECT
-private:
+public:
static const int HighlightRadius;
public:
${PROJECT_SOURCE_DIR}/pv/popups/channels.cpp
${PROJECT_SOURCE_DIR}/pv/view/analogsignal.cpp
${PROJECT_SOURCE_DIR}/pv/view/cursor.cpp
- ${PROJECT_SOURCE_DIR}/pv/view/cursorheader.cpp
${PROJECT_SOURCE_DIR}/pv/view/cursorpair.cpp
${PROJECT_SOURCE_DIR}/pv/view/flag.cpp
${PROJECT_SOURCE_DIR}/pv/view/header.cpp
${PROJECT_SOURCE_DIR}/pv/prop/string.hpp
${PROJECT_SOURCE_DIR}/pv/prop/binding/deviceoptions.hpp
${PROJECT_SOURCE_DIR}/pv/view/cursor.hpp
- ${PROJECT_SOURCE_DIR}/pv/view/cursorheader.hpp
${PROJECT_SOURCE_DIR}/pv/view/flag.hpp
${PROJECT_SOURCE_DIR}/pv/view/header.hpp
${PROJECT_SOURCE_DIR}/pv/view/logicsignal.hpp