[kde-doc-english] [calligra/stage-gsoc-paulm] kpresenter/part: Enhace Visual Apparience of Slides Sorter View

Paul Mendez paulestebanms at gmail.com
Fri Jun 24 23:24:26 CEST 2011


Git commit 09734257e8c00a545496eab29e151060c7dac3db by Paul Mendez.
Committed on 21/06/2011 at 03:05.
Pushed by mendez into branch 'stage-gsoc-paulm'.

Enhace Visual Apparience of Slides Sorter View

Add more space between slides thumbnails and numeration on top of them
Make more visible the line drawn when dragging slides

GUI: Add more space between slides thumbnails and numeration on top of
them
Make more visible the line drawn when dragging slides

M  +1    -0    kpresenter/part/CMakeLists.txt     
M  +12   -6    kpresenter/part/KPrSlidesManagerView.cpp     
M  +0    -1    kpresenter/part/KPrSlidesSorterDocumentModel.cpp     
A  +55   -0    kpresenter/part/KPrSlidesSorterItemDelegate.cpp         [License: LGPL (v2+)]
A  +40   -0    kpresenter/part/KPrSlidesSorterItemDelegate.h         [License: LGPL (v2+)]
M  +15   -8    kpresenter/part/KPrViewModeSlidesSorter.cpp     
M  +0    -1    kpresenter/part/KPrViewModeSlidesSorter.h     

http://commits.kde.org/calligra/09734257e8c00a545496eab29e151060c7dac3db

diff --git a/kpresenter/part/CMakeLists.txt b/kpresenter/part/CMakeLists.txt
index 80bbd45..b885898 100644
--- a/kpresenter/part/CMakeLists.txt
+++ b/kpresenter/part/CMakeLists.txt
@@ -72,6 +72,7 @@ set( calligrastageprivate_LIB_SRCS
      KPrSelectionManager.cpp
      KPrSelectionToggle.cpp
      KPrCustomSlideShowsModel.cpp
+     KPrSlidesSorterItemDelegate.cpp
 
      commands/KPrAnimationCreateCommand.cpp
      commands/KPrPageEffectSetCommand.cpp
diff --git a/kpresenter/part/KPrSlidesManagerView.cpp b/kpresenter/part/KPrSlidesManagerView.cpp
index 0964e35..c9ab129 100644
--- a/kpresenter/part/KPrSlidesManagerView.cpp
+++ b/kpresenter/part/KPrSlidesManagerView.cpp
@@ -43,6 +43,7 @@ KPrSlidesManagerView::KPrSlidesManagerView(QWidget *parent)
     setDragEnabled(true);
     setAcceptDrops(true);
     setDropIndicatorShown(true);
+    setSpacing(m_itemSize.width()/10);
     viewport()->installEventFilter(this);
 }
 
@@ -58,19 +59,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);
+        painter.setPen(pen);
         painter.drawLine(line);
     }
 }
@@ -150,11 +153,13 @@ void KPrSlidesManagerView::dragLeaveEvent(QDragLeaveEvent *e)
 
 void KPrSlidesManagerView::focusOutEvent(QFocusEvent *event)
 {
+    Q_UNUSED(event);
     emit focusLost();
 }
 
 void KPrSlidesManagerView::focusInEvent(QFocusEvent *event)
 {
+    Q_UNUSED(event);
     emit focusGot();
 }
 
@@ -177,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)
@@ -276,17 +282,17 @@ 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() - 20) / (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() - 20) / 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());
diff --git a/kpresenter/part/KPrSlidesSorterDocumentModel.cpp b/kpresenter/part/KPrSlidesSorterDocumentModel.cpp
index 355c231..f6ec591 100644
--- a/kpresenter/part/KPrSlidesSorterDocumentModel.cpp
+++ b/kpresenter/part/KPrSlidesSorterDocumentModel.cpp
@@ -41,7 +41,6 @@
 #include <QApplication>
 #include <QMenu>
 
-
 KPrSlidesSorterDocumentModel::KPrSlidesSorterDocumentModel(KPrViewModeSlidesSorter *viewModeSlidesSorter, QWidget *parent, KoPADocument *document)
    : QAbstractListModel(parent)
    , m_viewModeSlidesSorter(viewModeSlidesSorter)
diff --git a/kpresenter/part/KPrSlidesSorterItemDelegate.cpp b/kpresenter/part/KPrSlidesSorterItemDelegate.cpp
new file mode 100644
index 0000000..72a7a91
--- /dev/null
+++ b/kpresenter/part/KPrSlidesSorterItemDelegate.cpp
@@ -0,0 +1,55 @@
+/* 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 "KPrSlidesSorterItemDelegate.h"
+
+//Calligra headers
+#include <KoPADocument.h>
+
+//Qt headers
+#include <QPainter>
+
+KPrSlidesSorterItemDelegate::KPrSlidesSorterItemDelegate(KoPADocument *document, QObject *parent)
+    : QStyledItemDelegate(parent)
+    , m_document(document)
+{
+}
+
+KPrSlidesSorterItemDelegate::~KPrSlidesSorterItemDelegate()
+{
+
+}
+
+void KPrSlidesSorterItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+    QStyledItemDelegate::paint(painter, option, index);
+    painter->save();
+    painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
+    QFont font = option.font;
+    QFontMetrics fm(font);
+    QString slideNumber = QString("%1").arg(index.row() + 1);
+    QRect slideNumberRect = option.rect;
+    slideNumberRect.setLeft(option.rect.left() + 5);
+    slideNumberRect.setTop(option.rect.top() + 5);
+    slideNumberRect.setBottom(slideNumberRect.top() + fm.height() + 6);
+    slideNumberRect.setRight(option.rect.left() + 30);
+    painter->setFont(font);
+    painter->drawText(slideNumberRect, slideNumber);
+    painter->restore();
+}
diff --git a/kpresenter/part/KPrSlidesSorterItemDelegate.h b/kpresenter/part/KPrSlidesSorterItemDelegate.h
new file mode 100644
index 0000000..99d82ec
--- /dev/null
+++ b/kpresenter/part/KPrSlidesSorterItemDelegate.h
@@ -0,0 +1,40 @@
+/* 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 KPRSLIDESSORTERITEMDELEGATE_H
+#define KPRSLIDESSORTERITEMDELEGATE_H
+
+#include <QStyledItemDelegate>
+class KoPADocument;
+
+class KPrSlidesSorterItemDelegate: public QStyledItemDelegate
+{
+    Q_OBJECT
+public:
+    explicit KPrSlidesSorterItemDelegate(KoPADocument *document, QObject *parent = 0);
+
+    ~KPrSlidesSorterItemDelegate();
+
+    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
+
+private:
+    KoPADocument *m_document;
+};
+
+#endif // KPRSLIDESSORTERITEMDELEGATE_H
diff --git a/kpresenter/part/KPrViewModeSlidesSorter.cpp b/kpresenter/part/KPrViewModeSlidesSorter.cpp
index 9e451fd..3b1a0ba 100644
--- a/kpresenter/part/KPrViewModeSlidesSorter.cpp
+++ b/kpresenter/part/KPrViewModeSlidesSorter.cpp
@@ -41,6 +41,7 @@
 #include "KPrCustomSlideShowsModel.h"
 #include "KPrDocument.h"
 #include "KPrCustomSlideShows.h"
+#include "KPrSlidesSorterItemDelegate.h"
 #include "commands/KPrSetCustomSlideShowsCommand.h"
 
 #include <KoResourceManager.h>
@@ -170,8 +171,14 @@ KPrViewModeSlidesSorter::KPrViewModeSlidesSorter(KoPAView *view, KoPACanvas *can
     connect(view, SIGNAL(selectAllRequested()), m_slidesSorterView, SLOT(selectAll()));
     connect(view, SIGNAL(deselectAllRequested()), m_slidesSorterView, SLOT(clearSelection()));
 
-    //install selection manager for Slides Sorter View
-    m_selectionManagerSlidesSorter = new KPrSelectionManager(m_slidesSorterView);
+    //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(view->kopaDocument(), m_slidesSorterView);
+    m_slidesSorterView->setItemDelegate(slidesSorterDelegate);
 }
 
 KPrViewModeSlidesSorter::~KPrViewModeSlidesSorter()
@@ -440,8 +447,8 @@ void KPrViewModeSlidesSorter::addSlide()
 
 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());
 
 }
 
@@ -532,7 +539,7 @@ void KPrViewModeSlidesSorter::slidesSorterContextMenu(QContextMenuEvent *event)
     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()));
 
-    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()));
@@ -722,13 +729,13 @@ void KPrViewModeSlidesSorter::selectSlides(const QList<KoPAPageBase *> &slides)
         return;
     }
 
-    m_slidesSorter->clearSelection();
+    m_slidesSorterView->clearSelection();
 
     foreach (KoPAPageBase *slide, slides) {
         int row = m_view->kopaDocument()->pageIndex(slide);
-        QModelIndex index = m_documentModel->index(row, 0, QModelIndex());
+        QModelIndex index = m_slidesSorterModel->index(row, 0, QModelIndex());
         if (index.isValid()) {
-            m_slidesSorter->selectionModel()->select(index, QItemSelectionModel::Select);
+            m_slidesSorterView->selectionModel()->select(index, QItemSelectionModel::Select);
         }
     }
 }
diff --git a/kpresenter/part/KPrViewModeSlidesSorter.h b/kpresenter/part/KPrViewModeSlidesSorter.h
index 3b16694..de40eb2 100644
--- a/kpresenter/part/KPrViewModeSlidesSorter.h
+++ b/kpresenter/part/KPrViewModeSlidesSorter.h
@@ -131,7 +131,6 @@ private:
     KPrSlidesManagerView *m_customSlideShowView;
     KPrSlidesSorterDocumentModel *m_slidesSorterModel;
     int m_zoom;
-    KPrSelectionManager *m_selectionManagerSlidesSorter;
     QWidget *m_centralWidget;
     KPrCustomSlideShowsModel *m_customSlideShowModel;
     QSize m_iconSize;



More information about the kde-doc-english mailing list