automatically detect the size of help window for charts (QWT)
authorAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Mon, 26 Mar 2018 15:58:53 +0000 (18:58 +0300)
committerAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Mon, 26 Mar 2018 15:58:53 +0000 (18:58 +0300)
src/analyze/gui/chartwidget.cpp

index 95baca741b6cd509dc33ac292dcef02752b856e1..1d2948502db33aa6f50cd353e9f9c72203e4e301 100644 (file)
@@ -35,6 +35,7 @@
 #include <KChartHeaderFooter>
 #include <KChartLegend>
 #elif defined(QWT_FOUND)
+#include <algorithm>
 #include <QAction>
 #include <QContextMenuEvent>
 #include <QMenu>
@@ -97,9 +98,6 @@ public:
         setWindowFlags(Qt::Tool);
         setAttribute(Qt::WA_ShowWithoutActivating);
         setAttribute(Qt::WA_DeleteOnClose);
-        setGeometry(0, 0, 292, 164);
-        setMinimumSize(100, 70);
-        setMaximumSize(400, 280);
         setPalette(QToolTip::palette());
         setWindowOpacity(0.9);
         setAutoFillBackground(true);
@@ -108,7 +106,7 @@ public:
         textEdit->setContextMenuPolicy(Qt::NoContextMenu);
         textEdit->viewport()->setAutoFillBackground(false);
         setCentralWidget(textEdit);
-        textEdit->setHtml(
+        const auto text =
             "<p>Use <u>Context Menu</u> (right click inside the chart to open) to control different chart options.</p>" \
             "<p>Use <u>left mouse button</u> to <b>zoom in</b> to selection: press the button, drag " \
             "to make a rectangular selection, release.</p>" \
@@ -117,7 +115,15 @@ public:
             "<li><b>zoom out</b> (one step back) - <b>&lt;Shift&gt;</b>+click;" \
             "<li><b>reset zoom</b> - <b>&lt;Ctrl&gt;</b>+click;" \
             "<li><b>move (pan)</b> the chart  - <b>&lt;Alt&gt;</b>+drag." \
-            "</ul>");
+            "</ul>";
+        textEdit->setHtml(text);
+        QFontMetrics fm(textEdit->font());
+        QRect rect = fm.boundingRect("Use left mouse button to zoom in to selection: press the ");
+        int textWidth = std::max(292, (int)round(rect.width() * 1.03));
+        int textHeight = std::max(164, (int)round(rect.height() * 1.03 * 12));
+        setGeometry(0, 0, textWidth, textHeight);
+        setMinimumSize(120, 80);
+        setMaximumSize(std::max(400, textWidth * 2), std::max(280, textHeight * 2));
     }
 
     virtual ~HelpWidget()