2018-06-26 14:09:39 +02:00
|
|
|
#include "SplitOverlay.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "Application.hpp"
|
|
|
|
#include "singletons/Resources.hpp"
|
|
|
|
#include "singletons/Theme.hpp"
|
|
|
|
#include "widgets/splits/Split.hpp"
|
|
|
|
#include "widgets/splits/SplitContainer.hpp"
|
|
|
|
|
2018-05-08 15:12:04 +02:00
|
|
|
#include <QEvent>
|
2018-06-07 17:43:21 +02:00
|
|
|
#include <QGraphicsBlurEffect>
|
|
|
|
#include <QGraphicsEffect>
|
2018-05-08 15:12:04 +02:00
|
|
|
#include <QGraphicsOpacityEffect>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPushButton>
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-01-14 13:09:07 +01:00
|
|
|
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
|
|
|
|
|
2018-05-08 15:12:04 +02:00
|
|
|
namespace chatterino {
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-08 15:12:04 +02:00
|
|
|
SplitOverlay::SplitOverlay(Split *parent)
|
|
|
|
: BaseWidget(parent)
|
2018-07-06 19:23:47 +02:00
|
|
|
, split_(parent)
|
2018-05-08 15:12:04 +02:00
|
|
|
{
|
2024-01-14 13:09:07 +01:00
|
|
|
auto *layout = new QGridLayout(this);
|
2022-11-10 20:11:40 +01:00
|
|
|
layout->setContentsMargins(1, 1, 1, 1);
|
2018-05-08 15:12:04 +02:00
|
|
|
layout->setSpacing(1);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-08 15:12:04 +02:00
|
|
|
layout->setRowStretch(1, 1);
|
|
|
|
layout->setRowStretch(3, 1);
|
|
|
|
layout->setColumnStretch(1, 1);
|
|
|
|
layout->setColumnStretch(3, 1);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-01-14 13:09:07 +01:00
|
|
|
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, {});
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
this->move_->setFlat(true);
|
|
|
|
this->left_->setFlat(true);
|
|
|
|
this->right_->setFlat(true);
|
|
|
|
this->up_->setFlat(true);
|
|
|
|
this->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);
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-17 14:47:23 +02:00
|
|
|
this->setMouseTracking(true);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-25 16:11:03 +02:00
|
|
|
this->setCursor(Qt::ArrowCursor);
|
2018-05-08 15:12:04 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-01-14 13:09:07 +01:00
|
|
|
void SplitOverlay::setHoveredButton(
|
|
|
|
std::optional<SplitOverlayButton> hoveredButton)
|
2018-05-08 15:12:04 +02:00
|
|
|
{
|
2024-01-14 13:09:07 +01:00
|
|
|
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;
|
|
|
|
|
2018-05-08 15:12:04 +02:00
|
|
|
QPainter painter(this);
|
2018-07-06 17:11:37 +02:00
|
|
|
if (this->theme->isLightTheme())
|
|
|
|
{
|
2018-06-07 17:43:21 +02:00
|
|
|
painter.fillRect(this->rect(), QColor(255, 255, 255, 200));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
painter.fillRect(this->rect(), QColor(0, 0, 0, 150));
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-01-14 13:09:07 +01:00
|
|
|
if (!this->hoveredButton_.has_value())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-08 15:12:04 +02:00
|
|
|
QRect rect;
|
2024-01-14 13:09:07 +01:00
|
|
|
auto hoveredButton = this->hoveredButton_.value();
|
|
|
|
switch (hoveredButton)
|
2018-07-06 19:23:47 +02:00
|
|
|
{
|
2024-01-14 13:09:07 +01:00
|
|
|
case SplitOverlayButton::Left: {
|
2018-05-08 15:12:04 +02:00
|
|
|
rect = QRect(0, 0, this->width() / 2, this->height());
|
|
|
|
}
|
|
|
|
break;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-01-14 13:09:07 +01:00
|
|
|
case SplitOverlayButton::Right: {
|
2018-05-08 15:12:04 +02:00
|
|
|
rect =
|
|
|
|
QRect(this->width() / 2, 0, this->width() / 2, this->height());
|
|
|
|
}
|
|
|
|
break;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-01-14 13:09:07 +01:00
|
|
|
case SplitOverlayButton::Up: {
|
2018-05-08 15:12:04 +02:00
|
|
|
rect = QRect(0, 0, this->width(), this->height() / 2);
|
|
|
|
}
|
|
|
|
break;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-01-14 13:09:07 +01:00
|
|
|
case SplitOverlayButton::Down: {
|
2018-05-08 15:12:04 +02:00
|
|
|
rect =
|
|
|
|
QRect(0, this->height() / 2, this->width(), this->height() / 2);
|
|
|
|
}
|
|
|
|
break;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-25 16:11:03 +02:00
|
|
|
default:;
|
2018-05-08 15:12:04 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-08 15:12:04 +02:00
|
|
|
if (!rect.isNull())
|
|
|
|
{
|
2024-01-14 13:09:07 +01:00
|
|
|
rect.setRight(rect.right() - 1);
|
|
|
|
rect.setBottom(rect.bottom() - 1);
|
2024-01-19 17:59:55 +01:00
|
|
|
painter.setPen(getIApp()->getThemes()->splits.dropPreviewBorder);
|
|
|
|
painter.setBrush(getIApp()->getThemes()->splits.dropPreview);
|
2018-05-08 15:12:04 +02:00
|
|
|
painter.drawRect(rect);
|
|
|
|
}
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-10 23:58:07 +02:00
|
|
|
void SplitOverlay::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
2024-01-14 13:09:07 +01:00
|
|
|
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;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->left_->setVisible(wideEnough);
|
|
|
|
this->right_->setVisible(wideEnough);
|
|
|
|
this->up_->setVisible(highEnough);
|
|
|
|
this->down_->setVisible(highEnough);
|
2018-05-10 23:58:07 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-17 14:47:23 +02:00
|
|
|
void SplitOverlay::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
2018-05-17 16:39:38 +02:00
|
|
|
BaseWidget::mouseMoveEvent(event);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-17 16:39:38 +02:00
|
|
|
// if ((QGuiApplication::queryKeyboardModifiers() & Qt::AltModifier) ==
|
|
|
|
// Qt::AltModifier) {
|
|
|
|
// this->hide();
|
|
|
|
// }
|
2018-05-17 14:47:23 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-08 15:12:04 +02:00
|
|
|
} // namespace chatterino
|