2
* This file is a part of Qtpfsgui package.
3
* ----------------------------------------------------------------------
4
* Copyright (C) 2006,2007 Giuseppe Rota
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* ----------------------------------------------------------------------
21
* @author Giuseppe Rota <grota@users.sourceforge.net>
24
#include "resizedialog_impl.h"
25
pfs::Frame* resizeFrame(pfs::Frame* inpfsframe, int _xSize);
27
ResizeDialog::ResizeDialog(QWidget *parent,pfs::Frame *orig) : QDialog(parent),original(orig) {
29
orig_width=original->getWidth();
30
orig_height=original->getHeight();
31
resized_width=orig_width;
32
resized_height=orig_height;
34
widthSpinBox->setSuffix("");
35
widthSpinBox->setDecimals(0);
36
widthSpinBox->setMaximum(2*orig_width);
37
widthSpinBox->setMinimum(1);
38
heightSpinBox->setSuffix("");
39
heightSpinBox->setDecimals(0);
40
heightSpinBox->setMaximum(2*orig_height);
41
heightSpinBox->setMinimum(1);
42
//we are now in pixel mode, put directly original pixel values.
43
widthSpinBox->setValue(orig_width);
44
heightSpinBox->setValue(orig_height);
45
from_other_spinbox=false;
48
connect(scaleButton,SIGNAL(clicked()),this,SLOT(scaledPressed()));
49
connect(widthSpinBox,SIGNAL(editingFinished()),this,SLOT(update_heightSpinBox()));
50
connect(widthSpinBox,SIGNAL(valueChanged(double)),this,SLOT(update_heightSpinBox()));
51
connect(heightSpinBox,SIGNAL(editingFinished()),this,SLOT(update_widthSpinBox()));
52
connect(heightSpinBox,SIGNAL(valueChanged(double)),this,SLOT(update_widthSpinBox()));
53
connect(px_or_percentage,SIGNAL(activated(int)),this,SLOT(switch_px_percentage(int)));
54
connect(restoredefault,SIGNAL(clicked()),this,SLOT(defaultpressed()));
57
ResizeDialog::~ResizeDialog() {
58
//we don't delete *original, because in maingui_impl.cpp we will later call mdiwin->updateHDR which takes care of deleting its previous pfs::Frame* buffer.
61
pfs::Frame* ResizeDialog::getResizedFrame() {
65
void ResizeDialog::scaledPressed() {
66
resized=resizeFrame(original,resized_width);
70
void ResizeDialog::switch_px_percentage(int px_per) {
74
widthSpinBox->setMaximum(2*orig_width);
75
heightSpinBox->setMaximum(2*orig_height);
76
from_other_spinbox=true;
77
// qDebug("px w=%d, current=%g", (int)(widthSpinBox->value()*(float)orig_width/100.0),widthSpinBox->value());
78
widthSpinBox->setValue((int)(widthSpinBox->value()*(float)orig_width/100.0)); //from perc to px
79
from_other_spinbox=true;
80
// qDebug("px h=%d, current=%g", (int)(heightSpinBox->value()*(float)orig_height/100.0),heightSpinBox->value());
81
heightSpinBox->setValue((int)(heightSpinBox->value()*(float)orig_height/100.0)); //from perc to px
82
widthSpinBox->setSuffix("");
83
widthSpinBox->setDecimals(0);
84
widthSpinBox->setMinimum(1);
85
heightSpinBox->setSuffix("");
86
heightSpinBox->setDecimals(0);
87
heightSpinBox->setMinimum(1);
90
widthSpinBox->setDecimals(2);
91
heightSpinBox->setDecimals(2);
92
from_other_spinbox=true;
93
// qDebug("perc w=%g, current=%g", 100*widthSpinBox->value()/(float)orig_width,widthSpinBox->value());
94
widthSpinBox->setValue(100*widthSpinBox->value()/(float)orig_width); //from px to perc
95
from_other_spinbox=true;
96
// qDebug("perc h=%g, current=%g", 100*heightSpinBox->value()/(float)orig_height,heightSpinBox->value());
97
heightSpinBox->setValue(100*heightSpinBox->value()/(float)orig_height); //from px to perc
98
widthSpinBox->setSuffix("%");
99
widthSpinBox->setMaximum(200);
100
widthSpinBox->setMinimum(1);
101
heightSpinBox->setSuffix("%");
102
heightSpinBox->setMaximum(200);
103
heightSpinBox->setMinimum(1);
106
from_other_spinbox=false;
109
//get a proper resized_width from a resized_height
110
int ResizeDialog::rw_from_rh() {
111
return (int)((float)orig_width*(float)resized_height/(float)orig_height);
113
//get a proper resized_height from a resized_width
114
int ResizeDialog::rh_from_rw() {
115
return (int)((float)orig_height*(float)resized_width/(float)orig_width);
117
void ResizeDialog::update_heightSpinBox() {
118
if (from_other_spinbox) {
119
from_other_spinbox=false;
123
switch (px_or_percentage->currentIndex()) {
125
resized_width=(int)widthSpinBox->value();
126
resized_height=rh_from_rw();
127
// qDebug("new height=%d",resized_height);
128
from_other_spinbox=true;
129
//update directly resized_height
130
heightSpinBox->setValue(resized_height);
133
resized_width=(int)(orig_width*widthSpinBox->value()/100.0);
134
resized_height=rh_from_rw();
135
from_other_spinbox=true;
136
heightSpinBox->setValue((double)resized_height/(double)orig_height*100.0);
141
void ResizeDialog::update_widthSpinBox() {
142
if (from_other_spinbox) {
143
from_other_spinbox=false;
147
switch (px_or_percentage->currentIndex()) {
149
resized_height=(int)heightSpinBox->value();
150
resized_width=rw_from_rh();
151
// qDebug("new width=%d",resized_width);
152
from_other_spinbox=true;
153
//update directly resized_width
154
widthSpinBox->setValue(resized_width);
157
resized_height=(int)(orig_height*heightSpinBox->value()/100.0);
158
resized_width=rw_from_rh();
159
from_other_spinbox=true;
160
widthSpinBox->setValue((double)resized_width/(double)orig_width*100.0);
165
void ResizeDialog::updatelabel() {
166
sizepreview->setText(QString("%1x%2").arg(resized_width).arg(resized_height));
169
void ResizeDialog::defaultpressed() {
170
resized_height=orig_height;
171
resized_width=orig_width;
172
switch (px_or_percentage->currentIndex()) {
174
from_other_spinbox=true;
175
widthSpinBox->setValue(resized_width);
176
from_other_spinbox=true;
177
heightSpinBox->setValue(resized_height);
178
from_other_spinbox=false;
181
from_other_spinbox=true;
182
widthSpinBox->setValue(100);
183
from_other_spinbox=true;
184
heightSpinBox->setValue(100);
185
from_other_spinbox=false;