96 lines
3.5 KiB
C++
96 lines
3.5 KiB
C++
#include "TimeSliderPickerBox.h"
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
|
|
TimeSlidePickerBox::TimeSlidePickerBox(QWidget* aParent)
|
|
: QWidget(aParent)
|
|
, mLayout(new QHBoxLayout(this))
|
|
, mHourBox1(new SlidePickerBox(this))
|
|
, mHourBox2(new SlidePickerBox(this))
|
|
, mMinuteBox1(new SlidePickerBox(this))
|
|
, mMinuteBox2(new SlidePickerBox(this))
|
|
, mSecondBox1(new SlidePickerBox(this))
|
|
, mSecondBox2(new SlidePickerBox(this))
|
|
, mIsMinuteSixty(false)
|
|
, mIsSecondSixty(false)
|
|
{
|
|
initBox(mHourBox1, {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, 56);
|
|
initBox(mHourBox2, {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, 56);
|
|
|
|
QLabel* hour = new QLabel(this);
|
|
hour->setText("H");
|
|
hour->setAlignment(Qt::AlignCenter);
|
|
hour->setFixedWidth(50);
|
|
hour->setObjectName("sliderSpliterLabel");
|
|
mLayout->addWidget(hour);
|
|
|
|
initBox(mMinuteBox1, {"0", "1", "2", "3", "4", "5"}, 56);
|
|
initBox(mMinuteBox2, {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, 56);
|
|
|
|
QLabel* min = new QLabel(this);
|
|
min->setText("M");
|
|
min->setAlignment(Qt::AlignCenter);
|
|
min->setFixedWidth(50);
|
|
min->setObjectName("sliderSpliterLabel");
|
|
mLayout->addWidget(min);
|
|
|
|
initBox(mSecondBox1, {"0", "1", "2", "3", "4", "5"}, 56);
|
|
initBox(mSecondBox2, {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, 56);
|
|
|
|
QLabel* sec = new QLabel(this);
|
|
sec->setText("S");
|
|
sec->setAlignment(Qt::AlignCenter);
|
|
sec->setFixedWidth(50);
|
|
sec->setObjectName("sliderSpliterLabel");
|
|
mLayout->addWidget(sec);
|
|
}
|
|
|
|
void TimeSlidePickerBox::initBox(SlidePickerBox* aBox, const QStringList& aItemsValues, int width)
|
|
{
|
|
aBox->setItems(aItemsValues);
|
|
mLayout->addWidget(aBox);
|
|
aBox->setFixedWidth(width);
|
|
}
|
|
|
|
void TimeSlidePickerBox::resizeLabel()
|
|
{
|
|
mHourBox1->resizeLabelWidth();
|
|
mHourBox2->resizeLabelWidth();
|
|
mMinuteBox1->resizeLabelWidth();
|
|
mMinuteBox2->resizeLabelWidth();
|
|
mSecondBox1->resizeLabelWidth();
|
|
mSecondBox2->resizeLabelWidth();
|
|
}
|
|
|
|
QString TimeSlidePickerBox::getSelectedValue() const
|
|
{
|
|
return QString("%1%2%3%4%5%6%7%8%9").arg(mHourBox1->getSelectedValue())
|
|
.arg(mHourBox2->getSelectedValue())
|
|
.arg(tr("Hour"))
|
|
.arg(mMinuteBox1->getSelectedValue())
|
|
.arg(mMinuteBox2->getSelectedValue())
|
|
.arg(tr("Min"))
|
|
.arg(mSecondBox1->getSelectedValue())
|
|
.arg(mSecondBox2->getSelectedValue())
|
|
.arg(tr("Sec"));
|
|
}
|
|
int TimeSlidePickerBox::getTotalSeconds() const
|
|
{
|
|
return mHourBox1->getSelectedValue().toInt() * 10 * 3600 +
|
|
mHourBox2->getSelectedValue().toInt() * 3600 +
|
|
mMinuteBox1->getSelectedValue().toInt() * 10 * 60 +
|
|
mMinuteBox2->getSelectedValue().toInt() * 60 +
|
|
mSecondBox1->getSelectedValue().toInt() * 10 +
|
|
mSecondBox2->getSelectedValue().toInt();
|
|
}
|
|
|
|
void TimeSlidePickerBox::setSelectedValue(const int& aSeconds)
|
|
{
|
|
mHourBox1->setSelectedValue(QString::number(aSeconds / 36000));
|
|
mHourBox2->setSelectedValue(QString::number((aSeconds / 3600) % 10));
|
|
mMinuteBox1->setSelectedValue(QString::number((aSeconds % 3600) / 600));
|
|
mMinuteBox2->setSelectedValue(QString::number((aSeconds % 600) / 60));
|
|
mSecondBox1->setSelectedValue(QString::number((aSeconds % 60) / 10));
|
|
mSecondBox2->setSelectedValue(QString::number(aSeconds % 10));
|
|
}
|