Repeat custom interval now displayed in the menu
This commit is contained in:
parent
dd78a9fe70
commit
8da2f9f8d7
@ -6990,44 +6990,54 @@ void MainWindow::buildRepeatMenu(QMenu *menu, QPushButton * button, int * interv
|
|||||||
{"Repeat every 15 minutes", 15},
|
{"Repeat every 15 minutes", 15},
|
||||||
{"Repeat every 30 minutes", 30},
|
{"Repeat every 30 minutes", 30},
|
||||||
{"Repeat every 60 minutes", 60},
|
{"Repeat every 60 minutes", 60},
|
||||||
{"Repeat every N minutes (Custom Interval)", -1},
|
{"Repeat every N minutes (Custom Interval)", -1}, // this needs to be last because of isSet bool
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto customFormat = QString("Repeat every %1 minutes (Custom Interval)");
|
||||||
|
|
||||||
QActionGroup * group = new QActionGroup(menu);
|
QActionGroup * group = new QActionGroup(menu);
|
||||||
|
|
||||||
bool isSet = false;
|
bool isSet = false;
|
||||||
foreach(auto pair, items){
|
foreach(auto pair, items){
|
||||||
int minutes = pair.second;
|
int minutes = pair.second;
|
||||||
auto action = menu->addAction(pair.first);
|
|
||||||
action->setData(minutes);
|
|
||||||
action->setCheckable(true);
|
|
||||||
bool isMatch = *interval == minutes;
|
bool isMatch = *interval == minutes;
|
||||||
bool isCustom = (minutes == -1 && isSet == false);
|
bool isCustom = (minutes == -1 && isSet == false);
|
||||||
if(isMatch){
|
if(isMatch){
|
||||||
isSet = true;
|
isSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto text = pair.first;
|
||||||
|
if(isCustom){
|
||||||
|
text = QString(customFormat).arg(*interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto action = menu->addAction(text);
|
||||||
|
action->setData(minutes);
|
||||||
|
action->setCheckable(true);
|
||||||
action->setChecked(isMatch || isCustom);
|
action->setChecked(isMatch || isCustom);
|
||||||
group->addAction(action);
|
group->addAction(action);
|
||||||
|
|
||||||
connect(action, &QAction::toggled, this, [this, minutes, interval, button](bool checked){
|
connect(action, &QAction::toggled, this, [this, action, customFormat, minutes, interval, button](bool checked){
|
||||||
|
int min = minutes;
|
||||||
|
|
||||||
if(checked){
|
if(checked){
|
||||||
|
|
||||||
if(minutes == -1){
|
if(minutes == -1){
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
int min = QInputDialog::getInt(this, "Repeat every N minutes", "Minutes", 0, 1, 1440, 1, &ok);
|
min = QInputDialog::getInt(this, "Repeat every N minutes", "Minutes", 0, 1, 1440, 1, &ok);
|
||||||
if(!ok){
|
if(!ok){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*interval = min;
|
action->setText(QString(customFormat).arg(*interval));
|
||||||
} else {
|
|
||||||
*interval = minutes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(minutes > 0){
|
*interval = min;
|
||||||
|
|
||||||
|
if(min > 0){
|
||||||
// force a re-toggle
|
// force a re-toggle
|
||||||
button->setChecked(false);
|
button->setChecked(false);
|
||||||
}
|
}
|
||||||
button->setChecked(minutes > 0);
|
button->setChecked(min > 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user