feat(overlay): inherit zoom and add zoom factor (#6016)

This commit is contained in:
nerix
2025-03-02 15:28:47 +01:00
committed by GitHub
parent 49a6d75180
commit 13dfe716b8
9 changed files with 172 additions and 45 deletions
+100 -30
View File
@@ -3,6 +3,7 @@
#include "Application.hpp"
#include "common/FlagsEnum.hpp"
#include "common/Literals.hpp"
#include "common/QLogging.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
#include "singletons/Emotes.hpp"
#include "singletons/Settings.hpp"
@@ -89,8 +90,11 @@ using namespace std::chrono_literals;
OverlayWindow::OverlayWindow(IndirectChannel channel,
const QList<QUuid> &filterIDs)
: QWidget(nullptr,
Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
: BaseWindow({
BaseWindow::Frameless,
BaseWindow::TopMost,
BaseWindow::DisableLayoutSave,
})
#ifdef Q_OS_WIN
, sizeAllCursor_(::LoadCursor(nullptr, IDC_SIZEALL))
#endif
@@ -123,9 +127,10 @@ OverlayWindow::OverlayWindow(IndirectChannel channel,
this->channelView_.setChannel(this->channel_.get());
this->channelView_.setIsOverlay(true); // use overlay colors
this->channelView_.setAttribute(Qt::WA_TranslucentBackground);
this->holder_.managedConnect(this->channel_.getChannelChanged(), [this]() {
this->channelView_.setChannel(this->channel_.get());
});
this->signalHolder_.managedConnect(
this->channel_.getChannelChanged(), [this]() {
this->channelView_.setChannel(this->channel_.get());
});
this->channelView_.scrollbar()->setHideThumb(true);
this->channelView_.scrollbar()->setHideHighlights(true);
@@ -150,24 +155,40 @@ OverlayWindow::OverlayWindow(IndirectChannel channel,
}
this->applyTheme();
},
this->holder_);
this->signalHolder_);
settings->overlayBackgroundOpacity.connect(
[this] {
this->channelView_.updateColorTheme();
this->update();
},
this->holder_, false);
this->signalHolder_, false);
auto applyIt = [this](auto /*unused*/) {
this->applyTheme();
};
settings->overlayShadowOffsetX.connect(applyIt, this->holder_, false);
settings->overlayShadowOffsetY.connect(applyIt, this->holder_, false);
settings->overlayShadowOpacity.connect(applyIt, this->holder_, false);
settings->overlayShadowRadius.connect(applyIt, this->holder_, false);
settings->overlayShadowColor.connect(applyIt, this->holder_, false);
settings->overlayShadowOffsetX.connect(applyIt, this->signalHolder_, false);
settings->overlayShadowOffsetY.connect(applyIt, this->signalHolder_, false);
settings->overlayShadowOpacity.connect(applyIt, this->signalHolder_, false);
settings->overlayShadowRadius.connect(applyIt, this->signalHolder_, false);
settings->overlayShadowColor.connect(applyIt, this->signalHolder_, false);
this->addShortcuts();
this->signalHolder_.managedConnect(getApp()->getHotkeys()->onItemsUpdated,
[this]() {
this->clearShortcuts();
this->addShortcuts();
});
settings->overlayScaleFactor.connect(
[this] {
this->updateScale();
},
this->signalHolder_, false);
std::ignore = this->scaleChanged.connect([this](float /*scale*/) {
this->channelView_.queueLayout();
});
this->updateScale();
this->triggerFirstActivation();
getApp()->getEmotes()->getGIFTimer().registerOpenOverlayWindow();
}
@@ -197,6 +218,12 @@ void OverlayWindow::applyTheme()
this->update();
}
float OverlayWindow::desiredScale() const
{
return getSettings()->getClampedUiScale() *
getSettings()->getClampedOverlayScale();
}
bool OverlayWindow::eventFilter(QObject * /*object*/, QEvent *event)
{
#ifndef OVERLAY_NATIVE_MOVE
@@ -323,11 +350,9 @@ bool OverlayWindow::nativeEvent(const QByteArray &eventType, void *message,
break;
default:
return QWidget::nativeEvent(eventType, message, result);
return BaseWindow::nativeEvent(eventType, message, result);
}
QWidget::nativeEvent(eventType, message, result);
return returnValue;
}
@@ -464,23 +489,68 @@ void OverlayWindow::triggerFirstActivation()
void OverlayWindow::addShortcuts()
{
auto [seq, allOverlays] = toggleIntertiaShortcut();
if (seq.isEmpty())
{
return;
}
HotkeyController::HotkeyMap actions{
{"zoom",
[](const std::vector<QString> &arguments) -> QString {
if (arguments.size() == 0)
{
qCWarning(chatterinoHotkeys)
<< "zoom shortcut called without arguments. Takes "
"only "
"one argument: \"in\", \"out\", or \"reset\"";
return "zoom shortcut called without arguments. Takes "
"only "
"one argument: \"in\", \"out\", or \"reset\"";
}
auto change = 0.0F;
const auto &direction = arguments.at(0);
if (direction == "reset")
{
getSettings()->uiScale.setValue(1);
return "";
}
auto *shortcut = new QShortcut(seq, this);
if (allOverlays)
if (direction == u"in")
{
change = 0.1F;
}
else if (direction == u"out")
{
change = -0.1F;
}
else
{
qCWarning(chatterinoHotkeys)
<< "Invalid zoom direction, use \"in\", \"out\", or "
"\"reset\"";
return "Invalid zoom direction, use \"in\", \"out\", or "
"\"reset\"";
}
getSettings()->setClampedOverlayScale(
getSettings()->getClampedOverlayScale() + change);
return {};
}},
};
this->shortcuts_ = getApp()->getHotkeys()->shortcutsForCategory(
HotkeyCategory::Window, actions, this);
auto [seq, allOverlays] = toggleIntertiaShortcut();
if (!seq.isEmpty())
{
QObject::connect(shortcut, &QShortcut::activated, this, [] {
getApp()->getWindows()->toggleAllOverlayInertia();
});
}
else
{
QObject::connect(shortcut, &QShortcut::activated, this,
&OverlayWindow::toggleInertia);
auto *inertiaShortcut = new QShortcut(seq, this);
if (allOverlays)
{
QObject::connect(inertiaShortcut, &QShortcut::activated, this, [] {
getApp()->getWindows()->toggleAllOverlayInertia();
});
}
else
{
QObject::connect(inertiaShortcut, &QShortcut::activated, this,
&OverlayWindow::toggleInertia);
}
this->shortcuts_.push_back(inertiaShortcut);
}
}