diff options
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 10 | ||||
-rw-r--r-- | Swift/QtUI/QtTextEdit.h | 2 |
3 files changed, 13 insertions, 0 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 48d331e..7051683 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -123,60 +123,61 @@ QtChatWindow::QtChatWindow(const QString& contact, QtChatTheme* theme, UIEventSt midBar_ = new QWidget(this); //layout->addWidget(midBar); midBar_->setAutoFillBackground(true); QHBoxLayout *midBarLayout = new QHBoxLayout(midBar_); midBarLayout->setContentsMargins(0,0,0,0); midBarLayout->setSpacing(2); //midBarLayout->addStretch(); labelsWidget_ = new QComboBox(this); labelsWidget_->setFocusPolicy(Qt::NoFocus); labelsWidget_->hide(); labelsWidget_->setSizeAdjustPolicy(QComboBox::AdjustToContents); midBarLayout->addWidget(labelsWidget_,0); connect(labelsWidget_, SIGNAL(currentIndexChanged(int)), this, SLOT(handleCurrentLabelChanged(int))); defaultLabelsPalette_ = labelsWidget_->palette(); QHBoxLayout* inputBarLayout = new QHBoxLayout(); inputBarLayout->setContentsMargins(0,0,0,0); inputBarLayout->setSpacing(2); input_ = new QtTextEdit(settings_, this); input_->setAcceptRichText(false); inputBarLayout->addWidget(midBar_); inputBarLayout->addWidget(input_); correctingLabel_ = new QLabel(tr("Correcting"), this); inputBarLayout->addWidget(correctingLabel_); correctingLabel_->hide(); connect(input_, SIGNAL(receivedFocus()), this, SLOT(handleTextInputReceivedFocus())); connect(input_, SIGNAL(lostFocus()), this, SLOT(handleTextInputLostFocus())); + connect(input_, SIGNAL(itemDropped(QDropEvent*)), this, SLOT(dropEvent(QDropEvent*))); QPushButton* emojisButton_ = new QPushButton(this); #ifdef SWIFTEN_PLATFORM_MACOSX emojisButton_->setText("\xF0\x9F\x98\x83"); #else emojisButton_->setIcon(QIcon(":/emoticons/smile.png")); #endif connect(emojisButton_, SIGNAL(clicked()), this, SLOT(handleEmojisButtonClicked())); // using an extra layout to work around Qt margin glitches on OS X QHBoxLayout* actionLayout = new QHBoxLayout(); actionLayout->addWidget(emojisButton_); actionLayout->addWidget(actionButton_); inputBarLayout->addLayout(actionLayout); layout->addLayout(inputBarLayout); inputClearing_ = false; contactIsTyping_ = false; tabCompletion_ = false; connect(input_, SIGNAL(unhandledKeyPressEvent(QKeyEvent*)), this, SLOT(handleKeyPressEvent(QKeyEvent*))); connect(input_, SIGNAL(returnPressed()), this, SLOT(returnPressed())); connect(input_, SIGNAL(textChanged()), this, SLOT(handleInputChanged())); connect(input_, SIGNAL(cursorPositionChanged()), this, SLOT(handleCursorPositionChanged())); setFocusProxy(input_); logRosterSplitter_->setFocusProxy(input_); midBar_->setFocusProxy(input_); messageLog_->setFocusProxy(input_); connect(messageLog_, SIGNAL(gotFocus()), input_, SLOT(setFocus())); diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 1b4d76d..168e6fc 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -1,47 +1,48 @@ /* * Copyright (c) 2010-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/QtUI/QtTextEdit.h> #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> #include <boost/tuple/tuple.hpp> #include <QApplication> #include <QKeyEvent> #include <QKeySequence> #include <QMenu> #include <QTextDocument> +#include <QMimeData> #include <Swiften/Base/Log.h> #include <SwifTools/SpellChecker.h> #include <SwifTools/SpellCheckerFactory.h> #include <Swift/QtUI/QtSpellCheckerWindow.h> #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/QtUISettingConstants.h> #include <Swift/QtUI/QtUtilities.h> namespace Swift { QtTextEdit::QtTextEdit(SettingsProvider* settings, QWidget* parent) : QTextEdit(parent), checker_(nullptr), highlighter_(nullptr) { connect(this, SIGNAL(textChanged()), this, SLOT(handleTextChanged())); settings_ = settings; #ifdef HAVE_SPELLCHECKER setUpSpellChecker(); #endif handleTextChanged(); QTextOption textOption = document()->defaultTextOption(); textOption.setWrapMode(QTextOption::WordWrap); document()->setDefaultTextOption(textOption); } QtTextEdit::~QtTextEdit() { delete checker_; } void QtTextEdit::keyPressEvent(QKeyEvent* event) { @@ -152,60 +153,69 @@ PositionPair QtTextEdit::getWordFromCursor(int cursorPosition) { QSize QtTextEdit::sizeHint() const { QSize hint = document()->size().toSize(); QMargins margins = contentsMargins(); return hint + QSize(margins.left() + margins.right(), margins.top() + margins.bottom()); } void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { QMenu* menu = createStandardContextMenu(); QTextCursor cursor = cursorForPosition(event->pos()); #ifdef HAVE_SPELLCHECKER QAction* insertPoint = menu->actions().first(); QAction* settingsAction = new QAction(tr("Spell Checker Options"), menu); menu->insertAction(insertPoint, settingsAction); menu->insertAction(insertPoint, menu->addSeparator()); addSuggestions(menu, event); QAction* result = menu->exec(event->globalPos()); if (result == settingsAction) { spellCheckerSettingsWindow(); } for (auto& replaceWordAction : replaceWordActions_) { if (replaceWordAction == result) { replaceMisspelledWord(replaceWordAction->text(), cursor.position()); } } #else menu->exec(event->globalPos()); #endif delete menu; } +void QtTextEdit::dropEvent(QDropEvent* event) { + if (event->mimeData()->hasUrls()) { + itemDropped(event); + } + else { + QTextEdit::dropEvent(event); + } +} + void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) { replaceWordActions_.clear(); if (checker_ && highlighter_) { QAction* insertPoint = menu->actions().first(); QTextCursor cursor = cursorForPosition(event->pos()); PositionPair wordPosition = getWordFromCursor(cursor.position()); if (boost::get<0>(wordPosition) < 0) { // The click was executed outside a spellable word so no // suggestions are necessary return; } cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor); std::vector<std::string> wordList; checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); if (wordList.size() == 0) { QAction* noSuggestions = new QAction(tr("No Suggestions"), menu); noSuggestions->setDisabled(true); menu->insertAction(insertPoint, noSuggestions); } else { for (auto& word : wordList) { QAction* wordAction = new QAction(word.c_str(), menu); menu->insertAction(insertPoint, wordAction); replaceWordActions_.push_back(wordAction); } } menu->insertAction(insertPoint, menu->addSeparator()); } diff --git a/Swift/QtUI/QtTextEdit.h b/Swift/QtUI/QtTextEdit.h index 228aa9e..7ce5d88 100644 --- a/Swift/QtUI/QtTextEdit.h +++ b/Swift/QtUI/QtTextEdit.h @@ -8,61 +8,63 @@ #include <QPointer> #include <QTextEdit> #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(); + void itemDropped(QDropEvent* event); 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); + virtual void dropEvent(QDropEvent* 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 updateStyleSheet(); private: SpellChecker* checker_; QtSpellCheckHighlighter* highlighter_; std::vector<QAction*> replaceWordActions_; SettingsProvider* settings_; QPointer<QtSpellCheckerWindow> spellCheckerWindow_; bool emphasiseFocus_ = false; bool correctionHighlight_ = false; }; } |