CalendarSupport

messagewidget.cpp
1/*
2 This file is part of KOrganizer.
3
4 SPDX-FileCopyrightText: 2013 Sérgio Martins <iamsergio@gmail.com>
5
6 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
7*/
8
9#include "messagewidget.h"
10
11#include <QApplication>
12#include <QKeyEvent>
13
14using namespace CalendarSupport;
15
16MessageWidget::MessageWidget(QWidget *parent)
17 : KMessageWidget(parent)
18{
19 hide();
20 setCloseButtonVisible(false);
21 setWordWrap(true);
22}
23
24MessageWidget::~MessageWidget() = default;
25
26void MessageWidget::showEvent(QShowEvent *event)
27{
28 qApp->installEventFilter(this);
30}
31
32void MessageWidget::hideEvent(QHideEvent *event)
33{
34 // No need to spend cycles on an event-filter when this is going to
35 // me hidden most of the time
36 qApp->removeEventFilter(this);
38}
39
40bool MessageWidget::eventFilter(QObject *, QEvent *event)
41{
42 if (event->type() == QEvent::MouseButtonPress) {
43 hide();
44 }
45
46 if (event->type() == QEvent::KeyPress) {
47 auto ev = static_cast<QKeyEvent *>(event);
48 hide();
49 if (ev->key() == Qt::Key_Escape) {
50 return true; // We eat this one, it's for us
51 }
52 }
53
54 return false; // we don't want it
55}
56
57#include "moc_messagewidget.cpp"
MouseButtonPress
virtual bool event(QEvent *e) override
Key_Escape
void hide()
virtual void hideEvent(QHideEvent *event)
virtual void showEvent(QShowEvent *event)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:28 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.