-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtdaswahreschlagerfestmenudialog.cpp
107 lines (90 loc) · 2.74 KB
/
qtdaswahreschlagerfestmenudialog.cpp
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
102
103
104
105
106
#include "qtdaswahreschlagerfestmenudialog.h"
#include <QKeyEvent>
#include <QApplication>
#include <QDesktopWidget>
#include <QTimer>
#ifdef USE_SFML_FOR_JOYSTICK_SUPPORT
#include <SFML/Window/Joystick.hpp>
#endif //USE_SFML_FOR_JOYSTICK_SUPPORT
#include "daswahreschlagerfestmenudialog.h"
#include "qtaboutdialog.h"
#include "qtdaswahreschlagerfestwidget.h"
#include "daswahreschlagerfestwidget.h"
#include "testtimer.h"
#include "ui_qtdaswahreschlagerfestmenudialog.h"
#include "trace.h"
QKeyEvent CreateDown() noexcept { return QKeyEvent(QEvent::KeyPress,Qt::Key_Down,Qt::NoModifier); }
QKeyEvent CreateUp() noexcept { return QKeyEvent(QEvent::KeyPress,Qt::Key_Up,Qt::NoModifier); }
QKeyEvent CreateTab() noexcept { return QKeyEvent(QEvent::KeyPress,Qt::Key_Tab,Qt::NoModifier); }
QKeyEvent CreateEnter() noexcept { return QKeyEvent(QEvent::KeyPress,Qt::Key_Enter,Qt::NoModifier); }
ribi::dws::QtMenuDialog::QtMenuDialog(QWidget *parent) noexcept
: QtHideAndShowDialog(parent),
ui(new Ui::QtDwsMenuDialog),
m_timer_joystick{new QTimer(this)}
{
ui->setupUi(this);
//Timer for checking the joystick input
{
QObject::connect(m_timer_joystick,SIGNAL(timeout()),this,SLOT(OnJoystickCheck()));
m_timer_joystick->setInterval(100);
m_timer_joystick->start();
}
ui->button_start->setFocus();
}
ribi::dws::QtMenuDialog::~QtMenuDialog() noexcept
{
delete ui;
}
void ribi::dws::QtMenuDialog::keyPressEvent(QKeyEvent * e)
{
if (e->key() == Qt::Key_Escape) { close(); }
QtHideAndShowDialog::keyPressEvent(e);
}
void ribi::dws::QtMenuDialog::on_button_start_clicked() noexcept
{
QtDwsWidget d;
Widget w(&d);
d.OnChanged(w);
{
QRect screen = QApplication::desktop()->screenGeometry();
d.move( screen.center() - d.rect().center() );
}
d.setWindowTitle("Das Wahre Schlagerfest");
d.show();
w.Execute();
}
void ribi::dws::QtMenuDialog::on_button_about_clicked() noexcept
{
QtAboutDialog d(MenuDialog().GetAbout());
d.setWindowIcon(windowIcon());
d.setStyleSheet(styleSheet());
ShowChild(&d);
}
void ribi::dws::QtMenuDialog::OnJoystickCheck()
{
#ifdef USE_SFML_FOR_JOYSTICK_SUPPORT
sf::Joystick::update();
const int joystick_index{0};
if (sf::Joystick::isConnected(joystick_index))
{
if (sf::Joystick::hasAxis(joystick_index, sf::Joystick::Y))
{
const double dy{sf::Joystick::getAxisPosition(joystick_index, sf::Joystick::Y)};
if (dy > 50.0) {
this->focusNextChild();
}
if (dy < -50.0) {
this->focusPreviousChild();
}
}
if (sf::Joystick::isButtonPressed(joystick_index,0)) {
auto key = CreateEnter();
keyPressEvent(&key);
}
}
#endif // USE_SFML_FOR_JOYSTICK_SUPPORT
}
void ribi::dws::QtMenuDialog::on_button_quit_clicked() noexcept
{
close();
}