Subversion Repositories Scribus

Rev

Rev 17879 | Rev 19217 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
12031 fschmid 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
7
/**************************************************************************
8
*   Copyright (C) 2008 by Franz Schmid                                    *
9
*   franz.schmid@altmuehlnet.de                                           *
10
*                                                                         *
11
*   This program is free software; you can redistribute it and/or modify  *
12
*   it under the terms of the GNU General Public License as published by  *
13
*   the Free Software Foundation; either version 2 of the License, or     *
14
*   (at your option) any later version.                                   *
15
*                                                                         *
16
*   This program is distributed in the hope that it will be useful,       *
17
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19
*   GNU General Public License for more details.                          *
20
*                                                                         *
21
*   You should have received a copy of the GNU General Public License     *
22
*   along with this program; if not, write to the                         *
23
*   Free Software Foundation, Inc.,                                       *
18122 mrdocs 24
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
12031 fschmid 25
***************************************************************************/
26
 
27
#include "transformdialog.h"
14170 jghali 28
 
29
#include "commonstrings.h"
12031 fschmid 30
#include "selection.h"
31
#include "units.h"
14170 jghali 32
#include "util_icon.h"
33
 
17539 jghali 34
#if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
14170 jghali 35
#define _USE_MATH_DEFINES
36
#endif
12031 fschmid 37
#include <cmath>
38
 
39
TransformItem::TransformItem(QString text, QListWidget* parent, int type, double val1, double val2) : QListWidgetItem(text, parent, type)
40
{
41
        firstValue = val1;
42
        secondValue = val2;
43
}
44
 
45
TransformDialog::TransformDialog(QWidget* parent, ScribusDoc *doc) : QDialog(parent)
46
{
47
        setupUi(this);
48
        setModal(true);
49
        setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
50
        transformStack->setCurrentIndex(0);
51
        newTransformMenu = new QMenu(buttonAdd);
52
        newTransformMenu->addAction( tr("Scaling"), this, SLOT(newScaling()));
53
        newTransformMenu->addAction( tr("Translation"), this, SLOT(newTranslation()));
54
        newTransformMenu->addAction( tr("Rotation"), this, SLOT(newRotation()));
55
        newTransformMenu->addAction( tr("Skewing"), this, SLOT(newSkewing()));
56
        buttonAdd->setMenu(newTransformMenu);
57
        scaleLink->setChecked(true);
58
        buttonUp->setText( "" );
59
        buttonUp->setIcon(loadIcon("16/go-up.png"));
60
        buttonDown->setText( "" );
61
        buttonDown->setIcon(loadIcon("16/go-down.png"));
62
        buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
63
        m_doc = doc;
64
        m_unitRatio = unitGetRatioFromIndex(m_doc->unitIndex());
65
        m_suffix = unitGetSuffixFromIndex(m_doc->unitIndex());
66
        translateHorizontal->setSuffix(m_suffix);
67
        translateVertical->setSuffix(m_suffix);
68
        rotationValue->setWrapping( true );
69
        rotationValue->setValues( -180.0, 180.0, 1, 0);
70
        rotationValue->setSuffix(unitGetSuffixFromIndex(6));
71
        horizontalSkew->setSuffix(unitGetSuffixFromIndex(6));
72
        verticalSkew->setSuffix(unitGetSuffixFromIndex(6));
12085 fschmid 73
        linkSkew->setChecked(true);
12031 fschmid 74
        numberOfCopies->setValue(0);
13799 pierre 75
        basePoint->setCheckedId(m_doc->RotMode());
12031 fschmid 76
        connect(transformSelector, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(setCurrentTransform(QListWidgetItem*)));
77
        connect(horizontalScale, SIGNAL(valueChanged(double)), this, SLOT(changeHScale(double)));
78
        connect(verticalScale, SIGNAL(valueChanged(double)), this, SLOT(changeVScale(double)));
79
        connect(scaleLink, SIGNAL(clicked()), this, SLOT(toggleLink()));
80
        connect(translateHorizontal, SIGNAL(valueChanged(double)), this, SLOT(changeHTranslation(double)));
81
        connect(translateVertical, SIGNAL(valueChanged(double)), this, SLOT(changeVTranslation(double)));
82
        connect(rotationValue, SIGNAL(valueChanged(double)), this, SLOT(changeRotation(double)));
83
        connect(horizontalSkew, SIGNAL(valueChanged(double)), this, SLOT(changeHSkew(double)));
84
        connect(verticalSkew, SIGNAL(valueChanged(double)), this, SLOT(changeVSkew(double)));
85
        connect(linkSkew, SIGNAL(clicked()), this, SLOT(toggleLinkSkew()));
86
        connect(buttonUp, SIGNAL(clicked()), this, SLOT(moveTransformUp()));
87
        connect(buttonDown, SIGNAL(clicked()), this, SLOT(moveTransformDown()));
88
        connect(buttonRemove, SIGNAL(clicked()), this, SLOT(removeTransform()));
89
}
90
 
