1
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
3
Gwenview: an image viewer
4
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#include "printoptionspage.moc"
25
#include <QButtonGroup>
26
#include <QGridLayout>
27
#include <QToolButton>
30
#include <kconfigdialogmanager.h>
33
#include <gwenviewconfig.h>
34
#include <signalblocker.h>
35
#include <ui_printoptionspage.h>
40
static inline double unitToInches(PrintOptionsPage::Unit unit) {
41
if (unit == PrintOptionsPage::Inches) {
43
} else if (unit == PrintOptionsPage::Centimeters) {
45
} else { // Millimeters
51
struct PrintOptionsPagePrivate : public Ui_PrintOptionsPage {
53
QButtonGroup mScaleGroup;
54
QButtonGroup mPositionGroup;
55
KConfigDialogManager* mConfigDialogManager;
57
void initPositionFrame() {
58
mPositionFrame->setStyleSheet(
60
" background-color: palette(mid);"
61
" border: 1px solid palette(dark);"
65
" background: palette(base);"
68
" background: palette(alternate-base);"
69
" border: 1px solid palette(highlight);"
71
"QToolButton:checked {"
72
" background-color: palette(highlight);"
76
QGridLayout* layout = new QGridLayout(mPositionFrame);
78
layout->setSpacing(1);
79
for (int row = 0; row < 3; ++row) {
80
for (int col = 0; col < 3; ++col) {
81
QToolButton* button = new QToolButton(mPositionFrame);
82
button->setFixedSize(40, 40);
83
button->setCheckable(true);
84
layout->addWidget(button, row, col);
86
Qt::Alignment alignment;
88
alignment = Qt::AlignTop;
89
} else if (row == 1) {
90
alignment = Qt::AlignVCenter;
92
alignment = Qt::AlignBottom;
95
alignment |= Qt::AlignLeft;
96
} else if (col == 1) {
97
alignment |= Qt::AlignHCenter;
99
alignment |= Qt::AlignRight;
102
mPositionGroup.addButton(button, int(alignment));
109
PrintOptionsPage::PrintOptionsPage(const QSize& imageSize)
111
, d(new PrintOptionsPagePrivate) {
113
d->mImageSize = imageSize;
114
d->mConfigDialogManager = new KConfigDialogManager(this, GwenviewConfig::self());
116
d->initPositionFrame();
118
d->mScaleGroup.addButton(d->mNoScale, NoScale);
119
d->mScaleGroup.addButton(d->mScaleToPage, ScaleToPage);
120
d->mScaleGroup.addButton(d->mScaleTo, ScaleToCustomSize);
122
connect(d->kcfg_PrintWidth, SIGNAL(valueChanged(double)),
123
SLOT(adjustHeightToRatio()) );
125
connect(d->kcfg_PrintHeight, SIGNAL(valueChanged(double)),
126
SLOT(adjustWidthToRatio()) );
128
connect(d->kcfg_PrintKeepRatio, SIGNAL(toggled(bool)),
129
SLOT(adjustHeightToRatio()) );
133
PrintOptionsPage::~PrintOptionsPage() {
138
Qt::Alignment PrintOptionsPage::alignment() const {
139
int id = d->mPositionGroup.checkedId();
140
kWarning() << "alignment=" << id;
141
return Qt::Alignment(id);
145
PrintOptionsPage::ScaleMode PrintOptionsPage::scaleMode() const {
146
return PrintOptionsPage::ScaleMode( d->mScaleGroup.checkedId() );
150
bool PrintOptionsPage::enlargeSmallerImages() const {
151
return d->kcfg_PrintEnlargeSmallerImages->isChecked();
155
PrintOptionsPage::Unit PrintOptionsPage::scaleUnit() const {
156
return PrintOptionsPage::Unit(d->kcfg_PrintUnit->currentIndex());
160
double PrintOptionsPage::scaleWidth() const {
161
return d->kcfg_PrintWidth->value() * unitToInches(scaleUnit());
165
double PrintOptionsPage::scaleHeight() const {
166
return d->kcfg_PrintHeight->value() * unitToInches(scaleUnit());
170
void PrintOptionsPage::adjustWidthToRatio() {
171
if (!d->kcfg_PrintKeepRatio->isChecked()) {
174
double width = d->mImageSize.width() * d->kcfg_PrintHeight->value() / d->mImageSize.height();
176
SignalBlocker blocker(d->kcfg_PrintWidth);
177
d->kcfg_PrintWidth->setValue(width ? width : 1.);
181
void PrintOptionsPage::adjustHeightToRatio() {
182
if (!d->kcfg_PrintKeepRatio->isChecked()) {
185
double height = d->mImageSize.height() * d->kcfg_PrintWidth->value() / d->mImageSize.width();
187
SignalBlocker blocker(d->kcfg_PrintHeight);
188
d->kcfg_PrintHeight->setValue(height ? height : 1.);
192
void PrintOptionsPage::loadConfig() {
193
QAbstractButton* button;
195
button = d->mPositionGroup.button(GwenviewConfig::printPosition());
197
button->setChecked(true);
199
kWarning() << "Unknown button for position group";
202
button = d->mScaleGroup.button(GwenviewConfig::printScaleMode());
204
button->setChecked(true);
206
kWarning() << "Unknown button for scale group";
209
d->mConfigDialogManager->updateWidgets();
211
if (d->kcfg_PrintKeepRatio->isChecked()) {
212
adjustHeightToRatio();
217
void PrintOptionsPage::saveConfig() {
218
int position = d->mPositionGroup.checkedId();
219
GwenviewConfig::setPrintPosition(position);
221
ScaleMode scaleMode = ScaleMode( d->mScaleGroup.checkedId() );
222
GwenviewConfig::setPrintScaleMode(scaleMode);
224
d->mConfigDialogManager->updateSettings();
226
GwenviewConfig::self()->writeConfig();