📄 htmlobj.cpp
字号:
if (isSelected()) { if (isAllSelected()) { int fillStart = 0; int fillEnd = _painter->fontMetrics().width( text, posLen ); _painter->fillRect( x + fillStart + _tx, y - ascent + _ty, fillEnd - fillStart, ascent + descent, kapp->selectColor ); _painter->setPen( kapp->selectTextColor ); _painter->drawText( x + _tx + fillStart, y + _ty, text, posLen ); return; } else { short selStart = owner->selStart - posStart; short selEnd = owner->selEnd - posStart; // (partly) selected if (selEnd > posLen) selEnd = posLen; else if (selEnd < 0) selEnd = 0; if (selStart < 0) selStart = 0; else if (selStart > posLen) selStart = posLen; _painter->setPen( font->textColor() ); _painter->drawText( x + _tx, y + _ty, text, selStart ); int fillStart = _painter->fontMetrics().width( text, selStart ); int fillEnd = _painter->fontMetrics().width( text, selEnd ); _painter->fillRect( x + fillStart + _tx, y - ascent + _ty, fillEnd - fillStart, ascent + descent, kapp->selectColor ); _painter->setPen( kapp->selectTextColor ); _painter->drawText( x + _tx + fillStart, y + _ty, text + selStart, selEnd - selStart ); _painter->setPen( font->textColor() ); _painter->drawText( x + _tx + fillEnd, y + _ty, text + selEnd, posLen - selEnd ); return; } } } _painter->setPen( font->textColor() ); _painter->drawText( x + _tx, y + _ty, text, posLen );}//-----------------------------------------------------------------------------HTMLRule::HTMLRule( int _max_width, int _percent, int _size, bool _shade ) : HTMLObject(){ if ( _size < 1 ) _size = 1; ascent = 6 + _size; descent = 6; max_width = _max_width; width = _max_width; percent = _percent; shade = _shade; if ( percent > 0 ) { width = max_width * percent / 100; setFixedWidth( false ); }}int HTMLRule::calcMinWidth(){ if ( isFixedWidth() ) return width; return 1;}void HTMLRule::setMaxWidth( int _max_width ){ if ( !isFixedWidth() ) { max_width = _max_width; if ( percent > 0 ) width = _max_width * percent / 100; else width = max_width; }}bool HTMLRule::print( QPainter *_painter, int, int _y, int, int _height, int _tx, int _ty, bool toPrinter ){ if ( _y + _height < y - getAscent() || _y > y + getDescent() ) return false; if ( toPrinter ) { if ( _y + _height <= y + descent ) return true; if ( isPrinted() ) return false; setPrinted( true ); } print( _painter, _tx, _ty ); return false;}void HTMLRule::print( QPainter *_painter, int _tx, int _ty ){ QColorGroup colorGrp( black, lightGray, white, darkGray, gray, black, white ); int xp = x + _tx, yp = y + _ty; if ( shade ) qDrawShadeLine( _painter, xp, yp, xp + width, yp, colorGrp, TRUE, 1, ascent-7 ); else _painter->fillRect( xp, yp, width, ascent-6, QBrush(black) );}//-----------------------------------------------------------------------------HTMLBullet::HTMLBullet( int _height, int _level, const QColor &col ) : HTMLObject(), color( col ){ ascent = _height; descent = 0; width = 14; level = _level;}bool HTMLBullet::print( QPainter *_painter, int, int _y, int, int _height, int _tx, int _ty, bool toPrinter ){ if ( _y + _height < y - getAscent() || _y > y + getDescent() ) return false; if ( toPrinter ) { if ( _y + _height <= y + descent ) return true; if ( isPrinted() ) return false; setPrinted( true ); } print( _painter, _tx, _ty ); return false;}void HTMLBullet::print( QPainter *_painter, int _tx, int _ty ){ int yp = y + _ty - 9; int xp = x + _tx + 2; _painter->setPen( QPen( color ) ); switch ( level ) { case 1: _painter->setBrush( QBrush( color ) ); _painter->drawEllipse( xp, yp, 7, 7 ); break; case 2: _painter->setBrush( QBrush() ); _painter->drawEllipse( xp, yp, 7, 7 ); break; case 3: _painter->setBrush( QBrush( color ) ); _painter->drawRect( xp, yp, 7, 7 ); break; default: _painter->setBrush( QBrush() ); _painter->drawRect( xp, yp, 7, 7 ); }}//-----------------------------------------------------------------------------HTMLCachedImage::HTMLCachedImage( const char *_filename ){ pixmap = 0; filename = _filename;}QPixmap* HTMLCachedImage::getPixmap(){ if ( !pixmap ) { pixmap = new QPixmap(); pixmap->load( filename ); } return pixmap;}QPixmap* HTMLImage::findImage( const char *_filename ){ // Since this method is static, it is possible that pCache has not // yet been initialized. Better be careful. if( !pCache ) { pCache = new QDict<HTMLCachedImage>( 503, true, false ); return 0l; } HTMLCachedImage *img = pCache->find( _filename ); if ( img ) { return img->getPixmap(); } return 0L;}void HTMLImage::cacheImage( const char *_filename ){ // Since this method is static, it is possible that pCache has not // yet been initialized. Better be careful. if( !pCache ) pCache = new QDict<HTMLCachedImage>( 503, true, false ); pCache->insert( _filename, new HTMLCachedImage( _filename ) );}#ifdef EXEC_EXTENSIONSHTMLImage::HTMLImage(KHTMLWidget *widget,const char *_filename, char *_url,char *_target,char *_exec, int _max_width,int _width,int _height,int _percent,int bdr) : QObject(), HTMLObject()#elseHTMLImage::HTMLImage(KHTMLWidget *widget,const char *_filename, char *_url,char *_target, int _max_width,int _width,int _height,int _percent,int bdr) : QObject(), HTMLObject()#endif{ if ( pCache == 0 ) pCache = new QDict<HTMLCachedImage>( 503, true, false );; pixmap = 0; movieCache = 0; movie = 0; overlay = 0; bComplete = true; htmlWidget = widget; url = _url; target = _target;#ifdef EXEC_EXTENSIONS exec = _exec;#endif predefinedWidth = ( _width < 0 && !_percent ) ? false : true; predefinedHeight = _height < 0 ? false : true; border = bdr; percent = _percent; max_width = _max_width; ascent = _height + border; descent = border; if ( percent > 0 ) { width = (int)max_width * (int)percent / 100; width += border * 2; } else { width = _width + border * 2; } absX = -1; absY = -1; // A HTMLJSImage ? if ( _filename == 0L ) { // Do not load an image yet imageURL = ""; synchron = false; bComplete = false; return; } KURL kurl( _filename ); if ( kurl.isMalformed() ) { warning("Malformed URL '%s'\n", _filename ); return; } // Commented out jsk .. we always want to load from the main thread .. // (plus the cache manager is unimplemented) .. please fix me // if ( !kurl.isLocalFile() ) if(1) { imageURL = _filename; bComplete = false; synchron = TRUE; htmlWidget->requestFile( this, imageURL.data() ); synchron = FALSE; } else { QPixmap *p = HTMLImage::findImage( kurl.path() ); if ( p ) { pixmap = new QPixmap; *pixmap = *p; init(); } else { // the file is onl the local hard disk synchron = true; fileLoaded( kurl.path() ); synchron =false; } } // Is the image available ? if ( pixmap == 0 || pixmap->isNull() ) { if ( !predefinedWidth && !percent) width = 32; if ( !predefinedHeight ) ascent = 32; }}void HTMLImage::init(){ if ( percent > 0 ) { width = (int)max_width * (int)percent / 100; if ( !predefinedHeight ) ascent = pixmap->height() * width / pixmap->width(); setFixedWidth( false ); } else { if ( !predefinedWidth ) width = pixmap->width(); if ( !predefinedHeight ) ascent = pixmap->height(); if ( predefinedWidth && !predefinedHeight ) ascent = pixmap->height() * width / pixmap->width(); } if ( !predefinedWidth ) width += border*2; if ( !predefinedHeight ) ascent += border;}void HTMLImage::changeImage( const char *_url ){ KURL u( htmlWidget->getBaseURL(), _url ); if ( u.isMalformed() ) return; if ( !bComplete && !pixmap ) htmlWidget->cancelRequestFile( this ); imageURL = _url; if ( u.isLocalFile() ) { if ( !pixmap ) pixmap = new QPixmap(); QPixmap *p = HTMLImage::findImage( u.path() ); if ( p ) { *pixmap = *p; } else { pixmap->load( u.path() ); } bComplete = true; } else { synchron = TRUE; bComplete = false; htmlWidget->requestFile( this, imageURL.data() ); synchron = FALSE; } // Is the image available ? if ( pixmap == 0 || pixmap->isNull() ) { if ( !predefinedWidth && !percent) width = 32; if ( !predefinedHeight ) ascent = 32; } else init(); if ( bComplete && !isA( "HTMLJSImage" ) ) htmlWidget->paintSingleObject( this );}void HTMLImage::setOverlay( const char *_ol ){ // overlays must be cached overlay = HTMLImage::findImage( _ol );}bool HTMLImage::fileLoaded( const char* _url, QBuffer& _buffer ){ bComplete = true; char buffer[ 4 ]; buffer[0] = 0; _buffer.open( IO_ReadOnly ); _buffer.readBlock( buffer, 3 ); _buffer.close(); if ( strcmp( buffer, "GIF" ) == 0 ) { movie = new QMovie( _buffer.buffer() ); movie->connectUpdate( this, SLOT( movieUpdated( const QRect &) ) );#if QT_VERSION <= 141 movie->connectStatus( this, SLOT( statusChanged( int ) ) );#endif } else { pixmap = new QPixmap(); pixmap->loadFromData( _buffer.buffer() ); if ( pixmap == 0 || pixmap->isNull() ) return false; } init(); // Commented out .. jsk/* // We knew the size during the HTML parsing ? if ( predefinedWidth && predefinedHeight && !synchron ) htmlWidget->paintSingleObject( this ); else */if ( !synchron ) // We need an update. That means the size and position if // all elements has to be recalculated => return true return true; // No update of sizes and positions needed since we already knew // the size of the image or since we are in synchron mode. return false;}void HTMLImage::fileLoaded( const char *_filename ){ bComplete = true; char buffer[ 7 ]; buffer[0] = 0; FILE *f = fopen( _filename, "rb" ); if ( f ) { int n = fread( buffer, 1, 6, f ); if ( n >= 0 ) buffer[ n ] = 0; else buffer[0] = 0; fclose( f ); } else { warning( "Could not load %s\n", _filename ); perror( "" ); } if ( strcmp( buffer, "GIF89a" ) == 0 ) { // Workaround for bug in QMovie // Load the image in memory to avoid vasting file handles struct stat buff; stat( _filename, &buff ); int size = buff.st_size; char *p = new char[ size ]; FILE *f = fopen( _filename, "rb" ); fread( p, 1, size, f ); fclose( f ); QByteArray arr; arr.assign( p, size ); movie = new QMovie( arr, 8192 ); // End Workaround // movie = new QMovie( _filename, 8192 ); movie->connectUpdate( this, SLOT( movieUpdated( const QRect &) ) );#if QT_VERSION <= 141 // workaround for another bug... movie->connectStatus( this, SLOT( statusChanged( int ) ) );#endif } else { pixmap = new QPixmap(); pixmap->load( _filename ); if ( pixmap == 0 || pixmap->isNull() ) return; init(); debugM( "Loaded Image: %s, %d, %d, %d\n", imageURL.data(), predefinedWidth, predefinedHeight, synchron ); // Commented out .. jsk/* // We knew the size during the HTML parsing ? if ( predefinedWidth && predefinedHeight && !synchron ) htmlWidget->paintSingleObject( this ); else */if ( !synchron ) { htmlWidget->calcSize(); htmlWidget->calcAbsolutePos(); htmlWidget->scheduleUpdate( true ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -