Krita Source Code Documentation
Loading...
Searching...
No Matches
dlg_layersize.cc
Go to the documentation of this file.
1/*
2 * dlg_layersize.cc - part of Krita
3 *
4 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org>
5 * SPDX-FileCopyrightText: 2005 Sven Langkamp <sven.langkamp@gmail.com>
6 * SPDX-FileCopyrightText: 2013 Juan Palacios <jpalaciosdev@gmail.com>
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11#include "dlg_layersize.h"
12
13#include <KoUnit.h>
14#include <kis_config.h>
15
16#include <klocalizedstring.h>
17
19
20#include <kis_filter_strategy.h>// XXX: I'm really real bad at arithmetic, let alone math. Here
21// be rounding errors. (Boudewijn)
22
23const QString DlgLayerSize::PARAM_PREFIX = "layersizedlg";
24
27
30
32
33DlgLayerSize::DlgLayerSize(QWidget * parent, const char * name,
34 int width, int height, double resolution)
35 : KoDialog(parent)
36 , m_aspectRatio(((double) width) / height)
37 , m_originalWidth(width)
38 , m_originalHeight(height)
39 , m_width(width)
40 , m_height(height)
41 , m_resolution(resolution)
42 , m_keepAspect(true)
43{
44 setCaption(i18n("Layer Size"));
45 setObjectName(name);
48
49 m_page = new WdgLayerSize(this);
50 Q_CHECK_PTR(m_page);
51 m_page->layout()->setContentsMargins(0, 0, 0, 0);
52 m_page->setObjectName(name);
53
54 KisConfig cfg(true);
55
58
61
62 m_page->newWidthDouble->setUnitManager(_widthUnitManager);
63 m_page->newHeightDouble->setUnitManager(_heightUnitManager);
64 m_page->newWidthDouble->setDisplayUnit(false);
65 m_page->newHeightDouble->setDisplayUnit(false);
66
67 m_page->newWidthDouble->setValue(width);
68 m_page->newWidthDouble->setFocus();
69 m_page->newHeightDouble->setValue(height);
70
71 m_page->filterCmb->setIDList(KisFilterStrategyRegistry::instance()->listKeys());
72 m_page->filterCmb->setToolTip(KisFilterStrategyRegistry::instance()->formattedDescriptions());
73 m_page->filterCmb->allowAuto(true);
74
75 if (lastUsedFilter) { // Restore or Init..
76 m_page->filterCmb->setCurrent(lastUsedFilter->id());
77 } else {
78 m_page->filterCmb->setCurrent(KisCmbIDList::AutoOptionID);
79 }
80
81 m_page->newWidthUnit->setModel(_widthUnitManager);
82 m_page->newHeightUnit->setModel(_heightUnitManager);
83
84 QString unitw = cfg.readEntry<QString>(PARAM_WIDTH_UNIT, "px");
85 QString unith = cfg.readEntry<QString>(PARAM_HEIGHT_UNIT, "px");
86
89
90 const int wUnitIndex = _widthUnitManager->getsUnitSymbolList().indexOf(unitw);
91 const int hUnitIndex = _widthUnitManager->getsUnitSymbolList().indexOf(unith);
92
93 m_page->newWidthUnit->setCurrentIndex(wUnitIndex);
94 m_page->newHeightUnit->setCurrentIndex(hUnitIndex);
95
97 m_page->aspectRatioBtn->setKeepAspectRatio(m_keepAspect);
98 m_page->constrainProportionsCkb->setChecked(cfg.readEntry(PARAM_KEEP_PROP,true));
99
101 connect(this, SIGNAL(okClicked()), this, SLOT(accept()));
102
103 connect(m_page->aspectRatioBtn, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(slotAspectChanged(bool)));
104 connect(m_page->constrainProportionsCkb, SIGNAL(toggled(bool)), this, SLOT(slotAspectChanged(bool)));
105
106 connect(m_page->newWidthDouble, SIGNAL(valueChangedPt(double)), this, SLOT(slotWidthChanged(double)));
107 connect(m_page->newHeightDouble, SIGNAL(valueChangedPt(double)), this, SLOT(slotHeightChanged(double)));
108
109 connect(m_page->newWidthUnit, SIGNAL(currentIndexChanged(int)), _widthUnitManager, SLOT(selectApparentUnitFromIndex(int)));
110 connect(m_page->newHeightUnit, SIGNAL(currentIndexChanged(int)), _heightUnitManager, SLOT(selectApparentUnitFromIndex(int)));
111 connect(_widthUnitManager, SIGNAL(unitChanged(int)), m_page->newWidthUnit, SLOT(setCurrentIndex(int)));
112 connect(_heightUnitManager, SIGNAL(unitChanged(int)), m_page->newHeightUnit, SLOT(setCurrentIndex(int)));
113
114 connect(this, &DlgLayerSize::sigDesiredSizeChanged, [this](qint32 width, qint32 height, double){
116 m_page->filterCmb->setAutoHint(filterStrategy->name());
117 });
118}
119
121{
122
123 KisConfig cfg(false);
124
125 cfg.writeEntry<bool>(PARAM_KEEP_AR, m_page->aspectRatioBtn->keepAspectRatio());
126 cfg.writeEntry<bool>(PARAM_KEEP_PROP, m_page->constrainProportionsCkb->isChecked());
127
130
131 delete m_page;
132}
133
135{
136 return (qint32)m_width;
137}
138
140{
141 return (qint32)m_height;
142}
143
145{
146 KoID filterID = m_page->filterCmb->currentItem();
147
148 KisFilterStrategy *filter;
149 if (filterID == KisCmbIDList::AutoOptionID) {
151 } else {
152 filter = KisFilterStrategyRegistry::instance()->value(filterID.id());
153 lastUsedFilter = filter; // Save for next time!
154 }
155
156 return filter;
157}
158
159// SLOTS
160
162{
163
164 //this slot receives values in pt from the unitspinbox, so just use the resolution.
166 m_width = qRound(resValue);
167
168 if (m_keepAspect) {
169 m_height = qRound(m_width / m_aspectRatio);
170 m_page->newHeightDouble->blockSignals(true);
171 m_page->newHeightDouble->changeValue(w / m_aspectRatio);
172 m_page->newHeightDouble->blockSignals(false);
173 }
174
176}
177
179{
180
181 //this slot receives values in pt from the unitspinbox, so just use the resolution.
183 m_height = qRound(resValue);
184
185 if (m_keepAspect) {
186 m_width = qRound(m_height * m_aspectRatio);
187 m_page->newWidthDouble->blockSignals(true);
188 m_page->newWidthDouble->changeValue(h * m_aspectRatio);
189 m_page->newWidthDouble->blockSignals(false);
190 }
191
193}
194
196{
197 m_page->aspectRatioBtn->blockSignals(true);
198 m_page->constrainProportionsCkb->blockSignals(true);
199
200 m_page->aspectRatioBtn->setKeepAspectRatio(keep);
201 m_page->constrainProportionsCkb->setChecked(keep);
202
203 m_page->aspectRatioBtn->blockSignals(false);
204 m_page->constrainProportionsCkb->blockSignals(false);
205
206 m_keepAspect = keep;
207
208 if (keep) {
209 // values may be out of sync, so we need to reset it to defaults
212
215 }
216}
217
219{
220 m_page->newWidthDouble->blockSignals(true);
222 m_page->newWidthDouble->changeValue(resValue);
223 m_page->newWidthDouble->blockSignals(false);
224}
225
227{
228 m_page->newHeightDouble->blockSignals(true);
230 m_page->newHeightDouble->changeValue(resValue);
231 m_page->newHeightDouble->blockSignals(false);
232}
233
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void updateHeightUIValue(double value)
KisDocumentAwareSpinBoxUnitManager * _widthUnitManager
qint32 desiredHeight()
static const QString PARAM_WIDTH_UNIT
static const QString PARAM_HEIGHT_UNIT
void slotWidthChanged(double w)
void slotHeightChanged(double h)
~DlgLayerSize() override
static const QString PARAM_PREFIX
const double m_resolution
KisDocumentAwareSpinBoxUnitManager * _heightUnitManager
KisFilterStrategy * filterType()
qint32 desiredWidth()
const int m_originalHeight
const int m_originalWidth
void updateWidthUIValue(double value)
void sigDesiredSizeChanged(qint32 width, qint32 height, double resolution)
const double m_aspectRatio
DlgLayerSize(QWidget *parent, const char *name, int width, int height, double resolution)
void slotAspectChanged(bool keep)
static const QString PARAM_KEEP_PROP
WdgLayerSize * m_page
static const QString PARAM_KEEP_AR
static const KoID AutoOptionID
void writeEntry(const QString &name, const T &value)
Definition kis_config.h:779
T readEntry(const QString &name, const T &defaultValue=T())
Definition kis_config.h:789
The KisDocumentAwareSpinBoxUnitManager class is a KisSpinBoxUnitManager that is able to connect to th...
qreal getConversionFactor(int dim, QString psymbol) const override
static KisFilterStrategyRegistry * instance()
KisFilterStrategy * autoFilterStrategy(QSize originalSize, QSize desiredSize) const
void setApparentUnitFromSymbol(QString pSymbol)
virtual QStringList getsUnitSymbolList(bool withName=false) const
A dialog base class with standard buttons and predefined layouts.
Definition KoDialog.h:116
void setMainWidget(QWidget *widget)
Definition KoDialog.cpp:354
virtual void setCaption(const QString &caption)
Definition KoDialog.cpp:498
void setButtons(ButtonCodes buttonMask)
Definition KoDialog.cpp:195
void setDefaultButton(ButtonCode id)
Definition KoDialog.cpp:302
@ Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
Definition KoDialog.h:127
@ Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
Definition KoDialog.h:130
void okClicked()
const T value(const QString &id) const
Definition KoID.h:30
QString id() const
Definition KoID.cpp:63
static KisFilterStrategy * lastUsedFilter