Commit 1eafe4fe authored by Saheb Preet Singh's avatar Saheb Preet Singh Committed by Albert Astals Cid

New shortcut to resize window to fit page

FIXED-IN: KDE Applications 15.08
BUGS: 326844
REVIEW: 115283
parent 3f9f02a9
......@@ -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">
......
......@@ -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()
{
......
......@@ -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);
......
......@@ -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; */
......@@ -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();
......
......@@ -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"
......
......@@ -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
......
......@@ -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 );
......
......@@ -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 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment