Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
16957 jghali 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
#include "propertywidget_group.h"
9
#include "propertywidget_groupshape.h"
10
#include "transparencypalette.h"
11
#include "scribus.h"
12
#include "scribusdoc.h"
13
#include "selection.h"
14
#include "util_math.h"
15
 
17181 jghali 16
PropertyWidget_Group::PropertyWidget_Group(QWidget* parent) : QFrame(parent)
16957 jghali 17
{
18
        m_item = 0;
19
        m_ScMW = 0;
20
        m_unitIndex = 0;
21
        m_unitRatio = 1.0;
22
 
23
        setSizePolicy( QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
24
 
25
        QVBoxLayout* vboxLayout = new QVBoxLayout();
26
        vboxLayout->setMargin(5);
27
        vboxLayout->setSpacing(1);
28
        vboxLayout->setAlignment(Qt::AlignTop);
29
 
30
        this->setLayout(vboxLayout);
31
        this->setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum));
32
 
33
        groupShapeWidget = new PropertyWidget_GroupShape(this);
34
        vboxLayout->addWidget(groupShapeWidget);
35
 
36
        QVBoxLayout* tboxLayout = new QVBoxLayout();
37
        tboxLayout->setMargin(0);
38
        tboxLayout->setSpacing(1);
39
        tboxLayout->setAlignment(Qt::AlignTop);
40
 
41
        transGroupBox = new QGroupBox(this);
42
        transGroupBox->setLayout(tboxLayout);
43
        transGroupBox->setTitle( tr("Transparency") );
44
        transGroupBox->setFlat(true);
45
 
46
        groupTransWidget = new Tpalette(transGroupBox);
47
        groupTransWidget->hideSelectionButtons();
48
        tboxLayout->addWidget(groupTransWidget);
49
 
50
        vboxLayout->addWidget(transGroupBox);
51
 
52
        languageChange();
53
}
54
 
55
void PropertyWidget_Group::setMainWindow(ScribusMainWindow *mw)
56
{
57
        m_ScMW = mw;
58
 
59
        groupShapeWidget->setMainWindow(mw);
60
 
61
        connect(m_ScMW, SIGNAL(UpdateRequest(int)), this  , SLOT(handleUpdateRequest(int)));
62
}
63
 
64
void PropertyWidget_Group::setDoc(ScribusDoc *d)
65
{
66
        if((d == (ScribusDoc*) m_doc) || (m_ScMW && m_ScMW->scriptIsRunning()))
67
                return;
68
 
69
        if (m_doc)
70
        {
71
                disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
72
                disconnect(m_doc             , SIGNAL(docChanged())      , this, SLOT(handleSelectionChanged()));
73
        }
74
 
75
        m_doc  = d;
76
        m_item = NULL;
77
 
78
        groupShapeWidget->setDoc(m_doc);
79
 
80
        groupTransWidget->setDocument(m_doc);
81
        groupTransWidget->setCurrentItem(NULL);
82
 
83
        if (m_doc.isNull())
84
        {
85
                disconnectSignals();
86
                return;
87
        }
88
 
89
        m_unitRatio = m_doc->unitRatio();
90
        m_unitIndex = m_doc->unitIndex();
91
 
92
        connect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
93
        connect(m_doc             , SIGNAL(docChanged())      , this, SLOT(handleSelectionChanged()));
94
}
95
 
96
void PropertyWidget_Group::setCurrentItem(PageItem *item)
97
{
98
        if (!m_ScMW || m_ScMW->scriptIsRunning())
99
                return;
100
        //CB We shouldnt really need to process this if our item is the same one
101
        //maybe we do if the item has been changed by scripter.. but that should probably
102
        //set some status if so.
103
        //FIXME: This wont work until when a canvas deselect happens, m_item must be NULL.
104
        //if (m_item == i)
105
        //      return;
106
 
107
        if (item && m_doc.isNull())
108
                setDoc(item->doc());
109
 
110
        m_item = item;
111
 
112
        disconnectSignals();
113
        enableFromSelection();
114
 
115
        if (m_item)
116
        {
117
                connectSignals();
118
        }
119
}
120
 
