finished project explorer

This commit is contained in:
itsmattkc
2019-07-02 17:13:26 -07:00
parent 0f7192fc33
commit f9543fba4e
5 changed files with 125 additions and 1 deletions
+6
View File
@@ -23,6 +23,12 @@
Project::Project()
{
name_ = tr("(untitled)");
// FIXME: Test code
Folder* f = new Folder();
f->set_name("Foldery Boy");
root()->add_child(f);
// END Test code
}
Folder *Project::root()
@@ -38,6 +38,7 @@ ProjectExplorer::ProjectExplorer(QWidget *parent) :
// Set up navigation bar
nav_bar_ = new ProjectExplorerNavigation(this);
connect(nav_bar_, SIGNAL(SizeChanged(int)), this, SLOT(SizeChangedSlot(int)));
connect(nav_bar_, SIGNAL(DirectoryUpClicked()), this, SLOT(DirUpSlot()));
layout->addWidget(nav_bar_);
// Set up stacked widget
@@ -96,6 +97,25 @@ void ProjectExplorer::AddView(QAbstractItemView *view)
stacked_widget_->addWidget(view);
}
void ProjectExplorer::BrowseToFolder(const QModelIndex &index)
{
// Set appropriate views to this index
icon_view_->setRootIndex(index);
list_view_->setRootIndex(index);
// Set navbar text to folder's name
if (index.isValid()) {
Folder* f = static_cast<Folder*>(index.internalPointer());
nav_bar_->set_text(f->name());
} else {
// Or set it to an empty string if the index is valid (which means we're browsing to the root directory)
nav_bar_->set_text(QString());
}
// Set directory up enabled button based on whether we're in root or not
nav_bar_->set_dir_up_enabled(index.isValid());
}
void ProjectExplorer::DoubleClickViewSlot(const QModelIndex &index)
{
if (index.isValid()) {
@@ -103,6 +123,14 @@ void ProjectExplorer::DoubleClickViewSlot(const QModelIndex &index)
// Retrieve source item from index
Item* i = static_cast<Item*>(index.internalPointer());
// If the item is a folder, browse to it
if (i->type() == Item::kFolder
&& (view_type() == olive::ListView || view_type() == olive::IconView)) {
BrowseToFolder(index);
}
// Emit a signal
emit DoubleClickedItem(i);
@@ -121,6 +149,17 @@ void ProjectExplorer::SizeChangedSlot(int s)
list_view_->setIconSize(QSize(s, s));
}
void ProjectExplorer::DirUpSlot()
{
QModelIndex current_root = icon_view_->rootIndex();
if (current_root.isValid()) {
QModelIndex parent = current_root.parent();
BrowseToFolder(parent);
}
}
Project *ProjectExplorer::project()
{
return model_.project();
+14 -1
View File
@@ -33,7 +33,7 @@
#include "widget/projectexplorer/projectexplorernavigation.h"
/**
* @brief The ProjectExplorer class
* @brief A widget for browsing through Project classes
*
* A widget for browsing through a Project structure.
*
@@ -78,6 +78,17 @@ private:
*/
void AddView(QAbstractItemView* view);
/**
* @brief Browse to a specific folder index in the model
*
* Only affects list_view_ and icon_view_.
*
* @param index
*
* Either an invalid index to return to the project root, or an index to a valid Folder object.
*/
void BrowseToFolder(const QModelIndex& index);
QStackedWidget* stacked_widget_;
ProjectExplorerNavigation* nav_bar_;
@@ -94,6 +105,8 @@ private slots:
void DoubleClickViewSlot(const QModelIndex& index);
void SizeChangedSlot(int s);
void DirUpSlot();
};
#endif // PROJECTEXPLORER_H
@@ -35,6 +35,7 @@ ProjectExplorerNavigation::ProjectExplorerNavigation(QWidget *parent) :
// Create "directory up" button
dir_up_btn_ = new QPushButton(this);
dir_up_btn_->setEnabled(false);
dir_up_btn_->setIcon(olive::icon::DirUp);
dir_up_btn_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
layout->addWidget(dir_up_btn_);
@@ -63,6 +64,16 @@ void ProjectExplorerNavigation::set_text(const QString &s)
dir_lbl_->setText(s);
}
void ProjectExplorerNavigation::set_dir_up_enabled(bool e)
{
dir_up_btn_->setEnabled(e);
}
void ProjectExplorerNavigation::set_size_value(int s)
{
size_slider_->setValue(s);
}
void ProjectExplorerNavigation::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
@@ -26,16 +26,71 @@
#include <QSlider>
#include <QWidget>
/**
* @brief A navigation bar widget for ProjectExplorer's Icon and List views
*
* Unlike the Tree view, Icon and List don't follow a hierarchical view of information. This means there is no direct
* way of navigating in and out of folders in those view types. We solve this in two ways:
*
* * Double clicking a Folder in those views will enter that folder
* * This navigation bar offers a "directory up" button for leaving a folder
*
* This navbar also provides an icon size slider for those views (between olive::kProjectIconSizeMinimum and
* olive::kProjectIconSizeMaximum) as well as text that's intended to be set to the current Folder's name (or
* empty for the root folder).
*
* This widget does not actually communicate to Project or ProjectExplorer classes. It is simply UI widgets that are
* intended to be connected in ways that do. This is the primarily responsibility of ProjectExplorer.
*
* By default, the directory up button is disabled (assuming root folder), the text is empty, and the icon size slider
* is set to olive::kProjectIconSizeDefault.
*/
class ProjectExplorerNavigation : public QWidget
{
Q_OBJECT
public:
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);
/**
* @brief Set whether the "directory up" button is enabled or not
*
* @param e
*/
void set_dir_up_enabled(bool e);
/**
* @brief Set the current value of the size slider
*
* NOTE: Does NOT emit SizeChanged().
*
* @param s
*
* New size value to set to
*/
void set_size_value(int s);
signals:
/**
* @brief Signal emitted when the directory up button is clicked
*/
void DirectoryUpClicked();
/**
* @brief Signal emitted when the icon size slider changes value
*
* @param size
*
* New size set in the slider
*/
void SizeChanged(int size);
protected: