~ubuntu-branches/ubuntu/oneiric/muse/oneiric

« back to all changes in this revision

Viewing changes to widgets/sclif.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=========================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//    $Id: sclif.cpp,v 1.1 2002/01/30 14:54:03 muse Exp $
 
5
 
 
6
//    Copyright (C) 1997  Josef Wilgen
 
7
//      This program is free software; you can redistribute it and/or modify
 
8
//      it under the terms of the GNU General Public License, version 2,
 
9
//      as published by the Free Software Foundation.
 
10
//
 
11
//    (C) Copyright 2000 Werner Schweer (ws@seh.de)
 
12
//=========================================================
 
13
 
 
14
#include "sclif.h"
 
15
 
 
16
//  ScaleIf - An interface class for widgets containing a scale
 
17
//
 
18
//      This interface class is used to provide classes
 
19
//      with a protected ScaleDraw member and a public
 
20
//      interface to access that scale.
 
21
//
 
22
//      The primary purpose of this class is to define
 
23
//      a common interface for classes which are supposed to
 
24
//      contain a ScaleDraw class. It provides a protected
 
25
//      ScaleDraw member
 
26
//      called d_scale and a couple of public member functions
 
27
//      which allow direct but restricted access
 
28
//      to this scale by the user.
 
29
//      Widgets derived from this class have
 
30
//      to implement the member function scaleChange(),
 
31
//      which is called to notify changes of the
 
32
//      scale parameters and usually requires repainting or
 
33
//      resizing respectively.
 
34
//      In general, a class derived from ScaleIf is
 
35
//      expected to manage the division and the position of its scale internally
 
36
//      when no user-defined scale is set. It should take the d_maxMinor
 
37
//      and d_maxMajor members into account, which can be set by the user.
 
38
//      An implementation can check if a user-defined scale is set by calling the
 
39
//      @ScaleIf::hasUserScale@ member.
 
40
 
 
41
//------------------------------------------------------------
 
42
//      ScaleIf::ScaleIf
 
43
//      Construct a ScaleIf instance
 
44
//
 
45
//      Syntax
 
46
//       ScaleIf::ScaleIf()
 
47
//------------------------------------------------------------
 
48
 
 
49
ScaleIf::ScaleIf()
 
50
      {
 
51
      d_userScale = FALSE;
 
52
      d_maxMajor = 5;
 
53
      d_maxMinor = 3;
 
54
      d_scale.setScale(0.0,100.0,d_maxMajor, d_maxMinor);
 
55
      }
 
56
 
 
57
//------------------------------------------------------------
 
58
//      ScaleIf::setScale (1)
 
59
//      Specify a user-defined scale.
 
60
//
 
61
//      Syntax
 
62
//      void ScaleIf::setScale(double vmin, double vmax, int logarithmic)
 
63
//
 
64
//      Parameters
 
65
//      double vmin, double vmax        -- boundary values
 
66
//  int logarithmic     --      If != 0, Build a logarithmic scale
 
67
//
 
68
//      Description
 
69
//      By default, the widget is supposed to control the range of its scale
 
70
//      automatically,  but sometimes it is desirable to have a user-defined
 
71
//      scale which is not in sync with
 
72
//      the widget's range, e.g. if a logarithmic scale is needed
 
73
//      (sliders don't support that) or if the scale is required
 
74
//      to have a fixed range (say 0...100%), independent of the
 
75
//      widget's range.
 
76
//
 
77
//      See also
 
78
//  @ScaleIf::autoScale@
 
79
//------------------------------------------------------------
 
80
 
 
81
void ScaleIf::setScale(double vmin, double vmax, int logarithmic)
 
82
      {
 
83
      setScale(vmin,vmax,0.0,logarithmic);
 
84
      }
 
85
 
 
86
//------------------------------------------------------------
 
87
//      ScaleIf::setScale (2)
 
88
//      Specify a user-defined scale.
 
89
//
 
90
//      Syntax
 
91
//      void ScaleIf::setScale(double vmin, double vmax, int logarithmic)
 
92
//
 
93
//      Parameters
 
94
//      double vmin, double vmax        -- interval boundaries
 
95
//    int step                  -- major step size
 
96
//    int logarithmic                   -- If != 0, build a logarithmic scale
 
97
//
 
98
//      Description
 
99
//      By default, the widget is supposed to control the range of its scale
 
