2011-12-25 17:45:39 +00:00
|
|
|
/*
|
2025-01-04 13:37:40 +01:00
|
|
|
Copyright 2006-2025 The QElectroTech Team
|
2011-12-25 17:45:39 +00:00
|
|
|
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"
|
|
|
|
|
|
|
|
/**
|
|
|
|
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),
|
2012-01-22 14:35:57 +00:00
|
|
|
complete_(complete),
|
|
|
|
read_only_(false)
|
2011-12-25 17:45:39 +00:00
|
|
|
{
|
|
|
|
initWidgets();
|
|
|
|
initLayouts();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
TitleBlockDimensionWidget::~TitleBlockDimensionWidget()
|
|
|
|
{
|
2011-12-25 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return true if this dialog shows the optional radio buttons
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
bool TitleBlockDimensionWidget::isComplete() const
|
|
|
|
{
|
2011-12-25 17:45:39 +00:00
|
|
|
return(complete_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return a pointer to the label displayed right before the spinbox.
|
|
|
|
Useful to specify a custom text.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QLabel *TitleBlockDimensionWidget::label() const
|
|
|
|
{
|
2011-12-25 17:45:39 +00:00
|
|
|
return(spinbox_label_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return a pointer to the spinbox
|
|
|
|
Useful to specify custom parameters, such as the minimum value
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QSpinBox *TitleBlockDimensionWidget::spinbox() const
|
|
|
|
{
|
2011-12-25 17:45:39 +00:00
|
|
|
return(spinbox_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return The dimension as currently shown by the dialog
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
TitleBlockDimension TitleBlockDimensionWidget::value() const
|
|
|
|
{
|
2011-12-25 17:45:39 +00:00
|
|
|
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();
|
2012-05-09 02:31:40 +00:00
|
|
|
spinbox_ -> setValue(dim.value);
|
2011-12-25 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
2012-01-22 14:35:57 +00:00
|
|
|
/**
|
|
|
|
@return Whether or not this widget should allow edition of the displayed
|
|
|
|
dimension.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
bool TitleBlockDimensionWidget::isReadOnly() const
|
|
|
|
{
|
2012-01-22 14:35:57 +00:00
|
|
|
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_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
/**
|
|
|
|
Initialize the widgets composing the dialog.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void TitleBlockDimensionWidget::initWidgets()
|
|
|
|
{
|
2011-12-25 17:45:39 +00:00
|
|
|
// 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_) {
|
2020-09-07 22:03:40 +02:00
|
|
|
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"));
|
2011-12-25 17:45:39 +00:00
|
|
|
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_, SIGNAL(buttonClicked(int)), this, SLOT(updateSpinBoxSuffix()));
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSpinBoxSuffix();
|
|
|
|
|
|
|
|
// buttons, for the user to validate its input
|
|
|
|
buttons_ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
|
|
connect(buttons_, SIGNAL(accepted()), this, SLOT(accept()));
|
|
|
|
connect(buttons_, SIGNAL(rejected()), this, SLOT(reject()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the layout of the dialog.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void TitleBlockDimensionWidget::initLayouts()
|
|
|
|
{
|
2018-07-30 15:24:29 +00:00
|
|
|
QHBoxLayout *hlayout0 = new QHBoxLayout();
|
2011-12-25 17:45:39 +00:00
|
|
|
hlayout0 -> addWidget(spinbox_label_);
|
|
|
|
hlayout0 -> addWidget(spinbox_);
|
2018-07-30 15:24:29 +00:00
|
|
|
QVBoxLayout *vlayout0 = new QVBoxLayout();
|
2011-12-25 17:45:39 +00:00
|
|
|
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.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void TitleBlockDimensionWidget::updateSpinBoxSuffix()
|
|
|
|
{
|
2011-12-25 17:45:39 +00:00
|
|
|
if (complete_ && dimension_type_ -> checkedId() != QET::Absolute) {
|
|
|
|
spinbox_ -> setSuffix(tr("%", "spinbox suffix when changing the dimension of a row/column"));
|
2012-02-27 18:31:47 +00:00
|
|
|
spinbox_ -> setMinimum(1);
|
|
|
|
spinbox_ -> setMaximum(100);
|
2011-12-25 17:45:39 +00:00
|
|
|
} else {
|
|
|
|
spinbox_ -> setSuffix(tr("px", "spinbox suffix when changing the dimension of a row/column"));
|
2012-02-27 18:31:47 +00:00
|
|
|
spinbox_ -> setMinimum(5);
|
|
|
|
spinbox_ -> setMaximum(10000);
|
2011-12-25 17:45:39 +00:00
|
|
|
}
|
|
|
|
spinbox_ -> selectAll();
|
|
|
|
}
|