Compare commits

..

No commits in common. "292f9b97348d9a455b18ea8c658db870d33462f5" and "1554d7b6a4e184b69c9d34d6366899dcd27b91fe" have entirely different histories.

11 changed files with 226 additions and 317 deletions

View file

@ -65,8 +65,6 @@
- Bugfix: Fixed avatar in usercard and moderation button triggering when releasing the mouse outside their area. (#5052)
- Bugfix: Fixed moderator-only topics being subscribed to for non-moderators. (#5056)
- Bugfix: Fixed a bug where buttons would remain in a hovered state after leaving them. (#5077)
- Bugfix: Fixed popup windows not persisting between restarts. (#5081)
- Bugfix: Fixed splits not retaining their focus after minimizing. (#5080)
- Dev: Run miniaudio in a separate thread, and simplify it to not manage the device ourselves. There's a chance the simplification is a bad idea. (#4978)
- Dev: Change clang-format from v14 to v16. (#4929)
- Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791)
@ -104,7 +102,6 @@
- Dev: Added Tests for Windows and MacOS in CI. (#4970, #5032)
- Dev: Move `clang-tidy` checker to its own CI job. (#4996)
- Dev: Refactored the Image Uploader feature. (#4971)
- Dev: Refactored the SplitOverlay code. (#5082)
- Dev: Fixed deadlock and use-after-free in tests. (#4981)
- Dev: Moved all `.clang-format` files to the root directory. (#5037)
- Dev: Load less message history upon reconnects. (#5001, #5018)

View file

@ -696,7 +696,6 @@ set(SOURCE_FILES
widgets/splits/InputCompletionPopup.hpp
widgets/splits/Split.cpp
widgets/splits/Split.hpp
widgets/splits/SplitCommon.hpp
widgets/splits/SplitContainer.cpp
widgets/splits/SplitContainer.hpp
widgets/splits/SplitHeader.cpp

View file

@ -50,6 +50,7 @@ const QString WindowManager::WINDOW_LAYOUT_FILENAME(
QStringLiteral("window-layout.json"));
using SplitNode = SplitContainer::Node;
using SplitDirection = SplitContainer::Direction;
void WindowManager::showSettingsDialog(QWidget *parent,
SettingsDialogPreference preference)
@ -421,14 +422,7 @@ void WindowManager::save()
{
return;
}
if (this->shuttingDown_)
{
qCDebug(chatterinoWindowmanager) << "Skipping save (shutting down)";
return;
}
qCDebug(chatterinoWindowmanager) << "Saving";
qCDebug(chatterinoWindowmanager) << "[WindowManager] Saving";
assertInGuiThread();
QJsonDocument document;
@ -707,9 +701,6 @@ void WindowManager::closeAll()
{
assertInGuiThread();
qCDebug(chatterinoWindowmanager) << "Shutting down (closing windows)";
this->shuttingDown_ = true;
for (Window *window : windows_)
{
window->close();

View file

@ -140,7 +140,6 @@ private:
const QString windowLayoutFilePath;
bool initialized_ = false;
bool shuttingDown_ = false;
QPoint emotePopupPos_;

View file

@ -1332,19 +1332,13 @@ SplitNotebook::SplitNotebook(Window *parent)
});
}
void SplitNotebook::showEvent(QShowEvent * /*event*/)
void SplitNotebook::showEvent(QShowEvent *)
{
if (auto *page = this->getSelectedPage())
if (auto page = this->getSelectedPage())
{
auto *split = page->getSelectedSplit();
if (!split)
if (auto split = page->findChild<Split *>())
{
split = page->findChild<Split *>();
}
if (split)
{
split->setFocus(Qt::OtherFocusReason);
split->setFocus(Qt::FocusReason::OtherFocusReason);
}
}
}

View file

@ -4,7 +4,6 @@
#include "common/Channel.hpp"
#include "common/NullablePtr.hpp"
#include "widgets/BaseWidget.hpp"
#include "widgets/splits/SplitCommon.hpp"
#include <boost/signals2.hpp>
#include <pajlada/signals/signalholder.hpp>
@ -96,7 +95,8 @@ public:
pajlada::Signals::Signal<Action> actionRequested;
pajlada::Signals::Signal<ChannelPtr> openSplitRequested;
pajlada::Signals::Signal<SplitDirection, Split *> insertSplitRequested;
// args: (SplitContainer::Direction dir, Split* parent)
pajlada::Signals::Signal<int, Split *> insertSplitRequested;
protected:
void paintEvent(QPaintEvent *event) override;

View file

@ -1,12 +0,0 @@
#pragma once
namespace chatterino {
enum class SplitDirection {
Left,
Above,
Right,
Below,
};
} // namespace chatterino

View file

@ -159,7 +159,7 @@ void SplitContainer::insertSplit(Split *split, InsertOptions &&options)
}
auto *relativeTo = options.relativeNode;
const auto direction = options.direction.value_or(SplitDirection::Right);
const auto direction = options.direction.value_or(Direction::Right);
if (relativeTo == nullptr)
{
@ -260,25 +260,26 @@ void SplitContainer::addSplit(Split *split)
break;
case Split::Action::SelectSplitLeft:
this->selectNextSplit(SplitDirection::Left);
this->selectNextSplit(SplitContainer::Left);
break;
case Split::Action::SelectSplitRight:
this->selectNextSplit(SplitDirection::Right);
this->selectNextSplit(SplitContainer::Right);
break;
case Split::Action::SelectSplitAbove:
this->selectNextSplit(SplitDirection::Above);
this->selectNextSplit(SplitContainer::Above);
break;
case Split::Action::SelectSplitBelow:
this->selectNextSplit(SplitDirection::Below);
this->selectNextSplit(SplitContainer::Below);
break;
}
});
conns.managedConnect(
split->insertSplitRequested, [this](SplitDirection dir, Split *parent) {
this->insertSplit(new Split(this), {
split->insertSplitRequested, [this](int dir, Split *parent) {
this->insertSplit(new Split(this),
{
.relativeSplit = parent,
.direction = dir,
.direction = static_cast<Direction>(dir),
});
});
@ -354,7 +355,7 @@ SplitContainer::Position SplitContainer::deleteSplit(Split *split)
return releaseSplit(split);
}
void SplitContainer::selectNextSplit(SplitDirection direction)
void SplitContainer::selectNextSplit(Direction direction)
{
assertInGuiThread();
@ -364,7 +365,7 @@ void SplitContainer::selectNextSplit(SplitDirection direction)
}
}
void SplitContainer::selectSplitRecursive(Node *node, SplitDirection direction)
void SplitContainer::selectSplitRecursive(Node *node, Direction direction)
{
if (node->parent_ != nullptr)
{
@ -378,8 +379,7 @@ void SplitContainer::selectSplitRecursive(Node *node, SplitDirection direction)
});
assert(it != siblings.end());
if (direction == SplitDirection::Left ||
direction == SplitDirection::Above)
if (direction == Direction::Left || direction == Direction::Above)
{
if (it == siblings.begin())
{
@ -507,20 +507,20 @@ void SplitContainer::layout()
// left
dropRects.emplace_back(
QRect(g.left(), g.top(), g.width() / 3, g.height()),
Position(node, SplitDirection::Left));
Position(node, Direction::Left));
// right
dropRects.emplace_back(QRect(g.right() - g.width() / 3, g.top(),
g.width() / 3, g.height()),
Position(node, SplitDirection::Right));
Position(node, Direction::Right));
// top
dropRects.emplace_back(
QRect(g.left(), g.top(), g.width(), g.height() / 2),
Position(node, SplitDirection::Above));
Position(node, Direction::Above));
// bottom
dropRects.emplace_back(QRect(g.left(), g.bottom() - g.height() / 2,
g.width(), g.height() / 2),
Position(node, SplitDirection::Below));
Position(node, Direction::Below));
}
if (this->splits_.empty())
@ -528,7 +528,7 @@ void SplitContainer::layout()
QRect g = this->rect();
dropRects.emplace_back(
QRect(g.left(), g.top(), g.width() - 1, g.height() - 1),
Position(nullptr, SplitDirection::Below));
Position(nullptr, Direction::Below));
}
this->overlay_.setRects(std::move(dropRects));
@ -1027,7 +1027,7 @@ SplitContainer::Node *SplitContainer::Node::findNodeContainingSplit(
}
void SplitContainer::Node::insertSplitRelative(Split *_split,
SplitDirection _direction)
Direction _direction)
{
if (this->parent_ == nullptr)
{
@ -1066,7 +1066,7 @@ void SplitContainer::Node::insertSplitRelative(Split *_split,
}
void SplitContainer::Node::nestSplitIntoCollection(Split *_split,
SplitDirection _direction)
Direction _direction)
{
if (toContainerType(_direction) == this->type_)
{
@ -1095,8 +1095,7 @@ void SplitContainer::Node::nestSplitIntoCollection(Split *_split,
}
}
void SplitContainer::Node::insertNextToThis(Split *_split,
SplitDirection _direction)
void SplitContainer::Node::insertNextToThis(Split *_split, Direction _direction)
{
auto &siblings = this->parent_->children_;
@ -1116,8 +1115,7 @@ void SplitContainer::Node::insertNextToThis(Split *_split,
});
assert(it != siblings.end());
if (_direction == SplitDirection::Right ||
_direction == SplitDirection::Below)
if (_direction == Direction::Right || _direction == Direction::Below)
{
it++;
}
@ -1147,7 +1145,7 @@ SplitContainer::Position SplitContainer::Node::releaseSplit()
Position pos;
pos.relativeNode_ = nullptr;
pos.direction_ = SplitDirection::Right;
pos.direction_ = Direction::Right;
return pos;
}
@ -1165,15 +1163,13 @@ SplitContainer::Position SplitContainer::Node::releaseSplit()
position.relativeNode_ = this->parent_;
if (this->parent_->type_ == Type::VerticalContainer)
{
position.direction_ = siblings.begin() == it
? SplitDirection::Above
: SplitDirection::Below;
position.direction_ =
siblings.begin() == it ? Direction::Above : Direction::Below;
}
else
{
position.direction_ = siblings.begin() == it
? SplitDirection::Left
: SplitDirection::Right;
position.direction_ =
siblings.begin() == it ? Direction::Left : Direction::Right;
}
auto *parent = this->parent_;
@ -1195,8 +1191,8 @@ SplitContainer::Position SplitContainer::Node::releaseSplit()
{
position.direction_ =
this->parent_->type_ == Type::VerticalContainer
? SplitDirection::Below
: SplitDirection::Right;
? Direction::Below
: Direction::Right;
siblings.erase(it);
position.relativeNode_ = siblings.back().get();
}
@ -1205,8 +1201,8 @@ SplitContainer::Position SplitContainer::Node::releaseSplit()
position.relativeNode_ = (it + 1)->get();
position.direction_ =
this->parent_->type_ == Type::VerticalContainer
? SplitDirection::Above
: SplitDirection::Left;
? Direction::Above
: Direction::Left;
siblings.erase(it);
}
}
@ -1286,8 +1282,8 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale,
isVertical ? offset : this->geometry_.width(),
isVertical ? this->geometry_.height() : offset)
.toRect(),
Position(this, isVertical ? SplitDirection::Left
: SplitDirection::Above));
Position(this,
isVertical ? Direction::Left : Direction::Above));
// droprect right / below
if (isVertical)
@ -1297,7 +1293,7 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale,
this->geometry_.top(), offset,
this->geometry_.height())
.toRect(),
Position(this, SplitDirection::Right));
Position(this, Direction::Right));
}
else
{
@ -1306,7 +1302,7 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale,
this->geometry_.bottom() - offset,
this->geometry_.width(), offset)
.toRect(),
Position(this, SplitDirection::Below));
Position(this, Direction::Below));
}
// shrink childRect
@ -1395,10 +1391,9 @@ void SplitContainer::Node::clamp()
this->flexV_ = std::max(0.0, this->flexV_);
}
SplitContainer::Node::Type SplitContainer::Node::toContainerType(
SplitDirection _dir)
SplitContainer::Node::Type SplitContainer::Node::toContainerType(Direction _dir)
{
return _dir == SplitDirection::Left || _dir == SplitDirection::Right
return _dir == Direction::Left || _dir == Direction::Right
? Type::HorizontalContainer
: Type::VerticalContainer;
}

