1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
/* This file is part of the KDE project
Copyright (C) 1998-2002 Carsten Pfeiffer <pfeiffer@kde.org>
This program 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, version 2.
This program 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 this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qvgroupbox.h>
#include <kcombobox.h>
#include <kdialog.h>
#include <klocale.h>
#include <knuminput.h>
#include <kstandarddirs.h>
#include "imlibwidget.h"
#include "defaultswidget.h"
DefaultsWidget::DefaultsWidget( QWidget *parent, const char *name)
: QWidget( parent, name )
{
imFiltered = 0L;
cbEnableMods = new QCheckBox( i18n("Apply default image modifications"), this );
connect( cbEnableMods, SIGNAL( toggled(bool) ), SLOT( enableWidgets(bool) ));
// create all the widgets
gbScale = new QGroupBox( i18n("Scaling"), this );
gbScale->setColumnLayout( 0, Qt::Horizontal );
cbDownScale = new QCheckBox( i18n("Shrink image to screen size, if larger"),
gbScale, "shrinktoscreen" );
cbUpScale = new QCheckBox( i18n("Scale image to screen size, if smaller, up to factor:"), gbScale, "upscale checkbox" );
sbMaxUpScaleFactor = new KIntNumInput( gbScale, "upscale factor" );
sbMaxUpScaleFactor->setRange( 1, 100, 1, false );
connect(cbUpScale, SIGNAL( toggled(bool)), sbMaxUpScaleFactor,
SLOT( setEnabled(bool) ));
// --
gbGeometry = new QGroupBox( i18n("Geometry"), this );
gbGeometry->setColumnLayout( 0, Qt::Horizontal );
cbFlipVertically = new QCheckBox( i18n("Flip vertically"), gbGeometry );
cbFlipHorizontally = new QCheckBox( i18n("Flip horizontally"), gbGeometry );
lbRotate = new QLabel( i18n("Rotate image:"), gbGeometry );
comboRotate = new KComboBox( gbGeometry, "rotate combobox" );
comboRotate->insertItem( i18n("0 Degrees") );
comboRotate->insertItem( i18n("90 Degrees") );
comboRotate->insertItem( i18n("180 Degrees") );
comboRotate->insertItem( i18n("270 Degrees") );
// --
gbAdjust = new QVGroupBox( i18n("Adjustments"), this );
sbBrightness = new KIntNumInput( gbAdjust, "brightness spinbox" );
sbBrightness->setRange( -256, 256, 1, true );
sbBrightness->setLabel( i18n("Brightness:"), AlignVCenter );
sbContrast = new KIntNumInput( sbBrightness, 0,gbAdjust, 10,
"contrast spinbox");
sbContrast->setRange( -256, 256, 1, true );
sbContrast->setLabel( i18n("Contrast:"), AlignVCenter );
sbGamma = new KIntNumInput( sbContrast, 0, gbAdjust, 10, "gamma spinbox" );
sbGamma->setRange( -256, 256, 1, true );
sbGamma->setLabel( i18n("Gamma:"), AlignVCenter );
// --
gbPreview = new QGroupBox( i18n("Preview"), this );
gbPreview->setAlignment( AlignCenter );
lbImOrig = new QLabel( i18n("Original"), gbPreview );
imOrig = new ImlibWidget( 0L, gbPreview, "original image" );
lbImFiltered = new QLabel( i18n("Modified"), gbPreview );
imFiltered = new ImlibWidget( 0L, imOrig->getImlibData(), gbPreview, "" );
connect( imFiltered, SIGNAL( destroyed() ), SLOT( slotNoImage() ));
////
////////////////
// layout management
QVBoxLayout *mainLayout = new QVBoxLayout( this, 0,
KDialog::spacingHint(), "main layout" );
QVBoxLayout *gbScaleLayout = new QVBoxLayout( gbScale->layout(),
KDialog::spacingHint());
QVBoxLayout *gbGeometryLayout = new QVBoxLayout(gbGeometry->layout(),
KDialog::spacingHint());
QGridLayout *gbPreviewLayout = new QGridLayout(gbPreview, 2, 3, 0,
KDialog::spacingHint());
QHBoxLayout *scaleLayout = new QHBoxLayout();
QHBoxLayout *rotateLayout = new QHBoxLayout();
mainLayout->addWidget( cbEnableMods );
mainLayout->addWidget( gbScale );
QHBoxLayout *hl = new QHBoxLayout();
hl->addWidget( gbGeometry );
hl->addWidget( gbAdjust );
mainLayout->addLayout( hl );
mainLayout->addWidget( gbPreview );
mainLayout->addStretch();
// --
gbScaleLayout->addWidget( cbDownScale );
gbScaleLayout->addLayout( scaleLayout );
scaleLayout->addWidget( cbUpScale );
scaleLayout->addWidget( sbMaxUpScaleFactor );
// --
gbGeometryLayout->addWidget( cbFlipVertically, 0, AlignLeft );
gbGeometryLayout->addWidget( cbFlipHorizontally, 0, AlignLeft );
gbGeometryLayout->addLayout( rotateLayout, 0 );
rotateLayout->addWidget( lbRotate, 0, AlignLeft );
rotateLayout->addWidget( comboRotate, 0, AlignLeft );
// --
gbPreviewLayout->setMargin( 10 );
gbPreviewLayout->setSpacing( KDialog::spacingHint() );
gbPreviewLayout->addWidget( lbImOrig, 0, 0, AlignCenter );
gbPreviewLayout->addWidget( imOrig, 1, 0, AlignCenter | AlignTop );
gbPreviewLayout->addWidget( lbImFiltered, 0, 2, AlignCenter );
gbPreviewLayout->addWidget( imFiltered, 1, 2, AlignCenter | AlignTop );
////
////////////////
// connect them all to the update slot
connect( cbDownScale, SIGNAL( clicked() ), SLOT( updatePreview() ));
connect( cbUpScale, SIGNAL( clicked() ), SLOT( updatePreview() ));
connect( cbFlipVertically, SIGNAL( clicked() ), SLOT( updatePreview() ));
connect( cbFlipHorizontally, SIGNAL( clicked() ), SLOT( updatePreview() ));
connect( sbMaxUpScaleFactor, SIGNAL( valueChanged(int) ), SLOT( updatePreview() ));
connect( sbBrightness, SIGNAL( valueChanged(int) ), SLOT( updatePreview() ));
connect( sbContrast, SIGNAL( valueChanged(int) ), SLOT( updatePreview() ));
connect( sbGamma, SIGNAL( valueChanged(int) ), SLOT( updatePreview() ));
connect( comboRotate, SIGNAL( activated(int) ), SLOT( updatePreview() ));
QString filename = locate( "data", "kuickshow/pics/calibrate.png" );
if ( !imOrig->loadImage( filename ) )
imOrig = 0L; // FIXME - display some errormessage!
if ( !imFiltered->loadImage( filename ) )
imFiltered = 0L; // FIXME - display some errormessage!
loadSettings( *kdata );
if ( imOrig )
imOrig->setFixedSize( imOrig->size() );
if ( imFiltered )
imFiltered->setFixedSize( imFiltered->size() );
mainLayout->activate();
}
DefaultsWidget::~DefaultsWidget()
{
// those need to be deleted in the right order, as imFiltered
// references ImlibData from imOrig
delete imFiltered;
delete imOrig;
}
void DefaultsWidget::loadSettings( const KuickData& data )
{
cbDownScale->setChecked( data.downScale );
cbUpScale->setChecked( data.upScale );
sbMaxUpScaleFactor->setValue( data.maxUpScale );
cbFlipVertically->setChecked( data.flipVertically );
cbFlipHorizontally->setChecked( data.flipHorizontally );
comboRotate->setCurrentItem( data.rotation );
ImData *id = data.idata;
sbBrightness->setValue( id->brightness );
sbContrast->setValue( id->contrast );
sbGamma->setValue( id->gamma );
cbEnableMods->setChecked( data.isModsEnabled );
enableWidgets( data.isModsEnabled );
updatePreview();
}
void DefaultsWidget::applySettings( KuickData& data )
{
data.isModsEnabled = cbEnableMods->isChecked();
data.downScale = cbDownScale->isChecked();
data.upScale = cbUpScale->isChecked();
data.maxUpScale = sbMaxUpScaleFactor->value();
data.flipVertically = cbFlipVertically->isChecked();
data.flipHorizontally = cbFlipHorizontally->isChecked();
data.rotation = currentRotation();
ImData *id = data.idata;
id->brightness = sbBrightness->value();
id->contrast = sbContrast->value();
id->gamma = sbGamma->value();
}
void DefaultsWidget::updatePreview()
{
if ( !imFiltered )
return;
imFiltered->setAutoRender( false );
int flipMode = cbFlipHorizontally->isChecked() ? FlipHorizontal : FlipNone;
flipMode |= cbFlipVertically->isChecked() ? FlipVertical : FlipNone;
imFiltered->setFlipMode( flipMode );
Rotation rotation = cbEnableMods->isChecked() ? currentRotation() : ROT_0;
imFiltered->setRotation( rotation );
imFiltered->setBrightness( sbBrightness->value() );
imFiltered->setContrast( sbContrast->value() );
imFiltered->setGamma( sbGamma->value() );
imFiltered->updateImage();
imFiltered->setAutoRender( true );
}
void DefaultsWidget::enableWidgets( bool enable )
{
gbScale->setEnabled( enable );
sbMaxUpScaleFactor->setEnabled( enable & cbUpScale->isChecked() );
gbGeometry->setEnabled( enable );
gbAdjust->setEnabled( enable );
gbPreview->setEnabled( enable );
updatePreview();
}
Rotation DefaultsWidget::currentRotation() const
{
return (Rotation) comboRotate->currentItem();
}
#include "defaultswidget.moc"
|