summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtChatWindow.cpp7
-rw-r--r--Swift/QtUI/QtTextEdit.cpp29
-rw-r--r--Swift/QtUI/QtTextEdit.h6
3 files changed, 24 insertions, 18 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 0da4563..bda6b3e 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -284,75 +284,75 @@ void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) {
event->ignore();
}
else {
messageLog_->handleKeyPressEvent(event);
}
}
void QtChatWindow::beginCorrection() {
boost::optional<AlertID> newCorrectingAlert;
if (correctionEnabled_ == Maybe) {
newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat may not support message correction. If you send a correction anyway, it may appear as a duplicate message")));
}
else if (correctionEnabled_ == No) {
newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat does not support message correction. If you send a correction anyway, it will appear as a duplicate message")));
}
if (newCorrectingAlert) {
if (correctingAlert_) {
removeAlert(*correctingAlert_);
}
correctingAlert_ = newCorrectingAlert;
}
QTextCursor cursor = input_->textCursor();
cursor.select(QTextCursor::Document);
cursor.beginEditBlock();
cursor.insertText(QString(lastSentMessage_));
cursor.endEditBlock();
isCorrection_ = true;
correctingLabel_->show();
- input_->setStyleSheet(alertStyleSheet_);
+ input_->setCorrectionHighlight(true);
labelsWidget_->setEnabled(false);
}
void QtChatWindow::cancelCorrection() {
if (correctingAlert_) {
removeAlert(*correctingAlert_);
correctingAlert_.reset();
}
QTextCursor cursor = input_->textCursor();
cursor.select(QTextCursor::Document);
cursor.removeSelectedText();
isCorrection_ = false;
correctingLabel_->hide();
- input_->setStyleSheet(qApp->styleSheet());
+ input_->setCorrectionHighlight(false);
labelsWidget_->setEnabled(true);
}
QByteArray QtChatWindow::getSplitterState() {
return logRosterSplitter_->saveState();
}
void QtChatWindow::handleChangeSplitterState(QByteArray state) {
logRosterSplitter_->restoreState(state);
}
void QtChatWindow::handleSplitterMoved(int, int) {
emit splitterMoved();
}
void QtChatWindow::tabComplete() {
if (!completer_) {
return;
}
QTextCursor cursor;
if (tabCompleteCursor_.hasSelection()) {
cursor = tabCompleteCursor_;
}
else {
cursor = input_->textCursor();
while(cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor) && cursor.document()->characterAt(cursor.position() - 1) != ' ') { }
}
QString root = cursor.selectedText();
if (root.isEmpty()) {
@@ -817,64 +817,61 @@ void QtChatWindow::setAffiliations(MUCOccupant::Affiliation affiliation, const s
}
void QtChatWindow::setAvailableRoomActions(const std::vector<RoomAction>& actions) {
availableRoomActions_ = actions;
}
void QtChatWindow::setBlockingState(BlockingState state) {
blockingState_ = state;
}
void QtChatWindow::setCanInitiateImpromptuChats(bool supportsImpromptu) {
supportsImpromptuChat_ = supportsImpromptu;
}
void QtChatWindow::showBookmarkWindow(const MUCBookmark& bookmark) {
if (roomBookmarkState_ == RoomNotBookmarked) {
QtAddBookmarkWindow* window = new QtAddBookmarkWindow(eventStream_, bookmark);
window->show();
}
else {
QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, bookmark);
window->show();
}
}
std::string QtChatWindow::getID() const {
return id_;
}
void QtChatWindow::setEmphasiseFocus(bool emphasise) {
- input_->setAttribute(Qt::WA_MacShowFocusRect, emphasise);
-#ifdef SWIFTEN_PLATFORM_WINDOWS
input_->setEmphasiseFocus(emphasise);
-#endif
}
void QtChatWindow::showRoomConfigurationForm(Form::ref form) {
if (mucConfigurationWindow_) {
delete mucConfigurationWindow_.data();
}
mucConfigurationWindow_ = new QtMUCConfigurationWindow(form);
mucConfigurationWindow_->onFormComplete.connect(boost::bind(boost::ref(onConfigureRequest), _1));
mucConfigurationWindow_->onFormCancelled.connect(boost::bind(boost::ref(onConfigurationFormCancelled)));
}
void QtChatWindow::handleAppendedToLog() {
if (lastLineTracker_.getShouldMoveLastLine()) {
/* should this be queued? */
messageLog_->addLastSeenLine();
}
if (isWidgetSelected()) {
onAllMessagesRead();
}
}
void QtChatWindow::addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) {
handleAppendedToLog();
messageLog_->addMUCInvitation(senderName, jid, reason, password, direct, isImpromptu, isContinuation);
}
std::string QtChatWindow::addMessage(const ChatMessage& message, const std::string& senderName, bool senderIsSelf, std::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) {
handleAppendedToLog();
return messageLog_->addMessage(message, senderName, senderIsSelf, label, avatarPath, time);
}
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 {
diff --git a/Swift/QtUI/QtTextEdit.h b/Swift/QtUI/QtTextEdit.h
index 921c4b9..228aa9e 100644
--- a/Swift/QtUI/QtTextEdit.h
+++ b/Swift/QtUI/QtTextEdit.h
@@ -1,66 +1,68 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <QPointer>
#include <QTextEdit>
-#include <Swift/Controllers/SettingConstants.h>
#include <Swift/Controllers/Settings/SettingsProvider.h>
#include <SwifTools/SpellParser.h>
#include <Swift/QtUI/QtSpellCheckHighlighter.h>
namespace Swift {
class SpellChecker;
class QtSpellCheckerWindow;
class QtTextEdit : public QTextEdit {
Q_OBJECT
public:
QtTextEdit(SettingsProvider* settings, QWidget* parent = nullptr);
virtual ~QtTextEdit();
virtual QSize sizeHint() const;
+
void setEmphasiseFocus(bool emphasise);
+ void setCorrectionHighlight(bool coorectionHighlight);
signals:
void wordCorrected(QString& word);
void returnPressed();
void unhandledKeyPressEvent(QKeyEvent* event);
void receivedFocus();
void lostFocus();
public slots:
void handleSettingChanged(const std::string& settings);
protected:
virtual void keyPressEvent(QKeyEvent* event);
virtual void focusInEvent(QFocusEvent* event);
virtual void focusOutEvent(QFocusEvent* event);
virtual void contextMenuEvent(QContextMenuEvent* event);
private slots:
void handleTextChanged();
private:
void addSuggestions(QMenu* menu, QContextMenuEvent* event);
void replaceMisspelledWord(const QString& word, int cursorPosition);
void setUpSpellChecker();
void spellCheckerSettingsWindow();
PositionPair getWordFromCursor(int cursorPosition);
- void updateEmphasisedFocus();
+ void updateStyleSheet();
private:
SpellChecker* checker_;
QtSpellCheckHighlighter* highlighter_;
std::vector<QAction*> replaceWordActions_;
SettingsProvider* settings_;
QPointer<QtSpellCheckerWindow> spellCheckerWindow_;
bool emphasiseFocus_ = false;
+ bool correctionHighlight_ = false;
};
}