00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kpimagepage.h"
00021
#include "imageposition.h"
00022
#include "imagepreview.h"
00023
#include "driver.h"
00024
00025
#include <qcombobox.h>
00026
#include <qbuttongroup.h>
00027
#include <qradiobutton.h>
00028
#include <qgroupbox.h>
00029
#include <qpushbutton.h>
00030
#include <qapplication.h>
00031
#include <qimage.h>
00032
#include <qlabel.h>
00033
#include <qlayout.h>
00034
#include <klocale.h>
00035
#include <knuminput.h>
00036
#include <kseparator.h>
00037
#include <kstandarddirs.h>
00038
00039 KPImagePage::KPImagePage(DrMain *driver,
QWidget *parent,
const char *name)
00040 :
KPrintDialogPage(parent, name)
00041 {
00042 setTitle(i18n(
"Image"));
00043
00044
QGroupBox *colorbox =
new QGroupBox(0, Qt::Vertical, i18n(
"Color Settings"),
this);
00045 QGroupBox *sizebox =
new QGroupBox(0, Qt::Vertical, i18n(
"Image Size"),
this);
00046 QGroupBox *positionbox =
new QGroupBox(0, Qt::Vertical, i18n(
"Image Position"),
this);
00047
00048 m_brightness =
new KIntNumInput(100, colorbox);
00049 m_brightness->setLabel(i18n(
"&Brightness:"));
00050 m_brightness->setRange(0, 200, 20,
true);
00051 m_hue =
new KIntNumInput(m_brightness, 0, colorbox);
00052 m_hue->setLabel(i18n(
"&Hue (Color rotation):"));
00053 m_hue->setRange(-360, 360, 36,
true);
00054 m_saturation =
new KIntNumInput(m_brightness, 100, colorbox);
00055 m_saturation->setLabel(i18n(
"&Saturation:"));
00056 m_saturation->setRange(0, 200, 20,
true);
00057 m_gamma =
new KIntNumInput(m_saturation, 1000, colorbox);
00058 m_gamma->setLabel(i18n(
"&Gamma (Color correction):"));
00059 m_gamma->setRange(1, 3000, 100,
true);
00060 connect(m_brightness, SIGNAL(valueChanged(
int)), SLOT(slotImageSettingsChanged()));
00061 connect(m_hue, SIGNAL(valueChanged(
int)), SLOT(slotImageSettingsChanged()));
00062 connect(m_saturation, SIGNAL(valueChanged(
int)), SLOT(slotImageSettingsChanged()));
00063
00064
00065 m_preview =
new ImagePreview(colorbox);
00066
bool useColor = (driver ? driver->get(
"colordevice") ==
"1" :
true);
00067 m_preview->setBlackAndWhite(!useColor);
00068 m_hue->setEnabled(useColor);
00069 m_saturation->setEnabled(useColor);
00070
QImage img(locate(
"data",
"kdeprint/preview.png"));
00071 m_preview->setImage(img);
00072 KSeparator *sep =
new KSeparator(Qt::Horizontal, colorbox);
00073
00074
QPushButton *defbtn =
new QPushButton(i18n(
"&Default Settings"), colorbox);
00075 connect(defbtn, SIGNAL(clicked()), SLOT(slotDefaultClicked()));
00076 slotDefaultClicked();
00077
00078 m_sizetype =
new QComboBox(sizebox);
00079 m_sizetype->insertItem(i18n(
"Natural Image Size"));
00080 m_sizetype->insertItem(i18n(
"Resolution (ppi)"));
00081
00082 m_sizetype->insertItem(i18n(
"% of Page"));
00083
00084 m_sizetype->insertItem(i18n(
"% of Natural Image Size"));
00085 m_size =
new KIntNumInput(sizebox);
00086 m_size->setRange(1, 1200, 20,
true);
00087 m_size->setValue(72);
00088 connect(m_sizetype, SIGNAL(activated(
int)), SLOT(slotSizeTypeChanged(
int)));
00089 m_sizetype->setCurrentItem(0);
00090 slotSizeTypeChanged(0);
00091
QLabel *lab =
new QLabel(i18n(
"&Image size type:"), sizebox);
00092 lab->setBuddy(m_sizetype);
00093
00094 m_position =
new ImagePosition(positionbox);
00095
QRadioButton *bottom =
new QRadioButton(positionbox);
00096 QRadioButton *top =
new QRadioButton(positionbox);
00097 QRadioButton *vcenter =
new QRadioButton(positionbox);
00098 QRadioButton *left =
new QRadioButton(positionbox);
00099 QRadioButton *right =
new QRadioButton(positionbox);
00100 QRadioButton *hcenter =
new QRadioButton(positionbox);
00101
QSize sz = bottom->sizeHint();
00102 bottom->setFixedSize(sz);
00103 vcenter->setFixedSize(sz);
00104 top->setFixedSize(sz);
00105 left->setFixedSize(sz);
00106 hcenter->setFixedSize(sz);
00107 right->setFixedSize(sz);
00108 m_vertgrp =
new QButtonGroup(positionbox);
00109 m_vertgrp->hide();
00110 m_horizgrp =
new QButtonGroup(positionbox);
00111 m_horizgrp->hide();
00112 m_vertgrp->insert(top, 0);
00113 m_vertgrp->insert(vcenter, 1);
00114 m_vertgrp->insert(bottom, 2);
00115
if ( QApplication::reverseLayout() )
00116 {
00117 m_horizgrp->insert(left, 2);
00118 m_horizgrp->insert(hcenter, 1);
00119 m_horizgrp->insert(right, 0);
00120 }
00121
else
00122 {
00123 m_horizgrp->insert(left, 0);
00124 m_horizgrp->insert(hcenter, 1);
00125 m_horizgrp->insert(right, 2);
00126 }
00127 connect(m_vertgrp, SIGNAL(clicked(
int)), SLOT(slotPositionChanged()));
00128 connect(m_horizgrp, SIGNAL(clicked(
int)), SLOT(slotPositionChanged()));
00129 m_vertgrp->setButton(1);
00130 m_horizgrp->setButton(1);
00131 slotPositionChanged();
00132
00133
QGridLayout *l0 =
new QGridLayout(
this, 2, 2, 0, 10);
00134 l0->addMultiCellWidget(colorbox, 0, 0, 0, 1);
00135 l0->addWidget(sizebox, 1, 0);
00136 l0->addWidget(positionbox, 1, 1);
00137 l0->setColStretch(0, 1);
00138 QGridLayout *l1 =
new QGridLayout(colorbox->layout(), 5, 2, 10);
00139 l1->addWidget(m_brightness, 0, 0);
00140 l1->addWidget(m_hue, 1, 0);
00141 l1->addWidget(m_saturation, 2, 0);
00142 l1->addWidget(sep, 3, 0);
00143 l1->addWidget(m_gamma, 4, 0);
00144 l1->addMultiCellWidget(m_preview, 0, 3, 1, 1);
00145 l1->addWidget(defbtn, 4, 1);
00146
QVBoxLayout *l2 =
new QVBoxLayout(sizebox->layout(), 3);
00147 l2->addStretch(1);
00148 l2->addWidget(lab);
00149 l2->addWidget(m_sizetype);
00150 l2->addSpacing(10);
00151 l2->addWidget(m_size);
00152 l2->addStretch(1);
00153 QGridLayout *l3 =
new QGridLayout(positionbox->layout(), 2, 2, 10);
00154
QHBoxLayout *l4 =
new QHBoxLayout(0, 0, 10);
00155 QVBoxLayout *l5 =
new QVBoxLayout(0, 0, 10);
00156 l3->addLayout(l4, 0, 1);
00157 l3->addLayout(l5, 1, 0);
00158 l3->addWidget(m_position, 1, 1);
00159 l4->addWidget(left, Qt::AlignLeft);
00160 l4->addWidget(hcenter, Qt::AlignCenter);
00161 l4->addWidget(right, Qt::AlignRight);
00162 l5->addWidget(top, Qt::AlignTop);
00163 l5->addWidget(vcenter, Qt::AlignVCenter);
00164 l5->addWidget(bottom, Qt::AlignBottom);
00165 }
00166
00167 KPImagePage::~KPImagePage()
00168 {
00169 }
00170
00171
void KPImagePage::setOptions(
const QMap<QString,QString>& opts)
00172 {
00173
QString value;
00174
if (!(value=opts[
"brightness"]).isEmpty())
00175 m_brightness->setValue(value.toInt());
00176
if (!(value=opts[
"hue"]).isEmpty())
00177 m_hue->setValue(value.toInt());
00178
if (!(value=opts[
"saturation"]).isEmpty())
00179 m_saturation->setValue(value.toInt());
00180
if (!(value=opts[
"gamma"]).isEmpty())
00181 m_gamma->setValue(value.toInt());
00182
00183
int type = 0;
00184
int ival(0);
00185
if ((ival = opts[
"ppi"].toInt()) != 0)
00186 type = 1;
00187
else if ((ival = opts[
"scaling"].toInt()) != 0)
00188 type = 2;
00189
else if (!opts[
"natural-scaling"].isEmpty() && (ival = opts[
"natural-scaling"].toInt()) != 1)
00190 type = 3;
00191 m_sizetype->setCurrentItem(type);
00192 slotSizeTypeChanged(type);
00193
if (type != 0)
00194 m_size->setValue(ival);
00195
00196
if (!(value=opts[
"position"]).isEmpty())
00197 {
00198 m_position->setPosition(value.latin1());
00199
int pos = m_position->position();
00200 m_vertgrp->setButton(pos/3);
00201 m_horizgrp->setButton(pos%3);
00202 }
00203 }
00204
00205
void KPImagePage::getOptions(
QMap<QString,QString>& opts,
bool incldef)
00206 {
00207
if (incldef || m_brightness->value() != 100)
00208 opts[
"brightness"] = QString::number(m_brightness->value());
00209
if (m_hue->isEnabled())
00210 {
00211
if (incldef || m_hue->value() != 0)
00212 opts[
"hue"] = QString::number(m_hue->value());
00213
if (incldef || m_saturation->value() != 100)
00214 opts[
"saturation"] = QString::number(m_saturation->value());
00215 }
00216
if (incldef || m_gamma->value() != 1000)
00217 opts[
"gamma"] = QString::number(m_gamma->value());
00218
00219
QString name;
00220
if (incldef)
00221 {
00222 opts[
"ppi"] =
"0";
00223 opts[
"scaling"] =
"0";
00224 opts[
"natural-scaling"] =
"1";
00225 }
00226
switch (m_sizetype->currentItem())
00227 {
00228
case 0:
break;
00229
case 1: name =
"ppi";
break;
00230
case 2: name =
"scaling";
break;
00231
case 3: name =
"natural-scaling";
break;
00232 }
00233
if (!name.isEmpty())
00234 opts[name] = QString::number(m_size->value());
00235
00236
if (incldef || m_position->position() != ImagePosition::Center)
00237 opts[
"position"] = m_position->positionString();
00238 }
00239
00240
void KPImagePage::slotSizeTypeChanged(
int t)
00241 {
00242 m_size->setEnabled(t > 0);
00243
if (t > 0)
00244 {
00245
int minval, maxval, defval;
00246
if (t == 1)
00247 {
00248 minval = 1;
00249 maxval = 1200;
00250 defval = 72;
00251 }
00252
else
00253 {
00254 minval = 1;
00255 maxval = 800;
00256 defval = 100;
00257 }
00258 m_size->setRange(minval, maxval);
00259 m_size->setValue(defval);
00260 }
00261 }
00262
00263
void KPImagePage::slotPositionChanged()
00264 {
00265
int h = m_horizgrp->id(m_horizgrp->selected()), v = m_vertgrp->id(m_vertgrp->selected());
00266 m_position->setPosition(h, v);
00267 }
00268
00269
void KPImagePage::slotImageSettingsChanged()
00270 {
00271
int b = m_brightness->value(), h = m_hue->value(), s = m_saturation->value();
00272
00273
int g = 1000;
00274 m_preview->setParameters(b, h, s, g);
00275 }
00276
00277
void KPImagePage::slotDefaultClicked()
00278 {
00279 m_brightness->setValue(100);
00280 m_hue->setValue(0);
00281 m_saturation->setValue(100);
00282 m_gamma->setValue(1000);
00283 }
00284
00285
#include "kpimagepage.moc"