~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to parts/documentation/indexview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2004 by Alexander Dymo                                  *
3
 
 *   cloudtemple@mksat.net                                                 *
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                         *
17
 
 *   Free Software Foundation, Inc.,                                       *
18
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 
 ***************************************************************************/
20
 
#include "indexview.h"
21
 
 
22
 
#include <qapplication.h>
23
 
#include <qevent.h>
24
 
#include <qlayout.h>
25
 
#include <qlabel.h>
26
 
 
27
 
#include <klineedit.h>
28
 
#include <kiconloader.h>
29
 
#include <klocale.h>
30
 
#include <kurl.h>
31
 
#include <kdebug.h>
32
 
 
33
 
#include <kdevpartcontroller.h>
34
 
#include <kdevdocumentationplugin.h>
35
 
 
36
 
#include "docutils.h"
37
 
#include "selecttopic.h"
38
 
#include "documentation_part.h"
39
 
#include "documentation_widget.h"
40
 
 
41
 
IndexView::IndexView(DocumentationWidget *parent, const char *name)
42
 
     :QWidget(parent, name), m_widget(parent)
43
 
{
44
 
    QVBoxLayout *l = new QVBoxLayout(this, 0, 0);
45
 
 
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);
50
 
    l->addLayout(hl);
51
 
 
52
 
    m_index = new IndexBox(this);
53
 
    l->addWidget(m_index);
54
 
 
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&)));
60
 
 
61
 
    m_edit->installEventFilter(this);
62
 
}
63
 
 
64
 
IndexView::~IndexView()
65
 
{
66
 
}
67
 
 
68
 
void IndexView::searchInIndex()
69
 
{
70
 
    if (m_index->currentItem() != -1)
71
 
        searchInIndex(m_index->item(m_index->currentItem()));
72
 
}
73
 
 
74
 
void IndexView::searchInIndex(QListBoxItem *item)
75
 
{
76
 
    kdDebug() << "IndexView::searchInIndex" << endl;
77
 
    IndexItem *indexItem = dynamic_cast<IndexItem*>(item);
78
 
    if (!indexItem)
79
 
        return;
80
 
 
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) ;
85
 
    else
86
 
    {
87
 
        SelectTopic *dia = new SelectTopic(urls);
88
 
        dia->topicLabel->setText(dia->topicLabel->text().arg(item->text()));
89
 
        if (dia->exec())
90
 
            m_widget->part()->partController()->showDocument(dia->selectedURL());
91
 
        delete dia;
92
 
    }
93
 
}
94
 
 
95
 
void IndexView::showIndex(const QString &term)
96
 
{
97
 
    QListBoxItem *i = m_index->firstItem();
98
 
    QString sl = term.lower();
99
 
    while (i)
100
 
    {
101
 
        QString t = i->text();
102
 
        if ((t.length() >= sl.length()) && (i->text().left(term.length()).lower() == sl))
103
 
        {
104
 
            m_index->setCurrentItem(i);
105
 
            m_index->setTopItem(m_index->index(i));
106
 
            break;
107
 
        }
108
 
        i = i->next();
109
 
    }
110
 
/*
111
 
    for (uint i = 0; i < m_index->count(); ++ i)
112
 
    {
113
 
        if (m_index->text(i).startsWith(term))
114
 
        {
115
 
            m_index->setCurrentItem(i);
116
 
            m_index->setTopItem(i);
117
 
        }
118
 
    }*/
119
 
}
120
 
 
121
 
bool IndexView::eventFilter(QObject *watched, QEvent *e)
122
 
{
123
 
    if (!watched || !e)
124
 
        return true;
125
 
 
126
 
    if ((watched == m_edit) && (e->type() == QEvent::KeyPress))
127
 
    {
128
 
        QKeyEvent *ke = (QKeyEvent*)e;
129
 
        if (ke->key() == Key_Up)
130
 
        {
131
 
            int i = m_index->currentItem();
132
 
            if (--i >= 0)
133
 
            {
134
 
                m_index->setCurrentItem(i);
135
 
                m_edit->blockSignals(true);
136
 
                m_edit->setText(m_index->currentText());
137
 
                m_edit->blockSignals(false);
138
 
            }
139
 
            return true;
140
 
        } else if (ke->key() == Key_Down)
141
 
        {
142
 
            int i = m_index->currentItem();
143
 
            if ( ++i < int(m_index->count()) )
144
 
            {
145
 
                m_index->setCurrentItem(i);
146
 
                m_edit->blockSignals(true);
147
 
                m_edit->setText(m_index->currentText());
148
 
                m_edit->blockSignals(false);
149
 
            }
150
 
            return true;
151
 
        } else if ((ke->key() == Key_Next) || (ke->key() == Key_Prior))
152
 
        {
153
 
            QApplication::sendEvent(m_index, e);
154
 
            m_edit->blockSignals(true);
155
 
            m_edit->setText(m_index->currentText());
156
 
            m_edit->blockSignals(false);
157
 
        }
158
 
    }
159
 
 
160
 
    return QWidget::eventFilter(watched, e);
161
 
}
162
 
 
163
 
void IndexView::itemMouseButtonPressed(int button, QListBoxItem *item, const QPoint &pos)
164
 
{
165
 
    if ((button != Qt::RightButton) || (!item))
166
 
        return;
167
 
    IndexItem *docItem = dynamic_cast<IndexItem*>(item);
168
 
    if (!docItem)
169
 
        return;
170
 
 
171
 
    DocUtils::docItemPopup(m_widget->part(), docItem, pos, false, true);
172
 
}
173
 
 
174
 
void IndexView::setSearchTerm(const QString &term)
175
 
{
176
 
    m_edit->setFocus();
177
 
    m_edit->setText(term);
178
 
}
179
 
 
180
 
void IndexView::askSearchTerm( )
181
 
{
182
 
    m_edit->setFocus();
183
 
}
184
 
 
185
 
void IndexView::focusInEvent(QFocusEvent */*e*/)
186
 
{
187
 
    m_edit->setFocus();
188
 
}
189
 
 
190
 
#include "indexview.moc"