simplified settings page UI

simplfied UI and removed unneccessary code
This commit is contained in:
TranRed 2019-07-19 17:34:25 +02:00
parent 00ad80d93d
commit dc01cbf2a3
2 changed files with 32 additions and 90 deletions

View file

@ -3,7 +3,6 @@
#include "Application.hpp" #include "Application.hpp"
#include "controllers/taggedusers/TaggedUsersController.hpp" #include "controllers/taggedusers/TaggedUsersController.hpp"
#include "controllers/taggedusers/TaggedUsersModel.hpp" #include "controllers/taggedusers/TaggedUsersModel.hpp"
#include "debug/Log.hpp"
#include "singletons/Logging.hpp" #include "singletons/Logging.hpp"
#include "singletons/Paths.hpp" #include "singletons/Paths.hpp"
#include "util/Helpers.hpp" #include "util/Helpers.hpp"
@ -118,55 +117,46 @@ AdvancedPage::AdvancedPage()
QStringList::iterator itUnit; QStringList::iterator itUnit;
itUnit = initUnits.begin(); 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++) for (int i = 0; i < 8; i++)
{ {
durationInputs.append(new QLineEdit()); durationInputs.append(new QLineEdit());
unitInputs.append(new QComboBox()); unitInputs.append(new QComboBox());
durationsCalculated.append(new QSpinBox());
} }
itDurationInput = durationInputs.begin(); itDurationInput = durationInputs.begin();
itUnitInput = unitInputs.begin(); itUnitInput = unitInputs.begin();
itDurationsCalculated = durationsCalculated.begin();
auto timeoutLayout = tabs.appendTab(new QVBoxLayout, "Timeouts"); auto timeoutLayout = tabs.appendTab(new QVBoxLayout, "Timeouts");
auto infoLabel = timeoutLayout.emplace<QLabel>(); auto texts = timeoutLayout.emplace<QVBoxLayout>().withoutMargin();
infoLabel->setText("Customize your timeout buttons in seconds (s), " {
"minutes (m), hours (h), days (d) or weeks (w)."); auto infoLabel = texts.emplace<QLabel>();
auto maxLabel = timeoutLayout.emplace<QLabel>(); infoLabel->setText(
maxLabel->setText("Maximum timeout duration is 2 weeks = 14 days = 336 " "Customize your timeout buttons in seconds (s), "
"hours = 20,160 minutes = 1,209,600 seconds."); "minutes (m), hours (h), days (d) or weeks (w).");
auto allowedLabel = timeoutLayout.emplace<QLabel>();
allowedLabel->setText( infoLabel->setAlignment(Qt::AlignCenter);
"For simplicity only values from 1 to 99 are allowed here. Using "
"the units accordingly is highly recommended."); auto maxLabel = texts.emplace<QLabel>();
auto commandLabel = timeoutLayout.emplace<QLabel>(); maxLabel->setText("(maximum timeout duration = 2 w)");
commandLabel->setText( maxLabel->setAlignment(Qt::AlignCenter);
"For abitrary timeout durations use the /timeout command."); }
texts->setContentsMargins(0, 0, 0, 15);
texts->setSizeConstraint(QLayout::SetMaximumSize);
// build one line for each customizable button // build one line for each customizable button
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
auto timeout = timeoutLayout.emplace<QHBoxLayout>().withoutMargin(); auto timeout = timeoutLayout.emplace<QHBoxLayout>().withoutMargin();
{ {
auto buttonLabel = timeout.emplace<QLabel>();
buttonLabel->setText("Button " + QString::number(i + 1) + ": ");
QLineEdit *lineEditDurationInput = *itDurationInput; QLineEdit *lineEditDurationInput = *itDurationInput;
lineEditDurationInput->setObjectName(QString::number(i)); lineEditDurationInput->setObjectName(QString::number(i));
lineEditDurationInput->setValidator( lineEditDurationInput->setValidator(
new QIntValidator(1, 99, this)); new QIntValidator(1, 99, this));
lineEditDurationInput->setText(*itDurationPerUnit); lineEditDurationInput->setText(*itDurationPerUnit);
lineEditDurationInput->setAlignment(Qt::AlignRight); lineEditDurationInput->setAlignment(Qt::AlignRight);
lineEditDurationInput->setMaximumWidth(30);
timeout.append(lineEditDurationInput); timeout.append(lineEditDurationInput);
QComboBox *timeoutDurationUnit = *itUnitInput; QComboBox *timeoutDurationUnit = *itUnitInput;
@ -175,14 +165,6 @@ AdvancedPage::AdvancedPage()
timeoutDurationUnit->setCurrentText(*itUnit); timeoutDurationUnit->setCurrentText(*itUnit);
timeout.append(timeoutDurationUnit); timeout.append(timeoutDurationUnit);
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(lineEditDurationInput, &QLineEdit::textChanged, QObject::connect(lineEditDurationInput, &QLineEdit::textChanged,
this, &AdvancedPage::timeoutDurationChanged); this, &AdvancedPage::timeoutDurationChanged);
@ -190,21 +172,18 @@ AdvancedPage::AdvancedPage()
&QComboBox::currentTextChanged, this, &QComboBox::currentTextChanged, this,
&AdvancedPage::timeoutUnitChanged); &AdvancedPage::timeoutUnitChanged);
QObject::connect(spinBoxDurationCalculated,
qOverload<int>(&QSpinBox::valueChanged), this,
&AdvancedPage::calculatedDurationChanged);
auto secondsLabel = timeout.emplace<QLabel>(); auto secondsLabel = timeout.emplace<QLabel>();
secondsLabel->setText("seconds"); timeout->addStretch();
} }
timeout->setContentsMargins(40, 0, 0, 0);
timeout->setSizeConstraint(QLayout::SetMaximumSize);
++itDurationPerUnit; ++itDurationPerUnit;
++itUnit; ++itUnit;
++itDurationInSec;
++itDurationInput; ++itDurationInput;
++itUnitInput; ++itUnitInput;
++itDurationsCalculated;
} }
timeoutLayout->addStretch();
} }
// Timeoutbuttons end // Timeoutbuttons end
} }
@ -221,13 +200,9 @@ void AdvancedPage::timeoutDurationChanged(const QString &newDuration)
QComboBox *cbUnit = *itUnitInput; QComboBox *cbUnit = *itUnitInput;
QString unit = cbUnit->currentText(); QString unit = cbUnit->currentText();
itDurationsCalculated = durationsCalculated.begin() + index;
QSpinBox *sbDurationInSec = *itDurationsCalculated;
int valueInUnit = newDuration.toInt(); int valueInUnit = newDuration.toInt();
int valueInSec; int valueInSec;
log(newDuration);
log(unit);
if (unit == "s") if (unit == "s")
{ {
valueInSec = valueInUnit; valueInSec = valueInUnit;
@ -259,66 +234,39 @@ void AdvancedPage::timeoutDurationChanged(const QString &newDuration)
valueInSec = valueInUnit * 7 * 24 * 60 * 60; valueInSec = valueInUnit * 7 * 24 * 60 * 60;
} }
sbDurationInSec->setValue(valueInSec);
switch (index) switch (index)
{ {
case 0: case 0:
getSettings()->timeoutDurationPerUnit1 = newDuration; getSettings()->timeoutDurationPerUnit1 = newDuration;
getSettings()->timeoutDurationInSec1 = valueInSec;
break; break;
case 1: case 1:
getSettings()->timeoutDurationPerUnit2 = newDuration; getSettings()->timeoutDurationPerUnit2 = newDuration;
getSettings()->timeoutDurationInSec2 = valueInSec;
break; break;
case 2: case 2:
getSettings()->timeoutDurationPerUnit3 = newDuration; getSettings()->timeoutDurationPerUnit3 = newDuration;
getSettings()->timeoutDurationInSec3 = valueInSec;
break; break;
case 3: case 3:
getSettings()->timeoutDurationPerUnit4 = newDuration; getSettings()->timeoutDurationPerUnit4 = newDuration;
getSettings()->timeoutDurationInSec4 = valueInSec;
break; break;
case 4: case 4:
getSettings()->timeoutDurationPerUnit5 = newDuration; getSettings()->timeoutDurationPerUnit5 = newDuration;
getSettings()->timeoutDurationInSec5 = valueInSec;
break; break;
case 5: case 5:
getSettings()->timeoutDurationPerUnit6 = newDuration; getSettings()->timeoutDurationPerUnit6 = newDuration;
getSettings()->timeoutDurationInSec6 = valueInSec;
break; break;
case 6: case 6:
getSettings()->timeoutDurationPerUnit7 = newDuration; getSettings()->timeoutDurationPerUnit7 = newDuration;
getSettings()->timeoutDurationInSec7 = valueInSec;
break; break;
case 7: case 7:
getSettings()->timeoutDurationPerUnit8 = newDuration; getSettings()->timeoutDurationPerUnit8 = newDuration;
break; getSettings()->timeoutDurationInSec8 = valueInSec;
}
}
void AdvancedPage::calculatedDurationChanged(const int &newDurationInSec)
{
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; break;
} }
} }

View file

@ -13,19 +13,13 @@ private:
// list needed for dynamic timeout settings // list needed for dynamic timeout settings
QList<QLineEdit *> durationInputs; QList<QLineEdit *> durationInputs;
QList<QComboBox *> unitInputs; QList<QComboBox *> unitInputs;
QList<QSpinBox *> durationsCalculated;
// iterators used in dynamic timeout settings // iterators used in dynamic timeout settings
QList<QLineEdit *>::iterator itDurationInput; QList<QLineEdit *>::iterator itDurationInput;
QList<QComboBox *>::iterator itUnitInput; QList<QComboBox *>::iterator itUnitInput;
QList<QSpinBox *>::iterator itDurationsCalculated;
private slots: private slots:
void timeoutDurationChanged(const QString &newDuration); void timeoutDurationChanged(const QString &newDuration);
void calculatedDurationChanged(const int &newDurationInSec);
void timeoutUnitChanged(const QString &newUnit); void timeoutUnitChanged(const QString &newUnit);
}; };