kpresenter

KPrTextProperty.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
3
4 The code is mostly a copy from kword/framedia.cpp
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#include "KPrTextProperty.h"
23
24#include <tqcheckbox.h>
25#include <tqlayout.h>
26
27#include <tdelocale.h>
28#include <kdebug.h>
29
30#include "KPrMarginWidget.h"
31
32
33KPrTextProperty::KPrTextProperty( TQWidget *parent, const char *name, const MarginsStruct &marginsStruct,
34 const KoUnit::Unit unit, PropValue protectContent )
35: TQWidget( parent, name )
36, m_unit( unit )
37, m_protectContent( protectContent )
38{
39 TQGridLayout *layout = new TQGridLayout( this, 1, 1, 11, 6 );
40
41 layout->addWidget( m_protectContentCheck = new TQCheckBox( i18n( "Protect content" ), this ), 0, 0 );
42 layout->addWidget( m_margins = new KPrMarginWidget( this, name, m_unit ), 1, 0 );
43
44 connect( m_protectContentCheck, TQ_SIGNAL( toggled ( bool ) ),
45 this, TQ_SLOT( slotProtectContentChanged( bool ) ) );
46
47 resize( TQSize( 301, 217 ).expandedTo( minimumSizeHint() ) );
48
49 m_margins->setValues( marginsStruct.leftMargin, marginsStruct.rightMargin,
50 marginsStruct.topMargin, marginsStruct.bottomMargin );
51
52 slotReset();
53}
54
55
56KPrTextProperty::~KPrTextProperty()
57{
58}
59
60
61int KPrTextProperty::getTextPropertyChange() const
62{
63 int flags = 0;
64
65 if ( m_protectContentCheck->state() != TQButton::NoChange )
66 {
67 if ( ( m_protectContentCheck->isOn() ? STATE_ON : STATE_OFF ) != m_protectContent )
68 {
69 flags |= ProtectContent;
70 }
71
72 if ( ! m_protectContentCheck->isOn() && m_margins->changed() )
73 {
74 flags |= Margins;
75 }
76 }
77
78 return flags;
79}
80
81
82MarginsStruct KPrTextProperty::getMarginsStruct() const
83{
84 MarginsStruct marginsStruct;
85 marginsStruct.leftMargin = m_margins->leftValue();
86 marginsStruct.rightMargin = m_margins->rightValue();
87 marginsStruct.topMargin = m_margins->topValue();
88 marginsStruct.bottomMargin = m_margins->bottomValue();
89 return marginsStruct;
90}
91
92
93bool KPrTextProperty::getProtectContent() const
94{
95 return m_protectContentCheck->isOn();
96}
97
98
99void KPrTextProperty::apply()
100{
101 int flags = getTextPropertyChange();
102
103 if ( flags & ProtectContent )
104 m_protectContent = m_protectContentCheck->isOn() ? STATE_ON : STATE_OFF;
105
106 if ( flags & Margins )
107 m_margins->resetChanged();
108}
109
110
111void KPrTextProperty::slotProtectContentChanged( bool b )
112{
113 m_margins->setEnabled( !b );
114}
115
116
117void KPrTextProperty::slotReset()
118{
119 switch ( m_protectContent )
120 {
121 case STATE_ON:
122 m_protectContentCheck->setChecked( true );
123 break;
124 case STATE_OFF:
125 m_protectContentCheck->setChecked( false );
126 break;
127 case STATE_UNDEF:
128 m_protectContentCheck->setTristate( true );
129 m_protectContentCheck->setNoChange();
130 break;
131 default:
132 m_protectContentCheck->setChecked( false );
133 break;
134 }
135}
136
137
138#include "KPrTextProperty.moc"