📄 pageview.cpp.svn-base
字号:
bool wantCompositing = ( !selectionRect.isNull() && contentsRect.intersects( selectionRect ) ) || d->mouseTextSelecting; if ( wantCompositing && KpdfSettings::enableCompositing() ) { // create pixmap and open a painter over it (contents{left,top} becomes pixmap {0,0}) QPixmap doubleBuffer( contentsRect.size() ); QPainter pixmapPainter( &doubleBuffer ); pixmapPainter.translate( -contentsRect.left(), -contentsRect.top() ); // calculate the color XRenderColor col; float alpha=0.2f; QColor blCol=selBlendColor.dark(140); col.red=( (blCol.red() << 8) | blCol.red() ) * alpha; col.green=( (blCol.green() << 8) | blCol.green() )*alpha; col.blue=( (blCol.blue() << 8) | blCol.blue())*alpha; col.alpha=alpha*0xffff; // 1) Layer 0: paint items and clear bg on unpainted rects drawDocumentOnPainter( contentsRect, &pixmapPainter ); // 2) Layer 1a: paint (blend) transparent selection if ( !selectionRect.isNull() && selectionRect.intersects( contentsRect ) && !selectionRectInternal.contains( contentsRect ) ) { QRect blendRect = selectionRectInternal.intersect( contentsRect ); // skip rectangles covered by the selection's border if ( blendRect.isValid() ) { // grab current pixmap into a new one to colorize contents QPixmap blendedPixmap( blendRect.width(), blendRect.height() ); copyBlt( &blendedPixmap, 0,0, &doubleBuffer, blendRect.left() - contentsRect.left(), blendRect.top() - contentsRect.top(), blendRect.width(), blendRect.height() ); // blend selBlendColor into the background pixmap// QImage blendedImage = blendedPixmap.convertToImage();// KImageEffect::blend( selBlendColor.dark(140), blendedImage, 0.2 ); XRenderFillRectangle(x11Info().display(), PictOpOver, blendedPixmap.x11PictureHandle(), &col, 0,0, blendRect.width(), blendRect.height()); // copy the blended pixmap back to its place pixmapPainter.drawPixmap( blendRect.left(), blendRect.top(), blendedPixmap ); } // draw border (red if the selection is too small) pixmapPainter.setPen( selBlendColor ); pixmapPainter.drawRect( selectionRect ); } if ( d->mouseTextSelecting ) { QRect blendRect; QList<QRect>::iterator it=d->mouseTextSelectionRect->begin(), end=d->mouseTextSelectionRect->end(); XRenderColor col; float alpha=0.2f; QColor blCol=d->mouseTextSelectionColor.dark(140); col.red=( (blCol.red() << 8) | blCol.red() ) * alpha; col.green=( (blCol.green() << 8) | blCol.green() )*alpha; col.blue=( (blCol.blue() << 8) | blCol.blue())*alpha; col.alpha=alpha*0xffff; for (;it!=end;++it) { if (! ((*it).intersects( contentsRect ))) continue; blendRect = (*it).intersect(contentsRect); QPixmap blendedPixmap( blendRect.width(), blendRect.height() ); copyBlt( &blendedPixmap, 0,0, &doubleBuffer, blendRect.left() - contentsRect.left(), blendRect.top() - contentsRect.top(), blendRect.width(), blendRect.height() ); // blend selBlendColor into the background pixmap XRenderFillRectangle(x11Info().display(), PictOpOver, blendedPixmap.x11PictureHandle(), &col, 0,0, blendRect.width(), blendRect.height());// KImageEffect::blend( d->mouseTextSelectionColor.dark(140), blendedImage, 0.2 ); // copy the blended pixmap back to its place pixmapPainter.drawPixmap( blendRect.left(), blendRect.top(), blendedPixmap ); // draw border (red if the selection is too small) pixmapPainter.setPen( d->mouseTextSelectionColor ); pixmapPainter.drawRect( selectionRect ); } } // 3) Layer 1: give annotator painting control if ( d->annotator && d->annotator->routePaints( contentsRect ) ) d->annotator->routePaint( &pixmapPainter, contentsRect ); // 4) Layer 2: overlays if ( KpdfSettings::debugDrawBoundaries() ) { pixmapPainter.setPen( Qt::blue ); pixmapPainter.drawRect( contentsRect ); } // finish painting and draw contents pixmapPainter.end(); screenPainter.drawPixmap( contentsRect.left(), contentsRect.top(), doubleBuffer ); } else { // 1) Layer 0: paint items and clear bg on unpainted rects drawDocumentOnPainter( contentsRect, &screenPainter ); // 2) Layer 1: paint opaque selection if ( !selectionRect.isNull() && selectionRect.intersects( contentsRect ) && !selectionRectInternal.contains( contentsRect ) ) { screenPainter.setPen( palette().color( QPalette::Active, QPalette::Highlight ).dark(110) ); screenPainter.drawRect( selectionRect ); } // 3) Layer 1: give annotator painting control if ( d->annotator && d->annotator->routePaints( contentsRect ) ) d->annotator->routePaint( &screenPainter, contentsRect ); // 4) Layer 2: overlays if ( KpdfSettings::debugDrawBoundaries() ) { screenPainter.setPen( Qt::red ); screenPainter.drawRect( contentsRect ); } } }}}void PageView::viewportResizeEvent( QResizeEvent * event){if (d->document->handleEvent( event ) ){ if ( d->items.isEmpty() ) return; // start a timer that will refresh the pixmap after 0.2s if ( !d->delayResizeTimer ) { d->delayResizeTimer = new QTimer( this ); d->delayResizeTimer->setSingleShot( true ); connect( d->delayResizeTimer, SIGNAL( timeout() ), this, SLOT( slotRelayoutPages() ) ); } d->delayResizeTimer->start( 200 );}}void PageView::keyPressEvent( QKeyEvent * e ){if (d->document->handleEvent( e ) ){ e->accept(); // if performing a selection or dyn zooming, disable keys handling if ( d->mouseSelecting || d->mouseMidZooming ) return; // handle 'find as you type' (based on khtml/khtmlview.cpp) if( d->typeAheadActive ) { // backspace: remove a char and search or terminates search if( e->key() == Qt::Key_Backspace ) { if( d->typeAheadString.length() > 1 ) { d->typeAheadString = d->typeAheadString.left( d->typeAheadString.length() - 1 ); bool found = d->document->searchText( PAGEVIEW_SEARCH_ID, d->typeAheadString, true, false, KPDFDocument::NextMatch, true, qRgb( 128, 255, 128 ), true ); KLocalizedString status = found ? ki18n("Text found: \"%1\".") : ki18n("Text not found: \"%1\"."); d->messageWindow->display( status.subs(d->typeAheadString.toLower()).toString(), found ? PageViewMessage::Find : PageViewMessage::Warning, 4000 ); d->findTimeoutTimer->start( 3000 ); } else { slotStopFindAhead(); d->document->resetSearch( PAGEVIEW_SEARCH_ID ); } } // go to next occurrency else if( e->key() == d->actionCollection->action( "find_next" )->shortcut().keyQt() ) { // part doesn't get this key event because of the keyboard grab d->findTimeoutTimer->stop(); // restore normal operation during possible messagebox is displayed // (1/4) it is needed to grab the keyboard becase people may have Space assigned // to a accel and without grabbing the keyboard you can not vim-search for space // because it activates the accel releaseKeyboard(); if ( d->document->continueSearch( PAGEVIEW_SEARCH_ID ) ) d->messageWindow->display( i18n("Text found: \"%1\".", d->typeAheadString.toLower()), PageViewMessage::Find, 3000 ); d->findTimeoutTimer->start( 3000 ); // (2/4) it is needed to grab the keyboard becase people may have Space assigned // to a accel and without grabbing the keyboard you can not vim-search for space // because it activates the accel grabKeyboard(); } // esc and return: end search else if( e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return ) { slotStopFindAhead(); } // other key: add to text and search else if( !e->text().isEmpty() ) { d->typeAheadString += e->text(); doTypeAheadSearch(); } return; } else if( e->key() == '/' && d->document->isOpened() && d->document->supportsSearching() ) { // stop scrolling the page (if doing it) if ( d->autoScrollTimer ) { d->scrollIncrement = 0; d->autoScrollTimer->stop(); } // start type-adeas search d->typeAheadString = QString(); d->messageWindow->display( i18n("Starting -- find text as you type"), PageViewMessage::Find, 3000 ); d->typeAheadActive = true; if ( !d->findTimeoutTimer ) { // create the timer on demand d->findTimeoutTimer = new QTimer( this ); d->findTimeoutTimer->setSingleShot( true ); connect( d->findTimeoutTimer, SIGNAL( timeout() ), this, SLOT( slotStopFindAhead() ) ); } d->findTimeoutTimer->start( 3000 ); // (3/4) it is needed to grab the keyboard becase people may have Space assigned // to a accel and without grabbing the keyboard you can not vim-search for space // because it activates the accel grabKeyboard(); return; } // if viewport is moving, disable keys handling if ( d->viewportMoveActive ) return; // move/scroll page by using keys switch ( e->key() ) { case Qt::Key_Up: case Qt::Key_PageUp: case Qt::Key_Backspace: // if in single page mode and at the top of the screen, go to \ page if ( KpdfSettings::viewContinuous() || verticalScrollBar()->value() > verticalScrollBar()->minimum() ) { if ( e->key() == Qt::Key_Up ) verticalScrollBar()->triggerAction( QScrollBar::SliderSingleStepSub ); else verticalScrollBar()->triggerAction( QScrollBar::SliderPageStepSub ); } else if ( d->document->currentPage() > 0 ) { // more optimized than document->setPrevPage and then move view to bottom DocumentViewport newViewport = d->document->viewport(); newViewport.pageNumber -= viewColumns(); if ( newViewport.pageNumber < 0 ) newViewport.pageNumber = 0; newViewport.rePos.enabled = true; newViewport.rePos.normalizedY = 1.0; d->document->setViewport( newViewport ); } break; case Qt::Key_Down: case Qt::Key_PageDown: case Qt::Key_Space: // if in single page mode and at the bottom of the screen, go to next page if ( KpdfSettings::viewContinuous() || verticalScrollBar()->value() < verticalScrollBar()->maximum() ) { if ( e->key() == Qt::Key_Down ) verticalScrollBar()->triggerAction( QScrollBar::SliderSingleStepAdd ); else verticalScrollBar()->triggerAction( QScrollBar::SliderPageStepAdd ); } else if ( d->document->currentPage() < d->items.count() - 1 ) { // more optimized than document->setNextPage and then move view to top DocumentViewport newViewport = d->document->viewport(); newViewport.pageNumber += d->document->currentPage() ? viewColumns() : 1; if ( newViewport.pageNumber >= (int)d->items.count() ) newViewport.pageNumber = d->items.count() - 1; newViewport.rePos.enabled = true; newViewport.rePos.normalizedY = 0.0; d->document->setViewport( newViewport ); } break; case Qt::Key_Left: horizontalScrollBar()->triggerAction( QScrollBar::SliderSingleStepSub ); break; case Qt::Key_Right: horizontalScrollBar()->triggerAction( QScrollBar::SliderSingleStepAdd ); break; case Qt::Key_Shift: case Qt::Key_Control: if ( d->autoScrollTimer ) { if ( d->autoScrollTimer->isActive() ) d->autoScrollTimer->stop(); else slotAutoScoll(); return; } // else fall trhough default: e->ignore(); return; } // if a known key has been pressed, stop scrolling the page if ( d->autoScrollTimer ) { d->scrollIncrement = 0; d->autoScrollTimer->stop(); }}}void PageView::inputMethodEvent( QInputMethodEvent * e ){ if( d->typeAheadActive ) { if( !e->commitString().isEmpty() ) { d->typeAheadString += e->commitString(); doTypeAheadSearch(); e->accept(); } }}void PageView::contentsMouseMoveEvent( QMouseEvent * e ){if (d->document->handleEvent( e ) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -