-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcsxwindow.cpp
192 lines (155 loc) · 5.75 KB
/
pcsxwindow.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "pcsxwindow.h"
#include <QPixmap>
#include <QDockWidget>
#include <QScrollArea>
#include <QMenuBar>
#include <QMenu>
#include <QMessageBox>
#include <QSignalMapper>
#include <QSettings>
#include <QCoreApplication>
#include <QSpacerItem>
#include <QDebug>
#include <cstdlib>
#include <unistd.h>
PcsxWindow::PcsxWindow(QWidget *parent) : QMainWindow(parent) {
createMenu();
_screen = new QWidget();
setCentralWidget(_screen);
_vboxLayout = new QVBoxLayout();
_screen->setLayout(_vboxLayout);
addSettings();
_fileManager = new FileManager("data/");
createLabels(_fileManager->getFilesImages());
addSlider();
setMinimumSize(600, 600);
setWindowTitle(tr("PCSX Interface"));
}
void PcsxWindow::createMenu() {
QSettings settings("Pcsx2Interface", "Pcsx2InterfaceSettings");
settings.beginGroup("Options");
bool isFullscreen = settings.value("fullscreen").value<bool>();
bool isNohacks = settings.value("nohacks").value<bool>();
settings.endGroup();
QMenu* file = menuBar()->addMenu("File");
file->addAction("Quit", this, SLOT(close()));
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(saveSettings()));
QMenu *options = menuBar()->addMenu("Settings");
QAction *fullscreen = options->addAction("Fullscreen");
fullscreen->setCheckable(true);
fullscreen->setChecked((isFullscreen) ? true : false);
_actions.push_back(fullscreen);
QAction *nohacks = options->addAction("No hacks");
nohacks->setCheckable(true);
nohacks->setChecked((isNohacks) ? true : false);
_actions.push_back(nohacks);
QSignalMapper* mapper = new QSignalMapper(this);
mapper->setMapping(fullscreen, FULLSCREEN);
mapper->setMapping(nohacks, NOHACK);
connect(fullscreen, SIGNAL(triggered()), mapper, SLOT(map()));
connect(nohacks, SIGNAL(triggered()), mapper, SLOT(map()));
connect(mapper, SIGNAL(mapped(int)), this, SLOT(handleOption(int)));
QMenu* help = menuBar()->addMenu("Help");
help->addAction("About",this,SLOT(about()));
for(unsigned int i = 0; i < _actions.size(); ++i) {
handleOption(i);
}
}
void PcsxWindow::addSettings() {
QHBoxLayout *hlayout = new QHBoxLayout();
_vboxLayout->addLayout(hlayout);
hlayout->addStretch();
_lineEdit = new QLineEdit();
_lineEdit->setPlaceholderText("Ex : Final fantasy X");
_list = new QPushButton();
_list->setIcon(QIcon(":/img/list.png"));
_list->setIconSize(QSize(25,25));
_list->setStyleSheet("QPushButton { background: none; border: none; margin: 0px; padding: 0px; } QPushButton:focus { border: none; outline: none; } ");
_thumbnail = new QPushButton();
_thumbnail->setIcon(QIcon(":/img/thumbnails.png"));
_thumbnail->setIconSize(QSize(25,25));
_thumbnail->setStyleSheet("QPushButton { background: none; border: none; margin: 0px; padding: 0px; } QPushButton:focus { border: none; outline: none; } ");
hlayout->addWidget(_lineEdit);
hlayout->addSpacerItem(new QSpacerItem(300, 25));
hlayout->addWidget(_thumbnail);
hlayout->addSpacerItem(new QSpacerItem(5, 5));
hlayout->addWidget(_list);
hlayout->addStretch();
hlayout->setSpacing(0);
connect(_lineEdit, SIGNAL(textChanged(QString)), this, SLOT(handleLineEdit(QString)));
connect(_list, SIGNAL(clicked()), this, SLOT(handleList()));
connect(_thumbnail, SIGNAL(clicked()), this, SLOT(handleThumbnails()));
}
void PcsxWindow::createLabels(std::vector<std::string> filesImages) {
_gridLayout = new QGridLayout();
_vboxLayout->addLayout(_gridLayout);
unsigned int j = 0, k =0;
for (unsigned int i = 0; i < filesImages.size(); ++i) {
if(i % 4 == 0) {
j++;
k = 0;
}
QPixmap pix(filesImages[i].c_str());
PcsxLabel *label = new PcsxLabel("");
label->setPixmap(pix);
label->setMaximumHeight(400);
label->setScaledContents(true);
_gridLayout->addWidget(label, j, k);
_labels.push_back(label);
k++;
connect(label, SIGNAL(clicked(QString)), this, SLOT(launchGame(QString)));
}
}
void PcsxWindow::addSlider() {
QHBoxLayout *hlayout = new QHBoxLayout();
_vboxLayout->addLayout(hlayout);
_slider = new QSlider(Qt::Horizontal);
_slider->setMinimum(150);
_slider->setMaximum(400);
_slider->setValue(400);
hlayout->addWidget(_slider);
connect(_slider, SIGNAL(valueChanged(int)), this, SLOT(handleLabelSize(int)));
}
void PcsxWindow::handleLabelSize(int size) {
for(unsigned int i = 0; i < _labels.size(); ++i) {
_labels[i]->setMaximumHeight(size);
}
}
void PcsxWindow::handleLineEdit(QString text) {
}
void PcsxWindow::handleThumbnails() {
}
void PcsxWindow::handleList() {
}
void PcsxWindow::handleOption(int option) {
std::string optionName = optionsName[option];
if(_actions[option]->isChecked()) {
_options += optionName;
} else {
std::size_t found = _options.find(optionName);
if (found != std::string::npos) {
_options.replace(found, optionName.size(), "");
}
}
}
void PcsxWindow::launchGame(QString gameName) {
std::string command = "pcsx2 \""+gameName.toStdString()+"\" --nogui "+_options;
qDebug() << command.c_str();
// int pid = fork();
// if (pid==0) {
// system(command.c_str());
// exit(0);
// }
}
void PcsxWindow::about() {
QMessageBox *msg = new QMessageBox();
msg->setText("Author : Vimont Ludovic");
msg->exec();
}
void PcsxWindow::saveSettings() {
QSettings settings("Pcsx2Interface", "Pcsx2InterfaceSettings");
settings.beginGroup("Options");
settings.setValue("fullscreen", (_actions[FULLSCREEN]->isChecked()) ? true : false);
settings.setValue("nohacks", (_actions[NOHACK]->isChecked()) ? true : false);
settings.endGroup();
}