Commit d066fb00 authored by Elvis Stansvik's avatar Elvis Stansvik Committed by Albert Astals Cid

Remember collapse state of sidebar when file is auto-reloaded

BUGS: 289010
REVIEW: 103517
parent cdc1b0c7
......@@ -1213,7 +1213,7 @@ bool Part::openFile()
}
// if the 'OpenTOC' flag is set, open the TOC
if ( m_document->metaData( "OpenTOC" ).toBool() && m_sidebar->isItemEnabled( 0 ) )
if ( m_document->metaData( "OpenTOC" ).toBool() && m_sidebar->isItemEnabled( 0 ) && !m_sidebar->isCollapsed() )
{
const bool sidebarVisible = m_sidebar->isSidebarVisible();
m_sidebar->setCurrentIndex( 0 );
......@@ -1449,6 +1449,7 @@ void Part::slotDoFileDirty()
// store the current toolbox pane
m_dirtyToolboxIndex = m_sidebar->currentIndex();
m_wasSidebarVisible = m_sidebar->isSidebarVisible();
m_wasSidebarCollapsed = m_sidebar->isCollapsed();
// store if presentation view was open
m_wasPresentationOpen = ((PresentationWidget*)m_presentationWidget != 0);
......@@ -1469,7 +1470,8 @@ void Part::slotDoFileDirty()
m_document->setViewport( m_viewportDirty );
m_viewportDirty.pageNumber = -1;
m_document->setRotation( m_dirtyPageRotation );
if ( m_sidebar->currentIndex() != m_dirtyToolboxIndex && m_sidebar->isItemEnabled( m_dirtyToolboxIndex ) )
if ( m_sidebar->currentIndex() != m_dirtyToolboxIndex && m_sidebar->isItemEnabled( m_dirtyToolboxIndex )
&& !m_sidebar->isCollapsed() )
{
m_sidebar->setCurrentIndex( m_dirtyToolboxIndex );
}
......@@ -1477,6 +1479,10 @@ void Part::slotDoFileDirty()
{
m_sidebar->setSidebarVisibility( m_wasSidebarVisible );
}
if ( m_sidebar->isCollapsed() != m_wasSidebarCollapsed )
{
m_sidebar->setCollapsed( m_wasSidebarCollapsed );
}
if (m_wasPresentationOpen) slotShowPresentation();
emit enablePrintAction(true && m_document->printingSupport() != Okular::Document::NoPrinting);
}
......
......@@ -253,6 +253,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
bool m_wasPresentationOpen;
int m_dirtyToolboxIndex;
bool m_wasSidebarVisible;
bool m_wasSidebarCollapsed;
bool m_fileWasRemoved;
Rotation m_dirtyPageRotation;
......
......@@ -469,12 +469,12 @@ Sidebar::Sidebar( QWidget *parent )
d->stack = new QStackedWidget( d->sideContainer );
d->vlay->addWidget( d->stack );
d->sideContainer->hide();
connect( d->list, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(listContextMenu(QPoint)) );
connect( d->splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(splitterMoved(int,int)) );
setCollapsed( true );
setFocusProxy( d->list );
}
......@@ -592,18 +592,18 @@ void Sidebar::setSidebarVisibility( bool visible )
if ( visible != d->list->isHidden() )
return;
static bool sideWasVisible = !d->sideContainer->isHidden();
static bool wasCollapsed = isCollapsed();
d->list->setHidden( !visible );
if ( visible )
{
d->sideContainer->setHidden( !sideWasVisible );
sideWasVisible = true;
setCollapsed( wasCollapsed );
wasCollapsed = false;
}
else
{
sideWasVisible = !d->sideContainer->isHidden();
d->sideContainer->setHidden( true );
wasCollapsed = isCollapsed();
setCollapsed( true );
}
}
......@@ -612,6 +612,16 @@ bool Sidebar::isSidebarVisible() const
return !d->list->isHidden();
}
void Sidebar::setCollapsed( bool collapsed )
{
d->sideContainer->setHidden( collapsed );
}
bool Sidebar::isCollapsed() const
{
return d->sideContainer->isHidden();
}
void Sidebar::itemClicked( QListWidgetItem *item )
{
if ( !item )
......@@ -623,22 +633,22 @@ void Sidebar::itemClicked( QListWidgetItem *item )
if ( sbItem->widget() == d->stack->currentWidget() )
{
if ( d->sideContainer->isVisible() )
if ( !isCollapsed() )
{
d->list->selectionModel()->clear();
d->sideContainer->hide();
setCollapsed( true );
}
else
{
d->sideContainer->show();
setCollapsed( false );
d->list->show();
}
}
else
{
if ( d->sideContainer->isHidden() )
if ( isCollapsed() )
{
d->sideContainer->show();
setCollapsed( false );
d->list->show();
}
d->stack->setCurrentWidget( sbItem->widget() );
......
......@@ -36,6 +36,9 @@ class Sidebar : public QWidget
void setSidebarVisibility( bool visible );
bool isSidebarVisible() const;
void setCollapsed( bool collapsed );
bool isCollapsed() const;
private slots:
void itemClicked( QListWidgetItem *item );
void splitterMoved( int pos, int index );
......
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