91
void TransformDialog::newScaling()
92
{
93
        TransformItem *item = new TransformItem( tr("Scale"), transformSelector, 1001, 100.0, 100.0);
94
        transformSelector->setCurrentItem(item);
95
        setCurrentTransform(item);
96
        item->setText( tr("Scale H = %1 % V = %2 %").arg(100.0).arg(100.0));
97
        buttonRemove->setEnabled(true);
98
}
99
 
100
void TransformDialog::newTranslation()
101
{
102
        TransformItem *item = new TransformItem( tr("Translate"), transformSelector, 1002, 0.0, 0.0);
103
        transformSelector->setCurrentItem(item);
104
        setCurrentTransform(item);
105
        item->setText( tr("Translate H = %1%2 V = %3%4").arg(0.0).arg(m_suffix).arg(0.0).arg(m_suffix));
106
        buttonRemove->setEnabled(true);
107
}
108
 
109
void TransformDialog::newRotation()
110
{
111
        TransformItem *item = new TransformItem( tr("Rotate"), transformSelector, 1003, 0.0, 0.0);
112
        transformSelector->setCurrentItem(item);
113
        setCurrentTransform(item);
114
        item->setText( tr("Rotate Angle = %1%2").arg(0.0).arg(unitGetSuffixFromIndex(6)));
115
        buttonRemove->setEnabled(true);
116
}
117
 
118
void TransformDialog::newSkewing()
119
{
120
        TransformItem *item = new TransformItem( tr("Skew"), transformSelector, 1004, 0.0, 0.0);
121
        transformSelector->setCurrentItem(item);
122
        setCurrentTransform(item);
123
        item->setText( tr("Skew H = %1%2 V = %3%4").arg(0.0).arg(unitGetSuffixFromIndex(6)).arg(0.0).arg(unitGetSuffixFromIndex(6)));
124
        buttonRemove->setEnabled(true);
125
}
126
 
127
void TransformDialog::setCurrentTransform(QListWidgetItem* item)
128
{
129
        if (item != NULL)
130
        {
131
                TransformItem *ite = (TransformItem*)item;
132
                switch (item->type())
133
                {
134
                        case 1001:
135
                                transformStack->setCurrentIndex(1);
136
                                horizontalScale->setValue(ite->firstValue);
137
                                verticalScale->setValue(ite->secondValue);
138
                                break;
139
                        case 1002:
140
                                transformStack->setCurrentIndex(2);
141
                                translateHorizontal->setValue(ite->firstValue);
142
                                translateVertical->setValue(ite->secondValue);
143
                                break;
144
                        case 1003:
145
                                transformStack->setCurrentIndex(3);
146
                                rotationValue->setValue(ite->firstValue);
147
                                break;
148
                        case 1004:
149
                                transformStack->setCurrentIndex(4);
150
                                horizontalSkew->setValue(ite->firstValue);
151
                                verticalSkew->setValue(ite->secondValue);
152
                                break;
153
                        default:
154
                                transformStack->setCurrentIndex(0);
155
                                break;
156
                }
157
                if (transformSelector->count() > 1)
158
                {
159
                        buttonUp->setEnabled(true);
160
                        buttonDown->setEnabled(true);
161
                        if (transformSelector->currentRow() == 0)
162
                                buttonUp->setEnabled(false);
163
                        if (transformSelector->currentRow() == transformSelector->count()-1)
164
                                buttonDown->setEnabled(false);
165
                }
166
                else
167
                {
168
                        buttonUp->setEnabled(false);
169
                        buttonDown->setEnabled(false);
170
                }
171
                buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
172
        }
173
        else
174
        {
175
                transformStack->setCurrentIndex(0);
176
                buttonRemove->setEnabled(false);
177
                buttonUp->setEnabled(false);
178
                buttonDown->setEnabled(false);
179
        }
180
}
181
 
