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
102 bool showpointer : 1;
115 , d( new KRulerPrivate )
120 init(Qt::Horizontal);
128 , d( new KRulerPrivate )
135 if (orient == Qt::Horizontal)
145 , d( new KRulerPrivate )
152 if (orient == Qt::Horizontal)
159 void KRuler::init(Qt::Orientation orientation)
162 #warning FIXME setFrameStyle(WinPanel | Raised);
190 #ifndef KDE_NO_DEPRECATED
198 #ifndef KDE_NO_DEPRECATED
204 #ifndef KDE_NO_DEPRECATED
212 #ifndef KDE_NO_DEPRECATED
221 if (dist != d->tmDist) {
229 {
return d->tmDist; }
234 if (dist != d->lmDist) {
242 {
return d->lmDist; }
247 if (dist != d->mmDist) {
255 {
return d->mmDist; }
260 if (dist != d->bmDist) {
268 {
return d->bmDist; }
273 if (show != d->showtm) {
288 if (show != d->showlm) {
303 if (show != d->showmm) {
318 if (show != d->showbm) {
334 if (show != d->showem) {
349 if (show != d->showpointer) {
350 d->showpointer =
show;
359 return d->showpointer;
366 #warning implement me (jowenn)
373 if (d->showEndL != show) {
393 if (d->dir == Qt::Vertical) {
397 d->fontWidth = fm.
width(d->endlabel);
505 if (tmp != d->endOffset_length) {
506 d->endOffset_length = tmp;
515 return d->endOffset_length;
517 return (
width() - d->endOffset_length);
536 if (d->offset != _offset) {
544 {
return d->offset; }
550 return (
width() - d->endOffset_length);
552 return d->endOffset_length;
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);
595 QRect oldrec(10,-5+oldvalue, 6,11);
596 QRect newrec(10,-5+_value, 6,11);
604 if (d->offset != _offset) {
622 if (d->endOffset_length != tmp) {
623 d->endOffset_length = tmp;
637 for (
int profile=0; profile<10; profile++) {
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;
675 if (d->dir == Qt::Horizontal) {
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);
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.
void setPointSize(int pointSize)
double pixelPerMark() const
Returns the number of pixels between two base marks.
int tinyMarkDistance() const
Returns the distance between tiny marks.
bool showEndMarks() const
const QBrush & background() const
int littleMarkDistance() const
Returns the distance between little marks.
void setRange(int min, int max)
QRect contentsRect() const
KRuler(QWidget *parent=0)
The style (or look) of the ruler.
const QFont & font() const
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
QRect unite(const QRect &rectangle) const
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
void drawLine(const QLineF &line)
#define INIT_SHOW_TINY_MARK
#define INIT_BIG_MARK_DISTANCE
const QColor & color() const
void setShowEndMarks(bool)
Shows/hides end marks.
void setFont(const QFont &font)
int mediumMarkDistance() const
void setLengthFixed(bool fix)
Locks the length of the ruler, i.e.
Qt::Orientation orientation() const
void setPixelPerMark(double rate)
Sets the number of pixels between two base marks.
bool showBigMarks() const
void setBrush(const QBrush &brush)
void drawText(const QPointF &position, const QString &text)
#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.
int width(const QString &text, int len) const
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
void translate(const QPointF &offset)
#define INIT_SHOW_MEDIUM_MARK
#define INIT_LITTLE_MARK_DISTANCE
#define INIT_PIXEL_PER_MARK
void setPoints(int nPoints, const int *points)
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...