Krita Source Code Documentation
Loading...
Searching...
No Matches
KisWdgOptionsHeightmap Class Reference

#include <kis_wdg_options_heightmap.h>

+ Inheritance diagram for KisWdgOptionsHeightmap:

Signals

void statusUpdated (bool status)
 
- Signals inherited from KisConfigWidget
void sigConfigurationItemChanged ()
 
void sigConfigurationUpdated ()
 
void sigDropLockedConfig (KisPropertiesConfigurationSP p)
 
void sigSaveLockedConfig (KisPropertiesConfigurationSP p)
 

Public Member Functions

 KisWdgOptionsHeightmap (QWidget *parent)
 
 KisWdgOptionsHeightmap (QWidget *parent, bool export_mode)
 
- Public Member Functions inherited from KisConfigWidget
virtual KoCanvasResourcesInterfaceSP canvasResourcesInterface () const
 
virtual void setCanvasResourcesInterface (KoCanvasResourcesInterfaceSP canvasResourcesInterface)
 
virtual void setView (KisViewManager *view)
 
 ~KisConfigWidget () override
 

Protected Member Functions

KisPropertiesConfigurationSP configuration () const override
 
void setConfiguration (const KisPropertiesConfigurationSP cfg) override
 
void showEvent (QShowEvent *event) override
 
- Protected Member Functions inherited from KisConfigWidget
 KisConfigWidget (QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags(), int delay=200)
 

Private Slots

void guessDimensions ()
 
void heightChanged (int i)
 
void widthChanged (int i)
 

Private Member Functions

void updateStatus ()
 

Private Attributes

bool m_exportMode
 

Detailed Description

Definition at line 13 of file kis_wdg_options_heightmap.h.

Constructor & Destructor Documentation

◆ KisWdgOptionsHeightmap() [1/2]

KisWdgOptionsHeightmap::KisWdgOptionsHeightmap ( QWidget * parent)
explicit

Definition at line 30 of file kis_wdg_options_heightmap.cpp.

31 : KisWdgOptionsHeightmap(parent, false)
32{
33}

◆ KisWdgOptionsHeightmap() [2/2]

KisWdgOptionsHeightmap::KisWdgOptionsHeightmap ( QWidget * parent,
bool export_mode )
explicit

Definition at line 35 of file kis_wdg_options_heightmap.cpp.

36 : KisConfigWidget(parent)
37 , m_exportMode(export_mode)
38{
39 setupUi(this);
40
41 if (m_exportMode) {
42 dimensionsGroupBox->setVisible(false);
43 fileSizeDescLabel->setVisible(false);
44 fileSizeLabel->setVisible(false);
45 bppDescLabel->setVisible(false);
46 bppLabel->setVisible(false);
47 }
48 else {
49 connect(guessButton, SIGNAL(clicked(bool)), this, SLOT(guessDimensions()));
50 connect(widthInput, SIGNAL(valueChanged(int)), this, SLOT(widthChanged(int)));
51 connect(heightInput, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int)));
52 }
53}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisConfigWidget(QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags(), int delay=200)

References connect(), guessDimensions(), heightChanged(), m_exportMode, and widthChanged().

Member Function Documentation

◆ configuration()

KisPropertiesConfigurationSP KisWdgOptionsHeightmap::configuration ( ) const
overrideprotectedvirtual
Returns
the configuration

Implements KisConfigWidget.

Definition at line 66 of file kis_wdg_options_heightmap.cpp.

67{
69 if (radioBig->isChecked()) {
70 cfg->setProperty("endianness", 0);
71 }
72 else {
73 cfg->setProperty("endianness", 1);
74 }
75 return cfg;
76}

◆ guessDimensions

void KisWdgOptionsHeightmap::guessDimensions ( )
privateslot

Definition at line 140 of file kis_wdg_options_heightmap.cpp.

141{
142 quint32 w = widthInput->value();
143 quint32 h = heightInput->value();
144
145 bool ok;
146 quint32 fileSize = fileSizeLabel->text().toUInt(&ok);
148
149 quint32 depth = bppLabel->text().toUInt(&ok);
151
152 quint32 bytesPerPixel = depth / 8;
153
154 w = widthInput->text().toUInt(&ok);
156
157 h = heightInput->text().toUInt(&ok);
159
160 quint32 dimensions = fileSize / bytesPerPixel;
161
162 if (w > 0 && h > 0) {
163 if (w * h == dimensions) {
164 // toggle landscape/portrait orientation
165 widthInput->setValue(h);
166 heightInput->setValue(w);
167 }
168 }
169 else if (w == 0 && h == 0) {
170 quint32 r = (quint32)(qFloor(qSqrt(dimensions) + 0.5));
171
172 // First guess, square image?
173 if (r*r == dimensions) {
174 widthInput->setValue(r);
175 heightInput->setValue(r);
176 }
177 else {
178 // second guess, power of two?
179 w = prevPow2(r);
180 h = dimensions / w + (dimensions % w);
181 if (w * h != dimensions) {
182 showErrorTooltip(i18n("Too many possible combinations. Input a width or height and try again."));
183 return;
184 }
185
186 // prefer landscape orientation
187 widthInput->setValue(w > h ? w : h);
188 heightInput->setValue(w > h ? h : w);
189
190 // TODO: cycle through other pow2 combinations if called multiple times?
191 }
192 }
193 else if (w > 0) {
194 if (w > dimensions) {
195 showErrorTooltip(i18n("Width exceeds available pixels."));
196 return;
197 }
198 h = dimensions / w + (dimensions % w);
199 if (w * h != dimensions) {
200 showErrorTooltip(i18n("Unable to calculate an appropriate height. File does not contain enough pixels to form a rectangle."));
201 return;
202 }
203 heightInput->setValue(h);
204 }
205 else {
206 if (h > dimensions) {
207 showErrorTooltip(i18n("Height exceeds available pixels."));
208 return;
209 }
210 w = dimensions / h + (dimensions % h);
211 if (w * h != dimensions) {
212 showErrorTooltip(i18n("Unable to calculate an appropriate width. File does not contain enough pixels to form a rectangle."));
213 return;
214 }
215 widthInput->setValue(w);
216 }
217}
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
static void showErrorTooltip(const QString &msg)
static constexpr quint32 prevPow2(quint32 n)
int depth(typename Forest< T >::const_child_iterator beginIt, typename Forest< T >::const_child_iterator endIt)
Definition KisForest.h:1213

References KIS_ASSERT_RECOVER_RETURN, prevPow2(), and showErrorTooltip().

◆ heightChanged

void KisWdgOptionsHeightmap::heightChanged ( int i)
privateslot

Definition at line 134 of file kis_wdg_options_heightmap.cpp.

135{
136 Q_UNUSED(i);
137 updateStatus();
138}

References updateStatus().

◆ setConfiguration()

void KisWdgOptionsHeightmap::setConfiguration ( const KisPropertiesConfigurationSP config)
overrideprotectedvirtual
Parameters
configthe configuration for this configuration widget.

Implements KisConfigWidget.

Definition at line 55 of file kis_wdg_options_heightmap.cpp.

56{
57 int endianness = cfg->getInt("endianness", 1);
58 if (endianness == 0) {
59 radioBig->setChecked(true);
60 }
61 else {
62 radioLittle->setChecked(true);
63 }
64}

◆ showEvent()

void KisWdgOptionsHeightmap::showEvent ( QShowEvent * event)
overrideprotected

Definition at line 78 of file kis_wdg_options_heightmap.cpp.

79{
81 QWidget::showEvent(event);
82}

References updateStatus().

◆ statusUpdated

void KisWdgOptionsHeightmap::statusUpdated ( bool status)
signal

◆ updateStatus()

void KisWdgOptionsHeightmap::updateStatus ( )
private

Definition at line 84 of file kis_wdg_options_heightmap.cpp.

85{
86 if (m_exportMode)
87 return;
88 bool ok;
89 int fileSize = fileSizeLabel->text().toInt(&ok);
91 KIS_ASSERT_RECOVER_RETURN(fileSize > 0);
92 int w = widthInput->value();
93 int h = heightInput->value();
94
95 quint32 depth = bppLabel->text().toUInt(&ok);
97
98 QString old_status = statusLabel->text();
99
100 int bytesPerPixel = depth / 8;
101 int dataSize = w * h * bytesPerPixel;
102
103 bool status_ok = false;
104
105 QString fileMismatch = i18n("Input does not match file size");
106 if (w == 0 && h == 0) {
107 statusLabel->setText(i18n("Please specify width and height"));
108 }
109 else if (w == 0) {
110 statusLabel->setText(i18n("Please specify width"));
111 }
112 else if (h == 0) {
113 statusLabel->setText(i18n("Please specify height"));
114 }
115 else if (dataSize != fileSize) {
116 statusLabel->setText(fileMismatch);
117 }
118 else {
119 statusLabel->setText("");
120 status_ok = true;
121 }
122
123 if (old_status.compare(statusLabel->text()) != 0) {
124 Q_EMIT statusUpdated(status_ok);
125 }
126}
void statusUpdated(bool status)

References KIS_ASSERT_RECOVER_RETURN, m_exportMode, and statusUpdated().

◆ widthChanged

void KisWdgOptionsHeightmap::widthChanged ( int i)
privateslot

Definition at line 128 of file kis_wdg_options_heightmap.cpp.

129{
130 Q_UNUSED(i);
131 updateStatus();
132}

References updateStatus().

Member Data Documentation

◆ m_exportMode

bool KisWdgOptionsHeightmap::m_exportMode
private

Definition at line 36 of file kis_wdg_options_heightmap.h.


The documentation for this class was generated from the following files: