25 #include <QStylePainter>
28 #define INIT_MIN_VALUE 0
29 #define INIT_MAX_VALUE 100
30 #define INIT_TINY_MARK_DISTANCE 1
31 #define INIT_LITTLE_MARK_DISTANCE 5
32 #define INIT_MIDDLE_MARK_DISTANCE (INIT_LITTLE_MARK_DISTANCE * 2)
33 #define INIT_BIG_MARK_DISTANCE (INIT_LITTLE_MARK_DISTANCE * 10)
34 #define INIT_SHOW_TINY_MARK false
35 #define INIT_SHOW_LITTLE_MARK true
36 #define INIT_SHOW_MEDIUM_MARK true
37 #define INIT_SHOW_BIG_MARK true
38 #define INIT_SHOW_END_MARK true
39 #define INIT_SHOW_POINTER true
40 #define INIT_SHOW_END_LABEL true
42 #define INIT_PIXEL_PER_MARK (double)10.0
43 #define INIT_OFFSET (-20)
44 #define INIT_LENGTH_FIX true
45 #define INIT_END_OFFSET 0
48 #define LINE_END (FIX_WIDTH - 3)
49 #define END_MARK_LENGTH (FIX_WIDTH - 6)
50 #define END_MARK_X2 LINE_END
51 #define END_MARK_X1 (END_MARK_X2 - END_MARK_LENGTH)
52 #define BIG_MARK_LENGTH (END_MARK_LENGTH*3/4)
53 #define BIG_MARK_X2 LINE_END
54 #define BIG_MARK_X1 (BIG_MARK_X2 - BIG_MARK_LENGTH)
55 #define MIDDLE_MARK_LENGTH (END_MARK_LENGTH/2)
56 #define MIDDLE_MARK_X2 LINE_END
57 #define MIDDLE_MARK_X1 (MIDDLE_MARK_X2 - MIDDLE_MARK_LENGTH)
58 #define LITTLE_MARK_LENGTH (MIDDLE_MARK_LENGTH/2)
59 #define LITTLE_MARK_X2 LINE_END
60 #define LITTLE_MARK_X1 (LITTLE_MARK_X2 - LITTLE_MARK_LENGTH)
61 #define BASE_MARK_LENGTH (LITTLE_MARK_LENGTH/2)
62 #define BASE_MARK_X2 LINE_END
63 #define BASE_MARK_X1 (BASE_MARK_X2 - BASE_MARK_LENGTH)
67 #define END_LABEL_Y (END_LABEL_X + LABEL_SIZE - 2)
72 # include <qdatetime.h>
75 class KRuler::KRulerPrivate
89 QAbstractSlider range;
102 bool showpointer : 1;
114 : QAbstractSlider(parent)
115 , d( new KRulerPrivate )
120 init(Qt::Horizontal);
126 QWidget *parent, Qt::WindowFlags f)
127 : QAbstractSlider(parent)
128 , d( new KRulerPrivate )
135 if (orient == Qt::Horizontal)
143 QWidget *parent, Qt::WindowFlags f)
144 : QAbstractSlider(parent)
145 , d( new KRulerPrivate )
152 if (orient == Qt::Horizontal)
153 setFixedHeight(widgetWidth);
155 setFixedWidth(widgetWidth);
159 void KRuler::init(Qt::Orientation orientation)
162 #warning FIXME setFrameStyle(WinPanel | Raised);
181 d->dir = orientation;
190 #ifndef KDE_NO_DEPRECATED
198 #ifndef KDE_NO_DEPRECATED
201 {
return minimum(); }
204 #ifndef KDE_NO_DEPRECATED
212 #ifndef KDE_NO_DEPRECATED
215 {
return maximum(); }
221 if (dist != d->tmDist) {
223 update(contentsRect());
229 {
return d->tmDist; }
234 if (dist != d->lmDist) {
236 update(contentsRect());
242 {
return d->lmDist; }
247 if (dist != d->mmDist) {
249 update(contentsRect());
255 {
return d->mmDist; }
260 if (dist != d->bmDist) {
262 update(contentsRect());
268 {
return d->bmDist; }
273 if (show != d->showtm) {
275 update(contentsRect());
288 if (show != d->showlm) {
290 update(contentsRect());
303 if (show != d->showmm) {
305 update(contentsRect());
318 if (show != d->showbm) {
320 update(contentsRect());
334 if (show != d->showem) {
336 update(contentsRect());
349 if (show != d->showpointer) {
350 d->showpointer = show;
351 update(contentsRect());
359 return d->showpointer;
366 #warning implement me (jowenn)
373 if (d->showEndL != show) {
375 update(contentsRect());
393 if (d->dir == Qt::Vertical) {
394 QFont font = this->font();
396 QFontMetrics fm(font);
397 d->fontWidth = fm.width(d->endlabel);
399 update(contentsRect());
425 update(contentsRect());
441 update(contentsRect());
458 update(contentsRect());
488 update(contentsRect());
505 if (tmp != d->endOffset_length) {
506 d->endOffset_length = tmp;
507 update(contentsRect());
515 return d->endOffset_length;
517 return (width() - d->endOffset_length);
536 if (d->offset != _offset) {
538 update(contentsRect());
544 {
return d->offset; }
550 return (width() - d->endOffset_length);
552 return d->endOffset_length;
561 update(contentsRect());
570 update(contentsRect());
578 int oldvalue = value();
579 if (oldvalue == _value) {
584 if (value() == oldvalue) {
589 if (d->dir == Qt::Horizontal) {
590 QRect oldrec(-5+oldvalue,10, 11,6);
591 QRect newrec(-5+_value,10, 11,6);
592 repaint( oldrec.unite(newrec) );
595 QRect oldrec(10,-5+oldvalue, 6,11);
596 QRect newrec(10,-5+_value, 6,11);
597 repaint( oldrec.unite(newrec) );
604 if (d->offset != _offset) {
607 repaint(contentsRect());
622 if (d->endOffset_length != tmp) {
623 d->endOffset_length = tmp;
624 repaint(contentsRect());
633 QStylePainter p(
this);
637 for (
int profile=0; profile<10; profile++) {
640 int value = this->value(),
643 if (d->dir == Qt::Horizontal) {
646 - (d->lengthFix?(height()-d->endOffset_length):d->endOffset_length);
652 - (d->lengthFix?(width()-d->endOffset_length):d->endOffset_length);
659 offsetmin=(
double)(minval-d->offset),
660 offsetmax=(
double)(maxval-d->offset),
661 fontOffset = (((
double)minval)>offsetmin)?(
double)minval:offsetmin;
664 QFont font = p.font();
675 if (d->dir == Qt::Horizontal) {
676 p.translate( fontOffset, 0 );
681 #ifdef KRULER_ROTATE_TEST
682 p.rotate( -90.0 + rotate );
683 p.translate( -8.0 - fontOffset - d->fontWidth + xtrans,
687 p.translate( -8.0 - fontOffset - d->fontWidth, 0.0 );
696 fend = d->ppm*d->tmDist;
697 for ( f=offsetmin; f<offsetmax; f+=fend ) {
698 if (d->dir == Qt::Horizontal) {
708 fend = d->ppm*d->lmDist;
709 for ( f=offsetmin; f<offsetmax; f+=fend ) {
710 if (d->dir == Qt::Horizontal) {
720 fend = d->ppm*d->mmDist;
721 for ( f=offsetmin; f<offsetmax; f+=fend ) {
722 if (d->dir == Qt::Horizontal) {
732 fend = d->ppm*d->bmDist;
733 for ( f=offsetmin; f<offsetmax; f+=fend ) {
734 if (d->dir == Qt::Horizontal) {
744 if (d->dir == Qt::Horizontal) {
755 if (d->showpointer) {
757 if (d->dir == Qt::Horizontal) {
758 pa.setPoints(3, value-5, 10, value+5, 10, value,15);
761 pa.setPoints(3, 10, value-5, 10, value+5, 15, value);
763 p.setBrush( p.background().color() );
769 int elapsed = time.elapsed();
770 debug(
"paint time %i",elapsed);
775 #include "kruler.moc"
#define INIT_MIDDLE_MARK_DISTANCE
bool showMediumMarks() const
int maxValue() const
Returns the maximal value of the ruler pointer.
void slotNewOffset(int)
Sets the ruler marks to a new position.
double pixelPerMark() const
Returns the number of pixels between two base marks.
int tinyMarkDistance() const
Returns the distance between tiny marks.
bool showEndMarks() const
int littleMarkDistance() const
Returns the distance between little marks.
KRuler(QWidget *parent=0)
The style (or look) of the ruler.
void setShowEndLabel(bool)
Show/hide number values of the little marks.
QString label(StandardShortcut id)
Returns a localized label for user-visible display.
void setShowTinyMarks(bool)
Shows/hides tiny marks.
void setMaxValue(int)
Sets the maximum value of the ruler pointer (default is 100).
#define INIT_SHOW_POINTER
#define INIT_SHOW_TINY_MARK
#define INIT_BIG_MARK_DISTANCE
void setShowEndMarks(bool)
Shows/hides end marks.
int mediumMarkDistance() const
void setLengthFixed(bool fix)
Locks the length of the ruler, i.e.
void setPixelPerMark(double rate)
Sets the number of pixels between two base marks.
bool showBigMarks() const
#define INIT_SHOW_BIG_MARK
int bigMarkDistance() const
Returns the distance between big marks.
bool showLittleMarks() const
virtual void paintEvent(QPaintEvent *)
void slotNewValue(int)
Sets the pointer to a new position.
int minValue() const
Returns the minimal value of the ruler pointer.
void setTinyMarkDistance(int)
Sets the distance between tiny marks.
void setMediumMarkDistance(int)
Sets the distance between medium marks.
#define INIT_TINY_MARK_DISTANCE
void setMinValue(int)
Sets the minimal value of the ruler pointer (default is 0).
void setLength(int)
Sets the length of the ruler, i.e.
void setBigMarkDistance(int)
Sets distance between big marks.
bool showEndLabel() const
void setShowLittleMarks(bool)
Shows/hides little marks.
int offset() const
Returns the current ruler offset.
void slideDown(int count=1)
Sets the number of pixels by which the ruler may slide down or right.
bool showTinyMarks() const
#define INIT_SHOW_MEDIUM_MARK
#define INIT_LITTLE_MARK_DISTANCE
#define INIT_PIXEL_PER_MARK
void setRulerMetricStyle(KRuler::MetricStyle)
Sets up the necessary tasks for the provided styles.
void setShowBigMarks(bool)
Shows/hides big marks.
void setLittleMarkDistance(int)
Sets the distance between little marks.
void slideUp(int count=1)
Sets the number of pixels by which the ruler may slide up or left.
#define INIT_SHOW_LITTLE_MARK
void setShowPointer(bool)
Shows/hides the pointer.
void setOffset(int offset)
Sets the ruler slide offset.
MetricStyle
The types of units used.
#define INIT_SHOW_END_LABEL
#define INIT_SHOW_END_MARK
void setShowMediumMarks(bool)
Shows/hides medium marks.
void setEndLabel(const QString &)
Sets the label this is drawn at the beginning of the visible part of the ruler to label...