fix: QuickSwitcherPopup now pops up in the selected window (#4819)

This commit is contained in:
pajlada 2023-09-17 23:52:17 +02:00 committed by GitHub
parent 3265df7661
commit e6df652a4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 27 deletions

View file

@ -11,6 +11,7 @@
- Bugfix: Fixed Usercard popup not floating on tiling WMs on Linux when "Automatically close user popup when it loses focus" setting is enabled. (#3511) - Bugfix: Fixed Usercard popup not floating on tiling WMs on Linux when "Automatically close user popup when it loses focus" setting is enabled. (#3511)
- Bugfix: Fixed selection of tabs after closing a tab when using "Live Tabs Only". (#4770) - Bugfix: Fixed selection of tabs after closing a tab when using "Live Tabs Only". (#4770)
- Bugfix: Fixed input in reply thread popup losing focus when dragging. (#4815) - Bugfix: Fixed input in reply thread popup losing focus when dragging. (#4815)
- Bugfix: Fixed the Quick Switcher (CTRL+K) from sometimes showing up on the wrong window. (#4819)
- Bugfix: Fixed too much text being copied when copying chat messages. (#4812) - Bugfix: Fixed too much text being copied when copying chat messages. (#4812)
- Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791) - Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791)
- Dev: Temporarily disable High DPI scaling on Qt6 builds on Windows. (#4767) - Dev: Temporarily disable High DPI scaling on Qt6 builds on Windows. (#4767)

View file

@ -492,9 +492,8 @@ void Window::addShortcuts()
return ""; return "";
}}, }},
{"openQuickSwitcher", {"openQuickSwitcher",
[](std::vector<QString>) -> QString { [this](std::vector<QString>) -> QString {
auto quickSwitcher = auto *quickSwitcher = new QuickSwitcherPopup(this);
new QuickSwitcherPopup(&getApp()->windows->getMainWindow());
quickSwitcher->show(); quickSwitcher->show();
return ""; return "";
}}, }},

View file

@ -12,16 +12,17 @@
namespace chatterino { namespace chatterino {
NewTabItem::NewTabItem(const QString &channelName) NewTabItem::NewTabItem(Window *window_, const QString &channelName)
: AbstractSwitcherItem(QIcon(":/switcher/plus.svg")) : AbstractSwitcherItem(QIcon(":/switcher/plus.svg"))
, channelName_(channelName) , channelName_(channelName)
, text_(QString(TEXT_FORMAT).arg(channelName)) , text_(QString(TEXT_FORMAT).arg(channelName))
, window(window_)
{ {
} }
void NewTabItem::action() void NewTabItem::action()
{ {
auto &nb = getApp()->windows->getMainWindow().getNotebook(); auto &nb = this->window->getNotebook();
SplitContainer *container = nb.addPage(true); SplitContainer *container = nb.addPage(true);
Split *split = new Split(container); Split *split = new Split(container);

View file

@ -4,6 +4,8 @@
namespace chatterino { namespace chatterino {
class Window;
class NewTabItem : public AbstractSwitcherItem class NewTabItem : public AbstractSwitcherItem
{ {
public: public:
@ -13,7 +15,7 @@ public:
* *
* @param channelName name of channel to open * @param channelName name of channel to open
*/ */
NewTabItem(const QString &channelName); NewTabItem(Window *window_, const QString &channelName);
/** /**
* @brief Open the channel passed in the constructor in a new tab. * @brief Open the channel passed in the constructor in a new tab.
@ -27,6 +29,7 @@ private:
static constexpr const char *TEXT_FORMAT = "Open channel \"%1\" in new tab"; static constexpr const char *TEXT_FORMAT = "Open channel \"%1\" in new tab";
QString channelName_; QString channelName_;
QString text_; QString text_;
Window *window{};
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -15,30 +15,33 @@
#include "widgets/splits/SplitContainer.hpp" #include "widgets/splits/SplitContainer.hpp"
#include "widgets/Window.hpp" #include "widgets/Window.hpp"
namespace chatterino {
namespace { namespace {
QList<SplitContainer *> openPages()
using namespace chatterino;
QList<SplitContainer *> openPages(Window *window)
{
QList<SplitContainer *> pages;
auto &nb = window->getNotebook();
for (int i = 0; i < nb.getPageCount(); ++i)
{ {
QList<SplitContainer *> pages; pages.append(static_cast<SplitContainer *>(nb.getPageAt(i)));
auto &nb = getApp()->windows->getMainWindow().getNotebook();
for (int i = 0; i < nb.getPageCount(); ++i)
{
pages.append(static_cast<SplitContainer *>(nb.getPageAt(i)));
}
return pages;
} }
return pages;
}
} // namespace } // namespace
const QSize QuickSwitcherPopup::MINIMUM_SIZE(500, 300); namespace chatterino {
QuickSwitcherPopup::QuickSwitcherPopup(QWidget *parent) QuickSwitcherPopup::QuickSwitcherPopup(Window *parent)
: BasePopup({BaseWindow::Flags::Frameless, BaseWindow::Flags::TopMost, : BasePopup({BaseWindow::Flags::Frameless, BaseWindow::Flags::TopMost,
BaseWindow::DisableLayoutSave}, BaseWindow::DisableLayoutSave},
parent) parent)
, switcherModel_(this) , switcherModel_(this)
, window(parent)
{ {
this->setWindowFlag(Qt::Dialog); this->setWindowFlag(Qt::Dialog);
this->setActionOnFocusLoss(BaseWindow::ActionOnFocusLoss::Delete); this->setActionOnFocusLoss(BaseWindow::ActionOnFocusLoss::Delete);
@ -86,7 +89,7 @@ void QuickSwitcherPopup::updateSuggestions(const QString &text)
this->switcherModel_.clear(); this->switcherModel_.clear();
// Add items for navigating to different splits // Add items for navigating to different splits
for (auto *sc : openPages()) for (auto *sc : openPages(this->window))
{ {
const QString &tabTitle = sc->getTab()->getTitle(); const QString &tabTitle = sc->getTab()->getTitle();
const auto splits = sc->getSplits(); const auto splits = sc->getSplits();
@ -119,7 +122,7 @@ void QuickSwitcherPopup::updateSuggestions(const QString &text)
// Add item for opening a channel in a new tab or new popup // Add item for opening a channel in a new tab or new popup
if (!text.isEmpty()) if (!text.isEmpty())
{ {
auto newTabItem = std::make_unique<NewTabItem>(text); auto newTabItem = std::make_unique<NewTabItem>(this->window, text);
this->switcherModel_.addItem(std::move(newTabItem)); this->switcherModel_.addItem(std::move(newTabItem));
auto newPopupItem = std::make_unique<NewPopupItem>(text); auto newPopupItem = std::make_unique<NewPopupItem>(text);

View file

@ -10,6 +10,7 @@
namespace chatterino { namespace chatterino {
class GenericListView; class GenericListView;
class Window;
class QuickSwitcherPopup : public BasePopup class QuickSwitcherPopup : public BasePopup
{ {
@ -17,19 +18,19 @@ public:
/** /**
* @brief Construct a new QuickSwitcherPopup. * @brief Construct a new QuickSwitcherPopup.
* *
* @param parent Parent widget of the popup. The popup will be placed * @param parent Parent window of the popup. The popup will be placed
* in the center of the parent widget. * in the center of the window.
*/ */
explicit QuickSwitcherPopup(QWidget *parent = nullptr); explicit QuickSwitcherPopup(Window *parent);
protected: protected:
virtual void themeChangedEvent() override; void themeChangedEvent() override;
public slots: public slots:
void updateSuggestions(const QString &text); void updateSuggestions(const QString &text);
private: private:
static const QSize MINIMUM_SIZE; constexpr static const QSize MINIMUM_SIZE{500, 300};
struct { struct {
QLineEdit *searchEdit{}; QLineEdit *searchEdit{};
@ -38,6 +39,8 @@ private:
QuickSwitcherModel switcherModel_; QuickSwitcherModel switcherModel_;
Window *window{};
void initWidgets(); void initWidgets();
}; };