[kde-doc-english] [okular] /: New shortcut to resize window to fit page

Albert Astals Cid aacid at kde.org
Mon Mar 16 23:21:06 UTC 2015


Git commit 1eafe4feb151c713e8f7747164348c25886480bf by Albert Astals Cid, on behalf of Saheb Preet Singh.
Committed on 16/03/2015 at 23:20.
Pushed by aacid into branch 'master'.

New shortcut to resize window to fit page

FIXED-IN: KDE Applications 15.08
BUGS: 326844
REVIEW: 115283

M  +10   -0    doc/index.docbook
M  +6    -0    part.cpp
M  +3    -0    part.h
M  +11   -0    shell/shell.cpp
M  +5    -0    shell/shell.h
M  +41   -2    ui/pageview.cpp
M  +2    -0    ui/pageview.h
M  +9    -0    ui/sidebar.cpp
M  +2    -0    ui/sidebar.h

http://commits.kde.org/okular/1eafe4feb151c713e8f7747164348c25886480bf

diff --git a/doc/index.docbook b/doc/index.docbook
index 3237849..38fb7b9 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -949,6 +949,16 @@ Context menu actions like Rename Bookmarks etc.)
 			</variablelist>
 		    </sect2>
 		</sect1>
+		<sect1 id="fit-window-to-page">
+			<title>Fit window to page</title>
+			<para>
+			    The Fit window to page feature resizes the window so that it is exactly the same size as the page at the current zoom factor.
+			    If the page doesn't completely fit on the screen, the window is enlarged so that the largest possible part of the page is shown.
+			</para>
+			<para>
+			    This feature can be accessed by using the keyboard shortcut <keycombo action="simul">&Ctrl;<keycap>J</keycap></keycombo>
+			</para>
+		</sect1>
 	</chapter>
 
 	<chapter id="primary-menu-items">
diff --git a/part.cpp b/part.cpp
index fbeda1e..5b03e56 100644
--- a/part.cpp
+++ b/part.cpp
@@ -455,6 +455,7 @@ m_cliPresentation(false), m_cliPrint(false), m_embedMode(detectEmbedMode(parentW
     connect( m_document, SIGNAL(warning(QString,int)), this, SLOT(warningMessage(QString,int)) );
     connect( m_document, SIGNAL(notice(QString,int)), this, SLOT(noticeMessage(QString,int)) );
     connect( m_document, SIGNAL(sourceReferenceActivated(const QString&,int,int,bool*)), this, SLOT(slotHandleActivatedSourceReference(const QString&,int,int,bool*)) );
+    connect( m_pageView, SIGNAL(fitWindowToPage(QSize,QSize)), this, SIGNAL(fitWindowToPage(QSize,QSize)) );
     rightLayout->addWidget( m_pageView );
     m_findBar = new FindBar( m_document, rightContainer );
     rightLayout->addWidget( m_findBar );
@@ -2806,6 +2807,11 @@ void Part::noticeMessage( const QString &message, int duration )
     m_pageView->displayMessage( message, QString(), PageViewMessage::Info, duration );
 }
 
+void Part::moveSplitter(int sideWidgetSize)
+{
+    m_sidebar->moveSplitter( sideWidgetSize );
+}
+
 
 void Part::unsetDummyMode()
 {
diff --git a/part.h b/part.h
index 65ccac6..9eebdb2 100644
--- a/part.h
+++ b/part.h
@@ -159,6 +159,7 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
         void enableCloseAction(bool enable);
         void mimeTypeChanged(KMimeType::Ptr mimeType);
         void urlsDropped( const KUrl::List& urls );
+        void fitWindowToPage( const QSize& pageViewPortSize, const QSize& pageSize );
 
     protected:
         // reimplemented from KParts::ReadWritePart
@@ -231,6 +232,8 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
         void warningMessage( const QString &message, int duration = -1 );
         void noticeMessage( const QString &message, int duration = -1 );
 
+        void moveSplitter( const int sideWidgetSize );
+
     private:
         Document::OpenResult doOpenFile(const KMimeType::Ptr &mime, const QString &fileNameToOpen, bool *isCompressedFile);
 
diff --git a/shell/shell.cpp b/shell/shell.cpp
index 364d53a..7355968 100644
--- a/shell/shell.cpp
+++ b/shell/shell.cpp
@@ -565,10 +565,12 @@ void Shell::applyOptionsToPart( QObject* part, const QString &serializedOptions
 
 void Shell::connectPart( QObject* part )
 {
+    connect( this, SIGNAL(moveSplitter(int)), part, SLOT(moveSplitter(int)) );
     connect( part, SIGNAL(enablePrintAction(bool)), this, SLOT(setPrintEnabled(bool)));
     connect( part, SIGNAL(enableCloseAction(bool)), this, SLOT(setCloseEnabled(bool)));
     connect( part, SIGNAL(mimeTypeChanged(KMimeType::Ptr)), this, SLOT(setTabIcon(KMimeType::Ptr)));
     connect( part, SIGNAL(urlsDropped(KUrl::List)), this, SLOT(handleDroppedUrls(KUrl::List)) );
+    connect( part, SIGNAL(fitWindowToPage(QSize,QSize)), this, SLOT(slotFitWindowToPage(QSize,QSize)) );
 }
 
 void Shell::print()
@@ -665,4 +667,13 @@ void Shell::moveTabData( int from, int to )
    m_tabs.move( from, to );
 }
 
+void Shell::slotFitWindowToPage(const QSize& pageViewSize, const QSize& pageSize )
+{
+    const int xOffset = pageViewSize.width() - pageSize.width();
+    const int yOffset = pageViewSize.height() - pageSize.height();
+    showNormal();
+    resize( width() - xOffset, height() - yOffset);
+    moveSplitter(pageSize.width());
+}
+
 /* kate: replace-tabs on; indent-width 4; */
diff --git a/shell/shell.h b/shell/shell.h
index 3eaed1d..fea80ac 100644
--- a/shell/shell.h
+++ b/shell/shell.h
@@ -121,6 +121,11 @@ private slots:
   void testTabDrop( const QDragMoveEvent* event, bool& accept );
   void handleTabDrop( QDropEvent* event );
   void moveTabData( int from, int to );
+  
+  void slotFitWindowToPage( const QSize& pageViewSize, const QSize& pageSize );
+  
+signals:
+  void moveSplitter(int sideWidgetSize);
 
 private:
   void setupAccel();
diff --git a/ui/pageview.cpp b/ui/pageview.cpp
index 1631d93..49d6f8a 100644
--- a/ui/pageview.cpp
+++ b/ui/pageview.cpp
@@ -215,6 +215,7 @@ public:
     KAction * aSpeakStop;
     KActionCollection * actionCollection;
     QActionGroup * mouseModeActionGroup;
+    KAction * aFitWindowToPage;
 
     int setting_viewCols;
 
@@ -491,6 +492,12 @@ void PageView::setupViewerActions( KActionCollection * ac )
     ac->addAction("view_auto_fit", d->aZoomAutoFit );
     connect( d->aZoomAutoFit, SIGNAL(toggled(bool)), SLOT(slotAutoFitToggled(bool)) );
 
+    d->aFitWindowToPage = new KAction(KIcon( "zoom-fit-width" ), i18n("Fit Wi&ndow to Page"), this);
+    d->aFitWindowToPage->setEnabled( Okular::Settings::viewMode() == (int)Okular::Settings::EnumViewMode::Single );
+    d->aFitWindowToPage->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_J) );
+    ac->addAction( "fit_window_to_page", d->aFitWindowToPage );
+    connect( d->aFitWindowToPage, SIGNAL(triggered()), this, SLOT(slotFitWindowToPage()) );
+
     // View-Layout actions
     d->aViewMode = new KActionMenu( KIcon( "view-split-left-right" ), i18n( "&View Mode" ), this );
     d->aViewMode->setDelayed( false );
@@ -1077,6 +1084,8 @@ void PageView::updateActionState( bool haspages, bool documentChanged, bool hasf
     }
     if (d->aMouseMagnifier)
         d->aMouseMagnifier->setEnabled(d->document->supportsTiles());
+    if ( d->aFitWindowToPage )
+        d->aFitWindowToPage->setEnabled( haspages && !Okular::Settings::viewContinuous() );
 }
 
 bool PageView::areSourceLocationsShownGraphically() const
@@ -4012,8 +4021,15 @@ void PageView::toggleFormWidgets( bool on )
 void PageView::resizeContentArea( const QSize & newSize )
 {
     const QSize vs = viewport()->size();
-    horizontalScrollBar()->setRange( 0, newSize.width() - vs.width() );
-    verticalScrollBar()->setRange( 0, newSize.height() - vs.height() );
+    int hRange = newSize.width() - vs.width();
+    int vRange = newSize.height() - vs.height();
+    if ( horizontalScrollBar()->isVisible() && hRange == verticalScrollBar()->width() && verticalScrollBar()->isVisible() && vRange == horizontalScrollBar()->height() && Okular::Settings::showScrollBars() )
+    {
+        hRange = 0;
+        vRange = 0;
+    }
+    horizontalScrollBar()->setRange( 0, hRange );
+    verticalScrollBar()->setRange( 0, vRange );
     updatePageStep();
 }
 
@@ -4118,6 +4134,9 @@ void PageView::slotRelayoutPages()
     const bool centerLastPage = centerFirstPage && pageCount % 2 == 0;
     const bool continuousView = Okular::Settings::viewContinuous();
     const int nCols = overrideCentering ? 1 : viewColumns();
+    const bool singlePageViewMode = Okular::Settings::viewMode() == Okular::Settings::EnumViewMode::Single;
+
+    d->aFitWindowToPage->setEnabled( !continuousView && singlePageViewMode );
 
     // set all items geometry and resize contents. handle 'continuous' and 'single' modes separately
 
@@ -5062,6 +5081,26 @@ void PageView::slotToggleChangeColors()
     viewport()->update();
 }
 
+void PageView::slotFitWindowToPage()
+{
+    PageViewItem currentPageItem = NULL;
+    QSize viewportSize = viewport()->size();
+    foreach ( const PageViewItem * pageItem, d->items )
+    {
+        if ( pageItem->isVisible() )
+        {
+            currentPageItem = *pageItem;
+            break;
+        }
+    }
+    const QSize pageSize = QSize( currentPageItem.uncroppedWidth() + kcolWidthMargin, currentPageItem.uncroppedHeight() + krowHeightMargin );
+    if ( verticalScrollBar()->isVisible() )
+        viewportSize.setWidth( viewportSize.width() + verticalScrollBar()->width() );
+    if ( horizontalScrollBar()->isVisible() )
+        viewportSize.setHeight( viewportSize.height() + horizontalScrollBar()->height() );
+    emit fitWindowToPage( viewportSize, pageSize );
+}
+
 //END private SLOTS
 
 #include "pageview.moc"
diff --git a/ui/pageview.h b/ui/pageview.h
index a8adb2c..e65b575 100644
--- a/ui/pageview.h
+++ b/ui/pageview.h
@@ -124,6 +124,7 @@ Q_OBJECT
         void mouseBackButtonClick();
         void mouseForwardButtonClick();
         void escPressed();
+        void fitWindowToPage( const QSize& pageViewPortSize, const QSize& pageSize );
 
     protected:
         void resizeEvent( QResizeEvent* );
@@ -249,6 +250,7 @@ Q_OBJECT
         void slotProcessMovieAction( const Okular::MovieAction *action );
         void slotProcessRenditionAction( const Okular::RenditionAction *action );
         void slotToggleChangeColors();
+        void slotFitWindowToPage();
 };
 
 #endif
diff --git a/ui/sidebar.cpp b/ui/sidebar.cpp
index 0c722a9..9e51a1b 100644
--- a/ui/sidebar.cpp
+++ b/ui/sidebar.cpp
@@ -644,6 +644,15 @@ bool Sidebar::isCollapsed() const
     return d->sideContainer->isHidden();
 }
 
+void Sidebar::moveSplitter(int sideWidgetSize)
+{
+    QList<int> splitterSizeList = d->splitter->sizes();
+    const int total = splitterSizeList.at( 0 ) + splitterSizeList.at( 1 );
+    splitterSizeList.replace( 0, total - sideWidgetSize );
+    splitterSizeList.replace( 1, sideWidgetSize );
+    d->splitter->setSizes( splitterSizeList );
+}
+
 void Sidebar::itemClicked( QListWidgetItem *item )
 {
     itemClicked( item, UncollapseIfCollapsed );
diff --git a/ui/sidebar.h b/ui/sidebar.h
index cf5dfc6..2630166 100644
--- a/ui/sidebar.h
+++ b/ui/sidebar.h
@@ -42,6 +42,8 @@ class Sidebar : public QWidget
         void setCollapsed( bool collapsed );
         bool isCollapsed() const;
 
+	void moveSplitter( int sideWidgetSize );
+
     signals:
         void urlsDropped( const KUrl::List& urls );
 


More information about the kde-doc-english mailing list