CalendarSupport

messagewidget.cpp
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2013 Sérgio Martins <[email protected]>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 #include "messagewidget.h"
26 
27 #include <QApplication>
28 #include <QKeyEvent>
29 
30 using namespace CalendarSupport;
31 
32 MessageWidget::MessageWidget(QWidget *parent) : KMessageWidget(parent)
33 {
34  hide();
35  setCloseButtonVisible(false);
36  setWordWrap(true);
37 }
38 
39 MessageWidget::~MessageWidget()
40 {
41 }
42 
43 void MessageWidget::showEvent(QShowEvent *event)
44 {
45  qApp->installEventFilter(this);
47 }
48 
49 void MessageWidget::hideEvent(QHideEvent *event)
50 {
51  // No need to spend cycles on an event-filter when this is going to
52  // me hidden most of the time
53  qApp->removeEventFilter(this);
55 }
56 
57 bool MessageWidget::eventFilter(QObject *, QEvent *event)
58 {
59  if (event->type() == QEvent::MouseButtonPress) {
60  hide();
61  }
62 
63  if (event->type() == QEvent::KeyPress) {
64  QKeyEvent *ev = static_cast<QKeyEvent *>(event);
65  hide();
66  if (ev->key() == Qt::Key_Escape) {
67  return true; // We eat this one, it's for us
68  }
69  }
70 
71  return false; // we don't want it
72 }
MouseButtonPress
QEvent::Type type() const const
virtual void showEvent(QShowEvent *event)
virtual void hideEvent(QHideEvent *event)
void hide()
int key() const const
virtual bool event(QEvent *e) override
Key_Escape
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:08:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.