2018-03-16 21:46:57 +00:00
|
|
|
#include "CutterDockWidget.h"
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/MainWindow.h"
|
2018-03-16 21:46:57 +00:00
|
|
|
|
2019-03-14 09:28:42 +00:00
|
|
|
#include <QAction>
|
|
|
|
#include <QEvent>
|
2018-03-16 21:46:57 +00:00
|
|
|
|
2019-03-10 22:26:25 +00:00
|
|
|
CutterDockWidget::CutterDockWidget(MainWindow *parent, QAction *action) :
|
|
|
|
QDockWidget(parent),
|
2018-03-16 21:46:57 +00:00
|
|
|
action(action)
|
|
|
|
{
|
|
|
|
if (action) {
|
2019-03-10 22:26:25 +00:00
|
|
|
parent->addToDockWidgetList(this);
|
|
|
|
parent->addDockWidgetAction(this, action);
|
2018-03-16 21:46:57 +00:00
|
|
|
connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget);
|
|
|
|
}
|
2019-01-12 17:02:51 +00:00
|
|
|
|
|
|
|
// Install event filter to catch redraw widgets when needed
|
|
|
|
installEventFilter(this);
|
2019-01-12 19:25:43 +00:00
|
|
|
updateIsVisibleToUser();
|
2018-03-16 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 15:41:08 +00:00
|
|
|
CutterDockWidget::~CutterDockWidget() = default;
|
2019-01-12 17:02:51 +00:00
|
|
|
|
|
|
|
bool CutterDockWidget::eventFilter(QObject *object, QEvent *event)
|
|
|
|
{
|
2019-01-12 18:01:43 +00:00
|
|
|
if (event->type() == QEvent::FocusIn
|
|
|
|
|| event->type() == QEvent::ZOrderChange
|
|
|
|
|| event->type() == QEvent::Paint
|
|
|
|
|| event->type() == QEvent::Close
|
|
|
|
|| event->type() == QEvent::Show
|
|
|
|
|| event->type() == QEvent::Hide) {
|
|
|
|
updateIsVisibleToUser();
|
2019-01-12 17:02:51 +00:00
|
|
|
}
|
|
|
|
return QDockWidget::eventFilter(object, event);
|
|
|
|
}
|
2018-03-16 21:46:57 +00:00
|
|
|
|
|
|
|
void CutterDockWidget::toggleDockWidget(bool show)
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!show) {
|
2018-03-16 21:46:57 +00:00
|
|
|
this->close();
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2018-03-16 21:46:57 +00:00
|
|
|
this->show();
|
|
|
|
this->raise();
|
2019-01-12 17:02:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-12 18:01:43 +00:00
|
|
|
void CutterDockWidget::updateIsVisibleToUser()
|
2019-01-12 17:02:51 +00:00
|
|
|
{
|
2019-01-12 18:01:43 +00:00
|
|
|
// Check if the user can actually see the widget.
|
|
|
|
bool visibleToUser = isVisible() && !visibleRegion().isEmpty();
|
|
|
|
if (visibleToUser == isVisibleToUserCurrent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isVisibleToUserCurrent = visibleToUser;
|
|
|
|
if (isVisibleToUserCurrent) {
|
|
|
|
emit becameVisibleToUser();
|
2018-03-16 21:46:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
void CutterDockWidget::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2018-03-16 21:46:57 +00:00
|
|
|
if (action) {
|
|
|
|
this->action->setChecked(false);
|
|
|
|
}
|
|
|
|
QDockWidget::closeEvent(event);
|
|
|
|
}
|
|
|
|
|