mirror-chatterino2/src/widgets/splitcontainer.hpp

104 lines
2.4 KiB
C++
Raw Normal View History

#pragma once
2016-12-29 17:31:07 +01:00
#include "widgets/basewidget.hpp"
2017-11-12 17:21:50 +01:00
#include "widgets/helper/droppreview.hpp"
#include "widgets/helper/notebooktab.hpp"
#include "widgets/split.hpp"
2016-12-30 12:20:26 +01:00
2017-01-18 04:52:47 +01:00
#include <QDragEnterEvent>
#include <QHBoxLayout>
#include <QRect>
#include <QVBoxLayout>
#include <QVector>
#include <QWidget>
2017-01-18 21:30:23 +01:00
namespace chatterino {
namespace widgets {
2017-11-12 17:21:50 +01:00
class SplitContainer : public BaseWidget
2016-12-29 17:31:07 +01:00
{
2017-01-11 18:52:09 +01:00
Q_OBJECT
2016-12-29 17:31:07 +01:00
public:
SplitContainer(Notebook *parent, NotebookTab *_tab);
2017-11-12 17:21:50 +01:00
std::pair<int, int> removeFromLayout(Split *widget);
void addToLayout(Split *widget, std::pair<int, int> position = std::pair<int, int>(-1, -1));
2017-01-01 02:30:42 +01:00
2018-01-23 22:48:33 +01:00
const std::vector<Split *> &getSplits() const;
std::vector<std::vector<Split *>> getColumns() const;
2017-04-12 17:46:44 +02:00
NotebookTab *getTab() const;
2018-04-07 12:53:10 +02:00
void addChat(bool openChannelNameDialog = false);
2017-05-29 21:26:55 +02:00
2017-01-01 02:30:42 +01:00
static bool isDraggingSplit;
2017-11-12 17:21:50 +01:00
static Split *draggingSplit;
2017-01-01 02:30:42 +01:00
static std::pair<int, int> dropPosition;
2016-12-30 18:00:25 +01:00
int currentX = 0;
int currentY = 0;
std::map<int, int> lastRequestedY;
void refreshCurrentFocusCoordinates(bool alsoSetLastRequested = false);
void requestFocus(int x, int y);
2017-11-12 17:21:50 +01:00
void updateFlexValues();
int splitCount() const;
2017-11-12 17:21:50 +01:00
2016-12-30 18:00:25 +01:00
protected:
2018-04-07 12:53:10 +02:00
bool eventFilter(QObject *object, QEvent *event) override;
void paintEvent(QPaintEvent *event) override;
2017-01-01 02:30:42 +01:00
2018-04-07 12:53:10 +02:00
void showEvent(QShowEvent *event) override;
2018-04-07 12:53:10 +02:00
void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
2018-04-07 12:53:10 +02:00
void dragEnterEvent(QDragEnterEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;
void dropEvent(QDropEvent *event) override;
2017-01-01 02:30:42 +01:00
2017-04-12 17:46:44 +02:00
private:
2017-01-11 18:52:09 +01:00
struct DropRegion {
2017-01-01 02:30:42 +01:00
QRect rect;
std::pair<int, int> position;
DropRegion(QRect rect, std::pair<int, int> position)
{
this->rect = rect;
this->position = position;
}
};
NotebookTab *tab;
struct {
QVBoxLayout parentLayout;
2017-01-01 02:30:42 +01:00
QHBoxLayout hbox;
} ui;
2017-04-12 17:46:44 +02:00
std::vector<Split *> splits;
std::vector<DropRegion> dropRegions;
NotebookPageDropPreview dropPreview;
2017-01-01 02:30:42 +01:00
void setPreviewRect(QPoint mousePos);
2017-11-12 17:21:50 +01:00
std::pair<int, int> getChatPosition(const Split *chatWidget);
2017-01-29 12:26:22 +01:00
2018-04-07 12:53:10 +02:00
Split *createChatWidget();
public:
void refreshTitle();
void loadSplits();
void save();
2016-12-29 17:31:07 +01:00
};
2017-04-14 17:52:22 +02:00
} // namespace widgets
} // namespace chatterino