12#include <QStylePainter>
15#define INIT_MIN_VALUE 0
16#define INIT_MAX_VALUE 100
17#define INIT_TINY_MARK_DISTANCE 1
18#define INIT_LITTLE_MARK_DISTANCE 5
19#define INIT_MIDDLE_MARK_DISTANCE (INIT_LITTLE_MARK_DISTANCE * 2)
20#define INIT_BIG_MARK_DISTANCE (INIT_LITTLE_MARK_DISTANCE * 10)
21#define INIT_SHOW_TINY_MARK false
22#define INIT_SHOW_LITTLE_MARK true
23#define INIT_SHOW_MEDIUM_MARK true
24#define INIT_SHOW_BIG_MARK true
25#define INIT_SHOW_END_MARK true
26#define INIT_SHOW_POINTER true
27#define INIT_SHOW_END_LABEL true
29#define INIT_PIXEL_PER_MARK (double)10.0
30#define INIT_OFFSET (-20)
31#define INIT_LENGTH_FIX true
32#define INIT_END_OFFSET 0
35#define LINE_END (FIX_WIDTH - 3)
36#define END_MARK_LENGTH (FIX_WIDTH - 6)
37#define END_MARK_X2 LINE_END
38#define END_MARK_X1 (END_MARK_X2 - END_MARK_LENGTH)
39#define BIG_MARK_LENGTH (END_MARK_LENGTH * 3 / 4)
40#define BIG_MARK_X2 LINE_END
41#define BIG_MARK_X1 (BIG_MARK_X2 - BIG_MARK_LENGTH)
42#define MIDDLE_MARK_LENGTH (END_MARK_LENGTH / 2)
43#define MIDDLE_MARK_X2 LINE_END
44#define MIDDLE_MARK_X1 (MIDDLE_MARK_X2 - MIDDLE_MARK_LENGTH)
45#define LITTLE_MARK_LENGTH (MIDDLE_MARK_LENGTH / 2)
46#define LITTLE_MARK_X2 LINE_END
47#define LITTLE_MARK_X1 (LITTLE_MARK_X2 - LITTLE_MARK_LENGTH)
48#define BASE_MARK_LENGTH (LITTLE_MARK_LENGTH / 2)
49#define BASE_MARK_X2 LINE_END
50#define BASE_MARK_X1 (BASE_MARK_X2 - BASE_MARK_LENGTH)
54#define END_LABEL_Y (END_LABEL_X + LABEL_SIZE - 2)
100 , d(new KRulerPrivate)
102 setRange(INIT_MIN_VALUE, INIT_MAX_VALUE);
111 , d(new KRulerPrivate)
113 setRange(INIT_MIN_VALUE, INIT_MAX_VALUE);
127 , d(new KRulerPrivate)
129 setRange(INIT_MIN_VALUE, INIT_MAX_VALUE);
143 d->showpointer = INIT_SHOW_POINTER;
144 d->showEndL = INIT_SHOW_END_LABEL;
145 d->lengthFix = INIT_LENGTH_FIX;
146 d->endOffset_length = INIT_END_OFFSET;
148 d->tmDist = INIT_TINY_MARK_DISTANCE;
149 d->lmDist = INIT_LITTLE_MARK_DISTANCE;
150 d->mmDist = INIT_MIDDLE_MARK_DISTANCE;
151 d->bmDist = INIT_BIG_MARK_DISTANCE;
152 d->offset = INIT_OFFSET;
153 d->showtm = INIT_SHOW_TINY_MARK;
154 d->showlm = INIT_SHOW_LITTLE_MARK;
155 d->showmm = INIT_SHOW_MEDIUM_MARK;
156 d->showbm = INIT_SHOW_BIG_MARK;
157 d->showem = INIT_SHOW_END_MARK;
158 d->ppm = INIT_PIXEL_PER_MARK;
166 if (dist != d->tmDist) {
172int KRuler::tinyMarkDistance()
const
179 if (dist != d->lmDist) {
185int KRuler::littleMarkDistance()
const
192 if (dist != d->mmDist) {
198int KRuler::mediumMarkDistance()
const
205 if (dist != d->bmDist) {
211int KRuler::bigMarkDistance()
const
218 if (
show != d->showtm) {
224bool KRuler::showTinyMarks()
const
231 if (
show != d->showlm) {
237bool KRuler::showLittleMarks()
const
244 if (
show != d->showmm) {
250bool KRuler::showMediumMarks()
const
257 if (
show != d->showbm) {
263bool KRuler::showBigMarks()
const
270 if (
show != d->showem) {
276bool KRuler::showEndMarks()
const
283 if (
show != d->showpointer) {
284 d->showpointer =
show;
289bool KRuler::showPointer()
const
291 return d->showpointer;
296 if (d->showEndL !=
show) {
302bool KRuler::showEndLabel()
const
321QString KRuler::endLabel()
const
409double KRuler::pixelPerMark()
const
420 tmp =
width() - length;
422 if (tmp != d->endOffset_length) {
423 d->endOffset_length = tmp;
428int KRuler::length()
const
431 return d->endOffset_length;
433 return (
width() - d->endOffset_length);
441bool KRuler::lengthFixed()
const
449 if (d->offset != _offset) {
455int KRuler::offset()
const
460int KRuler::endOffset()
const
463 return (
width() - d->endOffset_length);
465 return d->endOffset_length;
486 int oldvalue =
value();
487 if (oldvalue == _value) {
492 if (
value() == oldvalue) {
498 QRect oldrec(-5 + oldvalue, 10, 11, 6);
499 QRect newrec(-5 + _value, 10, 11, 6);
502 QRect oldrec(10, -5 + oldvalue, 6, 11);
503 QRect newrec(10, -5 + _value, 6, 11);
510 if (d->offset != _offset) {
517void KRuler::slotEndOffset(
int offset)
521 tmp =
width() - offset;
525 if (d->endOffset_length != tmp) {
526 d->endOffset_length = tmp;
539 for (
int profile = 0; profile < 10; profile++) {
546 maxval =
maximum() + d->offset - (d->lengthFix ? (
height() - d->endOffset_length) : d->endOffset_length);
548 maxval =
maximum() + d->offset - (d->lengthFix ? (
width() - d->endOffset_length) : d->endOffset_length);
556 double offsetmin = (double)(minval - d->offset);
557 double offsetmax = (double)(maxval - d->offset);
558 double fontOffset = (((double)minval) > offsetmin) ? (
double)minval : offsetmin;
573 p.translate(fontOffset, 0);
574 p.drawText(END_LABEL_X, END_LABEL_Y, d->endlabel);
577#ifdef KRULER_ROTATE_TEST
578 p.rotate(-90.0 + rotate);
579 p.translate(-8.0 - fontOffset - d->fontWidth + xtrans, ytrans);
582 p.translate(-8.0 - fontOffset - d->fontWidth, 0.0);
584 p.drawText(END_LABEL_X, END_LABEL_Y, d->endlabel);
591 fend = d->ppm * d->tmDist;
592 for (f = offsetmin; f < offsetmax; f += fend) {
594 p.drawLine((
int)f, BASE_MARK_X1, (
int)f, BASE_MARK_X2);
596 p.drawLine(BASE_MARK_X1, (
int)f, BASE_MARK_X2, (
int)f);
602 fend = d->ppm * d->lmDist;
603 for (f = offsetmin; f < offsetmax; f += fend) {
605 p.drawLine((
int)f, LITTLE_MARK_X1, (
int)f, LITTLE_MARK_X2);
607 p.drawLine(LITTLE_MARK_X1, (
int)f, LITTLE_MARK_X2, (
int)f);
613 fend = d->ppm * d->mmDist;
614 for (f = offsetmin; f < offsetmax; f += fend) {
616 p.drawLine((
int)f, MIDDLE_MARK_X1, (
int)f, MIDDLE_MARK_X2);
618 p.drawLine(MIDDLE_MARK_X1, (
int)f, MIDDLE_MARK_X2, (
int)f);
624 fend = d->ppm * d->bmDist;
625 for (f = offsetmin; f < offsetmax; f += fend) {
627 p.drawLine((
int)f, BIG_MARK_X1, (
int)f, BIG_MARK_X2);
629 p.drawLine(BIG_MARK_X1, (
int)f, BIG_MARK_X2, (
int)f);
636 p.drawLine(minval - d->offset, END_MARK_X1, minval - d->offset, END_MARK_X2);
637 p.drawLine(maxval - d->offset, END_MARK_X1, maxval - d->offset, END_MARK_X2);
639 p.drawLine(END_MARK_X1, minval - d->offset, END_MARK_X2, minval - d->offset);
640 p.drawLine(END_MARK_X1, maxval - d->offset, END_MARK_X2, maxval - d->offset);
645 if (d->showpointer) {
652 p.setBrush(p.background().color());
658 int elapsed = time.elapsed();
659 debug(
"paint time %i", elapsed);
663#include "moc_kruler.cpp"
void setMediumMarkDistance(int)
Sets the distance between medium marks.
void slotNewOffset(int)
Sets the ruler marks to a new position.
void setPixelPerMark(double rate)
Sets the number of pixels between two base marks.
void setShowEndLabel(bool)
Show/hide number values of the end marks.
KRuler(QWidget *parent=nullptr)
Constructs a horizontal ruler.
void setLittleMarkDistance(int)
Sets the distance between little marks.
void setShowBigMarks(bool)
Shows/hides big marks.
void setShowTinyMarks(bool)
Shows/hides tiny marks.
void slideUp(int count=1)
Sets the number of pixels by which the ruler may slide up or left.
void setRulerMetricStyle(KRuler::MetricStyle)
Sets up the necessary tasks for the provided styles.
void setLengthFixed(bool fix)
Locks the length of the ruler, i.e.
void setEndLabel(const QString &)
Sets the label this is drawn at the beginning of the visible part of the ruler to label.
void setOffset(int offset)
Sets the ruler slide offset.
~KRuler() override
Destructor.
void slideDown(int count=1)
Sets the number of pixels by which the ruler may slide down or right.
void setShowEndMarks(bool)
Shows/hides end marks.
void setBigMarkDistance(int)
Sets distance between big marks.
void setTinyMarkDistance(int)
Sets the distance between tiny marks.
void slotNewValue(int)
Sets the pointer to a new position.
void setShowPointer(bool)
Shows/hides the pointer.
void setShowLittleMarks(bool)
Shows/hides little marks.
void setLength(int)
Sets the length of the ruler, i.e.
MetricStyle
The types of units used.
void setShowMediumMarks(bool)
Shows/hides medium marks.
void setRange(int min, int max)
void setPointSize(int pointSize)
int horizontalAdvance(QChar ch) const const
QRect united(const QRect &rectangle) const const
QRect contentsRect() const const