Commit bd25d17e authored by Felix Mauch's avatar Felix Mauch Committed by Oliver Sander

Save view information per file

Adds the functionality to save the view mode (single page, facing...),
continuous scrolling, and margin trimming  to the document information,
as it is already done with the zoom information.
parent 26c0a606
......@@ -697,6 +697,45 @@ void DocumentPrivate::loadViewsInfo( View *view, const QDomElement &e )
view->setCapability( View::ZoomModality, newmode );
}
}
else if ( viewElement.tagName() == "viewMode" )
{
const QString modeString = viewElement.attribute( "mode" );
bool newmode_ok = true;
const int newmode = !modeString.isEmpty() ? modeString.toInt( &newmode_ok ) : 2;
if ( newmode_ok
&& view->supportsCapability( View::ViewModeModality )
&& ( view->capabilityFlags( View::ViewModeModality )
& ( View::CapabilityRead | View::CapabilitySerializable ) ) )
{
view->setCapability( View::ViewModeModality, newmode );
}
}
else if ( viewElement.tagName() == "continuous" )
{
const QString modeString = viewElement.attribute( "mode" );
bool newmode_ok = true;
const int newmode = !modeString.isEmpty() ? modeString.toInt( &newmode_ok ) : 2;
if ( newmode_ok
&& view->supportsCapability( View::Continuous )
&& ( view->capabilityFlags( View::Continuous )
& ( View::CapabilityRead | View::CapabilitySerializable ) ) )
{
view->setCapability( View::Continuous, newmode );
}
}
else if ( viewElement.tagName() == "trimMargins" )
{
const QString valueString = viewElement.attribute( "value" );
bool newmode_ok = true;
const int newmode = !valueString.isEmpty() ? valueString.toInt( &newmode_ok ) : 2;
if ( newmode_ok
&& view->supportsCapability( View::TrimMargins )
&& ( view->capabilityFlags( View::TrimMargins )
& ( View::CapabilityRead | View::CapabilitySerializable ) ) )
{
view->setCapability( View::TrimMargins, newmode );
}
}
viewNode = viewNode.nextSibling();
}
......@@ -723,6 +762,37 @@ void DocumentPrivate::saveViewsInfo( View *view, QDomElement &e ) const
zoomEl.setAttribute( QStringLiteral("mode"), mode );
}
}
if ( view->supportsCapability( View::Continuous )
&& ( view->capabilityFlags( View::Continuous )
& ( View::CapabilityRead | View::CapabilitySerializable ) ) )
{
QDomElement contEl = e.ownerDocument().createElement( "continuous" );
e.appendChild( contEl );
const bool mode = view->capability( View::Continuous ).toBool();
contEl.setAttribute( "mode", mode );
}
if ( view->supportsCapability( View::ViewModeModality )
&& ( view->capabilityFlags( View::ViewModeModality )
& ( View::CapabilityRead | View::CapabilitySerializable ) ) )
{
QDomElement viewEl = e.ownerDocument().createElement( "viewMode" );
e.appendChild( viewEl );
bool ok = true;
const int mode = view->capability( View::ViewModeModality ).toInt( &ok );
if ( ok )
{
viewEl.setAttribute( "mode", mode );
}
}
if ( view->supportsCapability( View::TrimMargins )
&& ( view->capabilityFlags( View::TrimMargins )
& ( View::CapabilityRead | View::CapabilitySerializable ) ) )
{
QDomElement contEl = e.ownerDocument().createElement( "trimMargins" );
e.appendChild( contEl );
const bool value = view->capability( View::TrimMargins ).toBool();
contEl.setAttribute( "value", value );
}
}
QUrl DocumentPrivate::giveAbsoluteUrl( const QString & fileName ) const
......
......@@ -43,7 +43,10 @@ class OKULARCORE_EXPORT View
enum ViewCapability
{
Zoom, ///< Possibility to get/set the zoom of the view
ZoomModality ///< Possibility to get/set the zoom mode of the view
ZoomModality, ///< Possibility to get/set the zoom mode of the view
Continuous, ///< Possibility to toggle continuous mode
ViewModeModality, ///< Possibility to get/set the view mode
TrimMargins ///< Possibility to toggle trim-margins mode
};
/**
......
......@@ -1539,6 +1539,9 @@ bool PageView::supportsCapability( ViewCapability capability ) const
{
case Zoom:
case ZoomModality:
case Continuous:
case ViewModeModality:
case TrimMargins:
return true;
}
return false;
......@@ -1550,6 +1553,9 @@ Okular::View::CapabilityFlags PageView::capabilityFlags( ViewCapability capabili
{
case Zoom:
case ZoomModality:
case Continuous:
case ViewModeModality:
case TrimMargins:
return CapabilityRead | CapabilityWrite | CapabilitySerializable;
}
return nullptr;
......@@ -1563,6 +1569,20 @@ QVariant PageView::capability( ViewCapability capability ) const
return d->zoomFactor;
case ZoomModality:
return d->zoomMode;
case Continuous:
return d->aViewContinuous->isChecked();
case ViewModeModality:
{
for (int i=0; i < d->aViewMode->menu()->actions().size(); ++i)
{
const QAction* action = d->aViewMode->menu()->actions().at(i);
if ( action->isChecked() )
return action->data();
}
return QVariant();
}
case TrimMargins:
return d->aTrimMargins->isChecked();
}
return QVariant();
}
......@@ -1593,6 +1613,31 @@ void PageView::setCapability( ViewCapability capability, const QVariant &option
}
break;
}
case ViewModeModality:
{
bool ok = true;
int mode = option.toInt( &ok );
if ( ok )
{
if ( mode >= 0 && mode < Okular::Settings::EnumViewMode::COUNT)
updateViewMode(mode);
}
break;
}
case Continuous:
{
bool mode = option.toBool( );
d->aViewContinuous->setChecked(mode);
slotContinuousToggled(mode);
break;
}
case TrimMargins:
{
bool value = option.toBool( );
d->aTrimMargins->setChecked(value);
slotTrimMarginsToggled(value);
break;
}
}
}
......@@ -4177,6 +4222,17 @@ void PageView::updateZoomText()
d->aZoom->selectableActionGroup()->setEnabled( d->items.size() > 0 );
}
void PageView::updateViewMode(const int nr)
{
for (int i=0; i < d->aViewMode->menu()->actions().size(); ++i) {
const QAction* action = d->aViewMode->menu()->actions().at(i);
QVariant mode_id = action->data();
if (mode_id.toInt() == nr) {
d->aViewMode->menu()->actions().at( i )->trigger();
}
}
}
void PageView::updateCursor()
{
const QPoint p = contentAreaPosition() + viewport()->mapFromGlobal( QCursor::pos() );
......
......@@ -180,6 +180,8 @@ Q_OBJECT
void updateZoom( ZoomMode newZm );
// update the text on the label using global zoom value or current page's one
void updateZoomText();
// update view mode (single, facing...)
void updateViewMode ( const int nr );
void textSelectionClear();
// updates cursor
void updateCursor( const QPoint &p );
......
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