Changeset View
Changeset View
Standalone View
Standalone View
lib/resize/resizeimagedialog.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
43 | }; | 43 | }; | ||
44 | 44 | | |||
45 | ResizeImageDialog::ResizeImageDialog(QWidget* parent) | 45 | ResizeImageDialog::ResizeImageDialog(QWidget* parent) | ||
46 | : QDialog(parent) | 46 | : QDialog(parent) | ||
47 | , d(new ResizeImageDialogPrivate) | 47 | , d(new ResizeImageDialogPrivate) | ||
48 | { | 48 | { | ||
49 | d->mUpdateFromRatio = false; | 49 | d->mUpdateFromRatio = false; | ||
50 | d->mUpdateFromSizeOrPercentage = false; | 50 | d->mUpdateFromSizeOrPercentage = false; | ||
51 | 51 | | |||
52 | QVBoxLayout *mainLayout = new QVBoxLayout; | 52 | QVBoxLayout *mainLayout = new QVBoxLayout; | ||
huoni: I found the proper (and less cryptic) way to do this:
`mainLayout->setSizeConstraint(QLayout… | |||||
53 | setLayout(mainLayout); | 53 | setLayout(mainLayout); | ||
54 | mainLayout->setSizeConstraint(QLayout::SetFixedSize); | ||||
55 | | ||||
54 | QWidget* content = new QWidget(this); | 56 | QWidget* content = new QWidget(this); | ||
55 | d->setupUi(content); | 57 | d->setupUi(content); | ||
56 | mainLayout->addWidget(content); | 58 | mainLayout->addWidget(content); | ||
57 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); | 59 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); | ||
58 | QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | 60 | QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | ||
59 | okButton->setDefault(true); | 61 | okButton->setDefault(true); | ||
60 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | 62 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | ||
61 | connect(buttonBox, &QDialogButtonBox::accepted, this, &ResizeImageDialog::accept); | 63 | connect(buttonBox, &QDialogButtonBox::accepted, this, &ResizeImageDialog::accept); | ||
Show All 15 Lines | |||||
77 | ResizeImageDialog::~ResizeImageDialog() | 79 | ResizeImageDialog::~ResizeImageDialog() | ||
78 | { | 80 | { | ||
79 | delete d; | 81 | delete d; | ||
80 | } | 82 | } | ||
81 | 83 | | |||
82 | void ResizeImageDialog::setOriginalSize(const QSize& size) | 84 | void ResizeImageDialog::setOriginalSize(const QSize& size) | ||
83 | { | 85 | { | ||
84 | d->mOriginalSize = size; | 86 | d->mOriginalSize = size; | ||
85 | d->mOriginalWidthLabel->setText(QString::number(size.width())); | 87 | d->mOriginalWidthLabel->setText(QString::number(size.width()) + QStringLiteral(" px")); | ||
86 | d->mOriginalHeightLabel->setText(QString::number(size.height())); | 88 | d->mOriginalHeightLabel->setText(QString::number(size.height()) + QStringLiteral(" px")); | ||
87 | d->mWidthSpinBox->setValue(size.width()); | 89 | d->mWidthSpinBox->setValue(size.width()); | ||
88 | d->mHeightSpinBox->setValue(size.height()); | 90 | d->mHeightSpinBox->setValue(size.height()); | ||
89 | } | 91 | } | ||
90 | 92 | | |||
91 | QSize ResizeImageDialog::size() const | 93 | QSize ResizeImageDialog::size() const | ||
92 | { | 94 | { | ||
93 | return QSize( | 95 | return QSize( | ||
94 | d->mWidthSpinBox->value(), | 96 | d->mWidthSpinBox->value(), | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | |||||
156 | void ResizeImageDialog::slotHeightPercentChanged(double heightPercent) | 158 | void ResizeImageDialog::slotHeightPercentChanged(double heightPercent) | ||
157 | { | 159 | { | ||
158 | // Update height to match height percentage, only if this was a manual adjustment | 160 | // Update height to match height percentage, only if this was a manual adjustment | ||
159 | if (!d->mUpdateFromSizeOrPercentage && !d->mUpdateFromRatio) { | 161 | if (!d->mUpdateFromSizeOrPercentage && !d->mUpdateFromRatio) { | ||
160 | d->mUpdateFromSizeOrPercentage = true; | 162 | d->mUpdateFromSizeOrPercentage = true; | ||
161 | d->mHeightSpinBox->setValue((heightPercent / 100) * d->mOriginalSize.height()); | 163 | d->mHeightSpinBox->setValue((heightPercent / 100) * d->mOriginalSize.height()); | ||
162 | d->mUpdateFromSizeOrPercentage = false; | 164 | d->mUpdateFromSizeOrPercentage = false; | ||
163 | } | 165 | } | ||
164 | 166 | | |||
165 | if (!d->mKeepAspectCheckBox->isChecked() || d->mUpdateFromRatio) { | 167 | if (!d->mKeepAspectCheckBox->isChecked() || d->mUpdateFromRatio) { | ||
166 | return; | 168 | return; | ||
167 | } | 169 | } | ||
168 | 170 | | |||
169 | // Keep height percentage in sync with width percentage, only if ratio locked and this was a manual adjustment | 171 | // Keep height percentage in sync with width percentage, only if ratio locked and this was a manual adjustment | ||
170 | d->mUpdateFromRatio = true; | 172 | d->mUpdateFromRatio = true; | ||
171 | d->mWidthPercentSpinBox->setValue(d->mHeightPercentSpinBox->value()); | 173 | d->mWidthPercentSpinBox->setValue(d->mHeightPercentSpinBox->value()); | ||
172 | d->mUpdateFromRatio = false; | 174 | d->mUpdateFromRatio = false; | ||
Now that the GUI disables the Height Percentage when the aspect ratio is locked, this code is not needed. huoni: Now that the GUI disables the Height Percentage when the aspect ratio is locked, this code is… | |||||
Are you sure? As far as I can see this would break updating the width percentage when changing the pixel height. rkflx: Are you sure? As far as I can see this would break updating the width percentage when changing… | |||||
You're right (without testing to make sure). These Boolean guards are so confusing I confused myself! huoni: You're right (without testing to make sure). These Boolean guards are so confusing I confused… | |||||
Yeah, it is confusing. I spent a lot of time today trying to improve readability by using QSignalBlocker, but while this worked in 95% of the cases, ultimately I failed at that. Let's not touch it and hope it will just work now… rkflx: Yeah, it is confusing. I spent a lot of time today trying to improve readability by using… | |||||
173 | } | 175 | } | ||
174 | 176 | | |||
175 | void ResizeImageDialog::slotKeepAspectChanged(bool value) | 177 | void ResizeImageDialog::slotKeepAspectChanged(bool value) | ||
176 | { | 178 | { | ||
177 | if (value) { | 179 | if (value) { | ||
178 | d->mUpdateFromSizeOrPercentage = true; | 180 | d->mUpdateFromSizeOrPercentage = true; | ||
179 | slotWidthChanged(d->mWidthSpinBox->value()); | 181 | slotWidthChanged(d->mWidthSpinBox->value()); | ||
180 | slotWidthPercentChanged(d->mWidthPercentSpinBox->value()); | 182 | slotWidthPercentChanged(d->mWidthPercentSpinBox->value()); | ||
181 | d->mUpdateFromSizeOrPercentage = false; | 183 | d->mUpdateFromSizeOrPercentage = false; | ||
182 | } | 184 | } | ||
183 | } | 185 | } | ||
184 | 186 | | |||
185 | } // namespace | 187 | } // namespace |
I found the proper (and less cryptic) way to do this:
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
From the docs, QLayout::SetFixedSize means: