summaryrefslogtreecommitdiffstats
path: root/tdeui/kruler.h
blob: 6279d567df9c3caf4aebdb78e56cca924a1aff1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
/* This file is part of the KDE libraries
    Copyright (C) 1998 Jörg Habenicht (j.habenicht@europemail.com)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef KRULER_H
#define KRULER_H

#include <tqframe.h>
#include <tqrangecontrol.h>
#include <tdelibs_export.h>

/**
 * A ruler widget.
 *
 * The vertical ruler looks similar to this:
 *
 *\code
 *    meters                       inches
 *
 *    ------   <--- end mark  ---> ------
 *        --                            -
 *        --   <---little mark--->     --
 *        --                            -
 *        --                          ---
 *       ---   <---medium mark          -
 *        --                           --
 *        --        tiny mark---->      -
 *        --                         ----
 *        --                            -
 *      ----   <-----big mark          --
 *        --                            -
 *      |>--   <--ruler pointer-->   |>--
 *
 * \endcode
 *
 * There are tiny marks, little marks, medium marks, and big marks along the
 *  ruler.
 *
 * To receive mouse clicks or mouse moves,
 * the class has to be overloaded.
 *
 * For performance reasons, the public methods don't call TQWidget::repaint().
 * (Slots do, see documentation below.)
 * All the changed settings will be painted once after leaving
 * to the main event loop.
 * For performance painting the slot methods should be used,
 * they do a fast TQWidget::repaint() call after changing the values.
 * For setting multiple values like minValue(), maxValue(), offset() etc.
 * using the public methods is recommended
 * so the widget will be painted only once when entering the main event loop.
 *
 * @short A ruler widget.
 * @author Jörg Habenicht
 */
class TDEUI_EXPORT KRuler : public TQFrame
{
  TQ_OBJECT
  TQ_PROPERTY( int minValue READ minValue WRITE setMinValue )
  TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
  TQ_PROPERTY( int value READ value WRITE setValue )
  TQ_PROPERTY( bool showTinyMarks READ showTinyMarks WRITE setShowTinyMarks )
  TQ_PROPERTY( bool showLittleMarks READ showLittleMarks WRITE setShowLittleMarks )
  TQ_PROPERTY( bool showMediumMarks READ showMediumMarks WRITE setShowMediumMarks )
  TQ_PROPERTY( bool showBigMarks READ showBigMarks WRITE setShowBigMarks )
  TQ_PROPERTY( bool showPointer READ showPointer WRITE setShowPointer )
  TQ_PROPERTY( bool showEndLabel READ showEndLabel WRITE setShowEndLabel )
  TQ_PROPERTY( int tinyMarkDistance READ tinyMarkDistance WRITE setTinyMarkDistance )
  TQ_PROPERTY( int littleMarkDistance READ littleMarkDistance WRITE setLittleMarkDistance )
  TQ_PROPERTY( int mediumMarkDistance READ mediumMarkDistance WRITE setBigMarkDistance )
  TQ_PROPERTY( int bigMarkDistance READ bigMarkDistance WRITE setBigMarkDistance )
  TQ_PROPERTY( double pixelPerMark READ pixelPerMark WRITE setPixelPerMark )
  TQ_PROPERTY( bool lengthFixed READ lengthFixed WRITE setLengthFixed )

public:

/*
#define KRULER_ROTATE_TEST KRULER_ROTATE_TEST
#undef KRULER_ROTATE_TEST
#ifdef KRULER_ROTATE_TEST
  double xtrans, ytrans, rotate;
# warning tmporaer variablen eingeschaltet
#endif
*/

  /**
   * The types of units used.
   **/
  enum MetricStyle { Custom=0, Pixel, Inch, Millimetres, Centimetres, Metres };

  /**
   * The style (or look) of the ruler.
   **/
    //  enum PaintStyle { Flat, Raised, Sunken };

  /**
   * Constructs a horizontal ruler.
   */
  KRuler(TQWidget *parent=0, const char *name=0);
  /**
   * Constructs a ruler with orientation @p orient.
   *
   * @p parent, @p name and @p f are passed to TQFrame.
   * The default look is a raised widget
   * but may be changed with the inherited TQFrame methods.
   *
   * @param orient     Orientation of the ruler.
   * @param parent     Will be handed over to TQFrame.
   * @param name       Will be handed over to TQFrame.
   * @param f          Will be handed over to TQFrame.
   *
   **/
  KRuler(Orientation orient, TQWidget *parent=0, const char *name=0,
	 WFlags f=0);

