diff options
Diffstat (limited to 'gui/designwidget.cc')
-rw-r--r-- | gui/designwidget.cc | 104 |
1 files changed, 51 insertions, 53 deletions
diff --git a/gui/designwidget.cc b/gui/designwidget.cc index c17990a5..f9d231c1 100644 --- a/gui/designwidget.cc +++ b/gui/designwidget.cc @@ -775,54 +775,55 @@ std::vector<DecalXY> DesignWidget::getDecals(ElementType type, IdString value) return decals;
}
-void DesignWidget::updateHighlightGroup(QTreeWidgetItem *item, int group)
+void DesignWidget::updateHighlightGroup(QList<QTreeWidgetItem*> items, int group)
{
- if (highlightSelected.contains(item)) {
- if (highlightSelected[item] == group) {
- highlightSelected.remove(item);
- } else
- highlightSelected[item] = group;
- } else
- highlightSelected.insert(item, group);
-
- std::vector<DecalXY> decals;
-
- for (auto it : highlightSelected.toStdMap()) {
- if (it.second == group) {
- ElementType type = static_cast<ElementTreeItem *>(it.first)->getType();
- IdString value = static_cast<IdStringTreeItem *>(it.first)->getData();
- std::vector<DecalXY> d = getDecals(type, value);
- std::move(d.begin(), d.end(), std::back_inserter(decals));
+ const bool shouldClear = items.size() == 1;
+ for (auto item : items) {
+ if (highlightSelected.contains(item)) {
+ if (shouldClear && highlightSelected[item] == group) {
+ highlightSelected.remove(item);
+ }
+ else
+ highlightSelected[item] = group;
}
+ else
+ highlightSelected.insert(item, group);
}
+ std::vector<DecalXY> decals[8];
- Q_EMIT highlight(decals, group);
+ for (auto it : highlightSelected.toStdMap()) {
+ ElementType type = static_cast<ElementTreeItem *>(it.first)->getType();
+ IdString value = static_cast<IdStringTreeItem *>(it.first)->getData();
+ std::vector<DecalXY> d = getDecals(type, value);
+ std::move(d.begin(), d.end(), std::back_inserter(decals[it.second]));
+ }
+ for (int i=0;i<8;i++)
+ Q_EMIT highlight(decals[i], i);
}
void DesignWidget::prepareMenuProperty(const QPoint &pos)
{
QTreeWidget *tree = propertyEditor->treeWidget();
-
- itemContextMenu = tree->itemAt(pos);
- if (itemContextMenu->parent() == nullptr)
- return;
-
- QtBrowserItem *browserItem = propertyEditor->itemToBrowserItem(itemContextMenu);
- if (!browserItem)
- return;
- QtProperty *selectedProperty = browserItem->property();
- ElementType type = getElementTypeByName(selectedProperty->propertyId());
- if (type == ElementType::NONE)
- return;
- IdString value = ctx->id(selectedProperty->valueText().toStdString());
-
- QTreeWidgetItem *item = nameToItem[getElementIndex(type)].value(value.c_str(ctx));
+ QList<QTreeWidgetItem*> items;
+ for (auto itemContextMenu : tree->selectedItems()) {
+ QtBrowserItem *browserItem = propertyEditor->itemToBrowserItem(itemContextMenu);
+ if (!browserItem)
+ continue;
+ QtProperty *selectedProperty = browserItem->property();
+ ElementType type = getElementTypeByName(selectedProperty->propertyId());
+ if (type == ElementType::NONE)
+ continue;
+ IdString value = ctx->id(selectedProperty->valueText().toStdString());
+ items.append(nameToItem[getElementIndex(type)].value(value.c_str(ctx)));
+ }
+ int selectedIndex = -1;
+ if (items.size() == 1) {
+ QTreeWidgetItem *item = items.at(0);
+ if (highlightSelected.contains(item))
+ selectedIndex = highlightSelected[item];
+ }
QMenu menu(this);
- QAction *selectAction = new QAction("&Select", this);
- connect(selectAction, &QAction::triggered, this, [this, type, value] { Q_EMIT selected(getDecals(type, value)); });
- menu.addAction(selectAction);
-
QMenu *subMenu = menu.addMenu("Highlight");
QActionGroup *group = new QActionGroup(this);
group->setExclusive(true);
@@ -833,27 +834,24 @@ void DesignWidget::prepareMenuProperty(const QPoint &pos) action->setCheckable(true);
subMenu->addAction(action);
group->addAction(action);
- if (highlightSelected.contains(item) && highlightSelected[item] == i)
+ if (selectedIndex == i)
action->setChecked(true);
- connect(action, &QAction::triggered, this, [this, i, item] { updateHighlightGroup(item, i); });
+ connect(action, &QAction::triggered, this, [this, i, items] { updateHighlightGroup(items, i); });
}
menu.exec(tree->mapToGlobal(pos));
}
void DesignWidget::prepareMenuTree(const QPoint &pos)
{
- QTreeWidget *tree = treeWidget;
-
- itemContextMenu = tree->itemAt(pos);
-
- ElementType type = static_cast<ElementTreeItem *>(itemContextMenu)->getType();
- IdString value = static_cast<IdStringTreeItem *>(itemContextMenu)->getData();
-
- if (type == ElementType::NONE)
+ if (treeWidget->selectedItems().size() == 0)
return;
-
- QTreeWidgetItem *item = nameToItem[getElementIndex(type)].value(value.c_str(ctx));
-
+ int selectedIndex = -1;
+ QList<QTreeWidgetItem*> items = treeWidget->selectedItems();
+ if (treeWidget->selectedItems().size() == 1) {
+ QTreeWidgetItem *item = treeWidget->selectedItems().at(0);
+ if (highlightSelected.contains(item))
+ selectedIndex = highlightSelected[item];
+ }
QMenu menu(this);
QMenu *subMenu = menu.addMenu("Highlight");
QActionGroup *group = new QActionGroup(this);
@@ -865,11 +863,11 @@ void DesignWidget::prepareMenuTree(const QPoint &pos) action->setCheckable(true);
subMenu->addAction(action);
group->addAction(action);
- if (highlightSelected.contains(item) && highlightSelected[item] == i)
+ if (selectedIndex == i)
action->setChecked(true);
- connect(action, &QAction::triggered, this, [this, i, item] { updateHighlightGroup(item, i); });
+ connect(action, &QAction::triggered, this, [this, i, items] { updateHighlightGroup(items, i); });
}
- menu.exec(tree->mapToGlobal(pos));
+ menu.exec(treeWidget->mapToGlobal(pos));
}
void DesignWidget::onItemDoubleClicked(QTreeWidgetItem *item, int column)
|