]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/commentwidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org> *
3 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "commentwidget_p.h"
24 #include <kglobalsettings.h>
29 #include <QVBoxLayout>
31 CommentWidget::CommentWidget(QWidget
* parent
) :
36 m_label
= new QLabel(this);
37 m_label
->setFont(KGlobalSettings::smallestReadableFont());
38 connect(m_label
, SIGNAL(linkActivated(const QString
&)), this, SLOT(slotLinkActivated(const QString
&)));
40 QVBoxLayout
* layout
= new QVBoxLayout(this);
41 layout
->addWidget(m_label
);
46 CommentWidget::~CommentWidget()
50 void CommentWidget::setText(const QString
& comment
)
52 if (comment
.isEmpty()) {
53 m_label
->setText("<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>");
55 m_label
->setText("<p>" + comment
+ " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>");
60 QString
CommentWidget::text() const
65 void CommentWidget::slotLinkActivated(const QString
& link
)
67 KDialog
dialog(0, Qt::Dialog
);
69 QTextEdit
* editor
= new QTextEdit(&dialog
);
70 editor
->setText(m_comment
);
72 dialog
.setMainWidget(editor
);
74 const QString caption
= (link
== "changeComment") ?
75 i18nc("@title:window", "Change Comment") :
76 i18nc("@title:window", "Add Comment");
77 dialog
.setCaption(caption
);
78 dialog
.setButtons(KDialog::Ok
| KDialog::Cancel
);
79 dialog
.setDefaultButton(KDialog::Ok
);
81 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
83 dialog
.restoreDialogSize(dialogConfig
);
85 if (dialog
.exec() == QDialog::Accepted
) {
86 setText(editor
->toPlainText());
89 dialog
.saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
92 #include "commentwidget_p.moc"