plotter_gui/main.cpp
Go to the documentation of this file.
1 #include "mainwindow.h"
2 #include <iostream>
3 #include <QApplication>
4 #include <QSplashScreen>
5 #include <QThread>
6 #include <QCommandLineParser>
7 #include <QDesktopWidget>
8 #include <QFontDatabase>
9 #include <QSettings>
10 
11 QString getFunnySubtitle(){
12 
13  qsrand(time(nullptr));
14 
15  int n = qrand() % 20;
16  QSettings settings;
17  // do not repeat it twice in a row
18  while( settings.value("previousFunnySubtitle").toInt() == n)
19  {
20  n = qrand() % 20;
21  }
22  settings.setValue("previousFunnySubtitle", n);
23 
24  switch(n)
25  {
26  case 0: return "PlotJuggler does it better";
27  case 1: return "Talk is cheap, show me the data!";
28  case 2: return "The visualization tool that you deserve";
29  case 3: return "Who needs Matlab?";
30  case 4: return "Changing the world, one plot at a time";
31  case 5: return "\"Harry Plotter\" was also an option";
32  case 6: return "I like the smell of plots in the morning";
33  case 7: return "Timeseries, timeseries everywhere...";
34  case 8: return "I didn't find a better name...";
35  case 9: return "\"It won't take long to implement that\"\n"
36  "... Davide, 2014";
37  case 10: return "Visualize data responsibly";
38  case 11: return "How could you live without it?";
39  case 12: return "This time you will find that nasty bug!";
40  case 13: return "Now, with less bugs than usual!";
41  case 14: return "You log them, I visualize them";
42  case 15: return "The fancy timeseries visualization tool";
43  case 16: return "Send me a PR with your splashscreen phrase!";
44 
45  default: return "I don't always visualize data,\n"
46  "but when I do, I use PlotJuggler";
47  }
48 }
49 
50 int main(int argc, char *argv[])
51 {
52  QApplication app(argc, argv);
53 
54  app.setOrganizationName("IcarusTechnology");
55  app.setApplicationName("PlotJuggler");
56 
57  // Load an application style
58  QFile styleFile( "://style/stylesheet.qss" );
59  styleFile.open( QFile::ReadOnly );
60 
61  // Apply the loaded stylesheet
62  QString style( styleFile.readAll() );
63  app.setStyleSheet( style );
64 
65  QString VERSION_STRING = QString("%1.%2.%3").
66  arg(PJ_MAJOR_VERSION).
67  arg(PJ_MINOR_VERSION).
68  arg(PJ_PATCH_VERSION);
69 
70  app.setApplicationVersion(VERSION_STRING);
71 
72  QCommandLineParser parser;
73  parser.setApplicationDescription("PlotJuggler: the time series visualization tool that you deserve ");
74  parser.addVersionOption();
75  parser.addHelpOption();
76 
77  QCommandLineOption nosplash_option(QStringList() << "n" << "nosplash",
78  "Don't display the splashscreen");
79  parser.addOption(nosplash_option);
80 
81  QCommandLineOption test_option(QStringList() << "t" << "test",
82  "Generate test curves at startup");
83  parser.addOption(test_option);
84 
85  QCommandLineOption loadfile_option(QStringList() << "d" << "datafile",
86  "Load a file containing data",
87  "file" );
88  parser.addOption(loadfile_option);
89 
90  QCommandLineOption layout_option(QStringList() << "l" << "layout",
91  "Load a file containing the layout configuration",
92  "file" );
93  parser.addOption(layout_option);
94 
95  QCommandLineOption publish_option(QStringList() << "p" << "publish",
96  "Automatically start publisher when loading the layout file" );
97  parser.addOption(publish_option);
98 
99  QCommandLineOption buffersize_option(QStringList() << "buffer_size",
100  QCoreApplication::translate("main", "Change the maximum size of the streaming buffer (minimum: 10 default: 60)"),
101  QCoreApplication::translate("main", "seconds") );
102  parser.addOption(buffersize_option);
103 
104  parser.process( *qApp );
105 
106  if( parser.isSet(publish_option) && !parser.isSet(layout_option) )
107  {
108  std::cerr << "Option [ -p / --publish ] is invalid unless [ -l / --layout ] is used too." << std::endl;
109  return -1;
110  }
111 
112  /*
113  * You, fearless code reviewer, decided to start a journey into my source code.
114  * For your bravery, you deserve to know the truth, no matter how hard it is to accept it.
115  * The splashscreen is useless; not only it is useless, it will make your start-up
116  * time slower by a couple of seconds for absolutely no reason.
117  * But what are two seconds compared with the time that PlotJuggler will save you?
118  * The splashscreen is the connection between me and my users, the glue that keeps
119  * together our invisible relationship.
120  * Now it is up to you to decide: you can block the splashscreen forever or not,
121  * reject a message that brings a little of happiness into your day, spent analyzing data.
122  * Please don't do it.
123  */
124 
125  if( !parser.isSet(nosplash_option) && !( parser.isSet(loadfile_option) || parser.isSet(layout_option) ) )
126  // if(false) // if you uncomment this line, a kitten will die somewhere in the world.
127  {
128  QPixmap main_pixmap(":/splash/resources/splash_2.2.jpg");
129 
130  int font_id = QFontDatabase::addApplicationFont("://resources/DejaVuSans-ExtraLight.ttf");
131  QString family = QFontDatabase::applicationFontFamilies(font_id).at(0);
132  QFont font(family);
133  font.setStyleStrategy(QFont::PreferAntialias);
134 
135  QPainter painter;
136  painter.begin( &main_pixmap);
137  painter.setPen(QColor(255, 255, 255));
138  painter.setRenderHint(QPainter::TextAntialiasing, true);
139 
140  const QString subtitle = getFunnySubtitle();
141 
142  {
143  const int margin = 20;
144  const int text_height = 100;
145  const int text_width = main_pixmap.width() - margin*2;
146  QPoint topleft(margin, main_pixmap.height() - text_height);
147  QSize rect_size(text_width, text_height);
148  font.setPointSize( 16 );
149  painter.setFont( font );
150  painter.drawText( QRect(topleft, rect_size),
151  Qt::AlignHCenter | Qt::AlignVCenter, subtitle );
152  }
153  {
154  const int text_width = 100;
155  QPoint topleft( main_pixmap.width() - text_width, 0);
156  QSize rect_size( text_width, 40 );
157  font.setPointSize( 14 );
158  painter.setFont( font );
159  painter.drawText( QRect(topleft, rect_size),
160  Qt::AlignHCenter | Qt::AlignVCenter, VERSION_STRING );
161  }
162 
163  painter.end();
164 
165  QSplashScreen splash(main_pixmap);
166  QDesktopWidget* desktop = QApplication::desktop();
167  const int scrn = desktop->screenNumber(QCursor::pos());
168  const QPoint currentDesktopsCenter = desktop->availableGeometry(scrn).center();
169  splash.move(currentDesktopsCenter - splash.rect().center());
170 
171  splash.show();
172  app.processEvents();
173  splash.raise();
174 
175  const auto deadline = QDateTime::currentDateTime().addMSecs( 100*(30 + subtitle.size()*0.4) );
176 
177  MainWindow w( parser );
178  while( QDateTime::currentDateTime() < deadline && !splash.isHidden() )
179  {
180  app.processEvents();
181  QThread::msleep(100);
182  splash.raise();
183  }
184  splash.close();
185  w.show();
186  return app.exec();
187  }
188  else{
189  MainWindow w( parser );
190  w.show();
191  return app.exec();
192  }
193  return 0;
194 }
app
QString getFunnySubtitle()
TFSIMD_FORCE_INLINE const tfScalar & w() const
void * arg
parser
int main(int argc, char *argv[])
int n


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17