📄 helpdialogimpl.cpp
字号:
QStringList linkNames; for ( ; it != links.end(); ++it ) { linkList << *it; linkNames << titleOfLink( *it ); } QString link = TopicChooser::getLink( this, linkNames, linkList, i->text() ); if ( !link.isEmpty() ) emit showLink( link, i->text() ); }}void HelpDialog::searchInIndex( const QString &s ){ QListBoxItem *i = listIndex->firstItem(); QString sl = s.lower(); while ( i ) { QString t = i->text(); if ( t.length() >= sl.length() && i->text().left(s.length()).lower() == sl ) { listIndex->setCurrentItem( i ); break; } i = i->next(); }}QString HelpDialog::titleOfLink( const QString &link ){ QUrl u( link ); QString s = titleMap[ u.fileName() ]; if ( s.isEmpty() ) return link; return s;}bool HelpDialog::eventFilter( QObject * o, QEvent * e ){ if ( !o || !e ) return TRUE; if ( o == editIndex && e->type() == QEvent::KeyPress ) { QKeyEvent *ke = (QKeyEvent*)e; if ( ke->key() == Key_Up ) { int i = listIndex->currentItem(); if ( --i >= 0 ) { listIndex->setCurrentItem( i ); editIndex->blockSignals( TRUE ); editIndex->setText( listIndex->currentText() ); editIndex->blockSignals( FALSE ); } return TRUE; } else if ( ke->key() == Key_Down ) { int i = listIndex->currentItem(); if ( ++i < int(listIndex->count()) ) { listIndex->setCurrentItem( i ); editIndex->blockSignals( TRUE ); editIndex->setText( listIndex->currentText() ); editIndex->blockSignals( FALSE ); } return TRUE; } else if ( ke->key() == Key_Next || ke->key() == Key_Prior ) { QApplication::sendEvent( listIndex, e); editIndex->blockSignals( TRUE ); editIndex->setText( listIndex->currentText() ); editIndex->blockSignals( FALSE ); } } return QWidget::eventFilter( o, e );}void HelpDialog::addBookmark(){ if ( !bookmarksInserted ) insertBookmarks(); QString link = QUrl( help->viewer()->context(), help->viewer()->source() ).path(); QString title = titleOfLink( link ); HelpNavigationContentsItem *i = new HelpNavigationContentsItem( listBookmarks, 0 ); i->setText( 0, title ); i->setLink( QUrl( link ).fileName() ); saveBookmarks(); help->setupBookmarkMenu();}void HelpDialog::removeBookmark(){ if ( !listBookmarks->currentItem() ) return; delete listBookmarks->currentItem(); saveBookmarks(); help->setupBookmarkMenu();}void HelpDialog::insertBookmarks(){ if ( bookmarksInserted ) return; bookmarksInserted = TRUE; QFile f( QDir::homeDirPath() + "/.designer/bookmarks" ); if ( !f.open( IO_ReadOnly ) ) return; QTextStream ts( &f ); while ( !ts.atEnd() ) { HelpNavigationContentsItem *i = new HelpNavigationContentsItem( listBookmarks, 0 ); i->setText( 0, ts.readLine() ); i->setLink( ts.readLine() ); } help->setupBookmarkMenu();}void HelpDialog::currentBookmarkChanged( QListViewItem *i ){ buttonDisplay->setEnabled( (bool)i );}void HelpDialog::showBookmarkTopic(){ if ( !listBookmarks->currentItem() ) return; HelpNavigationContentsItem *i = (HelpNavigationContentsItem*)listBookmarks->currentItem(); emit showLink( i->link(), i->text( 0 ) );}void HelpDialog::saveBookmarks(){ QFile f( QDir::homeDirPath() + "/.designer/bookmarks" ); if ( !f.open( IO_WriteOnly ) ) return; QTextStream ts( &f ); QListViewItemIterator it( listBookmarks ); for ( ; it.current(); ++it ) { HelpNavigationContentsItem *i = (HelpNavigationContentsItem*)it.current(); ts << i->text( 0 ) << endl; ts << i->link() << endl; } f.close();}void HelpDialog::insertContents(){ if ( contentsInserted ) return; contentsInserted = TRUE; if ( !contentsDone ) setupTitleMap(); listContents->setSorting( -1 ); QListViewItem *qtDocu, *handbook; qtDocu = new QListViewItem( listContents, tr( "Qt Class Documentation" ) ); qtDocu->setPixmap( 0, PixmapChooser::loadPixmap( "book.xpm", PixmapChooser::Small ) ); handbook = new QListViewItem( listContents, tr( "Designer Handbook" ) ); handbook->setPixmap( 0, PixmapChooser::loadPixmap( "book.xpm", PixmapChooser::Small ) ); HelpNavigationContentsItem *lastItem = 0; HelpNavigationContentsItem *lastGroup = 0; QValueList<MyString>* lst = new QValueList<MyString>; for ( QMap<QString, QString>::Iterator it = titleMap.begin(); it != titleMap.end(); ++it ) { QString s = *it + " | " + it.key(); s = s.stripWhiteSpace(); if ( s.lower().find( "easter egg" ) != -1 || s.lower().find( "easteregg" ) != -1 ) continue; lst->append( s ); } qHeapSort( *lst ); for ( QValueList<MyString>::Iterator sit = lst->begin(); sit != lst->end(); ++sit ) { QString s = *sit; s = s.stripWhiteSpace(); int i = s.find( " - " ); if ( i == -1 ) { QListViewItem *oldLast = lastItem; lastItem = new HelpNavigationContentsItem( qtDocu, lastItem ); QString txt = s; QString title, link; i = txt.find( " | " ); if ( i == -1 ) { title = txt; } else { title = txt.left( i ); link = txt.mid( i + 3, 0xFFFFFF ); if ( oldLast && oldLast->text( 0 ).contains( title ) ) { QString s2 = link; i = s2.find( '.' ); if ( i != -1 ) s2 = s2.left( i ); s2[ 0 ] = s2[ 0 ].upper(); title += " (" + s2 + ")"; } } lastItem->setText( 0, title ); lastItem->setLink( link ); lastGroup = 0; } else { QString preMinus = s.left( i ); QListViewItemIterator lit( qtDocu ); if ( !lastGroup || lastGroup->text( 0 ).lower() != preMinus.lower() ) { lastItem = new HelpNavigationContentsItem( qtDocu, lastItem ); lastItem->setText( 0, preMinus ); lastGroup = lastItem; } QString txt = s.mid( i + 3, 0xFFFFFF ); QString title, link; i = txt.find( " | " ); if ( i == -1 ) { title = txt; } else { title = txt.left( i ); link = txt.mid( i + 3, 0xFFFFFF ); if ( lastItem && title == lastItem->text( 0 ) ) { QString s2 = link; i = s2.find( '.' ); if ( i != -1 ) s2 = s2.left( i ); s2[ 0 ] = s2[ 0 ].upper(); title += " (" + s2 + ")"; } } lastItem = new HelpNavigationContentsItem( lastGroup, lastItem ); lastItem->setText( 0, title ); lastItem->setLink( link ); } } delete lst; QString manualdir = QString( getenv( "QTDIR" ) ) + "/tools/designer/manual/book1.html"; if ( !QFile::exists( manualdir ) ) manualdir = QString( getenv( "QTDIR" ) ) + "/doc/html/designer/book1.html"; QFile file( manualdir ); if ( !file.open( IO_ReadOnly ) ) return; QTextStream ts( &file ); QString text = ts.read(); text = text.simplifyWhiteSpace(); QValueList<Entry> entries; int i = text.find( "Table of Contents" ); QString link, title; int depth = 0; while ( i < (int)text.length() ) { QChar c = text[ i ]; if ( c == '<' ) { ++i; c = text[ i ]; if ( c == 'a' ) { int j = text.find( "\"", i ); int k = text.find( "\"", j + 1 ); link = text.mid( j + 1, k - j - 1 ); k = text.find( ">", k ) + 1; j = text.find( "<", k ); title = text.mid( k, j - k ); title = title.simplifyWhiteSpace(); if ( title == "Next" ) { i = text.length(); continue; } if ( !title.isEmpty() ) { Entry e; e.link = link; e.title = title; e.depth = depth; entries.append( e ); } } if ( c == 'd' ) { ++i; c = text[ i ]; if ( c == 'l' ) depth++; } if ( c == '/' ) { ++i; c = text[ i ]; if ( c == 'd' ) { ++i; c = text[ i ]; if ( c == 'l' ) depth--; } } } ++i; } int oldDepth = -1; lastItem = (HelpNavigationContentsItem*)handbook; for ( QValueList<Entry>::Iterator it2 = entries.begin(); it2 != entries.end(); ++it2 ) { if ( (*it2).depth == oldDepth ) lastItem = new HelpNavigationContentsItem( lastItem->parent(), lastItem ); else if ( (*it2).depth > oldDepth ) lastItem = new HelpNavigationContentsItem( lastItem, lastItem ); else if ( (*it2).depth < oldDepth ) { int diff = oldDepth - (*it2).depth; HelpNavigationContentsItem *i = (HelpNavigationContentsItem*)lastItem->parent(), *i2 = lastItem; while ( diff > 0 ) { i = (HelpNavigationContentsItem*)i->parent(); i2 = (HelpNavigationContentsItem*)i2->parent(); --diff; } lastItem = new HelpNavigationContentsItem( i, i2 ); } oldDepth = (*it2).depth; lastItem->setText( 0, (*it2).title ); lastItem->setLink( (*it2).link ); }}void HelpDialog::currentContentsChanged( QListViewItem *i ){ if ( !i ) { buttonDisplay->setEnabled( FALSE ); return; } if ( !i->firstChild() ) { buttonDisplay->setEnabled( TRUE ); return; } QListViewItem *oi = i; while ( i->parent() ) i = i->parent(); buttonDisplay->setEnabled( i == listContents->firstChild() && oi != i );}void HelpDialog::showContentsTopic(){ if ( !buttonDisplay->isEnabled() || !listContents->currentItem()->parent() ) return; HelpNavigationContentsItem *i = (HelpNavigationContentsItem*)listContents->currentItem(); emit showLink( i->link(), i->text( 0 ) );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -