From b945ab9725a3d1c4c481cc46e869514df8313e2d Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sat, 1 Sep 2018 08:47:10 +0800 Subject: [PATCH] Fix focus lost --- src/skeletondocumentwindow.cpp | 12 ++++++++++++ src/skeletonparttreewidget.cpp | 12 ++++++++++++ src/skeletonparttreewidget.h | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/src/skeletondocumentwindow.cpp b/src/skeletondocumentwindow.cpp index 5181640b..9790386c 100644 --- a/src/skeletondocumentwindow.cpp +++ b/src/skeletondocumentwindow.cpp @@ -193,6 +193,8 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() : partListDocker->setAllowedAreas(Qt::RightDockWidgetArea); SkeletonPartTreeWidget *partTreeWidget = new SkeletonPartTreeWidget(m_document, partListDocker); + + partTreeWidget->setGraphicsFunctions(graphicsWidget); partListDocker->setWidget(partTreeWidget); addDockWidget(Qt::RightDockWidgetArea, partListDocker); @@ -656,6 +658,16 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() : connect(m_document, &SkeletonDocument::zlockStateChanged, this, &SkeletonDocumentWindow::updateZlockButtonState); connect(this, &SkeletonDocumentWindow::initialized, m_document, &SkeletonDocument::uiReady); + + QTimer *timer = new QTimer(this); + timer->setInterval(100); + connect(timer, &QTimer::timeout, [=] { + QWidget *focusedWidget = QApplication::focusWidget(); + //qDebug() << (focusedWidget ? ("Focused on:" + QString(focusedWidget->metaObject()->className()) + " title:" + focusedWidget->windowTitle()) : "No Focus") << " isActive:" << isActiveWindow(); + if (nullptr == focusedWidget && isActiveWindow()) + graphicsWidget->setFocus(); + }); + timer->start(); } SkeletonDocumentWindow *SkeletonDocumentWindow::createDocumentWindow() diff --git a/src/skeletonparttreewidget.cpp b/src/skeletonparttreewidget.cpp index 3a33c5f7..7c44ecb5 100644 --- a/src/skeletonparttreewidget.cpp +++ b/src/skeletonparttreewidget.cpp @@ -2,6 +2,7 @@ #include #include "skeletonparttreewidget.h" #include "skeletonpartwidget.h" +#include "skeletongraphicswidget.h" SkeletonPartTreeWidget::SkeletonPartTreeWidget(const SkeletonDocument *document, QWidget *parent) : QTreeWidget(parent), @@ -611,3 +612,14 @@ QSize SkeletonPartTreeWidget::sizeHint() const return QSize(size.width() * 1.35, size.height() * 5.5); } +void SkeletonPartTreeWidget::setGraphicsFunctions(SkeletonGraphicsFunctions *graphicsFunctions) +{ + m_graphicsFunctions = graphicsFunctions; +} + +void SkeletonPartTreeWidget::keyPressEvent(QKeyEvent *event) +{ + QTreeWidget::keyPressEvent(event); + if (m_graphicsFunctions) + m_graphicsFunctions->keyPress(event); +} diff --git a/src/skeletonparttreewidget.h b/src/skeletonparttreewidget.h index 9e0290cd..c88cab28 100644 --- a/src/skeletonparttreewidget.h +++ b/src/skeletonparttreewidget.h @@ -5,6 +5,8 @@ #include #include "skeletondocument.h" +class SkeletonGraphicsFunctions; + class SkeletonPartTreeWidget : public QTreeWidget { Q_OBJECT @@ -38,6 +40,7 @@ signals: public: SkeletonPartTreeWidget(const SkeletonDocument *document, QWidget *parent); QTreeWidgetItem *findComponentItem(QUuid componentId); + void setGraphicsFunctions(SkeletonGraphicsFunctions *graphicsFunctions); public slots: void componentNameChanged(QUuid componentId); void componentChildrenChanged(QUuid componentId); @@ -66,6 +69,7 @@ public slots: protected: virtual QSize sizeHint() const; virtual void mousePressEvent(QMouseEvent *event); + virtual void keyPressEvent(QKeyEvent *event); private: void addComponentChildrenToItem(QUuid componentId, QTreeWidgetItem *parentItem); void deleteItemChildren(QTreeWidgetItem *item); @@ -73,6 +77,7 @@ private: const SkeletonDocument *m_document = nullptr; std::map m_partItemMap; std::map m_componentItemMap; + SkeletonGraphicsFunctions *m_graphicsFunctions = nullptr; }; #endif