• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

kopete/kopete

avdeviceconfig.cpp

Go to the documentation of this file.
00001 /*
00002     avdeviceconfig.cpp  -  Kopete Video Device Configuration Panel
00003 
00004     Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro   <taupter@gmail.com>
00005 
00006 
00007     Kopete    (c) 2002-2003      by the Kopete developers  <kopete-devel@kde.org>
00008 
00009     *************************************************************************
00010     *                                                                       *
00011     * This program is free software; you can redistribute it and/or modify  *
00012     * it under the terms of the GNU General Public License as published by  *
00013     * the Free Software Foundation; either version 2 of the License, or     *
00014     * (at your option) any later version.                                   *
00015     *                                                                       *
00016     *************************************************************************
00017 */
00018 
00019 #include "avdeviceconfig.h"
00020 
00021 #include <qcheckbox.h>
00022 #include <qlayout.h>
00023 #include <qlabel.h>
00024 #include <qbuttongroup.h>
00025 #include <qspinbox.h>
00026 #include <qcombobox.h>
00027 #include <qslider.h>
00028 //Added by qt3to4:
00029 #include <QVBoxLayout>
00030 
00031 #include <kplugininfo.h>
00032 #include <klocale.h>
00033 #include <kpushbutton.h>
00034 #include <kpluginfactory.h>
00035 #include <ktrader.h>
00036 #include <kconfig.h>
00037 #include <kcombobox.h>
00038 #include <qimage.h>
00039 #include <qpixmap.h>
00040 
00041 #include <qtabwidget.h>
00042 
00043 //#include "videodevice.h"
00044 K_PLUGIN_FACTORY( KopeteAVDeviceConfigFactory,
00045         registerPlugin<AVDeviceConfig>(); )
00046 K_EXPORT_PLUGIN( KopeteAVDeviceConfigFactory("kcm_kopete_avdeviceconfig") )
00047 
00048 AVDeviceConfig::AVDeviceConfig(QWidget *parent, const QVariantList &args)
00049  : KCModule( KopeteAVDeviceConfigFactory::componentData(), parent, args )
00050 {
00051     kDebug() << "kopete:config (avdevice): KopeteAVDeviceConfigFactory::componentData() called. ";
00052 // "Video" TAB ============================================================
00053     mPrfsVideoDevice = new Ui_AVDeviceConfig_VideoDevice();
00054     mPrfsVideoDevice->setupUi(this);
00055 
00056     // set a default image for the webcam widget, in case the user does not have a video device
00057     mPrfsVideoDevice->mVideoImageLabel->setScaledContents(false);
00058     mPrfsVideoDevice->mVideoImageLabel->setPixmap(KIcon("camera-web").pixmap(128,128));
00059 
00060     connect(mPrfsVideoDevice->mDeviceKComboBox,              SIGNAL(activated(int)),    this, SLOT(slotDeviceKComboBoxChanged(int)));
00061     connect(mPrfsVideoDevice->mInputKComboBox,               SIGNAL(activated(int)),    this, SLOT(slotInputKComboBoxChanged(int)));
00062     connect(mPrfsVideoDevice->mStandardKComboBox,            SIGNAL(activated(int)),    this, SLOT(slotStandardKComboBoxChanged(int)));
00063     connect(mPrfsVideoDevice->mBrightnessSlider,             SIGNAL(valueChanged(int)), this, SLOT(slotBrightnessSliderChanged(int)));
00064     connect(mPrfsVideoDevice->mContrastSlider,               SIGNAL(valueChanged(int)), this, SLOT(slotContrastSliderChanged(int)));
00065     connect(mPrfsVideoDevice->mSaturationSlider,             SIGNAL(valueChanged(int)), this, SLOT(slotSaturationSliderChanged(int)));
00066     connect(mPrfsVideoDevice->mWhitenessSlider,              SIGNAL(valueChanged(int)), this, SLOT(slotWhitenessSliderChanged(int)));
00067     connect(mPrfsVideoDevice->mHueSlider,                    SIGNAL(valueChanged(int)), this, SLOT(slotHueSliderChanged(int)));
00068     connect(mPrfsVideoDevice->mImageAutoBrightnessContrast,  SIGNAL(toggled(bool)),     this, SLOT(slotImageAutoBrightnessContrastChanged(bool)));
00069     connect(mPrfsVideoDevice->mImageAutoColorCorrection,     SIGNAL(toggled(bool)),     this, SLOT(slotImageAutoColorCorrectionChanged(bool)));
00070     connect(mPrfsVideoDevice->mImageAsMirror,                SIGNAL(toggled(bool)),     this, SLOT(slotImageAsMirrorChanged(bool)));
00071 
00072     mVideoDevicePool = Kopete::AV::VideoDevicePool::self();
00073     mVideoDevicePool->open();
00074     mVideoDevicePool->setSize(320, 240);
00075 
00076     mVideoDevicePool->fillDeviceKComboBox(mPrfsVideoDevice->mDeviceKComboBox);
00077     mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
00078     mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
00079     setVideoInputParameters();
00080 
00081     mVideoDevicePool->startCapturing();
00082 
00083     connect(mVideoDevicePool, SIGNAL(deviceRegistered(const QString &) ),
00084             SLOT(deviceRegistered(const QString &)) );
00085     connect(mVideoDevicePool, SIGNAL(deviceUnregistered(const QString &) ),
00086             SLOT(deviceUnregistered(const QString &)) );
00087 
00088     connect(&qtimer, SIGNAL(timeout()), this, SLOT(slotUpdateImage()) );
00089 #define DONT_TRY_TO_GRAB 1
00090 #if DONT_TRY_TO_GRAB
00091     if ( mVideoDevicePool->hasDevices() ) {
00092         qtimer.start(40);
00093         mPrfsVideoDevice->mVideoImageLabel->setScaledContents(true);
00094     }
00095 #endif
00096 }
00097 
00098 
00099 AVDeviceConfig::~AVDeviceConfig()
00100 {
00101     mVideoDevicePool->close();
00102 }
00103 
00104 
00105 
00106 
00110 void AVDeviceConfig::save()
00111 {
00113     kDebug() << "kopete:config (avdevice): save() called. ";
00114     mVideoDevicePool->saveConfig();
00115 }
00116 
00117 
00121 void AVDeviceConfig::load()
00122 {
00124 }
00125 
00126 void AVDeviceConfig::slotSettingsChanged(bool){
00127   emit changed(true);
00128 }
00129 
00130 void AVDeviceConfig::slotValueChanged(int){
00131   emit changed( true );
00132 }
00133 
00134 void AVDeviceConfig::setVideoInputParameters()
00135 {
00136     if(mVideoDevicePool->size())
00137     {
00138         mPrfsVideoDevice->mBrightnessSlider->setValue((int)(mVideoDevicePool->getBrightness()*65535));
00139         mPrfsVideoDevice->mContrastSlider->setValue((int)(mVideoDevicePool->getContrast()*65535));
00140         mPrfsVideoDevice->mSaturationSlider->setValue((int)(mVideoDevicePool->getSaturation()*65535));
00141         mPrfsVideoDevice->mWhitenessSlider->setValue((int)(mVideoDevicePool->getWhiteness()*65535));
00142         mPrfsVideoDevice->mHueSlider->setValue((int)(mVideoDevicePool->getHue()*65535));
00143         mPrfsVideoDevice->mImageAutoBrightnessContrast->setChecked(mVideoDevicePool->getAutoBrightnessContrast());
00144         mPrfsVideoDevice->mImageAutoColorCorrection->setChecked(mVideoDevicePool->getAutoColorCorrection());
00145         mPrfsVideoDevice->mImageAsMirror->setChecked(mVideoDevicePool->getImageAsMirror());
00146     }
00147 }
00148 
00149 void AVDeviceConfig::slotDeviceKComboBoxChanged(int){
00150     kDebug() << "kopete:config (avdevice): slotDeviceKComboBoxChanged(int) called. ";
00151     int newdevice = mPrfsVideoDevice->mDeviceKComboBox->currentIndex();
00152     kDebug() << "kopete:config (avdevice): slotDeviceKComboBoxChanged(int) Current device: " << mVideoDevicePool->currentDevice() << "New device: " << newdevice;
00153     if ((newdevice>=0 && newdevice < mVideoDevicePool->m_videodevice.size())&&(newdevice!=mVideoDevicePool->currentDevice()))
00154     {
00155     kDebug() << "kopete:config (avdevice): slotDeviceKComboBoxChanged(int) should change device. ";
00156         mVideoDevicePool->open(newdevice);
00157         mVideoDevicePool->setSize(320, 240);
00158         mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
00159         mVideoDevicePool->startCapturing();
00160         setVideoInputParameters();
00161         kDebug() << "kopete:config (avdevice): slotDeviceKComboBoxChanged(int) called. ";
00162         emit changed( true );
00163     }
00164 }
00165 
00166 void AVDeviceConfig::slotInputKComboBoxChanged(int){
00167     int newinput = mPrfsVideoDevice->mInputKComboBox->currentIndex();
00168     if((newinput < mVideoDevicePool->inputs()) && ( newinput !=mVideoDevicePool->currentInput()))
00169     {
00170         mVideoDevicePool->selectInput(mPrfsVideoDevice->mInputKComboBox->currentIndex());
00171         mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
00172         setVideoInputParameters();
00173         emit changed( true );
00174     }
00175 }
00176 
00177 // ATTENTION: The 65535.0 value must be used instead of 65535 because the trailing ".0" converts the resulting value to floating point number.
00178 // Otherwise the resulting division operation would return 0 or 1 exclusively.
00179 
00180 void AVDeviceConfig::slotStandardKComboBoxChanged(int){
00181   emit changed( true );
00182 }
00183 
00184 void AVDeviceConfig::slotBrightnessSliderChanged(int){
00185     kDebug() << "kopete:config (avdevice): slotBrightnessSliderChanged(int) called. " << mPrfsVideoDevice->mBrightnessSlider->value() / 65535.0;
00186     mVideoDevicePool->setBrightness( mPrfsVideoDevice->mBrightnessSlider->value() / 65535.0 );
00187   emit changed( true );
00188 }
00189 
00190 void AVDeviceConfig::slotContrastSliderChanged(int){
00191     kDebug() << "kopete:config (avdevice): slotContrastSliderChanged(int) called. " << mPrfsVideoDevice->mContrastSlider->value() / 65535.0;
00192     mVideoDevicePool->setContrast( mPrfsVideoDevice->mContrastSlider->value() / 65535.0 );
00193   emit changed( true );
00194 }
00195 
00196 void AVDeviceConfig::slotSaturationSliderChanged(int){
00197     kDebug() << "kopete:config (avdevice): slotSaturationSliderChanged(int) called. " << mPrfsVideoDevice->mSaturationSlider->value() / 65535.0;
00198     mVideoDevicePool->setSaturation( mPrfsVideoDevice->mSaturationSlider->value() / 65535.0);
00199   emit changed( true );
00200 }
00201 
00202 void AVDeviceConfig::slotWhitenessSliderChanged(int){
00203     kDebug() << "kopete:config (avdevice): slotWhitenessSliderChanged(int) called. " << mPrfsVideoDevice->mWhitenessSlider->value() / 65535.0;
00204     mVideoDevicePool->setWhiteness( mPrfsVideoDevice->mWhitenessSlider->value() / 65535.0);
00205   emit changed( true );
00206 }
00207 
00208 void AVDeviceConfig::slotHueSliderChanged(int){
00209     kDebug() << "kopete:config (avdevice): slotHueSliderChanged(int) called. " << mPrfsVideoDevice->mHueSlider->value() / 65535.0;
00210     mVideoDevicePool->setHue( mPrfsVideoDevice->mHueSlider->value() / 65535.0 );
00211   emit changed( true );
00212 }
00213 
00214 void AVDeviceConfig::slotImageAutoBrightnessContrastChanged(bool){
00215     kDebug() << "kopete:config (avdevice): slotImageAutoBrightnessContrastChanged(" << mPrfsVideoDevice->mImageAutoBrightnessContrast->isChecked() << ") called. ";
00216     mVideoDevicePool->setAutoBrightnessContrast(mPrfsVideoDevice->mImageAutoBrightnessContrast->isChecked());
00217     emit changed( true );
00218 }
00219 
00220 void AVDeviceConfig::slotImageAutoColorCorrectionChanged(bool){
00221     kDebug() << "kopete:config (avdevice): slotImageAutoColorCorrectionChanged(" << mPrfsVideoDevice->mImageAutoColorCorrection->isChecked() << ") called. ";
00222     mVideoDevicePool->setAutoColorCorrection(mPrfsVideoDevice->mImageAutoColorCorrection->isChecked());
00223     emit changed( true );
00224 }
00225 
00226 void AVDeviceConfig::slotImageAsMirrorChanged(bool){
00227     kDebug() << "kopete:config (avdevice): slotImageAsMirrorChanged(" << mPrfsVideoDevice->mImageAsMirror->isChecked() << ") called. ";
00228     mVideoDevicePool->setImageAsMirror(mPrfsVideoDevice->mImageAsMirror->isChecked());
00229     emit changed( true );
00230 }
00231 
00232 void AVDeviceConfig::slotUpdateImage()
00233 {
00234     mVideoDevicePool->getFrame();
00235     mVideoDevicePool->getImage(&qimage);
00236     mPrfsVideoDevice->mVideoImageLabel->setPixmap(QPixmap::fromImage(qimage.mirrored(mVideoDevicePool->getImageAsMirror(),false)));
00237     //kDebug() << "kopete (avdeviceconfig_videoconfig): Image updated.";
00238 }
00239 
00240 void AVDeviceConfig::deviceRegistered( const QString & udi )
00241 {
00242     mVideoDevicePool->fillDeviceKComboBox(mPrfsVideoDevice->mDeviceKComboBox);
00243     mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
00244     mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
00245 
00246     // update the mVideoImageLabel to show the camera frames
00247     mVideoDevicePool->open();
00248     mVideoDevicePool->setSize(320, 240);
00249     mVideoDevicePool->startCapturing();
00250 
00251     setVideoInputParameters();
00252 
00253     qtimer.start(40);
00254     mPrfsVideoDevice->mVideoImageLabel->setScaledContents(true);
00255 }
00256 
00257 
00258 void AVDeviceConfig::deviceUnregistered( const QString & udi )
00259 {
00260 /*  mVideoDevicePool->fillDeviceKComboBox(mPrfsVideoDevice->mDeviceKComboBox);
00261     mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
00262     mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
00263 */}

kopete/kopete

Skip menu "kopete/kopete"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal