summaryrefslogtreecommitdiffstats
path: root/kpresenter/KPrGeneralProperty.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /kpresenter/KPrGeneralProperty.cpp
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpresenter/KPrGeneralProperty.cpp')
-rw-r--r--kpresenter/KPrGeneralProperty.cpp254
1 files changed, 254 insertions, 0 deletions
diff --git a/kpresenter/KPrGeneralProperty.cpp b/kpresenter/KPrGeneralProperty.cpp
new file mode 100644
index 00000000..e07bf84c
--- /dev/null
+++ b/kpresenter/KPrGeneralProperty.cpp
@@ -0,0 +1,254 @@
+// -*- 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 "KPrGeneralProperty.h"
+
+#include <qcheckbox.h>
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+
+#include <knuminput.h>
+#include <klocale.h>
+#include <KoUnitWidgets.h>
+
+#include <KoGeneralPropertyUi.h>
+
+KPrGeneralProperty::KPrGeneralProperty( QWidget *parent, const char *name, GeneralValue &generalValue, KoUnit::Unit unit )
+: QWidget( parent, name )
+, m_ratio( 1.0 )
+, m_generalValue( generalValue )
+, m_unit( unit )
+{
+ QVBoxLayout *layout = new QVBoxLayout( this );
+ layout->addWidget( m_ui = new KoGeneralPropertyUI( this ) );
+
+ QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ layout->addItem( spacer );
+
+ if ( m_generalValue.m_name.isNull() )
+ {
+ m_ui->nameLabel->setEnabled( false );
+ m_ui->nameInput->setEnabled( false );
+ }
+ else
+ {
+ m_ui->nameInput->setText( m_generalValue.m_name );
+ }
+
+ m_ui->positionGroup->setTitle( i18n( "Position" ) );
+
+ connect( m_ui->protect, SIGNAL( toggled( bool ) ), this, SLOT( slotProtectToggled( bool ) ) );
+ connect( m_ui->keepRatio, SIGNAL( toggled( bool ) ), this, SLOT( slotKeepRatioToggled( bool ) ) );
+
+ double dStep = KoUnit::fromUserValue( 0.5, m_unit );
+ double dMax = KoUnit::fromUserValue( 9999, m_unit );
+ m_ui->xInput->setUnit( m_unit );
+ m_ui->xInput->setMinMaxStep( 0, dMax, dStep );
+
+ m_ui->yInput->setUnit( m_unit );
+ m_ui->yInput->setMinMaxStep( 0, dMax, dStep );
+
+ m_ui->widthInput->setUnit( m_unit );
+ m_ui->widthInput->setMinMaxStep( 0, dMax, dStep );
+ connect( m_ui->widthInput, SIGNAL( valueChanged( double ) ), this, SLOT( slotWidthChanged( double ) ) );
+
+ m_ui->heightInput->setUnit( m_unit );
+ m_ui->heightInput->setMinMaxStep( 0, dMax, dStep );
+ connect( m_ui->heightInput, SIGNAL( valueChanged( double ) ), this, SLOT( slotHeightChanged( double ) ) );
+ slotReset();
+}
+
+
+KPrGeneralProperty::~KPrGeneralProperty()
+{
+}
+
+
+int KPrGeneralProperty::getGeneralPropertyChange() const
+{
+ int flags = 0;
+
+ if ( !m_generalValue.m_name.isNull() && m_generalValue.m_name != m_ui->nameInput->text() )
+ flags |= Name;
+
+ if ( m_ui->protect->state() != QButton::NoChange )
+ {
+ if ( ( m_ui->protect->isOn() ? STATE_ON : STATE_OFF ) != m_generalValue.m_protect )
+ flags |= Protect;
+
+ if ( !m_ui->protect->isOn() )
+ {
+ KoRect rect = getRect();
+ if ( m_generalValue.m_rect.left() != rect.left() )
+ flags |= Left;
+ if ( m_generalValue.m_rect.top() != rect.top() )
+ flags |= Top;
+ // this has to be done as the rect cahnges width/hight if left or top is changed
+ if ( QABS( m_generalValue.m_rect.width() - rect.width() ) > 1e-6 )
+ flags |= Width;
+ if ( QABS( m_generalValue.m_rect.height() - rect.height() ) > 1e-6 )
+ flags |= Height;
+ }
+ }
+
+ if ( m_ui->keepRatio->state() != QButton::NoChange
+ && ( m_ui->keepRatio->isOn() ? STATE_ON : STATE_OFF ) != m_generalValue.m_keepRatio )
+ {
+ flags |= KeepRatio;
+ }
+
+ return flags;
+}
+
+
+KPrGeneralProperty::GeneralValue KPrGeneralProperty::getGeneralValue() const
+{
+ GeneralValue generalValue;
+ generalValue.m_name = m_ui->nameInput->isEnabled() ? m_ui->nameInput->text() : QString();
+ generalValue.m_protect = m_ui->protect->isOn() ? STATE_ON : STATE_OFF;
+ generalValue.m_keepRatio = m_ui->keepRatio->isOn() ? STATE_ON : STATE_OFF;
+ generalValue.m_rect = getRect();
+ return generalValue;
+}
+
+
+void KPrGeneralProperty::apply()
+{
+ int flags = getGeneralPropertyChange();
+
+ if ( flags & Name )
+ m_generalValue.m_name = m_ui->nameInput->text();
+
+ if ( flags & Protect )
+ m_generalValue.m_protect = m_ui->protect->isOn() ? STATE_ON : STATE_OFF;
+
+ if ( flags & KeepRatio )
+ m_generalValue.m_keepRatio = m_ui->keepRatio->isOn() ? STATE_ON : STATE_OFF;
+
+ // get the values to the actual rect
+ m_generalValue.m_rect = getRect();
+}
+
+
+KoRect KPrGeneralProperty::getRect() const
+{
+ double x = QMAX( 0, m_ui->xInput->value() );
+ double y = QMAX( 0, m_ui->yInput->value() );
+ double w = QMAX( 0, m_ui->widthInput->value() );
+ double h = QMAX( 0, m_ui->heightInput->value() );
+
+ KoRect rect( x, y, w, h );
+ return rect;
+}
+
+
+void KPrGeneralProperty::setRect( KoRect &rect )
+{
+ m_ui->xInput->changeValue( QMAX( 0.00, rect.left() ) );
+ m_ui->yInput->changeValue( QMAX( 0.00, rect.top() ) );
+ m_ui->widthInput->changeValue( QMAX( 0.00, rect.width() ) );
+ m_ui->heightInput->changeValue( QMAX( 0.00, rect.height() ) );
+}
+
+
+void KPrGeneralProperty::slotReset()
+{
+ switch ( m_generalValue.m_protect )
+ {
+ case STATE_ON:
+ m_ui->protect->setChecked( true );
+ break;
+ case STATE_OFF:
+ m_ui->protect->setChecked( false );
+ break;
+ case STATE_UNDEF:
+ m_ui->protect->setTristate( true );
+ m_ui->protect->setNoChange();
+ break;
+ default:
+ m_ui->protect->setChecked( false );
+ break;
+ }
+
+ switch ( m_generalValue.m_keepRatio )
+ {
+ case STATE_ON:
+ m_ui->keepRatio->setChecked( true );
+ break;
+ case STATE_OFF:
+ m_ui->keepRatio->setChecked( false );
+ break;
+ case STATE_UNDEF:
+ m_ui->keepRatio->setTristate( true );
+ m_ui->keepRatio->setNoChange();
+ break;
+ default:
+ m_ui->keepRatio->setChecked( false );
+ break;
+ }
+
+ setRect( m_generalValue.m_rect );
+ // this is done due to the rounding so we can detect a change
+ m_generalValue.m_rect = getRect();
+}
+
+
+void KPrGeneralProperty::slotProtectToggled( bool state )
+{
+ m_ui->positionGroup->setEnabled( !state );
+}
+
+
+void KPrGeneralProperty::slotKeepRatioToggled( bool state )
+{
+ if ( state )
+ {
+ if ( m_ui->widthInput->value() == 0 )
+ {
+ m_ratio = 1.0;
+ }
+ else
+ {
+ m_ratio = m_ui->heightInput->value() / m_ui->widthInput->value();
+ }
+ }
+}
+
+
+void KPrGeneralProperty::slotWidthChanged( double value )
+{
+ if ( m_ui->keepRatio->isChecked() )
+ {
+ m_ui->heightInput->setValue( value * m_ratio );
+ }
+}
+
+
+void KPrGeneralProperty::slotHeightChanged( double value )
+{
+ if ( m_ui->keepRatio->isChecked() && m_ratio != 0 )
+ {
+ m_ui->widthInput->setValue( value / m_ratio );
+ }
+}
+
+
+#include "KPrGeneralProperty.moc"