Krita Source Code Documentation
Loading...
Searching...
No Matches
KisClickableLabel.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2023 Halla Rempt <halla@valdyas.org>
3 * SPDX-FileCopyrightText: 2023 Alvin Wong <alvin@alvinhc.com>
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#include "KisClickableLabel.h"
7
8#include <QResizeEvent>
9#include <QtMath>
10#include <QBoxLayout>
11#include <kis_icon_utils.h>
12
14 : QLabel(parent)
15{
16 m_closeButton = new QPushButton(this);
17 m_closeButton->setGeometry(0,0,16,16);
18 m_closeButton->setFlat(true);
19 m_closeButton->setIcon(KisIconUtils::loadIcon("dark_close-tab"));
20 connect(m_closeButton, &QPushButton::clicked, this, [&](){
21 Q_EMIT dismissed();
22 });
23
24 setDismissable(true);
25}
26
28
30{
31 return true;
32}
33
35{
36 if (m_pixmap.isNull()) {
37 return height();
38 }
39 return qCeil(static_cast<qreal>(w) * m_pixmap.height() / m_pixmap.width());
40}
41
43{
44 return {};
45}
46
48{
49 return {};
50}
51
53{
54 m_pixmap = std::move(pixmap);
55 setMaximumSize(m_pixmap.size());
57}
58
60{
61 if (!m_pixmap.isNull()) {
62 // setPixmap(m_pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
63 setPixmap(m_pixmap.scaledToWidth(width(), Qt::SmoothTransformation));
64 }
65}
66
73
78
79void KisClickableLabel::mousePressEvent(QMouseEvent *event)
80{
81 Q_UNUSED(event);
82 Q_EMIT clicked();
83}
84
85void KisClickableLabel::resizeEvent(QResizeEvent */*event*/)
86{
88}
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setUnscaledPixmap(QPixmap pixmap)
KisClickableLabel(QWidget *parent=nullptr)
bool hasHeightForWidth() const override
void mousePressEvent(QMouseEvent *event) override
int heightForWidth(int w) const override
void setDismissable(bool value=true)
QPushButton * m_closeButton
void resizeEvent(QResizeEvent *event) override
QSize minimumSizeHint() const override
QSize sizeHint() const override
QIcon loadIcon(const QString &name)