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

kmail

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

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