2017-06-07 10:09:24 +02:00
|
|
|
#pragma once
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/BaseWidget.hpp"
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2022-12-31 15:41:01 +01:00
|
|
|
#include <pajlada/signals/signal.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 <pajlada/signals/signalholder.hpp>
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QList>
|
2021-05-30 13:39:34 +02:00
|
|
|
#include <QMenu>
|
2018-01-10 01:59:55 +01:00
|
|
|
#include <QMessageBox>
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QWidget>
|
|
|
|
|
2023-06-11 11:34:28 +02:00
|
|
|
#include <functional>
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
class Window;
|
2018-08-11 22:23:06 +02:00
|
|
|
class UpdateDialog;
|
|
|
|
class NotebookButton;
|
|
|
|
class NotebookTab;
|
|
|
|
class SplitContainer;
|
2017-07-23 14:16:13 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
enum NotebookTabLocation { Top = 0, Left = 1, Right = 2, Bottom = 3 };
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2023-06-11 11:34:28 +02:00
|
|
|
// Controls the visibility of tabs in this notebook
|
|
|
|
enum NotebookTabVisibility : int {
|
|
|
|
// Show all tabs
|
|
|
|
AllTabs = 0,
|
|
|
|
|
|
|
|
// Only show tabs containing splits that are live
|
|
|
|
LiveOnly = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
using TabVisibilityFilter = std::function<bool(const NotebookTab *)>;
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
class Notebook : public BaseWidget
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-05-23 11:59:37 +02:00
|
|
|
explicit Notebook(QWidget *parent);
|
2018-08-11 22:23:06 +02:00
|
|
|
~Notebook() override = default;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
NotebookTab *addPage(QWidget *page, QString title = QString(),
|
|
|
|
bool select = false);
|
2018-04-18 09:12:29 +02:00
|
|
|
void removePage(QWidget *page);
|
|
|
|
void removeCurrentPage();
|
|
|
|
|
2023-09-10 12:38:59 +02:00
|
|
|
/**
|
|
|
|
* @brief Returns index of page in Notebook, or -1 if not found.
|
|
|
|
**/
|
2018-04-18 09:12:29 +02:00
|
|
|
int indexOf(QWidget *page) const;
|
2023-09-10 12:38:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the visible index of page in Notebook, or -1 if not found.
|
|
|
|
* Given page should be visible according to the set TabVisibilityFilter.
|
|
|
|
**/
|
|
|
|
int visibleIndexOf(QWidget *page) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the number of visible tabs in Notebook.
|
|
|
|
**/
|
|
|
|
int getVisibleTabCount() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Selects the Notebook tab containing the given page.
|
|
|
|
**/
|
2022-01-02 15:00:19 +01:00
|
|
|
virtual void select(QWidget *page, bool focusPage = true);
|
2023-09-10 12:38:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Selects the Notebook tab at the given index. Ignores whether tabs
|
|
|
|
* are visible or not.
|
|
|
|
**/
|
2022-01-02 15:00:19 +01:00
|
|
|
void selectIndex(int index, bool focusPage = true);
|
2023-09-10 12:38:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Selects the index'th visible tab in the Notebook.
|
|
|
|
*
|
|
|
|
* For example, selecting the 0th visible tab selects the first tab in this
|
|
|
|
* Notebook that is visible according to the TabVisibilityFilter. If no filter
|
|
|
|
* is set, equivalent to Notebook::selectIndex.
|
|
|
|
**/
|
2023-06-11 11:34:28 +02:00
|
|
|
void selectVisibleIndex(int index, bool focusPage = true);
|
2023-09-10 12:38:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Selects the next visible tab. Wraps to the start if required.
|
|
|
|
**/
|
2022-01-02 15:00:19 +01:00
|
|
|
void selectNextTab(bool focusPage = true);
|
2023-09-10 12:38:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Selects the previous visible tab. Wraps to the end if required.
|
|
|
|
**/
|
2022-01-02 15:00:19 +01:00
|
|
|
void selectPreviousTab(bool focusPage = true);
|
2023-09-10 12:38:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Selects the last visible tab.
|
|
|
|
**/
|
2022-01-02 15:00:19 +01:00
|
|
|
void selectLastTab(bool focusPage = true);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
int getPageCount() const;
|
2018-05-23 04:22:17 +02:00
|
|
|
QWidget *getPageAt(int index) const;
|
2018-04-18 09:12:29 +02:00
|
|
|
int getSelectedIndex() const;
|
|
|
|
QWidget *getSelectedPage() const;
|
|
|
|
|
|
|
|
QWidget *tabAt(QPoint point, int &index, int maxWidth = 2000000000);
|
|
|
|
void rearrangePage(QWidget *page, int index);
|
|
|
|
|
|
|
|
bool getAllowUserTabManagement() const;
|
|
|
|
void setAllowUserTabManagement(bool value);
|
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
bool getShowTabs() const;
|
|
|
|
void setShowTabs(bool value);
|
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
bool getShowAddButton() const;
|
|
|
|
void setShowAddButton(bool value);
|
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
void setTabLocation(NotebookTabLocation location);
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2022-03-26 14:16:45 +01:00
|
|
|
bool isNotebookLayoutLocked() const;
|
|
|
|
void setLockNotebookLayout(bool value);
|
|
|
|
|
|
|
|
void addNotebookActionsToMenu(QMenu *menu);
|
|
|
|
|
2023-06-11 11:34:28 +02:00
|
|
|
// Update layout and tab visibility
|
|
|
|
void refresh();
|
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
protected:
|
2023-10-25 18:13:48 +02:00
|
|
|
void scaleChangedEvent(float scale_) override;
|
|
|
|
void resizeEvent(QResizeEvent *) override;
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void paintEvent(QPaintEvent *) override;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
NotebookButton *getAddButton();
|
2018-05-23 12:24:18 +02:00
|
|
|
NotebookButton *addCustomButton();
|
2018-05-23 04:22:17 +02:00
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
struct Item {
|
2018-09-04 21:39:54 +02:00
|
|
|
NotebookTab *tab{};
|
|
|
|
QWidget *page{};
|
|
|
|
QWidget *selectedWidget{};
|
2018-04-18 09:12:29 +02:00
|
|
|
};
|
|
|
|
|
2021-04-17 16:15:23 +02:00
|
|
|
const QList<Item> items()
|
|
|
|
{
|
|
|
|
return items_;
|
|
|
|
}
|
|
|
|
|
2023-06-11 11:34:28 +02:00
|
|
|
/**
|
|
|
|
* @brief Apply the given tab visibility filter
|
|
|
|
*
|
|
|
|
* An empty function can be provided to denote that no filter will be applied
|
|
|
|
*
|
|
|
|
* Tabs will be redrawn after this function is called.
|
|
|
|
**/
|
|
|
|
void setTabVisibilityFilter(TabVisibilityFilter filter);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief shouldShowTab has the final say whether a tab should be visible right now.
|
|
|
|
**/
|
|
|
|
bool shouldShowTab(const NotebookTab *tab) const;
|
|
|
|
|
2021-04-17 16:15:23 +02:00
|
|
|
private:
|
2023-06-11 11:34:28 +02:00
|
|
|
void performLayout(bool animate = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Show a popup informing the user of some big tab visibility changes
|
|
|
|
**/
|
|
|
|
void showTabVisibilityInfoPopup();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Updates the visibility state of all tabs
|
|
|
|
**/
|
|
|
|
void updateTabVisibility();
|
2022-10-09 17:20:44 +02:00
|
|
|
void updateTabVisibilityMenuAction();
|
2022-07-23 16:09:12 +02:00
|
|
|
void resizeAddButton();
|
|
|
|
|
2018-05-31 16:02:20 +02:00
|
|
|
bool containsPage(QWidget *page);
|
2022-11-25 10:34:01 +01:00
|
|
|
Item *findItem(QWidget *page);
|
2018-05-31 16:02:20 +02:00
|
|
|
|
|
|
|
static bool containsChild(const QObject *obj, const QObject *child);
|
2018-07-06 19:23:47 +02:00
|
|
|
NotebookTab *getTabFromPage(QWidget *page);
|
2018-05-31 16:02:20 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
// Returns the number of buttons in `customButtons_` that are visible
|
|
|
|
size_t visibleButtonCount() const;
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
QList<Item> items_;
|
2021-05-30 13:39:34 +02:00
|
|
|
QMenu menu_;
|
2018-07-06 19:23:47 +02:00
|
|
|
QWidget *selectedPage_ = nullptr;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
NotebookButton *addButton_;
|
2018-07-06 19:23:47 +02:00
|
|
|
std::vector<NotebookButton *> customButtons_;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
bool allowUserTabManagement_ = false;
|
2021-05-30 13:39:34 +02:00
|
|
|
bool showTabs_ = true;
|
2018-07-06 19:23:47 +02:00
|
|
|
bool showAddButton_ = false;
|
2020-08-13 15:43:08 +02:00
|
|
|
int lineOffset_ = 20;
|
2022-03-26 14:16:45 +01:00
|
|
|
bool lockNotebookLayout_ = false;
|
2022-07-23 16:09:12 +02:00
|
|
|
NotebookTabLocation tabLocation_ = NotebookTabLocation::Top;
|
2022-03-26 14:16:45 +01:00
|
|
|
QAction *lockNotebookLayoutAction_;
|
2022-10-09 17:20:44 +02:00
|
|
|
QAction *showTabsAction_;
|
2023-06-11 11:34:28 +02:00
|
|
|
|
|
|
|
// This filter, if set, is used to figure out the visibility of
|
|
|
|
// the tabs in this notebook.
|
|
|
|
TabVisibilityFilter tabVisibilityFilter_;
|
2018-04-18 09:12:29 +02:00
|
|
|
};
|
|
|
|
|
2021-12-19 15:57:56 +01:00
|
|
|
class SplitNotebook : public Notebook
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-05-23 12:24:18 +02:00
|
|
|
SplitNotebook(Window *parent);
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
SplitContainer *addPage(bool select = false);
|
2018-04-10 15:59:53 +02:00
|
|
|
SplitContainer *getOrAddSelectedPage();
|
2023-10-01 08:40:34 +02:00
|
|
|
/// Returns `nullptr` when no page is selected.
|
|
|
|
SplitContainer *getSelectedPage();
|
2022-01-02 15:00:19 +01:00
|
|
|
void select(QWidget *page, bool focusPage = true) override;
|
2023-05-27 12:38:25 +02:00
|
|
|
void themeChangedEvent() override;
|
2018-06-04 15:36:48 +02:00
|
|
|
|
2020-09-26 01:52:39 +02:00
|
|
|
protected:
|
|
|
|
void showEvent(QShowEvent *event) override;
|
|
|
|
|
2018-06-04 15:36:48 +02:00
|
|
|
private:
|
2018-07-05 12:52:36 +02:00
|
|
|
void addCustomButtons();
|
|
|
|
|
|
|
|
pajlada::Signals::SignalHolder signalHolder_;
|
2023-05-27 12:38:25 +02:00
|
|
|
|
|
|
|
// Main window on Windows has basically a duplicate of this in Window
|
|
|
|
NotebookButton *streamerModeIcon_{};
|
|
|
|
|
|
|
|
void updateStreamerModeIcon();
|
2016-12-29 17:31:07 +01:00
|
|
|
};
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|