F:/KPlato/koffice/libs/kotext/KoTextBookmark.h

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2002-2003 Laurent Montel <montel@kde.org>
00003    Copyright (C) 2006      David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
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., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef KOTEXTBOOKMARK_H
00022 #define KOTEXTBOOKMARK_H
00023 
00024 #include <koffice_export.h>
00025 #include <QString>
00026 #include <q3valuelist.h>
00027 #include <QMap>
00028 class KoTextParag;
00029 class KoTextDocument;
00030 
00031 /*
00032  * A bookmark is a name associated with a single position or a run of text (start and end) in a text document.
00033  */
00034 class KOTEXT_EXPORT KoTextBookmark {
00035 public:
00036     KoTextBookmark( const QString& name = QString::null /*for QValueList; remove default value when going Qt4*/ );
00037     KoTextBookmark( const QString& name,
00038                     KoTextParag* startParag, KoTextParag* endParag,
00039                     int start, int end );
00040 
00041     QString bookmarkName() const { return m_name; }
00042     void setBookmarkName( const QString &name ) { m_name = name; }
00043 
00044     // Note: the text document always m_startParag->document(), which is also m_endParag->document().
00045     KoTextDocument* textDocument() const;
00046 
00047     KoTextParag* startParag() const { return m_startParag; }
00048     void setStartParag( KoTextParag* parag ) { m_startParag = parag; }
00049 
00050     KoTextParag* endParag() const { return m_endParag; }
00051     void setEndParag( KoTextParag* parag ) { m_endParag = parag; }
00052 
00053     void setBookmarkStartIndex( int pos ) { m_startIndex = pos; }
00054     int bookmarkStartIndex() const { return m_startIndex; }
00055 
00056     void setBookmarkEndIndex( int end ) { m_endIndex = end; }
00057     int bookmarkEndIndex() const { return m_endIndex; }
00058 
00059     bool isSimple() const { return m_startParag == m_endParag && m_startIndex == m_endIndex; }
00060 
00061 private:
00062     QString m_name;
00063     KoTextParag* m_startParag;
00064     KoTextParag* m_endParag;
00065     int m_startIndex;
00066     int m_endIndex;
00067 };
00068 
00069 class KOTEXT_EXPORT KoTextBookmarkList : public Q3ValueList<KoTextBookmark>
00070 {
00071 public:
00072     const_iterator findByName( const QString& name ) const {
00073         for ( const_iterator it = begin(), itend = end(); it != itend; ++it )
00074             if ( (*it).bookmarkName() == name )
00075                 return it;
00076         return end();
00077     }
00078     iterator findByName( const QString& name ) {
00079         for ( iterator it = begin(), itend = end(); it != itend; ++it )
00080             if ( (*it).bookmarkName() == name )
00081                 return it;
00082         return end();
00083     }
00084     bool removeByName( const QString& name ) {
00085         for ( iterator it = begin(), itend = end(); it != itend; ++it )
00086             if ( (*it).bookmarkName() == name ) {
00087                 remove( it );
00088                 return true;
00089             }
00090         return false;
00091     }
00094     QMap<const KoTextParag*, KoTextBookmarkList> bookmarksPerParagraph() const {
00095         QMap<const KoTextParag*, KoTextBookmarkList> ret;
00096         for ( const_iterator it = begin(), itend = end(); it != itend; ++it ) {
00097             ret[ (*it).startParag() ].append( *it );
00098             if ( (*it).startParag() != (*it).endParag() )
00099                 ret[ (*it).endParag() ].append( *it );
00100         }
00101         return ret;
00102     }
00103 };
00104 
00105 #endif /* KOTEXTBOOKMARK_H */
00106 

Généré le Wed Nov 22 23:41:09 2006 pour KPlato par  doxygen 1.5.1-p1