  /**
   * Constructs a ruler with orientation @p orient and initial width @p widgetWidth.
   *
   * The width sets the fixed width of the widget. This is useful if you
   * want to draw the ruler bigger or smaller than the default size.
   * Note: The size of the marks doesn't change.
   * @p parent, @p name and @p f are passed to TQFrame.
   *
   * @param orient      Orientation of the ruler.
   * @param widgetWidth Fixed width of the widget.
   * @param parent      Will be handed over to TQFrame.
   * @param name        Will be handed over to TQFrame.
   * @param f           Will be handed over to TQFrame.
   *
   */
  KRuler(Orientation orient, int widgetWidth, TQWidget *parent=0,
	 const char *name=0, WFlags f=0);

  /**
   * Destructor.
   */
  ~KRuler();

  /**
   * Sets the minimal value of the ruler pointer (default is 0).
   *
   * This method calls update() so that the widget is painted after leaving
   * to the main event loop.
   *
   **/
  void setMinValue(int);

  /**
   * Returns the minimal value of the ruler pointer.
   **/
  inline int minValue() const;

  /**
   * Sets the maximum value of the ruler pointer (default is 100).
   *
   * This method calls update() so that the widget is painted after leaving
   * to the main event loop.
   */
  void setMaxValue(int);

  /**
   * Returns the maximal value of the ruler pointer.
   */
  inline int maxValue() const;

  /**
   * Sets minimum and maximum values of the ruler pointer.
   *
   * This method calls update() so that the widget is painted after leaving
   * to the main event loop.
   */
  void setRange(int min, int max);

  /**
   * Sets the value of the ruler pointer.
   *
   * The value is indicated by painting the ruler pointer at the
   * corresponding position.
   * This method calls update() so that the widget is painted after leaving
   * to the main event loop.
   */
  void setValue(int);
  inline int value() const;

  /**
   * Sets the distance between tiny marks.
   *
   * This is mostly used in the English system (inches) with distance of 1.
   */
  void setTinyMarkDistance(int);
  /**
   * Returns the distance between tiny marks.
   **/
  inline int tinyMarkDistance() const;

  /**
   * Sets the distance between little marks.
   *
   * The default value is 1 in the metric system and 2 in the English (inches) system.
   */
  void setLittleMarkDistance(int);

  /**
   * Returns the distance between little marks.
   */
  inline int littleMarkDistance() const;

  /**
   * Sets the distance between medium marks.
   *
   * For English (inches) styles it defaults to twice the little mark distance.
   * For metric styles it defaults to five times the little mark distance.
   **/
  void setMediumMarkDistance(int);
  inline int mediumMarkDistance() const;

  /**
   * Sets distance between big marks.
   *
   * For English (inches) or metric styles it is twice the medium mark distance.
   **/
  void setBigMarkDistance(int);
  /**
   * Returns the distance between big marks.
   **/
  inline int bigMarkDistance() const;

  /**
   * Shows/hides tiny marks.
   **/
  void setShowTinyMarks(bool);
  bool showTinyMarks() const;
  /**
   * Shows/hides little marks.
   **/
  void setShowLittleMarks(bool);
  bool showLittleMarks() const;
  /**
   * Shows/hides medium marks.
   **/
  void setShowMediumMarks(bool);
  bool showMediumMarks() const;
  /**
   * Shows/hides big marks.
   **/
  void setShowBigMarks(bool);
  bool showBigMarks() const;
  /**
   * Shows/hides end marks.
   **/
  void setShowEndMarks(bool);
  bool showEndMarks() const;
  /**
   * Shows/hides the pointer.
   */
  void setShowPointer(bool);
  bool showPointer() const;

  //#### KDE4: The next 3 need to go.
  /**
   * @deprecated
   * This method has no effect other than an update. Do not use.
   **/
  void setValuePerLittleMark(int) TDE_DEPRECATED;

  /**
   * @deprecated
   * This method has no effect other than an update. Do not use.
   **/
  void setValuePerMediumMark(int) TDE_DEPRECATED;

  /**
   * @deprecated
   * This method has no effect other than an update. Do not use.
   */
  void setValuePerBigMark(int) TDE_DEPRECATED;

  /**
   * Show/hide number values of the little marks.
   *
   * Default is @p false.
   **/
    //  void setShowLittleMarkLabel(bool);

  /**
   * Show/hide number values of the medium marks.
   *
   * Default is @p false.
   **/
    //  void setShowMediumMarkLabel(bool);

  /**
   * Show/hide number values of the big marks.
   *
   * Default is @p false.
   **/
    //  void showBigMarkLabel(bool);

  /**
   * Show/hide number values of the end marks.
   *
   * Default is @p false.
   **/
   void setShowEndLabel(bool);
   bool showEndLabel() const;

  /**
   * Sets the label this is drawn at the beginning of the visible part
   * of the ruler to @p label
   **/
  void setEndLabel(const TQString&);
  TQString endLabel() const;

