7#include "decoratedclient.h"
8#include "decoration_p.h"
9#include "decorationbutton.h"
10#include "decorationsettings.h"
11#include "private/decoratedclientprivate.h"
12#include "private/decorationbridge.h"
14#include <QCoreApplication>
23DecorationBridge *findBridge(
const QVariantList &args)
25 for (
const auto &arg : args) {
26 if (
auto bridge = arg.toMap().value(QStringLiteral(
"bridge")).value<DecorationBridge *>()) {
34Decoration::Private::Private(Decoration *deco,
const QVariantList &args)
36 , bridge(findBridge(args))
37 , client(std::shared_ptr<DecoratedClient>(new DecoratedClient(deco, bridge)))
45 if (sectionUnderMouse == section) {
48 sectionUnderMouse = section;
49 Q_EMIT q->sectionUnderMouseChanged(sectionUnderMouse);
52void Decoration::Private::updateSectionUnderMouse(
const QPoint &mousePosition)
54 if (titleBar.contains(mousePosition)) {
58 const QSize size = q->size();
59 const int corner = 2 * settings->largeSpacing();
60 const bool left = mousePosition.
x() < borders.left();
61 const bool top = mousePosition.
y() < borders.top();
62 const bool bottom = size.
height() - mousePosition.
y() <= borders.bottom();
63 const bool right = size.
width() - mousePosition.
x() <= borders.right();
65 if (top && mousePosition.
y() < titleBar.top() + corner) {
67 }
else if (size.
height() - mousePosition.
y() <= borders.bottom() + corner && mousePosition.
y() > titleBar.bottom()) {
75 if (top && mousePosition.
y() < titleBar.top() + corner) {
77 }
else if (size.
height() - mousePosition.
y() <= borders.bottom() + corner && mousePosition.
y() > titleBar.bottom()) {
85 if (mousePosition.
y() > titleBar.bottom()) {
86 if (mousePosition.
x() < borders.left() + corner) {
88 }
else if (size.
width() - mousePosition.
x() <= borders.right() + corner) {
99 if (mousePosition.
y() < titleBar.top()) {
100 if (mousePosition.
x() < borders.left() + corner) {
102 }
else if (size.
width() - mousePosition.
x() <= borders.right() + corner) {
115void Decoration::Private::addButton(DecorationButton *button)
117 Q_ASSERT(!buttons.contains(button));
120 auto it = buttons.begin();
121 while (it != buttons.end()) {
122 if (*it ==
static_cast<DecorationButton *
>(o)) {
123 it = buttons.erase(it);
131Decoration::Decoration(
QObject *parent,
const QVariantList &args)
133 , d(new Private(this, args))
135 connect(
this, &Decoration::bordersChanged,
this, [
this] {
140Decoration::~Decoration() =
default;
144 return d->client.get();
147void Decoration::requestClose()
149 d->client->d->requestClose();
152void Decoration::requestContextHelp()
154 d->client->d->requestContextHelp();
157void Decoration::requestMinimize()
159 d->client->d->requestMinimize();
162void Decoration::requestToggleOnAllDesktops()
164 d->client->d->requestToggleOnAllDesktops();
167void Decoration::requestToggleShade()
169 d->client->d->requestToggleShade();
172void Decoration::requestToggleKeepAbove()
174 d->client->d->requestToggleKeepAbove();
177void Decoration::requestToggleKeepBelow()
179 d->client->d->requestToggleKeepBelow();
182#if KDECORATIONS2_ENABLE_DEPRECATED_SINCE(5, 21)
191 d->client->d->requestShowWindowMenu(
rect);
194void Decoration::requestShowToolTip(
const QString &text)
196 d->client->d->requestShowToolTip(text);
199void Decoration::requestHideToolTip()
201 d->client->d->requestHideToolTip();
206 d->client->d->requestToggleMaximization(buttons);
209void Decoration::showApplicationMenu(
int actionId)
211 const auto it = std::find_if(d->buttons.constBegin(), d->buttons.constEnd(), [](DecorationButton *button) {
212 return button->type() == DecorationButtonType::ApplicationMenu;
214 if (it != d->buttons.constEnd()) {
215 requestShowApplicationMenu((*it)->geometry().toRect(), actionId);
219void Decoration::requestShowApplicationMenu(
const QRect &rect,
int actionId)
221 if (
auto *appMenuEnabledPrivate =
dynamic_cast<ApplicationMenuEnabledDecoratedClientPrivate *
>(d->client->d.get())) {
222 appMenuEnabledPrivate->requestShowApplicationMenu(
rect, actionId);
226void Decoration::setBlurRegion(
const QRegion ®ion)
228 if (d->blurRegion != region) {
229 d->blurRegion = region;
230 Q_EMIT blurRegionChanged();
234void Decoration::setBorders(
const QMargins &borders)
236 if (d->borders != borders) {
237 d->borders = borders;
242void Decoration::setResizeOnlyBorders(
const QMargins &borders)
244 if (d->resizeOnlyBorders != borders) {
245 d->resizeOnlyBorders = borders;
246 Q_EMIT resizeOnlyBordersChanged();
252 if (d->titleBar !=
rect) {
258void Decoration::setOpaque(
bool opaque)
260 if (d->opaque !=
opaque) {
266void Decoration::setShadow(
const std::shared_ptr<DecorationShadow> &shadow)
268 if (d->shadow !=
shadow) {
276 return d->blurRegion;
284QMargins Decoration::resizeOnlyBorders()
const
286 return d->resizeOnlyBorders;
296 return d->sectionUnderMouse;
304bool Decoration::isOpaque()
const
309int Decoration::borderLeft()
const
311 return d->borders.left();
314int Decoration::resizeOnlyBorderLeft()
const
316 return d->resizeOnlyBorders.left();
319int Decoration::borderRight()
const
321 return d->borders.right();
324int Decoration::resizeOnlyBorderRight()
const
326 return d->resizeOnlyBorders.right();
329int Decoration::borderTop()
const
331 return d->borders.top();
334int Decoration::resizeOnlyBorderTop()
const
336 return d->resizeOnlyBorders.top();
339int Decoration::borderBottom()
const
341 return d->borders.bottom();
344int Decoration::resizeOnlyBorderBottom()
const
346 return d->resizeOnlyBorders.bottom();
349QSize Decoration::size()
const
353 (d->client->isShaded() ? 0 : d->client->height()) + b.
top() + b.
bottom());
361bool Decoration::event(
QEvent *event)
363 switch (event->type()) {
365 hoverEnterEvent(
static_cast<QHoverEvent *
>(event));
368 hoverLeaveEvent(
static_cast<QHoverEvent *
>(event));
374 mousePressEvent(
static_cast<QMouseEvent *
>(event));
377 mouseReleaseEvent(
static_cast<QMouseEvent *
>(event));
390void Decoration::hoverEnterEvent(
QHoverEvent *event)
392 for (DecorationButton *button : d->buttons) {
395 auto flooredPos =
QPoint(std::floor(
event->position().x()), std::floor(
event->position().y()));
396 d->updateSectionUnderMouse(flooredPos);
399void Decoration::hoverLeaveEvent(
QHoverEvent *event)
401 for (DecorationButton *button : d->buttons) {
409 for (DecorationButton *button : d->buttons) {
410 if (!button->isEnabled() || !button->isVisible()) {
413 const bool hovered = button->isHovered();
414 const bool contains = button->contains(
event->position());
415 if (!hovered && contains) {
418 }
else if (hovered && !contains) {
421 }
else if (hovered && contains) {
425 auto flooredPos =
QPoint(std::floor(
event->position().x()), std::floor(
event->position().y()));
426 d->updateSectionUnderMouse(flooredPos);
431 for (DecorationButton *button : d->buttons) {
432 if (button->isPressed()) {
440void Decoration::mousePressEvent(
QMouseEvent *event)
442 for (DecorationButton *button : d->buttons) {
443 if (button->isHovered()) {
444 if (button->acceptedButtons().testFlag(
event->button())) {
447 event->setAccepted(
true);
453void Decoration::mouseReleaseEvent(
QMouseEvent *event)
455 for (DecorationButton *button : d->buttons) {
456 if (button->isPressed() && button->acceptedButtons().testFlag(
event->button())) {
462 d->updateSectionUnderMouse(
event->pos());
467 for (DecorationButton *button : d->buttons) {
468 if (button->contains(
event->position())) {
470 event->setAccepted(
true);
475void Decoration::update(
const QRect &r)
480void Decoration::update()
497#include "moc_decoration.cpp"
The Client which gets decorated.
void setSettings(const std::shared_ptr< DecorationSettings > &settings)
Invoked by the framework to set the Settings for this Decoration before init is invoked.
void requestShowWindowMenu(const QRect &rect)
bool opaque
Whether the Decoration is fully opaque.
DecoratedClient * client() const
The DecoratedClient for this Decoration.
std::shared_ptr< DecorationShadow > shadow() const
DecorationShadow for this Decoration.
void setTitleBar(const QRect &rect)
An implementation has to invoke this method whenever the area containing the controls and caption cha...
QRegion blurRegion() const
The decoration's blur region in local coordinates.
QRect titleBar
The titleBar is the area inside the Decoration containing all controls (e.g.
QRect rect() const
The decoration's geometry in local coordinates.
std::shared_ptr< DecorationSettings > settings() const
Qt::WindowFrameSection sectionUnderMouse
This property denotes the part of the Decoration which is currently under the mouse pointer.
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
Framework for creating window decorations.
QCoreApplication * instance()
bool sendEvent(QObject *receiver, QEvent *event)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
virtual bool event(QEvent *e)
bool isNull() const const
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)