File indexing completed on 2024-04-28 11:25:40
0001 /* 0002 SPDX-FileCopyrightText: 2002 Jason Harris <kstars@30doradus.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "timestepbox.h" 0008 0009 #include "timespinbox.h" 0010 #include "timeunitbox.h" 0011 0012 #include <KLocalizedString> 0013 0014 #include <QDebug> 0015 #include <QHBoxLayout> 0016 0017 TimeStepBox::TimeStepBox(QWidget *parent, bool daysonly) : QWidget(parent) 0018 { 0019 timeBox = new TimeSpinBox(this, daysonly); 0020 unitBox = new TimeUnitBox(this, daysonly); 0021 0022 timeBox->setToolTip(i18n("Adjust time step")); 0023 unitBox->setToolTip(i18n("Adjust time step units")); 0024 0025 this->setWhatsThis( 0026 i18n("Set the timescale for the simulation clock. A setting of \"1 sec\" means the clock advances in " 0027 "real-time, keeping up perfectly with your CPU clock. Higher values make the simulation clock run " 0028 "faster, lower values make it run slower. Negative values make it run backwards." 0029 "\n\n" 0030 "There are two pairs of up/down buttons. The left pair will cycle through all available timesteps in " 0031 "sequence. Since there are a large number of timesteps, the right pair is provided to skip to the next " 0032 "higher/lower unit of time. For example, if the timescale is currently \"1 min\", the right up button " 0033 "will make it \"1 hour\", and the right down button will make it \"1 sec\"")); 0034 hlay = new QHBoxLayout(this); 0035 hlay->setContentsMargins(0, 0, 0, 0); 0036 hlay->setSpacing(0); 0037 hlay->addWidget(timeBox); 0038 hlay->addWidget(unitBox); 0039 hlay->activate(); 0040 0041 timeBox->setValue(4); //real-time 0042 0043 connect(unitBox, SIGNAL(valueChanged(int)), this, SLOT(changeUnits())); 0044 connect(timeBox, SIGNAL(valueChanged(int)), this, SLOT(syncUnits(int))); 0045 connect(timeBox, SIGNAL(scaleChanged(float)), this, SIGNAL(scaleChanged(float))); 0046 } 0047 0048 void TimeStepBox::changeUnits(void) 0049 { 0050 timeBox->setValue(unitBox->unitValue()); 0051 } 0052 0053 void TimeStepBox::syncUnits(int tstep) 0054 { 0055 int i; 0056 for (i = unitbox()->maxValue(); i >= unitbox()->minValue(); --i) 0057 if (abs(tstep) >= unitBox->getUnitValue(i)) 0058 break; 0059 0060 //don't want setValue to trigger changeUnits()... 0061 disconnect(unitBox, SIGNAL(valueChanged(int)), this, SLOT(changeUnits())); 0062 unitBox->setValue(tstep < 0 ? -i : i); 0063 connect(unitBox, SIGNAL(valueChanged(int)), this, SLOT(changeUnits())); 0064 } 0065 0066 void TimeStepBox::setDaysOnly(bool daysonly) 0067 { 0068 tsbox()->setDaysOnly(daysonly); 0069 unitbox()->setDaysOnly(daysonly); 0070 }