1394 } |
1394 } |
1395 } |
1395 } |
1396 |
1396 |
1397 return retval; |
1397 return retval; |
1398 } |
1398 } |
1399 /* |
1399 |
1400 * Three Mouse events(press, move and release) are needed to select the radio button, |
1400 // Returns row index based on mouse event handle and coordinates |
1401 * when the user clicks(press event) on tableItem and release event is also |
1401 int getRow(int widgetHandle, int x, int y) { |
1402 * happened without moving away(move event) from that time |
1402 int row = -1; |
1403 */ |
1403 if (widgetHandle == handle) { |
|
1404 // User has pressed on a TableItem |
|
1405 row = OS.QTableView_rowAt(topHandle, y); |
|
1406 } else { |
|
1407 // User has pressed on a radio button (the coordinates are |
|
1408 // relative to the button, not the Table) |
|
1409 Point mapped = OS.QWidget_mapTo(widgetHandle, handle, x, y); |
|
1410 row = OS.QTableView_rowAt(topHandle, mapped.y); |
|
1411 } |
|
1412 return row; |
|
1413 } |
|
1414 |
1404 boolean qt_event_mouseButtonPress_pp(int widgetHandle, int button, |
1415 boolean qt_event_mouseButtonPress_pp(int widgetHandle, int button, |
1405 int x, int y, int state, int buttons) { |
1416 int x, int y, int state, int buttons) { |
1406 |
1417 |
1407 if(widgetHandle == handle && (style & SWT.SINGLE) != 0 && (style & SWT.RADIO) != 0){ |
1418 if (button == OS.QT_LEFTBUTTON && |
|
1419 (style & SWT.SINGLE) != 0 && (style & SWT.RADIO) != 0) { |
1408 |
1420 |
1409 int itemHandle = OS.QTableWidget_itemAt(topHandle, x, y); |
1421 int row = getRow(widgetHandle, x, y); |
1410 |
1422 |
1411 if (itemHandle != 0) { |
1423 if (row != -1 && row != OS.QTableWidget_currentRow(topHandle)) { |
1412 oldIndex = OS.QTableWidget_row(topHandle, itemHandle); |
1424 apiSelection = true; |
1413 } |
1425 mouseSelection = true; |
1414 mouseSelection = true; |
1426 OS.QTableWidget_setCurrentCell(topHandle, row, 1); |
1415 } |
1427 apiSelection = false; |
|
1428 } |
|
1429 } |
|
1430 |
1416 return super.qt_event_mouseButtonPress_pp(widgetHandle, button, x, y, state, buttons); |
1431 return super.qt_event_mouseButtonPress_pp(widgetHandle, button, x, y, state, buttons); |
1417 } |
1432 } |
|
1433 |
|
1434 boolean qt_event_mouseButtonRelease_pp ( int widgetHandle, int button, int x, int y, int state, int buttons ) { |
|
1435 // Update the radio button manually in case of SWT.RADIO Table. |
|
1436 // In such a Table we have manually added QRadioButtons to QTableWidget |
|
1437 // cells, so that table selection would not happen automatically |
|
1438 if (button == OS.QT_LEFTBUTTON && |
|
1439 (style & SWT.SINGLE) != 0 && (style & SWT.RADIO) != 0) { |
|
1440 int row = getRow(widgetHandle, x, y); |
1418 |
1441 |
1419 boolean qt_event_mouseButtonRelease_pp(int widgetHandle, int button, |
1442 // Update selection if the row is valid |
1420 int x, int y, int state, int buttons) { |
1443 if (row != -1) { |
1421 |
1444 TableItem item = _getItem(row); |
1422 if(widgetHandle == handle && mouseSelection && (style & SWT.SINGLE) != 0 && (style & SWT.RADIO) != 0){ |
1445 OS.QAbstractButton_setChecked(item.radioButtonHandle, true); |
1423 // there is a chance that if we click on radio button, oldIndex is not going to update |
1446 if (mouseSelection) { |
1424 // in the mouseButtonPress. |
|
1425 if(oldIndex != -1){ |
|
1426 OS.QAbstractButton_setChecked(items[oldIndex].radioButtonHandle, true); |
|
1427 sendSelectionEvent(); |
|
1428 } else if(currentItem != null){ |
|
1429 Rectangle rect = OS.QTableWidget_visualItemRect(topHandle, currentItem.topHandle()); |
|
1430 if((rect.y <= y) && (y <= (rect.y+rect.height)) && (x<=rect.x+rect.width)){ |
|
1431 OS.QAbstractButton_setChecked(currentItem.radioButtonHandle, true); |
|
1432 sendSelectionEvent(); |
1447 sendSelectionEvent(); |
1433 } |
|
1434 } |
|
1435 mouseSelection = false; |
|
1436 oldIndex = -1; |
|
1437 } |
|
1438 return super.qt_event_mouseButtonRelease_pp(widgetHandle, button, x, y, state, buttons); |
|
1439 } |
|
1440 |
|
1441 boolean qt_event_mouseMove(int widgetHandle, int button, int x, int y, |
|
1442 int state, int buttons) { |
|
1443 if( mouseSelection && widgetHandle == handle && (style & SWT.SINGLE) != 0 && (style & SWT.RADIO) != 0){ |
|
1444 int itemHandle = OS.QTableWidget_itemAt(topHandle, x, y); |
|
1445 int index = -1; |
|
1446 if (itemHandle != 0) { |
|
1447 index = OS.QTableWidget_row(topHandle, itemHandle); |
|
1448 } |
|
1449 Rectangle rect = OS.QTableWidget_visualItemRect(topHandle, currentItem.topHandle()); |
|
1450 if(index != oldIndex){ |
|
1451 if (!((rect.y <= y) && (y <= (rect.y+rect.height)) &&(x<=rect.x+rect.width))){ |
|
1452 mouseSelection = false; |
|
1453 oldIndex = -1; |
|
1454 } |
|
1455 } else if(index == -1){ |
|
1456 if (!((rect.y <= y) && (y <= (rect.y+rect.height)) && (x<rect.x+rect.width))){ |
|
1457 mouseSelection = false; |
1448 mouseSelection = false; |
1458 } |
1449 } |
1459 } |
1450 } |
1460 } |
1451 } |
1461 return super.qt_event_mouseMove(widgetHandle, button, x, y, state, buttons); |
1452 |
1462 } |
1453 return super.qt_event_mouseButtonRelease_pp(widgetHandle, button, x, y, state, buttons); |
1463 |
|
1464 void qt_signal_released() |
|
1465 { |
|
1466 sendSelectionEvent(); |
|
1467 } |
1454 } |
1468 |
1455 |
1469 void qt_signal_table_cellActivated(int row, int column) |
1456 void qt_signal_table_cellActivated(int row, int column) |
1470 { |
1457 { |
1471 Event event = new Event(); |
1458 Event event = new Event(); |