##// 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
@@ -1,6 +1,8
1 1 !include( ../demos.pri ):error( "Couldn't find the demos.pri file!" )
2 2
3 3 TARGET = demoLauncher
4 4 SOURCES += main.cpp\
5 widget.cpp
6 HEADERS += widget.h
5 widget.cpp \
6 graphicsbutton.cpp
7 HEADERS += widget.h \
8 graphicsbutton.h
@@ -1,55 +1,108
1 1 #include "widget.h"
2 2 #include <QPushButton>
3 3 #include <QDir>
4 4 #include <QGridLayout>
5 5 #include <QApplication>
6 6 #include <QProcess>
7 7 #include <QDebug>
8 #include <QLabel>
9 #include <QMouseEvent>
10 #include "graphicsbutton.h"
8 11
9 12 Widget::Widget(QWidget *parent)
10 13 : QWidget(parent),
11 14 m_demoApp(0)
12 15 {
16 setMinimumSize(200, 200);
13 17 // Create a list of executables
14 18 QList<QFileInfo> appList;
15 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 31 #ifdef Q_OS_MAC
17 32 // The executable is inside an application bundle (a folder) on OSX
18 33 m_appFolder.cdUp();
19 34 m_appFolder.cdUp();
20 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 36 #endif
27 for (int k = appList.count() - 1; k >= 0; k--) {
28 QString name = appList[k].fileName();
29 if (name.startsWith("tst_") || name.startsWith("demoLauncher"))
30 appList.removeAt(k);
31 }
37
38 QDir imageFolder = m_appFolder;
39 imageFolder.cdUp();
40 imageFolder.cdUp();
41
42 int width = 300;
32 43
33 44 // Create push buttons for starting the executables
34 45 QGridLayout* demosLayout = new QGridLayout;
35 for( int i = 0; i < appList.count(); i++) {
36 QPushButton *button = new QPushButton(appList[i].fileName());
37 connect(button, SIGNAL(clicked()), this, SLOT (runApp()));
38 demosLayout->addWidget(button, i%10, i/10);
39 }
46
47 GraphicsButton *button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/demos_audio.png", m_appFolder, "audio", this);
48 demosLayout->addWidget(button, 0, 0);
49
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 74 setLayout(demosLayout);
41 75 }
42 76
43 77 Widget::~Widget()
44 78 {
45 if (m_demoApp)
46 m_demoApp->close();
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 }
47 85 }
48 86
49 87 void Widget::runApp()
50 88 {
51 89 QString name = qobject_cast<QPushButton *>(sender())->text();
52 90 QString program = m_appFolder.absolutePath() + QDir::separator() + name;
53 91 m_demoApp = new QProcess(this);
54 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 }
@@ -1,25 +1,31
1 1 #ifndef WIDGET_H
2 2 #define WIDGET_H
3 3
4 4 #include <QWidget>
5 5 #include <QDir>
6 #include <QMap>
6 7
7 8 class QProcess;
9 class QMouseEvent;
8 10
9 11 class Widget : public QWidget
10 12 {
11 13 Q_OBJECT
12 14
13 15 public:
14 16 Widget(QWidget *parent = 0);
15 17 ~Widget();
16 18
19 protected:
20 void mousePressEvent(QMouseEvent * event);
21
17 22 public slots:
18 23 void runApp();
19 24
20 25 private:
21 26 QDir m_appFolder;
22 27 QProcess *m_demoApp;
28 QMap<QWidget*, QString> m_map;
23 29 };
24 30
25 31 #endif // WIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now