File indexing completed on 2024-05-12 16:36:46

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2008 Fredy Yanardi <fyanardi@gmail.com>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include "KPrPresenterViewToolWidget.h"
0021 
0022 #include <KoIcon.h>
0023 #include <QBoxLayout>
0024 #include <QLabel>
0025 #include <QToolButton>
0026 #include <QTimer>
0027 
0028 
0029 KPrPresenterViewToolWidget::KPrPresenterViewToolWidget(QWidget *parent)
0030     : QFrame(parent)
0031 {
0032     QSize iconSize( 32, 32 );
0033     QHBoxLayout *mainLayout = new QHBoxLayout;
0034 
0035     QHBoxLayout *hLayout = new QHBoxLayout;
0036     QToolButton *toolButton = new QToolButton;
0037     toolButton->setIcon(koIcon("go-previous"));
0038     toolButton->setIconSize( iconSize );
0039     connect( toolButton, SIGNAL(clicked()), this, SIGNAL(previousSlideClicked()) );
0040     hLayout->addWidget(toolButton);
0041     toolButton = new QToolButton;
0042     toolButton->setIcon(koIcon("go-next"));
0043     toolButton->setIconSize( iconSize );
0044     connect( toolButton, SIGNAL(clicked()), this, SIGNAL(nextSlideClicked()) );
0045     hLayout->addWidget( toolButton );
0046 
0047     mainLayout->addLayout(hLayout);
0048     mainLayout->addSpacing( 5 );
0049     QFrame *frame = new QFrame;
0050     frame->setFrameStyle(QFrame::VLine | QFrame::Sunken);
0051     mainLayout->addWidget(frame);
0052     mainLayout->addSpacing( 5 );
0053 
0054     m_slidesToolButton = new QToolButton;
0055     m_slidesToolButton->setCheckable( true );
0056     m_slidesToolButton->setIcon(koIcon("view-list-icons"));
0057     m_slidesToolButton->setIconSize( iconSize );
0058     connect( m_slidesToolButton, SIGNAL(toggled(bool)), this, SIGNAL(slideThumbnailsToggled(bool)) );
0059     mainLayout->addWidget( m_slidesToolButton );
0060 
0061     mainLayout->addSpacing( 5 );
0062     frame = new QFrame;
0063     frame->setFrameStyle( QFrame::VLine | QFrame::Raised );
0064     mainLayout->addWidget( frame );
0065     mainLayout->addSpacing( 5 );
0066 
0067     hLayout = new QHBoxLayout;
0068     QLabel *iconLabel = new QLabel;
0069     iconLabel->setPixmap(koIcon("user-away").pixmap(iconSize));
0070     hLayout->addWidget( iconLabel );
0071     m_clockLabel = new QLabel( QTime::currentTime().toString( "hh:mm:ss ap" ) );
0072     m_clockLabel->setStyleSheet("QLabel { font-size: 24px }");
0073     hLayout->addWidget( m_clockLabel );
0074     mainLayout->addLayout( hLayout );
0075 
0076     mainLayout->addSpacing( 5 );
0077     frame = new QFrame;
0078     frame->setFrameStyle( QFrame::VLine | QFrame::Plain );
0079     mainLayout->addWidget(frame);
0080     mainLayout->addSpacing(5);
0081 
0082     hLayout = new QHBoxLayout;
0083     iconLabel = new QLabel;
0084     iconLabel->setPixmap(koIcon("chronometer").pixmap(iconSize));
0085     hLayout->addWidget(iconLabel);
0086     m_timerLabel = new QLabel( "00:00:00");
0087     m_timerLabel->setStyleSheet("QLabel { font-size: 24px }");
0088     hLayout->addWidget( m_timerLabel );
0089     mainLayout->addLayout(hLayout);
0090 
0091     setLayout(mainLayout);
0092     setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
0093 
0094     m_currentTime.start();
0095     m_clockTimer = new QTimer( this );
0096     connect( m_clockTimer, SIGNAL(timeout()), this, SLOT(updateClock()) );
0097     m_clockTimer->start( 1000 );
0098 }
0099 
0100 void KPrPresenterViewToolWidget::toggleSlideThumbnails( bool toggle )
0101 {
0102     m_slidesToolButton->setChecked( toggle );
0103 }
0104 
0105 void KPrPresenterViewToolWidget::updateClock()
0106 {
0107     QTime time = QTime::currentTime();
0108     m_clockLabel->setText( time.toString( "hh:mm:ss a" ) );
0109     int sec = m_currentTime.elapsed() / 1000;
0110 
0111     int hour = sec / 3600;
0112     sec -= hour * 3600;
0113     int min = sec / 60;
0114     sec -= min * 60;
0115 
0116     // display the timer, with 0 appended if only 1 digit
0117     m_timerLabel->setText( QString( "%1:%2:%3").arg( hour, 2, 10, QChar( '0' ) )
0118             .arg( min, 2, 10, QChar( '0' ) ).arg( sec, 2, 10, QChar( '0' ) ) );
0119 }