25 #define YUILogComponent "mga-ui" 29 #include <yui/YTypes.h> 30 #include <yui/YApplication.h> 31 #include <yui/YWidgetFactory.h> 32 #include <yui/YDialog.h> 33 #include <yui/YLayoutBox.h> 34 #include <yui/YAlignment.h> 35 #include <yui/YPushButton.h> 36 #include <yui/YEvent.h> 37 #include <yui/YRichText.h> 38 #include <YButtonBox.h> 40 #include <boost/algorithm/string/trim.hpp> 43 #include "YMGAMsgBox.h" 50 icon(), useRichText(
false),
51 minWidth(40), minHeight(15),
62 YLayoutSize_t minWidth;
63 YLayoutSize_t minHeight;
67 std::vector<std::string> label;
74 YUI_CHECK_NEW ( priv );
76 priv->buttons = b_num;
77 priv->mode = dlg_mode;
78 priv->label.resize((b_num==
B_TWO ? 2 : 1));
92 boost::algorithm::trim(priv->icon);
103 priv->useRichText = useRichText;
109 if ( minWidth > 80 || minHeight > 25 )
114 priv->minHeight = minHeight;
115 priv->minWidth = minWidth;
120 if ( priv->buttons !=
B_TWO && button ==
B_TWO)
121 YUI_THROW( YUIException(
"Only one button configured" ) );
123 priv->label[button] = label;
128 if ( priv->buttons !=
B_TWO && button ==
B_TWO)
129 YUI_THROW( YUIException(
"Only one button configured" ) );
131 priv->default_button = button;
139 std::string oldTitle = YUI::app()->applicationTitle();
140 YUI::app()->setApplicationTitle(priv->title);
141 if(priv->icon.length())
142 YUI::app()->setApplicationIcon(priv->icon);
144 YDialogColorMode colorMode;
145 if (priv->mode ==
D_INFO) {
146 colorMode = YDialogInfoColor;
149 colorMode = YDialogWarnColor;
152 colorMode = YDialogNormalColor;
155 YDialog *pDialog = YUI::widgetFactory()->createPopupDialog(colorMode);
156 YAlignment* minSize = YUI::widgetFactory()->createMinSize( pDialog, priv->minWidth, priv->minHeight );
157 auto vbox = YUI::widgetFactory()->createVBox( minSize );
159 auto midhbox = YUI::widgetFactory()->createHBox(vbox);
161 auto toprightvbox = YUI::widgetFactory()->createVBox(midhbox);
162 toprightvbox->setWeight(YD_HORIZ, 5);
163 YUI::widgetFactory()->createSpacing(toprightvbox,YD_HORIZ,
false,5.0);
164 YUI::widgetFactory()->createRichText(toprightvbox, priv->text, !priv->useRichText);
165 YUI::widgetFactory()->createSpacing(toprightvbox,YD_HORIZ,
false,5.0);
168 auto bottomhbox = YUI::widgetFactory()->createHBox(vbox);
169 YPushButton *pB1=
nullptr, *pB2=
nullptr;
170 if (priv->buttons ==
B_ONE) {
171 pB1 = YUI::widgetFactory()->createPushButton(bottomhbox, priv->label[
B_ONE]);
174 auto alignRight = YUI::widgetFactory()->createRight(bottomhbox);
175 auto buttonBox = YUI::widgetFactory()->createHBox( alignRight );
176 pB1 = YUI::widgetFactory()->createPushButton(buttonBox, priv->label[
B_ONE]);
177 pB2 = YUI::widgetFactory()->createPushButton(buttonBox, priv->label[
B_TWO]);
179 if (priv->default_button ==
B_TWO)
180 pDialog->setDefaultButton(pB2);
182 pDialog->setDefaultButton(pB1);
186 YEvent*
event = pDialog->waitForEvent();
190 if ( event->eventType() == YEvent::CancelEvent) {
193 else if( event->widget() == pB1 ) {
197 else if (pB2 !=
nullptr && event->widget() == pB2) {
205 YUI::app()->setApplicationTitle(oldTitle);
YMGAMessageBox(DLG_BUTTON b_num=B_ONE, DLG_MODE dlg_mode=D_NORMAL)
The constructor.
DLG_BUTTON show()
it shows the message box dialog using data set by user.
void setButtonLabel(const std::string &label, DLG_BUTTON button=B_ONE)
sets the message box button name (empty string is assigned by default)
two buttons dialog, or button two pressed
One button dialog, or button one pressed.
void setDefaultButton(DLG_BUTTON button=B_ONE)
sets the message box default button
void setText(const std::string &text, bool useRichText=false)
sets the message box text information
void setMinSize(YLayoutSize_t minWidth, YLayoutSize_t minHeight)
sets the dilaog box minimum size according to YWidgetFactory::createMinSize()
void setTitle(const std::string &title)
sets the message box title
virtual ~YMGAMessageBox()
Destructor.
void setIcon(const std::string &icon)
sets the message box icon (full path)