combjs

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gui/gui.cc	Thu Jul 14 15:40:20 2011 +0300
     1.3 @@ -0,0 +1,55 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <QMessageBox>
     1.7 +#include <QCloseEvent>
     1.8 +#include "gui.h"
     1.9 +#include "combjs.h"
    1.10 +
    1.11 +static std::vector<Joystick> jsvec;
    1.12 +
    1.13 +MainWindow::MainWindow(QWidget *parent)
    1.14 +	: QMainWindow(parent)
    1.15 +{
    1.16 +	setupUi(this);
    1.17 +
    1.18 +	int num_js = enum_joysticks(&jsvec);
    1.19 +
    1.20 +	list_js->clear();
    1.21 +	for(int i=0; i<num_js; i++) {
    1.22 +		QListWidgetItem *item = new QListWidgetItem(jsvec[i].name.c_str());
    1.23 +		item->setData(Qt::UserRole, i);
    1.24 +		item->setToolTip(jsvec[i].dev.c_str());
    1.25 +
    1.26 +		list_js->addItem(item);
    1.27 +	}
    1.28 +
    1.29 +	connect(list_js, SIGNAL(itemSelectionChanged()), this, SLOT(jslist_select()));
    1.30 +}
    1.31 +
    1.32 +
    1.33 +void MainWindow::closeEvent(QCloseEvent *ev)
    1.34 +{
    1.35 +	/*const char *msg_text = "Are you sure you want to quit?\n"
    1.36 +		"Quitting this application will destroy any virtual joystick devices you created!"
    1.37 +		"If this wasn't your intention, press cancel and minimize instead of quitting.";
    1.38 +
    1.39 +	if(QMessageBox::question(this, "Quit?", msg_text, QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
    1.40 +		ev->accept();
    1.41 +	} else {
    1.42 +		ev->ignore();
    1.43 +	}*/
    1.44 +	ev->accept();
    1.45 +}
    1.46 +
    1.47 +/* slots */
    1.48 +void MainWindow::jslist_select()
    1.49 +{
    1.50 +	QList<QListWidgetItem*> sel_list = list_js->selectedItems();
    1.51 +	QListWidgetItem *item = sel_list.isEmpty() ? 0 : sel_list.first();
    1.52 +
    1.53 +	if(item && jsvec[item->data(Qt::UserRole).toInt()].isvirt) {
    1.54 +		bn_del_virt->setEnabled(true);
    1.55 +	} else {
    1.56 +		bn_del_virt->setEnabled(false);
    1.57 +	}
    1.58 +}