Krita Source Code Documentation
Loading...
Searching...
No Matches
TagActions.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Boudewijn Rempt <boud@valdyas.org>
3 * SPDX-FileCopyrightText: 2020 Agata Cacko <cacko.azh@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7#include "TagActions.h"
8
9#include <QDebug>
10#include <QLabel>
11#include <QGridLayout>
12
13#include <KoIcon.h>
14#include <klocalizedstring.h>
15#include <KoResource.h>
16
18#include <KisTag.h>
19
20#include "kis_debug.h"
21
22// ############ Simple Existing Tag Action ##############
23
25 : QAction(parent)
26 , m_resource(resource)
27 , m_tag(tag)
28{
29 if (tag) {
30 setText(tag->name());
31 }
32 connect (this, SIGNAL(triggered()),
33 this, SLOT(onTriggered()));
34}
35
39
41{
42 if (!m_tag) return;
43 Q_EMIT triggered(m_tag, m_resource);
44}
45
46
47// ############ Line Edit ##############
48
50 : QWidgetAction(parent)
51 , m_closeParentOnTrigger(false)
52{
53 QWidget* pWidget = new QWidget (0);
54 QHBoxLayout* pLayout = new QHBoxLayout();
55 m_label = new QLabel(0);
57 m_editBox->setClearButtonEnabled(true);
58 m_AddButton = new QPushButton();
59 m_AddButton->setIcon(koIcon("list-add"));
60 pLayout->addWidget(m_label);
61 pLayout->addWidget(m_editBox);
62 pLayout->addWidget(m_AddButton);
63 pWidget->setLayout(pLayout);
64 setDefaultWidget(pWidget);
65
66 connect(m_editBox, &QLineEdit::returnPressed, this, &LineEditAction::slotActionTriggered);
67 connect(m_AddButton, &QPushButton::clicked, this, &LineEditAction::slotActionTriggered);
68
69}
70
74
75void LineEditAction::setIcon(const QIcon &icon)
76{
77 QPixmap pixmap = QPixmap(icon.pixmap(16,16));
78 m_label->setPixmap(pixmap);
79}
80
82{
83 m_closeParentOnTrigger = closeParent;
84}
85
90
91
93{
94 setData(userText());
95 QAction::trigger();
97 if (!m_editBox->text().isEmpty()) {
99 this->parentWidget()->close();
100 m_editBox->clearFocus();
101 m_editBox->clear();
102 }
103 }
104}
105
106void LineEditAction::setPlaceholderText(const QString& clickMessage)
107{
108 m_editBox->setPlaceholderText(clickMessage);
109}
110
111void LineEditAction::setText(const QString& text)
112{
113 m_editBox->setText(text);
114}
115
116void LineEditAction::setVisible(bool showAction)
117{
118 QLayout* currentLayout = defaultWidget()->layout();
119
120 this->QAction::setVisible(showAction);
121
122 for(int i=0;i<currentLayout->count();i++) {
123 currentLayout->itemAt(i)->widget()->setVisible(showAction);
124 }
125 defaultWidget()->setVisible(showAction);
126}
127
129{
130 return m_editBox->text();
131}
132
133// ############ New Tag ##############
134
136 : LineEditAction(parent)
137{
138 setIcon(koIcon("document-new"));
139 setPlaceholderText(i18n("New tag"));
141}
142
146
148{
149 Q_EMIT triggered(userText());
150}
151
152// ############ New Tag Resource ##############
153
155 : LineEditAction(parent)
156{
157 setIcon(koIcon("document-new"));
158 setPlaceholderText(i18n("New tag"));
160 m_resource = resource;
161}
162
166
168{
169 m_resource = resource;
170}
171
176
177// ############ TAG COMPARER ##############
178
179
184
186{
187// ENTER_FUNCTION() << "refTag: " << (m_referenceTag.isNull() ? "null" : m_referenceTag->name())
188// << " other: " << (otherTag.isNull() ? "null" : otherTag->name())
189// << " result = " << (!otherTag.isNull() && !m_referenceTag.isNull() && otherTag->url() == m_referenceTag->url());
190 return !otherTag.isNull() && !m_referenceTag.isNull() && otherTag->url() == m_referenceTag->url();
191}
192
196
200
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisTagSP m_referenceTag
Tag to compare all other tags to.
Definition TagActions.h:188
KisTagSP referenceTag()
referenceTag is a getter for the reference tag
bool operator()(KisTagSP otherTag)
operator () contains comparison logic
void setReferenceTag(KisTagSP referenceTag)
setReferenceTag sets a reference tag in the comparer
CompareWithOtherTagFunctor(KisTagSP referenceTag)
CompareWithOtherTagFunctor defines a default constructor.
The LineEditAction class defines an action with a user text input.
Definition TagActions.h:73
void setPlaceholderText(const QString &clickMessage)
LineEditAction(QObject *parent)
bool closeParentOnTrigger()
bool m_closeParentOnTrigger
Definition TagActions.h:113
virtual void onTriggered()
onTriggered defines additional behaviour for the action
Definition TagActions.h:104
QPushButton * m_AddButton
Definition TagActions.h:116
~LineEditAction() override
void slotActionTriggered()
slotActionTriggered defines all behaviour expressed when the widget is triggered
void setText(const QString &text)
QLabel * m_label
Definition TagActions.h:114
void setIcon(const QIcon &icon)
void setCloseParentOnTrigger(bool closeParent)
void setVisible(bool showAction)
QLineEdit * m_editBox
Definition TagActions.h:115
QString userText()
userText getter for the text inside the edit box
KoResourceSP m_resource
Definition TagActions.h:173
void onTriggered() override
void setResource(KoResourceSP resource)
~NewTagResourceAction() override
NewTagResourceAction(KoResourceSP resource, QObject *parent)
void triggered(const QString &newTagName, KoResourceSP resource)
KisTagSP m_tag
m_tag tag associated with the action
Definition TagActions.h:51
SimpleExistingTagAction(KoResourceSP resource, KisTagSP tag, QObject *parent=0)
KoResourceSP m_resource
m_resource resource associated with the action
Definition TagActions.h:47
void triggered(KisTagSP tag, KoResourceSP resource)
~SimpleExistingTagAction() override
void onTriggered() override
void triggered(const QString &newTagName)
~UserInputTagAction() override
UserInputTagAction(QObject *parent)
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25