~ubuntu-branches/ubuntu/raring/muse/raring-proposed

« back to all changes in this revision

Viewing changes to widgets/slider.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-02-07 15:18:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040207151822-es27xxkzbcxkebjm
Tags: 0.6.3-1
* New upstream version.
* Added patches:
  + [10_alsa_init_fix] New, from upstream CVS.
    Initialize direction variable when setting Alsa parameters.
  + [10_canvas_translation_fix] New, from upstream CVS.
    Do not translate tooltips twice in canvas popup.
  + [10_checkbox_fix] New, from upstream CVS.
    Use proper set/test methods on metronome checkboxes.
  + [10_html_doc_cleanup] New.
    Fix links and HTML errors in documentation.
  + [20_allow_system_timer] New.
    The new upstream version fails by default if the real-time clock
    could not be accessed (usually the case when not running suid-root).
    This patch reverts the old behaviour of falling back to the more
    inaccurate system timer.
* Updated patches:
  + [11_PIC_fixes_fixup] Rediffed.
* Removed patches:
  + [20_no_atomic_asm] Merged upstream.
* debian/compat: Splice out debhelper compatibility level from rules file.
* debian/control: Build-depend on latest jack release by default.
  Closes: #228788
* debian/control: Bump standards version.
* debian/control: Use auto-generated debconf dependency via misc:Depends.
* debian/control: Minor tweaks to the long description.
* debian/control: Tighten fluidsynth build dependency to sane version.
* debian/muse.doc-base: New. Register HTML documentation with doc-base.
* debian/templates: Tiny rewording, and typo fix.
* debian/templates, debian/po/*: Switch to po-debconf for translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <math.h>
 
1
#include <cmath>
2
2
#include "mmath.h"
3
 
#include <qdrawutl.h>
 
3
#include <qdrawutil.h>
4
4
#include <qpainter.h>
5
5
#include "slider.h"
6
6
 
7
7
//-------------------------------------------------------------
8
 
//.H Slider | 3 | 02/04/98 | Qwt Widget Library | Qwt Programmer's Manual
9
 
//.I sliders Sliders
10
 
//.U  NAME
11
8
//      Slider - The Slider Widget
12
9
//
13
 
//.U  SYNOPSIS
14
 
//      #include <qwt_slider.h>
15
 
//
16
 
//.U DESCRIPTION
17
10
//      Slider is a slider widget which operates on an interval
18
11
//      of type double. Slider supports different layouts as
19
12
//      well as a scale.
20
 
//
21
 
//
22
 
//.U INHERITED CLASSES
23
 
//      @^SliderBase@, @^QwtScaleIf@
24
 
//
25
 
//.U PUBLIC MEMBERS
26
 
//.R
27
 
//      Slider::Slider -- Constructor
28
 
//      Slider::~Slider -- Destructor
29
 
//      Slider::setThumbLength -- Set the length of the slider's thumb
30
 
//      Slider::setThumbWidth -- Set the length of the slider's thumb
31
 
//      Slider::setBorderWidth -- Set the border width
32
 
//      Slider::setMargins -- Set the internal border distance
33
 
//
34
 
//.U SEE ALSO
35
 
//      @^SliderBase@ and @^QwtScaleIf@ for the descriptions
36
 
//      of the inherited members.
37
 
//------------------------------------------------------------
38
 
 
39
 
//------------------------------------------------------------
40
 
//.C MEMBER FUNCTION DESCRIPTION
41
 
//------------------------------------------------------------
42
 
 
43
 
 
44
 
//------------------------------------------------------------
45
 
//
 
13
//------------------------------------------------------------
 
14
 
 
15
//------------------------------------------------------------
46
16
//.F    Slider::Slider
47
17
//
48
18
//              Constructor
49
19
//
50
20
//.u    Syntax:
51
 
//.f    Slider::Slider(QWidget *parent, const char *name, OrientationX orient = Horizontal, ScalePos scalePos = None, int bgStyle = BgTrough)
 
21
//.f    Slider::Slider(QWidget *parent, const char *name, Orientation orient = Horizontal, ScalePos scalePos = None, int bgStyle = BgTrough)
52
22
//
53
23
//.u    Parameters
54
24
//.p
64
34
//                              slider button in a trough, Slider::BgSlot draws
65
35
//                              a slot underneath the button. An or-combination of both
66
36
//                              may also be used. The default is Slider::BgTrough.
67
 
//
68
 
//
69
37
//------------------------------------------------------------
 
38
 
70
39
Slider::Slider(QWidget *parent, const char *name,
71
 
   OrientationX orient, ScalePos scalePos, int bgStyle)
 
40
   Orientation orient, ScalePos scalePos, int bgStyle)
72
41
      : SliderBase(parent,name)
73
42
      {
74
 
      ScaleDraw::OrientationX so;
 
43
      _id = -1;
75
44
 
76
45
 
77
46
      if (bgStyle == BgSlot) {
86
55
            }
87
56
 
88
57
      d_borderWidth = 2;
89
 
      d_scaleDist = 4;
90
 
      d_orient = orient;
91
 
      d_scaleStep = 0.0;
92
 
      d_scalePos = scalePos;
93
 
      d_xMargin = 0;
94
 
      d_yMargin = 0;
95
 
      d_bgStyle = bgStyle;
 
58
      d_scaleDist   = 4;
 
59
      d_scaleStep   = 0.0;
 
60
      d_scalePos    = scalePos;
 
61
      d_xMargin     = 0;
 
62
      d_yMargin     = 0;
 
63
      d_bgStyle     = bgStyle;
96
64
 
97
65
      if (bgStyle & BgTrough)
98
66
            d_bwTrough = d_borderWidth;
99
67
      else
100
68
            d_bwTrough = 0;
101
69
 
102
 
    d_sliderRect.setRect(0,0,8,8);
103
 
 
104
 
    switch(d_orient)
105
 
    {
106
 
    case Vertical:
107
 
        if (d_scalePos == Right)
108
 
           so = ScaleDraw::Right;
109
 
        else
110
 
           so = ScaleDraw::Left;
111
 
        break;
112
 
    default:
113
 
        if (d_scalePos == Bottom)
114
 
           so = ScaleDraw::Bottom;
115
 
        else
116
 
           so = ScaleDraw::Top;
117
 
        break;
118
 
    }
119
 
 
120
 
      d_scale.setGeometry(0, 0, 40, so);
121
 
        
122
 
      if (d_orient == Vertical)
123
 
            setMinimumSize(10,20);
124
 
      else
125
 
            setMinimumSize(20,10);
 
70
      d_sliderRect.setRect(0, 0, 8, 8);
 
71
      setOrientation(orient);
126
72
      }
127
73
 
128
 
 
129
74
//------------------------------------------------------------
130
75
//.F    Slider::~Slider
131
76
//              Destructor
149
94
//.p    int bd -- border width
150
95
//
151
96
//------------------------------------------------------------
 
97
 
152
98
void Slider::setBorderWidth(int bd)
153
99
{
154
100
    d_borderWidth = qwtMin(qwtMax(bd,0),10);
232
178
}
233
179
 
234
180
//------------------------------------------------------------
235
 
//.-
236
 
//.F    Slider::drawSlider
237
 
//              Draw the slider into the specified rectangle.   
238
 
//
239
 
//.u    Syntax:
240
 
//.f    void Slider::drawSlider(QPaiter *p, const QRect &r)
241
 
//
242
 
//.u    Parameters:
243
 
//.p    QPainter *p, const QRect &r
244
 
//
 
181
//    drawSlider
 
182
//         Draw the slider into the specified rectangle.        
245
183
//------------------------------------------------------------
246
 
void Slider::drawSlider (QPainter *p, const QRect &r)
247
 
{
248
 
 
249
 
    QColorGroup g = colorGroup();
250
 
    QBrush brBack(g.background());
251
 
    QBrush brMid;
252
 
    QBrush brDark(g.dark());
253
 
 
254
 
    QRect cr;
255
 
 
256
 
    int ipos,dist1;
257
 
    double rpos;
258
 
    int lineDist;
259
 
 
260
 
    if (d_bwTrough > 0)
261
 
    {
262
 
        qDrawShadePanel(p, r.x(), r.y(),
 
184
 
 
185
void Slider::drawSlider(QPainter *p, const QRect &r)
 
186
      {
 
187
      QColorGroup g = colorGroup();
 
188
      QBrush brBack(g.background());
 
189
      QBrush brMid;
 
190
      QBrush brDark(g.dark());
 
191
 
 
192
      QRect cr;
 
193
 
 
194
      int ipos,dist1;
 
195
      double rpos;
 
196
      int lineDist;
 
197
 
 
198
      if (d_bwTrough > 0) {
 
199
            qDrawShadePanel(p, r.x(), r.y(),
263
200
                        r.width(), r.height(),
264
201
                        g, TRUE, d_bwTrough,0);
265
 
        cr.setRect(r.x() + d_bwTrough,
 
202
        cr.setRect(r.x() + d_bwTrough,
266
203
                   r.y() + d_bwTrough,
267
204
                   r.width() - 2*d_bwTrough,
268
205
                   r.height() - 2*d_bwTrough);
269
 
        brMid = QBrush(g.mid());
270
 
 
271
 
    }
272
 
    else
273
 
    {
274
 
        cr = r;
275
 
        brMid = brBack;
276
 
    }
 
206
        brMid = QBrush(g.mid());
 
207
            }
 
208
    else {
 
209
            cr = r;
 
210
            brMid = brBack;
 
211
            }
277
212
 
278
213
    rpos = (value()  - minValue()) / (maxValue() - minValue());
279
214
 
664
599
}
665
600
 
666
601
//------------------------------------------------------------
667
 
//.-
668
602
//.F    Slider::paintEvent
669
603
//      Qt paint event
670
604
//
671
 
//.u    Parameters
672
 
//.p    QPaintEvent *e
673
 
//
674
605
//.u    Syntax
675
606
//.f    void Slider::paintEvent(QPaintEvent *e)
676
 
//
677
 
//------------------------------------------------------------
678
 
void Slider::paintEvent(QPaintEvent * /*e*/)
679
 
