]> cloud.milkyroute.net Git - dolphin.git/blob - src/tagcloud/resourcetaggingwidget.cpp
Removed minimum size hint since we have zooming anyway.
[dolphin.git] / src / tagcloud / resourcetaggingwidget.cpp
1 /*
2 This file is part of the Nepomuk KDE project.
3 Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
4
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.
8
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.
13
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.
18 */
19
20 #include "resourcetaggingwidget.h"
21 #include "tagcloud.h"
22 #include "taggingpopup.h"
23
24 #include <QtGui/QVBoxLayout>
25 #include <QtGui/QContextMenuEvent>
26 #include <QtGui/QCursor>
27 #include <QtGui/QLabel>
28
29 #include <KLocale>
30
31
32 class Nepomuk::ResourceTaggingWidget::Private
33 {
34 public:
35 Nepomuk::Resource resource;
36
37 TagCloud* resourceTagCloud;
38 TaggingPopup* popup;
39
40 QList<Tag> resourceTags;
41
42 void showTaggingPopup( const QPoint& );
43 void _k_slotShowTaggingPopup();
44 };
45
46
47 void Nepomuk::ResourceTaggingWidget::Private::showTaggingPopup( const QPoint& pos )
48 {
49 popup->showAllTags();
50 resourceTags = resource.tags();
51 Q_FOREACH( Tag tag, resourceTags ) {
52 popup->setTagSelected( tag, true );
53 }
54
55 popup->exec( pos );
56
57 resource.setTags( resourceTags );
58 }
59
60
61 void Nepomuk::ResourceTaggingWidget::Private::_k_slotShowTaggingPopup()
62 {
63 showTaggingPopup( QCursor::pos() );
64 }
65
66
67 Nepomuk::ResourceTaggingWidget::ResourceTaggingWidget( QWidget* parent )
68 : QWidget( parent ),
69 d( new Private() )
70 {
71 QVBoxLayout* layout = new QVBoxLayout( this );
72 layout->setMargin( 0 );
73 d->resourceTagCloud = new TagCloud( this );
74 layout->addWidget( d->resourceTagCloud );
75 QLabel* changeTagsLabel = new QLabel( "<p align=center><a style=\"font-size:small;\" href=\"dummy\">" + i18n( "Change tags..." ) + "</a>", this );
76 connect( changeTagsLabel, SIGNAL( linkActivated( const QString ) ),
77 this, SLOT( _k_slotShowTaggingPopup() ) );
78 layout->addWidget( changeTagsLabel );
79
80 // the popup tag cloud
81 d->popup = new TaggingPopup;
82 d->popup->setSelectionEnabled( true );
83 d->popup->setNewTagButtonEnabled( true );
84
85 connect( d->popup, SIGNAL( tagToggled( const Nepomuk::Tag&, bool ) ),
86 this, SLOT( slotTagToggled( const Nepomuk::Tag&, bool ) ) );
87 connect( d->popup, SIGNAL( tagAdded( const Nepomuk::Tag& ) ),
88 this, SLOT( slotTagAdded( const Nepomuk::Tag& ) ) );
89
90 connect( d->resourceTagCloud, SIGNAL( tagClicked( const Nepomuk::Tag& ) ),
91 this, SIGNAL( tagClicked( const Nepomuk::Tag& ) ) );
92 }
93
94
95 Nepomuk::ResourceTaggingWidget::~ResourceTaggingWidget()
96 {
97 delete d->popup;
98 delete d;
99 }
100
101
102 void Nepomuk::ResourceTaggingWidget::setResource( const Nepomuk::Resource& res )
103 {
104 d->resource = res;
105 d->resourceTagCloud->showResourceTags( res );
106 }
107
108
109 void Nepomuk::ResourceTaggingWidget::slotTagToggled( const Nepomuk::Tag& tag, bool enabled )
110 {
111 if ( enabled ) {
112 d->resourceTags.append( tag );
113 }
114 else {
115 d->resourceTags.removeAll( tag );
116 }
117 d->popup->hide();
118 }
119
120
121 void Nepomuk::ResourceTaggingWidget::slotTagAdded( const Nepomuk::Tag& tag )
122 {
123 // assign it right away
124 d->resourceTags.append( tag );
125 d->resource.addTag( tag );
126 }
127
128
129 void Nepomuk::ResourceTaggingWidget::contextMenuEvent( QContextMenuEvent* e )
130 {
131 d->showTaggingPopup( e->globalPos() );
132 }
133
134 #include "resourcetaggingwidget.moc"