  /**
   * Sets up the necessary tasks for the provided styles.
   *
   * A convenience method.
   **/
  void setRulerMetricStyle(KRuler::MetricStyle);

  /**
   * Sets the number of pixels between two base marks.
   *
   * Calling this method stretches or shrinks your ruler.
   *
   * For pixel display ( MetricStyle) the value is 10.0 marks
   * per pixel ;-)
   * For English (inches) it is 9.0, and for centimetres ~2.835 -> 3.0 .
   * If you want to magnify your part of display, you have to
   * adjust the mark distance @p here.
   * Notice: The double type is only supported to give the possibility
   *         of having some double values.
   *         It should be used with care.  Using values below 10.0
   *         shows visible jumps of markpositions (e.g. 2.345).
   *         Using whole numbers is highly recommended.
   * To use @p int values use setPixelPerMark((int)your_int_value);
   * default: 1 mark per 10 pixels
   */
  void setPixelPerMark(double rate);

  /**
   * Returns the number of pixels between two base marks.
   **/
  inline double pixelPerMark() const;

  /**
   * Sets the length of the ruler, i.e. the difference between
   * the begin mark and the end mark of the ruler.
   *
   * Same as (width() - offset())
   *
   * when the length is not locked, it gets adjusted with the
   * length of the widget.
   */
  void setLength(int);
  int length() const;

  /**
   * Locks the length of the ruler, i.e. the difference between
   * the two end marks doesn't change when the widget is resized.
   *
   * @param fix fixes the length, if true
   */
  void setLengthFixed(bool fix);
  bool lengthFixed() const;

  /**
   * Sets the number of pixels by which the ruler may slide up or left.
   * The number of pixels moved is realive to the previous position.
   * The Method makes sense for updating a ruler, which is working with
   * a scrollbar.
   *
   * This doesn't affect the position of the ruler pointer.
   * Only the visible part of the ruler is moved.
   *
   * @param count Number of pixel moving up or left relative to the previous position
   **/
  void slideUp(int count = 1);

  /**
   * Sets the number of pixels by which the ruler may slide down or right.
   * The number of pixels moved is realive to the previous position.
   * The Method makes sense for updating a ruler, which is working with
   * a scrollbar.
   *
   * This doesn't affect the position of the ruler pointer.
   * Only the visible part of the ruler is moved.
   *
   * @param count Number of pixel moving up or left relative to the previous position
   **/
  void slideDown(int count = 1);

  /**
   * Sets the ruler slide offset.
   *
   * This is like slideup() or slidedown() with an absolute offset
   * from the start of the ruler.
   *
   * @param offset Number of pixel to move the ruler up or left from the beginning
   **/
  void setOffset(int offset);

  /**
   * Returns the current ruler offset.
   **/
  inline int offset() const;

  int endOffset() const;

public slots:

  /**
   * Sets the pointer to a new position.
   *
   * The offset is NOT updated.
   * TQWidget::repaint() is called afterwards.
   **/
  void slotNewValue(int);

  /**
   * Sets the ruler marks to a new position.
   *
   * The pointer is NOT updated.
   * TQWidget::repaint() is called afterwards.
   **/
  void slotNewOffset(int);

  void slotEndOffset(int);

protected:
  virtual void drawContents(TQPainter *);

private:
  void init();

  TQRangeControl range;
  Orientation dir;
  int tmDist;
  int lmDist;
  int mmDist;
  int bmDist;
  int offset_;
  bool showtm; /* show tiny, little, medium, big, endmarks */
  bool showlm;
  bool showmm;
  bool showbm;
  bool showem;

  // #### KDE4 : All value* and show* below should be removed, unused

  int valuelm; /* value per little, medium, big mark */
  int valuemm;
  int valuebm;
  bool showValuelm;
  bool showValuemm;
  bool showValuebm;

  double ppm; /* pixel per mark */

  TQString endlabel;

protected:
  virtual void virtual_hook( int id, void* data );
private:
  class KRulerPrivate;
  KRulerPrivate *d;
};


int
KRuler::minValue() const
{ return range.minValue(); }

int
KRuler::maxValue() const
{ return range.maxValue(); }

int
KRuler::value() const
{ return range.value(); }

int
KRuler::tinyMarkDistance() const
{ return tmDist; }

int
KRuler::littleMarkDistance() const
{ return lmDist; }

int
KRuler::mediumMarkDistance() const
{ return mmDist; }

int
KRuler::bigMarkDistance() const
{ return bmDist; }

double
KRuler::pixelPerMark() const
{ return ppm; }

int
KRuler::offset() const
{ return offset_; }

#endif