F:/KPlato/koffice/libs/kofficeui/KoGuideLineDia.cpp

Aller à la documentation de ce fichier.
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 <q3buttongroup.h>
00025 
00026 
00027 #include <QLabel>
00028 #include <QLayout>
00029 #include <QRadioButton>
00030 
00031 #include <klocale.h>
00032 #include <KoUnitWidgets.h>
00033 #include <kvbox.h>
00034 
00035 
00036 KoGuideLineDia::KoGuideLineDia( QWidget *parent, double pos, double minPos, double maxPos,
00037                                 KoUnit::Unit unit, const char *name )
00038 : KDialog( parent )
00039 , m_hButton( 0 )
00040 , m_vButton( 0 )
00041 {
00042     setObjectName( name );
00043     setButtons( KDialog::Ok|KDialog::Cancel );
00044     setDefaultButton( KDialog::Ok );
00045     setModal( true );
00046     setCaption( i18n("Set Guide Line Position") );
00047     KHBox *page = new KHBox();
00048     setMainWidget(page);
00049     new QLabel( i18n( "Position:" ), page );
00050     m_position= new KoUnitDoubleSpinBox( page, qMax( 0.00, minPos ), qMax( 0.00, maxPos ), 1, qMax( 0.00, pos ), unit );
00051     m_position->setFocus();
00052 }
00053 
00054 
00055 KoGuideLineDia::KoGuideLineDia( QWidget *parent, KoPoint &pos, KoRect &rect,
00056                                 KoUnit::Unit unit, const char *name )
00057 : KDialog( parent )
00058 , m_rect( rect )
00059 , m_pos( pos )
00060 , m_positionChanged( false )
00061 , m_hButton( 0 )
00062 , m_vButton( 0 )
00063 {
00064     setObjectName( name );
00065     setButtons( KDialog::Ok|KDialog::Cancel );
00066     setDefaultButton( KDialog::Ok );
00067     setModal( true );
00068 
00069     setCaption( i18n("Add Guide Line") );
00070     KVBox *vbox = new KVBox();
00071     setMainWidget(vbox);
00072 
00073     Q3ButtonGroup *group = new Q3ButtonGroup( 1, Qt::Horizontal, i18n( "Orientation" ), vbox );
00074     group->setRadioButtonExclusive( true );
00075     //group->layout();
00076     m_hButton = new QRadioButton( i18n( "Horizontal" ), group );
00077     m_vButton = new QRadioButton( i18n( "Vertical" ), group );
00078 
00079     connect( group, SIGNAL( clicked( int ) ), this, SLOT( slotOrientationChanged() ) );
00080 
00081     m_vButton->setChecked( true );;
00082 
00083     KHBox *hbox = new KHBox( vbox );
00084     QLabel *label = new QLabel( i18n( "&Position:" ), hbox );
00085     m_position= new KoUnitDoubleSpinBox( hbox, qMax( 0.0, m_rect.left() ), qMax( 0.0, m_rect.right() ), 1, qMax( 0.0, pos.x() ), unit );
00086     m_position->setFocus();
00087     label->setBuddy( m_position );
00088 
00089     connect( m_position, SIGNAL( valueChanged( double ) ), this, SLOT( slotPositionChanged() ) );
00090 }
00091 
00092 
00093 double KoGuideLineDia::pos() const
00094 {
00095     return m_position->value();
00096 }
00097 
00098 
00099 Qt::Orientation KoGuideLineDia::orientation() const
00100 {
00101     Qt::Orientation o = Qt::Horizontal;
00102     if ( m_vButton && m_vButton->isChecked() )
00103     {
00104         o = Qt::Vertical;
00105     }
00106     return o;
00107 }
00108 
00109 
00110 void KoGuideLineDia::slotOrientationChanged()
00111 {
00112     if ( m_hButton && m_vButton )
00113     {
00114         if ( m_hButton->isChecked() )
00115         {
00116             m_position->setMinimum( qMax( 0.0, m_rect.top() ) );
00117             m_position->setMaximum( qMax( 0.0, m_rect.bottom() ) );
00118             if ( ! m_positionChanged )
00119             {
00120                 disconnect( m_position, SIGNAL( valueChanged( double ) ), this, SLOT( slotPositionChanged() ) );
00121                 m_position->changeValue( m_pos.y() );
00122                 connect( m_position, SIGNAL( valueChanged( double ) ), this, SLOT( slotPositionChanged() ) );
00123             }
00124         }
00125         else if ( m_vButton->isChecked() )
00126         {
00127             m_position->setMinimum( qMax( 0.0, m_rect.left() ) );
00128             m_position->setMaximum( qMax( 0.0, m_rect.right() ) );
00129             if ( ! m_positionChanged )
00130             {
00131                 disconnect( m_position, SIGNAL( valueChanged( double ) ), this, SLOT( slotPositionChanged() ) );
00132                 m_position->changeValue( m_pos.x() );
00133                 connect( m_position, SIGNAL( valueChanged( double ) ), this, SLOT( slotPositionChanged() ) );
00134             }
00135         }
00136     }
00137 }
00138 
00139 void KoGuideLineDia::slotPositionChanged()
00140 {
00141     m_positionChanged = true;
00142 }
00143 #include "KoGuideLineDia.moc"

Généré le Wed Nov 22 23:41:04 2006 pour KPlato par  doxygen 1.5.1-p1