Fix focus lost

master
Jeremy Hu 2018-09-01 08:47:10 +08:00
parent 80ccbc51bf
commit b945ab9725
3 changed files with 29 additions and 0 deletions

View File

@ -194,6 +194,8 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
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()

View File

@ -2,6 +2,7 @@
#include <vector>
#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);
}

View File

@ -5,6 +5,8 @@
#include <QMouseEvent>
#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<QUuid, QTreeWidgetItem *> m_partItemMap;
std::map<QUuid, QTreeWidgetItem *> m_componentItemMap;
SkeletonGraphicsFunctions *m_graphicsFunctions = nullptr;
};
#endif