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)
|
|
|
|
{
|
2019-06-18 13:02:41 +00:00
|
|
|
if (action) {
|
|
|
|
addAction(action);
|
|
|
|
connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget);
|
|
|
|
}
|
2019-05-01 16:15:33 +00:00
|
|
|
if (parent) {
|
2019-06-18 13:02:41 +00:00
|
|
|
parent->addWidget(this);
|
2018-03-16 21:46:57 +00:00
|
|
|
}
|
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) {
|
2019-06-18 13:02:41 +00:00
|
|
|
this->hide();
|
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-03-27 08:24:54 +00:00
|
|
|
QWidget *CutterDockWidget::widgetToFocusOnRaise()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
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);
|
2019-04-27 09:46:29 +00:00
|
|
|
if (isTransient) {
|
|
|
|
deleteLater();
|
|
|
|
}
|
2019-06-18 13:02:41 +00:00
|
|
|
|
|
|
|
emit closed();
|
2018-03-16 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 08:24:54 +00:00
|
|
|
QAction *CutterDockWidget::getBoundAction() const
|
|
|
|
{
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|