~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

« back to all changes in this revision

Viewing changes to scribus/vruler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2009-02-09 09:25:18 UTC
  • mfrom: (5.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090209092518-iqsxmh3pjspgrdyd
Tags: 1.3.5.dfsg~svn20090208-2
debian/control: Use "type-handling -n arm,armel,armeb any" to generate the
list of architectures to build on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 *                                                                         *
22
22
 ***************************************************************************/
23
23
 
24
 
#include "vruler.h"
25
 
#include "vruler.moc"
 
24
#include <QCursor>
 
25
//#include <QDebug>
 
26
#include <QMouseEvent>
 
27
#include <QPaintEvent>
 
28
#include <QPainter>
 
29
#include <QPixmap>
 
30
#include <QPolygon>
 
31
#include <QRect>
 
32
#include <QRubberBand>
 
33
 
 
34
#include "canvasgesture_rulermove.h"
26
35
#include "page.h"
27
 
#include <qcursor.h>
28
 
#include <qcolor.h>
29
 
#include <qrect.h>
30
 
#include <qpointarray.h>
 
36
#include "prefsmanager.h"
31
37
#include "scribus.h"
32
38
#include "scribusdoc.h"
33
39
#include "units.h"
34
 
#include "prefsmanager.h"
 
40
#include "vruler.h"
35
41
 
36
42
#if QT_VERSION  > 0x030102
37
 
        #define SPLITVC SplitHCursor
 
43
        #define SPLITVC Qt::SplitHCursor
38
44
#else
39
 
        #define SPLITVC SplitVCursor
 
45
        #define SPLITVC Qt::SplitVCursor
40
46
#endif
41
47
 
42
48
 
44
50
Vruler::Vruler(ScribusView *pa, ScribusDoc *doc) : QWidget(pa)
45
51
{
46
52
        prefsManager=PrefsManager::instance();
47
 
        setEraseColor(QColor(255,255,255));
 
53
        setBackgroundRole(QPalette::Window);
 
54
        setAutoFillBackground(true);
 
55
        QPalette palette;
 
56
        palette.setBrush(QPalette::Window, QColor(255, 255, 255));
 
57
        setPalette(palette);
48
58
        currDoc = doc;
49
59
        currView = pa;
50
60
        offs = 0;
51
61
        oldMark = 0;
52
62
        Mpressed = false;
 
63
        drawMark = false;
 
64
        rulerGesture = new RulerGesture(currView, RulerGesture::VERTICAL);
53
65
        unitChange();
54
66
}
55
67
 
56
68
void Vruler::mousePressEvent(QMouseEvent *m)
57
69
{
58
70
        Mpressed = true;
59
 
        if (prefsManager->appPrefs.guidesSettings.guidesShown)
 
71
        if (currDoc->guidesSettings.guidesShown)
60
72
        {
61
 
                QPoint py = currView->viewport()->mapFromGlobal(m->globalPos());
62
 
                currView->DrVX = py.x();
63
 
                qApp->setOverrideCursor(QCursor(SPLITVC), true);
 
73
                qApp->changeOverrideCursor(QCursor(SPLITVC));
 
74
                currView->startGesture(rulerGesture);
64
75
        }
65
76
}
66
77
 
67
78
void Vruler::mouseReleaseEvent(QMouseEvent *m)
68
79
{
69
 
        if ((Mpressed) && (m->pos().x() > width()))
 
80
        if (Mpressed)
70
81
        {
71
 
                currView->DrVX = -1;
72
 
                currView->SetXGuide(m, -1);
 
82
                rulerGesture->mouseReleaseEvent(m);
 
83
                Mpressed = false;
73
84
        }
74
 
        qApp->setOverrideCursor(QCursor(ArrowCursor), true);
75
 
        Mpressed = false;
76
 
        currView->updateContents();
77
85
}
78
86
 
79
87
void Vruler::mouseMoveEvent(QMouseEvent *m)
80
88
{
81
 
        if ((Mpressed) && (m->pos().x() > width()))
82
 
                currView->FromVRuler(m);
 
89
        if (Mpressed)
 
90
        {
 
91
                rulerGesture->mouseMoveEvent(m);
 
92
        }
83
93
}
84
94
 
85
95
void Vruler::paintEvent(QPaintEvent *e)
94
104
        setFont(ff);
95
105
        QPainter p;
96
106
        p.begin(this);
 
107
        p.save();
97
108
        p.setClipRect(e->rect());
98
109
        p.drawLine(16, 0, 16, height());
99
 
        p.setBrush(black);
100
 
        p.setPen(black);
 
110
        p.setBrush(Qt::black);
 
111
        p.setPen(Qt::black);
101
112
        p.setFont(font());
102
113
        double cc = height() / sc;
103
114
        double firstMark = ceil(offs / iter) * iter - offs;
114
125
                int textY = qRound(firstMark * sc)+10;
115
126
                switch (currDoc->unitIndex())
116
127
                {
117
 
                        case 1:
 
128
                        case SC_MM:
118
129
                                tx = QString::number(markC * iter2 / (iter2 / 100) / cor);
119
130
                                break;
120
 
                        case 2:
 
131
                        case SC_IN:
121
132
                                xl = (markC * iter2 / iter2) / cor;
122
133
                                tx = QString::number(static_cast<int>(xl));
123
134
                                frac = fabs(xl - static_cast<int>(xl));
131
142
                                        tx += QChar(0xBE);
132
143
                                tx = tx;
133
144
                                break;
134
 
                        case 3:
135
 
                        case 5:
136
 
                                tx = QString::number(markC * iter2 / (iter2 / 10) / cor);
 
145
                        case SC_P:
 
146
                        case SC_C:
 
147
                                tx = QString::number(markC * iter2 / (iter2 /5) / cor);
137
148
                                break;
138
 
                        case 4:
 
149
                        case SC_CM:
139
150
                                tx = QString::number(markC * iter2 / iter2 / cor);
140
151
                                break;
141
152
                        default:
146
157
                firstMark += iter2;
147
158
                markC++;
148
159
        }
 
160
        p.restore();
 
161
        if (drawMark)
 
162
        {
 
163
                QPolygon cr;
 
164
#ifdef OPTION_SMOOTH_MARKERS
 
165
                // draw new marker to pixmap
 
166
                static const int SCALE = 16;
 
167
                static const QColor BACKGROUND(255, 255, 255);
 
168
                static QPixmap pix( 16*SCALE, 4*SCALE );
 
169
                static bool initpix = true;
 
170
                if (initpix)
 
171
                {
 
172
                        initpix = false;
 
173
                        QPainter pp;
 
174
                        pp.begin( &pix );
 
175
                        pp.setBrush( BACKGROUND );
 
176
                        pp.drawRect( 0, 0, 16*SCALE, 4*SCALE );
 
177
        
 
178
                        pp.setPen(Qt::red);
 
179
                        pp.setBrush(Qt::red);
 
180
                        cr.setPoints(3, 16*SCALE, 2*SCALE, 0, 4*SCALE, 0, 0);
 
181
                        pp.drawPolygon(cr);
 
182
                        pp.end();
 
183
                }
 
184
                // draw pixmap
 
185
                p.save();
 
186
                p.translate(0, -currView->contentsY());
 
187
                p.scale(1.0/(SCALE+1), 1.0/SCALE);
 
188
                p.drawPixmap(0, (where-2)*SCALE, pix);
 
189
                p.restore();
 
190
                // repaint marks
 
191
                p.setBrush(Qt::black);
 
192
                p.setPen(Qt::black);
 
193
                p.setFont(font());
 
194
                double sc = currView->getScale();
 
195
                double cc = height() / sc;
 
196
                double firstMark = ceil(offs / iter) * iter - offs;
 
197
                while (firstMark < cc)
 
198
                {
 
199
                        p.drawLine(10, qRound(firstMark * sc), 16, qRound(firstMark * sc));
 
200
                        firstMark += iter;
 
201
                }
 
202
#else
 
203
                // draw slim marker
 
204
                p.translate(0, -currView->contentsY());
 
205
                p.setPen(Qt::red);
 
206
                p.setBrush(Qt::red);
 
207
                cr.setPoints(5,  5, whereToDraw, 16, whereToDraw, 5, whereToDraw, 0, whereToDraw+2, 0, whereToDraw-2);
 
208
                p.drawPolygon(cr);
 
209
#endif
 
210
        }
149
211
        p.end();
150
212
}
151
213
 