View file

@ -2,7 +2,6 @@
#include "common/WindowDescriptors.hpp"
#include "widgets/BaseWidget.hpp"
#include "widgets/splits/SplitCommon.hpp"
#include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
@ -36,17 +35,21 @@ class SplitContainer final : public BaseWidget
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 {
private:
Position() = default;
Position(Node *relativeNode, SplitDirection direction)
Position(Node *relativeNode, Direction direcion)
: relativeNode_(relativeNode)
, direction_(direction)
, direction_(direcion)
{
}
Node *relativeNode_{nullptr};
SplitDirection direction_{SplitDirection::Right};
Direction direction_{Direction::Right};
friend struct Node;
friend class SplitContainer;
@ -99,9 +102,9 @@ public:
bool isOrContainsNode(Node *_node);
Node *findNodeContainingSplit(Split *_split);
void insertSplitRelative(Split *_split, SplitDirection _direction);
void nestSplitIntoCollection(Split *_split, SplitDirection _direction);
void insertNextToThis(Split *_split, SplitDirection _direction);
void insertSplitRelative(Split *_split, Direction _direction);
void nestSplitIntoCollection(Split *_split, Direction _direction);
void insertNextToThis(Split *_split, Direction _direction);
void setSplit(Split *_split);
Position releaseSplit();
qreal getFlex(bool isVertical);
@ -114,7 +117,7 @@ public:
// Clamps the flex values ensuring they're never below 0
void clamp();
static Type toContainerType(SplitDirection _dir);
static Type toContainerType(Direction _dir);
Type type_;
Split *split_;
@ -187,7 +190,7 @@ public:
Split *relativeSplit{nullptr};
Node *relativeNode{nullptr};
std::optional<SplitDirection> direction{};
std::optional<Direction> direction{};
};
// Insert split into the base node of this container
@ -206,7 +209,7 @@ public:
Position releaseSplit(Split *split);
Position deleteSplit(Split *split);
void selectNextSplit(SplitDirection direction);
void selectNextSplit(Direction direction);
void setSelected(Split *split);
std::vector<Split *> getSplits() const;
@ -241,7 +244,7 @@ private:
Node *baseNode);
void layout();
void selectSplitRecursive(Node *node, SplitDirection direction);
void selectSplitRecursive(Node *node, Direction direction);
void focusSplitRecursive(Node *node);
void setPreferedTargetRecursive(Node *node);

