1 | #ifndef BTNLISTTEST_CPP |
---|
2 | #define BTNLISTTEST_CPP |
---|
3 | |
---|
4 | #include "btnlisttest.h" |
---|
5 | #include "mythmainwindow.h" |
---|
6 | #include "mythlistbutton.h" |
---|
7 | #include "mythcontext.h" |
---|
8 | #include "mythfontproperties.h" |
---|
9 | |
---|
10 | #include <qapplication.h> |
---|
11 | |
---|
12 | TestWindow::TestWindow(MythScreenStack *parent) |
---|
13 | : MythScreenType(parent, "dialogtest") |
---|
14 | { |
---|
15 | |
---|
16 | listWidth = GetMythMainWindow()->GetUIScreenRect().width() - 2*pad; |
---|
17 | |
---|
18 | this->setupHList(); |
---|
19 | this->hbuttons->SetActive(true); |
---|
20 | this->focused = this->hbuttons; |
---|
21 | |
---|
22 | new MythListButtonItem(hbuttons, "Hello"); |
---|
23 | new MythListButtonItem(hbuttons, "Goodbye"); |
---|
24 | new MythListButtonItem(hbuttons, "Really Really Really Really Long"); |
---|
25 | new MythListButtonItem(hbuttons, "A B C D"); |
---|
26 | |
---|
27 | this->setupVList(); |
---|
28 | new MythListButtonItem(vbuttons, "Hello"); |
---|
29 | new MythListButtonItem(vbuttons, "Goodbye"); |
---|
30 | new MythListButtonItem(vbuttons, "Really Really Really Really Long"); |
---|
31 | new MythListButtonItem(vbuttons, "A B C D"); |
---|
32 | } |
---|
33 | |
---|
34 | TestWindow::~TestWindow(void) |
---|
35 | { |
---|
36 | } |
---|
37 | |
---|
38 | void TestWindow::setupVList(void) |
---|
39 | { |
---|
40 | |
---|
41 | /* place below the first list */ |
---|
42 | QRect r(pad, listHeight + 2*pad, listWidth, listHeight); |
---|
43 | cout << "(" << r.x() << ", " << r.y() << ")\t" << r.width() << " x " |
---|
44 | << r.height() << endl; |
---|
45 | |
---|
46 | vbuttons = new MythListButton(this, "vlist", r, true, true); |
---|
47 | |
---|
48 | MythFontProperties fontProp; |
---|
49 | fontProp.face = CreateFont("Arial", 24, QFont::Bold); |
---|
50 | fontProp.color = QColor(Qt::white); |
---|
51 | fontProp.hasShadow = true; |
---|
52 | fontProp.shadowOffset = NormPoint(QPoint(4, 4)); |
---|
53 | fontProp.shadowColor = QColor(Qt::black); |
---|
54 | fontProp.shadowAlpha = 64; |
---|
55 | |
---|
56 | vbuttons->SetFontActive(fontProp); |
---|
57 | |
---|
58 | fontProp.color = Qt::darkGray; |
---|
59 | |
---|
60 | vbuttons->SetFontInactive(fontProp); |
---|
61 | vbuttons->SetSpacing(NormX(10)); |
---|
62 | vbuttons->SetMargin(NormX(6)); |
---|
63 | vbuttons->SetDrawFromBottom(true); |
---|
64 | vbuttons->SetTextFlags(Qt::AlignCenter); |
---|
65 | } |
---|
66 | |
---|
67 | void TestWindow::setupHList(void) |
---|
68 | { |
---|
69 | |
---|
70 | |
---|
71 | QRect prect = GetMythMainWindow()->GetUIScreenRect(); |
---|
72 | QRect r(pad, pad, listWidth, listHeight); |
---|
73 | |
---|
74 | hbuttons = new MythHorizListButton(this,"hlist",r,true,true, 3); |
---|
75 | |
---|
76 | MythFontProperties fontProp; |
---|
77 | fontProp.face = CreateFont("Arial", 24, QFont::Bold); |
---|
78 | fontProp.color = QColor(Qt::white); |
---|
79 | fontProp.hasShadow = true; |
---|
80 | fontProp.shadowOffset = NormPoint(QPoint(4, 4)); |
---|
81 | fontProp.shadowColor = QColor(Qt::black); |
---|
82 | fontProp.shadowAlpha = 64; |
---|
83 | |
---|
84 | hbuttons->SetFontActive(fontProp); |
---|
85 | |
---|
86 | fontProp.color = Qt::darkGray; |
---|
87 | |
---|
88 | hbuttons->SetFontInactive(fontProp); |
---|
89 | hbuttons->SetSpacing(NormX(10)); |
---|
90 | hbuttons->SetMargin(NormX(6)); |
---|
91 | hbuttons->SetDrawFromBottom(true); |
---|
92 | } |
---|
93 | |
---|
94 | void TestWindow::toggleActive(void) |
---|
95 | { |
---|
96 | focused->SetActive(false); |
---|
97 | focused = (focused == vbuttons) ? hbuttons : vbuttons; |
---|
98 | focused->SetActive(true); |
---|
99 | } |
---|
100 | |
---|
101 | bool TestWindow::keyPressEvent(QKeyEvent *e) |
---|
102 | { |
---|
103 | bool handled = false; |
---|
104 | QStringList actions; |
---|
105 | if (GetMythMainWindow()->TranslateKeyPress("qt", e, actions)) |
---|
106 | { |
---|
107 | for (size_t i = 0; (i < actions.size()) && !handled; i++) |
---|
108 | { |
---|
109 | QString action = actions[i]; |
---|
110 | if (action == "ESCAPE") |
---|
111 | QApplication::exit(); |
---|
112 | else if (action == "SELECT") |
---|
113 | toggleActive(); |
---|
114 | else if (action == "UP") |
---|
115 | { |
---|
116 | if (focused == vbuttons) |
---|
117 | focused->MoveUp(); |
---|
118 | } |
---|
119 | else if (action == "DOWN") |
---|
120 | { |
---|
121 | if (focused == vbuttons) |
---|
122 | focused->MoveDown(); |
---|
123 | } |
---|
124 | else if (action == "LEFT") |
---|
125 | { |
---|
126 | if (focused == hbuttons) |
---|
127 | focused->MoveUp(); |
---|
128 | } |
---|
129 | else if (action == "RIGHT") |
---|
130 | { |
---|
131 | if (focused == hbuttons) |
---|
132 | focused->MoveDown(); |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | return true; |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | #endif /* BTNLISTTEST_CPP */ |
---|