27#define MARKER_HEIGHT 20
30const char *VRuler::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"
43VRuler::VRuler(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_SIZE);
58 initMarker(MARKER_WIDTH, MARKER_HEIGHT);
60 setFixedWidth(RULER_SIZE);
61 initMarker(MARKER_HEIGHT, MARKER_WIDTH);
67 delete m_pixmapBuffer;
70void VRuler::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 VRuler::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 VRuler::unit()
const
112void VRuler::setUnit(KoUnit::Unit u)
116 updatePointer(m_currentPosition, m_currentPosition);
120void VRuler::setZoom(
double zoom)
125 updatePointer(m_currentPosition, m_currentPosition);
129void VRuler::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 VRuler::updateVisibleArea(TQ_INT32 xpos, TQ_INT32 ypos)
154 if (m_orientation == TQt::Horizontal)
155 m_firstVisible = xpos;
157 m_firstVisible = ypos;
162 updatePointer(m_currentPosition, m_currentPosition);
166void VRuler::paintEvent(TQPaintEvent *e)
168 if (m_pixmapBuffer) {
169 const TQRect& rect = e -> rect();
171 bitBlt(
this, rect.topLeft(), m_pixmapBuffer, rect);
172 super::paintEvent(e);
176void VRuler::drawRuler()
189 p.begin(m_pixmapBuffer);
190 p.setPen(TQColor(0x70, 0x70, 0x70));
191 p.setBackgroundColor(colorGroup().background());
192 p.eraseRect(0, 0, m_pixmapBuffer -> width(), m_pixmapBuffer -> height());
219 bool s1 = KoUnit::fromUserValue(st1, m_unit) * m_zoom > 3.0;
220 bool s2 = KoUnit::fromUserValue(st2, m_unit) * m_zoom > 3.0;
221 bool s3 = KoUnit::fromUserValue(st3, m_unit) * m_zoom > 3.0;
222 bool s4 = KoUnit::fromUserValue(st4, m_unit) * m_zoom > 3.0;
224 if (m_orientation == TQt::Horizontal) {
226 float cx = KoUnit::fromUserValue(100, m_unit) / m_zoom;
227 TQ_INT32 step = tqRound(cx);
228 TQ_INT32 start = (TQ_INT32)(KoUnit::toUserValue(m_firstVisible, m_unit) / m_zoom);
231 pos = (TQ_INT32)(KoUnit::fromUserValue(start, m_unit) * m_zoom - m_firstVisible);
233 if (!s3 && s4 && start % st4 == 0)
234 p.drawLine(pos, RULER_SIZE - 9, pos, RULER_SIZE);
236 if (s3 && start % st3 == 0)
237 p.drawLine(pos, RULER_SIZE - 9, pos, RULER_SIZE);
239 if (s2 && start % st2 == 0)
240 p.drawLine(pos, RULER_SIZE - 7, pos, RULER_SIZE);
242 if (s1 && start % st1 == 0)
243 p.drawLine(pos, RULER_SIZE - 5, pos, RULER_SIZE);
245 if (step && start % step == 0) {
246 buf.setNum(TQABS(start));
247 drawNums(&p, pos, 4, buf,
true);
251 }
while (pos < m_pixmapBuffer -> width());
254 float cx = KoUnit::fromUserValue(100, m_unit) / m_zoom;
255 TQ_INT32 height = m_pixmapBuffer -> height() - 1;
256 TQ_INT32 step = tqRound(cx);
257 TQ_INT32 start = (TQ_INT32)(KoUnit::toUserValue(m_firstVisible, m_unit) / m_zoom);
260 pos = height - (TQ_INT32)(KoUnit::fromUserValue(start, m_unit) * m_zoom - m_firstVisible);
262 if (!s3 && s4 && start % st4 == 0)
263 p.drawLine(RULER_SIZE - 9, pos, RULER_SIZE, pos);
265 if (s3 && start % st3 == 0)
266 p.drawLine(RULER_SIZE - 9, pos, RULER_SIZE, pos);
268 if (s2 && start % st2 == 0)
269 p.drawLine(RULER_SIZE - 7, pos, RULER_SIZE, pos);
271 if (s1 && start % st1 == 0)
272 p.drawLine(RULER_SIZE - 5, pos, RULER_SIZE, pos);
274 if (step && start % step == 0) {
275 buf.setNum(TQABS(start));
276 drawNums(&p, 4, pos, buf,
false);
286void VRuler::resizeEvent(TQResizeEvent *)
293 if (m_orientation == TQt::Horizontal) {
294 setFixedHeight(RULER_SIZE);
295 initMarker(MARKER_WIDTH, MARKER_HEIGHT);
297 setFixedWidth(RULER_SIZE);
298 initMarker(MARKER_HEIGHT, MARKER_WIDTH);
306 if (m_orientation == TQt::Horizontal)
312void VRuler::drawNums(TQPainter *p, TQ_INT32 x, TQ_INT32 y, TQString& num,
bool orientationHoriz)
314 if (orientationHoriz)
319 for (TQ_UINT32 k = 0; k < num.length(); k++) {
320 TQ_INT32 st = num.at(k).digitValue() * 7;
322 p -> drawPixmap(x, y, m_pixmapNums, st, 0, 7, 7);
324 if (orientationHoriz)