]> git.sesse.net Git - kdenlive/commitdiff
ItemDelegate has been moved in ProjectListView.
authorJean-Nicolas Artaud <jeannicolasartaud@gmail.com>
Sat, 11 Jan 2014 15:09:06 +0000 (16:09 +0100)
committerJean-Nicolas Artaud <jeannicolasartaud@gmail.com>
Sat, 11 Jan 2014 15:09:06 +0000 (16:09 +0100)
src/projectlist.cpp
src/projectlist.h
src/projectlistview.cpp
src/projectlistview.h

index 8016c7cc84bf9f24c1cfbd8a7d6e3e2d2d0c5d5f..286860f69d94fa0b92de77be808c8e5aa33d31a2 100644 (file)
@@ -3870,93 +3870,3 @@ void ProjectList::checkCamcorderFilters(DocClipBase *clip, QMap <QString, QStrin
 }*/
 
 #include "projectlist.moc"
-
-
-void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
-    if (index.column() == 0 && !index.data(DurationRole).isNull()) {
-        QRect r1 = option.rect;
-        painter->save();
-        QStyleOptionViewItemV4 opt(option);
-        QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
-        style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
-
-        if (option.state & QStyle::State_Selected) {
-            painter->setPen(option.palette.highlightedText().color());
-        }
-        const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
-        QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
-        QPoint pixmapPoint(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2);
-        painter->drawPixmap(pixmapPoint, pixmap);
-        int decoWidth = pixmap.width() + 2 * textMargin;
-
-        QFont font = painter->font();
-        font.setBold(true);
-        painter->setFont(font);
-        int mid = (int)((r1.height() / 2));
-        r1.adjust(decoWidth, 0, 0, -mid);
-        QRect r2 = option.rect;
-        r2.adjust(decoWidth, mid, 0, 0);
-        painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom, index.data().toString());
-        font.setBold(false);
-        painter->setFont(font);
-        QString subText = index.data(DurationRole).toString();
-        int usage = index.data(UsageRole).toInt();
-        if (usage != 0) subText.append(QString::fromLatin1(" (%1)").arg(usage));
-        QRectF bounding;
-        painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
-        int jobProgress = index.data(Qt::UserRole + 5).toInt();
-        if (jobProgress != 0 && jobProgress != JOBDONE && jobProgress != JOBABORTED) {
-            if (jobProgress != JOBCRASHED) {
-                // Draw job progress bar
-                QColor color = option.palette.alternateBase().color();
-                color.setAlpha(150);
-                painter->setPen(option.palette.link().color());
-                QRect progress(pixmapPoint.x() + 2, pixmapPoint.y() + pixmap.height() - 9, pixmap.width() - 4, 7);
-                painter->setBrush(QBrush(color));
-                painter->drawRect(progress);
-                painter->setBrush(option.palette.link());
-                progress.adjust(2, 2, -2, -2);
-                if (jobProgress == JOBWAITING) {
-                    progress.setLeft(progress.right() - 2);
-                    painter->drawRect(progress);
-                    progress.moveLeft(progress.left() - 5);
-                    painter->drawRect(progress);
-                }
-                else if (jobProgress > 0) {
-                    progress.setWidth(progress.width() * jobProgress / 100);
-                    painter->drawRect(progress);
-                }
-            } else if (jobProgress == JOBCRASHED) {
-                QString jobText = index.data(Qt::UserRole + 7).toString();
-                if (!jobText.isEmpty()) {
-                    QRectF txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, QLatin1Char(' ') + jobText + QLatin1Char(' ') );
-                    painter->setPen(Qt::NoPen);
-                    painter->setBrush(option.palette.highlight());
-                    painter->drawRoundedRect(txtBounding, 2, 2);
-                    painter->setPen(option.palette.highlightedText().color());
-                    painter->drawText(txtBounding, Qt::AlignCenter, jobText);
-                }
-            }
-        }
-
-        painter->restore();
-    } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
-        if (index.data().toString().isEmpty()) {
-            QStyledItemDelegate::paint(painter, option, index);
-            return;
-        }
-        QRect r1 = option.rect;
-        if (option.state & (QStyle::State_Selected)) {
-            painter->fillRect(r1, option.palette.highlight());
-        }
-#ifdef NEPOMUK
-        KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
-#endif
-#ifdef NEPOMUKCORE
-        KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
-#endif
-
-    } else {
-        QStyledItemDelegate::paint(painter, option, index);
-    }
-}
index 9ba4b355408113be9533451704263f76d1236fe8..d24a1d02df41b759b846ce78e3de12c350854c68 100644 (file)
@@ -27,7 +27,6 @@
 #include <QToolButton>
 #include <QTreeWidget>
 #include <QPainter>
-#include <QStyledItemDelegate>
 #include <QUndoStack>
 #include <QTimer>
 #include <QApplication>
@@ -101,6 +100,7 @@ class Render;
 class KdenliveDoc;
 class DocClipBase;
 class AbstractClipJob;
+class ItemDelegate;
 
 const int NameRole = Qt::UserRole;
 const int DurationRole = NameRole + 1;
@@ -123,19 +123,6 @@ private slots:
     void slotTimeLineFinished();
 };
 
-
-class ItemDelegate: public QStyledItemDelegate
-{
-public:
-    ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
-    }
-    
-    /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
-    }*/
-
-    void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
-};
-
 class ProjectList : public QWidget
 {
     Q_OBJECT
index 6267017a422cf0e5bb3438a54b53211fb799e2de..af26e4caafc75f1f9231ead0e1b44f8277e79984 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
  ***************************************************************************/
 
-
+// Self
 #include "projectlistview.h"
-#include "projectitem.h"
-#include "subprojectitem.h"
-#include "folderprojectitem.h"
-#include "kdenlivesettings.h"
 
+// Qt
+#include <QApplication>
+#include <QHeaderView>
+#include <QAction>
+
+// KDE
 #include <KDebug>
 #include <KMenu>
 #include <KLocalizedString>
 
-#include <QApplication>
-#include <QHeaderView>
-#include <QAction>
+// KDEnlive
+#include "projectlistview.h"
+#include "projectitem.h"
+#include "subprojectitem.h"
+#include "folderprojectitem.h"
+#include "kdenlivesettings.h"
 
-ProjectListView::ProjectListView(QWidget *parent) :
-        QTreeWidget(parent),
-        m_dragStarted(false)
+ProjectListView::ProjectListView(QWidget *parent)
+    : QTreeWidget(parent)
+    , m_dragStarted(false)
 {
     setSelectionMode(QAbstractItemView::ExtendedSelection);
     setDragDropMode(QAbstractItemView::DragDrop);
@@ -65,9 +70,16 @@ ProjectListView::ProjectListView(QWidget *parent) :
     sortByColumn(0, Qt::AscendingOrder);
     setSortingEnabled(true);
     installEventFilter(this);
-    if (!KdenliveSettings::showdescriptioncolumn()) hideColumn(1);
-    if (!KdenliveSettings::showratingcolumn()) hideColumn(2);
-    if (!KdenliveSettings::showdatecolumn()) hideColumn(3);
+
+    if (!KdenliveSettings::showdescriptioncolumn()) {
+        hideColumn(1);
+    }
+    if (!KdenliveSettings::showratingcolumn()) {
+        hideColumn(2);
+    }
+    if (!KdenliveSettings::showdatecolumn()) {
+        hideColumn(3);
+    }
 }
 
 ProjectListView::~ProjectListView()
@@ -412,4 +424,97 @@ Qt::DropActions ProjectListView::supportedDropActions() const
     return Qt::MoveAction | Qt::CopyAction;
 }
 
+void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+    if (index.column() == 0 && !index.data(ItemDelegate::DurationRole).isNull()) {
+        QRect r1 = option.rect;
+        painter->save();
+        QStyleOptionViewItemV4 opt(option);
+        QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
+        style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
+
+        if (option.state & QStyle::State_Selected) {
+            painter->setPen(option.palette.highlightedText().color());
+        }
+        const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
+        QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
+        QPoint pixmapPoint(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2);
+        painter->drawPixmap(pixmapPoint, pixmap);
+        int decoWidth = pixmap.width() + 2 * textMargin;
+
+        QFont font = painter->font();
+        font.setBold(true);
+        painter->setFont(font);
+        int mid = (int)((r1.height() / 2));
+        r1.adjust(decoWidth, 0, 0, -mid);
+        QRect r2 = option.rect;
+        r2.adjust(decoWidth, mid, 0, 0);
+        painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom, index.data().toString());
+        font.setBold(false);
+        painter->setFont(font);
+        QString subText = index.data(ItemDelegate::DurationRole).toString();
+        int usage = index.data(ItemDelegate::UsageRole).toInt();
+        if (usage != 0) {
+            subText.append(QString::fromLatin1(" (%1)").arg(usage));
+        }
+
+        QRectF bounding;
+        painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
+        int jobProgress = index.data(Qt::UserRole + 5).toInt();
+        if (jobProgress != 0 && jobProgress != JOBDONE && jobProgress != JOBABORTED) {
+            if (jobProgress != JOBCRASHED) {
+                // Draw job progress bar
+                QColor color = option.palette.alternateBase().color();
+                color.setAlpha(150);
+                painter->setPen(option.palette.link().color());
+                QRect progress(pixmapPoint.x() + 2, pixmapPoint.y() + pixmap.height() - 9, pixmap.width() - 4, 7);
+                painter->setBrush(QBrush(color));
+                painter->drawRect(progress);
+                painter->setBrush(option.palette.link());
+                progress.adjust(2, 2, -2, -2);
+                if (jobProgress == JOBWAITING) {
+                    progress.setLeft(progress.right() - 2);
+                    painter->drawRect(progress);
+                    progress.moveLeft(progress.left() - 5);
+                    painter->drawRect(progress);
+                }
+                else if (jobProgress > 0) {
+                    progress.setWidth(progress.width() * jobProgress / 100);
+                    painter->drawRect(progress);
+                }
+            } else if (jobProgress == JOBCRASHED) {
+                QString jobText = index.data(Qt::UserRole + 7).toString();
+                if (!jobText.isEmpty()) {
+                    QRectF txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, QLatin1Char(' ') + jobText + QLatin1Char(' ') );
+                    painter->setPen(Qt::NoPen);
+                    painter->setBrush(option.palette.highlight());
+                    painter->drawRoundedRect(txtBounding, 2, 2);
+                    painter->setPen(option.palette.highlightedText().color());
+                    painter->drawText(txtBounding, Qt::AlignCenter, jobText);
+                }
+            }
+        }
+
+        painter->restore();
+    } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
+        if (index.data().toString().isEmpty()) {
+            QStyledItemDelegate::paint(painter, option, index);
+            return;
+        }
+        QRect r1 = option.rect;
+        if (option.state & (QStyle::State_Selected)) {
+            painter->fillRect(r1, option.palette.highlight());
+        }
+#ifdef NEPOMUK
+        KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
+#endif
+#ifdef NEPOMUKCORE
+        KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
+#endif
+
+    } else {
+        QStyledItemDelegate::paint(painter, option, index);
+    }
+}
+
 #include "projectlistview.moc"
index b43aa26c25cea94a5a6034c68a86fcf9538c17af..67a7823f7e910759a45eb5e8725547b0db35b29d 100644 (file)
 #include <QTreeWidget>
 #include <QContextMenuEvent>
 #include <QPainter>
+#include <QStyledItemDelegate>
 
 class DocClipBase;
 
 
+class ItemDelegate: public QStyledItemDelegate
+{
+public:
+    ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
+    }
+
+    /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
+    }*/
+
+    void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+
+private:
+    enum ItemRole {
+        NameRole = Qt::UserRole,
+        DurationRole,
+        UsageRole
+    };
+};
+
 class ProjectListView : public QTreeWidget
 {
     Q_OBJECT