diff options
Diffstat (limited to 'kpdf/ui/pageview.cpp')
-rw-r--r-- | kpdf/ui/pageview.cpp | 138 |
1 files changed, 87 insertions, 51 deletions
diff --git a/kpdf/ui/pageview.cpp b/kpdf/ui/pageview.cpp index 58c46101..57f201a0 100644 --- a/kpdf/ui/pageview.cpp +++ b/kpdf/ui/pageview.cpp @@ -2,7 +2,7 @@ * Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> * * Copyright (C) 2004-2006 by Albert Astals Cid <tsdgeos@terra.es> * * * - * With portions of code from kpdf/kpdf_pagewidget.cc by: * + * With portions of code from kpdf/kpdf_pagewidget.cpp by: * * Copyright (C) 2002 by Wilco Greven <greven@kde.org> * * Copyright (C) 2003 by Christophe Devriese * * <Christophe.Devriese@student.kuleuven.ac.be> * @@ -114,6 +114,7 @@ public: TDEToggleAction * aZoomFitText; TDEToggleAction * aViewTwoPages; TDEToggleAction * aViewContinuous; + TDEToggleAction * aViewCoverPage; TDEAction * aPrevAction; }; @@ -206,7 +207,7 @@ PageView::PageView( TQWidget *parent, KPDFDocument *document ) // widget setup: setup focus, accept drops and track mouse viewport()->setFocusProxy( this ); - viewport()->setFocusPolicy( TQ_StrongFocus ); + viewport()->setFocusPolicy( TQWidget::StrongFocus ); //viewport()->setPaletteBackgroundColor( TQt::white ); viewport()->setBackgroundMode( TQt::NoBackground ); setResizePolicy( Manual ); @@ -215,8 +216,8 @@ PageView::PageView( TQWidget *parent, KPDFDocument *document ) viewport()->setMouseTracking( true ); // conntect the padding of the viewport to pixmaps requests - connect( this, TQT_SIGNAL(contentsMoving(int, int)), this, TQT_SLOT(slotRequestVisiblePixmaps(int, int)) ); - connect( &d->dragScrollTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotDragScroll()) ); + connect( this, TQ_SIGNAL(contentsMoving(int, int)), this, TQ_SLOT(slotRequestVisiblePixmaps(int, int)) ); + connect( &d->dragScrollTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(slotDragScroll()) ); // set a corner button to resize the view to the page size // TQPushButton * resizeButton = new TQPushButton( viewport() ); @@ -227,7 +228,7 @@ PageView::PageView( TQWidget *parent, KPDFDocument *document ) setInputMethodEnabled( true ); // schedule the welcome message - TQTimer::singleShot( 0, this, TQT_SLOT( slotShowWelcome() ) ); + TQTimer::singleShot( 0, this, TQ_SLOT( slotShowWelcome() ) ); } PageView::~PageView() @@ -245,63 +246,68 @@ PageView::~PageView() void PageView::setupActions( TDEActionCollection * ac ) { // Zoom actions ( higher scales takes lots of memory! ) - d->aZoom = new TDESelectAction( i18n( "Zoom" ), "viewmag", 0, TQT_TQOBJECT(this), TQT_SLOT( slotZoom() ), ac, "zoom_to" ); + d->aZoom = new TDESelectAction( i18n( "Zoom" ), "viewmag", 0, this, TQ_SLOT( slotZoom() ), ac, "zoom_to" ); d->aZoom->setEditable( true ); #if KDE_IS_VERSION(3,4,89) d->aZoom->setMaxComboViewCount( 13 ); #endif updateZoomText(); - KStdAction::zoomIn( TQT_TQOBJECT(this), TQT_SLOT( slotZoomIn() ), ac, "zoom_in" ); + KStdAction::zoomIn( this, TQ_SLOT( slotZoomIn() ), ac, "zoom_in" ); - KStdAction::zoomOut( TQT_TQOBJECT(this), TQT_SLOT( slotZoomOut() ), ac, "zoom_out" ); + KStdAction::zoomOut( this, TQ_SLOT( slotZoomOut() ), ac, "zoom_out" ); d->aZoomFitWidth = new TDEToggleAction( i18n("Fit to Page &Width"), "view_fit_width", 0, ac, "zoom_fit_width" ); - connect( d->aZoomFitWidth, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( slotFitToWidthToggled( bool ) ) ); + connect( d->aZoomFitWidth, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( slotFitToWidthToggled( bool ) ) ); d->aZoomFitPage = new TDEToggleAction( i18n("Fit to &Page"), "view_fit_window", 0, ac, "zoom_fit_page" ); - connect( d->aZoomFitPage, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( slotFitToPageToggled( bool ) ) ); + connect( d->aZoomFitPage, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( slotFitToPageToggled( bool ) ) ); d->aZoomFitText = new TDEToggleAction( i18n("Fit to &Text"), "zoom-fit-best", 0, ac, "zoom_fit_text" ); - connect( d->aZoomFitText, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( slotFitToTextToggled( bool ) ) ); + connect( d->aZoomFitText, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( slotFitToTextToggled( bool ) ) ); // rotate actions TDEAction *action; action = new TDEAction( i18n("Rotate Right"), "object-rotate-right", TDEShortcut( "Ctrl+Shift++" ), - TQT_TQOBJECT(this), TQT_SLOT( slotRotateRight() ), ac, "rotate_right" ); + this, TQ_SLOT( slotRotateRight() ), ac, "rotate_right" ); action = new TDEAction( i18n("Rotate Left"), "object-rotate-left", TDEShortcut( "Ctrl+Shift+-" ), - TQT_TQOBJECT(this), TQT_SLOT( slotRotateLeft() ), ac, "rotate_left" ); + this, TQ_SLOT( slotRotateLeft() ), ac, "rotate_left" ); // View-Layout actions d->aViewTwoPages = new TDEToggleAction( i18n("&Two Pages"), "view_left_right", 0, ac, "view_twopages" ); - connect( d->aViewTwoPages, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( slotTwoPagesToggled( bool ) ) ); + connect( d->aViewTwoPages, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( slotTwoPagesToggled( bool ) ) ); d->aViewTwoPages->setChecked( KpdfSettings::viewColumns() > 1 ); d->aViewContinuous = new TDEToggleAction( i18n("&Continuous"), "view_text", 0, ac, "view_continuous" ); - connect( d->aViewContinuous, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( slotContinuousToggled( bool ) ) ); + connect( d->aViewContinuous, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( slotContinuousToggled( bool ) ) ); d->aViewContinuous->setChecked( KpdfSettings::viewContinuous() ); + d->aViewCoverPage = new TDEToggleAction( i18n("Co&ver Page"), "contents2", 0, ac, "view_coverpage" ); + connect( d->aViewCoverPage, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( slotCoverPageToggled( bool ) ) ); + d->aViewCoverPage->setChecked( KpdfSettings::viewCoverPage() ); + d->aViewCoverPage->setEnabled( KpdfSettings::viewColumns() > 1 ); + // Mouse-Mode actions - d->aMouseNormal = new TDERadioAction( i18n("&Browse Tool"), "input-mouse", 0, TQT_TQOBJECT(this), TQT_SLOT( slotSetMouseNormal() ), ac, "mouse_drag" ); + d->aMouseNormal = new TDERadioAction( i18n("&Browse Tool"), "input-mouse", 0, this, TQ_SLOT( slotSetMouseNormal() ), ac, "mouse_drag" ); d->aMouseNormal->setExclusiveGroup( "MouseType" ); d->aMouseNormal->setChecked( true ); - TDEToggleAction * mz = new TDERadioAction( i18n("&Zoom Tool"), "viewmag", 0, TQT_TQOBJECT(this), TQT_SLOT( slotSetMouseZoom() ), ac, "mouse_zoom" ); + TDEToggleAction * mz = new TDERadioAction( i18n("&Zoom Tool"), "viewmag", 0, this, TQ_SLOT( slotSetMouseZoom() ), ac, "mouse_zoom" ); mz->setExclusiveGroup( "MouseType" ); - d->aMouseSelect = new TDERadioAction( i18n("&Select Tool"), "frame_edit", 0, TQT_TQOBJECT(this), TQT_SLOT( slotSetMouseSelect() ), ac, "mouse_select" ); + d->aMouseSelect = new TDERadioAction( i18n("&Select Tool"), "frame_edit", 0, this, TQ_SLOT( slotSetMouseSelect() ), ac, "mouse_select" ); d->aMouseSelect->setExclusiveGroup( "MouseType" ); -/* d->aMouseEdit = new TDERadioAction( i18n("Draw"), "edit", 0, TQT_TQOBJECT(this), TQT_SLOT( slotSetMouseDraw() ), ac, "mouse_draw" ); +/* d->aMouseEdit = new TDERadioAction( i18n("Draw"), "edit", 0, this, TQ_SLOT( slotSetMouseDraw() ), ac, "mouse_draw" ); d->aMouseEdit->setExclusiveGroup("MouseType"); d->aMouseEdit->setEnabled( false ); // implement feature before removing this line*/ // Other actions - TDEAction * su = new TDEAction( i18n("Scroll Up"), 0, TQT_TQOBJECT(this), TQT_SLOT( slotScrollUp() ), ac, "view_scroll_up" ); + TDEAction * su = new TDEAction( i18n("Scroll Up"), 0, this, TQ_SLOT( slotScrollUp() ), ac, "view_scroll_up" ); su->setShortcut( "Shift+Up" ); - TDEAction * sd = new TDEAction( i18n("Scroll Down"), 0, TQT_TQOBJECT(this), TQT_SLOT( slotScrollDown() ), ac, "view_scroll_down" ); + TDEAction * sd = new TDEAction( i18n("Scroll Down"), 0, this, TQ_SLOT( slotScrollDown() ), ac, "view_scroll_down" ); sd->setShortcut( "Shift+Down" ); } @@ -348,7 +354,7 @@ void PageView::notifySetup( const TQValueVector< KPDFPage * > & pageSet, bool do // Need slotRelayoutPages() here instead of d->dirtyLayout = true // because opening a pdf from another pdf will not trigger a viewportchange // so pages are never relayouted - TQTimer::singleShot(0, this, TQT_SLOT(slotRelayoutPages())); + TQTimer::singleShot(0, this, TQ_SLOT(slotRelayoutPages())); else { // update the mouse cursor when closing because we may have close through a link and @@ -431,8 +437,8 @@ void PageView::notifyViewportChanged( bool smoothMove ) if ( !d->viewportMoveTimer ) { d->viewportMoveTimer = new TQTimer( this ); - connect( d->viewportMoveTimer, TQT_SIGNAL( timeout() ), - this, TQT_SLOT( slotMoveViewport() ) ); + connect( d->viewportMoveTimer, TQ_SIGNAL( timeout() ), + this, TQ_SLOT( slotMoveViewport() ) ); } d->viewportMoveTimer->start( 25 ); verticalScrollBar()->setEnabled( false ); @@ -637,7 +643,7 @@ void PageView::viewportResizeEvent( TQResizeEvent * ) if ( !d->delayResizeTimer ) { d->delayResizeTimer = new TQTimer( this ); - connect( d->delayResizeTimer, TQT_SIGNAL( timeout() ), this, TQT_SLOT( slotRelayoutPages() ) ); + connect( d->delayResizeTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotRelayoutPages() ) ); } d->delayResizeTimer->start( 333, true ); } @@ -719,7 +725,7 @@ void PageView::keyPressEvent( TQKeyEvent * e ) { // create the timer on demand d->findTimeoutTimer = new TQTimer( this ); - connect( d->findTimeoutTimer, TQT_SIGNAL( timeout() ), this, TQT_SLOT( findAheadStop() ) ); + connect( d->findTimeoutTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( findAheadStop() ) ); } d->findTimeoutTimer->start( 3000, true ); // it is needed to grab the keyboard becase people may have Space assigned to a @@ -840,7 +846,7 @@ void PageView::contentsMouseMoveEvent( TQMouseEvent * e ) return; // if holding mouse mid button, perform zoom - if ( (e->state() & Qt::MidButton) && d->mouseMidStartY >= 0 ) + if ( (e->state() & TQt::MidButton) && d->mouseMidStartY >= 0 ) { int deltaY = d->mouseMidStartY - e->globalPos().y(); d->mouseMidStartY = e->globalPos().y(); @@ -851,8 +857,8 @@ void PageView::contentsMouseMoveEvent( TQMouseEvent * e ) return; } - bool leftButton = e->state() & Qt::LeftButton, - rightButton = e->state() & Qt::RightButton; + bool leftButton = e->state() & TQt::LeftButton, + rightButton = e->state() & TQt::RightButton; switch ( d->mouseMode ) { case MouseNormal: @@ -920,7 +926,7 @@ void PageView::contentsMousePressEvent( TQMouseEvent * e ) } // if pressing mid mouse button while not doing other things, begin 'comtinous zoom' mode - if ( e->button() & Qt::MidButton ) + if ( e->button() & TQt::MidButton ) { d->mouseMidStartY = e->globalPos().y(); setCursor( KCursor::sizeVerCursor() ); @@ -931,8 +937,8 @@ void PageView::contentsMousePressEvent( TQMouseEvent * e ) d->mousePressPos = e->globalPos(); // handle mode dependant mouse press actions - bool leftButton = e->button() & Qt::LeftButton, - rightButton = e->button() & Qt::RightButton; + bool leftButton = e->button() & TQt::LeftButton, + rightButton = e->button() & TQt::RightButton; switch ( d->mouseMode ) { case MouseNormal: // drag start / click / link following @@ -973,7 +979,7 @@ void PageView::contentsMouseReleaseEvent( TQMouseEvent * e ) if ( d->items.isEmpty() ) { // ..except for right Clicks (emitted even it viewport is empty) - if ( e->button() == Qt::RightButton ) + if ( e->button() == TQt::RightButton ) emit rightClick( 0, e->globalPos() ); return; } @@ -983,7 +989,7 @@ void PageView::contentsMouseReleaseEvent( TQMouseEvent * e ) return; // handle mode indepent mid buttom zoom - bool midButton = e->button() & Qt::MidButton; + bool midButton = e->button() & TQt::MidButton; if ( midButton && d->mouseMidStartY > 0 ) { d->mouseMidStartY = -1; @@ -992,8 +998,8 @@ void PageView::contentsMouseReleaseEvent( TQMouseEvent * e ) return; } - bool leftButton = e->button() & Qt::LeftButton, - rightButton = e->button() & Qt::RightButton; + bool leftButton = e->button() & TQt::LeftButton, + rightButton = e->button() & TQt::RightButton; switch ( d->mouseMode ) { case MouseNormal:{ @@ -1056,8 +1062,8 @@ void PageView::contentsMouseReleaseEvent( TQMouseEvent * e ) double nX = (double)(selRect.left() + selRect.right()) / (2.0 * (double)contentsWidth()); double nY = (double)(selRect.top() + selRect.bottom()) / (2.0 * (double)contentsHeight()); - // zoom up to 400% - if ( d->zoomFactor <= 4.0 || zoom <= 1.0 ) + // zoom up to 800% + if ( d->zoomFactor <= 8.0 || zoom <= 1.0 ) { d->zoomFactor *= zoom; viewport()->setUpdatesEnabled( false ); @@ -1537,8 +1543,8 @@ void PageView::updateZoom( ZoomMode newZoomMode ) d->zoomFactor = -1; break; } - if ( newFactor > 4.0 ) - newFactor = 4.0; + if ( newFactor > 8.0 ) + newFactor = 8.0; if ( newFactor < 0.1 ) newFactor = 0.1; @@ -1582,13 +1588,13 @@ void PageView::updateZoomText() // add percent items TQString double_oh( "00" ); - const float zoomValue[10] = { 0.125, 0.25, 0.333, 0.5, 0.667, 0.75, 1, 1.25, 1.50, 2 }; + const float zoomValue[11] = { 0.125, 0.25, 0.333, 0.5, 0.667, 0.75, 1, 1.25, 1.50, 2, 4 }; int idx = 0, selIdx = 2; // use 3 if "fit text" present bool inserted = false; //use: "d->zoomMode != ZoomFixed" to hide Fit/* zoom ratio - while ( idx < 10 || !inserted ) + while ( idx < 11 || !inserted ) { - float value = idx < 10 ? zoomValue[ idx ] : newFactor; + float value = idx < 11 ? zoomValue[ idx ] : newFactor; if ( !inserted && newFactor < (value - 0.0001) ) value = newFactor; else @@ -1652,6 +1658,7 @@ void PageView::doTypeAheadSearch() void PageView::slotRelayoutPages() // called by: notifySetup, viewportResizeEvent, slotTwoPagesToggled, slotContinuousToggled, updateZoom { + bool coverPageMode = ( KpdfSettings::viewColumns() == 2 && KpdfSettings::viewCoverPage() ); // set an empty container if we have no pages int pageCount = d->items.count(); if ( pageCount < 1 ) @@ -1682,11 +1689,12 @@ void PageView::slotRelayoutPages() { // Here we find out column's width and row's height to compute a table // so we can place widgets 'centered in virtual cells'. - int nCols = KpdfSettings::viewColumns(), - nRows = (int)ceil( (float)pageCount / (float)nCols ), + int pageShift = coverPageMode ? 1 : 0, + nCols = KpdfSettings::viewColumns(), + nRows = (int)ceil( (float)(pageCount + pageShift) / (float)nCols ), * colWidth = new int[ nCols ], * rowHeight = new int[ nRows ], - cIdx = 0, + cIdx = pageShift, rIdx = 0; for ( int i = 0; i < nCols; i++ ) colWidth[ i ] = viewportWidth / nCols; @@ -1716,13 +1724,18 @@ void PageView::slotRelayoutPages() // 2) arrange widgets inside cells int insertX = 0, insertY = 4; // 2 + 4*d->zoomFactor ? - cIdx = 0; + cIdx = pageShift; rIdx = 0; + for ( iIt = d->items.begin(); iIt != iEnd; ++iIt ) { PageViewItem * item = *iIt; int cWidth = colWidth[ cIdx ], rHeight = rowHeight[ rIdx ]; + + if( coverPageMode && item->pageNumber() == 0 ) // align widget right inside viewport + insertX+=cWidth; + // center widget inside 'cells' item->moveTo( insertX + (cWidth - item->width()) / 2, insertY + (rHeight - item->height()) / 2 ); @@ -1776,14 +1789,24 @@ void PageView::slotRelayoutPages() // 2) hide all widgets except the displayable ones and dispose those int insertX = 0; cIdx = 0; + + if( coverPageMode && (int)d->document->currentPage() == 0 ) + ++cIdx; + for ( iIt = d->items.begin(); iIt != iEnd; ++iIt ) { PageViewItem * item = *iIt; if ( item == currentItem || (cIdx > 0 && cIdx < nCols) ) { - // center widget inside 'cells' - item->moveTo( insertX + (colWidth[ cIdx ] - item->width()) / 2, - (fullHeight - item->height()) / 2 ); + if( KpdfSettings::viewCoverPage() && (int)d->document->currentPage() == 0 ) { + // center widget inside viewport + item->moveTo( insertX + (viewportWidth - item->width()) / 2, + (viewportHeight - item->height()) / 2 ); + } else { + // center widget inside 'cells' + item->moveTo( insertX + (colWidth[ cIdx ] - item->width()) / 2, + (fullHeight - item->height()) / 2 ); + } // advance col index insertX += colWidth[ cIdx ]; cIdx++; @@ -1981,7 +2004,7 @@ void PageView::slotAutoScoll() if ( !d->autoScrollTimer ) { d->autoScrollTimer = new TQTimer( this ); - connect( d->autoScrollTimer, TQT_SIGNAL( timeout() ), this, TQT_SLOT( slotAutoScoll() ) ); + connect( d->autoScrollTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotAutoScoll() ) ); } // if scrollIncrement is zero, stop the timer @@ -2110,6 +2133,8 @@ void PageView::slotTwoPagesToggled( bool on ) if ( d->document->pages() > 0 ) slotRelayoutPages(); } + + d->aViewCoverPage->setEnabled( on ); } void PageView::slotContinuousToggled( bool on ) @@ -2123,6 +2148,17 @@ void PageView::slotContinuousToggled( bool on ) } } +void PageView::slotCoverPageToggled( bool on ) +{ + if ( KpdfSettings::viewCoverPage() != on ) + { + KpdfSettings::setViewCoverPage( on ); + KpdfSettings::writeConfig(); + if ( d->document->pages() > 0 ) + slotRelayoutPages(); + } +} + void PageView::slotSetMouseNormal() { d->mouseMode = MouseNormal; |