kmail

snippetwidget.h

00001 /***************************************************************************
00002  *   snippet feature from kdevelop/plugins/snippet/                        *
00003  *                                                                         *
00004  *   Copyright (C) 2007 by Robert Gruber                                   *
00005  *   rgruber@users.sourceforge.net                                         *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  ***************************************************************************/
00013 #ifndef __SNIPPET_WIDGET_H__
00014 #define __SNIPPET_WIDGET_H__
00015 
00016 #include <qwidget.h>
00017 #include <qstring.h>
00018 #include <klistview.h>
00019 #include <qtooltip.h>
00020 #include <qrect.h>
00021 
00022 #include <ktexteditor/editinterface.h>
00023 #include <ktexteditor/view.h>
00024 #include "snippetconfig.h"
00025 
00026 class KDevProject;
00027 class SnippetPart;
00028 class QPushButton;
00029 class KListView;
00030 class QListViewItem;
00031 class QPoint;
00032 class SnippetDlg;
00033 class SnippetItem;
00034 class KTextEdit;
00035 class KConfig;
00036 class KMEdit;
00037 class KActionCollection;
00038 
00045 class SnippetWidget : public KListView, public QToolTip
00046 {
00047   Q_OBJECT
00048   public:
00049     SnippetWidget( KMEdit *editor, KActionCollection *actionCollection, QWidget *parent = 0 );
00050     ~SnippetWidget();
00051     QPtrList<SnippetItem> *getList() { return ( &_list ); }
00052     void writeConfig();
00053     SnippetConfig *getSnippetConfig() { return ( &_SnippetConfig ); }
00054 
00055   private slots:
00056     void initConfig();
00057 
00058   protected:
00059     void maybeTip( const QPoint & );
00060     bool acceptDrag( QDropEvent *event ) const;
00061 
00062   private:
00063     void insertIntoActiveView( const QString &text );
00064     QString parseText( QString text, QString del="$" );
00065     bool showMultiVarDialog( QMap<QString, QString> * map, QMap<QString, QString> * mapSave,
00066                              int &iWidth, int &iBasicHeight, int &iOneHeight );
00067     QString showSingleVarDialog( QString var, QMap<QString, QString> *mapSave, QRect &dlgSize );
00068     SnippetItem *makeItem( SnippetItem *parent, const QString &name, const QString &text,
00069                            const KShortcut &shortcut );
00070 
00071     QPtrList<SnippetItem> _list;
00072     QMap<QString, QString> _mapSaved;
00073     KConfig *_cfg;
00074     SnippetConfig _SnippetConfig;
00075     KMEdit *mEditor;
00076     KActionCollection *mActionCollection;
00077 
00078   public slots:
00079     void slotRemove();
00080     void slotEdit( QListViewItem *item_ = 0 );
00081     void slotEditGroup();
00082     void slotAdd();
00083     void slotAddGroup();
00084     void slotExecute();
00085 
00086   protected slots:
00087     void showPopupMenu( QListViewItem * item, const QPoint & p, int );
00088     void slotExecuted( QListViewItem * item =  0 );
00089     void slotDropped( QDropEvent *e, QListViewItem *after );
00090     void startDrag();
00091 };
00092 
00093 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys