diff --git a/MainWindow.cpp b/MainWindow.cpp index 71b7e48..fa9e2b2 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -188,15 +188,6 @@ void MainWindow::handlePaintItemSelected(QListWidgetItem* item) currentSelectedItem = item; } -void MainWindow::handleMappingItemSelected(const QModelIndex &index) -{ - if (index.isValid()) { - if (index.column() == MM::HideColumn) { - mappingListModel->setVisibility(index); - } - } -} - void MainWindow::handlePaintChanged(Paint::ptr paint) { // Change currently selected item. uid curMappingId = getCurrentMappingId(); @@ -1850,7 +1841,8 @@ void MainWindow::createMappingContextMenu() outputWindow->setContextMenuPolicy(Qt::CustomContextMenu); // Context Menu Connexions - connect(mappingList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMappingContextMenu(const QPoint&))); + connect(mappingItemDelegate, SIGNAL(itemContextMenuRequested(const QPoint&)), + this, SLOT(showMappingContextMenu(const QPoint&)), Qt::QueuedConnection); connect(destinationCanvas, SIGNAL(shapeContextMenuRequested(const QPoint&)), this, SLOT(showMappingContextMenu(const QPoint&))); connect(outputWindow->getCanvas(), SIGNAL(shapeContextMenuRequested(const QPoint&)), this, SLOT(showMappingContextMenu(const QPoint&))); } @@ -2643,7 +2635,7 @@ void MainWindow::enableStickyVertices(bool value) void MainWindow::showMappingContextMenu(const QPoint &point) { - QWidget *objectSender = dynamic_cast(sender()); + QWidget *objectSender = static_cast(sender()); uid mappingId = currentMappingItemId(); Mapping::ptr mapping = mappingManager->getMappingById(mappingId); @@ -2652,8 +2644,12 @@ void MainWindow::showMappingContextMenu(const QPoint &point) mappingHideAction->setChecked(!mapping->isVisible()); mappingSoloAction->setChecked(mapping->isSolo()); - if (objectSender != NULL && mappingListModel->rowCount() > 0) - mappingContextMenu->exec(objectSender->mapToGlobal(point)); + if (objectSender != NULL) { + if (sender() == mappingItemDelegate) // XXX: The item delegate is not a widget + mappingContextMenu->exec(mappingList->mapToGlobal(point)); + else + mappingContextMenu->exec(objectSender->mapToGlobal(point)); + } } void MainWindow::showPaintContextMenu(const QPoint &point) @@ -2722,12 +2718,6 @@ void MainWindow::connectProjectWidgets() connect(mappingListModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(handleMappingItemChanged(QModelIndex))); - - connect(mappingList, SIGNAL(pressed(QModelIndex)), - this, SLOT(handleMappingItemSelected(const QModelIndex&))); - - connect(mappingList, SIGNAL(activated(const QModelIndex&)), - this, SLOT(handleMappingItemSelected(const QModelIndex&))); connect(mappingListModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(handleMappingIndexesMoved())); @@ -2755,12 +2745,6 @@ void MainWindow::disconnectProjectWidgets() disconnect(mappingListModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(handleMappingItemChanged(QModelIndex))); - - disconnect(mappingList, SIGNAL(pressed(QModelIndex)), - this, SLOT(handleMappingItemSelected(const QModelIndex&))); - - disconnect(mappingList, SIGNAL(activated(const QModelIndex&)), - this, SLOT(handleMappingItemSelected(const QModelIndex&))); disconnect(mappingListModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(handleMappingIndexesMoved())); diff --git a/MainWindow.h b/MainWindow.h index 41496d4..407ac27 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -117,7 +117,6 @@ private slots: void handleMappingItemChanged(const QModelIndex &index); void handleMappingIndexesMoved(); void handlePaintItemSelected(QListWidgetItem* item); - void handleMappingItemSelected(const QModelIndex &index); void handlePaintChanged(Paint::ptr paint); void mappingPropertyChanged(uid id, QString propertyName, QVariant value); diff --git a/MappingItemDelegate.cpp b/MappingItemDelegate.cpp index 9893e8c..c2c300e 100644 --- a/MappingItemDelegate.cpp +++ b/MappingItemDelegate.cpp @@ -165,6 +165,7 @@ bool MappingItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, int x = rect.x(); int y = rect.y(); + QRect hideButtonRect = QRect(x + 4, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE); QRect soloButtonRect = QRect(x + 10, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE); QRect lockButtonRect = QRect(x + 40, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE); QRect duplicateButtonRect = QRect(x + 70, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE); @@ -176,22 +177,32 @@ bool MappingItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, if (event->type() == QEvent::MouseButtonPress) { - if (index.column() == MM::GroupButtonColum) { + if (mouseEvent->buttons() & Qt::LeftButton && index.isValid()) { + if (index.column() == MM::HideColumn) { + if (hideButtonRect.contains(mouseEvent->pos())) + model->setData(index, !(index.data(Qt::CheckStateRole).toBool()), Qt::CheckStateRole); + } + if (index.column() == MM::GroupButtonColum) { - if (soloButtonRect.contains(mouseEvent->pos())) - model->setData(index, !(index.data(Qt::CheckStateRole + 1).toBool()), Qt::CheckStateRole + 1); + if (soloButtonRect.contains(mouseEvent->pos())) + model->setData(index, !(index.data(Qt::CheckStateRole + 1).toBool()), Qt::CheckStateRole + 1); - if (lockButtonRect.contains(mouseEvent->pos())) - model->setData(index, !(index.data(Qt::CheckStateRole + 2).toBool()), Qt::CheckStateRole + 2); + if (lockButtonRect.contains(mouseEvent->pos())) + model->setData(index, !(index.data(Qt::CheckStateRole + 2).toBool()), Qt::CheckStateRole + 2); - if (duplicateButtonRect.contains(mouseEvent->pos())) - emit itemDuplicated(index.data(Qt::UserRole).toInt()); + if (duplicateButtonRect.contains(mouseEvent->pos())) + emit itemDuplicated(index.data(Qt::UserRole).toInt()); - if (deleteButtonRect.contains(mouseEvent->pos())) - emit itemRemoved(index.data(Qt::UserRole).toInt()); + if (deleteButtonRect.contains(mouseEvent->pos())) + emit itemRemoved(index.data(Qt::UserRole).toInt()); + } } + + if (mouseEvent->buttons() & Qt::RightButton && index.isValid()) + emit itemContextMenuRequested(mouseEvent->pos()); } - return false; + + return QAbstractItemDelegate::editorEvent(event, model, option, index); } MM_END_NAMESPACE diff --git a/MappingItemDelegate.h b/MappingItemDelegate.h index dddab0a..11a09e1 100644 --- a/MappingItemDelegate.h +++ b/MappingItemDelegate.h @@ -52,6 +52,7 @@ public: const QModelIndex &index) const Q_DECL_OVERRIDE; signals: + void itemContextMenuRequested(const QPoint &pos); void itemDuplicated(uid itemId); void itemRemoved(uid itemId); diff --git a/MappingListModel.cpp b/MappingListModel.cpp index 7941bdf..3f834e6 100644 --- a/MappingListModel.cpp +++ b/MappingListModel.cpp @@ -263,11 +263,4 @@ uid MappingListModel::getItemId(const QModelIndex &index) const return mappingList.at(index.row()).id; } -void MappingListModel::setVisibility(const QModelIndex &index) -{ - if (index.isValid() && index.column() == MM::HideColumn) { - setData(index, !(mappingList.at(index.row()).isVisible), Qt::CheckStateRole); - } -} - MM_END_NAMESPACE diff --git a/MappingListModel.h b/MappingListModel.h index b54fc22..0450c05 100644 --- a/MappingListModel.h +++ b/MappingListModel.h @@ -65,9 +65,6 @@ public: uid getItemId(const QModelIndex &index) const; QModelIndex getIndexFromId(uid id) const; -public slots: - void setVisibility(const QModelIndex &index); - private: struct MappingItem { int id;