2017-06-07 10:09:24 +02:00
|
|
|
#pragma once
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2018-06-04 15:36:48 +02:00
|
|
|
#include "pajlada/signals/signal.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/BaseWidget.hpp"
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QList>
|
2018-01-10 01:59:55 +01:00
|
|
|
#include <QMessageBox>
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QWidget>
|
2018-07-05 12:52:36 +02:00
|
|
|
#include <pajlada/signals/signalholder.hpp>
|
2017-01-18 04:52:47 +01:00
|
|
|
|
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
|
|
|
|
2020-08-13 15:43:08 +02:00
|
|
|
enum NotebookTabDirection { Horizontal = 0, Vertical = 1 };
|
|
|
|
|
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-08-06 21:17:03 +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();
|
|
|
|
|
|
|
|
int indexOf(QWidget *page) const;
|
2018-10-20 13:25:24 +02:00
|
|
|
virtual void select(QWidget *page);
|
2018-04-18 09:12:29 +02:00
|
|
|
void selectIndex(int index);
|
|
|
|
void selectNextTab();
|
|
|
|
void selectPreviousTab();
|
2019-08-04 16:22:48 +02:00
|
|
|
void selectLastTab();
|
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);
|
|
|
|
|
|
|
|
bool getShowAddButton() const;
|
|
|
|
void setShowAddButton(bool value);
|
|
|
|
|
2018-06-01 14:46:41 +02:00
|
|
|
void performLayout(bool animate = false);
|
2018-05-23 04:22:17 +02:00
|
|
|
|
2020-08-13 15:43:08 +02:00
|
|
|
void setTabDirection(NotebookTabDirection direction);
|
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
protected:
|
2018-07-06 17:11:37 +02:00
|
|
|
virtual void scaleChangedEvent(float scale_) override;
|
2018-04-18 09:12:29 +02:00
|
|
|
virtual void resizeEvent(QResizeEvent *) override;
|
|
|
|
virtual void paintEvent(QPaintEvent *) override;
|
|
|
|
|
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
|
|
|
private:
|
|
|
|
struct Item {
|
2018-09-04 21:39:54 +02:00
|
|
|
NotebookTab *tab{};
|
|
|
|
QWidget *page{};
|
|
|
|
QWidget *selectedWidget{};
|
2018-04-18 09:12:29 +02:00
|
|
|
};
|
|
|
|
|
2018-05-31 16:02:20 +02:00
|
|
|
bool containsPage(QWidget *page);
|
|
|
|
Item &findItem(QWidget *page);
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
QList<Item> items_;
|
|
|
|
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;
|
|
|
|
bool showAddButton_ = false;
|
2020-08-13 15:43:08 +02:00
|
|
|
int lineOffset_ = 20;
|
|
|
|
NotebookTabDirection tabDirection_ = NotebookTabDirection::Horizontal;
|
2018-04-18 09:12:29 +02:00
|
|
|
};
|
|
|
|
|
2018-06-04 15:36:48 +02:00
|
|
|
class SplitNotebook : public Notebook, pajlada::Signals::SignalHolder
|
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();
|
2018-10-20 13:25:24 +02:00
|
|
|
void select(QWidget *page) override;
|
2018-06-04 15:36:48 +02:00
|
|
|
|
|
|
|
private:
|
2018-07-05 12:52:36 +02:00
|
|
|
void addCustomButtons();
|
|
|
|
|
|
|
|
pajlada::Signals::SignalHolder signalHolder_;
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
std::vector<pajlada::Signals::ScopedConnection> connections_;
|
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
|