From 0f7192fc33f9858e68cb37d9eb32653de5a86b01 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 2 Jul 2019 16:46:09 -0700 Subject: [PATCH] work towards project explorer navigation bar --- app/decoder/decoder.h | 2 + app/decoder/ffmpeg/ffmpegdecoder.cpp | 11 ++-- app/project/item/footage/footage.cpp | 14 ++--- app/project/item/footage/footage.h | 9 +-- app/project/item/footage/stream.cpp | 10 +++ app/project/item/footage/stream.h | 5 ++ app/widget/projectexplorer/CMakeLists.txt | 1 + .../projectexplorer/projectexplorer.cpp | 52 +++++++++++++--- app/widget/projectexplorer/projectexplorer.h | 9 ++- .../projectexplorer/projectexplorerdefines.h | 13 ++++ .../projectexplorericonviewitemdelegate.cpp | 20 ++++++ .../projectexplorericonviewitemdelegate.h | 20 ++++++ .../projectexplorerlistviewitemdelegate.cpp | 20 ++++++ .../projectexplorerlistviewitemdelegate.h | 20 ++++++ .../projectexplorernavigation.cpp | 62 +++++++++++++++++++ .../projectexplorernavigation.h | 38 ++++++++++++ 16 files changed, 274 insertions(+), 32 deletions(-) create mode 100644 app/widget/projectexplorer/projectexplorerdefines.h diff --git a/app/decoder/decoder.h b/app/decoder/decoder.h index 36abee4e4..2af70e1ff 100644 --- a/app/decoder/decoder.h +++ b/app/decoder/decoder.h @@ -84,6 +84,8 @@ public: */ virtual bool Probe(Footage* f) = 0; + + /** * @brief Open media/allocate memory * diff --git a/app/decoder/ffmpeg/ffmpegdecoder.cpp b/app/decoder/ffmpeg/ffmpegdecoder.cpp index acfbc0dc3..bf44b9d52 100644 --- a/app/decoder/ffmpeg/ffmpegdecoder.cpp +++ b/app/decoder/ffmpeg/ffmpegdecoder.cpp @@ -167,11 +167,7 @@ bool FFmpegDecoder::Probe(Footage *f) if (error_code == 0) { // 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(); + av_dump_format(fmt_ctx_, 0, filename, 0); // Dump it into the Footage object for (unsigned int i=0;inb_streams;i++) { @@ -190,6 +186,8 @@ bool FFmpegDecoder::Probe(Footage *f) str = video_stream; + qDebug() << "Stream V" << i << "Len" << (rational(avstream_->duration) * rational(avstream_->time_base)).ToDouble(); + } else if (avstream_->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { // Create an audio stream object @@ -201,6 +199,8 @@ bool FFmpegDecoder::Probe(Footage *f) str = audio_stream; + qDebug() << "Stream A" << i << "Len" << (rational(avstream_->duration) * rational(avstream_->time_base)).ToDouble(); + } else { // This is data we can't utilize at the moment, but we make a Stream object anyway to keep parity with the file @@ -234,6 +234,7 @@ bool FFmpegDecoder::Probe(Footage *f) str->set_index(avstream_->index); str->set_timebase(avstream_->time_base); + str->set_duration(avstream_->duration); f->add_stream(str); } diff --git a/app/project/item/footage/footage.cpp b/app/project/item/footage/footage.cpp index a6658164c..60eea77a6 100644 --- a/app/project/item/footage/footage.cpp +++ b/app/project/item/footage/footage.cpp @@ -77,16 +77,6 @@ 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 @@ -142,6 +132,7 @@ void Footage::UpdateIcon() { switch (status_) { case kUnprobed: + case kUnindexed: // FIXME Set a waiting icon set_icon(QIcon()); break; @@ -178,6 +169,9 @@ void Footage::UpdateTooltip() case kUnprobed: set_tooltip(QCoreApplication::translate("Footage", "Waiting for probe")); break; + case kUnindexed: + set_tooltip(QCoreApplication::translate("Footage", "Waiting for index")); + break; case kReady: { QString tip = QCoreApplication::translate("Footage", "Filename: %1").arg(filename()); diff --git a/app/project/item/footage/footage.h b/app/project/item/footage/footage.h index ccaefad00..b7ac67a6b 100644 --- a/app/project/item/footage/footage.h +++ b/app/project/item/footage/footage.h @@ -34,6 +34,7 @@ class Footage : public Item public: enum Status { kUnprobed, + kUnindexed, kReady, kInvalid }; @@ -138,10 +139,6 @@ 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 * @@ -232,10 +229,6 @@ private: */ Status status_; - /** - * @brief Media duration - */ - rational duration_; }; #endif // FOOTAGE_H diff --git a/app/project/item/footage/stream.cpp b/app/project/item/footage/stream.cpp index f90b0db6f..c7d445b72 100644 --- a/app/project/item/footage/stream.cpp +++ b/app/project/item/footage/stream.cpp @@ -70,3 +70,13 @@ void Stream::set_index(const int &index) { index_ = index; } + +const int64_t &Stream::duration() +{ + return duration_; +} + +void Stream::set_duration(const int64_t &duration) +{ + duration_ = duration; +} diff --git a/app/project/item/footage/stream.h b/app/project/item/footage/stream.h index bcdd0c2b0..70da35be2 100644 --- a/app/project/item/footage/stream.h +++ b/app/project/item/footage/stream.h @@ -68,11 +68,16 @@ public: const int& index(); void set_index(const int& index); + const int64_t& duration(); + void set_duration(const int64_t& duration); + private: Footage* footage_; rational timebase_; + int64_t duration_; + int index_; Type type_; diff --git a/app/widget/projectexplorer/CMakeLists.txt b/app/widget/projectexplorer/CMakeLists.txt index e999f1d1d..faaf3bfc4 100644 --- a/app/widget/projectexplorer/CMakeLists.txt +++ b/app/widget/projectexplorer/CMakeLists.txt @@ -18,6 +18,7 @@ set(OLIVE_SOURCES ${OLIVE_SOURCES} widget/projectexplorer/projectexplorer.h widget/projectexplorer/projectexplorer.cpp + widget/projectexplorer/projectexplorerdefines.h widget/projectexplorer/projectexplorertreeview.h widget/projectexplorer/projectexplorertreeview.cpp widget/projectexplorer/projectexplorerlistview.h diff --git a/app/widget/projectexplorer/projectexplorer.cpp b/app/widget/projectexplorer/projectexplorer.cpp index 599665896..9f9a6ae17 100644 --- a/app/widget/projectexplorer/projectexplorer.cpp +++ b/app/widget/projectexplorer/projectexplorer.cpp @@ -21,20 +21,46 @@ #include "projectexplorer.h" #include +#include + +#include "projectexplorerdefines.h" ProjectExplorer::ProjectExplorer(QWidget *parent) : - QStackedWidget(parent), + QWidget(parent), view_type_(olive::TreeView), model_(this) { - tree_view_ = new ProjectExplorerTreeView(this); + // Create layout + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setSpacing(0); + layout->setMargin(0); + + // Set up navigation bar + nav_bar_ = new ProjectExplorerNavigation(this); + connect(nav_bar_, SIGNAL(SizeChanged(int)), this, SLOT(SizeChangedSlot(int))); + layout->addWidget(nav_bar_); + + // Set up stacked widget + stacked_widget_ = new QStackedWidget(this); + layout->addWidget(stacked_widget_); + + // Add tree view to stacked widget + tree_view_ = new ProjectExplorerTreeView(stacked_widget_); AddView(tree_view_); - list_view_ = new ProjectExplorerListView(this); + // Add list view to stacked widget + list_view_ = new ProjectExplorerListView(stacked_widget_); AddView(list_view_); - icon_view_ = new ProjectExplorerIconView(this); + // Add icon view to stacked widget + icon_view_ = new ProjectExplorerIconView(stacked_widget_); AddView(icon_view_); + + // Set default view to tree view + set_view_type(olive::TreeView); + + // Set default icon size + SizeChangedSlot(olive::kProjectIconSizeDefault); } const olive::ProjectViewType &ProjectExplorer::view_type() @@ -49,13 +75,16 @@ void ProjectExplorer::set_view_type(olive::ProjectViewType type) // Set widget based on view type switch (view_type_) { case olive::TreeView: - setCurrentWidget(tree_view_); + stacked_widget_->setCurrentWidget(tree_view_); + nav_bar_->setVisible(false); break; case olive::ListView: - setCurrentWidget(list_view_); + stacked_widget_->setCurrentWidget(list_view_); + nav_bar_->setVisible(true); break; case olive::IconView: - setCurrentWidget(icon_view_); + stacked_widget_->setCurrentWidget(icon_view_); + nav_bar_->setVisible(true); break; } } @@ -64,7 +93,7 @@ void ProjectExplorer::AddView(QAbstractItemView *view) { view->setModel(&model_); connect(view, SIGNAL(DoubleClickedView(const QModelIndex&)), this, SLOT(DoubleClickViewSlot(const QModelIndex&))); - addWidget(view); + stacked_widget_->addWidget(view); } void ProjectExplorer::DoubleClickViewSlot(const QModelIndex &index) @@ -85,6 +114,13 @@ void ProjectExplorer::DoubleClickViewSlot(const QModelIndex &index) } } +void ProjectExplorer::SizeChangedSlot(int s) +{ + icon_view_->setGridSize(QSize(s, s)); + + list_view_->setIconSize(QSize(s, s)); +} + Project *ProjectExplorer::project() { return model_.project(); diff --git a/app/widget/projectexplorer/projectexplorer.h b/app/widget/projectexplorer/projectexplorer.h index d27ba4f72..d9c750365 100644 --- a/app/widget/projectexplorer/projectexplorer.h +++ b/app/widget/projectexplorer/projectexplorer.h @@ -30,6 +30,7 @@ #include "widget/projectexplorer/projectexplorericonview.h" #include "widget/projectexplorer/projectexplorerlistview.h" #include "widget/projectexplorer/projectexplorertreeview.h" +#include "widget/projectexplorer/projectexplorernavigation.h" /** * @brief The ProjectExplorer class @@ -41,7 +42,7 @@ * * This widget contains three views, tree view, list view, and icon view. These can be switched at any time. */ -class ProjectExplorer : public QStackedWidget +class ProjectExplorer : public QWidget { Q_OBJECT public: @@ -77,6 +78,10 @@ private: */ void AddView(QAbstractItemView* view); + QStackedWidget* stacked_widget_; + + ProjectExplorerNavigation* nav_bar_; + ProjectExplorerIconView* icon_view_; ProjectExplorerListView* list_view_; ProjectExplorerTreeView* tree_view_; @@ -87,6 +92,8 @@ private: private slots: void DoubleClickViewSlot(const QModelIndex& index); + + void SizeChangedSlot(int s); }; #endif // PROJECTEXPLORER_H diff --git a/app/widget/projectexplorer/projectexplorerdefines.h b/app/widget/projectexplorer/projectexplorerdefines.h new file mode 100644 index 000000000..3bb2c23d8 --- /dev/null +++ b/app/widget/projectexplorer/projectexplorerdefines.h @@ -0,0 +1,13 @@ +#ifndef PROJECTEXPLORERDEFINES_H +#define PROJECTEXPLORERDEFINES_H + +namespace olive { + +const int kProjectIconSizeMinimum = 16; +const int kProjectIconSizeMaximum = 256; + +const int kProjectIconSizeDefault = 64; + +} + +#endif // PROJECTEXPLORERDEFINES_H diff --git a/app/widget/projectexplorer/projectexplorericonviewitemdelegate.cpp b/app/widget/projectexplorer/projectexplorericonviewitemdelegate.cpp index 2f5930331..ee14c89b1 100644 --- a/app/widget/projectexplorer/projectexplorericonviewitemdelegate.cpp +++ b/app/widget/projectexplorer/projectexplorericonviewitemdelegate.cpp @@ -1,3 +1,23 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + 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 3 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, see . + +***/ + #include "projectexplorericonviewitemdelegate.h" #include diff --git a/app/widget/projectexplorer/projectexplorericonviewitemdelegate.h b/app/widget/projectexplorer/projectexplorericonviewitemdelegate.h index fa5066843..a4b3f5f55 100644 --- a/app/widget/projectexplorer/projectexplorericonviewitemdelegate.h +++ b/app/widget/projectexplorer/projectexplorericonviewitemdelegate.h @@ -1,3 +1,23 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + 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 3 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, see . + +***/ + #ifndef PROJECTEXPLORERICONVIEWITEMDELEGATE_H #define PROJECTEXPLORERICONVIEWITEMDELEGATE_H diff --git a/app/widget/projectexplorer/projectexplorerlistviewitemdelegate.cpp b/app/widget/projectexplorer/projectexplorerlistviewitemdelegate.cpp index 2332b9ec4..d83316c04 100644 --- a/app/widget/projectexplorer/projectexplorerlistviewitemdelegate.cpp +++ b/app/widget/projectexplorer/projectexplorerlistviewitemdelegate.cpp @@ -1,3 +1,23 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + 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 3 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, see . + +***/ + #include "projectexplorerlistviewitemdelegate.h" #include diff --git a/app/widget/projectexplorer/projectexplorerlistviewitemdelegate.h b/app/widget/projectexplorer/projectexplorerlistviewitemdelegate.h index e8ca26092..8e1a9ed36 100644 --- a/app/widget/projectexplorer/projectexplorerlistviewitemdelegate.h +++ b/app/widget/projectexplorer/projectexplorerlistviewitemdelegate.h @@ -1,3 +1,23 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + 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 3 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, see . + +***/ + #ifndef PROJECTEXPLORERLISTVIEWITEMDELEGATE_H #define PROJECTEXPLORERLISTVIEWITEMDELEGATE_H diff --git a/app/widget/projectexplorer/projectexplorernavigation.cpp b/app/widget/projectexplorer/projectexplorernavigation.cpp index 9eace5279..6361ab11a 100644 --- a/app/widget/projectexplorer/projectexplorernavigation.cpp +++ b/app/widget/projectexplorer/projectexplorernavigation.cpp @@ -1,15 +1,77 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + 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 3 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, see . + +***/ + #include "projectexplorernavigation.h" +#include #include #include "ui/icons/icons.h" +#include "widget/projectexplorer/projectexplorerdefines.h" ProjectExplorerNavigation::ProjectExplorerNavigation(QWidget *parent) : QWidget(parent) { + // Create widget layout QHBoxLayout* layout = new QHBoxLayout(this); + layout->setMargin(0); + // Create "directory up" button dir_up_btn_ = new QPushButton(this); dir_up_btn_->setIcon(olive::icon::DirUp); + dir_up_btn_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); layout->addWidget(dir_up_btn_); + connect(dir_up_btn_, SIGNAL(clicked(bool)), this, SIGNAL(DirectoryUpClicked())); + + // Create directory tree label + dir_lbl_ = new QLabel(this); + dir_lbl_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + layout->addWidget(dir_lbl_); + + // Create size slider + size_slider_ = new QSlider(this); + size_slider_->setOrientation(Qt::Horizontal); + size_slider_->setMinimum(olive::kProjectIconSizeMinimum); + size_slider_->setMaximum(olive::kProjectIconSizeMaximum); + size_slider_->setValue(olive::kProjectIconSizeDefault); + size_slider_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + layout->addWidget(size_slider_); + connect(size_slider_, SIGNAL(valueChanged(int)), this, SIGNAL(SizeChanged(int))); + + Retranslate(); +} + +void ProjectExplorerNavigation::set_text(const QString &s) +{ + dir_lbl_->setText(s); +} + +void ProjectExplorerNavigation::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + Retranslate(); + } + QWidget::changeEvent(e); +} + +void ProjectExplorerNavigation::Retranslate() +{ + dir_up_btn_->setToolTip(tr("Go to parent folder")); } diff --git a/app/widget/projectexplorer/projectexplorernavigation.h b/app/widget/projectexplorer/projectexplorernavigation.h index 9b7de7457..bf6e86cde 100644 --- a/app/widget/projectexplorer/projectexplorernavigation.h +++ b/app/widget/projectexplorer/projectexplorernavigation.h @@ -1,16 +1,54 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + 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 3 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, see . + +***/ + #ifndef PROJECTEXPLORERLISTVIEWTOOLBAR_H #define PROJECTEXPLORERLISTVIEWTOOLBAR_H +#include #include +#include #include class ProjectExplorerNavigation : public QWidget { + Q_OBJECT public: ProjectExplorerNavigation(QWidget* parent); + void set_text(const QString& s); + +signals: + void DirectoryUpClicked(); + void SizeChanged(int size); + +protected: + virtual void changeEvent(QEvent *) override; + private: + void Retranslate(); + QPushButton* dir_up_btn_; + + QLabel* dir_lbl_; + + QSlider* size_slider_; }; #endif // PROJECTEXPLORERLISTVIEWTOOLBAR_H