121
void PropertyWidget_Group::connectSignals()
122
{
123
        connect(groupTransWidget, SIGNAL(gradientChanged())  , this, SLOT(handleGradientChanged()));
124
 
125
        connect(groupTransWidget, SIGNAL(NewTrans(double))   , this, SLOT(handleGroupTransparency(double)));
126
        connect(groupTransWidget, SIGNAL(NewBlend(int))      , this, SLOT(handleGroupBlending(int)));
127
        connect(groupTransWidget, SIGNAL(NewGradient(int))   , this, SLOT(handleGroupGradMask(int)));
128
        connect(groupTransWidget, SIGNAL(NewPattern(QString)), this, SLOT(handleGroupPatternMask(QString)));
129
        connect(groupTransWidget, SIGNAL(NewPatternProps(double, double, double, double, double, double, double, bool, bool)), this, SLOT(handleGroupPatternMaskProps(double, double, double, double, double, double, double, bool, bool)));
130
 
131
        connect(groupTransWidget, SIGNAL(editGradient())     , this, SLOT(handleGradientEdit()));
132
        connect(groupTransWidget, SIGNAL(NewSpecial(double, double, double, double, double, double, double, double, double, double)), this, SLOT(handleSpecialGradient(double, double, double, double, double, double, double, double )));
133
}
134
 
135
void PropertyWidget_Group::disconnectSignals()
136
{
137
        disconnect(groupTransWidget, SIGNAL(gradientChanged())  , this, SLOT(handleGradientChanged()));
138
 
139
        disconnect(groupTransWidget, SIGNAL(NewTrans(double))   , this, SLOT(handleGroupTransparency(double)));
140
        disconnect(groupTransWidget, SIGNAL(NewBlend(int))      , this, SLOT(handleGroupBlending(int)));
141
        disconnect(groupTransWidget, SIGNAL(NewGradient(int))   , this, SLOT(handleGroupGradMask(int)));
142
        disconnect(groupTransWidget, SIGNAL(NewPattern(QString)), this, SLOT(handleGroupPatternMask(QString)));
143
        disconnect(groupTransWidget, SIGNAL(NewPatternProps(double, double, double, double, double, double, double, bool, bool)), this, SLOT(handleGroupPatternMaskProps(double, double, double, double, double, double, double, bool, bool)));
144
 
145
        disconnect(groupTransWidget, SIGNAL(editGradient())     , this, SLOT(handleGradientEdit()));
146
        disconnect(groupTransWidget, SIGNAL(NewSpecial(double, double, double, double, double, double, double, double, double, double)), this, SLOT(handleSpecialGradient(double, double, double, double, double, double, double, double )));
147
}
148
 
149
void PropertyWidget_Group::enableFromSelection(void)
150
{
151
        bool widgetEnabled = false;
152
        if (m_item && m_doc)
153
        {
154
                if (m_doc->m_Selection->count() > 1)
155
                {
156
                        if ((m_item->isGroup()) && (!m_item->isSingleSel))
157
                                widgetEnabled = true;
158
                }
159
                else if (m_doc->m_Selection->count() == 1)
160
                {
161
                        widgetEnabled = m_item->isSymbol() || m_item->isGroup();
162
                }
163
        }
164
        setEnabled(widgetEnabled);
165
}
166
 
167
void PropertyWidget_Group::handleSelectionChanged()
168
{
169
        if (!m_doc || !m_ScMW || m_ScMW->scriptIsRunning())
170
                return;
171
 
172
        PageItem* currItem = currentItemFromSelection();
173
        setCurrentItem(currItem);
174
        updateGeometry();
175
        repaint();
176
}
177
 
178
void PropertyWidget_Group::handleUpdateRequest(int updateFlags)
179
{
180
        // Nothing to do, all is handled by subwidgets
181
}
182
 
183
void PropertyWidget_Group::handleGradientChanged()
184
{
185
        if (m_doc)
186
        {
187
                VGradient vg(groupTransWidget->gradEdit->gradient());
188
                m_doc->itemSelection_SetMaskGradient(vg);
189
        }
190
}
191
 
192
void PropertyWidget_Group::handleGroupTransparency(double trans)
193
{
194
        if (m_item)
195
        {
196
                m_item->setFillTransparency(trans);
197
                m_item->update();
198
                m_ScMW->slotDocCh();
199
        }
200
}
201
 
202
void PropertyWidget_Group::handleGroupBlending(int blend)
203
{
204
        if (m_item)
205
        {
206
                m_item->setFillBlendmode(blend);
207
                m_item->update();
208
                m_ScMW->slotDocCh();
209
        }
210
}
211
 
212
void PropertyWidget_Group::handleGroupGradMask(int typ)
213
{
214
        if (m_item)
215
        {
216
                m_item->GrMask = typ;
217
                if ((typ > 0) && (typ < 7))
218
                        m_item->updateGradientVectors();
219
                m_item->update();
220
                m_ScMW->slotDocCh();
221
        }
222
}
223
 
224
void PropertyWidget_Group::handleGroupPatternMask(QString pattern)
225
{
226
        if (m_item)
227
        {
228
                m_item->setPatternMask(pattern);
229
                m_item->update();
230
                m_ScMW->slotDocCh();
231
        }
232
}
233
 
