Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ocompletion.h

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Originally part of the KDE Project
00004                              Copyright (C) 1999,2000 Carsten Pfeiffer <pfeiffer@kde.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022  :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #ifndef OCOMPLETION_H
00032 #define OCOMPLETION_H
00033 
00034 /* QT */
00035 
00036 #include <qmap.h>
00037 #include <qlist.h>
00038 #include <qobject.h>
00039 #include <qstring.h>
00040 #include <qstringlist.h>
00041 #include <qguardedptr.h>
00042 
00043 /* OPIE */
00044 
00045 #include <opie2/oglobalsettings.h>
00046 #include <opie2/osortablevaluelist.h>
00047 
00048 /* FORWARDS */
00049 
00050 class OCompTreeNode;
00051 class OCompletionPrivate;
00052 class OCompletionBasePrivate;
00053 class OCompletionMatchesWrapper;
00054 class OCompletionMatches;
00055 class QPopupMenu;
00056 
00057 // FIXME: Do we need special ShortCut handling in Opie? If so, revise this.
00058 class OShortcut
00059 {
00060 public:
00061   bool isNull() const { return true; };
00062   bool operator == ( const OShortcut& bla ) const { return false; };
00063 };
00064 
00065 
00155 class OCompletion : public QObject
00156 {
00157     Q_ENUMS( CompOrder )
00158     Q_PROPERTY( CompOrder order READ order WRITE setOrder )
00159     Q_PROPERTY( bool ignoreCase READ ignoreCase WRITE setIgnoreCase )
00160     Q_PROPERTY( QStringList items READ items WRITE setItems )
00161     Q_OBJECT
00162 
00163   public:
00168     enum CompOrder { Sorted, Insertion, Weighted };
00169 
00173     OCompletion();
00174 
00175     // FIXME: copy constructor, assignment constructor...
00176 
00180     virtual ~OCompletion();
00181 
00203     virtual QString makeCompletion( const QString& string );
00204 
00211     QStringList substringCompletion( const QString& string ) const;
00212 
00221     QString previousMatch();
00222 
00231     QString nextMatch();
00232 
00238     virtual const QString& lastMatch() const { return myLastMatch; }
00239 
00258     QStringList items() const;
00259 
00268     virtual void setCompletionMode( OGlobalSettings::Completion mode );
00269 
00276     OGlobalSettings::Completion completionMode() const { return myCompletionMode; };
00277 
00297     virtual void setOrder( CompOrder order );
00298 
00303     CompOrder order() const { return myOrder; }
00304 
00311     virtual void setIgnoreCase( bool ignoreCase );
00312 
00318     bool ignoreCase() const { return myIgnoreCase; };
00319 
00326     QStringList allMatches();
00327 
00331     QStringList allMatches( const QString& string );
00332 
00344     OCompletionMatches allWeightedMatches();
00345 
00349     OCompletionMatches allWeightedMatches( const QString& string );
00350 
00363     virtual void setEnableSounds( bool enable ) { myBeep = enable; }
00364 
00371     bool isSoundsEnabled() const { return myBeep; };
00372 
00377     bool hasMultipleMatches() const { return myHasMultipleMatches; };
00378 
00379   public slots:
00385     void slotMakeCompletion( const QString& string ) { (void) makeCompletion( string ); };
00386 
00392     void slotPreviousMatch() { (void) previousMatch(); };
00393 
00399     void slotNextMatch() { (void) nextMatch(); };
00400 
00405     void insertItems( const QStringList& items );
00406 
00421     virtual void setItems( const QStringList& );
00422 
00428     void addItem( const QString& );
00429 
00439     void addItem( const QString&, uint weight );
00440 
00446     void removeItem( const QString& );
00447 
00451     virtual void clear();
00452 
00453   signals:
00459     void match( const QString& );
00460 
00466     void matches( const QStringList& );
00467 
00473     void multipleMatches();
00474 
00475   protected:
00488     virtual void postProcessMatch( QString * /*match*/ ) const {}
00489 
00499     virtual void postProcessMatches( QStringList * /*matches*/ ) const {}
00500 
00510     virtual void postProcessMatches( OCompletionMatches * /*matches*/ ) const {}
00511 
00512 private:
00513     void addWeightedItem( const QString& );
00514     QString findCompletion( const QString& string );
00515     void findAllCompletions( const QString&, OCompletionMatchesWrapper *matches, bool& hasMultipleMatches ) const;
00516 
00517     void extractStringsFromNode( const OCompTreeNode *,
00518                                  const QString& beginning,
00519                                  OCompletionMatchesWrapper *matches,
00520                                  bool addWeight = false ) const;
00521     void extractStringsFromNodeCI( const OCompTreeNode *,
00522                                    const QString& beginning,
00523                                    const QString& restString,
00524                                    OCompletionMatchesWrapper *matches) const;
00525 
00526     enum BeepMode { NoMatch, PartialMatch, Rotation };
00527     void doBeep( BeepMode ) const;
00528 
00529     OGlobalSettings::Completion myCompletionMode;
00530 
00531     CompOrder myOrder;
00532     QString myLastString;
00533     QString myLastMatch;
00534     QString myCurrentMatch;
00535     OCompTreeNode * myTreeRoot;
00536     QStringList myRotations;
00537     bool myBeep;
00538     bool myIgnoreCase;
00539     bool myHasMultipleMatches;
00540     uint myRotationIndex;
00541 
00542   private:
00543     OCompletionPrivate *d;
00544 };
00545 
00546 // some more helper stuff
00547 typedef OSortableValueList<QString> OCompletionMatchesList;
00548 class OCompletionMatchesPrivate;
00549 
00569 class OCompletionMatches
00570     : public OCompletionMatchesList
00571 {
00572   public:
00573     OCompletionMatches( bool sort );
00577     OCompletionMatches( const OCompletionMatchesWrapper& matches );
00578     ~OCompletionMatches();
00583     void removeDuplicates();
00589     QStringList list( bool sort = true ) const;
00594     bool sorting() const {
00595         return _sorting;
00596     }
00597 private:
00598     bool _sorting;
00599     OCompletionMatchesPrivate* d;
00600 };
00601 
00602 #endif // OCOMPLETION_H

Generated on Sat Nov 5 16:16:28 2005 for OPIE by  doxygen 1.4.2