kpresenter

KPrPolygonProperty.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 "KPrPolygonProperty.h"
00022 
00023 #include <qlayout.h>
00024 
00025 #include <kcombobox.h>
00026 #include <klocale.h>
00027 #include <knuminput.h>
00028 
00029 #include "polygonpropertyui.h"
00030 #include "KPrPolygonPreview.h"
00031 
00032 KPrPolygonProperty::KPrPolygonProperty( QWidget *parent, const char *name, KPrPolygonSettingCmd::PolygonSettings &polygonSettings )
00033 : QWidget( parent, name )
00034 , m_polygonSettings( polygonSettings )
00035 {
00036     QVBoxLayout *layout = new QVBoxLayout( this );
00037     layout->addWidget( m_ui = new PolygonPropertyUI( this ) );
00038 
00039     m_ui->typeCombo->insertItem( i18n( "Polygon" ) );
00040     m_ui->typeCombo->insertItem( i18n( "Convex/Concave" ) );
00041 
00042     connect( m_ui->typeCombo, SIGNAL( activated( int ) ),
00043              this, SLOT(slotTypeChanged( int ) ) );
00044 
00045     connect( m_ui->cornersInput, SIGNAL( valueChanged( int ) ),
00046              m_ui->polygonPreview, SLOT( slotCornersValue( int ) ) );
00047     connect( m_ui->sharpnessInput, SIGNAL( valueChanged( int ) ),
00048              m_ui->polygonPreview, SLOT( slotSharpnessValue( int ) ) );
00049 
00050     slotReset();
00051 }
00052 
00053 
00054 KPrPolygonProperty::~KPrPolygonProperty()
00055 {
00056 }
00057 
00058 
00059 int KPrPolygonProperty::getPolygonPropertyChange() const
00060 {
00061     int flags = 0;
00062 
00063     if ( isConvexConcave() != m_polygonSettings.checkConcavePolygon )
00064         flags |= KPrPolygonSettingCmd::ConcaveConvex;
00065 
00066     if ( m_ui->cornersInput->value() != m_polygonSettings.cornersValue )
00067         flags |= KPrPolygonSettingCmd::Corners;
00068 
00069     if ( m_ui->sharpnessInput->value() != m_polygonSettings.sharpnessValue )
00070         flags |= KPrPolygonSettingCmd::Sharpness;
00071 
00072     return flags;
00073 }
00074 
00075 
00076 KPrPolygonSettingCmd::PolygonSettings KPrPolygonProperty::getPolygonSettings() const
00077 {
00078     KPrPolygonSettingCmd::PolygonSettings polygonSettings;
00079     polygonSettings.checkConcavePolygon = isConvexConcave();
00080     polygonSettings.cornersValue = m_ui->cornersInput->value();;
00081     polygonSettings.sharpnessValue = m_ui->sharpnessInput->value();;
00082     return polygonSettings;
00083 }
00084 
00085 
00086 void KPrPolygonProperty::setPolygonSettings( const KPrPolygonSettingCmd::PolygonSettings &polygonSettings )
00087 {
00088     m_polygonSettings = polygonSettings;
00089     slotReset();
00090 }
00091 
00092 
00093 void KPrPolygonProperty::apply()
00094 {
00095     int flags = getPolygonPropertyChange();
00096 
00097     if ( flags & KPrPolygonSettingCmd::ConcaveConvex )
00098         m_polygonSettings.checkConcavePolygon = isConvexConcave();
00099 
00100     if ( flags & KPrPolygonSettingCmd::Corners )
00101         m_polygonSettings.cornersValue = m_ui->cornersInput->value();
00102 
00103     if ( flags & KPrPolygonSettingCmd::Sharpness )
00104         m_polygonSettings.sharpnessValue = m_ui->sharpnessInput->value();
00105 }
00106 
00107 
00108 bool KPrPolygonProperty::isConvexConcave() const
00109 {
00110     return m_ui->typeCombo->currentItem() == 1;
00111 }
00112 
00113 
00114 void KPrPolygonProperty::slotTypeChanged( int pos )
00115 {
00116     m_ui->polygonPreview->slotConvexConcave( pos == 1 );
00117 
00118     m_ui->sharpnessInput->setEnabled( pos == 1 );
00119 }
00120 
00121 
00122 void KPrPolygonProperty::slotReset()
00123 {
00124     m_ui->typeCombo->setCurrentItem( m_polygonSettings.checkConcavePolygon ? 1 : 0 );
00125     m_ui->polygonPreview->slotConvexConcave( m_polygonSettings.checkConcavePolygon );
00126     m_ui->sharpnessInput->setEnabled( m_polygonSettings.checkConcavePolygon );
00127     m_ui->cornersInput->setValue( m_polygonSettings.cornersValue );
00128     m_ui->polygonPreview->slotCornersValue( m_polygonSettings.cornersValue );
00129     m_ui->sharpnessInput->setValue( m_polygonSettings.sharpnessValue );
00130     m_ui->polygonPreview->slotSharpnessValue( m_polygonSettings.sharpnessValue );
00131 }
00132 
00133 
00134 #include "KPrPolygonProperty.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys