Warning, file /sdk/cervisia/annotatedialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  Copyright (C) 1999-2002 Bernd Gehrmann
0003  *                          bernd@mail.berlios.de
0004  *
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 #include "annotatedialog.h"
0021 #include "annotateview.h"
0022 
0023 #include <KConfigGroup>
0024 #include <KHelpClient>
0025 #include <KLocalizedString>
0026 #include <kconfig.h>
0027 
0028 #include <QDialogButtonBox>
0029 #include <QInputDialog>
0030 #include <QLineEdit>
0031 #include <QPushButton>
0032 #include <QVBoxLayout>
0033 
0034 AnnotateDialog::AnnotateDialog(KConfig &cfg, QWidget *parent)
0035     : QDialog(parent)
0036     , partConfig(cfg)
0037 {
0038     auto mainLayout = new QVBoxLayout;
0039     setLayout(mainLayout);
0040 
0041     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Close);
0042 
0043     auto user1Button = new QPushButton;
0044     user1Button->setText(i18n("Go to Line..."));
0045     user1Button->setAutoDefault(false);
0046     buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
0047 
0048     auto user2Button = new QPushButton;
0049     user2Button->setText(i18n("Find Prev"));
0050     user2Button->setAutoDefault(false);
0051     buttonBox->addButton(user2Button, QDialogButtonBox::ActionRole);
0052 
0053     auto user3Button = new QPushButton;
0054     user3Button->setText(i18n("Find Next"));
0055     buttonBox->addButton(user3Button, QDialogButtonBox::ActionRole);
0056 
0057     buttonBox->button(QDialogButtonBox::Help)->setAutoDefault(false);
0058 
0059     connect(buttonBox, &QDialogButtonBox::rejected, this, &AnnotateDialog::reject);
0060     connect(buttonBox, &QDialogButtonBox::helpRequested, this, &AnnotateDialog::slotHelp);
0061 
0062     findEdit = new QLineEdit;
0063     findEdit->setClearButtonEnabled(true);
0064     findEdit->setPlaceholderText(i18n("Search"));
0065 
0066     annotate = new AnnotateView(this);
0067 
0068     mainLayout->addWidget(findEdit);
0069     mainLayout->addWidget(annotate);
0070     mainLayout->addWidget(buttonBox);
0071 
0072     connect(user3Button, SIGNAL(clicked()), this, SLOT(findNext()));
0073     connect(user2Button, SIGNAL(clicked()), this, SLOT(findPrev()));
0074     connect(user1Button, SIGNAL(clicked()), this, SLOT(gotoLine()));
0075 
0076     setAttribute(Qt::WA_DeleteOnClose, true);
0077 
0078     KConfigGroup cg(&partConfig, "AnnotateDialog");
0079     restoreGeometry(cg.readEntry<QByteArray>("geometry", QByteArray()));
0080 
0081     findEdit->setFocus();
0082 }
0083 
0084 AnnotateDialog::~AnnotateDialog()
0085 {
0086     KConfigGroup cg(&partConfig, "AnnotateDialog");
0087     cg.writeEntry("geometry", saveGeometry());
0088 }
0089 
0090 void AnnotateDialog::slotHelp()
0091 {
0092     KHelpClient::invokeHelp(QLatin1String("annotate"));
0093 }
0094 
0095 void AnnotateDialog::addLine(const Cervisia::LogInfo &logInfo, const QString &content, bool odd)
0096 {
0097     annotate->addLine(logInfo, content, odd);
0098 }
0099 
0100 void AnnotateDialog::findNext()
0101 {
0102     if (!findEdit->text().isEmpty())
0103         annotate->findText(findEdit->text(), false);
0104 }
0105 
0106 void AnnotateDialog::findPrev()
0107 {
0108     if (!findEdit->text().isEmpty())
0109         annotate->findText(findEdit->text(), true);
0110 }
0111 
0112 void AnnotateDialog::gotoLine()
0113 {
0114     bool ok = false;
0115     int line = QInputDialog::getInt(this, i18n("Go to Line"), i18n("Go to line number:"), annotate->currentLine(), 1, annotate->lastLine(), 1, &ok);
0116 
0117     if (ok)
0118         annotate->gotoLine(line);
0119 }
0120 
0121 // Local Variables:
0122 // c-basic-offset: 4
0123 // End: