~ubuntu-branches/ubuntu/intrepid/digikam/intrepid

« back to all changes in this revision

Viewing changes to digikam/digikam/tagcreatedlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.2.15 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080717202539-6n7dtirbkoo7qvhd
Tags: 2:0.9.4-1
* New upstream release
  - digiKam 0.9.4 Release Plan (KDE3) ~ 13 July 08 (Closes: #490144)
* DEB_CONFIGURE_EXTRA_FLAGS := --without-included-sqlite3
* Debhelper compatibility level V7
* Install pixmaps in debian/*.install
* Add debian/digikam.lintian-overrides

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ============================================================
2
 
 *
3
 
 * This file is a part of digiKam project
4
 
 * http://www.digikam.org
5
 
 *
6
 
 * Date        : 2004-07-01
7
 
 * Description : dialog to edit and create digiKam Tags
8
 
 * 
9
 
 * Copyright (C) 2004-2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
10
 
 * Copyright (C) 2006-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
 
 *
12
 
 * This program is free software; you can redistribute it
13
 
 * and/or modify it under the terms of the GNU General
14
 
 * Public License as published by the Free Software Foundation;
15
 
 * either version 2, or (at your option)
16
 
 * any later version.
17
 
 *
18
 
 * This program is distributed in the hope that it will be useful,
19
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 
 * GNU General Public License for more details.
22
 
 *
23
 
 * ============================================================ */
24
 
 
25
 
// Qt includes.
26
 
 
27
 
#include <qcombobox.h>
28
 
#include <qlabel.h>
29
 
#include <qframe.h>
30
 
#include <qlayout.h>
31
 
 
32
 
// KDE includes.
33
 
 
34
 
#include <klineedit.h>
35
 
#include <klocale.h>
36
 
#include <kicondialog.h>
37
 
#include <kapplication.h>
38
 
#include <kdeversion.h>
39
 
#include <kiconloader.h>
40
 
 
41
 
// Local includes.
42
 
 
43
 
#include "album.h"
44
 
#include "syncjob.h"
45
 
#include "tagcreatedlg.h"
46
 
#include "tagcreatedlg.moc"
47
 
 
48
 
namespace Digikam
49
 
{
50
 
 
51
 
class TagCreateDlgPriv
52
 
{
53
 
public:
54
 
 
55
 
    TagCreateDlgPriv()
56
 
    {
57
 
        titleEdit  = 0;
58
 
        iconButton = 0;
59
 
        icon       = QString("tag");
60
 
    }
61
 
 
62
 
    QString      icon;
63
 
 
64
 
    QPushButton *iconButton;
65
 
 
66
 
    KLineEdit   *titleEdit;
67
 
};
68
 
 
69
 
TagCreateDlg::TagCreateDlg(QWidget *parent, TAlbum* album)
70
 
            : KDialogBase( Plain, i18n("New Tag"), Help|Ok|Cancel, Ok,
71
 
                           parent, 0, true, true )
72
 
{
73
 
    d = new TagCreateDlgPriv;
74
 
    setHelp("tagscreation.anchor", "digikam");
75
 
 
76
 
    QGridLayout* grid = new QGridLayout(plainPage(), 1, 1, 0, spacingHint());
77
 
    QLabel *logo = new QLabel(plainPage());
78
 
    KIconLoader* iconLoader = KApplication::kApplication()->iconLoader();
79
 
    logo->setPixmap(iconLoader->loadIcon("digikam", KIcon::NoGroup, 96, KIcon::DefaultState, 0, true));    
80
 
 
81
 
    QVBoxLayout *topLayout = new QVBoxLayout(spacingHint());
82
 
 
83
 
    QLabel *topLabel = new QLabel(plainPage());
84
 
    QString tagName  = album->prettyURL();
85
 
    if (tagName.endsWith("/")) tagName.truncate(tagName.length()-1);
86
 
    topLabel->setText( i18n("<qt><b>Create New Tag in <i>\"%1\"</i></b></qt>").arg(tagName));
87
 
    topLabel->setAlignment(Qt::AlignAuto | Qt::AlignVCenter | Qt::SingleLine);
88
 
    topLayout->addWidget(topLabel);
89
 
 
90
 
    // --------------------------------------------------------
91
 
 
92
 
    QFrame *topLine = new QFrame( plainPage() );
93
 
    topLine->setFrameShape( QFrame::HLine );
94
 
    topLine->setFrameShadow( QFrame::Sunken );
95
 
    topLayout->addWidget( topLine );
96
 
 
97
 
    // --------------------------------------------------------
98
 
 
99
 
    QGridLayout *gl = new QGridLayout(topLayout, spacingHint());
100
 
 
101
 
    QLabel *titleLabel = new QLabel(plainPage());
102
 
    titleLabel->setText(i18n("&Title:"));
103
 
    gl->addWidget(titleLabel, 0, 0);
104
 
 
105
 
    d->titleEdit = new KLineEdit(plainPage());
106
 
    titleLabel->setBuddy(d->titleEdit);
107
 
    gl->addWidget(d->titleEdit, 0, 1);
108
 
 
109
 
    setFocusProxy(d->titleEdit);
110
 
 
111
 
    QLabel *iconTextLabel = new QLabel(plainPage());
112
 
    iconTextLabel->setText(i18n("&Icon:"));
113
 
    gl->addWidget(iconTextLabel, 1, 0);
114
 
 
115
 
    d->iconButton = new QPushButton(plainPage());
116
 
    d->iconButton->setFixedSize(40, 40);
117
 
    iconTextLabel->setBuddy(d->iconButton);
118
 
    gl->addWidget(d->iconButton, 1, 1);
119
 
 
120
 
    QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum,
121
 
                                          QSizePolicy::Expanding);
122
 
    gl->addItem(spacer, 2, 1);
123
 
 
124
 
    grid->addMultiCellWidget(logo, 0, 0, 0, 0);
125
 
    grid->addMultiCellLayout(topLayout, 0, 1, 1, 1);
126
 
    grid->setRowStretch(1, 10);
127
 
 
128
 
    // --------------------------------------------------------
129
 
 
130
 
    connect(d->iconButton, SIGNAL(clicked()),
131
 
            this, SLOT(slotIconChange()));
132
 
 
133
 
    connect(d->titleEdit, SIGNAL(textChanged(const QString&)),
134
 
            this, SLOT(slotTitleChanged(const QString&)));
135
 
    
136
 
    // --------------------------------------------------------
137
 
 
138
 
    // by default assign the icon of the parent (if not root)
139
 
    // to this new tag
140
 
    if (!album->isRoot())
141
 
        d->icon = album->icon();
142
 
    
143
 
    d->iconButton->setIconSet(SyncJob::getTagThumbnail(d->icon, 20));
144
 
 
145
 
    enableButtonOK(!d->titleEdit->text().isEmpty());
146
 
    adjustSize();
147
 
}
148
 
 
149
 
TagCreateDlg::~TagCreateDlg()
150
 
{
151
 
    delete d;
152
 
}
153
 
 
154
 
QString TagCreateDlg::title() const
155
 
{
156
 
    return d->titleEdit->text();
157
 
}
158
 
 
159
 
QString TagCreateDlg::icon() const
160
 
{
161
 
    return d->icon;
162
 
}
163
 
 
164
 
void TagCreateDlg::slotIconChange()
165
 
{
166
 
#if KDE_IS_VERSION(3,3,0)
167
 
    KIconDialog dlg(this);
168
 
    dlg.setup(KIcon::NoGroup, KIcon::Application, false, 20, false, false, false);
169
 
    QString icon = dlg.openDialog();
170
 
#else
171
 
    QString icon = KIconDialog::getIcon(KIcon::NoGroup, KIcon::Application, false, 20);
172
 
    if (icon.startsWith("/"))
173
 
        return;
174
 
#endif
175
 
 
176
 
    if (icon.isEmpty() || d->icon == icon)
177
 
        return;
178
 
 
179
 
    d->icon = icon;
180
 
    d->iconButton->setIconSet(SyncJob::getTagThumbnail(d->icon, 20));
181
 
}
182
 
 
183
 
void TagCreateDlg::slotTitleChanged(const QString& newtitle)
184
 
{
185
 
    enableButtonOK(!newtitle.isEmpty());
186
 
}
187
 
 
188
 
bool TagCreateDlg::tagCreate(QWidget *parent, TAlbum* album, QString& title, QString& icon)
189
 
{
190
 
    TagCreateDlg dlg(parent, album);
191
 
 
192
 
    bool valRet = dlg.exec();
193
 
    if (valRet == QDialog::Accepted)
194
 
    {
195
 
        title = dlg.title();
196
 
        icon  = dlg.icon();
197
 
    }
198
 
 
199
 
    return valRet;
200
 
}
201
 
 
202
 
// -------------------------------------------------------------------------------------
203
 
 
204
 
class TagEditDlgPriv
205
 
{
206
 
public:
207
 
 
208
 
    TagEditDlgPriv()
209
 
    {
210
 
        titleEdit       = 0;
211
 
        iconButton      = 0;
212
 
        resetIconButton = 0;
213
 
    }
214
 
 
215
 
    QString      icon;
216
 
 
217
 
    QPushButton *iconButton;
218
 
    QPushButton *resetIconButton;
219
 
 
220
 
    KLineEdit   *titleEdit;
221
 
};
222
 
 
223
 
TagEditDlg::TagEditDlg(QWidget *parent, TAlbum* album)
224
 
          : KDialogBase(Plain, i18n("Edit Tag"), Help|Ok|Cancel, Ok, parent, 0, true, true )
225
 
{
226
 
    d = new TagEditDlgPriv;
227
 
    setHelp("tagscreation.anchor", "digikam");
228
 
 
229
 
    QGridLayout* grid = new QGridLayout(plainPage(), 1, 1, 0, spacingHint());
230
 
    QLabel *logo = new QLabel(plainPage());
231
 
    KIconLoader* iconLoader = KApplication::kApplication()->iconLoader();
232
 
    logo->setPixmap(iconLoader->loadIcon("digikam", KIcon::NoGroup, 96, KIcon::DefaultState, 0, true));    
233
 
 
234
 
    QVBoxLayout *topLayout = new QVBoxLayout(spacingHint());
235
 
 
236
 
    QLabel *topLabel = new QLabel(plainPage());
237
 
    QString tagName  = album->prettyURL();
238
 
    if (tagName.endsWith("/")) tagName.truncate(tagName.length()-1);
239
 
    topLabel->setText( i18n("<qt><b>Tag <i>\"%1\"</i> Properties </b></qt>").arg(tagName));
240
 
    topLabel->setAlignment(Qt::AlignAuto | Qt::AlignVCenter | Qt::SingleLine);
241
 
    topLayout->addWidget(topLabel);
242
 
 
243
 
    // --------------------------------------------------------
244
 
 
245
 
    QFrame *topLine = new QFrame( plainPage() );
246
 
    topLine->setFrameShape( QFrame::HLine );
247
 
    topLine->setFrameShadow( QFrame::Sunken );
248
 
    topLayout->addWidget( topLine );
249
 
 
250
 
    // --------------------------------------------------------
251
 
 
252
 
    QGridLayout *gl = new QGridLayout(topLayout, spacingHint());
253
 
 
254
 
    QLabel *titleLabel = new QLabel(plainPage());
255
 
    titleLabel->setText(i18n("&Title:"));
256
 
 
257
 
    d->titleEdit = new KLineEdit(plainPage());
258
 
    d->titleEdit->setText(album->title());
259
 
    titleLabel->setBuddy(d->titleEdit);
260
 
    setFocusProxy(d->titleEdit);
261
 
 
262
 
    QLabel *iconTextLabel = new QLabel(plainPage());
263
 
    iconTextLabel->setText(i18n("&Icon:"));
264
 
 
265
 
    d->iconButton = new QPushButton(plainPage());
266
 
    d->iconButton->setFixedSize(40, 40);
267
 
    iconTextLabel->setBuddy(d->iconButton);
268
 
    
269
 
    d->resetIconButton = new QPushButton(i18n("Reset"), plainPage());
270
 
 
271
 
    QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum,
272
 
                                           QSizePolicy::Expanding);
273
 
    
274
 
    gl->addWidget(titleLabel, 0, 0);
275
 
    gl->addMultiCellWidget(d->titleEdit, 0, 0, 1, 3);
276
 
    gl->addWidget(iconTextLabel, 1, 0);
277
 
    gl->addWidget(d->iconButton, 1, 1);
278
 
    gl->addWidget(d->resetIconButton, 1, 2);
279
 
    gl->addItem(spacer, 1, 3);
280
 
    
281
 
    grid->addMultiCellWidget(logo, 0, 0, 0, 0);
282
 
    grid->addMultiCellLayout(topLayout, 0, 1, 1, 1);
283
 
    grid->setRowStretch(1, 10);
284
 
 
285
 
    // --------------------------------------------------------
286
 
 
287
 
    connect(d->iconButton, SIGNAL(clicked()),
288
 
            this, SLOT(slotIconChange()));
289
 
 
290
 
    connect(d->resetIconButton, SIGNAL(clicked()),
291
 
            this, SLOT(slotIconResetClicked()));
292
 
            
293
 
    connect(d->titleEdit, SIGNAL(textChanged(const QString&)),
294
 
            this, SLOT(slotTitleChanged(const QString&)));
295
 
 
296
 
    // --------------------------------------------------------
297
 
 
298
 
    d->icon = album->icon();
299
 
    d->iconButton->setIconSet(SyncJob::getTagThumbnail(d->icon, 20));
300
 
 
301
 
    enableButtonOK(!d->titleEdit->text().isEmpty());
302
 
    adjustSize();
303
 
}
304
 
 
305
 
TagEditDlg::~TagEditDlg()
306
 
{
307
 
    delete d;
308
 
}
309
 
 
310
 
QString TagEditDlg::title() const
311
 
{
312
 
    return d->titleEdit->text();
313
 
}
314
 
 
315
 
QString TagEditDlg::icon() const
316
 
{
317
 
    return d->icon;
318
 
}
319
 
 
320
 
void TagEditDlg::slotIconResetClicked()
321
 
{
322
 
    d->icon = QString("tag");
323
 
    d->iconButton->setIconSet(SyncJob::getTagThumbnail(d->icon, 20));
324
 
}
325
 
    
326
 
void TagEditDlg::slotIconChange()
327
 
{
328
 
#if KDE_IS_VERSION(3,3,0)
329
 
    KIconDialog dlg(this);
330
 
    dlg.setup(KIcon::NoGroup, KIcon::Application, false, 20, false, false, false);
331
 
    QString icon = dlg.openDialog();
332
 
#else
333
 
    QString icon = KIconDialog::getIcon(KIcon::NoGroup, KIcon::Application, false, 20);
334
 
    if (icon.startsWith("/"))
335
 
        return;
336
 
#endif
337
 
    
338
 
    if (icon.isEmpty() || icon == d->icon)
339
 
        return;
340
 
 
341
 
    d->icon = icon;
342
 
    d->iconButton->setIconSet(SyncJob::getTagThumbnail(d->icon, 20));
343
 
}
344
 
 
345
 
void TagEditDlg::slotTitleChanged(const QString& newtitle)
346
 
{
347
 
    enableButtonOK(!newtitle.isEmpty());
348
 
}
349
 
 
350
 
bool TagEditDlg::tagEdit(QWidget *parent, TAlbum* album, QString& title, QString& icon)
351
 
{
352
 
    TagEditDlg dlg(parent, album);
353
 
 
354
 
    bool valRet = dlg.exec();
355
 
    if (valRet == QDialog::Accepted)
356
 
    {
357
 
        title = dlg.title();
358
 
        icon  = dlg.icon();
359
 
    }
360
 
 
361
 
    return valRet;
362
 
}
363
 
 
364
 
}  // namespace Digikam
365
 
 
366