* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
+// Self
+#include "projectlistview.h"
+
+// Qt
+#include <QApplication>
+#include <QHeaderView>
+#include <QAction>
+// KDE
+#include <KDebug>
+#include <KMenu>
+#include <KLocalizedString>
+
+// KDEnlive
#include "projectlistview.h"
#include "projectitem.h"
#include "subprojectitem.h"
#include "folderprojectitem.h"
#include "kdenlivesettings.h"
-#include <KDebug>
-#include <KMenu>
-#include <KLocale>
-
-#include <QApplication>
-#include <QHeaderView>
-#include <QAction>
-
-ProjectListView::ProjectListView(QWidget *parent) :
- QTreeWidget(parent),
- m_dragStarted(false)
+ProjectListView::ProjectListView(QWidget *parent)
+ : QTreeWidget(parent)
+ , m_dragStarted(false)
{
setSelectionMode(QAbstractItemView::ExtendedSelection);
setDragDropMode(QAbstractItemView::DragDrop);
QHeaderView* headerView = header();
headerView->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)),
- this, SLOT(configureColumns(const QPoint&)));
- connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem *)), this, SLOT(slotCollapsed(QTreeWidgetItem *)));
- connect(this, SIGNAL(itemExpanded(QTreeWidgetItem *)), this, SLOT(slotExpanded(QTreeWidgetItem *)));
+ connect(headerView, SIGNAL(customContextMenuRequested(QPoint)),
+ this, SLOT(configureColumns(QPoint)));
+ connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(slotCollapsed(QTreeWidgetItem*)));
+ connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(slotExpanded(QTreeWidgetItem*)));
headerView->setClickable(true);
headerView->setSortIndicatorShown(true);
headerView->setMovable(false);
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()
void ProjectListView::slotCollapsed(QTreeWidgetItem *item)
{
- if (item->type() == PROJECTFOLDERTYPE) {
+ if (item->type() == ProjectFoldeType) {
blockSignals(true);
static_cast <FolderProjectItem *>(item)->switchIcon();
blockSignals(false);
void ProjectListView::slotExpanded(QTreeWidgetItem *item)
{
- if (item->type() == PROJECTFOLDERTYPE) {
+ if (item->type() == ProjectFoldeType) {
blockSignals(true);
static_cast <FolderProjectItem *>(item)->switchIcon();
blockSignals(false);
return;
}
ProjectItem *item;
- if (it->type() == PROJECTFOLDERTYPE) {
+ if (it->type() == ProjectFoldeType) {
if ((columnAt(event->pos().x()) == 0)) {
QPixmap pix = qVariantValue<QPixmap>(it->data(0, Qt::DecorationRole));
int offset = pix.width() + indentation();
}
return;
}
- if (it->type() == PROJECTSUBCLIPTYPE) {
+ if (it->type() == ProjectSubclipType) {
// subitem
if ((columnAt(event->pos().x()) == 1)) {
QTreeWidget::mouseDoubleClickEvent(event);
if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
int column = columnAt(event->pos().x());
- if (column == 0 && (item->clipType() == SLIDESHOW || item->clipType() == TEXT || item->clipType() == COLOR || it->childCount() > 0)) {
+ if (column == 0 && (item->clipType() == SlideShow || item->clipType() == Text || item->clipType() == Color || it->childCount() > 0)) {
QPixmap pix = qVariantValue<QPixmap>(it->data(0, Qt::DecorationRole));
int offset = pix.width() + indentation();
if (item->parent()) offset += indentation();
return;
}
}
- if ((column == 1) && it->type() != PROJECTSUBCLIPTYPE) {
+ if ((column == 1) && it->type() != ProjectSubclipType) {
QTreeWidget::mouseDoubleClickEvent(event);
return;
}
{
FolderProjectItem *item = NULL;
QTreeWidgetItem *it = itemAt(event->pos());
- while (it && it->type() != PROJECTFOLDERTYPE) {
+ while (it && it->type() != ProjectFoldeType) {
it = it->parent();
}
if (it) item = static_cast <FolderProjectItem *>(it);
QString parentId = item->clipId();
foreach(QTreeWidgetItem *it, list) {
// TODO allow dragging of folders ?
- if (it->type() == PROJECTCLIPTYPE) {
+ if (it->type() == ProjectClipType) {
if (it->parent()) clone = (ProjectItem*) it->parent()->takeChild(it->parent()->indexOfChild(it));
else clone = (ProjectItem*) takeTopLevelItem(indexOfTopLevelItem(it));
if (clone && item) {
const QList <QTreeWidgetItem *> list = selectedItems();
ProjectItem *clone;
foreach(QTreeWidgetItem *it, list) {
- if (it->type() != PROJECTCLIPTYPE) continue;
+ if (it->type() != ProjectClipType) continue;
QTreeWidgetItem *parent = it->parent();
if (parent/* && ((ProjectItem *) it)->clipId() < 10000*/) {
kDebug() << "++ item parent: " << parent->text(1);
const QList <QTreeWidgetItem *> list = selectedItems();
QStringList ids;
foreach(const QTreeWidgetItem *item, list) {
- if (item->type() == PROJECTFOLDERTYPE) {
+ if (item->type() == ProjectFoldeType) {
const int children = item->childCount();
- for (int i = 0; i < children; i++) {
+ for (int i = 0; i < children; ++i) {
ids.append(static_cast <ProjectItem *>(item->child(i))->clipId());
}
- } else if (item->type() == PROJECTSUBCLIPTYPE) {
+ } else if (item->type() == ProjectSubclipType) {
const ProjectItem *parentclip = static_cast <const ProjectItem *>(item->parent());
const SubProjectItem *clickItem = static_cast <const SubProjectItem *>(item);
QPoint p = clickItem->zone();
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"