kpresenter

KPrPieProperty.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 "KPrPieProperty.h"
00022 
00023 #include <qlayout.h>
00024 
00025 #include <kcombobox.h>
00026 #include <klocale.h>
00027 #include <knuminput.h>
00028 
00029 #include "global.h"
00030 #include "piepropertyui.h"
00031 #include "KPrPiePreview.h"
00032 
00033 
00034 KPrPieProperty::KPrPieProperty( QWidget *parent, const char *name, KPrPieValueCmd::PieValues pieValues )
00035 : QWidget( parent, name )
00036 , m_pieValues( pieValues )
00037 {
00038     QVBoxLayout *layout = new QVBoxLayout( this );
00039     layout->addWidget( m_ui = new PiePropertyUI( this ) );
00040 
00041     m_ui->typeCombo->insertItem( i18n( "Pie" ) );
00042     m_ui->typeCombo->insertItem( i18n( "Arc" ) );
00043     m_ui->typeCombo->insertItem( i18n( "Chord" ) );
00044 
00045     connect( m_ui->typeCombo, SIGNAL( activated( int ) ), this, SLOT( slotTypeChanged( int ) ) );
00046 
00047     connect( m_ui->angleInput, SIGNAL( valueChanged( int ) ), this, SLOT( slotAngleChanged( int ) ) );
00048     connect( m_ui->lengthInput, SIGNAL( valueChanged( int ) ), this, SLOT( slotLengthChanged( int ) ) );
00049 
00050     slotReset();
00051 }
00052 
00053 
00054 KPrPieProperty::~KPrPieProperty()
00055 {
00056 }
00057 
00058 
00059 int KPrPieProperty::getPiePropertyChange() const
00060 {
00061     int flags = 0;
00062 
00063     KPrPieValueCmd::PieValues pieValues = getPieValues();
00064 
00065     if ( pieValues.pieType != m_pieValues.pieType )
00066         flags |= KPrPieValueCmd::Type;
00067 
00068     if ( pieValues.pieAngle != m_pieValues.pieAngle )
00069         flags |= KPrPieValueCmd::Angle;
00070 
00071     if ( pieValues.pieLength != m_pieValues.pieLength )
00072         flags |= KPrPieValueCmd::Length;
00073 
00074     return flags;
00075 }
00076 
00077 
00078 KPrPieValueCmd::PieValues KPrPieProperty::getPieValues() const
00079 {
00080     KPrPieValueCmd::PieValues pieValues;
00081     pieValues.pieType = static_cast<PieType>( m_ui->typeCombo->currentItem() );
00082     pieValues.pieAngle = m_ui->angleInput->value() * 16;
00083     pieValues.pieLength = m_ui->lengthInput->value() * 16;
00084     return pieValues;
00085 }
00086 
00087 
00088 void KPrPieProperty::setPieValues( const KPrPieValueCmd::PieValues &pieValues )
00089 {
00090     m_pieValues = pieValues;
00091     slotReset();
00092 }
00093 
00094 
00095 void KPrPieProperty::apply()
00096 {
00097     int flags = getPiePropertyChange();
00098 
00099     KPrPieValueCmd::PieValues pieValues = getPieValues();
00100 
00101     if ( flags & KPrPieValueCmd::Type )
00102         m_pieValues.pieType = pieValues.pieType;
00103 
00104     if ( flags & KPrPieValueCmd::Angle )
00105         m_pieValues.pieAngle = pieValues.pieAngle;
00106 
00107     if ( flags & KPrPieValueCmd::Length )
00108         m_pieValues.pieLength = pieValues.pieLength;
00109 }
00110 
00111 
00112 void KPrPieProperty::slotReset()
00113 {
00114     m_ui->typeCombo->setCurrentItem( ( int ) m_pieValues.pieType );
00115     m_ui->piePreview->setType( m_pieValues.pieType );
00116     m_ui->angleInput->setValue( m_pieValues.pieAngle / 16 );
00117     m_ui->piePreview->setAngle( m_pieValues.pieAngle );
00118     m_ui->lengthInput->setValue( m_pieValues.pieLength / 16 );
00119     m_ui->piePreview->setLength( m_pieValues.pieLength );
00120 }
00121 
00122 
00123 void KPrPieProperty::slotTypeChanged( int pos )
00124 {
00125     m_ui->piePreview->setType( static_cast<PieType>( pos ) );
00126 }
00127 
00128 
00129 void KPrPieProperty::slotAngleChanged( int num )
00130 {
00131     m_ui->piePreview->setAngle( num * 16 );
00132 }
00133 
00134 
00135 void KPrPieProperty::slotLengthChanged( int num )
00136 {
00137     m_ui->piePreview->setLength( num * 16 );
00138 }
00139 
00140 
00141 #include "KPrPieProperty.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys