Skip to content
Snippets Groups Projects
Commit 4419676a authored by stefan's avatar stefan
Browse files

FileBrowser added ContextMenu

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2322 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 7848a34a
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
// along with this library; if not, write to the Free Software Foundation, Inc., // along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#include <QCursor>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QDesktopServices>
#include <QDir> #include <QDir>
#include <QHeaderView> #include <QHeaderView>
#include <QFileInfo> #include <QFileInfo>
...@@ -91,6 +93,8 @@ void FileBrowser::Init(const QString& path) ...@@ -91,6 +93,8 @@ void FileBrowser::Init(const QString& path)
view_->setModel(model_); view_->setModel(model_);
view_->setRootIndex(model_->index(path)); view_->setRootIndex(model_->index(path));
view_->setAttribute(Qt::WA_MacShowFocusRect, false); view_->setAttribute(Qt::WA_MacShowFocusRect, false);
view_->setContextMenuPolicy(Qt::CustomContextMenu);
connect(view_,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(ShowContextMenu(const QPoint&)));
menu_= new QComboBox(this); menu_= new QComboBox(this);
UpdateMenu(path); UpdateMenu(path);
...@@ -137,13 +141,7 @@ bool FileBrowser::Restore(const QString& prefix) ...@@ -137,13 +141,7 @@ bool FileBrowser::Restore(const QString& prefix)
void FileBrowser::DoubleClicked(const QModelIndex& index) void FileBrowser::DoubleClicked(const QModelIndex& index)
{ {
if(model_->isDir(index)){ LoadObject(index);
view_->setRootIndex(index);
UpdateMenu(model_->filePath(index));
}
else{
LoadObject(index);
}
} }
void FileBrowser::ChangeToParentDirectory(int index){ void FileBrowser::ChangeToParentDirectory(int index){
...@@ -193,10 +191,15 @@ void FileBrowser::AddItem(const QDir& directory, const QString& mypath){ ...@@ -193,10 +191,15 @@ void FileBrowser::AddItem(const QDir& directory, const QString& mypath){
} }
void FileBrowser::LoadObject(const QModelIndex& index){ void FileBrowser::LoadObject(const QModelIndex& index){
gfx::GfxObjP obj;
if (index.isValid()) { if (index.isValid()) {
QString file_name=model_->filePath(index); if(model_->isDir(index)){
FileLoader::LoadObject(file_name); view_->setRootIndex(index);
UpdateMenu(model_->filePath(index));
}
else{
QString file_name=model_->filePath(index);
FileLoader::LoadObject(file_name);
}
} }
} }
...@@ -206,6 +209,44 @@ void FileBrowser::keyPressEvent(QKeyEvent* event){ ...@@ -206,6 +209,44 @@ void FileBrowser::keyPressEvent(QKeyEvent* event){
} }
} }
void FileBrowser::ShowContextMenu(const QPoint& pos){
QModelIndex index = view_->selectionModel()->currentIndex();
QMenu* menu = new QMenu(this);
if(model_->isDir(index)){
QAction* open_action = new QAction(menu);
open_action->setText("Open");
connect(open_action,SIGNAL(triggered(bool)),this,SLOT(LoadCurrentObject()));
menu->addAction(open_action);
}
if(!model_->isDir(index)){
QAction* load_action = new QAction(menu);
load_action->setText("Load");
connect(load_action,SIGNAL(triggered(bool)),this,SLOT(LoadCurrentObject()));
menu->addAction(load_action);
QAction* system_open_action = new QAction(menu);
system_open_action->setText("Open with system editor");
connect(system_open_action,SIGNAL(triggered(bool)),this,SLOT(LoadWithSystemEditor()));
menu->addAction(system_open_action);
}
if(menu->actions().size()>0){
menu->exec(QCursor::pos());
}
}
void FileBrowser::LoadCurrentObject(){
QModelIndex index = view_->selectionModel()->currentIndex();
this->LoadObject(index);
}
void FileBrowser::LoadWithSystemEditor(){
QModelIndex index = view_->selectionModel()->currentIndex();
QString file_name=model_->filePath(index);
std::cout << file_name.toStdString() << std::endl;
QDesktopServices::openUrl(file_name);
}
OST_REGISTER_WIDGET_WITH_DEFAULT_FACTORY(ost::gui, FileBrowser, "File Browser"); OST_REGISTER_WIDGET_WITH_DEFAULT_FACTORY(ost::gui, FileBrowser, "File Browser");
......
...@@ -51,6 +51,9 @@ private slots: ...@@ -51,6 +51,9 @@ private slots:
void DoubleClicked(const QModelIndex& index); void DoubleClicked(const QModelIndex& index);
void ChangeToParentDirectory(int index); void ChangeToParentDirectory(int index);
void Split(); void Split();
void ShowContextMenu(const QPoint& pos);
void LoadCurrentObject();
void LoadWithSystemEditor();
private: private:
void LoadObject(const QModelIndex& index); void LoadObject(const QModelIndex& index);
void UpdateMenu(const QString& path); void UpdateMenu(const QString& path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment