⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hand_book.cpp

📁 Linux平台下的内核及程序调试器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void HandBook::openFile(){   QString fn = QFileDialog::getOpenFileName( vkConfig->vkdocDir(),                                               "Html Files (*.html *.htm);;All Files (*)", this );   if ( !fn.isEmpty() ) {      browser->setSource( fn );   }}void HandBook::sourceChanged( const QString& url ){   if ( browser->documentTitle().isNull() )      setCaption( "Qt Example - Helpviewer - " + url );   else      setCaption( "Qt Example - Helpviewer - " + browser->documentTitle() ) ;      if ( !url.isEmpty() && pathCombo ) {      bool exists = FALSE;      int i;      for ( i = 0; i < pathCombo->count(); ++i ) {         if ( pathCombo->text( i ) == url ) {            exists = TRUE;            break;         }      }      if ( !exists ) {         pathCombo->insertItem( url, 0 );         pathCombo->setCurrentItem( 0 );         mapHistory[ historyMenu->insertItem( url ) ] = url;      } else         pathCombo->setCurrentItem( i );   }}void HandBook::print(){   QPrinter printer;   printer.setFullPage(true);   if ( !printer.setup( this ) )      return;   QPainter p( &printer );   QPaintDeviceMetrics metrics(p.device());   int dpix = metrics.logicalDpiX();   int dpiy = metrics.logicalDpiY();   const int margin = 72; // pt   QRect body(margin*dpix/72, margin*dpiy/72,              metrics.width()-margin*dpix/72*2,              metrics.height()-margin*dpiy/72*2 );   QSimpleRichText richText( browser->text(), QFont(),                              browser->context(), browser->styleSheet(),                             browser->mimeSourceFactory(), body.height() );   richText.setWidth( &p, body.width() );   QRect view( body );   int page = 1;   QString pnum;   do {      pnum.setNum( page );      richText.draw( &p, body.left(), body.top(), view, colorGroup() );      view.moveBy( 0,   body.height() );      p.translate( 0 , -body.height() );      p.drawText( view.right() - p.fontMetrics().width( pnum ),                  view.bottom() + p.fontMetrics().ascent() + 5, pnum );      if ( view.top()  >= richText.height() )         break;      printer.newPage();      page++;   } while (true);}void HandBook::save(){   QStringList aList;   /* save the history */   QMap<int, QString>::Iterator it1 = mapHistory.begin();   for ( ; it1 != mapHistory.end(); ++it1 ) {      aList.append( *it1 );   }   QFile aFile( vkConfig->rcDir() + "help.history" );   if ( aFile.open( IO_WriteOnly ) ) {      QTextStream stream( &aFile );      for ( QStringList::Iterator it = aList.begin();             it != aList.end(); ++it )         stream << *it << "\n";      aFile.close();   }   /* save the bookmarks */   aList.clear();   QMap<int, QString>::Iterator it2 = mapBookmarks.begin();   for ( ; it2 != mapBookmarks.end(); ++it2 ) {      aList.append( *it2 );   }   aFile.setName( vkConfig->rcDir() + "help.bookmarks" );   if ( aFile.open( IO_WriteOnly ) ) {      QTextStream stream( &aFile );      for ( QStringList::Iterator it = aList.begin();             it != aList.end(); ++it )         stream << *it << "\n";      aFile.close();   }   /* be tidy */   aList.clear();}void HandBook::pathSelected( const QString &path ){   browser->setSource( path );   QMap<int, QString>::Iterator it = mapHistory.begin();   bool exists = false;   for ( ; it != mapHistory.end(); ++it ) {      if ( *it == path ) {         exists = true;         break;      }   }   if ( !exists ) {      mapHistory[ historyMenu->insertItem(path) ] = path;   }}void HandBook::mkMenuToolBars(){   mainMenu = new QMenuBar( this, "help_menubar" );   /* file menu --------------------------------------------------------- */   QPopupMenu* fileMenu = new QPopupMenu( this );   fileMenu->insertItem( "Open File",  this, SLOT( openFile()  ) );   fileMenu->insertItem( "Print",      this, SLOT( print()     ) );   fileMenu->insertSeparator();   fileMenu->insertItem( "Close",      this, SLOT( close()     ) );   mainMenu->insertItem( "&File", fileMenu );   /* go menu ----------------------------------------------------------- */   QPopupMenu* goMenu = new QPopupMenu( this );   goMenu->insertItem( QPixmap(back_xpm), "Backward",                        browser, SLOT( backward() ), 0, BACKWARD );   goMenu->insertItem( QPixmap(forward_xpm), "Forward",                        browser, SLOT( forward() ),  0, FORWARD );   goMenu->insertItem( QPixmap(home_xpm),    "Home",                        browser, SLOT( home() ),     0, HOME );   mainMenu->insertItem( "&Go", goMenu );   /* history menu ------------------------------------------------------ */   QStringList aList;   historyMenu = new QPopupMenu( this );   /* load the history from file into the list */   QFile aFile( vkConfig->rcDir() + "help.history" );   if ( aFile.open( IO_ReadOnly ) ) {      QTextStream stream( &aFile );      while ( !stream.atEnd() ) {         aList += stream.readLine();      }      aFile.close();      while ( aList.count() > 20 ) {         aList.remove( aList.begin() );      }   }   /* put each string into the map */   for ( unsigned int id=0; id<aList.count(); id++ ) {      historyMenu->insertItem( aList[id], id );      mapHistory[id] = aList[id];   }   connect( historyMenu, SIGNAL( activated(int) ),            this,        SLOT( historyChosen(int) ) );   mainMenu->insertItem( "History", historyMenu );   /* bookmarks menu ---------------------------------------------------- */   aList.clear();   bookmarkMenu = new QPopupMenu( this );   bookmarkMenu->insertItem( "Add Bookmark", this, SLOT( addBookmark() ) );   bookmarkMenu->insertSeparator();   /* load the bookmarks from file into the list */   aFile.setName( vkConfig->rcDir() + "help.bookmarks" );   if ( aFile.open( IO_ReadOnly ) ) {      QTextStream stream( &aFile );      while ( !stream.atEnd() ) {         aList += stream.readLine();      }      aFile.close();   }   /* put the page titles in the menu, and the entire string in the map */   for ( unsigned int id=0; id<aList.count(); id++ ) {      QString url_title = aList[id];      int pos = url_title.find('[', 0, false );      QString title = url_title.left( pos );      bookmarkMenu->insertItem( title, id );      mapBookmarks[id] = url_title;   }   aList.clear();   connect( bookmarkMenu, SIGNAL( activated(int) ),            this,         SLOT( bookmarkChosen(int) ) );   mainMenu->insertItem( "Bookmarks", bookmarkMenu );   mainMenu->setItemEnabled( FORWARD,  false);   mainMenu->setItemEnabled( BACKWARD, false);   connect( browser, SIGNAL( backwardAvailable( bool ) ),            this,    SLOT( setBackwardAvailable( bool ) ) );   connect( browser, SIGNAL( forwardAvailable( bool ) ),            this,    SLOT( setForwardAvailable( bool ) ) );   /* dismiss 'button' -------------------------------------------------- */   mainMenu->insertSeparator();   QToolButton* dismissButton = new QToolButton( this, "tb_dismiss" );   dismissButton->setText( "Dismiss" );   dismissButton->setAutoRaise( true );   connect( dismissButton, SIGNAL( clicked() ),             this,          SLOT( close() ) );   mainMenu->insertItem( dismissButton );   /* toolbar ----------------------------------------------------------- */   QToolBar* toolbar = new QToolBar( this, "handbook_toolbar" );   addToolBar( toolbar, "Toolbar");   QToolButton* button;   button = new QToolButton( QPixmap(back_xpm), "Backward", "",                              browser, SLOT(backward()), toolbar );   connect( browser, SIGNAL( backwardAvailable(bool) ),             button,  SLOT( setEnabled(bool) ) );   button->setEnabled( false );   button = new QToolButton( QPixmap(forward_xpm), "Forward", "",                              browser, SLOT(forward()), toolbar );   connect( browser, SIGNAL( forwardAvailable(bool) ),             button,  SLOT( setEnabled(bool) ) );   button->setEnabled( false );   button = new QToolButton( QPixmap(home_xpm), "Home", "",                              browser, SLOT(home()), toolbar );   button = new QToolButton( QPixmap(reload_xpm), "Reload", "",                              browser, SLOT(reload()), toolbar );   toolbar->addSeparator();   pathCombo = new QComboBox( true, toolbar );   pathCombo->insertItem( vkConfig->vkdocDir() );   connect( pathCombo, SIGNAL( activated(const QString &) ),            this,      SLOT( pathSelected(const QString &) ) );   toolbar->setStretchableWidget( pathCombo );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -