##// END OF EJS Templates
Quick demolauncher fix
Marek Rosa -
r2252:66d0860f9aed
parent child
Show More
@@ -0,0 +1,28
1 #include "graphicsbutton.h"
2 #include <QPainter>
3 #include <QProcess>
4 #include <QMouseEvent>
5
6 GraphicsButton::GraphicsButton(const QString& path, QDir appFolder, const QString& app, QWidget *parent) :
7 QWidget(parent),
8 m_path(path),
9 m_appFolder(appFolder),
10 m_app(app)
11 {
12 m_pixmap = QPixmap(path);
13 }
14
15 void GraphicsButton::mousePressEvent(QMouseEvent * event)
16 {
17 QString program = m_appFolder.absolutePath() + QDir::separator() + m_app;
18 QProcess *demoApp = new QProcess(this);
19 demoApp->start(program);
20 event->accept();
21 }
22
23 void GraphicsButton::paintEvent(QPaintEvent *event)
24 {
25 QPainter painter(this);
26 painter.drawPixmap(0, 0, this->width(), this->height(), m_pixmap);
27 QWidget::paintEvent(event);
28 }
@@ -0,0 +1,24
1 #ifndef GRAPHICSBUTTON_H
2 #define GRAPHICSBUTTON_H
3
4 #include <QWidget>
5 #include <QDir>
6
7 class GraphicsButton : public QWidget
8 {
9 Q_OBJECT
10 public:
11 explicit GraphicsButton(const QString& path, QDir appFolder, const QString& app, QWidget *parent = 0);
12
13 protected:
14 void mousePressEvent(QMouseEvent * event);
15 void paintEvent(QPaintEvent *);
16
17 private:
18 QPixmap m_pixmap;
19 QString m_path;
20 QDir m_appFolder;
21 QString m_app;
22 };
23
24 #endif // GRAPHICSBUTTON_H
@@ -2,5 +2,7
2
2
3 TARGET = demoLauncher
3 TARGET = demoLauncher
4 SOURCES += main.cpp\
4 SOURCES += main.cpp\
5 widget.cpp
5 widget.cpp \
6 HEADERS += widget.h
6 graphicsbutton.cpp
7 HEADERS += widget.h \
8 graphicsbutton.h
@@ -5,45 +5,83
5 #include <QApplication>
5 #include <QApplication>
6 #include <QProcess>
6 #include <QProcess>
7 #include <QDebug>
7 #include <QDebug>
8 #include <QLabel>
9 #include <QMouseEvent>
10 #include "graphicsbutton.h"
8
11
9 Widget::Widget(QWidget *parent)
12 Widget::Widget(QWidget *parent)
10 : QWidget(parent),
13 : QWidget(parent),
11 m_demoApp(0)
14 m_demoApp(0)
12 {
15 {
16 setMinimumSize(200, 200);
13 // Create a list of executables
17 // Create a list of executables
14 QList<QFileInfo> appList;
18 QList<QFileInfo> appList;
15 m_appFolder = QDir(QApplication::applicationDirPath());
19 m_appFolder = QDir(QApplication::applicationDirPath());
20
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);
16 #ifdef Q_OS_MAC
31 #ifdef Q_OS_MAC
17 // The executable is inside an application bundle (a folder) on OSX
32 // The executable is inside an application bundle (a folder) on OSX
18 m_appFolder.cdUp();
33 m_appFolder.cdUp();
19 m_appFolder.cdUp();
34 m_appFolder.cdUp();
20 m_appFolder.cdUp();
35 m_appFolder.cdUp();
21 appList = m_appFolder.entryInfoList(QStringList("*.app"), QDir::Executable | QDir::Dirs | QDir::NoDotAndDotDot);
22 #elif defined(Q_OS_WIN)
23 appList = m_appFolder.entryInfoList(QStringList("*.exe"), QDir::Executable | QDir::Files | QDir::NoDotAndDotDot);
24 #else
25 appList = m_appFolder.entryInfoList(QDir::Executable | QDir::Files | QDir::NoDotAndDotDot);
26 #endif
36 #endif
27 for (int k = appList.count() - 1; k >= 0; k--) {
37
28 QString name = appList[k].fileName();
38 QDir imageFolder = m_appFolder;
29 if (name.startsWith("tst_") || name.startsWith("demoLauncher"))
39 imageFolder.cdUp();
30 appList.removeAt(k);
40 imageFolder.cdUp();
31 }
41
42 int width = 300;
32
43
33 // Create push buttons for starting the executables
44 // Create push buttons for starting the executables
34 QGridLayout* demosLayout = new QGridLayout;
45 QGridLayout* demosLayout = new QGridLayout;
35 for( int i = 0; i < appList.count(); i++) {
46
36 QPushButton *button = new QPushButton(appList[i].fileName());
47 GraphicsButton *button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/demos_audio.png", m_appFolder, "audio", this);
37 connect(button, SIGNAL(clicked()), this, SLOT (runApp()));
48 demosLayout->addWidget(button, 0, 0);
38 demosLayout->addWidget(button, i%10, i/10);
49
39 }
50 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_callout.png", m_appFolder, "callout", this);
51 demosLayout->addWidget(button, 0, 1);
52
53 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/demo_chartthemes_blue_cerulean.png", m_appFolder, "chartthemes", this);
54 demosLayout->addWidget(button, 0, 2);
55
56 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/demos_nesteddonuts.png", m_appFolder, "nesteddonuts", this);
57 demosLayout->addWidget(button, 1, 0);
58
59 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_zoomlinechart1.png", m_appFolder, "zoomlinechart", this);
60 demosLayout->addWidget(button, 1, 1);
61
62 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_stackedbarchartdrilldown1.png", m_appFolder, "stackedbarchartdrilldown", this);
63 demosLayout->addWidget(button, 1, 2);
64
65 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/piechart_customization.png", m_appFolder, "piechartcustomization", this);
66 demosLayout->addWidget(button, 2, 0);
67
68 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_datetimeaxis.png", m_appFolder, "datetimeaxis", this);
69 demosLayout->addWidget(button, 2, 1);
70
71 button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_datetimeaxis.png", m_appFolder, "donutbreakdown", this);
72 demosLayout->addWidget(button, 2, 2);
73
40 setLayout(demosLayout);
74 setLayout(demosLayout);
41 }
75 }
42
76
43 Widget::~Widget()
77 Widget::~Widget()
44 {
78 {
45 if (m_demoApp)
79 QList<QObject *> children = this->children();
46 m_demoApp->close();
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 }
47 }
85 }
48
86
49 void Widget::runApp()
87 void Widget::runApp()
@@ -53,3 +91,18 void Widget::runApp()
53 m_demoApp = new QProcess(this);
91 m_demoApp = new QProcess(this);
54 m_demoApp->start(program);
92 m_demoApp->start(program);
55 }
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 }
@@ -3,8 +3,10
3
3
4 #include <QWidget>
4 #include <QWidget>
5 #include <QDir>
5 #include <QDir>
6 #include <QMap>
6
7
7 class QProcess;
8 class QProcess;
9 class QMouseEvent;
8
10
9 class Widget : public QWidget
11 class Widget : public QWidget
10 {
12 {
@@ -14,12 +16,16 public:
14 Widget(QWidget *parent = 0);
16 Widget(QWidget *parent = 0);
15 ~Widget();
17 ~Widget();
16
18
19 protected:
20 void mousePressEvent(QMouseEvent * event);
21
17 public slots:
22 public slots:
18 void runApp();
23 void runApp();
19
24
20 private:
25 private:
21 QDir m_appFolder;
26 QDir m_appFolder;
22 QProcess *m_demoApp;
27 QProcess *m_demoApp;
28 QMap<QWidget*, QString> m_map;
23 };
29 };
24
30
25 #endif // WIDGET_H
31 #endif // WIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now