fixed loading issues of saved split layout

This commit is contained in:
fourtf 2018-05-24 17:13:46 +02:00
parent fecca83312
commit 835b6d80da
3 changed files with 31 additions and 22 deletions

View file

@ -4,7 +4,7 @@
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
class SplitContainer::Node; struct SplitContainer::Node;
} }
namespace singletons { namespace singletons {
@ -46,8 +46,6 @@ private:
widgets::Window *selectedWindow = nullptr; widgets::Window *selectedWindow = nullptr;
void encodeNodeRecusively(widgets::SplitContainer::Node *node, QJsonObject &obj); void encodeNodeRecusively(widgets::SplitContainer::Node *node, QJsonObject &obj);
void decodeNodeRecusively(widgets::SplitContainer *container,
widgets::SplitContainer::Node *node, QJsonObject &obj, bool vertical);
public: public:
static void encodeChannel(IndirectChannel channel, QJsonObject &obj); static void encodeChannel(IndirectChannel channel, QJsonObject &obj);

View file

@ -131,6 +131,11 @@ void SplitContainer::insertSplit(Split *split, Direction direction, Node *relati
relativeTo->insertSplitRelative(split, direction); relativeTo->insertSplitRelative(split, direction);
} }
this->addSplit(split);
}
void SplitContainer::addSplit(Split *split)
{
split->setParent(this); split->setParent(this);
split->show(); split->show();
split->giveFocus(Qt::MouseFocusReason); split->giveFocus(Qt::MouseFocusReason);
@ -223,7 +228,7 @@ void SplitContainer::layout()
} }
{ {
int i = 0; size_t i = 0;
for (ResizeRect &resizeRect : _resizeRects) { for (ResizeRect &resizeRect : _resizeRects) {
ResizeHandle *handle = this->resizeHandles[i].get(); ResizeHandle *handle = this->resizeHandles[i].get();
handle->setGeometry(resizeRect.rect); handle->setGeometry(resizeRect.rect);
@ -338,7 +343,7 @@ void SplitContainer::mouseMoveEvent(QMouseEvent *event)
this->update(); this->update();
} }
void SplitContainer::leaveEvent(QEvent *event) void SplitContainer::leaveEvent(QEvent *)
{ {
this->mouseOverPoint = QPoint(-10000, -10000); this->mouseOverPoint = QPoint(-10000, -10000);
this->update(); this->update();
@ -410,12 +415,16 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node)
split->setChannel( split->setChannel(
singletons::WindowManager::decodeChannel(_obj.value("data").toObject())); 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 = _node->flexH = _obj.value("flexh").toDouble(1.0);
_obj.value("flexh").toDouble(1.0); _node->flexV = _obj.value("flexv").toDouble(1.0);
this->baseNode.findNodeContainingSplit(split)->flexV = node->children.emplace_back(_node);
_obj.value("flexv").toDouble(1.0);
this->addSplit(split);
} else { } else {
Node *_node = new Node(); Node *_node = new Node();
_node->parent = node; _node->parent = node;
@ -571,7 +580,7 @@ void SplitContainer::Node::_insertNextToThis(Split *_split, Direction _direction
qreal height = this->parent->geometry.height() / siblings.size(); qreal height = this->parent->geometry.height() / siblings.size();
if (siblings.size() == 1) { 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(), 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) SplitContainer::DropOverlay::DropOverlay(SplitContainer *_parent)
: QWidget(_parent) : QWidget(_parent)
, parent(_parent)
, mouseOverPoint(-10000, -10000) , mouseOverPoint(-10000, -10000)
, parent(_parent)
{ {
this->setMouseTracking(true); this->setMouseTracking(true);
this->setAcceptDrops(true); this->setAcceptDrops(true);
@ -811,7 +820,7 @@ void SplitContainer::DropOverlay::setRects(std::vector<SplitContainer::DropRect>
// pajlada::Signals::NoArgSignal dragEnded; // pajlada::Signals::NoArgSignal dragEnded;
void SplitContainer::DropOverlay::paintEvent(QPaintEvent *event) void SplitContainer::DropOverlay::paintEvent(QPaintEvent *)
{ {
QPainter painter(this); QPainter painter(this);

View file

@ -39,7 +39,7 @@ public:
// fourtf: !!! preserve the order of left, up, right and down // fourtf: !!! preserve the order of left, up, right and down
enum Direction { Left, Above, Right, Below }; enum Direction { Left, Above, Right, Below };
struct Position { struct Position final {
private: private:
Position() = default; Position() = default;
Position(Node *_relativeNode, Direction _direcion) Position(Node *_relativeNode, Direction _direcion)
@ -56,7 +56,7 @@ public:
}; };
private: private:
struct DropRect { struct DropRect final {
QRect rect; QRect rect;
Position position; Position position;
@ -67,7 +67,7 @@ private:
} }
}; };
struct ResizeRect { struct ResizeRect final {
QRect rect; QRect rect;
Node *node; Node *node;
bool vertical; bool vertical;
@ -122,7 +122,7 @@ public:
}; };
private: private:
class DropOverlay : public QWidget class DropOverlay final : public QWidget
{ {
public: public:
DropOverlay(SplitContainer *_parent = nullptr); DropOverlay(SplitContainer *_parent = nullptr);
@ -133,10 +133,10 @@ private:
protected: protected:
void paintEvent(QPaintEvent *event) override; void paintEvent(QPaintEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event); void dragEnterEvent(QDragEnterEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event); void dragMoveEvent(QDragMoveEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event); void dragLeaveEvent(QDragLeaveEvent *event) override;
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event) override;
private: private:
std::vector<DropRect> rects; std::vector<DropRect> rects;
@ -144,7 +144,7 @@ private:
SplitContainer *parent; SplitContainer *parent;
}; };
class ResizeHandle : public QWidget class ResizeHandle final : public QWidget
{ {
public: public:
SplitContainer *parent; SplitContainer *parent;
@ -223,6 +223,8 @@ private:
} }
}; };
void addSplit(Split *split);
std::vector<DropRect> dropRects; std::vector<DropRect> dropRects;
std::vector<DropRegion> dropRegions; std::vector<DropRegion> dropRegions;
NotebookPageDropPreview dropPreview; NotebookPageDropPreview dropPreview;