summaryrefslogtreecommitdiffstats
path: root/kpresenter/KPrPieProperty.cpp
blob: 694a9653f3171b57fa25b6bc87d3e69965a38d33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
/* This file is part of the KDE project
   Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "KPrPieProperty.h"

#include <tqlayout.h>

#include <kcombobox.h>
#include <klocale.h>
#include <knuminput.h>

#include "global.h"
#include "piepropertyui.h"
#include "KPrPiePreview.h"


KPrPieProperty::KPrPieProperty( TQWidget *parent, const char *name, KPrPieValueCmd::PieValues pieValues )
: TQWidget( parent, name )
, m_pieValues( pieValues )
{
    TQVBoxLayout *tqlayout = new TQVBoxLayout( this );
    tqlayout->addWidget( m_ui = new PiePropertyUI( this ) );

    m_ui->typeCombo->insertItem( i18n( "Pie" ) );
    m_ui->typeCombo->insertItem( i18n( "Arc" ) );
    m_ui->typeCombo->insertItem( i18n( "Chord" ) );

    connect( m_ui->typeCombo, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( slotTypeChanged( int ) ) );

    connect( m_ui->angleInput, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( slotAngleChanged( int ) ) );
    connect( m_ui->lengthInput, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( slotLengthChanged( int ) ) );

    slotReset();
}


KPrPieProperty::~KPrPieProperty()
{
}


int KPrPieProperty::getPiePropertyChange() const
{
    int flags = 0;

    KPrPieValueCmd::PieValues pieValues = getPieValues();

    if ( pieValues.pieType != m_pieValues.pieType )
        flags |= KPrPieValueCmd::Type;

    if ( pieValues.pieAngle != m_pieValues.pieAngle )
        flags |= KPrPieValueCmd::Angle;

    if ( pieValues.pieLength != m_pieValues.pieLength )
        flags |= KPrPieValueCmd::Length;

    return flags;
}


KPrPieValueCmd::PieValues KPrPieProperty::getPieValues() const
{
    KPrPieValueCmd::PieValues pieValues;
    pieValues.pieType = static_cast<PieType>( m_ui->typeCombo->currentItem() );
    pieValues.pieAngle = m_ui->angleInput->value() * 16;
    pieValues.pieLength = m_ui->lengthInput->value() * 16;
    return pieValues;
}


void KPrPieProperty::setPieValues( const KPrPieValueCmd::PieValues &pieValues )
{
    m_pieValues = pieValues;
    slotReset();
}


void KPrPieProperty::apply()
{
    int flags = getPiePropertyChange();

    KPrPieValueCmd::PieValues pieValues = getPieValues();

    if ( flags & KPrPieValueCmd::Type )
        m_pieValues.pieType = pieValues.pieType;

    if ( flags & KPrPieValueCmd::Angle )
        m_pieValues.pieAngle = pieValues.pieAngle;

    if ( flags & KPrPieValueCmd::Length )
        m_pieValues.pieLength = pieValues.pieLength;
}


void KPrPieProperty::slotReset()
{
    m_ui->typeCombo->setCurrentItem( ( int ) m_pieValues.pieType );
    m_ui->piePreview->setType( m_pieValues.pieType );
    m_ui->angleInput->setValue( m_pieValues.pieAngle / 16 );
    m_ui->piePreview->setAngle( m_pieValues.pieAngle );
    m_ui->lengthInput->setValue( m_pieValues.pieLength / 16 );
    m_ui->piePreview->setLength( m_pieValues.pieLength );
}


void KPrPieProperty::slotTypeChanged( int pos )
{
    m_ui->piePreview->setType( static_cast<PieType>( pos ) );
}


void KPrPieProperty::slotAngleChanged( int num )
{
    m_ui->piePreview->setAngle( num * 16 );
}


void KPrPieProperty::slotLengthChanged( int num )
{
    m_ui->piePreview->setLength( num * 16 );
}


#include "KPrPieProperty.moc"