1 /*
2  *  Copyright (C) 1999-2002 Bernd Gehrmann
3  *                          bernd@mail.berlios.de
4  *
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.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19 
20 
21 #include "annotatedialog.h"
22 #include "annotateview.h"
23 
24 #include <kconfig.h>
25 #include <KConfigGroup>
26 #include <KHelpClient>
27 #include <KLocalizedString>
28 
29 #include <QLineEdit>
30 #include <QPushButton>
31 #include <QVBoxLayout>
32 #include <QInputDialog>
33 #include <QDialogButtonBox>
34 
AnnotateDialog(KConfig & cfg,QWidget * parent)35 AnnotateDialog::AnnotateDialog(KConfig& cfg, QWidget *parent)
36     : QDialog(parent)
37     , partConfig(cfg)
38 {
39     QVBoxLayout *mainLayout = new QVBoxLayout;
40     setLayout(mainLayout);
41 
42     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Close);
43 
44     QPushButton *user1Button = new QPushButton;
45     user1Button->setText(i18n("Go to Line..."));
46     user1Button->setAutoDefault(false);
47     buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
48 
49     QPushButton *user2Button = new QPushButton;
50     user2Button->setText(i18n("Find Prev"));
51     user2Button->setAutoDefault(false);
52     buttonBox->addButton(user2Button, QDialogButtonBox::ActionRole);
53 
54     QPushButton *user3Button = new QPushButton;
55     user3Button->setText(i18n("Find Next"));
56     buttonBox->addButton(user3Button, QDialogButtonBox::ActionRole);
57 
58     buttonBox->button(QDialogButtonBox::Help)->setAutoDefault(false);
59 
60     connect(buttonBox, &QDialogButtonBox::rejected, this, &AnnotateDialog::reject);
61     connect(buttonBox, &QDialogButtonBox::helpRequested, this, &AnnotateDialog::slotHelp);
62 
63     findEdit = new QLineEdit;
64     findEdit->setClearButtonEnabled(true);
65     findEdit->setPlaceholderText(i18n("Search"));
66 
67     annotate = new AnnotateView(this);
68 
69     mainLayout->addWidget(findEdit);
70     mainLayout->addWidget(annotate);
71     mainLayout->addWidget(buttonBox);
72 
73     connect(user3Button, SIGNAL(clicked()), this, SLOT(findNext()));
74     connect(user2Button, SIGNAL(clicked()), this, SLOT(findPrev()));
75     connect(user1Button, SIGNAL(clicked()), this, SLOT(gotoLine()));
76 
77     setAttribute(Qt::WA_DeleteOnClose, true);
78 
79     KConfigGroup cg(&partConfig, "AnnotateDialog");
80     restoreGeometry(cg.readEntry<QByteArray>("geometry", QByteArray()));
81 
82     findEdit->setFocus();
83 }
84 
85 
~AnnotateDialog()86 AnnotateDialog::~AnnotateDialog()
87 {
88     KConfigGroup cg(&partConfig, "AnnotateDialog");
89     cg.writeEntry("geometry", saveGeometry());
90 }
91 
slotHelp()92 void AnnotateDialog::slotHelp()
93 {
94   KHelpClient::invokeHelp(QLatin1String("annotate"));
95 }
96 
97 
addLine(const Cervisia::LogInfo & logInfo,const QString & content,bool odd)98 void AnnotateDialog::addLine(const Cervisia::LogInfo& logInfo,
99                              const QString& content, bool odd)
100 {
101     annotate->addLine(logInfo, content, odd);
102 }
103 
104 
findNext()105 void AnnotateDialog::findNext()
106 {
107     if ( !findEdit->text().isEmpty() )
108         annotate->findText(findEdit->text(), false);
109 }
110 
findPrev()111 void AnnotateDialog::findPrev()
112 {
113     if ( !findEdit->text().isEmpty() )
114         annotate->findText(findEdit->text(), true);
115 }
116 
gotoLine()117 void AnnotateDialog::gotoLine()
118 {
119     bool ok = false;
120     int line = QInputDialog::getInt(this, i18n("Go to Line"), i18n("Go to line number:"),
121                                     annotate->currentLine(), 1, annotate->lastLine(), 1, &ok);
122 
123     if ( ok )
124         annotate->gotoLine(line);
125 }
126 
127 
128 // Local Variables:
129 // c-basic-offset: 4
130 // End:
131