diff --git a/app/widget/projectexplorer/CMakeLists.txt b/app/widget/projectexplorer/CMakeLists.txt index aeb1d258a..610e2644b 100644 --- a/app/widget/projectexplorer/CMakeLists.txt +++ b/app/widget/projectexplorer/CMakeLists.txt @@ -20,5 +20,11 @@ set(OLIVE_SOURCES widget/projectexplorer/projectexplorer.cpp widget/projectexplorer/projectexplorertreeview.h widget/projectexplorer/projectexplorertreeview.cpp + widget/projectexplorer/projectexplorerlistview.h + widget/projectexplorer/projectexplorerlistview.cpp + widget/projectexplorer/projectexplorerlistviewbase.h + widget/projectexplorer/projectexplorerlistviewbase.cpp + widget/projectexplorer/projectexplorericonview.h + widget/projectexplorer/projectexplorericonview.cpp PARENT_SCOPE ) diff --git a/app/widget/projectexplorer/projectexplorer.cpp b/app/widget/projectexplorer/projectexplorer.cpp index e66b3e822..955a550ea 100644 --- a/app/widget/projectexplorer/projectexplorer.cpp +++ b/app/widget/projectexplorer/projectexplorer.cpp @@ -28,9 +28,13 @@ ProjectExplorer::ProjectExplorer(QWidget *parent) : model_(this) { tree_view_ = new ProjectExplorerTreeView(this); - tree_view_->setModel(&model_); - connect(tree_view_, SIGNAL(DoubleClickedView(const QModelIndex&)), this, SLOT(DoubleClickViewSlot(const QModelIndex&))); - addWidget(tree_view_); + AddView(tree_view_); + + list_view_ = new ProjectExplorerListView(this); + AddView(list_view_); + + icon_view_ = new ProjectExplorerIconView(this); + AddView(icon_view_); } const olive::ProjectViewType &ProjectExplorer::view_type() @@ -41,6 +45,16 @@ const olive::ProjectViewType &ProjectExplorer::view_type() void ProjectExplorer::set_view_type(olive::ProjectViewType type) { view_type_ = type; + + // Enum values correspond to the index of the widget in this stacked widget + setCurrentIndex(view_type_); +} + +void ProjectExplorer::AddView(QAbstractItemView *view) +{ + view->setModel(&model_); + connect(view, SIGNAL(DoubleClickedView(const QModelIndex&)), this, SLOT(DoubleClickViewSlot(const QModelIndex&))); + addWidget(view); } void ProjectExplorer::DoubleClickViewSlot(const QModelIndex &index) diff --git a/app/widget/projectexplorer/projectexplorer.h b/app/widget/projectexplorer/projectexplorer.h index 76c8c52c2..d27ba4f72 100644 --- a/app/widget/projectexplorer/projectexplorer.h +++ b/app/widget/projectexplorer/projectexplorer.h @@ -27,6 +27,8 @@ #include "project/project.h" #include "project/projectviewmodel.h" #include "project/projectviewtype.h" +#include "widget/projectexplorer/projectexplorericonview.h" +#include "widget/projectexplorer/projectexplorerlistview.h" #include "widget/projectexplorer/projectexplorertreeview.h" /** @@ -64,6 +66,19 @@ signals: void DoubleClickedItem(Item* item); private: + /** + * @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. + * + * @param view + * + * View to add to the stack + */ + void AddView(QAbstractItemView* view); + + ProjectExplorerIconView* icon_view_; + ProjectExplorerListView* list_view_; ProjectExplorerTreeView* tree_view_; olive::ProjectViewType view_type_; diff --git a/app/widget/projectexplorer/projectexplorericonview.cpp b/app/widget/projectexplorer/projectexplorericonview.cpp new file mode 100644 index 000000000..2adbc6b87 --- /dev/null +++ b/app/widget/projectexplorer/projectexplorericonview.cpp @@ -0,0 +1,27 @@ +/*** + + 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 "projectexplorericonview.h" + +ProjectExplorerIconView::ProjectExplorerIconView(QWidget *parent) : + ProjectExplorerListViewBase(parent) +{ + setViewMode(QListView::IconMode); +} diff --git a/app/widget/projectexplorer/projectexplorericonview.h b/app/widget/projectexplorer/projectexplorericonview.h new file mode 100644 index 000000000..a6af589db --- /dev/null +++ b/app/widget/projectexplorer/projectexplorericonview.h @@ -0,0 +1,33 @@ +/*** + + 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 PROJECTEXPLORERICONVIEW_H +#define PROJECTEXPLORERICONVIEW_H + +#include "projectexplorerlistviewbase.h" + +class ProjectExplorerIconView : public ProjectExplorerListViewBase +{ + Q_OBJECT +public: + ProjectExplorerIconView(QWidget* parent); +}; + +#endif // PROJECTEXPLORERICONVIEW_H diff --git a/app/widget/projectexplorer/projectexplorerlistview.cpp b/app/widget/projectexplorer/projectexplorerlistview.cpp new file mode 100644 index 000000000..c8d90fe92 --- /dev/null +++ b/app/widget/projectexplorer/projectexplorerlistview.cpp @@ -0,0 +1,27 @@ +/*** + + 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 "projectexplorerlistview.h" + +ProjectExplorerListView::ProjectExplorerListView(QWidget *parent) : + ProjectExplorerListViewBase(parent) +{ + setViewMode(QListView::ListMode); +} diff --git a/app/widget/projectexplorer/projectexplorerlistview.h b/app/widget/projectexplorer/projectexplorerlistview.h new file mode 100644 index 000000000..ba428f1c1 --- /dev/null +++ b/app/widget/projectexplorer/projectexplorerlistview.h @@ -0,0 +1,33 @@ +/*** + + 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 PROJECTEXPLORERLISTVIEW_H +#define PROJECTEXPLORERLISTVIEW_H + +#include "projectexplorerlistviewbase.h" + +class ProjectExplorerListView : public ProjectExplorerListViewBase +{ + Q_OBJECT +public: + ProjectExplorerListView(QWidget* parent); +}; + +#endif // PROJECTEXPLORERLISTVIEW_H diff --git a/app/widget/projectexplorer/projectexplorerlistviewbase.cpp b/app/widget/projectexplorer/projectexplorerlistviewbase.cpp new file mode 100644 index 000000000..a29099030 --- /dev/null +++ b/app/widget/projectexplorer/projectexplorerlistviewbase.cpp @@ -0,0 +1,51 @@ +/*** + + 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 "projectexplorerlistviewbase.h" + +#include + +ProjectExplorerListViewBase::ProjectExplorerListViewBase(QWidget *parent) : + QListView(parent) +{ + // FIXME Is this necessary? + setMovement(QListView::Free); + + // Set selection mode (allows multiple item selection) + setSelectionMode(QAbstractItemView::ExtendedSelection); + + // Set resize mode + setResizeMode(QListView::Adjust); + + // Set widget to emit a signal on right click + setContextMenuPolicy(Qt::CustomContextMenu); +} + +void ProjectExplorerListViewBase::mouseDoubleClickEvent(QMouseEvent *event) +{ + // Perform default double click functions + QListView::mouseDoubleClickEvent(event); + + // Get the index at whatever position was double clicked + QModelIndex index = indexAt(event->pos()); + + // Emit the signal with this index + emit DoubleClickedView(index); +} diff --git a/app/widget/projectexplorer/projectexplorerlistviewbase.h b/app/widget/projectexplorer/projectexplorerlistviewbase.h new file mode 100644 index 000000000..e589ddbe0 --- /dev/null +++ b/app/widget/projectexplorer/projectexplorerlistviewbase.h @@ -0,0 +1,52 @@ +/*** + + 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 PROJECTEXPLORERLISTVIEWBASE_H +#define PROJECTEXPLORERLISTVIEWBASE_H + +#include + +class ProjectExplorerListViewBase : public QListView +{ + Q_OBJECT +public: + ProjectExplorerListViewBase(QWidget* parent); + +protected: + /** + * @brief Double click event override + * + * Function that signals DoubleClickedView(). + * + * 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; + +signals: + /** + * @brief Unconditional double click signal + * + * Emits a signal when the view is double clicked, regardless of whether the double clicked index was valid. + */ + void DoubleClickedView(const QModelIndex& index); +}; + +#endif // PROJECTEXPLORERLISTVIEWBASE_H diff --git a/app/widget/projectexplorer/projectexplorertreeview.cpp b/app/widget/projectexplorer/projectexplorertreeview.cpp index 4bcd96f80..9063fb7f8 100644 --- a/app/widget/projectexplorer/projectexplorertreeview.cpp +++ b/app/widget/projectexplorer/projectexplorertreeview.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 "projectexplorertreeview.h" #include @@ -5,6 +25,8 @@ ProjectExplorerTreeView::ProjectExplorerTreeView(QWidget *parent) : QTreeView(parent) { + // Set selection mode (allows multiple item selection) + setSelectionMode(QAbstractItemView::ExtendedSelection); } void ProjectExplorerTreeView::mouseDoubleClickEvent(QMouseEvent *event) diff --git a/app/widget/projectexplorer/projectexplorertreeview.h b/app/widget/projectexplorer/projectexplorertreeview.h index f0de12eb7..0a7e4c29e 100644 --- a/app/widget/projectexplorer/projectexplorertreeview.h +++ b/app/widget/projectexplorer/projectexplorertreeview.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 PROJECTEXPLORERTREEVIEW_H #define PROJECTEXPLORERTREEVIEW_H @@ -16,9 +36,22 @@ public: ProjectExplorerTreeView(QWidget* parent); protected: + /** + * @brief Double click event override + * + * Function that signals DoubleClickedView(). + * + * 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; signals: + /** + * @brief Unconditional double click signal + * + * Emits a signal when the view is double clicked, regardless of whether the double clicked index was valid. + */ void DoubleClickedView(const QModelIndex& index); };