QElectroTech  0.70
dimensionwidget.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "dimensionwidget.h"
19 
28  QDialog(parent),
29  complete_(complete),
30  read_only_(false)
31 {
32  initWidgets();
33  initLayouts();
34 }
35 
40 }
41 
46  return(complete_);
47 }
48 
54  return(spinbox_label_);
55 }
56 
62  return(spinbox_);
63 }
64 
70  if (complete_) {
71  type = static_cast<QET::TitleBlockColumnLength>(dimension_type_ -> checkedId());
72  }
73  return(TitleBlockDimension(spinbox_ -> value(), type));
74 }
75 
80  if (complete_) {
81  if (QAbstractButton *button = dimension_type_ -> button(dim.type)) {
82  button -> setChecked(true);
83  }
84  }
86  spinbox_ -> setValue(dim.value);
87 }
88 
94  return(read_only_);
95 }
96 
102  if (read_only_ == read_only) return;
103  read_only_ = read_only;
104 
106  if (complete_) {
107  absolute_button_ -> setEnabled(!read_only_);
108  relative_button_ -> setEnabled(!read_only_);
109  remaining_button_ -> setEnabled(!read_only_);
110  }
111 }
112 
117  // basic widgets: label + spinbox
118  spinbox_label_ = new QLabel(tr("Largeur :", "default dialog label"));
119 
120  spinbox_ = new QSpinBox();
121  spinbox_ -> setValue(50);
122 
123  // extra widgets, for the user to specify whether the value is absolute, relative, etc.
124  if (complete_) {
125  absolute_button_ = new QRadioButton(tr("Absolu", "a traditional, absolute measure"));
126  relative_button_ = new QRadioButton(tr("Relatif au total", "a percentage of the total width"));
127  remaining_button_ = new QRadioButton(tr("Relatif au restant", "a percentage of what remains from the total width"));
128  dimension_type_ = new QButtonGroup(this);
132  absolute_button_ -> setChecked(true);
133  connect(dimension_type_, SIGNAL(buttonClicked(int)), this, SLOT(updateSpinBoxSuffix()));
134  }
135 
137 
138  // buttons, for the user to validate its input
139  buttons_ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
140  connect(buttons_, SIGNAL(accepted()), this, SLOT(accept()));
141  connect(buttons_, SIGNAL(rejected()), this, SLOT(reject()));
142 }
143 
148  QHBoxLayout *hlayout0 = new QHBoxLayout();
149  hlayout0 -> addWidget(spinbox_label_);
150  hlayout0 -> addWidget(spinbox_);
151  QVBoxLayout *vlayout0 = new QVBoxLayout();
152  vlayout0 -> addLayout(hlayout0);
153  if (complete_) {
154  vlayout0 -> addWidget(absolute_button_);
155  vlayout0 -> addWidget(relative_button_);
156  vlayout0 -> addWidget(remaining_button_);
157  }
158  vlayout0 -> addWidget(buttons_);
159  setLayout(vlayout0);
160 }
161 
166  if (complete_ && dimension_type_ -> checkedId() != QET::Absolute) {
167  spinbox_ -> setSuffix(tr("%", "spinbox suffix when changing the dimension of a row/column"));
168  spinbox_ -> setMinimum(1);
169  spinbox_ -> setMaximum(100);
170  } else {
171  spinbox_ -> setSuffix(tr("px", "spinbox suffix when changing the dimension of a row/column"));
172  spinbox_ -> setMinimum(5);
173  spinbox_ -> setMaximum(10000);
174  }
175  spinbox_ -> selectAll();
176 }
the length is just a fraction of the length that is still available when other types of lengths have ...
Definition: qet.h:146
QLabel * spinbox_label_
Label shown right before the spinbox.
the length is absolute and should be applied as is
Definition: qet.h:144
TitleBlockColumnLength
enum used to specify the type of a length
Definition: qet.h:143
int value
Numeric value.
Definition: dimension.h:34
TitleBlockDimension value() const
bool read_only_
Whether or not this widget allow edition of the displayed dimension.
QSpinBox * spinbox_
Spinbox displaying the length.
QSpinBox * spinbox() const
void setValue(const TitleBlockDimension &)
the length is just a fraction of the total available length
Definition: qet.h:145
QIcon tr
Definition: qeticons.cpp:204
QRadioButton * relative_button_
Radio button to indicate the length is relative to the total length.
TitleBlockDimensionWidget(bool, QWidget *parent=nullptr)
QRadioButton * absolute_button_
Radio button to indicate the length is absolute.
bool complete_
Whether or not this dialog is required to be complete, i.e. displaying also.
QDialogButtonBox * buttons_
Buttons to validate the dialog.
QIcon Cancel
Definition: qeticons.cpp:34
QRadioButton * remaining_button_
Radio button to indicate the length is relative to the remaining length.
QET::TitleBlockColumnLength type
Kind of length.
Definition: dimension.h:33
QButtonGroup * dimension_type_
QButtonGroup for the three radio buttons.