Compare commits

...

1 Commits

Author SHA1 Message Date
joshua
de2f161566 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.
2021-04-17 09:50:32 +02:00
4 changed files with 45 additions and 0 deletions

View File

@@ -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<int>::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);
}
/**

View File

@@ -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

View File

@@ -37,6 +37,8 @@
#include <QDomElement>
#include <utility>
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

View File

@@ -95,6 +95,7 @@ class Element : public QetGraphicsItem
public:
static void setPictureScale(qreal scale);
QList<Terminal *> terminals() const;
QList<Conductor *> conductors() const;
QList<QPair<Terminal *,Terminal *>> AlignedFreeTerminals() const;