2020-08-13 19:25:51 +02:00
|
|
|
#include "widgets/dialogs/switcher/QuickSwitcherPopup.hpp"
|
|
|
|
|
|
|
|
#include "Application.hpp"
|
2022-12-25 12:09:25 +01:00
|
|
|
#include "common/Channel.hpp"
|
2020-08-15 10:17:15 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2020-08-13 19:25:51 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
|
|
|
#include "util/LayoutCreator.hpp"
|
2022-06-25 13:00:32 +02:00
|
|
|
#include "widgets/dialogs/switcher/NewPopupItem.hpp"
|
2020-08-13 19:25:51 +02:00
|
|
|
#include "widgets/dialogs/switcher/NewTabItem.hpp"
|
|
|
|
#include "widgets/dialogs/switcher/SwitchSplitItem.hpp"
|
|
|
|
#include "widgets/helper/NotebookTab.hpp"
|
2020-08-15 18:59:17 +02:00
|
|
|
#include "widgets/listview/GenericListView.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "widgets/Notebook.hpp"
|
2022-12-25 12:09:25 +01:00
|
|
|
#include "widgets/splits/Split.hpp"
|
|
|
|
#include "widgets/splits/SplitContainer.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "widgets/Window.hpp"
|
2020-08-13 19:25:51 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2023-09-17 23:52:17 +02:00
|
|
|
using namespace chatterino;
|
|
|
|
|
|
|
|
QList<SplitContainer *> openPages(Window *window)
|
|
|
|
{
|
|
|
|
QList<SplitContainer *> pages;
|
2020-08-13 19:25:51 +02:00
|
|
|
|
2023-09-17 23:52:17 +02:00
|
|
|
auto &nb = window->getNotebook();
|
|
|
|
for (int i = 0; i < nb.getPageCount(); ++i)
|
|
|
|
{
|
|
|
|
pages.append(static_cast<SplitContainer *>(nb.getPageAt(i)));
|
2020-08-13 19:25:51 +02:00
|
|
|
}
|
2023-09-17 23:52:17 +02:00
|
|
|
|
|
|
|
return pages;
|
|
|
|
}
|
|
|
|
|
2020-08-13 19:25:51 +02:00
|
|
|
} // namespace
|
|
|
|
|
2023-09-17 23:52:17 +02:00
|
|
|
namespace chatterino {
|
2020-08-13 19:25:51 +02:00
|
|
|
|
2023-09-17 23:52:17 +02:00
|
|
|
QuickSwitcherPopup::QuickSwitcherPopup(Window *parent)
|
2023-12-02 12:56:03 +01:00
|
|
|
: BasePopup(
|
|
|
|
{
|
|
|
|
BaseWindow::Flags::Frameless,
|
|
|
|
BaseWindow::Flags::TopMost,
|
|
|
|
BaseWindow::DisableLayoutSave,
|
|
|
|
BaseWindow::BoundsCheckOnShow,
|
|
|
|
},
|
|
|
|
parent)
|
2020-08-13 19:25:51 +02:00
|
|
|
, switcherModel_(this)
|
2023-09-17 23:52:17 +02:00
|
|
|
, window(parent)
|
2020-08-13 19:25:51 +02:00
|
|
|
{
|
|
|
|
this->setWindowFlag(Qt::Dialog);
|
|
|
|
this->setActionOnFocusLoss(BaseWindow::ActionOnFocusLoss::Delete);
|
|
|
|
this->setMinimumSize(QuickSwitcherPopup::MINIMUM_SIZE);
|
|
|
|
|
|
|
|
this->initWidgets();
|
|
|
|
|
|
|
|
const QRect geom = parent->geometry();
|
|
|
|
// This places the popup in the middle of the parent widget
|
|
|
|
this->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter,
|
|
|
|
this->size(), geom));
|
2020-08-15 10:17:15 +02:00
|
|
|
|
|
|
|
this->themeChangedEvent();
|
2020-08-13 19:25:51 +02:00
|
|
|
|
2020-08-15 18:59:17 +02:00
|
|
|
this->installEventFilter(this->ui_.list);
|
2020-08-13 19:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QuickSwitcherPopup::initWidgets()
|
|
|
|
{
|
|
|
|
LayoutCreator<QWidget> creator(this->BaseWindow::getLayoutContainer());
|
|
|
|
auto vbox = creator.setLayoutType<QVBoxLayout>();
|
|
|
|
|
|
|
|
{
|
2020-08-13 20:20:24 +02:00
|
|
|
auto lineEdit = vbox.emplace<QLineEdit>().assign(&this->ui_.searchEdit);
|
|
|
|
lineEdit->setPlaceholderText("Jump to a channel or open a new one");
|
2020-08-13 19:25:51 +02:00
|
|
|
QObject::connect(this->ui_.searchEdit, &QLineEdit::textChanged, this,
|
|
|
|
&QuickSwitcherPopup::updateSuggestions);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-08-15 18:59:17 +02:00
|
|
|
auto listView = vbox.emplace<GenericListView>().assign(&this->ui_.list);
|
|
|
|
listView->setModel(&this->switcherModel_);
|
|
|
|
|
|
|
|
QObject::connect(listView.getElement(),
|
2020-11-08 12:02:19 +01:00
|
|
|
&GenericListView::closeRequested, this, [this] {
|
|
|
|
this->close();
|
|
|
|
});
|
2020-10-24 10:50:14 +02:00
|
|
|
|
|
|
|
this->ui_.searchEdit->installEventFilter(listView.getElement());
|
2020-08-13 19:25:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QuickSwitcherPopup::updateSuggestions(const QString &text)
|
|
|
|
{
|
|
|
|
this->switcherModel_.clear();
|
|
|
|
|
|
|
|
// Add items for navigating to different splits
|
2023-09-17 23:52:17 +02:00
|
|
|
for (auto *sc : openPages(this->window))
|
2020-08-13 19:25:51 +02:00
|
|
|
{
|
|
|
|
const QString &tabTitle = sc->getTab()->getTitle();
|
|
|
|
const auto splits = sc->getSplits();
|
|
|
|
|
|
|
|
// First, check for splits on this page
|
|
|
|
for (auto *split : splits)
|
|
|
|
{
|
|
|
|
if (split->getChannel()->getName().contains(text,
|
|
|
|
Qt::CaseInsensitive))
|
|
|
|
{
|
2021-04-17 16:15:23 +02:00
|
|
|
auto item = std::make_unique<SwitchSplitItem>(sc, split);
|
2020-08-13 20:05:54 +02:00
|
|
|
this->switcherModel_.addItem(std::move(item));
|
2020-08-13 19:25:51 +02:00
|
|
|
|
|
|
|
// We want to continue the outer loop so we need a goto
|
|
|
|
goto nextPage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then check if tab title matches
|
|
|
|
if (tabTitle.contains(text, Qt::CaseInsensitive))
|
|
|
|
{
|
2020-08-13 20:05:54 +02:00
|
|
|
auto item = std::make_unique<SwitchSplitItem>(sc);
|
|
|
|
this->switcherModel_.addItem(std::move(item));
|
2020-08-13 19:25:51 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nextPage:;
|
|
|
|
}
|
|
|
|
|
2022-06-25 13:00:32 +02:00
|
|
|
// Add item for opening a channel in a new tab or new popup
|
2020-08-13 19:25:51 +02:00
|
|
|
if (!text.isEmpty())
|
|
|
|
{
|
2023-09-17 23:52:17 +02:00
|
|
|
auto newTabItem = std::make_unique<NewTabItem>(this->window, text);
|
2022-06-25 13:00:32 +02:00
|
|
|
this->switcherModel_.addItem(std::move(newTabItem));
|
|
|
|
|
|
|
|
auto newPopupItem = std::make_unique<NewPopupItem>(text);
|
|
|
|
this->switcherModel_.addItem(std::move(newPopupItem));
|
2020-08-13 19:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto &startIdx = this->switcherModel_.index(0);
|
|
|
|
this->ui_.list->setCurrentIndex(startIdx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timeout interval 0 means the call will be delayed until all window events
|
|
|
|
* have been processed (cf. https://doc.qt.io/qt-5/qtimer.html#interval-prop).
|
|
|
|
*/
|
2020-11-08 12:02:19 +01:00
|
|
|
QTimer::singleShot(0, [this] {
|
|
|
|
this->adjustSize();
|
|
|
|
});
|
2020-08-13 19:25:51 +02:00
|
|
|
}
|
|
|
|
|
2020-08-15 10:17:15 +02:00
|
|
|
void QuickSwitcherPopup::themeChangedEvent()
|
|
|
|
{
|
|
|
|
BasePopup::themeChangedEvent();
|
|
|
|
|
|
|
|
this->ui_.searchEdit->setStyleSheet(this->theme->splits.input.styleSheet);
|
2020-08-15 18:59:17 +02:00
|
|
|
this->ui_.list->refreshTheme(*this->theme);
|
2020-08-15 10:17:15 +02:00
|
|
|
}
|
|
|
|
|
2020-08-13 19:25:51 +02:00
|
|
|
} // namespace chatterino
|