Source Code (Use browser search to find items of interest.)

Class Index

kdevelop'CDocBrowser (./kdevelop/kdevelop/cdocbrowser.h:42)

class CDocBrowser : public KHTMLPart {
  Q_OBJECT
public:
  /** construtor */
  CDocBrowser(QWidget*parent=0,const char* name=0);
  /** destructor */
  ~CDocBrowser();

  /**show a html in a htmlview,if reload true it reload a file even it is in memory*/
  void showURL(QString url,bool reload=false);
  void setDocBrowserOptions();
  QString currentURL();
	QString currentTitle();
	QPopupMenu* popup(){ return doc_pop; };	
public slots:
  void slotDocFontSize(int);
  void slotDocStandardFont(const char *);
  void slotDocFixedFont(const char *);
  void slotDocColorsChanged(const QColor&, const QColor&,
            		const QColor&, const QColor&, const bool, const bool);
  void slotPopupMenu(const QString &, const QPoint & );
  void slotCopyText();
  void slotURLBack();
  void slotURLForward();
  void slotSearchText();
	void slotGrepText();
	void slotSetFileTitle(const QString&);
	void slotViewInKFM();
		
 signals:
  void signalURLBack();
  void signalURLForward();
  void signalSearchText();
  void signalGrepText(QString text);
	void signalBookmarkAdd();
	void enableStop(int);	
protected:
  QString old_url, complete_url;
  QString m_title, m_refTitle;
//  void  mousePressEvent(QMouseEvent* event);
  QPopupMenu* doc_pop;
//  KBrowser* createFrame( QWidget *_parent, const char *_name );


private:
	// html view preferences
	static int  fSize;
	static QString standardFont;
	static QString fixedFont;

	static QColor bgColor;
	static QColor textColor;
	static QColor linkColor;
	static QColor vLinkColor;
	static bool   underlineLinks;
	static bool   forceDefaults;

};


//-----------------------------------------------------------------------------
// Adapted from options.h & options.cpp of
//
// KDE Help Options
//
// (c) Martin R. Jones 1996
//



//-----------------------------------------------------------------------------


kdevelop'CDocBrowser::CDocBrowser() (./kdevelop/kdevelop/cdocbrowser.cpp:59)

CDocBrowser::CDocBrowser(QWidget*parent,const char* name) : KHTMLPart(parent,name){

  doc_pop = new QPopupMenu();
  doc_pop->insertItem(BarIcon("back"),i18n("Back"),this, SLOT(slotURLBack()),0,ID_HELP_BACK);
  doc_pop->insertItem(BarIcon("forward"),i18n("Forward"),this,SLOT(slotURLForward()),0,ID_HELP_FORWARD);
  doc_pop->insertSeparator();
  doc_pop->insertItem(BarIcon("copy"),i18n("Copy"),this, SLOT(slotCopyText()),0,ID_EDIT_COPY);
  doc_pop->insertItem(i18n("Add Bookmark"),this, SIGNAL(signalBookmarkAdd()),0,ID_BOOKMARKS_ADD);
  doc_pop->insertItem(i18n("View in new window"), this, SLOT(slotViewInKFM()),0,ID_VIEW_IN_KFM);
  doc_pop->insertSeparator();
  doc_pop->insertItem(BarIcon("grep"),i18n("grep: "), this, SLOT(slotGrepText()), 0, ID_EDIT_SEARCH_IN_FILES);
  doc_pop->insertItem(BarIcon("lookup"),i18n("look up: "),this, SLOT(slotSearchText()),0,ID_HELP_SEARCH_TEXT);
	
  connect( this, SIGNAL( popupMenu(const QString &, const QPoint &) ),
           this, SLOT( slotPopupMenu(const QString &, const QPoint &) ) );
  connect(this, SIGNAL( setTitle(const QString &) ),
          this, SLOT( slotSetFileTitle(const QString &) ) );

}


kdevelop'CDocBrowser::~CDocBrowser() (./kdevelop/kdevelop/cdocbrowser.cpp:79)

CDocBrowser::~CDocBrowser(){
   delete doc_pop;
   doc_pop=0l;
}




kdevelop'CDocBrowser::slotViewInKFM() (./kdevelop/kdevelop/cdocbrowser.cpp:86)

void CDocBrowser::slotViewInKFM(){

    KProcess showHTML;
    showHTML << "kfmclient" << "openURL" << currentURL();
    showHTML.start(KProcess::DontCare);
	
}


kdevelop'CDocBrowser::showURL() (./kdevelop/kdevelop/cdocbrowser.cpp:94)

void CDocBrowser::showURL(QString url,bool reload){
 //read the htmlfile
  //cerr << "URL:" << url << "\n";

    //    return;
  QString url_wo_ref=url; // without ref
  QString ref;

  complete_url=url;
  int pos = url.findRev('#');
  int len = url.length();

  ref = (pos!=-1) ? (const char*) url.right(len - pos - 1) : "";
  m_refTitle = ref;

  if (pos!=-1)
   url_wo_ref = url.left(pos);

  if(url.left(7) == "http://" || url_wo_ref.right(4).find("htm", FALSE)==-1){

    KProcess showHTML;
    showHTML << "kfmclient" << "openURL" << url;
    showHTML.start(KProcess::DontCare);
    return;
  }


  if( (url_wo_ref != old_url) || reload){
    QString str="";
    KIO::NetAccess::download(url,str);

    //cerr << endl << "STR:" << str;

    char buffer[256+1];
    QFile file(str) ;
    if(file.exists()){
      emit enableStop(ID_HELP_BROWSER_STOP);
//        openURL(url,reload);

      file.open(IO_ReadOnly);
      QDataStream dstream ( &file );
      QString content;

      begin( url);
      while ( !dstream.eof() )
      {
        buffer[256]='\0';
        dstream.readRawBytes(buffer, 256);
	      write(buffer);
      }

      end();
      //      parse();
      //
      //show();

      KIO::NetAccess::removeTempFile(str);
      file.close();
    }
    else{
      KMessageBox::error(0, i18n("file \"%1\" not found!").arg(str));
       return;
    }
  }


  if (pos != -1){
    gotoAnchor(ref);
  }
  else
  {
    if (url_wo_ref == old_url)
        ;
        //     gotoXY(0,0);
  }

  if (url_wo_ref == old_url)
  {
      //     emit documentDone(this);  // simulate documentDone to put it in history...
  }
  old_url = url_wo_ref;

}


kdevelop'CDocBrowser::currentURL() (./kdevelop/kdevelop/cdocbrowser.cpp:178)

QString CDocBrowser::currentURL(){
  return complete_url;
}


kdevelop'CDocBrowser::setDocBrowserOptions() (./kdevelop/kdevelop/cdocbrowser.cpp:182)

void CDocBrowser::setDocBrowserOptions(){
/*
  KConfig *config = KApplication::getKApplication()->getConfig();
  config->setGroup( "DocBrowserAppearance" );

  QString fs = config->readEntry( "BaseFontSize" );
  if ( !fs.isEmpty() )
	fSize = fs.toInt();
  fs = "times";
  standardFont = config->readEntry( "StandardFont", fs );

  fs = "courier";
  fixedFont = config->readEntry( "FixedFont", fs );

  bgColor = config->readColorEntry( "BgColor", &white );
  textColor = config->readColorEntry( "TextColor", &black );
  linkColor = config->readColorEntry( "LinkColor", &blue );
  vLinkColor = config->readColorEntry( "VLinkColor", &darkMagenta );
  underlineLinks = config->readBoolEntry( "UnderlineLinks", true );
  forceDefaults = config->readBoolEntry( "ForceDefaultColors", false );

  htmlview->setFontSizes( &fSize );
  htmlview->setFixedFont( fixedFont);
  htmlview->setStandardFont( standardFont );
  htmlview->setURLCursor( KCursor::handCursor() );
  htmlview->setUnderlineLinks(underlineLinks);
  #warning uncommented htmlview->setForceDefault( force );
  //  htmlview->setForceDefault( forceDefaults );
  htmlview->setDefaultBGColor( bgColor );
  KHTMLWidget* htmlview;
  htmlview=getKHTMLWidget();
  htmlview->setDefaultBGColor(white);
  htmlview->setDefaultTextColors(black, blue, blue);
  htmlview->setUnderlineLinks(true);
  htmlview->setURLCursor( KCursor::handCursor() );
  QWidget::show();
  #warning FIXME
*/


}


kdevelop'CDocBrowser::slotDocFontSize() (./kdevelop/kdevelop/cdocbrowser.cpp:224)

void CDocBrowser::slotDocFontSize(int size){
    QValueList<int> fontSizes = KHTMLPart::fontSizes();
    fontSizes[3] = size;
    KHTMLPart::setFontSizes( fontSizes );
  //  htmlview->parse();
    openURL(complete_url);//, true);
//	busy = true;
//	emit enableMenuItems();
}


kdevelop'CDocBrowser::slotDocStandardFont() (./kdevelop/kdevelop/cdocbrowser.cpp:234)

void CDocBrowser::slotDocStandardFont(const char* n){
  standardFont = n;
  KHTMLPart::setStandardFont( n );
  //  htmlview->parse();
  openURL(complete_url);//, true);
//	busy = true;
//	emit enableMenuItems();
}


kdevelop'CDocBrowser::slotDocFixedFont() (./kdevelop/kdevelop/cdocbrowser.cpp:243)

