mirror-chatterino2/src/widgets/splitcontainer.hpp

113 lines
2.7 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 {
class ChannelManager;
2017-01-18 21:30:23 +01:00
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
const std::string settingPrefix;
std::string settingRoot;
2016-12-29 17:31:07 +01:00
public:
SplitContainer(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab,
const std::string &_settingPrefix);
ChannelManager &channelManager;
2017-01-01 02:30:42 +01:00
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
2017-11-12 17:21:50 +01:00
const std::vector<Split *> &getChatWidgets() const;
2017-04-12 17:46:44 +02:00
NotebookTab *getTab() const;
void addChat(bool openChannelNameDialog = false, std::string chatUUID = std::string());
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();
2016-12-30 18:00:25 +01:00
protected:
virtual bool eventFilter(QObject *object, QEvent *event) override;
virtual void paintEvent(QPaintEvent *) override;
2017-01-01 02:30:42 +01:00
virtual void showEvent(QShowEvent *) override;
virtual void enterEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void dragEnterEvent(QDragEnterEvent *event) override;
virtual void dragMoveEvent(QDragMoveEvent *event) override;
virtual void dragLeaveEvent(QDragLeaveEvent *event) override;
virtual 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
2017-11-12 17:21:50 +01:00
std::vector<Split *> chatWidgets;
std::vector<DropRegion> dropRegions;
pajlada::Settings::Setting<std::vector<std::vector<std::string>>> chats;
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
Split *createChatWidget(const std::string &uuid);
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