void Navigator::slotItemSelected( QTreeWidgetItem *currentItem ) { if ( !currentItem ) return; mSelected = true; NavigatorItem *item = static_cast<NavigatorItem *>( currentItem ); kDebug(1400) << item->entry()->name() << endl; item->setExpanded( !item->isExpanded() ); KUrl url ( item->entry()->url() ); if ( url.protocol() == "khelpcenter" ) { mView->closeUrl(); History::self().updateCurrentEntry( mView ); History::self().createEntry(); showOverview( item, url ); } else { emit itemSelected( url.url() ); } mLastUrl = url; }
QString Navigator::createChildrenList( QTreeWidgetItem *child ) { ++mDirLevel; QString t; t += QLatin1String("<ul>\n"); int cc = child->childCount(); for (int i=0;i<cc;i++) { NavigatorItem *childItem = static_cast<NavigatorItem *>( child->child(i) ); DocEntry *e = childItem->entry(); t += QLatin1String("<li><a href=\"") + e->url() + QLatin1String("\">"); if ( e->isDirectory() ) t += QLatin1String("<b>"); t += e->name(); if ( e->isDirectory() ) t += QLatin1String("</b>"); t += QLatin1String("</a>"); if ( !e->info().isEmpty() ) { t += QLatin1String("<br>") + e->info(); } t += QLatin1String("</li>\n"); if ( childItem->childCount() > 0 && mDirLevel < 2 ) { t += createChildrenList( childItem ); } } t += QLatin1String("</ul>\n"); --mDirLevel; return t; }
void Navigator::selectItem( const KUrl &url ) { kDebug() << "Navigator::selectItem(): " << url.url(); if ( url.url() == "khelpcenter:home" ) { clearSelection(); return; } // help:/foo&anchor=bar gets redirected to help:/foo#bar // Make sure that we match both the original URL as well as // its counterpart. KUrl alternativeURL = url; if (url.hasRef()) { alternativeURL.setQuery("anchor="+url.ref()); alternativeURL.setRef(QString()); } // If the navigator already has the given URL selected, do nothing. NavigatorItem *item; item = static_cast<NavigatorItem *>( mContentsTree->currentItem() ); if ( item && mSelected ) { KUrl currentURL ( item->entry()->url() ); if ( (currentURL == url) || (currentURL == alternativeURL) ) { kDebug() << "URL already shown."; return; } } // First, populate the NavigatorAppItems if we don't want the home page if ( url != homeURL() ) { QTreeWidgetItemIterator it1( mContentsTree ); while( (*it1) ) { NavigatorAppItem *appItem = dynamic_cast<NavigatorAppItem *>( (*it1) ); if ( appItem ) appItem->populate( true ); ++it1; } } QTreeWidgetItemIterator it( mContentsTree ); while ( (*it) ) { NavigatorItem *item = static_cast<NavigatorItem *>( (*it) ); KUrl itemUrl( item->entry()->url() ); if ( (itemUrl == url) || (itemUrl == alternativeURL) ) { mContentsTree->setCurrentItem( item ); // If the current item was not selected and remained unchanged it // needs to be explicitly selected mContentsTree->setCurrentItem(item); item->setExpanded( true ); break; } ++it; } if ( !(*it) ) { clearSelection(); } else { mSelected = true; } }