kutils Library API Documentation

kreplacedialog.cpp

00001 /*
00002     Copyright (C) 2001, S.R.Haque <srhaque@iee.org>.
00003     Copyright (C) 2002, David Faure <david@mandrakesoft.com>
00004     This file is part of the KDE project
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License version 2, as published by the Free Software Foundation.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include "kreplacedialog.h"
00022 
00023 #include <qcheckbox.h>
00024 #include <qgroupbox.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <kcombobox.h>
00028 
00034 class KReplaceDialog::KReplaceDialogPrivate {
00035   public:
00036     KReplaceDialogPrivate() : m_initialShowDone(false) {}
00037     QStringList replaceStrings;
00038     bool m_initialShowDone;
00039 };
00040 
00041 KReplaceDialog::KReplaceDialog(QWidget *parent, const char *name, long options, const QStringList &findStrings, const QStringList &replaceStrings, bool hasSelection) :
00042     KFindDialog(parent, name, true)
00043 {
00044     d = new KReplaceDialogPrivate;
00045     d->replaceStrings = replaceStrings;
00046     init(true, findStrings, hasSelection);
00047     setOptions(options);
00048 }
00049 
00050 KReplaceDialog::~KReplaceDialog()
00051 {
00052     delete d;
00053 }
00054 
00055 void KReplaceDialog::showEvent( QShowEvent *e )
00056 {
00057     if ( !d->m_initialShowDone )
00058     {
00059         d->m_initialShowDone = true; // only once
00060 
00061         if (!d->replaceStrings.isEmpty())
00062         {
00063           setReplacementHistory(d->replaceStrings);
00064           m_replace->lineEdit()->setText( d->replaceStrings[0] );
00065         }
00066     }
00067 
00068     KFindDialog::showEvent(e);
00069 }
00070 
00071 long KReplaceDialog::options() const
00072 {
00073     long options = 0;
00074 
00075     options = KFindDialog::options();
00076     if (m_promptOnReplace->isChecked())
00077         options |= PromptOnReplace;
00078     if (m_backRef->isChecked())
00079         options |= BackReference;
00080     return options;
00081 }
00082 
00083 QWidget *KReplaceDialog::replaceExtension()
00084 {
00085     if (!m_replaceExtension)
00086     {
00087       m_replaceExtension = new QWidget(m_replaceGrp);
00088       m_replaceLayout->addMultiCellWidget(m_replaceExtension, 3, 3, 0, 1);
00089     }
00090 
00091     return m_replaceExtension;
00092 }
00093 
00094 QString KReplaceDialog::replacement() const
00095 {
00096     return m_replace->currentText();
00097 }
00098 
00099 QStringList KReplaceDialog::replacementHistory() const
00100 {
00101     return m_replace->historyItems();
00102 }
00103 
00104 void KReplaceDialog::setOptions(long options)
00105 {
00106     KFindDialog::setOptions(options);
00107     m_promptOnReplace->setChecked(options & PromptOnReplace);
00108     m_backRef->setChecked(options & BackReference);
00109 }
00110 
00111 void KReplaceDialog::setReplacementHistory(const QStringList &strings)
00112 {
00113     if (strings.count() > 0)
00114         m_replace->setHistoryItems(strings, true);
00115     else
00116         m_replace->clearHistory();
00117 }
00118 
00119 void KReplaceDialog::slotOk()
00120 {
00121     KFindDialog::slotOk();
00122     m_replace->addToHistory(replacement());
00123 }
00124 
00125 #include "kreplacedialog.moc"
KDE Logo
This file is part of the documentation for kutils Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun May 16 22:04:34 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003