From 66d0860f9aed9c2868f45ff53442e9ddef2b704a 2012-11-09 15:31:13 From: Marek Rosa Date: 2012-11-09 15:31:13 Subject: [PATCH] Quick demolauncher fix --- diff --git a/demos/demoLauncher/demoLauncher.pro b/demos/demoLauncher/demoLauncher.pro index f723d12..218d283 100644 --- a/demos/demoLauncher/demoLauncher.pro +++ b/demos/demoLauncher/demoLauncher.pro @@ -2,5 +2,7 @@ TARGET = demoLauncher SOURCES += main.cpp\ - widget.cpp -HEADERS += widget.h + widget.cpp \ + graphicsbutton.cpp +HEADERS += widget.h \ + graphicsbutton.h diff --git a/demos/demoLauncher/graphicsbutton.cpp b/demos/demoLauncher/graphicsbutton.cpp new file mode 100644 index 0000000..daa23f0 --- /dev/null +++ b/demos/demoLauncher/graphicsbutton.cpp @@ -0,0 +1,28 @@ +#include "graphicsbutton.h" +#include +#include +#include + +GraphicsButton::GraphicsButton(const QString& path, QDir appFolder, const QString& app, QWidget *parent) : + QWidget(parent), + m_path(path), + m_appFolder(appFolder), + m_app(app) +{ + m_pixmap = QPixmap(path); +} + +void GraphicsButton::mousePressEvent(QMouseEvent * event) +{ + QString program = m_appFolder.absolutePath() + QDir::separator() + m_app; + QProcess *demoApp = new QProcess(this); + demoApp->start(program); + event->accept(); +} + +void GraphicsButton::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + painter.drawPixmap(0, 0, this->width(), this->height(), m_pixmap); + QWidget::paintEvent(event); +} diff --git a/demos/demoLauncher/graphicsbutton.h b/demos/demoLauncher/graphicsbutton.h new file mode 100644 index 0000000..9986995 --- /dev/null +++ b/demos/demoLauncher/graphicsbutton.h @@ -0,0 +1,24 @@ +#ifndef GRAPHICSBUTTON_H +#define GRAPHICSBUTTON_H + +#include +#include + +class GraphicsButton : public QWidget +{ + Q_OBJECT +public: + explicit GraphicsButton(const QString& path, QDir appFolder, const QString& app, QWidget *parent = 0); + +protected: + void mousePressEvent(QMouseEvent * event); + void paintEvent(QPaintEvent *); + +private: + QPixmap m_pixmap; + QString m_path; + QDir m_appFolder; + QString m_app; +}; + +#endif // GRAPHICSBUTTON_H diff --git a/demos/demoLauncher/widget.cpp b/demos/demoLauncher/widget.cpp index f7fbe2e..de80af8 100644 --- a/demos/demoLauncher/widget.cpp +++ b/demos/demoLauncher/widget.cpp @@ -5,45 +5,83 @@ #include #include #include +#include +#include +#include "graphicsbutton.h" Widget::Widget(QWidget *parent) : QWidget(parent), m_demoApp(0) { + setMinimumSize(200, 200); // Create a list of executables QList appList; m_appFolder = QDir(QApplication::applicationDirPath()); + + QStringList filter; + filter << "audio"; + filter << "callout"; + filter << "chartthemes"; + filter << "nesteddonuts"; + filter << "zoomlinechart"; + filter << "stackedbarchartdrilldown"; + filter << "piechartcustomization"; + filter << "barmodelmapper"; + m_appFolder.setNameFilters(filter); #ifdef Q_OS_MAC // The executable is inside an application bundle (a folder) on OSX m_appFolder.cdUp(); m_appFolder.cdUp(); m_appFolder.cdUp(); - appList = m_appFolder.entryInfoList(QStringList("*.app"), QDir::Executable | QDir::Dirs | QDir::NoDotAndDotDot); -#elif defined(Q_OS_WIN) - appList = m_appFolder.entryInfoList(QStringList("*.exe"), QDir::Executable | QDir::Files | QDir::NoDotAndDotDot); -#else - appList = m_appFolder.entryInfoList(QDir::Executable | QDir::Files | QDir::NoDotAndDotDot); #endif - for (int k = appList.count() - 1; k >= 0; k--) { - QString name = appList[k].fileName(); - if (name.startsWith("tst_") || name.startsWith("demoLauncher")) - appList.removeAt(k); - } + + QDir imageFolder = m_appFolder; + imageFolder.cdUp(); + imageFolder.cdUp(); + + int width = 300; // Create push buttons for starting the executables QGridLayout* demosLayout = new QGridLayout; - for( int i = 0; i < appList.count(); i++) { - QPushButton *button = new QPushButton(appList[i].fileName()); - connect(button, SIGNAL(clicked()), this, SLOT (runApp())); - demosLayout->addWidget(button, i%10, i/10); - } + + GraphicsButton *button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/demos_audio.png", m_appFolder, "audio", this); + demosLayout->addWidget(button, 0, 0); + + button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_callout.png", m_appFolder, "callout", this); + demosLayout->addWidget(button, 0, 1); + + button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/demo_chartthemes_blue_cerulean.png", m_appFolder, "chartthemes", this); + demosLayout->addWidget(button, 0, 2); + + button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/demos_nesteddonuts.png", m_appFolder, "nesteddonuts", this); + demosLayout->addWidget(button, 1, 0); + + button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_zoomlinechart1.png", m_appFolder, "zoomlinechart", this); + demosLayout->addWidget(button, 1, 1); + + button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_stackedbarchartdrilldown1.png", m_appFolder, "stackedbarchartdrilldown", this); + demosLayout->addWidget(button, 1, 2); + + button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/piechart_customization.png", m_appFolder, "piechartcustomization", this); + demosLayout->addWidget(button, 2, 0); + + button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_datetimeaxis.png", m_appFolder, "datetimeaxis", this); + demosLayout->addWidget(button, 2, 1); + + button = new GraphicsButton(imageFolder.absolutePath() + "/doc/images/examples_datetimeaxis.png", m_appFolder, "donutbreakdown", this); + demosLayout->addWidget(button, 2, 2); + setLayout(demosLayout); } Widget::~Widget() { - if (m_demoApp) - m_demoApp->close(); + QList children = this->children(); + for (int i = 0; i < children.count(); i++) { + QProcess *app = qobject_cast(children.at(i)); + if (app) + app->close(); + } } void Widget::runApp() @@ -53,3 +91,18 @@ void Widget::runApp() m_demoApp = new QProcess(this); m_demoApp->start(program); } + +void Widget::mousePressEvent(QMouseEvent * event) +{ + for (int i = 0; i < layout()->count(); i++) { + QWidget *pic = layout()->itemAt(i)->widget(); + if (pic && pic->rect().contains(pic->mapFromParent(event->pos()))) { + QString value = m_map.value(pic); + QString program = m_appFolder.absolutePath() + QDir::separator() + value; + m_demoApp = new QProcess(this); + m_demoApp->start(program); + event->accept(); + return; + } + } +} diff --git a/demos/demoLauncher/widget.h b/demos/demoLauncher/widget.h index 8946724..f559c2e 100644 --- a/demos/demoLauncher/widget.h +++ b/demos/demoLauncher/widget.h @@ -3,8 +3,10 @@ #include #include +#include class QProcess; +class QMouseEvent; class Widget : public QWidget { @@ -14,12 +16,16 @@ public: Widget(QWidget *parent = 0); ~Widget(); +protected: + void mousePressEvent(QMouseEvent * event); + public slots: void runApp(); private: QDir m_appFolder; QProcess *m_demoApp; + QMap m_map; }; #endif // WIDGET_H