182
void TransformDialog::changeHScale(double val)
183
{
184
        QListWidgetItem* item = transformSelector->currentItem();
185
        TransformItem *ite = (TransformItem*)item;
186
        ite->firstValue = val;
187
        if (scaleLink->isChecked())
188
        {
189
                verticalScale->setValue(horizontalScale->value());
190
                ite->secondValue = val;
191
        }
192
        item->setText( tr("Scale H = %1 % V = %2 %").arg(ite->firstValue).arg(ite->secondValue));
193
}
194
 
195
void TransformDialog::changeVScale(double val)
196
{
197
        QListWidgetItem* item = transformSelector->currentItem();
198
        TransformItem *ite = (TransformItem*)item;
199
        ite->secondValue = val;
200
        if (scaleLink->isChecked())
201
        {
202
                horizontalScale->setValue(verticalScale->value());
203
                ite->firstValue = val;
204
        }
205
        item->setText( tr("Scale H = %1 % V = %2 %").arg(ite->firstValue).arg(ite->secondValue));
206
}
207
 
208
void TransformDialog::toggleLink()
209
{
210
        if (scaleLink->isChecked())
211
                verticalScale->setValue(horizontalScale->value());
212
        QListWidgetItem* item = transformSelector->currentItem();
213
        TransformItem *ite = (TransformItem*)item;
214
        item->setText( tr("Scale H = %1 % V = %2 %").arg(ite->firstValue).arg(ite->secondValue));
215
}
216
 
217
void TransformDialog::changeHTranslation(double val)
218
{
219
        QListWidgetItem* item = transformSelector->currentItem();
220
        TransformItem *ite = (TransformItem*)item;
221
        ite->firstValue = val;
222
        item->setText( tr("Translate H = %1%2 V = %3%4").arg(ite->firstValue).arg(m_suffix).arg(ite->secondValue).arg(m_suffix));
223
}
224
 
225
void TransformDialog::changeVTranslation(double val)
226
{
227
        QListWidgetItem* item = transformSelector->currentItem();
228
        TransformItem *ite = (TransformItem*)item;
229
        ite->secondValue = val;
230
        item->setText( tr("Translate H = %1%2 V = %3%4").arg(ite->firstValue).arg(m_suffix).arg(ite->secondValue).arg(m_suffix));
231
}
232
 
233
void TransformDialog::changeRotation(double val)
234
{
235
        QListWidgetItem* item = transformSelector->currentItem();
236
        TransformItem *ite = (TransformItem*)item;
17879 fschmid 237
        ite->firstValue = -val;
238
        item->setText( tr("Rotate Angle = %1%2").arg(-ite->firstValue).arg(unitGetSuffixFromIndex(6)));
12031 fschmid 239
}
240
 
241
void TransformDialog::changeHSkew(double val)
242
{
243
        QListWidgetItem* item = transformSelector->currentItem();
244
        TransformItem *ite = (TransformItem*)item;
245
        ite->firstValue = val;
246
        if (linkSkew->isChecked())
247
        {
248
                verticalSkew->setValue(horizontalSkew->value());
249
                ite->secondValue = val;
250
        }
251
        item->setText( tr("Skew H = %1%2 V = %3%4").arg(ite->firstValue).arg(unitGetSuffixFromIndex(6)).arg(ite->secondValue).arg(unitGetSuffixFromIndex(6)));
252
}
253
 
