Files
qelectrotech-source-mirror/sources/titleblock/dimensionwidget.cpp
T
ispyisail a28e834185 Remember dialog size and position across sessions
QETElementEditor, QETDiagramEditor and QETTemplateEditor already
persist their geometry via QSettings; none of the modal QDialog
subclasses did, so any dialog resized to see more of its content
(Search and Replace, Diagram properties, Export, ...) is back to its
default size the next time it's opened.

Adds QET::trackDialogGeometry(), one call at the end of each dialog
constructor (after any default resize()), following the same
restoreGeometry()/saveGeometry() pattern as the three editors above,
stored under [dialoggeometry] and keyed by class name by default. An
explicit key is used for PropertiesEditorDialog, a single class
templated over several unrelated wrapped editors, so they don't all
fight over one saved size.

Covers the 36 dialogs of the original change (#691) plus seven added
since: RenumberElementsDialog, MaterialEntryDialog, AiAssistantDialog,
DuplicateOffsetDialog, ImageTransparentColorDialog, PdfPagesDialog and
WiringListDialog.

Deliberately not touched: BackupDialog and ImageCropDialog, which
setFixedSize() themselves, and MaterialSelectionDialog, which already
restores its own size.

A size saved while the dialog sat partly off-screen is restored on
screen: restoreGeometry() moves it back inside the available screen
(checked: saved at 1502,972 on a 1600x1000 screen, reopened at 600,317).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 10:31:12 +13:00

195 lines
5.6 KiB
C++

/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dimensionwidget.h"
#include "../qet.h"
/**
Constructor
@param complete True for this dialog to show the radio buttons that allow
the user to specify whether the dimension is absolute, relative to the
total width or relative to the remaining width.
@param parent Parent QWidget
*/
TitleBlockDimensionWidget::TitleBlockDimensionWidget(bool complete, QWidget *parent) :
QDialog(parent),
complete_(complete),
read_only_(false)
{
initWidgets();
initLayouts();
QET::trackDialogGeometry(this);
}
/**
Destructor
*/
TitleBlockDimensionWidget::~TitleBlockDimensionWidget()
{
}
/**
@return true if this dialog shows the optional radio buttons
*/
bool TitleBlockDimensionWidget::isComplete() const
{
return(complete_);
}
/**
@return a pointer to the label displayed right before the spinbox.
Useful to specify a custom text.
*/
QLabel *TitleBlockDimensionWidget::label() const
{
return(spinbox_label_);
}
/**
@return a pointer to the spinbox
Useful to specify custom parameters, such as the minimum value
*/
QSpinBox *TitleBlockDimensionWidget::spinbox() const
{
return(spinbox_);
}
/**
@return The dimension as currently shown by the dialog
*/
TitleBlockDimension TitleBlockDimensionWidget::value() const
{
QET::TitleBlockColumnLength type = QET::Absolute;
if (complete_) {
type = static_cast<QET::TitleBlockColumnLength>(dimension_type_ -> checkedId());
}
return(TitleBlockDimension(spinbox_ -> value(), type));
}
/**
@param dim Dimension to be displayed and edited by this dialog
*/
void TitleBlockDimensionWidget::setValue(const TitleBlockDimension &dim) {
if (complete_) {
if (QAbstractButton *button = dimension_type_ -> button(dim.type)) {
button -> setChecked(true);
}
}
updateSpinBoxSuffix();
spinbox_ -> setValue(dim.value);
}
/**
@return Whether or not this widget should allow edition of the displayed
dimension.
*/
bool TitleBlockDimensionWidget::isReadOnly() const
{
return(read_only_);
}
/**
@param read_only Whether or not this widget should allow edition of the
displayed dimension.
*/
void TitleBlockDimensionWidget::setReadOnly(bool read_only) {
if (read_only_ == read_only) return;
read_only_ = read_only;
spinbox_ -> setReadOnly(read_only_);
if (complete_) {
absolute_button_ -> setEnabled(!read_only_);
relative_button_ -> setEnabled(!read_only_);
remaining_button_ -> setEnabled(!read_only_);
}
}
/**
Initialize the widgets composing the dialog.
*/
void TitleBlockDimensionWidget::initWidgets()
{
// basic widgets: label + spinbox
spinbox_label_ = new QLabel(tr("Largeur :", "default dialog label"));
spinbox_ = new QSpinBox();
spinbox_ -> setValue(50);
// extra widgets, for the user to specify whether the value is absolute, relative, etc.
if (complete_) {
absolute_button_ = new QRadioButton(
tr("Absolu",
"a traditional, absolute measure"));
relative_button_ = new QRadioButton(
tr("Relatif au total",
"a percentage of the total width"));
remaining_button_ = new QRadioButton(
tr("Relatif au restant",
"a percentage of what remains from the total width"));
dimension_type_ = new QButtonGroup(this);
dimension_type_ -> addButton(absolute_button_, QET::Absolute);
dimension_type_ -> addButton(relative_button_, QET::RelativeToTotalLength);
dimension_type_ -> addButton(remaining_button_, QET::RelativeToRemainingLength);
absolute_button_ -> setChecked(true);
connect(dimension_type_, qOverload<QAbstractButton*>(&QButtonGroup::buttonClicked), this, &TitleBlockDimensionWidget::updateSpinBoxSuffix);
}
updateSpinBoxSuffix();
// buttons, for the user to validate its input
buttons_ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttons_, &QDialogButtonBox::accepted, this, &TitleBlockDimensionWidget::accept);
connect(buttons_, &QDialogButtonBox::rejected, this, &TitleBlockDimensionWidget::reject);
}
/**
Initialize the layout of the dialog.
*/
void TitleBlockDimensionWidget::initLayouts()
{
QHBoxLayout *hlayout0 = new QHBoxLayout();
hlayout0 -> addWidget(spinbox_label_);
hlayout0 -> addWidget(spinbox_);
QVBoxLayout *vlayout0 = new QVBoxLayout();
vlayout0 -> addLayout(hlayout0);
if (complete_) {
vlayout0 -> addWidget(absolute_button_);
vlayout0 -> addWidget(relative_button_);
vlayout0 -> addWidget(remaining_button_);
}
vlayout0 -> addWidget(buttons_);
setLayout(vlayout0);
}
/**
Ensure the suffix displayed by the spinbox matches the selected kind of length.
*/
void TitleBlockDimensionWidget::updateSpinBoxSuffix()
{
if (complete_ && dimension_type_ -> checkedId() != QET::Absolute) {
spinbox_ -> setSuffix(tr("%", "spinbox suffix when changing the dimension of a row/column"));
spinbox_ -> setMinimum(1);
spinbox_ -> setMaximum(100);
} else {
spinbox_ -> setSuffix(tr("px", "spinbox suffix when changing the dimension of a row/column"));
spinbox_ -> setMinimum(5);
spinbox_ -> setMaximum(10000);
}
spinbox_ -> selectAll();
}