kpresenter

KPrPieProperty.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 "KPrPieProperty.h"
21
22#include <tqlayout.h>
23
24#include <kcombobox.h>
25#include <tdelocale.h>
26#include <knuminput.h>
27
28#include "global.h"
29#include "piepropertyui.h"
30#include "KPrPiePreview.h"
31
32
33KPrPieProperty::KPrPieProperty( TQWidget *parent, const char *name, KPrPieValueCmd::PieValues pieValues )
34: TQWidget( parent, name )
35, m_pieValues( pieValues )
36{
37 TQVBoxLayout *layout = new TQVBoxLayout( this );
38 layout->addWidget( m_ui = new PiePropertyUI( this ) );
39
40 m_ui->typeCombo->insertItem( i18n( "Pie" ) );
41 m_ui->typeCombo->insertItem( i18n( "Arc" ) );
42 m_ui->typeCombo->insertItem( i18n( "Chord" ) );
43
44 connect( m_ui->typeCombo, TQ_SIGNAL( activated( int ) ), this, TQ_SLOT( slotTypeChanged( int ) ) );
45
46 connect( m_ui->angleInput, TQ_SIGNAL( valueChanged( int ) ), this, TQ_SLOT( slotAngleChanged( int ) ) );
47 connect( m_ui->lengthInput, TQ_SIGNAL( valueChanged( int ) ), this, TQ_SLOT( slotLengthChanged( int ) ) );
48
49 slotReset();
50}
51
52
53KPrPieProperty::~KPrPieProperty()
54{
55}
56
57
58int KPrPieProperty::getPiePropertyChange() const
59{
60 int flags = 0;
61
62 KPrPieValueCmd::PieValues pieValues = getPieValues();
63
64 if ( pieValues.pieType != m_pieValues.pieType )
65 flags |= KPrPieValueCmd::Type;
66
67 if ( pieValues.pieAngle != m_pieValues.pieAngle )
68 flags |= KPrPieValueCmd::Angle;
69
70 if ( pieValues.pieLength != m_pieValues.pieLength )
71 flags |= KPrPieValueCmd::Length;
72
73 return flags;
74}
75
76
77KPrPieValueCmd::PieValues KPrPieProperty::getPieValues() const
78{
79 KPrPieValueCmd::PieValues pieValues;
80 pieValues.pieType = static_cast<PieType>( m_ui->typeCombo->currentItem() );
81 pieValues.pieAngle = m_ui->angleInput->value() * 16;
82 pieValues.pieLength = m_ui->lengthInput->value() * 16;
83 return pieValues;
84}
85
86
87void KPrPieProperty::setPieValues( const KPrPieValueCmd::PieValues &pieValues )
88{
89 m_pieValues = pieValues;
90 slotReset();
91}
92
93
94void KPrPieProperty::apply()
95{
96 int flags = getPiePropertyChange();
97
98 KPrPieValueCmd::PieValues pieValues = getPieValues();
99
100 if ( flags & KPrPieValueCmd::Type )
101 m_pieValues.pieType = pieValues.pieType;
102
103 if ( flags & KPrPieValueCmd::Angle )
104 m_pieValues.pieAngle = pieValues.pieAngle;
105
106 if ( flags & KPrPieValueCmd::Length )
107 m_pieValues.pieLength = pieValues.pieLength;
108}
109
110
111void KPrPieProperty::slotReset()
112{
113 m_ui->typeCombo->setCurrentItem( ( int ) m_pieValues.pieType );
114 m_ui->piePreview->setType( m_pieValues.pieType );
115 m_ui->angleInput->setValue( m_pieValues.pieAngle / 16 );
116 m_ui->piePreview->setAngle( m_pieValues.pieAngle );
117 m_ui->lengthInput->setValue( m_pieValues.pieLength / 16 );
118 m_ui->piePreview->setLength( m_pieValues.pieLength );
119}
120
121
122void KPrPieProperty::slotTypeChanged( int pos )
123{
124 m_ui->piePreview->setType( static_cast<PieType>( pos ) );
125}
126
127
128void KPrPieProperty::slotAngleChanged( int num )
129{
130 m_ui->piePreview->setAngle( num * 16 );
131}
132
133
134void KPrPieProperty::slotLengthChanged( int num )
135{
136 m_ui->piePreview->setLength( num * 16 );
137}
138
139
140#include "KPrPieProperty.moc"