234
void PropertyWidget_Group::handleGroupPatternMaskProps(double imageScaleX, double imageScaleY, double offsetX, double offsetY, double rotation, double skewX, double skewY, bool mirrorX, bool mirrorY)
235
{
236
        if (m_item)
237
        {
238
                m_item->setMaskTransform(imageScaleX, imageScaleY, offsetX, offsetY, rotation, skewX, skewY);
239
                m_item->setMaskFlip(mirrorX, mirrorY);
240
                m_item->update();
241
                m_ScMW->slotDocCh();
242
        }
243
}
244
 
245
void PropertyWidget_Group::handleGradientEdit()
246
{
247
        if (!m_ScMW || m_ScMW->scriptIsRunning())
248
                return;
249
        if (m_doc && m_item)
250
        {
251
                m_ScMW->view->editStrokeGradient = 2;
252
                if (groupTransWidget->gradEditButton->isChecked())
253
                        m_ScMW->view->requestMode(modeEditGradientVectors);
254
                else
255
                        m_ScMW->view->requestMode(modeNormal);
256
        }
257
}
258
 
259
void PropertyWidget_Group::handleSpecialGradient(double x1, double y1, double x2, double y2, double fx, double fy, double sg, double sk)
260
{
261
        if (!m_ScMW || m_ScMW->scriptIsRunning())
262
                return;
263
        if (m_doc && m_item)
264
        {
265
                QRectF upRect;
266
                m_item->GrMaskStartX = x1 / m_unitRatio;
267
                m_item->GrMaskStartY = y1 / m_unitRatio;
268
                m_item->GrMaskEndX = x2 / m_unitRatio;
269
                m_item->GrMaskEndY = y2 / m_unitRatio;
270
                m_item->GrMaskFocalX = fx / m_unitRatio;
271
                m_item->GrMaskFocalY = fy / m_unitRatio;
272
                m_item->GrMaskScale = sg;
273
                m_item->GrMaskSkew = sk;
274
                if ((m_item->GrMask == 1) || (m_item->GrMask == 4))
275
                {
276
                        m_item->GrMaskFocalX = m_item->GrMaskStartX;
277
                        m_item->GrMaskFocalY = m_item->GrMaskStartY;
278
                }
279
                m_item->update();
280
                upRect = QRectF(QPointF(m_item->GrMaskStartX, m_item->GrMaskStartY), QPointF(m_item->GrMaskEndX, m_item->GrMaskEndY));
281
                double radEnd = distance(m_item->GrMaskEndX - m_item->GrMaskStartX, m_item->GrMaskEndY - m_item->GrMaskStartY);
282
                double rotEnd = xy2Deg(m_item->GrMaskEndX - m_item->GrMaskStartX, m_item->GrMaskEndY - m_item->GrMaskStartY);
283
                QTransform m;
284
                m.translate(m_item->GrMaskStartX, m_item->GrMaskStartY);
285
                m.rotate(rotEnd);
286
                m.rotate(-90);
287
                m.rotate(m_item->GrMaskSkew);
288
                m.translate(radEnd * m_item->GrMaskScale, 0);
289
                QPointF shP = m.map(QPointF(0,0));
290
                upRect |= QRectF(shP, QPointF(m_item->GrMaskEndX, m_item->GrMaskEndY)).normalized();
291
                upRect |= QRectF(shP, QPointF(m_item->GrMaskStartX, m_item->GrMaskStartY)).normalized();
292
                upRect |= QRectF(shP, QPointF(0, 0)).normalized();
293
                upRect |= QRectF(shP, QPointF(m_item->width(), m_item->height())).normalized();
294
                upRect.translate(m_item->xPos(), m_item->yPos());
295
                m_doc->regionsChanged()->update(upRect.adjusted(-10.0, -10.0, 10.0, 10.0));
296
                m_ScMW->slotDocCh();
297
        }
298
}
299
 
300
void PropertyWidget_Group::changeEvent(QEvent *e)
301
{
302
        if (e->type() == QEvent::LanguageChange)
303
        {
304
                languageChange();
305
                return;
306
        }
307
        QFrame::changeEvent(e);
308
}
309
 
310
void PropertyWidget_Group::languageChange()
311
{
312
        transGroupBox->setTitle( tr("Transparency") );
313
}
314
 
315
void PropertyWidget_Group::unitChange()
316
{
317
        if (!m_doc)
318
                return;
319
 
320
        double oldRatio = m_unitRatio;
321
        m_unitRatio = m_doc->unitRatio();
322
        m_unitIndex = m_doc->unitIndex();
323
 
324
        groupTransWidget->blockSignals(true);
325
        groupTransWidget->unitChange(oldRatio, m_unitRatio, m_doc->unitIndex());
326
        groupTransWidget->blockSignals(false);
327
}