~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kpresenter/KPrTextProperty.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
4
 
 
5
   The code is mostly a copy from kword/framedia.cc
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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.
 
21
*/
 
22
 
 
23
#include "KPrTextProperty.h"
 
24
 
 
25
#include <qcheckbox.h>
 
26
#include <qlayout.h>
 
27
 
 
28
#include <klocale.h>
 
29
#include <kdebug.h>
 
30
 
 
31
#include "KPrMarginWidget.h"
 
32
 
 
33
 
 
34
KPrTextProperty::KPrTextProperty( QWidget *parent, const char *name, const MarginsStruct &marginsStruct,
 
35
                            const KoUnit::Unit unit, PropValue protectContent )
 
36
: QWidget( parent, name )
 
37
, m_unit( unit )
 
38
, m_protectContent( protectContent )
 
39
{
 
40
    QGridLayout *layout = new QGridLayout( this, 1, 1, 11, 6 );
 
41
 
 
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 );
 
44
 
 
45
    connect( m_protectContentCheck, SIGNAL( toggled ( bool ) ),
 
46
             this, SLOT( slotProtectContentChanged( bool ) ) );
 
47
 
 
48
    resize( QSize( 301, 217 ).expandedTo( minimumSizeHint() ) );
 
49
 
 
50
    m_margins->setValues( marginsStruct.leftMargin, marginsStruct.rightMargin,
 
51
                          marginsStruct.topMargin, marginsStruct.bottomMargin );
 
52
 
 
53
    slotReset();
 
54
}
 
55
 
 
56
 
 
57
KPrTextProperty::~KPrTextProperty()
 
58
{
 
59
}
 
60
 
 
61
 
 
62
int KPrTextProperty::getTextPropertyChange() const
 
63
{
 
64
    int flags = 0;
 
65
 
 
66
    if ( m_protectContentCheck->state() != QButton::NoChange )
 
67
    {
 
68
        if ( ( m_protectContentCheck->isOn() ? STATE_ON : STATE_OFF ) != m_protectContent )
 
69
        {
 
70
            flags |= ProtectContent;
 
71
        }
 
72
 
 
73
        if ( ! m_protectContentCheck->isOn() && m_margins->changed() )
 
74
        {
 
75
            flags |= Margins;
 
76
        }
 
77
    }
 
78
 
 
79
    return flags;
 
80
}
 
81
 
 
82
 
 
83
MarginsStruct KPrTextProperty::getMarginsStruct() const
 
84
{
 
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();
 
90
    return marginsStruct;
 
91
}
 
92
 
 
93
 
 
94
bool KPrTextProperty::getProtectContent() const
 
95
{
 
96
    return m_protectContentCheck->isOn();
 
97
}
 
98
 
 
99
 
 
100
void KPrTextProperty::apply()
 
101
{
 
102
    int flags = getTextPropertyChange();
 
103
 
 
104
    if ( flags & ProtectContent )
 
105
        m_protectContent = m_protectContentCheck->isOn() ? STATE_ON : STATE_OFF;
 
106
 
 
107
    if ( flags & Margins )
 
108
        m_margins->resetChanged();
 
109
}
 
110
 
 
111
 
 
112
void KPrTextProperty::slotProtectContentChanged( bool b )
 
113
{
 
114
    m_margins->setEnabled( !b );
 
115
}
 
116
 
 
117
 
 
118
void KPrTextProperty::slotReset()
 
119
{
 
120
    switch ( m_protectContent )
 
121
    {
 
122
        case STATE_ON:
 
123
            m_protectContentCheck->setChecked( true );
 
124
            break;
 
125
        case STATE_OFF:
 
126
            m_protectContentCheck->setChecked( false );
 
127
            break;
 
128
        case STATE_UNDEF:
 
129
            m_protectContentCheck->setTristate( true );
 
130
            m_protectContentCheck->setNoChange();
 
131
            break;
 
132
        default:
 
133
            m_protectContentCheck->setChecked( false );
 
134
            break;
 
135
    }
 
136
}
 
137
 
 
138
 
 
139
#include "KPrTextProperty.moc"