]> sigrok.org Git - pulseview.git/commitdiff
CursorHeader: Make the size dependend on the used font.
authorJens Steinhauser <redacted>
Wed, 21 May 2014 10:16:03 +0000 (12:16 +0200)
committerJens Steinhauser <redacted>
Sat, 24 May 2014 16:33:43 +0000 (18:33 +0200)
pv/view/cursorheader.cpp
pv/view/cursorheader.h

index d1660276417d65a79e42a628aeee87cfd92bc716..861cd70f535249209268e6cc24b078e6a4f1ba62 100644 (file)
@@ -23,6 +23,7 @@
 #include "view.h"
 
 #include <QApplication>
+#include <QFontMetrics>
 #include <QMouseEvent>
 
 #include <pv/widgets/popup.h>
@@ -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()
index bab25191d3f9a0dc8d35ce15818cdd9a4cc9b60c..ff1759d47eb324b32e2ebfdb3948bc5674763d66 100644 (file)
@@ -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<TimeMarker> _grabbed_marker;
        QPoint _mouse_down_point;
        bool _dragging;
+       const int _textHeight;
 };
 
 } // namespace view