1 /* Copyright (C) 2003-2006 Jesper K. Pedersen <blackie@kde.org>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "CategoryImagePopup.h"
21 #include <Utilities/Set.h>
22 #include <qstringlist.h>
24 #include "DB/CategoryCollection.h"
25 #include "Viewer/CategoryImageConfig.h"
28 void MainWindow::CategoryImagePopup::populate( const QImage
& image
, const QString
& imageName
)
33 _imageInfo
= DB::ImageDB::instance()->info( imageName
, DB::AbsolutePath
);
36 QList
<DB::CategoryPtr
> categories
= DB::ImageDB::instance()->categoryCollection()->categories();
37 for ( QList
<DB::CategoryPtr
>::Iterator categoryIt
= categories
.begin(); categoryIt
!= categories
.end(); ++categoryIt
) {
38 if ( !(*categoryIt
)->isSpecialCategory() ) {
39 bool categoryMenuEnabled
= false;
40 const QString categoryName
= (*categoryIt
)->name();
41 QMenu
* categoryMenu
= new QMenu(this);
42 categoryMenu
->setTitle( (*categoryIt
)->text() );
44 // add category members
45 Utilities::StringSet members
= _imageInfo
->itemsOfCategory( categoryName
);
46 for ( Utilities::StringSet::const_iterator memberIt
= members
.begin();
47 memberIt
!= members
.end(); ++memberIt
) {
48 QAction
* action
= categoryMenu
->addAction( *memberIt
);
49 action
->setObjectName( categoryName
);
50 action
->setData( *memberIt
);
51 categoryMenuEnabled
= true;
54 categoryMenu
->setEnabled(categoryMenuEnabled
);
55 addMenu( categoryMenu
);
59 // Add the Category Editor menu item
60 QAction
* action
= addAction( QString::fromLatin1("viewer-show-category-editor"), this, SLOT( makeCategoryImage()) );
61 action
->setText( i18n("Show Category Editor") );
64 void MainWindow::CategoryImagePopup::slotExecuteService( QAction
* action
)
66 QString categoryName
= action
->objectName();
67 QString memberName
= action
->data().toString();
68 if (categoryName
.isNull())
70 DB::ImageDB::instance()->categoryCollection()->categoryForName( categoryName
)->
71 setCategoryImage(categoryName
, memberName
, _image
);
74 void MainWindow::CategoryImagePopup::makeCategoryImage()
76 CategoryImageConfig::instance()->setCurrentImage( _image
, _imageInfo
);
77 CategoryImageConfig::instance()->show();
80 MainWindow::CategoryImagePopup::CategoryImagePopup( QWidget
* parent
)
83 setTitle( i18n("Make Category Image") );
84 connect( this, SIGNAL( triggered( QAction
* ) ), this, SLOT( slotExecuteService( QAction
* ) ) );
87 #include "CategoryImagePopup.moc"