{
680
 
    QPainter p;
681
 
 
682
 
    if(p.begin(this))
683
 
    {
684
 
        if (d_scalePos != None)
685
 
        {
686
 
            p.fillRect(this->rect(), this->backgroundColor());
687
 
            d_scale.draw(&p);
688
 
        }
689
 
        
690
 
        drawSlider(&p, d_sliderRect);
691
 
    }
692
 
    p.end();
693
 
 
694
 
}
695
 
 
696
 
//------------------------------------------------------------
697
 
//.-
 
607
//------------------------------------------------------------
 
608
 
 
609
void Slider::paintEvent(QPaintEvent* /*e*/)
 
610
      {
 
611
      QPainter p;
 
612
 
 
613
      if (p.begin(this)) {
 
614
            if (d_scalePos != None) {
 
615
                  p.fillRect(this->rect(), this->backgroundColor());
 
616
                  d_scale.draw(&p);
 
617
                  }
 
618
            drawSlider(&p, d_sliderRect);
 
619
            }
 
620
      p.end();
 
621
      }
 
622
 
 
623
//------------------------------------------------------------
698
624
//.F    Slider::resizeEvent
699
625
//      Qt resize event
700
626
//
703
629
//
704
630
//.u    Syntax
705
631
//.f    void Slider::resizeEvent(QResizeEvent *e)
706
 
//
707
632
//------------------------------------------------------------
 
633
 
708
634
void Slider::resizeEvent(QResizeEvent *e)
709
635
{
710
636
 
795
721
//.f    void Slider::valueChange()
796
722
//
797
723
//------------------------------------------------------------
 
724
 
798
725
void Slider::valueChange()
799
 
{
800
 
    QPainter p;
801
 
 
802
 
    p.begin(this);
803
 
    drawSlider(&p,d_sliderRect);
804
 
    p.end();
805
 
 
806
 
    SliderBase::valueChange();
807
 
 
808
 
}
809
 
 
 
726
      {
 
727
      QPainter p;
 
728
 
 
729
      p.begin(this);
 
730
      drawSlider(&p, d_sliderRect);
 
731
      p.end();
 
732
 
 
733
      SliderBase::valueChange();
 
734
      emit valueChanged(value(), _id);
 
735
      }
810
736
 
811
737
//------------------------------------------------------------
812
738
//.-    
878
804
                  case Vertical:
879
805
                        w = 2*d_xMargin + d_thumbWidth + 2*d_bwTrough + msWidth + d_scaleDist + 2;
880
806
                        break;
881
 
                  default:
 
807
                  case Horizontal:
882
808
                        h = 2*d_yMargin + d_thumbWidth + 2*d_bwTrough + msHeight + d_scaleDist;
883
809
                        break;
884
810
                  }
888
814
                  case Vertical:
889
815
                        w = 16 + 2 * d_bwTrough;
890
816
                        break;
891
 
                  default:
 
817
                  case Horizontal:
892
818
                        h = 16 + 2 * d_bwTrough;
893
819
                        break;
894
820
                  }
895
821
            }
896
822
      return QSize(w, h);
897
823
      }
 
824
 
 
825
//---------------------------------------------------------
 
826
//   setOrientation
 
827
//---------------------------------------------------------
 
828
 
 
829
void Slider::setOrientation(Orientation o)
 
830
      {
 
831
      d_orient = o;
 
832
      ScaleDraw::OrientationX so = ScaleDraw::Bottom;
 
833
      switch(d_orient) {
 
834
            case Vertical:
 
835
                  if (d_scalePos == Right)
 
836
                        so = ScaleDraw::Right;
 
837
                  else
 
838
                        so = ScaleDraw::Left;
 
839
                  break;
 
840
            case Horizontal:
 
841
                  if (d_scalePos == Bottom)
 
842
                        so = ScaleDraw::Bottom;
 
843
                  else
 
844
                        so = ScaleDraw::Top;
 
845
                  break;
 
846
            }
 
847
 
 
848
      d_scale.setGeometry(0, 0, 40, so);
 
849
      if (d_orient == Vertical)
 
850
            setMinimumSize(10,20);
 
851
      else
 
852
            setMinimumSize(20,10);
 
853
      QRect r = geometry();
 
854
      setGeometry(r.x(), r.y(), r.height(), r.width());
 
855
      update();
 
856
      }
 
857
 
 
858
Qt::Orientation Slider::orientation() const
 
859
      {
 
860
      return d_orient;
 
861
      }
 
862
 
 
863
double Slider::lineStep() const
 
864
      {
 
865
      return 1.0;
 
866
      }
 
867
 
 
868
double Slider::pageStep() const
 
869
      {
 
870
      return 1.0;
 
871
      }
 
872
 
 
873
void Slider::setLineStep(double)
 
874
      {
 
875
      }
 
876
 
 
877
void Slider::setPageStep(double)
 
878
      {
 
879
      }
 
880