Rev 6141 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 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 | */ |
||
3614 | cbradney | 7 | /*************************************************************************** |
8 | pageitem.cpp - description |
||
9 | ------------------- |
||
10 | begin : Sat Apr 7 2001 |
||
11 | copyright : (C) 2001 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 "pageitem_imageframe.h" |
||
25 | #include "pageitem_imageframe.moc" |
||
26 | #include <qpainter.h> |
||
27 | #include <qpen.h> |
||
28 | #include <qfont.h> |
||
29 | #include <qregion.h> |
||
30 | #include <qpoint.h> |
||
31 | #include <qfileinfo.h> |
||
32 | #include <qdrawutil.h> |
||
33 | #include <qbitmap.h> |
||
34 | #include <qregexp.h> |
||
35 | #include <qmessagebox.h> |
||
36 | #include <cmath> |
||
37 | #include <cassert> |
||
38 | |||
39 | #include "mpalette.h" |
||
40 | #include "page.h" |
||
41 | #include "pageitem.h" |
||
42 | #include "prefsmanager.h" |
||
43 | #include "scpaths.h" |
||
44 | #include "scribus.h" |
||
45 | #include "scribusstructs.h" |
||
46 | #include "scribusdoc.h" |
||
4546 | subik | 47 | #include "commonstrings.h" |
3614 | cbradney | 48 | #include "undomanager.h" |
49 | #include "undostate.h" |
||
50 | #include "scconfig.h" |
||
51 | |||
52 | #include "util.h" |
||
53 | |||
54 | using namespace std; |
||
55 | |||
56 | PageItem_ImageFrame::PageItem_ImageFrame(ScribusDoc *pa, double x, double y, double w, double h, double w2, QString fill, QString outline) |
||
57 | : PageItem(pa, PageItem::ImageFrame, x, y, w, h, w2, fill, outline) |
||
58 | { |
||
59 | } |
||
60 | |||
5350 | avox | 61 | void PageItem_ImageFrame::DrawObj_Item(ScPainter *p, QRect /*e*/, double sc) |
3614 | cbradney | 62 | { |
4084 | cbradney | 63 | if(!m_Doc->RePos) |
3614 | cbradney | 64 | { |
5619 | fschmid | 65 | if (!m_Doc->layerOutline(LayerNr)) |
3614 | cbradney | 66 | { |
5572 | fschmid | 67 | if ((fillColor() != CommonStrings::None) || (GrType != 0)) |
68 | { |
||
69 | p->setupPolygon(&PoLine); |
||
70 | p->fillPath(); |
||
71 | } |
||
5584 | fschmid | 72 | p->save(); |
5471 | fschmid | 73 | #ifdef HAVE_CAIRO |
5584 | fschmid | 74 | if (imageClip.size() != 0) |
75 | { |
||
76 | p->setupPolygon(&imageClip); |
||
77 | p->setClipPath(); |
||
78 | } |
||
79 | p->setupPolygon(&PoLine); |
||
5471 | fschmid | 80 | p->setClipPath(); |
81 | #else |
||
5584 | fschmid | 82 | if (imageClip.size() != 0) |
3614 | cbradney | 83 | { |
5584 | fschmid | 84 | p->setupPolygon(&imageClip); |
85 | p->setClipPath2(&PoLine, true); |
||
3614 | cbradney | 86 | } |
5584 | fschmid | 87 | else |
3614 | cbradney | 88 | { |
5584 | fschmid | 89 | p->setupPolygon(&PoLine); |
90 | p->setClipPath(); |
||
91 | } |
||
92 | #endif |
||
93 | if (Pfile.isEmpty()) |
||
94 | { |
||
4084 | cbradney | 95 | if ((Frame) && (m_Doc->guidesSettings.framesShown)) |
3614 | cbradney | 96 | { |
5584 | fschmid | 97 | p->setPen(black, 1, SolidLine, FlatCap, MiterJoin); |
3614 | cbradney | 98 | p->drawLine(FPoint(0, 0), FPoint(Width, Height)); |
99 | p->drawLine(FPoint(0, Height), FPoint(Width, 0)); |
||
100 | } |
||
101 | } |
||
102 | else |
||
103 | { |
||
6141 | cbradney | 104 | //If we are missing our image, draw a red cross in the frame |
5584 | fschmid | 105 | if ((!PicArt) || (!PicAvail)) |
3614 | cbradney | 106 | { |
5584 | fschmid | 107 | if ((Frame) && (m_Doc->guidesSettings.framesShown)) |
108 | { |
||
109 | p->setPen(red, 1, SolidLine, FlatCap, MiterJoin); |
||
110 | p->drawLine(FPoint(0, 0), FPoint(Width, Height)); |
||
111 | p->drawLine(FPoint(0, Height), FPoint(Width, 0)); |
||
112 | } |
||
3614 | cbradney | 113 | } |
5584 | fschmid | 114 | else |
3614 | cbradney | 115 | { |
8000 | fschmid | 116 | #ifdef HAVE_CAIRO |
5584 | fschmid | 117 | if (imageFlippedH()) |
118 | { |
||
8000 | fschmid | 119 | p->translate(Width, 0); |
120 | p->scale(-1, 1); |
||
121 | } |
||
122 | if (imageFlippedV()) |
||
123 | { |
||
124 | p->translate(0, Height); |
||
125 | p->scale(1, -1); |
||
126 | } |
||
127 | p->translate(LocalX*LocalScX, LocalY*LocalScY); |
||
128 | #else |
||
129 | if (imageFlippedH()) |
||
130 | { |
||
5584 | fschmid | 131 | p->translate(Width * sc, 0); |
132 | p->scale(-1, 1); |
||
133 | } |
||
134 | if (imageFlippedV()) |
||
135 | { |
||
136 | p->translate(0, Height * sc); |
||
137 | p->scale(1, -1); |
||
138 | } |
||
139 | p->translate(LocalX*LocalScX*sc, LocalY*LocalScY*sc); |
||
8000 | fschmid | 140 | #endif |
5584 | fschmid | 141 | p->scale(LocalScX, LocalScY); |
142 | if (pixm.imgInfo.lowResType != 0) |
||
143 | p->scale(pixm.imgInfo.lowResScale, pixm.imgInfo.lowResScale); |
||
6063 | fschmid | 144 | p->drawImage(pixm.qImagePtr()); |
3614 | cbradney | 145 | } |
146 | } |
||
5584 | fschmid | 147 | p->restore(); |
3614 | cbradney | 148 | } |
149 | } |
||
150 | } |
||
3627 | cbradney | 151 | |
152 | void PageItem_ImageFrame::clearContents() |
||
153 | { |
||
3955 | fschmid | 154 | effectsInUse.clear(); |
155 | PicAvail = false; |
||
3627 | cbradney | 156 | Pfile = ""; |
157 | pixm = ScImage(); |
||
4546 | subik | 158 | |
3627 | cbradney | 159 | LocalScX = 1; |
160 | LocalScY = 1; |
||
161 | OrigW = 0; |
||
162 | OrigH = 0; |
||
163 | LocalX = 0; |
||
164 | LocalY = 0; |
||
165 | setImageFlippedH(false); |
||
166 | setImageFlippedV(false); |
||
167 | EmProfile = ""; |
||
168 | ScaleType = true; |
||
169 | AspectRatio = true; |
||
170 | setFillTransparency(0.0); |
||
171 | setLineTransparency(0.0); |
||
172 | imageClip.resize(0); |
||
4546 | subik | 173 | // emit UpdtObj(Doc->currentPage->pageNr(), ItemNr); |
3627 | cbradney | 174 | } |
175 | |||
5226 | cbradney | 176 | void PageItem_ImageFrame::handleModeEditKey(QKeyEvent *k, bool& keyRepeat) |
177 | { |
||
178 | double moveBy=1.0; |
||
179 | ButtonState buttonState = k->state(); |
||
5727 | cbradney | 180 | bool resizingImage=false; |
5921 | cbradney | 181 | bool controlDown=(buttonState & ControlButton); |
182 | if ((buttonState & ShiftButton) && !controlDown) |
||
5226 | cbradney | 183 | moveBy=10.0; |
5921 | cbradney | 184 | else if ((buttonState & ShiftButton) && controlDown && !(buttonState & AltButton)) |
5226 | cbradney | 185 | moveBy=0.1; |
5921 | cbradney | 186 | else if ((buttonState & ShiftButton) && controlDown && (buttonState & AltButton)) |
5226 | cbradney | 187 | moveBy=0.01; |
5921 | cbradney | 188 | else if (!(buttonState & ShiftButton) && (buttonState & AltButton)) |
5727 | cbradney | 189 | resizingImage=true; |
5226 | cbradney | 190 | double dX=0.0,dY=0.0; |
191 | int kk = k->key(); |
||
5727 | cbradney | 192 | if (!resizingImage) |
5226 | cbradney | 193 | { |
5727 | cbradney | 194 | moveBy/=m_Doc->unitRatio();//Lets allow movement by the current doc ratio, not only points |
195 | switch (kk) |
||
196 | { |
||
197 | case Key_Left: |
||
198 | dX=-moveBy; |
||
199 | break; |
||
200 | case Key_Right: |
||
201 | dX=moveBy; |
||
202 | break; |
||
203 | case Key_Up: |
||
204 | dY=-moveBy; |
||
205 | break; |
||
206 | case Key_Down: |
||
207 | dY=moveBy; |
||
208 | break; |
||
209 | } |
||
210 | if (dX!=0.0 || dY!=0.0) |
||
211 | { |
||
212 | moveImageInFrame(dX, dY); |
||
213 | ScribusView* view = m_Doc->view(); |
||
214 | view->updateContents(getRedrawBounding(view->scale())); |
||
215 | } |
||
5226 | cbradney | 216 | } |
5727 | cbradney | 217 | else |
5226 | cbradney | 218 | { |
5727 | cbradney | 219 | switch (kk) |
220 | { |
||
221 | case Key_Left: |
||
222 | dX=-moveBy+100; |
||
223 | break; |
||
224 | case Key_Right: |
||
225 | dX=moveBy+100; |
||
226 | break; |
||
227 | case Key_Up: |
||
228 | dY=-moveBy+100; |
||
229 | break; |
||
230 | case Key_Down: |
||
231 | dY=moveBy+100; |
||
232 | break; |
||
233 | default: |
||
234 | return; |
||
235 | } |
||
236 | if (dX!=0.0) |
||
237 | { |
||
238 | double newXScale=dX / 100.0 * LocalScX; |
||
239 | setImageXScale(newXScale); |
||
5976 | cbradney | 240 | if (!controlDown) |
5921 | cbradney | 241 | { |
242 | double newYScale=dX / 100.0 * LocalScY; |
||
243 | setImageYScale(newYScale); |
||
244 | } |
||
5727 | cbradney | 245 | } |
5921 | cbradney | 246 | else |
5727 | cbradney | 247 | if (dY!=0.0) |
248 | { |
||
249 | double newYScale=dY / 100.0 * LocalScY; |
||
250 | setImageYScale(newYScale); |
||
5976 | cbradney | 251 | if (!controlDown) |
5921 | cbradney | 252 | { |
253 | double newXScale=dY / 100.0 * LocalScY; |
||
254 | setImageXScale(newXScale); |
||
255 | } |
||
5727 | cbradney | 256 | } |
257 | if (dX!=0.0 || dY!=0.0) |
||
258 | if (imageClip.size() != 0) |
||
259 | { |
||
260 | imageClip = pixm.imgInfo.PDSpathData[pixm.imgInfo.usedPath].copy(); |
||
261 | QWMatrix cl; |
||
262 | cl.translate(imageXOffset()*imageXScale(), imageYOffset()*imageYScale()); |
||
263 | cl.scale(imageXScale(), imageYScale()); |
||
264 | imageClip.map(cl); |
||
265 | } |
||
5226 | cbradney | 266 | ScribusView* view = m_Doc->view(); |
5727 | cbradney | 267 | view->updateContents(getRedrawBounding(view->scale())); |
5226 | cbradney | 268 | } |
5243 | cbradney | 269 | } |