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
|
|
|
|
|
|
|
|
|
|
|
CutterDockWidget::CutterDockWidget(MainWindow *main, QAction *action) :
|
|
|
|
QDockWidget(main),
|
|
|
|
action(action)
|
|
|
|
{
|
|
|
|
if (action) {
|
2018-05-25 14:30:59 +00:00
|
|
|
main->addToDockWidgetList(this);
|
2018-03-16 21:46:57 +00:00
|
|
|
main->addDockWidgetAction(this, action);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|