![]() |
Home · All Namespaces · All Classes |
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (directui@nokia.com) 00006 ** 00007 ** This file is part of systemui. 00008 ** 00009 ** If you have questions regarding the use of this file, please contact 00010 ** Nokia at directui@nokia.com. 00011 ** 00012 ** This library is free software; you can redistribute it and/or 00013 ** modify it under the terms of the GNU Lesser General Public 00014 ** License version 2.1 as published by the Free Software Foundation 00015 ** and appearing in the file LICENSE.LGPL included in the packaging 00016 ** of this file. 00017 ** 00018 ****************************************************************************/ 00019 #include "volumebarwindow.h" 00020 #include "volumebar.h" 00021 #include "volumebarlogic.h" 00022 00023 #include <MSceneManager> 00024 #include <MOverlay> 00025 00026 VolumeBarWindow::VolumeBarWindow (QWidget *parent) : 00027 MWindow (parent), 00028 logic (new VolumeBarLogic), 00029 volumeBar (0), 00030 overlay (0), 00031 #ifdef HAVE_QMSYSTEM 00032 hwkeys (0), 00033 #endif 00034 locked (false) 00035 { 00036 #ifdef HAVE_QMSYSTEM 00037 hwkeys = new MeeGo::QmKeys (this); 00038 locks = new MeeGo::QmLocks (this); 00039 00040 connect (locks, SIGNAL (stateChanged(MeeGo::QmLocks::Lock, MeeGo::QmLocks::State)), 00041 SLOT (locksChanged(MeeGo::QmLocks::Lock, MeeGo::QmLocks::State))); 00042 #endif 00043 00044 #ifdef HAVE_LIBRESOURCEQT 00045 hwkeyResource = new ResourcePolicy::ResourceSet ("event"); 00046 hwkeyResource->setAlwaysReply (); 00047 00048 ResourcePolicy::ScaleButtonResource *volumeKeys = new ResourcePolicy::ScaleButtonResource; 00049 00050 hwkeyResource->addResourceObject (volumeKeys); 00051 00052 connect (hwkeyResource, SIGNAL (resourcesGranted (QList<ResourcePolicy::ResourceType>)), 00053 this, SLOT (hwKeyResourceAcquired ())); 00054 connect (hwkeyResource, SIGNAL (lostResources ()), 00055 this, SLOT (hwKeyResourceLost ())); 00056 00057 hwkeyResource->acquire (); 00058 #endif 00059 00060 // create the VolumeBar widget 00061 volumeBar = new VolumeBar; 00062 connect (volumeBar, SIGNAL (volumeChanged (int)), SLOT (volumeBarChanged (int))); 00063 connect (volumeBar, SIGNAL (animationsFinished ()), SLOT (hide ())); 00064 00065 connect (this, SIGNAL (orientationChangeFinished(M::Orientation)), 00066 volumeBar, SLOT (updateContents ())); 00067 00068 // create&set-up an overlay 00069 overlay = new MOverlay; 00070 overlay->setWidget (volumeBar); 00071 00072 // create a scenemanager and show the overlay 00073 setSceneManager (new MSceneManager); 00074 sceneManager ()->appearSceneWindow (overlay); 00075 00076 // and set the window attributes 00077 setTranslucentBackground (true); 00078 setAttribute (Qt::WA_X11NetWmWindowTypeNotification, true); 00079 setAttribute (Qt::WA_X11DoNotAcceptFocus, true); 00080 setObjectName ("VolumeBarWindow"); 00081 setProperty("followsCurrentApplicationWindowOrientation", true); 00082 } 00083 00084 VolumeBarWindow::~VolumeBarWindow () 00085 { 00086 #ifdef HAVE_LIBRESOURCEQT 00087 //Free the resources here 00088 hwkeyResource->deleteResource (ResourcePolicy::ScaleButtonType); 00089 #endif 00090 00091 delete logic; 00092 delete overlay; 00093 } 00094 00095 void VolumeBarWindow::volumeBarChanged (int val) 00096 { 00097 // Set the volume value 00098 logic->setVolume ((quint32) val); 00099 } 00100 00101 #ifdef HAVE_QMSYSTEM 00102 void VolumeBarWindow::hwKeyEvent (MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state) 00103 { 00104 int change_val = 0; 00105 00106 if (state == MeeGo::QmKeys::KeyUp) 00107 return; 00108 00109 switch (key) 00110 { 00111 case MeeGo::QmKeys::VolumeUp: 00112 change_val++; 00113 break; 00114 case MeeGo::QmKeys::VolumeDown: 00115 change_val--; 00116 break; 00117 default: 00118 // no-op for other hw-keys... 00119 return; 00120 break; 00121 } 00122 00123 int current_volume = (int) logic->volume (); 00124 int max_volume = (int) logic->maxVolume (); 00125 00126 current_volume += change_val; 00127 00128 if (current_volume >= max_volume) 00129 current_volume = max_volume - 1; 00130 if (current_volume < 0) 00131 current_volume = 0; 00132 00133 // This sets the volume 00134 volumeBarChanged (current_volume); 00135 00136 // When screen/device is locked, do not show the volumeBar: 00137 if (locked == true) 00138 return; 00139 00140 if (isVisible () == false) 00141 show (); 00142 00143 // And update the VolumeBar widget contents 00144 volumeBar->updateVolume (current_volume, max_volume); 00145 } 00146 00147 void VolumeBarWindow::locksChanged (MeeGo::QmLocks::Lock what, MeeGo::QmLocks::State how) 00148 { 00149 if (how == MeeGo::QmLocks::Locked) 00150 { 00151 locked = true; 00152 // hide the window if it is visible 00153 if (isVisible () == true) 00154 hide (); 00155 } 00156 else if (how == MeeGo::QmLocks::Unlocked) 00157 { 00158 /* 00159 * Check wether all the locks went away... 00160 */ 00161 if ((what == MeeGo::QmLocks::Device) && 00162 (locks->getState (MeeGo::QmLocks::TouchAndKeyboard) == 00163 MeeGo::QmLocks::Unlocked)) 00164 { 00165 locked = false; 00166 } 00167 else if (locks->getState (MeeGo::QmLocks::Device) == 00168 MeeGo::QmLocks::Unlocked) 00169 { 00170 locked = false; 00171 } 00172 } 00173 } 00174 #endif 00175 00176 void VolumeBarWindow::hwKeyResourceAcquired () 00177 { 00178 #ifdef HAVE_QMSYSTEM 00179 // Disconnect from everything first 00180 hwkeys->disconnect (); 00181 00182 connect(hwkeys, SIGNAL (keyEvent (MeeGo::QmKeys::Key, MeeGo::QmKeys::State)), 00183 this, SLOT (hwKeyEvent (MeeGo::QmKeys::Key, MeeGo::QmKeys::State))); 00184 #endif 00185 } 00186 00187 void VolumeBarWindow::hwKeyResourceLost () 00188 { 00189 #ifdef HAVE_QMSYSTEM 00190 hwkeys->disconnect (); 00191 #endif 00192 } 00193
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:19:35 Doxygen 1.7.1 |
MeeGo Touch |
