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 <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
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"