diff options
author | ExMix <rahuba.youri@mapswithme.com> | 2014-12-11 12:02:00 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:34:51 +0300 |
commit | 270c4915615e8e74c9605616f469a8e5c3b971a3 (patch) | |
tree | 000937bb75888d618e3f0848ac6a82683a1dd7c5 /qt_tstfrm | |
parent | 9cbaec6c292fae1167d0695d4103abfa60ae2b2b (diff) |
[drape] move test widget to common lib
Diffstat (limited to 'qt_tstfrm')
-rw-r--r-- | qt_tstfrm/qt_tstfrm.pro | 4 | ||||
-rw-r--r-- | qt_tstfrm/test_main_loop.cpp | 43 | ||||
-rw-r--r-- | qt_tstfrm/test_main_loop.hpp | 25 |
3 files changed, 71 insertions, 1 deletions
diff --git a/qt_tstfrm/qt_tstfrm.pro b/qt_tstfrm/qt_tstfrm.pro index f71ac76c08..3e8fe9bda4 100644 --- a/qt_tstfrm/qt_tstfrm.pro +++ b/qt_tstfrm/qt_tstfrm.pro @@ -6,15 +6,17 @@ ROOT_DIR = .. include($$ROOT_DIR/common.pri) -QT *= core gui opengl +QT *= core gui widgets opengl HEADERS += \ tstwidgets.hpp \ macros.hpp \ gl_test_widget.hpp \ gui_test_widget.hpp \ + test_main_loop.hpp SOURCES += \ tstwidgets.cpp \ + test_main_loop.cpp diff --git a/qt_tstfrm/test_main_loop.cpp b/qt_tstfrm/test_main_loop.cpp new file mode 100644 index 0000000000..9108b2ceb0 --- /dev/null +++ b/qt_tstfrm/test_main_loop.cpp @@ -0,0 +1,43 @@ +#include "test_main_loop.hpp" + +#include <QtCore/QTimer> +#include <QtWidgets/QApplication> +#include <QtWidgets/QWidget> + +#include "../base/scope_guard.hpp" + +#include "../std/cstring.hpp" + +TestMainLoop::TestMainLoop(TestMainLoop::TRednerFn const & fn) + : m_renderFn(fn) +{ +} + +void TestMainLoop::exec(char const * testName) +{ + char * buf = (char *)malloc(strlen(testName) + 1); + MY_SCOPE_GUARD(argvFreeFun, [&buf](){ free(buf); }); + strcpy(buf, testName); + + int argc = 1; + QApplication app(argc, &buf); + QTimer::singleShot(3000, &app, SLOT(quit())); + + QWidget w; + w.setWindowTitle(testName); + w.show(); + w.installEventFilter(this); + + app.exec(); +} + +bool TestMainLoop::eventFilter(QObject * obj, QEvent * event) +{ + if (event->type() == QEvent::Paint) + { + m_renderFn(qobject_cast<QWidget *>(obj)); + return true; + } + + return false; +} diff --git a/qt_tstfrm/test_main_loop.hpp b/qt_tstfrm/test_main_loop.hpp new file mode 100644 index 0000000000..6e0b41b1d1 --- /dev/null +++ b/qt_tstfrm/test_main_loop.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include <QtCore/QObject> + +#include "../std/function.hpp" + +class QPaintDevice; +class TestMainLoop : public QObject +{ + Q_OBJECT + +public: + + typedef function<void (QPaintDevice *)> TRednerFn; + TestMainLoop(TRednerFn const & fn); + virtual ~TestMainLoop() {} + + void exec(char const * testName); + +protected: + bool eventFilter(QObject * obj, QEvent * event); + +private: + TRednerFn m_renderFn; +}; |