7 #include "fwGuiQt/dialog/MessageDialog.hpp" 9 #include <fwGui/registry/macros.hpp> 11 #include <boost/assign/list_of.hpp> 13 #include <QApplication> 14 #include <QMessageBox> 15 #include <QPushButton> 27 typedef const std::map< ::fwGui::dialog::IMessageDialog::Icons, QMessageBox::Icon> MessageDialogQtIconsType;
28 MessageDialogQtIconsType messageDialogQtIcons =
29 ::boost::assign::map_list_of(::fwGui::dialog::IMessageDialog::NONE, QMessageBox::NoIcon )
30 (::fwGui::dialog::IMessageDialog::QUESTION, QMessageBox::Question )
31 (::fwGui::dialog::IMessageDialog::INFO, QMessageBox::Information)
32 (::fwGui::dialog::IMessageDialog::WARNING, QMessageBox::Warning )
33 (::fwGui::dialog::IMessageDialog::CRITICAL, QMessageBox::Critical );
36 QMessageBox::StandardButtons> MessageDialogQtButtonType;
37 MessageDialogQtButtonType messageDialogQtButton =
38 ::boost::assign::map_list_of(::fwGui::dialog::IMessageDialog::OK, QMessageBox::Ok )
39 (::fwGui::dialog::IMessageDialog::CANCEL, QMessageBox::Cancel)
40 (::fwGui::dialog::IMessageDialog::YES, QMessageBox::Yes )
41 (::fwGui::dialog::IMessageDialog::NO, QMessageBox::No );
46 m_buttons(::
fwGui::dialog::IMessageDialog::NOBUTTON),
47 m_defaultButton(::
fwGui::dialog::IMessageDialog::NOBUTTON),
48 m_icon(::
fwGui::dialog::IMessageDialog::NONE)
90 QPushButton* button =
new QPushButton( QString::fromStdString(label) );
91 m_customButtons.push_back( button );
92 QObject::connect(button, &QPushButton::clicked, clickedFn);
99 m_defaultButton = button;
106 MessageDialogQtIconsType::const_iterator iterIcon = messageDialogQtIcons.find(m_icon);
107 SLM_ASSERT(
"Unknown Icon", iterIcon != messageDialogQtIcons.end());
109 QMessageBox::Icon icon = iterIcon->second;
110 QString title = QString::fromStdString(m_title);
111 QString text = QString::fromStdString(m_message);
112 QMessageBox::StandardButtons buttons = QMessageBox::NoButton;
114 for(MessageDialogQtButtonType::value_type button : messageDialogQtButton)
116 if ( m_buttons & button.first)
118 buttons |= button.second;
122 QMessageBox box(icon, title, text, buttons, qApp->activeWindow());
124 for(
auto customButton : m_customButtons)
126 box.addButton(customButton, QMessageBox::ActionRole);
129 MessageDialogQtButtonType::const_iterator iter = messageDialogQtButton.find(m_defaultButton);
130 if(iter != messageDialogQtButton.end())
132 box.setDefaultButton(QMessageBox::StandardButton(static_cast<int>(iter->second)));
135 ::fwGui::dialog::IMessageDialog::Buttons result = ::fwGui::dialog::IMessageDialog::NOBUTTON;
139 for(MessageDialogQtButtonType::value_type button : messageDialogQtButton)
141 if ( box.standardButton( box.clickedButton() ) == button.second)
143 result = button.first;
The namespace fwGui contains the base interface for IHM services.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
The namespace fwGuiQt contains classes which provide the implementation of the Gui using Qt library...
virtual FWGUI_API void addCustomButton(const std::string &label, std::function< void()> clickedFn) override
Add a custom button to this dialog.
virtual FWGUI_API void addButton(IMessageDialog::Buttons button) override
Add a button (OK, YES_NO, YES, NO, CANCEL)
virtual FWGUI_API IMessageDialog::Buttons show() override
Show the message box and return the clicked button.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual FWGUI_API ~MessageDialog()
Destructor. Do nothing.
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
virtual FWGUI_API void setDefaultButton(IMessageDialog::Buttons button) override
Set the default button.
Defines the generic message box for IHM.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.