From e6424950847505ac767d517f17df7830ad34b2ea Mon Sep 17 00:00:00 2001 From: Mikko Siren Date: Tue, 26 May 2009 10:43:41 +0300 Subject: [PATCH] ViewBase added and major changes to use the new architecture --- QtMeetings.pro | 4 +- src/BusinessLogic/Engine.cpp | 297 ++++++++++++++------ src/BusinessLogic/Engine.h | 76 ++++- src/UserInterface/Components/MeetingRoomCombo.cpp | 2 +- src/UserInterface/Components/MeetingRoomCombo.h | 3 +- src/UserInterface/Components/TimeDisplayWidget.cpp | 2 +- src/UserInterface/Components/TimeDisplayWidget.h | 3 +- src/UserInterface/Views/MeetingInfoDialog.cpp | 27 +- src/UserInterface/Views/MeetingInfoDialog.h | 5 +- .../Views/RoomStatusIndicatorWidget.cpp | 2 +- .../Views/RoomStatusIndicatorWidget.h | 6 +- src/UserInterface/Views/SettingsView.cpp | 20 +- src/UserInterface/Views/SettingsView.h | 13 +- src/UserInterface/Views/ViewBase.cpp | 77 +++++ src/UserInterface/Views/ViewBase.h | 69 +++++ src/UserInterface/Views/WeeklyViewWidget.cpp | 28 +- src/UserInterface/Views/WeeklyViewWidget.h | 15 +- src/UserInterface/WindowManager.cpp | 243 +++++----------- src/UserInterface/WindowManager.h | 199 ++++--------- 19 files changed, 648 insertions(+), 443 deletions(-) create mode 100644 src/UserInterface/Views/ViewBase.cpp create mode 100644 src/UserInterface/Views/ViewBase.h diff --git a/QtMeetings.pro b/QtMeetings.pro index f223557..85e43bd 100644 --- a/QtMeetings.pro +++ b/QtMeetings.pro @@ -43,7 +43,8 @@ HEADERS += src/UserInterface/Utils/ProgressBar.h \ src/UserInterface/Views/WeeklyViewWidget.h \ src/UserInterface/Views/MeetingInfoDialog.h \ src/UserInterface/Views/SettingsView.h \ - src/UserInterface/WindowManager.h + src/UserInterface/WindowManager.h \ + src/UserInterface/Views/ViewBase.h SOURCES += src/UserInterface/Utils/ProgressBar.cpp \ src/Domain/Room.cpp \ src/Domain/Meeting.cpp \ @@ -75,6 +76,7 @@ SOURCES += src/UserInterface/Utils/ProgressBar.cpp \ src/UserInterface/Views/MeetingInfoDialog.cpp \ src/UserInterface/Views/SettingsView.cpp \ src/UserInterface/WindowManager.cpp \ + src/UserInterface/Views/ViewBase.cpp \ src/main.cpp RESOURCES += resources/BusinessLogic.qrc \ resources/UserInterface.qrc diff --git a/src/BusinessLogic/Engine.cpp b/src/BusinessLogic/Engine.cpp index 2f9d3cd..0b68a03 100644 --- a/src/BusinessLogic/Engine.cpp +++ b/src/BusinessLogic/Engine.cpp @@ -5,10 +5,14 @@ #include "Configuration.h" #include "DisplaySettings.h" #include "CommunicationManager.h" -#include "DeviceManager.h" +// #include "DeviceManager.h" #include "Clock.h" #include "ErrorMapper.h" #include "WeeklyViewWidget.h" +#include "SettingsView.h" +#include "RoomStatusIndicatorWidget.h" +#include "PasswordDialog.h" +#include "MeetingInfoDialog.h" #include #include @@ -18,65 +22,52 @@ QTime Engine::endOfTheDay = QTime( 23, 59, 0, 0 ); // end of the day is 11:59pm const int IDLE_TIME_MULTIPLIER = 60000; // Multiplies milliseconds to minutes +// Macro to help deleting objects. This could be global. +#define QT_DELETE(X) \ + if ( X != 0 ) \ + { \ + delete X; \ + X = 0; \ + } + + Engine::Engine() : - iClock( 0 ), iConfiguration( Configuration::instance() ), iCommunication( 0 ) + iClock( 0 ), iConfiguration( 0 ), iCommunication( 0 ) { qDebug() << "Engine::Engine()"; - // if reading of configuration fails, signal that initialization failed - if ( iConfiguration == 0 ) - { - QTimer::singleShot( 0, this, SLOT( closeApplication() ) ); - return; - } - - //initialize window manager - iWindowManager = new WindowManager( iConfiguration ); - connect( iWindowManager, SIGNAL( roomStatusInfoNeeded( Room * ) ), this, SLOT( roomStatusInfoNeeded( Room * ) ) ); - connect( iWindowManager, SIGNAL( observedEventDetected() ), this, SLOT( observedEventDetected() ) ); - connect( iWindowManager, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( fetchMeetingDetails( Meeting * ) ) ); - connect( iWindowManager, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) ) ); - connect( iWindowManager, SIGNAL( shownWeekChanged( QDate ) ), this, SLOT( shownWeekChanged( QDate ) ) ); - connect( iWindowManager, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), - this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) ); - - // initialize communication - iCommunication = new CommunicationManager( *(iConfiguration->connectionSettings()) ); - connect( iCommunication, SIGNAL( error( int, CommunicationManager::CommunicationType ) ), - this, SLOT( errorHandler( int ) ) ); - connect( iCommunication, SIGNAL( meetingsFetched( const QList& ) ), - this, SLOT( meetingsFetched( const QList& ) ) ); - connect( iCommunication, SIGNAL( meetingDetailsFetched( Meeting& ) ), - this, SLOT( meetingDetailsFetched( Meeting& ) ) ); - + initConfiguration(); + initDevice(); + initCommunication(); + initUserInterface(); + //initialize idle time counter iIdleTimeCounter = new QTimer(); iIdleTimeCounter->setSingleShot( true ); - iIdleTimeCounter->setInterval( IDLE_TIME_MULTIPLIER * iConfiguration->displaySettings()->screensaver() ); + // iIdleTimeCounter->setInterval( IDLE_TIME_MULTIPLIER * iConfiguration->displaySettings()->screensaver() ); + iIdleTimeCounter->setInterval( 10000 ); iIdleTimeCounter->start(); - connect( iIdleTimeCounter, SIGNAL( timeout() ), iWindowManager, SLOT( showRoomStatus() ) ); + // connect( iIdleTimeCounter, SIGNAL( timeout() ), iWindowManager, SLOT( showRoomStatus() ) ); + connect( iIdleTimeCounter, SIGNAL( timeout() ), this, SLOT( idleTimerTimeout() ) ); // create application clock iClock = new Clock; connect( iClock, SIGNAL( tick( QDateTime ) ), this, SLOT( checkStatusOfAllRooms() ) ); - connect( iClock, SIGNAL( tick( QDateTime ) ), iWindowManager, SLOT( distributeDateTimeInfo( QDateTime ) ) ); + // connect( iClock, SIGNAL( tick( QDateTime ) ), iWindowManager, SLOT( distributeDateTimeInfo( QDateTime ) ) ); iAutoRefresh = new QTimer; iAutoRefresh->setInterval( iConfiguration->connectionSettings()->refreshInterval() * 1000 ); iAutoRefresh->start(); connect( iAutoRefresh, SIGNAL( timeout() ), iAutoRefresh, SLOT( start() ) ); - connect( iAutoRefresh, SIGNAL( timeout() ), this, SLOT( fetchMeetings() ) ); - - // create device manager - iDevice = new DeviceManager( iConfiguration->startupSettings() ); - connect( iDevice, SIGNAL( error( int, const QString& ) ), this, SLOT( errorHandler( int, const QString& ) ) ); - connect( iDevice, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ), - this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) ); - iDevice->initDeviceManager(); +// connect( iAutoRefresh, SIGNAL( timeout() ), this, SLOT( fetchMeetings() ) ); if( iDevice->currentOperationMode() == DeviceManager::KioskMode ) - iWindowManager->fullScreen(); + { + iWindowManager->setFullscreen(); + } + connectSignals(); + QTimer::singleShot( 0, this, SLOT( fetchMeetings() ) ); // TODO: continue implementation @@ -87,15 +78,21 @@ Engine::~Engine() qDebug() << "Engine::~Engine()"; while ( !iMeetings.isEmpty() ) delete iMeetings.takeFirst(); - iIdleTimeCounter->stop(); - delete iIdleTimeCounter; - iIdleTimeCounter = 0; - delete iWindowManager; - iWindowManager = 0; - delete iClock; - iClock = 0; - delete iDevice; - iDevice = 0; + + if ( iIdleTimeCounter != 0 ) + { + iIdleTimeCounter->stop(); + delete iIdleTimeCounter; + iIdleTimeCounter = 0; + } + QT_DELETE( iClock ); + QT_DELETE( iDevice ); + + QT_DELETE( iRoomStatusIndicator ); + QT_DELETE( iSettingsView ); + QT_DELETE( iWeeklyView ); + QT_DELETE( iPasswordDialog ); + QT_DELETE( iWindowManager ); } void Engine::closeApplication() @@ -105,19 +102,6 @@ void Engine::closeApplication() QTimer::singleShot( 1000, QApplication::instance(), SLOT( quit() ) ); } -void Engine::observedEventDetected() -{ - qDebug() << "Engine::observedEventDetected()"; - iWindowManager->showWeeklyView(); - // prepare to restart idle counter - if ( iIdleTimeCounter->isActive() ) - { - iIdleTimeCounter->stop(); - } - // (re)start idle counter - iIdleTimeCounter->start(); -} - Room* Engine::defaultRoom() { qDebug() << "Engine::defaultRoom()"; @@ -126,7 +110,7 @@ Room* Engine::defaultRoom() void Engine::checkStatusOfAllRooms() { - qDebug() << "Engine::checkStatusOfAllRooms()"; +// qDebug() << "Engine::checkStatusOfAllRooms()"; // iterate trough on the rooms for ( int i = 0; i < iConfiguration->rooms().count(); i++ ) { @@ -137,7 +121,7 @@ void Engine::checkStatusOfAllRooms() int Engine::indexOfMeetingAt( Room *aRoom, QDateTime aAt ) { - qDebug() << "Engine::indexOfMeetingAt( Room *, QDateTime )"; +// qDebug() << "Engine::indexOfMeetingAt( Room *, QDateTime )"; for ( int i = 0; i < iMeetings.count(); i++ ) { // exchange server ensures that there is only one meeting in a room at a specified time @@ -153,7 +137,7 @@ int Engine::indexOfMeetingAt( Room *aRoom, QDateTime aAt ) int Engine::indexOfMeetingAfter( Room *aRoom, QDateTime aAfter ) { - qDebug() << "Engine::indexOfMeetingAfter( Room *, QDateTime )"; +// qDebug() << "Engine::indexOfMeetingAfter( Room *, QDateTime )"; // seeks for the next meeting on the SAME DAY int min = -1; for ( int i = 0; i < iMeetings.count(); i++ ) @@ -176,7 +160,7 @@ int Engine::indexOfMeetingAfter( Room *aRoom, QDateTime aAfter ) void Engine::roomStatusInfoNeeded( Room *aRoom ) { - qDebug() << "Engine::roomStatusInfoNeeded( Room * )"; +// qDebug() << "Engine::roomStatusInfoNeeded( Room * )"; if ( aRoom == 0 ) { return; @@ -193,8 +177,8 @@ void Engine::roomStatusInfoNeeded( Room *aRoom ) (( indexOfNextMeeting != -1 ) ? iMeetings.at( indexOfNextMeeting )->startsAt().time() : Engine::endOfTheDay ); //currently works only for deafult room - if( aRoom->equals( *(defaultRoom() ) ) ) - iWindowManager->roomStatusChanged( aRoom, status, until ); +// if( aRoom->equals( *(defaultRoom() ) ) ) +// iWindowManager->roomStatusChanged( aRoom, status, until ); } void Engine::fetchMeetings() @@ -236,7 +220,7 @@ void Engine::meetingsFetched( const QList &aMeetings ) Meeting* m = new Meeting( *(aMeetings.at( i )) ); iMeetings.append( m ); // and signal the changes - iWindowManager->insertMeeting( m ); + iWeeklyView->insertMeeting( m ); } } @@ -248,7 +232,7 @@ void Engine::meetingsFetched( const QList &aMeetings ) { Meeting* m = iMeetings.takeAt( i ); // signal the changes - iWindowManager->deleteMeeting( m ); + iWeeklyView->deleteMeeting( m ); // delete the meeting from the local list delete m; } @@ -261,7 +245,13 @@ void Engine::meetingsFetched( const QList &aMeetings ) void Engine::meetingDetailsFetched( Meeting &aDetailedMeeting ) { qDebug() << "Engine::meetingDetailsFetched( Meeting & )"; - iWindowManager->showMeetingInfo( &aDetailedMeeting ); + + if ( iMeetingInfoDialog != 0 ) + { + iMeetingInfoDialog->setMeeting( &aDetailedMeeting ); + iWindowManager->showDialog( iMeetingInfoDialog ); + } + } void Engine::errorHandler( int aCode, const QString &aAddInfo ) @@ -270,15 +260,15 @@ void Engine::errorHandler( int aCode, const QString &aAddInfo ) // inform UI about the problem if( aCode >= 100 && aCode <= 110 ) qDebug() << "CommunicationManager signaled an error:" << aCode; - iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) ); +// iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) ); } void Engine::currentRoomChanged( Room *aCurrentRoom ) { qDebug() << "Engine::currentRoomChanged to " << aCurrentRoom->name(); - QDateTime from( iWindowManager->weeklyView()->beginnigOfShownWeek() ); - QDateTime to( from.addDays( 8 ) ); - fetchMeetings( from, to, aCurrentRoom ); +// QDateTime from( iWindowManager->weeklyView()->beginnigOfShownWeek() ); +// QDateTime to( from.addDays( 8 ) ); +// fetchMeetings( from, to, aCurrentRoom ); } void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn ) @@ -293,7 +283,7 @@ void Engine::shownWeekChanged( QDate aFrom ) QDateTime from( aFrom ); QDateTime to( aFrom.addDays( 7 ), QTime( 23, 59 ) ); qDebug() << "Engine::shownWeekChanged " << aFrom.toString( "d.m. h:mm" ) << " to " << to.toString( "d.m. h:mm" ); - fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() ); +// fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() ); } void Engine::changeModeOrdered( DeviceManager::OperationMode aMode ) @@ -301,29 +291,30 @@ void Engine::changeModeOrdered( DeviceManager::OperationMode aMode ) qDebug() << "Engine::changeModeOrdered( DeviceManager::OperationMode )"; QString message = tr( "You are about to change operation mode to %1." ) .arg( iDevice->operationModeToString( aMode ) ); - - iWindowManager->showPasswordDialog( iConfiguration->adminPassword(), message ); + + // iPasswordDialog->update( message ); + iWindowManager->showDialog( static_cast( iPasswordDialog ) ); } void Engine::passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus ) { qDebug() << "Engine::passwordEntered( PasswordDialog::PasswordStatus )"; - iWindowManager->closePasswordDialog(); +// iWindowManager->closePasswordDialog(); switch ( aPasswordStatus ) { case PasswordDialog::Correct : { - iWindowManager->showProgressBar( "Changing current operation mode." ); - connect( iWindowManager, SIGNAL( progressBarCancelled() ), this, SLOT( progressBarCancelled() ) ); - connect( iDevice, SIGNAL( changingMode( const QString & ) ), - iWindowManager, SLOT( updateProgressBar( const QString & ) ) ); +// iWindowManager->showProgressBar( "Changing current operation mode." ); +// connect( iWindowManager, SIGNAL( progressBarCancelled() ), this, SLOT( progressBarCancelled() ) ); +// connect( iDevice, SIGNAL( changingMode( const QString & ) ), +// iWindowManager, SLOT( updateProgressBar( const QString & ) ) ); iDevice->changeMode( true ); break; } case PasswordDialog::Incorrect : { - iWindowManager->error( tr( "Incorrect password." ) ); +// iWindowManager->error( tr( "Incorrect password." ) ); iDevice->changeMode( false ); break; } @@ -338,6 +329,142 @@ void Engine::progressBarCancelled() { qDebug() << "Engine::progressBarCancelled()"; //TODO: cancel the on-going event - iWindowManager->closeProgressBar(); +// iWindowManager->closeProgressBar(); iDevice->changeMode( false ); } + +void Engine::initUserInterface() +{ + qDebug() << "[Engine::initUserInterface] "; + // Initialize the window manager and connect what ever signals can be connected + iWindowManager = new WindowManager; + connect( iWindowManager, SIGNAL( eventDetected() ), this, SLOT( handleViewEvent() ) ); + connect( iWindowManager, SIGNAL( previousViewRestored() ), this, SLOT( previousViewRestored() ) ); + connect( iWindowManager, SIGNAL( dialogActivated() ), this, SLOT( dialogActivated() ) ); + connect( iWindowManager, SIGNAL( dialogDeactivated() ), this, SLOT( dialogDeactivated() ) ); + + // Initialize the weekly view and connect what ever signals can be connected at this stage + iWeeklyView = new WeeklyViewWidget(QDateTime::currentDateTime(), iConfiguration); + connect( iWeeklyView, SIGNAL( settingsButtonClicked() ), this, SLOT( settingsViewRequested() ) ); + connect( iWeeklyView, SIGNAL( currentRoomChange( Room * ) ) , this, SLOT( currentRoomChange( Room * ) ) ); + connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( fetchMeetingDetails( Meeting * ) ) ) ; + connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ) , this, SLOT( shownWeekChanged( QDate ) ) ); + + // Initialize the settings view + iSettingsView = new SettingsView; + connect( iSettingsView, SIGNAL( okClicked() ) , this, SLOT( settingsOkClicked() ) ); + + // Initialize the room status indicator + iRoomStatusIndicator = new RoomStatusIndicatorWidget( defaultRoom(), Room::FreeStatus, QTime::currentTime(), iConfiguration->displaySettings()->dateFormat() ); + + // Create password dialog + iPasswordDialog = new PasswordDialog( iConfiguration->adminPassword(), tr("No Text Set"), tr("Title") ); + connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) ); + + // Show the UI + iWindowManager->setWindowState( Qt::WindowMaximized ); + iWindowManager->show(); + iWindowManager->showView( iWeeklyView ); + + qDebug() << "[Engine::initUserInterface] "; +} + +void Engine::settingsViewRequested() +{ + if ( iSettingsView != 0 ) + { + iWindowManager->showView( static_cast( iSettingsView ) ); + // Room status indicator will not be shown when settings view is active + iIdleTimeCounter->stop(); + } +} + +void Engine::handleViewEvent() +{ + qDebug() << "[Engine::handleViewEvent] "; + if ( iIdleTimeCounter != 0 ) + { + // Restart the idle time counter when view event is received + iIdleTimeCounter->stop(); + iIdleTimeCounter->start(); + } +} + +void Engine::initConfiguration() +{ + iConfiguration = Configuration::instance(); + if ( iConfiguration == 0 ) + { + QTimer::singleShot( 0, this, SLOT( closeApplication() ) ); + } +} + +void Engine::idleTimerTimeout() +{ + if ( iRoomStatusIndicator != 0 ) + { + iWindowManager->showView( static_cast( iRoomStatusIndicator ) ); + } +} + +void Engine::settingsOkClicked() +{ + if ( iWeeklyView != 0 ) + { + iWindowManager->showView( iWeeklyView ); + // Start the idle time counter when we return to the main view + iIdleTimeCounter->start(); + } +} + +void Engine::connectSignals() +{ + // Handle weekly view signal connections + connect( iClock, SIGNAL( tick( QDateTime ) ), iWeeklyView, SLOT( setCurrentDateTime( QDateTime ) ) ); +} + +void Engine::initCommunication() +{ + // initialize communication + iCommunication = new CommunicationManager( *(iConfiguration->connectionSettings()) ); + connect( iCommunication, SIGNAL( error( int, CommunicationManager::CommunicationType ) ), + this, SLOT( errorHandler( int ) ) ); + connect( iCommunication, SIGNAL( meetingsFetched( const QList& ) ), + this, SLOT( meetingsFetched( const QList& ) ) ); + connect( iCommunication, SIGNAL( meetingDetailsFetched( Meeting& ) ), + this, SLOT( meetingDetailsFetched( Meeting& ) ) ); +} + +void Engine::initDevice() +{ + // create device manager + iDevice = new DeviceManager( iConfiguration->startupSettings() ); + connect( iDevice, SIGNAL( error( int, const QString& ) ), this, SLOT( errorHandler( int, const QString& ) ) ); + connect( iDevice, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ), + this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) ); + iDevice->initDeviceManager(); +} + +void Engine::dialogActivated() +{ + if ( iIdleTimeCounter != 0 ) + { + iIdleTimeCounter->stop(); + } +} + +void Engine::dialogDeactivated() +{ + if ( iIdleTimeCounter != 0 ) + { + iIdleTimeCounter->start(); + } +} + +void Engine::previousViewRestored() +{ + if ( iIdleTimeCounter != 0 ) + { + iIdleTimeCounter->start(); + } +} \ No newline at end of file diff --git a/src/BusinessLogic/Engine.h b/src/BusinessLogic/Engine.h index 457d6ba..4695738 100644 --- a/src/BusinessLogic/Engine.h +++ b/src/BusinessLogic/Engine.h @@ -5,13 +5,20 @@ #include #include "Room.h" #include "WindowManager.h" +#include "DeviceManager.h" +#include "PasswordDialog.h" class QTimer; class Clock; class Configuration; class CommunicationManager; class Meeting; -class DeviceManager; +// class DeviceManager; +class WeeklyViewWidget; +class SettingsView; +class RoomStatusIndicatorWidget; +class PasswordDialog; +class MeetingInfoDialog; //! BusinessLogic class. Contains all the business logic of the application. /*! @@ -53,11 +60,6 @@ private slots: * \param aRoom The room which availability information is needed. */ void roomStatusInfoNeeded( Room *aRoom ); - //! Slot. Indicates that some user event has happened. - /*! - * Slot. Indicates that some user event has happened. - */ - void observedEventDetected(); //! Slot. Asks the communication to fetch new meeting data. /*! * Slot. Asks the communication to fetch new meeting data. @@ -126,6 +128,29 @@ private slots: */ void progressBarCancelled(); + void handleViewEvent(); + void previousViewRestored(); + void settingsViewRequested(); + + void idleTimerTimeout(); + + void settingsOkClicked(); + + //! Slot for dialog activation signal. + /*! + * This slot is used to inform that dialog is activated. It stops + * the idle time counter so screensaver is not activated while the + * dialog is displayed. + */ + void dialogActivated(); + //! Slot for dialog deactivation signal. + /*! + * This slot is used to inform that dialog is deactivated. It restarts + * the idle time counter so that the screensaver is being activated again + * as needed. + */ + void dialogDeactivated(); + private: //! Provides the index of the Meeting instance which is at the specified time. /*! @@ -161,11 +186,50 @@ private: * \param aIn The room which meetings need to be fetched. */ void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn ); + //! Initialize configuration package. + /*! + * This method initializes configuration classes and + * connects signals from and to the engine. + */ + void initConfiguration(); + //! Initialize device package. + /*! + * This method initializes device manager and + * connects signals from and to the engine. + */ + void initDevice(); + //! Initialize communication package. + /*! + * This method initializes the communication manager and + * connects signals from and to the engine. + */ + void initCommunication(); + //! Initialize user interface package. + /*! + * This method initializes the user interface and + * connects signals from and to the engine. This method + * makes the window manager visible and shows weekly + * view as the first view. + */ + void initUserInterface(); + //! Connects signal between objects. + /*! + * Signals that could not be connected while initializing different + * packages are connected here. + */ + void connectSignals(); private: static QTime endOfTheDay; WindowManager *iWindowManager; + WeeklyViewWidget *iWeeklyView; + SettingsView *iSettingsView; + RoomStatusIndicatorWidget *iRoomStatusIndicator; + + PasswordDialog *iPasswordDialog; + MeetingInfoDialog *iMeetingInfoDialog; + QTimer *iIdleTimeCounter; Clock *iClock; Configuration *iConfiguration; diff --git a/src/UserInterface/Components/MeetingRoomCombo.cpp b/src/UserInterface/Components/MeetingRoomCombo.cpp index 4b7a128..fad0493 100644 --- a/src/UserInterface/Components/MeetingRoomCombo.cpp +++ b/src/UserInterface/Components/MeetingRoomCombo.cpp @@ -7,7 +7,7 @@ #include MeetingRoomCombo::MeetingRoomCombo( QList aRooms, QWidget *aParent ) : - ObservedWidget( aParent ) + QWidget( aParent ) { iRooms = aRooms; qSort( iRooms.begin(), iRooms.end(), Room::caseInsensitiveLessThan ); diff --git a/src/UserInterface/Components/MeetingRoomCombo.h b/src/UserInterface/Components/MeetingRoomCombo.h index 5c7120a..01a858e 100644 --- a/src/UserInterface/Components/MeetingRoomCombo.h +++ b/src/UserInterface/Components/MeetingRoomCombo.h @@ -1,7 +1,6 @@ #ifndef MEETINGROOMCOMBO_H_ #define MEETINGROOMCOMBO_H_ -#include "ObservedWidget.h" #include #include @@ -13,7 +12,7 @@ class Room; * Userinterface class. Displays a list of selectable meeting rooms. Customized QComboBox which hides * all the not needed functionality of the "base" class. */ -class MeetingRoomCombo : public ObservedWidget +class MeetingRoomCombo : public QWidget { Q_OBJECT diff --git a/src/UserInterface/Components/TimeDisplayWidget.cpp b/src/UserInterface/Components/TimeDisplayWidget.cpp index 8267ca0..9fd2fab 100644 --- a/src/UserInterface/Components/TimeDisplayWidget.cpp +++ b/src/UserInterface/Components/TimeDisplayWidget.cpp @@ -1,7 +1,7 @@ #include "TimeDisplayWidget.h" TimeDisplayWidget::TimeDisplayWidget( QTime aNow, QWidget *aParent ) : - ObservedWidget( aParent ) + QWidget( aParent ) { iCurrentTime = aNow; diff --git a/src/UserInterface/Components/TimeDisplayWidget.h b/src/UserInterface/Components/TimeDisplayWidget.h index a1bcfd4..5f4e3a4 100644 --- a/src/UserInterface/Components/TimeDisplayWidget.h +++ b/src/UserInterface/Components/TimeDisplayWidget.h @@ -1,7 +1,6 @@ #ifndef TIMEDISPLAYWIDGET_H_ #define TIMEDISPLAYWIDGET_H_ -#include "ObservedWidget.h" #include #include #include @@ -11,7 +10,7 @@ * Abstact. UserInterface class. Offers basic functionality to display time. Inherited by * DigitalTimeDisplayWidget. */ -class TimeDisplayWidget : public ObservedWidget +class TimeDisplayWidget : public QWidget { Q_OBJECT diff --git a/src/UserInterface/Views/MeetingInfoDialog.cpp b/src/UserInterface/Views/MeetingInfoDialog.cpp index 95e2cce..3250e82 100644 --- a/src/UserInterface/Views/MeetingInfoDialog.cpp +++ b/src/UserInterface/Views/MeetingInfoDialog.cpp @@ -13,6 +13,26 @@ MeetingInfoDialog::MeetingInfoDialog( Meeting *aMeeting, QWidget *aParent ) : { setWindowTitle( tr( "Details" ) ); + if ( aMeeting != 0 ) + { + createDialogView( aMeeting ); + } + + setMinimumWidth( MeetingInfoDialog::width ); + setMinimumHeight( MeetingInfoDialog::height ); +} + +MeetingInfoDialog::~MeetingInfoDialog() +{ +} + +void MeetingInfoDialog::setMeeting(Meeting *aMeeting) +{ + createDialogView( aMeeting ); +} + +void MeetingInfoDialog::createDialogView(Meeting *aMeeting) +{ QFont normalFont; normalFont.setPointSize( 11 ); @@ -75,11 +95,4 @@ MeetingInfoDialog::MeetingInfoDialog( Meeting *aMeeting, QWidget *aParent ) : layout->addStretch(); layout->addLayout( buttonLayout ); setLayout( layout ); - - setMinimumWidth( MeetingInfoDialog::width ); - setMinimumHeight( MeetingInfoDialog::height ); -} - -MeetingInfoDialog::~MeetingInfoDialog() -{ } diff --git a/src/UserInterface/Views/MeetingInfoDialog.h b/src/UserInterface/Views/MeetingInfoDialog.h index a62cb32..86c33d1 100644 --- a/src/UserInterface/Views/MeetingInfoDialog.h +++ b/src/UserInterface/Views/MeetingInfoDialog.h @@ -19,11 +19,14 @@ public: * \param aMeeting The Meeting instance which is needed to be presented in detail. * \param aParent Pointer to the parent widget. Optional. */ - MeetingInfoDialog( Meeting *aMeeting, QWidget *aParent = 0 ); + MeetingInfoDialog( Meeting *aMeeting = 0, QWidget *aParent = 0 ); //! Destructor. virtual ~MeetingInfoDialog(); + + void setMeeting( Meeting * aMeeting ); private: + void createDialogView(Meeting *aMeeting); static const int width = 200; static const int height = 400; diff --git a/src/UserInterface/Views/RoomStatusIndicatorWidget.cpp b/src/UserInterface/Views/RoomStatusIndicatorWidget.cpp index 7421a47..c903bc0 100644 --- a/src/UserInterface/Views/RoomStatusIndicatorWidget.cpp +++ b/src/UserInterface/Views/RoomStatusIndicatorWidget.cpp @@ -11,7 +11,7 @@ QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0 ); RoomStatusIndicatorWidget::RoomStatusIndicatorWidget( Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent ) : - ObservedWidget( aParent ), iTimeFormat( aTimeFormat ) + ViewBase( ViewBase::ObservedView, aParent ), iTimeFormat( aTimeFormat ) { QFont importantTextFont; //importantTextFont.setBold( true ); diff --git a/src/UserInterface/Views/RoomStatusIndicatorWidget.h b/src/UserInterface/Views/RoomStatusIndicatorWidget.h index 615051e..96c4235 100644 --- a/src/UserInterface/Views/RoomStatusIndicatorWidget.h +++ b/src/UserInterface/Views/RoomStatusIndicatorWidget.h @@ -1,7 +1,7 @@ #ifndef ROOMSTATUSINDICATORWIDGET_H_ #define ROOMSTATUSINDICATORWIDGET_H_ -#include "ObservedWidget.h" +#include "ViewBase.h" #include #include #include @@ -19,7 +19,7 @@ class TimeDisplayWidget; * and disappears if there is any. Its function is to behave like a screen saver on one hand, and * to provide details about the current availability on the other hand. */ -class RoomStatusIndicatorWidget : public ObservedWidget +class RoomStatusIndicatorWidget : public ViewBase { Q_OBJECT @@ -55,6 +55,8 @@ public slots: * \param aUntil The new time until the specified status is valid. */ void statusChanged( const Room::Status aStatus, const QTime aUntil ); + + void viewResized(const QSize &size) { } private: //! Translates the status into human readable text. diff --git a/src/UserInterface/Views/SettingsView.cpp b/src/UserInterface/Views/SettingsView.cpp index caa5cfe..863d84e 100644 --- a/src/UserInterface/Views/SettingsView.cpp +++ b/src/UserInterface/Views/SettingsView.cpp @@ -24,7 +24,7 @@ #include SettingsView::SettingsView( QWidget *aParent ) : - ObservedWidget( aParent ) + ViewBase( ViewBase::NormalView, aParent ) { qDebug() << "SettingsView::ctor invoked"; // Prepare the tabbed view @@ -57,8 +57,8 @@ SettingsView::SettingsView( QWidget *aParent ) : setLayout( mainLayout ); // Handle component connections - connect( iOkButton, SIGNAL( pressed() ), this, SLOT( okClicked() ) ); - connect( iCancelButton, SIGNAL( pressed() ), this, SLOT( cancelClicked() ) ); + connect( iOkButton, SIGNAL( clicked() ), this, SLOT( handleOkClicked() ) ); + connect( iCancelButton, SIGNAL( clicked() ), this, SLOT( cancelClicked() ) ); } SettingsView::~SettingsView() @@ -389,7 +389,7 @@ QWidget *SettingsView::initKioskModeTab() return widget; } -void SettingsView::okClicked() +void SettingsView::handleOkClicked() { qDebug() << "[SettingsView::okClicked] "; @@ -409,8 +409,11 @@ void SettingsView::okClicked() bool powerSaveEnabled = iPowerSaveEnabled->isChecked(); // TODO : Set the values to configuration and save it + + // Emit the signal to notify that ok is pressed and data is saved. + emit okClicked(); - close(); +// close(); } void SettingsView::cancelClicked() @@ -418,3 +421,10 @@ void SettingsView::cancelClicked() qDebug() << "[SettingsView::cancelClicked] "; close(); } + +void SettingsView::viewResized(const QSize &size) +{ + qDebug() << "[SettingsView::viewResized] "; + + qDebug() << "[SettingsView::viewResized] "; +} \ No newline at end of file diff --git a/src/UserInterface/Views/SettingsView.h b/src/UserInterface/Views/SettingsView.h index 8b9bbeb..3e04eee 100644 --- a/src/UserInterface/Views/SettingsView.h +++ b/src/UserInterface/Views/SettingsView.h @@ -1,7 +1,7 @@ #ifndef SETTINGSVIEW_H_ #define SETTINGSVIEW_H_ -#include "ObservedWidget.h" +#include "ViewBase.h" class QTabWidget; class QPushButton; @@ -9,9 +9,10 @@ class QLineEdit; class QTimeEdit; class QRadioButton; class QCheckBox; +class QSize; //! User interface class. Shows the settings view and handles configuration changes. -class SettingsView : public ObservedWidget +class SettingsView : public ViewBase { Q_OBJECT @@ -25,10 +26,16 @@ public: SettingsView( QWidget *aParent = 0 ); //! Destructor. virtual ~SettingsView(); + +signals: + void okClicked(); + +public slots: + void viewResized(const QSize &size); private slots: //! Slot to handle the Ok button pressing. - void okClicked(); + void handleOkClicked(); //! Slot to handle the cancel button pressing. void cancelClicked(); diff --git a/src/UserInterface/Views/ViewBase.cpp b/src/UserInterface/Views/ViewBase.cpp new file mode 100644 index 0000000..24d6461 --- /dev/null +++ b/src/UserInterface/Views/ViewBase.cpp @@ -0,0 +1,77 @@ +#include "ViewBase.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +ViewBase::ViewBase( ViewBase::ViewMode aMode, QWidget *aParent ) : QWidget( aParent ), iViewMode( aMode ) +{ + +} + +ViewBase::~ViewBase() +{ + +} + +ViewBase::ViewMode ViewBase::viewMode() +{ + return iViewMode; +} + +bool ViewBase::event(QEvent *event) +{ + switch( event->type() ) + { + // TODO : Add events as needed !!! + case QEvent::KeyPress: + case QEvent::KeyRelease: + case QEvent::TabletMove: + case QEvent::TabletPress: + case QEvent::MouseMove: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: + emit eventDetected(); + break; + default: + break; + } + + return QWidget::event( event ); +} + +bool ViewBase::eventFilter( QObject *watched, QEvent *event ) +{ + if ( watched != this ) // We do not filter our own events + { + switch( event->type() ) + { + // TODO : Add events as needed !!!! + case QEvent::KeyPress: + case QEvent::KeyRelease: + case QEvent::TabletMove: + case QEvent::TabletPress: + case QEvent::MouseMove: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: + emit eventDetected(); + break; + default: + break; + } + } + + return QWidget::eventFilter( watched, event ); +} + +void ViewBase::observeChild(QWidget *aChild) +{ + aChild->setMouseTracking( true ); + aChild->installEventFilter( this ); +} diff --git a/src/UserInterface/Views/ViewBase.h b/src/UserInterface/Views/ViewBase.h new file mode 100644 index 0000000..00bcf70 --- /dev/null +++ b/src/UserInterface/Views/ViewBase.h @@ -0,0 +1,69 @@ +#ifndef VIEWBASE_ +#define VIEWBASE_ + +#include + +class QEvent; +class QSize; + +class ViewBase : public QWidget +{ + Q_OBJECT + +public: + enum ViewMode + { + NormalView, /*!< Indicates that the view is normal view that isn't hidden by events. */ + ObservedView /*!< Indicates that the view will be hidden when event occurs. */ + }; + +public: + ViewBase( ViewBase::ViewMode aMode, QWidget *aParent = 0 ); + virtual ~ViewBase(); + + //! Overwritten event handler. + /*! + * Listens for events and emits eventDetected signal when observed + * event is triggered. + */ + virtual bool event(QEvent *event); + + //! Event filter. + /*! + * Event filter method that is used to listen for child widgets + * events. + */ + virtual bool eventFilter(QObject *watched, QEvent *event); + + //! Returns view mode. + /*! + * Returns the views mode which is one of the ViewMode enumerations. + */ + ViewBase::ViewMode viewMode(); + +public slots: + //! This slot is called when the view is resized. + /*! + * This slot will be called after the view is resized by the window manager + * to fit its client area. This method can be used to refine the view size + * after it has been resized, for example when the on screen keyboard is + * displayed. + */ + virtual void viewResized(const QSize &size) = 0; + +signals: + /*! + * This signal indicates that some user initiated event has occured. + * Event filter tracks for mouse, pointer and key events. + */ + void eventDetected(); + +protected: + void observeChild(QWidget *aChild); + +private: + ViewMode iViewMode; + +}; + +#endif /*VIEWBASE_*/ diff --git a/src/UserInterface/Views/WeeklyViewWidget.cpp b/src/UserInterface/Views/WeeklyViewWidget.cpp index b33e517..3f2fec4 100644 --- a/src/UserInterface/Views/WeeklyViewWidget.cpp +++ b/src/UserInterface/Views/WeeklyViewWidget.cpp @@ -20,7 +20,7 @@ #include WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *aConfiguration, QWidget *aParent ) : - ObservedWidget( aParent ), iConfiguration( aConfiguration ) + ViewBase( ViewBase::NormalView, aParent ), iConfiguration( aConfiguration ) { // ***************************************** @@ -36,23 +36,21 @@ WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *a iSettingsButton = new QPushButton; iSettingsButton->setIcon( QPixmap( ":button_settings" ) ); iSettingsButton->setFixedWidth( 36 ); - connect( iSettingsButton, SIGNAL( clicked() ), this, SIGNAL( showSettingsView() ) ); + connect( iSettingsButton, SIGNAL( clicked() ), this, SIGNAL( settingsButtonClicked() ) ); iCurrentDayLabel = ToolBox::createLabel( aCurrentDateTime.toString( iConfiguration->displaySettings()->dateFormat() ), regularTextFont ); iCurrentWeekLabel = ToolBox::createLabel( tr( "Wk %1" ).arg( aCurrentDateTime.date().weekNumber() ), regularTextFont ); iRoomsCombo = new MeetingRoomCombo( iConfiguration->rooms(), this ); iRoomsCombo->setCurrentRoom( iConfiguration->defaultRoom() ); - connect( iRoomsCombo, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); + connect( iRoomsCombo, SIGNAL( currentRoomChange( Room * ) ), this, SIGNAL( currentRoomChange( Room * ) ) ); iTimeDisplay = new DigitalTimeDisplayWidget( aCurrentDateTime.time(), iConfiguration->displaySettings()->timeFormat(), this ); iTimeDisplay->setFrameVisible( false ); iTimeDisplay->setFont( regularTextFont ); - connect( iTimeDisplay, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); iSchedule = new ScheduleWidget( aCurrentDateTime, iConfiguration->displaySettings(), this ); connect( iSchedule, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) ); - connect( iSchedule, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); connect( iSchedule, SIGNAL( meetingActivated( Meeting* ) ), this, SIGNAL( meetingActivated( Meeting* ) ) ); iPreviousWeekButton = new QPushButton( this ); @@ -91,6 +89,16 @@ WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *a mainLayout->addLayout( tableLayout ); mainLayout->addLayout( bottomLayout ); setLayout( mainLayout ); + + // Set child observing + observeChild( iRoomsCombo ); + observeChild( iTimeDisplay ); + observeChild( iCurrentDayLabel ); + observeChild( iCurrentWeekLabel ); + observeChild( iPreviousWeekButton ); + observeChild( iCurrentWeekButton ); + observeChild( iNextWeekButton ); + observeChild( iSettingsButton ); QPalette palette; palette.setColor( QPalette::Window, Qt::white ); @@ -100,11 +108,11 @@ WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *a // ****************************************** // Handle all the signal connections // TODO : this solution if interaction monitoring is not elegant enough - connect( iPreviousWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); - connect( iCurrentWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); - connect( iNextWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); - connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( observedEventDetected() ) ); - connect( iRoomsCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( observedEventDetected() ) ); +// connect( iPreviousWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); +// connect( iCurrentWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); +// connect( iNextWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); +// connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( observedEventDetected() ) ); +// connect( iRoomsCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( observedEventDetected() ) ); // TODO: connect RoomCombo signals to change meetings data. connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), iSchedule, SLOT( clear() ) ); connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) ); diff --git a/src/UserInterface/Views/WeeklyViewWidget.h b/src/UserInterface/Views/WeeklyViewWidget.h index f0da141..1eb1812 100644 --- a/src/UserInterface/Views/WeeklyViewWidget.h +++ b/src/UserInterface/Views/WeeklyViewWidget.h @@ -1,7 +1,7 @@ #ifndef WEEKLYVIEWWIDGET_H_ #define WEEKLYVIEWWIDGET_H_ -#include "ObservedWidget.h" +#include "ViewBase.h" #include class QLabel; @@ -19,7 +19,7 @@ class Room; * selected meeting room. User can select meeting room, browse weeks back and forth, and can navigate * back to the current week. */ -class WeeklyViewWidget : public ObservedWidget +class WeeklyViewWidget : public ViewBase { Q_OBJECT @@ -103,14 +103,14 @@ signals: /*! * Signal is emited when settings button is clicked. */ - void showSettingsView(); + void settingsButtonClicked(); //! Signal. Emitted if the shown week has been changed. /*! * Signal. Emitted if the shown week has been changed. * \param aDate The first date of the shown week. */ - void shownWeekChanged( QDate aDate ); + void shownWeekChanged( QDate aDate ); public slots: //! Sets the date and time @@ -137,6 +137,13 @@ public slots: * \param aMeeting Meeting to be updated. */ void updateMeeting( Meeting *aMeeting ); + + //! Handle resizing + /*! + * Handle possible resize changes after the view is resized + * to match the window managers client area. + */ + void viewResized(const QSize &size) { } private: //! Displays the selectable meeting rooms. diff --git a/src/UserInterface/WindowManager.cpp b/src/UserInterface/WindowManager.cpp index 45d8b72..8685e6b 100644 --- a/src/UserInterface/WindowManager.cpp +++ b/src/UserInterface/WindowManager.cpp @@ -1,211 +1,110 @@ #include "WindowManager.h" -#include -#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 "PopUpMessageBox.h" -#include "DeviceManager.h" -#include "SettingsView.h" -#include "ProgressBar.h" +#include +#include +#include "ViewBase.h" #include -WindowManager::WindowManager( Configuration *aConfiguration ) : - QObject(), +const int IDLE_TIME_MULTIPLIER = 60000; // Multiplies milliseconds to minutes + +WindowManager::WindowManager( QWidget *aParent ) : + QWidget( aParent ), iApplicationName( tr( "Qt Meetings" ) ), - iFullScreen( false ), - 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 ); } 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 ) -{ - if ( iRoomStatusView != 0 && iRoomStatusView->isActiveWindow() ) - { - iRoomStatusView->setCurrentTime( aCurrentDateTime.time() ); - } - - if ( iWeeklyView != 0 && iWeeklyView->isActiveWindow() ) - { - iWeeklyView->setCurrentDateTime( aCurrentDateTime ); - } + } -void WindowManager::roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aTime ) +void WindowManager::showView( ViewBase *view ) { - if ( iRoomStatusView == 0 ) + // The views parent must be WindowManager when it is displayed trough this + QWidget *parent = static_cast(view->parent()); + if ( parent != this ) { - iRoomStatusView = new RoomStatusIndicatorWidget( aRoom, aStatus, aTime, iConfiguration->displaySettings()->timeFormat() ); - iRoomStatusView->setWindowTitle( iApplicationName ); - if( iFullScreen ) - iRoomStatusView->setWindowState( Qt::WindowFullScreen ); - connect( iRoomStatusView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); + view->setParent( this ); } - else + + // 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->statusChanged( aStatus, aTime ); + iViewList.push( iCurrentView ); } - if ( !iWeeklyView->isVisible() && !iRoomStatusView->isVisible() ) + + // Make the new view visible and handle connections + iCurrentView = view; + connect( iCurrentView, SIGNAL( eventDetected() ), this, SLOT( viewEventDetected() ) ); + connect( this, SIGNAL( viewResized(const QSize &) ), iCurrentView, SLOT( viewResized( const QSize & ) ) ); + view->resize( this->size() ); + + 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 &) ), oldView, SLOT( viewResized(const QSize &) ) ); + oldView->hide(); } + } -void WindowManager::showRoomStatus() +void WindowManager::showDialog(QDialog *dialog) { - qDebug() << "WindowManager::showRoomStatus"; + // Handle dialog displaying + emit dialogActivated(); + dialog->exec(); + emit dialogDeactivated(); +} - if ( iRoomStatusView == 0 ) - { - emit roomStatusInfoNeeded( iWeeklyView->currentRoom() ); - } - else +void WindowManager::viewEventDetected() +{ + + if ( iCurrentView != 0 ) { - iRoomStatusView->show(); - if ( iWeeklyView->isVisible() ) + if ( iCurrentView->viewMode() == ViewBase::NormalView ) + { + emit eventDetected(); + } + else if ( iCurrentView->viewMode() == ViewBase::ObservedView ) { - iWeeklyView->hide(); + if ( !iViewList.isEmpty() ) + { + ViewBase *previousView = static_cast( iViewList.pop() ); + this->showView( previousView ); + emit previousViewRestored(); + } } } - // closing/deleting meeting info dialog - if ( iMeetingInfo != 0 ) - { - iMeetingInfo->hide(); - } } -void WindowManager::showWeeklyView() +bool WindowManager::event(QEvent *event) { - qDebug() << "WindowManager::showWeeklyView"; - if ( iRoomStatusView != 0 && iRoomStatusView->isVisible() ) + if ( event->type() == QEvent::Resize ) { - iRoomStatusView->hide(); - } - - iWeeklyView->show(); -} - -void WindowManager::fullScreen() -{ - if ( iRoomStatusView != 0 ) - iRoomStatusView->setWindowState( Qt::WindowFullScreen ); - if ( iWeeklyView != 0 ) - iWeeklyView->setWindowState( Qt::WindowFullScreen ); - iFullScreen = true; -} - -void WindowManager::insertMeeting( Meeting *aMeeting ) -{ - 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; -} - -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(); - - //TODO connect connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); -} - -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() ) ); + if ( iCurrentView != 0 ) + { + iCurrentView->setFixedSize( this->size() ); + emit viewResized( this->size() ); + } } - //TODO connect connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); -} - -void WindowManager::closeProgressBar() -{ - qDebug() << "WindowManager::closeProgressBar()"; - iProgressBar->close(); - delete iProgressBar; - iProgressBar = 0; + return QWidget::event( event ); } -void WindowManager::updateProgressBar( const QString &aMessage ) +void WindowManager::setFullscreen() { - qDebug() << "WindowManager::updateProgressBar( const QString & )"; - if( iProgressBar != 0 ) - iProgressBar->update( aMessage ); + this->setWindowState( Qt::WindowFullScreen ); + // Resize event handles the rest. } diff --git a/src/UserInterface/WindowManager.h b/src/UserInterface/WindowManager.h index 1e460c0..4fd592f 100644 --- a/src/UserInterface/WindowManager.h +++ b/src/UserInterface/WindowManager.h @@ -1,30 +1,23 @@ #ifndef WINDOWMANAGER_H_ #define WINDOWMANAGER_H_ -#include -#include -#include "Room.h" -#include "Meeting.h" -#include "PasswordDialog.h" -#include "DeviceManager.h" +#include +#include -class QTimer; -class RoomStatusIndicatorWidget; -class WeeklyViewWidget; -class Engine; -class MeetingInfoDialog; -class SettingsView; -class ProgressBar; -class Configuration; +// Forward declarations +class ViewBase; +class QEvent; +class QSize; +class QDialog; -//! UserInterface class. Behaves as a proxy between the user interface and application's business logic. +//! UserInterface class. Manages displayed views. /*! - * UserInterface class. Controls the whole user interface, starting with displaying the appropriate - * views. It behaves as a proxy between the user interface and application's business logic, it connects - * the specified components together and forwards the data to the correct place. It also manages the correct - * appearance of current views on the screen. + * UserInterface class. WindowManager class is responsible for displaying views that inherit the + * ViewBase class. It also handles dialog showing. Depending on the views type the WindowManager + * can track the views events and restore previous view if the current on is ObservedView. This + * is a handy mechanism for screensaver etc. */ -class WindowManager : public QObject +class WindowManager : public QWidget { Q_OBJECT @@ -32,72 +25,12 @@ public: //! Constructor. /*! * Constructor of WindowManager. - * \param aConfiguration The pointer to configuration. */ - WindowManager( Configuration *aConfiguration ); + WindowManager( QWidget *aParent = 0 ); //! Destructor. virtual ~WindowManager(); - /*! - * Displays an error message - * \param aErrorMessage Message to be displayd - */ - void error( const QString &aErrorMessage ); - //! Updates the rooms status. - /*! - * Forwards the signal of changed status to current view. - * \param aRoom Room which status is changed. - * \param aStatus Current status of room. - * \param aTime Time when status is changed. - */ - void roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aTime ); - //! Shows the password dialog. - /*! - * Shows the password dialog. - * \param aAdminPassword The correct password. - * \param aMessage The message to be shown in the password dialog. - */ - void showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage ); - //! Closes the password dialog. - /*! - * Closes the password dialog. - */ - void closePasswordDialog(); - //! Displays the weekly view. - /*! - * Displays the weekly view. - */ - void showWeeklyView(); - //! Displays the meeting info dialog. - /*! - * Displays the meeting info dialog. - * \param aMeeting Meeting to be displayd - */ - void showMeetingInfo( Meeting *aMeeting ); - //! Returns the pointer to the weekly view. - /*! - * Returns the pointer to the weekly view. - */ - WeeklyViewWidget * weeklyView(); - //! Switches the views to full screen. - /*! - * Switches the views to full screen. - */ - void fullScreen(); - //! Shows the progress bar. - /*! - * Starts showing the progress bar. - * \param aText The text to be shown in progress bar. - */ - void showProgressBar( const QString &aText ); - //! Closes the progress bar. - /*! - * Closes the progress bar. - */ - void closeProgressBar(); - - void insertMeeting( Meeting *aMeeting ); - void deleteMeeting( Meeting *aMeeting ); + virtual bool event(QEvent *event); signals: //! Request current status of the room. @@ -105,80 +38,66 @@ signals: * Signal is emitted when there is need to check current status of room aRoom. * \param aRoom Meetingroom which status is requested. */ - void roomStatusInfoNeeded( Room *aRoom ); - //! Indicate that some user event has happened. - /*! - * Signal is emitted if some user event has happened. - */ - void observedEventDetected(); - //! Meeting activated. - /*! - * Signal is emitted when a meeting is clicked by the user. - * \param aMeeting actived meeting. - */ - void meetingActivated( Meeting *aMeeting ); - //! Signals if the shown week has been changed. - /*! - * Signal. Emitted if the shown week has been changed. - * \param aDate The first date of the shown week. - */ - void shownWeekChanged( QDate aDate ); - //! Signals change of the meeting room. - /*! - * Signal is emitted when meeting room is changed. - * \param aRoom Selected meeting room. - */ - void currentRoomChanged( Room *aRoom ); - //! Signals when the password dialog buttons are clicked. + void eventDetected(); + + //! The view size is changed. /*! - * Signal is emitted when the password dialog buttons are clicked. - * \param aPasswordStatus The status of the password. + * This signal is emitted when the window managers view changes, + * i.e. it received resized QEvent. + * \param The new view size. */ - void passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus ); - //! Signals when the cancel button in the progress bar is clicked. + void viewResized(const QSize &); + + //! Previous view is restored. /*! - * Signal is emitted when the cancel button in the progress bar is clicked. + * This signal is emitted when previously stored view is + * restored. This happens when view with type ViewMode::ObservedView + * is shown and it receives an event that initiates the view + * restoring chain. */ - void progressBarCancelled(); + void previousViewRestored(); + void dialogActivated(); + void dialogDeactivated(); + public slots: - //! Slot for displaying the screensaver (room status view). + //! Shows the view. /*! - * Slot. Displays the screensaver. + * Show view that inherits ViewBase class. If the views parent is not + * the WindowManager it will changed within this method. Depeding on the + * views type the currently active view might be stored and restored + * when specific event occurs in the view to be displayed. */ - void showRoomStatus(); - //! Slot for updating the time. + void showView( ViewBase *view ); + + //! Shows modal dialog. /*! - * Slot. Forwards the signal of changed time to current view. - * \param aCurrentDateTime Current date and time. + * Shows modal dialog. Emits dialogActivated() signal prior calling + * QDialog's exec() method and emits dialogDeactivated signal when + * the exec() method returns. */ - void distributeDateTimeInfo( QDateTime aCurrentDateTime ); + void showDialog( QDialog *dialog ); - void updateProgressBar( const QString &aMessage ); + //! View event is detected. + /*! + * WindowManager connects this slot to ViewBase classes eventDetected() + * signal and either emits eventDetected() signal if the current views + * type is ViewMode::NormalView or restores possible previous view + * if the current views type is ViewMode::ObservedView. + */ + void viewEventDetected(); -private slots: - //! Displays the settings view - void showSettingsView(); + void setFullscreen(); private: //! Name of the application. QString iApplicationName; - //! Defines whether the views should be shown as full screen - bool iFullScreen; - //! Pointer to the configuration. - Configuration *iConfiguration; - //! Pointer to the weekly view. - WeeklyViewWidget *iWeeklyView; - //! Pointer to the screensaver (room status view). - RoomStatusIndicatorWidget *iRoomStatusView; - //! Pointer to the meeting info dialog - MeetingInfoDialog *iMeetingInfo; - //! Pointer to the settings view - SettingsView *iSettingsView; - //! Pointer to the progress bar - ProgressBar *iProgressBar; - //! Pointer to the password dialog. - PasswordDialog *iPasswordDialog; + + //! Currently active view. + ViewBase *iCurrentView; + + //! Stack of views previously displayed. + QStack iViewList; }; -- 1.7.9.5