Kstars

timestepbox.cpp
1 /*
2  SPDX-FileCopyrightText: 2002 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "timestepbox.h"
8 
9 #include "timespinbox.h"
10 #include "timeunitbox.h"
11 
12 #include <KLocalizedString>
13 
14 #include <QDebug>
15 #include <QHBoxLayout>
16 
17 TimeStepBox::TimeStepBox(QWidget *parent, bool daysonly) : QWidget(parent)
18 {
19  timeBox = new TimeSpinBox(this, daysonly);
20  unitBox = new TimeUnitBox(this, daysonly);
21 
22  timeBox->setToolTip(i18n("Adjust time step"));
23  unitBox->setToolTip(i18n("Adjust time step units"));
24 
25  this->setWhatsThis(
26  i18n("Set the timescale for the simulation clock. A setting of \"1 sec\" means the clock advances in "
27  "real-time, keeping up perfectly with your CPU clock. Higher values make the simulation clock run "
28  "faster, lower values make it run slower. Negative values make it run backwards."
29  "\n\n"
30  "There are two pairs of up/down buttons. The left pair will cycle through all available timesteps in "
31  "sequence. Since there are a large number of timesteps, the right pair is provided to skip to the next "
32  "higher/lower unit of time. For example, if the timescale is currently \"1 min\", the right up button "
33  "will make it \"1 hour\", and the right down button will make it \"1 sec\""));
34  hlay = new QHBoxLayout(this);
35  hlay->setContentsMargins(0, 0, 0, 0);
36  hlay->setSpacing(0);
37  hlay->addWidget(timeBox);
38  hlay->addWidget(unitBox);
39  hlay->activate();
40 
41  timeBox->setValue(4); //real-time
42 
43  connect(unitBox, SIGNAL(valueChanged(int)), this, SLOT(changeUnits()));
44  connect(timeBox, SIGNAL(valueChanged(int)), this, SLOT(syncUnits(int)));
45  connect(timeBox, SIGNAL(scaleChanged(float)), this, SIGNAL(scaleChanged(float)));
46 }
47 
48 void TimeStepBox::changeUnits(void)
49 {
50  timeBox->setValue(unitBox->unitValue());
51 }
52 
53 void TimeStepBox::syncUnits(int tstep)
54 {
55  int i;
56  for (i = unitbox()->maxValue(); i >= unitbox()->minValue(); --i)
57  if (abs(tstep) >= unitBox->getUnitValue(i))
58  break;
59 
60  //don't want setValue to trigger changeUnits()...
61  disconnect(unitBox, SIGNAL(valueChanged(int)), this, SLOT(changeUnits()));
62  unitBox->setValue(tstep < 0 ? -i : i);
63  connect(unitBox, SIGNAL(valueChanged(int)), this, SLOT(changeUnits()));
64 }
65 
66 void TimeStepBox::setDaysOnly(bool daysonly)
67 {
68  tsbox()->setDaysOnly(daysonly);
69  unitbox()->setDaysOnly(daysonly);
70 }
void setWhatsThis(const QString &)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
int getUnitValue(int)
the same as unitValue, except you can get the UnitStep for any value, not just the current one.
TimeStepBox(QWidget *parent=nullptr, bool daysonly=false)
Constructor.
Definition: timestepbox.cpp:17
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
Provides a second set of up/down buttons for TimeStepBox. A pair of buttons, arranged one above the o...
Definition: timeunitbox.h:37
QString i18n(const char *text, const TYPE &arg...)
void setValue(int value)
Set the value which describes which time-unit is displayed in the TimeSpinBox.
Definition: timeunitbox.h:58
void setToolTip(const QString &)
void setSpacing(int spacing)
TimeSpinBox * tsbox() const
Definition: timestepbox.h:35
void setContentsMargins(int left, int top, int right, int bottom)
TimeUnitBox * unitbox() const
Definition: timestepbox.h:38
bool activate()
int minValue() const
Definition: timeunitbox.h:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:00:06 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.