View file

@ -14,117 +14,14 @@
#include <QPainter>
#include <QPushButton>
namespace {
using namespace chatterino;
class ButtonEventFilter : public QObject
{
SplitOverlay *parent;
SplitOverlayButton buttonType;
public:
ButtonEventFilter(SplitOverlay *_parent, SplitOverlayButton _buttonType);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
};
ButtonEventFilter::ButtonEventFilter(SplitOverlay *_parent,
SplitOverlayButton _buttonType)
: QObject(_parent)
, parent(_parent)
, buttonType(_buttonType)
{
}
bool ButtonEventFilter::eventFilter(QObject *watched, QEvent *event)
{
switch (event->type())
{
case QEvent::Enter: {
auto *effect = dynamic_cast<QGraphicsOpacityEffect *>(
((QWidget *)watched)->graphicsEffect());
if (effect != nullptr)
{
effect->setOpacity(0.99);
}
this->parent->setHoveredButton(this->buttonType);
}
break;
case QEvent::Leave: {
auto *effect = dynamic_cast<QGraphicsOpacityEffect *>(
((QWidget *)watched)->graphicsEffect());
if (effect != nullptr)
{
effect->setOpacity(0.7);
}
this->parent->setHoveredButton({});
}
break;
case QEvent::MouseButtonPress: {
if (this->buttonType == SplitOverlayButton::Move)
{
auto *mouseEvent = dynamic_cast<QMouseEvent *>(event);
assert(mouseEvent != nullptr);
if (mouseEvent->button() == Qt::LeftButton)
{
this->parent->dragPressed();
}
return true;
}
}
break;
case QEvent::MouseButtonRelease: {
switch (this->buttonType)
{
case SplitOverlayButton::Move:
break;
case SplitOverlayButton::Left: {
this->parent->createSplitPressed(SplitDirection::Left);
}
break;
case SplitOverlayButton::Up: {
this->parent->createSplitPressed(SplitDirection::Above);
}
break;
case SplitOverlayButton::Right: {
this->parent->createSplitPressed(SplitDirection::Right);
}
break;
case SplitOverlayButton::Down: {
this->parent->createSplitPressed(SplitDirection::Below);
}
break;
}
}
break;
default:;
}
return QObject::eventFilter(watched, event);
}
} // namespace
namespace chatterino {
SplitOverlay::SplitOverlay(Split *parent)
: BaseWidget(parent)
, split_(parent)
{
auto *layout = new QGridLayout(this);
QGridLayout *layout = new QGridLayout(this);
this->layout_ = layout;
layout->setContentsMargins(1, 1, 1, 1);
layout->setSpacing(1);
@ -133,93 +30,69 @@ SplitOverlay::SplitOverlay(Split *parent)
layout->setColumnStretch(1, 1);
layout->setColumnStretch(3, 1);
this->move_ = new QPushButton(getResources().split.move, {});
this->left_ = new QPushButton(getResources().split.left, {});
this->right_ = new QPushButton(getResources().split.right, {});
this->up_ = new QPushButton(getResources().split.up, {});
this->down_ = new QPushButton(getResources().split.down, {});
auto *move = new QPushButton(getResources().split.move, QString());
auto *left = this->left_ =
new QPushButton(getResources().split.left, QString());
auto *right = this->right_ =
new QPushButton(getResources().split.right, QString());
auto *up = this->up_ = new QPushButton(getResources().split.up, QString());
auto *down = this->down_ =
new QPushButton(getResources().split.down, QString());
this->move_->setGraphicsEffect(new QGraphicsOpacityEffect(this));
this->left_->setGraphicsEffect(new QGraphicsOpacityEffect(this));
this->right_->setGraphicsEffect(new QGraphicsOpacityEffect(this));
this->up_->setGraphicsEffect(new QGraphicsOpacityEffect(this));
this->down_->setGraphicsEffect(new QGraphicsOpacityEffect(this));
move->setGraphicsEffect(new QGraphicsOpacityEffect(this));
left->setGraphicsEffect(new QGraphicsOpacityEffect(this));
right->setGraphicsEffect(new QGraphicsOpacityEffect(this));
up->setGraphicsEffect(new QGraphicsOpacityEffect(this));
down->setGraphicsEffect(new QGraphicsOpacityEffect(this));
this->move_->setFlat(true);
this->left_->setFlat(true);
this->right_->setFlat(true);
this->up_->setFlat(true);
this->down_->setFlat(true);
move->setFlat(true);
left->setFlat(true);
right->setFlat(true);
up->setFlat(true);
down->setFlat(true);
layout->addWidget(this->move_, 2, 2);
layout->addWidget(this->left_, 2, 0);
layout->addWidget(this->right_, 2, 4);
layout->addWidget(this->up_, 0, 2);
layout->addWidget(this->down_, 4, 2);
layout->addWidget(move, 2, 2);
layout->addWidget(left, 2, 0);
layout->addWidget(right, 2, 4);
layout->addWidget(up, 0, 2);
layout->addWidget(down, 4, 2);
this->move_->installEventFilter(
new ButtonEventFilter(this, SplitOverlayButton::Move));
this->left_->installEventFilter(
new ButtonEventFilter(this, SplitOverlayButton::Left));
this->right_->installEventFilter(
new ButtonEventFilter(this, SplitOverlayButton::Right));
this->up_->installEventFilter(
new ButtonEventFilter(this, SplitOverlayButton::Up));
this->down_->installEventFilter(
new ButtonEventFilter(this, SplitOverlayButton::Down));
move->installEventFilter(new ButtonEventFilter(this, SplitMove));
left->installEventFilter(new ButtonEventFilter(this, SplitLeft));
right->installEventFilter(new ButtonEventFilter(this, SplitRight));
up->installEventFilter(new ButtonEventFilter(this, SplitUp));
down->installEventFilter(new ButtonEventFilter(this, SplitDown));
this->move_->setFocusPolicy(Qt::NoFocus);
this->left_->setFocusPolicy(Qt::NoFocus);
this->right_->setFocusPolicy(Qt::NoFocus);
this->up_->setFocusPolicy(Qt::NoFocus);
this->down_->setFocusPolicy(Qt::NoFocus);
move->setFocusPolicy(Qt::NoFocus);
left->setFocusPolicy(Qt::NoFocus);
right->setFocusPolicy(Qt::NoFocus);
up->setFocusPolicy(Qt::NoFocus);
down->setFocusPolicy(Qt::NoFocus);
this->move_->setCursor(Qt::SizeAllCursor);
this->left_->setCursor(Qt::PointingHandCursor);
this->right_->setCursor(Qt::PointingHandCursor);
this->up_->setCursor(Qt::PointingHandCursor);
this->down_->setCursor(Qt::PointingHandCursor);
move->setCursor(Qt::SizeAllCursor);
left->setCursor(Qt::PointingHandCursor);
right->setCursor(Qt::PointingHandCursor);
up->setCursor(Qt::PointingHandCursor);
down->setCursor(Qt::PointingHandCursor);
this->signalHolder_.managedConnect(this->scaleChanged, [=](float _scale) {
int a = int(_scale * 30);
QSize size(a, a);
move->setIconSize(size);
left->setIconSize(size);
right->setIconSize(size);
up->setIconSize(size);
down->setIconSize(size);
});
this->setMouseTracking(true);
this->setCursor(Qt::ArrowCursor);
}
void SplitOverlay::setHoveredButton(
std::optional<SplitOverlayButton> hoveredButton)
void SplitOverlay::paintEvent(QPaintEvent *)
{
this->hoveredButton_ = hoveredButton;
this->update();
}
void SplitOverlay::dragPressed()
{
this->split_->drag();
}
void SplitOverlay::createSplitPressed(SplitDirection direction)
{
this->split_->insertSplitRequested.invoke(direction, this->split_);
this->hide();
}
void SplitOverlay::scaleChangedEvent(float newScale)
{
int a = int(newScale * 30);
QSize size(a, a);
this->move_->setIconSize(size);
this->left_->setIconSize(size);
this->right_->setIconSize(size);
this->up_->setIconSize(size);
this->down_->setIconSize(size);
BaseWidget::scaleChangedEvent(newScale);
}
void SplitOverlay::paintEvent(QPaintEvent *event)
{
(void)event;
QPainter painter(this);
if (this->theme->isLightTheme())
{
@ -230,32 +103,26 @@ void SplitOverlay::paintEvent(QPaintEvent *event)
painter.fillRect(this->rect(), QColor(0, 0, 0, 150));
}
if (!this->hoveredButton_.has_value())
{
return;
}
QRect rect;
auto hoveredButton = this->hoveredButton_.value();
switch (hoveredButton)
switch (this->hoveredElement_)
{
case SplitOverlayButton::Left: {
case SplitLeft: {
rect = QRect(0, 0, this->width() / 2, this->height());
}
break;
case SplitOverlayButton::Right: {
case SplitRight: {
rect =
QRect(this->width() / 2, 0, this->width() / 2, this->height());
}
break;
case SplitOverlayButton::Up: {
case SplitUp: {
rect = QRect(0, 0, this->width(), this->height() / 2);
}
break;
case SplitOverlayButton::Down: {
case SplitDown: {
rect =
QRect(0, this->height() / 2, this->width(), this->height() / 2);
}
@ -264,10 +131,11 @@ void SplitOverlay::paintEvent(QPaintEvent *event)
default:;
}
if (!rect.isNull())
{
rect.setRight(rect.right() - 1);
rect.setBottom(rect.bottom() - 1);
if (!rect.isNull())
{
painter.setPen(getApp()->themes->splits.dropPreviewBorder);
painter.setBrush(getApp()->themes->splits.dropPreview);
painter.drawRect(rect);
@ -276,12 +144,9 @@ void SplitOverlay::paintEvent(QPaintEvent *event)
void SplitOverlay::resizeEvent(QResizeEvent *event)
{
const auto currentScale = this->scale();
const auto minimumWidth = 150.F * currentScale;
const auto minimumHeight = 150.F * currentScale;
const auto wideEnough = event->size().width() > minimumWidth;
const auto highEnough = event->size().height() > minimumHeight;
float _scale = this->scale();
bool wideEnough = event->size().width() > 150 * _scale;
bool highEnough = event->size().height() > 150 * _scale;
this->left_->setVisible(wideEnough);
this->right_->setVisible(wideEnough);
@ -299,4 +164,75 @@ void SplitOverlay::mouseMoveEvent(QMouseEvent *event)
// }
}
SplitOverlay::ButtonEventFilter::ButtonEventFilter(SplitOverlay *_parent,
HoveredElement _element)
: QObject(_parent)
, parent(_parent)
, hoveredElement(_element)
{
}
bool SplitOverlay::ButtonEventFilter::eventFilter(QObject *watched,
QEvent *event)
{
switch (event->type())
{
case QEvent::Enter: {
QGraphicsOpacityEffect *effect =
dynamic_cast<QGraphicsOpacityEffect *>(
((QWidget *)watched)->graphicsEffect());
if (effect != nullptr)
{
effect->setOpacity(0.99);
}
this->parent->hoveredElement_ = this->hoveredElement;
this->parent->update();
}
break;
case QEvent::Leave: {
QGraphicsOpacityEffect *effect =
dynamic_cast<QGraphicsOpacityEffect *>(
((QWidget *)watched)->graphicsEffect());
if (effect != nullptr)
{
effect->setOpacity(0.7);
}
this->parent->hoveredElement_ = HoveredElement::None;
this->parent->update();
}
break;
case QEvent::MouseButtonPress: {
if (this->hoveredElement == HoveredElement::SplitMove)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->button() == Qt::LeftButton)
{
this->parent->split_->drag();
}
return true;
}
}
break;
case QEvent::MouseButtonRelease: {
if (this->hoveredElement != HoveredElement::SplitMove)
{
auto dir = SplitContainer::Direction(
this->hoveredElement + SplitContainer::Left - SplitLeft);
this->parent->split_->insertSplitRequested.invoke(
static_cast<int>(dir), this->parent->split_);
this->parent->hide();
}
}
break;
default:;
}
return QObject::eventFilter(watched, event);
}
} // namespace chatterino

View file

@ -1,53 +1,60 @@
#pragma once
#include "widgets/BaseWidget.hpp"
#include "widgets/splits/SplitCommon.hpp"
#include <pajlada/signals/signalholder.hpp>
#include <QGridLayout>
#include <QPushButton>
#include <optional>
namespace chatterino {
class Split;
/// Type of button in the split overlay (the overlay that appears when holding down ctrl+alt)
enum class SplitOverlayButton {
Move,
Left,
Up,
Right,
Down,
};
class SplitOverlay : public BaseWidget
{
public:
explicit SplitOverlay(Split *parent);
// Called from the Split Overlay's button when it gets hovered over
void setHoveredButton(std::optional<SplitOverlayButton> hoveredButton);
// Called from the Split Overlay's button when the move button is pressed
void dragPressed();
// Called from the Split Overlay's button when one of the direction buttons are pressed
void createSplitPressed(SplitDirection direction);
explicit SplitOverlay(Split *parent = nullptr);
protected:
void scaleChangedEvent(float newScale) override;
// bool event(QEvent *event) override;
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
private:
std::optional<SplitOverlayButton> hoveredButton_{};
// fourtf: !!! preserve the order of left, up, right and down
enum HoveredElement {
None,
SplitMove,
SplitLeft,
SplitUp,
SplitRight,
SplitDown
};
class ButtonEventFilter : public QObject
{
SplitOverlay *parent;
HoveredElement hoveredElement;
public:
ButtonEventFilter(SplitOverlay *parent, HoveredElement hoveredElement);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
};
HoveredElement hoveredElement_ = None;
Split *split_;
QPushButton *move_;
QGridLayout *layout_;
QPushButton *left_;
QPushButton *up_;
QPushButton *right_;
QPushButton *down_;
pajlada::Signals::SignalHolder signalHolder_;
friend class ButtonEventFilter;
};
} // namespace chatterino