Kate
docwordcompletion.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 #ifndef _DocWordCompletionPlugin_h_
00030 #define _DocWordCompletionPlugin_h_
00031 
00032 #include <ktexteditor/plugin.h>
00033 #include <ktexteditor/view.h>
00034 #include <ktexteditor/codecompletioninterface.h>
00035 #include <ktexteditor/configinterfaceextension.h>
00036 #include <kxmlguiclient.h>
00037 
00038 #include <qevent.h>
00039 #include <qobject.h>
00040 #include <qvaluelist.h>
00041 
00042 class DocWordCompletionPlugin
00043   : public KTextEditor::Plugin
00044   , public KTextEditor::PluginViewInterface
00045   , public KTextEditor::ConfigInterfaceExtension
00046 {
00047   Q_OBJECT
00048 
00049   public:
00050     DocWordCompletionPlugin( QObject *parent = 0,
00051                             const char* name = 0,
00052                             const QStringList &args = QStringList() );
00053     virtual ~DocWordCompletionPlugin() {};
00054 
00055     void addView (KTextEditor::View *view);
00056     void removeView (KTextEditor::View *view);
00057 
00058     void readConfig();
00059     void writeConfig();
00060 
00061     
00062     uint configPages() const { return 1; };
00063     KTextEditor::ConfigPage * configPage( uint number, QWidget *parent, const char *name );
00064     QString configPageName( uint ) const;
00065     QString configPageFullName( uint ) const;
00066     QPixmap configPagePixmap( uint, int ) const;
00067 
00068     uint treshold() const { return m_treshold; };
00069     void setTreshold( uint t ) { m_treshold = t; };
00070     bool autoPopupEnabled() const { return m_autopopup; };
00071     void setAutoPopupEnabled( bool enable ) { m_autopopup = enable; };
00072 
00073 
00074   private:
00075     QPtrList<class DocWordCompletionPluginView> m_views;
00076     uint m_treshold;
00077     bool m_autopopup;
00078 
00079 };
00080 
00081 class DocWordCompletionPluginView
00082    : public QObject, public KXMLGUIClient
00083 {
00084   Q_OBJECT
00085 
00086   public:
00087     DocWordCompletionPluginView( uint treshold=3, bool autopopup=true, KTextEditor::View *view=0,
00088                                const char *name=0 );
00089     ~DocWordCompletionPluginView() {};
00090 
00091     void settreshold( uint treshold );
00092 
00093   private slots:
00094     void completeBackwards();
00095     void completeForwards();
00096     void shellComplete();
00097 
00098     void popupCompletionList( QString word=QString::null );
00099     void autoPopupCompletionList();
00100     void toggleAutoPopup();
00101 
00102     void slotVariableChanged( const QString &, const QString & );
00103 
00104   private:
00105     void complete( bool fw=true );
00106 
00107     QString word();
00108     QValueList<KTextEditor::CompletionEntry> allMatches( const QString &word );
00109     QString findLongestUnique(const QValueList < KTextEditor::CompletionEntry > &matches);
00110     KTextEditor::View *m_view;
00111     struct DocWordCompletionPluginViewPrivate *d;
00112 };
00113 
00114 class DocWordCompletionConfigPage : public KTextEditor::ConfigPage
00115 {
00116   Q_OBJECT
00117   public:
00118     DocWordCompletionConfigPage( DocWordCompletionPlugin *completion, QWidget *parent, const char *name );
00119     virtual ~DocWordCompletionConfigPage() {};
00120 
00121     virtual void apply();
00122     virtual void reset();
00123     virtual void defaults();
00124 
00125   private:
00126     DocWordCompletionPlugin *m_completion;
00127     class QCheckBox *cbAutoPopup;
00128     class QSpinBox *sbAutoPopup;
00129     class QLabel *lSbRight;
00130 };
00131 
00132 #endif // _DocWordCompletionPlugin_h_
00133