kword

KWFootNoteDia.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "KWFootNoteDia.h"
00021 #include "KWFootNoteDia.moc"
00022 
00023 #include <qbuttongroup.h>
00024 #include <qvbox.h>
00025 #include <qradiobutton.h>
00026 
00027 #include <klocale.h>
00028 #include <qlayout.h>
00029 #include <qlineedit.h>
00030 #include "KWConfigFootNoteDia.h"
00031 
00032 
00033 /******************************************************************/
00034 /* Class: KWFootNoteDia                                           */
00035 /******************************************************************/
00036 
00037 KWFootNoteDia::KWFootNoteDia( NoteType _noteType, KWFootNoteVariable::Numbering _numberingType, const QString & _manualString, QWidget *parent, KWDocument *_doc, const char *name )
00038     : KDialogBase( parent, name, true, QString::null, Ok|Cancel|User1, Ok, true )
00039 {
00040     m_doc =_doc;
00041     //setButtonOKText(i18n("&Insert"));
00042 
00043     setCaption( i18n("Insert Footnote/Endnote") );
00044 
00045     QVBox *page = makeVBoxMainWidget();
00046 
00047     QButtonGroup *grp = new QButtonGroup( i18n("Numbering"), page );
00048     QGridLayout *grid = new QGridLayout( grp, 9, 4, KDialog::marginHint(), KDialog::spacingHint());
00049     m_rbAuto = new QRadioButton( i18n("&Automatic"), grp );
00050     m_rbManual= new QRadioButton( i18n("&Manual"), grp );
00051 
00052     grp->setExclusive( true );
00053     int fHeight = grp->fontMetrics().height();
00054     grid->addRowSpacing( 0, fHeight/2 ); // groupbox title
00055     grid->addWidget( m_rbAuto, 1, 0);
00056     grid->addWidget( m_rbManual, 2, 0);
00057     if ( _numberingType == KWFootNoteVariable::Auto )
00058         m_rbAuto->setChecked( true );
00059     else
00060         m_rbManual->setChecked( true );
00061     m_footLine = new QLineEdit( grp);
00062     m_footLine->setText( _manualString );
00063     connect( m_footLine, SIGNAL( textChanged ( const QString & )), this, SLOT(footLineChanged( const QString & )));
00064     connect( grp, SIGNAL( clicked ( int ) ), this, SLOT(footNoteTypeChanged()));
00065     grid->addWidget( m_footLine, 2, 1);
00066 
00067 
00068     grp = new QButtonGroup( 4, Qt::Vertical, page );
00069     m_rbFootNote = new QRadioButton( i18n("&Footnote"), grp );
00070     m_rbEndNote = new QRadioButton( i18n("&Endnote"), grp );
00071 
00072     grp->setExclusive( true );
00073     grp->insert( m_rbFootNote );
00074     grp->insert( m_rbEndNote );
00075     if (_noteType == FootNote )
00076         m_rbFootNote->setChecked( true );
00077     else
00078         m_rbEndNote->setChecked( true );
00079 
00080     footNoteTypeChanged();
00081     setButtonText( KDialogBase::User1, i18n("C&onfigure...") );
00082     connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotConfigurate()));
00083 }
00084 
00085 void KWFootNoteDia::footNoteTypeChanged()
00086 {
00087     if ( m_rbManual->isChecked())
00088     {
00089         enableButtonOK( !m_footLine->text().isEmpty() );
00090         m_footLine->setFocus();
00091     }
00092     else
00093     {
00094         enableButtonOK(true);
00095         setFocus();
00096     }
00097 }
00098 
00099 void KWFootNoteDia::footLineChanged( const QString &text )
00100 {
00101     m_rbManual->setChecked( true );
00102     if ( text.isEmpty() || footNoteAlreadyExists(text) )
00103         enableButtonOK( false );
00104     else
00105         enableButtonOK( true );
00106 }
00107 
00108 NoteType KWFootNoteDia::noteType() const
00109 {
00110     return m_rbFootNote->isChecked() ? FootNote : EndNote;
00111 }
00112 
00113 KWFootNoteVariable::Numbering KWFootNoteDia::numberingType()const
00114 {
00115     return m_rbAuto->isChecked() ? KWFootNoteVariable::Auto : KWFootNoteVariable::Manual;
00116 }
00117 
00118 QString KWFootNoteDia::manualString()const
00119 {
00120     return  m_rbAuto->isChecked() ? QString::null : m_footLine->text();
00121 }
00122 
00123 void KWFootNoteDia::slotConfigurate()
00124 {
00125     KWConfigFootNoteDia *dia = new KWConfigFootNoteDia( this, "configfootnote", m_doc );
00126     dia->exec();
00127     delete dia;
00128 }
00129 
00130 bool KWFootNoteDia::footNoteAlreadyExists( const QString & text )
00131 {
00132     return manualFootNotes.contains( text );
00133 }
00134 
00135 void KWFootNoteDia::appendManualFootNote( const QString & text )
00136 {
00137     manualFootNotes.append( text );
00138 }
KDE Home | KDE Accessibility Home | Description of Access Keys