documentation and folded item delegates from old code back in

This commit is contained in:
itsmattkc
2019-07-02 03:01:46 -07:00
parent 1d05d6571a
commit 85b5bbd5d6
22 changed files with 293 additions and 3 deletions
+4
View File
@@ -169,6 +169,10 @@ bool FFmpegDecoder::Probe(Footage *f)
// Retrieve metadata about the media
av_dump_format(fmt_ctx_, stream()->index(), filename, 0);
// Set duration
f->set_duration(rational(fmt_ctx_->duration, AV_TIME_BASE));
qDebug() << "Found duration:" << f->duration().ToDouble();
// Dump it into the Footage object
for (unsigned int i=0;i<fmt_ctx_->nb_streams;i++) {
+11 -1
View File
@@ -77,6 +77,16 @@ void Footage::set_timestamp(const QDateTime &t)
timestamp_ = t;
}
const rational &Footage::duration()
{
return duration_;
}
void Footage::set_duration(const rational &duration)
{
duration_ = duration;
}
void Footage::add_stream(Stream *s)
{
// Add a copy of this stream to the list
@@ -170,7 +180,7 @@ void Footage::UpdateTooltip()
break;
case kReady:
{
QString tip = QCoreApplication::translate("Footage", "Filename: %1");
QString tip = QCoreApplication::translate("Footage", "Filename: %1").arg(filename());
if (!streams_.isEmpty()) {
tip.append("\n");
+10
View File
@@ -27,6 +27,7 @@
#include "project/item/item.h"
#include "project/item/footage/audiostream.h"
#include "project/item/footage/videostream.h"
#include "rational.h"
class Footage : public Item
{
@@ -137,6 +138,10 @@ public:
*/
void set_timestamp(const QDateTime& t);
const rational& duration();
void set_duration(const rational& duration);
/**
* @brief Add a stream metadata object to this footage
*
@@ -226,6 +231,11 @@ private:
* @brief Internal ready setting
*/
Status status_;
/**
* @brief Media duration
*/
rational duration_;
};
#endif // FOOTAGE_H
+9
View File
@@ -25,6 +25,15 @@
class Footage;
/**
* @brief The Stream class
*
* A base class for keeping metadata about a media stream. A Stream can contain video data, audio data, subtitle data,
* etc. and a Stream object stores metadata about it.
*
* The Stream class is fairly simple and is intended to be subclassed for data that pertains specifically to one
* Stream::Type. \see VideoStream and \see AudioStream.
*/
class Stream
{
public:
+10
View File
@@ -324,6 +324,16 @@ double rational::ToDouble() const
}
}
const int64_t &rational::numerator()
{
return numerator_;
}
const int64_t &rational::denominator()
{
return denominator_;
}
void rational::FixSigns()
{
// Ensures denominator is always positive (while numerator can be positive or negative)
+4
View File
@@ -84,6 +84,10 @@ public:
// Convert to double
double ToDouble() const;
// Specific values
const int64_t& numerator();
const int64_t& denominator();
private:
int64_t numerator_;
int64_t denominator_;
+8
View File
@@ -24,6 +24,14 @@
#include "project/item/folder/folder.h"
#include "task/task.h"
/**
* @brief The ImportTask class
*
* A background task to create Footage objects from a list of URLs, and then create ProbeTasks for each of them.
*
* Using this Task is the best way to import media into a project since it will run in the background/multithreaded
* without pausing the main thread.
*/
class ImportTask : public Task
{
Q_OBJECT
+10
View File
@@ -24,6 +24,16 @@
#include "project/item/footage/footage.h"
#include "task/task.h"
/**
* @brief The ProbeTask class
*
* A background task for probing a certain Footage file for its metadata and determining if we have a viable decoder
* for it.
*
* Currently this function just calls olive::ProbeMedia() which will call Footage::Clear(), clearing the Footage of
* any previous metadata before passing it through the available decoders until it finds one that can parse it.
* The ProbeTask mostly functions as a background/multithreaded wrapper for this functionality.
*/
class ProbeTask : public Task
{
Q_OBJECT
+2
View File
@@ -62,6 +62,7 @@ QIcon olive::icon::ZoomOut;
QIcon olive::icon::Record;
QIcon olive::icon::Add;
QIcon olive::icon::Error;
QIcon olive::icon::DirUp;
void olive::icon::LoadAll()
{
@@ -101,6 +102,7 @@ void olive::icon::LoadAll()
Record = Create("record");
Add = Create("add-button");
Error = Create("error");
DirUp = Create("dirup");
}
QIcon olive::icon::Create(const QString &name)
+1
View File
@@ -67,6 +67,7 @@ extern QIcon ZoomOut;
extern QIcon Record;
extern QIcon Add;
extern QIcon Error;
extern QIcon DirUp;
/**
* @brief Create an icon object loaded from file
@@ -24,7 +24,13 @@ set(OLIVE_SOURCES
widget/projectexplorer/projectexplorerlistview.cpp
widget/projectexplorer/projectexplorerlistviewbase.h
widget/projectexplorer/projectexplorerlistviewbase.cpp
widget/projectexplorer/projectexplorerlistviewitemdelegate.h
widget/projectexplorer/projectexplorerlistviewitemdelegate.cpp
widget/projectexplorer/projectexplorericonview.h
widget/projectexplorer/projectexplorericonview.cpp
widget/projectexplorer/projectexplorericonviewitemdelegate.h
widget/projectexplorer/projectexplorericonviewitemdelegate.cpp
widget/projectexplorer/projectexplorernavigation.h
widget/projectexplorer/projectexplorernavigation.cpp
PARENT_SCOPE
)
+12 -2
View File
@@ -46,8 +46,18 @@ void ProjectExplorer::set_view_type(olive::ProjectViewType type)
{
view_type_ = type;
// Enum values correspond to the index of the widget in this stacked widget
setCurrentIndex(view_type_);
// Set widget based on view type
switch (view_type_) {
case olive::TreeView:
setCurrentWidget(tree_view_);
break;
case olive::ListView:
setCurrentWidget(list_view_);
break;
case olive::IconView:
setCurrentWidget(icon_view_);
break;
}
}
void ProjectExplorer::AddView(QAbstractItemView *view)
@@ -24,4 +24,6 @@ ProjectExplorerIconView::ProjectExplorerIconView(QWidget *parent) :
ProjectExplorerListViewBase(parent)
{
setViewMode(QListView::IconMode);
setItemDelegate(&delegate_);
}
@@ -22,12 +22,16 @@
#define PROJECTEXPLORERICONVIEW_H
#include "projectexplorerlistviewbase.h"
#include "projectexplorericonviewitemdelegate.h"
class ProjectExplorerIconView : public ProjectExplorerListViewBase
{
Q_OBJECT
public:
ProjectExplorerIconView(QWidget* parent);
private:
ProjectExplorerIconViewItemDelegate delegate_;
};
#endif // PROJECTEXPLORERICONVIEW_H
@@ -0,0 +1,75 @@
#include "projectexplorericonviewitemdelegate.h"
#include <QPainter>
ProjectExplorerIconViewItemDelegate::ProjectExplorerIconViewItemDelegate(QObject *parent) :
QStyledItemDelegate (parent)
{
}
QSize ProjectExplorerIconViewItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const
{
Q_UNUSED(option)
return QSize(256, 256);
}
void ProjectExplorerIconViewItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QFontMetrics fm = painter->fontMetrics();
QRect img_rect = option.rect;
// Draw Text
if (fm.height() < option.rect.height() / 2) {
img_rect.setHeight(img_rect.height()-fm.height());
QRect text_rect = option.rect;
text_rect.setTop(text_rect.top() + option.rect.height() - fm.height());
QColor text_bgcolor;
QColor text_fgcolor;
if (option.state & QStyle::State_Selected) {
text_bgcolor = option.palette.highlight().color();
text_fgcolor = option.palette.highlightedText().color();
} else {
text_bgcolor = Qt::white;
text_fgcolor = Qt::black;
}
painter->fillRect(text_rect, text_bgcolor);
painter->setPen(text_fgcolor);
QString duration_str = index.data(Qt::UserRole).toString();
int timecode_width = fm.width(duration_str);
int max_name_width = option.rect.width();
if (timecode_width < option.rect.width() / 2) {
painter->drawText(text_rect, Qt::AlignBottom | Qt::AlignRight, index.data(Qt::UserRole).toString());
max_name_width -= timecode_width;
}
painter->drawText(text_rect,
Qt::AlignBottom | Qt::AlignLeft,
fm.elidedText(index.data(Qt::DisplayRole).toString(), Qt::ElideRight, max_name_width));
}
// Draw image
QIcon ico = index.data(Qt::DecorationRole).value<QIcon>();
QSize icon_size = ico.actualSize(img_rect.size());
img_rect = QRect(img_rect.x() + (img_rect.width() / 2 - icon_size.width() / 2),
img_rect.y() + (img_rect.height() / 2 - icon_size.height() / 2),
icon_size.width(),
icon_size.height());
painter->drawPixmap(img_rect, ico.pixmap(icon_size));
if (option.state & QStyle::State_Selected) {
QColor highlight_color = option.palette.highlight().color();
highlight_color.setAlphaF(0.5);
painter->setCompositionMode(QPainter::CompositionMode_SourceAtop);
painter->fillRect(img_rect, highlight_color);
}
}
@@ -0,0 +1,14 @@
#ifndef PROJECTEXPLORERICONVIEWITEMDELEGATE_H
#define PROJECTEXPLORERICONVIEWITEMDELEGATE_H
#include <QStyledItemDelegate>
class ProjectExplorerIconViewItemDelegate : public QStyledItemDelegate {
public:
ProjectExplorerIconViewItemDelegate(QObject *parent = nullptr);
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};
#endif // PROJECTEXPLORERICONVIEWITEMDELEGATE_H
@@ -24,4 +24,6 @@ ProjectExplorerListView::ProjectExplorerListView(QWidget *parent) :
ProjectExplorerListViewBase(parent)
{
setViewMode(QListView::ListMode);
setItemDelegate(&delegate_);
}
@@ -22,12 +22,16 @@
#define PROJECTEXPLORERLISTVIEW_H
#include "projectexplorerlistviewbase.h"
#include "projectexplorerlistviewitemdelegate.h"
class ProjectExplorerListView : public ProjectExplorerListViewBase
{
Q_OBJECT
public:
ProjectExplorerListView(QWidget* parent);
private:
ProjectExplorerListViewItemDelegate delegate_;
};
#endif // PROJECTEXPLORERLISTVIEW_H
@@ -0,0 +1,59 @@
#include "projectexplorerlistviewitemdelegate.h"
#include <QPainter>
ProjectExplorerListViewItemDelegate::ProjectExplorerListViewItemDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{
}
QSize ProjectExplorerListViewItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const
{
return QSize(option.decorationSize.height(), option.decorationSize.height());
}
void ProjectExplorerListViewItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QFontMetrics fm = painter->fontMetrics();
QRect img_rect = option.rect;
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
}
img_rect.setWidth(qMin(img_rect.width(), img_rect.height()));
QIcon ico = index.data(Qt::DecorationRole).value<QIcon>();
QSize icon_size = ico.actualSize(img_rect.size());
img_rect = QRect(img_rect.x() + (img_rect.width() / 2 - icon_size.width() / 2),
img_rect.y() + (img_rect.height() / 2 - icon_size.height() / 2),
icon_size.width(),
icon_size.height());
painter->drawPixmap(img_rect, ico.pixmap(icon_size));
QRect text_rect = option.rect;
text_rect.setLeft(text_rect.left() + option.rect.height());
int maximum_line_count = qMax(1, option.rect.height() / fm.height() - 1);
QString text;
if (maximum_line_count == 1) {
text = index.data(Qt::DisplayRole).toString();
} else {
text = index.data(Qt::ToolTipRole).toString();
if (text.isEmpty()) {
text = index.data(Qt::DisplayRole).toString();
} else {
QStringList strings = text.split("\n");
while (strings.size() > maximum_line_count) {
strings.removeLast();
}
text = strings.join("\n");
}
}
painter->setPen(option.state & QStyle::State_Selected ?
option.palette.highlightedText().color() : option.palette.text().color());
painter->drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, text);
}
@@ -0,0 +1,15 @@
#ifndef PROJECTEXPLORERLISTVIEWITEMDELEGATE_H
#define PROJECTEXPLORERLISTVIEWITEMDELEGATE_H
#include <QStyledItemDelegate>
class ProjectExplorerListViewItemDelegate : public QStyledItemDelegate
{
public:
ProjectExplorerListViewItemDelegate(QObject *parent = nullptr);
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};
#endif // PROJECTEXPLORERLISTVIEWITEMDELEGATE_H
@@ -0,0 +1,15 @@
#include "projectexplorernavigation.h"
#include <QHBoxLayout>
#include "ui/icons/icons.h"
ProjectExplorerNavigation::ProjectExplorerNavigation(QWidget *parent) :
QWidget(parent)
{
QHBoxLayout* layout = new QHBoxLayout(this);
dir_up_btn_ = new QPushButton(this);
dir_up_btn_->setIcon(olive::icon::DirUp);
layout->addWidget(dir_up_btn_);
}
@@ -0,0 +1,16 @@
#ifndef PROJECTEXPLORERLISTVIEWTOOLBAR_H
#define PROJECTEXPLORERLISTVIEWTOOLBAR_H
#include <QPushButton>
#include <QWidget>
class ProjectExplorerNavigation : public QWidget
{
public:
ProjectExplorerNavigation(QWidget* parent);
private:
QPushButton* dir_up_btn_;
};
#endif // PROJECTEXPLORERLISTVIEWTOOLBAR_H