1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "autohidedockwidget.h"
6
7#include <QEvent>
8
9AutoHideDockWidget::AutoHideDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
10 : QDockWidget (title, parent, flags)
11{
12
13}
14
15AutoHideDockWidget::AutoHideDockWidget(QWidget *parent, Qt::WindowFlags flags)
16 : QDockWidget (parent, flags)
17{
18
19}
20
21QWidget *AutoHideDockWidget::widget() const
22{
23 return QDockWidget::widget();
24}
25
26void AutoHideDockWidget::setWidget(QWidget *widget)
27{
28 if (widget) {
29 widget->installEventFilter(this);
30 }
31 return QDockWidget::setWidget(widget);
32}
33
34bool AutoHideDockWidget::eventFilter(QObject *obj, QEvent *e)
35{
36 if (obj == widget()) {
37 switch (e->type()){
38 case QEvent::HideToParent:
39 QDockWidget::hide();
40 return true;
41 case QEvent::ShowToParent:
42 QDockWidget::show();
43 return true;
44 case QEvent::Destroy:
45 QDockWidget::hide();
46 return true;
47 default:
48 return false;
49 }
50 }
51 return false;
52}
53