00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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"