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:
pajlada
2022-12-25 12:09:25 +01:00
committed by GitHub
parent cce1fd58f2
commit fdb0a1582c
16 changed files with 397 additions and 289 deletions
+26 -19
View File
@@ -34,6 +34,7 @@
#include "widgets/helper/SearchPopup.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/Scrollbar.hpp"
#include "widgets/splits/DraggedSplit.hpp"
#include "widgets/splits/SplitContainer.hpp"
#include "widgets/splits/SplitHeader.hpp"
#include "widgets/splits/SplitInput.hpp"
@@ -628,7 +629,7 @@ void Split::joinChannelInNewTab(ChannelPtr channel)
Split *split = new Split(container);
split->setChannel(channel);
container->appendSplit(split);
container->insertSplit(split);
}
void Split::openChannelInBrowserPlayer(ChannelPtr channel)
@@ -899,7 +900,7 @@ void Split::popup()
split->setModerationMode(this->getModerationMode());
split->setFilters(this->getFilters());
window.getNotebook().getOrAddSelectedPage()->appendSplit(split);
window.getNotebook().getOrAddSelectedPage()->insertSplit(split);
window.show();
}
@@ -1256,25 +1257,31 @@ static Iter select_randomly(Iter start, Iter end)
void Split::drag()
{
if (auto container = dynamic_cast<SplitContainer *>(this->parentWidget()))
auto *container = dynamic_cast<SplitContainer *>(this->parentWidget());
if (!container)
{
SplitContainer::isDraggingSplit = true;
SplitContainer::draggingSplit = this;
auto originalLocation = container->releaseSplit(this);
auto drag = new QDrag(this);
auto mimeData = new QMimeData;
mimeData->setData("chatterino/split", "xD");
drag->setMimeData(mimeData);
if (drag->exec(Qt::MoveAction) == Qt::IgnoreAction)
{
container->insertSplit(this, originalLocation);
}
SplitContainer::isDraggingSplit = false;
qCWarning(chatterinoWidget)
<< "Attempted to initiate split drag without a container parent";
return;
}
startDraggingSplit();
auto originalLocation = container->releaseSplit(this);
auto drag = new QDrag(this);
auto mimeData = new QMimeData;
mimeData->setData("chatterino/split", "xD");
drag->setMimeData(mimeData);
// drag->exec is a blocking action
if (drag->exec(Qt::MoveAction) == Qt::IgnoreAction)
{
// The split wasn't dropped in a valid spot, return it to its original position
container->insertSplit(this, {.position = originalLocation});
}
stopDraggingSplit();
}
void Split::setInputReply(const std::shared_ptr<MessageThread> &reply)