Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gui_test_widget.hpp « qt_tstfrm - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0cfb1c85116858d7a2f3d1005c64e4b21457e400 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once

#include "gl_test_widget.hpp"
#include "../../gui/controller.hpp"

template <class T, void (T::*)(gui::Controller*)>
struct init_with_controller_fn_bind
{
  typedef T type;
};

template <class T, class U>
struct has_init_with_controller
{
  static bool const value = false;
};

template <class T>
struct has_init_with_controller<T, typename init_with_controller_fn_bind<T, &T::Init>::type>
{
  static bool const value = true;
};

template <typename TTest>
class GUITestWidget : public GLTestWidget<TTest>
{
private:

  typedef GLTestWidget<TTest> base_t;

  shared_ptr<gui::Controller> m_controller;
  shared_ptr<graphics::Screen> m_cacheScreen;

public:

  void initializeGL()
  {
    base_t::initializeGL();

    m_controller.reset(new gui::Controller());

    gui::Controller::RenderParams rp;

    graphics::Screen::Params cp;

    cp.m_doUnbindRT = false;
    cp.m_threadSlot = 0;
    cp.m_storageType = graphics::ESmallStorage;
    cp.m_textureType = graphics::ESmallTexture;
    cp.m_skinName = "basic_mdpi.skn";
    cp.m_isSynchronized = false;
    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(&QGLWidget::update, this);
    rp.m_VisualScale = 1.0;

    InitImpl(m_controller, bool_tag<has_init_with_controller<TTest, TTest>::value >());

    m_controller->SetRenderParams(rp);
  }

  void InitImpl(shared_ptr<gui::Controller> const & c, bool_tag<true> const &)
  {
    base_t::test.Init(c.get());
  }

  void InitImpl(shared_ptr<gui::Controller> const & c, bool_tag<false> const &)
  {}

  void DoDraw(shared_ptr<graphics::Screen> const & s)
  {
    base_t::DoDraw(s);
    m_controller->UpdateElements();
    m_controller->DrawFrame(s.get());
  }
};

template <class Test> QWidget * create_gui_test_widget()
{
  GUITestWidget<Test> * w = new GUITestWidget<Test>();
  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<char *>(#name) };\
    int argc = 1;\
    QApplication app(argc, argv);\
    QWidget * w = create_gui_test_widget<name>();\
    w->show();\
    app.exec();\
  }