User interface and menu fixes
[qtmeetings] / src / UserInterface / Views / RoomStatusIndicatorWidget.cpp
index a1f75a1..be37768 100644 (file)
 #include <QLabel>
 #include <QFont>
 #include <QVBoxLayout>
-#include "DigitalTimeDisplayWidget.h"
+#include "BorderedBarWidget.h"
+
 #include "ToolBox.h"
 
 #include <QEvent>
 
 #include <QtDebug>
 
-QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0 );
+QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0);
 
-RoomStatusIndicatorWidget::RoomStatusIndicatorWidget( Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent ) :
-               ViewBase( ViewBase::ObservedView, aParent ), iTimeFormat( aTimeFormat )
+RoomStatusIndicatorWidget::RoomStatusIndicatorWidget(Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent) :
+       ViewBase(ViewBase::ObservedView, aParent), iTimeFormat(aTimeFormat)
 {
-       QFont importantTextFont;
-       //importantTextFont.setBold( true );
-       importantTextFont.setPointSize( 20 );
+       QFont clockFont;
+       clockFont.setStyleHint( QFont::Helvetica );
+       clockFont.setBold( true );
+       clockFont.setPixelSize( 36 );
+
+       QFont textFont;
+       textFont.setStyleHint( QFont::Helvetica );
+       textFont.setBold( true );
+       textFont.setPixelSize( 48 );
 
-       QFont regularTextFont;
-       //regularTextFont.setBold( true );
-       regularTextFont.setPointSize( 12 );
+       QFont statusBarFont;
+       statusBarFont.setStyleHint( QFont::Helvetica );
+       statusBarFont.setPixelSize( 18 );
 
        // display for current time
        // Note: the time display receives current time info from Engine::clock()
-       iTimeDisplay = new DigitalTimeDisplayWidget( QTime::currentTime(), iTimeFormat, this );
-       iTimeDisplay->setFrameVisible( false );
-       iTimeDisplay->setSize( 250, 120 );
+       iTimeDisplay = new BorderedBarWidget( this );
+       iTimeDisplay->setFaceColor( Qt::darkGray );
+       iTimeDisplay->setBackgroundColor( Qt::white );
+       iTimeDisplay->setBorderWidth( 6 );
+       iTimeDisplay->setFixedWidth( 170 );
+       iTimeDisplay->setFixedHeight( 50 );
+       iTimeDisplay->setFont( clockFont );
+
+       iStatusBar = new BorderedBarWidget( this );
+       iStatusBar->setFaceColor( Qt::darkGray );
+       iStatusBar->setBackgroundColor( Qt::white );
+       iStatusBar->setBorderWidth( 4 );
+       iStatusBar->setFont(statusBarFont);
+       iStatusBar->setFixedHeight( 36 );
+       iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );
 
        // Pegasus
-       iDefaultRoomLabel = ToolBox::createLabel( aDefaultRoom->name(), importantTextFont );
+       iDefaultRoomLabel
+                       = ToolBox::createLabel(aDefaultRoom->name(), textFont);
        iDefaultRoomLabel->setAlignment( Qt::AlignHCenter );
-       iDefaultRoomLabel->setStyleSheet( "background-color: transparent" );
        iDefaultRoomLabel->setHidden( true );
-       
+
        // is busy
-       iStatusLabel = ToolBox::createLabel( tr( "is %1" ).arg( statusToText( aStatus ) ), importantTextFont );
+       iStatusLabel = ToolBox::createLabel(tr( "is %1" ).arg(statusToText(aStatus) ), textFont);
        iStatusLabel->setAlignment( Qt::AlignHCenter );
-       iStatusLabel->setStyleSheet( "background-color: transparent" );
        iStatusLabel->setHidden( true );
 
        // until 13:22
-       iUntilTextLabel = ToolBox::createLabel( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ), importantTextFont );
+       iUntilTextLabel
+                       = ToolBox::createLabel(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ), textFont);
        iUntilTextLabel->setAlignment( Qt::AlignHCenter );
-       iUntilTextLabel->setStyleSheet( "background-color: transparent" );
        iUntilTextLabel->setHidden( true );
