From 417c4028a053bcce20bf76aed13d5991bb437e0f Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 31 Jul 2017 01:36:42 +0200 Subject: [PATCH] Improve user friendliness of changing chat widget channel/opening new chat widget --- src/widgets/chatwidget.cpp | 14 +++++++++++--- src/widgets/chatwidget.hpp | 2 +- src/widgets/chatwidgetheader.cpp | 2 +- src/widgets/notebookpage.cpp | 7 ++++++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/widgets/chatwidget.cpp b/src/widgets/chatwidget.cpp index 92e2331a3..77ff767a5 100644 --- a/src/widgets/chatwidget.cpp +++ b/src/widgets/chatwidget.cpp @@ -157,18 +157,26 @@ LimitedQueueSnapshot ChatWidget::getMessagesSnapshot() return this->messages.getSnapshot(); } -void ChatWidget::showChangeChannelPopup() +bool ChatWidget::showChangeChannelPopup(const char *dialogTitle, bool empty) { // create new input dialog and execute it TextInputDialog dialog(this); - dialog.setText(QString::fromStdString(this->channelName)); + dialog.setWindowTitle(dialogTitle); + + if (!empty) { + dialog.setText(QString::fromStdString(this->channelName)); + } if (dialog.exec() == QDialog::Accepted) { QString newChannelName = dialog.getText().trimmed(); this->channelName = newChannelName.toStdString(); + + return true; } + + return false; } void ChatWidget::layoutMessages(bool forceUpdate) @@ -229,7 +237,7 @@ void ChatWidget::doCloseSplit() void ChatWidget::doChangeChannel() { - this->showChangeChannelPopup(); + this->showChangeChannelPopup("Change channel"); } void ChatWidget::doPopup() diff --git a/src/widgets/chatwidget.hpp b/src/widgets/chatwidget.hpp index 64a038ee7..afdeaacb2 100644 --- a/src/widgets/chatwidget.hpp +++ b/src/widgets/chatwidget.hpp @@ -48,7 +48,7 @@ public: std::shared_ptr getChannel() const; std::shared_ptr &getChannelRef(); - void showChangeChannelPopup(); + bool showChangeChannelPopup(const char *dialogTitle, bool empty = false); messages::LimitedQueueSnapshot getMessagesSnapshot(); void layoutMessages(bool forceUpdate = false); void updateGifEmotes(); diff --git a/src/widgets/chatwidgetheader.cpp b/src/widgets/chatwidgetheader.cpp index 6e3a2bc6e..8e60c4ccd 100644 --- a/src/widgets/chatwidgetheader.cpp +++ b/src/widgets/chatwidgetheader.cpp @@ -132,7 +132,7 @@ void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event) void ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { - this->chatWidget->showChangeChannelPopup(); + this->chatWidget->showChangeChannelPopup("Change channel"); } } diff --git a/src/widgets/notebookpage.cpp b/src/widgets/notebookpage.cpp index fbec4e616..a1bfe7143 100644 --- a/src/widgets/notebookpage.cpp +++ b/src/widgets/notebookpage.cpp @@ -123,7 +123,12 @@ void NotebookPage::addChat(bool openChannelNameDialog) ChatWidget *w = this->createChatWidget(); if (openChannelNameDialog) { - w->showChangeChannelPopup(); + bool ret = w->showChangeChannelPopup("Open channel", true); + + if (!ret) { + delete w; + return; + } } this->addToLayout(w, std::pair(-1, -1));