1
//=========================================================
4
// $Id: sclif.cpp,v 1.1 2002/01/30 14:54:03 muse Exp $
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.
11
// (C) Copyright 2000 Werner Schweer (ws@seh.de)
12
//=========================================================
16
// ScaleIf - An interface class for widgets containing a scale
18
// This interface class is used to provide classes
19
// with a protected ScaleDraw member and a public
20
// interface to access that scale.
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
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.
41
//------------------------------------------------------------
43
// Construct a ScaleIf instance
47
//------------------------------------------------------------
54
d_scale.setScale(0.0,100.0,d_maxMajor, d_maxMinor);
57
//------------------------------------------------------------
58
// ScaleIf::setScale (1)
59
// Specify a user-defined scale.
62
// void ScaleIf::setScale(double vmin, double vmax, int logarithmic)
65
// double vmin, double vmax -- boundary values
66
// int logarithmic -- If != 0, Build a logarithmic scale
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
78
// @ScaleIf::autoScale@
79
//------------------------------------------------------------
81
void ScaleIf::setScale(double vmin, double vmax, int logarithmic)
83
setScale(vmin,vmax,0.0,logarithmic);
86
//------------------------------------------------------------
87
// ScaleIf::setScale (2)
88
// Specify a user-defined scale.
91
// void ScaleIf::setScale(double vmin, double vmax, int logarithmic)
94
// double vmin, double vmax -- interval boundaries
95
// int step -- major step size
96
// int logarithmic -- If != 0, build a logarithmic scale
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
106
//------------------------------------------------------------
108
void ScaleIf::setScale(double vmin, double vmax, double step, int logarithmic)
110
ScaleDiv oldscl(d_scale.scaleDiv());
112
d_scale.setScale(vmin, vmax, d_maxMajor, d_maxMinor, step, logarithmic);
114
if (oldscl != d_scale.scaleDiv())
118
//------------------------------------------------------------
120
// Assign a user-defined scale division
123
// void Scale::setScale(const ScaleDiv &s)
126
// const ScaleDiv &s -- scale division
127
//------------------------------------------------------------
129
void ScaleIf::setScale(const ScaleDiv &s)
135
//------------------------------------------------------------
136
// ScaleIf::autoScale
137
// Advise the widget to control the scale range
140
// void ScaleIf::autoScale
143
// Autoscaling is on by default.
144
//------------------------------------------------------------
146
void ScaleIf::autoScale()
154
//------------------------------------------------------------
155
// ScaleIf::setScaleMaxMajor
156
// Set the maximum number of major tick intervals.
159
// void ScaleIf::setScaleMaxMajor(int ticks)
162
// int ticks -- maximal number of major ticks.
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
//------------------------------------------------------------
170
void ScaleIf::setScaleMaxMajor(int ticks)
172
if (ticks != d_maxMajor) {
174
d_scale.setScale(d_scale.scaleDiv().lBound(), d_scale.scaleDiv().hBound(),
175
d_maxMajor, d_maxMinor, 0.0,d_scale.scaleDiv().logScale());
180
//------------------------------------------------------------
181
// ScaleIf::setScaleMaxMinor
182
// Set the maximum number of minor tick intervals
185
// void ScaleIf::setScaleMaxMinor(int ticks)
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
//------------------------------------------------------------
196
void ScaleIf::setScaleMaxMinor(int ticks)
198
if ( ticks != d_maxMinor) {
200
d_scale.setScale(d_scale.scaleDiv().lBound(), d_scale.scaleDiv().hBound(),
201
d_maxMajor, d_maxMinor, 0.0, d_scale.scaleDiv().logScale());