File indexing completed on 2024-12-22 04:40:07

0001 /*
0002     SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>
0003     SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "intinputdialog.h"
0009 
0010 #include <QLabel>
0011 #include <QLineEdit>
0012 #include <QSpinBox>
0013 #include <QSlider>
0014 #include <QDialogButtonBox>
0015 #include <QPushButton>
0016 
0017 using namespace SubtitleComposer;
0018 
0019 IntInputDialog::IntInputDialog(const QString &caption, const QString &label, QWidget *parent)
0020     : QDialog(parent)
0021 {
0022     init(caption, label, 0, 100, 0);
0023 }
0024 
0025 IntInputDialog::IntInputDialog(const QString &caption, const QString &label, int min, int max, QWidget *parent)
0026     : QDialog(parent)
0027 {
0028     init(caption, label, min, max, min);
0029 }
0030 
0031 IntInputDialog::IntInputDialog(const QString &caption, const QString &label, int min, int max, int value, QWidget *parent)
0032     : QDialog(parent)
0033 {
0034     init(caption, label, min, max, value);
0035 }
0036 
0037 void
0038 IntInputDialog::init(const QString &caption, const QString &labelText, int min, int max, int value)
0039 {
0040     setupUi(this);
0041 
0042     setWindowTitle(caption);
0043 
0044     slider->setRange(min, max);
0045     slider->setValue(value);
0046 
0047     spinBox->setRange(min, max);
0048     spinBox->setValue(value);
0049     spinBox->setFocus();
0050 
0051     int step = (max - min) / 10;
0052     slider->setTickInterval(step);
0053     slider->setPageStep(step);
0054 
0055     label->setText(labelText);
0056 
0057     resize(300, 10);
0058 }
0059 
0060 int
0061 IntInputDialog::minimum() const
0062 {
0063     return slider->minimum();
0064 }
0065 
0066 void
0067 IntInputDialog::setMinimum(int minimum)
0068 {
0069     slider->setMinimum(minimum);
0070     spinBox->setMinimum(minimum);
0071 
0072     int step = (maximum() - minimum) / 10;
0073     slider->setTickInterval(step);
0074     slider->setPageStep(step);
0075 }
0076 
0077 int
0078 IntInputDialog::maximum() const
0079 {
0080     return slider->maximum();
0081 }
0082 
0083 void
0084 IntInputDialog::setMaximum(int maximum)
0085 {
0086     slider->setMaximum(maximum);
0087     spinBox->setMaximum(maximum);
0088 
0089     int step = (maximum - minimum()) / 10;
0090     slider->setTickInterval(step);
0091     slider->setPageStep(step);
0092 }
0093 
0094 int
0095 IntInputDialog::value() const
0096 {
0097     return slider->value();
0098 }
0099 
0100 void
0101 IntInputDialog::setValue(int value)
0102 {
0103     slider->setValue(value);
0104     spinBox->setValue(value);
0105 }
0106 
0107