kpresenter

KPrPictureProperty.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KPrPictureProperty.h"
00022 
00023 #include "picturepropertyui.h"
00024 #include "KPrPicturePreview.h"
00025 
00026 #include <knuminput.h>
00027 #include <qradiobutton.h>
00028 #include <qcheckbox.h>
00029 #include <qlayout.h>
00030 
00031 KPrPictureProperty::KPrPictureProperty( QWidget *parent, const char *name, const QPixmap &pixmap,
00032                                   KPrPictureSettingCmd::PictureSettings pictureSettings )
00033 : QWidget( parent, name )
00034 , m_pictureSettings( pictureSettings )
00035 {
00036     QVBoxLayout *layout = new QVBoxLayout( this );
00037     layout->addWidget( m_ui = new PicturePropertyUI( this ) );
00038 
00039     connect( m_ui->depth0, SIGNAL( clicked() ), m_ui->picturePreview, SLOT( slotPictureDepth0() ) );
00040     connect( m_ui->depth1, SIGNAL( clicked() ), m_ui->picturePreview, SLOT( slotPictureDepth1() ) );
00041     connect( m_ui->depth8, SIGNAL( clicked() ), m_ui->picturePreview, SLOT( slotPictureDepth8() ) );
00042     connect( m_ui->depth16, SIGNAL( clicked() ), m_ui->picturePreview, SLOT( slotPictureDepth16() ) );
00043     connect( m_ui->depth32, SIGNAL( clicked() ), m_ui->picturePreview, SLOT( slotPictureDepth32() ) );
00044 
00045     connect( m_ui->swapRGB, SIGNAL( toggled( bool ) ), m_ui->picturePreview, SLOT( slotSwapRGBPicture( bool ) ) );
00046 
00047     connect( m_ui->grayscale, SIGNAL( toggled( bool ) ), m_ui->picturePreview, SLOT( slotGrayscalPicture( bool ) ) );
00048 
00049     connect( m_ui->brightnessInput, SIGNAL( valueChanged( int ) ), m_ui->picturePreview, SLOT( slotBrightValue( int ) ) );
00050 
00051     m_ui->picturePreview->setPicturePixmap( pixmap );
00052 
00053     slotReset();
00054 }
00055 
00056 
00057 KPrPictureProperty::~KPrPictureProperty()
00058 {
00059 }
00060 
00061 
00062 int KPrPictureProperty::getPicturePropertyChange() const
00063 {
00064     int flags = 0;
00065 
00066     KPrPictureSettingCmd::PictureSettings pictureSettings = getPictureSettings();
00067 
00068     if ( pictureSettings.depth != m_pictureSettings.depth )
00069         flags |= KPrPictureSettingCmd::Depth;
00070 
00071     if ( pictureSettings.swapRGB != m_pictureSettings.swapRGB )
00072         flags |= KPrPictureSettingCmd::SwapRGB;
00073 
00074     if ( pictureSettings.grayscal != m_pictureSettings.grayscal )
00075         flags |= KPrPictureSettingCmd::Grayscal;
00076 
00077     if ( pictureSettings.bright != m_pictureSettings.bright )
00078         flags |= KPrPictureSettingCmd::Bright;
00079 
00080     return flags;
00081 }
00082 
00083 
00084 KPrPictureSettingCmd::PictureSettings KPrPictureProperty::getPictureSettings() const
00085 {
00086     KPrPictureSettingCmd::PictureSettings pictureSettings;
00087     pictureSettings.mirrorType = m_pictureSettings.mirrorType;
00088     pictureSettings.depth = m_ui->picturePreview->getDepth();
00089     pictureSettings.swapRGB = m_ui->swapRGB->isOn();
00090     pictureSettings.grayscal = m_ui->grayscale->isOn();
00091     pictureSettings.bright = m_ui->brightnessInput->value();
00092     return pictureSettings;
00093 }
00094 
00095 
00096 void KPrPictureProperty::apply()
00097 {
00098     int flags = getPicturePropertyChange();
00099 
00100     KPrPictureSettingCmd::PictureSettings pictureSettings = getPictureSettings();
00101 
00102     if ( flags & KPrPictureSettingCmd::Depth )
00103         m_pictureSettings.depth = pictureSettings.depth;
00104 
00105     if ( flags & KPrPictureSettingCmd::SwapRGB )
00106         m_pictureSettings.swapRGB = pictureSettings.swapRGB;
00107 
00108     if ( flags & KPrPictureSettingCmd::Grayscal )
00109         m_pictureSettings.grayscal = pictureSettings.grayscal;
00110 
00111     if ( flags & KPrPictureSettingCmd::Bright )
00112         m_pictureSettings.bright = pictureSettings.bright;
00113 }
00114 
00115 
00116 void KPrPictureProperty::slotReset()
00117 {
00118     m_ui->depth0->setChecked( m_pictureSettings.depth == 0 );
00119     m_ui->depth1->setChecked( m_pictureSettings.depth == 1 );
00120     m_ui->depth8->setChecked( m_pictureSettings.depth == 8 );
00121     m_ui->depth16->setChecked( m_pictureSettings.depth == 16 );
00122     m_ui->depth32->setChecked( m_pictureSettings.depth == 32 );
00123     m_ui->picturePreview->setDepth( m_pictureSettings.depth );
00124 
00125     m_ui->swapRGB->setChecked( m_pictureSettings.swapRGB );
00126     m_ui->grayscale->setChecked( m_pictureSettings.grayscal );
00127 
00128     m_ui->brightnessInput->setValue( m_pictureSettings.bright );
00129 }
00130 
00131 
00132 #include "KPrPictureProperty.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys