📄 html.cpp
字号:
pressed = TRUE; // deselect all currently selected text if ( bIsTextSelected ) { bIsTextSelected = false; selectText( 0, 0, 0, 0 ); // deselect all text emit textSelected( false ); } // start point for text selection selectPt1.setX( _mouse->pos().x() + x_offset - leftBorder ); selectPt1.setY( _mouse->pos().y() + y_offset - topBorder ); } press_x = _mouse->pos().x(); press_y = _mouse->pos().y(); HTMLObject *obj; obj = clue->checkPoint( _mouse->pos().x() + x_offset - leftBorder, _mouse->pos().y() + y_offset - topBorder ); pressedURL = ""; pressedTarget = "";#ifdef EXEC_EXTENSIONS pressedExec = ""; if(obj != 0) { if(obj->getExec() != 0) { pressedExec = obj->getExec(); pressedExec.detach(); } }#endif if ( obj != 0) { if ( obj->getURL() != 0 ) { if (obj->getURL()[0] != 0) { // Save data. Perhaps the user wants to start a drag. if ( _mouse->button() == LeftButton || _mouse->button() == MidButton ) { pressedURL = obj->getURL(); pressedURL.detach(); pressedTarget = obj->getTarget(); pressedTarget.detach(); } // Does the parent want to process the event now ? if ( htmlView ) { if ( htmlView->mousePressedHook( obj->getURL(), obj->getTarget(), _mouse, obj->isSelected() ) ) return; } if ( _mouse->button() == RightButton ) { emit popupMenu(obj->getURL(),mapToGlobal( _mouse->pos() )); return; } return; } } } if ( htmlView ) if ( htmlView->mousePressedHook( 0, 0L, _mouse, FALSE ) ) return; if ( _mouse->button() == RightButton ) emit popupMenu( 0, mapToGlobal( _mouse->pos() ) ); }void KHTMLWidget::mouseDoubleClickEvent( QMouseEvent *_mouse ){ if ( clue == 0 ) return; HTMLObject *obj; obj = clue->checkPoint( _mouse->pos().x() + x_offset - leftBorder, _mouse->pos().y() + y_offset - topBorder ); if ( obj != 0) if ( obj->getURL() != 0 ) if (obj->getURL()[0] != 0) emit doubleClick( obj->getURL(), _mouse->button() );}void KHTMLWidget::dndMouseMoveEvent( QMouseEvent * _mouse ){ if ( clue == 0 ) return; if ( !pressed ) { // Look wether the cursor is over an URL. HTMLObject *obj=clue->checkPoint(_mouse->pos().x()+x_offset-leftBorder, _mouse->pos().y() + y_offset - topBorder ); if ( obj != 0 ) { if ( obj->getURL() && obj->getURL()[0] != 0 ) { if ( overURL != obj->getURL() ) { setCursor( linkCursor ); overURL = obj->getURL(); emit onURL( overURL ); } } else if ( overURL != "" ) { setCursor( KCursor::arrowCursor() ); emit onURL( 0 ); overURL = ""; } } else if ( overURL != "" ) { setCursor( KCursor::arrowCursor() ); emit onURL( 0 ); overURL = ""; } return; } // debugT(">>>>>>>>>>>>>>>>>>> Move detected <<<<<<<<<<<<<<<<<<<\n"); // Does the parent want to process the event now ? if ( htmlView ) { if ( htmlView->mouseMoveHook( _mouse ) ) return; } // text selection if ( pressed && pressedURL.isEmpty() ) { QPoint point = _mouse->pos(); if ( point.y() > height() ) point.setY( height() ); else if ( point.y() < 0 ) point.setY( 0 ); selectPt2.setX( point.x() + x_offset - leftBorder ); selectPt2.setY( point.y() + y_offset - topBorder ); if ( selectPt2.y() < selectPt1.y() ) { selectText( selectPt2.x(), selectPt2.y(), selectPt1.x(), selectPt1.y() ); } else { selectText( selectPt1.x(), selectPt1.y(), selectPt2.x(), selectPt2.y() ); } // Do we need to scroll because the user has moved the mouse // outside the widget bounds? if ( _mouse->pos().y() > height() ) { autoScrollY( 100, 20 ); connect( this, SIGNAL( scrollVert(int) ), SLOT( slotUpdateSelectText(int) ) ); } else if ( _mouse->pos().y() < 0 ) { autoScrollY( 100, -20 ); connect( this, SIGNAL( scrollVert(int) ), SLOT( slotUpdateSelectText(int) ) ); } else { stopAutoScrollY(); disconnect( this, SLOT( slotUpdateSelectText(int) ) ); } } // Drags are only started with the left mouse button ... // if ( _mouse->button() != LeftButton ) // return; // debugT("Testing pressedURL.isEmpty()\n"); if ( pressedURL.isEmpty() ) return; int x = _mouse->pos().x(); int y = _mouse->pos().y(); // debugT("Testing Drag\n"); // Did the user start a drag? if ( abs( x - press_x ) > Dnd_X_Precision || abs( y - press_y ) > Dnd_Y_Precision && !drag ) { // debugT(">>>>>>>>>>>>>>>> Starting DND <<<<<<<<<<<<<<<<<<<<<<<<\n"); QPoint p = mapToGlobal( _mouse->pos() ); // Does the parent want to process the event now ? if ( htmlView ) { if ( htmlView->dndHook( pressedURL.data(), p ) ) return; } int dx = - dndDefaultPixmap.width() / 2; int dy = - dndDefaultPixmap.height() / 2; startDrag( new KDNDIcon( dndDefaultPixmap, p.x() + dx, p.y() + dy ), pressedURL.data(), pressedURL.length(), DndURL, dx, dy ); }}void KHTMLWidget::dndMouseReleaseEvent( QMouseEvent * _mouse ){ if ( clue == 0 ) return; if ( pressed ) { // in case we started an autoscroll in MouseMove event stopAutoScrollY(); disconnect( this, SLOT( slotUpdateSelectText(int) ) ); } // Used to prevent dndMouseMoveEvent from initiating a drag before // the mouse is pressed again. pressed = false; if ( clue->mouseEvent( _mouse->x() + x_offset - leftBorder, _mouse->y() + y_offset - topBorder, _mouse->button(), _mouse->state() ) ) return; // Does the parent want to process the event now ? if ( htmlView ) { if ( htmlView->mouseReleaseHook( _mouse ) ) return; } // emit textSelected() if necessary if ( _mouse->button() == LeftButton || _mouse->button() == MidButton ) { if ( bIsTextSelected ) { debugM( "Text Selected\n" ); emit textSelected( true ); } } if ( clue == 0 ) return; #ifdef EXEC_EXTENSIONS if( !pressedExec.isEmpty()) { if(_mouse->button() != RightButton) emit execfunc(pressedExec.data()); }#endif if ( pressedURL.isEmpty() ) return; // if ( pressedURL.data()[0] == '#' ) // gotoAnchor( pressedURL.data() + 1 ); // else if ( _mouse->button() != RightButton ) { emit URLSelected( pressedURL.data(), _mouse->button(), pressedTarget.data() ); // required for backward compatability emit URLSelected( pressedURL.data(), _mouse->button() ); }}void KHTMLWidget::dragEndEvent(){ // Used to prevent dndMouseMoveEvent from initiating a new drag before // the mouse is pressed again. pressed = false;}void KHTMLWidget::setBlob( QPoint pos ){#ifdef USE_THE_BLOB_ALEX_MADE setCursor(waitCursor); scrollBlob = new QWidget(this); scrollBlob->resize(scrollBlobPixmap.size()); scrollBlob->setBackgroundPixmap(scrollBlobPixmap); scrollBlob->move(pos); scrollBlob->show(); scrollBlobTimer->start(500, false);#endif}void KHTMLWidget::clearBlob (){#ifdef USE_THE_BLOB_ALEX_MADE scrollBlobTimer->stop(); setCursor(arrowCursor); delete scrollBlob; scrollBlob=0;#endif}void KHTMLWidget::scrollBlobTimeout (){#ifdef USE_THE_BLOB_ALEX_MADE int newY=0; switch (scrollBlobType) { case SCROLL_NONE: break; case SCROLL_UP: { if ( docHeight() < height() ) { clearBlob(); break; } newY = y_offset - 20; if ( newY < 0 ) newY = 0; slotScrollVert( newY ); emit scrollVert( newY ); break; } case SCROLL_DOWN: { if ( docHeight() < height() ) { clearBlob(); break; } newY = y_offset + 20; if ( newY > docHeight() - height() ) newY = docHeight() - height(); slotScrollVert( newY ); emit scrollVert( newY ); break; } default:{ break; } return;#endif}bool KHTMLWidget::URLVisited( const char *_url ){ if ( htmlView ) return htmlView->URLVisited( _url ); return false;}/* * Checks out wether there is a URL under the point p and returns a pointer * to this URL or 0 if there is none. */const char* KHTMLWidget::getURL( QPoint &p ){ printf("Inside KHTMLWidget::getURL()\n"); if ( clue == 0 ) return 0; HTMLObject *obj; obj = clue->checkPoint( p.x() + x_offset, p.y() + y_offset ); if ( obj != 0) if ( obj->getURL() && obj->getURL()[0] != 0 ) return obj->getURL(); return 0;}void KHTMLWidget::select( QPainter * _painter, QRect &_rect ){ if ( clue == 0 ) return; QRect r = _rect; r.moveBy( -x_offset, -y_offset ); int tx = -x_offset + leftBorder; int ty = -y_offset + topBorder; HTMLChain chain; clue->select( this, &chain, r, tx, ty );}void KHTMLWidget::selectText( int _x1, int _y1, int _x2, int _y2 ){ if ( clue == 0 ) return; int tx = -x_offset + leftBorder; int ty = -y_offset + topBorder; HTMLChain chain; bIsTextSelected = clue->selectText(this,&chain,_x1, _y1, _x2, _y2, tx, ty);}void KHTMLWidget::findTextBegin(){ if ( clue == 0 ) return; findTextEnd(); textFindIter = new HTMLListIterator( clue );}bool KHTMLWidget::findTextNext( const QRegExp &exp ){ if ( clue == 0 ) return false; HTMLObject *obj; if ( !textFindIter ) findTextBegin(); selectText( 0, 0, 0, 0 ); // deselect all text // loop until we match the regexp, or reach the end of the document. do { obj = textFindIter->current(); textFindIter->next(); } while ( obj && !obj->selectText( exp ) ); if ( obj ) { // We found a match - highlight int x = 0, y = 0; clue->getObjectPosition( obj, x, y ); if ( y < y_offset || y > y_offset + height() - obj->getHeight() ) { gotoXY( x_offset, y - 40 ); } paintSingleObject( obj ); } else { // end of document reached. findTextEnd(); } return ( obj != 0 );}void KHTMLWidget::findTextEnd(){ if ( textFindIter ) { delete textFindIter; textFindIter = 0; selectText( 0, 0, 0, 0 ); // deselect all text }}void KHTMLWidget::paintEvent( QPaintEvent* _pe ){ bool newPainter = FALSE; if ( clue == 0 ) return; if ( painter == 0 ) { painter = new QPainter; painter->begin( this ); newPainter = TRUE; } painter->setBackgroundColor( settings->bgColor ); positionFormElements(); // painter->translate( x_offset, -y_offset ); int tx = -x_offset + leftBorder; int ty = -y_offset + topBorder; drawBackground( x_offset, y_offset, _pe->rect().x(), _pe->rect().y(), _pe->rect().width(), _pe->rect().height() ); clue->print( painter, _pe->rect().x() - x_offset, _pe->rect().y() + y_offset - topBorder, _pe->rect().width(), _pe->rect().height(), tx, ty, false ); if (bIsSelected && htmlView && htmlView->getFrameBorder()) { cerr << "Drawing frame (frameborder = " << htmlView->getFrameBorder() << " )\n"; QPen pen = painter->pen(); painter->setPen( black ); QBrush brush; painter->setBrush( brush ); painter->drawRect( 0, 0, width(), height() ); painter->drawRect( 1, 1, width() - 2, height() - 2 ); painter->setPen( pen ); } if ( newPainter ) { painter->end(); delete painter; painter = 0; }}void KHTMLWidget::resizeEvent( QResizeEvent* _re ){ if ( clue == 0 ) return; if ( isFrameSet() ) { framesetList.getFirst()->setGeometry( 0, 0, width(), height() ); } else if ( clue && _re->oldSize().width() != _re->size().width() ) { calcSize(); calcAbsolutePos(); positionFormElements(); } emit resized( _re->size() );}void KHTMLWidget::keyPressEvent( QKeyEvent *_ke ){ switch ( _ke->key() ) { //------------------------------------- // KFM Extension //------------------------------------- case Key_Space: { cellSelected(); flushKeys(); } break; case Key_Escape: { cellContextMenu(); flushKeys(); } break; case Key_Return: { cellActivated(); flushKeys(); } break; case Key_Backspace: { QString saved (currentKeySeq); flushKeys(); currentKeySeq = saved.left( saved.length() - 1 ); cellSequenceChanged(); } break; //------------------------------------- // End KFM Extension //------------------------------------- case Key_Down: {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -