From 44c23327e09ea811850581e2d3d23cc4fc5abcc2 Mon Sep 17 00:00:00 2001 From: aquiles Date: Sun, 29 May 2011 22:30:06 +0200 Subject: [PATCH] Changed: #1306 added leveldesign path dock widget --- .../src/plugins/georges_editor/CMakeLists.txt | 6 +- .../georges_editor/georges_dirtree_dialog.cpp | 99 +++++++++++++++++++ .../georges_editor/georges_dirtree_dialog.h | 62 ++++++++++++ .../georges_editor/georges_dirtree_form.ui | 54 ++++++++++ .../georges_editor/georges_editor_form.cpp | 60 ++++++++--- .../georges_editor/georges_editor_form.h | 7 +- .../georges_editor/georges_editor_plugin.cpp | 7 +- .../georges_filesystem_model.cpp | 95 ++++++++++++++++++ .../georges_editor/georges_filesystem_model.h | 50 ++++++++++ .../src/plugins/log/log_plugin.cpp | 4 +- 10 files changed, 419 insertions(+), 25 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_form.ui create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/CMakeLists.txt index fd180b931..d1dd346ba 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/CMakeLists.txt @@ -9,9 +9,11 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h - georges_editor_form.h) + georges_editor_form.h + georges_dirtree_dialog.h) -SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui ) +SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui + georges_dirtree_form.ui) SET(OVQT_PLUGIN_GEORGES_EDITOR_RCS georges_editor.qrc) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.cpp new file mode 100644 index 000000000..f7e250cce --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.cpp @@ -0,0 +1,99 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Project includes +#include "georges_dirtree_dialog.h" + +// Qt includes +#include +#include + +// NeL includes + +//using namespace NLMISC; + +namespace Plugin +{ + +CGeorgesDirTreeDialog::CGeorgesDirTreeDialog(QString ldPath, QWidget *parent) + :QDockWidget(parent), m_ldPath(ldPath) +{ + + m_ui.setupUi(this); + + m_dirModel = new CGeorgesFileSystemModel(m_ldPath); + m_ui.dirTree->setModel(m_dirModel); + + if (m_dirModel->isCorrectLDPath()) + { + m_dirModel->setRootPath(m_ldPath); + m_ui.dirTree->setRootIndex(m_dirModel->index(m_ldPath)); + } + else + { + m_dirModel->setRootPath(QDir::currentPath()); + } + + m_ui.dirTree->setAnimated(false); + m_ui.dirTree->setIndentation(20); + + connect(m_ui.dirTree, SIGNAL(activated(QModelIndex)), + this, SLOT(fileSelected(QModelIndex))); +} + +CGeorgesDirTreeDialog::~CGeorgesDirTreeDialog() +{ + delete m_dirModel; +} + +void CGeorgesDirTreeDialog::fileSelected(QModelIndex index) +{ + QString name; + if (index.isValid() && !m_dirModel->isDir(index)) + { + Q_EMIT selectedForm(m_dirModel->fileName(index)); + } +} + +void CGeorgesDirTreeDialog::changeFile(QString file) +{ + QModelIndex index = m_dirModel->index(file); + m_ui.dirTree->selectionModel()->select(index,QItemSelectionModel::ClearAndSelect); + m_ui.dirTree->scrollTo(index,QAbstractItemView::PositionAtCenter); + fileSelected(index); +} + +void CGeorgesDirTreeDialog::ldPathChanged(QString path) +{ + m_ldPath = path; + + delete m_dirModel; + + m_dirModel = new CGeorgesFileSystemModel(m_ldPath); + m_ui.dirTree->setModel(m_dirModel); + + if (m_dirModel->isCorrectLDPath()) + { + m_dirModel->setRootPath(m_ldPath); + m_ui.dirTree->setRootIndex(m_dirModel->index(m_ldPath)); + } + else + { + m_dirModel->setRootPath(QDir::currentPath()); + } +} + +} /* namespace NLQT */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.h new file mode 100644 index 000000000..3079f76c2 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.h @@ -0,0 +1,62 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef GEORGES_DIRTREE_DIALOG_H +#define GEORGES_DIRTREE_DIALOG_H + +// Qt includes +#include + +// STL includes + +// NeL includes + +// Project includes +#include "ui_georges_dirtree_form.h" +#include "georges_filesystem_model.h" + +namespace Plugin +{ + +class CGeorgesDirTreeDialog: public QDockWidget +{ + Q_OBJECT + +public: + CGeorgesDirTreeDialog(QString ldPath, QWidget *parent = 0); + ~CGeorgesDirTreeDialog(); + + void ldPathChanged(QString); + +private: + Ui::CGeorgesDirTreeDialog m_ui; + + CGeorgesFileSystemModel *m_dirModel; + QString m_ldPath; + +Q_SIGNALS: + void selectedForm(const QString); + +private Q_SLOTS: + void fileSelected(QModelIndex index); + void changeFile(QString file); + + friend class CMainWindow; +}; /* CGEorgesDirTreeDialog */ + +} /* namespace NLQT */ + +#endif // GEORGES_DIRTREE_DIALOG_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_form.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_form.ui new file mode 100644 index 000000000..8731d1ca8 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_form.ui @@ -0,0 +1,54 @@ + + + CGeorgesDirTreeDialog + + + + 0 + 0 + 400 + 300 + + + + + 0 + 0 + + + + + 200 + 111 + + + + QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable + + + Leveldesign Path + + + + + 50 + 0 + + + + + + + + 0 + 0 + + + + + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp index 2e3b9efb3..aa614a161 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp @@ -17,6 +17,7 @@ // Project includes #include "georges_editor_form.h" #include "georges_editor_constants.h" +#include "georges_dirtree_dialog.h" #include "../core/icore.h" #include "../core/imenu_manager.h" @@ -34,36 +35,44 @@ namespace Plugin { GeorgesEditorForm::GeorgesEditorForm(QWidget *parent) - : QMainWindow(parent) + : QMainWindow(parent), + m_georgesDirTreeDialog(0) { m_ui.setupUi(this); m_undoStack = new QUndoStack(this); - _openAction = new QAction(tr("&Open..."), this); - _openAction->setIcon(QIcon(Core::Constants::ICON_OPEN)); - _openAction->setShortcut(QKeySequence::Open); - _openAction->setStatusTip(tr("Open an existing file")); + _openAction = new QAction(tr("&Open..."), this); + _openAction->setIcon(QIcon(Core::Constants::ICON_OPEN)); + _openAction->setShortcut(QKeySequence::Open); + _openAction->setStatusTip(tr("Open an existing file")); connect(_openAction, SIGNAL(triggered()), this, SLOT(open())); - _newAction = new QAction(tr("&New..."), this); - _newAction->setIcon(QIcon(Core::Constants::ICON_NEW)); - _newAction->setShortcut(QKeySequence::New); - _newAction->setStatusTip(tr("Create a new file")); + _newAction = new QAction(tr("&New..."), this); + _newAction->setIcon(QIcon(Core::Constants::ICON_NEW)); + _newAction->setShortcut(QKeySequence::New); + _newAction->setStatusTip(tr("Create a new file")); connect(_newAction, SIGNAL(triggered()), this, SLOT(newFile())); - _saveAction = new QAction(tr("&Save..."), this); - _saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); - _saveAction->setShortcut(QKeySequence::Save); - _saveAction->setStatusTip(tr("Save the current file")); + _saveAction = new QAction(tr("&Save..."), this); + _saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); + _saveAction->setShortcut(QKeySequence::Save); + _saveAction->setStatusTip(tr("Save the current file")); connect(_saveAction, SIGNAL(triggered()), this, SLOT(save())); - _fileToolBar = addToolBar(tr("&File")); - _fileToolBar->addAction(_openAction); - _fileToolBar->addAction(_newAction); + _fileToolBar = addToolBar(tr("&File")); + _fileToolBar->addAction(_openAction); + _fileToolBar->addAction(_newAction); _fileToolBar->addAction(_saveAction); readSettings(); + + // create leveldesign directory tree dockwidget + m_georgesDirTreeDialog = new CGeorgesDirTreeDialog(m_leveldesignPath, this); + addDockWidget(Qt::LeftDockWidgetArea, m_georgesDirTreeDialog); + //m_georgesDirTreeDialog->setVisible(false); + connect(Core::ICore::instance(), SIGNAL(changeSettings()), + this, SLOT(settingsChanged())); } GeorgesEditorForm::~GeorgesEditorForm() @@ -98,6 +107,10 @@ void GeorgesEditorForm::readSettings() QSettings *settings = Core::ICore::instance()->settings(); settings->beginGroup(Constants::GEORGES_EDITOR_SECTION); settings->endGroup(); + + settings->beginGroup(Core::Constants::DATA_PATH_SECTION); + m_leveldesignPath = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString(); + settings->endGroup(); } void GeorgesEditorForm::writeSettings() @@ -108,4 +121,19 @@ void GeorgesEditorForm::writeSettings() settings->sync(); } +void GeorgesEditorForm::settingsChanged() +{ + QSettings *settings = Core::ICore::instance()->settings(); + + settings->beginGroup(Core::Constants::DATA_PATH_SECTION); + QString oldLDPath = m_leveldesignPath; + m_leveldesignPath = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString(); + settings->endGroup(); + + if (oldLDPath != m_leveldesignPath) + { + m_georgesDirTreeDialog->ldPathChanged(m_leveldesignPath); + } +} + } /* namespace Plugin */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h index 65c37cb8d..96fceb4ed 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h @@ -26,6 +26,7 @@ namespace Plugin { +class CGeorgesDirTreeDialog; class GeorgesEditorForm: public QMainWindow { Q_OBJECT @@ -36,13 +37,12 @@ public: QUndoStack *undoStack() const; -Q_SIGNALS: public Q_SLOTS: void open(); void newFile(); void save(); + void settingsChanged(); -private Q_SLOTS: private: void readSettings(); void writeSettings(); @@ -50,10 +50,13 @@ private: QUndoStack *m_undoStack; Ui::GeorgesEditorForm m_ui; + CGeorgesDirTreeDialog *m_georgesDirTreeDialog; QToolBar *_fileToolBar; QAction *_openAction; QAction *_newAction; QAction *_saveAction; + + QString m_leveldesignPath; }; /* class GeorgesEditorForm */ } /* namespace Plugin */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_plugin.cpp index 941722994..a97188751 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_plugin.cpp @@ -69,12 +69,12 @@ void GeorgesEditorPlugin::setNelContext(NLMISC::INelContext *nelContext) QString GeorgesEditorPlugin::name() const { - return tr("GeorgesEditor"); + return tr("Georges Editor"); } QString GeorgesEditorPlugin::version() const { - return "0.1"; + return "0.2"; } QString GeorgesEditorPlugin::vendor() const @@ -84,13 +84,14 @@ QString GeorgesEditorPlugin::vendor() const QString GeorgesEditorPlugin::description() const { - return "Tool to create & edit sheets or forms."; + return tr("Tool to create & edit sheets or forms."); } QStringList GeorgesEditorPlugin::dependencies() const { QStringList list; list.append(Core::Constants::OVQT_CORE_PLUGIN); + list.append("ObjectViewer"); // TODO return list; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.cpp new file mode 100644 index 000000000..20cb30b33 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.cpp @@ -0,0 +1,95 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "georges_filesystem_model.h" + +#include +#include + +namespace Plugin +{ + +CGeorgesFileSystemModel::CGeorgesFileSystemModel(QString ldPath, QObject *parent) + : QFileSystemModel(parent), + m_ldPath(ldPath), + m_correct(false) +{ + checkLDPath(); +} + +CGeorgesFileSystemModel::~CGeorgesFileSystemModel() +{ + +} + +QVariant CGeorgesFileSystemModel::data(const QModelIndex& index, int role) const +{ + + if (role == Qt::DecorationRole) + { + if (!m_correct) + return QVariant(); + if (isDir(index)) + return QApplication::style()->standardIcon(QStyle::SP_DirIcon); + } + if (!m_correct && role == Qt::DisplayRole) + { + if (index.parent().isValid()) + return QVariant(); + return tr("Set a correct leveldesign path ..."); + } + return QFileSystemModel::data(index, role); +} + +int CGeorgesFileSystemModel::columnCount(const QModelIndex &/*parent*/) const +{ + return 1; +} + +int CGeorgesFileSystemModel::rowCount(const QModelIndex &parent) const +{ + + if (!m_correct) + { + if(parent.isValid()) + { + return 0; + } + else + { + return qMin(QFileSystemModel::rowCount(parent),1); + } + } + return QFileSystemModel::rowCount(parent); +} + +void CGeorgesFileSystemModel::checkLDPath() +{ + QFileInfo check1(QString("%1/game_element").arg(m_ldPath)); + QFileInfo check2(QString("%1/DFN").arg(m_ldPath)); + + if (check1.exists() && check2.exists()) + { + m_correct = true; + } + else + { + m_correct = false; + } +} +} /* namespace NLQT */ + +/* end of file */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.h new file mode 100644 index 000000000..775dcb18d --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.h @@ -0,0 +1,50 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef GEORGES_FILESYSTEM_MODEL_H +#define GEORGES_FILESYSTEM_MODEL_H + +#include + +namespace Plugin +{ + +class CGeorgesFileSystemModel : public QFileSystemModel +{ + QString m_ldPath; + +public: + CGeorgesFileSystemModel(QString ldPath, QObject *parent = 0); + ~CGeorgesFileSystemModel(); + + int columnCount(const QModelIndex &/*parent*/) const; + int rowCount(const QModelIndex &/*parent*/) const; + + QVariant data(const QModelIndex& index, int role) const ; + + bool isCorrectLDPath() + { + return m_correct; + } + void checkLDPath(); + +private: + bool m_correct; +};/* class CGeorgesFileSystemModel */ + +} /* namespace NLQT */ + +#endif // GEORGES_FILESYSTEM_MODEL_H \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.cpp index 8344b5217..2f88200ec 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.cpp @@ -103,7 +103,7 @@ namespace Plugin QString CLogPlugin::name() const { - return "LogPlugin"; + return "NeL Log"; } QString CLogPlugin::version() const @@ -118,7 +118,7 @@ namespace Plugin QString CLogPlugin::description() const { - return "DockWidget to display all log messages from NeL."; + return tr("DockWidget to display all log messages from NeL."); } QStringList CLogPlugin::dependencies() const