diff options
author | Daniel Baczynski <danielbaczynski8@gmail.com> | 2015-03-25 00:16:20 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2015-03-26 07:39:31 (GMT) |
commit | 85e53159321ab3e013dd2fc0a16748ed6755b119 (patch) | |
tree | 6ed333198bb756c8e1946505663ae0c95e72223b /Swift/QtUI/QtChatWindow.cpp | |
parent | b23f4fb9bee49f93bbba6a9039f0f764664125cd (diff) | |
download | swift-85e53159321ab3e013dd2fc0a16748ed6755b119.zip swift-85e53159321ab3e013dd2fc0a16748ed6755b119.tar.bz2 |
Add emoticons input popup
This is simple popup menu added to chat window where it is possible to choose an emoticon. To activate click on the smiling face next to input field.
When emoticon is selected its text equivalent is appended to input.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Tested on Ubuntu 14.10 with KDE and Qt 4.8.6
Change-Id: I6c5907959970398c9c38591f64ceec20efcbf409
Diffstat (limited to 'Swift/QtUI/QtChatWindow.cpp')
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 33bec75..f25c033 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -15,6 +15,7 @@ #include <QBoxLayout> #include <QCloseEvent> #include <QComboBox> +#include <QCursor> #include <QFileDialog> #include <QFileInfo> #include <QInputDialog> @@ -23,7 +24,9 @@ #include <QMenu> #include <QMessageBox> #include <QMimeData> +#include <QPoint> #include <QPushButton> +#include <QSize> #include <QSplitter> #include <QString> #include <QTextDocument> @@ -57,7 +60,7 @@ namespace Swift { -QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream, SettingsProvider* settings) : QtTabbable(), id_(Q2PSTRING(contact)), contact_(contact), nextAlertId_(0), eventStream_(eventStream), blockingState_(BlockingUnsupported), isMUC_(false), supportsImpromptuChat_(false) { +QtChatWindow::QtChatWindow(const QString& contact, QtChatTheme* theme, UIEventStream* eventStream, SettingsProvider* settings, const std::map<std::string, std::string>& emoticons) : QtTabbable(), id_(Q2PSTRING(contact)), contact_(contact), nextAlertId_(0), eventStream_(eventStream), blockingState_(BlockingUnsupported), isMUC_(false), supportsImpromptuChat_(false) { settings_ = settings; unreadCount_ = 0; isOnline_ = true; @@ -140,8 +143,17 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt inputBarLayout->addWidget(correctingLabel_); correctingLabel_->hide(); + QPushButton* emoticonsButton_ = new QPushButton(this); + emoticonsButton_->setIcon(QIcon(":/emoticons/smile.png")); + connect(emoticonsButton_, SIGNAL(clicked()), this, SLOT(handleEmoticonsButtonClicked())); + + emoticonsMenu_ = new QMenu(this); + QtEmoticonsGrid* emoticonsGrid = new QtEmoticonsGrid(emoticons, emoticonsMenu_); + connect(emoticonsGrid, SIGNAL(emoticonClicked(QString)), this, SLOT(handleEmoticonClicked(QString))); + // using an extra layout to work around Qt margin glitches on OS X QHBoxLayout* actionLayout = new QHBoxLayout(); + actionLayout->addWidget(emoticonsButton_); actionLayout->addWidget(actionButton_); inputBarLayout->addLayout(actionLayout); @@ -514,6 +526,7 @@ void QtChatWindow::updateTitleWithUnreadCount() { + void QtChatWindow::flash() { emit requestFlash(); } @@ -637,6 +650,16 @@ void QtChatWindow::setSubject(const std::string& subject) { subject_->setCursorPosition(0); } +void QtChatWindow::handleEmoticonsButtonClicked() { + emoticonsMenu_->adjustSize(); + QSize menuSize = emoticonsMenu_->size(); + emoticonsMenu_->exec(QPoint(QCursor::pos().x() - menuSize.width(), QCursor::pos().y() - menuSize.height())); +} + +void QtChatWindow::handleEmoticonClicked(QString emoticonAsText) { + input_->textCursor().insertText(emoticonAsText); +} + void QtChatWindow::handleActionButtonClicked() { QMenu contextMenu; QAction* changeSubject = NULL; |