7be6080219870f2fb71ec4d12e90de897897f412
[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 &) ), iCurrentView, SLOT( viewResized( 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 &) ), oldView, SLOT( viewResized(const QSize &) ) );
56                 oldView->hide();
57         }
58         
59 }
60
61 void WindowManager::showDialog(QDialog *dialog)
62 {
63         // Handle dialog displaying
64         emit dialogActivated();
65         dialog->exec();
66         emit dialogDeactivated();
67 }
68
69 void WindowManager::viewEventDetected()
70 {
71         
72         if ( iCurrentView != 0 )
73         {
74                 if ( iCurrentView->viewMode() == ViewBase::NormalView )
75                 {
76                         emit eventDetected();
77                 }
78                 else if ( iCurrentView->viewMode() == ViewBase::ObservedView )
79                 {
80                         if ( !iViewList.isEmpty() )
81                         {
82                                 ViewBase *previousView = static_cast<ViewBase *>( iViewList.pop() );
83                                 this->showView( previousView );
84                                 emit previousViewRestored();
85                         }
86                 }
87         }
88
89 }
90
91 bool WindowManager::event(QEvent *event)
92 {
93         if ( event->type() == QEvent::Resize )
94         {
95                 if ( iCurrentView != 0 )
96                 {
97                         iCurrentView->setFixedSize( this->size() );
98                         emit viewResized( this->size() );
99                 }
100         }
101         
102         return QWidget::event( event );
103 }
104
105 void WindowManager::error( const QString &aErrorMessage )
106 {
107         qDebug() << "WindowManager::showErrorPopup";
108
109         showDialog( static_cast<QDialog *>( PopUpMessageBox::error( 0, aErrorMessage ) ) );
110 }
111
112 void WindowManager::setFullscreen()
113 {
114         this->setWindowState( Qt::WindowFullScreen );
115         // Resize event handles the rest.
116 }