Akonadi Contacts

waitingoverlay.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "waitingoverlay_p.h"
10
11#include <KJob>
12#include <KLocalizedString>
13
14#include <QBoxLayout>
15#include <QEvent>
16#include <QLabel>
17#include <QPalette>
18
19//@cond PRIVATE
20using namespace Akonadi;
21WaitingOverlay::WaitingOverlay(KJob *job, QWidget *baseWidget, QWidget *parent)
22 : QWidget(parent ? parent : baseWidget->window())
23 , mBaseWidget(baseWidget)
24{
25 Q_ASSERT(baseWidget);
26 Q_ASSERT(parentWidget() != baseWidget);
27
30 mPreviousState = mBaseWidget->isEnabled();
31
32 QBoxLayout *topLayout = new QVBoxLayout(this);
33 topLayout->addStretch();
34 auto description = new QLabel(this);
35 description->setText(i18n("<p style=\"color: white;\"><b>Waiting for operation</b><br/></p>"));
36 description->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
37 topLayout->addWidget(description);
38 topLayout->addStretch();
39
40 QPalette p = palette();
41 p.setColor(backgroundRole(), QColor(0, 0, 0, 128));
42 setPalette(p);
43 setAutoFillBackground(true);
44
45 mBaseWidget->installEventFilter(this);
46
47 reposition();
48}
49
50WaitingOverlay::~WaitingOverlay()
51{
52 if (mBaseWidget) {
53 mBaseWidget->setEnabled(mPreviousState);
54 }
55}
56
57void WaitingOverlay::reposition()
58{
59 if (!mBaseWidget) {
60 return;
61 }
62
63 // reparent to the current top level widget of the base widget if needed
64 // needed eg. in dock widgets
65 if (parentWidget() != mBaseWidget->window()) {
66 setParent(mBaseWidget->window());
67 }
68
69 // follow base widget visibility
70 // needed eg. in tab widgets
71 if (!mBaseWidget->isVisible()) {
72 hide();
73 return;
74 }
75 show();
76
77 // follow position changes
78 const QPoint topLevelPos = mBaseWidget->mapTo(window(), QPoint(0, 0));
79 const QPoint parentPos = parentWidget()->mapFrom(window(), topLevelPos);
80 move(parentPos);
81
82 // follow size changes
83 // TODO: hide/scale icon if we don't have enough space
84 resize(mBaseWidget->size());
85}
86
87bool WaitingOverlay::eventFilter(QObject *object, QEvent *event)
88{
89 if (object == mBaseWidget
90 && (event->type() == QEvent::Move || event->type() == QEvent::Resize || event->type() == QEvent::Show || event->type() == QEvent::Hide
91 || event->type() == QEvent::ParentChange)) {
92 reposition();
93 }
94 return QWidget::eventFilter(object, event);
95}
96
97//@endcond
98
99#include "moc_waitingoverlay_p.cpp"
void result(KJob *job)
QString i18n(const char *text, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
A widget for editing the display name of a contact.
KIOCORE_EXPORT CopyJob * move(const QList< QUrl > &src, const QUrl &dest, JobFlags flags=DefaultFlags)
QWidget * window(QObject *job)
void addStretch(int stretch)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void deleteLater()
void destroyed(QObject *obj)
virtual bool eventFilter(QObject *watched, QEvent *event)
void setColor(ColorGroup group, ColorRole role, const QColor &color)
AlignHCenter
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.