more work on project management

This commit is contained in:
itsmattkc
2019-07-06 09:46:55 -05:00
parent bc631c495d
commit a6971b3fde
15 changed files with 290 additions and 114 deletions
+51 -13
View File
@@ -62,6 +62,10 @@ ProjectExplorer::ProjectExplorer(QWidget *parent) :
// Set default icon size
SizeChangedSlot(olive::kProjectIconSizeDefault);
// Set rename timer timeout
rename_timer_.setInterval(500);
connect(&rename_timer_, SIGNAL(timeout()), this, SLOT(RenameTimerSlot()));
}
const olive::ProjectViewType &ProjectExplorer::view_type()
@@ -90,15 +94,25 @@ void ProjectExplorer::set_view_type(olive::ProjectViewType type)
}
}
void ProjectExplorer::Edit(Item *item)
{
CurrentView()->edit(model_.CreateIndexFromItem(item));
}
void ProjectExplorer::AddView(QAbstractItemView *view)
{
view->setModel(&model_);
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
connect(view, SIGNAL(DoubleClickedView(const QModelIndex&)), this, SLOT(DoubleClickViewSlot(const QModelIndex&)));
connect(view, SIGNAL(clicked(const QModelIndex&)), this, SLOT(ItemClickedSlot(const QModelIndex&)));
stacked_widget_->addWidget(view);
}
void ProjectExplorer::BrowseToFolder(const QModelIndex &index)
{
// Make sure any rename timers are stopped
rename_timer_.stop();
// Set appropriate views to this index
icon_view_->setRootIndex(index);
list_view_->setRootIndex(index);
@@ -116,6 +130,30 @@ void ProjectExplorer::BrowseToFolder(const QModelIndex &index)
nav_bar_->set_dir_up_enabled(index.isValid());
}
QAbstractItemView *ProjectExplorer::CurrentView()
{
return static_cast<QAbstractItemView*>(stacked_widget_->currentWidget());
}
void ProjectExplorer::ItemClickedSlot(const QModelIndex &index)
{
if (index.isValid()) {
if (clicked_index_ == index) {
// The item has been clicked more than once, start a timer for renaming
rename_timer_.start();
} else {
// Cache this index for the next click
clicked_index_ = index;
// If the rename timer had started, stop it now
rename_timer_.stop();
}
} else {
// Stop the rename timer
rename_timer_.stop();
}
}
void ProjectExplorer::DoubleClickViewSlot(const QModelIndex &index)
{
if (index.isValid()) {
@@ -160,6 +198,18 @@ void ProjectExplorer::DirUpSlot()
}
}
void ProjectExplorer::RenameTimerSlot()
{
// Start editing this index
CurrentView()->edit(clicked_index_);
// Reset clicked index state
clicked_index_ = QModelIndex();
// Stop rename timer
rename_timer_.stop();
}
Project *ProjectExplorer::project()
{
return model_.project();
@@ -172,20 +222,8 @@ void ProjectExplorer::set_project(Project *p)
QList<Item *> ProjectExplorer::SelectedItems()
{
QModelIndexList index_list;
// Determine which view is active and get its selected indexes
switch (view_type_) {
case olive::TreeView:
index_list = tree_view_->selectionModel()->selectedRows();
break;
case olive::ListView:
index_list = list_view_->selectionModel()->selectedRows();
break;
case olive::IconView:
index_list = icon_view_->selectionModel()->selectedRows();
break;
}
QModelIndexList index_list = CurrentView()->selectionModel()->selectedRows();
// Convert indexes to item objects
QList<Item*> selected_items;
@@ -22,6 +22,7 @@
#define PROJECTEXPLORER_H
#include <QStackedWidget>
#include <QTimer>
#include <QTreeView>
#include "project/project.h"
@@ -77,6 +78,8 @@ public:
public slots:
void set_view_type(olive::ProjectViewType type);
void Edit(Item* item);
signals:
/**
* @brief Emitted when an Item is double clicked
@@ -110,6 +113,11 @@ private:
*/
void BrowseToFolder(const QModelIndex& index);
/**
* @brief Get the currently active QAbstractItemView
*/
QAbstractItemView* CurrentView();
QStackedWidget* stacked_widget_;
ProjectExplorerNavigation* nav_bar_;
@@ -122,12 +130,20 @@ private:
ProjectViewModel model_;
QModelIndex clicked_index_;
QTimer rename_timer_;
private slots:
void ItemClickedSlot(const QModelIndex& index);
void DoubleClickViewSlot(const QModelIndex& index);
void SizeChangedSlot(int s);
void DirUpSlot();
void RenameTimerSlot();
};
#endif // PROJECTEXPLORER_H
@@ -29,7 +29,7 @@ class ProjectExplorerListViewBase : public QListView
public:
ProjectExplorerListViewBase(QWidget* parent);
protected:
protected:
/**
* @brief Double click event override
*