[kde-doc-english] [calligra] /: Stage: New UI for Create/Edit Custom Slide Shows
Paul Mendez
paulestebanms at gmail.com
Fri Jul 22 21:55:17 CEST 2011
Git commit f911dad2a9ea3159defc8cb3fa96679eae59213f by Paul Mendez.
Committed on 22/07/2011 at 21:51.
Pushed by mendez into branch 'master'.
Stage: New UI for Create/Edit Custom Slide Shows
Integrate new UI for manage/create custom slide shows in Slides Sorter View
Several visual improvements to slides sorter view.
Add undo/redo command for delete slides from custom shows.
Add unit tests for new commands.
REVIEW: 101820
GUI: New UI for manage/create custom slide shows on Stage
M +66 -13 kpresenter/part/KPrViewModeSlidesSorter.h
M +7 -3 kpresenter/part/CMakeLists.txt
M +7 -0 libs/kopageapp/KoPADocument.cpp
M +1 -1 libs/kopageapp/KoPADocumentStructureDocker.cpp
M +4 -1 kpresenter/part/ui/KPrConfigureSlideShowDialog.h
M +120 -44 kpresenter/part/KPrSlidesSorterDocumentModel.cpp
M +31 -0 kpresenter/part/tests/CMakeLists.txt
M +7 -30 kpresenter/part/ui/KPrConfigureSlideShowDialog.cpp
M +1 -1 kpresenter/part/KPrDocument.h
M +3 -1 kpresenter/part/KPrAnimationDirector.cpp
M +8 -2 kpresenter/part/KPrView.h
D +0 -46 kpresenter/part/commands/KPrSetCustomSlideShowsCommand.h
M +4 -9 kpresenter/part/KPrDocument.cpp
D +0 -56 kpresenter/part/commands/KPrSetCustomSlideShowsCommand.cpp
M +51 -29 kpresenter/part/KPrSlidesManagerView.cpp
D +0 -66 kpresenter/part/ui/KPrCustomSlideShowsDialog.h
M +13 -17 kpresenter/part/KPrView.cpp
D +0 -301 kpresenter/part/ui/KPrCustomSlideShowsDialog.cpp
M +355 -116 kpresenter/part/KPrViewModeSlidesSorter.cpp
M +30 -1 kpresenter/part/KPrCustomSlideShows.cpp
M +14 -6 kpresenter/part/KPrSlidesManagerView.h
M +2 -1 kpresenter/part/KPrViewModePresentation.cpp
D +0 -223 kpresenter/part/ui/KPrCustomSlideShowsDialog.ui
M +48 -0 kpresenter/part/KPrSlidesSorterDocumentModel.h
M +37 -3 kpresenter/part/KPrCustomSlideShows.h
M +9 -0 libs/kopageapp/KoPADocument.h
http://commits.kde.org/calligra/f911dad2a9ea3159defc8cb3fa96679eae59213f
diff --git a/kpresenter/part/CMakeLists.txt b/kpresenter/part/CMakeLists.txt
index 613ff8d..6a2142f 100644
--- a/kpresenter/part/CMakeLists.txt
+++ b/kpresenter/part/CMakeLists.txt
@@ -71,11 +71,17 @@ set( calligrastageprivate_LIB_SRCS
KPrSlidesManagerView.cpp
KPrSelectionManager.cpp
KPrSelectionToggle.cpp
+ KPrCustomSlideShowsModel.cpp
+ KPrSlidesSorterItemDelegate.cpp
commands/KPrAnimationCreateCommand.cpp
commands/KPrPageEffectSetCommand.cpp
commands/KPrPageLayoutCommand.cpp
- commands/KPrSetCustomSlideShowsCommand.cpp
+ commands/KPrEditCustomSlideShowsCommand.cpp
+ commands/KPrAddCustomSlideShowCommand.cpp
+ commands/KPrDelCustomSlideShowCommand.cpp
+ commands/KPrRenameCustomSlideShowCommand.cpp
+ commands/KPrDeleteSlidesCommand.cpp
dockers/KPrPreviewWidget.cpp
dockers/KPrPageLayoutDockerFactory.cpp
@@ -119,7 +125,6 @@ set( calligrastageprivate_LIB_SRCS
pagelayout/KPrPageLayoutSharedSavingData.cpp
pagelayout/KPrPlaceholders.cpp
- ui/KPrCustomSlideShowsDialog.cpp
ui/KPrConfigureSlideShowDialog.cpp
ui/KPrConfigurePresenterViewDialog.cpp
ui/KPrPresentationToolWidget.cpp
@@ -130,7 +135,6 @@ set( calligrastageprivate_LIB_SRCS
)
kde4_add_ui_files(calligrastageprivate_LIB_SRCS
- ui/KPrCustomSlideShowsDialog.ui
ui/KPrConfigureSlideShow.ui
ui/KPrConfigurePresenterView.ui
ui/KPrPresentationTool.ui
diff --git a/kpresenter/part/KPrAnimationDirector.cpp b/kpresenter/part/KPrAnimationDirector.cpp
index d9600e22..e731fa9 100644
--- a/kpresenter/part/KPrAnimationDirector.cpp
+++ b/kpresenter/part/KPrAnimationDirector.cpp
@@ -275,7 +275,9 @@ void KPrAnimationDirector::updateActivePage( KoPAPageBase * page )
KPrPage * kprPage = dynamic_cast<KPrPage *>( page );
Q_ASSERT( kprPage );
- m_pageIndex = m_pages.indexOf(page);
+ if (m_pageIndex > m_pages.size() || m_pageIndex < 0) {
+ m_pageIndex = m_pages.indexOf(page);
+ }
m_animations = kprPage->animations().steps();
// it can be that the pages have different sizes. So we need to recalulate
diff --git a/kpresenter/part/KPrCustomSlideShows.cpp b/kpresenter/part/KPrCustomSlideShows.cpp
index 632dda6..e23fd90 100644
--- a/kpresenter/part/KPrCustomSlideShows.cpp
+++ b/kpresenter/part/KPrCustomSlideShows.cpp
@@ -61,6 +61,7 @@ void KPrCustomSlideShows::update( const QString &name, const QList<KoPAPageBase*
Q_ASSERT( it != m_customSlideShows.constEnd() );
Q_UNUSED( it ); // only used in the above Q_ASSERT.
m_customSlideShows.insert( name, slideShow );
+ emit updated();
}
void KPrCustomSlideShows::rename( const QString &oldName, const QString &newName )
{
@@ -86,7 +87,20 @@ QList<KoPAPageBase*> KPrCustomSlideShows::getByName( const QString &name ) const
return it.value();
}
-void KPrCustomSlideShows::addSlideToAll( KoPAPageBase* page, unsigned int position )
+KoPAPageBase *KPrCustomSlideShows::pageByIndex(const QString &name, int index) const
+{
+ QList<KoPAPageBase*> pages = getByName(name);
+ return pages.value(index);
+}
+
+
+int KPrCustomSlideShows::indexByPage(const QString &name, KoPAPageBase *page) const
+{
+ QList<KoPAPageBase*> pages = getByName(name);
+ return pages.indexOf(page);
+}
+
+void KPrCustomSlideShows::addSlideToAll( KoPAPageBase *page, unsigned int position )
{
QMap< QString, QList<KoPAPageBase*> >::iterator it = m_customSlideShows.begin();
//FIXME: should we allow negative index?
@@ -96,6 +110,7 @@ void KPrCustomSlideShows::addSlideToAll( KoPAPageBase* page, unsigned int positi
it.value().insert( (position<=size)? position : size, page );
++it;
}
+ emit updated();
}
void KPrCustomSlideShows::addSlidesToAll( const QList<KoPAPageBase*> &slideShow, unsigned int position )
@@ -114,6 +129,7 @@ void KPrCustomSlideShows::removeSlideFromAll( KoPAPageBase* page )
it.value().removeAll( page );
++it;
}
+ emit updated();
}
void KPrCustomSlideShows::removeSlidesFromAll( const QList<KoPAPageBase*> &slideShow )
@@ -179,3 +195,16 @@ void KPrCustomSlideShows::loadOdf( const KoXmlElement & presentationSettings, Ko
}
}
}
+
+QStringList KPrCustomSlideShows::namesByPage(KoPAPageBase *page)
+{
+ QMap< QString, QList<KoPAPageBase*> >::iterator it = m_customSlideShows.begin();
+ QStringList names;
+ while(it != m_customSlideShows.end()) {
+ if (it.value().contains(page)) {
+ names.append(it.key());
+ }
+ ++it;
+ }
+ return names;
+}
diff --git a/kpresenter/part/KPrCustomSlideShows.h b/kpresenter/part/KPrCustomSlideShows.h
index 7d8a91b..e443049 100644
--- a/kpresenter/part/KPrCustomSlideShows.h
+++ b/kpresenter/part/KPrCustomSlideShows.h
@@ -24,6 +24,7 @@
#include<QMap>
#include<QList>
#include<QString>
+#include<QObject>
//Forward declarations
class KoXmlWriter;
@@ -35,8 +36,9 @@ class KPrDocument;
#include "stage_export.h"
-class STAGE_TEST_EXPORT KPrCustomSlideShows
+class STAGE_TEST_EXPORT KPrCustomSlideShows : public QObject
{
+ Q_OBJECT
public:
KPrCustomSlideShows();
~KPrCustomSlideShows();
@@ -88,6 +90,25 @@ public:
QList<KoPAPageBase*> getByName( const QString &name ) const;
/**
+ * @brief Return the object that match the give index in the list with the given name
+ *
+ * @param name the name of the custom SlideShow
+ / @param index the index of the slide to be retrived from the custom SlideShow
+ * @return a Page in the SlideShow if it was found or a null pointer if not.
+ */
+ KoPAPageBase* pageByIndex(const QString &name, int index) const;
+
+ /**
+ * @brief return the index of a page within a custom show
+ *
+ * @param name the name of the custom SlideShow
+ * @param page the KoPAPageBase within the custom SlideShow
+ * @return a int index of the page within the SlideShow if it was found
+ * -1 if the page was not found
+ */
+ int indexByPage(const QString &name, KoPAPageBase *page) const;
+
+ /**
* @brief Insert a slide to the right of the given position of all the known custom SlideShows.
* If the position is higher than the size of the list of the SlideShow, the slide is inserted at the end.
*
@@ -96,7 +117,7 @@ public:
* If it's 0 it will be prepended to the list, if it's the size it will be appended to the list.
* Negative numbers can be used to count backwards.
*/
- void addSlideToAll( KoPAPageBase* page, unsigned int position );
+ void addSlideToAll(KoPAPageBase *page, unsigned int position);
/**
* @brief Insert a list of slides to the right of the given position of all the known custom SlideShows.
@@ -112,7 +133,7 @@ public:
*
* @param slide slide to be removed
*/
- void removeSlideFromAll( KoPAPageBase* page );
+ void removeSlideFromAll(KoPAPageBase *page);
/**
* @brief Deletes all the ocurrencies of a given list of slides from all the known custom SlideShows
@@ -136,7 +157,20 @@ public:
*/
void loadOdf( const KoXmlElement & presentationSettings, KoPALoadingContext & context );
+ /**
+ * @brief Return the names of custom shows that contains the given page
+ *
+ * @param page the page to be searched in the custom shows
+ * @return a List of the Slide Show names that contains the page
+ * a blank list if the page was not found
+ */
+ QStringList namesByPage(KoPAPageBase *page);
+
+signals:
+ void updated();
+
private:
QMap< QString, QList<KoPAPageBase*> > m_customSlideShows;
+
};
#endif /* KPRCUSTOMSLIDESHOWS_H */
diff --git a/kpresenter/part/KPrDocument.cpp b/kpresenter/part/KPrDocument.cpp
index 02bf53c..841e86a 100644
--- a/kpresenter/part/KPrDocument.cpp
+++ b/kpresenter/part/KPrDocument.cpp
@@ -35,7 +35,7 @@
#include "KPrPageSelectStrategyActive.h"
#include "pagelayout/KPrPageLayouts.h"
#include "tools/KPrPlaceholderToolFactory.h"
-#include "commands/KPrSetCustomSlideShowsCommand.h"
+#include "commands/KPrDeleteSlidesCommand.h"
#include <KoPACanvas.h>
#include <KoPACanvasItem.h>
#include <KoPAViewModeNormal.h>
@@ -259,15 +259,10 @@ void KPrDocument::postRemoveShape( KoPAPageBase * page, KoShape * shape )
}
}
-void KPrDocument::pageRemoved( KoPAPageBase * page, KUndo2Command * parent )
+void KPrDocument::removePages(QList<KoPAPageBase *> &pages)
{
- // only normal pages can be part of a slide show
- if ( dynamic_cast<KPrPage *>( page ) ) {
- KPrCustomSlideShows * slideShows = new KPrCustomSlideShows( *customSlideShows() );
- slideShows->removeSlideFromAll( page );
- // maybe we should check if old and new are different and only than create the command
- new KPrSetCustomSlideShowsCommand( this, slideShows, parent );
- }
+ KPrDeleteSlidesCommand *command = new KPrDeleteSlidesCommand(this, pages);
+ addCommand(command);
}
void KPrDocument::loadKPrConfig()
diff --git a/kpresenter/part/KPrDocument.h b/kpresenter/part/KPrDocument.h
index 7756f5e..d32ad26 100644
--- a/kpresenter/part/KPrDocument.h
+++ b/kpresenter/part/KPrDocument.h
@@ -188,7 +188,7 @@ protected:
virtual void postRemoveShape( KoPAPageBase * page, KoShape * shape );
/// reimplemented
- virtual void pageRemoved( KoPAPageBase * page, KUndo2Command * parent );
+ virtual void removePages(QList<KoPAPageBase*> &pages);
/// load configuration specific to KPresenter
void loadKPrConfig();
diff --git a/kpresenter/part/KPrSlidesManagerView.cpp b/kpresenter/part/KPrSlidesManagerView.cpp
index 39e80b1..a406cda 100644
--- a/kpresenter/part/KPrSlidesManagerView.cpp
+++ b/kpresenter/part/KPrSlidesManagerView.cpp
@@ -24,18 +24,17 @@
#include <QtCore/qmath.h>
#include <QPaintEvent>
#include <QScrollBar>
+#include <QPainter>
+#include <QPen>
//Kde headers
#include <klocale.h>
#include <KIconLoader>
-//Calligra headers
-#include <KoToolProxy.h>
-
-KPrSlidesManagerView::KPrSlidesManagerView(KoToolProxy *toolProxy, QWidget *parent)
+KPrSlidesManagerView::KPrSlidesManagerView(QWidget *parent)
: QListView(parent)
, m_dragingFlag(false)
- , m_toolProxy(toolProxy)
+ , margin(23)
{
setViewMode(QListView::IconMode);
setFlow(QListView::LeftToRight);
@@ -44,6 +43,7 @@ KPrSlidesManagerView::KPrSlidesManagerView(KoToolProxy *toolProxy, QWidget *pare
setDragEnabled(true);
setAcceptDrops(true);
setDropIndicatorShown(true);
+ setSpacing(m_itemSize.width()/10);
viewport()->installEventFilter(this);
}
@@ -58,20 +58,21 @@ void KPrSlidesManagerView::paintEvent(QPaintEvent *event)
// Paint the line where the slide should go
if (isDraging()) {
-
- QSize size(itemSize().width(), itemSize().height());
-
+ QSize size(itemSize().width() + spacing(), itemSize().height() + spacing());
QPair <int, int> m_pair = cursorRowAndColumn();
int numberColumn = m_pair.first;
int numberRow = m_pair.second;
int scrollBarValue = verticalScrollBar()->value();
- QPoint point1(numberColumn * size.width(), numberRow * size.height() - scrollBarValue);
- QPoint point2(numberColumn * size.width(), (numberRow + 1) * size.height() - scrollBarValue);
-
+ QPoint point1(numberColumn * size.width() + spacing() / 2, numberRow * size.height() + spacing() - scrollBarValue);
+ QPoint point2(numberColumn * size.width() + spacing() / 2, (numberRow + 1) * size.height() - scrollBarValue);
QLineF line(point1, point2);
QPainter painter(this->viewport());
+ QPen pen = QPen(palette().brush(QPalette::Highlight), spacing() / 4);
+ pen.setCapStyle(Qt::RoundCap);
+ painter.setPen(pen);
+ painter.setOpacity(0.8);
painter.drawLine(line);
}
}
@@ -114,6 +115,10 @@ void KPrSlidesManagerView::dropEvent(QDropEvent *ev)
clearSelection();
+ if (!model()) {
+ return;
+ }
+
int newIndex = cursorSlideIndex();
if (newIndex >= model()->rowCount(QModelIndex())) {
@@ -126,16 +131,18 @@ void KPrSlidesManagerView::dropEvent(QDropEvent *ev)
void KPrSlidesManagerView::dragMoveEvent(QDragMoveEvent *ev)
{
ev->accept();
+ if (!model()) {
+ return;
+ }
+ QListView::dragMoveEvent(ev);
setDragingFlag();
viewport()->update();
}
void KPrSlidesManagerView::dragEnterEvent(QDragEnterEvent *event)
{
- if (event->mimeData()->hasFormat("application/x-calligra-sliderssorter")) {
- event->setDropAction(Qt::MoveAction);
- event->accept();
- }
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
}
void KPrSlidesManagerView::dragLeaveEvent(QDragLeaveEvent *e)
@@ -144,6 +151,18 @@ void KPrSlidesManagerView::dragLeaveEvent(QDragLeaveEvent *e)
setDragingFlag(false);
}
+void KPrSlidesManagerView::focusOutEvent(QFocusEvent *event)
+{
+ Q_UNUSED(event);
+ emit focusLost();
+}
+
+void KPrSlidesManagerView::focusInEvent(QFocusEvent *event)
+{
+ Q_UNUSED(event);
+ emit focusGot();
+}
+
void KPrSlidesManagerView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
if (!this->selectionModel()->selection().isEmpty()) {
@@ -163,6 +182,7 @@ QRect KPrSlidesManagerView::itemSize() const
void KPrSlidesManagerView::setItemSize(QRect size)
{
m_itemSize = size;
+ setSpacing(m_itemSize.width() / 10);
}
void KPrSlidesManagerView::setDragingFlag(bool flag)
@@ -177,7 +197,7 @@ bool KPrSlidesManagerView::isDraging() const
bool KPrSlidesManagerView::eventFilter(QObject *watched, QEvent *event)
{
- if (watched == viewport()) {
+ if (watched == viewport() && model()) {
switch (event->type()) {
case QEvent::MouseButtonPress: {
QModelIndex item = indexAt(QWidget::mapFromGlobal(QCursor::pos()));
@@ -193,12 +213,10 @@ bool KPrSlidesManagerView::eventFilter(QObject *watched, QEvent *event)
}
break;
}
-
default:
break;
}
}
-
return QObject::eventFilter(watched, event);
}
@@ -242,7 +260,7 @@ QPixmap KPrSlidesManagerView::createDragPixmap() const
QPainter painter(&dragPixmap);
int x = 0;
int y = 0;
- foreach (const QModelIndex& selectedIndex, selectedIndexes) {
+ foreach (const QModelIndex &selectedIndex, selectedIndexes) {
const QIcon icon = (model()->data(selectedIndex, Qt::DecorationRole)).value<QIcon>();
painter.drawPixmap(x, y, icon.pixmap(size, size));
@@ -262,22 +280,21 @@ QPixmap KPrSlidesManagerView::createDragPixmap() const
int KPrSlidesManagerView::cursorSlideIndex() const
{
QPair <int, int> m_pair = cursorRowAndColumn();
- int slidesNumber = qFloor((contentsRect().width() - 20) / itemSize().width());
+ int slidesNumber = qFloor((contentsRect().width() - (margin + spacing() - contentsMargins().right())) /
+ (itemSize().width() + spacing()));
return (m_pair.first + m_pair.second * slidesNumber);
}
QPair<int, int> KPrSlidesManagerView::cursorRowAndColumn() const
{
- //20 is for the margin.
- int slidesNumber = qFloor((contentsRect().width() - 20) / itemSize().width());
+ QSize size(itemSize().width() + spacing(), itemSize().height() + spacing());
+ int slidesNumber = qFloor((contentsRect().width() - (margin + spacing() - contentsMargins().right())) / size.width());
int scrollBarValue = verticalScrollBar()->value();
-
- QSize size(itemSize().width(), itemSize().height());
QPoint cursorPosition = QWidget::mapFromGlobal(QCursor::pos());
-
int numberColumn = qFloor(cursorPosition.x() / size.width());
int numberRow = qFloor((cursorPosition.y() + scrollBarValue) / size.height());
- int numberMod = (numberColumn + slidesNumber * numberRow) % (model()->rowCount(QModelIndex()) + 1);
+ int numberMod = model()->rowCount(QModelIndex()) > 0 ?
+ (numberColumn + slidesNumber * numberRow) % (model()->rowCount(QModelIndex())) : 0;
int totalRows = qCeil((model()->rowCount(QModelIndex())) / slidesNumber);
@@ -285,13 +302,18 @@ QPair<int, int> KPrSlidesManagerView::cursorRowAndColumn() const
numberColumn = slidesNumber;
}
- if (numberColumn > numberMod) {
- numberColumn = numberColumn - (numberMod + 1);
+ if ((numberColumn > numberMod) & (model()->rowCount(QModelIndex()) % slidesNumber != 0)) {
+ numberColumn = model()->rowCount(QModelIndex()) % slidesNumber;
+ }
+
+ if (model()->rowCount(QModelIndex()) % slidesNumber == 0) {
+ totalRows = totalRows - 1;
}
if (numberRow > totalRows) {
numberRow = totalRows;
- numberColumn = model()->rowCount(QModelIndex()) % slidesNumber;
+ numberColumn = model()->rowCount(QModelIndex()) % slidesNumber != 0 ?
+ model()->rowCount(QModelIndex()) % slidesNumber : slidesNumber;
}
return QPair<int,int>(numberColumn, numberRow);
diff --git a/kpresenter/part/KPrSlidesManagerView.h b/kpresenter/part/KPrSlidesManagerView.h
index 6f345e0..1e86f96 100644
--- a/kpresenter/part/KPrSlidesManagerView.h
+++ b/kpresenter/part/KPrSlidesManagerView.h
@@ -22,7 +22,6 @@
#define KPRSLIDESMANAGERVIEW_H
#include <QListView>
-class KoToolProxy;
/**
* Class meant to hold a List View of slides thumbnails
@@ -34,15 +33,14 @@ class KPrSlidesManagerView : public QListView
{
Q_OBJECT
public:
- explicit KPrSlidesManagerView(KoToolProxy *toolProxy, QWidget *parent = 0);
+ explicit KPrSlidesManagerView(QWidget *parent = 0);
~KPrSlidesManagerView();
virtual void paintEvent (QPaintEvent *event);
-
- //It emits a slideDblClick signal and then calls the parent
- //implementation
+ //It emits a slideDblClick signal and then calls the parent
+ //implementation
virtual void mouseDoubleClickEvent(QMouseEvent *event);
virtual void contextMenuEvent(QContextMenuEvent *event);
@@ -64,6 +62,10 @@ public:
//a suitable active item for the context menu.
virtual bool eventFilter(QObject *watched, QEvent *event);
+ void focusOutEvent(QFocusEvent *event);
+
+ void focusInEvent(QFocusEvent *event);
+
/**
* Setter of the size with a rect
*
@@ -107,6 +109,12 @@ signals:
/** Is emitted when an item is selected */
void itemSelected();
+ /** Is emitted when the view loses focus */
+ void focusLost();
+
+ /** Is emitted when the view get focus */
+ void focusGot();
+
private:
/**
@@ -132,7 +140,7 @@ private:
QRect m_itemSize;
bool m_dragingFlag;
- KoToolProxy *m_toolProxy;
+ int margin;
};
diff --git a/kpresenter/part/KPrSlidesSorterDocumentModel.cpp b/kpresenter/part/KPrSlidesSorterDocumentModel.cpp
index 4938e36..6073928 100644
--- a/kpresenter/part/KPrSlidesSorterDocumentModel.cpp
+++ b/kpresenter/part/KPrSlidesSorterDocumentModel.cpp
@@ -19,27 +19,29 @@
*/
#include "KPrSlidesSorterDocumentModel.h"
-
#include "KPrViewModeSlidesSorter.h"
+#include "KPrDocument.h"
//Calligra headers
#include <KoPADocument.h>
#include <KoPAPageBase.h>
#include <KoPAViewBase.h>
+#include <KoPAView.h>
#include <KoPAPage.h>
-#include <KoPAPageMoveCommand.h>
#include <KoPAOdfPageSaveHelper.h>
#include <KoDrag.h>
+#include <KoPAPageMoveCommand.h>
#include <KoShapeRenameCommand.h>
+#include <KoPAPageDeleteCommand.h>
+#include "commands/KPrDeleteSlidesCommand.h"
//KDE Headers
#include <KIcon>
//Qt Headers
#include <QMimeData>
-#include <QMenu>
#include <QApplication>
-
+#include <QMenu>
KPrSlidesSorterDocumentModel::KPrSlidesSorterDocumentModel(KPrViewModeSlidesSorter *viewModeSlidesSorter, QWidget *parent, KoPADocument *document)
: QAbstractListModel(parent)
@@ -81,20 +83,17 @@ QVariant KPrSlidesSorterDocumentModel::data(const QModelIndex &index, int role)
}
Q_ASSERT(index.model() == this);
-
- KoPAPageBase *page = m_document->pageByIndex(index.row(), false);
+ KoPAPageBase *page = pageByIndex(index);
switch (role) {
case Qt::DisplayRole:
{
QString name = i18n("Unknown");
- if (page)
- {
+ if (page) {
name = page->name();
- if (name.isEmpty())
- {
+ if (name.isEmpty()) {
//Default case
- name = i18n("Slide %1", m_document->pageIndex(page) + 1);
+ name = i18n("Slide %1", m_document->pageIndex(page) + 1);
}
}
return name;
@@ -114,7 +113,7 @@ QVariant KPrSlidesSorterDocumentModel::data(const QModelIndex &index, int role)
bool KPrSlidesSorterDocumentModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
- if(! index.isValid() || !m_document) {
+ if (!index.isValid() || !m_document) {
return false;
}
@@ -145,7 +144,6 @@ int KPrSlidesSorterDocumentModel::rowCount(const QModelIndex &parent) const
if (!m_document) {
return 0;
}
-
return m_document->pages(false).count();
}
@@ -157,7 +155,7 @@ QStringList KPrSlidesSorterDocumentModel::mimeTypes() const
QMimeData * KPrSlidesSorterDocumentModel::mimeData(const QModelIndexList &indexes) const
{
// check if there is data to encode
- if (! indexes.count()) {
+ if (!indexes.count()) {
return 0;
}
@@ -174,8 +172,17 @@ QMimeData * KPrSlidesSorterDocumentModel::mimeData(const QModelIndexList &indexe
// encode the data
QModelIndexList::ConstIterator it = indexes.begin();
- for (; it != indexes.end(); ++it) {
- stream << QVariant::fromValue((*it).row());
+ // order slides
+ QMap<int, KoPAPageBase*> map;
+ for( ; it != indexes.end(); ++it) {
+ map.insert(m_document->pages(false).indexOf((KoPAPageBase*)it->internalPointer()),
+ (KoPAPageBase*)it->internalPointer());
+ }
+
+ QList<KoPAPageBase *> slides = map.values();
+
+ foreach (KoPAPageBase *slide, slides) {
+ stream << QVariant::fromValue(qulonglong((void*)slide));
}
data->setData(format, encoded);
@@ -192,7 +199,6 @@ bool KPrSlidesSorterDocumentModel::removeRows(int row, int count, const QModelIn
bool success = true;
beginRemoveRows(parent,row, row + count- 1);
endRemoveRows();
-
return success;
}
@@ -224,11 +230,7 @@ bool KPrSlidesSorterDocumentModel::dropMimeData(const QMimeData *data, Qt::DropA
return true;
}
- if (!data->hasFormat("application/x-calligra-sliderssorter")) {
- return false;
- }
-
- if (column > 0) {
+ if (!data->hasFormat("application/x-calligra-sliderssorter") || (column > 0)) {
return false;
}
@@ -237,21 +239,16 @@ bool KPrSlidesSorterDocumentModel::dropMimeData(const QMimeData *data, Qt::DropA
QList<KoPAPageBase *> slides;
// decode the data
- while (! stream.atEnd()) {
+ while (!stream.atEnd()) {
QVariant v;
stream >> v;
- KoPAPageBase *page = m_document->pageByIndex(v.toInt(),false);
- if (page) {
- slides.append(page);
- }
+ slides.append(static_cast<KoPAPageBase*>((void*)v.value<qulonglong>()));
}
if (slides.empty()) {
return false;
}
- qSort(slides.begin(), slides.end());
-
int beginRow;
if (row != -1) {
@@ -270,7 +267,7 @@ bool KPrSlidesSorterDocumentModel::dropMimeData(const QMimeData *data, Qt::DropA
pageAfter = m_document->pageByIndex(beginRow - 1,false);
}
- if (!slides.empty ()) {
+ if (!slides.empty()) {
doDrop(slides, pageAfter, action);
}
@@ -280,6 +277,16 @@ bool KPrSlidesSorterDocumentModel::dropMimeData(const QMimeData *data, Qt::DropA
void KPrSlidesSorterDocumentModel::doDrop(QList<KoPAPageBase *> slides, KoPAPageBase *pageAfter, Qt::DropAction action)
{
Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
+ bool enableMove = true;
+
+ foreach (KoPAPageBase *slide, slides) {
+ if (!m_document->pages(false).contains(slide)) {
+ KoPAPageBase *newSlide = slide;
+ slides.replace(slides.indexOf(slide), newSlide);
+ enableMove = false;
+ break;
+ }
+ }
if (((modifiers & Qt::ControlModifier) == 0) &&
((modifiers & Qt::ShiftModifier) == 0)) {
@@ -297,18 +304,21 @@ void KPrSlidesSorterDocumentModel::doDrop(QList<KoPAPageBase *> slides, KoPAPage
QAction *popupCancelAction = new QAction(i18n("C&ancel") + '\t' + QKeySequence(Qt::Key_Escape).toString(), this);
popupCancelAction->setIcon(KIcon("process-stop"));
- popup.addAction(popupMoveAction);
+ if (enableMove) {
+ popup.addAction(popupMoveAction);
+ }
popup.addAction(popupCopyAction);
-
popup.addSeparator();
popup.addAction(popupCancelAction);
QAction *result = popup.exec(QCursor::pos());
- if(result == popupCopyAction)
+ if (result == popupCopyAction) {
action = Qt::CopyAction;
- else if(result == popupMoveAction)
+ }
+ else if (result == popupMoveAction) {
action = Qt::MoveAction;
+ }
else {
return;
}
@@ -323,22 +333,24 @@ void KPrSlidesSorterDocumentModel::doDrop(QList<KoPAPageBase *> slides, KoPAPage
return;
}
-
switch (action) {
case Qt::MoveAction: {
- KoPAPageMoveCommand *command = new KoPAPageMoveCommand(m_document, slides, pageAfter);
- m_document->addCommand(command);
- m_viewModeSlidesSorter->view()->setActivePage(slides.first());
- m_viewModeSlidesSorter->selectSlides(slides);
+ //You can't move slides that not belong to the current document
+ foreach (KoPAPageBase *slide, slides) {
+ if (!m_document->pages(false).contains(slide)) {
+ slides.removeAll(slide);
+ }
+ }
+ if (slides.isEmpty()) {
+ return;
+ }
+ moveSlides(slides, pageAfter);
return;
}
case Qt::CopyAction: {
- KoPAOdfPageSaveHelper saveHelper(m_document, slides);
- KoDrag drag;
- drag.setOdf(KoOdf::mimeType(m_document->documentType()), saveHelper);
- drag.addToClipboard();
+ copySlides(slides);
m_viewModeSlidesSorter->view()->setActivePage(pageAfter);
- m_viewModeSlidesSorter->editPaste();
+ pasteSlides();
m_viewModeSlidesSorter->view()->setActivePage(slides.first());
m_viewModeSlidesSorter->selectSlides(slides);
return;
@@ -349,4 +361,68 @@ void KPrSlidesSorterDocumentModel::doDrop(QList<KoPAPageBase *> slides, KoPAPage
}
}
+KoPAPageBase * KPrSlidesSorterDocumentModel::pageByIndex(const QModelIndex &index) const
+{
+ Q_ASSERT(index.internalPointer());
+ return static_cast<KoPAPageBase*>(index.internalPointer());
+}
+
+bool KPrSlidesSorterDocumentModel::removeSlides(const QList<KoPAPageBase *> &slides)
+{
+ if (!slides.empty() && m_document->pages().count() > slides.count()) {
+ KPrDocument *doc = static_cast<KPrDocument *>(m_document);
+ KUndo2Command *cmd = new KPrDeleteSlidesCommand(doc, slides);
+ if (cmd) {
+ m_document->addCommand(cmd);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool KPrSlidesSorterDocumentModel::addNewSlide()
+{
+ KoPAView *view = dynamic_cast<KoPAView *>(m_viewModeSlidesSorter->view());
+ if (view) {
+ view->insertPage();
+ return true;
+ }
+ return false;
+}
+
+bool KPrSlidesSorterDocumentModel::copySlides(const QList<KoPAPageBase *> &slides)
+{
+ if (!slides.empty()) {
+ // Copy Pages
+ KoPAOdfPageSaveHelper saveHelper(m_document, slides);
+ KoDrag drag;
+ drag.setOdf(KoOdf::mimeType(m_document->documentType()), saveHelper);
+ drag.addToClipboard();
+ return true;
+ }
+ return false;
+}
+
+bool KPrSlidesSorterDocumentModel::pasteSlides()
+{
+ KoPAView *view = dynamic_cast<KoPAView *>(m_viewModeSlidesSorter->view());
+ if (view) {
+ view->pagePaste();
+ return true;
+ }
+ return false;
+}
+
+bool KPrSlidesSorterDocumentModel::moveSlides(const QList<KoPAPageBase *> &slides, KoPAPageBase *pageAfter)
+{
+ KoPAPageMoveCommand *command = new KoPAPageMoveCommand(m_document, slides, pageAfter);
+ if (command) {
+ m_document->addCommand(command);
+ m_viewModeSlidesSorter->view()->setActivePage(slides.first());
+ m_viewModeSlidesSorter->selectSlides(slides);
+ return true;
+ }
+ return false;
+}
+
#include "KPrSlidesSorterDocumentModel.moc"
diff --git a/kpresenter/part/KPrSlidesSorterDocumentModel.h b/kpresenter/part/KPrSlidesSorterDocumentModel.h
index a5b65a4..257a0ee 100644
--- a/kpresenter/part/KPrSlidesSorterDocumentModel.h
+++ b/kpresenter/part/KPrSlidesSorterDocumentModel.h
@@ -75,7 +75,55 @@ public:
*/
void doDrop(QList<KoPAPageBase *> slides, KoPAPageBase *pageAfter, Qt::DropAction action);
+ /**
+ * @brief Return the page that match the give index in the list
+ *
+ / @param index the index of the slide to be retrived
+ * @return a Page in the document if it was found or a null pointer if not.
+ */
+ KoPAPageBase* pageByIndex(const QModelIndex &index) const;
+
+ /**
+ * @brief Deletes a given list of slides from the current document
+ *
+ * @param slides list of slides to be removed
+ * @return true if the command execution was successful
+ */
+ bool removeSlides(const QList<KoPAPageBase *> &slides);
+
+ /**
+ * @brief Add a new slide after the current active page
+ *
+ * @return true if the command execution was successful
+ */
+ bool addNewSlide();
+
+ /**
+ * @brief copy a given list of slides
+ *
+ * @param slides list of slides to be copied
+ * @return true if the command execution was successful
+ */
+ bool copySlides(const QList<KoPAPageBase *> &slides);
+
+ /**
+ * @brief Paste slides from clipboard
+ *
+ * @return true if the command execution was successful
+ */
+ bool pasteSlides();
+
+ /**
+ * @brief Moves a given list of slides after pageAfter slide
+ *
+ * @param slides list of slides to be moved
+ * @param pageAfter indicates where the slides will be moved
+ * @return true if the command execution was successful
+ */
+ bool moveSlides(const QList<KoPAPageBase *> &slides, KoPAPageBase *pageAfter);
+
public slots:
+ /** emit signals indicating a change in the model layout or items */
void update();
private:
diff --git a/kpresenter/part/KPrView.cpp b/kpresenter/part/KPrView.cpp
index 04d502d..fb34504 100644
--- a/kpresenter/part/KPrView.cpp
+++ b/kpresenter/part/KPrView.cpp
@@ -53,12 +53,10 @@
#include "KPrPicturesImport.h"
#include "KPrFactory.h"
#include "commands/KPrAnimationCreateCommand.h"
-#include "commands/KPrSetCustomSlideShowsCommand.h"
#include "dockers/KPrPageLayoutDockerFactory.h"
#include "dockers/KPrPageLayoutDocker.h"
#include "KPrHtmlExport.h"
#include "KPrCustomSlideShows.h"
-#include "ui/KPrCustomSlideShowsDialog.h"
#include "ui/KPrConfigureSlideShowDialog.h"
#include "ui/KPrConfigurePresenterViewDialog.h"
#include "ui/KPrHtmlExportDialog.h"
@@ -135,6 +133,12 @@ KPrViewModePresentation * KPrView::presentationMode() const
return m_presentationMode;
}
+
+KPrViewModeSlidesSorter * KPrView::slidesSorter() const
+{
+ return m_slidesSorterMode;
+}
+
bool KPrView::isPresentationRunning() const
{
return ( viewMode() == m_presentationMode );
@@ -234,9 +238,9 @@ void KPrView::initActions()
actionCollection()->addAction( "edit_createanimation", m_actionCreateAnimation );
connect( m_actionCreateAnimation, SIGNAL( activated() ), this, SLOT( createAnimation() ) );
- m_actionCreateCustomSlideShowsDialog = new KAction( i18n( "Edit Custom Slide Shows..." ), this );
- actionCollection()->addAction( "edit_customslideshows", m_actionCreateCustomSlideShowsDialog );
- connect( m_actionCreateCustomSlideShowsDialog, SIGNAL( activated() ), this, SLOT( dialogCustomSlideShows() ) );
+ m_actionEditCustomSlideShows = new KAction( i18n( "Edit Custom Slide Shows..." ), this );
+ actionCollection()->addAction( "edit_customslideshows", m_actionEditCustomSlideShows );
+ connect( m_actionEditCustomSlideShows, SIGNAL( activated() ), this, SLOT( editCustomSlideShows() ) );
m_actionStartPresentation = new KActionMenu( KIcon("view-presentation"), i18n( "Start Presentation" ), this );
actionCollection()->addAction( "slideshow_start", m_actionStartPresentation );
@@ -367,24 +371,16 @@ void KPrView::showSlidesSorter()
setViewMode(m_slidesSorterMode);
}
-void KPrView::dialogCustomSlideShows()
+void KPrView::editCustomSlideShows()
{
- KPrDocument *doc = static_cast<KPrDocument *>( kopaDocument() );
- KPrCustomSlideShows *finalSlideShows;
- KPrCustomSlideShowsDialog dialog( this, doc->customSlideShows(), doc, finalSlideShows );
- dialog.setModal( true );
- if ( dialog.exec() == QDialog::Accepted ) {
- kopaCanvas()->addCommand( new KPrSetCustomSlideShowsCommand( doc, finalSlideShows ) );
- }
- else {
- delete finalSlideShows;
- }
+ slidesSorter()->setActiveCustomSlideShow(1);
+ showSlidesSorter();
}
void KPrView::configureSlideShow()
{
KPrDocument *doc = static_cast<KPrDocument *>( kopaDocument() );
- KPrConfigureSlideShowDialog *dialog = new KPrConfigureSlideShowDialog( doc, this );
+ KPrConfigureSlideShowDialog *dialog = new KPrConfigureSlideShowDialog(doc, this);
if ( dialog->exec() == QDialog::Accepted ) {
doc->setActiveCustomSlideShow( dialog->activeCustomSlideShow() );
diff --git a/kpresenter/part/KPrView.h b/kpresenter/part/KPrView.h
index a558a2e..8c9d461 100644
--- a/kpresenter/part/KPrView.h
+++ b/kpresenter/part/KPrView.h
@@ -37,6 +37,7 @@ class KoPAPageBase;
class STAGE_EXPORT KPrView : public KoPAView
{
Q_OBJECT
+ friend class KPrConfigureSlideShowDialog;
public:
explicit KPrView( KPrDocument * document, QWidget * parent = 0 );
~KPrView();
@@ -60,6 +61,11 @@ public:
KPrViewModePresentation * presentationMode() const;
/**
+ * Get the slides sorter view mode
+ */
+ KPrViewModeSlidesSorter *slidesSorter() const;
+
+ /**
* Find whether the presentation view mode is active
*/
bool isPresentationRunning() const;
@@ -127,7 +133,7 @@ protected slots:
void createAnimation();
void showNotes();
void showSlidesSorter();
- void dialogCustomSlideShows();
+ void editCustomSlideShows();
void configureSlideShow();
void configurePresenterView();
void exportToHtml();
@@ -145,7 +151,7 @@ private:
KAction *m_actionViewModeNormal;
KAction *m_actionViewModeNotes;
KAction *m_actionViewModeSlidesSorter;
- KAction *m_actionCreateCustomSlideShowsDialog;
+ KAction *m_actionEditCustomSlideShows;
KAction *m_actionExportHtml;
KAction *m_actionInsertPictures;
KAction *m_actionDrawOnPresentation;
diff --git a/kpresenter/part/KPrViewModePresentation.cpp b/kpresenter/part/KPrViewModePresentation.cpp
index 46b61e1..7825827 100644
--- a/kpresenter/part/KPrViewModePresentation.cpp
+++ b/kpresenter/part/KPrViewModePresentation.cpp
@@ -220,7 +220,8 @@ void KPrViewModePresentation::deactivate()
KoPAPageBase * page = m_view->activePage();
if ( m_endOfSlideShowPage ) {
if ( page == m_endOfSlideShowPage ) {
- page = m_view->kopaDocument()->pages().last();
+ KPrDocument *document = static_cast<KPrDocument *>( m_view->kopaDocument() );
+ page = document->slideShow().last();
}
}
m_tool->deactivate();
diff --git a/kpresenter/part/KPrViewModeSlidesSorter.cpp b/kpresenter/part/KPrViewModeSlidesSorter.cpp
index 61866f8..6940cf9 100644
--- a/kpresenter/part/KPrViewModeSlidesSorter.cpp
+++ b/kpresenter/part/KPrViewModeSlidesSorter.cpp
@@ -19,76 +19,170 @@
*/
#include "KPrViewModeSlidesSorter.h"
-
-#include <QtCore/QEvent>
-#include <QtGui/QPainter>
-#include <QVariant>
-#include <QScrollBar>
-#include <QMenu>
-#include <QtCore/qmath.h>
-
#include "KPrSlidesSorterDocumentModel.h"
#include "KPrFactory.h"
#include "KPrSlidesManagerView.h"
#include "KPrSelectionManager.h"
+#include "KPrCustomSlideShowsModel.h"
+#include "KPrDocument.h"
+#include "KPrCustomSlideShows.h"
+#include "KPrSlidesSorterItemDelegate.h"
+#include "KPrView.h"
+//Qt Headers
+#include <QMenu>
+#include <QContextMenuEvent>
+#include <QGridLayout>
+#include <QPushButton>
+#include <QSplitter>
+#include <QComboBox>
+#include <QLabel>
+#include <QPropertyAnimation>
+#include <QLineEdit>
+
+//Calligra Headers
#include <KoResourceManager.h>
-#include <KoRuler.h>
-#include <KoSelection.h>
-#include <KoShapeLayer.h>
-#include <KoShapeManager.h>
#include <KoText.h>
-#include <KoToolManager.h>
-#include <KoToolProxy.h>
#include <KoZoomController.h>
-
#include <KoPACanvas.h>
#include <KoPADocument.h>
#include <KoPAPageBase.h>
#include <KoPAMasterPage.h>
#include <KoPAView.h>
-#include <KPrView.h>
-#include <KoPAPageMoveCommand.h>
-#include <KoPAPageDeleteCommand.h>
-#include <KoPAOdfPageSaveHelper.h>
-#include <KoDrag.h>
#include <KoCanvasController.h>
#include <KoCopyController.h>
#include <KoCutController.h>
+//KDE Headers
#include <klocale.h>
#include <KDebug>
#include <kconfiggroup.h>
+#include <KIconLoader>
+#include <KGlobalSettings>
+#include <KMessageBox>
#include <KActionCollection>
KPrViewModeSlidesSorter::KPrViewModeSlidesSorter(KoPAView *view, KoPACanvas *canvas)
- : KoPAViewMode( view, canvas )
- , m_slidesSorter( new KPrSlidesManagerView(m_toolProxy, view->parentWidget()))
- , m_documentModel(new KPrSlidesSorterDocumentModel(this, view->parentWidget()))
- , m_iconSize( QSize(200, 200) )
-{
- m_slidesSorter->hide();
- m_slidesSorter->setIconSize( m_iconSize );
-
- connect(m_slidesSorter, SIGNAL(requestContextMenu(QContextMenuEvent*)), this, SLOT(slidesSorterContextMenu(QContextMenuEvent*)));
- connect(m_slidesSorter, SIGNAL(slideDblClick()), this, SLOT(activateNormalViewMode()));
- connect(m_slidesSorter, SIGNAL(selectionCleared()), this, SLOT(disableEditActions()));
- connect(m_slidesSorter, SIGNAL(itemSelected()), this, SLOT(enableEditActions()));
-
- //connect signals for manage standard edit actions
+ : KoPAViewMode(view, canvas)
+ , m_slidesSorterView(new KPrSlidesManagerView())
+ , m_customSlideShowView(new KPrSlidesManagerView())
+ , m_slidesSorterModel(new KPrSlidesSorterDocumentModel(this, view->parentWidget()))
+ , m_centralWidget(new QWidget(view->parentWidget()))
+ , m_customSlideShowModel(new KPrCustomSlideShowsModel(static_cast<KPrDocument *>(view->kopaDocument()), view->parentWidget()))
+ , m_iconSize(QSize(200, 200))
+ , m_editCustomSlideShow(false)
+{
+ //Create customSlideShow GUI
+ QWidget *m_customShowsToolBar = new QWidget();
+
+ QHBoxLayout *toolBarLayout = new QHBoxLayout(m_customShowsToolBar);
+ QVBoxLayout *centralWidgetLayout = new QVBoxLayout(m_centralWidget);
+
+ QLabel *slideShowsLabel = new QLabel(i18n("Slide Show: "));
+ m_customSlideShowsList = new QComboBox;
+ m_customSlideShowsList->setEditable(false);
+ m_customSlideShowsList->setInsertPolicy(QComboBox::NoInsert);
+ m_customSlideShowsList->setMinimumContentsLength(30);
+ slideShowsLabel->setBuddy(m_customSlideShowsList);
+
+ m_buttonAddCustomSlideShow = new QToolButton();
+ m_buttonAddCustomSlideShow->setIcon(SmallIcon("list-add"));
+ m_buttonAddCustomSlideShow->setToolTip(i18n("Add a new custom slide show"));
+
+ m_buttonDelCustomSlideShow = new QToolButton();
+ m_buttonDelCustomSlideShow->setIcon(SmallIcon("list-remove"));
+ m_buttonDelCustomSlideShow->setEnabled(false);
+ m_buttonDelCustomSlideShow->setToolTip(i18n("Delete current custom slide show"));
+
+ m_buttonAddSlideToCurrentShow = new QToolButton();
+ m_buttonAddSlideToCurrentShow->setIcon(SmallIcon("arrow-down"));
+ m_buttonAddSlideToCurrentShow->setToolTip(i18n("Add slides to current custom slide show"));
+ m_buttonAddSlideToCurrentShow->setEnabled(false);
+
+ m_buttonDelSlideFromCurrentShow = new QToolButton();
+ m_buttonDelSlideFromCurrentShow->setIcon(SmallIcon("arrow-up"));
+ m_buttonDelSlideFromCurrentShow->setToolTip(i18n("Remove slides from current custom slide show"));
+ m_buttonDelSlideFromCurrentShow->setEnabled(false);
+
+ QSplitter *viewsSplitter = new QSplitter(Qt::Vertical);
+
+ //hide Custom Shows View
+ m_customSlideShowView->setMaximumHeight(0);
+
+ //Layout Widgets
+ toolBarLayout->addWidget(slideShowsLabel);
+ toolBarLayout->addWidget(m_customSlideShowsList);
+ toolBarLayout->addWidget(m_buttonAddCustomSlideShow);
+ toolBarLayout->addWidget(m_buttonDelCustomSlideShow);
+ toolBarLayout->addStretch();
+ toolBarLayout->addWidget(m_buttonAddSlideToCurrentShow);
+ toolBarLayout->addWidget(m_buttonDelSlideFromCurrentShow);
+
+ viewsSplitter->addWidget(m_slidesSorterView);
+ viewsSplitter->addWidget(m_customSlideShowView);
+ centralWidgetLayout->addWidget(viewsSplitter);
+ centralWidgetLayout->addWidget(m_customShowsToolBar);
+
+ //initialize widgets
+ m_centralWidget->hide();
+ m_slidesSorterView->setIconSize(m_iconSize);
+ m_slidesSorterView->setAutoScroll(true);
+ m_customSlideShowView->setIconSize(m_iconSize);
+ m_customSlideShowView->setAutoScroll(true);
+
+ //Populate ComboBox
+ customShowChanged(0);
+ updateCustomSlideShowsList();
+
+ //Setup customSlideShows view
+ m_customSlideShowView->setModel(m_customSlideShowModel);
+ m_customSlideShowView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ m_customSlideShowView->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ m_customSlideShowView->setDragDropMode(QAbstractItemView::InternalMove);
+
+ //Setup slides sorter view
+ m_slidesSorterModel->setDocument(m_view->kopaDocument());
+ m_slidesSorterView->setModel(m_slidesSorterModel);
+ m_slidesSorterView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ m_slidesSorterView->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ m_slidesSorterView->setDragDropMode(QAbstractItemView::InternalMove);
+
+ //setup signals
+ connect(m_slidesSorterView, SIGNAL(requestContextMenu(QContextMenuEvent*)), this, SLOT(slidesSorterContextMenu(QContextMenuEvent*)));
+ connect(m_customSlideShowView, SIGNAL(requestContextMenu(QContextMenuEvent*)), this, SLOT(customSlideShowsContextMenu(QContextMenuEvent*)));
+ connect(m_slidesSorterView, SIGNAL(slideDblClick()), this, SLOT(activateNormalViewMode()));
+ connect(m_buttonAddCustomSlideShow, SIGNAL(clicked()), this, SLOT(addCustomSlideShow()));
+ connect(m_buttonDelCustomSlideShow, SIGNAL(clicked()), this, SLOT(removeCustomSlideShow()));
+ connect(m_buttonAddSlideToCurrentShow, SIGNAL(clicked()), this, SLOT(addSlideToCustomShow()));
+ connect(m_buttonDelSlideFromCurrentShow, SIGNAL(clicked()), this, SLOT(deleteSlidesFromCustomShow()));
+ connect(m_customSlideShowModel, SIGNAL(customSlideShowsChanged()), this, SLOT(updateCustomSlideShowsList()));
+
+ //setup signals for manage edit actions
connect(view->copyController(), SIGNAL(copyRequested()), this, SLOT(editCopy()));
connect(view->cutController(), SIGNAL(copyRequested()), this, SLOT(editCut()));
- connect(view, SIGNAL(selectAllRequested()), m_slidesSorter, SLOT(selectAll()));
- connect(view, SIGNAL(deselectAllRequested()), m_slidesSorter, SLOT(clearSelection()));
+ connect(view, SIGNAL(selectAllRequested()), m_slidesSorterView, SLOT(selectAll()));
+ connect(view, SIGNAL(deselectAllRequested()), m_slidesSorterView, SLOT(clearSelection()));
+ connect(m_slidesSorterView, SIGNAL(selectionCleared()), this, SLOT(disableEditActions()));
+ connect(m_slidesSorterView, SIGNAL(itemSelected()), this, SLOT(enableEditActions()));
+ connect(m_slidesSorterView, SIGNAL(focusLost()), SLOT(disableEditActions()));
+ connect(m_slidesSorterView, SIGNAL(focusGot()), SLOT(manageAddRemoveSlidesButtons()));
+ connect(m_customSlideShowView, SIGNAL(focusGot()), SLOT(disableEditActions()));
+ connect(m_customSlideShowView, SIGNAL(focusGot()), SLOT(manageAddRemoveSlidesButtons()));
- //install selection manager for Slides Sorter View
- m_selectionManagerSlidesSorter = new KPrSelectionManager(m_slidesSorter);
+ //install selection manager for Slides Sorter View and Custom Shows View
+ new KPrSelectionManager(m_slidesSorterView);
+ new KPrSelectionManager(m_customSlideShowView);
+
+ //install delegate for Slides Sorter View
+ KPrSlidesSorterItemDelegate *slidesSorterDelegate = new KPrSlidesSorterItemDelegate(m_slidesSorterView);
+ m_slidesSorterView->setItemDelegate(slidesSorterDelegate);
}
KPrViewModeSlidesSorter::~KPrViewModeSlidesSorter()
{
//save zoom value
saveZoomConfig(zoom());
+ delete m_centralWidget;
}
void KPrViewModeSlidesSorter::paint(KoPACanvasBase* /*canvas*/, QPainter& /*painter*/, const QRectF &/*paintRect*/)
@@ -156,12 +250,13 @@ void KPrViewModeSlidesSorter::activate(KoPAViewMode *previousViewMode)
if (view) {
view->hide();
}
- m_slidesSorter->show();
- m_slidesSorter->setFocus(Qt::ActiveWindowFocusReason);
+ m_centralWidget->show();
+ m_slidesSorterView->setFocus(Qt::ActiveWindowFocusReason);
updateToActivePageIndex();
- connect(m_slidesSorter,SIGNAL(indexChanged(QModelIndex)), this, SLOT(itemClicked(QModelIndex)));
- connect(m_slidesSorter, SIGNAL(pressed(QModelIndex)), this, SLOT(itemClicked(const QModelIndex)));
+ //setup signals
+ connect(m_slidesSorterView,SIGNAL(indexChanged(QModelIndex)), this, SLOT(itemClicked(QModelIndex)));
+ connect(m_slidesSorterView, SIGNAL(pressed(QModelIndex)), this, SLOT(itemClicked(const QModelIndex)));
connect(m_view->proxyObject, SIGNAL(activePageChanged()), this, SLOT(updateToActivePageIndex()));
connect(m_view->kopaDocument(),SIGNAL(pageAdded(KoPAPageBase*)),this, SLOT(updateSlidesSorterDocumentModel()));
connect(m_view->kopaDocument(),SIGNAL(pageRemoved(KoPAPageBase*)),this, SLOT(updateSlidesSorterDocumentModel()));
@@ -181,7 +276,7 @@ void KPrViewModeSlidesSorter::activate(KoPAViewMode *previousViewMode)
void KPrViewModeSlidesSorter::deactivate()
{
- m_slidesSorter->hide();
+ m_centralWidget->hide();
// Give the ressources back to the canvas
m_canvas->resourceManager()->setResource(KoText::ShowTextFrames, 0);
// Active the view as a basic but active one
@@ -197,10 +292,8 @@ void KPrViewModeSlidesSorter::deactivate()
//change zoom saving slot and restore normal view zoom values
disconnect(m_view->zoomController(), SIGNAL(zoomChanged(KoZoomMode::Mode, qreal)), this, SLOT(updateZoom(KoZoomMode::Mode, qreal)));
-
m_view->zoomController()->zoomAction()->setZoomModes(KoZoomMode::ZOOM_PAGE | KoZoomMode::ZOOM_WIDTH);
-
- m_view->setActivePage(m_view->kopaDocument()->pageByIndex(m_slidesSorter->currentIndex().row(), false));
+ m_view->setActivePage(m_view->kopaDocument()->pageByIndex(m_slidesSorterView->currentIndex().row(), false));
KPrView *kPrview = dynamic_cast<KPrView *>(m_view);
if (kPrview) {
@@ -209,13 +302,12 @@ void KPrViewModeSlidesSorter::deactivate()
connect(kPrview->deleteSelectionAction(), SIGNAL(triggered()), kPrview, SLOT(editDeleteSelection()));
disconnect(kPrview->deleteSelectionAction(), SIGNAL(triggered()), this, SLOT(deleteSlide()));
}
-
disableEditActions();
}
void KPrViewModeSlidesSorter::updateSlidesSorterDocumentModel()
{
- m_documentModel->update();
+ m_slidesSorterModel->update();
updateToActivePageIndex();
}
@@ -230,13 +322,13 @@ void KPrViewModeSlidesSorter::updateActivePage( KoPAPageBase *page )
void KPrViewModeSlidesSorter::updateToActivePageIndex()
{
int row = m_view->kopaDocument()->pageIndex(m_view->activePage());
- QModelIndex index = m_documentModel->index(row, 0, QModelIndex());
- m_slidesSorter->setCurrentIndex(index);
+ QModelIndex index = m_slidesSorterModel->index(row, 0, QModelIndex());
+ m_slidesSorterView->setCurrentIndex(index);
}
void KPrViewModeSlidesSorter::updateActivePageToCurrentIndex()
{
- QModelIndex c_index = m_slidesSorter->currentIndex();
+ QModelIndex c_index = m_slidesSorterView->currentIndex();
m_view->setActivePage(m_view->kopaDocument()->pageByIndex(c_index.row(), false));
}
@@ -252,15 +344,12 @@ void KPrViewModeSlidesSorter::removeShape( KoShape *shape )
void KPrViewModeSlidesSorter::populate()
{
- m_documentModel->setDocument(m_view->kopaDocument());
- m_slidesSorter->setModel(m_documentModel);
+ //Init m_slidesSorter view
+ QModelIndex item = m_slidesSorterModel->index(0, 0, QModelIndex());
+ m_slidesSorterView->setItemSize(m_slidesSorterView->visualRect(item));
- m_slidesSorter->setSelectionBehavior(QAbstractItemView::SelectRows);
- m_slidesSorter->setSelectionMode(QAbstractItemView::ExtendedSelection);
-
- m_slidesSorter->setDragDropMode(QAbstractItemView::InternalMove);
- QModelIndex item = m_documentModel->index(0, 0, QModelIndex());
- m_slidesSorter->setItemSize (m_slidesSorter->visualRect(item));
+ //Init m_customSlidesShowsView
+ m_customSlideShowView->setItemSize(m_slidesSorterView->visualRect(item));
}
QSize KPrViewModeSlidesSorter::iconSize() const
@@ -268,6 +357,23 @@ QSize KPrViewModeSlidesSorter::iconSize() const
return m_iconSize;
}
+void KPrViewModeSlidesSorter::selectSlides(const QList<KoPAPageBase *> &slides)
+{
+ if (slides.isEmpty()) {
+ return;
+ }
+
+ m_slidesSorterView->clearSelection();
+
+ foreach (KoPAPageBase *slide, slides) {
+ int row = m_view->kopaDocument()->pageIndex(slide);
+ QModelIndex index = m_slidesSorterModel->index(row, 0, QModelIndex());
+ if (index.isValid()) {
+ m_slidesSorterView->selectionModel()->select(index, QItemSelectionModel::Select);
+ }
+ }
+}
+
void KPrViewModeSlidesSorter::activateNormalViewMode()
{
KPrView *view = static_cast<KPrView *>(m_view);
@@ -281,12 +387,11 @@ void KPrViewModeSlidesSorter::itemClicked(const QModelIndex index)
}
//Avoid deselect slides when dragging
- if (m_slidesSorter->selectionModel()->selectedIndexes().length () > 1) {
+ if (m_slidesSorterView->selectionModel()->selectedIndexes().length () > 1) {
return;
}
KoPAPageBase *page = m_view->kopaDocument()->pageByIndex(index.row(), false);
-
if (page) {
m_view->setActivePage(page);
}
@@ -296,50 +401,48 @@ void KPrViewModeSlidesSorter::itemClicked(const QModelIndex index)
QList<KoPAPageBase *> KPrViewModeSlidesSorter::extractSelectedSlides()
{
QList<KoPAPageBase *> slides;
-
- QModelIndexList selectedItems = m_slidesSorter->selectionModel()->selectedIndexes();
+ QModelIndexList selectedItems = m_slidesSorterView->selectionModel()->selectedIndexes();
if (selectedItems.count() == 0) {
return slides;
}
- qSort(selectedItems.begin(), selectedItems.end());
-
- foreach (const QModelIndex & index, selectedItems) {
+ foreach (const QModelIndex &index, selectedItems) {
KoPAPageBase *page = m_view->kopaDocument()->pageByIndex(index.row (), false);
if (page) {
slides.append(page);
}
}
+ //order slides
+ QMap<int, KoPAPageBase*> map;
+ foreach (KoPAPageBase *slide, slides)
+ map.insert(m_view->kopaDocument()->pages(false).indexOf(slide), slide);
+ slides = map.values();
+
return slides;
}
void KPrViewModeSlidesSorter::deleteSlide()
{
- // create a list with all selected slides
- QList<KoPAPageBase*> selectedSlides = extractSelectedSlides();
-
- if (!selectedSlides.empty() && m_view->kopaDocument()->pages().count() > selectedSlides.count()) {
- KUndo2Command *cmd = new KoPAPageDeleteCommand(m_view->kopaDocument(), selectedSlides);
- if (cmd) {
- m_view->kopaDocument()->addCommand(cmd);
- }
+ if (m_slidesSorterView->hasFocus()) {
+ // create a list with all selected slides
+ QList<KoPAPageBase*> selectedSlides = extractSelectedSlides();
+ m_slidesSorterModel->removeSlides(selectedSlides);
+ }
+ else if (m_customSlideShowView->hasFocus()) {
+ deleteSlidesFromCustomShow();
}
}
void KPrViewModeSlidesSorter::addSlide()
{
- KoPAView *view = dynamic_cast<KoPAView *>(m_view);
- if (view) {
- view->insertPage();
- }
+ m_slidesSorterModel->addNewSlide();
}
void KPrViewModeSlidesSorter::renameCurrentSlide()
{
- QModelIndexList selectedItems = m_slidesSorter->selectionModel()->selectedIndexes();
- m_slidesSorter->edit(selectedItems.first());
-
+ QModelIndexList selectedItems = m_slidesSorterView->selectionModel()->selectedIndexes();
+ m_slidesSorterView->edit(selectedItems.first());
}
void KPrViewModeSlidesSorter::editCut()
@@ -351,37 +454,29 @@ void KPrViewModeSlidesSorter::editCut()
void KPrViewModeSlidesSorter::editCopy()
{
// separate selected layers and selected shapes
- QList<KoPAPageBase*> slides = extractSelectedSlides();;
-
- if (!slides.empty()) {
- // Copy Pages
- KoPAOdfPageSaveHelper saveHelper(m_view->kopaDocument (), slides);
- KoDrag drag;
- drag.setOdf(KoOdf::mimeType(m_view->kopaDocument()->documentType()), saveHelper);
- drag.addToClipboard();
- }
+ QList<KoPAPageBase*> slides = extractSelectedSlides();
+ m_slidesSorterModel->copySlides(slides);
}
void KPrViewModeSlidesSorter::editPaste()
{
- KoPAView *view = dynamic_cast<KoPAView *>(m_view);
- if (view) {
- view->pagePaste();
- }
+ m_slidesSorterModel->pasteSlides();
}
void KPrViewModeSlidesSorter::updateZoom(KoZoomMode::Mode mode, qreal zoom)
{
Q_UNUSED(mode);
-
//at zoom 100%, iconSize is set in 200 x 200
//KPrSlidesSorterDocumentModel uses iconSize function in decorate Role.
setIconSize(QSize(qRound(zoom*200),qRound(zoom*200)));
- m_slidesSorter->setIconSize(iconSize());
+ m_slidesSorterView->setIconSize(iconSize());
+ m_customSlideShowModel->setIconSize(iconSize());
+ m_customSlideShowView->setIconSize(iconSize());
//update item size
- QModelIndex item = m_documentModel->index(0, 0, QModelIndex());
- m_slidesSorter->setItemSize(m_slidesSorter->visualRect(item));
+ QModelIndex item = m_slidesSorterModel->index(0, 0, QModelIndex());
+ m_slidesSorterView->setItemSize(m_slidesSorterView->visualRect(item));
+ m_customSlideShowView->setItemSize(m_slidesSorterView->visualRect(item));
setZoom(qRound(zoom * 100.));
}
@@ -391,7 +486,6 @@ void KPrViewModeSlidesSorter::setIconSize(QSize size)
if (size != m_iconSize) {
m_iconSize = size;
}
-
}
void KPrViewModeSlidesSorter::loadZoomConfig()
@@ -425,21 +519,27 @@ int KPrViewModeSlidesSorter::zoom()
void KPrViewModeSlidesSorter::slidesSorterContextMenu(QContextMenuEvent *event)
{
- QMenu menu(m_slidesSorter);
-
+ QMenu menu(m_slidesSorterView);
menu.addAction(KIcon("document-new"), i18n("Add a new slide"), this, SLOT(addSlide()));
menu.addAction(KIcon("edit-delete"), i18n("Delete selected slides"), this, SLOT(deleteSlide()));
- menu.addAction(KIcon("edit-cut"), i18n("Cut"), this, SLOT(editCut()));
- menu.addAction(KIcon("edit-copy"), i18n("Copy"), this, SLOT(editCopy()));
- menu.addAction(KIcon("edit-paste"), i18n("Paste"), this, SLOT(editPaste()));
-
- QModelIndexList selectedItems = m_slidesSorter->selectionModel()->selectedIndexes();
-
+ QModelIndexList selectedItems = m_slidesSorterView->selectionModel()->selectedIndexes();
if (selectedItems.count() == 1 && selectedItems.first().isValid()) {
menu.addAction(KIcon("edit-rename"), i18n("Rename"), this, SLOT(renameCurrentSlide()));
}
+ menu.addSeparator();
+ menu.addAction(KIcon("edit-cut"), i18n("Cut"), this, SLOT(editCut()));
+ menu.addAction(KIcon("edit-copy"), i18n("Copy"), this, SLOT(editCopy()));
+ menu.addAction(KIcon("edit-paste"), i18n("Paste"), this, SLOT(editPaste()));
+ menu.exec(event->globalPos());
+ enableEditActions();
+}
+
+void KPrViewModeSlidesSorter::customSlideShowsContextMenu(QContextMenuEvent *event)
+{
+ QMenu menu(m_customSlideShowView);
+ menu.addAction(KIcon("edit-delete"), i18n("Delete selected slides"), this, SLOT(deleteSlidesFromCustomShow()));
menu.exec(event->globalPos());
}
@@ -459,19 +559,158 @@ void KPrViewModeSlidesSorter::disableEditActions()
ac->action("edit_delete")->setEnabled(false);
}
-void KPrViewModeSlidesSorter::selectSlides(const QList<KoPAPageBase *> &slides)
+void KPrViewModeSlidesSorter::customShowChanged(int showNumber)
{
- if (slides.isEmpty()) {
+ QString name = m_customSlideShowsList->itemText(showNumber);
+
+ bool panelVisible = true;
+ if (showNumber < 1) {
+ panelVisible = false;
+ name = QString();
+ }
+
+ //Change document current custom slide show
+ KPrDocument *doc = static_cast<KPrDocument *>(m_view->kopaDocument());
+ doc->setActiveCustomSlideShow(name);
+
+ //Decide show or hide Custom Slide Shows View
+ if (panelVisible != m_editCustomSlideShow) {
+ const bool animate = KGlobalSettings::graphicEffectsLevel() && KGlobalSettings::SimpleAnimationEffects;
+ const int duration = animate ? 250 : 1;
+ QPropertyAnimation *animation = new QPropertyAnimation(m_customSlideShowView, "maximumHeight");
+
+ if (!panelVisible) {
+ animation->setDuration(duration);
+ animation->setStartValue(m_customSlideShowView->maximumHeight());
+ animation->setEndValue(0);
+ //Deactivate tool buttons and edition
+ disableEditCustomShowButtons();
+ m_slidesSorterView->setAutoScroll(true);
+ }
+ else {
+ animation->setDuration(duration);
+ animation->setStartValue(0);
+ animation->setEndValue(m_slidesSorterView->height() / 2);
+ //Activate tool buttons and edition
+ enableEditCustomShowButtons();
+ m_slidesSorterView->setAutoScroll(false);
+ }
+ animation->start();
+ }
+
+ m_editCustomSlideShow = panelVisible;
+
+ //Populate Custom Slide Shows View if visible
+ if (panelVisible) {
+ m_customSlideShowModel->setActiveSlideShow(showNumber - 1);
+ }
+}
+
+void KPrViewModeSlidesSorter::deleteSlidesFromCustomShow()
+{
+ QModelIndexList selectedItems = m_customSlideShowView->selectionModel()->selectedIndexes();
+ if (selectedItems.count() == 0) {
return;
}
+ m_customSlideShowModel->removeSlidesByIndexes(selectedItems);
+}
- m_slidesSorter->clearSelection();
+void KPrViewModeSlidesSorter::addSlideToCustomShow()
+{
+ // create a list with all selected slides
+ QList<KoPAPageBase*> selectedSlides = extractSelectedSlides();
+ int row = (m_customSlideShowView->currentIndex().row() >= 0) ? m_customSlideShowView->currentIndex().row() + 1 : 0;
+ m_customSlideShowModel->addSlides(selectedSlides, row);
+}
- foreach (KoPAPageBase *slide, slides) {
- int row = m_view->kopaDocument()->pageIndex(slide);
- QModelIndex index = m_documentModel->index(row, 0, QModelIndex());
- if (index.isValid()) {
- m_slidesSorter->selectionModel()->select(index, QItemSelectionModel::Select);
- }
+void KPrViewModeSlidesSorter::addCustomSlideShow()
+{
+ //We create a different default name for every SlideShow:
+ static int newSlideShowsCount = 1;
+ while(m_customSlideShowModel->customShowsNamesList().contains(i18n("Slide Show %1", newSlideShowsCount)))
+ {
+ ++newSlideShowsCount;
+ }
+
+ m_customSlideShowModel->addNewCustomShow(i18n("Slide Show %1", newSlideShowsCount));
+}
+
+
+void KPrViewModeSlidesSorter::removeCustomSlideShow()
+{
+ m_customSlideShowModel->removeCustomShow(m_customSlideShowsList->currentText());
+}
+
+void KPrViewModeSlidesSorter::updateCustomSlideShowsList()
+{
+ disconnect(m_customSlideShowsList, SIGNAL(currentIndexChanged(int)), this, SLOT(customShowChanged(int)));
+
+ QStringList slideShows;
+ slideShows << i18n("All slides") << (m_customSlideShowModel->customShowsNamesList());
+ m_customSlideShowsList->clear();
+ m_customSlideShowsList->addItems(slideShows);
+ int index = slideShows.indexOf(m_customSlideShowModel->activeCustomSlideShow());
+ m_customSlideShowsList->setCurrentIndex(index >= 0 ? index : 0);
+ customShowChanged(m_customSlideShowsList->currentIndex());
+
+ connect(m_customSlideShowsList, SIGNAL(currentIndexChanged(int)), this, SLOT(customShowChanged(int)));
+}
+
+void KPrViewModeSlidesSorter::renameCustomSlideShow()
+{
+ QString newName = m_customSlideShowsList->currentText();
+
+ if (newName == m_customSlideShowModel->activeCustomSlideShow()) {
+ return;
+ }
+
+ // Empty string is not allowed as a name, if the name is empty, revert back to previous name
+ if (newName.isEmpty()) {
+ updateCustomSlideShowsList();
+ }
+ //If the name is not already in use, use it, otherwise let the user know
+ else if (!m_customSlideShowModel->customShowsNamesList().contains(newName)) {
+ m_customSlideShowModel->renameCustomShow(m_customSlideShowModel->activeCustomSlideShow(), newName);
+ updateCustomSlideShowsList();
+ }
+ else {
+ KMessageBox Message;
+ Message.sorry(m_customSlideShowView, i18n("There cannot be two slideshows with the same name."), i18n("Error"),
+ KMessageBox::Notify);
+ updateCustomSlideShowsList();
}
}
+
+void KPrViewModeSlidesSorter::enableEditCustomShowButtons()
+{
+ m_customSlideShowsList->setEditable(true);
+ connect(m_customSlideShowsList->lineEdit(), SIGNAL(editingFinished()), this, SLOT(renameCustomSlideShow()));
+ m_buttonDelCustomSlideShow->setEnabled(true);
+}
+
+void KPrViewModeSlidesSorter::disableEditCustomShowButtons()
+{
+ m_customSlideShowsList->setEditable(false);
+ m_buttonDelCustomSlideShow->setEnabled(false);
+ m_buttonAddSlideToCurrentShow->setEnabled(false);
+ m_buttonDelSlideFromCurrentShow->setEnabled(false);
+}
+
+void KPrViewModeSlidesSorter::manageAddRemoveSlidesButtons()
+{
+ m_buttonAddSlideToCurrentShow->setEnabled(m_slidesSorterView->hasFocus());
+ m_buttonDelSlideFromCurrentShow->setEnabled(m_customSlideShowView->hasFocus());
+ KActionCollection *ac = canvas()->canvasController()->actionCollection();
+ ac->action("edit_delete")->setEnabled(m_customSlideShowView->hasFocus() ||
+ !m_slidesSorterView->selectionModel()->selectedIndexes().isEmpty());
+}
+
+void KPrViewModeSlidesSorter::setActiveCustomSlideShow(int index)
+{
+ disconnect(m_customSlideShowsList, SIGNAL(currentIndexChanged(int)), this, SLOT(customShowChanged(int)));
+
+ m_customSlideShowsList->setCurrentIndex(index >= 0 && index < m_customSlideShowsList->count() ? index : 0);
+ customShowChanged(m_customSlideShowsList->currentIndex());
+
+ connect(m_customSlideShowsList, SIGNAL(currentIndexChanged(int)), this, SLOT(customShowChanged(int)));
+}
diff --git a/kpresenter/part/KPrViewModeSlidesSorter.h b/kpresenter/part/KPrViewModeSlidesSorter.h
index 240bd9e..a87c39c 100644
--- a/kpresenter/part/KPrViewModeSlidesSorter.h
+++ b/kpresenter/part/KPrViewModeSlidesSorter.h
@@ -31,9 +31,18 @@ class KoPAPageBase;
class KPrSlidesSorterDocumentModel;
class KPrSlidesManagerView;
class KPrSelectionManager;
-
-//This view mode holds Slides Sorter view widget and
-//TODO: holds view and toolbar to manage custom slides shows
+class KPrCustomSlideShowsModel;
+class KPrCustomSlideShows;
+class QToolButton;
+class QComboBox;
+
+/**
+ * This view mode holds Slides Sorter view widget and
+ * holds view and toolbar to manage custom slide shows
+ * This class also manages all interaction between
+ * the standard GUI and the slides sorter view and between
+ * slides sorter view - custom slide shows view
+ */
class KPrViewModeSlidesSorter : public KoPAViewMode
{
Q_OBJECT
@@ -41,7 +50,7 @@ public:
KPrViewModeSlidesSorter(KoPAView *view, KoPACanvas *canvas);
~KPrViewModeSlidesSorter();
- void paint(KoPACanvasBase *canvas, QPainter& painter, const QRectF &paintRect);
+ void paint(KoPACanvasBase *canvas, QPainter &painter, const QRectF &paintRect);
void paintEvent(KoPACanvas *canvas, QPaintEvent *event);
void tabletEvent(QTabletEvent *event, const QPointF &point);
void mousePressEvent(QMouseEvent *event, const QPointF &point);
@@ -84,6 +93,9 @@ public:
*/
void selectSlides(const QList<KoPAPageBase *> &slides);
+ /** Set active custom slide show */
+ void setActiveCustomSlideShow(int index);
+
protected:
/**
@@ -123,14 +135,19 @@ protected:
void saveZoomConfig(int zoom);
private:
- KPrSlidesManagerView *m_slidesSorter;
- KPrSlidesSorterDocumentModel *m_documentModel;
- QSize m_iconSize;
+ KPrSlidesManagerView *m_slidesSorterView;
+ KPrSlidesManagerView *m_customSlideShowView;
+ KPrSlidesSorterDocumentModel *m_slidesSorterModel;
int m_zoom;
- KPrSelectionManager *m_selectionManagerSlidesSorter;
-
-public slots:
- void editPaste();
+ QWidget *m_centralWidget;
+ KPrCustomSlideShowsModel *m_customSlideShowModel;
+ QSize m_iconSize;
+ bool m_editCustomSlideShow;
+ QToolButton *m_buttonAddCustomSlideShow;
+ QToolButton *m_buttonDelCustomSlideShow;
+ QToolButton *m_buttonAddSlideToCurrentShow;
+ QToolButton *m_buttonDelSlideFromCurrentShow;
+ QComboBox *m_customSlideShowsList;
private slots:
/** Changes the view active page to match the slides sorter current index*/
@@ -139,6 +156,9 @@ private slots:
/** Update the slides sorter document model*/
void updateSlidesSorterDocumentModel();
+ /** Updates custom slide Shows list */
+ void updateCustomSlideShowsList();
+
/** Changes the view active page to match the slides sorter item selected*/
void itemClicked(const QModelIndex);
@@ -157,6 +177,9 @@ private slots:
/** copy the current selected slides*/
void editCopy();
+ /** paste slides in slides sorter view*/
+ void editPaste();
+
/** update the zoom of the Slides Sorter view*/
void updateZoom(KoZoomMode::Mode mode, qreal zoom);
@@ -169,11 +192,41 @@ private slots:
/** Provides a custom context menu for the slides sorter view*/
void slidesSorterContextMenu(QContextMenuEvent *event);
- /** Enable standard edit actions */
+ /** Provides a custom context menu for the slides sorter view*/
+ void customSlideShowsContextMenu(QContextMenuEvent *event);
+
+ /** Updates the UI according to the custom Show selected */
+ void customShowChanged(int showNumber);
+
+ /** Delete selected slides from the current custom slide show */
+ void deleteSlidesFromCustomShow();
+
+ /** Add slides selected on Slides Sorter view to the current custom slide show */
+ void addSlideToCustomShow();
+
+ /** Add a new slides custom Show */
+ void addCustomSlideShow();
+
+ /** Remove a new slides custom Show */
+ void removeCustomSlideShow();
+
+ /** Renames current custom slide show */
+ void renameCustomSlideShow();
+
+ /** Enable standard edit actions for Slides Sorter View */
void enableEditActions();
- /** Disable standard edit actions */
+ /** Disable standard edit actions for Slides Sorter View */
void disableEditActions();
+
+ /** Enable edit buttons for Custom Slide Shows List*/
+ void enableEditCustomShowButtons();
+
+ /** Disable edit buttons for Custom Slide Shows View and List*/
+ void disableEditCustomShowButtons();
+
+ /** Enable/Disable add and remove slides buttons for Custom Slide Show View */
+ void manageAddRemoveSlidesButtons();
};
#endif // KPRVIEWMODESLIDESSORTER_H
diff --git a/kpresenter/part/commands/KPrSetCustomSlideShowsCommand.cpp b/kpresenter/part/commands/KPrSetCustomSlideShowsCommand.cpp
deleted file mode 100644
index 24b9996..0000000
--- a/kpresenter/part/commands/KPrSetCustomSlideShowsCommand.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/* This file is part of the KDE project
- * Copyright (C) 2008 Thorsten Zachmann <zachmann at kde.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or ( at your option ) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "KPrSetCustomSlideShowsCommand.h"
-
-#include "KPrCustomSlideShows.h"
-#include "KPrDocument.h"
-
-KPrSetCustomSlideShowsCommand::KPrSetCustomSlideShowsCommand( KPrDocument * doc, KPrCustomSlideShows * newSlideShows, KUndo2Command *parent )
-: KUndo2Command( parent )
-, m_doc( doc )
-, m_oldSlideShows( doc->customSlideShows() )
-, m_newSlideShows( newSlideShows )
-, m_deleteNewSlideShows( true )
-{
- // TODO 2.1 change text to "Edit custom slide shows"
- setText( i18nc("(qtundo-format)", "Edit") );
-}
-
-KPrSetCustomSlideShowsCommand::~KPrSetCustomSlideShowsCommand()
-{
- if ( m_deleteNewSlideShows ) {
- delete m_newSlideShows;
- }
- else {
- delete m_oldSlideShows;
- }
-}
-
-void KPrSetCustomSlideShowsCommand::redo()
-{
- m_doc->setCustomSlideShows( m_newSlideShows );
- m_deleteNewSlideShows = false;
-}
-
-void KPrSetCustomSlideShowsCommand::undo()
-{
- m_doc->setCustomSlideShows( m_oldSlideShows );
- m_deleteNewSlideShows = true;
-}
diff --git a/kpresenter/part/commands/KPrSetCustomSlideShowsCommand.h b/kpresenter/part/commands/KPrSetCustomSlideShowsCommand.h
deleted file mode 100644
index 6cc29e2..0000000
--- a/kpresenter/part/commands/KPrSetCustomSlideShowsCommand.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* This file is part of the KDE project
- * Copyright (C) 2008 Thorsten Zachmann <zachmann at kde.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or ( at your option ) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef KPRSETCUSTOMSLIDESHOWSCOMMAND_H
-#define KPRSETCUSTOMSLIDESHOWSCOMMAND_H
-
-#include <kundo2command.h>
-
-class KPrCustomSlideShows;
-class KPrDocument;
-
-class KPrSetCustomSlideShowsCommand : public KUndo2Command
-{
-public:
- KPrSetCustomSlideShowsCommand( KPrDocument * doc, KPrCustomSlideShows * newSlideShows, KUndo2Command *parent = 0 );
- virtual ~KPrSetCustomSlideShowsCommand();
-
- /// redo the command
- virtual void redo();
- /// revert the actions done in redo
- virtual void undo();
-
-private:
- KPrDocument * m_doc;
- KPrCustomSlideShows * m_oldSlideShows;
- KPrCustomSlideShows * m_newSlideShows;
- bool m_deleteNewSlideShows;
-};
-
-#endif /* KPRSETCUSTOMSLIDESHOWSCOMMAND_H */
diff --git a/kpresenter/part/tests/CMakeLists.txt b/kpresenter/part/tests/CMakeLists.txt
index f9b56a6..85b0e24 100644
--- a/kpresenter/part/tests/CMakeLists.txt
+++ b/kpresenter/part/tests/CMakeLists.txt
@@ -17,3 +17,34 @@ kde4_add_unit_test(TestCustomSlideShows TESTNAME stage-part-TestCustomSlideShows
target_link_libraries(TestCustomSlideShows calligrastageprivate ${QT_QTTEST_LIBRARY})
+########### next target ###############
+
+set(TestEditCustomSlideShowsCommand_test_SRCS TestEditCustomSlideShowsCommand.cpp )
+
+kde4_add_unit_test(TestEditCustomSlideShowsCommand TESTNAME stage-part-TestEditCustomSlideShowsCommand ${TestEditCustomSlideShowsCommand_test_SRCS})
+
+target_link_libraries(TestEditCustomSlideShowsCommand calligrastageprivate ${QT_QTTEST_LIBRARY})
+
+########### next target ###############
+
+set(TestAddCustomSlideShowCommand_test_SRCS TestAddCustomSlideShowCommand.cpp )
+
+kde4_add_unit_test(TestAddCustomSlideShowCommand TESTNAME stage-part-TestAddCustomSlideShowCommand ${TestAddCustomSlideShowCommand_test_SRCS})
+
+target_link_libraries(TestAddCustomSlideShowCommand calligrastageprivate ${QT_QTTEST_LIBRARY})
+
+########### next target ###############
+
+set(TestDelCustomSlideShowCommand_test_SRCS TestDelCustomSlideShowCommand.cpp )
+
+kde4_add_unit_test(TestDelCustomSlideShowCommand TESTNAME stage-part-TestDelCustomSlideShowCommand ${TestDelCustomSlideShowCommand_test_SRCS})
+
+target_link_libraries(TestDelCustomSlideShowCommand calligrastageprivate ${QT_QTTEST_LIBRARY})
+
+########### next target ###############
+
+set(TestRenameCustomSlideShowCommand_test_SRCS TestRenameCustomSlideShowCommand.cpp )
+
+kde4_add_unit_test(TestRenameCustomSlideShowCommand TESTNAME stage-part-TestRenameCustomSlideShowCommand ${TestRenameCustomSlideShowCommand_test_SRCS})
+
+target_link_libraries(TestRenameCustomSlideShowCommand calligrastageprivate ${QT_QTTEST_LIBRARY})
diff --git a/kpresenter/part/ui/KPrConfigureSlideShowDialog.cpp b/kpresenter/part/ui/KPrConfigureSlideShowDialog.cpp
index 847a5a5..7117762 100644
--- a/kpresenter/part/ui/KPrConfigureSlideShowDialog.cpp
+++ b/kpresenter/part/ui/KPrConfigureSlideShowDialog.cpp
@@ -25,13 +25,14 @@
#include <KDebug>
#include "KPrDocument.h"
+#include "KPrView.h"
#include "KPrCustomSlideShows.h"
-#include "KPrCustomSlideShowsDialog.h"
-#include "commands/KPrSetCustomSlideShowsCommand.h"
+#include "KPrViewModeSlidesSorter.h"
-KPrConfigureSlideShowDialog::KPrConfigureSlideShowDialog( KPrDocument *document, QWidget *parent )
+KPrConfigureSlideShowDialog::KPrConfigureSlideShowDialog( KPrDocument *document, KPrView *parent )
: KDialog( parent )
, m_document( document )
+ , m_view(parent)
{
QWidget *widget = new QWidget( this );
@@ -70,33 +71,9 @@ QString KPrConfigureSlideShowDialog::activeCustomSlideShow() const
void KPrConfigureSlideShowDialog::editCustomSlideShow()
{
- KPrCustomSlideShows *finalSlideShows;
-
- KPrCustomSlideShowsDialog dialog( this, m_document->customSlideShows(), m_document, finalSlideShows );
- dialog.setModal( true );
- if ( dialog.exec() == QDialog::Accepted ) {
- m_document->addCommand( new KPrSetCustomSlideShowsCommand( m_document, finalSlideShows ) );
- QString activeSlideShow = ui.slidesComboBox->currentText();
- int index = ui.slidesComboBox->currentIndex();
-
- // re-add all custom slide shows
- ui.slidesComboBox->clear();
- ui.slidesComboBox->addItem( i18n( "All slides" ) );
- ui.slidesComboBox->addItems( finalSlideShows->names() );
-
- QList<QString> customSlideShows = finalSlideShows->names();
- if ( !customSlideShows.contains( activeSlideShow ) || index == 0 ) {
- index = 0;
- }
- else {
- index = customSlideShows.indexOf( activeSlideShow ) + 1;
- }
- Q_ASSERT( index < ui.slidesComboBox->count() );
- ui.slidesComboBox->setCurrentIndex( index );
- }
- else {
- delete finalSlideShows;
- }
+ m_view->slidesSorter()->setActiveCustomSlideShow(ui.slidesComboBox->currentIndex());
+ m_view->showSlidesSorter();
+ accept();
}
#include "KPrConfigureSlideShowDialog.moc"
diff --git a/kpresenter/part/ui/KPrConfigureSlideShowDialog.h b/kpresenter/part/ui/KPrConfigureSlideShowDialog.h
index 1c7794a..e8b1902 100644
--- a/kpresenter/part/ui/KPrConfigureSlideShowDialog.h
+++ b/kpresenter/part/ui/KPrConfigureSlideShowDialog.h
@@ -21,6 +21,7 @@
#define KPRCONFIGURESLIDESHOWDIALOG_H
#include <KDialog>
+class KPrView;
#include "ui_KPrConfigureSlideShow.h"
@@ -29,8 +30,9 @@ class KPrDocument;
class KPrConfigureSlideShowDialog : public KDialog
{
Q_OBJECT
+
public:
- explicit KPrConfigureSlideShowDialog( KPrDocument *document, QWidget *parent=0 );
+ explicit KPrConfigureSlideShowDialog( KPrDocument *document, KPrView *parent=0 );
QString activeCustomSlideShow() const;
@@ -40,6 +42,7 @@ private slots:
private:
Ui::KPrConfigureSlideShow ui;
KPrDocument *m_document;
+ KPrView *m_view;
};
#endif // KPRCONFIGUREPRESENTERVIEWDIALOG_H
diff --git a/kpresenter/part/ui/KPrCustomSlideShowsDialog.cpp b/kpresenter/part/ui/KPrCustomSlideShowsDialog.cpp
deleted file mode 100644
index da697e0..0000000
--- a/kpresenter/part/ui/KPrCustomSlideShowsDialog.cpp
+++ /dev/null
@@ -1,301 +0,0 @@
-/* This file is part of the KDE project
- Copyright (C) 2008 Carlos Licea <carlos.licea at kdemail.net>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
-*/
-
-#include "KPrCustomSlideShowsDialog.h"
-
-//Qt includes
-#include <QDebug>
-#include <QStringList>
-#include <QListWidgetItem>
-#include <QIcon>
-#include <QList>
-
-//KDE includes
-#include <KMessageBox>
-
-//Calligra includes
-#include <KoPAPageBase.h>
-#include <KPrDocument.h>
-
-//KPresenter includes
-#include <KPrCustomSlideShows.h>
-
-//so to be able to use it in a QVariant
-Q_DECLARE_METATYPE(KoPAPageBase*)
-
-KPrCustomSlideShowsDialog::KPrCustomSlideShowsDialog( QWidget *parent, KPrCustomSlideShows *slideShows,
- KPrDocument *doc, KPrCustomSlideShows *&newSlideShows )
-: QDialog(parent)
-, m_firstTime( true )
-, m_slideShows( new KPrCustomSlideShows(*slideShows) )
-, m_oldSlideShows(slideShows)
-, m_doc(doc)
-{
- m_uiWidget.setupUi( this );
- //Conections
- connect( m_uiWidget.addButton, SIGNAL( clicked() ), this, SLOT( addCustomSlideShow() ) );
- connect( m_uiWidget.okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
- connect( m_uiWidget.deleteButton, SIGNAL( clicked() ), this, SLOT( deleteCustomSlideShow() ) );
- connect( m_uiWidget.undoButton, SIGNAL( clicked() ), this, SLOT( loadCustomSlideShowsData() ) );
- connect( m_uiWidget.addSlideButton, SIGNAL( clicked() ), this, SLOT( addSlidesToCurrentSlideShow() ) );
- connect( m_uiWidget.customSlideShowsList, SIGNAL( currentItemChanged(QListWidgetItem*, QListWidgetItem*) ),
- this, SLOT( changedSelectedSlideshow(QListWidgetItem*, QListWidgetItem*) ) );
- connect( m_uiWidget.deleteSlideButton, SIGNAL( clicked() ),
- this, SLOT( removeSlidesFromCurrentSlideShow() ) );
- connect( m_uiWidget.currentSlidesList, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ),
- this, SLOT( removeSlidesFromCurrentSlideShow( QListWidgetItem* ) ) );
- connect( m_uiWidget.availableSlidesList, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ),
- this, SLOT( addSlidesToCurrentSlideShow( QListWidgetItem* ) ) );
-
- //Set the size of the icon
- m_uiWidget.availableSlidesList->setIconSize( QSize(75,75) );
- m_uiWidget.currentSlidesList->setIconSize( QSize(75,75) );
-
- //Make the newSlideShows be the same as m_slideShows
- newSlideShows = m_slideShows;
-
- //Load the CustomSlideShows already created
- loadCustomSlideShowsData();
-
- //Load the available slides
- int currentPage = 1;
- QListWidgetItem * item;
-
- foreach( KoPAPageBase* page, doc->pages() )
- {
- item = new QListWidgetItem( QIcon( page->thumbnail( QSize(75,75) ) ), i18n("Slide %1", currentPage++), m_uiWidget.availableSlidesList );
- item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
- item->setData( SlideData, QVariant::fromValue(page) );
- }
-}
-
-KPrCustomSlideShowsDialog::~KPrCustomSlideShowsDialog()
-{
-}
-
-void KPrCustomSlideShowsDialog::addCustomSlideShow()
-{
- //We create a different default name for every SlideShow:
- static int newSlideShowsCount = 1;
- while( m_slideShows->names().contains( i18n("New Slide Show %1", newSlideShowsCount) ) )
- {
- ++newSlideShowsCount;
- }
- QListWidgetItem * item = new QListWidgetItem( i18n("New Slide Show %1", newSlideShowsCount) );
- item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
- item->setData( SlideShowNameData, QVariant(i18n("New Slide Show %1", newSlideShowsCount)) );
-
- //we add it to the display and the slideShows
- m_uiWidget.customSlideShowsList->addItem( item );
-
- m_slideShows->insert( i18n("New Slide Show %1", newSlideShowsCount), QList<KoPAPageBase*>() );
-
- //Let the user choose the name
- m_uiWidget.customSlideShowsList->editItem( item );
-}
-
-void KPrCustomSlideShowsDialog::renameCustomSlideShow( QListWidgetItem *item )
-{
- //We disconect the signal so not to call this function over and over:
- disconnect( m_uiWidget.customSlideShowsList, SIGNAL( itemChanged( QListWidgetItem*) ),
- this, SLOT( renameCustomSlideShow(QListWidgetItem*) ) );
-
- // Empty string is not allowed as a name, if the name is empty, revert back to previous name
- if ( item->data( Qt::DisplayRole ).toString().isEmpty() ) {
- item->setText( item->data( SlideShowNameData ).toString() );
- }
- //If the name is not already in use, use it
- else if( !m_slideShows->names().contains( item->data( Qt::DisplayRole ).toString() ) )
- {
- m_slideShows->rename( item->data( SlideShowNameData ).toString(), item->data( Qt::DisplayRole ).toString() );
- item->setData( SlideShowNameData, item->data( Qt::DisplayRole ) );
- }
- //otherwise let the user know
- else
- {
- KMessageBox Message;
- Message.sorry(this, i18n("There cannot be two slideshows with the same name."), i18n("Error"), KMessageBox::Notify );
-
- item->setText( item->data( SlideShowNameData ).toString() );
- m_uiWidget.customSlideShowsList->editItem( item );
- }
-
- //Reconect the rename function.
- connect( m_uiWidget.customSlideShowsList, SIGNAL( itemChanged( QListWidgetItem*) ),
- this, SLOT( renameCustomSlideShow(QListWidgetItem*) ) );
-}
-
-void KPrCustomSlideShowsDialog::deleteCustomSlideShow()
-{
- //Ask the user if he is sure about it
- KMessageBox Message;
- int clickedButton = Message.warningContinueCancel(this, i18n("Are you sure you want to delete the selected slide show?"), i18n("Confirm action") );
-
- if( clickedButton == KMessageBox::Cancel )
- {
- return;
- }
-
- QListWidgetItem* item = m_uiWidget.customSlideShowsList->currentItem();
- //Use item, which points to current item, to calculate the row to
- //take it from the widget:
- m_uiWidget.customSlideShowsList->takeItem( m_uiWidget.customSlideShowsList->row(item) );
- if( item )
- {
- m_slideShows->remove( item->data(SlideShowNameData).toString() );
- delete item;
- }
- if( m_uiWidget.customSlideShowsList->count() == 0 )
- {
- m_selectedSlideShowName.clear();
- m_uiWidget.currentSlidesList->clear();
- m_uiWidget.addSlideButton->setEnabled( false );
- m_uiWidget.deleteButton->setEnabled( false );
- }
-}
-
-void KPrCustomSlideShowsDialog::loadCustomSlideShowsData()
-{
- //We disconect the signal so not to call the rename function over and over:
- disconnect( m_uiWidget.customSlideShowsList, SIGNAL( itemChanged( QListWidgetItem*) ),
- this, SLOT( renameCustomSlideShow(QListWidgetItem*) ) );
-
- //check if is our first load so to use the work already done
- if( !m_firstTime )
- {
- delete m_slideShows;
- m_slideShows = new KPrCustomSlideShows(*m_oldSlideShows);
- m_uiWidget.customSlideShowsList->clear();
- }
- m_firstTime = false;
-
- bool deleteEnabled = true;
- if( m_oldSlideShows->names().size() == 0 )
- {
- deleteEnabled = false;
- }
- m_uiWidget.deleteButton->setEnabled( deleteEnabled );
-
- //build, configure and insert every Item:
- QListWidgetItem * item;
- foreach( QString slideShowName, m_oldSlideShows->names() )
- {
- item = new QListWidgetItem( slideShowName, m_uiWidget.customSlideShowsList );
- item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
- item->setData( SlideShowNameData, QVariant(slideShowName) );
- }
-
- //clear the slides if no slideShow is left a selected
- if( m_uiWidget.customSlideShowsList->count() == 0 )
- {
- m_uiWidget.currentSlidesList->clear();
- }
- //Reconect the rename function.
- connect( m_uiWidget.customSlideShowsList, SIGNAL( itemChanged( QListWidgetItem*) ),
- this, SLOT( renameCustomSlideShow(QListWidgetItem*) ) );
-}
-
-void KPrCustomSlideShowsDialog::changedSelectedSlideshow(QListWidgetItem* current, QListWidgetItem* previous)
-{
- Q_UNUSED(previous);
-
- //If we aren't selecting anything don't do anything
- if( !current )
- {
- return;
- }
-
- m_uiWidget.currentSlidesList->clear();
-
- //if we have selected a slideShow we can safelly try to add slides to it
- m_uiWidget.addSlideButton->setEnabled( true );
- //and allow to delete slideShows
- m_uiWidget.deleteButton->setEnabled( true );
-
- //get the slideShow and its pages
- m_selectedSlideShowName = current->data( SlideShowNameData ).toString();
- QList<KoPAPageBase*> pages = m_slideShows->getByName( m_selectedSlideShowName );
-
- //insert them into the current slideShow list
- QListWidgetItem * item;
- foreach( KoPAPageBase* page, pages )
- {
- item = new QListWidgetItem( QIcon( page->thumbnail( QSize(75,75) ) ), i18n( "Slide %1", m_doc->pageIndex(page)+1 ), m_uiWidget.currentSlidesList );
- item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
- item->setData( SlideData, QVariant::fromValue<KoPAPageBase*>( page ) );
- }
-}
-
-void KPrCustomSlideShowsDialog::addSlidesToCurrentSlideShow()
-{
- //get the selected items and slideshow
- QList<QListWidgetItem*> selectedPages = m_uiWidget.availableSlidesList->selectedItems();
- QList<KoPAPageBase*> selectedSlideShow = m_slideShows->getByName( m_selectedSlideShowName );
-
- //insert the slides at the end and update the Widget
- foreach( QListWidgetItem* item, selectedPages )
- {
- KoPAPageBase* page( (item->data( SlideData ).value<KoPAPageBase*>()));
- selectedSlideShow.append( page );
-
- item = new QListWidgetItem( QIcon( page->thumbnail( QSize(75,75) ) ), i18n("Slide %1", m_doc->pageIndex(page)+1 ), m_uiWidget.currentSlidesList );
- item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
- item->setData( SlideData, QVariant::fromValue<KoPAPageBase*>( page ) );
- }
- //update the SlideShow with the resulting list
- m_slideShows->update( m_selectedSlideShowName, selectedSlideShow );
-}
-
-void KPrCustomSlideShowsDialog::addSlidesToCurrentSlideShow( QListWidgetItem* currentItem )
-{
- Q_UNUSED(currentItem);
- if( !m_selectedSlideShowName.isNull() )
- {
- addSlidesToCurrentSlideShow();
- }
-}
-
-void KPrCustomSlideShowsDialog::removeSlidesFromCurrentSlideShow()
-{
- //get the selected items and slideshow
- QList<QListWidgetItem*> selectedPages = m_uiWidget.currentSlidesList->selectedItems();
- if( m_selectedSlideShowName.isEmpty())
- return;
-
- QList<KoPAPageBase*> selectedSlideShow = m_slideShows->getByName( m_selectedSlideShowName );
-
- //remove the slides and update the widget
- foreach( QListWidgetItem* item, selectedPages )
- {
- int row = m_uiWidget.currentSlidesList->row(item);
- m_uiWidget.currentSlidesList->takeItem( row );
- selectedSlideShow.removeAt( row );
- delete item;
- }
- //update the selected SlideShow
- m_slideShows->update( m_selectedSlideShowName, selectedSlideShow );
-}
-
-void KPrCustomSlideShowsDialog::removeSlidesFromCurrentSlideShow( QListWidgetItem* currentItem )
-{
- Q_UNUSED(currentItem);
- removeSlidesFromCurrentSlideShow();
-}
-
-#include "KPrCustomSlideShowsDialog.moc"
diff --git a/kpresenter/part/ui/KPrCustomSlideShowsDialog.h b/kpresenter/part/ui/KPrCustomSlideShowsDialog.h
deleted file mode 100644
index f5d53f9..0000000
--- a/kpresenter/part/ui/KPrCustomSlideShowsDialog.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* This file is part of the KDE project
- Copyright (C) 2008 Carlos Licea <carlos.licea at kdemail.net>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
-*/
-
-#ifndef KPRCUSTOMSLIDESHOWSDIALOG_H
-#define KPRCUSTOMSLIDESHOWSDIALOG_H
-
-#include <QtGui/QDialog>
-
-#include "ui_KPrCustomSlideShowsDialog.h"
-
-class KPrCustomSlideShows;
-class KoPAPageBase;
-class QListWidgetItem;
-class KPrCustomSlideShows;
-class KPrDocument;
-
-class KPrCustomSlideShowsDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- KPrCustomSlideShowsDialog( QWidget *parent, KPrCustomSlideShows *slideShows, KPrDocument *doc, KPrCustomSlideShows *&newSlideShows );
- ~KPrCustomSlideShowsDialog();
-private Q_SLOTS:
- void addCustomSlideShow();
- void addSlidesToCurrentSlideShow();
- void addSlidesToCurrentSlideShow( QListWidgetItem* currentItem );
- void deleteCustomSlideShow();
- void renameCustomSlideShow( QListWidgetItem *item );
- void loadCustomSlideShowsData();
- void changedSelectedSlideshow( QListWidgetItem *current, QListWidgetItem *previous );
- void removeSlidesFromCurrentSlideShow();
- void removeSlidesFromCurrentSlideShow( QListWidgetItem* currentItem );
-
-// Q_SIGNALS:
-private:
- enum {
- SlideShowNameData = 33,
- SlideData = 34
- };
-
- bool m_firstTime;
- QString m_selectedSlideShowName;
-
- Ui::CustomSlideShowsWidget m_uiWidget;
- KPrCustomSlideShows *m_slideShows;
- KPrCustomSlideShows *m_oldSlideShows;
- KPrDocument *m_doc;
-};
-#endif
diff --git a/kpresenter/part/ui/KPrCustomSlideShowsDialog.ui b/kpresenter/part/ui/KPrCustomSlideShowsDialog.ui
deleted file mode 100644
index be25bc8..0000000
--- a/kpresenter/part/ui/KPrCustomSlideShowsDialog.ui
+++ /dev/null
@@ -1,223 +0,0 @@
-<ui version="4.0" >
- <class>CustomSlideShowsWidget</class>
- <widget class="QWidget" name="CustomSlideShowsWidget" >
- <property name="windowModality" >
- <enum>Qt::WindowModal</enum>
- </property>
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>771</width>
- <height>507</height>
- </rect>
- </property>
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Minimum" hsizetype="Minimum" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="windowTitle" >
- <string>Custom Slideshows editor</string>
- </property>
- <layout class="QGridLayout" >
- <item rowspan="5" row="0" column="0" >
- <layout class="QVBoxLayout" >
- <item>
- <widget class="QLabel" name="label" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text" >
- <string>Customs Slideshows</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QListWidget" name="customSlideShowsList" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Expanding" hsizetype="Ignored" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="selectionMode" >
- <enum>QAbstractItemView::SingleSelection</enum>
- </property>
- <property name="selectionBehavior" >
- <enum>QAbstractItemView::SelectItems</enum>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="addButton" >
- <property name="text" >
- <string>Add new slideshow</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="deleteButton" >
- <property name="text" >
- <string>Delete slideshow</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="0" column="1" >
- <widget class="QLabel" name="label_3" >
- <property name="text" >
- <string>Available Slides</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1" >
- <widget class="QListWidget" name="availableSlidesList" >
- <property name="dragEnabled" >
- <bool>true</bool>
- </property>
- <property name="dragDropMode" >
- <enum>QAbstractItemView::DropOnly</enum>
- </property>
- <property name="selectionMode" >
- <enum>QAbstractItemView::ExtendedSelection</enum>
- </property>
- <property name="movement" >
- <enum>QListView::Static</enum>
- </property>
- <property name="flow" >
- <enum>QListView::LeftToRight</enum>
- </property>
- <property name="viewMode" >
- <enum>QListView::IconMode</enum>
- </property>
- </widget>
- </item>
- <item row="2" column="1" >
- <layout class="QHBoxLayout" >
- <item>
- <widget class="QLabel" name="label_2" >
- <property name="text" >
- <string>Current Slideshow:</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0" >
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="addSlideButton" >
- <property name="enabled" >
- <bool>false</bool>
- </property>
- <property name="text" >
- <string>Add Slide</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="deleteSlideButton" >
- <property name="text" >
- <string>Delete Slide</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="3" column="1" >
- <widget class="QListWidget" name="currentSlidesList" >
- <property name="verticalScrollBarPolicy" >
- <enum>Qt::ScrollBarAsNeeded</enum>
- </property>
- <property name="dragEnabled" >
- <bool>true</bool>
- </property>
- <property name="dragDropMode" >
- <enum>QAbstractItemView::DropOnly</enum>
- </property>
- <property name="movement" >
- <enum>QListView::Static</enum>
- </property>
- <property name="flow" >
- <enum>QListView::LeftToRight</enum>
- </property>
- <property name="viewMode" >
- <enum>QListView::IconMode</enum>
- </property>
- </widget>
- </item>
- <item row="4" column="1" >
- <layout class="QHBoxLayout" >
- <item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0" >
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="undoButton" >
- <property name="text" >
- <string>Undo</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="okButton" >
- <property name="text" >
- <string>Ok</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="closeButton" >
- <property name="text" >
- <string>Close</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections>
- <connection>
- <sender>closeButton</sender>
- <signal>clicked()</signal>
- <receiver>CustomSlideShowsWidget</receiver>
- <slot>close()</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>719</x>
- <y>381</y>
- </hint>
- <hint type="destinationlabel" >
- <x>452</x>
- <y>393</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/libs/kopageapp/KoPADocument.cpp b/libs/kopageapp/KoPADocument.cpp
index 2a03e42..a88eac0 100644
--- a/libs/kopageapp/KoPADocument.cpp
+++ b/libs/kopageapp/KoPADocument.cpp
@@ -560,6 +560,13 @@ void KoPADocument::removePage( KoPAPageBase * page )
addCommand( command );
}
+
+void KoPADocument::removePages(QList<KoPAPageBase *> &pages)
+{
+ KoPAPageDeleteCommand *command = new KoPAPageDeleteCommand(this, pages);
+ addCommand(command);
+}
+
void KoPADocument::pageRemoved( KoPAPageBase * page, KUndo2Command * parent )
{
Q_UNUSED( page );
diff --git a/libs/kopageapp/KoPADocument.h b/libs/kopageapp/KoPADocument.h
index 9347ae9..cfc9822 100644
--- a/libs/kopageapp/KoPADocument.h
+++ b/libs/kopageapp/KoPADocument.h
@@ -155,6 +155,15 @@ public:
*/
virtual void removePage( KoPAPageBase * page );
+ /**
+ * Remove the given pages from the document
+ *
+ * This generates the command and adds the command that deletes the pages
+ *
+ * @param pages The list of pages that gets removed
+ */
+ virtual void removePages(QList<KoPAPageBase*> &pages);
+
void addShape( KoShape *shape );
void removeShape( KoShape* shape );
diff --git a/libs/kopageapp/KoPADocumentStructureDocker.cpp b/libs/kopageapp/KoPADocumentStructureDocker.cpp
index 02af382..a17e85c 100644
--- a/libs/kopageapp/KoPADocumentStructureDocker.cpp
+++ b/libs/kopageapp/KoPADocumentStructureDocker.cpp
@@ -380,7 +380,7 @@ void KoPADocumentStructureDocker::deleteItem()
cmd = new KoShapeDeleteCommand( m_doc, selectedShapes );
}
else if (!selectedPages.isEmpty() && selectedPages.count() < m_doc->pages().count()) {
- cmd = new KoPAPageDeleteCommand(m_doc, selectedPages);
+ m_doc->removePages(selectedPages);
}
if( cmd )
More information about the kde-doc-english
mailing list