#pragma once #include "gl_test_widget.hpp" #include "../../gui/controller.hpp" #include "../../base/strings_bundle.hpp" #include #include #include template struct init_with_controller_fn_bind { typedef T type; }; template struct has_init_with_controller { static bool const value = false; }; template struct has_init_with_controller::type> { static bool const value = true; }; template class GUITestWidget : public GLTestWidget { private: typedef GLTestWidget base_t; shared_ptr m_controller; shared_ptr m_cacheScreen; shared_ptr m_stringBundle; shared_ptr m_timerObj; int m_timerID; public: void invalidate() { base_t::updateGL(); } void initializeGL() { m_timerObj.reset(new QObject()); m_timerObj->installEventFilter(this); m_timerID = m_timerObj->startTimer(1000 / 60); base_t::initializeGL(); m_controller.reset(new gui::Controller()); gui::Controller::RenderParams rp; graphics::Screen::Params cp; cp.m_threadSlot = 0; cp.m_storageType = graphics::ETinyStorage; cp.m_textureType = graphics::ESmallTexture; cp.m_resourceManager = base_t::m_resourceManager; cp.m_renderContext = base_t::m_primaryContext; m_cacheScreen = make_shared_ptr(new graphics::Screen(cp)); rp.m_CacheScreen = m_cacheScreen.get(); rp.m_GlyphCache = base_t::m_resourceManager->glyphCache(0); rp.m_InvalidateFn = bind(&GUITestWidget::invalidate, this); rp.m_Density = graphics::EDensityMDPI; m_stringBundle.reset(new StringsBundle()); m_stringBundle->SetDefaultString("country_status_download", "Download^"); m_controller->SetStringsBundle(m_stringBundle.get()); InitImpl(m_controller, bool_tag::value >()); m_controller->SetRenderParams(rp); } void InitImpl(shared_ptr const & c, bool_tag const &) { base_t::test.Init(c.get()); } void InitImpl(shared_ptr const & c, bool_tag const &) {} void DoDraw(shared_ptr const & s) { base_t::DoDraw(s); m_controller->UpdateElements(); m_controller->DrawFrame(s.get()); } void mousePressEvent(QMouseEvent * e) { base_t::mousePressEvent(e); if (e->button() == Qt::LeftButton) m_controller->OnTapStarted(m2::PointU(e->pos().x(), e->pos().y())); } void mouseReleaseEvent(QMouseEvent * e) { base_t::mouseReleaseEvent(e); if (e->button() == Qt::LeftButton) m_controller->OnTapEnded(m2::PointU(e->pos().x(), e->pos().y())); } void mouseMoveEvent(QMouseEvent * e) { base_t::mouseMoveEvent(e); m_controller->OnTapMoved(m2::PointU(e->pos().x(), e->pos().y())); } bool eventFilter(QObject * obj, QEvent *event) { if (obj == m_timerObj.get() && event->type() == QEvent::Timer) { if (((QTimerEvent *)event)->timerId() == m_timerID) { invalidate(); return true; } } return false; } }; template QWidget * create_gui_test_widget() { GUITestWidget * w = new GUITestWidget(); w->Init(); return w; } #define UNIT_TEST_GUI(name)\ void UnitTestGUI_##name();\ TestRegister g_TestRegisterGUI_##name("Test::"#name, __FILE__, &UnitTestGUI_##name);\ void UnitTestGUI_##name()\ {\ char * argv[] = { const_cast(#name) };\ int argc = 1;\ QApplication app(argc, argv);\ QWidget * w = create_gui_test_widget();\ w->show();\ app.exec();\ }