Ticket #197: btnlisttest.cpp

File btnlisttest.cpp, 3.6 KB (added by mfgalizi@…, 15 years ago)

Screen to show lists.

Line 
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
12TestWindow::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
34TestWindow::~TestWindow(void)
35{
36}
37
38void 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
67void TestWindow::setupHList(void)
68{
69
70
71    QRect prect = GetMythMainWindow()->GetUIScreenRect();
72    QRect r(pad, pad, listWidth, listHeight);
73
74    hbuttons = new MythListButton(this,"hlist",r,true,true);
75    hbuttons->SetOrientation(Qt::Horizontal);
76    hbuttons->SetHorizontalItems(3);
77
78    MythFontProperties fontProp;
79    fontProp.face = CreateFont("Arial", 24, QFont::Bold);
80    fontProp.color = QColor(Qt::white);
81    fontProp.hasShadow = true;
82    fontProp.shadowOffset = NormPoint(QPoint(4, 4));
83    fontProp.shadowColor = QColor(Qt::black);
84    fontProp.shadowAlpha = 64;
85
86    hbuttons->SetFontActive(fontProp);
87
88    fontProp.color = Qt::darkGray;
89
90    hbuttons->SetFontInactive(fontProp);
91    hbuttons->SetSpacing(NormX(10));
92    hbuttons->SetMargin(NormX(6));
93    hbuttons->SetDrawFromBottom(true);
94}
95
96void TestWindow::toggleActive(void)
97{
98    focused->SetActive(false);
99    focused = (focused == vbuttons) ? hbuttons : vbuttons;
100    focused->SetActive(true);
101}
102
103bool TestWindow::keyPressEvent(QKeyEvent *e)
104{
105    bool handled = false;
106    QStringList actions;
107    if (GetMythMainWindow()->TranslateKeyPress("qt", e, actions))
108    {
109        for (size_t i = 0; (i < actions.size()) && !handled; i++)
110        {
111            QString action = actions[i];
112            if (action == "ESCAPE")
113                QApplication::exit();
114            else if (action == "SELECT")
115                toggleActive();
116            else if (action == "UP")
117            {
118                if (focused == vbuttons)
119                    focused->MoveUp();
120            }
121            else if (action == "DOWN")
122            {
123                if (focused == vbuttons)
124                    focused->MoveDown();
125            }
126            else if (action == "LEFT")
127            {
128                if (focused == hbuttons)
129                    focused->MoveLeft();
130            }
131            else if (action == "RIGHT")
132            {
133                if (focused == hbuttons)
134                    focused->MoveRight();
135            }
136        }
137    }
138
139    return true;
140}
141
142
143#endif /* BTNLISTTEST_CPP */