-       
-       // No connection to server note
-       qDebug() << "RoomStatusIndicatorWidget::RoomStatusIndicatorWidget() creating connection label";
-       QFrame* connectionLabelFrame = new QFrame( this );
-       iConnectionLabel = new QLabel( tr( "No connection to server" ), connectionLabelFrame );
-       iConnectionLabel->setFont( importantTextFont ); 
-       iConnectionLabel->setAlignment( Qt::AlignHCenter );
-       iConnectionLabel->setWordWrap( true );
-       iConnectionLabel->setStyleSheet( "background-color: transparent; color: red; text-decoration:blink; max-width: 250px" );
-       connectionLabelFrame->setFixedSize( iConnectionLabel->sizeHint() );
-       if( connectedOnce && !connectionError ) iConnectionLabel->setHidden( true );
-               
-
-       QVBoxLayout *topLayout = new QVBoxLayout;
-       topLayout->addStretch();
-       topLayout->addWidget( iTimeDisplay );
-       topLayout->addSpacing( 28 );
-       topLayout->addWidget( iDefaultRoomLabel );
-       topLayout->addWidget( iStatusLabel );
-       topLayout->addWidget( iUntilTextLabel );
-       topLayout->addSpacing( 28 );
-       topLayout->addWidget( connectionLabelFrame );
-       topLayout->addStretch();
-
-       QHBoxLayout *mainLayout = new QHBoxLayout;
+
+       QHBoxLayout *topLayout = new QHBoxLayout;
+       topLayout->addWidget(iTimeDisplay);
+
+       QVBoxLayout *textLayout = new QVBoxLayout;
+       textLayout->addWidget(iDefaultRoomLabel);
+       textLayout->addWidget(iStatusLabel);
+       textLayout->addWidget(iUntilTextLabel);
+       textLayout->addSpacing( 250 );
+
+       QHBoxLayout *centerLayout = new QHBoxLayout;
+       centerLayout->addLayout( textLayout );
+       centerLayout->addSpacing( 250 );
+
+       QHBoxLayout *bottomLayout = new QHBoxLayout;
+       bottomLayout->addSpacing( 56 );
+       bottomLayout->addWidget( iStatusBar );
+       bottomLayout->addSpacing( 56 );
+
+       QVBoxLayout *mainLayout = new QVBoxLayout;
        mainLayout->addLayout( topLayout );
-       mainLayout->addStretch();
-       //mainLayout->setMargin( 65 );
-       mainLayout->setContentsMargins( 65, 65, 65, 0 );
-       setLayout( mainLayout );
+       mainLayout->addSpacing( 50 );
+       mainLayout->addLayout( centerLayout );
+       mainLayout->addLayout( bottomLayout );
+       setLayout(mainLayout);
+
+       statusChanged(aStatus, aUntil);
 
-       statusChanged( aStatus, aUntil );
+       QPalette palette;
+       palette.setColor( QPalette::Window, Qt::white );
+       palette.setColor( QPalette::WindowText, Qt::darkGray );
+       setPalette( palette );
 
-       setFocusPolicy( Qt::StrongFocus );
-       setEnabled( true ); // enable mouse & key events
+       setAutoFillBackground( true );
+       setFocusPolicy(Qt::StrongFocus);
+       setEnabled( true); // enable mouse & key events
 }
 
 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
 {
        delete iTimeDisplay;
        iTimeDisplay = 0;
+
+       delete iStatusBar;
+       iStatusBar = 0;
 }
 
-QString RoomStatusIndicatorWidget::statusToText( const Room::Status aStatus )
+QString RoomStatusIndicatorWidget::statusToText(const Room::Status aStatus)
 {
-       return ( aStatus == Room::BusyStatus ) ? tr( "busy" ) : tr( "free" );
+       return (aStatus == Room::BusyStatus ) ? tr("busy") : tr("free");
 }
 
-QPalette RoomStatusIndicatorWidget::createPalette( Room::Status aStatus )
+QPalette RoomStatusIndicatorWidget::createPalette(Room::Status aStatus)
 {
-       QString image = aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
-       QPixmap pixmap( image );
+       QString
+                       image =
+                                       aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
+       QPixmap pixmap(image);
 
        // The image needs to be moved in normal mode so the traffic light not partly outside the screen
-       const int xoffset( 60 );
-       const int yoffset( 19 );
-       int cropwidth( pixmap.width() - xoffset );
-       int cropheight( pixmap.height() - yoffset );
-       
+       const int xoffset( 60);
+       const int yoffset( 19);
+       int cropwidth(pixmap.width() - xoffset);
+       int cropheight(pixmap.height() - yoffset);
+
        QBrush brush;
-       if ( windowState() == Qt::WindowFullScreen )
+       if ( (pixmap.width() == rect().width()) && (pixmap.height() == rect().height()) )
        {
                // Use the full image in full screen mode
-               brush.setTexture( pixmap );
+               brush.setTexture(pixmap);
        }
        else
        {
                // Take part of the image so the traffic lights are moved xoffset poxels to left 
                // and yoffset pixels to up
-               brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );
+               brush.setTexture(pixmap.copy(xoffset, yoffset, cropwidth, cropheight) );
        }
 
        QPalette palette;
+       palette.setColor( QPalette::Window, Qt::white );
+       palette.setColor( QPalette::WindowText, Qt::black );
        palette.setBrush( QPalette::Window, brush );
        return palette;
 }
 
-void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )
+void RoomStatusIndicatorWidget::setConnectionStatus( QDateTime aCurrentTime, bool aConnected,
+               QTime aLastUpdated, QString aError )
+{
+       iTimeDisplay->setText( aCurrentTime.toString( iTimeFormat ) );
+       if ( aLastUpdated.isNull() )
+               iStatusBar->setText( tr("Disconnected") , BorderedBarWidget::LeftAlign );
+       else
+       {
+               iDefaultRoomLabel->setHidden( false );
+               iUntilTextLabel->setHidden( false );
+               iStatusLabel->setHidden( false );
+
+               if (!aConnected)
+               {
+                       iStatusBar->setText( tr("Disconnected").arg(aLastUpdated.toString(iTimeFormat))
+                                       , BorderedBarWidget::LeftAlign );
+               }
+               else
+               {
+                       iStatusBar->setText( tr("Connected - Last update %1").arg(aLastUpdated.toString(iTimeFormat)) ,
+                                       BorderedBarWidget::LeftAlign );
+               }
+       }
+       showError( aError );
+}
+
+void RoomStatusIndicatorWidget::showError( QString aError )
 {
-       iTimeDisplay->setTime( aCurrentTime );
+       iStatusBar->setText( aError );
 }
 
-void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )
+
+void RoomStatusIndicatorWidget::statusChanged(const Room::Status aStatus, const QTime aUntil)
 {
-       iStatusLabel->setText( tr( "is %1" ).arg( statusToText( aStatus ) ) );
-       if ( aUntil == RoomStatusIndicatorWidget::endOfTheDay )
+       iStatusLabel->setText(tr( "is %1" ).arg(statusToText(aStatus) ) );
+       if (aUntil == RoomStatusIndicatorWidget::endOfTheDay)
        {
-               iUntilTextLabel->setText( tr( "whole day." ) );
+               iUntilTextLabel->setText(tr("whole day.") );
        }
        else
        {
-               iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );
+               iUntilTextLabel->setText(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ) );
        }
-       setPalette( createPalette( aStatus ) );
+       setPalette(createPalette(aStatus) );
 }
 
-void RoomStatusIndicatorWidget::currentRoomChanged( Room *aRoom )
+void RoomStatusIndicatorWidget::currentRoomChanged(Room *aRoom)
 {
-       iDefaultRoomLabel->setText( aRoom->name() );
+       iDefaultRoomLabel->setText(aRoom->name() );
 }
 
 bool RoomStatusIndicatorWidget::event(QEvent *event)
 {
-       switch(event->type())
+       switch (event->type())
        {
                case QEvent::Paint:
-                       qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
+                       //qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
                        break;
                case QEvent::PaletteChange:
-                       qDebug() << "[RoomStatusIndicatorWidget::event] <Palette change event>";
+                       //qDebug()
+                       //              << "[RoomStatusIndicatorWidget::event] <Palette change event>";
                        break;
                default:
                        break;
        }
-       
-       return ViewBase::event( event );
+
+       return ViewBase::event(event);
+}
+
+void RoomStatusIndicatorWidget::connectionEstablished()
+{
+       ViewBase::connectionEstablished();
+}
+
+void RoomStatusIndicatorWidget::connectionLost()
+{
+       ViewBase::connectionLost();
 }