mdifloatingwindow.h 4.38 KB
Newer Older
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
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

30
31
#ifndef MDIFLOATINGWINDOW_H__
#define MDIFLOATINGWINDOW_H__
32
33
34
35
36
37

#include <QWidget>

namespace campvis {

    /**
38
     * Specialised widget for detached MDI subwindows.
39
     *
40
41
42
43
44
45
46
47
     * MdiFloatingWindow is a top-level floating window representing an undocked MDI subwindow.
     * It reports changes in its position via the s_positionChanged signal. The MDI area that
     * created it listens to this signal to decide when to scrap the floating window and dock back
     * the widget that it wraps.
     *
     * MdiFloatingWindow also implements additional methods (forceWindowDrag, stopWindowDrag)
     * that should be used to coordinate its creation/disposal with respect to grabbing/releasing
     * the mouse input.
48
     */
49
    class MdiFloatingWindow : public QWidget {
50

51
        Q_OBJECT
52
53
54

    public:
        /**
55
         * Construct a new MdiFloatingWindow.
56
         *
57
58
         * \param canvas the widget this window is to wrap
         * \param parent the windows's parent
59
         */
60
        explicit MdiFloatingWindow(QWidget* widget, QWidget* parent = 0);
61
62

        /**
63
         * Enter the window into forced drag mode.
64
         *
65
         * This method causes the window to grab the mouse input and follow the cursor.
66
67
68
         */
        void forceWindowDrag();

69
        /**
70
         * Cancel the dragging of the window.
71
         *
72
         * This method causes the window to release the mouse grab and stop following the cursor.
73
74
75
         */
        void stopWindowDrag();

76
        /**
77
         * Return the widget this window wraps.
78
         */
79
        QWidget* widget();
80

81
82
    signals:
        /**
83
         * Emitted when the window's position changes.
84
         *
85
         * \param newPos the window's new position
86
         */
87
        void s_positionChanged(MdiFloatingWindow* pipelineWidget, const QPoint& newPos);
88

89
90
    protected:
        /**
91
         * Event handler that receives mouse move events for the window.
92
93
94
95
         */
        virtual void mouseMoveEvent(QMouseEvent* event);

        /**
96
         * Event handler that receives mouse release events for the window.
97
98
99
         */
        virtual void mouseReleaseEvent(QMouseEvent * event);

100
101
102
103
104
        /**
         * Event handler that receives move events for the window.
         */
        virtual void moveEvent(QMoveEvent* event);

105
    private:
106
107
108
109
110
        /**
         * Moves the window so that its title bar is centered around \p cursorPos.
         */
        void snapToCursor(const QPoint& cursorPos);

111
112
        QWidget* _widget;            ///< The widget this window wraps
        bool _dragActive;            ///< Is the window currently being dragged?
113
114
115
116

    };
}

117
#endif // MDIFLOATINGWINDOW_H__