From 4707a23dc7b76258f95d9522fbb6f4c7fd5cc558 Mon Sep 17 00:00:00 2001 From: Jens Steinhauser Date: Wed, 21 May 2014 12:16:03 +0200 Subject: [PATCH] CursorHeader: Make the size dependend on the used font. --- pv/view/cursorheader.cpp | 15 ++++++++++++--- pv/view/cursorheader.h | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pv/view/cursorheader.cpp b/pv/view/cursorheader.cpp index d1660276..861cd70f 100644 --- a/pv/view/cursorheader.cpp +++ b/pv/view/cursorheader.cpp @@ -23,6 +23,7 @@ #include "view.h" #include +#include #include #include @@ -32,18 +33,26 @@ using std::shared_ptr; namespace pv { namespace view { -const int CursorHeader::CursorHeaderHeight = 26; +const int CursorHeader::Padding = 20; + +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); } void CursorHeader::clear_selection() diff --git a/pv/view/cursorheader.h b/pv/view/cursorheader.h index bab25191..ff1759d4 100644 --- a/pv/view/cursorheader.h +++ b/pv/view/cursorheader.h @@ -37,6 +37,8 @@ class CursorHeader : public MarginWidget { Q_OBJECT + static const int Padding; + public: CursorHeader(View &parent); @@ -51,11 +53,12 @@ private: void mousePressEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *); - static const int CursorHeaderHeight; + int calculateTextHeight(); std::weak_ptr _grabbed_marker; QPoint _mouse_down_point; bool _dragging; + const int _textHeight; }; } // namespace view -- 2.30.2