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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
|
/****************************************************************************
**
** Implementation of the dial widget
**
** Created : 979899
**
** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
**
** This file is part of the widgets module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file. Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/
#include "tqdial.h"
#ifndef TQT_NO_DIAL
#include "tqpainter.h"
#include "tqpointarray.h"
#include "tqcolor.h"
#include "tqapplication.h"
#include "tqregion.h"
#include "tqbitmap.h"
#include "tqstyle.h"
#if defined(TQT_ACCESSIBILITY_SUPPORT)
#include "tqaccessible.h"
#endif
#include <math.h> // sin(), cos(), atan()
//### Forutsetter linking med math lib - Jfr kommentar i qpainter_x11.cpp!
static const double m_pi = 3.14159265358979323846;
static const double rad_factor = 180.0 / m_pi;
class TQDialPrivate
{
public:
TQDialPrivate()
{
wrapping = FALSE;
tracking = TRUE;
doNotEmit = FALSE;
target = 3.7;
mousePressed = FALSE;
}
bool wrapping;
bool tracking;
bool doNotEmit;
double target;
TQRect eraseArea;
bool eraseAreaValid;
bool showNotches;
bool onlyOutside;
bool mousePressed;
TQPointArray lines;
};
/*!
\class TQDial tqdial.h
\brief The TQDial class provides a rounded range control (like a speedometer or potentiometer).
\ingroup basic
\mainclass
TQDial is used when the user needs to control a value within a
program-definable range, and the range either wraps around
(typically, 0..359 degrees) or the dialog tqlayout needs a square
widget.
Both API- and UI-wise, the dial is very similar to a \link TQSlider
slider. \endlink Indeed, when wrapping() is FALSE (the default)
there is no real difference between a slider and a dial. They
have the same Q_SIGNALS, Q_SLOTS and member functions, all of which do
the same things. Which one you use depends only on your taste
and on the application.
The dial initially emits valueChanged() Q_SIGNALS continuously while
the slider is being moved; you can make it emit the signal less
often by calling setTracking(FALSE). dialMoved() is emitted
continuously even when tracking() is FALSE.
The slider also emits dialPressed() and dialReleased() Q_SIGNALS
when the mouse button is pressed and released. But note that the
dial's value can change without these Q_SIGNALS being emitted; the
keyboard and wheel can be used to change the value.
Unlike the slider, TQDial attempts to draw a "nice" number of
notches rather than one per lineStep(). If possible, the number
of notches drawn is one per lineStep(), but if there aren't enough
pixels to draw every one, TQDial will draw every second, third
etc., notch. notchSize() returns the number of units per notch,
hopefully a multiple of lineStep(); setNotchTarget() sets the
target distance between neighbouring notches in pixels. The
default is 3.75 pixels.
Like the slider, the dial makes the TQRangeControl functions
setValue(), addLine(), subtractLine(), addPage() and
subtractPage() available as Q_SLOTS.
The dial's keyboard interface is fairly simple: The left/up and
right/down arrow keys move by lineStep(), page up and page down by
pageStep() and Home and End to minValue() and maxValue().
<img src=qdial-m.png> <img src=qdial-w.png>
\sa TQScrollBar TQSpinBox
\link guibooks.html#fowler GUI Design Handbook: Slider\endlink
*/
/*!
Constructs a dial called \a name with tqparent \a tqparent. \a f is
propagated to the TQWidget constructor. It has the default range of
a TQRangeControl.
*/
TQDial::TQDial( TQWidget *tqparent, const char *name, WFlags f )
: TQWidget( tqparent, name, f | TQt::WNoAutoErase ), TQRangeControl()
{
d = new TQDialPrivate;
d->eraseAreaValid = FALSE;
d->showNotches = FALSE;
d->onlyOutside = FALSE;
setFocusPolicy( Qt::WheelFocus );
}
/*!
Constructs a dial called \a name with tqparent \a tqparent. The dial's
value can never be smaller than \a minValue or greater than \a
maxValue. Its page step size is \a pageStep, and its initial value
is \a value.
\a value is forced to be within the legal range.
*/
TQDial::TQDial( int minValue, int maxValue, int pageStep, int value,
TQWidget *tqparent, const char *name )
: TQWidget( tqparent, name, TQt::WNoAutoErase ),
TQRangeControl( minValue, maxValue, 1, pageStep, value )
{
d = new TQDialPrivate;
d->eraseAreaValid = FALSE;
d->showNotches = FALSE;
d->onlyOutside = FALSE;
setFocusPolicy( Qt::WheelFocus );
}
/*!
Destroys the dial.
*/
TQDial::~TQDial()
{
delete d;
}
void TQDial::setTracking( bool enable )
{
d->tracking = enable;
}
/*!
\property TQDial::tracking
\brief whether tracking is enabled
If TRUE (the default), tracking is enabled. This means that the
arrow can be moved using the mouse; otherwise the arrow cannot be
moved with the mouse.
*/
bool TQDial::tracking() const
{
return d ? d->tracking : TRUE;
}
void TQDial::setValue( int newValue )
{ // ### set doNotEmit? Matthias?
TQRangeControl::setValue( newValue );
}
/*!
Increments the dial's value() by one lineStep().
*/
void TQDial::addLine()
{
TQRangeControl::addLine();
}
/*!
Decrements the dial's value() by one lineStep().
*/
void TQDial::subtractLine()
{
TQRangeControl::subtractLine();
}
/*! \reimp */
void TQDial::resizeEvent( TQResizeEvent * e )
{
d->lines.resize( 0 );
TQWidget::resizeEvent( e );
}
/*!
\reimp
*/
void TQDial::paintEvent( TQPaintEvent * e )
{
repaintScreen( &e->rect() );
}
/*!
Paints the dial using clip region \a cr.
*/
void TQDial::repaintScreen( const TQRect *cr )
{
TQPainter p;
p.begin( this );
bool resetClipping = FALSE;
// calculate clip-region for erasing background
if ( cr ) {
p.setClipRect( *cr );
} else if ( !d->onlyOutside && d->eraseAreaValid ) {
TQRegion reg = d->eraseArea;
double a;
reg = reg.subtract( calcArrow( a ) );
p.setClipRegion( reg );
resetClipping = TRUE;
}
TQRect br( calcDial() );
p.setPen( Qt::NoPen );
// if ( style() == MotifStyle )
// p.setBrush( tqcolorGroup().brush( TQColorGroup::Mid ) );
// else {
TQBrush b;
if ( TQT_TQBRUSH_OBJECT(tqcolorGroup().brush( TQColorGroup::Light )).pixmap() )
b = TQBrush( tqcolorGroup().brush( TQColorGroup::Light ) );
else
b = TQBrush( tqcolorGroup().light(), Qt::Dense4Pattern );
p.setBrush( b );
p.setBackgroundMode( Qt::OpaqueMode );
// }
TQRect te = br;
te.setWidth(te.width()+2);
te.setHeight(te.height()+2);
// erase background of dial
if ( !d->onlyOutside ) {
p.drawEllipse( te );
}
// erase remaining space around the dial
TQRegion remaining( 0, 0, width(), height() );
remaining = remaining.subtract( TQRegion( te, TQRegion::Ellipse ) );
if ( p.hasClipping() )
remaining = remaining.intersect( p.clipRegion() );
erase(remaining);
if ( resetClipping ) {
if ( cr )
p.setClipRect( *cr );
else
p.setClipRect( TQRect( 0, 0, width(), height() ) );
}
// draw notches
if ( d->showNotches ) {
calcLines();
p.setPen( tqcolorGroup().foreground() );
p.drawLineSegments( d->lines );
}
// calculate and paint arrow
p.setPen( TQPen( tqcolorGroup().dark() ) );
p.drawArc( te, 60 * 16, 180 * 16 );
p.setPen( TQPen( tqcolorGroup().light() ) );
p.drawArc( te, 240 * 16, 180 * 16 );
double a;
TQPointArray arrow( calcArrow( a ) );
TQRect ea( arrow.boundingRect() );
d->eraseArea = ea;
d->eraseAreaValid = TRUE;
p.setPen( Qt::NoPen );
p.setBrush( tqcolorGroup().brush( TQColorGroup::Button ) );
if ( !d->onlyOutside )
p.drawPolygon( arrow );
a = angle( TQPoint( width() / 2, height() / 2 ), arrow[ 0 ] );
p.setBrush( TQt::NoBrush );
// that's still a hack...
if ( a <= 0 || a > 200 ) {
p.setPen( tqcolorGroup().light() );
p.drawLine( arrow[ 2 ], arrow[ 0 ] );
p.drawLine( arrow[ 1 ], arrow[ 2 ] );
p.setPen( tqcolorGroup().dark() );
p.drawLine( arrow[ 0 ], arrow[ 1 ] );
} else if ( a > 0 && a < 45 ) {
p.setPen( tqcolorGroup().light() );
p.drawLine( arrow[ 2 ], arrow[ 0 ] );
p.setPen( tqcolorGroup().dark() );
p.drawLine( arrow[ 1 ], arrow[ 2 ] );
p.drawLine( arrow[ 0 ], arrow[ 1 ] );
} else if ( a >= 45 && a < 135 ) {
p.setPen( tqcolorGroup().dark() );
p.drawLine( arrow[ 2 ], arrow[ 0 ] );
p.drawLine( arrow[ 1 ], arrow[ 2 ] );
p.setPen( tqcolorGroup().light() );
p.drawLine( arrow[ 0 ], arrow[ 1 ] );
} else if ( a >= 135 && a < 200 ) {
p.setPen( tqcolorGroup().dark() );
p.drawLine( arrow[ 2 ], arrow[ 0 ] );
p.setPen( tqcolorGroup().light() );
p.drawLine( arrow[ 0 ], arrow[ 1 ] );
p.drawLine( arrow[ 1 ], arrow[ 2 ] );
}
// draw focus rect around the dial
if ( hasFocus() ) {
p.setClipping( FALSE );
br.setWidth( br.width() + 2 );
br.setHeight( br.height() + 2 );
if ( d->showNotches ) {
int r = TQMIN( width(), height() ) / 2;
br.moveBy( -r / 6, - r / 6 );
br.setWidth( br.width() + r / 3 );
br.setHeight( br.height() + r / 3 );
}
// strange, but else we get redraw errors on Windows
p.end();
p.begin( this );
p.save();
p.setPen( TQPen( tqcolorGroup().background() ) );
p.setBrush( Qt::NoBrush );
p.drawRect( br );
p.restore();
tqstyle().tqdrawPrimitive( TQStyle::PE_FocusRect, &p, br, tqcolorGroup());
}
p.end();
}
/*!
\reimp
*/
void TQDial::keyPressEvent( TQKeyEvent * e )
{
switch ( e->key() ) {
case Qt::Key_Left: case Qt::Key_Down:
subtractLine();
break;
case Qt::Key_Right: case Qt::Key_Up:
addLine();
break;
case TQt::Key_Prior:
subtractPage();
break;
case TQt::Key_Next:
addPage();
break;
case Qt::Key_Home:
setValue( minValue() );
break;
case Qt::Key_End:
setValue( maxValue() );
break;
default:
e->ignore();
break;
}
}
/*!
\reimp
*/
void TQDial::mousePressEvent( TQMouseEvent * e )
{
d->mousePressed = TRUE;
setValue( valueFromPoint( e->pos() ) );
emit dialPressed();
}
/*!
\reimp
*/
void TQDial::mouseReleaseEvent( TQMouseEvent * e )
{
d->mousePressed = FALSE;
setValue( valueFromPoint( e->pos() ) );
emit dialReleased();
}
/*!
\reimp
*/
void TQDial::mouseMoveEvent( TQMouseEvent * e )
{
if ( !d->mousePressed )
return;
if ( !d->tracking || (e->state() & Qt::LeftButton) == 0 )
return;
d->doNotEmit = TRUE;
setValue( valueFromPoint( e->pos() ) );
emit dialMoved( value() );
d->doNotEmit = FALSE;
}
/*!
\reimp
*/
#ifndef TQT_NO_WHEELEVENT
void TQDial::wheelEvent( TQWheelEvent *e )
{
setValue( value() - e->delta() / 120 );
}
#endif
/*!
\reimp
*/
void TQDial::focusInEvent( TQFocusEvent * )
{
d->onlyOutside = TRUE;
repaintScreen();
d->onlyOutside = FALSE;
}
/*!
\reimp
*/
void TQDial::focusOutEvent( TQFocusEvent * )
{
d->onlyOutside = TRUE;
repaintScreen();
d->onlyOutside = FALSE;
}
/*!
Reimplemented to ensure the display is correct and to emit the
valueChanged(int) signal when appropriate.
*/
void TQDial::valueChange()
{
d->lines.resize( 0 );
repaintScreen();
if ( d->tracking || !d->doNotEmit ) {
emit valueChanged( value() );
#if defined(TQT_ACCESSIBILITY_SUPPORT)
TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged );
#endif
}
}
/*!
Reimplemented to ensure tick-marks are consistent with the new range.
*/
void TQDial::rangeChange()
{
d->lines.resize( 0 );
repaintScreen();
}
/*!
\internal
*/
int TQDial::valueFromPoint( const TQPoint & p ) const
{
double yy = (double)height()/2.0 - p.y();
double xx = (double)p.x() - width()/2.0;
double a = (xx || yy) ? atan2(yy, xx) : 0;
if ( a < m_pi/-2 )
a = a + m_pi*2;
int dist = 0;
int minv = minValue(), maxv = maxValue();
if ( minValue() < 0 ) {
dist = -minValue();
minv = 0;
maxv = maxValue() + dist;
}
int r = maxv - minv;
int v;
if ( d->wrapping )
v = (int)(0.5 + minv + r*(m_pi*3/2-a)/(2*m_pi));
else
v = (int)(0.5 + minv + r*(m_pi*4/3-a)/(m_pi*10/6));
if ( dist > 0 )
v -= dist;
return bound( v );
}
/*!
\internal
*/
double TQDial::angle( const TQPoint &p1, const TQPoint &p2 ) const
{
double _angle = 0.0;
if ( p1.x() == p2.x() ) {
if ( p1.y() < p2.y() )
_angle = 270.0;
else
_angle = 90.0;
} else {
double x1, x2, y1, y2;
if ( p1.x() <= p2.x() ) {
x1 = p1.x(); y1 = p1.y();
x2 = p2.x(); y2 = p2.y();
} else {
x2 = p1.x(); y2 = p1.y();
x1 = p2.x(); y1 = p2.y();
}
double m = -( y2 - y1 ) / ( x2 - x1 );
_angle = atan( m ) * rad_factor;
if ( p1.x() < p2.x() )
_angle = 180.0 - _angle;
else
_angle = -_angle;
}
return _angle;
}
void TQDial::setWrapping( bool enable )
{
if ( d->wrapping == enable )
return;
d->lines.resize( 0 );
d->wrapping = enable;
d->eraseAreaValid = FALSE;
repaintScreen();
}
/*!
\property TQDial::wrapping
\brief whether wrapping is enabled
If TRUE, wrapping is enabled. This means that the arrow can be
turned around 360�. Otherwise there is some space at the bottom of
the dial which is skipped by the arrow.
This property's default is FALSE.
*/
bool TQDial::wrapping() const
{
return d->wrapping;
}
/*!
\property TQDial::notchSize
\brief the current notch size
The notch size is in range control units, not pixels, and if
possible it is a multiple of lineStep() that results in an
on-screen notch size near notchTarget().
\sa notchTarget() lineStep()
*/
int TQDial::notchSize() const
{
// radius of the arc
int r = TQMIN( width(), height() )/2;
// length of the whole arc
int l = (int)(r*(d->wrapping ? 6 : 5)*m_pi/6);
// length of the arc from minValue() to minValue()+pageStep()
if ( maxValue() > minValue()+pageStep() )
l = (int)(0.5 + l * pageStep() / (maxValue()-minValue()));
// length of a lineStep() arc
l = l * lineStep() / pageStep();
if ( l < 1 )
l = 1;
// how many times lineStep can be draw in d->target pixels
l = (int)(0.5 + d->target / l);
// we want notchSize() to be a non-zero multiple of lineStep()
if ( !l )
l = 1;
return lineStep() * l;
}
void TQDial::setNotchTarget( double target )
{
d->lines.resize( 0 );
d->target = target;
d->eraseAreaValid = FALSE;
d->onlyOutside = TRUE;
repaintScreen();
d->onlyOutside = FALSE;
}
/*!
\property TQDial::notchTarget
\brief the target number of pixels between notches
The notch target is the number of pixels TQDial attempts to put
between each notch.
The actual size may differ from the target size.
*/
double TQDial::notchTarget() const
{
return d->target;
}
/*!
Increments the dial's value() by one pageStep() of steps.
*/
void TQDial::addPage()
{
TQRangeControl::addPage();
}
/*!
Decrements the dial's value() by one pageStep() of steps.
*/
void TQDial::subtractPage()
{
TQRangeControl::subtractPage();
}
/*!
\fn void TQDial::valueChanged( int value )
This signal is emitted whenever the dial's \a value changes. The
frequency of this signal is influenced by setTracking().
*/
/*!
\fn void TQDial::dialPressed()
This signal is emitted when the user begins mouse interaction with
the dial.
\sa dialReleased()
*/
/*!
\fn void TQDial::dialMoved( int value )
This signal is emitted whenever the dial \a value changes. The
frequency of this signal is \e not influenced by setTracking().
\sa valueChanged()
*/
/*!
\fn void TQDial::dialReleased()
This signal is emitted when the user ends mouse interaction with
the dial.
\sa dialPressed()
*/
void TQDial::setNotchesVisible( bool b )
{
d->showNotches = b;
d->eraseAreaValid = FALSE;
d->onlyOutside = TRUE;
repaintScreen();
d->onlyOutside = FALSE;
}
/*!
\property TQDial::notchesVisible
\brief whether the notches are shown
If TRUE, the notches are shown. If FALSE (the default) notches are
not shown.
*/
bool TQDial::notchesVisible() const
{
return d->showNotches;
}
/*!
\reimp
*/
TQSize TQDial::tqminimumSizeHint() const
{
return TQSize( 50, 50 );
}
/*!
\reimp
*/
TQSize TQDial::sizeHint() const
{
return TQSize( 100, 100 ).expandedTo( TQApplication::globalStrut() );
}
/*!
\internal
*/
TQPointArray TQDial::calcArrow( double &a ) const
{
int r = TQMIN( width(), height() ) / 2;
if ( maxValue() == minValue() )
a = m_pi / 2;
else if ( d->wrapping )
a = m_pi * 3 / 2 - ( value() - minValue() ) * 2 * m_pi / ( maxValue() - minValue() );
else
a = ( m_pi * 8 - ( value() - minValue() ) * 10 * m_pi / ( maxValue() - minValue() ) ) / 6;
int xc = width() / 2;
int yc = height() / 2;
int len = r - calcBigLineSize() - 5;
if ( len < 5 )
len = 5;
int back = len / 4;
if ( back < 1 )
back = 1;
TQPointArray arrow( 3 );
arrow[0] = TQPoint( (int)( 0.5 + xc + len * cos(a) ),
(int)( 0.5 + yc -len * sin( a ) ) );
arrow[1] = TQPoint( (int)( 0.5 + xc + back * cos( a + m_pi * 5 / 6 ) ),
(int)( 0.5 + yc - back * sin( a + m_pi * 5 / 6 ) ) );
arrow[2] = TQPoint( (int)( 0.5 + xc + back * cos( a - m_pi * 5 / 6 ) ),
(int)( 0.5 + yc - back * sin( a - m_pi * 5 / 6 ) ) );
return arrow;
}
/*!
\internal
*/
TQRect TQDial::calcDial() const
{
double r = TQMIN( width(), height() ) / 2.0;
double d_ = r / 6.0;
double dx = d_ + ( width() - 2 * r ) / 2.0 + 1;
double dy = d_ + ( height() - 2 * r ) / 2.0 + 1;
return TQRect( int(dx), int(dy),
int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2) );
}
/*!
\internal
*/
int TQDial::calcBigLineSize() const
{
int r = TQMIN( width(), height() ) / 2;
int bigLineSize = r / 6;
if ( bigLineSize < 4 )
bigLineSize = 4;
if ( bigLineSize > r / 2 )
bigLineSize = r / 2;
return bigLineSize;
}
/*!
\internal
*/
void TQDial::calcLines()
{
if ( !d->lines.size() ) {
double r = TQMIN( width(), height() ) / 2.0;
int bigLineSize = calcBigLineSize();
double xc = width() / 2.0;
double yc = height() / 2.0;
int ns = notchSize();
int notches = ( maxValue() + ns - 1 - minValue() ) / ns;
d->lines.resize( 2 + 2 * notches );
int smallLineSize = bigLineSize / 2;
int i;
for( i = 0; i <= notches; i++ ) {
double angle = d->wrapping
? m_pi * 3 / 2 - i * 2 * m_pi / notches
: (m_pi * 8 - i * 10 * m_pi / notches) / 6;
double s = sin( angle ); // sin/cos aren't defined as const...
double c = cos( angle );
if ( i == 0 || ( ((ns * i ) % pageStep() ) == 0 ) ) {
d->lines[2*i] = TQPoint( (int)( xc + ( r - bigLineSize ) * c ),
(int)( yc - ( r - bigLineSize ) * s ) );
d->lines[2*i+1] = TQPoint( (int)( xc + r * c ),
(int)( yc - r * s ) );
} else {
d->lines[2*i] = TQPoint( (int)( xc + ( r - 1 - smallLineSize ) * c ),
(int)( yc - ( r - 1 - smallLineSize ) * s ) );
d->lines[2*i+1] = TQPoint( (int)( xc + ( r - 1 ) * c ),
(int)( yc -( r - 1 ) * s ) );
}
}
}
}
/*!
\property TQDial::minValue
\brief the current minimum value
When setting this property, the \l TQDial::maxValue is adjusted if
necessary to ensure that the range remains valid.
\sa setRange()
*/
int TQDial::minValue() const
{
return TQRangeControl::minValue();
}
/*!
\property TQDial::maxValue
\brief the current maximum value
When setting this property, the \l TQDial::minValue is adjusted if
necessary to ensure that the range remains valid.
\sa setRange()
*/
int TQDial::maxValue() const
{
return TQRangeControl::maxValue();
}
void TQDial::setMinValue( int minVal )
{
TQRangeControl::setMinValue( minVal );
}
void TQDial::setMaxValue( int maxVal )
{
TQRangeControl::setMaxValue( maxVal );
}
/*!
\property TQDial::lineStep
\brief the current line step
setLineStep() calls the virtual stepChange() function if the new
line step is different from the previous setting.
\sa TQRangeControl::setSteps() pageStep setRange()
*/
int TQDial::lineStep() const
{
return TQRangeControl::lineStep();
}
/*!
\property TQDial::pageStep
\brief the current page step
setPageStep() calls the virtual stepChange() function if the new
page step is different from the previous setting.
\sa stepChange()
*/
int TQDial::pageStep() const
{
return TQRangeControl::pageStep();
}
void TQDial::setLineStep( int i )
{
setSteps( i, pageStep() );
}
void TQDial::setPageStep( int i )
{
setSteps( lineStep(), i );
}
/*!
\property TQDial::value
\brief the current dial value
This is guaranteed to be within the range
\l{TQDial::minValue}..\l{TQDial::maxValue}.
\sa minValue maxValue
*/
int TQDial::value() const
{
return TQRangeControl::value();
}
#endif // TQT_FEATURE_DIAL
|