source: src/UIElements/Views/Qt4/Plotting/QScrollZoomer/ScrollBar.cpp@ 3b1798

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 3b1798 was 35302b, checked in by Frederik Heber <heber@…>, 11 years ago

Added many files from project Seismolo.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * QSeisScrollbar.cpp
3 *
4 * taken from "realtime"-example
5 *
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include <qstyle.h>
14#if QT_VERSION >= 0x040000
15#include <qstyleoption.h>
16#endif
17#include "ScrollBar.hpp"
18
19
20// have this after(!) all Qt includes
21#include "CodePatterns/MemDebug.hpp"
22
23ScrollBar::ScrollBar(QWidget * parent):
24 QScrollBar(parent)
25{
26 init();
27}
28
29ScrollBar::ScrollBar(Qt::Orientation o,
30 QWidget *parent):
31 QScrollBar(o, parent)
32{
33 init();
34}
35
36ScrollBar::ScrollBar(double minBase, double maxBase,
37 Qt::Orientation o, QWidget *parent):
38 QScrollBar(o, parent)
39{
40 init();
41 setBase(minBase, maxBase);
42 moveSlider(minBase, maxBase);
43}
44
45void ScrollBar::init()
46{
47 d_inverted = orientation() == Qt::Vertical;
48 d_baseTicks = 1000000;
49 d_minBase = 0.0;
50 d_maxBase = 1.0;
51 moveSlider(d_minBase, d_maxBase);
52
53 connect(this, SIGNAL(sliderMoved(int)), SLOT(catchSliderMoved(int)));
54 connect(this, SIGNAL(valueChanged(int)), SLOT(catchValueChanged(int)));
55}
56
57void ScrollBar::setInverted(bool inverted)
58{
59 if ( d_inverted != inverted )
60 {
61 d_inverted = inverted;
62 moveSlider(minSliderValue(), maxSliderValue());
63 }
64}
65
66bool ScrollBar::isInverted() const
67{
68 return d_inverted;
69}
70
71void ScrollBar::setBase(double min, double max)
72{
73 if ( min != d_minBase || max != d_maxBase )
74 {
75 d_minBase = min;
76 d_maxBase = max;
77
78 moveSlider(minSliderValue(), maxSliderValue());
79 }
80}
81
82void ScrollBar::moveSlider(double min, double max)
83{
84 const int sliderTicks = qRound((max - min) /
85 (d_maxBase - d_minBase) * d_baseTicks);
86
87 // setRange initiates a valueChanged of the scrollbars
88 // in some situations. So we block
89 // and unblock the signals.
90
91 blockSignals(true);
92
93 setRange(sliderTicks / 2, d_baseTicks - sliderTicks / 2);
94 int steps = sliderTicks / 200;
95 if ( steps <= 0 )
96 steps = 1;
97
98#if QT_VERSION < 0x040000
99 setSteps(steps, sliderTicks);
100#else
101 setSingleStep(steps);
102 setPageStep(sliderTicks);
103#endif
104
105 int tick = mapToTick(min + (max - min) / 2);
106 if ( isInverted() )
107 tick = d_baseTicks - tick;
108
109#if QT_VERSION < 0x040000
110 directSetValue(tick);
111 rangeChange();
112#else
113 setSliderPosition(tick);
114#endif
115 blockSignals(false);
116}
117
118double ScrollBar::minBaseValue() const
119{
120 return d_minBase;
121}
122
123double ScrollBar::maxBaseValue() const
124{
125 return d_maxBase;
126}
127
128void ScrollBar::sliderRange(int value, double &min, double &max) const
129{
130 if ( isInverted() )
131 value = d_baseTicks - value;
132
133 const int visibleTicks = pageStep();
134
135 min = mapFromTick(value - visibleTicks / 2);
136 max = mapFromTick(value + visibleTicks / 2);
137}
138
139double ScrollBar::minSliderValue() const
140{
141 double min, dummy;
142 sliderRange(value(), min, dummy);
143
144 return min;
145}
146
147double ScrollBar::maxSliderValue() const
148{
149 double max, dummy;
150 sliderRange(value(), dummy, max);
151
152 return max;
153}
154
155int ScrollBar::mapToTick(double v) const
156{
157 return (int) ( ( v - d_minBase) / (d_maxBase - d_minBase ) * d_baseTicks );
158}
159
160double ScrollBar::mapFromTick(int tick) const
161{
162 return d_minBase + ( d_maxBase - d_minBase ) * tick / d_baseTicks;
163}
164
165void ScrollBar::catchValueChanged(int value)
166{
167 double min, max;
168 sliderRange(value, min, max);
169 emit valueChanged(orientation(), min, max);
170}
171
172void ScrollBar::catchSliderMoved(int value)
173{
174 double min, max;
175 sliderRange(value, min, max);
176 emit sliderMoved(orientation(), min, max);
177}
178
179int ScrollBar::extent() const
180{
181#if QT_VERSION < 0x040000
182 return style().pixelMetric(QStyle::PM_ScrollBarExtent, this);
183#else
184 QStyleOptionSlider opt;
185 opt.init(this);
186 opt.subControls = QStyle::SC_None;
187 opt.activeSubControls = QStyle::SC_None;
188 opt.orientation = orientation();
189 opt.minimum = minimum();
190 opt.maximum = maximum();
191 opt.sliderPosition = sliderPosition();
192 opt.sliderValue = value();
193 opt.singleStep = singleStep();
194 opt.pageStep = pageStep();
195 opt.upsideDown = invertedAppearance();
196 if (orientation() == Qt::Horizontal)
197 opt.state |= QStyle::State_Horizontal;
198 return style()->pixelMetric(QStyle::PM_ScrollBarExtent, &opt, this);
199#endif
200}
Note: See TracBrowser for help on using the repository browser.