File indexing completed on 2024-05-12 16:35:16

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003 Norbert Andres <nandres@web.de>
0003              (C) 2002 Ariya Hidayat <ariya@kde.org>
0004              (C) 2002 Philipp Mueller <philipp.mueller@gmx.de>
0005              (C) 1999-2002 Laurent Montel <montel@kde.org>
0006              (C) 1998-1999 Torben Weis <weis@kde.org>
0007 
0008    This library is free software; you can redistribute it and/or
0009    modify it under the terms of the GNU Library General Public
0010    License as published by the Free Software Foundation; either
0011    version 2 of the License, or (at your option) any later version.
0012 
0013    This library is distributed in the hope that it will be useful,
0014    but WITHOUT ANY WARRANTY; without even the implied warranty of
0015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016    Library General Public License for more details.
0017 
0018    You should have received a copy of the GNU Library General Public License
0019    along with this library; see the file COPYING.LIB.  If not, write to
0020    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0021    Boston, MA 02110-1301, USA.
0022 */
0023 
0024 // Local
0025 #include "CommentDialog.h"
0026 
0027 #include <QPushButton>
0028 #include <QVBoxLayout>
0029 
0030 #include <KLocalizedString>
0031 #include <ktextedit.h>
0032 
0033 // Sheets
0034 #include "Cell.h"
0035 #include "ui/Selection.h"
0036 #include "Sheet.h"
0037 
0038 #include "commands/CommentCommand.h"
0039 
0040 using namespace Calligra::Sheets;
0041 
0042 CommentDialog::CommentDialog(QWidget* parent, Selection* selection)
0043         : KoDialog(parent)
0044 {
0045     setCaption(i18n("Cell Comment"));
0046     setModal(true);
0047     setButtons(Ok | Cancel);
0048 
0049     m_selection = selection;
0050 
0051     QWidget *page = new QWidget();
0052     setMainWidget(page);
0053     QVBoxLayout *lay1 = new QVBoxLayout(page);
0054 
0055     multiLine = new KTextEdit(page);
0056     lay1->addWidget(multiLine);
0057 
0058     multiLine->setFocus();
0059 
0060     const QString comment = Cell(m_selection->activeSheet(), m_selection->marker()).comment();
0061     if (!comment.isEmpty())
0062         multiLine->setText(comment);
0063 
0064     connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
0065     connect(multiLine, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
0066 
0067     slotTextChanged();
0068     resize(400, height());
0069 }
0070 
0071 void CommentDialog::slotTextChanged()
0072 {
0073     enableButtonOk(!multiLine->toPlainText().isEmpty());
0074 }
0075 
0076 void CommentDialog::slotOk()
0077 {
0078     CommentCommand* command = new CommentCommand();
0079     command->setSheet(m_selection->activeSheet());
0080     command->setText(kundo2_i18n("Add Comment"));
0081     command->setComment(multiLine->toPlainText().trimmed());
0082     command->add(*m_selection);
0083     command->execute(m_selection->canvas());
0084     accept();
0085 }