1 #include "WindowManager.h"
7 #include "PopUpMessageBox.h"
11 WindowManager::WindowManager( QWidget *aParent ) :
12 QMainWindow( aParent ),
13 iApplicationName( tr( "Qt Meetings" ) ),
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);
27 WindowManager::~WindowManager()
32 void WindowManager::showView( ViewBase *view )
34 // The views parent must be WindowManager when it is displayed trough this
35 QWidget *parent = static_cast<QWidget *>(view->parent());
38 view->setParent( this );
41 // Store the current view because it is hidden after the new view is shown
42 QWidget *oldView = iCurrentView;
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
47 if ( view->viewMode() == ViewBase::ObservedView )
49 iViewList.push( iCurrentView );
52 // Make the new view visible and handle connections
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)
60 view->resize(this->size());
64 // Disconnect old connections and hide the view
67 disconnect( oldView, SIGNAL( eventDetected() ), this, SLOT( viewEventDetected() ) );
68 disconnect( this, SIGNAL( viewResized(const QSize &, const QSize &) ), oldView, SLOT( viewResized(const QSize &, const QSize &) ) );
74 void WindowManager::showDialog(QDialog *aDialog, bool blocking, bool aSendSignal)
76 // Handle dialog displaying
77 if ( aSendSignal ) emit dialogActivated();
86 if ( aSendSignal ) emit dialogDeactivated();
89 void WindowManager::viewEventDetected()
92 if ( iCurrentView != 0 )
94 if ( iCurrentView->viewMode() == ViewBase::NormalView )
98 else if ( iCurrentView->viewMode() == ViewBase::ObservedView )
100 if ( !iViewList.isEmpty() )
102 ViewBase *previousView = static_cast<ViewBase *>( iViewList.pop() );
103 this->showView( previousView );
104 emit previousViewRestored();
111 bool WindowManager::event(QEvent *event)
113 if ( event->type() == QEvent::Resize )
115 if ( iCurrentView != 0 )
117 QSize currentSize = iCurrentView->size();
118 iCurrentView->setFixedSize( this->size() );
119 emit viewResized( this->size(), currentSize );
123 return QWidget::event( event );
126 void WindowManager::error( const QString &aErrorMessage )
128 qDebug() << "WindowManager::error ";
130 PopUpMessageBox *popup = PopUpMessageBox::error( 0, aErrorMessage );
133 showDialog( static_cast<QDialog *>( popup ), false );
137 void WindowManager::setFullscreen()
139 this->setWindowState( Qt::WindowFullScreen );
140 // Resize event handles the rest.