Falkon Develop
Cross-platform Qt-based web browser
clickablelabel.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "clickablelabel.h"
19
20#include <QMouseEvent>
21
23 : QLabel(parent)
24{
25}
26
28{
29 return m_themeIcon;
30}
31
32void ClickableLabel::setThemeIcon(const QString &name)
33{
34 m_themeIcon = name;
35 updateIcon();
36}
37
39{
40 return m_fallbackIcon;
41}
42
43void ClickableLabel::setFallbackIcon(const QIcon &fallbackIcon)
44{
45 m_fallbackIcon = fallbackIcon;
46 updateIcon();
47}
48
49void ClickableLabel::updateIcon()
50{
51 if (!m_themeIcon.isEmpty()) {
52 const QIcon icon = QIcon::fromTheme(m_themeIcon);
53 if (!icon.isNull()) {
54 setPixmap(icon.pixmap(size()));
55 return;
56 }
57 }
58
59 if (!m_fallbackIcon.isNull())
60 setPixmap(m_fallbackIcon.pixmap(size()));
61}
62
63void ClickableLabel::resizeEvent(QResizeEvent *ev)
64{
65 QLabel::resizeEvent(ev);
66 updateIcon();
67}
68
69void ClickableLabel::mouseReleaseEvent(QMouseEvent* ev)
70{
71 if (ev->button() == Qt::LeftButton && rect().contains(ev->pos())) {
72 if (ev->modifiers() == Qt::ControlModifier) {
73 Q_EMIT middleClicked(ev->globalPosition().toPoint());
74 }
75 else {
76 Q_EMIT clicked(ev->globalPosition().toPoint());
77 }
78 }
79 else if (ev->button() == Qt::MiddleButton && rect().contains(ev->pos())) {
80 Q_EMIT middleClicked(ev->globalPosition().toPoint());
81 }
82 else {
83 QLabel::mouseReleaseEvent(ev);
84 }
85}
void setFallbackIcon(const QIcon &fallbackIcon)
void clicked(QPoint)
void setThemeIcon(const QString &name)
ClickableLabel(QWidget *parent=nullptr)
void middleClicked(QPoint)