Commit a16881fe authored by Thorsten Zachmann's avatar Thorsten Zachmann

o Added actions for inserting/deleting a page

svn path=/trunk/koffice/; revision=696717
parent 2528f0be
......@@ -410,6 +410,8 @@ void KoPADocument::insertPage( KoPAPageBase* page, KoPAPageBase* after )
}
pages.insert( index, page );
// move active view to new page
}
int KoPADocument::takePage( KoPAPageBase *page )
......@@ -420,8 +422,22 @@ int KoPADocument::takePage( KoPAPageBase *page )
int index = pages.indexOf( page );
// it should not be possible to delete the last page
Q_ASSERT( pages.size() > 1 );
if ( index != -1 ) {
pages.removeAt( index );
// change to previous page when the page is the active one if the first one is delete go to the next one
int newIndex = index == 0 ? 0 : index - 1;
KoPAPageBase * newActivePage = pages.at( newIndex );
foreach( KoView *view, views() )
{
KoPAView * kopaView = static_cast<KoPAView*>( view );
if ( page == kopaView->activePage() ) {
kopaView->setActivePage( newActivePage );
}
}
}
return index;
}
......
......@@ -46,6 +46,8 @@
#include "KoPAPage.h"
#include "KoPAMasterPage.h"
#include "KoPAViewModeNormal.h"
#include "commands/KoPAPageInsertCommand.h"
#include "commands/KoPAPageDeleteCommand.h"
#include <klocale.h>
#include <kicon.h>
......@@ -163,6 +165,18 @@ void KoPAView::initActions()
m_viewRulers->setToolTip(i18n("Show/hide the view's rulers"));
connect(m_viewRulers, SIGNAL(triggered(bool)), this, SLOT(setShowRulers(bool)));
setShowRulers(true);
m_actionInsertPage = new KAction( i18n( "Insert Page" ), this );
actionCollection()->addAction( "edit_insertpage", m_actionInsertPage );
m_actionInsertPage->setToolTip( i18n( "Insert a new page after the current one" ) );
m_actionInsertPage->setWhatsThis( i18n( "Insert a new page after the current one" ) );
connect( m_actionInsertPage, SIGNAL( triggered() ), this, SLOT( insertPage() ) );
m_actionDeletePage = new KAction( i18n( "Delete Page" ), this );
actionCollection()->addAction( "edit_deletepage", m_actionDeletePage );
m_actionDeletePage->setToolTip( i18n( "Delete a new page after the current one" ) );
m_actionDeletePage->setWhatsThis( i18n( "Delete a new page after the current one" ) );
connect( m_actionDeletePage, SIGNAL( triggered() ), this, SLOT( deletePage() ) );
}
void KoPAView::viewSnapToGrid()
......@@ -312,4 +326,27 @@ void KoPAView::setShowRulers(bool show)
m_viewRulers->setChecked(show);
}
void KoPAView::insertPage()
{
KoPAPageBase * page = 0;
if ( m_viewMode->masterMode() ) {
page = m_doc->newMasterPage();
}
else {
KoPAPage * activePage = dynamic_cast<KoPAPage*>( m_activePage );
KoPAMasterPage * masterPage = activePage->masterPage();
page = m_doc->newPage( masterPage );
}
KoPAPageInsertCommand * command = new KoPAPageInsertCommand( m_doc, page, m_activePage );
m_canvas->addCommand( command );
}
void KoPAView::deletePage()
{
KoPAPageDeleteCommand * command = new KoPAPageDeleteCommand( m_doc, m_activePage );
m_canvas->addCommand( command );
}
#include "KoPAView.moc"
......@@ -115,6 +115,12 @@ protected slots:
/// Called when the selection changed
virtual void selectionChanged();
/// Insert a new page after the current one
void insertPage();
/// Delete the current page
void deletePage();
protected:
KoPADocument *m_doc;
KoPACanvas *m_canvas;
......@@ -130,13 +136,14 @@ private:
KToggleAction *m_actionViewShowGrid;
KToggleAction *m_actionViewShowMasterPages;
KAction * m_actionInsertPage;
KAction * m_actionDeletePage;
KoRuler *m_horizontalRuler;
KoRuler *m_verticalRuler;
KToggleAction* m_viewRulers;
KoZoomAction *m_zoomAction;
KAction *m_actionFormatFont;
};
#endif /* KOPAVIEW_H */
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