combjs
view gui/gui.cc @ 1:dd02002227a2
- added a few commandline arguments to combjs
- trying to make a gui frontend
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 14 Jul 2011 15:40:20 +0300 |
parents | |
children | 4e8f2bbe8426 |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <QMessageBox>
4 #include <QCloseEvent>
5 #include "gui.h"
6 #include "combjs.h"
8 static std::vector<Joystick> jsvec;
10 MainWindow::MainWindow(QWidget *parent)
11 : QMainWindow(parent)
12 {
13 setupUi(this);
15 int num_js = enum_joysticks(&jsvec);
17 list_js->clear();
18 for(int i=0; i<num_js; i++) {
19 QListWidgetItem *item = new QListWidgetItem(jsvec[i].name.c_str());
20 item->setData(Qt::UserRole, i);
21 item->setToolTip(jsvec[i].dev.c_str());
23 list_js->addItem(item);
24 }
26 connect(list_js, SIGNAL(itemSelectionChanged()), this, SLOT(jslist_select()));
27 }
30 void MainWindow::closeEvent(QCloseEvent *ev)
31 {
32 /*const char *msg_text = "Are you sure you want to quit?\n"
33 "Quitting this application will destroy any virtual joystick devices you created!"
34 "If this wasn't your intention, press cancel and minimize instead of quitting.";
36 if(QMessageBox::question(this, "Quit?", msg_text, QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
37 ev->accept();
38 } else {
39 ev->ignore();
40 }*/
41 ev->accept();
42 }
44 /* slots */
45 void MainWindow::jslist_select()
46 {
47 QList<QListWidgetItem*> sel_list = list_js->selectedItems();
48 QListWidgetItem *item = sel_list.isEmpty() ? 0 : sel_list.first();
50 if(item && jsvec[item->data(Qt::UserRole).toInt()].isvirt) {
51 bn_del_virt->setEnabled(true);
52 } else {
53 bn_del_virt->setEnabled(false);
54 }
55 }