mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-14 20:33:05 +02:00
150 lines
4.6 KiB
C++
150 lines
4.6 KiB
C++
|
/*
|
||
|
Copyright 2006-2011 Xavier Guerrin
|
||
|
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),
|
||
|
complete_(complete)
|
||
|
{
|
||
|
initWidgets();
|
||
|
initLayouts();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
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) {
|
||
|
spinbox_ -> setValue(dim.value);
|
||
|
if (complete_) {
|
||
|
if (QAbstractButton *button = dimension_type_ -> button(dim.type)) {
|
||
|
button -> setChecked(true);
|
||
|
}
|
||
|
}
|
||
|
updateSpinBoxSuffix();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
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_ -> setMinimum(5);
|
||
|
spinbox_ -> setMaximum(10000);
|
||
|
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"));
|
||
|
relative_button_ = new QRadioButton(tr("Relatif au total"));
|
||
|
remaining_button_ = new QRadioButton(tr("Relatif au restant"));
|
||
|
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.
|
||
|
*/
|
||
|
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"));
|
||
|
} else {
|
||
|
spinbox_ -> setSuffix(tr("px", "spinbox suffix when changing the dimension of a row/column"));
|
||
|
}
|
||
|
spinbox_ -> selectAll();
|
||
|
}
|