]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tagcloud/resourcetaggingwidget.cpp
2 This file is part of the Nepomuk KDE project.
3 Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "resourcetaggingwidget.h"
22 #include "taggingpopup.h"
24 #include <QtGui/QVBoxLayout>
25 #include <QtGui/QContextMenuEvent>
26 #include <QtGui/QCursor>
27 #include <QtGui/QAction>
32 class Nepomuk::ResourceTaggingWidget::Private
35 Nepomuk::Resource resource
;
37 TagCloud
* resourceTagCloud
;
40 QList
<Tag
> resourceTags
;
42 QAction
* changeTagsAction
;
44 void showTaggingPopup( const QPoint
& );
45 void _k_slotShowTaggingPopup();
49 void Nepomuk::ResourceTaggingWidget::Private::showTaggingPopup( const QPoint
& pos
)
52 resourceTags
= resource
.tags();
53 Q_FOREACH( Tag tag
, resourceTags
) {
54 popup
->setTagSelected( tag
, true );
59 resource
.setTags( resourceTags
);
63 void Nepomuk::ResourceTaggingWidget::Private::_k_slotShowTaggingPopup()
65 showTaggingPopup( QCursor::pos() );
69 Nepomuk::ResourceTaggingWidget::ResourceTaggingWidget( QWidget
* parent
)
73 QVBoxLayout
* layout
= new QVBoxLayout( this );
74 layout
->setMargin( 0 );
75 d
->resourceTagCloud
= new TagCloud( this );
76 layout
->addWidget( d
->resourceTagCloud
);
78 d
->changeTagsAction
= new QAction( i18n( "Change tags..." ), this );
79 d
->resourceTagCloud
->setCustomNewTagAction( d
->changeTagsAction
);
81 // the popup tag cloud
82 d
->popup
= new TaggingPopup
;
83 d
->popup
->setSelectionEnabled( true );
84 d
->popup
->setNewTagButtonEnabled( true );
86 connect( d
->popup
, SIGNAL( tagToggled( const Nepomuk::Tag
&, bool ) ),
87 this, SLOT( slotTagToggled( const Nepomuk::Tag
&, bool ) ) );
88 connect( d
->popup
, SIGNAL( tagAdded( const Nepomuk::Tag
& ) ),
89 this, SLOT( slotTagAdded( const Nepomuk::Tag
& ) ) );
91 connect( d
->changeTagsAction
, SIGNAL( activated() ),
92 this, SLOT( _k_slotShowTaggingPopup() ) );
94 connect( d
->resourceTagCloud
, SIGNAL( tagClicked( const Nepomuk::Tag
& ) ),
95 this, SIGNAL( tagClicked( const Nepomuk::Tag
& ) ) );
99 Nepomuk::ResourceTaggingWidget::~ResourceTaggingWidget()
106 void Nepomuk::ResourceTaggingWidget::setResource( const Nepomuk::Resource
& res
)
109 d
->resourceTagCloud
->showResourceTags( res
);
113 void Nepomuk::ResourceTaggingWidget::slotTagToggled( const Nepomuk::Tag
& tag
, bool enabled
)
116 d
->resourceTags
.append( tag
);
119 d
->resourceTags
.removeAll( tag
);
125 void Nepomuk::ResourceTaggingWidget::slotTagAdded( const Nepomuk::Tag
& tag
)
127 // assign it right away
128 d
->resourceTags
.append( tag
);
129 d
->resource
.addTag( tag
);
133 void Nepomuk::ResourceTaggingWidget::contextMenuEvent( QContextMenuEvent
* e
)
135 d
->showTaggingPopup( e
->globalPos() );
138 #include "resourcetaggingwidget.moc"