change: change code style to Linux style except indent.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -34,7 +34,8 @@
|
||||
#include "widget/projectexplorer/projectexplorernavigation.h"
|
||||
#include "widget/projecttoolbar/projecttoolbar.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief A widget for browsing through a Project structure.
|
||||
@@ -44,23 +45,22 @@ namespace olive {
|
||||
*
|
||||
* This widget contains three views, tree view, list view, and icon view. These can be switched at any time.
|
||||
*/
|
||||
class ProjectExplorer : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
class ProjectExplorer : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorer(QWidget* parent);
|
||||
ProjectExplorer(QWidget *parent);
|
||||
|
||||
const ProjectToolbar::ViewType& view_type() const;
|
||||
const ProjectToolbar::ViewType &view_type() const;
|
||||
|
||||
Project* project() const;
|
||||
void set_project(Project* p);
|
||||
Project *project() const;
|
||||
void set_project(Project *p);
|
||||
|
||||
Folder *get_root() const;
|
||||
void set_root(Folder *item);
|
||||
Folder *get_root() const;
|
||||
void set_root(Folder *item);
|
||||
|
||||
QVector<Node *> SelectedItems() const;
|
||||
QVector<Node *> SelectedItems() const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Use a heuristic to determine which (if any) folder is selected
|
||||
*
|
||||
* Generally for some import/adding processes, we assume that if a folder is selected, the user probably wants to
|
||||
@@ -72,51 +72,51 @@ public:
|
||||
* A folder that's heuristically been determined as "selected", or the root directory if none, or nullptr if no
|
||||
* project is open.
|
||||
*/
|
||||
Folder* GetSelectedFolder() const;
|
||||
Folder *GetSelectedFolder() const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Access the ViewModel model of the project
|
||||
*/
|
||||
ProjectViewModel* model();
|
||||
ProjectViewModel *model();
|
||||
|
||||
void SelectAll();
|
||||
void SelectAll();
|
||||
|
||||
void DeselectAll();
|
||||
void DeselectAll();
|
||||
|
||||
void DeleteSelected();
|
||||
void DeleteSelected();
|
||||
|
||||
bool SelectItem(Node *n, bool deselect_all_first = true);
|
||||
bool SelectItem(Node *n, bool deselect_all_first = true);
|
||||
|
||||
public slots:
|
||||
void set_view_type(ProjectToolbar::ViewType type);
|
||||
void set_view_type(ProjectToolbar::ViewType type);
|
||||
|
||||
void Edit(Node* item);
|
||||
void Edit(Node *item);
|
||||
|
||||
void RenameSelectedItem();
|
||||
void RenameSelectedItem();
|
||||
|
||||
void SetSearchFilter(const QString &s);
|
||||
void SetSearchFilter(const QString &s);
|
||||
|
||||
signals:
|
||||
/**
|
||||
/**
|
||||
* @brief Emitted when an Item is double clicked
|
||||
*
|
||||
* @param item
|
||||
*
|
||||
* The Item that was double clicked, or nullptr if empty area was double clicked
|
||||
*/
|
||||
void DoubleClickedItem(Node* item);
|
||||
void DoubleClickedItem(Node *item);
|
||||
|
||||
void SelectionChanged(const QVector<Node *> &selected);
|
||||
void SelectionChanged(const QVector<Node *> &selected);
|
||||
|
||||
private:
|
||||
/**
|
||||
/**
|
||||
* @brief Get all the blocks that solely rely on an input node
|
||||
*
|
||||
* Ignores blocks that depend on multiple inputs
|
||||
*/
|
||||
QList<Block*> GetFootageBlocks(QList<Node*> nodes);
|
||||
QList<Block *> GetFootageBlocks(QList<Node *> nodes);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Simple convenience function for adding a view to this stacked widget
|
||||
*
|
||||
* Mainly for use in the constructor. Adds the view, connects its signals/slots, and sets the model.
|
||||
@@ -125,9 +125,9 @@ private:
|
||||
*
|
||||
* View to add to the stack
|
||||
*/
|
||||
void AddView(QAbstractItemView* view);
|
||||
void AddView(QAbstractItemView *view);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Browse to a specific folder index in the model
|
||||
*
|
||||
* Only affects list_view_ and icon_view_.
|
||||
@@ -136,61 +136,62 @@ private:
|
||||
*
|
||||
* Either an invalid index to return to the project root, or an index to a valid Folder object.
|
||||
*/
|
||||
void BrowseToFolder(const QModelIndex& index);
|
||||
void BrowseToFolder(const QModelIndex &index);
|
||||
|
||||
int ConfirmItemDeletion(Node *item);
|
||||
int ConfirmItemDeletion(Node *item);
|
||||
|
||||
bool DeleteItemsInternal(const QVector<Node *> &selected, bool &check_if_item_is_in_use, MultiUndoCommand *command);
|
||||
bool DeleteItemsInternal(const QVector<Node *> &selected,
|
||||
bool &check_if_item_is_in_use,
|
||||
MultiUndoCommand *command);
|
||||
|
||||
static QString GetHumanReadableNodeName(Node* node);
|
||||
static QString GetHumanReadableNodeName(Node *node);
|
||||
|
||||
void UpdateNavBarText();
|
||||
void UpdateNavBarText();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Get the currently active QAbstractItemView
|
||||
*/
|
||||
QAbstractItemView* CurrentView() const;
|
||||
QAbstractItemView *CurrentView() const;
|
||||
|
||||
QStackedWidget* stacked_widget_;
|
||||
QStackedWidget *stacked_widget_;
|
||||
|
||||
ProjectExplorerNavigation* nav_bar_;
|
||||
ProjectExplorerNavigation *nav_bar_;
|
||||
|
||||
ProjectExplorerIconView* icon_view_;
|
||||
ProjectExplorerListView* list_view_;
|
||||
ProjectExplorerTreeView* tree_view_;
|
||||
ProjectExplorerIconView *icon_view_;
|
||||
ProjectExplorerListView *list_view_;
|
||||
ProjectExplorerTreeView *tree_view_;
|
||||
|
||||
ProjectToolbar::ViewType view_type_;
|
||||
ProjectToolbar::ViewType view_type_;
|
||||
|
||||
QSortFilterProxyModel sort_model_;
|
||||
ProjectViewModel model_;
|
||||
QSortFilterProxyModel sort_model_;
|
||||
ProjectViewModel model_;
|
||||
|
||||
QVector<Node*> context_menu_items_;
|
||||
QVector<Node *> context_menu_items_;
|
||||
|
||||
private slots:
|
||||
void ViewEmptyAreaDoubleClickedSlot();
|
||||
void ViewEmptyAreaDoubleClickedSlot();
|
||||
|
||||
void ItemDoubleClickedSlot(const QModelIndex& index);
|
||||
void ItemDoubleClickedSlot(const QModelIndex &index);
|
||||
|
||||
void SizeChangedSlot(int s);
|
||||
void SizeChangedSlot(int s);
|
||||
|
||||
void DirUpSlot();
|
||||
void DirUpSlot();
|
||||
|
||||
void ShowContextMenu();
|
||||
void ShowContextMenu();
|
||||
|
||||
void ShowItemPropertiesDialog();
|
||||
void ShowItemPropertiesDialog();
|
||||
|
||||
void RevealSelectedFootage();
|
||||
void RevealSelectedFootage();
|
||||
|
||||
void ReplaceSelectedFootage();
|
||||
void ReplaceSelectedFootage();
|
||||
|
||||
void OpenContextMenuItemInNewTab();
|
||||
void OpenContextMenuItemInNewTab();
|
||||
|
||||
void OpenContextMenuItemInNewWindow();
|
||||
void OpenContextMenuItemInNewWindow();
|
||||
|
||||
void ContextMenuStartProxy(QAction* a);
|
||||
|
||||
void ViewSelectionChanged();
|
||||
void ContextMenuStartProxy(QAction *a);
|
||||
|
||||
void ViewSelectionChanged();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,14 +20,15 @@
|
||||
|
||||
#include "projectexplorericonview.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
ProjectExplorerIconView::ProjectExplorerIconView(QWidget *parent) :
|
||||
ProjectExplorerListViewBase(parent)
|
||||
namespace olive
|
||||
{
|
||||
setViewMode(QListView::IconMode);
|
||||
|
||||
setItemDelegate(&delegate_);
|
||||
ProjectExplorerIconView::ProjectExplorerIconView(QWidget *parent)
|
||||
: ProjectExplorerListViewBase(parent)
|
||||
{
|
||||
setViewMode(QListView::IconMode);
|
||||
|
||||
setItemDelegate(&delegate_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,19 +24,19 @@
|
||||
#include "projectexplorerlistviewbase.h"
|
||||
#include "projectexplorericonviewitemdelegate.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The view widget used when ProjectExplorer is in Icon View
|
||||
*/
|
||||
class ProjectExplorerIconView : public ProjectExplorerListViewBase
|
||||
{
|
||||
Q_OBJECT
|
||||
class ProjectExplorerIconView : public ProjectExplorerListViewBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerIconView(QWidget* parent);
|
||||
ProjectExplorerIconView(QWidget *parent);
|
||||
|
||||
private:
|
||||
ProjectExplorerIconViewItemDelegate delegate_;
|
||||
ProjectExplorerIconViewItemDelegate delegate_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -24,79 +24,86 @@
|
||||
|
||||
#include "common/qtutils.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectExplorerIconViewItemDelegate::ProjectExplorerIconViewItemDelegate(QObject *parent) :
|
||||
QStyledItemDelegate (parent)
|
||||
ProjectExplorerIconViewItemDelegate::ProjectExplorerIconViewItemDelegate(
|
||||
QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QSize ProjectExplorerIconViewItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||
QSize ProjectExplorerIconViewItemDelegate::sizeHint(
|
||||
const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(option)
|
||||
|
||||
return QSize(256, 256);
|
||||
return QSize(256, 256);
|
||||
}
|
||||
|
||||
void ProjectExplorerIconViewItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
void ProjectExplorerIconViewItemDelegate::paint(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QFontMetrics fm = painter->fontMetrics();
|
||||
QRect img_rect = option.rect;
|
||||
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());
|
||||
// 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());
|
||||
QRect text_rect = option.rect;
|
||||
text_rect.setTop(text_rect.top() + option.rect.height() - fm.height());
|
||||
|
||||
QColor text_bgcolor;
|
||||
QColor text_fgcolor;
|
||||
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;
|
||||
}
|
||||
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);
|
||||
painter->fillRect(text_rect, text_bgcolor);
|
||||
painter->setPen(text_fgcolor);
|
||||
|
||||
QString duration_str = index.data(Qt::UserRole).toString();
|
||||
QString duration_str = index.data(Qt::UserRole).toString();
|
||||
|
||||
int timecode_width = QtUtils::QFontMetricsWidth(fm, duration_str);
|
||||
int timecode_width = QtUtils::QFontMetricsWidth(fm, duration_str);
|
||||
|
||||
int max_name_width = option.rect.width();
|
||||
int max_name_width = option.rect.width();
|
||||
|
||||
if (timecode_width < option.rect.width() / 2) {
|
||||
painter->drawText(text_rect, static_cast<int>(Qt::AlignBottom | Qt::AlignRight), index.data(Qt::UserRole).toString());
|
||||
max_name_width -= timecode_width;
|
||||
}
|
||||
if (timecode_width < option.rect.width() / 2) {
|
||||
painter->drawText(
|
||||
text_rect, static_cast<int>(Qt::AlignBottom | Qt::AlignRight),
|
||||
index.data(Qt::UserRole).toString());
|
||||
max_name_width -= timecode_width;
|
||||
}
|
||||
|
||||
painter->drawText(text_rect,
|
||||
static_cast<int>(Qt::AlignBottom | Qt::AlignLeft),
|
||||
fm.elidedText(index.data(Qt::DisplayRole).toString(), Qt::ElideRight, max_name_width));
|
||||
painter->drawText(text_rect,
|
||||
static_cast<int>(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));
|
||||
|
||||
// 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);
|
||||
|
||||
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);
|
||||
}
|
||||
painter->setCompositionMode(QPainter::CompositionMode_SourceAtop);
|
||||
painter->fillRect(img_rect, highlight_color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,17 +25,20 @@
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The delegate that's used to draw items when ProjectExplorer is in Icon view
|
||||
*/
|
||||
class ProjectExplorerIconViewItemDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
ProjectExplorerIconViewItemDelegate(QObject *parent = nullptr);
|
||||
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;
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,14 +20,15 @@
|
||||
|
||||
#include "projectexplorerlistview.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
ProjectExplorerListView::ProjectExplorerListView(QWidget *parent) :
|
||||
ProjectExplorerListViewBase(parent)
|
||||
namespace olive
|
||||
{
|
||||
setViewMode(QListView::ListMode);
|
||||
|
||||
setItemDelegate(&delegate_);
|
||||
ProjectExplorerListView::ProjectExplorerListView(QWidget *parent)
|
||||
: ProjectExplorerListViewBase(parent)
|
||||
{
|
||||
setViewMode(QListView::ListMode);
|
||||
|
||||
setItemDelegate(&delegate_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,19 +24,19 @@
|
||||
#include "projectexplorerlistviewbase.h"
|
||||
#include "projectexplorerlistviewitemdelegate.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The view widget used when ProjectExplorer is in List View
|
||||
*/
|
||||
class ProjectExplorerListView : public ProjectExplorerListViewBase
|
||||
{
|
||||
Q_OBJECT
|
||||
class ProjectExplorerListView : public ProjectExplorerListViewBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerListView(QWidget* parent);
|
||||
ProjectExplorerListView(QWidget *parent);
|
||||
|
||||
private:
|
||||
ProjectExplorerListViewItemDelegate delegate_;
|
||||
ProjectExplorerListViewItemDelegate delegate_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,36 +22,37 @@
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
namespace olive {
|
||||
|
||||
ProjectExplorerListViewBase::ProjectExplorerListViewBase(QWidget *parent) :
|
||||
QListView(parent)
|
||||
namespace olive
|
||||
{
|
||||
// FIXME Is this necessary?
|
||||
setMovement(QListView::Free);
|
||||
|
||||
// Set selection mode (allows multiple item selection)
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
ProjectExplorerListViewBase::ProjectExplorerListViewBase(QWidget *parent)
|
||||
: QListView(parent)
|
||||
{
|
||||
// FIXME Is this necessary?
|
||||
setMovement(QListView::Free);
|
||||
|
||||
// Set resize mode
|
||||
setResizeMode(QListView::Adjust);
|
||||
// Set selection mode (allows multiple item selection)
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
|
||||
// Set widget to emit a signal on right click
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
// Set resize mode
|
||||
setResizeMode(QListView::Adjust);
|
||||
|
||||
// Set widget to emit a signal on right click
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
}
|
||||
|
||||
void ProjectExplorerListViewBase::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
// Cache here so if the index becomes invalid after the base call, we still know the truth
|
||||
bool item_at_location = indexAt(event->pos()).isValid();
|
||||
// Cache here so if the index becomes invalid after the base call, we still know the truth
|
||||
bool item_at_location = indexAt(event->pos()).isValid();
|
||||
|
||||
// Perform default double click functions
|
||||
QListView::mouseDoubleClickEvent(event);
|
||||
// Perform default double click functions
|
||||
QListView::mouseDoubleClickEvent(event);
|
||||
|
||||
// QAbstractItemView already has a doubleClicked() signal, but we emit another here for double clicking empty space
|
||||
if (!item_at_location) {
|
||||
emit DoubleClickedEmptyArea();
|
||||
}
|
||||
// QAbstractItemView already has a doubleClicked() signal, but we emit another here for double clicking empty space
|
||||
if (!item_at_location) {
|
||||
emit DoubleClickedEmptyArea();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,20 +25,20 @@
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief A QListView derivative that contains functionality used by both List view and Icon view (which are both based
|
||||
* on QListView)
|
||||
*/
|
||||
class ProjectExplorerListViewBase : public QListView
|
||||
{
|
||||
Q_OBJECT
|
||||
class ProjectExplorerListViewBase : public QListView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerListViewBase(QWidget* parent);
|
||||
ProjectExplorerListViewBase(QWidget *parent);
|
||||
|
||||
protected:
|
||||
/**
|
||||
/**
|
||||
* @brief Double click event override
|
||||
*
|
||||
* Function that signals DoubleClickedView().
|
||||
@@ -46,15 +46,15 @@ protected:
|
||||
* FIXME: This code is the same as the code in ProjectExplorerTreeView. Is there a way to merge these two through
|
||||
* subclassing?
|
||||
*/
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
signals:
|
||||
/**
|
||||
/**
|
||||
* @brief Unconditional double click signal
|
||||
*
|
||||
* Emits a signal when the view is double clicked but not on any particular item
|
||||
*/
|
||||
void DoubleClickedEmptyArea();
|
||||
void DoubleClickedEmptyArea();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,62 +22,69 @@
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
namespace olive {
|
||||
|
||||
ProjectExplorerListViewItemDelegate::ProjectExplorerListViewItemDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
namespace olive
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QSize ProjectExplorerListViewItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||
ProjectExplorerListViewItemDelegate::ProjectExplorerListViewItemDelegate(
|
||||
QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
return QSize(option.decorationSize.height(), option.decorationSize.height());
|
||||
}
|
||||
|
||||
void ProjectExplorerListViewItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
QSize ProjectExplorerListViewItemDelegate::sizeHint(
|
||||
const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||
{
|
||||
QFontMetrics fm = painter->fontMetrics();
|
||||
QRect img_rect = option.rect;
|
||||
return QSize(option.decorationSize.height(),
|
||||
option.decorationSize.height());
|
||||
}
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
painter->fillRect(option.rect, option.palette.highlight());
|
||||
}
|
||||
void ProjectExplorerListViewItemDelegate::paint(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QFontMetrics fm = painter->fontMetrics();
|
||||
QRect img_rect = option.rect;
|
||||
|
||||
img_rect.setWidth(qMin(img_rect.width(), img_rect.height()));
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
painter->fillRect(option.rect, option.palette.highlight());
|
||||
}
|
||||
|
||||
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));
|
||||
img_rect.setWidth(qMin(img_rect.width(), img_rect.height()));
|
||||
|
||||
QRect text_rect = option.rect;
|
||||
text_rect.setLeft(text_rect.left() + option.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));
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
QRect text_rect = option.rect;
|
||||
text_rect.setLeft(text_rect.left() + option.rect.height());
|
||||
|
||||
painter->setPen(option.state & QStyle::State_Selected ?
|
||||
option.palette.highlightedText().color() : option.palette.text().color());
|
||||
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->drawText(text_rect, static_cast<int>(Qt::AlignLeft | Qt::AlignVCenter), text);
|
||||
painter->setPen(option.state & QStyle::State_Selected ?
|
||||
option.palette.highlightedText().color() :
|
||||
option.palette.text().color());
|
||||
|
||||
painter->drawText(text_rect,
|
||||
static_cast<int>(Qt::AlignLeft | Qt::AlignVCenter), text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,18 +25,20 @@
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The delegate that's used to draw items when ProjectExplorer is in List view
|
||||
*/
|
||||
class ProjectExplorerListViewItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
class ProjectExplorerListViewItemDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
ProjectExplorerListViewItemDelegate(QObject *parent = nullptr);
|
||||
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;
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -26,74 +26,77 @@
|
||||
#include "common/define.h"
|
||||
#include "ui/icons/icons.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
ProjectExplorerNavigation::ProjectExplorerNavigation(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
namespace olive
|
||||
{
|
||||
// Create widget layout
|
||||
QHBoxLayout* layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// Create "directory up" button
|
||||
dir_up_btn_ = new QPushButton(this);
|
||||
dir_up_btn_->setEnabled(false);
|
||||
dir_up_btn_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||
layout->addWidget(dir_up_btn_);
|
||||
connect(dir_up_btn_, SIGNAL(clicked(bool)), this, SIGNAL(DirectoryUpClicked()));
|
||||
ProjectExplorerNavigation::ProjectExplorerNavigation(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
// Create widget layout
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// Create directory tree label
|
||||
dir_lbl_ = new QLabel(this);
|
||||
dir_lbl_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
layout->addWidget(dir_lbl_);
|
||||
// Create "directory up" button
|
||||
dir_up_btn_ = new QPushButton(this);
|
||||
dir_up_btn_->setEnabled(false);
|
||||
dir_up_btn_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||
layout->addWidget(dir_up_btn_);
|
||||
connect(dir_up_btn_, SIGNAL(clicked(bool)), this,
|
||||
SIGNAL(DirectoryUpClicked()));
|
||||
|
||||
// Create size slider
|
||||
size_slider_ = new QSlider(this);
|
||||
size_slider_->setOrientation(Qt::Horizontal);
|
||||
size_slider_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
layout->addWidget(size_slider_);
|
||||
connect(size_slider_, SIGNAL(valueChanged(int)), this, SIGNAL(SizeChanged(int)));
|
||||
// Create directory tree label
|
||||
dir_lbl_ = new QLabel(this);
|
||||
dir_lbl_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
layout->addWidget(dir_lbl_);
|
||||
|
||||
Retranslate();
|
||||
UpdateIcons();
|
||||
// Create size slider
|
||||
size_slider_ = new QSlider(this);
|
||||
size_slider_->setOrientation(Qt::Horizontal);
|
||||
size_slider_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
layout->addWidget(size_slider_);
|
||||
connect(size_slider_, SIGNAL(valueChanged(int)), this,
|
||||
SIGNAL(SizeChanged(int)));
|
||||
|
||||
Retranslate();
|
||||
UpdateIcons();
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::set_text(const QString &s)
|
||||
{
|
||||
dir_lbl_->setText(s);
|
||||
dir_lbl_->setText(s);
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::set_dir_up_enabled(bool e)
|
||||
{
|
||||
dir_up_btn_->setEnabled(e);
|
||||
dir_up_btn_->setEnabled(e);
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::set_size_value(int s)
|
||||
{
|
||||
size_slider_->setValue(s);
|
||||
size_slider_->setValue(s);
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
Retranslate();
|
||||
} else if (e->type() == QEvent::StyleChange) {
|
||||
UpdateIcons();
|
||||
}
|
||||
QWidget::changeEvent(e);
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
Retranslate();
|
||||
} else if (e->type() == QEvent::StyleChange) {
|
||||
UpdateIcons();
|
||||
}
|
||||
QWidget::changeEvent(e);
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::Retranslate()
|
||||
{
|
||||
dir_up_btn_->setToolTip(tr("Go to parent folder"));
|
||||
dir_up_btn_->setToolTip(tr("Go to parent folder"));
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::UpdateIcons()
|
||||
{
|
||||
dir_up_btn_->setIcon(icon::DirUp);
|
||||
size_slider_->setMinimum(kProjectIconSizeMinimum);
|
||||
size_slider_->setMaximum(kProjectIconSizeMaximum);
|
||||
size_slider_->setValue(kProjectIconSizeDefault);
|
||||
dir_up_btn_->setIcon(icon::DirUp);
|
||||
size_slider_->setMinimum(kProjectIconSizeMinimum);
|
||||
size_slider_->setMaximum(kProjectIconSizeMaximum);
|
||||
size_slider_->setValue(kProjectIconSizeDefault);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief A navigation bar widget for ProjectExplorer's Icon and List views
|
||||
@@ -49,29 +50,28 @@ namespace olive {
|
||||
* By default, the directory up button is disabled (assuming root folder), the text is empty, and the icon size slider
|
||||
* is set to kProjectIconSizeDefault.
|
||||
*/
|
||||
class ProjectExplorerNavigation : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
class ProjectExplorerNavigation : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerNavigation(QWidget* parent);
|
||||
ProjectExplorerNavigation(QWidget *parent);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Sets the text string
|
||||
*
|
||||
* This text is intended to be set to the current Folder's name
|
||||
*
|
||||
* @param s
|
||||
*/
|
||||
void set_text(const QString& s);
|
||||
void set_text(const QString &s);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Set whether the "directory up" button is enabled or not
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
void set_dir_up_enabled(bool e);
|
||||
void set_dir_up_enabled(bool e);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Set the current value of the size slider
|
||||
*
|
||||
* NOTE: Does NOT emit SizeChanged().
|
||||
@@ -80,36 +80,36 @@ public:
|
||||
*
|
||||
* New size value to set to
|
||||
*/
|
||||
void set_size_value(int s);
|
||||
void set_size_value(int s);
|
||||
|
||||
signals:
|
||||
/**
|
||||
/**
|
||||
* @brief Signal emitted when the directory up button is clicked
|
||||
*/
|
||||
void DirectoryUpClicked();
|
||||
void DirectoryUpClicked();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Signal emitted when the icon size slider changes value
|
||||
*
|
||||
* @param size
|
||||
*
|
||||
* New size set in the slider
|
||||
*/
|
||||
void SizeChanged(int size);
|
||||
void SizeChanged(int size);
|
||||
|
||||
protected:
|
||||
virtual void changeEvent(QEvent *) override;
|
||||
virtual void changeEvent(QEvent *) override;
|
||||
|
||||
private:
|
||||
void Retranslate();
|
||||
void Retranslate();
|
||||
|
||||
void UpdateIcons();
|
||||
void UpdateIcons();
|
||||
|
||||
QPushButton* dir_up_btn_;
|
||||
QPushButton *dir_up_btn_;
|
||||
|
||||
QLabel* dir_lbl_;
|
||||
QLabel *dir_lbl_;
|
||||
|
||||
QSlider* size_slider_;
|
||||
QSlider *size_slider_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,36 +22,37 @@
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
namespace olive {
|
||||
|
||||
ProjectExplorerTreeView::ProjectExplorerTreeView(QWidget *parent) :
|
||||
QTreeView(parent)
|
||||
namespace olive
|
||||
{
|
||||
// Set selection mode (allows multiple item selection)
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
|
||||
// Allow dragging and dropping
|
||||
setDragDropMode(QAbstractItemView::DragDrop);
|
||||
ProjectExplorerTreeView::ProjectExplorerTreeView(QWidget *parent)
|
||||
: QTreeView(parent)
|
||||
{
|
||||
// Set selection mode (allows multiple item selection)
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
|
||||
// Enable dragging
|
||||
setDragEnabled(true);
|
||||
// Allow dragging and dropping
|
||||
setDragDropMode(QAbstractItemView::DragDrop);
|
||||
|
||||
// Allow dropping from external sources
|
||||
setAcceptDrops(true);
|
||||
// Enable dragging
|
||||
setDragEnabled(true);
|
||||
|
||||
// Set context menu to emit a signal
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
// Allow dropping from external sources
|
||||
setAcceptDrops(true);
|
||||
|
||||
// Set context menu to emit a signal
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
}
|
||||
|
||||
void ProjectExplorerTreeView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
// Perform default double click functions
|
||||
QTreeView::mouseDoubleClickEvent(event);
|
||||
// Perform default double click functions
|
||||
QTreeView::mouseDoubleClickEvent(event);
|
||||
|
||||
// QAbstractItemView already has a doubleClicked() signal, but we emit another here for double clicking empty space
|
||||
if (!indexAt(event->pos()).isValid()) {
|
||||
emit DoubleClickedEmptyArea();
|
||||
}
|
||||
// QAbstractItemView already has a doubleClicked() signal, but we emit another here for double clicking empty space
|
||||
if (!indexAt(event->pos()).isValid()) {
|
||||
emit DoubleClickedEmptyArea();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The view widget used when ProjectExplorer is in Tree View
|
||||
@@ -33,14 +34,13 @@ namespace olive {
|
||||
* A fairly simple subclass of QTreeView that provides a double clicked signal whether the index is valid or not
|
||||
* (QAbstractItemView has a doubleClicked() signal but it's only emitted with a valid index).
|
||||
*/
|
||||
class ProjectExplorerTreeView : public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
class ProjectExplorerTreeView : public QTreeView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerTreeView(QWidget* parent);
|
||||
ProjectExplorerTreeView(QWidget *parent);
|
||||
|
||||
protected:
|
||||
/**
|
||||
/**
|
||||
* @brief Double click event override
|
||||
*
|
||||
* Function that signals DoubleClickedView().
|
||||
@@ -48,15 +48,15 @@ protected:
|
||||
* FIXME: This code is the same as the code in ProjectExplorerListViewBase. Is there a way to merge these two through
|
||||
*
|
||||
*/
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
signals:
|
||||
/**
|
||||
/**
|
||||
* @brief Unconditional double click signal
|
||||
*
|
||||
* Emits a signal when the view is double clicked but not on any particular item
|
||||
*/
|
||||
void DoubleClickedEmptyArea();
|
||||
void DoubleClickedEmptyArea();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
#include "undo/undocommand.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -28,517 +28,544 @@
|
||||
#include "core.h"
|
||||
#include "node/nodeundo.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectViewModel::ProjectViewModel(QObject *parent) :
|
||||
QAbstractItemModel(parent),
|
||||
project_(nullptr)
|
||||
ProjectViewModel::ProjectViewModel(QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
, project_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Project *ProjectViewModel::project() const
|
||||
{
|
||||
return project_;
|
||||
return project_;
|
||||
}
|
||||
|
||||
void ProjectViewModel::set_project(Project *p)
|
||||
{
|
||||
beginResetModel();
|
||||
beginResetModel();
|
||||
|
||||
if (project_) {
|
||||
DisconnectItem(project_->root());
|
||||
}
|
||||
if (project_) {
|
||||
DisconnectItem(project_->root());
|
||||
}
|
||||
|
||||
project_ = p;
|
||||
project_ = p;
|
||||
|
||||
if (project_) {
|
||||
ConnectItem(project_->root());
|
||||
}
|
||||
if (project_) {
|
||||
ConnectItem(project_->root());
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QModelIndex ProjectViewModel::index(int row, int column, const QModelIndex &parent) const
|
||||
QModelIndex ProjectViewModel::index(int row, int column,
|
||||
const QModelIndex &parent) const
|
||||
{
|
||||
// I'm actually not 100% sure what this does, but it seems logical and was in the earlier code
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
return QModelIndex();
|
||||
}
|
||||
// I'm actually not 100% sure what this does, but it seems logical and was in the earlier code
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
// Get the parent object, we assume it's a folder since only folders can have children
|
||||
Folder* item_parent = static_cast<Folder*>(GetItemObjectFromIndex(parent));
|
||||
// Get the parent object, we assume it's a folder since only folders can have children
|
||||
Folder *item_parent = static_cast<Folder *>(GetItemObjectFromIndex(parent));
|
||||
|
||||
// Return an index to this object
|
||||
return createIndex(row, column, item_parent->item_child(row));
|
||||
// Return an index to this object
|
||||
return createIndex(row, column, item_parent->item_child(row));
|
||||
}
|
||||
|
||||
QModelIndex ProjectViewModel::parent(const QModelIndex &child) const
|
||||
{
|
||||
// Get the Item object from the index
|
||||
Node* item = GetItemObjectFromIndex(child);
|
||||
// Get the Item object from the index
|
||||
Node *item = GetItemObjectFromIndex(child);
|
||||
|
||||
// Get Item's parent object
|
||||
Folder* par = item->folder();
|
||||
// Get Item's parent object
|
||||
Folder *par = item->folder();
|
||||
|
||||
// If the parent is the root, return an empty index
|
||||
if (par == project_->root()) {
|
||||
return QModelIndex();
|
||||
}
|
||||
// If the parent is the root, return an empty index
|
||||
if (par == project_->root()) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
// Otherwise return a true index to its parent
|
||||
int parent_index = IndexOfChild(par);
|
||||
// Otherwise return a true index to its parent
|
||||
int parent_index = IndexOfChild(par);
|
||||
|
||||
// Make sure the index is valid (there's no reason it shouldn't be)
|
||||
Q_ASSERT(parent_index > -1);
|
||||
// Make sure the index is valid (there's no reason it shouldn't be)
|
||||
Q_ASSERT(parent_index > -1);
|
||||
|
||||
// Return an index to the parent
|
||||
return createIndex(parent_index, 0, par);
|
||||
// Return an index to the parent
|
||||
return createIndex(parent_index, 0, par);
|
||||
}
|
||||
|
||||
int ProjectViewModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
// If there's no project, there are obviously no items to show
|
||||
if (project_ == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
// If there's no project, there are obviously no items to show
|
||||
if (project_ == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If the index is the root, return the root child count
|
||||
if (parent == QModelIndex()) {
|
||||
return project_->root()->item_child_count();
|
||||
}
|
||||
// If the index is the root, return the root child count
|
||||
if (parent == QModelIndex()) {
|
||||
return project_->root()->item_child_count();
|
||||
}
|
||||
|
||||
// Otherwise, the index must contain a valid pointer, so we just return its child count
|
||||
return static_cast<Folder*>(GetItemObjectFromIndex(parent))->item_child_count();
|
||||
// Otherwise, the index must contain a valid pointer, so we just return its child count
|
||||
return static_cast<Folder *>(GetItemObjectFromIndex(parent))
|
||||
->item_child_count();
|
||||
}
|
||||
|
||||
int ProjectViewModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
Q_UNUSED(parent)
|
||||
|
||||
// Not strictly necessary, but a decent visual cue that there's no project currently active
|
||||
if (project_ == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
// Not strictly necessary, but a decent visual cue that there's no project currently active
|
||||
if (project_ == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return kColumnCount;
|
||||
return kColumnCount;
|
||||
}
|
||||
|
||||
QVariant ProjectViewModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
Node* internal_item = GetItemObjectFromIndex(index);
|
||||
Node *internal_item = GetItemObjectFromIndex(index);
|
||||
|
||||
ColumnType column_type = static_cast<ColumnType>(index.column());
|
||||
ColumnType column_type = static_cast<ColumnType>(index.column());
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case kInnerTextRole:
|
||||
{
|
||||
// Standard text role
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case kInnerTextRole: {
|
||||
// Standard text role
|
||||
|
||||
switch (column_type) {
|
||||
case kName:
|
||||
return internal_item->GetLabel();
|
||||
case kDuration:
|
||||
return internal_item->data(Node::DURATION);
|
||||
case kRate:
|
||||
return internal_item->data(Node::FREQUENCY_RATE);
|
||||
case kLastModified:
|
||||
case kCreatedTime:
|
||||
{
|
||||
qint64 using_time = (column_type == kLastModified) ? internal_item->data(Node::MODIFIED_TIME).toLongLong() : internal_item->data(Node::CREATED_TIME).toLongLong();
|
||||
switch (column_type) {
|
||||
case kName:
|
||||
return internal_item->GetLabel();
|
||||
case kDuration:
|
||||
return internal_item->data(Node::DURATION);
|
||||
case kRate:
|
||||
return internal_item->data(Node::FREQUENCY_RATE);
|
||||
case kLastModified:
|
||||
case kCreatedTime: {
|
||||
qint64 using_time =
|
||||
(column_type == kLastModified) ?
|
||||
internal_item->data(Node::MODIFIED_TIME).toLongLong() :
|
||||
internal_item->data(Node::CREATED_TIME).toLongLong();
|
||||
|
||||
if (using_time == 0) {
|
||||
// 0 is the null value, return nothing
|
||||
break;
|
||||
}
|
||||
if (using_time == 0) {
|
||||
// 0 is the null value, return nothing
|
||||
break;
|
||||
}
|
||||
|
||||
QVariant ret;
|
||||
QVariant ret;
|
||||
|
||||
if (role == kInnerTextRole) {
|
||||
// Use time value directly for correct sorting
|
||||
ret = using_time;
|
||||
} else {
|
||||
// Display role, format to a human readable string
|
||||
ret = QtUtils::GetFormattedDateTime(QDateTime::fromSecsSinceEpoch(using_time));
|
||||
}
|
||||
if (role == kInnerTextRole) {
|
||||
// Use time value directly for correct sorting
|
||||
ret = using_time;
|
||||
} else {
|
||||
// Display role, format to a human readable string
|
||||
ret = QtUtils::GetFormattedDateTime(
|
||||
QDateTime::fromSecsSinceEpoch(using_time));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
case kColumnCount:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Qt::EditRole:
|
||||
if (column_type == kName) {
|
||||
return internal_item->GetLabel();
|
||||
}
|
||||
break;
|
||||
case Qt::DecorationRole:
|
||||
// If this is the first column, return the Item's icon
|
||||
if (column_type == kName) {
|
||||
return internal_item->data(Node::ICON);
|
||||
}
|
||||
break;
|
||||
case Qt::ToolTipRole:
|
||||
return internal_item->data(Node::TOOLTIP);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
case kColumnCount:
|
||||
break;
|
||||
}
|
||||
} break;
|
||||
case Qt::EditRole:
|
||||
if (column_type == kName) {
|
||||
return internal_item->GetLabel();
|
||||
}
|
||||
break;
|
||||
case Qt::DecorationRole:
|
||||
// If this is the first column, return the Item's icon
|
||||
if (column_type == kName) {
|
||||
return internal_item->data(Node::ICON);
|
||||
}
|
||||
break;
|
||||
case Qt::ToolTipRole:
|
||||
return internal_item->data(Node::TOOLTIP);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant ProjectViewModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
QVariant ProjectViewModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
// Check if we need text data (DisplayRole) and orientation is horizontal
|
||||
// FIXME I'm not 100% sure what happens if the orientation is vertical/if that check is necessary
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||
ColumnType column_type = static_cast<ColumnType>(section);
|
||||
// Check if we need text data (DisplayRole) and orientation is horizontal
|
||||
// FIXME I'm not 100% sure what happens if the orientation is vertical/if that check is necessary
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||
ColumnType column_type = static_cast<ColumnType>(section);
|
||||
|
||||
// Return the name based on the column's current type
|
||||
switch (column_type) {
|
||||
case kName:
|
||||
return tr("Name");
|
||||
case kDuration:
|
||||
return tr("Duration");
|
||||
case kRate:
|
||||
return tr("Rate");
|
||||
case kLastModified:
|
||||
return tr("Modified");
|
||||
case kCreatedTime:
|
||||
return tr("Created");
|
||||
case kColumnCount:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Return the name based on the column's current type
|
||||
switch (column_type) {
|
||||
case kName:
|
||||
return tr("Name");
|
||||
case kDuration:
|
||||
return tr("Duration");
|
||||
case kRate:
|
||||
return tr("Rate");
|
||||
case kLastModified:
|
||||
return tr("Modified");
|
||||
case kCreatedTime:
|
||||
return tr("Created");
|
||||
case kColumnCount:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return QAbstractItemModel::headerData(section, orientation, role);
|
||||
return QAbstractItemModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
bool ProjectViewModel::hasChildren(const QModelIndex &parent) const
|
||||
{
|
||||
// If it's a folder, we always return TRUE in order to always show the "expand triangle" icon,
|
||||
// even when there are no "physical" children
|
||||
Node* item = GetItemObjectFromIndex(parent);
|
||||
// If it's a folder, we always return TRUE in order to always show the "expand triangle" icon,
|
||||
// even when there are no "physical" children
|
||||
Node *item = GetItemObjectFromIndex(parent);
|
||||
|
||||
return dynamic_cast<Folder*>(item);
|
||||
return dynamic_cast<Folder *>(item);
|
||||
}
|
||||
|
||||
bool ProjectViewModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
bool ProjectViewModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
int role)
|
||||
{
|
||||
// The name is editable
|
||||
if (index.isValid() && index.column() == kName && role == Qt::EditRole) {
|
||||
Node* item = GetItemObjectFromIndex(index);
|
||||
// The name is editable
|
||||
if (index.isValid() && index.column() == kName && role == Qt::EditRole) {
|
||||
Node *item = GetItemObjectFromIndex(index);
|
||||
|
||||
QString new_name = value.toString();
|
||||
QString new_name = value.toString();
|
||||
|
||||
if (!new_name.isEmpty()) {
|
||||
NodeRenameCommand* nrc = new NodeRenameCommand();
|
||||
if (!new_name.isEmpty()) {
|
||||
NodeRenameCommand *nrc = new NodeRenameCommand();
|
||||
|
||||
nrc->AddNode(item, value.toString());
|
||||
nrc->AddNode(item, value.toString());
|
||||
|
||||
Core::instance()->undo_stack()->push(nrc, tr("Renamed Item \"%1\" to \"%2\"").arg(item->GetLabel(), new_name));
|
||||
Core::instance()->undo_stack()->push(
|
||||
nrc, tr("Renamed Item \"%1\" to \"%2\"")
|
||||
.arg(item->GetLabel(), new_name));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ProjectViewModel::canFetchMore(const QModelIndex &parent) const
|
||||
{
|
||||
// Use the same hack that always returns true with folders so the expand triangle is always visible
|
||||
return hasChildren(parent);
|
||||
// Use the same hack that always returns true with folders so the expand triangle is always visible
|
||||
return hasChildren(parent);
|
||||
}
|
||||
|
||||
Qt::ItemFlags ProjectViewModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
// Allow dropping files from external sources
|
||||
return Qt::ItemIsDropEnabled;
|
||||
}
|
||||
if (!index.isValid()) {
|
||||
// Allow dropping files from external sources
|
||||
return Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
||||
Qt::ItemFlags f = Qt::ItemIsDragEnabled | QAbstractItemModel::flags(index);
|
||||
Qt::ItemFlags f = Qt::ItemIsDragEnabled | QAbstractItemModel::flags(index);
|
||||
|
||||
if (dynamic_cast<Folder*>(GetItemObjectFromIndex(index))) {
|
||||
f |= Qt::ItemIsDropEnabled;
|
||||
}
|
||||
if (dynamic_cast<Folder *>(GetItemObjectFromIndex(index))) {
|
||||
f |= Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
||||
// If the column is the kName column, that means it's editable
|
||||
if (index.column() == kName) {
|
||||
f |= Qt::ItemIsEditable;
|
||||
}
|
||||
// If the column is the kName column, that means it's editable
|
||||
if (index.column() == kName) {
|
||||
f |= Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
return f;
|
||||
return f;
|
||||
}
|
||||
|
||||
QStringList ProjectViewModel::mimeTypes() const
|
||||
{
|
||||
// Allow data from this model and a file list from external sources
|
||||
return {Project::kItemMimeType, QStringLiteral("text/uri-list")};
|
||||
// Allow data from this model and a file list from external sources
|
||||
return { Project::kItemMimeType, QStringLiteral("text/uri-list") };
|
||||
}
|
||||
|
||||
QMimeData *ProjectViewModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
// Compliance with Qt standard
|
||||
if (indexes.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
// Compliance with Qt standard
|
||||
if (indexes.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Encode mime data for the rows/items that were dragged
|
||||
QMimeData* data = new QMimeData();
|
||||
// Encode mime data for the rows/items that were dragged
|
||||
QMimeData *data = new QMimeData();
|
||||
|
||||
// Use QDataStream to stream the item data into a byte array
|
||||
QByteArray encoded_data;
|
||||
QDataStream stream(&encoded_data, QIODevice::WriteOnly);
|
||||
// Use QDataStream to stream the item data into a byte array
|
||||
QByteArray encoded_data;
|
||||
QDataStream stream(&encoded_data, QIODevice::WriteOnly);
|
||||
|
||||
// The indexes list includes indexes for each column which we don't use. To make sure each row only gets sent *once*,
|
||||
// we keep a list of dragged items
|
||||
QVector<void*> dragged_items;
|
||||
// The indexes list includes indexes for each column which we don't use. To make sure each row only gets sent *once*,
|
||||
// we keep a list of dragged items
|
||||
QVector<void *> dragged_items;
|
||||
|
||||
foreach (QModelIndex index, indexes) {
|
||||
if (index.isValid()) {
|
||||
// Check if we've dragged this item before
|
||||
if (!dragged_items.contains(index.internalPointer())) {
|
||||
// If not, add it to the stream (and also keep track of it in the vector)
|
||||
Node *item = static_cast<Node*>(index.internalPointer());
|
||||
QVector<Track::Reference> streams;
|
||||
foreach (QModelIndex index, indexes) {
|
||||
if (index.isValid()) {
|
||||
// Check if we've dragged this item before
|
||||
if (!dragged_items.contains(index.internalPointer())) {
|
||||
// If not, add it to the stream (and also keep track of it in the vector)
|
||||
Node *item = static_cast<Node *>(index.internalPointer());
|
||||
QVector<Track::Reference> streams;
|
||||
|
||||
if (ViewerOutput* footage = dynamic_cast<ViewerOutput*>(item)) {
|
||||
streams = footage->GetEnabledStreamsAsReferences();
|
||||
}
|
||||
if (ViewerOutput *footage =
|
||||
dynamic_cast<ViewerOutput *>(item)) {
|
||||
streams = footage->GetEnabledStreamsAsReferences();
|
||||
}
|
||||
|
||||
stream << streams << reinterpret_cast<quintptr>(item);
|
||||
stream << streams << reinterpret_cast<quintptr>(item);
|
||||
|
||||
dragged_items.append(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
dragged_items.append(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set byte array as the mime data and return the mime data
|
||||
data->setData(Project::kItemMimeType, encoded_data);
|
||||
// Set byte array as the mime data and return the mime data
|
||||
data->setData(Project::kItemMimeType, encoded_data);
|
||||
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
bool ProjectViewModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &drop)
|
||||
bool ProjectViewModel::dropMimeData(const QMimeData *data,
|
||||
Qt::DropAction action, int row, int column,
|
||||
const QModelIndex &drop)
|
||||
{
|
||||
// Default recommended checks from https://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
|
||||
if (!canDropMimeData(data, action, row, column, drop)) {
|
||||
return false;
|
||||
}
|
||||
// Default recommended checks from https://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
|
||||
if (!canDropMimeData(data, action, row, column, drop)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (action == Qt::IgnoreAction) {
|
||||
return true;
|
||||
}
|
||||
if (action == Qt::IgnoreAction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Probe mime data for its format
|
||||
QStringList mime_formats = data->formats();
|
||||
// Probe mime data for its format
|
||||
QStringList mime_formats = data->formats();
|
||||
|
||||
if (mime_formats.contains(Project::kItemMimeType)) {
|
||||
// Data is drag/drop data from this model
|
||||
QByteArray model_data = data->data(Project::kItemMimeType);
|
||||
if (mime_formats.contains(Project::kItemMimeType)) {
|
||||
// Data is drag/drop data from this model
|
||||
QByteArray model_data = data->data(Project::kItemMimeType);
|
||||
|
||||
// Use QDataStream to deserialize the data
|
||||
QDataStream stream(&model_data, QIODevice::ReadOnly);
|
||||
// Use QDataStream to deserialize the data
|
||||
QDataStream stream(&model_data, QIODevice::ReadOnly);
|
||||
|
||||
// Get the Item object that the items were dropped on
|
||||
Folder* drop_location = dynamic_cast<Folder*>(GetItemObjectFromIndex(drop));
|
||||
// Get the Item object that the items were dropped on
|
||||
Folder *drop_location =
|
||||
dynamic_cast<Folder *>(GetItemObjectFromIndex(drop));
|
||||
|
||||
// If this is not a folder, we cannot drop these items here
|
||||
if (!drop_location) {
|
||||
return false;
|
||||
}
|
||||
// If this is not a folder, we cannot drop these items here
|
||||
if (!drop_location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Variables to deserialize into
|
||||
quintptr item_ptr;
|
||||
QList<Track::Reference> streams;
|
||||
// Variables to deserialize into
|
||||
quintptr item_ptr;
|
||||
QList<Track::Reference> streams;
|
||||
|
||||
// Loop through all data
|
||||
MultiUndoCommand* move_command = new MultiUndoCommand();
|
||||
// Loop through all data
|
||||
MultiUndoCommand *move_command = new MultiUndoCommand();
|
||||
|
||||
int count = 0;
|
||||
int count = 0;
|
||||
|
||||
while (!stream.atEnd()) {
|
||||
stream >> streams >> item_ptr;
|
||||
while (!stream.atEnd()) {
|
||||
stream >> streams >> item_ptr;
|
||||
|
||||
Node* item = reinterpret_cast<Node*>(item_ptr);
|
||||
Node *item = reinterpret_cast<Node *>(item_ptr);
|
||||
|
||||
// Check if Item is already the drop location or if its parent is the drop location, in which case this is a
|
||||
// no-op
|
||||
// Check if Item is already the drop location or if its parent is the drop location, in which case this is a
|
||||
// no-op
|
||||
|
||||
if (item != drop_location && item->folder() != drop_location
|
||||
&& (!dynamic_cast<Folder*>(item) || !ItemIsParentOfChild(static_cast<Folder*>(item), drop_location))) {
|
||||
move_command->add_child(new NodeEdgeRemoveCommand(item, NodeInput(item->folder(), Folder::kChildInput, item->folder()->index_of_child_in_array(item))));
|
||||
move_command->add_child(new FolderAddChild(drop_location, item));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (item != drop_location && item->folder() != drop_location &&
|
||||
(!dynamic_cast<Folder *>(item) ||
|
||||
!ItemIsParentOfChild(static_cast<Folder *>(item),
|
||||
drop_location))) {
|
||||
move_command->add_child(new NodeEdgeRemoveCommand(
|
||||
item,
|
||||
NodeInput(item->folder(), Folder::kChildInput,
|
||||
item->folder()->index_of_child_in_array(item))));
|
||||
move_command->add_child(
|
||||
new FolderAddChild(drop_location, item));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->push(move_command, tr("Move %1 Item(s)").arg(count));
|
||||
Core::instance()->undo_stack()->push(move_command,
|
||||
tr("Move %1 Item(s)").arg(count));
|
||||
|
||||
return true;
|
||||
return true;
|
||||
|
||||
} else if (mime_formats.contains(QStringLiteral("text/uri-list"))) {
|
||||
// We received a list of files
|
||||
QByteArray file_data = data->data(QStringLiteral("text/uri-list"));
|
||||
} else if (mime_formats.contains(QStringLiteral("text/uri-list"))) {
|
||||
// We received a list of files
|
||||
QByteArray file_data = data->data(QStringLiteral("text/uri-list"));
|
||||
|
||||
// Use text stream to parse (just an easy way of sifting through line breaks
|
||||
QTextStream stream(&file_data);
|
||||
// Use text stream to parse (just an easy way of sifting through line breaks
|
||||
QTextStream stream(&file_data);
|
||||
|
||||
// Convert QByteArray to QStringList (which Core takes for importing)
|
||||
QStringList urls;
|
||||
while (!stream.atEnd()) {
|
||||
QUrl url = stream.readLine();
|
||||
// Convert QByteArray to QStringList (which Core takes for importing)
|
||||
QStringList urls;
|
||||
while (!stream.atEnd()) {
|
||||
QUrl url = stream.readLine();
|
||||
|
||||
if (!url.isEmpty()) {
|
||||
urls.append(url.toLocalFile());
|
||||
}
|
||||
}
|
||||
if (!url.isEmpty()) {
|
||||
urls.append(url.toLocalFile());
|
||||
}
|
||||
}
|
||||
|
||||
// Get folder dropped onto
|
||||
Node* drop_item = GetItemObjectFromIndex(drop);
|
||||
// Get folder dropped onto
|
||||
Node *drop_item = GetItemObjectFromIndex(drop);
|
||||
|
||||
// If we didn't drop onto an item, find the nearest parent folder (should eventually terminate at root either way)
|
||||
if (!dynamic_cast<Folder*>(drop_item)) {
|
||||
drop_item = drop_item->folder();
|
||||
// If we didn't drop onto an item, find the nearest parent folder (should eventually terminate at root either way)
|
||||
if (!dynamic_cast<Folder *>(drop_item)) {
|
||||
drop_item = drop_item->folder();
|
||||
|
||||
if (!drop_item) {
|
||||
// Failed to find folder to place this in
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!drop_item) {
|
||||
// Failed to find folder to place this in
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger an import
|
||||
Core::instance()->ImportFiles(urls, static_cast<Folder*>(drop_item));
|
||||
// Trigger an import
|
||||
Core::instance()->ImportFiles(urls, static_cast<Folder *>(drop_item));
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
int ProjectViewModel::IndexOfChild(Node *item) const
|
||||
{
|
||||
// Find parent's index within its own parent
|
||||
Folder* parent = item->folder();
|
||||
// Find parent's index within its own parent
|
||||
Folder *parent = item->folder();
|
||||
|
||||
if (parent) {
|
||||
return parent->index_of_child(item);
|
||||
}
|
||||
if (parent) {
|
||||
return parent->index_of_child(item);
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Node *ProjectViewModel::GetItemObjectFromIndex(const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid()) {
|
||||
return static_cast<Node*>(index.internalPointer());
|
||||
}
|
||||
if (index.isValid()) {
|
||||
return static_cast<Node *>(index.internalPointer());
|
||||
}
|
||||
|
||||
return project_ ? project_->root() : nullptr;
|
||||
return project_ ? project_->root() : nullptr;
|
||||
}
|
||||
|
||||
bool ProjectViewModel::ItemIsParentOfChild(Folder *parent, Node *child) const
|
||||
{
|
||||
// Loop through parent hierarchy checking if `parent` is one of its parents
|
||||
do {
|
||||
child = child->folder();
|
||||
// Loop through parent hierarchy checking if `parent` is one of its parents
|
||||
do {
|
||||
child = child->folder();
|
||||
|
||||
if (parent == child) {
|
||||
return true;
|
||||
}
|
||||
} while (child != nullptr);
|
||||
if (parent == child) {
|
||||
return true;
|
||||
}
|
||||
} while (child != nullptr);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void ProjectViewModel::ConnectItem(Node *n)
|
||||
{
|
||||
connect(n, &Node::LabelChanged, this, &ProjectViewModel::ItemRenamed);
|
||||
connect(n, &Node::LabelChanged, this, &ProjectViewModel::ItemRenamed);
|
||||
|
||||
Folder* f = dynamic_cast<Folder*>(n);
|
||||
if (f) {
|
||||
connect(f, &Folder::BeginInsertItem, this, &ProjectViewModel::FolderBeginInsertItem);
|
||||
connect(f, &Folder::EndInsertItem, this, &ProjectViewModel::FolderEndInsertItem);
|
||||
connect(f, &Folder::BeginRemoveItem, this, &ProjectViewModel::FolderBeginRemoveItem);
|
||||
connect(f, &Folder::EndRemoveItem, this, &ProjectViewModel::FolderEndRemoveItem);
|
||||
Folder *f = dynamic_cast<Folder *>(n);
|
||||
if (f) {
|
||||
connect(f, &Folder::BeginInsertItem, this,
|
||||
&ProjectViewModel::FolderBeginInsertItem);
|
||||
connect(f, &Folder::EndInsertItem, this,
|
||||
&ProjectViewModel::FolderEndInsertItem);
|
||||
connect(f, &Folder::BeginRemoveItem, this,
|
||||
&ProjectViewModel::FolderBeginRemoveItem);
|
||||
connect(f, &Folder::EndRemoveItem, this,
|
||||
&ProjectViewModel::FolderEndRemoveItem);
|
||||
|
||||
foreach (Node* c, f->children()) {
|
||||
ConnectItem(c);
|
||||
}
|
||||
}
|
||||
foreach (Node *c, f->children()) {
|
||||
ConnectItem(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectViewModel::DisconnectItem(Node *n)
|
||||
{
|
||||
disconnect(n, &Node::LabelChanged, this, &ProjectViewModel::ItemRenamed);
|
||||
disconnect(n, &Node::LabelChanged, this, &ProjectViewModel::ItemRenamed);
|
||||
|
||||
Folder* f = dynamic_cast<Folder*>(n);
|
||||
if (f) {
|
||||
disconnect(f, &Folder::BeginInsertItem, this, &ProjectViewModel::FolderBeginInsertItem);
|
||||
disconnect(f, &Folder::EndInsertItem, this, &ProjectViewModel::FolderEndInsertItem);
|
||||
disconnect(f, &Folder::BeginRemoveItem, this, &ProjectViewModel::FolderBeginRemoveItem);
|
||||
disconnect(f, &Folder::EndRemoveItem, this, &ProjectViewModel::FolderEndRemoveItem);
|
||||
Folder *f = dynamic_cast<Folder *>(n);
|
||||
if (f) {
|
||||
disconnect(f, &Folder::BeginInsertItem, this,
|
||||
&ProjectViewModel::FolderBeginInsertItem);
|
||||
disconnect(f, &Folder::EndInsertItem, this,
|
||||
&ProjectViewModel::FolderEndInsertItem);
|
||||
disconnect(f, &Folder::BeginRemoveItem, this,
|
||||
&ProjectViewModel::FolderBeginRemoveItem);
|
||||
disconnect(f, &Folder::EndRemoveItem, this,
|
||||
&ProjectViewModel::FolderEndRemoveItem);
|
||||
|
||||
foreach (Node* c, f->children()) {
|
||||
DisconnectItem(c);
|
||||
}
|
||||
}
|
||||
foreach (Node *c, f->children()) {
|
||||
DisconnectItem(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectViewModel::FolderBeginInsertItem(Node *n, int insert_index)
|
||||
{
|
||||
Folder* folder = static_cast<Folder*>(sender());
|
||||
Folder *folder = static_cast<Folder *>(sender());
|
||||
|
||||
ConnectItem(n);
|
||||
ConnectItem(n);
|
||||
|
||||
QModelIndex index;
|
||||
QModelIndex index;
|
||||
|
||||
if (folder != project_->root()) {
|
||||
index = CreateIndexFromItem(folder);
|
||||
}
|
||||
if (folder != project_->root()) {
|
||||
index = CreateIndexFromItem(folder);
|
||||
}
|
||||
|
||||
beginInsertRows(index, insert_index, insert_index);
|
||||
beginInsertRows(index, insert_index, insert_index);
|
||||
}
|
||||
|
||||
void ProjectViewModel::FolderEndInsertItem()
|
||||
{
|
||||
endInsertRows();
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void ProjectViewModel::FolderBeginRemoveItem(Node *n, int child_index)
|
||||
{
|
||||
Folder* folder = static_cast<Folder*>(sender());
|
||||
Folder *folder = static_cast<Folder *>(sender());
|
||||
|
||||
DisconnectItem(n);
|
||||
DisconnectItem(n);
|
||||
|
||||
QModelIndex index;
|
||||
QModelIndex index;
|
||||
|
||||
if (folder != project_->root()) {
|
||||
index = CreateIndexFromItem(folder);
|
||||
}
|
||||
if (folder != project_->root()) {
|
||||
index = CreateIndexFromItem(folder);
|
||||
}
|
||||
|
||||
beginRemoveRows(index, child_index, child_index);
|
||||
beginRemoveRows(index, child_index, child_index);
|
||||
}
|
||||
|
||||
void ProjectViewModel::FolderEndRemoveItem()
|
||||
{
|
||||
endRemoveRows();
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void ProjectViewModel::ItemRenamed()
|
||||
{
|
||||
Node* item = static_cast<Node*>(sender());
|
||||
Node *item = static_cast<Node *>(sender());
|
||||
|
||||
QModelIndex index = CreateIndexFromItem(item);
|
||||
QModelIndex index = CreateIndexFromItem(item);
|
||||
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
|
||||
}
|
||||
|
||||
QModelIndex ProjectViewModel::CreateIndexFromItem(Node *item, int column)
|
||||
{
|
||||
return createIndex(IndexOfChild(item), column, item);
|
||||
return createIndex(IndexOfChild(item), column, item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
#include "node/project.h"
|
||||
#include "undo/undocommand.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief An adapter that interprets the data in a Project into a Qt item model for usage in ViewModel Views.
|
||||
@@ -37,50 +38,49 @@ namespace olive {
|
||||
* ProjectViewModel so that the views can be efficiently and correctly updated. ProjectViewModel contains several
|
||||
* "wrapper" functions for Project and Item functions that also signal any connected views to update accordingly.
|
||||
*/
|
||||
class ProjectViewModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
class ProjectViewModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ColumnType {
|
||||
/// Media name
|
||||
kName,
|
||||
enum ColumnType {
|
||||
/// Media name
|
||||
kName,
|
||||
|
||||
/// Media duration
|
||||
kDuration,
|
||||
/// Media duration
|
||||
kDuration,
|
||||
|
||||
/// Media rate (frame rate for video, sample rate for audio)
|
||||
kRate,
|
||||
/// Media rate (frame rate for video, sample rate for audio)
|
||||
kRate,
|
||||
|
||||
/// Last modified time (for footage/files)
|
||||
kLastModified,
|
||||
/// Last modified time (for footage/files)
|
||||
kLastModified,
|
||||
|
||||
/// Creation time (for footage/files)
|
||||
kCreatedTime,
|
||||
/// Creation time (for footage/files)
|
||||
kCreatedTime,
|
||||
|
||||
/// Count
|
||||
kColumnCount
|
||||
};
|
||||
/// Count
|
||||
kColumnCount
|
||||
};
|
||||
|
||||
static const int kInnerTextRole = Qt::UserRole + 1;
|
||||
static const int kInnerTextRole = Qt::UserRole + 1;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief ProjectViewModel Constructor
|
||||
*
|
||||
* @param parent
|
||||
* Parent object for memory handling
|
||||
*/
|
||||
ProjectViewModel(QObject* parent);
|
||||
ProjectViewModel(QObject *parent);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Get currently active project
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* Currently active project or nullptr if there is none
|
||||
*/
|
||||
Project* project() const;
|
||||
Project *project() const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Set the project to adapt
|
||||
*
|
||||
* Any views attached to this model will get updated by this function.
|
||||
@@ -89,34 +89,44 @@ public:
|
||||
*
|
||||
* Project to adapt, can be set to nullptr to "close" the project (will show an empty model that cannot be modified)
|
||||
*/
|
||||
void set_project(Project* p);
|
||||
void set_project(Project *p);
|
||||
|
||||
/** Compulsory Qt QAbstractItemModel overrides */
|
||||
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual QModelIndex parent(const QModelIndex &child) const override;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
/** Compulsory Qt QAbstractItemModel overrides */
|
||||
virtual QModelIndex
|
||||
index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual QModelIndex parent(const QModelIndex &child) const override;
|
||||
virtual int
|
||||
rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual int
|
||||
columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual QVariant data(const QModelIndex &index,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
/** Optional Qt QAbstractItemModel overrides */
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
virtual bool canFetchMore(const QModelIndex &parent) const override;
|
||||
/** Optional Qt QAbstractItemModel overrides */
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
virtual bool
|
||||
hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
virtual bool canFetchMore(const QModelIndex &parent) const override;
|
||||
|
||||
/** Drag and drop support */
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
virtual QStringList mimeTypes() const override;
|
||||
virtual QMimeData * mimeData(const QModelIndexList &indexes) const override;
|
||||
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
||||
/** Drag and drop support */
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
virtual QStringList mimeTypes() const override;
|
||||
virtual QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
||||
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
||||
int row, int column,
|
||||
const QModelIndex &parent) override;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Convenience function for creating QModelIndexes from an Item object
|
||||
*/
|
||||
QModelIndex CreateIndexFromItem(Node *item, int column = 0);
|
||||
QModelIndex CreateIndexFromItem(Node *item, int column = 0);
|
||||
|
||||
private:
|
||||
/**
|
||||
/**
|
||||
* @brief Retrieve the index of `item` in its parent
|
||||
*
|
||||
* This function will return the index of a specified item in its parent according to whichever sorting algorithm
|
||||
@@ -126,39 +136,38 @@ private:
|
||||
*
|
||||
* Index of the specified item, or -1 if the item is root (in which case it has no parent).
|
||||
*/
|
||||
int IndexOfChild(Node* item) const;
|
||||
int IndexOfChild(Node *item) const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Retrieves the Item object from a given index
|
||||
*
|
||||
* A convenience function for retrieving Item objects. If the index is not valid, this returns the root Item.
|
||||
*/
|
||||
Node* GetItemObjectFromIndex(const QModelIndex& index) const;
|
||||
Node *GetItemObjectFromIndex(const QModelIndex &index) const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Check if an Item is a parent of a Child
|
||||
*
|
||||
* Checks entire "parent hierarchy" of `child` to see if `parent` is one of its parents.
|
||||
*/
|
||||
bool ItemIsParentOfChild(Folder *parent, Node* child) const;
|
||||
bool ItemIsParentOfChild(Folder *parent, Node *child) const;
|
||||
|
||||
void ConnectItem(Node* n);
|
||||
void ConnectItem(Node *n);
|
||||
|
||||
void DisconnectItem(Node *n);
|
||||
void DisconnectItem(Node *n);
|
||||
|
||||
Project* project_;
|
||||
Project *project_;
|
||||
|
||||
private slots:
|
||||
void FolderBeginInsertItem(Node *n, int insert_index);
|
||||
void FolderBeginInsertItem(Node *n, int insert_index);
|
||||
|
||||
void FolderEndInsertItem();
|
||||
void FolderEndInsertItem();
|
||||
|
||||
void FolderBeginRemoveItem(Node* n, int child_index);
|
||||
void FolderBeginRemoveItem(Node *n, int child_index);
|
||||
|
||||
void FolderEndRemoveItem();
|
||||
|
||||
void ItemRenamed();
|
||||
void FolderEndRemoveItem();
|
||||
|
||||
void ItemRenamed();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user