Splashscreen.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QMutex>
00027 # include <QSysInfo>
00028 # include <QWaitCondition>
00029 #endif
00030
00031 #include "Splashscreen.h"
00032 #include "ui_AboutApplication.h"
00033 #include <Base/Console.h>
00034 #include <App/Application.h>
00035 #include <Gui/MainWindow.h>
00036
00037
00038 using namespace Gui;
00039 using namespace Gui::Dialog;
00040
00041 namespace Gui {
00045 class SplashObserver : public Base::ConsoleObserver
00046 {
00047 public:
00048 SplashObserver(QSplashScreen* splasher=0, const char* name=0)
00049 : splash(splasher), alignment(Qt::AlignBottom|Qt::AlignLeft), textColor(Qt::black)
00050 {
00051 Base::Console().AttachObserver(this);
00052
00053
00054 const std::map<std::string,std::string>& cfg = App::GetApplication().Config();
00055 std::map<std::string,std::string>::const_iterator al = cfg.find("SplashAlignment");
00056 if (al != cfg.end()) {
00057 QString alt = QString::fromAscii(al->second.c_str());
00058 int align=0;
00059 if (alt.startsWith(QLatin1String("VCenter")))
00060 align = Qt::AlignVCenter;
00061 else if (alt.startsWith(QLatin1String("Top")))
00062 align = Qt::AlignTop;
00063 else
00064 align = Qt::AlignBottom;
00065
00066 if (alt.endsWith(QLatin1String("HCenter")))
00067 align += Qt::AlignHCenter;
00068 else if (alt.endsWith(QLatin1String("Right")))
00069 align += Qt::AlignRight;
00070 else
00071 align += Qt::AlignLeft;
00072
00073 alignment = align;
00074 }
00075
00076
00077 std::map<std::string,std::string>::const_iterator tc = cfg.find("SplashTextColor");
00078 if (tc != cfg.end()) {
00079 QColor col; col.setNamedColor(QString::fromAscii(tc->second.c_str()));
00080 if (col.isValid())
00081 textColor = col;
00082 }
00083 }
00084
00085 virtual ~SplashObserver()
00086 {
00087 Base::Console().DetachObserver(this);
00088 }
00089
00090 void Warning(const char * s)
00091 {
00092 Log(s);
00093 }
00094 void Message(const char * s)
00095 {
00096 Log(s);
00097 }
00098 void Error (const char * s)
00099 {
00100 Log(s);
00101 }
00102 void Log (const char * s)
00103 {
00104 QString msg(QString::fromUtf8(s));
00105 QRegExp rx;
00106
00107 rx.setPattern(QLatin1String("^\\s*(Init:|Mod:)\\s*"));
00108 int pos = rx.indexIn(msg);
00109 if (pos != -1) {
00110 msg = msg.mid(rx.matchedLength());
00111 }
00112 else {
00113
00114 rx.setPattern(QLatin1String("^\\s*(\\+App::|Create|CmdC:|CmdG:|Act:)\\s*"));
00115 pos = rx.indexIn(msg);
00116 if (pos == 0)
00117 return;
00118 }
00119
00120 splash->showMessage(msg.replace(QLatin1String("\n"), QString()), alignment, textColor);
00121 QMutex mutex;
00122 mutex.lock();
00123 QWaitCondition().wait(&mutex, 50);
00124 }
00125
00126 private:
00127 QSplashScreen* splash;
00128 int alignment;
00129 QColor textColor;
00130 };
00131 }
00132
00133
00134
00138 SplashScreen::SplashScreen( const QPixmap & pixmap , Qt::WFlags f )
00139 : QSplashScreen(pixmap, f)
00140 {
00141
00142 messages = new SplashObserver(this);
00143 }
00144
00146 SplashScreen::~SplashScreen()
00147 {
00148 delete messages;
00149 }
00150
00155 void SplashScreen::drawContents ( QPainter * painter )
00156 {
00157 QSplashScreen::drawContents(painter);
00158 }
00159
00160
00161
00162 AboutDialogFactory* AboutDialogFactory::factory = 0;
00163
00164 AboutDialogFactory::~AboutDialogFactory()
00165 {
00166 }
00167
00168 QDialog *AboutDialogFactory::create(QWidget *parent) const
00169 {
00170 return new AboutDialog(false, parent);
00171 }
00172
00173 const AboutDialogFactory *AboutDialogFactory::defaultFactory()
00174 {
00175 static const AboutDialogFactory this_factory;
00176 if (factory)
00177 return factory;
00178 return &this_factory;
00179 }
00180
00181 void AboutDialogFactory::setDefaultFactory(AboutDialogFactory *f)
00182 {
00183 if (factory != f)
00184 delete factory;
00185 factory = f;
00186 }
00187
00188
00189
00190
00191
00198 AboutDialog::AboutDialog(bool showLic, QWidget* parent)
00199 : QDialog(parent, Qt::FramelessWindowHint), ui(new Ui_AboutApplication)
00200 {
00201 setModal(true);
00202 ui->setupUi(this);
00203 ui->labelSplashPicture->setPixmap(getMainWindow()->splashImage());
00204 if (!showLic)
00205 ui->licenseButton->hide();
00206 setupLabels();
00207 }
00208
00212 AboutDialog::~AboutDialog()
00213 {
00214
00215 delete ui;
00216 }
00217
00218 static QString getPlatform()
00219 {
00220 #if defined (Q_OS_WIN32)
00221 switch(QSysInfo::windowsVersion())
00222 {
00223 case QSysInfo::WV_NT:
00224 return QString::fromAscii("Windows NT");
00225 case QSysInfo::WV_2000:
00226 return QString::fromAscii("Windows 2000");
00227 case QSysInfo::WV_XP:
00228 return QString::fromAscii("Windows XP");
00229 case QSysInfo::WV_2003:
00230 return QString::fromAscii("Windows Server 2003");
00231 case QSysInfo::WV_VISTA:
00232 return QString::fromAscii("Windows Vista");
00233 case QSysInfo::WV_WINDOWS7:
00234 return QString::fromAscii("Windows 7");
00235 default:
00236 return QString::fromAscii("Windows");
00237 }
00238 #elif defined (Q_OS_MAC)
00239 return QString::fromAscii("Mac OS X");
00240 #elif defined (Q_OS_LINUX)
00241 return QString::fromAscii("Linux");
00242 #elif defined (Q_OS_UNIX)
00243 return QString::fromAscii("UNIX");
00244 #else
00245 return QString();
00246 #endif
00247 }
00248
00249 void AboutDialog::setupLabels()
00250 {
00251 QString exeName = QString::fromAscii(App::Application::Config()["ExeName"].c_str());
00252 std::map<std::string,std::string>& cfg = App::Application::Config();
00253 std::map<std::string,std::string>::iterator it = cfg.find("WindowTitle");
00254 if (it != cfg.end())
00255 exeName = QString::fromUtf8(it->second.c_str());
00256 QString banner = QString::fromUtf8(App::Application::Config()["ConsoleBanner"].c_str());
00257 banner = banner.left( banner.indexOf(QLatin1Char('\n')) );
00258 QString major = QString::fromAscii(App::Application::Config()["BuildVersionMajor"].c_str());
00259 QString minor = QString::fromAscii(App::Application::Config()["BuildVersionMinor"].c_str());
00260 QString build = QString::fromAscii(App::Application::Config()["BuildRevision"].c_str());
00261 QString disda = QString::fromAscii(App::Application::Config()["BuildRevisionDate"].c_str());
00262 QString mturl = QString::fromAscii(App::Application::Config()["MaintainerUrl"].c_str());
00263
00264 QString author = ui->labelAuthor->text();
00265 author.replace(QString::fromAscii("Unknown Application"), exeName);
00266 author.replace(QString::fromAscii("Unknown Author"), banner);
00267 ui->labelAuthor->setText(author);
00268 ui->labelAuthor->setUrl(mturl);
00269
00270 QString version = ui->labelBuildVersion->text();
00271 version.replace(QString::fromAscii("Unknown"), QString::fromAscii("%1.%2").arg(major).arg(minor));
00272 ui->labelBuildVersion->setText(version);
00273
00274 QString revision = ui->labelBuildRevision->text();
00275 revision.replace(QString::fromAscii("Unknown"), build);
00276 ui->labelBuildRevision->setText(revision);
00277
00278 QString date = ui->labelBuildDate->text();
00279 date.replace(QString::fromAscii("Unknown"), disda);
00280 ui->labelBuildDate->setText(date);
00281
00282 QString platform = ui->labelBuildPlatform->text();
00283 platform.replace(QString::fromAscii("Unknown"),
00284 QString::fromAscii("%1 (%2-bit)").arg(getPlatform()).arg(QSysInfo::WordSize));
00285 ui->labelBuildPlatform->setText(platform);
00286 }
00287
00288 void AboutDialog::on_licenseButton_clicked()
00289 {
00290 }
00291
00292 #include "moc_Splashscreen.cpp"