diff --git a/shell/documentationview.cpp b/shell/documentationview.cpp index 9eda4114bc..3689fa9e5c 100644 --- a/shell/documentationview.cpp +++ b/shell/documentationview.cpp @@ -1,189 +1,191 @@ /* Copyright 2009 Aleix Pol Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "documentationview.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class ProvidersModel : public QAbstractListModel { public: ProvidersModel(QObject* parent = 0) : QAbstractListModel(parent) , mProviders(KDevelop::ICore::self()->documentationController()->documentationProviders()) {} virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const { QVariant ret; switch(role) { case Qt::DisplayRole: ret=provider(index.row())->name(); break; case Qt::DecorationRole: ret=provider(index.row())->icon(); break; } return ret; } virtual int rowCount(const QModelIndex&) const { return mProviders.count(); } KDevelop::IDocumentationProvider* provider(int pos) const { return mProviders[pos]; } int rowForProvider(KDevelop::IDocumentationProvider* provider) { return mProviders.indexOf(provider); } private: QList mProviders; }; DocumentationView::DocumentationView(QWidget* parent) : QWidget(parent) { setWindowIcon(KIcon("documentation")); setLayout(new QVBoxLayout(this)); mActions=new KToolBar(this); layout()->addWidget(mActions); mBack=mActions->addAction(KIcon("go-previous"), i18n("Back")); mForward=mActions->addAction(KIcon("go-next"), i18n("Forward")); mActions->addSeparator(); mProviders=new QComboBox(mActions); + mProviders->setFocusPolicy(Qt::NoFocus); mProvidersModel=new ProvidersModel(mProviders); mProviders->setModel(mProvidersModel); connect(mProviders, SIGNAL(activated(int)), SLOT(changedProvider(int))); mIdentifiers=new KLineEdit(mActions); + mIdentifiers->setClearButtonShown(true); mIdentifiers->setCompleter(new QCompleter(mIdentifiers)); // mIdentifiers->completer()->setCompletionMode(QCompleter::UnfilteredPopupCompletion); mIdentifiers->completer()->setCaseSensitivity(Qt::CaseInsensitive); mIdentifiers->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); connect(mIdentifiers, SIGNAL(returnPressed()), SLOT(changedSelection())); connect(mIdentifiers->completer(), SIGNAL(activated(QModelIndex)), SLOT(changeProvider(QModelIndex))); mActions->addWidget(mProviders); mActions->addWidget(mIdentifiers); mBack->setEnabled(false); mForward->setEnabled(false); connect(mBack, SIGNAL(triggered()), this, SLOT(browseBack())); connect(mForward, SIGNAL(triggered()), this, SLOT(browseForward())); mCurrent=mHistory.end(); QLabel* message=new QLabel(i18n("There is no documentation selected yet"), this); message->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); layout()->addWidget(message); if(mProvidersModel->rowCount(QModelIndex())>0) changedProvider(0); } void DocumentationView::browseBack() { mCurrent--; mBack->setEnabled(mCurrent!=mHistory.begin()); mForward->setEnabled(true); updateView(); } void DocumentationView::browseForward() { mCurrent++; mForward->setEnabled(mCurrent+1!=mHistory.end()); mBack->setEnabled(true); updateView(); } void DocumentationView::changedSelection() { changeProvider(mIdentifiers->completer()->currentIndex()); } void DocumentationView::changeProvider(const QModelIndex& idx) { if(idx.isValid()) { KSharedPtr doc=mProvidersModel->provider(mProviders->currentIndex())->documentationForIndex(idx); if(doc) showDocumentation(doc); } } void DocumentationView::showDocumentation(KSharedPtr< KDevelop::IDocumentation > doc) { kDebug(9529) << "showing" << doc->name(); mBack->setEnabled( !mHistory.isEmpty() ); mForward->setEnabled(false); mHistory.append(doc); mCurrent=mHistory.end()-1; updateView(); } void DocumentationView::updateView() { mProviders->setCurrentIndex(mProvidersModel->rowForProvider((*mCurrent)->provider())); mIdentifiers->completer()->setModel((*mCurrent)->provider()->indexModel()); mIdentifiers->setText((*mCurrent)->name()); QLayoutItem* lastview=layout()->takeAt(1); if(lastview->widget()->parent()==this) lastview->widget()->deleteLater(); delete lastview; QWidget* w; if((*mCurrent)->providesWidget()) w=(*mCurrent)->documentationWidget(this); else { QTextBrowser* widget=new QTextBrowser(this); widget->setReadOnly(true); widget->setText((*mCurrent)->description()); w=widget; } Q_ASSERT(w); layout()->addWidget(w); } void DocumentationView::changedProvider(int row) { mIdentifiers->completer()->setModel(mProvidersModel->provider(row)->indexModel()); mIdentifiers->clear(); } diff --git a/shell/documentationview.h b/shell/documentationview.h index a9270f5256..8fa7614b79 100644 --- a/shell/documentationview.h +++ b/shell/documentationview.h @@ -1,59 +1,59 @@ /* Copyright 2009 Aleix Pol Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef DOCUMENTATIONVIEW_H #define DOCUMENTATIONVIEW_H #include #include #include class QModelIndex; -class QLineEdit; +class KLineEdit; class ProvidersModel; class QComboBox; class DocumentationView : public QWidget { Q_OBJECT public: DocumentationView(QWidget* parent); void showDocumentation(KSharedPtr< KDevelop::IDocumentation > doc); public slots: void browseForward(); void browseBack(); void changedSelection(); void changedProvider(int); void changeProvider(const QModelIndex &); private: void updateView(); KToolBar* mActions; QAction* mForward; QAction* mBack; - QLineEdit* mIdentifiers; + KLineEdit* mIdentifiers; QList< KSharedPtr< KDevelop::IDocumentation > > mHistory; QList< KSharedPtr< KDevelop::IDocumentation > >::iterator mCurrent; QComboBox* mProviders; ProvidersModel* mProvidersModel; }; #endif // DOCUMENTATIONVIEW_H