kword

KWFootNoteDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KWFootNoteDia.h"
21#include "KWFootNoteDia.moc"
22
23#include <tqbuttongroup.h>
24#include <tqvbox.h>
25#include <tqradiobutton.h>
26
27#include <tdelocale.h>
28#include <tqlayout.h>
29#include <tqlineedit.h>
30#include "KWConfigFootNoteDia.h"
31
32
33/******************************************************************/
34/* Class: KWFootNoteDia */
35/******************************************************************/
36
37KWFootNoteDia::KWFootNoteDia( NoteType _noteType, KWFootNoteVariable::Numbering _numberingType, const TQString & _manualString, TQWidget *parent, KWDocument *_doc, const char *name )
38 : KDialogBase( parent, name, true, TQString(), Ok|Cancel|User1, Ok, true )
39{
40 m_doc =_doc;
41 //setButtonOKText(i18n("&Insert"));
42
43 setCaption( i18n("Insert Footnote/Endnote") );
44
45 TQVBox *page = makeVBoxMainWidget();
46
47 TQButtonGroup *grp = new TQButtonGroup( i18n("Numbering"), page );
48 TQGridLayout *grid = new TQGridLayout( grp, 9, 4, KDialog::marginHint(), KDialog::spacingHint());
49 m_rbAuto = new TQRadioButton( i18n("&Automatic"), grp );
50 m_rbManual= new TQRadioButton( i18n("&Manual"), grp );
51
52 grp->setExclusive( true );
53 int fHeight = grp->fontMetrics().height();
54 grid->addRowSpacing( 0, fHeight/2 ); // groupbox title
55 grid->addWidget( m_rbAuto, 1, 0);
56 grid->addWidget( m_rbManual, 2, 0);
57 if ( _numberingType == KWFootNoteVariable::Auto )
58 m_rbAuto->setChecked( true );
59 else
60 m_rbManual->setChecked( true );
61 m_footLine = new TQLineEdit( grp);
62 m_footLine->setText( _manualString );
63 connect( m_footLine, TQ_SIGNAL( textChanged ( const TQString & )), this, TQ_SLOT(footLineChanged( const TQString & )));
64 connect( grp, TQ_SIGNAL( clicked ( int ) ), this, TQ_SLOT(footNoteTypeChanged()));
65 grid->addWidget( m_footLine, 2, 1);
66
67
68 grp = new TQButtonGroup( 4, TQt::Vertical, page );
69 m_rbFootNote = new TQRadioButton( i18n("&Footnote"), grp );
70 m_rbEndNote = new TQRadioButton( i18n("&Endnote"), grp );
71
72 grp->setExclusive( true );
73 grp->insert( m_rbFootNote );
74 grp->insert( m_rbEndNote );
75 if (_noteType == FootNote )
76 m_rbFootNote->setChecked( true );
77 else
78 m_rbEndNote->setChecked( true );
79
80 footNoteTypeChanged();
81 setButtonText( KDialogBase::User1, i18n("C&onfigure...") );
82 connect( this, TQ_SIGNAL( user1Clicked() ), this, TQ_SLOT(slotConfigurate()));
83}
84
85void KWFootNoteDia::footNoteTypeChanged()
86{
87 if ( m_rbManual->isChecked())
88 {
89 enableButtonOK( !m_footLine->text().isEmpty() );
90 m_footLine->setFocus();
91 }
92 else
93 {
94 enableButtonOK(true);
95 setFocus();
96 }
97}
98
99void KWFootNoteDia::footLineChanged( const TQString &text )
100{
101 m_rbManual->setChecked( true );
102 if ( text.isEmpty() || footNoteAlreadyExists(text) )
103 enableButtonOK( false );
104 else
105 enableButtonOK( true );
106}
107
108NoteType KWFootNoteDia::noteType() const
109{
110 return m_rbFootNote->isChecked() ? FootNote : EndNote;
111}
112
113KWFootNoteVariable::Numbering KWFootNoteDia::numberingType()const
114{
115 return m_rbAuto->isChecked() ? KWFootNoteVariable::Auto : KWFootNoteVariable::Manual;
116}
117
118TQString KWFootNoteDia::manualString()const
119{
120 return m_rbAuto->isChecked() ? TQString() : m_footLine->text();
121}
122
123void KWFootNoteDia::slotConfigurate()
124{
125 KWConfigFootNoteDia *dia = new KWConfigFootNoteDia( this, "configfootnote", m_doc );
126 dia->exec();
127 delete dia;
128}
129
130bool KWFootNoteDia::footNoteAlreadyExists( const TQString & text )
131{
132 return manualFootNotes.contains( text );
133}
134
135void KWFootNoteDia::appendManualFootNote( const TQString & text )
136{
137 manualFootNotes.append( text );
138}