100
//      automatically,  but sometimes it is desirable to have a user-defined
 
101
//      scale which is not in sync with
 
102
//      the widget's range, e.g. if a logarithmic scale is needed
 
103
//      (sliders don't support that) or if the scale is required
 
104
//      to have a fixed range (say 0...100%), independent of the
 
105
//      widget's range.
 
106
//------------------------------------------------------------
 
107
 
 
108
void ScaleIf::setScale(double vmin, double vmax, double step, int logarithmic)
 
109
      {
 
110
      ScaleDiv oldscl(d_scale.scaleDiv());
 
111
 
 
112
      d_scale.setScale(vmin, vmax, d_maxMajor, d_maxMinor, step, logarithmic);
 
113
      d_userScale = TRUE;
 
114
      if (oldscl != d_scale.scaleDiv())
 
115
            scaleChange();
 
116
      }
 
117
 
 
118
//------------------------------------------------------------
 
119
//      Scale::setScale
 
120
//  Assign a user-defined scale division
 
121
//
 
122
//      Syntax
 
123
//      void Scale::setScale(const ScaleDiv &s)
 
124
//
 
125
//      Parameters
 
126
//      const ScaleDiv &s -- scale division
 
127
//------------------------------------------------------------
 
128
 
 
129
void ScaleIf::setScale(const ScaleDiv &s)
 
130
      {
 
131
      d_scale.setScale(s);
 
132
      scaleChange();
 
133
      }
 
134
 
 
135
//------------------------------------------------------------
 
136
//      ScaleIf::autoScale
 
137
//      Advise the widget to control the scale range
 
138
//      internally.
 
139
//      Syntax
 
140
//      void ScaleIf::autoScale
 
141
//
 
142
//      Description
 
143
//      Autoscaling is on by default.
 
144
//------------------------------------------------------------
 
145
 
 
146
void ScaleIf::autoScale()
 
147
      {
 
148
      if (!d_userScale) {
 
149
            d_userScale = FALSE;
 
150
            scaleChange();
 
151
            }
 
152
      }
 
153
 
 
154
//------------------------------------------------------------
 
155
//      ScaleIf::setScaleMaxMajor
 
156
//      Set the maximum number of major tick intervals.
 
157
//
 
158
//      Syntax
 
159
//      void ScaleIf::setScaleMaxMajor(int ticks)
 
160
//
 
161
//      Parameters
 
162
//      int ticks               --              maximal number of major ticks.
 
163
//
 
164
//      Description
 
165
//      The scale's major ticks are calculated automatically such that
 
166
//      the number of major intervals does not exceed <ticks>.
 
167
//      The default value is 5.
 
168
//------------------------------------------------------------
 
169
 
 
170
void ScaleIf::setScaleMaxMajor(int ticks)
 
171
      {
 
172
      if (ticks != d_maxMajor) {
 
173
            d_maxMajor = ticks;
 
174
            d_scale.setScale(d_scale.scaleDiv().lBound(), d_scale.scaleDiv().hBound(),
 
175
               d_maxMajor, d_maxMinor, 0.0,d_scale.scaleDiv().logScale());
 
176
            scaleChange();
 
177
            }
 
178
      }
 
179
 
 
180
//------------------------------------------------------------
 
181
//  ScaleIf::setScaleMaxMinor
 
182
//    Set the maximum number of minor tick intervals
 
183
//
 
184
//      Syntax
 
185
//      void ScaleIf::setScaleMaxMinor(int ticks)
 
186
//
 
187
//      Parameters
 
188
//      int ticks
 
189
//
 
190
//      Description
 
191
//      The scale's minor ticks are calculated automatically such that
 
192
//      the number of minor intervals does not exceed <ticks>.
 
193
//      The default value is 3.
 
194
//------------------------------------------------------------
 
195
 
 
196
void ScaleIf::setScaleMaxMinor(int ticks)
 
197
      {
 
198
      if ( ticks != d_maxMinor) {
 
199
            d_maxMinor = ticks;
 
200
            d_scale.setScale(d_scale.scaleDiv().lBound(), d_scale.scaleDiv().hBound(),
 
201
               d_maxMajor, d_maxMinor, 0.0, d_scale.scaleDiv().logScale());
 
202
            scaleChange();
 
203
            }
 
204
      }
 
205