Krita Source Code Documentation
Loading...
Searching...
No Matches
KisTagToolButton.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the KDE project
3 * SPDX-FileCopyrightText: 2002 Patrick Julien <freak@codepimps.org>
4 * SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net>
5 * SPDX-FileCopyrightText: 2007 Sven Langkamp <sven.langkamp@gmail.com>
6 * SPDX-FileCopyrightText: 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com>
7 * SPDX-FileCopyrightText: 2011 José Luis Vergara <pentalis@gmail.com>
8 * SPDX-FileCopyrightText: 2013 Sascha Suelzer <s.suelzer@gmail.com>
9 * SPDX-FileCopyrightText: 2020 Agata Cacko <cacko.azh@gmail.com>
10 *
11 * SPDX-License-Identifier: LGPL-2.0-or-later
12 */
13
14#include "KisTagToolButton.h"
15
16#include <QToolButton>
17#include <QGridLayout>
18
19#include <klocalizedstring.h>
20
21#include <KoIcon.h>
22
23#include <kis_debug.h>
24#include <KisTagModel.h>
25
28
43
45 : QWidget(parent)
46 , d(new Private())
47{
48 QGridLayout* buttonLayout = new QGridLayout(this);
49 buttonLayout->setContentsMargins(0, 0, 0, 0);
50 buttonLayout->setSpacing(0);
51
52 d->tagToolButton = new QToolButton(this);
53 loadIcon();
54 d->tagToolButton->setText(i18n("Tag"));
55 d->tagToolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
56 d->tagToolButton->setToolTip(i18nc("@info:tooltip", "<qt>Show the tag box options.</qt>"));
57 d->tagToolButton->setPopupMode(QToolButton::InstantPopup);
58 d->tagToolButton->setEnabled(true);
59
60 QMenu* popup = new QMenu(this);
61
62 KisMenuStyleDontCloseOnAlt *menuStyle = new KisMenuStyleDontCloseOnAlt(popup->style());
63 menuStyle->setParent(popup);
64 popup->setStyle(menuStyle);
65
66 d->addTagAction = new UserInputTagAction(popup);
67 d->addTagAction->setPlaceholderText(i18n("New tag"));
68 d->addTagAction->setIcon(koIcon("document-new"));
70 popup->addAction(d->addTagAction);
71
72 connect(d->addTagAction, SIGNAL(triggered(QString)), this, SIGNAL(newTagRequested(QString)));
73
75 d->renameTagAction->setPlaceholderText(i18n("Rename tag"));
76 d->renameTagAction->setIcon(koIcon("edit-rename"));
78 popup->addAction(d->renameTagAction);
79
80 connect(d->renameTagAction, SIGNAL(triggered(QString)), this, SIGNAL(renamingOfCurrentTagRequested(QString)));
81
82 popup->addSeparator();
83
84 d->deleteTagAction = new QAction(popup);
85 d->deleteTagAction->setText(i18n("Delete this tag"));
86 d->deleteTagAction->setIcon(koIcon("edit-delete"));
87 popup->addAction(d->deleteTagAction);
88
89 connect(d->deleteTagAction, SIGNAL(triggered()), this, SIGNAL(deletionOfCurrentTagRequested()));
90
91 popup->addSeparator();
92
93 d->undeleteTagAction = new QAction(popup);
94 d->undeleteTagAction->setIcon(koIcon("edit-redo"));
95 d->undeleteTagAction->setVisible(false);
96 popup->addAction(d->undeleteTagAction);
97
98 connect(d->undeleteTagAction, SIGNAL(triggered()), this, SLOT(onTagUndeleteClicked()));
99
100 connect(popup, SIGNAL(aboutToShow()), this, SIGNAL(popupMenuAboutToShow()));
101
102 d->tagToolButton->setMenu(popup);
103 buttonLayout->addWidget(d->tagToolButton);
104}
105
110
112{
113 activate = !activate;
114 d->renameTagAction->setVisible(activate);
115 d->deleteTagAction->setVisible(activate);
116}
117
119{
120 if (deletedTag.isNull() || deletedTag->name().isEmpty()) {
121 d->undeleteTagAction->setVisible(false);
122 d->undeleteCandidate.clear();
123 } else {
124 d->undeleteCandidate = deletedTag;
125 d->undeleteTagAction->setText(i18n("Undelete") +" "+ deletedTag->name());
126 d->undeleteTagAction->setVisible(true);
127 }
128}
129
134
136{
137 d->currentTag = tag;
138 d->deleteTagAction->setProperty("currentTag", QVariant::fromValue<KisTagSP>(tag));
139}
140
142{
143 d->tagToolButton->setIcon(koIcon("bookmarks"));
144}
145
150
151
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
UserInputTagAction * addTagAction
UserInputTagAction * renameTagAction
void popupMenuAboutToShow()
popupMenuAboutToShow signals that the tags popup will be shown soon.
void deletionOfCurrentTagRequested()
deletionOfCurrentTagRequested signals to KisTagChooserWidget to delete the current tag
void setCurrentTag(const KisTagSP tag)
KisTagToolButton(QWidget *parent=0)
void newTagRequested(const QString &tagName)
newTagRequested signals to the KisTagChooserWidget to create a new tag
void renamingOfCurrentTagRequested(const QString &tagName)
renamingOfCurrentTagRequested signals to KisTagChooserWidget to rename the current tag
void onTagUndeleteClicked()
onTagUndeleteClicked is called when the user
void loadIcon()
updates icon file when loading and changing themes
void readOnlyMode(bool activate)
readOnlyMode sets the mode of the popup
void undeletionOfTagRequested(const KisTagSP tag)
undeletionOfTagRequested signals to KisTagChooserWidget to undelete the mentioned tag
void setUndeletionCandidate(const KisTagSP deletedTag)
setUndeletionCandidate sets a new item in the deleted tags list
KisTagSP undeletionCandidate() const
void setPlaceholderText(const QString &clickMessage)
void setIcon(const QIcon &icon)
void setCloseParentOnTrigger(bool closeParent)
void setVisible(bool showAction)
The UserInputTagAction class defines an action with user text input that sends a signal with a simple...
Definition TagActions.h:131
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25