Files
qelectrotech-source-mirror/sources/titleblock/dimensionwidget.cpp
T
ispyisail f5962ecd06 Make English the source language of the interface text
Every tr() source string in the code and the forms is now the English
text, and French is a translation (qet_fr.ts) like the other languages.
Generated, not hand-edited: master ef795a21e5 converted by
qet-en-source (harness 4c4ddc9).

3144 messages get an English source, 665 already had one, 0 left French; 8 shared-wording pairs disambiguated.
C++: 2904 literals in 233 files. Forms: 809 strings in 65 files. All 34 .ts files re-keyed; qet_fr.ts filled.
lupdate check: PASS. What each of 38 languages shows, old vs new: same 118266, English instead of French 38433, comment fallback 51, differences 0.
2026-10-08 12:50:13 +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("Width:", "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("Absolute",
"a traditional, absolute measure"));
relative_button_ = new QRadioButton(
tr("Relative to total",
"a percentage of the total width"));
remaining_button_ = new QRadioButton(
tr("Relative to remaining",
"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();
}