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