/***************************************************************************
- * Copyright (C) 2005-2016 by the Quassel Project *
+ * Copyright (C) 2005-2018 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
#include <QMessageBox>
#include <QScrollBar>
-#ifdef HAVE_SONNET
-# include <Sonnet/SpellCheckDecorator>
-#endif
-
#include "actioncollection.h"
#include "bufferview.h"
#include "graphicalui.h"
enableFindReplace(false);
#endif
-#ifdef HAVE_SONNET
- new Sonnet::SpellCheckDecorator(this);
+#if defined HAVE_SONNET && !defined HAVE_KDE
+ _spellCheckDecorator = new Sonnet::SpellCheckDecorator(this);
+ highlighter()->setActive(highlighter()->checkerEnabledByDefault());
#endif
setMode(SingleLine);
{
}
+#if defined HAVE_SONNET && !defined HAVE_KDE
+Sonnet::Highlighter *MultiLineEdit::highlighter() const
+{
+ return _spellCheckDecorator->highlighter();
+}
+
+
+void MultiLineEdit::setSpellCheckEnabled(bool enabled)
+{
+ highlighter()->setActive(enabled);
+ if (enabled) {
+ highlighter()->slotRehighlight();
+ }
+}
+
+void MultiLineEdit::contextMenuEvent(QContextMenuEvent *event)
+{
+ QMenu *menu = createStandardContextMenu();
+ menu->addSeparator();
+
+ auto action = menu->addAction(tr("Auto Spell Check"));
+ action->setCheckable(true);
+ action->setChecked(highlighter()->isActive());
+ connect(action, SIGNAL(toggled(bool)), this, SLOT(setSpellCheckEnabled(bool)));
+
+ menu->exec(event->globalPos());
+ delete menu;
+}
+
+#endif
+
void MultiLineEdit::setCustomFont(const QFont &font)
{
// use the style to determine a decent size
int h = qMin(qMax((int)document()->size().height() + scrollBarHeight, minPixelHeight), maxPixelHeight) + 2 * frameWidth();
- QStyleOptionFrameV2 opt;
+
+ QStyleOptionFrame opt;
opt.initFrom(this);
opt.rect = QRect(0, 0, 100, h);
opt.lineWidth = lineWidth();
opt.midLineWidth = midLineWidth();
opt.state |= QStyle::State_Sunken;
- QSize s = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(100, h).expandedTo(QApplication::globalStrut()), this);
+ QWidget *widget = this;
+#ifdef Q_OS_MAC
+ widget = 0;
+#endif
+ QSize s = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(100, h).expandedTo(QApplication::globalStrut()), widget);
if (s != _sizeHint) {
_sizeHint = s;
updateGeometry();
}
-void MultiLineEdit::setSpellCheckEnabled(bool enable)
-{
-#ifdef HAVE_KDE
- setCheckSpellingEnabled(enable);
-#else
- Q_UNUSED(enable)
-#endif
-}
-
-
void MultiLineEdit::setPasteProtectionEnabled(bool enable, QWidget *)
{
_pasteProtectionEnabled = enable;
QString msg = tr("Do you really want to paste %n line(s)?", "", lines.count());
msg += "<p>";
for (int i = 0; i < 4; i++) {
-#if QT_VERSION < 0x050000
- msg += Qt::escape(lines[i].left(40));
-#else
msg += lines[i].left(40).toHtmlEscaped();
-#endif
if (lines[i].count() > 40)
msg += "...";
msg += "<br />";