|
|
@ -39,77 +39,77 @@
|
|
|
|
NotificationActionsWidget::NotificationActionsWidget(const QStringList& actions, QWidget *parent)
|
|
|
|
NotificationActionsWidget::NotificationActionsWidget(const QStringList& actions, QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i = 0; i < actions.count(); ++i)
|
|
|
|
for (int i = 0; i < actions.count(); i += 2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (i == actions.count()-1)
|
|
|
|
QString key = actions[i];
|
|
|
|
{
|
|
|
|
QString value;
|
|
|
|
qDebug() << "NotificationActionsWidget actions has contains pairs (id, value, id, value...) got odd count:" << actions.count() << "Actions:" << actions;
|
|
|
|
|
|
|
|
m_actionMap[actions.at(i)] = actions.at(i);
|
|
|
|
if (i == actions.count() - 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_actionMap[actions.at(i)] = actions.at(i+1);
|
|
|
|
value = key;
|
|
|
|
|
|
|
|
qWarning() << "Odd number of elements in action list. Last action will use key as text (" << key << ")";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
value = actions[i + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++i; // move to the next ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if there is only one action let's take it as a default one
|
|
|
|
if (key == "default")
|
|
|
|
if (m_actionMap.count() == 1)
|
|
|
|
m_defaultAction = key;
|
|
|
|
m_defaultAction = m_actionMap[m_actionMap.keys().at(0)];
|
|
|
|
|
|
|
|
|
|
|
|
m_actions.append({key, value});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "NotificationActionsWidget processed actions:" << m_actionMap;
|
|
|
|
// if there is only one action let's use it as the default one
|
|
|
|
|
|
|
|
if (m_actions.count() == 1)
|
|
|
|
|
|
|
|
m_defaultAction = m_actions[0].first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NotificationActionsButtonsWidget::NotificationActionsButtonsWidget(const QStringList& actions, QWidget *parent)
|
|
|
|
NotificationActionsButtonsWidget::NotificationActionsButtonsWidget(const QStringList& actions, QWidget *parent)
|
|
|
|
: NotificationActionsWidget(actions, parent)
|
|
|
|
: NotificationActionsWidget(actions, parent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QHashIterator<QString,QString> it(m_actionMap);
|
|
|
|
|
|
|
|
QHBoxLayout *l = new QHBoxLayout();
|
|
|
|
QHBoxLayout *l = new QHBoxLayout();
|
|
|
|
setLayout(l);
|
|
|
|
setLayout(l);
|
|
|
|
|
|
|
|
|
|
|
|
QButtonGroup *group = new QButtonGroup(this);
|
|
|
|
QButtonGroup *group = new QButtonGroup(this);
|
|
|
|
|
|
|
|
|
|
|
|
while (it.hasNext())
|
|
|
|
for (auto const & action : m_actions)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
it.next();
|
|
|
|
QPushButton *b = new QPushButton(action.second, this);
|
|
|
|
QPushButton *b = new QPushButton(it.value(), this);
|
|
|
|
b->setObjectName(action.first);
|
|
|
|
l->addWidget(b);
|
|
|
|
l->addWidget(b);
|
|
|
|
group->addButton(b);
|
|
|
|
group->addButton(b);
|
|
|
|
if (it.key() == "default")
|
|
|
|
|
|
|
|
{
|
|
|
|
if (action.first == m_defaultAction)
|
|
|
|
b->setFocus(Qt::OtherFocusReason);
|
|
|
|
b->setFocus(Qt::OtherFocusReason);
|
|
|
|
m_defaultAction = it.key();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
connect(group, SIGNAL(buttonClicked(QAbstractButton*)),
|
|
|
|
connect(group, static_cast<void (QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonClicked),
|
|
|
|
this, SLOT(actionButtonActivated(QAbstractButton*)));
|
|
|
|
this, &NotificationActionsButtonsWidget::actionButtonActivated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NotificationActionsButtonsWidget::actionButtonActivated(QAbstractButton* button)
|
|
|
|
void NotificationActionsButtonsWidget::actionButtonActivated(QAbstractButton* button)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
emit actionTriggered(m_actionMap.key(button->text()));
|
|
|
|
emit actionTriggered(button->objectName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NotificationActionsComboWidget::NotificationActionsComboWidget(const QStringList& actions, QWidget *parent)
|
|
|
|
NotificationActionsComboWidget::NotificationActionsComboWidget(const QStringList& actions, QWidget *parent)
|
|
|
|
: NotificationActionsWidget(actions, parent)
|
|
|
|
: NotificationActionsWidget(actions, parent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QHashIterator<QString,QString> it(m_actionMap);
|
|
|
|
|
|
|
|
QHBoxLayout *l = new QHBoxLayout();
|
|
|
|
QHBoxLayout *l = new QHBoxLayout();
|
|
|
|
setLayout(l);
|
|
|
|
setLayout(l);
|
|
|
|
|
|
|
|
|
|
|
|
l->addWidget(new QLabel(tr("Actions:"), this));
|
|
|
|
l->addWidget(new QLabel(tr("Actions:"), this));
|
|
|
|
m_comboBox = new QComboBox(this);
|
|
|
|
m_comboBox = new QComboBox(this);
|
|
|
|
int currentIndex = -1;
|
|
|
|
int currentIndex = -1;
|
|
|
|
while (it.hasNext())
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_actions.count(); ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
it.next();
|
|
|
|
auto const & action = m_actions[i];
|
|
|
|
m_comboBox->addItem(it.value(), it.key());
|
|
|
|
|
|
|
|
if (it.key() == "default")
|
|
|
|
m_comboBox->addItem(action.second, action.first);
|
|
|
|
|
|
|
|
if (action.first == m_defaultAction)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
currentIndex = m_comboBox->count()-1;
|
|
|
|
currentIndex = i;
|
|
|
|
m_defaultAction = it.key();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l->addWidget(m_comboBox);
|
|
|
|
l->addWidget(m_comboBox);
|
|
|
@ -119,8 +119,8 @@ NotificationActionsComboWidget::NotificationActionsComboWidget(const QStringList
|
|
|
|
|
|
|
|
|
|
|
|
QPushButton *b = new QPushButton(tr("OK"), this);
|
|
|
|
QPushButton *b = new QPushButton(tr("OK"), this);
|
|
|
|
l->addWidget(b);
|
|
|
|
l->addWidget(b);
|
|
|
|
connect(b, SIGNAL(clicked()),
|
|
|
|
connect(b, &QPushButton::clicked,
|
|
|
|
this, SLOT(actionComboBoxActivated()));
|
|
|
|
this, &NotificationActionsComboWidget::actionComboBoxActivated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NotificationActionsComboWidget::actionComboBoxActivated()
|
|
|
|
void NotificationActionsComboWidget::actionComboBoxActivated()
|
|
|
@ -130,5 +130,5 @@ void NotificationActionsComboWidget::actionComboBoxActivated()
|
|
|
|
int ix = m_comboBox->currentIndex();
|
|
|
|
int ix = m_comboBox->currentIndex();
|
|
|
|
if (ix == -1)
|
|
|
|
if (ix == -1)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
emit actionTriggered(m_actionMap.key(m_comboBox->itemText(ix)));
|
|
|
|
emit actionTriggered(m_actions[ix].first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|