From 4ac811f2a9e11a71e6363a2d4396e7dedadfffea Mon Sep 17 00:00:00 2001 From: Cranken Date: Tue, 12 Sep 2017 22:10:30 +0200 Subject: [PATCH] Fixed popups in viewer list. (#110) --- forms/accountpopupform.ui | 6 ++++++ src/widgets/accountpopup.cpp | 8 +++++++- src/widgets/accountpopup.hpp | 5 +++-- src/widgets/chatwidget.cpp | 35 ++++++++++++++++++++++++++++++-- src/widgets/chatwidget.hpp | 1 + src/widgets/chatwidgetheader.cpp | 2 +- 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/forms/accountpopupform.ui b/forms/accountpopupform.ui index 1e816a144..9080f61fb 100644 --- a/forms/accountpopupform.ui +++ b/forms/accountpopupform.ui @@ -71,6 +71,12 @@ + + + 100 + 100 + + 100 diff --git a/src/widgets/accountpopup.cpp b/src/widgets/accountpopup.cpp index a58a8a493..01dfcb8af 100644 --- a/src/widgets/accountpopup.cpp +++ b/src/widgets/accountpopup.cpp @@ -14,7 +14,7 @@ namespace chatterino { namespace widgets { -AccountPopupWidget::AccountPopupWidget(std::shared_ptr &channel) +AccountPopupWidget::AccountPopupWidget(std::shared_ptr channel) : QWidget(nullptr) , _ui(new Ui::AccountPopup) , _channel(channel) @@ -37,8 +37,14 @@ void AccountPopupWidget::setName(const QString &name) getUserId(); } +void AccountPopupWidget::setChannel(std::shared_ptr channel) +{ + this->_channel = channel; +} + void AccountPopupWidget::getUserId() { + qDebug() << this->_channel.get()->name; QUrl nameUrl("https://api.twitch.tv/kraken/users?login=" + _ui->lblUsername->text()); QNetworkRequest req(nameUrl); diff --git a/src/widgets/accountpopup.hpp b/src/widgets/accountpopup.hpp index ee102f558..ccbf57317 100644 --- a/src/widgets/accountpopup.hpp +++ b/src/widgets/accountpopup.hpp @@ -19,9 +19,10 @@ class AccountPopupWidget : public QWidget { Q_OBJECT public: - AccountPopupWidget(std::shared_ptr &channel); + AccountPopupWidget(std::shared_ptr channel); void setName(const QString &name); + void setChannel(std::shared_ptr channel); private: Ui::AccountPopup *_ui; @@ -30,7 +31,7 @@ private: void getUserData(); void loadAvatar(const QUrl &avatarUrl); - std::shared_ptr &_channel; + std::shared_ptr _channel; QString userID; QPixmap avatar; diff --git a/src/widgets/chatwidget.cpp b/src/widgets/chatwidget.cpp index bc5867c2b..e31904490 100644 --- a/src/widgets/chatwidget.cpp +++ b/src/widgets/chatwidget.cpp @@ -104,6 +104,8 @@ void ChatWidget::setChannel(std::shared_ptr _newChannel) this->header.checkLive(); }); + this->view.userPopupWidget.setChannel(_newChannel); + // on new message this->messageAppendedConnection = this->channel->messageAppended.connect([this](SharedMessage &message) { @@ -267,6 +269,12 @@ void ChatWidget::doCloseSplit() void ChatWidget::doChangeChannel() { this->showChangeChannelPopup("Change channel"); + auto popup = this->findChildren(); + if(popup.at(0)->isVisible() && !popup.at(0)->isFloating()) + { + popup.at(0)->hide(); + doOpenViewerList(); + } } void ChatWidget::doPopup() @@ -371,9 +379,10 @@ void ChatWidget::doOpenViewerList() viewerDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable); - viewerDock->setMaximumHeight(this->height()); - viewerDock->resize(0.5*this->width(),this->height()); + viewerDock->resize(0.5*this->width(),this->height() - this->header.height() - this->input.height()); + viewerDock->move(0,this->header.height()); + auto accountPopup = new AccountPopupWidget(this->channel); auto multiWidget = new QWidget(viewerDock); auto dockVbox = new QVBoxLayout(viewerDock); auto searchBar = new QLineEdit(viewerDock); @@ -430,6 +439,20 @@ void ChatWidget::doOpenViewerList() viewerDock->setMinimumWidth(300); }); + QObject::connect(chattersList,&QListWidget::doubleClicked,this,[=](){ + if(!labels.contains(chattersList->currentItem()->text())) + { + doOpenAccountPopupWidget(accountPopup,chattersList->currentItem()->text()); + } + }); + + QObject::connect(resultList,&QListWidget::doubleClicked,this,[=](){ + if(!labels.contains(resultList->currentItem()->text())) + { + doOpenAccountPopupWidget(accountPopup,resultList->currentItem()->text()); + } + }); + dockVbox->addWidget(searchBar); dockVbox->addWidget(loadingLabel); dockVbox->addWidget(chattersList); @@ -442,6 +465,14 @@ void ChatWidget::doOpenViewerList() viewerDock->show(); } +void ChatWidget::doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user) +{ + widget->setName(user); + widget->move(QCursor::pos()); + widget->show(); + widget->setFocus(); +} + void ChatWidget::doCopy() { QApplication::clipboard()->setText(this->view.getSelectedText()); diff --git a/src/widgets/chatwidget.hpp b/src/widgets/chatwidget.hpp index 56a4cf20e..b2dd7cfc4 100644 --- a/src/widgets/chatwidget.hpp +++ b/src/widgets/chatwidget.hpp @@ -68,6 +68,7 @@ public: private: void setChannel(std::shared_ptr newChannel); void detachChannel(); + void doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user); void channelNameUpdated(const std::string &newChannelName); diff --git a/src/widgets/chatwidgetheader.cpp b/src/widgets/chatwidgetheader.cpp index 6eb99b048..2f0ae8d91 100644 --- a/src/widgets/chatwidgetheader.cpp +++ b/src/widgets/chatwidgetheader.cpp @@ -155,7 +155,7 @@ void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event) void ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { - this->chatWidget->showChangeChannelPopup("Change channel"); + this->chatWidget->doChangeChannel(); } }