KPIMTextedit Library
textedit.h
00001 /* 00002 Copyright (c) 2009 Thomas McGuire <mcguire@kde.org> 00003 00004 Based on KMail and libkdepim code by: 00005 Copyright 2007 - 2010 Laurent Montel <montel@kde.org> 00006 00007 This library is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU Library General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or (at your 00010 option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00015 License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to the 00019 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00020 02110-1301, USA. 00021 */ 00022 #ifndef KPIMTEXTEDIT_TEXTEDIT_H 00023 #define KPIMTEXTEDIT_TEXTEDIT_H 00024 00025 #include "kpimtextedit_export.h" 00026 00027 #include <kpimidentities/signature.h> 00028 00029 #include <KDE/KRichTextWidget> 00030 00031 #include <QtCore/QSharedPointer> 00032 00033 #include <memory> 00034 #define FIX_KMAIL_INSERT_IMAGE 1 00035 00036 class KUrl; 00037 class QFileInfo; 00038 namespace KPIMTextEdit { 00039 00040 class TextEditPrivate; 00041 class EMailQuoteHighlighter; 00042 00047 struct EmbeddedImage 00048 { 00049 QByteArray image; 00050 QString contentID; 00051 QString imageName; 00052 }; 00053 00060 struct ImageWithName 00061 { 00062 QImage image; 00063 QString name; 00064 }; 00065 00066 typedef QSharedPointer<ImageWithName> ImageWithNamePtr; 00067 typedef QList< ImageWithNamePtr > ImageWithNameList; 00068 typedef QList< QSharedPointer<EmbeddedImage> > ImageList; 00069 00081 class KPIMTEXTEDIT_EXPORT TextEdit : public KRichTextWidget, 00082 protected KTextEditSpellInterface // TODO: KDE5: get rid of the spell interface 00083 { 00084 Q_OBJECT 00085 00086 public: 00087 00093 explicit TextEdit( const QString& text, QWidget *parent = 0 ); 00094 00099 explicit TextEdit( QWidget *parent = 0 ); 00100 00101 00110 explicit TextEdit( QWidget * parent, const QString & configFile ); 00111 00120 void enableImageActions(); 00121 00125 ~TextEdit(); 00126 00136 virtual void createActions( KActionCollection *actionCollection ); 00137 00144 void addImage( const KUrl &url ); 00145 00156 void loadImage( const QImage &image, const QString &matchName, const QString &resourceName ); 00157 00162 void deleteCurrentLine(); 00163 00171 ImageList embeddedImages() const; 00172 00179 ImageWithNameList imagesWithName() const; 00180 00185 QString toWrappedPlainText() const; 00186 00191 QString toCleanPlainText() const; 00192 00204 virtual void setHighlighterColors( EMailQuoteHighlighter *highlighter ); 00205 00209 bool isLineQuoted( const QString &line ) const; 00210 00221 virtual int quoteLength( const QString &line ) const; 00222 00227 virtual const QString defaultQuoteSign() const; 00228 00246 static QByteArray imageNamesToContentIds( const QByteArray &htmlBody, const ImageList &imageList ); 00247 00256 bool isFormattingUsed() const; 00257 00258 /* Return config file 00259 * @since 4.5 00260 */ 00261 QString configFile() const; 00262 00263 /* Return true if richtext mode support image 00264 * @since 4.6 00265 */ 00266 bool isEnableImageActions() const; 00267 /* 00268 * @since 4.6 00269 */ 00270 void insertImage( const QImage &image, const QFileInfo&info ); 00271 00272 protected: 00273 00277 virtual bool canInsertFromMimeData( const QMimeData *source ) const; 00278 00282 virtual void insertFromMimeData( const QMimeData *source ); 00283 00288 virtual bool eventFilter( QObject*o, QEvent* e ); 00289 00294 virtual void keyPressEvent ( QKeyEvent * e ); 00295 00296 // For the explaination for these four methods, see the comment at the 00297 // spellCheckingEnabled variable of the private class. 00298 00302 virtual bool isSpellCheckingEnabled() const; 00303 00307 virtual void setSpellCheckingEnabled( bool enable ); 00308 00313 virtual bool shouldBlockBeSpellChecked( const QString& block ) const; 00314 00319 virtual void createHighlighter(); 00320 00321 private: 00322 00323 std::auto_ptr<TextEditPrivate> const d; 00324 friend class TextEditPrivate; 00325 Q_PRIVATE_SLOT( d, void _k_slotAddImage() ) 00326 Q_PRIVATE_SLOT( d, void _k_slotDeleteLine() ) 00327 }; 00328 00329 } // namespace 00330 00331 #endif