7 #include "fwGuiQt/dialog/SelectorDialog.hpp" 9 #include <fwCore/base.hpp> 11 #include <fwGui/registry/macros.hpp> 13 #include <QApplication> 15 #include <QHBoxLayout> 17 #include <QListWidget> 18 #include <QPushButton> 19 #include <QVBoxLayout> 38 SelectorDialog::~SelectorDialog()
46 this->m_selections = _selections;
53 this->m_title = _title;
60 QWidget* parent = qApp->activeWindow();
62 QDialog* dialog =
new QDialog(parent);
63 dialog->setWindowTitle(QString::fromStdString(m_title));
65 QListWidget* selectionList =
new QListWidget(dialog);
66 for( std::string selection : m_selections)
68 selectionList->addItem(QString::fromStdString( selection ));
71 QListWidgetItem* firstItem = selectionList->item(0);
72 selectionList->setCurrentItem(firstItem);
74 QPushButton* okButton =
new QPushButton(QObject::tr(
"Ok"));
75 QPushButton* cancelButton =
new QPushButton(QObject::tr(
"Cancel"));
77 QHBoxLayout* hLayout =
new QHBoxLayout();
78 hLayout->addWidget(okButton);
79 hLayout->addWidget(cancelButton);
81 for(
auto customButton : m_customButtons)
83 hLayout->addWidget(customButton);
84 QObject::connect(customButton, SIGNAL(clicked()), dialog, SLOT(reject()));
87 QVBoxLayout* vLayout =
new QVBoxLayout();
88 if(!m_message.empty())
90 QLabel* msgText =
new QLabel(QString::fromStdString(m_message), dialog);
91 vLayout->addWidget( msgText);
93 vLayout->addWidget(selectionList);
94 vLayout->addLayout(hLayout);
96 dialog->setLayout(vLayout);
97 QObject::connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept()));
98 QObject::connect(cancelButton, SIGNAL(clicked()), dialog, SLOT(reject()));
99 QObject::connect(selectionList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), dialog, SLOT(accept()));
101 std::string selection =
"";
104 selection = selectionList->currentItem()->text().toStdString();
121 QPushButton* button =
new QPushButton( QString::fromStdString(label) );
122 m_customButtons.push_back( button );
123 QObject::connect(button, &QPushButton::clicked, clickedFn);
virtual FWGUI_API void setSelections(std::vector< std::string > _selections) override
Set the string list that can be chosen by the selector.
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
static FWGUI_API const FactoryRegistryKeyType REGISTRY_KEY
this unique key should be used for all factory for specific Selector(qt,wx,...)
FWGUI_API void setTitle(std::string title) override
Sets the selector title.
The namespace fwGuiQt contains classes which provide the implementation of the Gui using Qt library...
FWGUI_API std::string show() override
Show the selector and return the selection.
virtual FWGUI_API void addCustomButton(const std::string &label, std::function< void()> clickedFn) override
Add a custom button to this dialog.
SelectorDialog allowing the choice of an element among severals (_selections)