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&)),
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");
269 "A tag with this unique name already exists. Do you want to replace it?"),
270 i18nc(
"Option in a dialog to discard the previously existing tag and creating a new one in its place",
"Replace (overwrite) tag"),
271 undeleteOption, i18n(
"Cancel"));
277 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);
281 if (tagName.isEmpty())
return;
283 KisTagSP tagForUrl =
d->model->tagForUrl(tagName);
284 if (!tagForUrl.isNull()) {
287 d->model->setTagActive(tagForUrl);
288 if (!resource.isNull()) {
293 }
else if (response ==
Cancel) {
298 d->model->addTag(tagName,
true, resources);
305 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);
309 KisTagSP tagForUrl =
d->model->tagForUrl(tag->url());
310 if (!tagForUrl.isNull()) {
313 d->model->setTagActive(tagForUrl);
314 if (!resource.isNull()) {
319 }
else if (response ==
Cancel) {
324 d->model->addTag(tag,
true, resources);
330 int row =
d->comboBox->currentIndex();
335 QModelIndex index =
d->model->index(row, 0);
336 KisTagSP tag =
d->model->tagForIndex(index);
342 d->tagToolButton->loadIcon();
352 d->tagToolButton->readOnlyMode(
true);
QSharedPointer< KisTag > KisTagSP
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
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)