kpresenter

KPrPolygonProperty.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KPrPolygonProperty.h"
21
22#include <tqlayout.h>
23
24#include <kcombobox.h>
25#include <tdelocale.h>
26#include <knuminput.h>
27
28#include "polygonpropertyui.h"
29#include "KPrPolygonPreview.h"
30
31KPrPolygonProperty::KPrPolygonProperty( TQWidget *parent, const char *name, KPrPolygonSettingCmd::PolygonSettings &polygonSettings )
32: TQWidget( parent, name )
33, m_polygonSettings( polygonSettings )
34{
35 TQVBoxLayout *layout = new TQVBoxLayout( this );
36 layout->addWidget( m_ui = new PolygonPropertyUI( this ) );
37
38 m_ui->typeCombo->insertItem( i18n( "Polygon" ) );
39 m_ui->typeCombo->insertItem( i18n( "Convex/Concave" ) );
40
41 connect( m_ui->typeCombo, TQ_SIGNAL( activated( int ) ),
42 this, TQ_SLOT(slotTypeChanged( int ) ) );
43
44 connect( m_ui->cornersInput, TQ_SIGNAL( valueChanged( int ) ),
45 m_ui->polygonPreview, TQ_SLOT( slotCornersValue( int ) ) );
46 connect( m_ui->sharpnessInput, TQ_SIGNAL( valueChanged( int ) ),
47 m_ui->polygonPreview, TQ_SLOT( slotSharpnessValue( int ) ) );
48
49 slotReset();
50}
51
52
53KPrPolygonProperty::~KPrPolygonProperty()
54{
55}
56
57
58int KPrPolygonProperty::getPolygonPropertyChange() const
59{
60 int flags = 0;
61
62 if ( isConvexConcave() != m_polygonSettings.checkConcavePolygon )
63 flags |= KPrPolygonSettingCmd::ConcaveConvex;
64
65 if ( m_ui->cornersInput->value() != m_polygonSettings.cornersValue )
66 flags |= KPrPolygonSettingCmd::Corners;
67
68 if ( m_ui->sharpnessInput->value() != m_polygonSettings.sharpnessValue )
69 flags |= KPrPolygonSettingCmd::Sharpness;
70
71 return flags;
72}
73
74
75KPrPolygonSettingCmd::PolygonSettings KPrPolygonProperty::getPolygonSettings() const
76{
77 KPrPolygonSettingCmd::PolygonSettings polygonSettings;
78 polygonSettings.checkConcavePolygon = isConvexConcave();
79 polygonSettings.cornersValue = m_ui->cornersInput->value();;
80 polygonSettings.sharpnessValue = m_ui->sharpnessInput->value();;
81 return polygonSettings;
82}
83
84
85void KPrPolygonProperty::setPolygonSettings( const KPrPolygonSettingCmd::PolygonSettings &polygonSettings )
86{
87 m_polygonSettings = polygonSettings;
88 slotReset();
89}
90
91
92void KPrPolygonProperty::apply()
93{
94 int flags = getPolygonPropertyChange();
95
96 if ( flags & KPrPolygonSettingCmd::ConcaveConvex )
97 m_polygonSettings.checkConcavePolygon = isConvexConcave();
98
99 if ( flags & KPrPolygonSettingCmd::Corners )
100 m_polygonSettings.cornersValue = m_ui->cornersInput->value();
101
102 if ( flags & KPrPolygonSettingCmd::Sharpness )
103 m_polygonSettings.sharpnessValue = m_ui->sharpnessInput->value();
104}
105
106
107bool KPrPolygonProperty::isConvexConcave() const
108{
109 return m_ui->typeCombo->currentItem() == 1;
110}
111
112
113void KPrPolygonProperty::slotTypeChanged( int pos )
114{
115 m_ui->polygonPreview->slotConvexConcave( pos == 1 );
116
117 m_ui->sharpnessInput->setEnabled( pos == 1 );
118}
119
120
121void KPrPolygonProperty::slotReset()
122{
123 m_ui->typeCombo->setCurrentItem( m_polygonSettings.checkConcavePolygon ? 1 : 0 );
124 m_ui->polygonPreview->slotConvexConcave( m_polygonSettings.checkConcavePolygon );
125 m_ui->sharpnessInput->setEnabled( m_polygonSettings.checkConcavePolygon );
126 m_ui->cornersInput->setValue( m_polygonSettings.cornersValue );
127 m_ui->polygonPreview->slotCornersValue( m_polygonSettings.cornersValue );
128 m_ui->sharpnessInput->setValue( m_polygonSettings.sharpnessValue );
129 m_ui->polygonPreview->slotSharpnessValue( m_polygonSettings.sharpnessValue );
130}
131
132
133#include "KPrPolygonProperty.moc"