#include "WindowManager.h"
-#include <QTimer>
-#include "Configuration.h"
-#include "DisplaySettings.h"
-#include "Meeting.h"
-#include "Room.h"
-#include "Clock.h"
-#include "WeeklyViewWidget.h"
-#include "RoomStatusIndicatorWidget.h"
-#include "MeetingInfoDialog.h"
+#include <QEvent>
+#include <QDialog>
+#include <QMenuBar>
+#include "ViewBase.h"
#include "PopUpMessageBox.h"
-#include "DeviceManager.h"
-#include "SettingsView.h"
-#include "ProgressBar.h"
#include <QtDebug>
-WindowManager::WindowManager( Configuration *aConfiguration ) :
- QObject(),
+WindowManager::WindowManager( QWidget *aParent ) :
+ QMainWindow( aParent ),
iApplicationName( tr( "Qt Meetings" ) ),
- iConfiguration( aConfiguration ),
- iWeeklyView( 0 ),
- iRoomStatusView( 0 ),
- iMeetingInfo( 0 ),
- iProgressBar( 0 ),
- iPasswordDialog( 0 )
+ iCurrentView( 0 )
{
- iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), aConfiguration );
- iWeeklyView->setWindowTitle( iApplicationName );
- connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
- connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SIGNAL( meetingActivated( Meeting * ) ) );
- connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) );
- connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) );
-
- showWeeklyView();
-
+ this->setWindowTitle( iApplicationName );
+ settingsAction = new QAction(tr("&Settings"), this);
+ closeAction = new QAction(tr("&Close"), this);
+ connect(settingsAction, SIGNAL(triggered()), this, SIGNAL(showSettingsClicked()));
+ connect(closeAction, SIGNAL(triggered()), this, SIGNAL(closeClicked()));
+ editMenu = menuBar()->addMenu(tr("&Edit"));
+ editMenu->addAction(settingsAction);
+ menuBar()->addMenu(editMenu);
+ menuBar()->addAction(closeAction);
}
WindowManager::~WindowManager()
{
- delete iWeeklyView;
- iWeeklyView = 0;
- delete iRoomStatusView;
- iRoomStatusView = 0;
- delete iMeetingInfo;
- iMeetingInfo = 0;
- delete iProgressBar;
- iProgressBar = 0;
- delete iPasswordDialog;
- iPasswordDialog = 0;
+
}
-void WindowManager::distributeDateTimeInfo( QDateTime aCurrentDateTime )
+void WindowManager::showView( ViewBase *view )
{
- if ( iRoomStatusView != 0 && iRoomStatusView->isActiveWindow() )
- {
- iRoomStatusView->setCurrentTime( aCurrentDateTime.time() );
- }
-
- if ( iWeeklyView != 0 && iWeeklyView->isActiveWindow() )
+ // The views parent must be WindowManager when it is displayed trough this
+ QWidget *parent = static_cast<QWidget *>(view->parent());
+ if ( parent != this )
{
- iWeeklyView->setCurrentDateTime( aCurrentDateTime );
+ view->setParent( this );
}
-}
-
-void WindowManager::roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aTime )
-{
- if ( iRoomStatusView == 0 )
+
+ // Store the current view because it is hidden after the new view is shown
+ QWidget *oldView = iCurrentView;
+
+ // If the new view is observed view we store the current into stack
+ // from which it is restored when the new view receives event we are
+ // listening to.
+ if ( view->viewMode() == ViewBase::ObservedView )
{
- iRoomStatusView = new RoomStatusIndicatorWidget( aRoom, aStatus, aTime, iConfiguration->displaySettings()->timeFormat() );
- iRoomStatusView->setWindowTitle( iApplicationName );
- connect( iRoomStatusView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
+ iViewList.push( iCurrentView );
}
- else
+
+ // Make the new view visible and handle connections
+ iCurrentView = view;
+ connect( iCurrentView, SIGNAL( eventDetected() ), this, SLOT( viewEventDetected() ) );
+ connect( this, SIGNAL( viewResized(const QSize &, const QSize &) ), iCurrentView, SLOT( viewResized( const QSize &, const QSize & ) ) );
+ if (((QWidget*)view) != this)
{
- iRoomStatusView->statusChanged( aStatus, aTime );
+ this->adjustSize();
}
- if ( !iWeeklyView->isVisible() && !iRoomStatusView->isVisible() )
+ view->resize(this->size());
+ //view->adjustSize();
+ view->show();
+
+ // Disconnect old connections and hide the view
+ if ( oldView != 0 )
{
- showRoomStatus();
+ disconnect( oldView, SIGNAL( eventDetected() ), this, SLOT( viewEventDetected() ) );
+ disconnect( this, SIGNAL( viewResized(const QSize &, const QSize &) ), oldView, SLOT( viewResized(const QSize &, const QSize &) ) );
+ oldView->hide();
}
+
}
-void WindowManager::showRoomStatus()
+void WindowManager::showDialog(QDialog *aDialog, bool blocking, bool aSendSignal)
{
- qDebug() << "WindowManager::showRoomStatus";
-
- if ( iRoomStatusView == 0 )
+ // Handle dialog displaying
+ if ( aSendSignal ) emit dialogActivated();
+ if ( blocking )
{
- emit roomStatusInfoNeeded( iWeeklyView->currentRoom() );
+ aDialog->exec();
}
else
{
- iRoomStatusView->show();
- if ( iWeeklyView->isVisible() )
- {
- iWeeklyView->hide();
- }
- }
-
- // closing/deleting meeting info dialog
- if ( iMeetingInfo != 0 )
- {
- iMeetingInfo->hide();
+ aDialog->show();
}
+ if ( aSendSignal ) emit dialogDeactivated();
}
-void WindowManager::showWeeklyView()
+void WindowManager::viewEventDetected()
{
- qDebug() << "WindowManager::showWeeklyView";
- if ( iRoomStatusView != 0 && iRoomStatusView->isVisible() )
+
+ if ( iCurrentView != 0 )
{
- iRoomStatusView->hide();
+ if ( iCurrentView->viewMode() == ViewBase::NormalView )
+ {
+ emit eventDetected();
+ }
+ else if ( iCurrentView->viewMode() == ViewBase::ObservedView )
+ {
+ if ( !iViewList.isEmpty() )
+ {
+ ViewBase *previousView = static_cast<ViewBase *>( iViewList.pop() );
+ this->showView( previousView );
+ emit previousViewRestored();
+ }
+ }
}
- iWeeklyView->show();
-}
-
-void WindowManager::fullScreen()
-{
- iRoomStatusView->setWindowState( Qt::WindowFullScreen );
- iWeeklyView->setWindowState( Qt::WindowFullScreen );
}
-void WindowManager::insertMeeting( Meeting *aMeeting )
+bool WindowManager::event(QEvent *event)
{
- iWeeklyView->insertMeeting( aMeeting );
-}
-
-void WindowManager::deleteMeeting( Meeting *aMeeting )
-{
- iWeeklyView->deleteMeeting( aMeeting );
-}
-
-void WindowManager::showMeetingInfo( Meeting *aMeeting )
-{
- iMeetingInfo = new MeetingInfoDialog( aMeeting );
- // Display modal dialog
- iMeetingInfo->exec();
-
- delete iMeetingInfo;
- iMeetingInfo = 0;
-}
-
-void WindowManager::showSettingsView()
-{
- // TODO : give the Torspo for the person who was responsible to write this method
-}
-
-WeeklyViewWidget * WindowManager::weeklyView()
-{
- return iWeeklyView;
+ if ( event->type() == QEvent::Resize )
+ {
+ if ( iCurrentView != 0 )
+ {
+ QSize currentSize = iCurrentView->size();
+ iCurrentView->setFixedSize( this->size() );
+ emit viewResized( this->size(), currentSize );
+ }
+ }
+
+ return QWidget::event( event );
}
void WindowManager::error( const QString &aErrorMessage )
{
- qDebug() << "WindowManager::showErrorPopup";
-
- PopUpMessageBox::error( 0, aErrorMessage );
-}
-
-void WindowManager::showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage )
-{
- iPasswordDialog = new PasswordDialog( aAdminPassword, aMessage );
- connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ),
- this, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ) );
- iPasswordDialog->show();
-}
+ qDebug() << "WindowManager::error ";
-void WindowManager::closePasswordDialog()
-{
- iPasswordDialog->close();
- delete iPasswordDialog;
- iPasswordDialog = 0;
-}
-
-void WindowManager::showProgressBar( const QString &aText )
-{
- qDebug() << "WindowManager::showProgressBar( const QString & )";
- if( iProgressBar == 0 ) {
- iProgressBar = new ProgressBar( aText );
- iProgressBar->show();
- connect( iProgressBar, SIGNAL( cancel() ), this, SIGNAL( progressBarCancelled() ) );
+ PopUpMessageBox *popup = PopUpMessageBox::error( 0, aErrorMessage );
+ if ( popup != 0 )
+ {
+ showDialog( static_cast<QDialog *>( popup ), false );
}
}
-void WindowManager::closeProgressBar()
+void WindowManager::setFullscreen()
{
- iProgressBar->close();
- delete iProgressBar;
- iProgressBar = 0;
+ this->setWindowState( Qt::WindowFullScreen );
+ // Resize event handles the rest.
}