1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_MDI_MANAGER_IMPL_H_
23 #define _U2_MDI_MANAGER_IMPL_H_
24 
25 #include <QEvent>
26 #include <QMdiArea>
27 #include <QMdiSubWindow>
28 #include <QSignalMapper>
29 
30 #include "MainWindowImpl.h"
31 
32 namespace U2 {
33 
34 class MDIItem : QWidget {
35     Q_OBJECT
36 public:
MDIItem(MWMDIWindow * _w,QMdiSubWindow * _qw)37     MDIItem(MWMDIWindow *_w, QMdiSubWindow *_qw)
38         : w(_w), qw(_qw) {
39         this->setObjectName(_w->objectName() + "_MDIItem");
40         qw->setObjectName(_w->objectName() + "_SubWindow");
41     }
42 
43     MWMDIWindow *w;
44     QMdiSubWindow *qw;
45 };
46 
47 typedef QList<MDIItem *> MDIItems;
48 
49 class MWMDIManagerImpl : public MWMDIManager {
50     Q_OBJECT
51 public:
MWMDIManagerImpl(MainWindow * _mw,FixedMdiArea * _mdiArea)52     MWMDIManagerImpl(MainWindow *_mw, FixedMdiArea *_mdiArea)
53         : MWMDIManager(_mw), mw(_mw), mdiArea(_mdiArea) {
54         prepareGUI();
55     }
56 
57     ~MWMDIManagerImpl();
58 
59     virtual void addMDIWindow(MWMDIWindow *w);
60 
61     virtual bool closeMDIWindow(MWMDIWindow *w);
62 
63     virtual QList<MWMDIWindow *> getWindows() const;
64 
65     virtual MWMDIWindow *getWindowById(int id) const;
66 
67     virtual void activateWindow(MWMDIWindow *w);
68 
69     virtual MWMDIWindow *getActiveWindow() const;
70 
71 protected:
72     bool eventFilter(QObject *obj, QEvent *event);
73 
74 private slots:
75     void sl_setActiveSubWindow(QWidget *);
76     void sl_updateWindowMenu();
77     void sl_onSubWindowActivated(QMdiSubWindow *);
78     void sl_updateWindowLayout();
79     void sl_setWindowLayoutToMultiDoc();
80     void sl_setWindowLayoutToTabbed();
81 
82 private:
83     MDIItem *getMDIItem(int id) const;
84     MDIItem *getMDIItem(MWMDIWindow *w) const;
85     MDIItem *getMDIItem(QMdiSubWindow *qw) const;
86 
87     void clearMDIContent(bool addCloseAction);
88     void prepareGUI();
89 
90     void updateActions();
91     void updateState();
92 
93     MDIItem *getCurrentMDIItem() const;
94 
95     void onWindowsSwitched(QMdiSubWindow *deactivated, MWMDIWindow *activated);
96 
97     MainWindow *mw;
98     FixedMdiArea *mdiArea;
99     MDIItems items;
100 
101     QAction *closeAct;
102     QAction *closeAllAct;
103     QAction *tileAct;
104     QAction *cascadeAct;
105     QAction *nextAct;
106     QAction *previousAct;
107     QAction *separatorAct;
108     QMenu *windowLayout;
109     QAction *multipleDocsAct;
110     QAction *tabbedDocsAct;
111 
112     QSignalMapper *windowMapper;
113     bool defaultIsMaximized;
114     MDIItem *mdiContentOwner;
115 };
116 
117 }  // namespace U2
118 
119 #endif
120