| 1 | /**************************************************************************************** | 
|---|
| 2 | ** Copyright (C) 2016-2020  Francesc Martinez <es.linkedin.com/in/cescmm/en> | 
|---|
| 3 | ** | 
|---|
| 4 | ** This file is part of DietPlanner. | 
|---|
| 5 | ** DietPlanner is an application to create, edit and manage diets, food and patients. | 
|---|
| 6 | ** | 
|---|
| 7 | ** This application is free software; you can redistribute it and/or | 
|---|
| 8 | ** modify it under the terms of the GNU Lesser General Public | 
|---|
| 9 | ** License as published by the Free Software Foundation; either | 
|---|
| 10 | ** version 3 of the License, or (at your option) any later version. | 
|---|
| 11 | ** | 
|---|
| 12 | ** This application is distributed in the hope that it will be useful, | 
|---|
| 13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 15 | ** Lesser General Public License for more details. | 
|---|
| 16 | ** | 
|---|
| 17 | ** You should have received a copy of the GNU Lesser General Public | 
|---|
| 18 | ** License along with this library; if not, write to the Free Software | 
|---|
| 19 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA | 
|---|
| 20 | ***************************************************************************************/ | 
|---|
| 21 | #ifndef BUTTONLINK_H | 
|---|
| 22 | #define BUTTONLINK_H | 
|---|
| 23 |  | 
|---|
| 24 | #include <QLabel> | 
|---|
| 25 | #include <QVariant> | 
|---|
| 26 |  | 
|---|
| 27 | /** | 
|---|
| 28 | * @brief This class creates a clickable QLabel that emits a signal when it's clicked and another one with the data the | 
|---|
| 29 | * user has configured | 
|---|
| 30 | * | 
|---|
| 31 | */ | 
|---|
| 32 | class ButtonLink : public QLabel | 
|---|
| 33 | { | 
|---|
| 34 | Q_OBJECT | 
|---|
| 35 |  | 
|---|
| 36 | signals: | 
|---|
| 37 | /** | 
|---|
| 38 | * @brief Signal when the link has been clicked | 
|---|
| 39 | * | 
|---|
| 40 | */ | 
|---|
| 41 | void clicked(); | 
|---|
| 42 |  | 
|---|
| 43 | public: | 
|---|
| 44 | /** | 
|---|
| 45 | * @brief Default constructor of the ButtonLink class that creates an empty text button link. | 
|---|
| 46 | * | 
|---|
| 47 | * @param parent The parent widget | 
|---|
| 48 | */ | 
|---|
| 49 | explicit ButtonLink(QWidget *parent = nullptr); | 
|---|
| 50 |  | 
|---|
| 51 | /** | 
|---|
| 52 | * @brief Overload constructor of the ButtonLink class that creates a button link with text and data if the user sets | 
|---|
| 53 | * it. | 
|---|
| 54 | * | 
|---|
| 55 | * @param text The text that the will be shown | 
|---|
| 56 | * @param parent The parent widget | 
|---|
| 57 | */ | 
|---|
| 58 | explicit ButtonLink(const QString &text, QWidget *parent = nullptr); | 
|---|
| 59 |  | 
|---|
| 60 | /** | 
|---|
| 61 | * @brief Overload constructor of the ButtonLink class that creates a button link with text and data if the user sets | 
|---|
| 62 | * it. | 
|---|
| 63 | * | 
|---|
| 64 | * @param text The text that the will be shown | 
|---|
| 65 | * @param data The user data input | 
|---|
| 66 | * @param parent The parent widget | 
|---|
| 67 | */ | 
|---|
| 68 | explicit ButtonLink(const QString &text, const QVariant &data, QWidget *parent = nullptr); | 
|---|
| 69 |  | 
|---|
| 70 | void setData(const QVariant &data) { mData = data; } | 
|---|
| 71 | QVariant data() const { return mData; } | 
|---|
| 72 |  | 
|---|
| 73 | protected: | 
|---|
| 74 | /** | 
|---|
| 75 | * | 
|---|
| 76 | *@brief Event that processes whether the user  presses or not the mouse | 
|---|
| 77 | * | 
|---|
| 78 | * @param e The event | 
|---|
| 79 | */ | 
|---|
| 80 | void mousePressEvent(QMouseEvent *e) override; | 
|---|
| 81 |  | 
|---|
| 82 | /** | 
|---|
| 83 | * @brief Event that processes whether the user releases the mouse button or not | 
|---|
| 84 | * | 
|---|
| 85 | * @param event The event | 
|---|
| 86 | */ | 
|---|
| 87 | void mouseReleaseEvent(QMouseEvent *event) override; | 
|---|
| 88 |  | 
|---|
| 89 | /** | 
|---|
| 90 | * @brief Event that processes if the users enters the button link | 
|---|
| 91 | * | 
|---|
| 92 | * @param event The event | 
|---|
| 93 | */ | 
|---|
| 94 | void enterEvent(QEvent *event) override; | 
|---|
| 95 |  | 
|---|
| 96 | /** | 
|---|
| 97 | * @brief Event that processes if the users leaves the button link | 
|---|
| 98 | * | 
|---|
| 99 | * @param event The event | 
|---|
| 100 | */ | 
|---|
| 101 | void leaveEvent(QEvent *event) override; | 
|---|
| 102 |  | 
|---|
| 103 | private: | 
|---|
| 104 | bool mPressed = false; | 
|---|
| 105 | QVariant mData; | 
|---|
| 106 | }; | 
|---|
| 107 |  | 
|---|
| 108 | #endif // BUTTONLINK_H | 
|---|
| 109 |  | 
|---|