#include "cursorheader.h"
+#include "ruler.h"
#include "view.h"
#include <QApplication>
+#include <QFontMetrics>
#include <QMouseEvent>
#include <pv/widgets/popup.h>
namespace pv {
namespace view {
-const int CursorHeader::CursorHeaderHeight = 26;
+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),
- _dragging(false)
+ _dragging(false),
+ _textHeight(calculateTextHeight())
{
setMouseTracking(true);
}
QSize CursorHeader::sizeHint() const
{
- return QSize(0, CursorHeaderHeight);
+ return QSize(0, _textHeight + Padding + BaselineOffset);
}
void CursorHeader::clear_selection()
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
+ unsigned int prefix = pv::view::Ruler::calculate_tick_spacing(
+ p, _view.scale(), _view.offset()).second;
+
// Draw the cursors
if (_view.cursors_shown()) {
- _view.cursors().draw_markers(p, rect(), 0); //prefix);
+ // 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);
+ _view.cursors().draw_markers(p, r, prefix);
}
}
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);
+ const QPoint arrpos(m->get_x(), height() - BaselineOffset);
+ p->set_position(mapToGlobal(arrpos), Popup::Bottom);
p->show();
}