1
/***********************************************************************
3
* Copyright (C) 2008, 2010, 2011 Graeme Gott <graeme@gottcode.org>
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
***********************************************************************/
20
#include "image_properties_dialog.h"
22
#include "tag_manager.h"
24
#include <QDialogButtonBox>
25
#include <QFormLayout>
28
#include <QListWidget>
29
#include <QPushButton>
32
//-----------------------------------------------------------------------------
34
ImagePropertiesDialog::ImagePropertiesDialog(const QIcon& icon, const QString& name, TagManager* manager, const QString& image, QWidget* parent)
35
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
39
setWindowTitle(tr("Image Properties"));
41
QLabel* preview = new QLabel(this);
42
preview->setAlignment(Qt::AlignCenter);
43
preview->setPixmap(icon.pixmap(74,74));
44
preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
47
m_name = new QLineEdit(name, this);
50
m_tags = new QListWidget(this);
51
m_tags->setSortingEnabled(true);
52
QStringList tags = m_manager->tags();
53
foreach (const QString& tag, tags) {
54
QListWidgetItem* item = new QListWidgetItem(tag, m_tags);
55
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
56
item->setCheckState(m_manager->images(tag).contains(image) ? Qt::Checked : Qt::Unchecked);
58
if (m_tags->count() > 0) {
59
QListWidgetItem* item = m_tags->item(0);
60
item->setSelected(true);
61
m_tags->setCurrentItem(item);
65
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
66
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
67
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
70
QFormLayout* layout = new QFormLayout(this);
71
layout->addRow(preview);
72
layout->addRow(tr("Name:"), m_name);
73
layout->addRow(tr("Tags:"), m_tags);
74
layout->addRow(buttons);
77
resize(QSettings().value("ImageProperties/Size", sizeHint()).toSize());
80
//-----------------------------------------------------------------------------
82
QString ImagePropertiesDialog::name() const
84
return m_name->text();
87
//-----------------------------------------------------------------------------
89
void ImagePropertiesDialog::accept()
92
int count = m_tags->count();
93
for (int i = 0; i < count; ++i) {
94
if (m_tags->item(i)->checkState() == Qt::Checked) {
95
tags.append(m_tags->item(i)->text());
98
m_manager->setImageTags(m_image, tags);
102
//-----------------------------------------------------------------------------
104
void ImagePropertiesDialog::hideEvent(QHideEvent* event)
106
QSettings().setValue("ImageProperties/Size", size());
107
QDialog::hideEvent(event);
110
//-----------------------------------------------------------------------------