| 1 |
/****************************************************************************** |
| 2 |
* |
| 3 |
* Copyright (C) 1997-2019 by Dimitri van Heesch. |
| 4 |
* |
| 5 |
* Permission to use, copy, modify, and distribute this software and its |
| 6 |
* documentation under the terms of the GNU General Public License is hereby |
| 7 |
* granted. No representations are made about the suitability of this software |
| 8 |
* for any purpose. It is provided "as is" without express or implied warranty. |
| 9 |
* See the GNU General Public License for more details. |
| 10 |
* |
| 11 |
*/ |
| 12 |
|
| 13 |
#ifndef HELPLABEL_H |
| 14 |
#define HELPLABEL_H |
| 15 |
|
| 16 |
#include <QLabel> |
| 17 |
#include <QMenu> |
| 18 |
|
| 19 |
class HelpLabel : public QLabel |
| 20 |
{ |
| 21 |
Q_OBJECT |
| 22 |
public: |
| 23 |
HelpLabel(const QString &text) : QLabel(text) |
| 24 |
{ setContextMenuPolicy(Qt::CustomContextMenu); |
| 25 |
connect(this,SIGNAL(customContextMenuRequested(const QPoint&)), |
| 26 |
this,SLOT(showMenu(const QPoint&))); |
| 27 |
} |
| 28 |
signals: |
| 29 |
void enter(); |
| 30 |
void reset(); |
| 31 |
private slots: |
| 32 |
void showMenu(const QPoint &p) |
| 33 |
{ |
| 34 |
QMenu menu(this); |
| 35 |
QAction *a = menu.addAction(tr("Reset to default")); |
| 36 |
if (menu.exec(mapToGlobal(p))==a) |
| 37 |
{ |
| 38 |
reset(); |
| 39 |
} |
| 40 |
} |
| 41 |
protected: |
| 42 |
void enterEvent( |
| 43 |
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 44 |
QEvent * event |
| 45 |
#else |
| 46 |
QEnterEvent * event |
| 47 |
#endif |
| 48 |
) { enter(); QLabel::enterEvent(event); } |
| 49 |
}; |
| 50 |
|
| 51 |
#endif |