lib

KoGuideLineDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Montel Laurent <lmontel@mandrakesoft.com>
3 Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KoGuideLineDia.h"
22
23#include <tqbuttongroup.h>
24#include <tqhbox.h>
25#include <tqvbox.h>
26#include <tqlabel.h>
27#include <tqlayout.h>
28#include <tqradiobutton.h>
29
30#include <tdelocale.h>
31#include <KoUnitWidgets.h>
32
33
34KoGuideLineDia::KoGuideLineDia( TQWidget *parent, double pos, double minPos, double maxPos,
35 KoUnit::Unit unit, const char *name )
36: KDialogBase( parent, name , true, "", Ok | Cancel, Ok, true )
37, m_hButton( 0 )
38, m_vButton( 0 )
39{
40 setCaption( i18n("Set Guide Line Position") );
41 TQHBox *page = makeHBoxMainWidget();
42 new TQLabel( i18n( "Position:" ), page );
43 m_position= new KoUnitDoubleSpinBox( page, TQMAX( 0.00, minPos ), TQMAX( 0.00, maxPos ), 1, TQMAX( 0.00, pos ), unit );
44 m_position->setFocus();
45}
46
47
49 KoUnit::Unit unit, const char *name )
50: KDialogBase( parent, name , true, "", Ok | Cancel, Ok, true )
51, m_rect( rect )
52, m_pos( pos )
53, m_positionChanged( false )
54, m_hButton( 0 )
55, m_vButton( 0 )
56{
57 setCaption( i18n("Add Guide Line") );
58 TQVBox * vbox = makeVBoxMainWidget();
59
60 TQButtonGroup *group = new TQButtonGroup( 1, TQt::Horizontal, i18n( "Orientation" ), vbox );
61 group->setRadioButtonExclusive( true );
62 //group->layout();
63 m_hButton = new TQRadioButton( i18n( "Horizontal" ), group );
64 m_vButton = new TQRadioButton( i18n( "Vertical" ), group );
65
66 connect( group, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotOrientationChanged() ) );
67
68 m_vButton->setChecked( true );;
69
70 TQHBox *hbox = new TQHBox( vbox );
71 TQLabel *label = new TQLabel( i18n( "&Position:" ), hbox );
72 m_position= new KoUnitDoubleSpinBox( hbox, TQMAX( 0.0, m_rect.left() ), TQMAX( 0.0, m_rect.right() ), 1, TQMAX( 0.0, pos.x() ), unit );
73 m_position->setFocus();
74 label->setBuddy( m_position );
75
76 connect( m_position, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( slotPositionChanged() ) );
77}
78
79
80double KoGuideLineDia::pos() const
81{
82 return m_position->value();
83}
84
85
86TQt::Orientation KoGuideLineDia::orientation() const
87{
88 TQt::Orientation o = TQt::Horizontal;
89 if ( m_vButton && m_vButton->isChecked() )
90 {
91 o = TQt::Vertical;
92 }
93 return o;
94}
95
96
97void KoGuideLineDia::slotOrientationChanged()
98{
99 if ( m_hButton && m_vButton )
100 {
101 if ( m_hButton->isChecked() )
102 {
103 m_position->setMinValue( TQMAX( 0.0, m_rect.top() ) );
104 m_position->setMaxValue( TQMAX( 0.0, m_rect.bottom() ) );
105 if ( ! m_positionChanged )
106 {
107 disconnect( m_position, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( slotPositionChanged() ) );
108 m_position->changeValue( m_pos.y() );
109 connect( m_position, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( slotPositionChanged() ) );
110 }
111 }
112 else if ( m_vButton->isChecked() )
113 {
114 m_position->setMinValue( TQMAX( 0.0, m_rect.left() ) );
115 m_position->setMaxValue( TQMAX( 0.0, m_rect.right() ) );
116 if ( ! m_positionChanged )
117 {
118 disconnect( m_position, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( slotPositionChanged() ) );
119 m_position->changeValue( m_pos.x() );
120 connect( m_position, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( slotPositionChanged() ) );
121 }
122 }
123 }
124}
125
126void KoGuideLineDia::slotPositionChanged()
127{
128 m_positionChanged = true;
129}
130#include "KoGuideLineDia.moc"
KDialogBase(TQWidget *parent=0, const char *name=0, bool modal=true, const TQString &caption=TQString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem())
TQVBox * makeVBoxMainWidget()
TQHBox * makeHBoxMainWidget()
virtual void setCaption(const TQString &caption)
KoGuideLineDia(TQWidget *parent, double pos, double minPos, double maxPos, KoUnit::Unit unit, const char *name=0L)
Constructor.
double pos() const
the position
TQt::Orientation orientation() const
the orientation
A point whose coordinates are floating-point values ( "double"s ).
Definition KoPoint.h:30
A rect whose coordinates are floating-point values ( "double"s ).
Definition KoRect.h:31
Spin box for double precision numbers with unit display.
void setMinValue(double min)
Set minimum value in points.
void setMaxValue(double max)
Set maximum value in points.
Unit
Length units supported by KOffice.
Definition KoUnit.h:63