lib

KoGuideLineDia.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)  2002 Montel Laurent <lmontel@mandrakesoft.com>
00004    Copyright (C)  2005 Thorsten Zachmann <zachmann@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "KoGuideLineDia.h"
00023 
00024 #include <qbuttongroup.h>
00025 #include <qhbox.h>
00026 #include <qvbox.h>
00027 #include <qlabel.h>
00028 #include <qlayout.h>
00029 #include <qradiobutton.h>
00030 
00031 #include <klocale.h>
00032 #include <KoUnitWidgets.h>
00033 
00034 
00035 KoGuideLineDia::KoGuideLineDia( QWidget *parent, double pos, double minPos, double maxPos,
00036                                 KoUnit::Unit unit, const char *name )
00037 : KDialogBase( parent, name , true, "", Ok | Cancel, Ok, true )
00038 , m_hButton( 0 )
00039 , m_vButton( 0 )
00040 {
00041     setCaption( i18n("Set Guide Line Position") );
00042     QHBox *page = makeHBoxMainWidget();
00043     new QLabel( i18n( "Position:" ), page );
00044     m_position= new KoUnitDoubleSpinBox( page, QMAX( 0.00, minPos ), QMAX( 0.00, maxPos ), 1, QMAX( 0.00, pos ), unit );
00045     m_position->setFocus();
00046 }
00047 
00048 
00049 KoGuideLineDia::KoGuideLineDia( QWidget *parent, KoPoint &pos, KoRect &rect,
00050                                 KoUnit::Unit unit, const char *name )
00051 : KDialogBase( parent, name , true, "", Ok | Cancel, Ok, true )
00052 , m_rect( rect )
00053 , m_pos( pos )
00054 , m_positionChanged( false )
00055 , m_hButton( 0 )
00056 , m_vButton( 0 )
00057 {
00058     setCaption( i18n("Add Guide Line") );
00059     QVBox * vbox = makeVBoxMainWidget();
00060 
00061     QButtonGroup *group = new QButtonGroup( 1, QGroupBox::Horizontal, i18n( "Orientation" ), vbox );
00062     group->setRadioButtonExclusive( true );
00063     //group->layout();
00064     m_hButton = new QRadioButton( i18n( "Horizontal" ), group );
00065     m_vButton = new QRadioButton( i18n( "Vertical" ), group );
00066 
00067     connect( group, SIGNAL( clicked( int ) ), this, SLOT( slotOrientationChanged() ) );
00068 
00069     m_vButton->setChecked( true );;
00070 
00071     QHBox *hbox = new QHBox( vbox );
00072     QLabel *label = new QLabel( i18n( "&Position:" ), hbox );
00073     m_position= new KoUnitDoubleSpinBox( hbox, QMAX( 0.0, m_rect.left() ), QMAX( 0.0, m_rect.right() ), 1, QMAX( 0.0, pos.x() ), unit );
00074     m_position->setFocus();
00075     label->setBuddy( m_position );
00076 
00077     connect( m_position, SIGNAL( valueChanged( double ) ), this, SLOT( slotPositionChanged() ) );
00078 }
00079 
00080 
00081 double KoGuideLineDia::pos() const
00082 {
00083     return m_position->value();
00084 }
00085 
00086 
00087 Qt::Orientation KoGuideLineDia::orientation() const
00088 {
00089     Qt::Orientation o = Qt::Horizontal;
00090     if ( m_vButton && m_vButton->isChecked() )
00091     {
00092         o = Qt::Vertical;
00093     }
00094     return o;
00095 }
00096 
00097 
00098 void KoGuideLineDia::slotOrientationChanged()
00099 {
00100     if ( m_hButton && m_vButton )
00101     {
00102         if ( m_hButton->isChecked() )
00103         {
00104             m_position->setMinValue( QMAX( 0.0, m_rect.top() ) );
00105             m_position->setMaxValue( QMAX( 0.0, m_rect.bottom() ) );
00106             if ( ! m_positionChanged )
00107             {
00108                 disconnect( m_position, SIGNAL( valueChanged( double ) ), this, SLOT( slotPositionChanged() ) );
00109                 m_position->changeValue( m_pos.y() );
00110                 connect( m_position, SIGNAL( valueChanged( double ) ), this, SLOT( slotPositionChanged() ) );
00111             }
00112         }
00113         else if ( m_vButton->isChecked() )
00114         {
00115             m_position->setMinValue( QMAX( 0.0, m_rect.left() ) );
00116             m_position->setMaxValue( QMAX( 0.0, m_rect.right() ) );
00117             if ( ! m_positionChanged )
00118             {
00119                 disconnect( m_position, SIGNAL( valueChanged( double ) ), this, SLOT( slotPositionChanged() ) );
00120                 m_position->changeValue( m_pos.x() );
00121                 connect( m_position, SIGNAL( valueChanged( double ) ), this, SLOT( slotPositionChanged() ) );
00122             }
00123         }
00124     }
00125 }
00126 
00127 void KoGuideLineDia::slotPositionChanged()
00128 {
00129     m_positionChanged = true;
00130 }
00131 #include "KoGuideLineDia.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys