SplitContainer refactor (#4261)
* Remove unused include util/Helpers.hpp * SplitContainer::setTag fix parameter naming * autofy/constify where possible * More const auto ptr magicifying * Make SplitNode::Type an enum class * Move QuickSwitcherPopup includes from header to source file * Remove unused DropRegion code * use empty() instead of size() == 0 * Add curly braces everywhere * Remove useless reinterpret_cast It was casting Node* to Node* * Clarify that the connect is QObject::connect * SplitContainer::setSelected fix parameter naming * Rename function variables to remove unneccesary underscore Also move addSpacing parameter out of the layout function * emplace_back where possible * Name parameters * Remove ineffective const from return type * Make node getters const * Flatten Node::releaseSplit * Rename in-function variable to match code style * [ACTUAL CODE CHANGE/MOVE] Move clamp logic to its own function * name params * applyFromDescriptorRecursively: rename node param to baseNode * [ACTUAL CODE CHANGE/MOVE] Remove the many overloads for append/insertSplit This utilizes the C++20 designed initializers aggregate initialization feature * Remove unused includes * [ACTUAL CODE CHANGE] Clean up dragging logic There's no need to keep a pointer around to which split is being dragged, it's already stored in the QDropEvent source() * UNRELATED .clang-tidy: Only suggest UPPER_CASE for constant global variables * Remove unused SplitContainer::getSplitCount function * Use std::max in Node's clamp function * Remove test code * DraggedSplit.hpp: remove unused include * Split `setDraggingSplit` into two functions, `startDraggingSplit` and `stopDraggingSplit`
This commit is contained in:
@@ -6,14 +6,11 @@
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QHBoxLayout>
|
||||
#include <QRect>
|
||||
#include <QVBoxLayout>
|
||||
#include <QVector>
|
||||
#include <QWidget>
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -38,6 +35,7 @@ public:
|
||||
struct Node;
|
||||
|
||||
// fourtf: !!! preserve the order of left, up, right and down
|
||||
// It's important to preserve since we cast from an int to this enum, so 0 = left, 1 = above etc
|
||||
enum Direction { Left, Above, Right, Below };
|
||||
|
||||
struct Position final {
|
||||
@@ -49,8 +47,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
Node *relativeNode_;
|
||||
Direction direction_;
|
||||
Node *relativeNode_{nullptr};
|
||||
Direction direction_{Direction::Right};
|
||||
|
||||
friend struct Node;
|
||||
friend class SplitContainer;
|
||||
@@ -83,13 +81,18 @@ private:
|
||||
|
||||
public:
|
||||
struct Node final {
|
||||
enum Type { EmptyRoot, _Split, VerticalContainer, HorizontalContainer };
|
||||
enum class Type {
|
||||
EmptyRoot,
|
||||
Split,
|
||||
VerticalContainer,
|
||||
HorizontalContainer,
|
||||
};
|
||||
|
||||
Type getType();
|
||||
Split *getSplit();
|
||||
Node *getParent();
|
||||
qreal getHorizontalFlex();
|
||||
qreal getVerticalFlex();
|
||||
Type getType() const;
|
||||
Split *getSplit() const;
|
||||
Node *getParent() const;
|
||||
qreal getHorizontalFlex() const;
|
||||
qreal getVerticalFlex() const;
|
||||
const std::vector<std::unique_ptr<Node>> &getChildren();
|
||||
|
||||
private:
|
||||
@@ -110,6 +113,9 @@ public:
|
||||
std::vector<DropRect> &dropRects_,
|
||||
std::vector<ResizeRect> &resizeRects);
|
||||
|
||||
// Clamps the flex values ensuring they're never below 0
|
||||
void clamp();
|
||||
|
||||
static Type toContainerType(Direction _dir);
|
||||
|
||||
Type type_;
|
||||
@@ -174,33 +180,48 @@ public:
|
||||
SplitContainer(Notebook *parent);
|
||||
|
||||
Split *appendNewSplit(bool openChannelNameDialog);
|
||||
void appendSplit(Split *split);
|
||||
void insertSplit(Split *split, const Position &position);
|
||||
void insertSplit(Split *split, Direction direction, Split *relativeTo);
|
||||
void insertSplit(Split *split, Direction direction,
|
||||
Node *relativeTo = nullptr);
|
||||
|
||||
struct InsertOptions {
|
||||
/// Position must be set alone, as if it's set it will override direction & relativeNode with its underlying values
|
||||
std::optional<Position> position{};
|
||||
|
||||
/// Will be used to figure out the relative node, so relative node or position must not be set if using this
|
||||
Split *relativeSplit{nullptr};
|
||||
|
||||
Node *relativeNode{nullptr};
|
||||
std::optional<Direction> direction{};
|
||||
};
|
||||
|
||||
// Insert split into the base node of this container
|
||||
// Default values for each field must be specified due to these bugs:
|
||||
// - https://bugs.llvm.org/show_bug.cgi?id=36684
|
||||
// - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96645
|
||||
void insertSplit(Split *split, InsertOptions &&options = InsertOptions{
|
||||
.position = std::nullopt,
|
||||
.relativeSplit = nullptr,
|
||||
.relativeNode = nullptr,
|
||||
.direction = std::nullopt,
|
||||
});
|
||||
|
||||
// Returns a pointer to the selected split
|
||||
Split *getSelectedSplit() const;
|
||||
Position releaseSplit(Split *split);
|
||||
Position deleteSplit(Split *split);
|
||||
|
||||
void selectNextSplit(Direction direction);
|
||||
void setSelected(Split *selected_);
|
||||
void setSelected(Split *split);
|
||||
|
||||
int getSplitCount();
|
||||
const std::vector<Split *> getSplits() const;
|
||||
std::vector<Split *> getSplits() const;
|
||||
|
||||
void refreshTab();
|
||||
|
||||
NotebookTab *getTab() const;
|
||||
Node *getBaseNode();
|
||||
|
||||
void setTab(NotebookTab *tab_);
|
||||
void setTab(NotebookTab *tab);
|
||||
void hideResizeHandles();
|
||||
void resetMouseStatus();
|
||||
|
||||
static bool isDraggingSplit;
|
||||
static Split *draggingSplit;
|
||||
|
||||
void applyFromDescriptor(const NodeDescriptor &rootNode);
|
||||
|
||||
void popup();
|
||||
@@ -219,7 +240,7 @@ protected:
|
||||
|
||||
private:
|
||||
void applyFromDescriptorRecursively(const NodeDescriptor &rootNode,
|
||||
Node *node);
|
||||
Node *baseNode);
|
||||
|
||||
void layout();
|
||||
void selectSplitRecursive(Node *node, Direction direction);
|
||||
@@ -233,19 +254,7 @@ private:
|
||||
void refreshTabTitle();
|
||||
void refreshTabLiveStatus();
|
||||
|
||||
struct DropRegion {
|
||||
QRect rect;
|
||||
std::pair<int, int> position;
|
||||
|
||||
DropRegion(QRect rect, std::pair<int, int> position)
|
||||
{
|
||||
this->rect = rect;
|
||||
this->position = position;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<DropRect> dropRects_;
|
||||
std::vector<DropRegion> dropRegions_;
|
||||
DropOverlay overlay_;
|
||||
std::vector<std::unique_ptr<ResizeHandle>> resizeHandles_;
|
||||
QPoint mouseOverPoint_;
|
||||
@@ -263,6 +272,7 @@ private:
|
||||
|
||||
pajlada::Signals::SignalHolder signalHolder_;
|
||||
|
||||
// Specifies whether the user is currently dragging something over this container
|
||||
bool isDragging_ = false;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user