Changeset View
Changeset View
Standalone View
Standalone View
kcms/touchpadx/src/kcm/xlib/testbutton.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2013 Alexander Mezin <mezin.alexander@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #include "testbutton.h" | ||||
20 | | ||||
21 | #include <QMouseEvent> | ||||
22 | #include <QTimer> | ||||
23 | | ||||
24 | #include <KLocalizedString> | ||||
25 | | ||||
26 | TestButton::TestButton(QWidget *parent) | ||||
27 | : QPushButton(parent), m_firstClick(true) | ||||
28 | { | ||||
29 | } | ||||
30 | | ||||
31 | void TestButton::mousePressEvent(QMouseEvent *e) | ||||
32 | { | ||||
33 | if (m_firstClick) { | ||||
34 | m_originalText = text(); | ||||
35 | m_firstClick = false; | ||||
36 | } | ||||
37 | | ||||
38 | switch (e->button()) { | ||||
39 | case Qt::LeftButton: | ||||
40 | setText(i18nc("Mouse button", "Left button")); | ||||
41 | break; | ||||
42 | case Qt::RightButton: | ||||
43 | setText(i18nc("Mouse button", "Right button")); | ||||
44 | break; | ||||
45 | case Qt::MiddleButton: | ||||
46 | setText(i18nc("Mouse button", "Middle button")); | ||||
47 | break; | ||||
48 | default: | ||||
49 | break; | ||||
50 | } | ||||
51 | | ||||
52 | QTimer::singleShot(500, this, SLOT(resetText())); | ||||
53 | | ||||
54 | QPushButton::mousePressEvent(e); | ||||
55 | } | ||||
56 | | ||||
57 | void TestButton::resetText() | ||||
58 | { | ||||
59 | setText(m_originalText); | ||||
60 | } |