KDevelop API Documentation

indexview.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Alexander Dymo                                  *
00003  *   cloudtemple@mksat.net                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include "indexview.h"
00021 
00022 #include <qapplication.h>
00023 #include <qevent.h>
00024 #include <qlayout.h>
00025 #include <qlabel.h>
00026 
00027 #include <klineedit.h>
00028 #include <kiconloader.h>
00029 #include <klocale.h>
00030 #include <kurl.h>
00031 #include <kdebug.h>
00032 
00033 #include <kdevpartcontroller.h>
00034 #include <kdevdocumentationplugin.h>
00035 
00036 #include "docutils.h"
00037 #include "selecttopic.h"
00038 #include "documentation_part.h"
00039 #include "documentation_widget.h"
00040 
00041 IndexView::IndexView(DocumentationWidget *parent, const char *name)
00042      :QWidget(parent, name), m_widget(parent)
00043 {
00044     QVBoxLayout *l = new QVBoxLayout(this, 0, 0);
00045     
00046     QHBoxLayout *hl = new QHBoxLayout(this, 0, 0);
00047     m_edit = new KLineEdit(this);
00048     hl->addWidget(new QLabel(m_edit, i18n("&Look for:"), this));
00049     hl->addWidget(m_edit);
00050     l->addLayout(hl);
00051 
00052     m_index = new IndexBox(this);
00053     l->addWidget(m_index);
00054        
00055     connect(m_index, SIGNAL(doubleClicked(QListBoxItem* )), this, SLOT(searchInIndex(QListBoxItem* )));
00056     connect(m_index, SIGNAL(mouseButtonPressed(int, QListBoxItem*, const QPoint& )),
00057         this, SLOT(itemMouseButtonPressed(int, QListBoxItem*, const QPoint& )));
00058     connect(m_edit, SIGNAL(returnPressed()), this, SLOT(searchInIndex()));
00059     connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(showIndex(const QString&)));
00060     
00061     m_edit->installEventFilter(this);
00062 }
00063 
00064 IndexView::~IndexView()
00065 {
00066 }
00067 
00068 void IndexView::searchInIndex()
00069 {
00070     if (m_index->currentItem() != -1)
00071         searchInIndex(m_index->item(m_index->currentItem()));
00072 }
00073 
00074 void IndexView::searchInIndex(QListBoxItem *item)
00075 {
00076     kdDebug() << "IndexView::searchInIndex" << endl;
00077     IndexItem *indexItem = dynamic_cast<IndexItem*>(item);
00078     if (!indexItem)
00079         return;
00080     
00081     IndexItem::List urls = indexItem->urls();
00082     if (urls.count() == 1)
00083         m_widget->part()->partController()->showDocument(urls.first().second);
00084     else if (urls.count() == 0) ;
00085     else
00086     {
00087         SelectTopic *dia = new SelectTopic(urls);
00088         dia->topicLabel->setText(dia->topicLabel->text().arg(item->text()));
00089         if (dia->exec())
00090             m_widget->part()->partController()->showDocument(dia->selectedURL());
00091         delete dia;
00092     }
00093 }
00094 
00095 void IndexView::showIndex(const QString &term)
00096 {
00097     QListBoxItem *i = m_index->firstItem();
00098     QString sl = term.lower();
00099     while (i)
00100     {
00101         QString t = i->text();
00102         if ((t.length() >= sl.length()) && (i->text().left(term.length()).lower() == sl))
00103         {
00104             m_index->setCurrentItem(i);
00105             m_index->setTopItem(m_index->index(i));
00106             break;
00107         }
00108         i = i->next();
00109     }
00110 /*
00111     for (uint i = 0; i < m_index->count(); ++ i)
00112     {
00113         if (m_index->text(i).startsWith(term))
00114         {
00115             m_index->setCurrentItem(i);
00116             m_index->setTopItem(i);
00117         }
00118     }*/
00119 }
00120 
00121 bool IndexView::eventFilter(QObject *watched, QEvent *e)
00122 {
00123     if (!watched || !e)
00124         return true;
00125 
00126     if ((watched == m_edit) && (e->type() == QEvent::KeyPress))
00127     {
00128         QKeyEvent *ke = (QKeyEvent*)e;
00129         if (ke->key() == Key_Up)
00130         {
00131             int i = m_index->currentItem();
00132             if (--i >= 0)
00133             {
00134                 m_index->setCurrentItem(i);
00135                 m_edit->blockSignals(true);
00136                 m_edit->setText(m_index->currentText());
00137                 m_edit->blockSignals(false);
00138             }
00139             return true;
00140         } else if (ke->key() == Key_Down)
00141         {
00142             int i = m_index->currentItem();
00143             if ( ++i < int(m_index->count()) ) 
00144             {
00145                 m_index->setCurrentItem(i);
00146                 m_edit->blockSignals(true);
00147                 m_edit->setText(m_index->currentText());
00148                 m_edit->blockSignals(false);
00149             }
00150             return true;
00151         } else if ((ke->key() == Key_Next) || (ke->key() == Key_Prior))
00152         {
00153             QApplication::sendEvent(m_index, e);
00154             m_edit->blockSignals(true);
00155             m_edit->setText(m_index->currentText());
00156             m_edit->blockSignals(false);
00157         }
00158     }
00159 
00160     return QWidget::eventFilter(watched, e);    
00161 }
00162 
00163 void IndexView::itemMouseButtonPressed(int button, QListBoxItem *item, const QPoint &pos)
00164 {
00165     if ((button != Qt::RightButton) || (!item))
00166         return;
00167     IndexItem *docItem = dynamic_cast<IndexItem*>(item);
00168     if (!docItem)
00169         return;
00170     
00171     DocUtils::docItemPopup(m_widget->part(), docItem, pos, false, true);
00172 }
00173 
00174 void IndexView::setSearchTerm(const QString &term)
00175 {
00176     m_edit->setFocus();
00177     m_edit->setText(term);
00178 }
00179 
00180 void IndexView::askSearchTerm( )
00181 {
00182     m_edit->setFocus();
00183 }
00184 
00185 void IndexView::focusInEvent(QFocusEvent */*e*/)
00186 {
00187     m_edit->setFocus();
00188 }
00189 
00190 #include "indexview.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:55 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003