mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added new overlay for splits when you hold alt that does nothing yet
This commit is contained in:
parent
f695a41c6c
commit
463a1f1945
15 changed files with 274 additions and 12 deletions
|
@ -194,7 +194,8 @@ SOURCES += \
|
|||
src/widgets/helper/editablemodelview.cpp \
|
||||
src/controllers/accounts/accountcontroller.cpp \
|
||||
src/controllers/accounts/accountmodel.cpp \
|
||||
src/controllers/accounts/account.cpp
|
||||
src/controllers/accounts/account.cpp \
|
||||
src/widgets/helper/splitoverlay.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/precompiled_header.hpp \
|
||||
|
@ -336,7 +337,8 @@ HEADERS += \
|
|||
src/controllers/accounts/accountcontroller.hpp \
|
||||
src/controllers/accounts/accountmodel.hpp \
|
||||
src/controllers/accounts/account.hpp \
|
||||
src/util/sharedptrelementless.hpp
|
||||
src/util/sharedptrelementless.hpp \
|
||||
src/widgets/helper/splitoverlay.hpp
|
||||
|
||||
RESOURCES += \
|
||||
resources/resources.qrc
|
||||
|
|
BIN
resources/images/split/splitdown.png
Normal file
BIN
resources/images/split/splitdown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 793 B |
BIN
resources/images/split/splitleft.png
Normal file
BIN
resources/images/split/splitleft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 812 B |
BIN
resources/images/split/splitmove.png
Normal file
BIN
resources/images/split/splitmove.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
resources/images/split/splitright.png
Normal file
BIN
resources/images/split/splitright.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 811 B |
BIN
resources/images/split/splitup.png
Normal file
BIN
resources/images/split/splitup.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 793 B |
|
@ -46,6 +46,11 @@
|
|||
<file>images/about.svg</file>
|
||||
<file>images/moderatormode_disabled.png</file>
|
||||
<file>images/moderatormode_enabled.png</file>
|
||||
<file>images/split/splitdown.png</file>
|
||||
<file>images/split/splitleft.png</file>
|
||||
<file>images/split/splitright.png</file>
|
||||
<file>images/split/splitup.png</file>
|
||||
<file>images/split/splitmove.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/qt/etc">
|
||||
<file>qt.conf</file>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "resourcemanager.hpp"
|
||||
#include "util/urlfetch.hpp"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
|
||||
namespace chatterino {
|
||||
|
@ -288,6 +289,11 @@ ResourceManager::ResourceManager()
|
|||
, buttonBan(lli(":/images/button_ban.png", 0.25))
|
||||
, buttonTimeout(lli(":/images/button_timeout.png", 0.25))
|
||||
{
|
||||
this->split.left = QIcon(":/images/split/splitleft.png");
|
||||
this->split.right = QIcon(":/images/split/splitright.png");
|
||||
this->split.up = QIcon(":/images/split/splitup.png");
|
||||
this->split.down = QIcon(":/images/split/splitdown.png");
|
||||
this->split.move = QIcon(":/images/split/splitmove.png");
|
||||
qDebug() << "init ResourceManager";
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,14 @@ public:
|
|||
|
||||
void initialize();
|
||||
|
||||
struct {
|
||||
QIcon left;
|
||||
QIcon right;
|
||||
QIcon up;
|
||||
QIcon down;
|
||||
QIcon move;
|
||||
} split;
|
||||
|
||||
messages::Image *badgeStaff;
|
||||
messages::Image *badgeAdmin;
|
||||
messages::Image *badgeGlobalModerator;
|
||||
|
|
|
@ -111,7 +111,7 @@ void BaseWidget::childEvent(QChildEvent *event)
|
|||
|
||||
void BaseWidget::showEvent(QShowEvent *)
|
||||
{
|
||||
this->scaleChangedEvent(this->getScale());
|
||||
this->setScale(this->getScale());
|
||||
this->themeRefreshEvent();
|
||||
}
|
||||
|
||||
|
|
152
src/widgets/helper/splitoverlay.cpp
Normal file
152
src/widgets/helper/splitoverlay.cpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
#include "splitoverlay.hpp"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QGraphicsOpacityEffect>
|
||||
#include <QGridLayout>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "application.hpp"
|
||||
#include "singletons/resourcemanager.hpp"
|
||||
#include "widgets/split.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
SplitOverlay::SplitOverlay(Split *parent)
|
||||
: BaseWidget(parent)
|
||||
, split(parent)
|
||||
{
|
||||
QGridLayout *layout = new QGridLayout(this);
|
||||
layout->setMargin(1);
|
||||
layout->setSpacing(1);
|
||||
|
||||
layout->setRowStretch(1, 1);
|
||||
layout->setRowStretch(3, 1);
|
||||
layout->setColumnStretch(1, 1);
|
||||
layout->setColumnStretch(3, 1);
|
||||
|
||||
QPushButton *move = new QPushButton(getApp()->resources->split.move, QString());
|
||||
QPushButton *left = new QPushButton(getApp()->resources->split.left, QString());
|
||||
QPushButton *right = new QPushButton(getApp()->resources->split.right, QString());
|
||||
QPushButton *up = new QPushButton(getApp()->resources->split.up, QString());
|
||||
QPushButton *down = new QPushButton(getApp()->resources->split.down, QString());
|
||||
|
||||
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));
|
||||
|
||||
move->setFlat(true);
|
||||
left->setFlat(true);
|
||||
right->setFlat(true);
|
||||
up->setFlat(true);
|
||||
down->setFlat(true);
|
||||
|
||||
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);
|
||||
|
||||
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));
|
||||
|
||||
move->setFocusPolicy(Qt::NoFocus);
|
||||
left->setFocusPolicy(Qt::NoFocus);
|
||||
right->setFocusPolicy(Qt::NoFocus);
|
||||
up->setFocusPolicy(Qt::NoFocus);
|
||||
down->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
move->setCursor(Qt::SizeAllCursor);
|
||||
|
||||
this->managedConnect(this->scaleChanged, [=](float scale) {
|
||||
int a = scale * 40;
|
||||
QSize size(a, a);
|
||||
|
||||
move->setIconSize(size);
|
||||
left->setIconSize(size);
|
||||
right->setIconSize(size);
|
||||
up->setIconSize(size);
|
||||
down->setIconSize(size);
|
||||
});
|
||||
}
|
||||
|
||||
void SplitOverlay::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.fillRect(this->rect(), QColor(0, 0, 0, 90));
|
||||
|
||||
QRect rect;
|
||||
switch (this->hoveredElement) {
|
||||
case SplitLeft: {
|
||||
rect = QRect(0, 0, this->width() / 2, this->height());
|
||||
} break;
|
||||
case SplitRight: {
|
||||
rect = QRect(this->width() / 2, 0, this->width() / 2, this->height());
|
||||
} break;
|
||||
case SplitUp: {
|
||||
rect = QRect(0, 0, this->width(), this->height() / 2);
|
||||
} break;
|
||||
case SplitDown: {
|
||||
rect = QRect(0, this->height() / 2, this->width(), this->height() / 2);
|
||||
} break;
|
||||
}
|
||||
if (!rect.isNull()) {
|
||||
painter.setPen(QColor(0, 148, 255, 0x70));
|
||||
painter.setBrush(QColor(0, 148, 255, 0x30));
|
||||
painter.drawRect(rect);
|
||||
}
|
||||
}
|
||||
|
||||
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(1);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
40
src/widgets/helper/splitoverlay.hpp
Normal file
40
src/widgets/helper/splitoverlay.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include "pajlada/signals/signalholder.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
class Split;
|
||||
|
||||
class SplitOverlay : public BaseWidget, pajlada::Signals::SignalHolder
|
||||
{
|
||||
public:
|
||||
explicit SplitOverlay(Split *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
enum HoveredElement { None, SplitMove, SplitLeft, SplitRight, SplitUp, SplitDown };
|
||||
HoveredElement hoveredElement = None;
|
||||
Split *split;
|
||||
|
||||
class ButtonEventFilter : public QObject
|
||||
{
|
||||
HoveredElement hoveredElement;
|
||||
SplitOverlay *parent;
|
||||
|
||||
public:
|
||||
ButtonEventFilter(SplitOverlay *parent, HoveredElement hoveredElement);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
};
|
||||
|
||||
friend class ButtonEventFilter;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
|
@ -13,6 +13,7 @@
|
|||
#include "widgets/helper/debugpopup.hpp"
|
||||
#include "widgets/helper/searchpopup.hpp"
|
||||
#include "widgets/helper/shortcut.hpp"
|
||||
#include "widgets/helper/splitoverlay.hpp"
|
||||
#include "widgets/qualitypopup.hpp"
|
||||
#include "widgets/selectchanneldialog.hpp"
|
||||
#include "widgets/splitcontainer.hpp"
|
||||
|
@ -38,6 +39,9 @@ using namespace chatterino::messages;
|
|||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
pajlada::Signals::Signal<bool> Split::altPressedStatusChanged;
|
||||
bool Split::altPressesStatus = false;
|
||||
|
||||
Split::Split(SplitContainer *parent)
|
||||
: Split((QWidget *)parent)
|
||||
{
|
||||
|
@ -52,6 +56,7 @@ Split::Split(QWidget *parent)
|
|||
, header(this)
|
||||
, view(this)
|
||||
, input(this)
|
||||
, overlay(new SplitOverlay(this))
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
|
@ -119,8 +124,17 @@ Split::Split(QWidget *parent)
|
|||
this->managedConnections);
|
||||
|
||||
this->header.updateModerationModeIcon();
|
||||
this->overlay->hide();
|
||||
|
||||
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
|
||||
this->managedConnect(altPressedStatusChanged, [this](bool status) {
|
||||
if (status && this->isMouseOver) {
|
||||
this->overlay->show();
|
||||
} else {
|
||||
this->overlay->hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Split::~Split()
|
||||
|
@ -287,15 +301,39 @@ void Split::keyReleaseEvent(QKeyEvent *event)
|
|||
this->handleModifiers(event, event->modifiers());
|
||||
}
|
||||
|
||||
void Split::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
BaseWidget::resizeEvent(event);
|
||||
|
||||
this->overlay->setGeometry(this->rect());
|
||||
}
|
||||
|
||||
void Split::enterEvent(QEvent *event)
|
||||
{
|
||||
this->isMouseOver = true;
|
||||
if (altPressesStatus) {
|
||||
this->overlay->show();
|
||||
}
|
||||
}
|
||||
|
||||
void Split::leaveEvent(QEvent *event)
|
||||
{
|
||||
this->isMouseOver = false;
|
||||
this->overlay->hide();
|
||||
}
|
||||
|
||||
void Split::handleModifiers(QEvent *event, Qt::KeyboardModifiers modifiers)
|
||||
{
|
||||
if (modifiers == Qt::AltModifier) {
|
||||
this->setCursor(Qt::SizeAllCursor);
|
||||
event->accept();
|
||||
// } else if (modifiers == Qt::ControlModifier) {
|
||||
// this->setCursor(Qt::SplitHCursor);
|
||||
// event->accept();
|
||||
if (!altPressesStatus) {
|
||||
altPressesStatus = true;
|
||||
altPressedStatusChanged.invoke(true);
|
||||
}
|
||||
} else {
|
||||
if (altPressesStatus) {
|
||||
altPressesStatus = false;
|
||||
altPressedStatusChanged.invoke(false);
|
||||
}
|
||||
this->setCursor(Qt::ArrowCursor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace chatterino {
|
|||
namespace widgets {
|
||||
|
||||
class SplitContainer;
|
||||
class SplitOverlay;
|
||||
|
||||
// Each ChatWidget consists of three sub-elements that handle their own part of the chat widget:
|
||||
// ChatWidgetHeader
|
||||
|
@ -32,12 +33,15 @@ class SplitContainer;
|
|||
// - Responsible for rendering and handling user text input
|
||||
//
|
||||
// Each sub-element has a reference to the parent Chat Widget
|
||||
class Split : public BaseWidget
|
||||
class Split : public BaseWidget, pajlada::Signals::SignalHolder
|
||||
{
|
||||
friend class SplitInput;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
static pajlada::Signals::Signal<bool> altPressedStatusChanged;
|
||||
static bool altPressesStatus;
|
||||
|
||||
public:
|
||||
explicit Split(SplitContainer *parent);
|
||||
explicit Split(QWidget *parent);
|
||||
|
@ -81,6 +85,9 @@ protected:
|
|||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void keyReleaseEvent(QKeyEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void enterEvent(QEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
|
||||
private:
|
||||
SplitContainer *container;
|
||||
|
@ -90,11 +97,15 @@ private:
|
|||
SplitHeader header;
|
||||
ChannelView view;
|
||||
SplitInput input;
|
||||
SplitOverlay *overlay;
|
||||
|
||||
double flexSizeX = 1;
|
||||
double flexSizeY = 1;
|
||||
|
||||
bool moderationMode = false;
|
||||
|
||||
bool isMouseOver = false;
|
||||
|
||||
pajlada::Signals::Connection channelIDChangedConnection;
|
||||
pajlada::Signals::Connection usermodeChangedConnection;
|
||||
pajlada::Signals::Connection indirectChannelChangedConnection;
|
||||
|
|
|
@ -138,9 +138,9 @@ void Window::refreshWindowTitle(const QString &username)
|
|||
this->setWindowTitle(username + " - Chatterino for Twitch");
|
||||
}
|
||||
|
||||
bool Window::event(QEvent *e)
|
||||
bool Window::event(QEvent *event)
|
||||
{
|
||||
switch (e->type()) {
|
||||
switch (event->type()) {
|
||||
case QEvent::WindowActivate:
|
||||
break;
|
||||
|
||||
|
@ -156,7 +156,7 @@ bool Window::event(QEvent *e)
|
|||
}
|
||||
} break;
|
||||
};
|
||||
return BaseWindow::event(e);
|
||||
return BaseWindow::event(event);
|
||||
}
|
||||
|
||||
void Window::closeEvent(QCloseEvent *event)
|
||||
|
|
Loading…
Reference in a new issue