unscuffed settings tab

removed copy past cody in favor of an itsy-bitsy more flexible solution
This commit is contained in:
TranRed 2019-07-19 16:20:31 +02:00
parent c45bb144e9
commit 00ad80d93d
2 changed files with 234 additions and 476 deletions

View file

@ -73,6 +73,8 @@ AdvancedPage::AdvancedPage()
});
// Logs end
// Timeoutbuttons
QStringList units = QStringList();
units.append("s");
units.append("m");
@ -80,6 +82,65 @@ AdvancedPage::AdvancedPage()
units.append("d");
units.append("w");
QStringList initDurationsPerUnit;
initDurationsPerUnit = QStringList();
initDurationsPerUnit.append(
QString(getSettings()->timeoutDurationPerUnit1));
initDurationsPerUnit.append(
QString(getSettings()->timeoutDurationPerUnit2));
initDurationsPerUnit.append(
QString(getSettings()->timeoutDurationPerUnit3));
initDurationsPerUnit.append(
QString(getSettings()->timeoutDurationPerUnit4));
initDurationsPerUnit.append(
QString(getSettings()->timeoutDurationPerUnit5));
initDurationsPerUnit.append(
QString(getSettings()->timeoutDurationPerUnit6));
initDurationsPerUnit.append(
QString(getSettings()->timeoutDurationPerUnit7));
initDurationsPerUnit.append(
QString(getSettings()->timeoutDurationPerUnit8));
QStringList::iterator itDurationPerUnit;
itDurationPerUnit = initDurationsPerUnit.begin();
QStringList initUnits;
initUnits = QStringList();
initUnits.append(QString(getSettings()->timeoutDurationUnit1));
initUnits.append(QString(getSettings()->timeoutDurationUnit2));
initUnits.append(QString(getSettings()->timeoutDurationUnit3));
initUnits.append(QString(getSettings()->timeoutDurationUnit4));
initUnits.append(QString(getSettings()->timeoutDurationUnit5));
initUnits.append(QString(getSettings()->timeoutDurationUnit6));
initUnits.append(QString(getSettings()->timeoutDurationUnit7));
initUnits.append(QString(getSettings()->timeoutDurationUnit8));
QStringList::iterator itUnit;
itUnit = initUnits.begin();
std::list<int> initDurationsInSec;
initDurationsInSec.push_back(int(getSettings()->timeoutDurationInSec1));
initDurationsInSec.push_back(int(getSettings()->timeoutDurationInSec2));
initDurationsInSec.push_back(int(getSettings()->timeoutDurationInSec3));
initDurationsInSec.push_back(int(getSettings()->timeoutDurationInSec4));
initDurationsInSec.push_back(int(getSettings()->timeoutDurationInSec5));
initDurationsInSec.push_back(int(getSettings()->timeoutDurationInSec6));
initDurationsInSec.push_back(int(getSettings()->timeoutDurationInSec7));
initDurationsInSec.push_back(int(getSettings()->timeoutDurationInSec8));
std::list<int>::iterator itDurationInSec;
itDurationInSec = initDurationsInSec.begin();
for (int i = 0; i < 8; i++)
{
durationInputs.append(new QLineEdit());
unitInputs.append(new QComboBox());
durationsCalculated.append(new QSpinBox());
}
itDurationInput = durationInputs.begin();
itUnitInput = unitInputs.begin();
itDurationsCalculated = durationsCalculated.begin();
auto timeoutLayout = tabs.appendTab(new QVBoxLayout, "Timeouts");
auto infoLabel = timeoutLayout.emplace<QLabel>();
infoLabel->setText("Customize your timeout buttons in seconds (s), "
@ -95,494 +156,95 @@ AdvancedPage::AdvancedPage()
commandLabel->setText(
"For abitrary timeout durations use the /timeout command.");
auto timeout1 = timeoutLayout.emplace<QHBoxLayout>().withoutMargin();
// build one line for each customizable button
for (int i = 0; i < 8; i++)
{
QLineEdit *lineEditDurationInput1 = new QLineEdit;
lineEditDurationInput1->setValidator(
new QIntValidator(1, 99, this));
lineEditDurationInput1->setText(
getSettings()->timeoutDurationPerUnit1);
lineEditDurationInput1->setAlignment(Qt::AlignRight);
timeout1.append(lineEditDurationInput1);
auto timeout = timeoutLayout.emplace<QHBoxLayout>().withoutMargin();
{
QLineEdit *lineEditDurationInput = *itDurationInput;
lineEditDurationInput->setObjectName(QString::number(i));
lineEditDurationInput->setValidator(
new QIntValidator(1, 99, this));
lineEditDurationInput->setText(*itDurationPerUnit);
lineEditDurationInput->setAlignment(Qt::AlignRight);
timeout.append(lineEditDurationInput);
QComboBox *timeoutDurationUnit1 = new QComboBox();
timeoutDurationUnit1->addItems(units);
timeoutDurationUnit1->setCurrentText(
getSettings()->timeoutDurationUnit1);
timeout1.append(timeoutDurationUnit1);
QComboBox *timeoutDurationUnit = *itUnitInput;
timeoutDurationUnit->setObjectName(QString::number(i));
timeoutDurationUnit->addItems(units);
timeoutDurationUnit->setCurrentText(*itUnit);
timeout.append(timeoutDurationUnit);
QSpinBox *spinBoxDurationCalculated1 = new QSpinBox;
spinBoxDurationCalculated1->setRange(1, 1209600);
spinBoxDurationCalculated1->setValue(
getSettings()->timeoutDurationInSec1);
spinBoxDurationCalculated1->setReadOnly(true);
spinBoxDurationCalculated1->setAlignment(Qt::AlignRight);
timeout1.append(spinBoxDurationCalculated1);
QSpinBox *spinBoxDurationCalculated = *itDurationsCalculated;
spinBoxDurationCalculated->setObjectName(QString::number(i));
spinBoxDurationCalculated->setRange(1, 1209600);
spinBoxDurationCalculated->setValue(*itDurationInSec);
spinBoxDurationCalculated->setReadOnly(true);
spinBoxDurationCalculated->setAlignment(Qt::AlignRight);
timeout.append(spinBoxDurationCalculated);
QObject::connect(lineEditDurationInput1, &QLineEdit::textChanged,
[=] {
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput1,
getSettings()->timeoutDurationUnit1,
*spinBoxDurationCalculated1,
getSettings()->timeoutDurationPerUnit1);
});
QObject::connect(lineEditDurationInput, &QLineEdit::textChanged,
this, &AdvancedPage::timeoutDurationChanged);
QObject::connect(spinBoxDurationCalculated1,
qOverload<int>(&QSpinBox::valueChanged), [=] {
AdvancedPage::calculatedDurationChanged(
spinBoxDurationCalculated1->value(),
getSettings()->timeoutDurationInSec1);
});
QObject::connect(timeoutDurationUnit,
&QComboBox::currentTextChanged, this,
&AdvancedPage::timeoutUnitChanged);
QObject::connect(timeoutDurationUnit1,
&QComboBox::currentTextChanged, [=] {
AdvancedPage::timeoutUnitChanged(
timeoutDurationUnit1->currentText(),
getSettings()->timeoutDurationUnit1);
QObject::connect(spinBoxDurationCalculated,
qOverload<int>(&QSpinBox::valueChanged), this,
&AdvancedPage::calculatedDurationChanged);
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput1,
getSettings()->timeoutDurationUnit1,
*spinBoxDurationCalculated1,
getSettings()->timeoutDurationPerUnit1);
});
auto secondsLabel = timeout.emplace<QLabel>();
secondsLabel->setText("seconds");
}
auto secondsLabel = timeout1.emplace<QLabel>();
secondsLabel->setText("seconds");
}
auto timeout2 = timeoutLayout.emplace<QHBoxLayout>().withoutMargin();
{
QLineEdit *lineEditDurationInput2 = new QLineEdit;
lineEditDurationInput2->setValidator(
new QIntValidator(1, 99, this));
lineEditDurationInput2->setText(
getSettings()->timeoutDurationPerUnit2);
lineEditDurationInput2->setAlignment(Qt::AlignRight);
timeout2.append(lineEditDurationInput2);
QComboBox *timeoutDurationUnit2 = new QComboBox();
timeoutDurationUnit2->addItems(units);
timeoutDurationUnit2->setCurrentText(
getSettings()->timeoutDurationUnit2);
timeout2.append(timeoutDurationUnit2);
QSpinBox *spinBoxDurationCalculated2 = new QSpinBox;
spinBoxDurationCalculated2->setRange(1, 1209600);
spinBoxDurationCalculated2->setValue(
getSettings()->timeoutDurationInSec2);
spinBoxDurationCalculated2->setReadOnly(true);
spinBoxDurationCalculated2->setAlignment(Qt::AlignRight);
timeout2.append(spinBoxDurationCalculated2);
QObject::connect(lineEditDurationInput2, &QLineEdit::textChanged,
[=] {
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput2,
getSettings()->timeoutDurationUnit2,
*spinBoxDurationCalculated2,
getSettings()->timeoutDurationPerUnit2);
});
QObject::connect(spinBoxDurationCalculated2,
qOverload<int>(&QSpinBox::valueChanged), [=] {
AdvancedPage::calculatedDurationChanged(
spinBoxDurationCalculated2->value(),
getSettings()->timeoutDurationInSec2);
});
QObject::connect(timeoutDurationUnit2,
&QComboBox::currentTextChanged, [=] {
AdvancedPage::timeoutUnitChanged(
timeoutDurationUnit2->currentText(),
getSettings()->timeoutDurationUnit2);
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput2,
getSettings()->timeoutDurationUnit2,
*spinBoxDurationCalculated2,
getSettings()->timeoutDurationPerUnit2);
});
auto secondsLabel = timeout2.emplace<QLabel>();
secondsLabel->setText("seconds");
}
auto timeout3 = timeoutLayout.emplace<QHBoxLayout>().withoutMargin();
{
QLineEdit *lineEditDurationInput3 = new QLineEdit;
lineEditDurationInput3->setValidator(
new QIntValidator(1, 99, this));
lineEditDurationInput3->setText(
getSettings()->timeoutDurationPerUnit3);
lineEditDurationInput3->setAlignment(Qt::AlignRight);
timeout3.append(lineEditDurationInput3);
QComboBox *timeoutDurationUnit3 = new QComboBox();
timeoutDurationUnit3->addItems(units);
timeoutDurationUnit3->setCurrentText(
getSettings()->timeoutDurationUnit3);
timeout3.append(timeoutDurationUnit3);
QSpinBox *spinBoxDurationCalculated3 = new QSpinBox;
spinBoxDurationCalculated3->setRange(1, 1209600);
spinBoxDurationCalculated3->setValue(
getSettings()->timeoutDurationInSec3);
spinBoxDurationCalculated3->setReadOnly(true);
spinBoxDurationCalculated3->setAlignment(Qt::AlignRight);
timeout3.append(spinBoxDurationCalculated3);
QObject::connect(lineEditDurationInput3, &QLineEdit::textChanged,
[=] {
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput3,
getSettings()->timeoutDurationUnit3,
*spinBoxDurationCalculated3,
getSettings()->timeoutDurationPerUnit3);
});
QObject::connect(spinBoxDurationCalculated3,
qOverload<int>(&QSpinBox::valueChanged), [=] {
AdvancedPage::calculatedDurationChanged(
spinBoxDurationCalculated3->value(),
getSettings()->timeoutDurationInSec3);
});
QObject::connect(timeoutDurationUnit3,
&QComboBox::currentTextChanged, [=] {
AdvancedPage::timeoutUnitChanged(
timeoutDurationUnit3->currentText(),
getSettings()->timeoutDurationUnit3);
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput3,
getSettings()->timeoutDurationUnit3,
*spinBoxDurationCalculated3,
getSettings()->timeoutDurationPerUnit3);
});
auto secondsLabel = timeout3.emplace<QLabel>();
secondsLabel->setText("seconds");
}
auto timeout4 = timeoutLayout.emplace<QHBoxLayout>().withoutMargin();
{
QLineEdit *lineEditDurationInput4 = new QLineEdit;
lineEditDurationInput4->setValidator(
new QIntValidator(1, 99, this));
lineEditDurationInput4->setText(
getSettings()->timeoutDurationPerUnit4);
lineEditDurationInput4->setAlignment(Qt::AlignRight);
timeout4.append(lineEditDurationInput4);
QComboBox *timeoutDurationUnit4 = new QComboBox();
timeoutDurationUnit4->addItems(units);
timeoutDurationUnit4->setCurrentText(
getSettings()->timeoutDurationUnit4);
timeout4.append(timeoutDurationUnit4);
QSpinBox *spinBoxDurationCalculated4 = new QSpinBox;
spinBoxDurationCalculated4->setRange(1, 1209600);
spinBoxDurationCalculated4->setValue(
getSettings()->timeoutDurationInSec4);
spinBoxDurationCalculated4->setReadOnly(true);
spinBoxDurationCalculated4->setAlignment(Qt::AlignRight);
timeout4.append(spinBoxDurationCalculated4);
QObject::connect(lineEditDurationInput4, &QLineEdit::textChanged,
[=] {
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput4,
getSettings()->timeoutDurationUnit4,
*spinBoxDurationCalculated4,
getSettings()->timeoutDurationPerUnit4);
});
QObject::connect(spinBoxDurationCalculated4,
qOverload<int>(&QSpinBox::valueChanged), [=] {
AdvancedPage::calculatedDurationChanged(
spinBoxDurationCalculated4->value(),
getSettings()->timeoutDurationInSec4);
});
QObject::connect(timeoutDurationUnit4,
&QComboBox::currentTextChanged, [=] {
AdvancedPage::timeoutUnitChanged(
timeoutDurationUnit4->currentText(),
getSettings()->timeoutDurationUnit4);
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput4,
getSettings()->timeoutDurationUnit4,
*spinBoxDurationCalculated4,
getSettings()->timeoutDurationPerUnit4);
});
auto secondsLabel = timeout4.emplace<QLabel>();
secondsLabel->setText("seconds");
}
auto timeout5 = timeoutLayout.emplace<QHBoxLayout>().withoutMargin();
{
QLineEdit *lineEditDurationInput5 = new QLineEdit;
lineEditDurationInput5->setValidator(
new QIntValidator(1, 99, this));
lineEditDurationInput5->setText(
getSettings()->timeoutDurationPerUnit5);
lineEditDurationInput5->setAlignment(Qt::AlignRight);
timeout5.append(lineEditDurationInput5);
QComboBox *timeoutDurationUnit5 = new QComboBox();
timeoutDurationUnit5->addItems(units);
timeoutDurationUnit5->setCurrentText(
getSettings()->timeoutDurationUnit5);
timeout5.append(timeoutDurationUnit5);
QSpinBox *spinBoxDurationCalculated5 = new QSpinBox;
spinBoxDurationCalculated5->setRange(1, 1209600);
spinBoxDurationCalculated5->setValue(
getSettings()->timeoutDurationInSec5);
spinBoxDurationCalculated5->setReadOnly(true);
spinBoxDurationCalculated5->setAlignment(Qt::AlignRight);
timeout5.append(spinBoxDurationCalculated5);
QObject::connect(lineEditDurationInput5, &QLineEdit::textChanged,
[=] {
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput5,
getSettings()->timeoutDurationUnit5,
*spinBoxDurationCalculated5,
getSettings()->timeoutDurationPerUnit5);
});
QObject::connect(spinBoxDurationCalculated5,
qOverload<int>(&QSpinBox::valueChanged), [=] {
AdvancedPage::calculatedDurationChanged(
spinBoxDurationCalculated5->value(),
getSettings()->timeoutDurationInSec5);
});
QObject::connect(timeoutDurationUnit5,
&QComboBox::currentTextChanged, [=] {
AdvancedPage::timeoutUnitChanged(
timeoutDurationUnit5->currentText(),
getSettings()->timeoutDurationUnit5);
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput5,
getSettings()->timeoutDurationUnit5,
*spinBoxDurationCalculated5,
getSettings()->timeoutDurationPerUnit5);
});
auto secondsLabel = timeout5.emplace<QLabel>();
secondsLabel->setText("seconds");
}
auto timeout6 = timeoutLayout.emplace<QHBoxLayout>().withoutMargin();
{
QLineEdit *lineEditDurationInput6 = new QLineEdit;
lineEditDurationInput6->setValidator(
new QIntValidator(1, 99, this));
lineEditDurationInput6->setText(
getSettings()->timeoutDurationPerUnit6);
lineEditDurationInput6->setAlignment(Qt::AlignRight);
timeout6.append(lineEditDurationInput6);
QComboBox *timeoutDurationUnit6 = new QComboBox();
timeoutDurationUnit6->addItems(units);
timeoutDurationUnit6->setCurrentText(
getSettings()->timeoutDurationUnit6);
timeout6.append(timeoutDurationUnit6);
QSpinBox *spinBoxDurationCalculated6 = new QSpinBox;
spinBoxDurationCalculated6->setRange(1, 1209600);
spinBoxDurationCalculated6->setValue(
getSettings()->timeoutDurationInSec6);
spinBoxDurationCalculated6->setReadOnly(true);
spinBoxDurationCalculated6->setAlignment(Qt::AlignRight);
timeout6.append(spinBoxDurationCalculated6);
QObject::connect(lineEditDurationInput6, &QLineEdit::textChanged,
[=] {
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput6,
getSettings()->timeoutDurationUnit6,
*spinBoxDurationCalculated6,
getSettings()->timeoutDurationPerUnit6);
});
QObject::connect(spinBoxDurationCalculated6,
qOverload<int>(&QSpinBox::valueChanged), [=] {
AdvancedPage::calculatedDurationChanged(
spinBoxDurationCalculated6->value(),
getSettings()->timeoutDurationInSec6);
});
QObject::connect(timeoutDurationUnit6,
&QComboBox::currentTextChanged, [=] {
AdvancedPage::timeoutUnitChanged(
timeoutDurationUnit6->currentText(),
getSettings()->timeoutDurationUnit6);
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput6,
getSettings()->timeoutDurationUnit6,
*spinBoxDurationCalculated6,
getSettings()->timeoutDurationPerUnit6);
});
auto secondsLabel = timeout6.emplace<QLabel>();
secondsLabel->setText("seconds");
}
auto timeout7 = timeoutLayout.emplace<QHBoxLayout>().withoutMargin();
{
QLineEdit *lineEditDurationInput7 = new QLineEdit;
lineEditDurationInput7->setValidator(
new QIntValidator(1, 99, this));
lineEditDurationInput7->setText(
getSettings()->timeoutDurationPerUnit7);
lineEditDurationInput7->setAlignment(Qt::AlignRight);
timeout7.append(lineEditDurationInput7);
QComboBox *timeoutDurationUnit7 = new QComboBox();
timeoutDurationUnit7->addItems(units);
timeoutDurationUnit7->setCurrentText(
getSettings()->timeoutDurationUnit7);
timeout7.append(timeoutDurationUnit7);
QSpinBox *spinBoxDurationCalculated7 = new QSpinBox;
spinBoxDurationCalculated7->setRange(1, 1209600);
spinBoxDurationCalculated7->setValue(
getSettings()->timeoutDurationInSec7);
spinBoxDurationCalculated7->setReadOnly(true);
spinBoxDurationCalculated7->setAlignment(Qt::AlignRight);
timeout7.append(spinBoxDurationCalculated7);
QObject::connect(lineEditDurationInput7, &QLineEdit::textChanged,
[=] {
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput7,
getSettings()->timeoutDurationUnit7,
*spinBoxDurationCalculated7,
getSettings()->timeoutDurationPerUnit7);
});
QObject::connect(spinBoxDurationCalculated7,
qOverload<int>(&QSpinBox::valueChanged), [=] {
AdvancedPage::calculatedDurationChanged(
spinBoxDurationCalculated7->value(),
getSettings()->timeoutDurationInSec7);
});
QObject::connect(timeoutDurationUnit7,
&QComboBox::currentTextChanged, [=] {
AdvancedPage::timeoutUnitChanged(
timeoutDurationUnit7->currentText(),
getSettings()->timeoutDurationUnit7);
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput7,
getSettings()->timeoutDurationUnit7,
*spinBoxDurationCalculated7,
getSettings()->timeoutDurationPerUnit7);
});
auto secondsLabel = timeout7.emplace<QLabel>();
secondsLabel->setText("seconds");
}
auto timeout8 = timeoutLayout.emplace<QHBoxLayout>().withoutMargin();
{
QLineEdit *lineEditDurationInput8 = new QLineEdit;
lineEditDurationInput8->setValidator(
new QIntValidator(1, 99, this));
lineEditDurationInput8->setText(
getSettings()->timeoutDurationPerUnit8);
lineEditDurationInput8->setAlignment(Qt::AlignRight);
timeout8.append(lineEditDurationInput8);
QComboBox *timeoutDurationUnit8 = new QComboBox();
timeoutDurationUnit8->addItems(units);
timeoutDurationUnit8->setCurrentText(
getSettings()->timeoutDurationUnit8);
timeout8.append(timeoutDurationUnit8);
QSpinBox *spinBoxDurationCalculated8 = new QSpinBox;
spinBoxDurationCalculated8->setRange(1, 1209600);
spinBoxDurationCalculated8->setValue(
getSettings()->timeoutDurationInSec8);
spinBoxDurationCalculated8->setReadOnly(true);
spinBoxDurationCalculated8->setAlignment(Qt::AlignRight);
timeout8.append(spinBoxDurationCalculated8);
QObject::connect(lineEditDurationInput8, &QLineEdit::textChanged,
[=] {
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput8,
getSettings()->timeoutDurationUnit8,
*spinBoxDurationCalculated8,
getSettings()->timeoutDurationPerUnit8);
});
QObject::connect(spinBoxDurationCalculated8,
qOverload<int>(&QSpinBox::valueChanged), [=] {
AdvancedPage::calculatedDurationChanged(
spinBoxDurationCalculated8->value(),
getSettings()->timeoutDurationInSec8);
});
QObject::connect(timeoutDurationUnit8,
&QComboBox::currentTextChanged, [=] {
AdvancedPage::timeoutUnitChanged(
timeoutDurationUnit8->currentText(),
getSettings()->timeoutDurationUnit8);
AdvancedPage::timeoutDurationChanged(
*lineEditDurationInput8,
getSettings()->timeoutDurationUnit8,
*spinBoxDurationCalculated8,
getSettings()->timeoutDurationPerUnit8);
});
auto secondsLabel = timeout8.emplace<QLabel>();
secondsLabel->setText("seconds");
++itDurationPerUnit;
++itUnit;
++itDurationInSec;
++itDurationInput;
++itUnitInput;
++itDurationsCalculated;
}
}
// Timeoutbuttons end
}
void AdvancedPage::timeoutDurationChanged(QLineEdit &durationPerUnit,
const QString &unit,
QSpinBox &durationInSec,
QStringSetting settingDurationPerUnit)
void AdvancedPage::timeoutDurationChanged(const QString &newDuration)
{
int valueInUnit = durationPerUnit.text().toInt();
QObject *sender = QObject::sender();
int index = sender->objectName().toInt();
itDurationInput = durationInputs.begin() + index;
QLineEdit *durationPerUnit = *itDurationInput;
itUnitInput = unitInputs.begin() + index;
QComboBox *cbUnit = *itUnitInput;
QString unit = cbUnit->currentText();
itDurationsCalculated = durationsCalculated.begin() + index;
QSpinBox *sbDurationInSec = *itDurationsCalculated;
int valueInUnit = newDuration.toInt();
int valueInSec;
log(newDuration);
log(unit);
if (unit == "s")
{
valueInSec = valueInUnit;
}
else if (unit == "m")
{
if (valueInUnit > 20160)
{
durationPerUnit.setText("20160");
return;
}
valueInSec = valueInUnit * 60;
}
else if (unit == "h")
{
if (valueInUnit > 336)
{
durationPerUnit.setText("336");
return;
}
valueInSec = valueInUnit * 60 * 60;
}
else if (unit == "d")
{
if (valueInUnit > 14)
{
durationPerUnit.setText("14");
durationPerUnit->setText("14");
return;
}
valueInSec = valueInUnit * 24 * 60 * 60;
@ -591,25 +253,113 @@ void AdvancedPage::timeoutDurationChanged(QLineEdit &durationPerUnit,
{
if (valueInUnit > 2)
{
durationPerUnit.setText("2");
durationPerUnit->setText("2");
return;
}
valueInSec = valueInUnit * 7 * 24 * 60 * 60;
}
durationInSec.setValue(valueInSec);
settingDurationPerUnit = durationPerUnit.text();
sbDurationInSec->setValue(valueInSec);
switch (index)
{
case 0:
getSettings()->timeoutDurationPerUnit1 = newDuration;
break;
case 1:
getSettings()->timeoutDurationPerUnit2 = newDuration;
break;
case 2:
getSettings()->timeoutDurationPerUnit3 = newDuration;
break;
case 3:
getSettings()->timeoutDurationPerUnit4 = newDuration;
break;
case 4:
getSettings()->timeoutDurationPerUnit5 = newDuration;
break;
case 5:
getSettings()->timeoutDurationPerUnit6 = newDuration;
break;
case 6:
getSettings()->timeoutDurationPerUnit7 = newDuration;
break;
case 7:
getSettings()->timeoutDurationPerUnit8 = newDuration;
break;
}
}
void AdvancedPage::calculatedDurationChanged(const int durationInSec,
IntSetting settingDurationInSec)
void AdvancedPage::calculatedDurationChanged(const int &newDurationInSec)
{
settingDurationInSec = durationInSec;
QObject *sender = QObject::sender();
int index = sender->objectName().toInt();
switch (index)
{
case 0:
getSettings()->timeoutDurationInSec1 = newDurationInSec;
break;
case 1:
getSettings()->timeoutDurationInSec2 = newDurationInSec;
break;
case 2:
getSettings()->timeoutDurationInSec3 = newDurationInSec;
break;
case 3:
getSettings()->timeoutDurationInSec4 = newDurationInSec;
break;
case 4:
getSettings()->timeoutDurationInSec5 = newDurationInSec;
break;
case 5:
getSettings()->timeoutDurationInSec6 = newDurationInSec;
break;
case 6:
getSettings()->timeoutDurationInSec7 = newDurationInSec;
break;
case 7:
getSettings()->timeoutDurationInSec8 = newDurationInSec;
break;
}
}
void AdvancedPage::timeoutUnitChanged(const QString newUnit,
QStringSetting settingUnit)
void AdvancedPage::timeoutUnitChanged(const QString &newUnit)
{
settingUnit = newUnit;
QObject *sender = QObject::sender();
int index = sender->objectName().toInt();
switch (index)
{
case 0:
getSettings()->timeoutDurationUnit1 = newUnit;
break;
case 1:
getSettings()->timeoutDurationUnit2 = newUnit;
break;
case 2:
getSettings()->timeoutDurationUnit3 = newUnit;
break;
case 3:
getSettings()->timeoutDurationUnit4 = newUnit;
break;
case 4:
getSettings()->timeoutDurationUnit5 = newUnit;
break;
case 5:
getSettings()->timeoutDurationUnit6 = newUnit;
break;
case 6:
getSettings()->timeoutDurationUnit7 = newUnit;
break;
case 7:
getSettings()->timeoutDurationUnit8 = newUnit;
break;
}
itDurationInput = durationInputs.begin() + index;
QLineEdit *durationPerUnit = *itDurationInput;
AdvancedPage::timeoutDurationChanged(durationPerUnit->text());
}
} // namespace chatterino

View file

@ -9,16 +9,24 @@ class AdvancedPage : public SettingsPage
public:
AdvancedPage();
void timeoutDurationChanged(QLineEdit &durationPerUnit, const QString &unit,
QSpinBox &durationInSec,
QStringSetting settingDurationInUnit);
void calculatedDurationChanged(const int durationInSec,
IntSetting settingDurationInSec);
void timeoutUnitChanged(const QString newUnit, QStringSetting settingUnit);
private:
// list needed for dynamic timeout settings
QList<QLineEdit *> durationInputs;
QList<QComboBox *> unitInputs;
QList<QSpinBox *> durationsCalculated;
// iterators used in dynamic timeout settings
QList<QLineEdit *>::iterator itDurationInput;
QList<QComboBox *>::iterator itUnitInput;
QList<QSpinBox *>::iterator itDurationsCalculated;
private slots:
void timeoutDurationChanged(const QString &newDuration);
void calculatedDurationChanged(const int &newDurationInSec);
void timeoutUnitChanged(const QString &newUnit);
};
} // namespace chatterino