]>
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/QLabel>
32 class Nepomuk::ResourceTaggingWidget::Private
35 Nepomuk::Resource resource
;
37 TagCloud
* resourceTagCloud
;
40 QList
<Tag
> resourceTags
;
42 void showTaggingPopup( const QPoint
& );
43 void _k_slotShowTaggingPopup();
47 void Nepomuk::ResourceTaggingWidget::Private::showTaggingPopup( const QPoint
& pos
)
50 resourceTags
= resource
.tags();
51 Q_FOREACH( Tag tag
, resourceTags
) {
52 popup
->setTagSelected( tag
, true );
57 resource
.setTags( resourceTags
);
61 void Nepomuk::ResourceTaggingWidget::Private::_k_slotShowTaggingPopup()
63 showTaggingPopup( QCursor::pos() );
67 Nepomuk::ResourceTaggingWidget::ResourceTaggingWidget( QWidget
* parent
)
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
);
80 // the popup tag cloud
81 d
->popup
= new TaggingPopup
;
82 d
->popup
->setSelectionEnabled( true );
83 d
->popup
->setNewTagButtonEnabled( true );
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
& ) ) );
90 connect( d
->resourceTagCloud
, SIGNAL( tagClicked( const Nepomuk::Tag
& ) ),
91 this, SIGNAL( tagClicked( const Nepomuk::Tag
& ) ) );
95 Nepomuk::ResourceTaggingWidget::~ResourceTaggingWidget()
102 void Nepomuk::ResourceTaggingWidget::setResource( const Nepomuk::Resource
& res
)
105 d
->resourceTagCloud
->showResourceTags( res
);
109 void Nepomuk::ResourceTaggingWidget::slotTagToggled( const Nepomuk::Tag
& tag
, bool enabled
)
112 d
->resourceTags
.append( tag
);
115 d
->resourceTags
.removeAll( tag
);
121 void Nepomuk::ResourceTaggingWidget::slotTagAdded( const Nepomuk::Tag
& tag
)
123 // assign it right away
124 d
->resourceTags
.append( tag
);
125 d
->resource
.addTag( tag
);
129 void Nepomuk::ResourceTaggingWidget::contextMenuEvent( QContextMenuEvent
* e
)
131 d
->showTaggingPopup( e
->globalPos() );
134 #include "resourcetaggingwidget.moc"