diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a096ad4..ff37c9a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Minor: Added ability to execute commands on chat messages using the message context menu. (#3738, #3765) - Minor: Added `/copy` command. Usage: `/copy `. Copies provided text to clipboard - can be useful with custom commands. (#3763) - Minor: Removed total views from the usercard, as Twitch no longer updates the number. (#3792) +- Minor: Add Quick Switcher item to open a channel in a new popup window. (#3828) - Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716) - Bugfix: Fix crash that can occur when changing channels. (#3799) - Bugfix: Fixed viewers list search not working when used before loading finishes. (#3774) diff --git a/chatterino.pro b/chatterino.pro index 0d14dbc5..8c09d234 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -289,6 +289,7 @@ SOURCES += \ src/widgets/dialogs/SelectChannelDialog.cpp \ src/widgets/dialogs/SelectChannelFiltersDialog.cpp \ src/widgets/dialogs/SettingsDialog.cpp \ + src/widgets/dialogs/switcher/NewPopupItem.cpp \ src/widgets/dialogs/switcher/NewTabItem.cpp \ src/widgets/dialogs/switcher/QuickSwitcherModel.cpp \ src/widgets/dialogs/switcher/QuickSwitcherPopup.cpp \ @@ -570,6 +571,7 @@ HEADERS += \ src/widgets/dialogs/SelectChannelFiltersDialog.hpp \ src/widgets/dialogs/SettingsDialog.hpp \ src/widgets/dialogs/switcher/AbstractSwitcherItem.hpp \ + src/widgets/dialogs/switcher/NewPopupItem.hpp \ src/widgets/dialogs/switcher/NewTabItem.hpp \ src/widgets/dialogs/switcher/QuickSwitcherModel.hpp \ src/widgets/dialogs/switcher/QuickSwitcherPopup.hpp \ diff --git a/resources/resources_autogenerated.qrc b/resources/resources_autogenerated.qrc index 550bf343..143b93a7 100644 --- a/resources/resources_autogenerated.qrc +++ b/resources/resources_autogenerated.qrc @@ -99,6 +99,7 @@ split/up.png streamerMode.png switcher/plus.svg + switcher/popup.svg switcher/switch.svg tlds.txt twitch/admin.png diff --git a/resources/switcher/popup.svg b/resources/switcher/popup.svg new file mode 100644 index 00000000..f382de01 --- /dev/null +++ b/resources/switcher/popup.svg @@ -0,0 +1,70 @@ + +image/svg+xml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 44e41c2d..d622372e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -395,6 +395,8 @@ set(SOURCE_FILES widgets/dialogs/UserInfoPopup.hpp widgets/dialogs/WelcomeDialog.cpp widgets/dialogs/WelcomeDialog.hpp + widgets/dialogs/switcher/NewPopupItem.cpp + widgets/dialogs/switcher/NewPopupItem.hpp widgets/dialogs/switcher/NewTabItem.cpp widgets/dialogs/switcher/NewTabItem.hpp widgets/dialogs/switcher/QuickSwitcherModel.cpp diff --git a/src/widgets/dialogs/switcher/NewPopupItem.cpp b/src/widgets/dialogs/switcher/NewPopupItem.cpp new file mode 100644 index 00000000..cadcd2a8 --- /dev/null +++ b/src/widgets/dialogs/switcher/NewPopupItem.cpp @@ -0,0 +1,57 @@ +#include "widgets/dialogs/switcher/NewPopupItem.hpp" + +#include "Application.hpp" +#include "providers/twitch/TwitchIrcServer.hpp" +#include "singletons/Fonts.hpp" +#include "singletons/Theme.hpp" +#include "singletons/WindowManager.hpp" +#include "widgets/Notebook.hpp" +#include "widgets/Window.hpp" +#include "widgets/helper/NotebookTab.hpp" +#include "widgets/splits/Split.hpp" + +namespace chatterino { + +NewPopupItem::NewPopupItem(const QString &channelName) + : AbstractSwitcherItem(QIcon(":/switcher/popup.svg")) + , channelName_(channelName) + , text_(QString(TEXT_FORMAT).arg(channelName)) +{ +} + +void NewPopupItem::action() +{ + auto *app = getApp(); + auto &popup = app->windows->createWindow(WindowType::Popup, true); + auto *split = + popup.getNotebook().getOrAddSelectedPage()->appendNewSplit(false); + split->setChannel(app->twitch->getOrAddChannel(this->channelName_)); +} + +void NewPopupItem::paint(QPainter *painter, const QRect &rect) const +{ + painter->save(); + + painter->setRenderHint(QPainter::Antialiasing, true); + + painter->setPen(getApp()->themes->splits.header.text); + painter->setBrush(Qt::SolidPattern); + painter->setFont(getApp()->fonts->getFont(FontStyle::UiMediumBold, 1.0)); + + QRect iconRect(rect.topLeft(), ICON_SIZE); + this->icon_.paint(painter, iconRect, Qt::AlignLeft | Qt::AlignVCenter); + + QRect textRect = + QRect(iconRect.topRight(), + QSize(rect.width() - iconRect.width(), iconRect.height())); + painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, this->text_); + + painter->restore(); +} + +QSize NewPopupItem::sizeHint(const QRect &rect) const +{ + return QSize(rect.width(), ICON_SIZE.height()); +} + +} // namespace chatterino diff --git a/src/widgets/dialogs/switcher/NewPopupItem.hpp b/src/widgets/dialogs/switcher/NewPopupItem.hpp new file mode 100644 index 00000000..cc1ad8ce --- /dev/null +++ b/src/widgets/dialogs/switcher/NewPopupItem.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "widgets/dialogs/switcher/AbstractSwitcherItem.hpp" + +namespace chatterino { + +class NewPopupItem : public AbstractSwitcherItem +{ +public: + /** + * @brief Construct a new NewPopupItem that opens a passed channel in a new + * popup. + * + * @param channelName name of channel to open + */ + NewPopupItem(const QString &channelName); + + /** + * @brief Open the channel passed in the constructor in a new popup. + */ + virtual void action() override; + + virtual void paint(QPainter *painter, const QRect &rect) const override; + virtual QSize sizeHint(const QRect &rect) const override; + +private: + static constexpr const char *TEXT_FORMAT = + "Open channel \"%1\" in new popup"; + QString channelName_; + QString text_; +}; + +} // namespace chatterino diff --git a/src/widgets/dialogs/switcher/QuickSwitcherPopup.cpp b/src/widgets/dialogs/switcher/QuickSwitcherPopup.cpp index 4d7d56bd..5447bd1d 100644 --- a/src/widgets/dialogs/switcher/QuickSwitcherPopup.cpp +++ b/src/widgets/dialogs/switcher/QuickSwitcherPopup.cpp @@ -6,6 +6,7 @@ #include "util/LayoutCreator.hpp" #include "widgets/Notebook.hpp" #include "widgets/Window.hpp" +#include "widgets/dialogs/switcher/NewPopupItem.hpp" #include "widgets/dialogs/switcher/NewTabItem.hpp" #include "widgets/dialogs/switcher/SwitchSplitItem.hpp" #include "widgets/helper/NotebookTab.hpp" @@ -113,11 +114,14 @@ void QuickSwitcherPopup::updateSuggestions(const QString &text) nextPage:; } - // Add item for opening a channel in a new tab + // Add item for opening a channel in a new tab or new popup if (!text.isEmpty()) { - auto item = std::make_unique(text); - this->switcherModel_.addItem(std::move(item)); + auto newTabItem = std::make_unique(text); + this->switcherModel_.addItem(std::move(newTabItem)); + + auto newPopupItem = std::make_unique(text); + this->switcherModel_.addItem(std::move(newPopupItem)); } const auto &startIdx = this->switcherModel_.index(0);