28#define MARKER_HEIGHT RULER_THICKNESS
30const char *KisRuler::m_nums[] = {
34 "XX XXXXXX XXXX XXXX XXXXXX XXX XXXX XXX XXX XXXX XX",
35 "X XXX XXXX XXX XXX XX XXX XXXX XXX XXXXXXX XXXXXXXXX XX XXX XX XXX X",
36 "X XXX XXXXX XXXXXXX XXXXXX XXX X XXX XXXXXX XXXXXXXXX XXX XXX XX XXX X",
37 "X XXX XXXXX XXXXX XXXXX XXX XX XXX XXX XXXXXX XXXX XXXX X",
38 "X XXX XXXXX XXXX XXXXXXXXX XX XXXXXX XX XXX XXXX XXXX XXX XXXXXX X",
39 "X XXX XXXXX XXX XXXXXX XXX XXXXX XXXXXXX XX XXX XXXX XXXX XXX XXXXX XX",
40 "XX XXXXXX XXX XXX XXXXXX XXX XXXX XXXXX XXXXX XXXX XXX"
43KisRuler::KisRuler(TQt::Orientation o, TQWidget *parent,
const char *name) : super(parent, name, WRepaintNoErase | WResizeNoErase), m_pixmapNums(m_nums)
45 setBackgroundMode(NoBackground);
46 setFrameStyle(Box | Sunken);
50 m_unit = KoUnit::U_PT;
54 m_currentPosition = -1;
56 if (m_orientation == TQt::Horizontal) {
57 setFixedHeight(RULER_THICKNESS);
58 initMarker(MARKER_WIDTH, MARKER_HEIGHT);
60 setFixedWidth(RULER_THICKNESS);
61 initMarker(MARKER_HEIGHT, MARKER_WIDTH);
67 delete m_pixmapBuffer;
70void KisRuler::initMarker(TQ_INT32 w, TQ_INT32 h)
74 m_pixmapMarker.resize(w, h);
75 p.begin(&m_pixmapMarker);
77 p.eraseRect(0, 0, w, h);
78 p.drawLine(0, 0, w - 1, h - 1);
82void KisRuler::recalculateSize()
88 delete m_pixmapBuffer;
92 if (m_orientation == TQt::Horizontal) {
100 m_pixmapBuffer =
new TQPixmap(w, h);
101 TQ_CHECK_PTR(m_pixmapBuffer);
104 updatePointer(m_currentPosition, m_currentPosition);
107KoUnit::Unit KisRuler::unit()
const
112void KisRuler::setUnit(KoUnit::Unit u)
116 updatePointer(m_currentPosition, m_currentPosition);
120void KisRuler::setZoom(
double zoom)
125 updatePointer(m_currentPosition, m_currentPosition);
129void KisRuler::updatePointer(TQ_INT32 x, TQ_INT32 y)
131 if (m_pixmapBuffer) {
132 if (m_orientation == TQt::Horizontal) {
133 if (m_currentPosition != -1)
134 repaint(m_currentPosition, 1, MARKER_WIDTH, MARKER_HEIGHT);
137 bitBlt(
this, x, 1, &m_pixmapMarker, 0, 0, MARKER_WIDTH, MARKER_HEIGHT);
138 m_currentPosition = x;
141 if (m_currentPosition != -1)
142 repaint(1, m_currentPosition, MARKER_HEIGHT, MARKER_WIDTH);
145 bitBlt(
this, 1, y, &m_pixmapMarker, 0, 0, MARKER_HEIGHT, MARKER_WIDTH);
146 m_currentPosition = y;
152void KisRuler::updateVisibleArea(TQ_INT32 xpos, TQ_INT32 ypos)
154 if (m_orientation == TQt::Horizontal)
155 m_firstVisible = xpos;
157 m_firstVisible = ypos;
161 updatePointer(m_currentPosition, m_currentPosition);
164void KisRuler::paintEvent(TQPaintEvent *e)
166 if (m_pixmapBuffer) {
167 const TQRect& rect = e->rect();
169 bitBlt(
this, rect.topLeft(), m_pixmapBuffer, rect);
170 super::paintEvent(e);
174void KisRuler::drawRuler()
186 p.begin(m_pixmapBuffer);
187 p.setPen(colorGroup().text());
188 p.setBackgroundColor(colorGroup().base());
189 p.eraseRect(0, 0, m_pixmapBuffer->width(), m_pixmapBuffer->height());
211 bool s1 = KoUnit::fromUserValue(st1, m_unit) * m_zoom > 3.0;
212 bool s2 = KoUnit::fromUserValue(st2, m_unit) * m_zoom > 3.0;
213 bool s3 = KoUnit::fromUserValue(st3, m_unit) * m_zoom > 3.0;
214 bool s4 = KoUnit::fromUserValue(st4, m_unit) * m_zoom > 3.0;
216 float cx = KoUnit::fromUserValue(100, m_unit) / m_zoom;
217 TQ_INT32 step = tqRound(cx);
221 }
else if (step < 10) {
223 }
else if (step < 25) {
225 }
else if (step < 50) {
227 }
else if (step < 100) {
229 }
else if (step < 250) {
231 }
else if (step < 500) {
233 }
else if (step < 1000) {
235 }
else if (step < 2500) {
237 }
else if (step < 5000) {
239 }
else if (step < 10000) {
241 }
else if (step < 25000) {
243 }
else if (step < 50000) {
245 }
else if (step < 100000) {
251 TQ_INT32 start = (TQ_INT32)(KoUnit::fromUserValue(m_firstVisible, m_unit) / m_zoom);
254 if (m_orientation == TQt::Horizontal) {
256 pos = (TQ_INT32)(KoUnit::fromUserValue(start, m_unit) * m_zoom - m_firstVisible);
258 if (!s3 && s4 && start % st4 == 0)
259 p.drawLine(pos, RULER_THICKNESS - 9, pos, RULER_THICKNESS);
261 if (s3 && start % st3 == 0)
262 p.drawLine(pos, RULER_THICKNESS - 9, pos, RULER_THICKNESS);
264 if (s2 && start % st2 == 0)
265 p.drawLine(pos, RULER_THICKNESS - 7, pos, RULER_THICKNESS);
267 if (s1 && start % st1 == 0)
268 p.drawLine(pos, RULER_THICKNESS - 5, pos, RULER_THICKNESS);
270 if (start % step == 0) {
271 buf.setNum(TQABS(start));
272 drawNums(&p, pos, 4, buf,
true);
276 }
while (pos < m_pixmapBuffer->width());
279 pos = (TQ_INT32)(KoUnit::fromUserValue(start, m_unit) * m_zoom - m_firstVisible);
281 if (!s3 && s4 && start % st4 == 0)
282 p.drawLine(RULER_THICKNESS - 9, pos, RULER_THICKNESS, pos);
284 if (s3 && start % st3 == 0)
285 p.drawLine(RULER_THICKNESS - 9, pos, RULER_THICKNESS, pos);
287 if (s2 && start % st2 == 0)
288 p.drawLine(RULER_THICKNESS - 7, pos, RULER_THICKNESS, pos);
290 if (s1 && start % st1 == 0)
291 p.drawLine(RULER_THICKNESS - 5, pos, RULER_THICKNESS, pos);
293 if (start % step == 0) {
294 buf.setNum(TQABS(start));
295 drawNums(&p, 4, pos, buf,
false);
299 }
while (pos < m_pixmapBuffer->height());
305void KisRuler::resizeEvent(TQResizeEvent *)
310void KisRuler::styleChange(TQStyle& oldStyle)
317void KisRuler::paletteChange(
const TQPalette& oldPalette)
319 Q_UNUSED(oldPalette);
325 if (m_orientation == TQt::Horizontal) {
326 setFixedHeight(RULER_THICKNESS);
327 initMarker(MARKER_WIDTH, MARKER_HEIGHT);
329 setFixedWidth(RULER_THICKNESS);
330 initMarker(MARKER_HEIGHT, MARKER_WIDTH);
347void KisRuler::drawNums(TQPainter *p, TQ_INT32 x, TQ_INT32 y, TQString& num,
bool orientationHoriz)
349 if (orientationHoriz)
354 for (TQ_UINT32 k = 0; k < num.length(); k++) {
355 TQ_INT32 st = num.at(k).digitValue() * 7;
357 p->drawPixmap(x, y, m_pixmapNums, st, 0, 7, 7);
359 if (orientationHoriz)
366#include "kis_ruler.moc"