]> Creatis software - bbtk.git/blob - kernel/src/bbtkQt.h
Feature #1774
[bbtk.git] / kernel / src / bbtkQt.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkQt.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.3 $
34 =========================================================================*/
35
36
37
38 #ifndef __bbtkQt_h_INCLUDED__
39 #define __bbtkQt_h_INCLUDED__
40
41 //===========================================================================
42 // SIGNAL/SLOT MECHANISM 
43 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION 
44 // BBTKWXSIG
45 #include <boost/signal.hpp>
46 #include <boost/bind.hpp>
47 typedef boost::signals::trackable SignalObserver;
48 // \BBTKWXSIG
49 //===========================================================================
50
51
52 //===========================================================================
53 // Qt headers
54 #ifdef USE_QT
55 #include "qwidget.h"
56 // EO Qt headers
57
58 #else //USE_QT
59
60 // define QWidget
61 typedef void QWidget;
62 typedef void QBusyCursor;
63
64 #endif // EO USE_WXWIDGETS
65 //===========================================================================
66
67 //===========================================================================
68 #include "bbtkSystem.h"
69 //===========================================================================
70
71
72 namespace bbtk
73 {
74
75   //==================================================================
76   /// Global qt handlers (cursor...)
77   
78 // BBTKWXSIG
79 #define bbtkAddQtSignalObserver(METHOD)         \
80   Qt::AddSignalObserver(boost::bind(&METHOD, this))
81 // \BBTKWXSIG
82
83 #define BBTK_BUSY_CURSOR bbtk::Qt::BusyCursor __bbtk_dummy_busy_cursor;
84
85   struct BBTK_EXPORT Qt
86   {     
87   public:
88     // BBTKWXSIG
89     // The keyword 'signals' is also a macro in qt
90     //    typedef boost::signals::trackable SignalObserver;
91     typedef boost::signal<void ()>  Signal_type;
92     typedef Signal_type::slot_function_type Slot_function_type;
93     // \BBTKWXSIG
94
95     /*
96     static void ResetCursor();
97     static void BeginBusyCursor(); 
98     static void EndBusyCursor();
99     */
100
101     static void LoopUntilAllWindowsClose();
102
103     class BusyCursor
104     {
105     public:
106       BusyCursor();
107       ~BusyCursor();
108       //wxBusyCursor* mCursor;
109     };
110
111     static void SetTopWindowParent(QWidget*);
112     static void SetAutoDestroyTopWindow(bool);
113
114     /// Returns the creation time parent of all bbtk windows 
115     /// (window can be reparented after creation)
116     static QWidget* GetTopWindow();
117     static bool TopWindowExists();
118     
119     static void IncNbWindowsAlive();
120     static void DecNbWindowsAlive();
121     static int  GetNbWindowsAlive();
122     static bool IsSomeWindowAlive();
123     
124     static void IncNbWindowsShown();
125     static void DecNbWindowsShown();
126     static int  GetNbWindowsShown();
127     static bool IsSomeWindowShown();
128
129     // BBTKWXSIG
130     static void AddSignalObserver(Slot_function_type);
131     // \BBTKWXSIG
132
133
134
135     static void CreateQtAppIfNeeded();
136     static void DestroyQtAppIfNeeded();
137
138   private:
139     static void CreateTopWindowIfNeeded();
140     static void DestroyTopWindowIfNeeded();
141
142     /// Sets the creation time parent of all bbtk windows
143     static void SetTopWindow(QWidget*);
144   }; // struct Qt
145   //==================================================================
146   
147
148
149
150
151   
152 } // namespace bbtk
153   
154
155 #endif // EO __bbtkQt_h_INCLUDED__