mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-17 03:50:03 +02:00
gui/MultiSelect: Add user_add_item parameter to constructor
adds a button and signal to the MultiSelect, allowing client code to implement adding items from user input.
This commit is contained in:
parent
925ef7e8ad
commit
50a2805c3f
2 changed files with 23 additions and 3 deletions
|
|
@ -28,8 +28,8 @@
|
|||
#include <QListWidgetItem>
|
||||
#include "MultiSelect.h"
|
||||
|
||||
MultiSelect::MultiSelect(const QString& text, QWidget *parent) :
|
||||
QPushButton (text + ": none", parent)
|
||||
MultiSelect::MultiSelect(const QString& text, bool user_can_add, QWidget *parent) :
|
||||
QPushButton (text + ": none", parent)
|
||||
{
|
||||
QPushButton* btn;
|
||||
QVBoxLayout* layout;
|
||||
|
|
@ -52,6 +52,13 @@ QPushButton (text + ": none", parent)
|
|||
QObject::connect(btn, SIGNAL(clicked()), m_dialog, SLOT(accept()));
|
||||
QObject::connect(m_dialog, SIGNAL(accepted()), this, SLOT(selectionConfirmed()));
|
||||
QObject::connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(listItemClicked(QListWidgetItem*)));
|
||||
|
||||
// Configured to let users add items. provide button and signal.
|
||||
if (user_can_add) {
|
||||
btn = new QPushButton("Add");
|
||||
layout->addWidget(btn);
|
||||
QObject::connect(btn, SIGNAL(clicked()), this, SLOT(addBtnClicked()));
|
||||
}
|
||||
}
|
||||
|
||||
void MultiSelect::addItem(const QString& text, bool checked)
|
||||
|
|
@ -125,6 +132,12 @@ void MultiSelect::listItemClicked(QListWidgetItem *item)
|
|||
item->setCheckState(checked ? Qt::Unchecked : Qt::Checked);
|
||||
}
|
||||
|
||||
void MultiSelect::addBtnClicked()
|
||||
{
|
||||
// Just emit addNewItem event.
|
||||
emit addNewItem();
|
||||
}
|
||||
|
||||
void MultiSelect::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class MultiSelect : public QPushButton
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MultiSelect(const QString& text, QWidget *parent = 0);
|
||||
MultiSelect(const QString& text, bool user_add_item = false, QWidget *parent = 0);
|
||||
|
||||
// Items.
|
||||
|
||||
|
|
@ -61,6 +61,10 @@ signals:
|
|||
// This signal is emitted whenever the user has made a new selection.
|
||||
void selectionChanged(QStringList selected);
|
||||
|
||||
// This signal is emitted whenever the user clicks the "Add" button.
|
||||
// NOTE: Will only be emitted if `user_add_item` has been set to `true` in the constructor.
|
||||
void addNewItem();
|
||||
|
||||
private slots :
|
||||
|
||||
// Called when the dialog is accepted.
|
||||
|
|
@ -69,6 +73,9 @@ private slots :
|
|||
// Called when a list item is clicked on.
|
||||
void listItemClicked(QListWidgetItem *item);
|
||||
|
||||
// Called when the add button is clicked on.
|
||||
void addBtnClicked();
|
||||
|
||||
protected :
|
||||
|
||||
// Event handlers
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue