23 #include <tqpainter.h>
27 #define INIT_MIN_VALUE 0
28 #define INIT_MAX_VALUE 100
29 #define INIT_TINY_MARK_DISTANCE 1
30 #define INIT_LITTLE_MARK_DISTANCE 5
31 #define INIT_MIDDLE_MARK_DISTANCE (INIT_LITTLE_MARK_DISTANCE * 2)
32 #define INIT_BIG_MARK_DISTANCE (INIT_LITTLE_MARK_DISTANCE * 10)
33 #define INIT_SHOW_TINY_MARK false
34 #define INIT_SHOW_LITTLE_MARK true
35 #define INIT_SHOW_MEDIUM_MARK true
36 #define INIT_SHOW_BIG_MARK true
37 #define INIT_SHOW_END_MARK true
38 #define INIT_SHOW_POINTER true
39 #define INIT_SHOW_END_LABEL true
41 #define INIT_PIXEL_PER_MARK (double)10.0
42 #define INIT_OFFSET (-20)
43 #define INIT_LENGTH_FIX true
44 #define INIT_END_OFFSET 0
47 #define LINE_END (FIX_WIDTH - 3)
48 #define END_MARK_LENGTH (FIX_WIDTH - 6)
49 #define END_MARK_X2 LINE_END
50 #define END_MARK_X1 (END_MARK_X2 - END_MARK_LENGTH)
51 #define BIG_MARK_LENGTH (END_MARK_LENGTH*3/4)
52 #define BIG_MARK_X2 LINE_END
53 #define BIG_MARK_X1 (BIG_MARK_X2 - BIG_MARK_LENGTH)
54 #define MIDDLE_MARK_LENGTH (END_MARK_LENGTH/2)
55 #define MIDDLE_MARK_X2 LINE_END
56 #define MIDDLE_MARK_X1 (MIDDLE_MARK_X2 - MIDDLE_MARK_LENGTH)
57 #define LITTLE_MARK_LENGTH (MIDDLE_MARK_LENGTH/2)
58 #define LITTLE_MARK_X2 LINE_END
59 #define LITTLE_MARK_X1 (LITTLE_MARK_X2 - LITTLE_MARK_LENGTH)
60 #define BASE_MARK_LENGTH (LITTLE_MARK_LENGTH/2)
61 #define BASE_MARK_X2 LINE_END
62 #define BASE_MARK_X1 (BASE_MARK_X2 - BASE_MARK_LENGTH)
66 #define END_LABEL_Y (END_LABEL_X + LABEL_SIZE - 2)
71 # include <tqdatetime.h>
74 class KRuler::KRulerPrivate
95 : TQFrame(parent, name),
96 range(INIT_MIN_VALUE, INIT_MAX_VALUE, 1, 10, INIT_VALUE),
100 setFixedHeight(FIX_WIDTH);
105 TQWidget *parent,
const char *name, WFlags f)
106 : TQFrame(parent, name, f),
107 range(INIT_MIN_VALUE, INIT_MAX_VALUE, 1, 10, INIT_VALUE),
111 if (orient == TQt::Horizontal)
112 setFixedHeight(FIX_WIDTH);
114 setFixedWidth(FIX_WIDTH);
119 TQWidget *parent,
const char *name, WFlags f)
120 : TQFrame(parent, name, f),
121 range(INIT_MIN_VALUE, INIT_MAX_VALUE, 1, 10, INIT_VALUE),
126 if (orient == TQt::Horizontal)
127 setFixedHeight(widgetWidth);
129 setFixedWidth(widgetWidth);
135 setFrameStyle(WinPanel | Raised);
137 tmDist = INIT_TINY_MARK_DISTANCE;
138 lmDist = INIT_LITTLE_MARK_DISTANCE;
139 mmDist = INIT_MIDDLE_MARK_DISTANCE;
140 bmDist = INIT_BIG_MARK_DISTANCE;
141 offset_= INIT_OFFSET;
142 showtm = INIT_SHOW_TINY_MARK;
143 showlm = INIT_SHOW_LITTLE_MARK;
144 showmm = INIT_SHOW_MEDIUM_MARK;
145 showbm = INIT_SHOW_BIG_MARK;
146 showem = INIT_SHOW_END_MARK;
147 ppm = INIT_PIXEL_PER_MARK;
149 d =
new KRuler::KRulerPrivate;
150 d->showpointer = INIT_SHOW_POINTER;
151 d->showEndL = INIT_SHOW_END_LABEL;
152 d->lengthFix = INIT_LENGTH_FIX;
153 d->endOffset_length = INIT_END_OFFSET;
165 if (range.minValue() != value) {
166 range.setRange( value, range.maxValue() );
167 update(contentsRect());
174 if (range.maxValue() != value) {
175 range.setRange( range.minValue(), value );
176 update(contentsRect());
183 if ((range.minValue() != min) || (range.maxValue() != max)) {
184 range.setRange( min, max );
185 update(contentsRect());
192 range.setValue(value);
193 update(contentsRect());
199 if (dist != tmDist) {
201 update(contentsRect());
208 if (dist != lmDist) {
210 update(contentsRect());
217 if (dist != mmDist) {
219 update(contentsRect());
226 if (dist != bmDist) {
228 update(contentsRect());
235 if (show != showtm) {
237 update(contentsRect());
242 KRuler::showTinyMarks()
const
250 if (show != showlm) {
252 update(contentsRect());
257 KRuler::showLittleMarks()
const
265 if (show != showmm) {
267 update(contentsRect());
272 KRuler::showMediumMarks()
const
280 if (show != showbm) {
282 update(contentsRect());
288 KRuler::showBigMarks()
const
296 if (show != showem) {
298 update(contentsRect());
303 KRuler::showEndMarks()
const
311 if (show != d->showpointer) {
312 d->showpointer = show;
313 update(contentsRect());
319 KRuler::showPointer()
const
321 return d->showpointer;
327 update(contentsRect());
333 update(contentsRect());
339 update(contentsRect());
345 if (d->showEndL != show) {
347 update(contentsRect());
353 KRuler::showEndLabel()
const
365 if (dir == TQt::Vertical) {
366 TQFont font = this->font();
367 font.setPointSize(LABEL_SIZE);
368 TQFontMetrics fm(font);
369 d->fontWidth = fm.width(endlabel);
371 update(contentsRect());
374 TQString KRuler::endLabel()
const
397 update(contentsRect());
413 update(contentsRect());
430 update(contentsRect());
460 update(contentsRect());
472 tmp = this->width() - length;
474 if (tmp != d->endOffset_length) {
475 d->endOffset_length = tmp;
476 update(contentsRect());
481 KRuler::length()
const
484 return d->endOffset_length;
486 return (this->width() - d->endOffset_length);
497 KRuler::lengthFixed()
const
505 if (offset_ != _offset) {
507 update(contentsRect());
512 KRuler::endOffset()
const
515 return (this->width() - d->endOffset_length);
517 return d->endOffset_length;
526 update(contentsRect());
535 update(contentsRect());
543 int oldvalue = range.value();
544 if (oldvalue == _value) {
548 range.setValue(_value);
549 if (range.value() == oldvalue) {
554 if (dir == TQt::Horizontal) {
555 TQRect oldrec(-5+oldvalue,10, 11,6);
556 TQRect newrec(-5+_value,10, 11,6);
557 repaint( oldrec.unite(newrec) );
560 TQRect oldrec(10,-5+oldvalue, 6,11);
561 TQRect newrec(10,-5+_value, 6,11);
562 repaint( oldrec.unite(newrec) );
569 if (offset_ != _offset) {
572 repaint(contentsRect());
578 KRuler::slotEndOffset(
int offset)
582 tmp = this->width() -
offset;
587 if (d->endOffset_length != tmp) {
588 d->endOffset_length = tmp;
589 repaint(contentsRect());
594 KRuler::drawContents(TQPainter *p)
601 for (
int profile=0; profile<10; profile++) {
604 int value = range.value(),
605 minval = range.minValue(),
607 if (dir == TQt::Horizontal) {
608 maxval = range.maxValue()
610 - (d->lengthFix?(height()-d->endOffset_length):d->endOffset_length);
614 maxval = range.maxValue()
616 - (d->lengthFix?(width()-d->endOffset_length):d->endOffset_length);
623 offsetmin=(double)(minval-offset_),
624 offsetmax=(double)(maxval-offset_),
625 fontOffset = (((double)minval)>offsetmin)?(
double)minval:offsetmin;
628 TQFont font = p->font();
629 font.setPointSize(LABEL_SIZE);
639 if (dir == TQt::Horizontal) {
640 p->translate( fontOffset, 0 );
641 p->drawText( END_LABEL_X, END_LABEL_Y, endlabel );
645 #ifdef KRULER_ROTATE_TEST
646 p->rotate( -90.0 + rotate );
647 p->translate( -8.0 - fontOffset - d->fontWidth + xtrans,
651 p->translate( -8.0 - fontOffset - d->fontWidth, 0.0 );
653 p->drawText( END_LABEL_X, END_LABEL_Y, endlabel );
661 for ( f=offsetmin; f<offsetmax; f+=fend ) {
662 if (dir == TQt::Horizontal) {
663 p->drawLine((
int)f, BASE_MARK_X1, (int)f, BASE_MARK_X2);
666 p->drawLine(BASE_MARK_X1, (
int)f, BASE_MARK_X2, (int)f);
673 for ( f=offsetmin; f<offsetmax; f+=fend ) {
674 if (dir == TQt::Horizontal) {
675 p->drawLine((
int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2);
678 p->drawLine(LITTLE_MARK_X1, (
int)f, LITTLE_MARK_X2, (int)f);
685 for ( f=offsetmin; f<offsetmax; f+=fend ) {
686 if (dir == TQt::Horizontal) {
687 p->drawLine((
int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2);
690 p->drawLine(MIDDLE_MARK_X1, (
int)f, MIDDLE_MARK_X2, (int)f);
697 for ( f=offsetmin; f<offsetmax; f+=fend ) {
698 if (dir == TQt::Horizontal) {
699 p->drawLine((
int)f, BIG_MARK_X1, (int)f, BIG_MARK_X2);
702 p->drawLine(BIG_MARK_X1, (
int)f, BIG_MARK_X2, (int)f);
708 if (dir == TQt::Horizontal) {
709 p->drawLine(minval-offset_, END_MARK_X1, minval-offset_, END_MARK_X2);
710 p->drawLine(maxval-offset_, END_MARK_X1, maxval-offset_, END_MARK_X2);
713 p->drawLine(END_MARK_X1, minval-offset_, END_MARK_X2, minval-offset_);
714 p->drawLine(END_MARK_X1, maxval-offset_, END_MARK_X2, maxval-offset_);
719 if (d->showpointer) {
721 if (dir == TQt::Horizontal) {
722 pa.setPoints(3, value-5, 10, value+5, 10, value,15);
725 pa.setPoints(3, 10, value-5, 10, value+5, 15, value);
727 p->setBrush( p->backgroundColor() );
728 p->drawPolygon( pa );
733 int elapsed = time.elapsed();
734 debug(
"paint time %i",elapsed);
739 void KRuler::virtual_hook(
int,
void* )
742 #include "kruler.moc"
void setMediumMarkDistance(int)
Sets the distance between medium marks.
int offset() const
Returns the current ruler offset.
void slotNewOffset(int)
Sets the ruler marks to a new position.
void setValuePerMediumMark(int) TDE_DEPRECATED
void setPixelPerMark(double rate)
Sets the number of pixels between two base marks.
void setShowEndLabel(bool)
Show/hide number values of the little marks.
void setRange(int min, int max)
Sets minimum and maximum values of the ruler pointer.
void setMaxValue(int)
Sets the maximum value of the ruler pointer (default is 100).
void setValue(int)
Sets the value of the ruler pointer.
KRuler(TQWidget *parent=0, const char *name=0)
The style (or look) of the 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 setValuePerBigMark(int) TDE_DEPRECATED
void setLengthFixed(bool fix)
Locks the length of the ruler, i.e.
void setMinValue(int)
Sets the minimal value of the ruler pointer (default is 0).
void setValuePerLittleMark(int) TDE_DEPRECATED
void setOffset(int offset)
Sets the ruler slide offset.
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 setEndLabel(const TQString &)
Sets the label this is drawn at the beginning of the visible part of the ruler to label.
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.