From de2f161566d9eb5811595e24f9a645b058fe4973 Mon Sep 17 00:00:00 2001 From: joshua Date: Sat, 17 Apr 2021 09:49:23 +0200 Subject: [PATCH] Add a combo box to change the QPicture scale of element picture This is a test commit to see if we can fix the wrong scale of element in some screen size.: Add a QComboBox into the QToolBar of the diagram editor to change the current scale factor of the element QPicture. --- sources/qetdiagrameditor.cpp | 25 +++++++++++++++++++++++++ sources/qetdiagrameditor.h | 2 ++ sources/qetgraphicsitem/element.cpp | 17 +++++++++++++++++ sources/qetgraphicsitem/element.h | 1 + 4 files changed, 45 insertions(+) diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 22916b1f1..636cd3a7e 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -738,11 +738,36 @@ void QETDiagramEditor::setUpToolBar() m_depth_tool_bar->setObjectName("diagram_depth_toolbar"); m_depth_tool_bar->addActions(m_depth_action_group->actions()); + auto element_picture_scale_tool_bar = new QToolBar(tr("Facteur d'échelle des élements"), this); + auto label_ = new QLabel(tr("Facteur d'échelle des élements : "), this); + element_picture_scale_tool_bar->addWidget(label_); + m_scale_picture_cb = new QComboBox(this); + m_scale_picture_cb->addItem("0,25", 0.25); + m_scale_picture_cb->addItem("0,50", 0.5); + m_scale_picture_cb->addItem("0,75", 0.75); + m_scale_picture_cb->addItem("1", 1); + m_scale_picture_cb->addItem("1,25", 1.25); + m_scale_picture_cb->addItem("1,50", 1.5); + m_scale_picture_cb->addItem("1,75", 1.75); + m_scale_picture_cb->addItem("2", 2); + m_scale_picture_cb->setCurrentIndex(3); + element_picture_scale_tool_bar->addWidget(m_scale_picture_cb); + connect(m_scale_picture_cb, QOverload::of(&QComboBox::currentIndexChanged), [this](int) + { + Element::setPictureScale(m_scale_picture_cb->currentData().toReal()); + auto dv = this->currentDiagramView(); + if (dv && dv->scene()) { + dv->scene()->update(); + } + }); + + addToolBar(Qt::TopToolBarArea, main_tool_bar); addToolBar(Qt::TopToolBarArea, view_tool_bar); addToolBar(Qt::TopToolBarArea, diagram_tool_bar); addToolBar(Qt::TopToolBarArea, m_add_item_tool_bar); addToolBar(Qt::TopToolBarArea, m_depth_tool_bar); + addToolBar(Qt::TopToolBarArea, element_picture_scale_tool_bar); } /** diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index db17ea877..7d42be23d 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -42,6 +42,7 @@ class RecentFiles; class DiagramPropertiesEditorDockWidget; class ElementsCollectionWidget; class AutoNumberingDockWidget; +class QComboBox; #ifdef BUILD_WITHOUT_KF5 #else @@ -240,5 +241,6 @@ class QETDiagramEditor : public QETMainWindow int activeSubWindowIndex; bool m_first_show = true; SearchAndReplaceWidget m_search_and_replace_widget; + QComboBox *m_scale_picture_cb = nullptr; }; #endif diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 2b7bef380..cd0a1d177 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -37,6 +37,8 @@ #include #include +qreal PICTURE_SCALE = 1; + class ElementXmlRetroCompatibility { friend class Element; @@ -126,6 +128,11 @@ Element::Element( }); } +void Element::setPictureScale(qreal scale) +{ + PICTURE_SCALE = scale; +} + /** @brief Element::~Element */ @@ -234,7 +241,17 @@ void Element::paint( { painter->drawPicture(0, 0, m_low_zoom_picture); } else { + if (Q_UNLIKELY(PICTURE_SCALE != 1.0)) + { + painter->save(); + painter->scale(PICTURE_SCALE, PICTURE_SCALE); painter->drawPicture(0, 0, m_picture); + painter->restore(); + } + else + { + painter->drawPicture(0, 0, m_picture); + } } painter->restore(); //Restor the QPainter after use drawPicture diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index ca4d8fa69..937a579a8 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -95,6 +95,7 @@ class Element : public QetGraphicsItem public: + static void setPictureScale(qreal scale); QList terminals() const; QList conductors() const; QList> AlignedFreeTerminals() const;