mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-08 21:14:14 +02:00
Merge remote-tracking branch 'upstream/master' into fix/675-line-editor-stale-refresh
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
#include <QActionGroup>
|
||||
#include <QFileDialog>
|
||||
#include <QSvgGenerator>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
/**
|
||||
* @brief QETElementEditor::QETElementEditor
|
||||
@@ -77,8 +78,9 @@ QETElementEditor::QETElementEditor(QWidget *parent) :
|
||||
//ui->m_display_menu->insertMenu(ui->m_zoom_in_action, menu);
|
||||
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
readSettings();
|
||||
readSettings(); // restoreGeometry before show()
|
||||
show();
|
||||
readSettingsState(); // restoreState() must be called after show() in Qt6
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -860,7 +862,7 @@ bool QETElementEditor::event(QEvent *event)
|
||||
{
|
||||
if (m_first_activation && event->type() == QEvent::WindowActivate) {
|
||||
m_first_activation = false;
|
||||
QTimer::singleShot(250, m_view, SLOT(zoomFit()));
|
||||
QTimer::singleShot(250, m_view, &ElementView::zoomFit);
|
||||
}
|
||||
|
||||
return QMainWindow::event(event);
|
||||
@@ -962,16 +964,28 @@ void QETElementEditor::readSettings()
|
||||
restoreGeometry(geometry.toByteArray());
|
||||
}
|
||||
|
||||
QVariant state = settings.value("elementeditor/state");
|
||||
if (state.isValid()) {
|
||||
restoreState(state.toByteArray());
|
||||
}
|
||||
|
||||
auto data = m_elmt_scene->elementData();
|
||||
data.m_drawing_information = settings.value("elementeditor/default-informations", "").toString();
|
||||
m_elmt_scene->setElementData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETElementEditor::readSettingsState
|
||||
* Restore the window state (docks, toolbars).
|
||||
* Must be called AFTER show() in Qt6 for restoreState() to work correctly.
|
||||
*/
|
||||
void QETElementEditor::readSettingsState()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
QVariant state = settings.value("elementeditor/state");
|
||||
if (state.isValid()) {
|
||||
if (!restoreState(state.toByteArray())) {
|
||||
settings.remove("elementeditor/state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETElementEditor::writeSettings
|
||||
* Write some setting of this widget in the
|
||||
@@ -1100,29 +1114,39 @@ void QETElementEditor::updateAction()
|
||||
{
|
||||
//Action disabled if read only
|
||||
auto ro_list = m_add_part_action_grp->actions();
|
||||
ro_list << ui->m_select_all_act
|
||||
<< ui->m_revert_selection_action
|
||||
<< ui->m_paste_from_file_action
|
||||
ro_list << ui->m_paste_from_file_action
|
||||
<< ui->m_paste_from_element_action;
|
||||
for (auto action : std::as_const(ro_list)) {
|
||||
action->setDisabled(m_read_only);
|
||||
}
|
||||
|
||||
//Changing what is selected does not change the element, so these stay
|
||||
//available when it is read only -- otherwise there is no way to pick
|
||||
//out the primitive you want to copy out of it.
|
||||
ui->m_select_all_act->setEnabled(true);
|
||||
ui->m_revert_selection_action->setEnabled(true);
|
||||
|
||||
//Action enabled if a primitive is selected
|
||||
auto select_list = m_depth_action_group->actions();
|
||||
select_list << ui->m_deselect_all_action
|
||||
<< ui->m_cut_action
|
||||
<< ui->m_copy_action
|
||||
select_list << ui->m_cut_action
|
||||
<< ui->m_delete_action
|
||||
<< ui->m_rotate_action
|
||||
<< ui->m_rotateFine_action
|
||||
<< ui->m_flip_action
|
||||
<< ui->m_mirror_action;
|
||||
auto items_selected = !m_read_only && m_elmt_scene->selectedItems().count();
|
||||
const bool has_selection = m_elmt_scene->selectedItems().count() > 0;
|
||||
auto items_selected = !m_read_only && has_selection;
|
||||
for (auto action : std::as_const(select_list)) {
|
||||
action->setEnabled(items_selected);
|
||||
}
|
||||
|
||||
//Copying only reads the element -- ElementScene::copy() serialises the
|
||||
//selection to the clipboard and touches nothing else -- so it is
|
||||
//allowed on a read-only element too. Cut, paste and delete above stay
|
||||
//disabled, so the element itself is still protected.
|
||||
ui->m_copy_action->setEnabled(has_selection);
|
||||
ui->m_deselect_all_action->setEnabled(has_selection);
|
||||
|
||||
//Action about clipboard
|
||||
auto clipboard_contain_elmt = !m_read_only && ElementScene::clipboardMayContainElement();
|
||||
ui->m_paste_action->setEnabled(clipboard_contain_elmt);
|
||||
@@ -1212,7 +1236,18 @@ void QETElementEditor::initGui()
|
||||
//Live cursor position readout, in the same scene coordinates as the parts' X/Y properties
|
||||
m_position_label = new QLabel(this);
|
||||
m_position_label->setMinimumWidth(120);
|
||||
statusBar()->addPermanentWidget(m_position_label);
|
||||
|
||||
// Layout
|
||||
QHBoxLayout *coordDisplayLayout = new QHBoxLayout();
|
||||
coordDisplayLayout->setContentsMargins(0, 0, 0, 0);
|
||||
coordDisplayLayout->addWidget(m_position_label);
|
||||
coordDisplayLayout->addStretch();
|
||||
// Widget
|
||||
QWidget *coordDisplay = new QWidget;
|
||||
coordDisplay->setLayout(coordDisplayLayout);
|
||||
|
||||
statusBar()->addPermanentWidget(coordDisplay);
|
||||
|
||||
connect(m_elmt_scene, &ElementScene::mouseMoved, this, [this](const QPointF &pos) {
|
||||
m_position_label->setText(tr("X: %1 Y: %2")
|
||||
.arg(pos.x(), 0, 'f', 1)
|
||||
|
||||
Reference in New Issue
Block a user