File: MainWindow.h

package info (click to toggle)
camitk 6.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 389,496 kB
  • sloc: cpp: 103,476; sh: 2,448; python: 1,618; xml: 984; makefile: 128; perl: 84; sed: 20
file content (253 lines) | stat: -rw-r--r-- 8,056 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*****************************************************************************
 * $CAMITK_LICENCE_BEGIN$
 *
 * CamiTK - Computer Assisted Medical Intervention ToolKit
 * (c) 2001-2025 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
 *
 * Visit http://camitk.imag.fr for more information
 *
 * This file is part of CamiTK.
 *
 * CamiTK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * CamiTK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with CamiTK.  If not, see <http://www.gnu.org/licenses/>.
 *
 * $CAMITK_LICENCE_END$
 ****************************************************************************/


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

// -- Core stuff
#include "CamiTKAPI.h"
#include "ConsoleStream.h"

// -- QT stuff
#include <QMainWindow>
#include <QApplication>
#include <QDir>
#include <QTextEdit>
#include <QLineEdit>
#include <QProgressBar>
#include <QStatusBar>
#include <QStackedLayout>

namespace camitk {

// -- Core stuff classes
class Component;
class Viewer;
class LogSyntaxHighlighter;

/**
  * @ingroup group_sdk_libraries_core_application
  *
  * @brief
  * This class is the base class for your application. It sets up the main
  * window and creates a menubar and statusbar (all hidden by default).
  *
  * It is the default main window for a application.
  *
  * Create a class that inherits from MainWindow to
  * get all the goodies of CamiTK and add your own customization/UI.
  *
  * See tutorials applications for examples.
  *
  * The central widget's layout is a QStackedLayout: when new central viewers are added, the previous central
  * viewer is hidden, not destroyed.
  */
class CAMITK_API MainWindow : public QMainWindow {
    Q_OBJECT

public:

    /// @name general
    ///@{
    /** Constructor, the window title can be changed here, it is inconsistent to use setWindowTitle().
     * If you like to dynamically add some information to the window title, please use setWindowSubtitle() instead.
     *
     * @see setWindowSubtitle
     * @param title main window title
     */
    MainWindow(QString title);

    /// destructor
    ~MainWindow() override;

    /** this method is automatically called by Application before the first time show() is called.
     * This method calls initSettings().
     */
    virtual void aboutToShow();

    ///@}

    /// @name title, subtitle, status bar message, progress bar state and console
    ///@{

    /// Get the main window title
    QString getName() const;

    /** The subtitle is situated at the end of the title, on the title bar, is helps for example showing which file is currently
     *  selected.
     *  It appears between brackets "[ ... ]"
     *
     *  \note the main title is set to Core::version(), you can change the title part (i.e. the part
     *  of the title bar before the subtitle), by calling setWindowTitle(...)
     */
    void setWindowSubtitle(QString);

    /// similar as statusBar() from QMainWindow but for the progress bar
    QProgressBar* getProgressBar();

    /// show the status bar (by default it is hidden)
    void showStatusBar(bool);

    /// use or not the application console (redirect or not standard out/err streams)
    virtual void redirectToConsole(bool);

    /// get the console window
    void showConsole(bool);

    /// get the visibility state of the console (@return true if and only if the console is currently visible)
    bool getConsoleVisibility();
    ///@}

    /** @name Initialize and save settings */
    ///@{
    /// init MainWindow specific settings (e.g. size, position)
    virtual void initSettings();

    /// Save MainWindow's settings into Application::settings
    void saveSettings();
    ///@}

    /// @name Viewers
    ///@{

    /// set the visibility for the given docked viewer
    virtual void showDockViewer(Viewer*, bool);

    /** add a Viewer to the application as a docking widget and specify where it has to be docked
    * Note that MainWindow takes ownership of the Viewer pointer and deletes it at the appropriate time.
    *
    * This method calls addViewer(...).
    * This method calls showDockViewer(..,true)
    *
    * \note MainWindow takes ownership of the viewer pointer and deletes it when it is itself destroyed.
    */
    virtual void addDockViewer(Qt::DockWidgetArea, Viewer*);

    /** Method uses to refresh all the viewer of the Main Window */
    void refreshViewers();

    /** set the central Viewer of the application.
    * The central viewer has a specific behaviour in a MainWindow. It uses a QStackWidget to keep
    * all the central viewer that are used. When a new central viewers is set, the previous central
    * viewer (i.e., its widget) is hidden but not destroyed.
    *
    * This method calls addViewer(..).
    *
    * \note MainWindow takes ownership of the viewer pointer and deletes it when it is itself destroyed.
    */
    virtual void setCentralViewer(Viewer*);

    /**
     * @return the current central viewer.
     */
    virtual Viewer* getCentralViewer() const;
    ///@}

public slots:

    /** @name Refresh and show */
    ///@{
    /// this slot is connected to all the viewers selectionChanged() signal, this will call the refresh method of all viewers
    virtual void refresh();

    /// inherited from QWidget, just to refresh all viewers
    void show();
    ///@}

protected:

    /// overriden from QMainWindow, just connect to slotFileQuit
    void closeEvent(QCloseEvent*) override;

    /** @name Viewer and other things */
    ///@{
    /// the set of viewers
    QList<Viewer*> viewers;

    /// the map that gives the corresponding QDockWidget for a given Viewer
    QMap<Viewer*, QDockWidget*> dockWidgetMap;

    ///@}

    /// called when a drag event started on the main window, accept drag only if file is MIME type text/uri-list
    void dragEnterEvent(QDragEnterEvent* event) override;

    /// called when the mouse moves inside the widgets area during a drag/drop operation
    void dragMoveEvent(QDragMoveEvent* event) override;

    /// called when the mouse leaves the widgets area during a drag/drop operation
    void dragLeaveEvent(QDragLeaveEvent* event) override;

    /// just call open with the dragged uri
    void dropEvent(QDropEvent* event) override;

    /**
     * @brief The actual central Viewer.
     * @note MainWindow, like QMainWindow with its central widget contains an unique central viewer.
     */
    Viewer* centralViewer;


private:

    /**
     * Add a viewer (called by addDockViewer and setCentralViewer), returns true if not already added.
     * Note that MainWindow takes ownership of the Viewer pointer and deletes it when it is itself destroyed.
     *
     * This method connects the selectionChanged signal of the viewer to the refresh method of MainWindow.
     */
    virtual bool addViewer(Viewer*);

    /// the output stream for the application console
    ConsoleStream cout;

    /// the error stream for the application console
    ConsoleStream cerr;

    /// the progress bar (access through setProgress() method)
    QProgressBar* myProgressBar;

    /// console to display all messages
    QDockWidget* consoleWindow;

    /// the QTextEdit part of the console dialog
    QTextEdit* consoleWindowTextEdit;

    /// the log syntax highlighter used in the console
    LogSyntaxHighlighter* logSyntaxHighlighter;

    /// the main part of the title
    QString mainTitle;

    /// the central widget is a frame, its layout is a QStackedLayout so that
    /// it is possible to easily switch between viewers
    QStackedLayout* centralLayout;

};
}


#endif // MAINWINDOW_H