152
214
void Vruler::drawNumber(QString num, int starty, QPainter *p)
153
215
{
154
216
        int textY = starty;
155
 
        for (uint a = 0; a < num.length(); ++a)
 
217
        for (int a = 0; a < num.length(); ++a)
156
218
        {
157
219
                QString txt = num.mid(a, 1);
158
 
#ifndef QT_MAC
 
220
#ifndef Q_WS_MAC
159
221
                p->drawText(1, textY, txt);
160
222
#else
161
223
                static const int SCALE = 16;
163
225
                QRect bbox = fm.boundingRect(txt);
164
226
                static QPixmap pix;
165
227
                if (pix.width() < bbox.width()*SCALE || pix.height() < bbox.height()*SCALE)
166
 
                        pix.resize(bbox.width()*SCALE, bbox.height()*SCALE);
 
228
                        pix = QPixmap(bbox.width()*SCALE, bbox.height()*SCALE);
167
229
                QFont fnt = p->font();
168
230
                QPainter p2;
169
231
                pix.fill();
189
251
{
190
252
        // erase old marker
191
253
        int currentCoor = where - currView->contentsY();
 
254
        whereToDraw = where;
 
255
        drawMark = true;
192
256
        repaint(0, oldMark-3, 17, 6);
193
 
        QPointArray cr;
194
 
        QPainter p;
195
 
#ifdef OPTION_SMOOTH_MARKERS
196
 
        // draw new marker to pixmap
197
 
        static const int SCALE = 16;
198
 
        static const QColor BACKGROUND(255, 255, 255);
199
 
        static QPixmap pix( 16*SCALE, 4*SCALE );
200
 
        static bool initpix = true;
201
 
        if (initpix) {
202
 
                initpix = false;
203
 
                p.begin( &pix );
204
 
                p.setBrush( BACKGROUND );
205
 
                p.drawRect( 0, 0, 16*SCALE, 4*SCALE );
206
 
 
207
 
                p.setPen(red);
208
 
                p.setBrush(red);
209
 
                cr.setPoints(3, 16*SCALE, 2*SCALE, 0, 4*SCALE, 0, 0);
210
 
                p.drawPolygon(cr);
211
 
                p.end();
212
 
        }
213
 
        // draw pixmap
214
 
        p.begin(this);
215
 
        p.translate(0, -currView->contentsY());
216
 
        p.scale(1.0/(SCALE+1), 1.0/SCALE);
217
 
        p.drawPixmap(0, (where-2)*SCALE, pix);
218
 
        p.end();
219
 
        // restore marks
220
 
        p.begin(this);
221
 
        p.setBrush(black);
222
 
        p.setPen(black);
223
 
        p.setFont(font());
224
 
        double sc = currView->getScale();
225
 
        double cc = height() / sc;
226
 
        double firstMark = ceil(offs / iter) * iter - offs;
227
 
        while (firstMark < cc)
228
 
        {
229
 
                p.drawLine(10, qRound(firstMark * sc), 16, qRound(firstMark * sc));
230
 
                firstMark += iter;
231
 
        }
232
 
        p.end();
233
 
#else
234
 
        // draw slim marker
235
 
        p.begin(this);
236
 
        p.translate(0, -currView->contentsY());
237
 
        p.setPen(red);
238
 
        p.setBrush(red);
239
 
        cr.setPoints(5,  5, where, 16, where, 5, where, 0, where+2, 0, where-2);
240
 
        p.drawPolygon(cr);
241
 
        p.end();
242
 
#endif
243
 
 
 
257
//      drawMark = false;
244
258
        oldMark = currentCoor;
245
259
}
246
260
 
251
265
        int docUnitIndex=currDoc->unitIndex();
252
266
        switch (docUnitIndex)
253
267
        {
254
 
                case 0:
 
268
                case SC_PT:
255
269
                        if (sc > 1 && sc <= 4)
256
270
                                cor = 2;
257
271
                        if (sc > 4)
272
286
                                iter2 = unitRulerGetIter2FromIndex(docUnitIndex) / cor;
273
287
                        }
274
288
                        break;
275
 
                case 1:
 
289
                case SC_MM:
276
290
                        if (sc > 1)
277
291
                                cor = 10;
278
292
                        iter = unitRulerGetIter1FromIndex(docUnitIndex) / cor;
279
293
                        iter2 = unitRulerGetIter2FromIndex(docUnitIndex) / cor;
280
294
                        break;
281
 
                case 2:
 
295
                case SC_IN:
282
296
                        iter = unitRulerGetIter1FromIndex(docUnitIndex);
283
297
                        iter2 = unitRulerGetIter2FromIndex(docUnitIndex);
284
298
                        if (sc > 1 && sc <= 4)
293
307
                                iter /= cor;
294
308
                                iter2 /= cor;
295
309
                        }
 
310
                        if (sc < 0.25)
 
311
                        {
 
312
                                cor = 0.5;
 
313
                                iter = 72.0*16.0;
 
314
                                iter2 = 72.0*2.0;
 
315
                        }
296
316
                        break;
297
 
                case 3:
 
317
                case SC_P:
298
318
                        iter = unitRulerGetIter1FromIndex(docUnitIndex);
299
319
                        iter2 = unitRulerGetIter2FromIndex(docUnitIndex);
300
 
                        if (sc > 1 && sc <= 4)
 
320
                        if (sc >= 1 && sc <= 4)
301
321
                        {
302
322
                                cor = 1;
303
323
                                iter = 12.0;
309
329
                                iter = 6.0;
310
330
                                iter2 = 12.0;
311
331
                        }
 
332
                        if (sc < 0.3)
 
333
                        {
 
334
                                cor = 0.25;
 
335
                                iter = 12.0*4;
 
336
                                iter2 = 60.0*4;
 
337
                        }
 
338
                        else
 
339
                                if (sc < 1)
 
340
                        {
 
341
                                cor = 1;
 
342
                                iter = 12.0;
 
343
                                iter2 = 60.0;
 
344
                        }
312
345
                        break;
313
 
                case 4:
 
346
                case SC_CM:
314
347
                        if (sc > 1 && sc <= 4)
315
348
                                cor = 1;
316
349
                        if (sc > 4)
317
350
                                cor = 10;
318
 
                        if (sc < 0.3)
319
 
                        {
320
 
                                iter = unitRulerGetIter1FromIndex(docUnitIndex) * 4;
321
 
                                iter2 = unitRulerGetIter2FromIndex(docUnitIndex) * 4;
322
 
                        }
323
 
                        else if (sc < 0.6)
324
 
                        {
325
 
                                iter = unitRulerGetIter1FromIndex(docUnitIndex) * 3;
326
 
                                iter2 = unitRulerGetIter2FromIndex(docUnitIndex) * 3;
 
351
                        if (sc < 0.6)
 
352
                        {
 
353
                                cor=0.1;
 
354
                                iter = 720.0/25.4;
 
355
                                iter2 = 7200.0/25.4;
327
356
                        }
328
357
                        else
329
358
                        {
331
360
                                iter2 = unitRulerGetIter2FromIndex(docUnitIndex) / cor;
332
361
                        }
333
362
                        break;
334
 
                case 5:
 
363
                case SC_C:
335
364
                        iter = unitRulerGetIter1FromIndex(docUnitIndex);
336
365
                        iter2 = unitRulerGetIter2FromIndex(docUnitIndex);
337
 
                        if (sc > 1 && sc <= 4)
 
366
                        if (sc >= 1 && sc <= 4)
338
367
                        {
339
368
                                cor = 1;
340
369
                                iter = 72.0/25.4*4.512;
346
375
                                iter = 72.0/25.4*4.512/2.0;
347
376
                                iter2 = 72.0/25.4*4.512;
348
377
                        }
 
378
                        if (sc < 0.3)
 
379
                        {
 
380
                                cor = 0.1;
 
381
                                iter = 72.0/25.4*4.512*10;
 
382
                                iter2 = 72.0/25.4*4.512*5.0*10;
 
383
                        }
 
384
                        else
 
385
                                if (sc < 1)
 
386
                        {
 
387
                                cor = 1;
 
388
                                iter = 72.0/25.4*4.512;
 
389
                                iter2 = 72.0/25.4*4.512*5.0;
 
390
                        }
349
391
                        break;
350
392
                default:
351
393
                        if (sc > 1 && sc <= 4)