Change parts tree menu trigger method
Left mouse single press will popup short version of context menumaster
parent
89d49d488d
commit
cff5cff6bc
|
@ -70,7 +70,9 @@ PartTreeWidget::PartTreeWidget(const Document *document, QWidget *parent) :
|
|||
m_firstSelect = true;
|
||||
selectComponent(QUuid());
|
||||
|
||||
connect(this, &QTreeWidget::customContextMenuRequested, this, &PartTreeWidget::showContextMenu);
|
||||
connect(this, &QTreeWidget::customContextMenuRequested, this, [&](const QPoint &pos) {
|
||||
showContextMenu(pos);
|
||||
});
|
||||
connect(this, &QTreeWidget::itemChanged, this, &PartTreeWidget::groupChanged);
|
||||
connect(this, &QTreeWidget::itemExpanded, this, &PartTreeWidget::groupExpanded);
|
||||
connect(this, &QTreeWidget::itemCollapsed, this, &PartTreeWidget::groupCollapsed);
|
||||
|
@ -154,11 +156,38 @@ void PartTreeWidget::updateComponentSelectState(QUuid componentId, bool selected
|
|||
}
|
||||
}
|
||||
|
||||
void PartTreeWidget::mousePressEvent(QMouseEvent *event)
|
||||
void PartTreeWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
QModelIndex itemIndex = indexAt(event->pos());
|
||||
QTreeView::mousePressEvent(event);
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
delete m_delayedMousePressTimer;
|
||||
m_delayedMousePressTimer = nullptr;
|
||||
|
||||
QWidget::mouseDoubleClickEvent(event);
|
||||
auto componentIds = collectSelectedComponentIds(event->pos());
|
||||
for (const auto &componentId: componentIds) {
|
||||
std::vector<QUuid> partIds;
|
||||
m_document->collectComponentDescendantParts(componentId, partIds);
|
||||
for (const auto &partId: partIds) {
|
||||
emit addPartToSelection(partId);
|
||||
}
|
||||
}
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void PartTreeWidget::handleSingleClick(const QPoint &pos)
|
||||
{
|
||||
QModelIndex itemIndex = indexAt(pos);
|
||||
|
||||
auto showMenu = [=]() {
|
||||
delete m_delayedMousePressTimer;
|
||||
m_delayedMousePressTimer = new QTimer(this);
|
||||
m_delayedMousePressTimer->setSingleShot(true);
|
||||
m_delayedMousePressTimer->setInterval(200);
|
||||
connect(m_delayedMousePressTimer, &QTimer::timeout, this, [=]() {
|
||||
showContextMenu(pos, true);
|
||||
});
|
||||
m_delayedMousePressTimer->start();
|
||||
};
|
||||
|
||||
bool multiple = QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier);
|
||||
if (itemIndex.isValid()) {
|
||||
QTreeWidgetItem *item = itemFromIndex(itemIndex);
|
||||
|
@ -202,16 +231,29 @@ void PartTreeWidget::mousePressEvent(QMouseEvent *event)
|
|||
}
|
||||
}
|
||||
}
|
||||
showMenu();
|
||||
return;
|
||||
} else {
|
||||
m_shiftStartComponentId = componentId;
|
||||
}
|
||||
selectComponent(componentId, multiple);
|
||||
showMenu();
|
||||
return;
|
||||
}
|
||||
if (!multiple)
|
||||
selectComponent(QUuid());
|
||||
}
|
||||
|
||||
showMenu();
|
||||
}
|
||||
|
||||
void PartTreeWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QTreeView::mousePressEvent(event);
|
||||
|
||||
if (event->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
handleSingleClick(event->pos());
|
||||
}
|
||||
|
||||
void PartTreeWidget::showClothSettingMenu(const QPoint &pos, const QUuid &componentId)
|
||||
|
@ -294,12 +336,8 @@ void PartTreeWidget::showClothSettingMenu(const QPoint &pos, const QUuid &compon
|
|||
popupMenu.exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void PartTreeWidget::showContextMenu(const QPoint &pos)
|
||||
std::vector<QUuid> PartTreeWidget::collectSelectedComponentIds(const QPoint &pos)
|
||||
{
|
||||
const Component *component = nullptr;
|
||||
const SkeletonPart *part = nullptr;
|
||||
PartWidget *partWidget = nullptr;
|
||||
|
||||
std::set<QUuid> unorderedComponentIds = m_selectedComponentIds;
|
||||
if (!m_currentSelectedComponentId.isNull())
|
||||
unorderedComponentIds.insert(m_currentSelectedComponentId);
|
||||
|
@ -320,6 +358,25 @@ void PartTreeWidget::showContextMenu(const QPoint &pos)
|
|||
componentIds.push_back(cand);
|
||||
}
|
||||
|
||||
return componentIds;
|
||||
}
|
||||
|
||||
void PartTreeWidget::showContextMenu(const QPoint &pos, bool shorted)
|
||||
{
|
||||
delete m_delayedMousePressTimer;
|
||||
m_delayedMousePressTimer = nullptr;
|
||||
|
||||
const Component *component = nullptr;
|
||||
const SkeletonPart *part = nullptr;
|
||||
PartWidget *partWidget = nullptr;
|
||||
|
||||
std::vector<QUuid> componentIds = collectSelectedComponentIds(pos);
|
||||
|
||||
if (shorted) {
|
||||
if (componentIds.size() != 1)
|
||||
return;
|
||||
}
|
||||
|
||||
QMenu contextMenu(this);
|
||||
|
||||
if (componentIds.size() == 1) {
|
||||
|
@ -493,6 +550,13 @@ void PartTreeWidget::showContextMenu(const QPoint &pos)
|
|||
contextMenu.addSeparator();
|
||||
//}
|
||||
|
||||
if (shorted) {
|
||||
auto globalPos = mapToGlobal(pos);
|
||||
globalPos.setX(globalPos.x() - contextMenu.sizeHint().width() - pos.x());
|
||||
contextMenu.exec(globalPos);
|
||||
return;
|
||||
}
|
||||
|
||||
QAction showAction(tr("Show"), this);
|
||||
showAction.setIcon(Theme::awesome()->icon(fa::eye));
|
||||
QAction hideAction(tr("Hide"), this);
|
||||
|
@ -758,7 +822,9 @@ void PartTreeWidget::showContextMenu(const QPoint &pos)
|
|||
contextMenu.addAction(&deleteAction);
|
||||
}
|
||||
|
||||
contextMenu.exec(mapToGlobal(pos));
|
||||
auto globalPos = mapToGlobal(pos);
|
||||
globalPos.setX(globalPos.x() - contextMenu.sizeHint().width() - pos.x());
|
||||
contextMenu.exec(globalPos);
|
||||
|
||||
for (const auto &action: groupsActions) {
|
||||
delete action;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QUuid>
|
||||
#include <QMouseEvent>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QTimer>
|
||||
#include "document.h"
|
||||
|
||||
class PartTreeWidget : public QTreeWidget
|
||||
|
@ -85,11 +86,12 @@ public slots:
|
|||
void groupExpanded(QTreeWidgetItem *item);
|
||||
void groupCollapsed(QTreeWidgetItem *item);
|
||||
void removeAllContent();
|
||||
void showContextMenu(const QPoint &pos);
|
||||
void showContextMenu(const QPoint &pos, bool shorted=false);
|
||||
void showClothSettingMenu(const QPoint &pos, const QUuid &componentId);
|
||||
protected:
|
||||
QSize sizeHint() const override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
private:
|
||||
void addComponentChildrenToItem(QUuid componentId, QTreeWidgetItem *parentItem);
|
||||
void deleteItemChildren(QTreeWidgetItem *item);
|
||||
|
@ -98,9 +100,12 @@ private:
|
|||
void updateComponentSelectState(QUuid componentId, bool selected);
|
||||
void updateComponentAppearance(QUuid componentId);
|
||||
bool isComponentSelected(QUuid componentId);
|
||||
std::vector<QUuid> collectSelectedComponentIds(const QPoint &pos);
|
||||
void handleSingleClick(const QPoint &pos);
|
||||
private:
|
||||
const Document *m_document = nullptr;
|
||||
QTreeWidgetItem *m_rootItem = nullptr;
|
||||
QTimer *m_delayedMousePressTimer = nullptr;
|
||||
bool m_firstSelect = true;
|
||||
std::map<QUuid, QTreeWidgetItem *> m_partItemMap;
|
||||
std::map<QUuid, QTreeWidgetItem *> m_componentItemMap;
|
||||
|
|
|
@ -323,11 +323,11 @@ void PartWidget::updateUnnormalState(bool unnormal)
|
|||
updateAllButtons();
|
||||
}
|
||||
|
||||
void PartWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
QWidget::mouseDoubleClickEvent(event);
|
||||
emit checkPart(m_partId);
|
||||
}
|
||||
//void PartWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
//{
|
||||
// QWidget::mouseDoubleClickEvent(event);
|
||||
// emit checkPart(m_partId);
|
||||
//}
|
||||
|
||||
void PartWidget::initToolButtonWithoutFont(QPushButton *button)
|
||||
{
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
static QSize preferredSize();
|
||||
ModelWidget *previewWidget();
|
||||
protected:
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
//void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
public slots:
|
||||
void showDeformSettingPopup(const QPoint &pos);
|
||||
void showCutRotationSettingPopup(const QPoint &pos);
|
||||
|
|
Loading…
Reference in New Issue