From: Jens Steinhauser Date: Wed, 21 May 2014 10:16:03 +0000 (+0200) Subject: CursorHeader: Make the size dependend on the used font. X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=commitdiff_plain;h=4707a23dc7b76258f95d9522fbb6f4c7fd5cc558 CursorHeader: Make the size dependend on the used font. --- diff --git a/pv/view/cursorheader.cpp b/pv/view/cursorheader.cpp index d166027..861cd70 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 bab2519..ff1759d 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