254
void TransformDialog::changeVSkew(double val)
255
{
256
        QListWidgetItem* item = transformSelector->currentItem();
257
        TransformItem *ite = (TransformItem*)item;
258
        ite->secondValue = val;
259
        if (linkSkew->isChecked())
260
        {
261
                horizontalSkew->setValue(verticalSkew->value());
262
                ite->firstValue = val;
263
        }
264
        item->setText( tr("Skew H = %1%2 V = %3%4").arg(ite->firstValue).arg(unitGetSuffixFromIndex(6)).arg(ite->secondValue).arg(unitGetSuffixFromIndex(6)));
265
}
266
 
267
void TransformDialog::toggleLinkSkew()
268
{
269
        if (linkSkew->isChecked())
270
                verticalSkew->setValue(horizontalSkew->value());
271
        QListWidgetItem* item = transformSelector->currentItem();
272
        TransformItem *ite = (TransformItem*)item;
273
        item->setText( tr("Skew H = %1%2 V = %3%4").arg(ite->firstValue).arg(unitGetSuffixFromIndex(6)).arg(ite->secondValue).arg(unitGetSuffixFromIndex(6)));
274
}
275
 
276
void TransformDialog::moveTransformUp()
277
{
278
        int curr = transformSelector->currentRow();
279
        if (curr == 0)
280
                return;
281
        QListWidgetItem *it = transformSelector->takeItem(curr);
282
        transformSelector->insertItem(curr-1, it);
283
        transformSelector->setCurrentItem(it);
284
        setCurrentTransform(it);
285
}
286
 
287
void TransformDialog::moveTransformDown()
288
{
289
        int curr = transformSelector->currentRow();
290
        if (curr == transformSelector->count()-1)
291
                return;
292
        QListWidgetItem *it = transformSelector->takeItem(curr);
293
        transformSelector->insertItem(curr+1, it);
294
        transformSelector->setCurrentItem(it);
295
        setCurrentTransform(it);
296
}
297
 
298
void TransformDialog::removeTransform()
299
{
300
        int curr = transformSelector->currentRow();
301
        QListWidgetItem *it = transformSelector->takeItem(curr);
302
        delete it;
303
        transformSelector->clearSelection();
304
        if (transformSelector->count() == 0)
305
        {
306
                transformStack->setCurrentIndex(0);
307
                buttonRemove->setEnabled(false);
308
                buttonUp->setEnabled(false);
309
                buttonDown->setEnabled(false);
310
                buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
311
        }
312
        else
313
        {
314
                transformSelector->setCurrentItem(transformSelector->item(qMax(curr-1, 0)));
315
                transformSelector->currentItem()->setSelected(true);
316
                setCurrentTransform(transformSelector->currentItem());
317
                buttonRemove->setEnabled(true);
318
        }
319
}
320
 
13951 fschmid 321
QTransform TransformDialog::getTransformMatrix()
12031 fschmid 322
{
13951 fschmid 323
        QTransform ret = QTransform();
12031 fschmid 324
        for (int a = 0; a < transformSelector->count(); a++)
325
        {
326
                QListWidgetItem *it = transformSelector->item(a);
327
                TransformItem *ite = (TransformItem*)it;
328
                switch (it->type())
329
                {
330
                        case 1001:
331
                                ret.scale(ite->firstValue / 100.0, ite->secondValue / 100.0);
332
                                break;
333
                        case 1002:
12036 fschmid 334
                                ret.translate(ite->firstValue / m_unitRatio, ite->secondValue / m_unitRatio);
12031 fschmid 335
                                break;
336
                        case 1003:
337
                                ret.rotate(ite->firstValue);
338
                                break;
339
                        case 1004:
340
                                ret.shear(-sin(ite->firstValue / 180.0 * M_PI), -sin(ite->secondValue / 180.0 * M_PI));
341
                                break;
342
                        default:
343
                                break;
344
                }
345
        }
346
        return ret;
347
}
348
 
349
int TransformDialog::getCount()
350
{
351
        return numberOfCopies->value();
352
}
353
 
354
int TransformDialog::getBasepoint()
355
{
12092 fschmid 356
        return basePoint->checkedId();
12031 fschmid 357
}