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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
/***************************************************************************
imgprintdialog.h - Kooka's Image Printing
-------------------
begin : May 2003
copyright : (C) 1999 by Klaas Freitag
email : freitag@suse.de
***************************************************************************/
/***************************************************************************
* *
* This file may be distributed and/or modified under the terms of the *
* GNU General Public License version 2 as published by the Free Software *
* Foundation and appearing in the file COPYING included in the *
* packaging of this file. *
*
* As a special exception, permission is given to link this program *
* with any version of the KADMOS ocr/icr engine of reRecognition GmbH, *
* Kreuzlingen and distribute the resulting executable without *
* including the source code for KADMOS in the source distribution. *
*
* As a special exception, permission is given to link this program *
* with any edition of TQt, and distribute the resulting executable, *
* without including the source code for TQt in the source distribution. *
* *
***************************************************************************/
#include "imgprintdialog.h"
#include <klocale.h>
#include <knuminput.h>
#include <kdialog.h>
#include <tqstring.h>
#include <tqmap.h>
#include <layout.h>
#include <tqvbuttongroup.h>
#include <tqcheckbox.h>
#include <tqradiobutton.h>
#include "kookaimage.h"
#include <tqvgroupbox.h>
#include <tqpaintdevicemetrics.h>
#include <tqlabel.h>
#include <tqtooltip.h>
#include <kdebug.h>
#define ID_SCREEN 0
#define ID_ORIG 1
#define ID_CUSTOM 2
#define ID_FIT_PAGE 3
ImgPrintDialog::ImgPrintDialog( KookaImage *img, TQWidget *parent, const char* name )
: KPrintDialogPage( parent, name ),
m_image(img),
m_ignoreSignal(false)
{
setTitle(i18n("Image Printing"));
TQVBoxLayout *layout = new TQVBoxLayout( this );
// layout->setMargin( KDialog::marginHint() );
// layout->setSpacing( KDialog::spacingHint() );
m_scaleRadios = new TQButtonGroup( 2, Qt::Vertical, i18n("Image Print Size"), this );
m_scaleRadios->setRadioButtonExclusive(true);
connect( m_scaleRadios, TQT_SIGNAL(clicked(int)), TQT_SLOT(slScaleChanged(int)));
m_rbScreen = new TQRadioButton( i18n("Scale to same size as on screen"),
m_scaleRadios );
TQToolTip::add( m_rbScreen, i18n("Screen scaling. That prints according to the screen resolution."));
m_scaleRadios->insert( m_rbScreen, ID_SCREEN );
m_rbOrigSize = new TQRadioButton( i18n("Original size (calculate from scan resolution)"),
m_scaleRadios );
TQToolTip::add( m_rbOrigSize,
i18n("Calculates the print size from the scan resolution. Enter the scan resolution in the dialog field below." ));
m_scaleRadios->insert( m_rbOrigSize, ID_ORIG );
m_rbScale = new TQRadioButton( i18n("Scale image to custom dimension"), m_scaleRadios );
TQToolTip::add( m_rbScale,
i18n("Set the print size yourself in the dialog below. The image is centered on the paper."));
m_scaleRadios->insert( m_rbScale, ID_CUSTOM );
m_rbFitPage = new TQRadioButton( i18n("Scale image to fit to page"), m_scaleRadios );
TQToolTip::add( m_rbFitPage, i18n("Printout uses maximum space on the selected pager. Aspect ratio is maintained."));
m_scaleRadios->insert( m_rbFitPage, ID_FIT_PAGE );
layout->addWidget( m_scaleRadios );
TQHBoxLayout *hbox = new TQHBoxLayout( this );
layout->addLayout( hbox );
/** Box for Image Resolutions **/
TQVGroupBox *group1 = new TQVGroupBox( i18n("Resolutions"), this );
hbox->addWidget( group1 );
/* Postscript generation resolution */
m_psDraft = new TQCheckBox( i18n("Generate low resolution PostScript (fast draft print)"),
group1, "cbPostScriptRes" );
m_psDraft->setChecked( false );
/* Scan resolution of the image */
m_dpi = new KIntNumInput( group1 );
m_dpi->setLabel( i18n("Scan resolution (dpi) " ), AlignVCenter );
m_dpi->setValue( 300 );
m_dpi->setSuffix( i18n(" dpi"));
/* Label for displaying the screen Resolution */
m_screenRes = new TQLabel( group1 );
/** Box for Image Print Size **/
TQVGroupBox *group = new TQVGroupBox( i18n("Image Print Size"), this );
hbox->addWidget( group );
m_sizeW = new KIntNumInput( group );
m_sizeW->setLabel( i18n("Image width:"), AlignVCenter );
m_sizeW->setSuffix( i18n(" mm"));
connect( m_sizeW, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slCustomWidthChanged(int)));
m_sizeH = new KIntNumInput( m_sizeW, AlignVCenter, group );
m_sizeH->setLabel( i18n("Image height:"), AlignVCenter);
m_sizeH->setSuffix( i18n(" mm"));
connect( m_sizeH, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slCustomHeightChanged(int)));
m_ratio = new TQCheckBox( i18n("Maintain aspect ratio"), group, "cbAspectRatio" );
m_ratio->setChecked(true);
TQWidget *spaceEater = new TQWidget( this );
spaceEater->setSizePolicy( TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Ignored ));
layout->addWidget( spaceEater );
/* Set start values */
m_rbScreen->setChecked(true);
slScaleChanged( ID_SCREEN );
}
void ImgPrintDialog::setImage( KookaImage *img )
{
if( ! img ) return;
// TODO: get scan resolution out of the image
}
void ImgPrintDialog::setOptions(const TQMap<TQString,TQString>& opts)
{
// m_autofit->setChecked(opts["app-img-autofit"] == "1");
TQString scale = opts[OPT_SCALING];
kdDebug(28000) << "In setOption" << endl;
if( scale == "scan" )
m_rbOrigSize->setChecked(true);
else if( scale == "custom" )
m_rbScale->setChecked(true);
else
m_rbScreen->setChecked(true);
int help = opts[OPT_SCAN_RES].toInt();
m_dpi->setValue( help );
help = opts[OPT_WIDTH].toInt();
m_sizeW->setValue( help );
help = opts[OPT_HEIGHT].toInt();
m_sizeH->setValue( help );
help = opts[OPT_SCREEN_RES].toInt();
m_screenRes->setText(i18n( "Screen resolution: %1 dpi").arg(help));
help = opts[OPT_PSGEN_DRAFT].toInt();
m_psDraft->setChecked( help == 1 );
help = opts[OPT_RATIO].toInt();
m_ratio->setChecked( help == 1 );
}
void ImgPrintDialog::getOptions(TQMap<TQString,TQString>& opts, bool )
{
// TODO: Check for meaning of include_def !
// kdDebug(28000) << "In getOption with include_def: " << include_def << endl;
TQString scale = "screen";
if( m_rbOrigSize->isChecked() )
scale = "scan";
else if( m_rbScale->isChecked() )
scale = "custom";
else if( m_rbFitPage->isChecked() )
scale = "fitpage";
opts[OPT_SCALING] = scale;
opts[OPT_SCAN_RES] = TQString::number( m_dpi->value() );
opts[OPT_WIDTH] = TQString::number( m_sizeW->value() );
opts[OPT_HEIGHT] = TQString::number( m_sizeH->value() );
opts[OPT_PSGEN_DRAFT] = TQString::number( m_psDraft->isChecked() );
opts[OPT_RATIO] = TQString::number( m_ratio->isChecked() );
{
TQPaintDeviceMetrics metric( this );
opts[OPT_SCREEN_RES] = TQString::number( metric.logicalDpiX());
}
}
bool ImgPrintDialog::isValid(TQString& msg)
{
/* check if scan reso is higher than 0 in case its needed */
int id = m_scaleRadios->id( m_scaleRadios->selected());
if( id == ID_ORIG && m_dpi->value() == 0 )
{
msg = i18n("Please specify a scan resolution larger than 0");
return false;
}
else if( id == ID_CUSTOM && (m_sizeW->value() == 0 || m_sizeH->value() == 0 ) )
{
msg = i18n("For custom printing, a valid size should be specified.\n"
"At least one dimension is zero.");
}
return true;
}
void ImgPrintDialog::slScaleChanged( int id )
{
if( id == ID_SCREEN )
{
/* disalbe size, scan res. */
m_dpi->setEnabled(false);
m_ratio->setEnabled(false);
m_sizeW->setEnabled(false);
m_sizeH->setEnabled(false);
}
else if( id == ID_ORIG )
{
/* disable size */
m_dpi->setEnabled(true);
m_ratio->setEnabled(false);
m_sizeW->setEnabled(false);
m_sizeH->setEnabled(false);
}
else if( id == ID_CUSTOM )
{
m_dpi->setEnabled(false);
m_ratio->setEnabled(true);
m_sizeW->setEnabled(true);
m_sizeH->setEnabled(true);
}
else if( id == ID_FIT_PAGE )
{
m_dpi->setEnabled(false);
m_ratio->setEnabled(true);
m_sizeW->setEnabled(false);
m_sizeH->setEnabled(false);
}
}
void ImgPrintDialog::slCustomWidthChanged( int val )
{
if( m_ignoreSignal )
{
m_ignoreSignal = false;
return;
}
/* go out here if scaling is not custom */
if( m_scaleRadios->id( m_scaleRadios->selected()) != ID_CUSTOM ) return;
/* go out here if maintain aspect ration is off */
if( ! m_ratio->isChecked() ) return;
m_ignoreSignal = true;
kdDebug(28000) << "Setting value to horizontal size" << endl;
m_sizeH->setValue( int( double(val) *
double(m_image->height())/double(m_image->width()) ) );
}
void ImgPrintDialog::slCustomHeightChanged( int val )
{
if( m_ignoreSignal )
{
m_ignoreSignal = false;
return;
}
/* go out here if scaling is not custom */
if( m_scaleRadios->id( m_scaleRadios->selected()) != ID_CUSTOM ) return;
/* go out here if maintain aspect ration is off */
if( ! m_ratio->isChecked() ) return;
m_ignoreSignal = true;
kdDebug(28000) << "Setting value to vertical size" << endl;
m_sizeW->setValue( int( double(val) *
double(m_image->width())/double(m_image->height()) ) );
}
#include "imgprintdialog.moc"
|