##// END OF EJS Templates
Cleaned up demoLauncher
Marek Rosa -
r2254:3e008d6a7c89
parent child
Show More
@@ -7,16 +7,23 GraphicsButton::GraphicsButton(const QString& path, QDir appFolder, const QStri
7 QWidget(parent),
7 QWidget(parent),
8 m_path(path),
8 m_path(path),
9 m_appFolder(appFolder),
9 m_appFolder(appFolder),
10 m_app(app)
10 m_app(app),
11 m_demoApp(0)
11 {
12 {
12 m_pixmap = QPixmap(path);
13 m_pixmap = QPixmap(path);
13 }
14 }
14
15
16 GraphicsButton::~GraphicsButton()
17 {
18 if (m_demoApp)
19 m_demoApp->close();
20 }
21
15 void GraphicsButton::mousePressEvent(QMouseEvent * event)
22 void GraphicsButton::mousePressEvent(QMouseEvent * event)
16 {
23 {
17 QString program = m_appFolder.absolutePath() + QDir::separator() + m_app;
24 QString program = m_appFolder.absolutePath() + QDir::separator() + m_app;
18 QProcess *demoApp = new QProcess(this);
25 m_demoApp = new QProcess(this);
19 demoApp->start(program);
26 m_demoApp->start(program);
20 event->accept();
27 event->accept();
21 }
28 }
22
29
@@ -4,11 +4,14
4 #include <QWidget>
4 #include <QWidget>
5 #include <QDir>
5 #include <QDir>
6
6
7 class QProcess;
8
7 class GraphicsButton : public QWidget
9 class GraphicsButton : public QWidget
8 {
10 {
9 Q_OBJECT
11 Q_OBJECT
10 public:
12 public:
11 explicit GraphicsButton(const QString& path, QDir appFolder, const QString& app, QWidget *parent = 0);
13 explicit GraphicsButton(const QString& path, QDir appFolder, const QString& app, QWidget *parent = 0);
14 ~GraphicsButton();
12
15
13 protected:
16 protected:
14 void mousePressEvent(QMouseEvent * event);
17 void mousePressEvent(QMouseEvent * event);
@@ -19,6 +22,7 private:
19 QString m_path;
22 QString m_path;
20 QDir m_appFolder;
23 QDir m_appFolder;
21 QString m_app;
24 QString m_app;
25 QProcess *m_demoApp;
22 };
26 };
23
27
24 #endif // GRAPHICSBUTTON_H
28 #endif // GRAPHICSBUTTON_H
@@ -1,33 +1,15
1 #include "widget.h"
1 #include "widget.h"
2 #include <QPushButton>
3 #include <QDir>
2 #include <QDir>
4 #include <QGridLayout>
3 #include <QGridLayout>
5 #include <QApplication>
4 #include <QApplication>
6 #include <QProcess>
7 #include <QDebug>
8 #include <QLabel>
9 #include <QMouseEvent>
10 #include "graphicsbutton.h"
5 #include "graphicsbutton.h"
11
6
12 Widget::Widget(QWidget *parent)
7 Widget::Widget(QWidget *parent)
13 : QWidget(parent),
8 : QWidget(parent)
14 m_demoApp(0)
15 {
9 {
16 setMinimumSize(200, 200);
10 setMinimumSize(200, 200);
17 // Create a list of executables
18 QList<QFileInfo> appList;
19 m_appFolder = QDir(QApplication::applicationDirPath());
20
11
21 QStringList filter;
12 m_appFolder = QDir(QApplication::applicationDirPath());
22 filter << "audio";
23 filter << "callout";
24 filter << "chartthemes";
25 filter << "nesteddonuts";
26 filter << "zoomlinechart";
27 filter << "stackedbarchartdrilldown";
28 filter << "piechartcustomization";
29 filter << "barmodelmapper";
30 m_appFolder.setNameFilters(filter);
31 #ifdef Q_OS_MAC
13 #ifdef Q_OS_MAC
32 // The executable is inside an application bundle (a folder) on OSX
14 // The executable is inside an application bundle (a folder) on OSX
33 m_appFolder.cdUp();
15 m_appFolder.cdUp();
@@ -38,71 +20,42 Widget::Widget(QWidget *parent)
38 QDir imageFolder = m_appFolder;
20 QDir imageFolder = m_appFolder;
39 imageFolder.cdUp();
21 imageFolder.cdUp();
40 imageFolder.cdUp();
22 imageFolder.cdUp();
41
23 imageFolder.cd("doc");
42 int width = 300;
24 imageFolder.cd("images");
43
25
44 // Create push buttons for starting the executables
26 // Create push buttons for starting the executables
45 QGridLayout* demosLayout = new QGridLayout;
27 QGridLayout* demosLayout = new QGridLayout;
46
28
47 GraphicsButton *button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/demos_audio.png", m_appFolder, "audio", this);
29 GraphicsButton *button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() + "demos_audio.png", m_appFolder, "audio", this);
48 demosLayout->addWidget(button, 0, 0);
30 demosLayout->addWidget(button, 0, 0);
49
31
50 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_callout.png", m_appFolder, "callout", this);
32 button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_callout.png", m_appFolder, "callout", this);
51 demosLayout->addWidget(button, 0, 1);
33 demosLayout->addWidget(button, 0, 1);
52
34
53 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/demo_chartthemes_blue_cerulean.png", m_appFolder, "chartthemes", this);
35 button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"demo_chartthemes_blue_cerulean.png", m_appFolder, "chartthemes", this);
54 demosLayout->addWidget(button, 0, 2);
36 demosLayout->addWidget(button, 0, 2);
55
37
56 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/demos_nesteddonuts.png", m_appFolder, "nesteddonuts", this);
38 button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"demos_nesteddonuts.png", m_appFolder, "nesteddonuts", this);
57 demosLayout->addWidget(button, 1, 0);
39 demosLayout->addWidget(button, 1, 0);
58
40
59 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_zoomlinechart1.png", m_appFolder, "zoomlinechart", this);
41 button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_zoomlinechart1.png", m_appFolder, "zoomlinechart", this);
60 demosLayout->addWidget(button, 1, 1);
42 demosLayout->addWidget(button, 1, 1);
61
43
62 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_stackedbarchartdrilldown1.png", m_appFolder, "stackedbarchartdrilldown", this);
44 button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_stackedbarchartdrilldown1.png", m_appFolder, "stackedbarchartdrilldown", this);
63 demosLayout->addWidget(button, 1, 2);
45 demosLayout->addWidget(button, 1, 2);
64
46
65 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/piechart_customization.png", m_appFolder, "piechartcustomization", this);
47 button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"piechart_customization.png", m_appFolder, "piechartcustomization", this);
66 demosLayout->addWidget(button, 2, 0);
48 demosLayout->addWidget(button, 2, 0);
67
49
68 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_datetimeaxis.png", m_appFolder, "datetimeaxis", this);
50 button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_datetimeaxis.png", m_appFolder, "datetimeaxis", this);
69 demosLayout->addWidget(button, 2, 1);
51 demosLayout->addWidget(button, 2, 1);
70
52
71 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_donutbreakdown.png", m_appFolder, "donutbreakdown", this);
53 button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_donutbreakdown.png", m_appFolder, "donutbreakdown", this);
72 demosLayout->addWidget(button, 2, 2);
54 demosLayout->addWidget(button, 2, 2);
73
55
74 setLayout(demosLayout);
56 setLayout(demosLayout);
75 }
57 }
76
58
77 Widget::~Widget()
59 Widget::~Widget()
78 {
60 {
79 QList<QObject *> children = this->children();
80 for (int i = 0; i < children.count(); i++) {
81 QProcess *app = qobject_cast<QProcess *>(children.at(i));
82 if (app)
83 app->close();
84 }
85 }
86
87 void Widget::runApp()
88 {
89 QString name = qobject_cast<QPushButton *>(sender())->text();
90 QString program = m_appFolder.absolutePath() + QDir::separator() + name;
91 m_demoApp = new QProcess(this);
92 m_demoApp->start(program);
93 }
94
95 void Widget::mousePressEvent(QMouseEvent * event)
96 {
97 for (int i = 0; i < layout()->count(); i++) {
98 QWidget *pic = layout()->itemAt(i)->widget();
99 if (pic && pic->rect().contains(pic->mapFromParent(event->pos()))) {
100 QString value = m_map.value(pic);
101 QString program = m_appFolder.absolutePath() + QDir::separator() + value;
102 m_demoApp = new QProcess(this);
103 m_demoApp->start(program);
104 event->accept();
105 return;
106 }
107 }
108 }
61 }
@@ -3,10 +3,6
3
3
4 #include <QWidget>
4 #include <QWidget>
5 #include <QDir>
5 #include <QDir>
6 #include <QMap>
7
8 class QProcess;
9 class QMouseEvent;
10
6
11 class Widget : public QWidget
7 class Widget : public QWidget
12 {
8 {
@@ -16,16 +12,8 public:
16 Widget(QWidget *parent = 0);
12 Widget(QWidget *parent = 0);
17 ~Widget();
13 ~Widget();
18
14
19 protected:
20 void mousePressEvent(QMouseEvent * event);
21
22 public slots:
23 void runApp();
24
25 private:
15 private:
26 QDir m_appFolder;
16 QDir m_appFolder;
27 QProcess *m_demoApp;
28 QMap<QWidget*, QString> m_map;
29 };
17 };
30
18
31 #endif // WIDGET_H
19 #endif // WIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now