26 #define YUILogComponent "mga-ui" 30 #include <yui/YOptionalWidgetFactory.h> 31 #include <yui/YApplication.h> 32 #include <yui/YWidgetFactory.h> 33 #include <yui/YDialog.h> 34 #include <yui/YLayoutBox.h> 35 #include <yui/YLabel.h> 36 #include <yui/YPushButton.h> 37 #include <yui/YEvent.h> 38 #include <yui/YImage.h> 39 #include <yui/YRichText.h> 40 #include <yui/YDumbTab.h> 41 #include <yui/YReplacePoint.h> 42 #include <yui/YAlignment.h> 44 #include <boost/algorithm/string/trim.hpp> 46 #include "YMGAAboutDialog.h" 56 std::string appVersion;
57 std::string appLicense;
58 std::string appAuthors;
59 std::string appDescription;
62 std::string appCredits;
63 std::string appInformation;
64 YLayoutSize_t columns;
83 const std::string& version,
84 const std::string& license,
85 const std::string& authors,
86 const std::string& description,
87 const std::string& logo,
88 const std::string& icon,
89 const std::string& credits,
90 const std::string& information
94 YUI_CHECK_NEW ( priv );
97 priv->appVersion = version;
98 priv->appLicense = license;
99 priv->appAuthors = authors;
100 priv->appDescription = description;
101 priv->appLogo = logo;
102 priv->appIcon = icon;
103 priv->appCredits = credits;
104 priv->appInformation = information;
107 boost::algorithm::trim(priv->appIcon);
110 YMGAAboutDialog::~YMGAAboutDialog()
120 void YMGAAboutDialog::showInformation()
122 auto infoDialog = YUI::widgetFactory()->createPopupDialog();
123 auto minsize = YUI::widgetFactory()->createMinSize(infoDialog, priv->columns, priv->lines);
124 auto vbox = YUI::widgetFactory()->createVBox(minsize);
125 auto tophbox = YUI::widgetFactory()->createHBox(vbox);
126 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,10.0);
127 YUI::widgetFactory()->createLabel(tophbox,
"Information");
128 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,10.0);
129 auto bottomhbox = YUI::widgetFactory()->createHBox(vbox);
130 YUI::widgetFactory()->createSpacing(bottomhbox,YD_HORIZ,
false,1.0);
131 auto rtcontent = YUI::widgetFactory()->createRichText(bottomhbox);
132 YUI::widgetFactory()->createSpacing(bottomhbox,YD_HORIZ,
false,1.0);
133 rtcontent->setText(priv->appInformation);
134 auto closeButton = YUI::widgetFactory()->createPushButton(vbox,
"Close");
137 YEvent*
event = infoDialog->waitForEvent();
141 if ( event->eventType() == YEvent::CancelEvent
142 ||
event->widget() == closeButton )
146 infoDialog->destroy();
154 void YMGAAboutDialog::showCredits()
156 auto creditDialog = YUI::widgetFactory()->createPopupDialog();
157 auto vbox = YUI::widgetFactory()->createVBox(creditDialog);
158 auto tophbox = YUI::widgetFactory()->createHBox(vbox);
159 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,16.0);
160 YUI::widgetFactory()->createLabel(tophbox,
"Credits");
161 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,16.0);
162 auto rtcontent = YUI::widgetFactory()->createLabel(vbox,
"");
163 rtcontent->setText(priv->appCredits);
164 auto closeButton = YUI::widgetFactory()->createPushButton(vbox,
"Close");
167 YEvent*
event = creditDialog->waitForEvent();
171 if ( event->eventType() == YEvent::CancelEvent
172 ||
event->widget() == closeButton )
176 creditDialog->destroy();
186 void YMGAAboutDialog::genAuthorsTab(YReplacePoint* rpoint)
188 rpoint->deleteChildren();
189 auto hbox = YUI::widgetFactory()->createHBox(rpoint);
190 auto minsize = YUI::widgetFactory()->createMinSize(hbox, priv->columns, priv->lines);
192 YUI::widgetFactory()->createRichText(minsize,priv->appAuthors);
194 priv->mainDialog->recalcLayout();
203 void YMGAAboutDialog::genContributorsTab(YReplacePoint* rpoint)
205 rpoint->deleteChildren();
206 auto hbox = YUI::widgetFactory()->createHBox(rpoint);
207 auto minsize = YUI::widgetFactory()->createMinSize(hbox, priv->columns, priv->lines);
208 YUI::widgetFactory()->createRichText(minsize,priv->appDescription);
210 priv->mainDialog->recalcLayout();
219 void YMGAAboutDialog::genInformationTab(YReplacePoint* rpoint)
221 rpoint->deleteChildren();
222 auto hbox = YUI::widgetFactory()->createHBox(rpoint);
223 auto minsize = YUI::widgetFactory()->createMinSize(hbox, priv->columns, priv->lines);
224 YUI::widgetFactory()->createRichText(minsize,priv->appInformation);
226 priv->mainDialog->recalcLayout();
236 priv->columns = columns;
245 void YMGAAboutDialog::Tabbed()
247 std::string oldTitle = YUI::app()->applicationTitle();
248 YUI::app()->setApplicationTitle(
"About " + priv->appName);
249 if(priv->appIcon.length())
250 YUI::app()->setApplicationIcon(priv->appIcon);
251 priv->mainDialog = YUI::widgetFactory()->createPopupDialog();
252 auto vbox = YUI::widgetFactory()->createVBox(priv->mainDialog);
265 YUI::widgetFactory()->createSpacing(vbox,YD_VERT,
false,1.0);
266 auto upperhbox = YUI::widgetFactory()->createHBox(vbox);
269 if(priv->appLogo.length())
271 YUI::widgetFactory()->createSpacing(upperhbox,YD_HORIZ,
false,3.0);
272 YUI::widgetFactory()->createImage(upperhbox,priv->appLogo);
273 YUI::widgetFactory()->createSpacing(upperhbox,YD_HORIZ,
false,3.0);
277 YUI::widgetFactory()->createSpacing(upperhbox,YD_HORIZ,
false,3.0);
278 YUI::widgetFactory()->createLabel(upperhbox,priv->appName +
" " + priv->appVersion);
279 YUI::widgetFactory()->createSpacing(upperhbox,YD_HORIZ,
false,5.0);
280 YUI::widgetFactory()->createSpacing(vbox,YD_VERT,
false,1.0);
283 auto tophbox = YUI::widgetFactory()->createHBox(vbox);
284 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,3.0);
285 YUI::widgetFactory()->createLabel(tophbox,priv->appCredits);
286 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,3.0);
287 YUI::widgetFactory()->createSpacing(vbox,YD_VERT,
false,0.5);
290 auto licensehbox = YUI::widgetFactory()->createHBox(vbox);
291 YUI::widgetFactory()->createSpacing(licensehbox,YD_HORIZ,
false,3.0);
292 YUI::widgetFactory()->createLabel(licensehbox,priv->appLicense);
293 YUI::widgetFactory()->createSpacing(licensehbox,YD_HORIZ,
false,3.0);
294 YUI::widgetFactory()->createSpacing(vbox,YD_VERT,
false,0.5);
296 if(YUI::optionalWidgetFactory()->hasDumbTab())
298 auto dumbTab = YUI::optionalWidgetFactory()->createDumbTab(vbox);
300 if(priv->appAuthors.length())
302 dumbTab->addItem(
new YItem(
"Authors"));
304 if(priv->appDescription.length())
306 dumbTab->addItem(
new YItem(
"Description"));
308 if(priv->appInformation.length())
310 dumbTab->addItem(
new YItem(
"Information"));
313 auto bottomvbox = YUI::widgetFactory()->createVBox(vbox);
314 auto rpoint = YUI::widgetFactory()->createReplacePoint(bottomvbox);
316 if(priv->appAuthors.length())
318 this->genAuthorsTab(rpoint);
321 auto cancelButton = YUI::widgetFactory()->createPushButton(vbox,
"Close");
322 cancelButton->setDefaultButton();
326 YEvent*
event = priv->mainDialog->waitForEvent();
330 if ( event->eventType() == YEvent::CancelEvent
331 ||
event->widget() == cancelButton )
333 if ( event->eventType() == YEvent::MenuEvent )
335 if( event->item()->label().replace(event->item()->label().find(
"&"),1,
"").compare(
"Authors")==0 )
337 this->genAuthorsTab(rpoint);
339 else if( event->item()->label().replace(event->item()->label().find(
"&"),1,
"").compare(
"Description")==0 )
341 this->genContributorsTab(rpoint);
343 else if( event->item()->label().replace(event->item()->label().find(
"&"),1,
"").compare(
"Information")==0 )
345 this->genInformationTab(rpoint);
350 priv->mainDialog->destroy();
356 YUI::app()->setApplicationTitle(oldTitle);
364 void YMGAAboutDialog::Classic()
366 YPushButton* creditsButton =
nullptr;
367 YPushButton* infoButton =
nullptr;
368 std::string oldTitle = YUI::app()->applicationTitle();
369 YUI::app()->setApplicationTitle(
"About " + priv->appName);
370 if(priv->appIcon.length())
371 YUI::app()->setApplicationIcon(priv->appIcon);
372 priv->mainDialog = YUI::widgetFactory()->createPopupDialog();
373 auto minsize = YUI::widgetFactory()->createMinSize(priv->mainDialog, priv->columns, priv->lines);
374 auto vbox = YUI::widgetFactory()->createVBox(minsize);
375 auto tophbox = YUI::widgetFactory()->createHBox(vbox);
378 if(priv->appLogo.length())
380 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,2.0);
381 YUI::widgetFactory()->createImage(tophbox,priv->appLogo);
384 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,8.0);
385 auto headvbox = YUI::widgetFactory()->createVBox(tophbox);
386 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,12.0);
389 auto lblAppName = YUI::widgetFactory()->createLabel(headvbox,
"");
390 lblAppName->setValue(priv->appName);
391 auto lblAppVersion = YUI::widgetFactory()->createLabel(headvbox,
"");
392 lblAppVersion->setValue(priv->appVersion);
393 auto lblLicense = YUI::widgetFactory()->createLabel(headvbox,
"");
394 lblLicense->setValue(priv->appLicense);
396 auto midhbox = YUI::widgetFactory()->createHBox(vbox);
398 auto toprightvbox = YUI::widgetFactory()->createVBox(midhbox);
399 toprightvbox->setWeight(YD_HORIZ, 5);
400 YUI::widgetFactory()->createSpacing(toprightvbox,YD_HORIZ,
false,5.0);
401 auto rt = YUI::widgetFactory()->createRichText(toprightvbox,
"");
402 YUI::widgetFactory()->createSpacing(toprightvbox,YD_HORIZ,
false,5.0);
403 rt->setValue(priv->appDescription);
406 auto bottomhbox = YUI::widgetFactory()->createHBox(vbox);
407 if(priv->appInformation.length())
409 infoButton = YUI::widgetFactory()->createPushButton(bottomhbox,
"Info");
413 if(!priv->appCredits.empty())
415 creditsButton = YUI::widgetFactory()->createPushButton(bottomhbox,
"Credits");
418 auto cancelButton = YUI::widgetFactory()->createPushButton(bottomhbox,
"Close");
419 cancelButton->setDefaultButton();
423 YEvent*
event = priv->mainDialog->waitForEvent();
427 if ( event->eventType() == YEvent::CancelEvent
428 ||
event->widget() == cancelButton )
430 else if( ( infoButton !=
nullptr ) &&
event->widget() == infoButton )
432 this->showInformation();
434 else if( ( creditsButton !=
nullptr ) && event->widget() == creditsButton )
440 priv->mainDialog->destroy();
441 YUI::app()->setApplicationTitle(oldTitle);
void setMinSize(YLayoutSize_t columns, YLayoutSize_t lines)
Set the dialog mimimum size if Classic dialog is shown, minimum text size otherwise.
YMGAAboutDialog(const std::string &name, const std::string &version, const std::string &license, const std::string &authors, const std::string &description, const std::string &logo, const std::string &icon=std::string(), const std::string &credits=std::string(), const std::string &information=std::string())
The constructor.
void show(DLG_MODE type=TABBED)
it actually shows the about dialog