void CDocBrowser::slotDocFixedFont(const char* n){
  fixedFont = n;
  KHTMLPart::setFixedFont( n );
  //  htmlview->parse();
  openURL(complete_url);//, true);
//	busy = true;
//	emit enableMenuItems();
}


kdevelop'CDocBrowser::slotDocColorsChanged() (./kdevelop/kdevelop/cdocbrowser.cpp:252)

void CDocBrowser::slotDocColorsChanged( const QColor &bg, const QColor &text,
	const QColor &link, const QColor &vlink, const bool uline, const bool force)
{
  #warning uncommented htmlview->setForceDefault( force );
  //  htmlview->setForceDefault( force );
    QString styleSheet;

    styleSheet += "body { background-color: " + bg.name() + ";\n";
    styleSheet += "       color: " + text.name() + "; }\n";
    styleSheet += "a[href] { color: " + link.name() + ";\n";
    styleSheet += "          text-decoration: ";
    if(uline)
	styleSheet += "underline; }\n";
    else
	styleSheet += "none; }\n";
    styleSheet += "a:visited { color: " + vlink.name() + "; }\n";

    setUserStyleSheet(styleSheet);
  //  htmlview->parse();
    openURL(complete_url);//, true);
//	busy = true;
//	emit enableMenuItems();){
}


kdevelop'CDocBrowser::slotPopupMenu() (./kdevelop/kdevelop/cdocbrowser.cpp:276)

void CDocBrowser::slotPopupMenu(const QString &, const QPoint & pnt){
  QString text;

  if(hasSelection()){
    text = selectedText();
    text.replace(QRegExp("^\n"), "");
    int pos=text.find("\n");
    if (pos>-1)
     text=text.left(pos);
  }

  if (!text.isEmpty())
  {
    doc_pop->setItemEnabled(ID_EDIT_COPY,true);
    doc_pop->setItemEnabled(ID_HELP_SEARCH_TEXT,true);
    doc_pop->setItemEnabled(ID_EDIT_SEARCH_IN_FILES,true);

    if(text.length() > 20 ){
      text = text.left(20) + "...";
    }
    doc_pop->changeItem(BarIcon("grep"),i18n("grep: ")+text, ID_EDIT_SEARCH_IN_FILES);
    doc_pop->changeItem(BarIcon("lookup"),i18n("look up: ")+ text,ID_HELP_SEARCH_TEXT);
  }
  else{
    doc_pop->setItemEnabled(ID_EDIT_COPY,false);
    doc_pop->setItemEnabled(ID_HELP_SEARCH_TEXT,false);
    doc_pop->setItemEnabled(ID_EDIT_SEARCH_IN_FILES,false);
    doc_pop->changeItem(BarIcon("grep"),i18n("grep: "), ID_EDIT_SEARCH_IN_FILES);
    doc_pop->changeItem(BarIcon("lookup"),i18n("look up: "),ID_HELP_SEARCH_TEXT);
  }
  doc_pop->popup(pnt);

}


kdevelop'CDocBrowser::slotCopyText() (./kdevelop/kdevelop/cdocbrowser.cpp:310)

void CDocBrowser::slotCopyText(){
    //kapp->clipboard()->setText(KHTMLPart::selectedText());
}


kdevelop'CDocBrowser::slotSearchText() (./kdevelop/kdevelop/cdocbrowser.cpp:314)

void CDocBrowser::slotSearchText(){
  emit signalSearchText();
}


kdevelop'CDocBrowser::slotGrepText() (./kdevelop/kdevelop/cdocbrowser.cpp:318)

void CDocBrowser::slotGrepText(){
    //emit signalGrepText(KHTMLPart::selectedText());
}


kdevelop'CDocBrowser::slotURLBack() (./kdevelop/kdevelop/cdocbrowser.cpp:322)

void CDocBrowser::slotURLBack(){
  emit signalURLBack();
}


kdevelop'CDocBrowser::slotURLForward() (./kdevelop/kdevelop/cdocbrowser.cpp:326)

void CDocBrowser::slotURLForward(){
  emit signalURLForward();
}


kdevelop'CDocBrowser::slotSetFileTitle() (./kdevelop/kdevelop/cdocbrowser.cpp:330)

void CDocBrowser::slotSetFileTitle( const QString &title){
	m_title= title;
}


kdevelop'CDocBrowser::currentTitle() (./kdevelop/kdevelop/cdocbrowser.cpp:334)

QString CDocBrowser::currentTitle(){
	return (m_refTitle.isEmpty()) ? m_title : m_refTitle+" - "+m_title;	
}
/*
KBrowser* CDocBrowser::createFrame( QWidget *_parent, const char *_name ){
    return new CDocBrowser(_parent,_name);
}*/
//
// KDE Help Options
//
// (c) Martin R. Jones 1996
//



//-----------------------------------------------------------------------------