combjs
changeset 2:4e8f2bbe8426 tip
doing the gui
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 15 Jul 2011 06:54:32 +0300 |
parents | dd02002227a2 |
children | |
files | gui/gui.cc gui/gui.h gui/main.ui |
diffstat | 3 files changed, 329 insertions(+), 83 deletions(-) [+] |
line diff
1.1 --- a/gui/gui.cc Thu Jul 14 15:40:20 2011 +0300 1.2 +++ b/gui/gui.cc Fri Jul 15 06:54:32 2011 +0300 1.3 @@ -5,6 +5,10 @@ 1.4 #include "gui.h" 1.5 #include "combjs.h" 1.6 1.7 +static void add_to_list(int jsidx, QListWidget *list); 1.8 +static QListWidgetItem *get_selected(QListWidget *list); 1.9 +static int find_item(QListWidget *list, int jsidx); 1.10 + 1.11 static std::vector<Joystick> jsvec; 1.12 1.13 MainWindow::MainWindow(QWidget *parent) 1.14 @@ -16,14 +20,16 @@ 1.15 1.16 list_js->clear(); 1.17 for(int i=0; i<num_js; i++) { 1.18 - QListWidgetItem *item = new QListWidgetItem(jsvec[i].name.c_str()); 1.19 - item->setData(Qt::UserRole, i); 1.20 - item->setToolTip(jsvec[i].dev.c_str()); 1.21 - 1.22 - list_js->addItem(item); 1.23 + add_to_list(i, list_js); 1.24 } 1.25 1.26 connect(list_js, SIGNAL(itemSelectionChanged()), this, SLOT(jslist_select())); 1.27 + connect(list_newdev, SIGNAL(itemSelectionChanged()), this, SLOT(clist_select())); 1.28 + 1.29 + connect(action_addjs, SIGNAL(triggered()), this, SLOT(add_js())); 1.30 + connect(action_remove, SIGNAL(triggered()), this, SLOT(remove_js())); 1.31 + connect(action_combine, SIGNAL(triggered()), this, SLOT(start_virt())); 1.32 + connect(action_delete, SIGNAL(triggered()), this, SLOT(stop_virt())); 1.33 } 1.34 1.35 1.36 @@ -44,12 +50,97 @@ 1.37 /* slots */ 1.38 void MainWindow::jslist_select() 1.39 { 1.40 - QList<QListWidgetItem*> sel_list = list_js->selectedItems(); 1.41 - QListWidgetItem *item = sel_list.isEmpty() ? 0 : sel_list.first(); 1.42 + QListWidgetItem *item = get_selected(list_js); 1.43 1.44 - if(item && jsvec[item->data(Qt::UserRole).toInt()].isvirt) { 1.45 - bn_del_virt->setEnabled(true); 1.46 + if(item) { 1.47 + int idx = item->data(Qt::UserRole).toInt(); 1.48 + 1.49 + bn_add->setEnabled(true); 1.50 + if(jsvec[idx].isvirt) { 1.51 + bn_del_virt->setEnabled(true); 1.52 + } else { 1.53 + bn_del_virt->setEnabled(false); 1.54 + } 1.55 + 1.56 + lb_name->setText(jsvec[idx].name.c_str()); 1.57 + lb_dev->setText(jsvec[idx].dev.c_str()); 1.58 + lb_axes->setText(QString::number(jsvec[idx].num_axes)); 1.59 + lb_buttons->setText(QString::number(jsvec[idx].num_bn)); 1.60 + 1.61 } else { 1.62 + bn_add->setEnabled(false); 1.63 bn_del_virt->setEnabled(false); 1.64 + 1.65 + lb_name->setText(""); 1.66 + lb_dev->setText(""); 1.67 + lb_axes->setText(""); 1.68 + lb_buttons->setText(""); 1.69 } 1.70 } 1.71 + 1.72 +void MainWindow::clist_select() 1.73 +{ 1.74 + QListWidgetItem *item = get_selected(list_newdev); 1.75 + 1.76 + bn_remove->setEnabled(item != 0); 1.77 +} 1.78 + 1.79 +void MainWindow::add_js() 1.80 +{ 1.81 + QListWidgetItem *item = get_selected(list_js); 1.82 + if(!item) { 1.83 + return; 1.84 + } 1.85 + 1.86 + int idx = item->data(Qt::UserRole).toInt(); 1.87 + if(find_item(list_newdev, idx) == -1) { 1.88 + add_to_list(idx, list_newdev); 1.89 + bn_create->setEnabled(true); 1.90 + } 1.91 +} 1.92 + 1.93 +void MainWindow::remove_js() 1.94 +{ 1.95 + QListWidgetItem *item = get_selected(list_newdev); 1.96 + if(item) { 1.97 + list_newdev->takeItem(list_newdev->row(item)); 1.98 + delete item; 1.99 + 1.100 + if(list_newdev->count() == 0) { 1.101 + bn_create->setEnabled(false); 1.102 + } 1.103 + } 1.104 +} 1.105 + 1.106 +void MainWindow::start_virt() 1.107 +{ 1.108 +} 1.109 + 1.110 +void MainWindow::stop_virt() 1.111 +{ 1.112 +} 1.113 + 1.114 +static void add_to_list(int jsidx, QListWidget *list) 1.115 +{ 1.116 + QListWidgetItem *item = new QListWidgetItem(jsvec[jsidx].name.c_str()); 1.117 + item->setData(Qt::UserRole, jsidx); 1.118 + item->setToolTip(jsvec[jsidx].dev.c_str()); 1.119 + list->addItem(item); 1.120 +} 1.121 + 1.122 +static QListWidgetItem *get_selected(QListWidget *list) 1.123 +{ 1.124 + QList<QListWidgetItem*> sel_list = list->selectedItems(); 1.125 + return sel_list.isEmpty() ? 0 : sel_list.first(); 1.126 +} 1.127 + 1.128 +static int find_item(QListWidget *list, int jsidx) 1.129 +{ 1.130 + int num = list->count(); 1.131 + for(int i=0; i<num; i++) { 1.132 + if(list->item(i)->data(Qt::UserRole).toInt() == jsidx) { 1.133 + return i; 1.134 + } 1.135 + } 1.136 + return -1; 1.137 +}
2.1 --- a/gui/gui.h Thu Jul 14 15:40:20 2011 +0300 2.2 +++ b/gui/gui.h Fri Jul 15 06:54:32 2011 +0300 2.3 @@ -7,6 +7,13 @@ 2.4 Q_OBJECT 2.5 private slots: 2.6 void jslist_select(); 2.7 + void clist_select(); 2.8 + 2.9 + void add_js(); 2.10 + void remove_js(); 2.11 + 2.12 + void start_virt(); 2.13 + void stop_virt(); 2.14 2.15 private: 2.16 void closeEvent(QCloseEvent *ev);
3.1 --- a/gui/main.ui Thu Jul 14 15:40:20 2011 +0300 3.2 +++ b/gui/main.ui Fri Jul 15 06:54:32 2011 +0300 3.3 @@ -14,9 +14,9 @@ 3.4 <string>Joystick Combiner</string> 3.5 </property> 3.6 <widget class="QWidget" name="centralwidget"> 3.7 - <layout class="QVBoxLayout" name="verticalLayout_4"> 3.8 + <layout class="QVBoxLayout" name="verticalLayout_6"> 3.9 <item> 3.10 - <widget class="QSplitter" name="splitter_3"> 3.11 + <widget class="QSplitter" name="splitter"> 3.12 <property name="orientation"> 3.13 <enum>Qt::Horizontal</enum> 3.14 </property> 3.15 @@ -31,17 +31,30 @@ 3.16 <layout class="QVBoxLayout" name="verticalLayout_3"> 3.17 <item> 3.18 <widget class="QListWidget" name="list_js"> 3.19 + <property name="showDropIndicator" stdset="0"> 3.20 + <bool>false</bool> 3.21 + </property> 3.22 <property name="dragEnabled"> 3.23 - <bool>true</bool> 3.24 + <bool>false</bool> 3.25 </property> 3.26 <property name="dragDropMode"> 3.27 - <enum>QAbstractItemView::DragDrop</enum> 3.28 + <enum>QAbstractItemView::NoDragDrop</enum> 3.29 </property> 3.30 </widget> 3.31 </item> 3.32 <item> 3.33 <layout class="QHBoxLayout" name="horizontalLayout_3"> 3.34 <item> 3.35 + <widget class="QPushButton" name="bn_add"> 3.36 + <property name="enabled"> 3.37 + <bool>false</bool> 3.38 + </property> 3.39 + <property name="text"> 3.40 + <string>Add joystick</string> 3.41 + </property> 3.42 + </widget> 3.43 + </item> 3.44 + <item> 3.45 <spacer name="horizontalSpacer_2"> 3.46 <property name="orientation"> 3.47 <enum>Qt::Horizontal</enum> 3.48 @@ -83,12 +96,16 @@ 3.49 </widget> 3.50 </item> 3.51 <item> 3.52 - <widget class="QLineEdit" name="tx_devname"/> 3.53 + <widget class="QLineEdit" name="tx_devname"> 3.54 + <property name="text"> 3.55 + <string>combjs virtual joystick</string> 3.56 + </property> 3.57 + </widget> 3.58 </item> 3.59 </layout> 3.60 </item> 3.61 <item> 3.62 - <widget class="DropList" name="list_newdev"> 3.63 + <widget class="QListWidget" name="list_newdev"> 3.64 <property name="acceptDrops"> 3.65 <bool>true</bool> 3.66 </property> 3.67 @@ -96,13 +113,13 @@ 3.68 <bool>true</bool> 3.69 </property> 3.70 <property name="dragDropOverwriteMode"> 3.71 - <bool>true</bool> 3.72 + <bool>false</bool> 3.73 </property> 3.74 <property name="dragDropMode"> 3.75 - <enum>QAbstractItemView::DragDrop</enum> 3.76 + <enum>QAbstractItemView::InternalMove</enum> 3.77 </property> 3.78 <property name="defaultDropAction"> 3.79 - <enum>Qt::CopyAction</enum> 3.80 + <enum>Qt::MoveAction</enum> 3.81 </property> 3.82 <property name="alternatingRowColors"> 3.83 <bool>false</bool> 3.84 @@ -115,7 +132,7 @@ 3.85 <item> 3.86 <layout class="QHBoxLayout" name="horizontalLayout_2"> 3.87 <item> 3.88 - <widget class="QPushButton" name="pushButton_3"> 3.89 + <widget class="QPushButton" name="bn_create"> 3.90 <property name="enabled"> 3.91 <bool>false</bool> 3.92 </property> 3.93 @@ -138,7 +155,7 @@ 3.94 </spacer> 3.95 </item> 3.96 <item> 3.97 - <widget class="QPushButton" name="pushButton_2"> 3.98 + <widget class="QPushButton" name="bn_remove"> 3.99 <property name="enabled"> 3.100 <bool>false</bool> 3.101 </property> 3.102 @@ -152,62 +169,125 @@ 3.103 </layout> 3.104 </widget> 3.105 </widget> 3.106 - <widget class="QSplitter" name="splitter"> 3.107 - <property name="orientation"> 3.108 - <enum>Qt::Vertical</enum> 3.109 - </property> 3.110 - <widget class="QGroupBox" name="groupBox_3"> 3.111 - <property name="sizePolicy"> 3.112 - <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> 3.113 - <horstretch>0</horstretch> 3.114 - <verstretch>0</verstretch> 3.115 - </sizepolicy> 3.116 - </property> 3.117 - <property name="minimumSize"> 3.118 - <size> 3.119 - <width>0</width> 3.120 - <height>347</height> 3.121 - </size> 3.122 - </property> 3.123 - <property name="title"> 3.124 - <string>Joystick information</string> 3.125 - </property> 3.126 - <layout class="QVBoxLayout" name="verticalLayout"> 3.127 - <item> 3.128 - <widget class="QListWidget" name="list_joyinfo"/> 3.129 - </item> 3.130 - </layout> 3.131 - </widget> 3.132 - <widget class="QGroupBox" name="groupBox_4"> 3.133 - <property name="sizePolicy"> 3.134 - <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> 3.135 - <horstretch>0</horstretch> 3.136 - <verstretch>0</verstretch> 3.137 - </sizepolicy> 3.138 - </property> 3.139 - <property name="title"> 3.140 - <string>Joystick test</string> 3.141 - </property> 3.142 - <layout class="QVBoxLayout" name="verticalLayout_5"> 3.143 - <item> 3.144 - <widget class="QScrollArea" name="test_area"> 3.145 - <property name="widgetResizable"> 3.146 - <bool>true</bool> 3.147 - </property> 3.148 - <widget class="QWidget" name="scrollAreaWidgetContents"> 3.149 - <property name="geometry"> 3.150 - <rect> 3.151 - <x>0</x> 3.152 - <y>0</y> 3.153 - <width>360</width> 3.154 - <height>158</height> 3.155 - </rect> 3.156 - </property> 3.157 - </widget> 3.158 - </widget> 3.159 - </item> 3.160 - </layout> 3.161 - </widget> 3.162 + <widget class="QWidget" name=""> 3.163 + <layout class="QVBoxLayout" name="verticalLayout_4"> 3.164 + <item> 3.165 + <widget class="QGroupBox" name="groupBox_3"> 3.166 + <property name="sizePolicy"> 3.167 + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> 3.168 + <horstretch>0</horstretch> 3.169 + <verstretch>0</verstretch> 3.170 + </sizepolicy> 3.171 + </property> 3.172 + <property name="minimumSize"> 3.173 + <size> 3.174 + <width>0</width> 3.175 + <height>0</height> 3.176 + </size> 3.177 + </property> 3.178 + <property name="title"> 3.179 + <string>Joystick information</string> 3.180 + </property> 3.181 + <layout class="QVBoxLayout" name="verticalLayout"> 3.182 + <item> 3.183 + <layout class="QFormLayout" name="formLayout"> 3.184 + <property name="fieldGrowthPolicy"> 3.185 + <enum>QFormLayout::ExpandingFieldsGrow</enum> 3.186 + </property> 3.187 + <item row="0" column="0"> 3.188 + <widget class="QLabel" name="label_2"> 3.189 + <property name="text"> 3.190 + <string>Name:</string> 3.191 + </property> 3.192 + </widget> 3.193 + </item> 3.194 + <item row="0" column="1"> 3.195 + <widget class="QLabel" name="lb_name"> 3.196 + <property name="text"> 3.197 + <string/> 3.198 + </property> 3.199 + </widget> 3.200 + </item> 3.201 + <item row="1" column="0"> 3.202 + <widget class="QLabel" name="label_3"> 3.203 + <property name="text"> 3.204 + <string>Device:</string> 3.205 + </property> 3.206 + </widget> 3.207 + </item> 3.208 + <item row="1" column="1"> 3.209 + <widget class="QLabel" name="lb_dev"> 3.210 + <property name="text"> 3.211 + <string/> 3.212 + </property> 3.213 + </widget> 3.214 + </item> 3.215 + <item row="2" column="0"> 3.216 + <widget class="QLabel" name="label_5"> 3.217 + <property name="text"> 3.218 + <string>Axes:</string> 3.219 + </property> 3.220 + </widget> 3.221 + </item> 3.222 + <item row="2" column="1"> 3.223 + <widget class="QLabel" name="lb_axes"> 3.224 + <property name="text"> 3.225 + <string/> 3.226 + </property> 3.227 + </widget> 3.228 + </item> 3.229 + <item row="3" column="0"> 3.230 + <widget class="QLabel" name="label_6"> 3.231 + <property name="text"> 3.232 + <string>Buttons:</string> 3.233 + </property> 3.234 + </widget> 3.235 + </item> 3.236 + <item row="3" column="1"> 3.237 + <widget class="QLabel" name="lb_buttons"> 3.238 + <property name="text"> 3.239 + <string/> 3.240 + </property> 3.241 + </widget> 3.242 + </item> 3.243 + </layout> 3.244 + </item> 3.245 + </layout> 3.246 + </widget> 3.247 + </item> 3.248 + <item> 3.249 + <widget class="QGroupBox" name="groupBox_4"> 3.250 + <property name="sizePolicy"> 3.251 + <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> 3.252 + <horstretch>0</horstretch> 3.253 + <verstretch>0</verstretch> 3.254 + </sizepolicy> 3.255 + </property> 3.256 + <property name="title"> 3.257 + <string>Joystick test</string> 3.258 + </property> 3.259 + <layout class="QVBoxLayout" name="verticalLayout_5"> 3.260 + <item> 3.261 + <widget class="QScrollArea" name="test_area"> 3.262 + <property name="widgetResizable"> 3.263 + <bool>true</bool> 3.264 + </property> 3.265 + <widget class="QWidget" name="scrollAreaWidgetContents"> 3.266 + <property name="geometry"> 3.267 + <rect> 3.268 + <x>0</x> 3.269 + <y>0</y> 3.270 + <width>321</width> 3.271 + <height>394</height> 3.272 + </rect> 3.273 + </property> 3.274 + </widget> 3.275 + </widget> 3.276 + </item> 3.277 + </layout> 3.278 + </widget> 3.279 + </item> 3.280 + </layout> 3.281 </widget> 3.282 </widget> 3.283 </item> 3.284 @@ -226,6 +306,7 @@ 3.285 <property name="title"> 3.286 <string>Joystick</string> 3.287 </property> 3.288 + <addaction name="action_addjs"/> 3.289 <addaction name="action_combine"/> 3.290 <addaction name="action_delete"/> 3.291 <addaction name="action_quit"/> 3.292 @@ -266,14 +347,17 @@ 3.293 <string>Quit</string> 3.294 </property> 3.295 </action> 3.296 + <action name="action_addjs"> 3.297 + <property name="text"> 3.298 + <string>Add joystick</string> 3.299 + </property> 3.300 + </action> 3.301 + <action name="action_remove"> 3.302 + <property name="text"> 3.303 + <string>Remove</string> 3.304 + </property> 3.305 + </action> 3.306 </widget> 3.307 - <customwidgets> 3.308 - <customwidget> 3.309 - <class>DropList</class> 3.310 - <extends>QListWidget</extends> 3.311 - <header>droplist.h</header> 3.312 - </customwidget> 3.313 - </customwidgets> 3.314 <resources/> 3.315 <connections> 3.316 <connection> 3.317 @@ -292,5 +376,69 @@ 3.318 </hint> 3.319 </hints> 3.320 </connection> 3.321 + <connection> 3.322 + <sender>bn_add</sender> 3.323 + <signal>clicked()</signal> 3.324 + <receiver>action_addjs</receiver> 3.325 + <slot>trigger()</slot> 3.326 + <hints> 3.327 + <hint type="sourcelabel"> 3.328 + <x>63</x> 3.329 + <y>267</y> 3.330 + </hint> 3.331 + <hint type="destinationlabel"> 3.332 + <x>-1</x> 3.333 + <y>-1</y> 3.334 + </hint> 3.335 + </hints> 3.336 + </connection> 3.337 + <connection> 3.338 + <sender>bn_create</sender> 3.339 + <signal>clicked()</signal> 3.340 + <receiver>action_combine</receiver> 3.341 + <slot>trigger()</slot> 3.342 + <hints> 3.343 + <hint type="sourcelabel"> 3.344 + <x>58</x> 3.345 + <y>559</y> 3.346 + </hint> 3.347 + <hint type="destinationlabel"> 3.348 + <x>-1</x> 3.349 + <y>-1</y> 3.350 + </hint> 3.351 + </hints> 3.352 + </connection> 3.353 + <connection> 3.354 + <sender>bn_remove</sender> 3.355 + <signal>clicked()</signal> 3.356 + <receiver>action_remove</receiver> 3.357 + <slot>trigger()</slot> 3.358 + <hints> 3.359 + <hint type="sourcelabel"> 3.360 + <x>345</x> 3.361 + <y>559</y> 3.362 + </hint> 3.363 + <hint type="destinationlabel"> 3.364 + <x>-1</x> 3.365 + <y>-1</y> 3.366 + </hint> 3.367 + </hints> 3.368 + </connection> 3.369 + <connection> 3.370 + <sender>bn_del_virt</sender> 3.371 + <signal>clicked()</signal> 3.372 + <receiver>action_delete</receiver> 3.373 + <slot>trigger()</slot> 3.374 + <hints> 3.375 + <hint type="sourcelabel"> 3.376 + <x>315</x> 3.377 + <y>267</y> 3.378 + </hint> 3.379 + <hint type="destinationlabel"> 3.380 + <x>-1</x> 3.381 + <y>-1</y> 3.382 + </hint> 3.383 + </hints> 3.384 + </connection> 3.385 </connections> 3.386 </ui>