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