main.cpp
Go to the documentation of this file.
00001 #include "mainwindow.h"
00002 #include <QApplication>
00003 #include <QSplashScreen>
00004 #include <QThread>
00005 #include <QCommandLineParser>
00006 
00007 QString getFunnySubtitle(){
00008 
00009     qsrand(time(NULL));
00010     int n = qrand() % 18;
00011     switch(n)
00012     {
00013     case 0: return "The best excuse to buy a second monitor";
00014     case 1: return "Now with 100% more splashscreens";
00015     case 2: return "Because command line tools suck";
00016     case 3: return "Time-series at your fingertips";
00017     case 4: return "Changing the world, one plot at a time";
00018     case 5: return "Have you starred me on Github?";
00019     case 6: return "Insert [useless message] here";
00020     case 7: return "\"Harry Plotter\" was also an option";
00021     case 8: return "Add data and mix vigorously";
00022     case 9: return "Just Plot It!";
00023     case 10: return "I didn't find a better name...";
00024     case 11: return "Happy Plotting, or get your money back";
00025     case 12: return "\"It won't take long to code that\".. Davide, 2014";
00026     case 13: return "Startup is actually fast. I added splashscreens for fun";
00027     case 14: return "Graphic-less version coming soon";
00028     case 15: return "Visualize data responsibly";
00029     }
00030     return "Juggle with data";
00031 }
00032 
00033 int main(int argc, char *argv[])
00034 {
00035     QApplication app(argc, argv);
00036     app.setApplicationName("PlotJuggler");
00037 
00038     qApp->setStyleSheet(QString("QToolTip {\n"
00039                                 "   border: 1px solid black;\n"
00040                                 "   border-radius: 4px;\n"
00041                                 "   background: white;\n"
00042                                 "   color: black; }" ));
00043 
00044     QString VERSION_STRING = QString::number(PJ_MAJOR_VERSION) + QString(".") +
00045             QString::number(PJ_MINOR_VERSION) + QString(".") +
00046             QString::number(PJ_PATCH_VERSION);
00047 
00048     app.setApplicationVersion(VERSION_STRING);
00049 
00050     QCommandLineParser parser;
00051     parser.setApplicationDescription("PlotJuggler: the time series visualization tool that you deserve ");
00052     parser.addVersionOption();
00053     parser.addHelpOption();
00054 
00055     QCommandLineOption nosplash_option(QStringList() << "n" << "nosplash",
00056                                        QCoreApplication::translate("main", "Don't display the splashscreen"));
00057     parser.addOption(nosplash_option);
00058 
00059     QCommandLineOption test_option(QStringList() << "t" << "test",
00060                                    QCoreApplication::translate("main", "Generate test curves at startup"));
00061     parser.addOption(test_option);
00062 
00063     QCommandLineOption loadfile_option(QStringList() << "d" << "datafile",
00064                                        QCoreApplication::translate("main", "Load a file containing data"),
00065                                        QCoreApplication::translate("main", "file") );
00066     parser.addOption(loadfile_option);
00067 
00068     QCommandLineOption config_option(QStringList() << "l" << "layout",
00069                                      QCoreApplication::translate("main", "Load a file containing the layout configuration"),
00070                                      QCoreApplication::translate("main", "file") );
00071     parser.addOption(config_option);
00072 
00073     QCommandLineOption buffersize_option(QStringList() << "buffer_size",
00074                                      QCoreApplication::translate("main", "Change the maximum size of the streaming buffer (minimum: 10 default: 60)"),
00075                                      QCoreApplication::translate("main", "seconds") );
00076     parser.addOption(buffersize_option);
00077 
00078     parser.process( *qApp );
00079 
00080     /*
00081      * You, fearless code reviewer, decided to start a journey into my source code.
00082      * For your bravery, you deserve to know the truth, no matter how hard it is to accept it.
00083      * The splashscreen is useless; not only it is useless, it will make your start-up
00084      * time slower by a couple of seconds for absolutely no reason.
00085      * But what are two seconds compared with the time that PlotJuggler will save you?
00086      * The splashscreen is the connection between me and my users, the glue that keep
00087      * together our invisible relationship.
00088      * Now it is up to you to decide: you can block the splashscreen forever or not,
00089      * reject a message that brings a little of happiness into your day, spent analyzing data.
00090      * Please don't do it.
00091      */
00092 
00093     if( parser.isSet(nosplash_option) == false)
00094     // if(false) // if you uncomment this line, a kitten will die somewhere in the world.
00095     {
00096         QPixmap main_pixmap(":/splash/resources/splash.jpg");
00097 
00098         QPainter painter;
00099         painter.begin( &main_pixmap);
00100         painter.setPen(QColor(77, 77, 77));
00101 
00102         QString subtitle = getFunnySubtitle();
00103         int font_size = 36;
00104         do{
00105             painter.setFont( QFont("Arial", font_size-- ) );
00106         }while( painter.fontMetrics().width(subtitle) > 550 );
00107 
00108         painter.drawText( QRect(50, 200, 580, 100), Qt::AlignHCenter | Qt::AlignVCenter, subtitle );
00109         painter.end();
00110 
00111         QSplashScreen splash(main_pixmap);
00112         splash.show();
00113 
00114         MainWindow w( parser );
00115 
00116         for (int i =0; i<(25 + subtitle.size()/2) && !splash.isHidden(); i++ ) {
00117             app.processEvents();
00118             QThread::msleep(100);
00119             splash.raise();
00120         }
00121 
00122         splash.close();
00123         w.show();
00124         return app.exec();
00125     }
00126     else{
00127         MainWindow w( parser );
00128         w.show();
00129         return app.exec();
00130     }
00131 
00132     return -1;
00133 }


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:56