22#include <kconfiggroup.h>
23#include <ksharedconfig.h>
24#include <klocalizedstring.h>
50 d->comboBox =
new QComboBox(
this);
51 d->comboBox->setToolTip(i18n(
"Tag"));
52 d->comboBox->setSizePolicy(QSizePolicy::Policy::Expanding , QSizePolicy::Policy::Fixed);
57 d->comboBox->setMinimumContentsLength(1);
58 d->comboBox->setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy::AdjustToMinimumContentsLengthWithIcon);
60 d->comboBox->setInsertPolicy(QComboBox::InsertAlphabetically);
62 d->comboBox->setModel(
model);
68 QGridLayout* comboLayout =
new QGridLayout(
this);
70 comboLayout->addWidget(
d->comboBox, 0, 0);
73 d->tagToolButton->setToolTip(i18n(
"Tag options"));
74 comboLayout->addWidget(
d->tagToolButton, 0, 1);
76 comboLayout->setSpacing(0);
77 comboLayout->setContentsMargins(0, 0, 0, 0);
78 comboLayout->setColumnStretch(0, 3);
79 this->setEnabled(
true);
81 connect(
d->comboBox, SIGNAL(currentIndexChanged(
int)),
84 connect(
d->tagToolButton, SIGNAL(popupMenuAboutToShow()),
87 connect(
d->tagToolButton, SIGNAL(newTagRequested(QString)),
88 this, SLOT(
addTag(QString)));
90 connect(
d->tagToolButton, SIGNAL(deletionOfCurrentTagRequested()),
93 connect(
d->tagToolButton, SIGNAL(renamingOfCurrentTagRequested(
const QString&)),
96 connect(
d->tagToolButton, SIGNAL(undeletionOfTagRequested(
KisTagSP)),
102 connect(
d->model, SIGNAL(modelAboutToBeReset()),
this, SLOT(
cacheSelectedTag()));
104 connect(
d->allTagsModel.data(), SIGNAL(dataChanged(
const QModelIndex&,
const QModelIndex&,
const QVector<int>&)),
117 if (!currentTag.isNull() && currentTag->id() >= 0) {
118 d->model->setTagInactive(currentTag);
128 d->tagToolButton->setCurrentTag(tag);
129 KConfigGroup group = KSharedConfig::openConfig()->group(
"SelectedTags");
141 bool canRenameCurrentTag = !tag.isNull() && (tagName != tag->name());
144 QMessageBox::information(
this, i18nc(
"Dialog title",
"Can't rename the tag"), i18nc(
"Dialog message",
"You can't use this name for your custom tags."), QMessageBox::Ok);
150 if (canRenameCurrentTag && !tagName.isEmpty()) {
151 result =
d->model->renameTag(tag, tagName,
false);
154 KisTagSP tagToRemove =
d->model->tagForUrl(tagName);
157 QMessageBox::question(
this, i18nc(
"Dialog title",
"Remove existing tag with that name?"),
158 i18nc(
"Dialog message (the arguments are both somewhat user readable nouns or adjectives (names of the tags), can be treated as nouns since they represent the tags)",
159 "A tag with this unique name already exists. In order to continue renaming, the existing tag needs to be removed. Do you want to continue?\n"
160 "Tag to be removed: %1\n"
161 "Tag's unique name: %2", tagToRemove->name(), tagToRemove->url()), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel) != QMessageBox::Cancel) {
162 result =
d->model->renameTag(tag, tagName,
true);
169 KisTagSP renamedTag =
d->model->tagForUrl(tagName);
171 const QModelIndex idx =
d->model->indexForTag(renamedTag);
178 int previousIndex =
d->comboBox->currentIndex();
180 bool success =
d->model->setTagActive(tag);
196 QModelIndex cachedIndex =
d->model->indexForTag(
d->cachedTag);
198 d->cachedTag =
nullptr;
205 if (!roles.isEmpty() && !roles.contains(Qt::CheckStateRole)) {
209 const QModelIndex currIdx =
210 d->allTagsModel->indexForTag(
d->tagToolButton->undeletionCandidate());
212 if (currIdx.isValid() &&
213 currIdx.row() >= topLeft.row() && currIdx.row() <= bottomRight.row() &&
214 currIdx.column() >= topLeft.column() && currIdx.column() <= bottomRight.column()) {
216 const bool isNowActive =
d->allTagsModel->data(currIdx, Qt::CheckStateRole).toBool();
219 d->tagToolButton->setUndeletionCandidate(
KisTagSP());
223 for (
int row = topLeft.row(); row <= bottomRight.row(); row++) {
224 for (
int column = topLeft.column(); column <= bottomRight.column(); column++) {
225 const QModelIndex idx =
d->allTagsModel->index(row, column);
227 const bool isActive =
d->allTagsModel->data(idx, Qt::CheckStateRole).toBool();
229 if (idx != currIdx && !isActive) {
230 d->tagToolButton->setUndeletionCandidate(
d->allTagsModel->tagForIndex(idx));
239 d->comboBox->setCurrentIndex(index);
244 return d->comboBox->currentIndex();
249 for (
int i = 0; i <
d->model->rowCount(); i++) {
250 QModelIndex index =
d->model->index(i, 0);
252 if (currentRowTag == tag) {
265 QString undeleteOption = !tagIsActive ? i18nc(
"Option in a dialog to undelete (reactivate) existing tag with its old assigned resources",
"Restore previous tag")
266 : i18nc(
"Option in a dialog to use existing tag with its old assigned resources",
"Use existing tag");
267 QMessageBox question = QMessageBox(QMessageBox::Question,
268 i18nc(
"Dialog title",
"Overwrite tag?"),
269 i18nc(
"Question to the user in a dialog about creating a tag",
270 "A tag with this unique name already exists. Do you want to replace it?")
272 question.setParent(parent);
274 i18nc(
"Option in a dialog to discard the previously existing tag and creating a new one in its place",
275 "Replace (overwrite) tag"),
276 QMessageBox::DestructiveRole
278 question.addButton(undeleteOption, QMessageBox::AcceptRole);
279 question.addButton(QMessageBox::Cancel);
281 return question.buttonRole(question.clickedButton());
287 QMessageBox::information(
this, i18nc(
"Dialog title",
"Can't create the tag"), i18nc(
"Dialog message",
"You can't use this name for your custom tags."), QMessageBox::Ok);
291 if (tagName.isEmpty())
return;
293 KisTagSP tagForUrl =
d->model->tagForUrl(tagName);
294 if (!tagForUrl.isNull()) {
296 if (response == QMessageBox::AcceptRole) {
297 d->model->setTagActive(tagForUrl);
298 if (!resource.isNull()) {
303 }
else if (response == QMessageBox::RejectRole) {
308 d->model->addTag(tagName,
true, resources);
315 QMessageBox::information(
this, i18nc(
"Dialog title",
"Can't rename the tag"), i18nc(
"Dialog message",
"You can't use this name for your custom tags."), QMessageBox::Ok);
319 KisTagSP tagForUrl =
d->model->tagForUrl(tag->url());
320 if (!tagForUrl.isNull()) {
322 if (response == QMessageBox::AcceptRole) {
323 d->model->setTagActive(tagForUrl);
324 if (!resource.isNull()) {
329 }
else if (response == QMessageBox::RejectRole) {
334 d->model->addTag(tag,
true, resources);
340 int row =
d->comboBox->currentIndex();
345 QModelIndex index =
d->model->index(row, 0);
346 KisTagSP tag =
d->model->tagForIndex(index);
352 d->tagToolButton->loadIcon();
362 d->tagToolButton->readOnlyMode(
true);
QSharedPointer< KisTag > KisTagSP
The KisTagResourceModel class makes it possible to retrieve the resources for certain tags or the tag...
bool tagResources(const KisTagSP tag, const QVector< int > &resourceIds) override
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)