1
// -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
2
/* This file is part of the KDE project
3
Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
5
The code is mostly a copy from kword/framedia.cc
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Library General Public
9
License as published by the Free Software Foundation; either
10
version 2 of the License, or (at your option) any later version.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Library General Public License for more details.
17
You should have received a copy of the GNU Library General Public License
18
along with this library; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
* Boston, MA 02110-1301, USA.
23
#include "KPrTextProperty.h"
25
#include <qcheckbox.h>
31
#include "KPrMarginWidget.h"
34
KPrTextProperty::KPrTextProperty( QWidget *parent, const char *name, const MarginsStruct &marginsStruct,
35
const KoUnit::Unit unit, PropValue protectContent )
36
: QWidget( parent, name )
38
, m_protectContent( protectContent )
40
QGridLayout *layout = new QGridLayout( this, 1, 1, 11, 6 );
42
layout->addWidget( m_protectContentCheck = new QCheckBox( i18n( "Protect content" ), this ), 0, 0 );
43
layout->addWidget( m_margins = new KPrMarginWidget( this, name, m_unit ), 1, 0 );
45
connect( m_protectContentCheck, SIGNAL( toggled ( bool ) ),
46
this, SLOT( slotProtectContentChanged( bool ) ) );
48
resize( QSize( 301, 217 ).expandedTo( minimumSizeHint() ) );
50
m_margins->setValues( marginsStruct.leftMargin, marginsStruct.rightMargin,
51
marginsStruct.topMargin, marginsStruct.bottomMargin );
57
KPrTextProperty::~KPrTextProperty()
62
int KPrTextProperty::getTextPropertyChange() const
66
if ( m_protectContentCheck->state() != QButton::NoChange )
68
if ( ( m_protectContentCheck->isOn() ? STATE_ON : STATE_OFF ) != m_protectContent )
70
flags |= ProtectContent;
73
if ( ! m_protectContentCheck->isOn() && m_margins->changed() )
83
MarginsStruct KPrTextProperty::getMarginsStruct() const
85
MarginsStruct marginsStruct;
86
marginsStruct.leftMargin = m_margins->leftValue();
87
marginsStruct.rightMargin = m_margins->rightValue();
88
marginsStruct.topMargin = m_margins->topValue();
89
marginsStruct.bottomMargin = m_margins->bottomValue();
94
bool KPrTextProperty::getProtectContent() const
96
return m_protectContentCheck->isOn();
100
void KPrTextProperty::apply()
102
int flags = getTextPropertyChange();
104
if ( flags & ProtectContent )
105
m_protectContent = m_protectContentCheck->isOn() ? STATE_ON : STATE_OFF;
107
if ( flags & Margins )
108
m_margins->resetChanged();
112
void KPrTextProperty::slotProtectContentChanged( bool b )
114
m_margins->setEnabled( !b );
118
void KPrTextProperty::slotReset()
120
switch ( m_protectContent )
123
m_protectContentCheck->setChecked( true );
126
m_protectContentCheck->setChecked( false );
129
m_protectContentCheck->setTristate( true );
130
m_protectContentCheck->setNoChange();
133
m_protectContentCheck->setChecked( false );
139
#include "KPrTextProperty.moc"