]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/commentwidget.cpp
Group classes into folders, Dolphin is too big in the meantime for having a flat...
[dolphin.git] / src / panels / information / commentwidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "commentwidget.h"
21 #include "commenteditwidget.h"
22
23 #include <QtGui/QLabel>
24 #include <QtGui/QTextEdit>
25 #include <QtGui/QLayout>
26 #include <QtGui/QCursor>
27 #include <QtCore/QEvent>
28
29 #include <KLocale>
30
31
32 class CommentWidget::Private
33 {
34 public:
35 Private( CommentWidget* parent )
36 : q( parent ) {
37 }
38
39 void update();
40 void _k_slotEnableEditing();
41
42 QLabel* label;
43 CommentEditWidget* edit;
44
45 QString comment;
46
47 private:
48 CommentWidget* q;
49 };
50
51
52 void CommentWidget::Private::update()
53 {
54 if ( comment.isEmpty() ) {
55 label->setText( "<p align=center><a style=\"font-size:small;\" href=\"addComment\">" + i18nc( "@label", "Add Comment..." ) + "</a>" );
56 }
57 else {
58 label->setText( "<p>" + comment + "<p align=center><a style=\"font-size:small;\" href=\"addComment\">" + i18nc( "@label", "Change Comment..." ) + "</a>" );
59 }
60 }
61
62
63 void CommentWidget::Private::_k_slotEnableEditing()
64 {
65 CommentEditWidget w;
66 w.setComment( comment );
67 if ( w.exec( QCursor::pos() ) ) {
68 comment = w.comment();
69 update();
70 emit q->commentChanged( comment );
71 }
72 }
73
74
75
76 CommentWidget::CommentWidget( QWidget* parent )
77 : QWidget( parent ),
78 d( new Private( this ) )
79 {
80 d->label = new QLabel( this );
81 d->label->setWordWrap( true );
82 QVBoxLayout* layout = new QVBoxLayout( this );
83 layout->setMargin( 0 );
84 layout->addWidget( d->label );
85 d->update();
86 connect( d->label, SIGNAL( linkActivated( const QString& ) ), this, SLOT( _k_slotEnableEditing() ) );
87 }
88
89
90 CommentWidget::~CommentWidget()
91 {
92 delete d;
93 }
94
95
96 void CommentWidget::setComment( const QString& comment )
97 {
98 d->comment = comment;
99 d->update();
100 }
101
102
103 QString CommentWidget::comment() const
104 {
105 return d->comment;
106 }
107
108
109 bool CommentWidget::eventFilter( QObject* watched, QEvent* event )
110 {
111 return QWidget::eventFilter( watched, event );
112 }
113
114 #include "commentwidget.moc"