Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #pragma once
23 :
24 : #include <QObject>
25 : #include <QQuickItem>
26 :
27 : #include "async/notification.h"
28 : #include "async/asyncable.h"
29 :
30 : #include "modularity/ioc.h"
31 : #include "interactive/iinteractive.h"
32 : #include "ui/imainwindow.h"
33 :
34 : namespace muse::uicomponents {
35 : class PopupViewCloseController : public QObject, public muse::Contextable, public async::Asyncable
36 : {
37 : Q_OBJECT
38 :
39 : muse::ContextInject<IInteractive> interactive = { this };
40 : muse::ContextInject<ui::IMainWindow> mainWindow = { this };
41 :
42 : public:
43 : explicit PopupViewCloseController(const muse::modularity::ContextPtr& iocCtx, QObject* parent = nullptr);
44 0 : ~PopupViewCloseController() override = default;
45 :
46 : void init();
47 :
48 : bool active() const;
49 : void setActive(bool active);
50 :
51 : QQuickItem* parentItem() const;
52 : void setParentItem(QQuickItem* parentItem);
53 :
54 : QWindow* popupWindow() const;
55 : void setWindow(QWindow* window);
56 :
57 : void setIsCloseOnPressOutsideParent(bool arg);
58 : void setCanClose(bool arg);
59 :
60 : async::Notification closeNotification() const;
61 :
62 : private slots:
63 : void onApplicationStateChanged(Qt::ApplicationState state);
64 :
65 : protected:
66 : bool eventFilter(QObject* watched, QEvent* event) override;
67 :
68 : void doFocusOut(const QPointF& mousePos);
69 : virtual void doUpdateEventFilters();
70 :
71 : bool isMouseWithinBoundaries(const QPointF& mousePos) const;
72 :
73 : void notifyAboutClose();
74 :
75 : private:
76 : QWindow* parentWindow() const;
77 :
78 : bool m_active = false;
79 :
80 : QQuickItem* m_parentItem = nullptr;
81 : QWindow* m_popupWindow = nullptr;
82 :
83 : bool m_isCloseOnPressOutsideParent = false;
84 : bool m_canClose = true;
85 :
86 : async::Notification m_closeNotification;
87 : };
88 : }
|