~ubuntu-branches/ubuntu/natty/qtpfsgui/natty

« back to all changes in this revision

Viewing changes to src/Resize/resizedialog_impl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-01-06 04:39:36 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080106043936-a9u9g7yih3w16ru5
Tags: 1.9.0-1
* New upstream release.
* Replace “COPYING” with “LICENSE” in the NOT_NEEDED variable of
  debian/rules, following upstream's renaming.
* Update debian/links accordingly.
* Delete the matching TODO item since there's no longer needed to have a
  patched (with HTML tags) license file to get a correct display in the
  “License agreement” tab.
* Update the gcc4.3 patch (drop the hunk touching src/Libpfs/pfs.cpp):
   - 20_gcc4.3_includes.
* Add a link from /usr/share/qtpfsgui/html to the HTML documentation
  under /usr/share/doc/qtpfsgui/html since the former is used at runtime
  to display the manual.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * This file is a part of Qtpfsgui package.
3
 
 * ---------------------------------------------------------------------- 
4
 
 * Copyright (C) 2006,2007 Giuseppe Rota
5
 
 * 
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.
10
 
 *
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.
15
 
 *
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
 
 * ---------------------------------------------------------------------- 
20
 
 *
21
 
 * @author Giuseppe Rota <grota@users.sourceforge.net>
22
 
 */
23
 
 
24
 
#include "resizedialog_impl.h"
25
 
pfs::Frame* resizeFrame(pfs::Frame* inpfsframe, int _xSize);
26
 
 
27
 
ResizeDialog::ResizeDialog(QWidget *parent,pfs::Frame *orig) : QDialog(parent),original(orig) {
28
 
        setupUi(this);
29
 
        orig_width=original->getWidth();
30
 
        orig_height=original->getHeight();
31
 
        resized_width=orig_width;
32
 
        resized_height=orig_height;
33
 
 
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;
46
 
        updatelabel();
47
 
 
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()));
55
 
}
56
 
 
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.
59
 
}
60
 
 
61
 
pfs::Frame* ResizeDialog::getResizedFrame() {
62
 
        return resized;
63
 
}
64
 
 
65
 
void ResizeDialog::scaledPressed() {
66
 
        resized=resizeFrame(original,resized_width);
67
 
        accept();
68
 
}
69
 
 
70
 
void ResizeDialog::switch_px_percentage(int px_per) {
71
 
 
72
 
        switch (px_per) {
73
 
        case 0:
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);
88
 
                break;
89
 
        case 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);
104
 
                break;
105
 
        }
106
 
        from_other_spinbox=false;
107
 
        updatelabel();
108
 
}
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);
112
 
}
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);
116
 
}
117
 
void ResizeDialog::update_heightSpinBox() {
118
 
        if (from_other_spinbox) {
119
 
                from_other_spinbox=false;
120
 
                return;
121
 
        }
122
 
//      qDebug("here1");
123
 
        switch (px_or_percentage->currentIndex()) {
124
 
        case 0:
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);
131
 
        break;
132
 
        case 1:
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);
137
 
        break;
138
 
        }
139
 
        updatelabel();
140
 
}
141
 
void ResizeDialog::update_widthSpinBox() {
142
 
        if (from_other_spinbox) {
143
 
                from_other_spinbox=false;
144
 
                return;
145
 
        }
146
 
//      qDebug("here2");
147
 
        switch (px_or_percentage->currentIndex()) {
148
 
        case 0:
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);
155
 
                break;
156
 
        case 1:
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);
161
 
                break;
162
 
        }
163
 
        updatelabel();
164
 
}
165
 
void ResizeDialog::updatelabel() {
166
 
        sizepreview->setText(QString("%1x%2").arg(resized_width).arg(resized_height));
167
 
}
168
 
 
169
 
void ResizeDialog::defaultpressed() {
170
 
        resized_height=orig_height;
171
 
        resized_width=orig_width;
172
 
        switch (px_or_percentage->currentIndex()) {
173
 
        case 0:
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;
179
 
                break;
180
 
        case 1:
181
 
                from_other_spinbox=true;
182
 
                widthSpinBox->setValue(100);
183
 
                from_other_spinbox=true;
184
 
                heightSpinBox->setValue(100);
185
 
                from_other_spinbox=false;
186
 
                break;
187
 
        }
188
 
        updatelabel();
189
 
}