1
/***************************************************************************
2
* Copyright (C) 2004 by Alexander Dymo *
3
* cloudtemple@mksat.net *
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
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
20
#include "indexview.h"
22
#include <qapplication.h>
27
#include <klineedit.h>
28
#include <kiconloader.h>
33
#include <kdevpartcontroller.h>
34
#include <kdevdocumentationplugin.h>
37
#include "selecttopic.h"
38
#include "documentation_part.h"
39
#include "documentation_widget.h"
41
IndexView::IndexView(DocumentationWidget *parent, const char *name)
42
:QWidget(parent, name), m_widget(parent)
44
QVBoxLayout *l = new QVBoxLayout(this, 0, 0);
46
QHBoxLayout *hl = new QHBoxLayout(this, 0, 0);
47
m_edit = new KLineEdit(this);
48
hl->addWidget(new QLabel(m_edit, i18n("&Look for:"), this));
49
hl->addWidget(m_edit);
52
m_index = new IndexBox(this);
53
l->addWidget(m_index);
55
connect(m_index, SIGNAL(executed(QListBoxItem* )), this, SLOT(searchInIndex(QListBoxItem* )));
56
connect(m_index, SIGNAL(mouseButtonPressed(int, QListBoxItem*, const QPoint& )),
57
this, SLOT(itemMouseButtonPressed(int, QListBoxItem*, const QPoint& )));
58
connect(m_edit, SIGNAL(returnPressed()), this, SLOT(searchInIndex()));
59
connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(showIndex(const QString&)));
61
m_edit->installEventFilter(this);
64
IndexView::~IndexView()
68
void IndexView::searchInIndex()
70
if (m_index->currentItem() != -1)
71
searchInIndex(m_index->item(m_index->currentItem()));
74
void IndexView::searchInIndex(QListBoxItem *item)
76
kdDebug() << "IndexView::searchInIndex" << endl;
77
IndexItem *indexItem = dynamic_cast<IndexItem*>(item);
81
IndexItem::List urls = indexItem->urls();
82
if (urls.count() == 1)
83
m_widget->part()->partController()->showDocument(urls.first().second);
84
else if (urls.count() == 0) ;
87
SelectTopic *dia = new SelectTopic(urls);
88
dia->topicLabel->setText(dia->topicLabel->text().arg(item->text()));
90
m_widget->part()->partController()->showDocument(dia->selectedURL());
95
void IndexView::showIndex(const QString &term)
97
QListBoxItem *i = m_index->firstItem();
98
QString sl = term.lower();
101
QString t = i->text();
102
if ((t.length() >= sl.length()) && (i->text().left(term.length()).lower() == sl))
104
m_index->setCurrentItem(i);
105
m_index->setTopItem(m_index->index(i));
111
for (uint i = 0; i < m_index->count(); ++ i)
113
if (m_index->text(i).startsWith(term))
115
m_index->setCurrentItem(i);
116
m_index->setTopItem(i);
121
bool IndexView::eventFilter(QObject *watched, QEvent *e)
126
if ((watched == m_edit) && (e->type() == QEvent::KeyPress))
128
QKeyEvent *ke = (QKeyEvent*)e;
129
if (ke->key() == Key_Up)
131
int i = m_index->currentItem();
134
m_index->setCurrentItem(i);
135
m_edit->blockSignals(true);
136
m_edit->setText(m_index->currentText());
137
m_edit->blockSignals(false);
140
} else if (ke->key() == Key_Down)
142
int i = m_index->currentItem();
143
if ( ++i < int(m_index->count()) )
145
m_index->setCurrentItem(i);
146
m_edit->blockSignals(true);
147
m_edit->setText(m_index->currentText());
148
m_edit->blockSignals(false);
151
} else if ((ke->key() == Key_Next) || (ke->key() == Key_Prior))
153
QApplication::sendEvent(m_index, e);
154
m_edit->blockSignals(true);
155
m_edit->setText(m_index->currentText());
156
m_edit->blockSignals(false);
160
return QWidget::eventFilter(watched, e);
163
void IndexView::itemMouseButtonPressed(int button, QListBoxItem *item, const QPoint &pos)
165
if ((button != Qt::RightButton) || (!item))
167
IndexItem *docItem = dynamic_cast<IndexItem*>(item);
171
DocUtils::docItemPopup(m_widget->part(), docItem, pos, false, true);
174
void IndexView::setSearchTerm(const QString &term)
177
m_edit->setText(term);
180
void IndexView::askSearchTerm( )
185
void IndexView::focusInEvent(QFocusEvent */*e*/)
190
#include "indexview.moc"