25 #define YUILogComponent "mga-ui"
29 #include <yui/YOptionalWidgetFactory.h>
30 #include <yui/YApplication.h>
31 #include <yui/YWidgetFactory.h>
32 #include <yui/YDialog.h>
33 #include <yui/YLayoutBox.h>
34 #include <yui/YLabel.h>
35 #include <yui/YPushButton.h>
36 #include <yui/YEvent.h>
37 #include <yui/YImage.h>
38 #include <yui/YRichText.h>
39 #include <yui/YDumbTab.h>
40 #include <yui/YReplacePoint.h>
42 #include <boost/algorithm/string/trim.hpp>
44 #include "YMGAAboutDialog.h"
54 std::string appVersion;
55 std::string appLicense;
56 std::string appAuthors;
57 std::string appDescription;
60 std::string appCredits;
61 std::string appInformation;
79 const std::string& version,
80 const std::string& license,
81 const std::string& authors,
82 const std::string& description,
83 const std::string& logo,
84 const std::string& icon,
85 const std::string& credits,
86 const std::string& information
90 YUI_CHECK_NEW ( priv );
93 priv->appVersion = version;
94 priv->appLicense = license;
95 priv->appAuthors = authors;
96 priv->appDescription = description;
99 priv->appCredits = credits;
100 priv->appInformation = information;
101 boost::algorithm::trim(priv->appIcon);
104 YMGAAboutDialog::~YMGAAboutDialog()
114 void YMGAAboutDialog::showInformation()
116 auto infoDialog = YUI::widgetFactory()->createPopupDialog();
117 auto vbox = YUI::widgetFactory()->createVBox(infoDialog);
118 auto tophbox = YUI::widgetFactory()->createHBox(vbox);
119 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,10.0);
120 YUI::widgetFactory()->createLabel(tophbox,
"Information");
121 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,10.0);
122 auto bottomhbox = YUI::widgetFactory()->createHBox(vbox);
123 YUI::widgetFactory()->createSpacing(bottomhbox,YD_HORIZ,
false,1.0);
124 auto rtcontent = YUI::widgetFactory()->createRichText(bottomhbox);
125 YUI::widgetFactory()->createSpacing(bottomhbox,YD_HORIZ,
false,1.0);
126 rtcontent->setText(priv->appInformation);
127 auto closeButton = YUI::widgetFactory()->createPushButton(vbox,
"Close");
130 YEvent*
event = infoDialog->waitForEvent();
134 if ( event->eventType() == YEvent::CancelEvent
135 ||
event->widget() == closeButton )
139 infoDialog->destroy();
147 void YMGAAboutDialog::showCredits()
149 auto creditDialog = YUI::widgetFactory()->createPopupDialog();
150 auto vbox = YUI::widgetFactory()->createVBox(creditDialog);
151 auto tophbox = YUI::widgetFactory()->createHBox(vbox);
152 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,16.0);
153 YUI::widgetFactory()->createLabel(tophbox,
"Credits");
154 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,16.0);
155 auto rtcontent = YUI::widgetFactory()->createLabel(vbox,
"");
156 rtcontent->setText(priv->appCredits);
157 auto closeButton = YUI::widgetFactory()->createPushButton(vbox,
"Close");
160 YEvent*
event = creditDialog->waitForEvent();
164 if ( event->eventType() == YEvent::CancelEvent
165 ||
event->widget() == closeButton )
169 creditDialog->destroy();
179 void YMGAAboutDialog::genAuthorsTab(YReplacePoint* rpoint)
181 rpoint->deleteChildren();
182 auto hbox = YUI::widgetFactory()->createHBox(rpoint);
183 YUI::widgetFactory()->createRichText(hbox,priv->appAuthors);
185 priv->mainDialog->recalcLayout();
194 void YMGAAboutDialog::genContributorsTab(YReplacePoint* rpoint)
196 rpoint->deleteChildren();
197 auto hbox = YUI::widgetFactory()->createHBox(rpoint);
198 YUI::widgetFactory()->createRichText(hbox,priv->appDescription);
200 priv->mainDialog->recalcLayout();
209 void YMGAAboutDialog::genInformationTab(YReplacePoint* rpoint)
211 rpoint->deleteChildren();
212 auto hbox = YUI::widgetFactory()->createHBox(rpoint);
213 YUI::widgetFactory()->createRichText(hbox,priv->appInformation);
215 priv->mainDialog->recalcLayout();
223 void YMGAAboutDialog::Tabbed()
225 std::string oldTitle = YUI::app()->applicationTitle();
226 YUI::app()->setApplicationTitle(
"About " + priv->appName);
227 if(priv->appIcon.length())
228 YUI::app()->setApplicationIcon(priv->appIcon);
229 priv->mainDialog = YUI::widgetFactory()->createPopupDialog();
230 auto vbox = YUI::widgetFactory()->createVBox(priv->mainDialog);
243 YUI::widgetFactory()->createSpacing(vbox,YD_VERT,
false,1.0);
244 auto upperhbox = YUI::widgetFactory()->createHBox(vbox);
247 if(priv->appLogo.length())
249 YUI::widgetFactory()->createSpacing(upperhbox,YD_HORIZ,
false,3.0);
250 YUI::widgetFactory()->createImage(upperhbox,priv->appLogo);
251 YUI::widgetFactory()->createSpacing(upperhbox,YD_HORIZ,
false,3.0);
255 YUI::widgetFactory()->createSpacing(upperhbox,YD_HORIZ,
false,3.0);
256 YUI::widgetFactory()->createLabel(upperhbox,priv->appName +
" " + priv->appVersion);
257 YUI::widgetFactory()->createSpacing(upperhbox,YD_HORIZ,
false,5.0);
258 YUI::widgetFactory()->createSpacing(vbox,YD_VERT,
false,1.0);
261 auto tophbox = YUI::widgetFactory()->createHBox(vbox);
262 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,3.0);
263 YUI::widgetFactory()->createLabel(tophbox,priv->appCredits);
264 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,3.0);
265 YUI::widgetFactory()->createSpacing(vbox,YD_VERT,
false,0.5);
268 auto licensehbox = YUI::widgetFactory()->createHBox(vbox);
269 YUI::widgetFactory()->createSpacing(licensehbox,YD_HORIZ,
false,3.0);
270 YUI::widgetFactory()->createLabel(licensehbox,priv->appLicense);
271 YUI::widgetFactory()->createSpacing(licensehbox,YD_HORIZ,
false,3.0);
272 YUI::widgetFactory()->createSpacing(vbox,YD_VERT,
false,0.5);
274 if(YUI::optionalWidgetFactory()->hasDumbTab())
276 auto dumbTab = YUI::optionalWidgetFactory()->createDumbTab(vbox);
278 if(priv->appAuthors.length())
280 dumbTab->addItem(
new YItem(
"Authors"));
282 if(priv->appDescription.length())
284 dumbTab->addItem(
new YItem(
"Description"));
286 if(priv->appInformation.length())
288 dumbTab->addItem(
new YItem(
"Information"));
291 auto bottomvbox = YUI::widgetFactory()->createVBox(vbox);
292 auto rpoint = YUI::widgetFactory()->createReplacePoint(bottomvbox);
294 if(priv->appAuthors.length())
296 this->genAuthorsTab(rpoint);
299 auto cancelButton = YUI::widgetFactory()->createPushButton(vbox,
"Close");
303 YEvent*
event = priv->mainDialog->waitForEvent();
307 if ( event->eventType() == YEvent::CancelEvent
308 ||
event->widget() == cancelButton )
310 if ( event->eventType() == YEvent::MenuEvent )
312 if( event->item()->label().replace(event->item()->label().find(
"&"),1,
"").compare(
"Authors")==0 )
314 this->genAuthorsTab(rpoint);
316 else if( event->item()->label().replace(event->item()->label().find(
"&"),1,
"").compare(
"Description")==0 )
318 this->genContributorsTab(rpoint);
320 else if( event->item()->label().replace(event->item()->label().find(
"&"),1,
"").compare(
"Information")==0 )
322 this->genInformationTab(rpoint);
327 priv->mainDialog->destroy();
333 YUI::app()->setApplicationTitle(oldTitle);
341 void YMGAAboutDialog::Classic()
343 YPushButton* creditsButton =
nullptr;
344 YPushButton* infoButton =
nullptr;
345 std::string oldTitle = YUI::app()->applicationTitle();
346 YUI::app()->setApplicationTitle(
"About " + priv->appName);
347 if(priv->appIcon.length())
348 YUI::app()->setApplicationIcon(priv->appIcon);
349 priv->mainDialog = YUI::widgetFactory()->createPopupDialog();
350 auto vbox = YUI::widgetFactory()->createVBox(priv->mainDialog);
351 auto tophbox = YUI::widgetFactory()->createHBox(vbox);
354 if(priv->appLogo.length())
356 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,2.0);
357 YUI::widgetFactory()->createImage(tophbox,priv->appLogo);
360 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,8.0);
361 auto headvbox = YUI::widgetFactory()->createVBox(tophbox);
362 YUI::widgetFactory()->createSpacing(tophbox,YD_HORIZ,
false,12.0);
365 auto lblAppName = YUI::widgetFactory()->createLabel(headvbox,
"");
366 lblAppName->setValue(priv->appName);
367 auto lblAppVersion = YUI::widgetFactory()->createLabel(headvbox,
"");
368 lblAppVersion->setValue(priv->appVersion);
369 auto lblLicense = YUI::widgetFactory()->createLabel(headvbox,
"");
370 lblLicense->setValue(priv->appLicense);
372 auto midhbox = YUI::widgetFactory()->createHBox(vbox);
374 auto toprightvbox = YUI::widgetFactory()->createVBox(midhbox);
375 toprightvbox->setWeight(YD_HORIZ, 5);
376 YUI::widgetFactory()->createSpacing(toprightvbox,YD_HORIZ,
false,5.0);
377 auto rt = YUI::widgetFactory()->createRichText(toprightvbox,
"");
378 YUI::widgetFactory()->createSpacing(toprightvbox,YD_HORIZ,
false,5.0);
379 rt->setValue(priv->appDescription);
382 auto bottomhbox = YUI::widgetFactory()->createHBox(vbox);
383 if(priv->appInformation.length())
385 infoButton = YUI::widgetFactory()->createPushButton(bottomhbox,
"Info");
389 if(!priv->appCredits.empty())
391 creditsButton = YUI::widgetFactory()->createPushButton(bottomhbox,
"Credits");
394 auto cancelButton = YUI::widgetFactory()->createPushButton(bottomhbox,
"Close");
397 YEvent*
event = priv->mainDialog->waitForEvent();
401 if ( event->eventType() == YEvent::CancelEvent
402 ||
event->widget() == cancelButton )
404 else if( ( infoButton !=
nullptr ) &&
event->widget() == infoButton )
406 this->showInformation();
408 else if( ( creditsButton !=
nullptr ) && event->widget() == creditsButton )
414 priv->mainDialog->destroy();
415 YUI::app()->setApplicationTitle(oldTitle);
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