summaryrefslogtreecommitdiffstats
path: root/src/dialog
diff options
context:
space:
mode:
authorDaniel Poelzleithner <git@poelzi.org>2021-02-05 00:46:42 +0100
committerDaniel Poelzleithner <git@poelzi.org>2021-02-05 00:46:42 +0100
commita3544c5c8cecf83b06f071b030aff9d35ad66161 (patch)
treed70658f6fbd5d061412c4f426fe1fe5e22c96bc8 /src/dialog
parentcd3fc10dccd750095e08a100a282c914cc0229db (diff)
Add workaround for wrong SVG size after loading
Diffstat (limited to 'src/dialog')
-rw-r--r--src/dialog/dlgkeywheel.cpp17
-rw-r--r--src/dialog/dlgkeywheel.h2
2 files changed, 18 insertions, 1 deletions
diff --git a/src/dialog/dlgkeywheel.cpp b/src/dialog/dlgkeywheel.cpp
index 5ff64b962a..01ef50639c 100644
--- a/src/dialog/dlgkeywheel.cpp
+++ b/src/dialog/dlgkeywheel.cpp
@@ -3,6 +3,7 @@
#include <QDir>
#include <QKeyEvent>
#include <QMouseEvent>
+#include <QSvgRenderer>
#include "control/controlobject.h"
@@ -24,7 +25,7 @@ DlgKeywheel::DlgKeywheel(QWidget* parent, const UserSettingsPointer& pConfig)
QFile xmlFile(svgPath);
if (!xmlFile.exists() || !xmlFile.open(QFile::ReadOnly | QFile::Text)) {
- qDebug() << "Could not load template: " << svgPath;
+ qWarning() << "Could not load svg template: " << svgPath;
return;
}
m_domDocument.setContent(&xmlFile);
@@ -34,6 +35,10 @@ DlgKeywheel::DlgKeywheel(QWidget* parent, const UserSettingsPointer& pConfig)
graphic->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
graphic->setMinimumSize(200, 200);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ graphic->renderer()->setAspectRatioMode(Qt::KeepAspectRatio);
+#endif
+
connect(closeButton,
&QAbstractButton::clicked,
this,
@@ -68,6 +73,16 @@ bool DlgKeywheel::eventFilter(QObject* obj, QEvent* event) {
return QDialog::eventFilter(obj, event);
}
+void DlgKeywheel::show() {
+ QDialog::show();
+ // FIXME(XXX) this is a very ugly workaround that the svg graphics gets its
+ // correct form. The SVG seems only to be scaled correctly after it has been shown
+ if (!m_resized) {
+ resize(height() - 1, width() - 1);
+ m_resized = true;
+ }
+}
+
void DlgKeywheel::resizeEvent(QResizeEvent* ev) {
QSize newSize = ev->size();
int size = qMin(graphic->size().height(), graphic->size().width());
diff --git a/src/dialog/dlgkeywheel.h b/src/dialog/dlgkeywheel.h
index 091833baff..9d02e74de8 100644
--- a/src/dialog/dlgkeywheel.h
+++ b/src/dialog/dlgkeywheel.h
@@ -17,6 +17,7 @@ class DlgKeywheel : public QDialog, public Ui::DlgKeywheel {
void switchNotation(int dir = 1);
void updateSvg();
~DlgKeywheel() = default;
+ void show();
protected:
bool eventFilter(QObject* obj, QEvent* event) override;
@@ -28,6 +29,7 @@ class DlgKeywheel : public QDialog, public Ui::DlgKeywheel {
QDomDocument m_domDocument;
QSvgWidget* m_wheel;
const UserSettingsPointer m_pConfig;
+ bool m_resized{false};
};
#endif // DLGKEYWHEEL_H