connected project toolbar to project explorer
This commit is contained in:
@@ -42,6 +42,15 @@ ProjectPanel::ProjectPanel(QWidget *parent) :
|
||||
explorer_ = new ProjectExplorer(this);
|
||||
layout->addWidget(explorer_);
|
||||
|
||||
// Set toolbar's view to the explorer's view
|
||||
toolbar->SetView(explorer_->view_type());
|
||||
|
||||
// Connect toolbar's view change signal to the explorer's view change slot
|
||||
connect(toolbar,
|
||||
SIGNAL(ViewChanged(olive::ProjectViewType)),
|
||||
explorer_,
|
||||
SLOT(set_view_type(olive::ProjectViewType)));
|
||||
|
||||
// Set strings
|
||||
Retranslate();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef PROJECTVIEWTYPE_H
|
||||
#define PROJECTVIEWTYPE_H
|
||||
|
||||
namespace olive {
|
||||
enum ProjectViewType {
|
||||
TreeView,
|
||||
ListView,
|
||||
IconView
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PROJECTVIEWTYPE_H
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
ProjectExplorer::ProjectExplorer(QWidget *parent) :
|
||||
QStackedWidget(parent),
|
||||
view_type_(TreeView),
|
||||
view_type_(olive::TreeView),
|
||||
model_(this)
|
||||
{
|
||||
tree_view_ = new QTreeView(this);
|
||||
@@ -30,12 +30,12 @@ ProjectExplorer::ProjectExplorer(QWidget *parent) :
|
||||
addWidget(tree_view_);
|
||||
}
|
||||
|
||||
const ProjectExplorer::ViewType &ProjectExplorer::view_type()
|
||||
const olive::ProjectViewType &ProjectExplorer::view_type()
|
||||
{
|
||||
return view_type_;
|
||||
}
|
||||
|
||||
void ProjectExplorer::set_view_type(const ProjectExplorer::ViewType &type)
|
||||
void ProjectExplorer::set_view_type(olive::ProjectViewType type)
|
||||
{
|
||||
view_type_ = type;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "project/project.h"
|
||||
#include "project/projectviewmodel.h"
|
||||
#include "project/projectviewtype.h"
|
||||
|
||||
/**
|
||||
* @brief The ProjectExplorer class
|
||||
@@ -39,25 +40,22 @@
|
||||
*/
|
||||
class ProjectExplorer : public QStackedWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ViewType {
|
||||
TreeView,
|
||||
ListView,
|
||||
IconView
|
||||
};
|
||||
|
||||
ProjectExplorer(QWidget* parent);
|
||||
|
||||
const ViewType& view_type();
|
||||
void set_view_type(const ViewType& type);
|
||||
const olive::ProjectViewType& view_type();
|
||||
|
||||
Project* project();
|
||||
void set_project(Project* p);
|
||||
|
||||
public slots:
|
||||
void set_view_type(olive::ProjectViewType type);
|
||||
|
||||
private:
|
||||
QTreeView* tree_view_;
|
||||
|
||||
ViewType view_type_;
|
||||
olive::ProjectViewType view_type_;
|
||||
|
||||
ProjectViewModel model_;
|
||||
};
|
||||
|
||||
@@ -66,19 +66,19 @@ ProjectToolbar::ProjectToolbar(QWidget *parent) :
|
||||
tree_button_ = new QPushButton();
|
||||
tree_button_->setIcon(olive::icon::TreeView);
|
||||
tree_button_->setCheckable(true);
|
||||
connect(tree_button_, SIGNAL(clicked(bool)), this, SIGNAL(TreeViewClicked()));
|
||||
connect(tree_button_, SIGNAL(clicked(bool)), this, SLOT(ViewButtonClicked()));
|
||||
layout->addWidget(tree_button_);
|
||||
|
||||
list_button_ = new QPushButton();
|
||||
list_button_->setIcon(olive::icon::ListView);
|
||||
list_button_->setCheckable(true);
|
||||
connect(list_button_, SIGNAL(clicked(bool)), this, SIGNAL(ListViewClicked()));
|
||||
connect(list_button_, SIGNAL(clicked(bool)), this, SLOT(ViewButtonClicked()));
|
||||
layout->addWidget(list_button_);
|
||||
|
||||
icon_button_ = new QPushButton();
|
||||
icon_button_->setIcon(olive::icon::IconView);
|
||||
icon_button_->setCheckable(true);
|
||||
connect(icon_button_, SIGNAL(clicked(bool)), this, SIGNAL(IconViewClicked()));
|
||||
connect(icon_button_, SIGNAL(clicked(bool)), this, SLOT(ViewButtonClicked()));
|
||||
layout->addWidget(icon_button_);
|
||||
|
||||
// Group Tree/List/Icon view buttons into a button group for easy exclusive-buttons
|
||||
@@ -91,6 +91,21 @@ ProjectToolbar::ProjectToolbar(QWidget *parent) :
|
||||
Retranslate();
|
||||
}
|
||||
|
||||
void ProjectToolbar::SetView(olive::ProjectViewType type)
|
||||
{
|
||||
switch (type) {
|
||||
case olive::TreeView:
|
||||
tree_button_->setChecked(true);
|
||||
break;
|
||||
case olive::IconView:
|
||||
icon_button_->setChecked(true);
|
||||
break;
|
||||
case olive::ListView:
|
||||
list_button_->setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectToolbar::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
@@ -113,3 +128,18 @@ void ProjectToolbar::Retranslate()
|
||||
list_button_->setToolTip(tr("Switch to List View"));
|
||||
icon_button_->setToolTip(tr("Switch to Icon View"));
|
||||
}
|
||||
|
||||
void ProjectToolbar::ViewButtonClicked()
|
||||
{
|
||||
// Determine which view button triggered this slot and emit a signal accordingly
|
||||
if (sender() == tree_button_) {
|
||||
emit ViewChanged(olive::TreeView);
|
||||
} else if (sender() == icon_button_) {
|
||||
emit ViewChanged(olive::IconView);
|
||||
} else if (sender() == list_button_) {
|
||||
emit ViewChanged(olive::ListView);
|
||||
} else {
|
||||
// Assert that it was one of the above buttons
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "project/projectviewtype.h"
|
||||
|
||||
/**
|
||||
* @brief The ProjectToolbar class
|
||||
*
|
||||
@@ -38,8 +40,13 @@ class ProjectToolbar : public QWidget
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectToolbar(QWidget* parent);
|
||||
|
||||
public slots:
|
||||
void SetView(olive::ProjectViewType type);
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *) override;
|
||||
|
||||
signals:
|
||||
void NewClicked();
|
||||
void OpenClicked();
|
||||
@@ -50,9 +57,8 @@ signals:
|
||||
|
||||
void SearchChanged(const QString&);
|
||||
|
||||
void TreeViewClicked();
|
||||
void IconViewClicked();
|
||||
void ListViewClicked();
|
||||
void ViewChanged(olive::ProjectViewType type);
|
||||
|
||||
private:
|
||||
void Retranslate();
|
||||
|
||||
@@ -67,6 +73,9 @@ private:
|
||||
QPushButton* tree_button_;
|
||||
QPushButton* list_button_;
|
||||
QPushButton* icon_button_;
|
||||
|
||||
private slots:
|
||||
void ViewButtonClicked();
|
||||
};
|
||||
|
||||
#endif // PROJECTTOOLBAR_H
|
||||
|
||||
Reference in New Issue
Block a user