mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
fixed loading issues of saved split layout
This commit is contained in:
parent
fecca83312
commit
835b6d80da
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
class SplitContainer::Node;
|
||||
struct SplitContainer::Node;
|
||||
}
|
||||
namespace singletons {
|
||||
|
||||
|
@ -46,8 +46,6 @@ private:
|
|||
widgets::Window *selectedWindow = nullptr;
|
||||
|
||||
void encodeNodeRecusively(widgets::SplitContainer::Node *node, QJsonObject &obj);
|
||||
void decodeNodeRecusively(widgets::SplitContainer *container,
|
||||
widgets::SplitContainer::Node *node, QJsonObject &obj, bool vertical);
|
||||
|
||||
public:
|
||||
static void encodeChannel(IndirectChannel channel, QJsonObject &obj);
|
||||
|
|
|
@ -131,6 +131,11 @@ void SplitContainer::insertSplit(Split *split, Direction direction, Node *relati
|
|||
relativeTo->insertSplitRelative(split, direction);
|
||||
}
|
||||
|
||||
this->addSplit(split);
|
||||
}
|
||||
|
||||
void SplitContainer::addSplit(Split *split)
|
||||
{
|
||||
split->setParent(this);
|
||||
split->show();
|
||||
split->giveFocus(Qt::MouseFocusReason);
|
||||
|
@ -223,7 +228,7 @@ void SplitContainer::layout()
|
|||
}
|
||||
|
||||
{
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
for (ResizeRect &resizeRect : _resizeRects) {
|
||||
ResizeHandle *handle = this->resizeHandles[i].get();
|
||||
handle->setGeometry(resizeRect.rect);
|
||||
|
@ -338,7 +343,7 @@ void SplitContainer::mouseMoveEvent(QMouseEvent *event)
|
|||
this->update();
|
||||
}
|
||||
|
||||
void SplitContainer::leaveEvent(QEvent *event)
|
||||
void SplitContainer::leaveEvent(QEvent *)
|
||||
{
|
||||
this->mouseOverPoint = QPoint(-10000, -10000);
|
||||
this->update();
|
||||
|
@ -410,12 +415,16 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node)
|
|||
split->setChannel(
|
||||
singletons::WindowManager::decodeChannel(_obj.value("data").toObject()));
|
||||
|
||||
this->insertSplit(split, direction, node);
|
||||
Node *_node = new Node();
|
||||
_node->parent = node;
|
||||
_node->split = split;
|
||||
_node->type = Node::_Split;
|
||||
|
||||
this->baseNode.findNodeContainingSplit(split)->flexH =
|
||||
_obj.value("flexh").toDouble(1.0);
|
||||
this->baseNode.findNodeContainingSplit(split)->flexV =
|
||||
_obj.value("flexv").toDouble(1.0);
|
||||
_node->flexH = _obj.value("flexh").toDouble(1.0);
|
||||
_node->flexV = _obj.value("flexv").toDouble(1.0);
|
||||
node->children.emplace_back(_node);
|
||||
|
||||
this->addSplit(split);
|
||||
} else {
|
||||
Node *_node = new Node();
|
||||
_node->parent = node;
|
||||
|
@ -571,7 +580,7 @@ void SplitContainer::Node::_insertNextToThis(Split *_split, Direction _direction
|
|||
qreal height = this->parent->geometry.height() / siblings.size();
|
||||
|
||||
if (siblings.size() == 1) {
|
||||
this->geometry = QRect(0, 0, width, height);
|
||||
this->geometry = QRect(0, 0, int(width), int(height));
|
||||
}
|
||||
|
||||
auto it = std::find_if(siblings.begin(), siblings.end(),
|
||||
|
@ -797,8 +806,8 @@ SplitContainer::Node::Type SplitContainer::Node::toContainerType(Direction _dir)
|
|||
|
||||
SplitContainer::DropOverlay::DropOverlay(SplitContainer *_parent)
|
||||
: QWidget(_parent)
|
||||
, parent(_parent)
|
||||
, mouseOverPoint(-10000, -10000)
|
||||
, parent(_parent)
|
||||
{
|
||||
this->setMouseTracking(true);
|
||||
this->setAcceptDrops(true);
|
||||
|
@ -811,7 +820,7 @@ void SplitContainer::DropOverlay::setRects(std::vector<SplitContainer::DropRect>
|
|||
|
||||
// pajlada::Signals::NoArgSignal dragEnded;
|
||||
|
||||
void SplitContainer::DropOverlay::paintEvent(QPaintEvent *event)
|
||||
void SplitContainer::DropOverlay::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
// fourtf: !!! preserve the order of left, up, right and down
|
||||
enum Direction { Left, Above, Right, Below };
|
||||
|
||||
struct Position {
|
||||
struct Position final {
|
||||
private:
|
||||
Position() = default;
|
||||
Position(Node *_relativeNode, Direction _direcion)
|
||||
|
@ -56,7 +56,7 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
struct DropRect {
|
||||
struct DropRect final {
|
||||
QRect rect;
|
||||
Position position;
|
||||
|
||||
|
@ -67,7 +67,7 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
struct ResizeRect {
|
||||
struct ResizeRect final {
|
||||
QRect rect;
|
||||
Node *node;
|
||||
bool vertical;
|
||||
|
@ -122,7 +122,7 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
class DropOverlay : public QWidget
|
||||
class DropOverlay final : public QWidget
|
||||
{
|
||||
public:
|
||||
DropOverlay(SplitContainer *_parent = nullptr);
|
||||
|
@ -133,10 +133,10 @@ private:
|
|||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dragMoveEvent(QDragMoveEvent *event);
|
||||
void dragLeaveEvent(QDragLeaveEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
|
||||
private:
|
||||
std::vector<DropRect> rects;
|
||||
|
@ -144,7 +144,7 @@ private:
|
|||
SplitContainer *parent;
|
||||
};
|
||||
|
||||
class ResizeHandle : public QWidget
|
||||
class ResizeHandle final : public QWidget
|
||||
{
|
||||
public:
|
||||
SplitContainer *parent;
|
||||
|
@ -223,6 +223,8 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
void addSplit(Split *split);
|
||||
|
||||
std::vector<DropRect> dropRects;
|
||||
std::vector<DropRegion> dropRegions;
|
||||
NotebookPageDropPreview dropPreview;
|
||||
|
|
Loading…
Reference in a new issue