summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtTextEdit.cpp')
-rw-r--r--Swift/QtUI/QtTextEdit.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp
index 60dac9b..d9ee2f4 100644
--- a/Swift/QtUI/QtTextEdit.cpp
+++ b/Swift/QtUI/QtTextEdit.cpp
@@ -55,88 +55,95 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) {
else if (((key == Qt::Key_PageUp || key == Qt::Key_PageDown) && modifiers == Qt::ShiftModifier)
|| (key == Qt::Key_C && modifiers == Qt::ControlModifier && textCursor().selectedText().isEmpty())
|| (key == Qt::Key_W && modifiers == Qt::ControlModifier)
|| (key == Qt::Key_PageUp && modifiers == Qt::ControlModifier)
|| (key == Qt::Key_PageDown && modifiers == Qt::ControlModifier)
|| (key == Qt::Key_Tab && modifiers == Qt::ControlModifier)
|| (key == Qt::Key_A && modifiers == Qt::AltModifier)
|| (key == Qt::Key_Tab)
|| (event->matches(QKeySequence::ZoomIn))
|| (event->matches(QKeySequence::ZoomOut))
) {
emit unhandledKeyPressEvent(event);
}
else if ((key == Qt::Key_Up)
|| (key == Qt::Key_Down)) {
emit unhandledKeyPressEvent(event);
QTextEdit::keyPressEvent(event);
}
else if ((key == Qt::Key_K && modifiers == QtUtilities::ctrlHardwareKeyModifier)) {
QTextCursor cursor = textCursor();
cursor.setPosition(toPlainText().size(), QTextCursor::KeepAnchor);
cursor.removeSelectedText();
}
else {
QTextEdit::keyPressEvent(event);
}
}
void QtTextEdit::setEmphasiseFocus(bool emphasise) {
emphasiseFocus_ = emphasise;
- updateEmphasisedFocus();
+ updateStyleSheet();
}
-void QtTextEdit::updateEmphasisedFocus() {
+void QtTextEdit::setCorrectionHighlight(bool correctionHighlight) {
+ correctionHighlight_ = correctionHighlight;
+ updateStyleSheet();
+}
+
+void QtTextEdit::updateStyleSheet() {
+ QString newStyleSheet;
+
+ if (correctionHighlight_) {
+ newStyleSheet += "background: rgb(255, 255, 153); color: black;";
+ }
+
if (emphasiseFocus_) {
if (hasFocus()) {
- setStyleSheet("border: 2px solid palette(highlight);");
- }
- else {
- setStyleSheet("");
+ newStyleSheet += "border: 2px solid palette(highlight);";
}
}
- else {
- setStyleSheet("");
- }
+
+ setStyleSheet(newStyleSheet);
handleTextChanged();
}
void QtTextEdit::focusInEvent(QFocusEvent* event) {
receivedFocus();
QTextEdit::focusInEvent(event);
- updateEmphasisedFocus();
+ updateStyleSheet();
}
void QtTextEdit::focusOutEvent(QFocusEvent* event) {
lostFocus();
QTextEdit::focusOutEvent(event);
- updateEmphasisedFocus();
+ updateStyleSheet();
}
void QtTextEdit::handleTextChanged() {
QSize previous(maximumSize());
setMaximumSize(QSize(maximumWidth(), sizeHint().height()));
if (previous != maximumSize()) {
updateGeometry();
}
}
void QtTextEdit::replaceMisspelledWord(const QString& word, int cursorPosition) {
QTextCursor cursor = textCursor();
PositionPair wordPosition = getWordFromCursor(cursorPosition);
cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor);
cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor);
QTextCharFormat normalFormat;
cursor.insertText(word, normalFormat);
}
PositionPair QtTextEdit::getWordFromCursor(int cursorPosition) {
PositionPairList misspelledPositions = highlighter_->getMisspelledPositions();
for (auto& misspelledPosition : misspelledPositions) {
if (cursorPosition >= boost::get<0>(misspelledPosition) && cursorPosition <= boost::get<1>(misspelledPosition)) {
return misspelledPosition;
}
}
return boost::make_tuple(-1,-1);
}
QSize QtTextEdit::sizeHint() const {