qtmobility/tests/playerex_s60/playercontrols.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "playercontrols.h"
       
    43 
       
    44 #include <QtGui/qboxlayout.h>
       
    45 #include <QtGui/qslider.h>
       
    46 #include <QtGui/qstyle.h>
       
    47 #include <QtGui/qtoolbutton.h>
       
    48 #include <QtGui/qcombobox.h>
       
    49 
       
    50 PlayerControls::PlayerControls(QWidget *parent)
       
    51     : QWidget(parent)
       
    52     , playerState(QMediaPlayer::StoppedState)
       
    53     , playerMuted(false)
       
    54     , playButton(0)
       
    55     , nextButton(0)
       
    56     , previousButton(0)
       
    57     , muteButton(0)
       
    58 {
       
    59     playButton = new QToolButton;
       
    60     playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
       
    61 
       
    62     connect(playButton, SIGNAL(clicked()), this, SLOT(playClicked()));
       
    63 
       
    64     nextButton = new QToolButton;
       
    65     nextButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipForward));
       
    66 
       
    67     connect(nextButton, SIGNAL(clicked()), this, SIGNAL(next()));
       
    68 
       
    69     previousButton = new QToolButton;
       
    70     previousButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipBackward));
       
    71 
       
    72     connect(previousButton, SIGNAL(clicked()), this, SIGNAL(previous()));
       
    73 
       
    74     muteButton = new QToolButton;
       
    75     muteButton->setIcon(style()->standardIcon(QStyle::SP_MediaVolume));
       
    76 
       
    77     connect(muteButton, SIGNAL(clicked()), this, SLOT(muteClicked()));
       
    78     
       
    79     QBoxLayout *layout = new QHBoxLayout;
       
    80     layout->setMargin(0);
       
    81     layout->addWidget(previousButton);
       
    82     layout->addWidget(playButton);
       
    83     layout->addWidget(nextButton);
       
    84     layout->addWidget(muteButton);
       
    85     setLayout(layout);
       
    86 }
       
    87 
       
    88 QMediaPlayer::State PlayerControls::state() const
       
    89 {
       
    90     return playerState;
       
    91 }
       
    92 
       
    93 void PlayerControls::setState(QMediaPlayer::State state)
       
    94 {
       
    95     if (state != playerState) {
       
    96         playerState = state;
       
    97 
       
    98         switch (state) {
       
    99         case QMediaPlayer::StoppedState:
       
   100             playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
       
   101             break;
       
   102         case QMediaPlayer::PlayingState:
       
   103             playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
       
   104             break;
       
   105         case QMediaPlayer::PausedState:
       
   106             playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
       
   107             break;
       
   108         }
       
   109     }
       
   110 }
       
   111 
       
   112 bool PlayerControls::isMuted() const
       
   113 {
       
   114     return playerMuted;
       
   115 }
       
   116 
       
   117 void PlayerControls::setMuted(bool muted)
       
   118 {
       
   119     if (muted != playerMuted) {
       
   120         playerMuted = muted;
       
   121 
       
   122         muteButton->setIcon(style()->standardIcon(muted
       
   123                 ? QStyle::SP_MediaVolumeMuted
       
   124                 : QStyle::SP_MediaVolume));
       
   125     }
       
   126 }
       
   127 
       
   128 void PlayerControls::playClicked()
       
   129 {
       
   130     switch (playerState) {
       
   131     case QMediaPlayer::StoppedState:
       
   132     case QMediaPlayer::PausedState:
       
   133         emit play();
       
   134         break;
       
   135     case QMediaPlayer::PlayingState:
       
   136         emit pause();
       
   137         break;
       
   138     }
       
   139 }
       
   140 
       
   141 void PlayerControls::muteClicked()
       
   142 {
       
   143     emit changeMuting(!playerMuted);
       
   144 }