• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
  • editor
kmcomposereditor.cpp
Go to the documentation of this file.
1 
22 #include "kmcomposereditor.h"
23 #include "editor/kmcomposewin.h"
24 #include "kmcommands.h"
25 #include "util.h"
26 
27 #include <kabc/addressee.h>
28 #include <kmime/kmime_codecs.h>
29 #include <akonadi/itemfetchjob.h>
30 
31 #include <kio/jobuidelegate.h>
32 
33 #include "messagecore/settings/globalsettings.h"
34 
35 #include <KPIMTextEdit/EMailQuoteHighlighter>
36 
37 #include <KAction>
38 #include <KActionCollection>
39 #include <KLocale>
40 #include <KMenu>
41 #include <KPushButton>
42 #include <KInputDialog>
43 
44 #include <Sonnet/ConfigDialog>
45 
46 #include "kmkernel.h"
47 #include "foldercollection.h"
48 #include <QCheckBox>
49 #include <QTextCodec>
50 #include <QtCore/QMimeData>
51 
52 using namespace MailCommon;
53 
54 KMComposerEditor::KMComposerEditor( KMComposeWin *win,QWidget *parent)
55  : MessageComposer::KMeditor(parent, QLatin1String("kmail2rc") ),mComposerWin(win)
56 {
57  setAutocorrection(KMKernel::self()->composerAutoCorrection());
58 }
59 
60 KMComposerEditor::~KMComposerEditor()
61 {
62 }
63 
64 void KMComposerEditor::createActions( KActionCollection *actionCollection )
65 {
66  KMeditor::createActions( actionCollection );
67 
68  KAction *pasteQuotation = new KAction( i18n("Pa&ste as Quotation"), this );
69  actionCollection->addAction(QLatin1String("paste_quoted"), pasteQuotation );
70  pasteQuotation->setShortcut(QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_O));
71  connect( pasteQuotation, SIGNAL(triggered(bool)), this, SLOT(slotPasteAsQuotation()) );
72 
73  KAction *addQuoteChars = new KAction( i18n("Add &Quote Characters"), this );
74  actionCollection->addAction( QLatin1String("tools_quote"), addQuoteChars );
75  connect( addQuoteChars, SIGNAL(triggered(bool)), this, SLOT(slotAddQuotes()) );
76 
77  KAction *remQuoteChars = new KAction( i18n("Re&move Quote Characters"), this );
78  actionCollection->addAction( QLatin1String("tools_unquote"), remQuoteChars );
79  connect (remQuoteChars, SIGNAL(triggered(bool)), this, SLOT(slotRemoveQuotes()) );
80 
81  KAction *pasteWithoutFormatting = new KAction( i18n("Paste Without Formatting"), this );
82  actionCollection->addAction( QLatin1String("paste_without_formatting"), pasteWithoutFormatting );
83  pasteWithoutFormatting->setShortcut(QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_V));
84  connect (pasteWithoutFormatting, SIGNAL(triggered(bool)), this, SLOT(slotPasteWithoutFormatting()) );
85 }
86 
87 void KMComposerEditor::setHighlighterColors(KPIMTextEdit::EMailQuoteHighlighter * highlighter)
88 {
89  QColor color1 = KMail::Util::quoteL1Color();
90  QColor color2 = KMail::Util::quoteL2Color();
91  QColor color3 = KMail::Util::quoteL3Color();
92  QColor misspelled = KMail::Util::misspelledColor();
93 
94  if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
95  color1 = MessageCore::GlobalSettings::self()->quotedText1();
96  color2 = MessageCore::GlobalSettings::self()->quotedText2();
97  color3 = MessageCore::GlobalSettings::self()->quotedText3();
98  misspelled = MessageCore::GlobalSettings::self()->misspelledColor();
99  }
100 
101  highlighter->setQuoteColor( Qt::black /* ignored anyway */,
102  color1, color2, color3, misspelled );
103 }
104 
105 QString KMComposerEditor::smartQuote( const QString & msg )
106 {
107  return mComposerWin->smartQuote( msg );
108 }
109 
110 void KMComposerEditor::replaceUnknownChars( const QTextCodec *codec )
111 {
112  QTextCursor cursor( document() );
113  cursor.beginEditBlock();
114  while ( !cursor.atEnd() ) {
115  cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor );
116  const QChar cur = cursor.selectedText().at( 0 );
117  if ( codec->canEncode( cur ) ) {
118  cursor.clearSelection();
119  } else {
120  cursor.insertText( QLatin1String("?") );
121  }
122  }
123  cursor.endEditBlock();
124 }
125 
126 bool KMComposerEditor::canInsertFromMimeData( const QMimeData *source ) const
127 {
128  if ( source->hasImage() && source->hasFormat( QLatin1String("image/png") ) )
129  return true;
130  if ( source->hasFormat( QLatin1String("text/x-kmail-textsnippet") ) )
131  return true;
132  if ( source->hasUrls() )
133  return true;
134 
135  return KPIMTextEdit::TextEdit::canInsertFromMimeData( source );
136 }
137 
138 void KMComposerEditor::insertFromMimeData( const QMimeData *source )
139 {
140  if ( source->hasFormat( QLatin1String("text/x-kmail-textsnippet") ) ) {
141  emit insertSnippet();
142  return;
143  }
144 
145  if ( !mComposerWin->insertFromMimeData( source, false ) )
146  KPIMTextEdit::TextEdit::insertFromMimeData( source );
147 }
148 
149 void KMComposerEditor::showSpellConfigDialog( const QString & configFileName )
150 {
151  KConfig config( configFileName );
152  Sonnet::ConfigDialog dialog( &config, this );
153  if ( !spellCheckingLanguage().isEmpty() ) {
154  dialog.setLanguage( spellCheckingLanguage() );
155  }
156  // Hackish way to hide the "Enable spell check by default" checkbox
157  // Our highlighter ignores this setting, so we should not expose its UI
158  QCheckBox *enabledByDefaultCB = dialog.findChild<QCheckBox *>( QLatin1String("m_checkerEnabledByDefaultCB") );
159  if ( enabledByDefaultCB ) {
160  enabledByDefaultCB->hide();
161  } else {
162  kWarning() << "Could not find any checkbox named 'm_checkerEnabledByDefaultCB'. Sonnet::ConfigDialog must have changed!";
163  }
164  if ( dialog.exec() ) {
165  setSpellCheckingLanguage( dialog.language() );
166  }
167 }
168 
169 void KMComposerEditor::mousePopupMenuImplementation(const QPoint& pos)
170 {
171  QMenu *popup = mousePopupMenu();
172  if ( popup ) {
173  QTextCursor cursor = textCursor();
174  if (cursor.hasSelection()) {
175  popup->addSeparator();
176  QMenu *changeCaseMenu = new QMenu(i18n("Change case..."), popup);
177  changeCaseMenu->addAction(mComposerWin->lowerCaseAction());
178  changeCaseMenu->addAction(mComposerWin->upperCaseAction());
179  popup->addMenu(changeCaseMenu);
180  }
181  aboutToShowContextMenu(popup);
182  popup->exec( pos );
183  delete popup;
184  }
185 }
186 
187 
188 #include "kmcomposereditor.moc"
KMComposerEditor::mousePopupMenuImplementation
void mousePopupMenuImplementation(const QPoint &pos)
Definition: kmcomposereditor.cpp:169
kmcomposereditor.h
KMComposerEditor::insertSnippet
void insertSnippet()
KMComposeWin::lowerCaseAction
KAction * lowerCaseAction() const
Definition: kmcomposewin.h:233
QWidget
KMComposeWin
Definition: kmcomposewin.h:106
KMComposerEditor::KMComposerEditor
KMComposerEditor(KMComposeWin *win, QWidget *parent=0)
Constructs a KMComposerEditor object.
Definition: kmcomposereditor.cpp:54
KMKernel::self
static KMKernel * self()
normal control stuff
Definition: kmkernel.cpp:1451
KMComposerEditor::insertFromMimeData
void insertFromMimeData(const QMimeData *source)
Definition: kmcomposereditor.cpp:138
KMComposerEditor::setHighlighterColors
void setHighlighterColors(KPIMTextEdit::EMailQuoteHighlighter *highlighter)
Reimplemented from KMEditor.
Definition: kmcomposereditor.cpp:87
KMComposeWin::smartQuote
QString smartQuote(const QString &msg)
Definition: kmcomposewin.cpp:2131
KMail::Util::quoteL3Color
QColor quoteL3Color()
Definition: util.cpp:221
KMail::Util::quoteL1Color
QColor quoteL1Color()
Definition: util.cpp:211
KMComposerEditor::replaceUnknownChars
void replaceUnknownChars(const QTextCodec *codec)
This replaces all characters not known to the specified codec with questionmarks. ...
Definition: kmcomposereditor.cpp:110
QMimeData
util.h
KMComposerEditor::canInsertFromMimeData
bool canInsertFromMimeData(const QMimeData *source) const
Definition: kmcomposereditor.cpp:126
KMail::Util::misspelledColor
QColor misspelledColor()
Definition: util.cpp:206
KMComposerEditor::~KMComposerEditor
~KMComposerEditor()
Definition: kmcomposereditor.cpp:60
KMComposeWin::upperCaseAction
KAction * upperCaseAction() const
Definition: kmcomposewin.h:234
QMenu
kmkernel.h
kmcomposewin.h
KMComposerEditor::showSpellConfigDialog
void showSpellConfigDialog(const QString &configFileName)
Static override because we want to hide part of the dialog UI.
Definition: kmcomposereditor.cpp:149
KMComposerEditor::smartQuote
QString smartQuote(const QString &msg)
Reimplemented from KMEditor.
Definition: kmcomposereditor.cpp:105
KMail::Util::quoteL2Color
QColor quoteL2Color()
Definition: util.cpp:216
kmcommands.h
KMComposeWin::insertFromMimeData
bool insertFromMimeData(const QMimeData *source, bool forceAttachment=false)
Definition: kmcomposewin.cpp:2137
KMComposerEditor::createActions
void createActions(KActionCollection *actionCollection)
Reimplemented from KMEditor, to support more actions.
Definition: kmcomposereditor.cpp:64
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal