##// END OF EJS Templates
Cleaned up demoLauncher
Marek Rosa -
r2254:3e008d6a7c89
parent child
Show More
@@ -1,28 +1,35
1 1 #include "graphicsbutton.h"
2 2 #include <QPainter>
3 3 #include <QProcess>
4 4 #include <QMouseEvent>
5 5
6 6 GraphicsButton::GraphicsButton(const QString& path, QDir appFolder, const QString& app, QWidget *parent) :
7 7 QWidget(parent),
8 8 m_path(path),
9 9 m_appFolder(appFolder),
10 m_app(app)
10 m_app(app),
11 m_demoApp(0)
11 12 {
12 13 m_pixmap = QPixmap(path);
13 14 }
14 15
16 GraphicsButton::~GraphicsButton()
17 {
18 if (m_demoApp)
19 m_demoApp->close();
20 }
21
15 22 void GraphicsButton::mousePressEvent(QMouseEvent * event)
16 23 {
17 24 QString program = m_appFolder.absolutePath() + QDir::separator() + m_app;
18 QProcess *demoApp = new QProcess(this);
19 demoApp->start(program);
25 m_demoApp = new QProcess(this);
26 m_demoApp->start(program);
20 27 event->accept();
21 28 }
22 29
23 30 void GraphicsButton::paintEvent(QPaintEvent *event)
24 31 {
25 32 QPainter painter(this);
26 33 painter.drawPixmap(0, 0, this->width(), this->height(), m_pixmap);
27 34 QWidget::paintEvent(event);
28 35 }
@@ -1,24 +1,28
1 1 #ifndef GRAPHICSBUTTON_H
2 2 #define GRAPHICSBUTTON_H
3 3
4 4 #include <QWidget>
5 5 #include <QDir>
6 6
7 class QProcess;
8
7 9 class GraphicsButton : public QWidget
8 10 {
9 11 Q_OBJECT
10 12 public:
11 13 explicit GraphicsButton(const QString& path, QDir appFolder, const QString& app, QWidget *parent = 0);
14 ~GraphicsButton();
12 15
13 16 protected:
14 17 void mousePressEvent(QMouseEvent * event);
15 18 void paintEvent(QPaintEvent *);
16 19
17 20 private:
18 21 QPixmap m_pixmap;
19 22 QString m_path;
20 23 QDir m_appFolder;
21 24 QString m_app;
25 QProcess *m_demoApp;
22 26 };
23 27
24 28 #endif // GRAPHICSBUTTON_H
@@ -1,108 +1,61
1 1 #include "widget.h"
2 #include <QPushButton>
3 2 #include <QDir>
4 3 #include <QGridLayout>
5 4 #include <QApplication>
6 #include <QProcess>
7 #include <QDebug>
8 #include <QLabel>
9 #include <QMouseEvent>
10 5 #include "graphicsbutton.h"
11 6
12 7 Widget::Widget(QWidget *parent)
13 : QWidget(parent),
14 m_demoApp(0)
8 : QWidget(parent)
15 9 {
16 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;
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);
12 m_appFolder = QDir(QApplication::applicationDirPath());
31 13 #ifdef Q_OS_MAC
32 14 // The executable is inside an application bundle (a folder) on OSX
33 15 m_appFolder.cdUp();
34 16 m_appFolder.cdUp();
35 17 m_appFolder.cdUp();
36 18 #endif
37 19
38 20 QDir imageFolder = m_appFolder;
39 21 imageFolder.cdUp();
40 22 imageFolder.cdUp();
41
42 int width = 300;
23 imageFolder.cd("doc");
24 imageFolder.cd("images");
43 25
44 26 // Create push buttons for starting the executables
45 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 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 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 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 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 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 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 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 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 54 demosLayout->addWidget(button, 2, 2);
73 55
74 56 setLayout(demosLayout);
75 57 }
76 58
77 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 }
@@ -1,31 +1,19
1 1 #ifndef WIDGET_H
2 2 #define WIDGET_H
3 3
4 4 #include <QWidget>
5 5 #include <QDir>
6 #include <QMap>
7
8 class QProcess;
9 class QMouseEvent;
10 6
11 7 class Widget : public QWidget
12 8 {
13 9 Q_OBJECT
14 10
15 11 public:
16 12 Widget(QWidget *parent = 0);
17 13 ~Widget();
18 14
19 protected:
20 void mousePressEvent(QMouseEvent * event);
21
22 public slots:
23 void runApp();
24
25 15 private:
26 16 QDir m_appFolder;
27 QProcess *m_demoApp;
28 QMap<QWidget*, QString> m_map;
29 17 };
30 18
31 19 #endif // WIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now