📄 htmlobj.cpp
字号:
}int HTMLImage::calcMinWidth(){ if ( percent > 0 ) return 1; return width;}int HTMLImage::calcPreferredWidth(){ return width;}void HTMLImage::setMaxWidth( int _max_width ){ if ( percent > 0 ) max_width = _max_width; if ( pixmap == 0 || pixmap->isNull() ) return; if ( percent > 0 ) { width = (int)max_width * (int)percent / 100; if ( !predefinedHeight ) ascent = pixmap->height() * width / pixmap->width() + border; width += border * 2; }}bool HTMLImage::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 HTMLImage::print( QPainter *_painter, int _tx, int _ty ){ QPixmap *pixptr = pixmap; QRect rect( 0, 0, width - border*2, ascent - border );#ifdef USE_QMOVIE if ( movie && pixmap ) { // Wow... all this mess, just to get QMovies with transparent // parts working... (Lars 30.11.98) rect = movie->getValidRect(); if( !movieCache ) { movieCache = new QPixmap(pixmap->width(), pixmap->height(), pixmap->depth()); QPainter p; p.begin(movieCache); if( bgColor.isValid() ) p.fillRect( 0, 0, pixmap->width(), pixmap->height(), bgColor ); else htmlWidget->drawBackground(x + _tx + border, y - ascent + _ty + border, x + _tx + border, y - ascent + _ty + border, pixmap->width(), pixmap->height(), &p); p.end(); } QPainter p; QPixmap pm; pm = movie->framePixmap(); p.begin(movieCache); p.drawPixmap(QPoint( rect.x(), rect.y() ), *pixmap, oldRect); p.drawPixmap(QPoint( rect.x(), rect.y() ), movie->framePixmap(), rect); p.end(); *pixmap = movie->framePixmap(); p.begin(pixmap); if( bgColor.isValid() ) p.fillRect( 0, 0, pixmap->width(), pixmap->height(), bgColor ); else htmlWidget->drawBackground(x + _tx + border + rect.x(), y - ascent + _ty + border + rect.y(), x + _tx + border + rect.x(), y - ascent + _ty + border + rect.y(), rect.width(), rect.height(), &p); p.end(); oldRect = rect; pixptr = movieCache; }#endif if ( pixmap ) { if ( predefinedWidth ) rect.setWidth( pixmap->width() ); if ( predefinedHeight ) rect.setHeight( pixmap->height() ); } if ( pixptr == 0 || pixptr->isNull() ) { if ( !predefinedWidth || !predefinedHeight ) { QColorGroup colorGrp( black, lightGray, white, darkGray, gray, black, white ); qDrawShadePanel( _painter, x + _tx, y - ascent + _ty, width, ascent, colorGrp, true, 1 ); } } else { QPixmap pm = *pixptr; if ( isSelected() ) { QPainter p( &pm );// p.setRasterOp( NotEraseROP );// p.fillRect( 0, 0, pm.width(), pm.height(), blue ); QBrush b( kapp->selectColor, Dense4Pattern ); p.fillRect( 0, 0, pm.width(), pm.height(), b ); } if ( (width - border*2 != pixptr->width() || ascent - border != pixptr->height() ) && pixptr->width() != 0 && pixptr->height() != 0 ) { QWMatrix matrix; matrix.scale( (float)(width-border*2)/pixptr->width(), (float)(ascent-border)/pixptr->height() ); QPixmap tp = pm.xForm( matrix ); rect.setRight( rect.width() * (width-border*2)/pixptr->width() ); rect.setBottom( rect.height() * (ascent-border)/pixptr->height()); _painter->drawPixmap( QPoint( x + _tx + border, y - ascent + _ty + border ), tp, rect ); } else _painter->drawPixmap( QPoint( x + _tx + border, y - ascent + _ty + border), pm, rect ); if ( overlay ) _painter->drawPixmap( QPoint( x + _tx + border, y - ascent + _ty + border ), *overlay, rect ); } if ( border ) { QPen pen( borderColor ); _painter->setPen( pen ); QBrush brush; _painter->setBrush( brush ); // null brush for ( int i = 1; i <= border; i++ ) _painter->drawRect( x+_tx+border-i, y - ascent + border + _ty - i, (width - border*2) + i*2, ascent - border + i*2 ); }}void HTMLImage::calcAbsolutePos( int _x, int _y ){ absX = _x + x; absY = _y + y - ascent;}int HTMLImage::getAbsX(){ return absX;}int HTMLImage::getAbsY(){ return absY;}void HTMLImage::setBgColor( QColor col ){ bgColor = col; if( movieCache ) { QPainter p; p.begin(movieCache); if( bgColor.isValid() ) p.fillRect( 0, 0, pixmap->width(), pixmap->height(), bgColor ); //p.drawPixmap(QPoint( rect.x(), rect.y() ), movie->framePixmap(), // rect); p.end(); }}void HTMLImage::movieUpdated( const QRect & ){#ifdef USE_QMOVIE if ( !pixmap ) { pixmap = new QPixmap; *pixmap = movie->framePixmap(); init(); if ( !predefinedWidth || !predefinedHeight ) { htmlWidget->calcSize(); htmlWidget->calcAbsolutePos(); htmlWidget->scheduleUpdate( true ); return; } } htmlWidget->paintSingleObject( this );#endif}// workaround for a bug in QMovie...void HTMLImage::statusChanged( int status){#ifdef USE_QMOVIE if( status < 0 ) movie->pause();#endif}HTMLImage::~HTMLImage(){ if ( !bComplete && !pixmap ) htmlWidget->cancelRequestFile( this ); // if ( !imageURL.isEmpty() && !pixmap ) // htmlWidget->cancelRequestFile( this ); if ( pixmap ) delete pixmap; if ( movieCache ) delete movieCache;#ifdef USE_QMOVIE if ( movie ) { movie->disconnectUpdate( this, 0 ); delete movie; }#endif}//----------------------------------------------------------------------------HTMLArea::HTMLArea( const QPointArray &_points, const char *_url, const char *_target ){ region = QRegion( _points ); url = _url; target = _target;}HTMLArea::HTMLArea( const QRect &_rect, const char *_url, const char *_target ){ region = QRegion( _rect ); url = _url; target = _target;}HTMLArea::HTMLArea( int _x, int _y, int _r, const char *_url, const char *_target ){ QRect r( _x - _r, _y - _r, _r * 2, _y * 2 ); region = QRegion( r, QRegion::Ellipse ); url = _url; target = _target;}//----------------------------------------------------------------------------HTMLMap::HTMLMap( KHTMLWidget *w, const char *_url ) : HTMLObject(){ areas.setAutoDelete( true ); mapurl = _url; htmlWidget = w; if ( strchr ( mapurl, ':' ) ) htmlWidget->requestFile( this, mapurl );}HTMLMap::~HTMLMap(){ if ( strchr ( mapurl, ':' ) ) htmlWidget->cancelRequestFile( this );}bool HTMLMap::fileLoaded( const char* _url, QBuffer& _buffer ){ if ( !_buffer.open( IO_ReadOnly ) ) { warning("Could not open buffer for reading a map\n" ); return false; } bool res = fileLoaded( _buffer ); _buffer.close(); return res;}// The external map has been downloadedvoid HTMLMap::fileLoaded( const char *_filename ){ QFile file( _filename ); if ( !file.open( IO_ReadOnly ) ) { warning("Could not open %s for reading a map\n", _filename ); return; } (void)fileLoaded( file ); file.close();}bool HTMLMap::fileLoaded( QIODevice& file ){ QString buffer; QString href; QString coords; HTMLArea::Shape shape = HTMLArea::Rect; char ch; while ( !file.atEnd() ) { // read in a line buffer[0] = '\0'; do { ch = file.getch(); if ( ch != '\n' && ch != -1 ); buffer += ch; } while ( ch != '\n' && ch != -1 ); // comment? if ( buffer[0] == '#' ) continue; StringTokenizer st; st.tokenize( buffer, " " ); // get shape const char *p = st.nextToken(); if ( strncasecmp( p, "rect", 4 ) == 0 ) shape = HTMLArea::Rect; else if ( strncasecmp( p, "poly", 4 ) == 0 ) shape = HTMLArea::Poly; else if ( strncasecmp( p, "circle", 6 ) == 0 ) shape = HTMLArea::Circle; // get url p = st.nextToken(); if ( *p == '#' ) {// reference KURL u( htmlWidget->getDocumentURL() ); u.setReference( p + 1 ); href = u.url(); } else if ( strchr( p, ':' ) ) {// full URL href = p; } else {// relative URL KURL u2( htmlWidget->getBaseURL(), p ); href = u2.url(); } // read coords and create object HTMLArea *area = 0; switch ( shape ) { case HTMLArea::Rect: { p = st.nextToken(); int x1, y1, x2, y2; sscanf( p, "%d,%d,%d,%d", &x1, &y1, &x2, &y2 ); QRect rect( x1, y1, x2-x1, y2-y1 ); area = new HTMLArea( rect, href, "" ); //printf( "Area Rect %d, %d, %d, %d\n", x1, y1, x2, y2 ); } break; case HTMLArea::Circle: { p = st.nextToken(); int xc, yc, rc; sscanf( p, "%d,%d,%d", &xc, &yc, &rc ); area = new HTMLArea( xc, yc, rc, href, "" ); //printf( "Area Circle %d, %d, %d\n", xc, yc, rc ); } break; case HTMLArea::Poly: { //printf( "Area Poly " ); int count = 0, x, y; QPointArray parray; while ( st.hasMoreTokens() ) { p = st.nextToken(); sscanf( p, "%d,%d", &x, &y ); parray.resize( count + 1 ); parray.setPoint( count, x, y ); //printf( "%d, %d ", x, y ); count++; } //printf( "\n" ); if ( count > 2 ) area = new HTMLArea( parray, href, "" ); } break; } if ( area ) addArea( area ); } // No update needed. return false;}const HTMLArea *HTMLMap::containsPoint( int _x, int _y ){ const HTMLArea *area; for ( area = areas.first(); area != 0; area = areas.next() ) { if ( area->contains( QPoint( _x, _y ) ) ) return area; } return 0;}//----------------------------------------------------------------------------#ifdef EXEC_EXTENSIONSHTMLImageMap::HTMLImageMap(KHTMLWidget *widget,const char *_filename,char *_url,char *_target,char *_exec,int _max_width,int _width,int _height,int _percent,int bdr) : HTMLImage(widget,_filename,_url,_target,_exec,_max_width,_width,_height,_percent,bdr)#elseHTMLImageMap::HTMLImageMap(KHTMLWidget *widget,const char *_filename,char *_url,char *_target,int _max_width,int _width,int _height,int _percent,int bdr) : HTMLImage(widget,_filename,_url,_target,_max_width,_width,_height,_percent,bdr)#endif{ type = ClientSide; serverurl = _url; serverurl.detach();}HTMLObject* HTMLImageMap::checkPoint( int _x, int _y ){ if ( _x >= x && _x < x + width ) { if ( _y > y - ascent && _y < y + descent + 1 ) { if ( type == ClientSide ) { HTMLMap *map = htmlWidget->getMap( mapurl ); if ( map ) { const HTMLArea *area = map->containsPoint( _x - x, _y - ( y -ascent ) ); if ( area ) { strncpy( url, area->getURL(), KHTMLW_MAX_URL ); strncpy( target, area->getTarget(), KHTMLW_MAX_TARGET ); return this; } else { *url = '\0'; *target = '\0'; } } } else { QString coords; coords.sprintf( "?%d,%d", _x - x, _y - ( y -ascent ) ); strcpy( url, serverurl ); strcat( url, coords ); return this; } } } return 0;}//-----------------------------------------------------------------------------HTMLAnchor* HTMLAnchor::findAnchor( const char *_name, QPoint *_p ){ if ( strcmp( _name, name ) == 0 ) { _p->setX( _p->x() + x ); _p->setY( _p->y() + y ); return this; } return 0L;}void HTMLAnchor::setMaxAscent( int _a ){ y -= _a;}//-----------------------------------------------------------------------------#include "htmlobj.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -