This way the cursor labels don't overlap with the ruler.
pv/toolbars/samplingbar.cpp
pv/view/analogsignal.cpp
pv/view/cursor.cpp
+ pv/view/cursorheader.cpp
pv/view/cursorpair.cpp
pv/view/header.cpp
pv/view/marginwidget.cpp
pv/prop/string.h
pv/toolbars/samplingbar.h
pv/view/cursor.h
+ pv/view/cursorheader.h
pv/view/header.h
pv/view/logicsignal.h
pv/view/marginwidget.h
--- /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.h"
+
+#include "view.h"
+
+#include <QApplication>
+#include <QMouseEvent>
+
+#include <pv/widgets/popup.h>
+
+using std::shared_ptr;
+
+namespace pv {
+namespace view {
+
+const int CursorHeader::CursorHeaderHeight = 26;
+
+CursorHeader::CursorHeader(View &parent) :
+ MarginWidget(parent),
+ _dragging(false)
+{
+ setMouseTracking(true);
+}
+
+QSize CursorHeader::sizeHint() const
+{
+ return QSize(0, CursorHeaderHeight);
+}
+
+void CursorHeader::clear_selection()
+{
+ CursorPair &cursors = _view.cursors();
+ cursors.first()->select(false);
+ cursors.second()->select(false);
+ update();
+}
+
+void CursorHeader::paintEvent(QPaintEvent*)
+{
+ QPainter p(this);
+ p.setRenderHint(QPainter::Antialiasing);
+
+ // Draw the cursors
+ if (_view.cursors_shown()) {
+ _view.cursors().draw_markers(p, rect(), 0); //prefix);
+ }
+}
+
+void CursorHeader::mouseMoveEvent(QMouseEvent *e)
+{
+ if (!(e->buttons() & Qt::LeftButton))
+ return;
+
+ if ((e->pos() - _mouse_down_point).manhattanLength() <
+ QApplication::startDragDistance())
+ return;
+
+ _dragging = true;
+
+ if (shared_ptr<TimeMarker> m = _grabbed_marker.lock())
+ m->set_time(_view.offset() +
+ ((double)e->x() + 0.5) * _view.scale());
+}
+
+void CursorHeader::mousePressEvent(QMouseEvent *e)
+{
+ if (e->buttons() & Qt::LeftButton) {
+ _mouse_down_point = e->pos();
+
+ _grabbed_marker.reset();
+
+ clear_selection();
+
+ if (_view.cursors_shown()) {
+ CursorPair &cursors = _view.cursors();
+ if (cursors.first()->get_label_rect(
+ rect()).contains(e->pos()))
+ _grabbed_marker = cursors.first();
+ else if (cursors.second()->get_label_rect(
+ rect()).contains(e->pos()))
+ _grabbed_marker = cursors.second();
+ }
+
+ if (shared_ptr<TimeMarker> m = _grabbed_marker.lock())
+ m->select();
+
+ selection_changed();
+ }
+}
+
+void CursorHeader::mouseReleaseEvent(QMouseEvent *)
+{
+ using pv::widgets::Popup;
+
+ if (!_dragging)
+ if (shared_ptr<TimeMarker> m = _grabbed_marker.lock()) {
+ Popup *const p = m->create_popup(&_view);
+ p->set_position(mapToGlobal(QPoint(m->get_x(),
+ height())), Popup::Bottom);
+ p->show();
+ }
+
+ _dragging = false;
+ _grabbed_marker.reset();
+}
+
+} // 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.h"
+
+namespace pv {
+namespace view {
+
+class TimeMarker;
+
+/**
+ * Widget to hold the labels over the cursors.
+ */
+class CursorHeader : public MarginWidget
+{
+ Q_OBJECT
+
+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 *);
+
+ static const int CursorHeaderHeight;
+
+ std::weak_ptr<TimeMarker> _grabbed_marker;
+ QPoint _mouse_down_point;
+ bool _dragging;
+};
+
+} // namespace view
+} // namespace pv
+
+#endif // PULSEVIEW_PV_VIEW_CURSORHEADER_H
{
}
+void MarginWidget::clear_selection()
+{
+}
+
} // namespace view
} // namespace pv
MarginWidget(pv::view::View &parent);
public slots:
- virtual void clear_selection() = 0;
+ virtual void clear_selection();
signals:
void selection_changed();
#include "ruler.h"
-#include "cursor.h"
#include "view.h"
-#include "viewport.h"
#include "pv/util.h"
#include <extdef.h>
-#include <QApplication>
-#include <QMouseEvent>
-#include <QPainter>
-#include <QTextStream>
-
-#include <pv/widgets/popup.h>
-
using namespace Qt;
-using std::shared_ptr;
namespace pv {
namespace view {
const int Ruler::HoverArrowSize = 5;
Ruler::Ruler(View &parent) :
- MarginWidget(parent),
- _dragging(false)
+ MarginWidget(parent)
{
setMouseTracking(true);
this, SLOT(hover_point_changed()));
}
-void Ruler::clear_selection()
-{
- CursorPair &cursors = _view.cursors();
- cursors.first()->select(false);
- cursors.second()->select(false);
- update();
-}
-
-
QSize Ruler::sizeHint() const
{
return QSize(0, RulerHeight);
void Ruler::paintEvent(QPaintEvent*)
{
-
const double SpacingIncrement = 32.0f;
const double MinValueSpacing = 32.0f;
const int ValueMargin = 3;
} while (x < width());
- // Draw the cursors
- if (_view.cursors_shown())
- _view.cursors().draw_markers(p, rect(), prefix);
-
// Draw the hover mark
draw_hover_mark(p);
-
- p.end();
-}
-
-void Ruler::mouseMoveEvent(QMouseEvent *e)
-{
- if (!(e->buttons() & Qt::LeftButton))
- return;
-
- if ((e->pos() - _mouse_down_point).manhattanLength() <
- QApplication::startDragDistance())
- return;
-
- _dragging = true;
-
- if (shared_ptr<TimeMarker> m = _grabbed_marker.lock())
- m->set_time(_view.offset() +
- ((double)e->x() + 0.5) * _view.scale());
-}
-
-void Ruler::mousePressEvent(QMouseEvent *e)
-{
- if (e->buttons() & Qt::LeftButton)
- {
- _mouse_down_point = e->pos();
-
- _grabbed_marker.reset();
-
- clear_selection();
-
- if (_view.cursors_shown()) {
- CursorPair &cursors = _view.cursors();
- if (cursors.first()->get_label_rect(
- rect()).contains(e->pos()))
- _grabbed_marker = cursors.first();
- else if (cursors.second()->get_label_rect(
- rect()).contains(e->pos()))
- _grabbed_marker = cursors.second();
- }
-
- if (shared_ptr<TimeMarker> m = _grabbed_marker.lock())
- m->select();
-
- selection_changed();
- }
-}
-
-void Ruler::mouseReleaseEvent(QMouseEvent *)
-{
- using pv::widgets::Popup;
-
- if (!_dragging)
- if (shared_ptr<TimeMarker> m = _grabbed_marker.lock()) {
- Popup *const p = m->create_popup(&_view);
- p->set_position(mapToGlobal(QPoint(m->get_x(),
- height())), Popup::Bottom);
- p->show();
- }
-
- _dragging = false;
- _grabbed_marker.reset();
}
void Ruler::draw_hover_mark(QPainter &p)
{
const int x = _view.hover_point().x();
- if (x == -1 || _dragging)
+ if (x == -1)
return;
p.setPen(QPen(Qt::NoPen));
namespace pv {
namespace view {
-class TimeMarker;
-class View;
-
class Ruler : public MarginWidget
{
Q_OBJECT
public:
Ruler(View &parent);
- void clear_selection();
-
public:
QSize sizeHint() const;
private:
void paintEvent(QPaintEvent *event);
- void mouseMoveEvent(QMouseEvent *e);
- void mousePressEvent(QMouseEvent *e);
- void mouseReleaseEvent(QMouseEvent *);
-
private:
/**
* Draw a hover arrow under the cursor position.
private slots:
void hover_point_changed();
-
-private:
- std::weak_ptr<TimeMarker> _grabbed_marker;
- QPoint _mouse_down_point;
- bool _dragging;
};
} // namespace view
#include <QMouseEvent>
#include <QScrollBar>
+#include "cursorheader.h"
#include "decodetrace.h"
#include "header.h"
#include "ruler.h"
_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()),
- _ruler, SLOT(clear_selection()));
- connect(_ruler, SIGNAL(selection_changed()),
+ _cursorheader, SLOT(clear_selection()));
+ connect(_cursorheader, SIGNAL(selection_changed()),
_header, SLOT(clear_selection()));
connect(_header, SIGNAL(selection_changed()),
this, SIGNAL(selection_changed()));
- connect(_ruler, SIGNAL(selection_changed()),
+ connect(_cursorheader, SIGNAL(selection_changed()),
this, SIGNAL(selection_changed()));
setViewport(_viewport);
_viewport->installEventFilter(this);
_ruler->installEventFilter(this);
+ _cursorheader->installEventFilter(this);
_header->installEventFilter(this);
// Trigger the initial event manually. The default device has signals
// which were created before this object came into being
signals_changed();
+
+ // make sure the cursorheader is over the ruler
+ _cursorheader->raise();
}
SigSession& View::session()
update_scroll();
_ruler->update();
+ _cursorheader->update();
_viewport->update();
scale_offset_changed();
}
void View::show_cursors(bool show)
{
_show_cursors = show;
- _ruler->update();
+ _cursorheader->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);
- _ruler->update();
+ _cursorheader->update();
_viewport->update();
}
_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());
_header->setGeometry(0, _viewport->y(),
_viewport->x(), _viewport->height());
update_scroll();
const QMouseEvent *const mouse_event = (QMouseEvent*)event;
if (object == _viewport)
_hover_point = mouse_event->pos();
- else if (object == _ruler)
+ else if (object == _ruler || object == _cursorheader)
_hover_point = QPoint(mouse_event->x(), 0);
else if (object == _header)
_hover_point = QPoint(0, mouse_event->y());
}
_ruler->update();
+ _cursorheader->update();
_viewport->update();
}
void View::marker_time_changed()
{
- _ruler->update();
+ _cursorheader->update();
_viewport->update();
}
namespace view {
+class CursorHeader;
class Header;
class Ruler;
class Trace;
Viewport *_viewport;
Ruler *_ruler;
+ CursorHeader *_cursorheader;
Header *_header;
/// The view time scale in seconds per pixel.