Added delay button
This commit is contained in:
@@ -123,7 +123,9 @@ void ButtonController::addButton(const QString &label,
|
||||
const QString &actionUrl,
|
||||
const QString &successText,
|
||||
const QString &errorText,
|
||||
const QString &color)
|
||||
const QString &color,
|
||||
const QString &triggerMode,
|
||||
int holdMs)
|
||||
{
|
||||
QJsonObject action;
|
||||
action.insert("type", actionType.isEmpty() ? "http_get" : actionType);
|
||||
@@ -136,12 +138,17 @@ void ButtonController::addButton(const QString &label,
|
||||
feedback.insert("errorText", errorText);
|
||||
feedback.insert("fadeMs", 5000);
|
||||
|
||||
QJsonObject trigger;
|
||||
trigger.insert("mode", triggerMode == "click" ? "click" : "hold");
|
||||
trigger.insert("holdMs", holdMs > 0 ? holdMs : 800);
|
||||
|
||||
QJsonObject btn;
|
||||
btn.insert("label", label);
|
||||
btn.insert("iconPath", iconPath);
|
||||
btn.insert("color", color.isEmpty() ? "#7b007b" : color);
|
||||
btn.insert("action", action);
|
||||
btn.insert("feedback", feedback);
|
||||
btn.insert("trigger", trigger);
|
||||
m_config->addButton(btn);
|
||||
}
|
||||
|
||||
@@ -152,7 +159,9 @@ void ButtonController::updateButton(const QString &id,
|
||||
const QString &actionUrl,
|
||||
const QString &successText,
|
||||
const QString &errorText,
|
||||
const QString &color)
|
||||
const QString &color,
|
||||
const QString &triggerMode,
|
||||
int holdMs)
|
||||
{
|
||||
QJsonArray arr = m_config->buttons();
|
||||
for (const auto &v : arr) {
|
||||
@@ -165,11 +174,15 @@ void ButtonController::updateButton(const QString &id,
|
||||
feedback.insert("successText", successText);
|
||||
feedback.insert("errorText", errorText);
|
||||
if (!feedback.contains("fadeMs")) feedback.insert("fadeMs", 5000);
|
||||
QJsonObject trigger = b.value("trigger").toObject();
|
||||
trigger.insert("mode", triggerMode == "click" ? "click" : "hold");
|
||||
trigger.insert("holdMs", holdMs > 0 ? holdMs : trigger.value("holdMs").toInt(800));
|
||||
b.insert("label", label);
|
||||
b.insert("iconPath", iconPath);
|
||||
b.insert("color", color.isEmpty() ? "#7b007b" : color);
|
||||
b.insert("action", action);
|
||||
b.insert("feedback", feedback);
|
||||
b.insert("trigger", trigger);
|
||||
m_config->updateButton(id, b);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ public:
|
||||
const QString &actionUrl,
|
||||
const QString &successText,
|
||||
const QString &errorText,
|
||||
const QString &color = QString());
|
||||
const QString &color = QString(),
|
||||
const QString &triggerMode = QString(),
|
||||
int holdMs = 0);
|
||||
Q_INVOKABLE void updateButton(const QString &id,
|
||||
const QString &label,
|
||||
const QString &iconPath,
|
||||
@@ -34,7 +36,9 @@ public:
|
||||
const QString &actionUrl,
|
||||
const QString &successText,
|
||||
const QString &errorText,
|
||||
const QString &color = QString());
|
||||
const QString &color = QString(),
|
||||
const QString &triggerMode = QString(),
|
||||
int holdMs = 0);
|
||||
Q_INVOKABLE void removeButton(const QString &id);
|
||||
Q_INVOKABLE void moveButton(int from, int to);
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ QVariant ButtonsModel::data(const QModelIndex &index, int role) const
|
||||
QString id = b.value("id").toString();
|
||||
QJsonObject action = b.value("action").toObject();
|
||||
QJsonObject feedback = b.value("feedback").toObject();
|
||||
QJsonObject trigger = b.value("trigger").toObject();
|
||||
RuntimeState rt = m_runtime.value(id);
|
||||
|
||||
switch (role) {
|
||||
@@ -67,6 +68,8 @@ QVariant ButtonsModel::data(const QModelIndex &index, int role) const
|
||||
case StatusRole: return rt.status;
|
||||
case StatusTextRole: return rt.text;
|
||||
case BtnColorRole: return b.value("color").toString("#7b007b");
|
||||
case TriggerModeRole: return trigger.value("mode").toString("hold");
|
||||
case HoldMsRole: return trigger.value("holdMs").toInt(800);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -86,7 +89,9 @@ QHash<int, QByteArray> ButtonsModel::roleNames() const
|
||||
{FadeMsRole, "fadeMs"},
|
||||
{StatusRole, "status"},
|
||||
{StatusTextRole, "statusText"},
|
||||
{BtnColorRole, "btnColor"}
|
||||
{BtnColorRole, "btnColor"},
|
||||
{TriggerModeRole, "triggerMode"},
|
||||
{HoldMsRole, "holdMs"}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -26,7 +26,9 @@ public:
|
||||
FadeMsRole,
|
||||
StatusRole, // 0=idle, 1=ok, 2=error, 3=in-progress
|
||||
StatusTextRole,
|
||||
BtnColorRole
|
||||
BtnColorRole,
|
||||
TriggerModeRole, // "hold" | "click"
|
||||
HoldMsRole
|
||||
};
|
||||
|
||||
explicit ButtonsModel(ConfigManager *config, QObject *parent = nullptr);
|
||||
|
||||
Reference in New Issue
Block a user