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 patternpropsdialog.cpp - description
9 -------------------
10 begin : Thu Nov 19 2009
11 copyright : (C) 2009 by Franz Schmid
12 email : Franz.Schmid@altmuehlnet.de
13 ***************************************************************************/
14
15 /***************************************************************************
16 * *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
21 * *
22 ***************************************************************************/
23
24 #include "patternpropsdialog.h"
25 #include "iconmanager.h"
26 #include "util_math.h"
27
PatternPropsDialog(QWidget * parent,int unitIndex,bool isStroke)28 PatternPropsDialog::PatternPropsDialog(QWidget* parent, int unitIndex, bool isStroke) : QDialog( parent )
29 {
30 setModal(true);
31 forStroke = isStroke;
32 frame3Layout = new QVBoxLayout( this );
33 frame3Layout->setContentsMargins(9, 9, 9, 9);
34 frame3Layout->setSpacing(6);
35
36 groupOffset = new QGroupBox( this );
37 groupOffsetLayout = new QHBoxLayout( groupOffset );
38 groupOffsetLayout->setSpacing(6);
39 groupOffsetLayout->setContentsMargins(9, 9, 9, 9);
40 groupOffsetLayout->setAlignment( Qt::AlignTop );
41 textLabel1 = new QLabel( groupOffset );
42 groupOffsetLayout->addWidget( textLabel1 );
43 spinXoffset = new ScrSpinBox( -3000, 3000, groupOffset, 0);
44 groupOffsetLayout->addWidget( spinXoffset );
45 textLabel2 = new QLabel( groupOffset );
46 groupOffsetLayout->addWidget( textLabel2 );
47 spinYoffset = new ScrSpinBox( -3000, 3000, groupOffset, 0);
48 groupOffsetLayout->addWidget( spinYoffset );
49 frame3Layout->addWidget( groupOffset );
50
51 groupScale = new QGroupBox( this );
52 groupScaleLayout = new QGridLayout( groupScale );
53 groupScaleLayout->setSpacing(6);
54 groupScaleLayout->setContentsMargins(9, 9, 9, 9);
55 groupScaleLayout->setAlignment( Qt::AlignTop );
56 textLabel5 = new QLabel( groupScale );
57 groupScaleLayout->addWidget( textLabel5, 0, 0 );
58 spinXscaling = new ScrSpinBox( 0.01, 500, groupScale, 0);
59 spinXscaling->setValue( 100 );
60 groupScaleLayout->addWidget( spinXscaling, 0, 1 );
61 textLabel6 = new QLabel( groupScale );
62 groupScaleLayout->addWidget( textLabel6, 1, 0 );
63 spinYscaling = new ScrSpinBox( 0.01, 500, groupScale, 0 );
64 spinYscaling->setValue( 100 );
65 groupScaleLayout->addWidget( spinYscaling, 1, 1 );
66 keepScaleRatio = new LinkButton( groupScale );
67 keepScaleRatio->setCheckable( true );
68 keepScaleRatio->setAutoRaise( true );
69 keepScaleRatio->setMaximumSize( QSize( 15, 32767 ) );
70 groupScaleLayout->addWidget( keepScaleRatio, 0, 2, 2, 1 );
71 frame3Layout->addWidget( groupScale );
72 groupRotation = new QGroupBox( this );
73 groupRotationLayout = new QHBoxLayout( groupRotation );
74 groupRotationLayout->setSpacing(6);
75 groupRotationLayout->setContentsMargins(9, 9, 9, 9);
76 groupRotationLayout->setAlignment( Qt::AlignTop );
77 textLabel7 = new QLabel( groupRotation );
78 groupRotationLayout->addWidget( textLabel7 );
79 spinAngle = new ScrSpinBox( -180, 180, groupRotation, 6 );
80 groupRotationLayout->addWidget( spinAngle );
81 frame3Layout->addWidget( groupRotation );
82
83 groupSkew = new QGroupBox( this );
84 groupSkewLayout = new QGridLayout( groupSkew );
85 groupSkewLayout->setSpacing(6);
86 groupSkewLayout->setContentsMargins(9, 9, 9, 9);
87 groupSkewLayout->setAlignment( Qt::AlignTop );
88 textLabel8 = new QLabel( groupSkew );
89 groupSkewLayout->addWidget( textLabel8, 0, 0 );
90 spinXSkew = new ScrSpinBox( -89, 89, groupSkew, 6);
91 spinXSkew->setValue( 0 );
92 groupSkewLayout->addWidget( spinXSkew, 0, 1 );
93 textLabel9 = new QLabel( groupSkew );
94 groupSkewLayout->addWidget( textLabel9, 1, 0 );
95 spinYSkew = new ScrSpinBox( -89, 89, groupSkew, 6 );
96 spinYSkew->setValue( 0 );
97 groupSkewLayout->addWidget( spinYSkew, 1, 1 );
98 frame3Layout->addWidget( groupSkew );
99
100 if (forStroke)
101 {
102 groupSpace = new QGroupBox( this );
103 groupSpaceLayout = new QHBoxLayout( groupSpace );
104 groupSpaceLayout->setSpacing(6);
105 groupSpaceLayout->setContentsMargins(9, 9, 9, 9);
106 groupSpaceLayout->setAlignment( Qt::AlignTop );
107 textLabel20 = new QLabel( groupSpace );
108 groupSpaceLayout->addWidget( textLabel20 );
109 spinSpacing = new ScrSpinBox( 1, 500, groupSpace, 0 );
110 spinSpacing->setValue( 100 );
111 groupSpaceLayout->addWidget( spinSpacing );
112 frame3Layout->addWidget( groupSpace );
113 }
114
115 groupFlipLayout = new QHBoxLayout();
116 groupFlipLayout->setSpacing(6);
117 groupFlipLayout->setContentsMargins(0, 0, 0, 0);
118 textLabel15 = new QLabel( this );
119 groupFlipLayout->addWidget( textLabel15 );
120 QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
121 groupFlipLayout->addItem( spacer );
122 FlipH = new QToolButton( this );
123 FlipH->setIcon(IconManager::instance().loadIcon("16/flip-object-horizontal.png"));
124 FlipH->setCheckable( true );
125 groupFlipLayout->addWidget( FlipH );
126 FlipV = new QToolButton( this );
127 FlipV->setIcon(IconManager::instance().loadIcon("16/flip-object-vertical.png"));
128 FlipV->setCheckable( true );
129 groupFlipLayout->addWidget( FlipV );
130 frame3Layout->addLayout( groupFlipLayout );
131
132 buttonLayout = new QHBoxLayout;
133 buttonLayout->setContentsMargins(0, 0, 0, 0);
134 buttonLayout->setSpacing(6);
135 QSpacerItem* hspacing = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
136 buttonLayout->addItem(hspacing);
137 buttonOk = new QPushButton( this );
138 buttonOk->setAutoDefault( true );
139 buttonOk->setDefault( true );
140 buttonLayout->addWidget( buttonOk );
141 frame3Layout->addLayout( buttonLayout );
142 spinXoffset->setNewUnit(unitIndex);
143 spinYoffset->setNewUnit(unitIndex);
144 languageChange();
145 connect(spinXoffset, SIGNAL(valueChanged(double)), this, SLOT(changePatternProps()));
146 connect(spinYoffset, SIGNAL(valueChanged(double)), this, SLOT(changePatternProps()));
147 connect(spinXSkew, SIGNAL(valueChanged(double)), this, SLOT(changePatternProps()));
148 connect(spinYSkew, SIGNAL(valueChanged(double)), this, SLOT(changePatternProps()));
149 connect(spinXscaling, SIGNAL(valueChanged(double)), this, SLOT(HChange()));
150 connect(spinYscaling, SIGNAL(valueChanged(double)), this, SLOT(VChange()));
151 connect(spinYscaling, SIGNAL(valueChanged(double)), this, SLOT(changePatternProps()));
152 connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(changePatternProps()));
153 connect(keepScaleRatio, SIGNAL(clicked()), this, SLOT(ToggleKette()));
154 connect(FlipH, SIGNAL(clicked()), this, SLOT(changePatternProps()));
155 connect(FlipV, SIGNAL(clicked()), this, SLOT(changePatternProps()));
156 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
157 if (forStroke)
158 connect(spinSpacing, SIGNAL(valueChanged(double)), this, SLOT(changePatternProps()));
159 }
160
changeEvent(QEvent * e)161 void PatternPropsDialog::changeEvent(QEvent *e)
162 {
163 if (e->type() == QEvent::LanguageChange)
164 {
165 languageChange();
166 }
167 else
168 QWidget::changeEvent(e);
169 }
170
languageChange()171 void PatternPropsDialog::languageChange()
172 {
173 setWindowTitle( tr( "Pattern Properties" ));
174 QString ptSuffix=tr(" pt");
175 QString pctSuffix=tr(" %");
176 groupOffset->setTitle( tr( "Offsets" ) );
177 textLabel1->setText( tr( "X:" ) );
178 spinXoffset->setSuffix( ptSuffix );
179 textLabel2->setText( tr( "Y:" ) );
180 spinYoffset->setSuffix( ptSuffix );
181 groupScale->setTitle( tr( "Scaling" ) );
182 textLabel5->setText( tr( "X-Scale:" ) );
183 spinXscaling->setSuffix( pctSuffix );
184 textLabel6->setText( tr( "Y-Scale:" ) );
185 spinYscaling->setSuffix( pctSuffix );
186 groupRotation->setTitle( tr( "Rotation" ) );
187 groupSkew->setTitle( tr( "Skewing" ) );
188 if (forStroke)
189 {
190 groupSpace->setTitle( tr( "Spacing" ) );
191 spinSpacing->setSuffix( pctSuffix );
192 textLabel20->setText( tr( "Value:" ) );
193 }
194 textLabel8->setText( tr( "X-Skew:" ) );
195 textLabel9->setText( tr( "Y-Skew:" ) );
196 textLabel7->setText( tr( "Angle:" ) );
197 textLabel15->setText( tr( "Flip:" ) );
198 buttonOk->setText( tr("Close"));
199 resize(minimumSizeHint());
200 }
201
changePatternProps()202 void PatternPropsDialog::changePatternProps()
203 {
204 double a = M_PI / 180.0 * spinXSkew->value();
205 double b = M_PI / 180.0 * spinYSkew->value();
206 double sina = tan(a);
207 double sinb = tan(b);
208 bool fH = FlipH->isChecked();
209 bool fV = FlipV->isChecked();
210 if (forStroke)
211 emit NewPatternPropsS(spinXscaling->value(), spinYscaling->value(), spinXoffset->value(), spinYoffset->value(), spinAngle->value(), sina, sinb, spinSpacing->value() / 100.0, fH, fV);
212 else
213 emit NewPatternProps(spinXscaling->value(), spinYscaling->value(), spinXoffset->value(), spinYoffset->value(), spinAngle->value(), sina, sinb, fH, fV);
214 }
215
ToggleKette()216 void PatternPropsDialog::ToggleKette()
217 {
218 disconnect(spinXscaling, SIGNAL(valueChanged(double)), this, SLOT(HChange()));
219 disconnect(spinYscaling, SIGNAL(valueChanged(double)), this, SLOT(VChange()));
220 if (keepScaleRatio->isChecked())
221 {
222 spinYscaling->setValue(spinXscaling->value());
223 changePatternProps();
224 keepScaleRatio->setChecked(true);
225 }
226 else
227 keepScaleRatio->setChecked(false);
228 connect(spinXscaling, SIGNAL(valueChanged(double)), this, SLOT(HChange()));
229 connect(spinYscaling, SIGNAL(valueChanged(double)), this, SLOT(VChange()));
230 }
231
HChange()232 void PatternPropsDialog::HChange()
233 {
234 disconnect(spinXscaling, SIGNAL(valueChanged(double)), this, SLOT(HChange()));
235 disconnect(spinYscaling, SIGNAL(valueChanged(double)), this, SLOT(VChange()));
236 if (keepScaleRatio->isChecked())
237 spinYscaling->setValue(spinXscaling->value());
238 changePatternProps();
239 connect(spinXscaling, SIGNAL(valueChanged(double)), this, SLOT(HChange()));
240 connect(spinYscaling, SIGNAL(valueChanged(double)), this, SLOT(VChange()));
241 }
242
VChange()243 void PatternPropsDialog::VChange()
244 {
245 disconnect(spinXscaling, SIGNAL(valueChanged(double)), this, SLOT(HChange()));
246 disconnect(spinYscaling, SIGNAL(valueChanged(double)), this, SLOT(VChange()));
247 if (keepScaleRatio->isChecked())
248 spinXscaling->setValue(spinYscaling->value());
249 changePatternProps();
250 connect(spinXscaling, SIGNAL(valueChanged(double)), this, SLOT(HChange()));
251 connect(spinYscaling, SIGNAL(valueChanged(double)), this, SLOT(VChange()));
252 }
253