1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/***************************************************************************
* Copyright (C) 2004 by Alexander Dymo *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "indexview.h"
#include <qapplication.h>
#include <qevent.h>
#include <qlayout.h>
#include <qlabel.h>
#include <klineedit.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kurl.h>
#include <kdebug.h>
#include <kdevpartcontroller.h>
#include <kdevdocumentationplugin.h>
#include "docutils.h"
#include "selecttopic.h"
#include "documentation_part.h"
#include "documentation_widget.h"
IndexView::IndexView(DocumentationWidget *parent, const char *name)
:QWidget(parent, name), m_widget(parent)
{
QVBoxLayout *l = new QVBoxLayout(this, 0, 0);
QHBoxLayout *hl = new QHBoxLayout(this, 0, 0);
m_edit = new KLineEdit(this);
hl->addWidget(new QLabel(m_edit, i18n("&Look for:"), this));
hl->addWidget(m_edit);
l->addLayout(hl);
m_index = new IndexBox(this);
l->addWidget(m_index);
connect(m_index, SIGNAL(executed(QListBoxItem* )), this, SLOT(searchInIndex(QListBoxItem* )));
connect(m_index, SIGNAL(mouseButtonPressed(int, QListBoxItem*, const QPoint& )),
this, SLOT(itemMouseButtonPressed(int, QListBoxItem*, const QPoint& )));
connect(m_edit, SIGNAL(returnPressed()), this, SLOT(searchInIndex()));
connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(showIndex(const QString&)));
m_edit->installEventFilter(this);
}
IndexView::~IndexView()
{
}
void IndexView::searchInIndex()
{
if (m_index->currentItem() != -1)
searchInIndex(m_index->item(m_index->currentItem()));
}
void IndexView::searchInIndex(QListBoxItem *item)
{
kdDebug() << "IndexView::searchInIndex" << endl;
IndexItem *indexItem = dynamic_cast<IndexItem*>(item);
if (!indexItem)
return;
IndexItem::List urls = indexItem->urls();
if (urls.count() == 1)
m_widget->part()->partController()->showDocument(urls.first().second);
else if (urls.count() == 0) ;
else
{
SelectTopic *dia = new SelectTopic(urls);
dia->topicLabel->setText(dia->topicLabel->text().arg(item->text()));
if (dia->exec())
m_widget->part()->partController()->showDocument(dia->selectedURL());
delete dia;
}
}
void IndexView::showIndex(const QString &term)
{
QListBoxItem *i = m_index->firstItem();
QString sl = term.lower();
while (i)
{
QString t = i->text();
if ((t.length() >= sl.length()) && (i->text().left(term.length()).lower() == sl))
{
m_index->setCurrentItem(i);
m_index->setTopItem(m_index->index(i));
break;
}
i = i->next();
}
/*
for (uint i = 0; i < m_index->count(); ++ i)
{
if (m_index->text(i).startsWith(term))
{
m_index->setCurrentItem(i);
m_index->setTopItem(i);
}
}*/
}
bool IndexView::eventFilter(QObject *watched, QEvent *e)
{
if (!watched || !e)
return true;
if ((watched == m_edit) && (e->type() == QEvent::KeyPress))
{
QKeyEvent *ke = (QKeyEvent*)e;
if (ke->key() == Key_Up)
{
int i = m_index->currentItem();
if (--i >= 0)
{
m_index->setCurrentItem(i);
m_edit->blockSignals(true);
m_edit->setText(m_index->currentText());
m_edit->blockSignals(false);
}
return true;
} else if (ke->key() == Key_Down)
{
int i = m_index->currentItem();
if ( ++i < int(m_index->count()) )
{
m_index->setCurrentItem(i);
m_edit->blockSignals(true);
m_edit->setText(m_index->currentText());
m_edit->blockSignals(false);
}
return true;
} else if ((ke->key() == Key_Next) || (ke->key() == Key_Prior))
{
QApplication::sendEvent(m_index, e);
m_edit->blockSignals(true);
m_edit->setText(m_index->currentText());
m_edit->blockSignals(false);
}
}
return QWidget::eventFilter(watched, e);
}
void IndexView::itemMouseButtonPressed(int button, QListBoxItem *item, const QPoint &pos)
{
if ((button != Qt::RightButton) || (!item))
return;
IndexItem *docItem = dynamic_cast<IndexItem*>(item);
if (!docItem)
return;
DocUtils::docItemPopup(m_widget->part(), docItem, pos, false, true);
}
void IndexView::setSearchTerm(const QString &term)
{
m_edit->setFocus();
m_edit->setText(term);
}
void IndexView::askSearchTerm( )
{
m_edit->setFocus();
}
void IndexView::focusInEvent(QFocusEvent */*e*/)
{
m_edit->setFocus();
}
#include "indexview.moc"
|