Commit a4cccdb4 authored by Enrico Ros's avatar Enrico Ros
Browse files

Removed saveSettings and use in place "Settings::setVariable(..)" instead.

(way more consistant) Removed duplicate values. Apply settings in Part's
slotNewConfig() on the fly.

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=358760
parent 69166fa9
......@@ -47,12 +47,14 @@
<entry key="SplitterSizes" type="IntList" />
</group>
<group name="PageView" >
<entry key="ViewTwoPages" type="Bool" >
<default>false</default>
</entry>
<entry key="ViewContinous" type="Bool" >
<default>true</default>
</entry>
<entry key="ViewColumns" type="UInt" >
<default>1</default>
<min>1</min>
<max>8</max>
</entry>
</group>
<group name="Performance" >
<entry key="MemoryLevel" type="Enum" >
......
......@@ -125,10 +125,6 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
iIdx = m_toolBox->addItem( editFrame, QIconSet(SmallIcon("pencil")), i18n("Annotations") );
m_toolBox->setItemEnabled( iIdx, false );
QFrame * moreFrame = new QFrame( m_toolBox );
iIdx = m_toolBox->addItem( moreFrame, QIconSet(SmallIcon("fork")), i18n("More stuff..") );
m_toolBox->setItemEnabled( iIdx, false );
// widgets: [] | [right 'pageView']
m_pageView = new PageView( m_splitter, document );
connect( m_pageView, SIGNAL( urlDropped( const KURL& ) ), SLOT( openURL( const KURL & )));
......@@ -171,17 +167,12 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
KStdAction::preferences( this, SLOT( slotPreferences() ), ac, "preferences" );
KStdAction::printPreview( this, SLOT( slotPrintPreview() ), ac );
KToggleAction * sLp = new KToggleAction( i18n( "Show &Left Panel" ), 0, ac, "show_leftpanel" );
sLp->setCheckedState(i18n("Hide &Left Panel"));
connect( sLp, SIGNAL( toggled( bool ) ), SLOT( slotToggleLeftPanel( bool ) ) );
// attach the actions of the 2 children widgets too
m_pageView->setupActions( ac );
// local settings
// apply configuration (both internal settings and GUI configured items)
m_splitter->setSizes( Settings::splitterSizes() );
sLp->setChecked( Settings::showLeftPanel() );
slotToggleLeftPanel( sLp->isChecked() );
slotNewConfig();
// set our XML-UI resource file
setXMLFile("kpdf_part.rc");
......@@ -190,12 +181,9 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
Part::~Part()
{
// save local settings
// save internal settings
Settings::setSplitterSizes( m_splitter->sizes() );
Settings::setShowLeftPanel( m_toolBox->isShown() );
// save settings of internal widgets
m_pageView->saveSettings();
// save config file
// write to disk config file
Settings::writeConfig();
delete document;
......@@ -372,20 +360,40 @@ void Part::slotPreferences()
return;
// we didn't find an instance of this dialog, so lets create it
PreferencesDialog * dialog = new PreferencesDialog( 0, Settings::self() );
PreferencesDialog * dialog = new PreferencesDialog( m_pageView, Settings::self() );
// keep us informed when the user changes settings
connect( dialog, SIGNAL( settingsChanged() ),
this, SLOT( slotNewConfig() ) );
connect( dialog, SIGNAL( settingsChanged() ), this, SLOT( slotNewConfig() ) );
dialog->show();
}
void Part::slotNewConfig()
{
// apply runtime changes TODO apply changes here
if ( Settings::showSearchBar() != m_searchWidget->isShown() )
m_searchWidget->setShown( Settings::showSearchBar() );
// Apply settings here. A good policy is to check wether the setting has
// changed before applying changes.
// Left Panel and search Widget
bool showLeft = Settings::showLeftPanel();
if ( m_toolBox->isShown() != showLeft )
{
// show/hide left qtoolbox
m_toolBox->setShown( showLeft );
// this needs to be hidden explicitly to disable thumbnails gen
m_thumbnailList->setShown( showLeft );
}
bool showSearch = Settings::showSearchBar();
if ( m_searchWidget->isShown() != showSearch )
m_searchWidget->setShown( showSearch );
// Main View
QScrollView::ScrollBarMode scrollBarMode = Settings::showScrollBars() ?
QScrollView::AlwaysOn : QScrollView::AlwaysOff;
if ( m_pageView->hScrollBarMode() != scrollBarMode )
{
m_pageView->setHScrollBarMode( scrollBarMode );
m_pageView->setVScrollBarMode( scrollBarMode );
}
}
void Part::slotPrintPreview()
......@@ -420,14 +428,6 @@ void Part::slotPrintPreview()
*/
}
void Part::slotToggleLeftPanel( bool on )
{
// show/hide left qtoolbox
m_toolBox->setShown( on );
// this needs to be hidden explicitly to disable thumbnails gen
m_thumbnailList->setShown( on );
}
void Part::slotPrint()
{
/*
......
......@@ -89,7 +89,6 @@ protected slots:
void slotPreferences();
void slotNewConfig();
void slotPrintPreview();
void slotToggleLeftPanel( bool );
// can be connected to widget elements
void updateActions();
void enableTOC(bool enable);
......
......@@ -49,9 +49,7 @@ public:
QValueVector< PageWidget * > pages;
int vectorIndex;
// view layout, zoom and mouse
int viewColumns;
bool viewContinous;
// view layout (columns and continous in Settings), zoom and mouse
PageView::ZoomMode zoomMode;
float zoomFactor;
PageView::MouseMode mouseMode;
......@@ -99,8 +97,6 @@ PageView::PageView( QWidget *parent, KPDFDocument *document )
d->document = document;
d->page = 0;
d->vectorIndex = -1;
d->viewColumns = 1;
d->viewContinous = false;
d->zoomMode = ZoomFixed;
d->zoomFactor = 1.0;
d->mouseMode = MouseNormal;
......@@ -168,13 +164,11 @@ void PageView::setupActions( KActionCollection * ac )
// View-Layout actions
d->aViewTwoPages = new KToggleAction( i18n("Two Pages"), "view_left_right", 0, ac, "view_twopages" );
connect( d->aViewTwoPages, SIGNAL( toggled( bool ) ), SLOT( slotTwoPagesToggled( bool ) ) );
d->aViewTwoPages->setChecked( Settings::viewTwoPages() );
slotTwoPagesToggled( d->aViewTwoPages->isChecked() );
d->aViewTwoPages->setChecked( Settings::viewColumns() > 1 );
d->aViewContinous = new KToggleAction( i18n("Continous"), "view_text", 0, ac, "view_continous" );
connect( d->aViewContinous, SIGNAL( toggled( bool ) ), SLOT( slotContinousToggled( bool ) ) );
d->aViewContinous->setChecked( Settings::viewContinous() );
slotContinousToggled( d->aViewContinous->isChecked() );
// Mouse-Mode actions
KToggleAction * mn = new KRadioAction( i18n("Normal"), "mouse", 0, this, SLOT( slotSetMouseNormal() ), ac, "mouse_drag" );
......@@ -195,20 +189,6 @@ void PageView::setupActions( KActionCollection * ac )
KAction * sd = new KAction( i18n("Scroll Down"), 0, this, SLOT( slotScrollDown() ), ac, "view_scroll_down" );
sd->setShortcut( "Shift+Down" );
KToggleAction * ss = new KToggleAction( i18n( "Show &Scrollbars" ), 0, ac, "show_scrollbars" );
ss->setCheckedState(i18n("Hide &Scrollbars"));
connect( ss, SIGNAL( toggled( bool ) ), SLOT( slotToggleScrollBars( bool ) ) );
ss->setChecked( Settings::showScrollBars() );
slotToggleScrollBars( ss->isChecked() );
}
void PageView::saveSettings()
{
Settings::setShowScrollBars( hScrollBarMode() == AlwaysOn );
Settings::setViewTwoPages( d->aViewTwoPages->isChecked() );
Settings::setViewContinous( d->aViewContinous->isChecked() );
}
......@@ -266,7 +246,7 @@ void PageView::pageSetCurrent( int pageNumber, const QRect & /*viewport*/ )
return;
// relayout in "Single Pages" mode or if a relayout is pending
if ( !d->viewContinous || d->dirtyLayout )
if ( !Settings::viewContinous() || d->dirtyLayout )
slotRelayoutPages();
// center the view to see the selected page
......@@ -556,13 +536,13 @@ void PageView::keyPressEvent( QKeyEvent * e )
switch ( e->key() )
{
case Key_Up:
if ( atTop() && !d->viewContinous )
if ( atTop() && !Settings::viewContinous() )
scrollUp();
else
verticalScrollBar()->subtractLine();
break;
case Key_Down:
if ( atBottom() && !d->viewContinous )
if ( atBottom() && !Settings::viewContinous() )
scrollDown();
else
verticalScrollBar()->addLine();
......@@ -611,9 +591,9 @@ void PageView::wheelEvent( QWheelEvent *e )
else
slotZoomIn();
}
else if ( delta <= -120 && atBottom() && !d->viewContinous )
else if ( delta <= -120 && atBottom() && !Settings::viewContinous() )
scrollDown();
else if ( delta >= 120 && atTop() && !d->viewContinous )
else if ( delta >= 120 && atTop() && !Settings::viewContinous() )
scrollUp();
else
QScrollView::wheelEvent( e );
......@@ -682,20 +662,22 @@ void PageView::slotFitToRectToggled( bool on )
void PageView::slotTwoPagesToggled( bool on )
{
int newColumns = on ? 2 : 1;
if ( d->viewColumns != newColumns )
uint newColumns = on ? 2 : 1;
if ( Settings::viewColumns() != newColumns )
{
d->viewColumns = newColumns;
slotRelayoutPages();
Settings::setViewColumns( newColumns );
if ( d->document->pages() > 0 )
slotRelayoutPages();
}
}
void PageView::slotContinousToggled( bool on )
{
if ( d->viewContinous != on )
if ( Settings::viewContinous() != on )
{
d->viewContinous = on;
slotRelayoutPages();
Settings::setViewContinous( on );
if ( d->document->pages() > 0 )
slotRelayoutPages();
}
}
......@@ -731,12 +713,6 @@ void PageView::slotScrollDown()
slotAutoScoll();
}
void PageView::slotToggleScrollBars( bool on )
{
setHScrollBarMode( on ? AlwaysOn : AlwaysOff );
setVScrollBarMode( on ? AlwaysOn : AlwaysOff );
}
void PageView::slotRelayoutPages()
// called by: pageSetup, viewportResizeEvent, slotTwoPagesToggled, slotContinousToggled, updateZoom
{
......@@ -753,11 +729,11 @@ void PageView::slotRelayoutPages()
fullWidth = 0,
fullHeight = 0;
if ( d->viewContinous == TRUE )
if ( Settings::viewContinous() )
{
// 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 = d->viewColumns,
int nCols = Settings::viewColumns(),
nRows = (int)ceilf( (float)pageCount / (float)nCols ),
* colWidth = new int[ nCols ],
* rowHeight = new int[ nRows ],
......@@ -836,7 +812,7 @@ void PageView::slotRelayoutPages()
PageWidget * currentPage = d->page ? d->page : d->pages[0];
// setup varialbles for a 1(row) x N(columns) grid
int nCols = d->viewColumns,
int nCols = Settings::viewColumns(),
* colWidth = new int[ nCols ],
cIdx = 0;
fullHeight = viewportHeight;
......
......@@ -51,7 +51,6 @@ public:
// create actions that interact with this widget
void setupActions( KActionCollection * collection );
void saveSettings();
// inherited from KPDFDocumentObserver
uint observerId() const { return PAGEVIEW_ID; }
......@@ -91,7 +90,6 @@ private slots:
void slotSetMouseDraw();
void slotScrollUp();
void slotScrollDown();
void slotToggleScrollBars( bool on );
// activated either directly or via QTimer on the viewportResizeEvent
void slotRelayoutPages();
......
......@@ -52,9 +52,6 @@ SearchWidget::SearchWidget( QWidget * parent, KPDFDocument * document )
int sideLength = m_lineEdit->sizeHint().height();
m_clearButton->setMinimumSize( QSize( sideLength, sideLength ) );
// search->setMinimumSize( QSize( sideLength, sideLength ) );
// handle initial visiblity
setShown( Settings::showSearchBar() );
}
void SearchWidget::hideEvent( QHideEvent * )
......
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