22
22
***************************************************************************/
26
#include <QMouseEvent>
27
#include <QPaintEvent>
32
#include <QRubberBand>
34
#include "canvasgesture_rulermove.h"
30
#include <qpointarray.h>
36
#include "prefsmanager.h"
31
37
#include "scribus.h"
32
38
#include "scribusdoc.h"
34
#include "prefsmanager.h"
36
42
#if QT_VERSION > 0x030102
37
#define SPLITVC SplitHCursor
43
#define SPLITVC Qt::SplitHCursor
39
#define SPLITVC SplitVCursor
45
#define SPLITVC Qt::SplitVCursor
44
50
Vruler::Vruler(ScribusView *pa, ScribusDoc *doc) : QWidget(pa)
46
52
prefsManager=PrefsManager::instance();
47
setEraseColor(QColor(255,255,255));
53
setBackgroundRole(QPalette::Window);
54
setAutoFillBackground(true);
56
palette.setBrush(QPalette::Window, QColor(255, 255, 255));
64
rulerGesture = new RulerGesture(currView, RulerGesture::VERTICAL);
56
68
void Vruler::mousePressEvent(QMouseEvent *m)
59
if (prefsManager->appPrefs.guidesSettings.guidesShown)
71
if (currDoc->guidesSettings.guidesShown)
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);
67
78
void Vruler::mouseReleaseEvent(QMouseEvent *m)
69
if ((Mpressed) && (m->pos().x() > width()))
72
currView->SetXGuide(m, -1);
82
rulerGesture->mouseReleaseEvent(m);
74
qApp->setOverrideCursor(QCursor(ArrowCursor), true);
76
currView->updateContents();
79
87
void Vruler::mouseMoveEvent(QMouseEvent *m)
81
if ((Mpressed) && (m->pos().x() > width()))
82
currView->FromVRuler(m);
91
rulerGesture->mouseMoveEvent(m);
85
95
void Vruler::paintEvent(QPaintEvent *e)
97
108
p.setClipRect(e->rect());
98
109
p.drawLine(16, 0, 16, height());
110
p.setBrush(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())
118
129
tx = QString::number(markC * iter2 / (iter2 / 100) / cor);
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));
146
157
firstMark += iter2;
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;
175
pp.setBrush( BACKGROUND );
176
pp.drawRect( 0, 0, 16*SCALE, 4*SCALE );
179
pp.setBrush(Qt::red);
180
cr.setPoints(3, 16*SCALE, 2*SCALE, 0, 4*SCALE, 0, 0);
186
p.translate(0, -currView->contentsY());
187
p.scale(1.0/(SCALE+1), 1.0/SCALE);
188
p.drawPixmap(0, (where-2)*SCALE, pix);
191
p.setBrush(Qt::black);
194
double sc = currView->getScale();
195
double cc = height() / sc;
196
double firstMark = ceil(offs / iter) * iter - offs;
197
while (firstMark < cc)
199
p.drawLine(10, qRound(firstMark * sc), 16, qRound(firstMark * sc));
204
p.translate(0, -currView->contentsY());
207
cr.setPoints(5, 5, whereToDraw, 16, whereToDraw, 5, whereToDraw, 0, whereToDraw+2, 0, whereToDraw-2);
152
214
void Vruler::drawNumber(QString num, int starty, QPainter *p)
154
216
int textY = starty;
155
for (uint a = 0; a < num.length(); ++a)
217
for (int a = 0; a < num.length(); ++a)
157
219
QString txt = num.mid(a, 1);
159
221
p->drawText(1, textY, txt);
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();
190
252
// erase old marker
191
253
int currentCoor = where - currView->contentsY();
192
256
repaint(0, oldMark-3, 17, 6);
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;
204
p.setBrush( BACKGROUND );
205
p.drawRect( 0, 0, 16*SCALE, 4*SCALE );
209
cr.setPoints(3, 16*SCALE, 2*SCALE, 0, 4*SCALE, 0, 0);
215
p.translate(0, -currView->contentsY());
216
p.scale(1.0/(SCALE+1), 1.0/SCALE);
217
p.drawPixmap(0, (where-2)*SCALE, pix);
224
double sc = currView->getScale();
225
double cc = height() / sc;
226
double firstMark = ceil(offs / iter) * iter - offs;
227
while (firstMark < cc)
229
p.drawLine(10, qRound(firstMark * sc), 16, qRound(firstMark * sc));
236
p.translate(0, -currView->contentsY());
239
cr.setPoints(5, 5, where, 16, where, 5, where, 0, where+2, 0, where-2);
244
258
oldMark = currentCoor;
272
286
iter2 = unitRulerGetIter2FromIndex(docUnitIndex) / cor;
278
292
iter = unitRulerGetIter1FromIndex(docUnitIndex) / cor;
279
293
iter2 = unitRulerGetIter2FromIndex(docUnitIndex) / cor;
282
296
iter = unitRulerGetIter1FromIndex(docUnitIndex);
283
297
iter2 = unitRulerGetIter2FromIndex(docUnitIndex);
284
298
if (sc > 1 && sc <= 4)