7#include "decoratedwindow.h"
8#include "decoration_p.h"
9#include "decorationbutton.h"
10#include "decorationsettings.h"
11#include "private/decoratedwindowprivate.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<DecoratedWindow>(new DecoratedWindow(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 d->client->d->requestShowApplicationMenu(
rect, actionId);
224void Decoration::setBlurRegion(
const QRegion ®ion)
226 if (d->blurRegion != region) {
227 d->blurRegion = region;
228 Q_EMIT blurRegionChanged();
232void Decoration::setBorders(
const QMargins &borders)
234 if (d->borders != borders) {
235 d->borders = borders;
240void Decoration::setResizeOnlyBorders(
const QMargins &borders)
242 if (d->resizeOnlyBorders != borders) {
243 d->resizeOnlyBorders = borders;
244 Q_EMIT resizeOnlyBordersChanged();
250 if (d->titleBar !=
rect) {
256void Decoration::setOpaque(
bool opaque)
258 if (d->opaque !=
opaque) {
264void Decoration::setShadow(
const std::shared_ptr<DecorationShadow> &shadow)
266 if (d->shadow !=
shadow) {
274 return d->blurRegion;
282QMargins Decoration::resizeOnlyBorders()
const
284 return d->resizeOnlyBorders;
294 return d->sectionUnderMouse;
302bool Decoration::isOpaque()
const
307int Decoration::borderLeft()
const
309 return d->borders.left();
312int Decoration::resizeOnlyBorderLeft()
const
314 return d->resizeOnlyBorders.left();
317int Decoration::borderRight()
const
319 return d->borders.right();
322int Decoration::resizeOnlyBorderRight()
const
324 return d->resizeOnlyBorders.right();
327int Decoration::borderTop()
const
329 return d->borders.top();
332int Decoration::resizeOnlyBorderTop()
const
334 return d->resizeOnlyBorders.top();
337int Decoration::borderBottom()
const
339 return d->borders.bottom();
342int Decoration::resizeOnlyBorderBottom()
const
344 return d->resizeOnlyBorders.bottom();
347QSize Decoration::size()
const
351 (d->client->isShaded() ? 0 : d->client->height()) + b.
top() + b.
bottom());
359bool Decoration::event(
QEvent *event)
361 switch (event->type()) {
363 hoverEnterEvent(
static_cast<QHoverEvent *
>(event));
366 hoverLeaveEvent(
static_cast<QHoverEvent *
>(event));
372 mousePressEvent(
static_cast<QMouseEvent *
>(event));
375 mouseReleaseEvent(
static_cast<QMouseEvent *
>(event));
388void Decoration::hoverEnterEvent(
QHoverEvent *event)
390 for (DecorationButton *button : d->buttons) {
393 auto flooredPos =
QPoint(std::floor(
event->position().x()), std::floor(
event->position().y()));
394 d->updateSectionUnderMouse(flooredPos);
397void Decoration::hoverLeaveEvent(
QHoverEvent *event)
399 for (DecorationButton *button : d->buttons) {
407 for (DecorationButton *button : d->buttons) {
408 if (!button->isEnabled() || !button->isVisible()) {
411 const bool hovered = button->isHovered();
412 const bool contains = button->contains(
event->position());
413 if (!hovered && contains) {
416 }
else if (hovered && !contains) {
419 }
else if (hovered && contains) {
423 auto flooredPos =
QPoint(std::floor(
event->position().x()), std::floor(
event->position().y()));
424 d->updateSectionUnderMouse(flooredPos);
429 for (DecorationButton *button : d->buttons) {
430 if (button->isPressed()) {
438void Decoration::mousePressEvent(
QMouseEvent *event)
440 for (DecorationButton *button : d->buttons) {
441 if (button->isHovered()) {
442 if (button->acceptedButtons().testFlag(
event->button())) {
445 event->setAccepted(
true);
451void Decoration::mouseReleaseEvent(
QMouseEvent *event)
453 for (DecorationButton *button : d->buttons) {
454 if (button->isPressed() && button->acceptedButtons().testFlag(
event->button())) {
460 d->updateSectionUnderMouse(
event->pos());
465 for (DecorationButton *button : d->buttons) {
466 if (button->contains(
event->position())) {
468 event->setAccepted(
true);
473void Decoration::update(
const QRect &r)
478void Decoration::update()
495#include "moc_decoration.cpp"
The Client which gets decorated.
DecoratedWindow * window() const
The DecoratedWindow for this Decoration.
QRect titleBar
The titleBar is the area inside the Decoration containing all controls (e.g.
void requestShowWindowMenu(const QRect &rect)
void setSettings(const std::shared_ptr< DecorationSettings > &settings)
Invoked by the framework to set the Settings for this Decoration before init is invoked.
QRegion blurRegion() const
The decoration's blur region in local coordinates.
Qt::WindowFrameSection sectionUnderMouse
This property denotes the part of the Decoration which is currently under the mouse pointer.
std::shared_ptr< DecorationSettings > settings() const
void setTitleBar(const QRect &rect)
An implementation has to invoke this method whenever the area containing the controls and caption cha...
bool opaque
Whether the Decoration is fully opaque.
std::shared_ptr< DecorationShadow > shadow() const
DecorationShadow for this Decoration.
QRect rect() const
The decoration's geometry in local coordinates.
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)