]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/commentwidget.cpp
Disable additional properties per default as discussed with Sebastian TrĂ¼g.
[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 <QtGui/QScrollArea>
28 #include <QtCore/QEvent>
29
30 #include <KLocale>
31
32
33 class CommentWidget::Private
34 {
35 public:
36 Private( CommentWidget* parent )
37 : q( parent ) {
38 }
39
40 void update();
41 void _k_slotEnableEditing();
42
43 QLabel* commentLabel;
44 QScrollArea* scrollArea;
45 QLabel* commentLink;
46 CommentEditWidget* edit;
47
48 QString comment;
49
50 private:
51 CommentWidget* q;
52 };
53
54
55 void CommentWidget::Private::update()
56 {
57 commentLabel->setText( comment );
58 if ( comment.isEmpty() ) {
59 scrollArea->hide();
60 commentLink->setText( "<p align=center><a style=\"font-size:small;\" href=\"addComment\">" + i18nc( "@label", "Add Comment..." ) + "</a>" );
61 }
62 else {
63 scrollArea->show();
64 commentLink->setText( "<p align=center><a style=\"font-size:small;\" href=\"addComment\">" + i18nc( "@label", "Change Comment..." ) + "</a>" );
65 }
66 }
67
68
69 void CommentWidget::Private::_k_slotEnableEditing()
70 {
71 CommentEditWidget w;
72 w.setComment( comment );
73 if ( w.exec( QCursor::pos() ) ) {
74 comment = w.comment();
75 update();
76 emit q->commentChanged( comment );
77 }
78 }
79
80
81
82 CommentWidget::CommentWidget( QWidget* parent )
83 : QWidget( parent ),
84 d( new Private( this ) )
85 {
86 d->commentLabel = new QLabel( this );
87 d->commentLabel->setWordWrap( true );
88
89 d->scrollArea = new QScrollArea( this );
90 d->scrollArea->setWidget( d->commentLabel );
91 d->scrollArea->setWidgetResizable( true );
92 d->scrollArea->setFrameShape( QFrame::StyledPanel );
93
94 d->commentLink = new QLabel( this );
95
96 QVBoxLayout* layout = new QVBoxLayout( this );
97 layout->setMargin( 0 );
98 layout->addWidget( d->scrollArea );
99 layout->addWidget( d->commentLink );
100 d->update();
101 connect( d->commentLink, SIGNAL( linkActivated( const QString& ) ), this, SLOT( _k_slotEnableEditing() ) );
102 }
103
104
105 CommentWidget::~CommentWidget()
106 {
107 delete d;
108 }
109
110
111 void CommentWidget::setComment( const QString& comment )
112 {
113 d->comment = comment;
114 d->update();
115 }
116
117
118 QString CommentWidget::comment() const
119 {
120 return d->comment;
121 }
122
123
124 bool CommentWidget::eventFilter( QObject* watched, QEvent* event )
125 {
126 return QWidget::eventFilter( watched, event );
127 }
128
129 #include "commentwidget.moc"