Kstars

timestepbox.cpp
1/*
2 SPDX-FileCopyrightText: 2002 Jason Harris <kstars@30doradus.org>
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
17TimeStepBox::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
48void TimeStepBox::changeUnits(void)
49{
50 timeBox->setValue(unitBox->unitValue());
51}
52
53void 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
66void TimeStepBox::setDaysOnly(bool daysonly)
67{
68 tsbox()->setDaysOnly(daysonly);
69 unitbox()->setDaysOnly(daysonly);
70}
Custom spinbox to handle selection of timestep values with variable units.
TimeUnitBox * unitbox() const
Definition timestepbox.h:38
TimeSpinBox * tsbox() const
Definition timestepbox.h:35
TimeStepBox(QWidget *parent=nullptr, bool daysonly=false)
Constructor.
Provides a second set of up/down buttons for TimeStepBox.
Definition timeunitbox.h:38
int getUnitValue(int)
the same as unitValue, except you can get the UnitStep for any value, not just the current one.
int minValue() const
Definition timeunitbox.h:68
void setValue(int value)
Set the value which describes which time-unit is displayed in the TimeSpinBox.
Definition timeunitbox.h:58
QString i18n(const char *text, const TYPE &arg...)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void setSpacing(int spacing) override
bool activate()
void setContentsMargins(const QMargins &margins)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
void setValue(int val)
void setToolTip(const QString &)
void setWhatsThis(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.