Go to the documentation of this file.00001 #include "mainwindow.h"
00002 #include <iostream>
00003 #include <QApplication>
00004 #include <QSplashScreen>
00005 #include <QThread>
00006 #include <QCommandLineParser>
00007 #include <QDesktopWidget>
00008 #include <QFontDatabase>
00009 #include <QSettings>
00010
00011 QString getFunnySubtitle(){
00012
00013 qsrand(time(nullptr));
00014
00015 int n = qrand() % 20;
00016 QSettings settings;
00017
00018 while( settings.value("previousFunnySubtitle").toInt() == n)
00019 {
00020 n = qrand() % 20;
00021 }
00022 settings.setValue("previousFunnySubtitle", n);
00023
00024 switch(n)
00025 {
00026 case 0: return "PlotJuggler does it better";
00027 case 1: return "Talk is cheap, show me the data!";
00028 case 2: return "The visualization tool that you deserve";
00029 case 3: return "Who needs Matlab?";
00030 case 4: return "Changing the world, one plot at a time";
00031 case 5: return "\"Harry Plotter\" was also an option";
00032 case 6: return "I like the smell of plots in the morning";
00033 case 7: return "Timeseries, timeseries everywhere...";
00034 case 8: return "I didn't find a better name...";
00035 case 9: return "\"It won't take long to implement that\"\n"
00036 "... Davide, 2014";
00037 case 10: return "Visualize data responsibly";
00038 case 11: return "How could you live without it?";
00039 case 12: return "This time you will find that nasty bug!";
00040 case 13: return "Now, with less bugs than usual!";
00041 case 14: return "You log them, I visualize them";
00042 case 15: return "The fancy timeseries visualization tool";
00043 case 16: return "Send me a PR with your splashscreen phrase!";
00044
00045 default: return "I don't always visualize data,\n"
00046 "but when I do, I use PlotJuggler";
00047 }
00048 }
00049
00050 int main(int argc, char *argv[])
00051 {
00052 QApplication app(argc, argv);
00053
00054 app.setOrganizationName("IcarusTechnology");
00055 app.setApplicationName("PlotJuggler");
00056
00057
00058 QFile styleFile( "://style/stylesheet.qss" );
00059 styleFile.open( QFile::ReadOnly );
00060
00061
00062 QString style( styleFile.readAll() );
00063 app.setStyleSheet( style );
00064
00065 QString VERSION_STRING = QString("%1.%2.%3").
00066 arg(PJ_MAJOR_VERSION).
00067 arg(PJ_MINOR_VERSION).
00068 arg(PJ_PATCH_VERSION);
00069
00070 app.setApplicationVersion(VERSION_STRING);
00071
00072 QCommandLineParser parser;
00073 parser.setApplicationDescription("PlotJuggler: the time series visualization tool that you deserve ");
00074 parser.addVersionOption();
00075 parser.addHelpOption();
00076
00077 QCommandLineOption nosplash_option(QStringList() << "n" << "nosplash",
00078 "Don't display the splashscreen");
00079 parser.addOption(nosplash_option);
00080
00081 QCommandLineOption test_option(QStringList() << "t" << "test",
00082 "Generate test curves at startup");
00083 parser.addOption(test_option);
00084
00085 QCommandLineOption loadfile_option(QStringList() << "d" << "datafile",
00086 "Load a file containing data",
00087 "file" );
00088 parser.addOption(loadfile_option);
00089
00090 QCommandLineOption layout_option(QStringList() << "l" << "layout",
00091 "Load a file containing the layout configuration",
00092 "file" );
00093 parser.addOption(layout_option);
00094
00095 QCommandLineOption publish_option(QStringList() << "p" << "publish",
00096 "Automatically start publisher when loading the layout file" );
00097 parser.addOption(publish_option);
00098
00099 QCommandLineOption buffersize_option(QStringList() << "buffer_size",
00100 QCoreApplication::translate("main", "Change the maximum size of the streaming buffer (minimum: 10 default: 60)"),
00101 QCoreApplication::translate("main", "seconds") );
00102 parser.addOption(buffersize_option);
00103
00104 parser.process( *qApp );
00105
00106 if( parser.isSet(publish_option) && !parser.isSet(layout_option) )
00107 {
00108 std::cerr << "Option [ -p / --publish ] is invalid unless [ -l / --layout ] is used too." << std::endl;
00109 return -1;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 if( !parser.isSet(nosplash_option) && !( parser.isSet(loadfile_option) || parser.isSet(layout_option) ) )
00126
00127 {
00128 QPixmap main_pixmap(":/splash/resources/splash_2.2.jpg");
00129
00130 int font_id = QFontDatabase::addApplicationFont("://resources/DejaVuSans-ExtraLight.ttf");
00131 QString family = QFontDatabase::applicationFontFamilies(font_id).at(0);
00132 QFont font(family);
00133 font.setStyleStrategy(QFont::PreferAntialias);
00134
00135 QPainter painter;
00136 painter.begin( &main_pixmap);
00137 painter.setPen(QColor(255, 255, 255));
00138 painter.setRenderHint(QPainter::TextAntialiasing, true);
00139
00140 const QString subtitle = getFunnySubtitle();
00141
00142 {
00143 const int margin = 20;
00144 const int text_height = 100;
00145 const int text_width = main_pixmap.width() - margin*2;
00146 QPoint topleft(margin, main_pixmap.height() - text_height);
00147 QSize rect_size(text_width, text_height);
00148 font.setPointSize( 16 );
00149 painter.setFont( font );
00150 painter.drawText( QRect(topleft, rect_size),
00151 Qt::AlignHCenter | Qt::AlignVCenter, subtitle );
00152 }
00153 {
00154 const int text_width = 100;
00155 QPoint topleft( main_pixmap.width() - text_width, 0);
00156 QSize rect_size( text_width, 40 );
00157 font.setPointSize( 14 );
00158 painter.setFont( font );
00159 painter.drawText( QRect(topleft, rect_size),
00160 Qt::AlignHCenter | Qt::AlignVCenter, VERSION_STRING );
00161 }
00162
00163 painter.end();
00164
00165 QSplashScreen splash(main_pixmap);
00166 QDesktopWidget* desktop = QApplication::desktop();
00167 const int scrn = desktop->screenNumber(QCursor::pos());
00168 const QPoint currentDesktopsCenter = desktop->availableGeometry(scrn).center();
00169 splash.move(currentDesktopsCenter - splash.rect().center());
00170
00171 splash.show();
00172 app.processEvents();
00173 splash.raise();
00174
00175 const auto deadline = QDateTime::currentDateTime().addMSecs( 100*(30 + subtitle.size()*0.4) );
00176
00177 MainWindow w( parser );
00178 while( QDateTime::currentDateTime() < deadline && !splash.isHidden() )
00179 {
00180 app.processEvents();
00181 QThread::msleep(100);
00182 splash.raise();
00183 }
00184 splash.close();
00185 w.show();
00186 return app.exec();
00187 }
00188 else{
00189 MainWindow w( parser );
00190 w.show();
00191 return app.exec();
00192 }
00193 return 0;
00194 }