# HG changeset patch # User John Tsiombikas # Date 1310702072 -10800 # Node ID 4e8f2bbe8426d59fb448bf56b44486acfc4b48d9 # Parent dd02002227a2c40ece5a94d70b0e7e2307b964d1 doing the gui diff -r dd02002227a2 -r 4e8f2bbe8426 gui/gui.cc --- a/gui/gui.cc Thu Jul 14 15:40:20 2011 +0300 +++ b/gui/gui.cc Fri Jul 15 06:54:32 2011 +0300 @@ -5,6 +5,10 @@ #include "gui.h" #include "combjs.h" +static void add_to_list(int jsidx, QListWidget *list); +static QListWidgetItem *get_selected(QListWidget *list); +static int find_item(QListWidget *list, int jsidx); + static std::vector jsvec; MainWindow::MainWindow(QWidget *parent) @@ -16,14 +20,16 @@ list_js->clear(); for(int i=0; isetData(Qt::UserRole, i); - item->setToolTip(jsvec[i].dev.c_str()); - - list_js->addItem(item); + add_to_list(i, list_js); } connect(list_js, SIGNAL(itemSelectionChanged()), this, SLOT(jslist_select())); + connect(list_newdev, SIGNAL(itemSelectionChanged()), this, SLOT(clist_select())); + + connect(action_addjs, SIGNAL(triggered()), this, SLOT(add_js())); + connect(action_remove, SIGNAL(triggered()), this, SLOT(remove_js())); + connect(action_combine, SIGNAL(triggered()), this, SLOT(start_virt())); + connect(action_delete, SIGNAL(triggered()), this, SLOT(stop_virt())); } @@ -44,12 +50,97 @@ /* slots */ void MainWindow::jslist_select() { - QList sel_list = list_js->selectedItems(); - QListWidgetItem *item = sel_list.isEmpty() ? 0 : sel_list.first(); + QListWidgetItem *item = get_selected(list_js); - if(item && jsvec[item->data(Qt::UserRole).toInt()].isvirt) { - bn_del_virt->setEnabled(true); + if(item) { + int idx = item->data(Qt::UserRole).toInt(); + + bn_add->setEnabled(true); + if(jsvec[idx].isvirt) { + bn_del_virt->setEnabled(true); + } else { + bn_del_virt->setEnabled(false); + } + + lb_name->setText(jsvec[idx].name.c_str()); + lb_dev->setText(jsvec[idx].dev.c_str()); + lb_axes->setText(QString::number(jsvec[idx].num_axes)); + lb_buttons->setText(QString::number(jsvec[idx].num_bn)); + } else { + bn_add->setEnabled(false); bn_del_virt->setEnabled(false); + + lb_name->setText(""); + lb_dev->setText(""); + lb_axes->setText(""); + lb_buttons->setText(""); } } + +void MainWindow::clist_select() +{ + QListWidgetItem *item = get_selected(list_newdev); + + bn_remove->setEnabled(item != 0); +} + +void MainWindow::add_js() +{ + QListWidgetItem *item = get_selected(list_js); + if(!item) { + return; + } + + int idx = item->data(Qt::UserRole).toInt(); + if(find_item(list_newdev, idx) == -1) { + add_to_list(idx, list_newdev); + bn_create->setEnabled(true); + } +} + +void MainWindow::remove_js() +{ + QListWidgetItem *item = get_selected(list_newdev); + if(item) { + list_newdev->takeItem(list_newdev->row(item)); + delete item; + + if(list_newdev->count() == 0) { + bn_create->setEnabled(false); + } + } +} + +void MainWindow::start_virt() +{ +} + +void MainWindow::stop_virt() +{ +} + +static void add_to_list(int jsidx, QListWidget *list) +{ + QListWidgetItem *item = new QListWidgetItem(jsvec[jsidx].name.c_str()); + item->setData(Qt::UserRole, jsidx); + item->setToolTip(jsvec[jsidx].dev.c_str()); + list->addItem(item); +} + +static QListWidgetItem *get_selected(QListWidget *list) +{ + QList sel_list = list->selectedItems(); + return sel_list.isEmpty() ? 0 : sel_list.first(); +} + +static int find_item(QListWidget *list, int jsidx) +{ + int num = list->count(); + for(int i=0; iitem(i)->data(Qt::UserRole).toInt() == jsidx) { + return i; + } + } + return -1; +} diff -r dd02002227a2 -r 4e8f2bbe8426 gui/gui.h --- a/gui/gui.h Thu Jul 14 15:40:20 2011 +0300 +++ b/gui/gui.h Fri Jul 15 06:54:32 2011 +0300 @@ -7,6 +7,13 @@ Q_OBJECT private slots: void jslist_select(); + void clist_select(); + + void add_js(); + void remove_js(); + + void start_virt(); + void stop_virt(); private: void closeEvent(QCloseEvent *ev); diff -r dd02002227a2 -r 4e8f2bbe8426 gui/main.ui --- a/gui/main.ui Thu Jul 14 15:40:20 2011 +0300 +++ b/gui/main.ui Fri Jul 15 06:54:32 2011 +0300 @@ -14,9 +14,9 @@ Joystick Combiner - + - + Qt::Horizontal @@ -31,17 +31,30 @@ + + false + - true + false - QAbstractItemView::DragDrop + QAbstractItemView::NoDragDrop + + + false + + + Add joystick + + + + Qt::Horizontal @@ -83,12 +96,16 @@ - + + + combjs virtual joystick + + - + true @@ -96,13 +113,13 @@ true - true + false - QAbstractItemView::DragDrop + QAbstractItemView::InternalMove - Qt::CopyAction + Qt::MoveAction false @@ -115,7 +132,7 @@ - + false @@ -138,7 +155,7 @@ - + false @@ -152,62 +169,125 @@ - - - Qt::Vertical - - - - - 0 - 0 - - - - - 0 - 347 - - - - Joystick information - - - - - - - - - - - 0 - 0 - - - - Joystick test - - - - - - true - - - - - 0 - 0 - 360 - 158 - - - - - - - + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Joystick information + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Name: + + + + + + + + + + + + + + Device: + + + + + + + + + + + + + + Axes: + + + + + + + + + + + + + + Buttons: + + + + + + + + + + + + + + + + + + + + 0 + 0 + + + + Joystick test + + + + + + true + + + + + 0 + 0 + 321 + 394 + + + + + + + + + @@ -226,6 +306,7 @@ Joystick + @@ -266,14 +347,17 @@ Quit + + + Add joystick + + + + + Remove + + - - - DropList - QListWidget -
droplist.h
-
-
@@ -292,5 +376,69 @@ + + bn_add + clicked() + action_addjs + trigger() + + + 63 + 267 + + + -1 + -1 + + + + + bn_create + clicked() + action_combine + trigger() + + + 58 + 559 + + + -1 + -1 + + + + + bn_remove + clicked() + action_remove + trigger() + + + 345 + 559 + + + -1 + -1 + + + + + bn_del_virt + clicked() + action_delete + trigger() + + + 315 + 267 + + + -1 + -1 + + +