Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

volumeapplet.cpp

Go to the documentation of this file.
00001 /*
00002                      This file is part of the Opie Project
00003 
00004               =.             (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
00005             .=l.
00006      .>+-=
00007 _;:,   .>  :=|.         This program is free software; you can
00008 .> <`_,  > .  <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--  :           the terms of the GNU Library General Public
00010 .="- .-=="i,   .._         License as published by the Free Software
00011 - .  .-<_>   .<>         Foundation; either version 2 of the License,
00012   ._= =}    :          or (at your option) any later version.
00013   .%`+i>    _;_.
00014   .i_,=:_.   -<s.       This program is distributed in the hope that
00015   + . -:.    =       it will be useful,  but WITHOUT ANY WARRANTY;
00016   : ..  .:,   . . .    without even the implied warranty of
00017   =_    +   =;=|`    MERCHANTABILITY or FITNESS FOR A
00018  _.=:.    :  :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=    =    ;      Library General Public License for more
00020 ++=  -.   .`   .:       details.
00021 :   = ...= . :.=-
00022 -.  .:....=;==+<;          You should have received a copy of the GNU
00023  -_. . .  )=. =           Library General Public License along with
00024   --    :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 
00029 */
00030 
00031 #include "volumeapplet.h"
00032 
00033 /* OPIE */
00034 #include <opie2/odebug.h>
00035 #include <opie2/otaskbarapplet.h>
00036 #include <opie2/osoundsystem.h>
00037 #include <opie2/oledbox.h>
00038 #include <opie2/oresource.h>
00039 
00040 #include <qpe/applnk.h>
00041 #include <qpe/qpeapplication.h>
00042 
00043 using namespace Opie::Core;
00044 using namespace Opie::MM;
00045 using namespace Opie::Ui;
00046 
00047 /* QT */
00048 #include <qpainter.h>
00049 #include <qlabel.h>
00050 #include <qlayout.h>
00051 #include <qslider.h>
00052 
00053 /* STD */
00054 #include <assert.h>
00055 
00056 Channel::Channel( OMixerInterface* mixer, QWidget* parent, const char* name )
00057         :QVBox( parent, name )
00058 {
00059     _name = new QLabel( name, this );
00060     _name->setFont( QFont( "Vera", 8 ) );
00061     _volume = new QSlider( 0, 100, 10, mixer->volume( name ) & 0xff, QSlider::Vertical, this );
00062     _volume->setTickmarks( QSlider::Both );
00063     _volume->setTickInterval( 20 );
00064     _mute = new OLedBox( green, this );
00065     _mute->setFocusPolicy( QWidget::NoFocus );
00066     _mute->setFixedSize( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
00067     _name->show();
00068     _volume->show();
00069     _mute->show();
00070 }
00071 
00072 
00073 Channel::~Channel()
00074 {
00075 }
00076 
00077 
00078 VolumeAppletControl::VolumeAppletControl( OTaskbarApplet* parent, const char* name )
00079                     :QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), l(0)
00080 {
00081     setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
00082     l = new QGridLayout( this );
00083     build();
00084 }
00085 
00086 
00087 void VolumeAppletControl::build()
00088 {
00089     OSoundSystem* sound = OSoundSystem::instance();
00090     OSoundSystem::CardIterator it = sound->iterator();
00091 
00092 //    OMixerInterface*
00093     mixer = new OMixerInterface( this, "/dev/mixer" );
00094 
00095     QStringList channels = mixer->allChannels();
00096 
00097     int x = 0;
00098     // int y = 0;
00099 
00100     for ( QStringList::Iterator it = channels.begin(); it != channels.end(); ++it )
00101     {
00102        if((*it) == mixer->volume( "Vol")) {
00103        m_vol_percent=mixer->volume( *it ) >> 8;
00104     }
00105         owarn << "OSSDEMO: Mixer has channel " <<  *it << "" << oendl;
00106         owarn << "OSSDEMO:              +--- volume " << ( mixer->volume( *it ) & 0xff )
00107                << " (left) | " << ( mixer->volume( *it ) >> 8 ) << " (right)" << oendl;
00108 
00109         l->addWidget( new Channel( mixer, this, *it ), 0, x++, AlignCenter );
00110     }
00111 
00112 }
00113 
00114 
00115 VolumeAppletControl::~VolumeAppletControl()
00116 {
00117 }
00118 
00119 int VolumeAppletControl::volPercent ( ) const
00120 {
00121   return m_vol_percent;
00122 }
00123 
00124 bool VolumeAppletControl::volMuted ( ) const
00125 {
00126   return m_vol_muted;
00127 }
00128 
00129 
00130 void VolumeAppletControl::showEvent( QShowEvent* e )
00131 {
00132     odebug << "showEvent" << oendl;
00133     QWidget::showEvent( e );
00134 }
00135 
00136 
00137 void VolumeAppletControl::hideEvent( QHideEvent* e )
00138 {
00139     odebug << "hideEvent" << oendl;
00140     QWidget::hideEvent( e );
00141 }
00142 
00143 
00144  QSize VolumeAppletControl::sizeHint() const
00145  {
00146    int wd =  QPEApplication::desktop()->width();
00147    return QSize( wd, 200 ); //QFrame::sizeHint();
00148 }
00149 
00150 
00151 VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
00152              :OTaskbarApplet( parent, name )
00153 {
00154     setFixedHeight( AppLnk::smallIconSize() +4);
00155     setFixedWidth( AppLnk::smallIconSize() );
00156     _pixmap = Opie::Core::OResource::loadPixmap( "volume", Opie::Core::OResource::SmallIcon );
00157 //    _pixmap =  new QPixmap (Opie::Core::OResource::loadPixmap( "volume", Opie::Core::OResource::SmallIcon ));
00158    _control = new VolumeAppletControl( this, "control" );
00159 }
00160 
00161 
00162 VolumeApplet::~VolumeApplet()
00163 {
00164 }
00165 
00166 
00167 int VolumeApplet::position()
00168 {
00169     return 4;
00170 }
00171 
00172 
00173 void VolumeApplet::paintEvent( QPaintEvent* )
00174 {
00175     QPainter p(this);
00176     p.drawPixmap(0, 2, _pixmap );
00177 
00178 /*
00179   p. drawPixmap ( (width()- _pixmap->width())/2, QMAX( (height()-4-_pixmap->height() )/2, 1), *_pixmap );
00180   p. setPen ( darkGray );
00181   p. drawRect ( 1, height() - 4, width() - 2, 4 );
00182 
00183   OMixerInterface* mixer = new OMixerInterface( this, "/dev/mixer" );
00184 
00185   int volPercent =   mixer->volume( "Vol" ) >> 8;
00186   
00187   int pixelsWide =  volPercent  * ( width() - 4 ) / 100;
00188   p. fillRect ( 2, height() - 3, pixelsWide, 2, red );
00189   p. fillRect ( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray );
00190 */
00191 
00192 //   if ( _control-> volMuted ( )) {
00193 //     p. setPen ( red );
00194 //     p. drawLine ( 1, 2, width() - 2, height() - 5 );
00195 //     p. drawLine ( 1, 3, width() - 2, height() - 4 );
00196 //     p. drawLine ( width() - 2, 2, 1, height() - 5 );
00197 //     p. drawLine ( width() - 2, 3, 1, height() - 4 );
00198 //   }
00199 
00200 //  QPainter p(this);
00201   //  p.drawPixmap(0, 2, _pixmap );
00202 }
00203 
00204 
00205 void VolumeApplet::mousePressEvent( QMouseEvent* )
00206 {
00207     if ( !_control->isVisible() )
00208     {
00209         popup( _control );
00210     }
00211     else
00212     {
00213         _control->hide();
00214     }
00215 }
00216 
00217 EXPORT_OPIE_APPLET_v1( VolumeApplet )

Generated on Sat Nov 5 16:16:45 2005 for OPIE by  doxygen 1.4.2