]>
cloud.milkyroute.net Git - dolphin.git/blob - src/metadatawidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2007 by Sebastian Trueg <trueg@kde.org> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program 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 *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include <config-kmetadata.h>
22 #include "metadatawidget.h"
27 #include <QGridLayout>
31 #include <kmetadatatagwidget.h>
32 #include <kmetadata/resourcemanager.h>
33 #include <kmetadata/file.h>
34 #include <kratingwidget.h>
35 #include <kmetadatatagwidget.h>
39 bool MetaDataWidget::metaDataAvailable()
42 return !Nepomuk::KMetaData::ResourceManager::instance()->init();
49 class MetaDataWidget::Private
52 void loadComment( const QString
& comment
) {
53 editComment
->blockSignals( true );
54 if ( comment
.isEmpty() ) {
55 editComment
->setFontItalic( true );
56 editComment
->setText( i18n( "Click to add comment..." ) );
59 editComment
->setFontItalic( false );
60 editComment
->setText( comment
);
62 editComment
->blockSignals( false );
68 Nepomuk::KMetaData::File file
;
70 QTextEdit
* editComment
;
71 KRatingWidget
* ratingWidget
;
72 Nepomuk::KMetaData::TagWidget
* tagWidget
;
77 MetaDataWidget::MetaDataWidget( QWidget
* parent
)
83 d
->editComment
= new QTextEdit( this );
84 d
->tagWidget
= new Nepomuk::KMetaData::TagWidget( this );
85 d
->ratingWidget
= new KRatingWidget( this );
86 connect( d
->ratingWidget
, SIGNAL(ratingChanged(int)), this, SLOT(slotRatingChanged(int)) );
87 connect( d
->editComment
, SIGNAL( textChanged() ), this, SLOT( slotCommentChanged() ) );
89 QVBoxLayout
* lay
= new QVBoxLayout( this );
91 QHBoxLayout
* hbox
= new QHBoxLayout
;
92 hbox
->addWidget( new QLabel( i18n( "Rating:" ), this ) );
93 hbox
->addStretch( 1 );
94 hbox
->addWidget( d
->ratingWidget
);
95 lay
->addLayout( hbox
);
96 lay
->addWidget( d
->editComment
);
97 hbox
= new QHBoxLayout
;
98 hbox
->addWidget( new QLabel( i18n( "Tags:" ), this ) );
99 hbox
->addWidget( d
->tagWidget
, 1 );
100 lay
->addLayout( hbox
);
102 d
->editComment
->installEventFilter( this );
103 d
->editComment
->viewport()->installEventFilter( this );
108 MetaDataWidget::~MetaDataWidget()
114 void MetaDataWidget::setFile( const KUrl
& url
)
116 #ifdef HAVE_KMETADATA
118 d
->file
= Nepomuk::KMetaData::File( url
.url() );
119 d
->file
.setLocation( url
.url() );
120 d
->ratingWidget
->setRating( d
->file
.getRating() );
121 d
->tagWidget
->setTaggedResource( d
->file
);
122 d
->loadComment( d
->file
.getComment() );
127 void MetaDataWidget::setFiles( const KUrl::List urls
)
129 // FIXME: support multiple files
130 setFile( urls
.first() );
134 void MetaDataWidget::slotCommentChanged()
136 d
->file
.setComment( d
->editComment
->toPlainText() );
140 void MetaDataWidget::slotRatingChanged( int r
)
142 d
->file
.setRating( r
);
146 bool MetaDataWidget::eventFilter( QObject
* obj
, QEvent
* event
)
148 if ( obj
== d
->editComment
->viewport()
149 || obj
== d
->editComment
) {
150 if ( event
->type() == QEvent::FocusOut
) {
151 // make sure the info text is displayed again
152 d
->loadComment( d
->editComment
->toPlainText() );
154 else if ( event
->type() == QEvent::FocusIn
) {
155 qDebug() << "JKGHLKGLKHÖLKJHLÖ" << endl
;
156 d
->editComment
->setFontItalic( false );
157 if ( d
->file
.getComment().isEmpty() )
158 d
->editComment
->setText( QString() );
162 return QWidget::eventFilter( obj
, event
);
165 #include "metadatawidget.moc"