| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2010-09-12 |
| 7 |
* Description : Widget for assignment and confirmation of names for faces |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2010 by Aditya Bhatt <adityabhatt1991 at gmail dot com> |
| 10 |
* SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> |
| 11 |
* SPDX-FileCopyrightText: 2012-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 12 |
* |
| 13 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 14 |
* |
| 15 |
* ============================================================ */ |
| 16 |
|
| 17 |
#include "assignnamewidget_p.h" |
| 18 |
|
| 19 |
namespace Digikam |
| 20 |
{ |
| 21 |
|
| 22 |
AssignNameWidget::AssignNameWidget(QWidget* const parent) |
| 23 |
: QFrame(parent), |
| 24 |
d (new Private(this)) |
| 25 |
{ |
| 26 |
setObjectName(QLatin1String("assignNameWidget")); |
| 27 |
setVisualStyle(StyledFrame); |
| 28 |
} |
| 29 |
|
| 30 |
AssignNameWidget::~AssignNameWidget() |
| 31 |
{ |
| 32 |
delete d; |
| 33 |
} |
| 34 |
|
| 35 |
void AssignNameWidget::setDefaultModel() |
| 36 |
{ |
| 37 |
setAlbumModels(nullptr, nullptr, nullptr); |
| 38 |
} |
| 39 |
|
| 40 |
void AssignNameWidget::setAlbumModels(TagModel* const model, |
| 41 |
TagPropertiesFilterModel* const filteredModel, |
| 42 |
CheckableAlbumFilterModel* const filterModel) |
| 43 |
{ |
| 44 |
// Restrict the tag properties filter model to people if configured. |
| 45 |
|
| 46 |
const ApplicationSettings* const settings = ApplicationSettings::instance(); |
| 47 |
|
| 48 |
if (settings) |
| 49 |
{ |
| 50 |
if (filteredModel && settings->showOnlyPersonTagsInPeopleSidebar()) |
| 51 |
{ |
| 52 |
filteredModel->listOnlyTagsWithProperty(TagPropertyName::person()); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
if (d->comboBox) |
| 57 |
{ |
| 58 |
d->comboBox->setAlbumModels(model, filteredModel, filterModel); |
| 59 |
} |
| 60 |
else if (d->lineEdit) |
| 61 |
{ |
| 62 |
d->lineEdit->setAlbumModels(model, filteredModel, filterModel); |
| 63 |
} |
| 64 |
|
| 65 |
if (model || filteredModel || filterModel) |
| 66 |
{ |
| 67 |
// Possibly set later on box. |
| 68 |
|
| 69 |
d->modelsGiven = true; |
| 70 |
d->tagModel = model; |
| 71 |
d->tagFilterModel = filterModel; |
| 72 |
d->tagFilteredModel = filteredModel; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
void AssignNameWidget::setParentTag(TAlbum* album) |
| 77 |
{ |
| 78 |
d->parentTag = album; |
| 79 |
|
| 80 |
if (d->comboBox) |
| 81 |
{ |
| 82 |
d->comboBox->setParentTag(album); |
| 83 |
} |
| 84 |
else if (d->lineEdit) |
| 85 |
{ |
| 86 |
d->lineEdit->setParentTag(album); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
AddTagsComboBox* AssignNameWidget::comboBox() const |
| 91 |
{ |
| 92 |
return d->comboBox; |
| 93 |
} |
| 94 |
|
| 95 |
AddTagsLineEdit* AssignNameWidget::lineEdit() const |
| 96 |
{ |
| 97 |
return d->lineEdit; |
| 98 |
} |
| 99 |
|
| 100 |
void AssignNameWidget::setMode(Mode mode) |
| 101 |
{ |
| 102 |
/** |
| 103 |
* Reject tooltip and icon should be updated even if the |
| 104 |
* same mode is passed, because Unconfirmed and Unknown. |
| 105 |
* Faces have the same mode but different tooltips and icons. |
| 106 |
*/ |
| 107 |
if ( |
| 108 |
(d->layoutMode == Compact) && |
| 109 |
(mode == AssignNameWidget::UnconfirmedEditMode) |
| 110 |
) |
| 111 |
{ |
| 112 |
d->updateRejectButton(); |
| 113 |
} |
| 114 |
|
| 115 |
if (mode == d->mode) |
| 116 |
{ |
| 117 |
return; |
| 118 |
} |
| 119 |
|
| 120 |
d->mode = mode; |
| 121 |
d->updateModes(); |
| 122 |
d->updateContents(); |
| 123 |
} |
| 124 |
|
| 125 |
AssignNameWidget::Mode AssignNameWidget::mode() const |
| 126 |
{ |
| 127 |
return d->mode; |
| 128 |
} |
| 129 |
|
| 130 |
void AssignNameWidget::setTagEntryWidgetMode(TagEntryWidgetMode mode) |
| 131 |
{ |
| 132 |
if (d->widgetMode == mode) |
| 133 |
{ |
| 134 |
return; |
| 135 |
} |
| 136 |
|
| 137 |
d->widgetMode = mode; |
| 138 |
d->updateModes(); |
| 139 |
d->updateContents(); |
| 140 |
} |
| 141 |
|
| 142 |
AssignNameWidget::TagEntryWidgetMode AssignNameWidget::tagEntryWidgetMode() const |
| 143 |
{ |
| 144 |
return d->widgetMode; |
| 145 |
} |
| 146 |
|
| 147 |
void AssignNameWidget::setLayoutMode(LayoutMode mode) |
| 148 |
{ |
| 149 |
if (d->layoutMode == mode) |
| 150 |
{ |
| 151 |
return; |
| 152 |
} |
| 153 |
|
| 154 |
d->layoutMode = mode; |
| 155 |
d->updateModes(); |
| 156 |
d->updateContents(); |
| 157 |
} |
| 158 |
|
| 159 |
AssignNameWidget::LayoutMode AssignNameWidget::layoutMode() const |
| 160 |
{ |
| 161 |
return d->layoutMode; |
| 162 |
} |
| 163 |
|
| 164 |
void AssignNameWidget::setVisualStyle(VisualStyle style) |
| 165 |
{ |
| 166 |
if (d->visualStyle == style) |
| 167 |
{ |
| 168 |
return; |
| 169 |
} |
| 170 |
|
| 171 |
d->visualStyle = style; |
| 172 |
d->updateModes(); |
| 173 |
} |
| 174 |
|
| 175 |
AssignNameWidget::VisualStyle AssignNameWidget::visualStyle() const |
| 176 |
{ |
| 177 |
return d->visualStyle; |
| 178 |
} |
| 179 |
|
| 180 |
void AssignNameWidget::setUserData(const ItemInfo& info, const QVariant& faceIdentifier) |
| 181 |
{ |
| 182 |
d->info = info; |
| 183 |
d->faceIdentifier = faceIdentifier; |
| 184 |
|
| 185 |
FaceTagsIface face = FaceTagsIface::fromVariant(faceIdentifier); |
| 186 |
|
| 187 |
/** |
| 188 |
* Ignored faces are drawn over with a different |
| 189 |
* overlay, as Reject button should be disabled. |
| 190 |
*/ |
| 191 |
|
| 192 |
if (face.type() == FaceTagsIface::ConfirmedName) |
| 193 |
{ |
| 194 |
setMode(AssignNameWidget::ConfirmedMode); |
| 195 |
} |
| 196 |
else if (face.type() == FaceTagsIface::IgnoredName) |
| 197 |
{ |
| 198 |
setMode(AssignNameWidget::IgnoredMode); |
| 199 |
} |
| 200 |
else |
| 201 |
{ |
| 202 |
setMode(AssignNameWidget::UnconfirmedEditMode); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
ItemInfo AssignNameWidget::info() const |
| 207 |
{ |
| 208 |
return d->info; |
| 209 |
} |
| 210 |
|
| 211 |
QVariant AssignNameWidget::faceIdentifier() const |
| 212 |
{ |
| 213 |
return d->faceIdentifier; |
| 214 |
} |
| 215 |
|
| 216 |
void AssignNameWidget::setCurrentFace(const FaceTagsIface& face) |
| 217 |
{ |
| 218 |
TAlbum* album = nullptr; |
| 219 |
|
| 220 |
if (!face.isNull() && !face.isUnknownName() && !face.isIgnoredName()) |
| 221 |
{ |
| 222 |
album = AlbumManager::instance()->findTAlbum(face.tagId()); |
| 223 |
} |
| 224 |
|
| 225 |
setCurrentTag(album); |
| 226 |
} |
| 227 |
|
| 228 |
void AssignNameWidget::setCurrentTag(int tagId) |
| 229 |
{ |
| 230 |
setCurrentTag(AlbumManager::instance()->findTAlbum(tagId)); |
| 231 |
} |
| 232 |
|
| 233 |
void AssignNameWidget::setCurrentTag(TAlbum* album) |
| 234 |
{ |
| 235 |
if (d->currentTag == album) |
| 236 |
{ |
| 237 |
if (d->clickLabel && (d->mode != IgnoredMode)) |
| 238 |
{ |
| 239 |
d->clickLabel->setText(d->currentTag ? d->currentTag->title() |
| 240 |
: QString()); |
| 241 |
} |
| 242 |
|
| 243 |
return; |
| 244 |
} |
| 245 |
|
| 246 |
d->currentTag = album; |
| 247 |
d->updateContents(); |
| 248 |
} |
| 249 |
|
| 250 |
void AssignNameWidget::slotConfirm() |
| 251 |
{ |
| 252 |
if (d->comboBox) |
| 253 |
{ |
| 254 |
Q_EMIT assigned(d->comboBox->currentTaggingAction(), d->info, d->faceIdentifier); |
| 255 |
} |
| 256 |
|
| 257 |
else if (d->lineEdit) |
| 258 |
{ |
| 259 |
Q_EMIT assigned(d->lineEdit->currentTaggingAction(), d->info, d->faceIdentifier); |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
void AssignNameWidget::slotReject() |
| 264 |
{ |
| 265 |
Q_EMIT rejected(d->info, d->faceIdentifier); |
| 266 |
} |
| 267 |
|
| 268 |
void AssignNameWidget::slotIgnore() |
| 269 |
{ |
| 270 |
Q_EMIT ignored(d->info, d->faceIdentifier); |
| 271 |
} |
| 272 |
|
| 273 |
void AssignNameWidget::slotActionActivated(const TaggingAction& action) |
| 274 |
{ |
| 275 |
Q_EMIT assigned(action, d->info, d->faceIdentifier); |
| 276 |
} |
| 277 |
|
| 278 |
void AssignNameWidget::slotActionSelected(const TaggingAction& action) |
| 279 |
{ |
| 280 |
if (d->confirmButton) |
| 281 |
{ |
| 282 |
d->confirmButton->setEnabled(action.isValid()); |
| 283 |
} |
| 284 |
|
| 285 |
Q_EMIT selected(action, d->info, d->faceIdentifier); |
| 286 |
} |
| 287 |
|
| 288 |
void AssignNameWidget::slotIgnoredClicked() |
| 289 |
{ |
| 290 |
Q_EMIT ignoredClicked(d->info, d->faceIdentifier); |
| 291 |
} |
| 292 |
|
| 293 |
void AssignNameWidget::slotLabelClicked() |
| 294 |
{ |
| 295 |
Q_EMIT labelClicked(d->info, d->faceIdentifier); |
| 296 |
} |
| 297 |
|
| 298 |
void AssignNameWidget::keyPressEvent(QKeyEvent* e) |
| 299 |
{ |
| 300 |
switch (e->key()) |
| 301 |
{ |
| 302 |
case Qt::Key_Enter: |
| 303 |
case Qt::Key_Return: |
| 304 |
{ |
| 305 |
return; |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
QWidget::keyPressEvent(e); |
| 310 |
} |
| 311 |
|
| 312 |
void AssignNameWidget::showEvent(QShowEvent* e) |
| 313 |
{ |
| 314 |
if ((d->mode == UnconfirmedEditMode) || (d->mode == ConfirmedEditMode)) |
| 315 |
{ |
| 316 |
if (d->comboBox) |
| 317 |
{ |
| 318 |
d->comboBox->setMinimumWidth(qMax(250, size().width() - 4)); |
| 319 |
|
| 320 |
if (d->currentTag) |
| 321 |
{ |
| 322 |
d->comboBox->blockSignals(true); |
| 323 |
d->comboBox->setCurrentTag(d->currentTag); |
| 324 |
d->comboBox->blockSignals(false); |
| 325 |
} |
| 326 |
|
| 327 |
d->comboBox->lineEdit()->selectAll(); |
| 328 |
d->comboBox->lineEdit()->setFocus(); |
| 329 |
} |
| 330 |
else if (d->lineEdit) |
| 331 |
{ |
| 332 |
if (d->currentTag) |
| 333 |
{ |
| 334 |
d->lineEdit->blockSignals(true); |
| 335 |
d->lineEdit->setCurrentTag(d->currentTag); |
| 336 |
d->lineEdit->blockSignals(false); |
| 337 |
} |
| 338 |
|
| 339 |
d->lineEdit->selectAll(); |
| 340 |
d->lineEdit->setFocus(); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
QWidget::showEvent(e); |
| 345 |
} |
| 346 |
|
| 347 |
} // namespace Digikam |
| 348 |
|
| 349 |
#include "moc_assignnamewidget.cpp" |