~ubuntu-branches/ubuntu/precise/tetzle/precise

« back to all changes in this revision

Viewing changes to src/image_properties_dialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bart Martens
  • Date: 2011-06-02 02:51:09 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110602025109-6jmxy9wekpwlrkw6
Tags: 2.0.0-1
* Synced with https://launchpad.net/~gottcode/+archive/gcppa/
* debian/control: Fixed "dpkg-source: warning: unknown information field
  'Suggests' in input data in general section of control info file".

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***********************************************************************
 
2
 *
 
3
 * Copyright (C) 2008, 2010, 2011 Graeme Gott <graeme@gottcode.org>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 *
 
18
 ***********************************************************************/
 
19
 
 
20
#include "image_properties_dialog.h"
 
21
 
 
22
#include "tag_manager.h"
 
23
 
 
24
#include <QDialogButtonBox>
 
25
#include <QFormLayout>
 
26
#include <QLabel>
 
27
#include <QLineEdit>
 
28
#include <QListWidget>
 
29
#include <QPushButton>
 
30
#include <QSettings>
 
31
 
 
32
//-----------------------------------------------------------------------------
 
33
 
 
34
ImagePropertiesDialog::ImagePropertiesDialog(const QIcon& icon, const QString& name, TagManager* manager, const QString& image, QWidget* parent)
 
35
        : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
 
36
        m_image(image),
 
37
        m_manager(manager)
 
38
{
 
39
        setWindowTitle(tr("Image Properties"));
 
40
 
 
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);
 
45
 
 
46
        // Add name
 
47
        m_name = new QLineEdit(name, this);
 
48
 
 
49
        // Add tags
 
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);
 
57
        }
 
58
        if (m_tags->count() > 0) {
 
59
                QListWidgetItem* item = m_tags->item(0);
 
60
                item->setSelected(true);
 
61
                m_tags->setCurrentItem(item);
 
62
        }
 
63
 
 
64
        // Add dialog buttons
 
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()));
 
68
 
 
69
        // Layout dialog
 
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);
 
75
 
 
76
        // Resize dialog
 
77
        resize(QSettings().value("ImageProperties/Size", sizeHint()).toSize());
 
78
}
 
79
 
 
80
//-----------------------------------------------------------------------------
 
81
 
 
82
QString ImagePropertiesDialog::name() const
 
83
{
 
84
        return m_name->text();
 
85
}
 
86
 
 
87
//-----------------------------------------------------------------------------
 
88
 
 
89
void ImagePropertiesDialog::accept()
 
90
{
 
91
        QStringList tags;
 
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());
 
96
                }
 
97
        }
 
98
        m_manager->setImageTags(m_image, tags);
 
99
        QDialog::accept();
 
100
}
 
101
 
 
102
//-----------------------------------------------------------------------------
 
103
 
 
104
void ImagePropertiesDialog::hideEvent(QHideEvent* event)
 
105
{
 
106
        QSettings().setValue("ImageProperties/Size", size());
 
107
        QDialog::hideEvent(event);
 
108
}
 
109
 
 
110
//-----------------------------------------------------------------------------