Krita Source Code Documentation
Loading...
Searching...
No Matches
WdgCloseableLabel Class Reference

#include <KisTagSelectionWidget.h>

+ Inheritance diagram for WdgCloseableLabel:

Signals

void sigRemoveTagFromSelection (KoID tag)
 

Public Member Functions

 WdgCloseableLabel (KoID tag, bool editable, bool semiSelected=false, QWidget *parent=0)
 
 ~WdgCloseableLabel () override
 

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 

Private Attributes

QPushButton * m_closeIconLabel {nullptr}
 
bool m_editable {false}
 
bool m_semiSelected {false}
 
int m_size {18}
 
KoID m_tag
 
QLabel * m_textLabel {nullptr}
 

Friends

class TestKisTagSelectionWidget
 

Detailed Description

Definition at line 23 of file KisTagSelectionWidget.h.

Constructor & Destructor Documentation

◆ WdgCloseableLabel()

WdgCloseableLabel::WdgCloseableLabel ( KoID tag,
bool editable,
bool semiSelected = false,
QWidget * parent = 0 )
explicit

Definition at line 39 of file KisTagSelectionWidget.cpp.

40 : QWidget(parent)
41 , m_editable(editable)
42 , m_semiSelected(semiSelected)
43 , m_tag(tag)
44{
45 QHBoxLayout *layout = new QHBoxLayout(this);
46 layout->setContentsMargins(4, 0, 1, 0);
47 layout->setSpacing(2);
48
49 m_textLabel = new QLabel(parent);
50 m_textLabel->setText(tag.name());
51 m_textLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
52 layout->addWidget(m_textLabel);
53
54 if (m_editable) {
55 m_closeIconLabel = new QPushButton(parent);
56 m_closeIconLabel->setFlat(true);
57 m_closeIconLabel->setIcon(KisIconUtils::loadIcon("docker_close"));
58 m_closeIconLabel->setToolTip(i18n("Remove tag"));
59 m_closeIconLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
60 m_closeIconLabel->setMaximumSize(QSize(1, 1) * m_size);
61
62 connect(m_closeIconLabel, &QAbstractButton::clicked, this, [&]() {
64 });
65 layout->addWidget(m_closeIconLabel);
66 }
67 else {
68 //Add a margin to the right when there's no delete button
69 layout->setContentsMargins(4, 2, 4, 2);
70 }
71 setLayout(layout);
72}
QString name() const
Definition KoID.cpp:68
QPushButton * m_closeIconLabel
void sigRemoveTagFromSelection(KoID tag)
QIcon loadIcon(const QString &name)

References KisIconUtils::loadIcon(), m_closeIconLabel, m_editable, m_size, m_tag, m_textLabel, KoID::name(), and sigRemoveTagFromSelection().

◆ ~WdgCloseableLabel()

WdgCloseableLabel::~WdgCloseableLabel ( )
override

Definition at line 74 of file KisTagSelectionWidget.cpp.

75{
76
77}

Member Function Documentation

◆ paintEvent()

void WdgCloseableLabel::paintEvent ( QPaintEvent * event)
overrideprotected

Definition at line 79 of file KisTagSelectionWidget.cpp.

80{
81 QPainter painter(this);
82
83 QColor backGroundColor = qApp->palette().light().color();
84 QColor foregroundColor = qApp->palette().windowText().color();
85 qreal r1 = 0.65;
86 qreal r2 = 1 - r1;
87 QColor outlineColor = QColor::fromRgb(256*(r1*backGroundColor.redF() + r2*foregroundColor.redF()),
88 256*(r1*backGroundColor.greenF() + r2*foregroundColor.greenF()),
89 256*(r1*backGroundColor.blueF() + r2*foregroundColor.blueF()));
90
91
92 QBrush windowB = qApp->palette().window();
93 QBrush windowTextB = qApp->palette().windowText();
94
95 QWidget::paintEvent(event);
96 painter.setRenderHint(QPainter::Antialiasing);
97 QPainterPath path;
98 path.addRoundedRect(this->rect(), 6, 6);
99
100 // good color:
101 painter.fillPath(path, qApp->palette().light());
102
103 if (m_semiSelected) {
104
105 QPen penwt = QPen(outlineColor, 1);
106 penwt.setStyle(Qt::DashLine);
107
108 QPainterPath outlinePath;
109 outlinePath.addRoundedRect(this->rect().adjusted(1, 1, -1, -1), 4, 4);
110
111 painter.setPen(penwt);
112 painter.drawPath(outlinePath);
113 }
114
115}
QPointF r2
QPointF r1

References m_semiSelected, r1, and r2.

◆ sigRemoveTagFromSelection

void WdgCloseableLabel::sigRemoveTagFromSelection ( KoID tag)
signal

Friends And Related Symbol Documentation

◆ TestKisTagSelectionWidget

friend class TestKisTagSelectionWidget
friend

Definition at line 46 of file KisTagSelectionWidget.h.

Member Data Documentation

◆ m_closeIconLabel

QPushButton* WdgCloseableLabel::m_closeIconLabel {nullptr}
private

Definition at line 39 of file KisTagSelectionWidget.h.

39{nullptr};

◆ m_editable

bool WdgCloseableLabel::m_editable {false}
private

Definition at line 42 of file KisTagSelectionWidget.h.

42{false};

◆ m_semiSelected

bool WdgCloseableLabel::m_semiSelected {false}
private

Definition at line 43 of file KisTagSelectionWidget.h.

43{false};

◆ m_size

int WdgCloseableLabel::m_size {18}
private

Definition at line 41 of file KisTagSelectionWidget.h.

41{18};

◆ m_tag

KoID WdgCloseableLabel::m_tag
private

Definition at line 44 of file KisTagSelectionWidget.h.

◆ m_textLabel

QLabel* WdgCloseableLabel::m_textLabel {nullptr}
private

Definition at line 38 of file KisTagSelectionWidget.h.

38{nullptr};

The documentation for this class was generated from the following files: