feat: add Quick Switcher item to open channel in a new popup window (#3828)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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<NewTabItem>(text);
|
||||
this->switcherModel_.addItem(std::move(item));
|
||||
auto newTabItem = std::make_unique<NewTabItem>(text);
|
||||
this->switcherModel_.addItem(std::move(newTabItem));
|
||||
|
||||
auto newPopupItem = std::make_unique<NewPopupItem>(text);
|
||||
this->switcherModel_.addItem(std::move(newPopupItem));
|
||||
}
|
||||
|
||||
const auto &startIdx = this->switcherModel_.index(0);
|
||||
|
||||
Reference in New Issue
Block a user