Git commit d198819b03831ef3feedfdf1f3f25259f58234e9 by Vincent Pinon. Committed on 28/02/2017 at 22:30. Pushed by vpinon into branch 'master'. Fix GCC warnings: move bin internal classes away from header M +189 -0 src/bin/bin.cpp M +4 -189 src/bin/bin.h https://commits.kde.org/kdenlive/d198819b03831ef3feedfdf1f3f25259f58234e9 diff --git a/src/bin/bin.cpp b/src/bin/bin.cpp index f00ae75b5..40ecf9f00 100644 --- a/src/bin/bin.cpp +++ b/src/bin/bin.cpp @@ -302,6 +302,195 @@ void SmallJobLabel::slotSetJobCount(int jobCount) } } = +/** + * @class BinItemDelegate + * @brief This class is responsible for drawing items in the QTreeView. + */ + +class BinItemDelegate: public QStyledItemDelegate +{ +public: + explicit BinItemDelegate(QObject *parent =3D nullptr): QStyledItemDele= gate(parent) + { + } + + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem = &option, const QModelIndex &index) const Q_DECL_OVERRIDE + { + if (index.column() !=3D 0) { + return QStyledItemDelegate::updateEditorGeometry(editor, optio= n, index); + } + QStyleOptionViewItem opt =3D option; + initStyleOption(&opt, index); + QRect r1 =3D option.rect; + QStyle *style =3D opt.widget ? opt.widget->style() : QApplication:= :style(); + const int textMargin =3D style->pixelMetric(QStyle::PM_FocusFrameH= Margin) + 1; + int type =3D index.data(AbstractProjectItem::ItemTypeRole).toInt(); + double factor =3D (double) opt.decorationSize.height() / r1.height= (); + int decoWidth =3D 2 * textMargin; + int mid =3D 0; + if (factor > 0) { + decoWidth +=3D opt.decorationSize.width() / factor; + } + if (type =3D=3D AbstractProjectItem::ClipItem || type =3D=3D Abstr= actProjectItem::SubClipItem) { + mid =3D (int)((r1.height() / 2)); + } + r1.adjust(decoWidth, 0, 0, -mid); + QFont ft =3D option.font; + ft.setBold(true); + QFontMetricsF fm(ft); + QRect r2 =3D fm.boundingRect(r1, Qt::AlignLeft | Qt::AlignTop, ind= ex.data(AbstractProjectItem::DataName).toString()).toRect(); + editor->setGeometry(r2); + } + + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &= index) const Q_DECL_OVERRIDE + { + QSize hint =3D QStyledItemDelegate::sizeHint(option, index); + QString text =3D index.data(AbstractProjectItem::DataName).toStrin= g(); + QRectF r =3D option.rect; + QFont ft =3D option.font; + ft.setBold(true); + QFontMetricsF fm(ft); + QStyle *style =3D option.widget ? option.widget->style() : QApplic= ation::style(); + const int textMargin =3D style->pixelMetric(QStyle::PM_FocusFrameH= Margin) + 1; + int width =3D fm.boundingRect(r, Qt::AlignLeft | Qt::AlignTop, tex= t).width() + option.decorationSize.width() + 2 * textMargin; + hint.setWidth(width); + int type =3D index.data(AbstractProjectItem::ItemTypeRole).toInt(); + if (type =3D=3D AbstractProjectItem::FolderItem || type =3D=3D Abs= tractProjectItem::FolderUpItem) { + return QSize(hint.width(), qMin(option.fontMetrics.lineSpacing= () + 4, hint.height())); + } + if (type =3D=3D AbstractProjectItem::ClipItem) { + return QSize(hint.width(), qMax(option.fontMetrics.lineSpacing= () * 2 + 4, qMax(hint.height(), option.decorationSize.height()))); + } + if (type =3D=3D AbstractProjectItem::SubClipItem) { + return QSize(hint.width(), qMax(option.fontMetrics.lineSpacing= () * 2 + 4, qMin(hint.height(), (int)(option.decorationSize.height() / 1.5)= ))); + } + QIcon icon =3D qvariant_cast(index.data(Qt::DecorationRole)= ); + QString line1 =3D index.data(Qt::DisplayRole).toString(); + QString line2 =3D index.data(Qt::UserRole).toString(); + + int textW =3D qMax(option.fontMetrics.width(line1), option.fontMet= rics.width(line2)); + QSize iconSize =3D icon.actualSize(option.decorationSize); + return QSize(qMax(textW, iconSize.width()) + 4, option.fontMetrics= .lineSpacing() * 2 + 4); + } + + void paint(QPainter *painter, const QStyleOptionViewItem &option, cons= t QModelIndex &index) const Q_DECL_OVERRIDE + { + if (index.column() =3D=3D 0 && !index.data().isNull()) { + QRect r1 =3D option.rect; + painter->save(); + painter->setClipRect(r1); + QStyleOptionViewItem opt(option); + initStyleOption(&opt, index); + int type =3D index.data(AbstractProjectItem::ItemTypeRole).toI= nt(); + QStyle *style =3D opt.widget ? opt.widget->style() : QApplicat= ion::style(); + const int textMargin =3D style->pixelMetric(QStyle::PM_FocusFr= ameHMargin) + 1; + //QRect r =3D QStyle::alignedRect(opt.direction, Qt::AlignVCen= ter | Qt::AlignLeft, opt.decorationSize, r1); + + style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, paint= er, opt.widget); + if (option.state & QStyle::State_Selected) { + painter->setPen(option.palette.highlightedText().color()); + } else { + painter->setPen(option.palette.text().color()); + } + QRect r =3D r1; + QFont font =3D painter->font(); + font.setBold(true); + painter->setFont(font); + if (type =3D=3D AbstractProjectItem::ClipItem || type =3D=3D A= bstractProjectItem::SubClipItem) { + double factor =3D (double) opt.decorationSize.height() / r= 1.height(); + int decoWidth =3D 2 * textMargin; + if (factor > 0) { + r.setWidth(opt.decorationSize.width() / factor); + // Draw thumbnail + opt.icon.paint(painter, r); + decoWidth +=3D r.width(); + } + int mid =3D (int)((r1.height() / 2)); + r1.adjust(decoWidth, 0, 0, -mid); + QRect r2 =3D option.rect; + r2.adjust(decoWidth, mid, 0, 0); + QRectF bounding; + painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop, index.= data(AbstractProjectItem::DataName).toString(), &bounding); + font.setBold(false); + painter->setFont(font); + QString subText =3D index.data(AbstractProjectItem::DataDu= ration).toString(); + if (!subText.isEmpty()) { + r2.adjust(0, bounding.bottom() - r2.top(), 0, 0); + QColor subTextColor =3D painter->pen().color(); + subTextColor.setAlphaF(.5); + painter->setPen(subTextColor); + painter->drawText(r2, Qt::AlignLeft | Qt::AlignTop, su= bText, &bounding); + // Draw usage counter + int usage =3D index.data(AbstractProjectItem::UsageCou= nt).toInt(); + if (usage > 0) { + bounding.moveLeft(bounding.right() + (2 * textMarg= in)); + QString us =3D QString().sprintf("[%d]", usage); + painter->drawText(bounding, Qt::AlignLeft | Qt::Al= ignTop, us, &bounding); + } + } + if (type =3D=3D AbstractProjectItem::ClipItem) { + // Overlay icon if necessary + QVariant v =3D index.data(AbstractProjectItem::IconOve= rlay); + if (!v.isNull()) { + QIcon reload =3D QIcon::fromTheme(v.toString()); + r.setTop(r.bottom() - bounding.height()); + r.setWidth(bounding.height()); + reload.paint(painter, r); + } + + int jobProgress =3D index.data(AbstractProjectItem::Jo= bProgress).toInt(); + if (jobProgress > 0 || jobProgress =3D=3D JobWaiting) { + // Draw job progress bar + int progressWidth =3D option.fontMetrics.averageCh= arWidth() * 8; + int progressHeight =3D option.fontMetrics.ascent()= / 4; + QRect progress(r1.x() + 1, opt.rect.bottom() - pro= gressHeight - 2, progressWidth, progressHeight); + painter->setPen(Qt::NoPen); + painter->setBrush(Qt::darkGray); + if (jobProgress > 0) { + painter->drawRoundedRect(progress, 2, 2); + painter->setBrush(option.state & QStyle::State= _Selected ? option.palette.text() : option.palette.highlight()); + progress.setWidth((progressWidth - 2) * jobPro= gress / 100); + painter->drawRoundedRect(progress, 2, 2); + } else if (jobProgress =3D=3D JobWaiting) { + // Draw kind of a pause icon + progress.setWidth(3); + painter->drawRect(progress); + progress.moveLeft(progress.right() + 3); + painter->drawRect(progress); + } + } else if (jobProgress =3D=3D JobCrashed) { + QString jobText =3D index.data(AbstractProjectItem= ::JobMessage).toString(); + if (!jobText.isEmpty()) { + QRectF txtBounding =3D painter->boundingRect(r= 2, Qt::AlignRight | Qt::AlignVCenter, " " + jobText + " "); + 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); + } + } + } + } else { + // Folder or Folder Up items + double factor =3D (double) opt.decorationSize.height() / r= 1.height(); + int decoWidth =3D 2 * textMargin; + if (factor > 0) { + r.setWidth(opt.decorationSize.width() / factor); + // Draw thumbnail + opt.icon.paint(painter, r); + decoWidth +=3D r.width(); + } + r1.adjust(decoWidth, 0, 0, 0); + QRectF bounding; + painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop, index.= data(AbstractProjectItem::DataName).toString(), &bounding); + } + painter->restore(); + } else { + QStyledItemDelegate::paint(painter, option, index); + } + } +}; + LineEventEater::LineEventEater(QObject *parent) : QObject(parent) { } diff --git a/src/bin/bin.h b/src/bin/bin.h index 72ad15500..c1c1a38b7 100644 --- a/src/bin/bin.h +++ b/src/bin/bin.h @@ -60,6 +60,9 @@ class ProjectSortProxyModel; class JobManager; class ProjectFolderUp; class InvalidDialog; +class BinItemDelegate; +class BinMessageWidget; +class SmallJobLabel; = namespace Mlt { @@ -144,195 +147,6 @@ private slots: void slotTimeLineFinished(); }; = -/** - * @class BinItemDelegate - * @brief This class is responsible for drawing items in the QTreeView. - */ - -class BinItemDelegate: public QStyledItemDelegate -{ -public: - explicit BinItemDelegate(QObject *parent =3D nullptr): QStyledItemDele= gate(parent) - { - } - - void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem = &option, const QModelIndex &index) const Q_DECL_OVERRIDE - { - if (index.column() !=3D 0) { - return QStyledItemDelegate::updateEditorGeometry(editor, optio= n, index); - } - QStyleOptionViewItem opt =3D option; - initStyleOption(&opt, index); - QRect r1 =3D option.rect; - QStyle *style =3D opt.widget ? opt.widget->style() : QApplication:= :style(); - const int textMargin =3D style->pixelMetric(QStyle::PM_FocusFrameH= Margin) + 1; - int type =3D index.data(AbstractProjectItem::ItemTypeRole).toInt(); - double factor =3D (double) opt.decorationSize.height() / r1.height= (); - int decoWidth =3D 2 * textMargin; - int mid =3D 0; - if (factor !=3D 0) { - decoWidth +=3D opt.decorationSize.width() / factor; - } - if (type =3D=3D AbstractProjectItem::ClipItem || type =3D=3D Abstr= actProjectItem::SubClipItem) { - mid =3D (int)((r1.height() / 2)); - } - r1.adjust(decoWidth, 0, 0, -mid); - QFont ft =3D option.font; - ft.setBold(true); - QFontMetricsF fm(ft); - QRect r2 =3D fm.boundingRect(r1, Qt::AlignLeft | Qt::AlignTop, ind= ex.data(AbstractProjectItem::DataName).toString()).toRect(); - editor->setGeometry(r2); - } - - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &= index) const Q_DECL_OVERRIDE - { - QSize hint =3D QStyledItemDelegate::sizeHint(option, index); - QString text =3D index.data(AbstractProjectItem::DataName).toStrin= g(); - QRectF r =3D option.rect; - QFont ft =3D option.font; - ft.setBold(true); - QFontMetricsF fm(ft); - QStyle *style =3D option.widget ? option.widget->style() : QApplic= ation::style(); - const int textMargin =3D style->pixelMetric(QStyle::PM_FocusFrameH= Margin) + 1; - int width =3D fm.boundingRect(r, Qt::AlignLeft | Qt::AlignTop, tex= t).width() + option.decorationSize.width() + 2 * textMargin; - hint.setWidth(width); - int type =3D index.data(AbstractProjectItem::ItemTypeRole).toInt(); - if (type =3D=3D AbstractProjectItem::FolderItem || type =3D=3D Abs= tractProjectItem::FolderUpItem) { - return QSize(hint.width(), qMin(option.fontMetrics.lineSpacing= () + 4, hint.height())); - } - if (type =3D=3D AbstractProjectItem::ClipItem) { - return QSize(hint.width(), qMax(option.fontMetrics.lineSpacing= () * 2 + 4, qMax(hint.height(), option.decorationSize.height()))); - } - if (type =3D=3D AbstractProjectItem::SubClipItem) { - return QSize(hint.width(), qMax(option.fontMetrics.lineSpacing= () * 2 + 4, qMin(hint.height(), (int)(option.decorationSize.height() / 1.5)= ))); - } - QIcon icon =3D qvariant_cast(index.data(Qt::DecorationRole)= ); - QString line1 =3D index.data(Qt::DisplayRole).toString(); - QString line2 =3D index.data(Qt::UserRole).toString(); - - int textW =3D qMax(option.fontMetrics.width(line1), option.fontMet= rics.width(line2)); - QSize iconSize =3D icon.actualSize(option.decorationSize); - return QSize(qMax(textW, iconSize.width()) + 4, option.fontMetrics= .lineSpacing() * 2 + 4); - } - - void paint(QPainter *painter, const QStyleOptionViewItem &option, cons= t QModelIndex &index) const Q_DECL_OVERRIDE - { - if (index.column() =3D=3D 0 && !index.data().isNull()) { - QRect r1 =3D option.rect; - painter->save(); - painter->setClipRect(r1); - QStyleOptionViewItem opt(option); - initStyleOption(&opt, index); - int type =3D index.data(AbstractProjectItem::ItemTypeRole).toI= nt(); - QStyle *style =3D opt.widget ? opt.widget->style() : QApplicat= ion::style(); - const int textMargin =3D style->pixelMetric(QStyle::PM_FocusFr= ameHMargin) + 1; - //QRect r =3D QStyle::alignedRect(opt.direction, Qt::AlignVCen= ter | Qt::AlignLeft, opt.decorationSize, r1); - - style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, paint= er, opt.widget); - if (option.state & QStyle::State_Selected) { - painter->setPen(option.palette.highlightedText().color()); - } else { - painter->setPen(option.palette.text().color()); - } - QRect r =3D r1; - QFont font =3D painter->font(); - font.setBold(true); - painter->setFont(font); - if (type =3D=3D AbstractProjectItem::ClipItem || type =3D=3D A= bstractProjectItem::SubClipItem) { - double factor =3D (double) opt.decorationSize.height() / r= 1.height(); - int decoWidth =3D 2 * textMargin; - if (factor !=3D 0) { - r.setWidth(opt.decorationSize.width() / factor); - // Draw thumbnail - opt.icon.paint(painter, r); - decoWidth +=3D r.width(); - } - int mid =3D (int)((r1.height() / 2)); - r1.adjust(decoWidth, 0, 0, -mid); - QRect r2 =3D option.rect; - r2.adjust(decoWidth, mid, 0, 0); - QRectF bounding; - painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop, index.= data(AbstractProjectItem::DataName).toString(), &bounding); - font.setBold(false); - painter->setFont(font); - QString subText =3D index.data(AbstractProjectItem::DataDu= ration).toString(); - if (!subText.isEmpty()) { - r2.adjust(0, bounding.bottom() - r2.top(), 0, 0); - QColor subTextColor =3D painter->pen().color(); - subTextColor.setAlphaF(.5); - painter->setPen(subTextColor); - painter->drawText(r2, Qt::AlignLeft | Qt::AlignTop, su= bText, &bounding); - // Draw usage counter - int usage =3D index.data(AbstractProjectItem::UsageCou= nt).toInt(); - if (usage > 0) { - bounding.moveLeft(bounding.right() + (2 * textMarg= in)); - QString us =3D QString().sprintf("[%d]", usage); - painter->drawText(bounding, Qt::AlignLeft | Qt::Al= ignTop, us, &bounding); - } - } - if (type =3D=3D AbstractProjectItem::ClipItem) { - // Overlay icon if necessary - QVariant v =3D index.data(AbstractProjectItem::IconOve= rlay); - if (!v.isNull()) { - QIcon reload =3D QIcon::fromTheme(v.toString()); - r.setTop(r.bottom() - bounding.height()); - r.setWidth(bounding.height()); - reload.paint(painter, r); - } - - int jobProgress =3D index.data(AbstractProjectItem::Jo= bProgress).toInt(); - if (jobProgress > 0 || jobProgress =3D=3D JobWaiting) { - // Draw job progress bar - int progressWidth =3D option.fontMetrics.averageCh= arWidth() * 8; - int progressHeight =3D option.fontMetrics.ascent()= / 4; - QRect progress(r1.x() + 1, opt.rect.bottom() - pro= gressHeight - 2, progressWidth, progressHeight); - painter->setPen(Qt::NoPen); - painter->setBrush(Qt::darkGray); - if (jobProgress > 0) { - painter->drawRoundedRect(progress, 2, 2); - painter->setBrush(option.state & QStyle::State= _Selected ? option.palette.text() : option.palette.highlight()); - progress.setWidth((progressWidth - 2) * jobPro= gress / 100); - painter->drawRoundedRect(progress, 2, 2); - } else if (jobProgress =3D=3D JobWaiting) { - // Draw kind of a pause icon - progress.setWidth(3); - painter->drawRect(progress); - progress.moveLeft(progress.right() + 3); - painter->drawRect(progress); - } - } else if (jobProgress =3D=3D JobCrashed) { - QString jobText =3D index.data(AbstractProjectItem= ::JobMessage).toString(); - if (!jobText.isEmpty()) { - QRectF txtBounding =3D painter->boundingRect(r= 2, Qt::AlignRight | Qt::AlignVCenter, QLatin1Char(' ') + jobText + QLatin1C= har(' ')); - 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); - } - } - } - } else { - // Folder or Folder Up items - double factor =3D (double) opt.decorationSize.height() / r= 1.height(); - int decoWidth =3D 2 * textMargin; - if (factor !=3D 0) { - r.setWidth(opt.decorationSize.width() / factor); - // Draw thumbnail - opt.icon.paint(painter, r); - decoWidth +=3D r.width(); - } - r1.adjust(decoWidth, 0, 0, 0); - QRectF bounding; - painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop, index.= data(AbstractProjectItem::DataName).toString(), &bounding); - } - painter->restore(); - } else { - QStyledItemDelegate::paint(painter, option, index); - } - } -}; - class LineEventEater : public QObject { Q_OBJECT @@ -347,6 +161,7 @@ signals: void showClearButton(bool); }; = + /** * @class Bin * @brief The bin widget takes care of both item model and view upon proje= ct opening.