cutter/src/widgets/CutterDockWidget.cpp

83 lines
1.9 KiB
C++
Raw Normal View History

#include "CutterDockWidget.h"
#include "core/MainWindow.h"
2019-03-14 09:28:42 +00:00
#include <QAction>
#include <QEvent>
CutterDockWidget::CutterDockWidget(MainWindow *parent, QAction *action) :
QDockWidget(parent),
action(action)
{
if (parent) {
parent->addToDockWidgetList(this);
if (action) {
parent->addDockWidgetAction(this, action);
connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget);
}
}
// Install event filter to catch redraw widgets when needed
installEventFilter(this);
2019-01-12 19:25:43 +00:00
updateIsVisibleToUser();
}
CutterDockWidget::~CutterDockWidget() = default;
bool CutterDockWidget::eventFilter(QObject *object, QEvent *event)
{
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();
}
return QDockWidget::eventFilter(object, event);
}
void CutterDockWidget::toggleDockWidget(bool show)
{
2018-03-21 20:32:32 +00:00
if (!show) {
this->close();
2018-03-21 20:32:32 +00:00
} else {
this->show();
this->raise();
}
}
QWidget *CutterDockWidget::widgetToFocusOnRaise()
{
return this;
}
void CutterDockWidget::updateIsVisibleToUser()
{
// 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-21 20:32:32 +00:00
void CutterDockWidget::closeEvent(QCloseEvent *event)
{
if (action) {
this->action->setChecked(false);
}
QDockWidget::closeEvent(event);
2019-04-27 09:46:29 +00:00
if (isTransient) {
deleteLater();
}
}
QAction *CutterDockWidget::getBoundAction() const
{
return action;
}