kpresenter

KPrTextProperty.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
00004 
00005    The code is mostly a copy from kword/framedia.cc
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "KPrTextProperty.h"
00024 
00025 #include <qcheckbox.h>
00026 #include <qlayout.h>
00027 
00028 #include <klocale.h>
00029 #include <kdebug.h>
00030 
00031 #include "KPrMarginWidget.h"
00032 
00033 
00034 KPrTextProperty::KPrTextProperty( QWidget *parent, const char *name, const MarginsStruct &marginsStruct,
00035                             const KoUnit::Unit unit, PropValue protectContent )
00036 : QWidget( parent, name )
00037 , m_unit( unit )
00038 , m_protectContent( protectContent )
00039 {
00040     QGridLayout *layout = new QGridLayout( this, 1, 1, 11, 6 );
00041 
00042     layout->addWidget( m_protectContentCheck = new QCheckBox( i18n( "Protect content" ), this ), 0, 0 );
00043     layout->addWidget( m_margins = new KPrMarginWidget( this, name, m_unit ), 1, 0 );
00044 
00045     connect( m_protectContentCheck, SIGNAL( toggled ( bool ) ),
00046              this, SLOT( slotProtectContentChanged( bool ) ) );
00047 
00048     resize( QSize( 301, 217 ).expandedTo( minimumSizeHint() ) );
00049 
00050     m_margins->setValues( marginsStruct.leftMargin, marginsStruct.rightMargin,
00051                           marginsStruct.topMargin, marginsStruct.bottomMargin );
00052 
00053     slotReset();
00054 }
00055 
00056 
00057 KPrTextProperty::~KPrTextProperty()
00058 {
00059 }
00060 
00061 
00062 int KPrTextProperty::getTextPropertyChange() const
00063 {
00064     int flags = 0;
00065 
00066     if ( m_protectContentCheck->state() != QButton::NoChange )
00067     {
00068         if ( ( m_protectContentCheck->isOn() ? STATE_ON : STATE_OFF ) != m_protectContent )
00069         {
00070             flags |= ProtectContent;
00071         }
00072 
00073         if ( ! m_protectContentCheck->isOn() && m_margins->changed() )
00074         {
00075             flags |= Margins;
00076         }
00077     }
00078 
00079     return flags;
00080 }
00081 
00082 
00083 MarginsStruct KPrTextProperty::getMarginsStruct() const
00084 {
00085     MarginsStruct marginsStruct;
00086     marginsStruct.leftMargin = m_margins->leftValue();
00087     marginsStruct.rightMargin = m_margins->rightValue();
00088     marginsStruct.topMargin = m_margins->topValue();
00089     marginsStruct.bottomMargin = m_margins->bottomValue();
00090     return marginsStruct;
00091 }
00092 
00093 
00094 bool KPrTextProperty::getProtectContent() const
00095 {
00096     return m_protectContentCheck->isOn();
00097 }
00098 
00099 
00100 void KPrTextProperty::apply()
00101 {
00102     int flags = getTextPropertyChange();
00103 
00104     if ( flags & ProtectContent )
00105         m_protectContent = m_protectContentCheck->isOn() ? STATE_ON : STATE_OFF;
00106 
00107     if ( flags & Margins )
00108         m_margins->resetChanged();
00109 }
00110 
00111 
00112 void KPrTextProperty::slotProtectContentChanged( bool b )
00113 {
00114     m_margins->setEnabled( !b );
00115 }
00116 
00117 
00118 void KPrTextProperty::slotReset()
00119 {
00120     switch ( m_protectContent )
00121     {
00122         case STATE_ON:
00123             m_protectContentCheck->setChecked( true );
00124             break;
00125         case STATE_OFF:
00126             m_protectContentCheck->setChecked( false );
00127             break;
00128         case STATE_UNDEF:
00129             m_protectContentCheck->setTristate( true );
00130             m_protectContentCheck->setNoChange();
00131             break;
00132         default:
00133             m_protectContentCheck->setChecked( false );
00134             break;
00135     }
00136 }
00137 
00138 
00139 #include "KPrTextProperty.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys