]> git.sesse.net Git - kdenlive/commitdiff
ProjectList cleaningh
authorJean-Nicolas Artaud <jeannicolasartaud@gmail.com>
Sat, 11 Jan 2014 14:25:30 +0000 (15:25 +0100)
committerJean-Nicolas Artaud <jeannicolasartaud@gmail.com>
Sat, 11 Jan 2014 14:25:30 +0000 (15:25 +0100)
 - Put InvalidDialog out of the ProjectList files.
 - Put the paint method out the header, in the cpp file.

src/CMakeLists.txt
src/projectlist.cpp
src/projectlist.h
src/widgets/CMakeLists.txt [new file with mode: 0644]
src/widgets/invaliddialog.cpp [new file with mode: 0644]
src/widgets/invaliddialog.h [new file with mode: 0644]

index 57283cf373061bafd44a08195c7fb66f8704050a..c784aafcc3dc15edca7bddd6f99954387b9a378c 100644 (file)
@@ -93,6 +93,7 @@ add_subdirectory(onmonitoritems)
 add_subdirectory(scopes)
 add_subdirectory(simplekeyframes)
 add_subdirectory(stopmotion)
+add_subdirectory(widgets)
 
 if(QJSON_FOUND)
   add_subdirectory(onmonitoritems/rotoscoping)
index ccdaed495d30cbd333efe0654b6ea158aa08ac5e..8016c7cc84bf9f24c1cfbd8a7d6e3e2d2d0c5d5f 100644 (file)
@@ -185,44 +185,6 @@ void SmallInfoLabel::slotSetJobCount(int jobCount)
     
 }
 
-
-InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
-{
-    setCaption(caption);
-    if (infoOnly) setButtons(KDialog::Ok);
-    else setButtons(KDialog::Yes | KDialog::No);
-    QWidget *w = new QWidget(this);
-    QVBoxLayout *l = new QVBoxLayout;
-    l->addWidget(new QLabel(message));
-    m_clipList = new QListWidget;
-    l->addWidget(m_clipList);
-    w->setLayout(l);
-    setMainWidget(w);
-}
-
-InvalidDialog::~InvalidDialog()
-{
-    delete m_clipList;
-}
-
-
-void InvalidDialog::addClip(const QString &id, const QString &path)
-{
-    QListWidgetItem *item = new QListWidgetItem(path);
-    item->setData(Qt::UserRole, id);
-    m_clipList->addItem(item);
-}
-
-QStringList InvalidDialog::getIds() const
-{
-    QStringList ids;
-    for (int i = 0; i < m_clipList->count(); ++i) {
-        ids << m_clipList->item(i)->data(Qt::UserRole).toString();
-    }
-    return ids;
-}
-
-
 ProjectList::ProjectList(QWidget *parent) :
     QWidget(parent)
   , m_render(NULL)
@@ -1854,11 +1816,9 @@ void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
         if (!path.isEmpty()) {
             if (m_invalidClipDialog) {
                 m_invalidClipDialog->addClip(id, path);
-                qDebug() << "Toto";
                 return;
             }
             else {
-                qDebug() << "Tata";
                 if (replace)
                     m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"),  i18n("Clip is invalid, will be removed from project."), replace, kapp->activeWindow());
                 else {
@@ -3910,3 +3870,93 @@ 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 b944eea1425c8ce91d24d6d1ec4939c5cdb1477a..9ba4b355408113be9533451704263f76d1236fe8 100644 (file)
@@ -59,7 +59,7 @@
 #include "folderprojectitem.h"
 #include "subprojectitem.h"
 #include "projecttree/abstractclipjob.h"
-#include <kdialog.h>
+#include "widgets/invaliddialog.h"
 
 #if KDE_IS_VERSION(4,7,0)
 #include <KMessageWidget>
@@ -123,18 +123,6 @@ private slots:
     void slotTimeLineFinished();
 };
 
-class InvalidDialog: public KDialog
-{
-    Q_OBJECT
-public:
-    explicit InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent = 0);
-    ~InvalidDialog();
-    void addClip(const QString &id, const QString &path);
-    QStringList getIds() const;
-private:
-    QListWidget *m_clipList;
-};
-
 
 class ItemDelegate: public QStyledItemDelegate
 {
@@ -145,94 +133,7 @@ public:
     /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
     }*/
 
-    void 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);
-        }
-    }
+    void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
 };
 
 class ProjectList : public QWidget
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1f649ee
--- /dev/null
@@ -0,0 +1,6 @@
+set(kdenlive_SRCS
+  ${kdenlive_SRCS}
+  widgets/invaliddialog.cpp
+  PARENT_SCOPE
+)
+
diff --git a/src/widgets/invaliddialog.cpp b/src/widgets/invaliddialog.cpp
new file mode 100644 (file)
index 0000000..e8d1e34
--- /dev/null
@@ -0,0 +1,73 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *               2013 by Jean-Nicolas Artaud (jeannicolasartaud@gmail.com) *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program 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 General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+// Self
+#include "invaliddialog.h"
+
+// Qt
+#include <QListWidget>
+#include <QVBoxLayout>
+#include <QBoxLayout>
+#include <QLabel>
+
+// KDE
+#include <KDialog>
+
+InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent)
+    : KDialog(parent)
+{
+    setCaption(caption);
+    // Info only means users can only click on ok
+    if (infoOnly) {
+        setButtons(KDialog::Ok);
+    } else {
+        setButtons(KDialog::Yes | KDialog::No);
+    }
+
+    QWidget *mainWidget = new QWidget(this);
+    QVBoxLayout *boxLayout = new QVBoxLayout;
+    boxLayout->addWidget(new QLabel(message));
+
+    m_clipList = new QListWidget();
+    boxLayout->addWidget(m_clipList);
+    mainWidget->setLayout(boxLayout);
+    setMainWidget(mainWidget);
+}
+
+InvalidDialog::~InvalidDialog()
+{
+    delete m_clipList;
+}
+
+void InvalidDialog::addClip(const QString &id, const QString &path)
+{
+    QListWidgetItem *item = new QListWidgetItem(path);
+    item->setData(Qt::UserRole, id);
+    m_clipList->addItem(item);
+}
+
+QStringList InvalidDialog::getIds() const
+{
+    QStringList ids;
+    for (int i = 0; i < m_clipList->count(); ++i) {
+        ids << m_clipList->item(i)->data(Qt::UserRole).toString();
+    }
+    return ids;
+}
diff --git a/src/widgets/invaliddialog.h b/src/widgets/invaliddialog.h
new file mode 100644 (file)
index 0000000..239df7c
--- /dev/null
@@ -0,0 +1,44 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *               2013 by Jean-Nicolas Artaud (jeannicolasartaud@gmail.com) *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program 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 General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+#ifndef INVALIDDIALOG_H
+#define INVALIDDIALOG_H
+
+// KDE
+#include <KDialog>
+
+class QListWidget;
+
+class InvalidDialog : public KDialog
+{
+    Q_OBJECT
+
+public:
+    explicit InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent = 0);
+    ~InvalidDialog();
+
+    void addClip(const QString &id, const QString &path);
+    QStringList getIds() const;
+
+private:
+    QListWidget *m_clipList;
+};
+
+#endif // INVALIDDIALOG_H