summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtChatWindow.cpp')
-rw-r--r--Swift/QtUI/QtChatWindow.cpp113
1 files changed, 100 insertions, 13 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 874f710..82c65ce 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2017 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -111,8 +111,11 @@ QtChatWindow::QtChatWindow(const QString& contact, QtChatTheme* theme, UIEventSt
messageLog_ = new QtPlainChatView(this, eventStream_);
}
else {
- messageLog_ = new QtWebKitChatView(this, eventStream_, theme, this); // I accept that passing the ChatWindow in so that the view can call the signals is somewhat inelegant, but it saves a lot of boilerplate. This patch is unpleasant enough already. So let's fix this soon (it at least needs fixing by the time history is sorted), but not now.
+ messageLog_ = new QtWebKitChatView(this, eventStream_, theme, this, settings); // I accept that passing the ChatWindow in so that the view can call the signals is somewhat inelegant, but it saves a lot of boilerplate. This patch is unpleasant enough already. So let's fix this soon (it at least needs fixing by the time history is sorted), but not now.
}
+ // When used with QSplitter and setChildrenCollapsible(false), the following prevents
+ // this widget to be hidden, i.e. resized to zero width.
+ messageLog_->setMinimumWidth(20);
logRosterSplitter_->addWidget(messageLog_);
treeWidget_ = new QtOccupantListWidget(eventStream_, settings_, QtTreeWidget::MessageDisplayJID, this);
@@ -152,11 +155,15 @@ QtChatWindow::QtChatWindow(const QString& contact, QtChatTheme* theme, UIEventSt
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"));
+
+#if defined(SWIFTEN_PLATFORM_WINDOWS) || defined(SWIFTEN_PLATFORM_LINUX)
+ //Using a emoji glyph instead of an image makes the button sizes inequal in windows & linux,
+ //so we set fixed size for both buttons, the one that is hinted for actionButton_
+ emojisButton_->setMaximumWidth(actionButton_->sizeHint().width());
+ emojisButton_->setMaximumHeight(actionButton_->sizeHint().height());
+ actionButton_->setMaximumWidth(actionButton_->sizeHint().width());
+ actionButton_->setMaximumHeight(actionButton_->sizeHint().height());
#endif
connect(emojisButton_, SIGNAL(clicked()), this, SLOT(handleEmojisButtonClicked()));
@@ -353,6 +360,10 @@ QByteArray QtChatWindow::getSplitterState() {
void QtChatWindow::handleChangeSplitterState(QByteArray state) {
logRosterSplitter_->restoreState(state);
+#ifdef SWIFTEN_PLATFORM_MACOSX
+ logRosterSplitter_->setHandleWidth(0);
+#endif
+ logRosterSplitter_->setChildrenCollapsible(false);
}
void QtChatWindow::handleSplitterMoved(int, int) {
@@ -494,7 +505,7 @@ void QtChatWindow::showEvent(QShowEvent* event) {
QWidget::showEvent(event);
}
-void QtChatWindow::setUnreadMessageCount(int count) {
+void QtChatWindow::setUnreadMessageCount(size_t count) {
if (unreadCount_ != count) {
unreadCount_ = count;
updateTitleWithUnreadCount();
@@ -536,7 +547,7 @@ void QtChatWindow::flash() {
emit requestFlash();
}
-int QtChatWindow::getCount() {
+size_t QtChatWindow::getCount() {
return unreadCount_;
}
@@ -693,7 +704,7 @@ void QtChatWindow::handleEmojisButtonClicked() {
emojisLayout->setContentsMargins(style()->pixelMetric(QStyle::PM_MenuHMargin),style()->pixelMetric(QStyle::PM_MenuVMargin),
style()->pixelMetric(QStyle::PM_MenuHMargin),style()->pixelMetric(QStyle::PM_MenuVMargin));
emojisLayout->addWidget(emojisGrid_);
- emojisMenu_ = std::unique_ptr<QMenu>(new QMenu());
+ emojisMenu_ = std::make_unique<QMenu>();
emojisMenu_->setLayout(emojisLayout);
emojisMenu_->adjustSize();
@@ -716,7 +727,17 @@ void QtChatWindow::handleEmojiClicked(QString emoji) {
void QtChatWindow::handleTextInputReceivedFocus() {
lastLineTracker_.setHasFocus(true);
input_->setFocus();
- onAllMessagesRead();
+ if (focusTimer_) {
+ focusTimer_->stop();
+ }
+ else {
+ focusTimer_ = std::make_unique<QTimer>(this);
+ focusTimer_->setSingleShot(true);
+ focusTimer_->setTimerType(Qt::CoarseTimer);
+ connect(focusTimer_.get(), &QTimer::timeout, this, &QtChatWindow::handleFocusTimerTick);
+ }
+ focusTimer_->setInterval(1000);
+ focusTimer_->start();
}
void QtChatWindow::handleTextInputLostFocus() {
@@ -730,6 +751,7 @@ void QtChatWindow::handleActionButtonClicked() {
QAction* affiliations = nullptr;
QAction* destroy = nullptr;
QAction* invite = nullptr;
+ QAction* leave = nullptr;
QAction* block = nullptr;
QAction* unblock = nullptr;
@@ -783,6 +805,10 @@ void QtChatWindow::handleActionButtonClicked() {
invite = contextMenu.addAction(tr("Invite person to this room…"));
invite->setEnabled(isOnline_);
break;
+ case ChatWindow::Leave:
+ leave = contextMenu.addAction(tr("Leave room"));
+ leave->setEnabled(isOnline_);
+ break;
}
}
}
@@ -834,6 +860,9 @@ void QtChatWindow::handleActionButtonClicked() {
else if (result == invite) {
onInviteToChat(std::vector<JID>());
}
+ else if (result == leave) {
+ close();
+ }
else if (result == block) {
onBlockUserRequest();
}
@@ -867,14 +896,16 @@ void QtChatWindow::setCanInitiateImpromptuChats(bool supportsImpromptu) {
}
void QtChatWindow::showBookmarkWindow(const MUCBookmark& bookmark) {
- if (roomBookmarkState_ == RoomNotBookmarked) {
- QtAddBookmarkWindow* window = new QtAddBookmarkWindow(eventStream_, bookmark);
+ if (roomBookmarkState_ != RoomNotBookmarked) {
+ QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, bookmark);
window->show();
}
+#ifndef NOT_YET
else {
- QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, bookmark);
+ QtAddBookmarkWindow* window = new QtAddBookmarkWindow(eventStream_, bookmark);
window->show();
}
+#endif // ! NOT_YET
}
std::string QtChatWindow::getID() const {
@@ -984,4 +1015,60 @@ void QtChatWindow::setBookmarkState(RoomBookmarkState bookmarkState) {
roomBookmarkState_ = bookmarkState;
}
+void QtChatWindow::setChatSecurityMarking(const std::string& markingValue, const std::string& markingForegroundColorValue, const std::string& markingBackgroundColorValue) {
+ auto layout = static_cast<QBoxLayout*>(this->layout());
+
+ if (securityMarkingLayout_) {
+ layout->removeItem(securityMarkingLayout_);
+ securityMarkingLayout_->removeWidget(securityMarkingDisplay_);
+ delete securityMarkingLayout_;
+ }
+ delete securityMarkingDisplay_;
+
+ securityMarkingLayout_ = new QHBoxLayout();
+ securityMarkingDisplay_ = new QLabel(P2QSTRING(markingValue));
+
+ securityMarkingLayout_->addWidget(securityMarkingDisplay_);
+ layout->insertLayout(1, securityMarkingLayout_);
+
+ auto palette = securityMarkingDisplay_->palette();
+ palette.setColor(securityMarkingDisplay_->foregroundRole(), P2QSTRING(markingForegroundColorValue));
+ palette.setColor(securityMarkingDisplay_->backgroundRole(), P2QSTRING(markingBackgroundColorValue));
+
+ securityMarkingDisplay_->setPalette(palette);
+ securityMarkingDisplay_->setContentsMargins(4,4,4,4);
+ securityMarkingDisplay_->setAutoFillBackground(true);
+ securityMarkingDisplay_->setAlignment(Qt::AlignCenter);
+}
+
+void QtChatWindow::removeChatSecurityMarking() {
+ if (!securityMarkingLayout_) {
+ return;
+ }
+
+ auto layout = static_cast<QBoxLayout*>(this->layout());
+
+ layout->removeItem(securityMarkingLayout_);
+ securityMarkingLayout_->removeWidget(securityMarkingDisplay_);
+
+ delete securityMarkingDisplay_;
+ delete securityMarkingLayout_;
+ securityMarkingDisplay_ = nullptr;
+ securityMarkingLayout_ = nullptr;
+}
+
+void QtChatWindow::handleFocusTimerTick() {
+ if (hasFocus()) {
+ onAllMessagesRead();
+ }
+ focusTimer_.reset();
+}
+
+void QtChatWindow::resendMessage(const std::string& id) {
+ if (!isOnline_ || (blockingState_ == IsBlocked)) {
+ return;
+ }
+ onResendMessageRequest(id);
+}
+
}