1#pragma once
2
3/****************************************************************************************
4 ** GitQlient is an application to manage and operate one or several Git repositories. With
5 ** GitQlient you will be able to add commits, branches and manage all the options Git provides.
6 ** Copyright (C) 2021 Francesc Martinez
7 **
8 ** LinkedIn: www.linkedin.com/in/cescmm/
9 ** Web: www.francescmm.com
10 **
11 ** This program is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU Lesser General Public
13 ** License as published by the Free Software Foundation; either
14 ** version 2 of the License, or (at your option) any later version.
15 **
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** Lesser General Public License for more details.
20 **
21 ** You should have received a copy of the GNU Lesser General Public
22 ** License along with this library; if not, write to the Free Software
23 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 ***************************************************************************************/
25
26#include <QFrame>
27
28class QLabel;
29
30/**
31 * @brief The ClickableFrame class is simple widget to make QLabel clickable and at the same time give the ability to
32 * customize its look & feel. The behaviour is so simplified that only has a @p clicked() signal to notify the user that
33 * the object was clicked.
34 *
35 * Another reason to have the widget is that it allows the user to fill it with other widgets keeping the click
36 * behaviour in top of them.
37 *
38 * @class ClickableFrame ClickableFrame.h "ClickableFrame.h"
39 */
40class ClickableFrame : public QFrame
41{
42 Q_OBJECT
43
44signals:
45 /**
46 * @brief Signal emitted when the user clicks the object.
47 */
48 void clicked();
49
50public:
51 /**
52 * @brief Default constructor. This creates an empty
53 *
54 * @param parent The parent widget if needed.
55 */
56 explicit ClickableFrame(QWidget *parent = nullptr);
57 /**
58 * @brief Creates a ClickableFrame with a QLabel inside filled with the given @p text and in the given @p alignment
59 *
60 * @param text The text that the widget will display
61 * @param alignment The alignment of the text in the widget
62 * @param parent The parent widget if needed
63 */
64 explicit ClickableFrame(const QString &text, Qt::Alignment alignment, QWidget *parent = nullptr);
65
66 /**
67 * @brief setLinkStyle Sets the text of the widget overlined when hover.
68 */
69 void setLinkStyle() { mHasLinkStyles = true; }
70
71protected:
72 /**
73 * @brief Detects the press event to prepare the click signal.
74 *
75 * @param e The event
76 */
77 void mousePressEvent(QMouseEvent *e) override;
78 /**
79 * @brief Detects the release event and if the press was detected before, it triggers the clicked signal.
80 *
81 * @param e The event
82 */
83 void mouseReleaseEvent(QMouseEvent *e) override;
84
85 /**
86 * @brief enterEvent Detects the enter event and in case the link style is enabled it applies it.
87 * @param event The event.
88 */
89 void enterEvent(QEvent *event) override;
90
91 /**
92 * @brief leaveEvent Detects the leave event and in case the link style is enabled it removes the underline.
93 * @param event
94 */
95 void leaveEvent(QEvent *event) override;
96
97private:
98 bool mPressed = false;
99 bool mHasLinkStyles = false;
100 QLabel *mText = nullptr;
101};
102