Got something working
[qtmeetings] / src / UserInterface / WindowManager.cpp
1 #include "WindowManager.h"
2
3 #include <QEvent>
4 #include <QDialog>
5 #include "ViewBase.h"
6 #include "PopUpMessageBox.h"
7
8 #include <QtDebug>
9
10 WindowManager::WindowManager( QWidget *aParent ) :
11                 QWidget( aParent ),
12                 iApplicationName( tr( "Qt Meetings" ) ),
13                 iCurrentView( 0 )
14 {
15         this->setWindowTitle( iApplicationName );
16 }
17
18 WindowManager::~WindowManager()
19 {
20         
21 }
22
23 void WindowManager::showView( ViewBase *view )
24 {
25         // The views parent must be WindowManager when it is displayed trough this
26         QWidget *parent = static_cast<QWidget *>(view->parent());
27         if ( parent != this )
28         {
29                 view->setParent( this );
30         }
31         
32         // Store the current view because it is hidden after the new view is shown
33         QWidget *oldView = iCurrentView;
34         
35         // If the new view is observed view we store the current into stack
36         // from which it is restored when the new view receives event we are
37         // listening to.
38         if ( view->viewMode() == ViewBase::ObservedView )
39         {
40                 iViewList.push( iCurrentView );
41         }
42         
43         // Make the new view visible and handle connections
44         iCurrentView = view;
45         connect( iCurrentView, SIGNAL( eventDetected() ), this, SLOT( viewEventDetected() ) );
46         connect( this, SIGNAL( viewResized(const QSize &, const QSize &) ), iCurrentView, SLOT( viewResized( const QSize &, const QSize & ) ) );
47         view->resize( this->size() );
48         
49         view->show();
50         
51         // Disconnect old connections and hide the view
52         if ( oldView != 0 )
53         {
54                 disconnect( oldView, SIGNAL( eventDetected() ), this, SLOT( viewEventDetected() ) );
55                 disconnect( this, SIGNAL( viewResized(const QSize &, const QSize &) ), oldView, SLOT( viewResized(const QSize &, const QSize &) ) );
56                 oldView->hide();
57         }
58         
59 }
60
61 void WindowManager::showDialog(QDialog *aDialog, bool blocking, bool aSendSignal)
62 {
63         // Handle dialog displaying
64         if ( aSendSignal ) emit dialogActivated();
65         if ( blocking )
66         {
67                 aDialog->exec();
68         }
69         else
70         {
71                 aDialog->show();
72         }
73         if ( aSendSignal ) emit dialogDeactivated();
74 }
75
76 void WindowManager::viewEventDetected()
77 {
78         
79         if ( iCurrentView != 0 )
80         {
81                 if ( iCurrentView->viewMode() == ViewBase::NormalView )
82                 {
83                         emit eventDetected();
84                 }
85                 else if ( iCurrentView->viewMode() == ViewBase::ObservedView )
86                 {
87                         if ( !iViewList.isEmpty() )
88                         {
89                                 ViewBase *previousView = static_cast<ViewBase *>( iViewList.pop() );
90                                 this->showView( previousView );
91                                 emit previousViewRestored();
92                         }
93                 }
94         }
95
96 }
97
98 bool WindowManager::event(QEvent *event)
99 {
100         if ( event->type() == QEvent::Resize )
101         {
102                 if ( iCurrentView != 0 )
103                 {
104                         QSize currentSize = iCurrentView->size();
105                         iCurrentView->setFixedSize( this->size() );
106                         emit viewResized( this->size(), currentSize );
107                 }
108         }
109         
110         return QWidget::event( event );
111 }
112
113 void WindowManager::error( const QString &aErrorMessage )
114 {
115         qDebug() << "WindowManager::error       ";
116
117         PopUpMessageBox *popup = PopUpMessageBox::error( 0, aErrorMessage );
118         if ( popup != 0 )
119         {
120                 showDialog( static_cast<QDialog *>( popup ), false );
121         }
122 }
123
124 void WindowManager::setFullscreen()
125 {
126         this->setWindowState( Qt::WindowFullScreen );
127         // Resize event handles the rest.
128 }