Changed: #1150 Code Cleanup
This commit is contained in:
parent
ad7e7ccc23
commit
7eca51b274
32 changed files with 2476 additions and 2250 deletions
|
@ -2,8 +2,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${LI
|
||||||
INCLUDE( ${QT_USE_FILE} )
|
INCLUDE( ${QT_USE_FILE} )
|
||||||
|
|
||||||
FILE(GLOB GEORGES_EDITOR_SRC *.cpp)
|
FILE(GLOB GEORGES_EDITOR_SRC *.cpp)
|
||||||
SET(GEORGES_EDITOR_HDR georges_dirtree_dialog.h georges_treeview_dialog.h georgesform_model.h main_window.h
|
SET(GEORGES_EDITOR_HDR georges_dirtree_dialog.h georges_treeview_dialog.h main_window.h
|
||||||
log_dialog.h objectviewer_dialog.h settings_dialog.h)
|
objectviewer_dialog.h settings_dialog.h)
|
||||||
SET(GEORGES_EDITOR_UIS settings_form.ui objectviewer_form.ui log_form.ui georges_treeview_form.ui georges_dirtree_form.ui)
|
SET(GEORGES_EDITOR_UIS settings_form.ui objectviewer_form.ui log_form.ui georges_treeview_form.ui georges_dirtree_form.ui)
|
||||||
SET(GEORGES_EDITOR_RCS georges_editor_qt.qrc)
|
SET(GEORGES_EDITOR_RCS georges_editor_qt.qrc)
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "filesystem_model.h"
|
#include "filesystem_model.h"
|
||||||
|
@ -21,26 +21,31 @@
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QStyle>
|
#include <QtGui/QStyle>
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
CFileSystemModel::CFileSystemModel(QString ldPath, QObject *parent)
|
CFileSystemModel::CFileSystemModel(QString ldPath, QObject *parent)
|
||||||
: QFileSystemModel(parent),
|
: QFileSystemModel(parent),
|
||||||
_ldPath(ldPath){
|
_ldPath(ldPath)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
CFileSystemModel::~CFileSystemModel() {
|
CFileSystemModel::~CFileSystemModel()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CFileSystemModel::data(const QModelIndex& index, int role) const {
|
QVariant CFileSystemModel::data(const QModelIndex& index, int role) const {
|
||||||
|
|
||||||
if (role == Qt::DecorationRole) {
|
if (role == Qt::DecorationRole)
|
||||||
|
{
|
||||||
if (_ldPath.isEmpty())
|
if (_ldPath.isEmpty())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (isDir(index))
|
if (isDir(index))
|
||||||
return QApplication::style()->standardIcon(QStyle::SP_DirIcon);
|
return QApplication::style()->standardIcon(QStyle::SP_DirIcon);
|
||||||
}
|
}
|
||||||
if (_ldPath.isEmpty() && role == Qt::DisplayRole) {
|
if (_ldPath.isEmpty() && role == Qt::DisplayRole)
|
||||||
|
{
|
||||||
if (index.parent().isValid())
|
if (index.parent().isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
return QString("Set a correct leveldesign path ...");
|
return QString("Set a correct leveldesign path ...");
|
||||||
|
@ -55,10 +60,14 @@ namespace NLQT {
|
||||||
|
|
||||||
int CFileSystemModel::rowCount(const QModelIndex &parent) const
|
int CFileSystemModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (_ldPath.isEmpty()) {
|
if (_ldPath.isEmpty())
|
||||||
if(parent.isValid()) {
|
{
|
||||||
|
if(parent.isValid())
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return qMin(QFileSystemModel::rowCount(parent),1);
|
return qMin(QFileSystemModel::rowCount(parent),1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FILESYSTEM_MODEL_H
|
#ifndef FILESYSTEM_MODEL_H
|
||||||
|
@ -21,7 +21,8 @@
|
||||||
|
|
||||||
#include <QtGui/QFileSystemModel>
|
#include <QtGui/QFileSystemModel>
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
class CFileSystemModel : public QFileSystemModel
|
class CFileSystemModel : public QFileSystemModel
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,302 @@
|
||||||
|
/*
|
||||||
|
Georges Editor Qt
|
||||||
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "formdelegate.h"
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
#include <nel/georges/u_type.h>
|
||||||
|
#include <nel/georges/u_form_elm.h>
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QDoubleSpinBox>
|
||||||
|
#include <QColorDialog>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QTextDocument>
|
||||||
|
#include <QAbstractTextDocumentLayout>
|
||||||
|
#include <QPainter>
|
||||||
|
// Project includes
|
||||||
|
#include "georgesform_model.h"
|
||||||
|
#include "formitem.h"
|
||||||
|
|
||||||
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
|
FormDelegate::FormDelegate(QObject *parent)
|
||||||
|
: QStyledItemDelegate(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *FormDelegate::createEditor(QWidget *parent,
|
||||||
|
const QStyleOptionViewItem & option ,
|
||||||
|
const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
CFormItem *item = static_cast<CFormItem*>(index.internalPointer());
|
||||||
|
QString value = item->data(1).toString();
|
||||||
|
|
||||||
|
if (value.isEmpty())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
const NLGEORGES::UType *type = dynamic_cast<const CGeorgesFormModel *>(index.model())->
|
||||||
|
getItem(index)->getFormElm()->getType();
|
||||||
|
if(type)
|
||||||
|
{
|
||||||
|
int numDefinitions = type->getNumDefinition();
|
||||||
|
|
||||||
|
if (numDefinitions)
|
||||||
|
{
|
||||||
|
std::string l, v;
|
||||||
|
QString label,value;
|
||||||
|
|
||||||
|
QComboBox *editor = new QComboBox(parent);
|
||||||
|
for (int i = 0; i < numDefinitions; i++)
|
||||||
|
{
|
||||||
|
type->getDefinition(i,l,v);
|
||||||
|
label = l.c_str();
|
||||||
|
value = v.c_str();
|
||||||
|
editor->addItem(label);
|
||||||
|
}
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (type->getType())
|
||||||
|
{
|
||||||
|
case NLGEORGES::UType::UnsignedInt:
|
||||||
|
case NLGEORGES::UType::SignedInt:
|
||||||
|
{
|
||||||
|
QSpinBox *editor = new QSpinBox(parent);
|
||||||
|
|
||||||
|
//QString min = QString(type->getMin().c_str());
|
||||||
|
//QString max = QString(type->getMax().c_str());
|
||||||
|
//QString inc = QString(type->getIncrement().c_str());
|
||||||
|
//nldebug(QString("min %1 max %2 inc %3").arg(min).arg(max).arg(inc).toStdString().c_str());
|
||||||
|
|
||||||
|
// TODO: use saved min/max values
|
||||||
|
editor->setMinimum(-99999);
|
||||||
|
editor->setMaximum(99999);
|
||||||
|
editor->setSingleStep(1);
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
case NLGEORGES::UType::Double:
|
||||||
|
{
|
||||||
|
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
|
||||||
|
|
||||||
|
//QString min = QString(type->getMin().c_str());
|
||||||
|
//QString max = QString(type->getMax().c_str());
|
||||||
|
//QString inc = QString(type->getIncrement().c_str());
|
||||||
|
//nldebug(QString("min %1 max %2 inc %3").arg(min).arg(max).arg(inc).toStdString().c_str());
|
||||||
|
|
||||||
|
// TODO: use saved min/max values
|
||||||
|
editor->setMinimum(-99999);
|
||||||
|
editor->setMaximum(99999);
|
||||||
|
editor->setSingleStep(0.1);
|
||||||
|
editor->setDecimals(1);
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
case NLGEORGES::UType::Color:
|
||||||
|
{
|
||||||
|
return new QColorDialog();
|
||||||
|
}
|
||||||
|
default: // UType::String
|
||||||
|
{
|
||||||
|
QLineEdit *editor = new QLineEdit(parent);
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormDelegate::setEditorData(QWidget *editor,
|
||||||
|
const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
const NLGEORGES::UType *type = dynamic_cast<const CGeorgesFormModel *>(index.model())->
|
||||||
|
getItem(index)->getFormElm()->getType();
|
||||||
|
int numDefinitions = type->getNumDefinition();
|
||||||
|
QString value = index.model()->data(index, Qt::DisplayRole).toString();
|
||||||
|
|
||||||
|
if (numDefinitions)
|
||||||
|
{
|
||||||
|
QComboBox *cb = static_cast<QComboBox*>(editor);
|
||||||
|
cb->setCurrentIndex(cb->findText(value));
|
||||||
|
//cb->setIconSize()
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (type->getType())
|
||||||
|
{
|
||||||
|
case NLGEORGES::UType::UnsignedInt:
|
||||||
|
case NLGEORGES::UType::SignedInt:
|
||||||
|
{
|
||||||
|
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
||||||
|
spinBox->setValue((int)value.toDouble());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NLGEORGES::UType::Double:
|
||||||
|
{
|
||||||
|
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||||
|
spinBox->setValue(value.toDouble());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NLGEORGES::UType::Color:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
QLineEdit *textEdit = static_cast<QLineEdit*>(editor);
|
||||||
|
textEdit->setText(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||||
|
const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
const NLGEORGES::UType *type = dynamic_cast<const CGeorgesFormModel *>(index.model())->
|
||||||
|
getItem(index)->getFormElm()->getType();
|
||||||
|
int numDefinitions = type->getNumDefinition();
|
||||||
|
|
||||||
|
if (numDefinitions)
|
||||||
|
{
|
||||||
|
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
||||||
|
QString value = comboBox->currentText();
|
||||||
|
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
|
||||||
|
if (value == oldValue)
|
||||||
|
{
|
||||||
|
// nothing's changed
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nldebug(QString("setModelData from %1 to %2")
|
||||||
|
.arg(oldValue).arg(value).toStdString().c_str());
|
||||||
|
model->setData(index, value, Qt::EditRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (type->getType())
|
||||||
|
{
|
||||||
|
case NLGEORGES::UType::UnsignedInt:
|
||||||
|
case NLGEORGES::UType::SignedInt:
|
||||||
|
{
|
||||||
|
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
||||||
|
int value = spinBox->value();
|
||||||
|
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
|
||||||
|
if (QString("%1").arg(value) == oldValue)
|
||||||
|
{
|
||||||
|
// nothing's changed
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nldebug(QString("setModelData from %1 to %2")
|
||||||
|
.arg(oldValue).arg(value).toStdString().c_str());
|
||||||
|
model->setData(index, value, Qt::EditRole);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NLGEORGES::UType::Double:
|
||||||
|
{
|
||||||
|
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||||
|
double value = spinBox->value();
|
||||||
|
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
|
||||||
|
if (QString("%1").arg(value) == oldValue)
|
||||||
|
{
|
||||||
|
// nothing's changed
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nldebug(QString("setModelData from %1 to %2")
|
||||||
|
.arg(oldValue).arg(value).toStdString().c_str());
|
||||||
|
model->setData(index, value, Qt::EditRole);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NLGEORGES::UType::Color:
|
||||||
|
{
|
||||||
|
break; // TODO
|
||||||
|
}
|
||||||
|
default: // UType::String
|
||||||
|
{
|
||||||
|
QLineEdit *textEdit = static_cast<QLineEdit*>(editor);
|
||||||
|
QString value = textEdit->text();
|
||||||
|
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
|
||||||
|
if (value == oldValue)
|
||||||
|
{
|
||||||
|
// nothing's changed
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nldebug(QString("setModelData from %1 to %2")
|
||||||
|
.arg(oldValue).arg(value).toStdString().c_str());
|
||||||
|
model->setData(index, value, Qt::EditRole);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormDelegate::updateEditorGeometry(QWidget *editor,
|
||||||
|
const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
QRect r = option.rect;
|
||||||
|
editor->setGeometry(r);
|
||||||
|
//option.decorationAlignment = QStyleOptionViewItem::Right;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
QStyleOptionViewItemV4 optionV4 = option;
|
||||||
|
optionV4.decorationPosition = QStyleOptionViewItem::Right;
|
||||||
|
//optionV4.decorationSize = QSize(32,32);
|
||||||
|
initStyleOption(&optionV4, index);
|
||||||
|
|
||||||
|
QStyledItemDelegate::paint(painter,optionV4,index);
|
||||||
|
|
||||||
|
//QStyle *style = optionV4.widget? optionV4.widget->style() : QApplication::style();
|
||||||
|
|
||||||
|
//QTextDocument doc;
|
||||||
|
//doc.setHtml(optionV4.text);
|
||||||
|
|
||||||
|
///// Painting item without text
|
||||||
|
//optionV4.text = QString();
|
||||||
|
//style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
|
||||||
|
|
||||||
|
//QAbstractTextDocumentLayout::PaintContext ctx;
|
||||||
|
|
||||||
|
//// Highlighting text if item is selected
|
||||||
|
//if (optionV4.state & QStyle::State_Selected)
|
||||||
|
// ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));
|
||||||
|
|
||||||
|
//QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4);
|
||||||
|
//painter->save();
|
||||||
|
//painter->translate(textRect.topLeft());
|
||||||
|
//painter->setClipRect(textRect.translated(-textRect.topLeft()));
|
||||||
|
//doc.documentLayout()->draw(painter, ctx);
|
||||||
|
//painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace NLQT */
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
Georges Editor Qt
|
||||||
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FORMDELEGATE_H
|
||||||
|
#define FORMDELEGATE_H
|
||||||
|
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
|
class FormDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
FormDelegate(QObject *parent = 0);
|
||||||
|
|
||||||
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||||
|
const QModelIndex &index) const;
|
||||||
|
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||||
|
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||||
|
const QModelIndex &index) const;
|
||||||
|
void updateEditorGeometry(QWidget *editor,
|
||||||
|
const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
void paint ( QPainter * painter, const QStyleOptionViewItem & option,
|
||||||
|
const QModelIndex & index ) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // FORMDELEGATE_H
|
|
@ -24,10 +24,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
// NeL includes
|
// NeL includes
|
||||||
#include <nel/georges/u_type.h>
|
#include <nel/georges/u_type.h>
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
CFormItem::CFormItem(NLGEORGES::UFormElm* elm, const QList<QVariant> &data, CFormItem *parent,
|
CFormItem::CFormItem(NLGEORGES::UFormElm* elm, const QList<QVariant> &data, CFormItem *parent,
|
||||||
NLGEORGES::UFormElm::TWhereIsValue wV, NLGEORGES::UFormElm::TWhereIsNode wN) {
|
NLGEORGES::UFormElm::TWhereIsValue wV, NLGEORGES::UFormElm::TWhereIsNode wN)
|
||||||
|
{
|
||||||
parentItem = parent;
|
parentItem = parent;
|
||||||
itemData = data;
|
itemData = data;
|
||||||
formElm = elm;
|
formElm = elm;
|
||||||
|
@ -35,27 +37,33 @@ namespace NLQT {
|
||||||
whereN = wN;
|
whereN = wN;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFormItem::~CFormItem() {
|
CFormItem::~CFormItem()
|
||||||
|
{
|
||||||
qDeleteAll(childItems);
|
qDeleteAll(childItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFormItem::appendChild(CFormItem *item) {
|
void CFormItem::appendChild(CFormItem *item)
|
||||||
|
{
|
||||||
childItems.append(item);
|
childItems.append(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFormItem *CFormItem::child(int row) {
|
CFormItem *CFormItem::child(int row)
|
||||||
|
{
|
||||||
return childItems.value(row);
|
return childItems.value(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFormItem::childCount() const {
|
int CFormItem::childCount() const
|
||||||
|
{
|
||||||
return childItems.count();
|
return childItems.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFormItem::columnCount() const {
|
int CFormItem::columnCount() const
|
||||||
|
{
|
||||||
return itemData.count();
|
return itemData.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CFormItem::data(int column) const {
|
QVariant CFormItem::data(int column) const
|
||||||
|
{
|
||||||
return itemData.value(column);
|
return itemData.value(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,36 +72,41 @@ namespace NLQT {
|
||||||
return parentItem;
|
return parentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFormItem::row() const {
|
int CFormItem::row() const
|
||||||
|
{
|
||||||
if (parentItem)
|
if (parentItem)
|
||||||
return parentItem->childItems.indexOf(const_cast<CFormItem*>(this));
|
return parentItem->childItems.indexOf(const_cast<CFormItem*>(this));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFormItem::setData(int column, const QVariant &value) {
|
bool CFormItem::setData(int column, const QVariant &value)
|
||||||
|
{
|
||||||
if (column < 0 || column >= itemData.size())
|
if (column < 0 || column >= itemData.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
itemData[column] = value;
|
itemData[column] = value;
|
||||||
if (formElm->isAtom()) {
|
if (formElm->isAtom())
|
||||||
|
{
|
||||||
const NLGEORGES::UType *type = formElm->getType();
|
const NLGEORGES::UType *type = formElm->getType();
|
||||||
if (type) {
|
if (type)
|
||||||
switch (type->getType()) {
|
{
|
||||||
case NLGEORGES::UType::UnsignedInt:
|
switch (type->getType())
|
||||||
case NLGEORGES::UType::SignedInt:
|
{
|
||||||
case NLGEORGES::UType::Double:
|
case NLGEORGES::UType::UnsignedInt:
|
||||||
case NLGEORGES::UType::String:
|
case NLGEORGES::UType::SignedInt:
|
||||||
nldebug(QString("string %1 %2")
|
case NLGEORGES::UType::Double:
|
||||||
.arg(itemData[0].toString()).arg(value.toString())
|
case NLGEORGES::UType::String:
|
||||||
.toStdString().c_str());
|
nldebug(QString("string %1 %2")
|
||||||
parentItem->formElm->setValueByName(
|
.arg(itemData[0].toString()).arg(value.toString())
|
||||||
value.toString().toStdString().c_str(),itemData[0].toString().toStdString().c_str());
|
.toStdString().c_str());
|
||||||
break;
|
parentItem->formElm->setValueByName(
|
||||||
case NLGEORGES::UType::Color:
|
value.toString().toStdString().c_str(),itemData[0].toString().toStdString().c_str());
|
||||||
break;
|
break;
|
||||||
default:
|
case NLGEORGES::UType::Color:
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FORMITEM_H
|
#ifndef FORMITEM_H
|
||||||
|
@ -26,43 +26,46 @@
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
class CFormItem
|
class CFormItem
|
||||||
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CFormItem(NLGEORGES::UFormElm *elm, const QList<QVariant> &data,
|
CFormItem(NLGEORGES::UFormElm *elm, const QList<QVariant> &data,
|
||||||
CFormItem *parent = 0,
|
CFormItem *parent = 0,
|
||||||
NLGEORGES::UFormElm::TWhereIsValue = NLGEORGES::UFormElm::ValueForm,
|
NLGEORGES::UFormElm::TWhereIsValue = NLGEORGES::UFormElm::ValueForm,
|
||||||
NLGEORGES::UFormElm::TWhereIsNode = NLGEORGES::UFormElm::NodeForm);
|
NLGEORGES::UFormElm::TWhereIsNode = NLGEORGES::UFormElm::NodeForm);
|
||||||
~CFormItem();
|
~CFormItem();
|
||||||
|
|
||||||
void appendChild(CFormItem *child);
|
void appendChild(CFormItem *child);
|
||||||
|
|
||||||
CFormItem *child(int row);
|
CFormItem *child(int row);
|
||||||
int childCount() const;
|
int childCount() const;
|
||||||
int columnCount() const;
|
int columnCount() const;
|
||||||
QVariant data(int column) const;
|
QVariant data(int column) const;
|
||||||
int row() const;
|
int row() const;
|
||||||
CFormItem *parent();
|
CFormItem *parent();
|
||||||
bool setData(int column, const QVariant &value);
|
bool setData(int column, const QVariant &value);
|
||||||
NLGEORGES::UFormElm* getFormElm() {return formElm;};
|
NLGEORGES::UFormElm* getFormElm() {return formElm;};
|
||||||
NLGEORGES::UFormElm::TWhereIsValue CFormItem::valueFrom() {
|
NLGEORGES::UFormElm::TWhereIsValue CFormItem::valueFrom()
|
||||||
return whereV;
|
{
|
||||||
}
|
return whereV;
|
||||||
NLGEORGES::UFormElm::TWhereIsNode CFormItem::nodeFrom() {
|
}
|
||||||
return whereN;
|
NLGEORGES::UFormElm::TWhereIsNode CFormItem::nodeFrom()
|
||||||
}
|
{
|
||||||
|
return whereN;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<CFormItem*> childItems;
|
QList<CFormItem*> childItems;
|
||||||
QList<QVariant> itemData;
|
QList<QVariant> itemData;
|
||||||
CFormItem *parentItem;
|
CFormItem *parentItem;
|
||||||
NLGEORGES::UFormElm* formElm;
|
NLGEORGES::UFormElm* formElm;
|
||||||
NLGEORGES::UFormElm::TWhereIsValue whereV;
|
NLGEORGES::UFormElm::TWhereIsValue whereV;
|
||||||
NLGEORGES::UFormElm::TWhereIsNode whereN;
|
NLGEORGES::UFormElm::TWhereIsNode whereN;
|
||||||
}; // CFormItem
|
}; // CFormItem
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // FORMITEM_H
|
#endif // FORMITEM_H
|
||||||
|
|
|
@ -29,15 +29,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using namespace NLGEORGES;
|
using namespace NLGEORGES;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
CGeorges::CGeorges(): FormLoader(0) {
|
CGeorges::CGeorges(): FormLoader(0)
|
||||||
|
{
|
||||||
FormLoader = UFormLoader::createLoader();
|
FormLoader = UFormLoader::createLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
CGeorges::~CGeorges() {}
|
CGeorges::~CGeorges()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
UForm *CGeorges::loadForm(std::string formName) {
|
UForm *CGeorges::loadForm(std::string formName)
|
||||||
|
{
|
||||||
UForm *form = FormLoader->loadForm(formName.c_str());
|
UForm *form = FormLoader->loadForm(formName.c_str());
|
||||||
|
|
||||||
return form;
|
return form;
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef GEORGES_H
|
#ifndef GEORGES_H
|
||||||
|
@ -38,26 +38,27 @@ namespace NLGEORGES
|
||||||
|
|
||||||
using namespace NLGEORGES;
|
using namespace NLGEORGES;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
|
||||||
/**
|
|
||||||
@class CGeorges
|
|
||||||
A CGeorges class loading and viewing sheets.
|
|
||||||
*/
|
|
||||||
class CGeorges
|
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
/// Default constructor.
|
|
||||||
CGeorges();
|
|
||||||
virtual ~CGeorges();
|
|
||||||
|
|
||||||
// Load the given form root
|
/**
|
||||||
UForm* loadForm(std::string formName);
|
@class CGeorges
|
||||||
|
A CGeorges class loading and viewing sheets.
|
||||||
|
*/
|
||||||
|
class CGeorges
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// Default constructor.
|
||||||
|
CGeorges();
|
||||||
|
virtual ~CGeorges();
|
||||||
|
|
||||||
// A form loader
|
// Load the given form root
|
||||||
UFormLoader *FormLoader;
|
UForm* loadForm(std::string formName);
|
||||||
|
|
||||||
};/* class CGeorges */
|
// A form loader
|
||||||
|
UFormLoader *FormLoader;
|
||||||
|
|
||||||
|
};/* class CGeorges */
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
|
|
@ -30,101 +30,113 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
CGeorgesDirTreeDialog::CGeorgesDirTreeDialog(QString ldPath, QWidget *parent):
|
CGeorgesDirTreeDialog::CGeorgesDirTreeDialog(QString ldPath, QWidget *parent)
|
||||||
QDockWidget(parent),
|
:QDockWidget(parent), _ldPath(ldPath)
|
||||||
_ldPath(ldPath){
|
{
|
||||||
|
|
||||||
_ui.setupUi(this);
|
_ui.setupUi(this);
|
||||||
|
|
||||||
//QStyleOptionViewItem myButtonOption;
|
//QStyleOptionViewItem myButtonOption;
|
||||||
// const QStyleOptionViewItem *buttonOption =
|
// const QStyleOptionViewItem *buttonOption =
|
||||||
// qstyleoption_cast<const QStyleOptionViewItem *>(_ui.dirTree->style());
|
// qstyleoption_cast<const QStyleOptionViewItem *>(_ui.dirTree->style());
|
||||||
|
|
||||||
/*setStyleSheet(" \
|
/*setStyleSheet(" \
|
||||||
QTreeView { \
|
QTreeView { \
|
||||||
alternate-background-color: yellow; \
|
alternate-background-color: yellow; \
|
||||||
} \
|
} \
|
||||||
QTreeView::item { \
|
QTreeView::item { \
|
||||||
border: 1px solid #d9d9d9; \
|
border: 1px solid #d9d9d9; \
|
||||||
border-top-color: transparent; \
|
border-top-color: transparent; \
|
||||||
border-bottom-color: transparent; \
|
border-bottom-color: transparent; \
|
||||||
} \
|
} \
|
||||||
QTreeView::item:hover { \
|
QTreeView::item:hover { \
|
||||||
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);\
|
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);\
|
||||||
border: 1px solid #bfcde4; \
|
border: 1px solid #bfcde4; \
|
||||||
} \
|
} \
|
||||||
QTreeView::item:selected { \
|
QTreeView::item:selected { \
|
||||||
border: 1px solid #567dbc; \
|
border: 1px solid #567dbc; \
|
||||||
} \
|
} \
|
||||||
QTreeView::item:selected:active{ \
|
QTreeView::item:selected:active{ \
|
||||||
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);\
|
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);\
|
||||||
} \
|
} \
|
||||||
QTreeView::item:selected:!active { \
|
QTreeView::item:selected:!active { \
|
||||||
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf);\
|
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf);\
|
||||||
}\
|
}\
|
||||||
");*/
|
");*/
|
||||||
//QString leveldata = Modules::config().getConfigFile().getVar("SearchPaths").asString().c_str();
|
//QString leveldata = Modules::config().getConfigFile().getVar("SearchPaths").asString().c_str();
|
||||||
|
|
||||||
_dirModel = new CFileSystemModel(_ldPath);
|
|
||||||
_ui.dirTree->setModel(_dirModel);
|
|
||||||
|
|
||||||
QFileInfo info(_ldPath);
|
|
||||||
|
|
||||||
if (!_ldPath.isEmpty() && info.isDir()) {
|
|
||||||
_dirModel->setRootPath(_ldPath);
|
|
||||||
_ui.dirTree->setRootIndex(_dirModel->index(_ldPath));
|
|
||||||
} else {
|
|
||||||
_dirModel->setRootPath(QDir::currentPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
_ui.dirTree->setAnimated(false);
|
|
||||||
_ui.dirTree->setIndentation(20);
|
|
||||||
//_ui.dirTree->setSortingEnabled(true);
|
|
||||||
|
|
||||||
/*connect(_ui.dirTree, SIGNAL(clicked(QModelIndex)),
|
|
||||||
this, SLOT(fileSelected(QModelIndex)));*/
|
|
||||||
connect(_ui.dirTree, SIGNAL(activated(QModelIndex)),
|
|
||||||
this, SLOT(fileSelected(QModelIndex)));
|
|
||||||
}
|
|
||||||
|
|
||||||
CGeorgesDirTreeDialog::~CGeorgesDirTreeDialog() {
|
|
||||||
delete _dirModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CGeorgesDirTreeDialog::fileSelected(QModelIndex index) {
|
|
||||||
QString name;
|
|
||||||
if (index.isValid() && !_dirModel->isDir(index)) {
|
|
||||||
Q_EMIT selectedForm(_dirModel->fileName(index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CGeorgesDirTreeDialog::changeFile(QString file) {
|
|
||||||
QModelIndex index = _dirModel->index(file);
|
|
||||||
//_dirModel->;
|
|
||||||
_ui.dirTree->selectionModel()->select(index,QItemSelectionModel::ClearAndSelect);
|
|
||||||
_ui.dirTree->scrollTo(index,QAbstractItemView::PositionAtCenter);
|
|
||||||
fileSelected(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CGeorgesDirTreeDialog::ldPathChanged(QString path) {
|
|
||||||
_ldPath = path;
|
|
||||||
QFileInfo info(_ldPath);
|
|
||||||
|
|
||||||
delete _dirModel;
|
|
||||||
|
|
||||||
if (!_ldPath.isEmpty() && info.isDir()) {
|
|
||||||
_dirModel = new CFileSystemModel(_ldPath);
|
_dirModel = new CFileSystemModel(_ldPath);
|
||||||
_ui.dirTree->setModel(_dirModel);
|
_ui.dirTree->setModel(_dirModel);
|
||||||
_dirModel->setRootPath(_ldPath);
|
|
||||||
_ui.dirTree->setRootIndex(_dirModel->index(_ldPath));
|
QFileInfo info(_ldPath);
|
||||||
} else {
|
|
||||||
_dirModel = new CFileSystemModel("");
|
if (!_ldPath.isEmpty() && info.isDir())
|
||||||
_ui.dirTree->setModel(_dirModel);
|
{
|
||||||
_dirModel->setRootPath(QDir::currentPath());
|
_dirModel->setRootPath(_ldPath);
|
||||||
_ldPath = "";
|
_ui.dirTree->setRootIndex(_dirModel->index(_ldPath));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_dirModel->setRootPath(QDir::currentPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
_ui.dirTree->setAnimated(false);
|
||||||
|
_ui.dirTree->setIndentation(20);
|
||||||
|
//_ui.dirTree->setSortingEnabled(true);
|
||||||
|
|
||||||
|
/*connect(_ui.dirTree, SIGNAL(clicked(QModelIndex)),
|
||||||
|
this, SLOT(fileSelected(QModelIndex)));*/
|
||||||
|
connect(_ui.dirTree, SIGNAL(activated(QModelIndex)),
|
||||||
|
this, SLOT(fileSelected(QModelIndex)));
|
||||||
|
}
|
||||||
|
|
||||||
|
CGeorgesDirTreeDialog::~CGeorgesDirTreeDialog()
|
||||||
|
{
|
||||||
|
delete _dirModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesDirTreeDialog::fileSelected(QModelIndex index)
|
||||||
|
{
|
||||||
|
QString name;
|
||||||
|
if (index.isValid() && !_dirModel->isDir(index))
|
||||||
|
{
|
||||||
|
Q_EMIT selectedForm(_dirModel->fileName(index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesDirTreeDialog::changeFile(QString file)
|
||||||
|
{
|
||||||
|
QModelIndex index = _dirModel->index(file);
|
||||||
|
//_dirModel->;
|
||||||
|
_ui.dirTree->selectionModel()->select(index,QItemSelectionModel::ClearAndSelect);
|
||||||
|
_ui.dirTree->scrollTo(index,QAbstractItemView::PositionAtCenter);
|
||||||
|
fileSelected(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesDirTreeDialog::ldPathChanged(QString path)
|
||||||
|
{
|
||||||
|
_ldPath = path;
|
||||||
|
QFileInfo info(_ldPath);
|
||||||
|
|
||||||
|
delete _dirModel;
|
||||||
|
|
||||||
|
if (!_ldPath.isEmpty() && info.isDir())
|
||||||
|
{
|
||||||
|
_dirModel = new CFileSystemModel(_ldPath);
|
||||||
|
_ui.dirTree->setModel(_dirModel);
|
||||||
|
_dirModel->setRootPath(_ldPath);
|
||||||
|
_ui.dirTree->setRootIndex(_dirModel->index(_ldPath));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_dirModel = new CFileSystemModel("");
|
||||||
|
_ui.dirTree->setModel(_dirModel);
|
||||||
|
_dirModel->setRootPath(QDir::currentPath());
|
||||||
|
_ldPath = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef GEORGES_DIRTREE_DIALOG_H
|
#ifndef GEORGES_DIRTREE_DIALOG_H
|
||||||
|
@ -30,34 +30,35 @@
|
||||||
#include "ui_georges_dirtree_form.h"
|
#include "ui_georges_dirtree_form.h"
|
||||||
#include "filesystem_model.h"
|
#include "filesystem_model.h"
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
|
||||||
class CGeorgesDirTreeDialog: public QDockWidget
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
class CGeorgesDirTreeDialog: public QDockWidget
|
||||||
CGeorgesDirTreeDialog(QString ldPath, QWidget *parent = 0);
|
{
|
||||||
~CGeorgesDirTreeDialog();
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
public:
|
||||||
Ui::CGeorgesDirTreeDialog _ui;
|
CGeorgesDirTreeDialog(QString ldPath, QWidget *parent = 0);
|
||||||
|
~CGeorgesDirTreeDialog();
|
||||||
|
|
||||||
CFileSystemModel *_dirModel;
|
private:
|
||||||
QString _ldPath;
|
Ui::CGeorgesDirTreeDialog _ui;
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void selectedForm(QString);
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
CFileSystemModel *_dirModel;
|
||||||
void ldPathChanged(QString path);
|
QString _ldPath;
|
||||||
|
|
||||||
private Q_SLOTS:
|
Q_SIGNALS:
|
||||||
void fileSelected(QModelIndex index);
|
void selectedForm(QString);
|
||||||
void changeFile(QString file);
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void ldPathChanged(QString path);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void fileSelected(QModelIndex index);
|
||||||
|
void changeFile(QString file);
|
||||||
|
|
||||||
friend class CMainWindow;
|
friend class CMainWindow;
|
||||||
}; /* CGEorgesDirTreeDialog */
|
}; /* CGEorgesDirTreeDialog */
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "georgesform_model.h"
|
#include "georgesform_model.h"
|
||||||
#include "georgesform_proxy_model.h"
|
#include "georgesform_proxy_model.h"
|
||||||
#include "formitem.h"
|
#include "formitem.h"
|
||||||
#include "spindelegate.h"
|
#include "formdelegate.h"
|
||||||
|
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
using namespace NLGEORGES;
|
using namespace NLGEORGES;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/, bool emptyView /*= false*/)
|
CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/, bool emptyView /*= false*/)
|
||||||
: QDockWidget(parent)
|
: QDockWidget(parent)
|
||||||
|
@ -50,7 +51,8 @@ namespace NLQT {
|
||||||
_ui.setupUi(this);
|
_ui.setupUi(this);
|
||||||
_ui.treeViewTabWidget->setTabEnabled (2,false);
|
_ui.treeViewTabWidget->setTabEnabled (2,false);
|
||||||
|
|
||||||
if (emptyView) {
|
if (emptyView)
|
||||||
|
{
|
||||||
_ui.treeViewTabWidget->clear();
|
_ui.treeViewTabWidget->clear();
|
||||||
setWindowTitle("Form Area");
|
setWindowTitle("Form Area");
|
||||||
}
|
}
|
||||||
|
@ -59,9 +61,9 @@ namespace NLQT {
|
||||||
_ui.checkBoxDefaults->setStyleSheet("background-color: rgba(255,0,0,30)");
|
_ui.checkBoxDefaults->setStyleSheet("background-color: rgba(255,0,0,30)");
|
||||||
_form = 0;
|
_form = 0;
|
||||||
|
|
||||||
SpinBoxDelegate *spindelegate = new SpinBoxDelegate(this);
|
FormDelegate *formdelegate = new FormDelegate(this);
|
||||||
_ui.treeView->setItemDelegateForColumn(1, spindelegate);
|
_ui.treeView->setItemDelegateForColumn(1, formdelegate);
|
||||||
|
|
||||||
|
|
||||||
connect(_ui.treeView, SIGNAL(doubleClicked (QModelIndex)),
|
connect(_ui.treeView, SIGNAL(doubleClicked (QModelIndex)),
|
||||||
this, SLOT(doubleClicked (QModelIndex)));
|
this, SLOT(doubleClicked (QModelIndex)));
|
||||||
|
@ -77,15 +79,18 @@ namespace NLQT {
|
||||||
//settings.setValue("dirViewGeometry", saveGeometry());
|
//settings.setValue("dirViewGeometry", saveGeometry());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGeorgesTreeViewDialog::selectedForm(QString formName) {
|
void CGeorgesTreeViewDialog::selectedForm(QString formName)
|
||||||
|
{
|
||||||
_form = Modules::georges().loadForm(formName.toStdString());
|
_form = Modules::georges().loadForm(formName.toStdString());
|
||||||
|
|
||||||
if (_form) {
|
if (_form)
|
||||||
|
{
|
||||||
UFormElm *root = 0;
|
UFormElm *root = 0;
|
||||||
root = &_form->getRootNode();
|
root = &_form->getRootNode();
|
||||||
|
|
||||||
QStringList parents;
|
QStringList parents;
|
||||||
for (uint i = 0; i < _form->getNumParent(); i++) {
|
for (uint i = 0; i < _form->getNumParent(); i++)
|
||||||
|
{
|
||||||
UForm *u = _form->getParentForm(i);
|
UForm *u = _form->getParentForm(i);
|
||||||
parents << u->getFilename().c_str();
|
parents << u->getFilename().c_str();
|
||||||
}
|
}
|
||||||
|
@ -93,7 +98,8 @@ namespace NLQT {
|
||||||
QString comments;
|
QString comments;
|
||||||
comments = _form->getComment().c_str();
|
comments = _form->getComment().c_str();
|
||||||
|
|
||||||
if (!comments.isEmpty()) {
|
if (!comments.isEmpty())
|
||||||
|
{
|
||||||
_ui.treeViewTabWidget->setTabEnabled (1,true);
|
_ui.treeViewTabWidget->setTabEnabled (1,true);
|
||||||
_ui.commentEdit->setPlainText(comments);
|
_ui.commentEdit->setPlainText(comments);
|
||||||
}
|
}
|
||||||
|
@ -103,16 +109,18 @@ namespace NLQT {
|
||||||
_form->getDependencies(dependencies);
|
_form->getDependencies(dependencies);
|
||||||
|
|
||||||
QMap< QString, QStringList> deps;
|
QMap< QString, QStringList> deps;
|
||||||
Q_FOREACH(std::string str, dependencies) {
|
Q_FOREACH(std::string str, dependencies)
|
||||||
|
{
|
||||||
QString file = str.c_str();
|
QString file = str.c_str();
|
||||||
if (file == formName) continue;
|
if (file == formName) continue;
|
||||||
deps[file.remove(0,file.indexOf(".")+1)] << str.c_str();
|
deps[file.remove(0,file.indexOf(".")+1)] << str.c_str();
|
||||||
}
|
}
|
||||||
nlinfo("typ's %d",deps["typ"].count());
|
nlinfo("typ's %d",deps["typ"].count());
|
||||||
nlinfo("dfn's %d",deps["dfn"].count());
|
nlinfo("dfn's %d",deps["dfn"].count());
|
||||||
|
|
||||||
//nlwarning(strList.join(";").toStdString().c_str());
|
//nlwarning(strList.join(";").toStdString().c_str());
|
||||||
if (root) {
|
if (root)
|
||||||
|
{
|
||||||
loadedForm = formName;
|
loadedForm = formName;
|
||||||
|
|
||||||
CGeorgesFormModel *model = new CGeorgesFormModel(root,deps,comments,parents);
|
CGeorgesFormModel *model = new CGeorgesFormModel(root,deps,comments,parents);
|
||||||
|
@ -137,8 +145,10 @@ namespace NLQT {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGeorgesTreeViewDialog::modifiedFile( ) {
|
void CGeorgesTreeViewDialog::modifiedFile( )
|
||||||
if (!_modified) {
|
{
|
||||||
|
if (!_modified)
|
||||||
|
{
|
||||||
_modified = true;
|
_modified = true;
|
||||||
setWindowTitle(windowTitle()+"*");
|
setWindowTitle(windowTitle()+"*");
|
||||||
Modules::mainWin().setWindowTitle(Modules::mainWin().windowTitle()+"*");
|
Modules::mainWin().setWindowTitle(Modules::mainWin().windowTitle()+"*");
|
||||||
|
@ -146,13 +156,17 @@ namespace NLQT {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGeorgesTreeViewDialog::write( ) {
|
void CGeorgesTreeViewDialog::write( )
|
||||||
|
{
|
||||||
|
|
||||||
COFile file;
|
COFile file;
|
||||||
std::string s = CPath::lookup(loadedForm.toStdString());
|
std::string s = CPath::lookup(loadedForm.toStdString());
|
||||||
if (file.open (s)) {
|
if (file.open (s))
|
||||||
try {
|
{
|
||||||
if (loadedForm.contains(".typ")) {
|
try
|
||||||
|
{
|
||||||
|
if (loadedForm.contains(".typ"))
|
||||||
|
{
|
||||||
//nlassert (Type != NULL);
|
//nlassert (Type != NULL);
|
||||||
|
|
||||||
//// Write the file
|
//// Write the file
|
||||||
|
@ -167,7 +181,9 @@ namespace NLQT {
|
||||||
//flushValueChange ();
|
//flushValueChange ();
|
||||||
//UpdateAllViews (NULL);
|
//UpdateAllViews (NULL);
|
||||||
//return TRUE;
|
//return TRUE;
|
||||||
} else if (loadedForm.contains(".dfn")) {
|
}
|
||||||
|
else if (loadedForm.contains(".dfn"))
|
||||||
|
{
|
||||||
//nlassert (Dfn != NULL);
|
//nlassert (Dfn != NULL);
|
||||||
|
|
||||||
//// Write the file
|
//// Write the file
|
||||||
|
@ -180,13 +196,15 @@ namespace NLQT {
|
||||||
//modify (NULL, NULL, false);
|
//modify (NULL, NULL, false);
|
||||||
//UpdateAllViews (NULL);
|
//UpdateAllViews (NULL);
|
||||||
//return TRUE;
|
//return TRUE;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
nlassert (_form != NULL);
|
nlassert (_form != NULL);
|
||||||
|
|
||||||
// Write the file
|
// Write the file
|
||||||
/*if (IsModified ())
|
/*if (IsModified ())
|
||||||
{
|
{
|
||||||
((CForm*)(UForm*)Form)->Header.MinorVersion++;
|
((CForm*)(UForm*)Form)->Header.MinorVersion++;
|
||||||
}*/
|
}*/
|
||||||
//((CForm*)(UForm*)Form)->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS);
|
//((CForm*)(UForm*)Form)->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS);
|
||||||
_form->write(file, false);
|
_form->write(file, false);
|
||||||
|
@ -196,7 +214,7 @@ namespace NLQT {
|
||||||
//{
|
//{
|
||||||
// char message[512];
|
// char message[512];
|
||||||
// smprintf (message, 512, "Error while saving file: %s", xmlStream.getErrorString ());
|
// smprintf (message, 512, "Error while saving file: %s", xmlStream.getErrorString ());
|
||||||
//theApp.outputError (message);
|
//theApp.outputError (message);
|
||||||
//}
|
//}
|
||||||
//modify (NULL, NULL, false);
|
//modify (NULL, NULL, false);
|
||||||
//flushValueChange ();
|
//flushValueChange ();
|
||||||
|
@ -205,16 +223,23 @@ namespace NLQT {
|
||||||
// Get the left view
|
// Get the left view
|
||||||
//CView* pView = getLeftView ();
|
//CView* pView = getLeftView ();
|
||||||
}
|
}
|
||||||
} catch (Exception &e) {
|
}
|
||||||
|
catch (Exception &e)
|
||||||
|
{
|
||||||
nlerror("Error while loading file: %s", e.what());
|
nlerror("Error while loading file: %s", e.what());
|
||||||
}
|
}
|
||||||
} else { //if (!file.open())
|
}
|
||||||
|
else
|
||||||
|
{ //if (!file.open())
|
||||||
nlerror("Can't open the file %s for writing.", s);
|
nlerror("Can't open the file %s for writing.", s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index ) {
|
void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index )
|
||||||
if (index.column() == 1) return;
|
{
|
||||||
|
if (index.column() == 1)
|
||||||
|
return;
|
||||||
|
|
||||||
CFormItem *item = static_cast<CFormItem*>(index.internalPointer());
|
CFormItem *item = static_cast<CFormItem*>(index.internalPointer());
|
||||||
|
|
||||||
QString value = item->data(1).toString();
|
QString value = item->data(1).toString();
|
||||||
|
@ -222,7 +247,8 @@ namespace NLQT {
|
||||||
|
|
||||||
if (!path.isEmpty() && !path.contains(".shape"))
|
if (!path.isEmpty() && !path.contains(".shape"))
|
||||||
Q_EMIT changeFile(path);
|
Q_EMIT changeFile(path);
|
||||||
if (path.contains(".shape")) {
|
if (path.contains(".shape"))
|
||||||
|
{
|
||||||
Modules::objView().resetScene();
|
Modules::objView().resetScene();
|
||||||
Modules::config().configRemapExtensions();
|
Modules::config().configRemapExtensions();
|
||||||
Modules::objView().loadMesh(path.toStdString(),"");
|
Modules::objView().loadMesh(path.toStdString(),"");
|
||||||
|
@ -230,37 +256,55 @@ namespace NLQT {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) {
|
void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event)
|
||||||
if (Modules::mainWin().getEmptyView() == this) {
|
{
|
||||||
|
if (Modules::mainWin().getEmptyView() == this)
|
||||||
|
{
|
||||||
event->ignore();
|
event->ignore();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Modules::mainWin().getTreeViewList().removeOne(this);
|
Modules::mainWin().getTreeViewList().removeOne(this);
|
||||||
if(!Modules::mainWin().getTreeViewList().size()) {
|
if(!Modules::mainWin().getTreeViewList().size())
|
||||||
|
{
|
||||||
Modules::mainWin().createEmptyView();
|
Modules::mainWin().createEmptyView();
|
||||||
}
|
}
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGeorgesTreeViewDialog::showParentRows(int newState) {
|
void CGeorgesTreeViewDialog::showParentRows(int newState)
|
||||||
|
{
|
||||||
CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(_ui.treeView->model());
|
CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(_ui.treeView->model());
|
||||||
CGeorgesFormModel *m = qobject_cast<CGeorgesFormModel *>(mp->sourceModel());
|
CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel());
|
||||||
|
|
||||||
for (int i = 0; i < m->rowCount(); i++) {
|
for (int i = 0; i < m->rowCount(); i++)
|
||||||
|
{
|
||||||
const QModelIndex in = m->index(i,0);
|
const QModelIndex in = m->index(i,0);
|
||||||
if (m->getItem(in)->nodeFrom() == UFormElm::NodeParentForm) {
|
if (m->getItem(in)->nodeFrom() == UFormElm::NodeParentForm)
|
||||||
if (newState == Qt::Checked) {
|
{
|
||||||
|
if (newState == Qt::Checked)
|
||||||
|
{
|
||||||
_ui.treeView->setRowHidden(in.row(),in.parent(),false);
|
_ui.treeView->setRowHidden(in.row(),in.parent(),false);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
_ui.treeView->setRowHidden(in.row(),in.parent(),true);
|
_ui.treeView->setRowHidden(in.row(),in.parent(),true);
|
||||||
}
|
}
|
||||||
} else { // search childs // recursive?
|
}
|
||||||
for (int j = 0; j < m->rowCount(in); j++) {
|
else
|
||||||
|
{ // search childs // recursive?
|
||||||
|
for (int j = 0; j < m->rowCount(in); j++)
|
||||||
|
{
|
||||||
const QModelIndex in2 = m->index(j,0,in);
|
const QModelIndex in2 = m->index(j,0,in);
|
||||||
if (m->getItem(in2)->nodeFrom() == UFormElm::NodeParentForm) {
|
if (m->getItem(in2)->nodeFrom() == UFormElm::NodeParentForm)
|
||||||
if (newState == Qt::Checked) {
|
{
|
||||||
|
if (newState == Qt::Checked)
|
||||||
|
{
|
||||||
_ui.treeView->setRowHidden(in2.row(),in,false);
|
_ui.treeView->setRowHidden(in2.row(),in,false);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
_ui.treeView->setRowHidden(in2.row(),in,true);
|
_ui.treeView->setRowHidden(in2.row(),in,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,4 +312,5 @@ namespace NLQT {
|
||||||
} // end of search childs
|
} // end of search childs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
|
@ -37,7 +37,8 @@ namespace NLGEORGES
|
||||||
|
|
||||||
using namespace NLGEORGES;
|
using namespace NLGEORGES;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
class CGeorgesTreeViewDialog: public QDockWidget
|
class CGeorgesTreeViewDialog: public QDockWidget
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "georgesform_model.h"
|
#include "georgesform_model.h"
|
||||||
|
@ -38,79 +38,89 @@
|
||||||
|
|
||||||
using namespace NLGEORGES;
|
using namespace NLGEORGES;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
CGeorgesFormModel::CGeorgesFormModel(UFormElm *rootElm, QMap< QString, QStringList> deps,
|
CGeorgesFormModel::CGeorgesFormModel(UFormElm *rootElm, QMap< QString, QStringList> deps,
|
||||||
QString comment, QStringList parents, QObject *parent) : QAbstractItemModel(parent) {
|
QString comment, QStringList parents, QObject *parent) : QAbstractItemModel(parent)
|
||||||
|
{
|
||||||
|
QList<QVariant> rootData;
|
||||||
|
rootData << "Value" << "Data" << "Extra" << "Type";
|
||||||
|
_rootElm = rootElm;
|
||||||
|
_rootItem = new CFormItem(_rootElm, rootData);
|
||||||
|
_dependencies = deps;
|
||||||
|
_comments = comment;
|
||||||
|
_parents = parents;
|
||||||
|
_parentRows = new QList<const QModelIndex*>;
|
||||||
|
|
||||||
QList<QVariant> rootData;
|
setupModelData();
|
||||||
rootData << "Value" << "Data" << "Extra" << "Type";
|
|
||||||
_rootElm = rootElm;
|
|
||||||
_rootItem = new CFormItem(_rootElm, rootData);
|
|
||||||
_dependencies = deps;
|
|
||||||
_comments = comment;
|
|
||||||
_parents = parents;
|
|
||||||
_parentRows = new QList<const QModelIndex*>;
|
|
||||||
|
|
||||||
setupModelData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CGeorgesFormModel::~CGeorgesFormModel() {
|
CGeorgesFormModel::~CGeorgesFormModel()
|
||||||
|
{
|
||||||
delete _rootItem;
|
delete _rootItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
QVariant CGeorgesFormModel::data(const QModelIndex &p_index, int p_role) const {
|
QVariant CGeorgesFormModel::data(const QModelIndex &p_index, int p_role) const
|
||||||
|
{
|
||||||
if (!p_index.isValid())
|
if (!p_index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
switch (p_role) {
|
switch (p_role)
|
||||||
case Qt::DisplayRole:
|
{
|
||||||
{
|
case Qt::DisplayRole:
|
||||||
return getItem(p_index)->data(p_index.column());
|
{
|
||||||
}
|
return getItem(p_index)->data(p_index.column());
|
||||||
case Qt::BackgroundRole:
|
}
|
||||||
{
|
case Qt::BackgroundRole:
|
||||||
if (getItem(p_index)->valueFrom() == UFormElm::ValueDefaultDfn)
|
{
|
||||||
return QBrush(QColor(255,0,0,30));
|
if (getItem(p_index)->valueFrom() == UFormElm::ValueDefaultDfn)
|
||||||
if (getItem(p_index)->nodeFrom() == UFormElm::NodeParentForm)
|
return QBrush(QColor(255,0,0,30));
|
||||||
return QBrush(QColor(0,255,0,30));
|
if (getItem(p_index)->nodeFrom() == UFormElm::NodeParentForm)
|
||||||
return QVariant();
|
return QBrush(QColor(0,255,0,30));
|
||||||
}
|
|
||||||
case Qt::DecorationRole:
|
|
||||||
{
|
|
||||||
if (p_index.column() == 2) {
|
|
||||||
//p_index.
|
|
||||||
QModelIndex in = index(p_index.row(),p_index.column()-1,p_index.parent());
|
|
||||||
CFormItem *item = getItem(in);
|
|
||||||
|
|
||||||
QString value = item->data(1).toString();
|
|
||||||
//QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str();
|
|
||||||
|
|
||||||
if (value.contains(".shape")) {
|
|
||||||
return QIcon(":/images/pqrticles.png");
|
|
||||||
} else if(value.contains(".tga") || value.contains(".png")) {
|
|
||||||
qDebug() << p_index << p_role;
|
|
||||||
QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str();
|
|
||||||
return QIcon(":/images/pqrticles.png");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
}
|
||||||
|
case Qt::DecorationRole:
|
||||||
|
{
|
||||||
|
if (p_index.column() == 2)
|
||||||
|
{
|
||||||
|
//p_index.
|
||||||
|
QModelIndex in = index(p_index.row(),p_index.column()-1,p_index.parent());
|
||||||
|
CFormItem *item = getItem(in);
|
||||||
|
|
||||||
|
QString value = item->data(1).toString();
|
||||||
|
//QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str();
|
||||||
|
|
||||||
|
if (value.contains(".shape"))
|
||||||
|
{
|
||||||
|
return QIcon(":/images/pqrticles.png");
|
||||||
|
}
|
||||||
|
else if(value.contains(".tga") || value.contains(".png"))
|
||||||
|
{
|
||||||
|
qDebug() << p_index << p_role;
|
||||||
|
QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str();
|
||||||
|
return QIcon(":/images/pqrticles.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
CFormItem *CGeorgesFormModel::getItem(const QModelIndex &index) const {
|
CFormItem *CGeorgesFormModel::getItem(const QModelIndex &index) const
|
||||||
if (index.isValid()) {
|
{
|
||||||
|
if (index.isValid())
|
||||||
|
{
|
||||||
CFormItem *item = static_cast<CFormItem*>(index.internalPointer());
|
CFormItem *item = static_cast<CFormItem*>(index.internalPointer());
|
||||||
if (item) return item;
|
if (item)
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
return _rootItem;
|
return _rootItem;
|
||||||
}
|
}
|
||||||
|
@ -118,18 +128,19 @@ namespace NLQT {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value,
|
bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
int role) {
|
int role)
|
||||||
|
{
|
||||||
|
|
||||||
if (role != Qt::EditRole)
|
if (role != Qt::EditRole)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CFormItem *item = getItem(index);
|
CFormItem *item = getItem(index);
|
||||||
bool result = item->setData(index.column(), value);
|
bool result = item->setData(index.column(), value);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
Q_EMIT dataChanged(index, index);
|
Q_EMIT dataChanged(index, index);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -142,7 +153,7 @@ namespace NLQT {
|
||||||
Qt::ItemFlags returnValue = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
Qt::ItemFlags returnValue = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
|
|
||||||
if(index.column() == 1)
|
if(index.column() == 1)
|
||||||
returnValue |= Qt::ItemIsEditable;
|
returnValue |= Qt::ItemIsEditable;
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
|
|
||||||
|
@ -229,21 +240,25 @@ namespace NLQT {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
void CGeorgesFormModel::loadFormData(UFormElm *root, CFormItem *parent) {
|
void CGeorgesFormModel::loadFormData(UFormElm *root, CFormItem *parent) {
|
||||||
|
|
||||||
if (!root) return;
|
if (!root)
|
||||||
|
return;
|
||||||
|
|
||||||
uint num = 0;
|
uint num = 0;
|
||||||
UFormElm::TWhereIsNode *whereN = new UFormElm::TWhereIsNode;
|
UFormElm::TWhereIsNode *whereN = new UFormElm::TWhereIsNode;
|
||||||
UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue;
|
UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue;
|
||||||
|
|
||||||
if (root->isStruct()) {
|
if (root->isStruct())
|
||||||
|
{
|
||||||
//((CFormElm*)root)->getForm()->getComment();
|
//((CFormElm*)root)->getForm()->getComment();
|
||||||
uint structSize = 0;
|
uint structSize = 0;
|
||||||
root->getStructSize(structSize);
|
root->getStructSize(structSize);
|
||||||
while (num < structSize) {
|
while (num < structSize)
|
||||||
|
{
|
||||||
// Append a new item to the current parent's list of children.
|
// Append a new item to the current parent's list of children.
|
||||||
std::string elmName;
|
std::string elmName;
|
||||||
if(root->getStructNodeName(num, elmName)) {
|
if(root->getStructNodeName(num, elmName))
|
||||||
|
{
|
||||||
QList<QVariant> columnData;
|
QList<QVariant> columnData;
|
||||||
//QVariant value;
|
//QVariant value;
|
||||||
std::string value;
|
std::string value;
|
||||||
|
@ -253,8 +268,10 @@ namespace NLQT {
|
||||||
//double value_double;
|
//double value_double;
|
||||||
QString elmtType = "";
|
QString elmtType = "";
|
||||||
UFormElm *elmt = 0;
|
UFormElm *elmt = 0;
|
||||||
if(root->getNodeByName(&elmt, elmName.c_str(), whereN, true)) {
|
if(root->getNodeByName(&elmt, elmName.c_str(), whereN, true))
|
||||||
if (elmt) {
|
{
|
||||||
|
if (elmt)
|
||||||
|
{
|
||||||
if (elmt->isArray())
|
if (elmt->isArray())
|
||||||
elmtType = "Array";
|
elmtType = "Array";
|
||||||
if (elmt->isStruct())
|
if (elmt->isStruct())
|
||||||
|
@ -263,43 +280,50 @@ namespace NLQT {
|
||||||
elmtType = "Atom";
|
elmtType = "Atom";
|
||||||
uint numDefinitions = 0;
|
uint numDefinitions = 0;
|
||||||
const UType *type = elmt->getType();
|
const UType *type = elmt->getType();
|
||||||
if (type) {
|
if (type)
|
||||||
|
{
|
||||||
numDefinitions = type->getNumDefinition();
|
numDefinitions = type->getNumDefinition();
|
||||||
root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
|
root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
|
||||||
switch (type->getType()) {
|
switch (type->getType())
|
||||||
case UType::UnsignedInt:
|
{
|
||||||
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble()).toStdString();
|
case UType::UnsignedInt:
|
||||||
elmtType.append("_uint");break;
|
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble()).toStdString();
|
||||||
case UType::SignedInt:
|
elmtType.append("_uint");break;
|
||||||
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble()).toStdString();
|
case UType::SignedInt:
|
||||||
elmtType.append("_sint");break;
|
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble()).toStdString();
|
||||||
case UType::Double:
|
elmtType.append("_sint");break;
|
||||||
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble(),0,'f',1).toStdString();
|
case UType::Double:
|
||||||
elmtType.append("_double");break;
|
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble(),0,'f',1).toStdString();
|
||||||
case UType::String:
|
elmtType.append("_double");break;
|
||||||
elmtType.append("_string");break;
|
case UType::String:
|
||||||
case UType::Color:
|
elmtType.append("_string");break;
|
||||||
elmtType.append("_color");break;
|
case UType::Color:
|
||||||
default:
|
elmtType.append("_color");break;
|
||||||
elmtType.append("_unknownType");
|
default:
|
||||||
|
elmtType.append("_unknownType");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numDefinitions) {
|
if (numDefinitions)
|
||||||
|
{
|
||||||
std::string l, v;
|
std::string l, v;
|
||||||
QString tmpLabel, tmpValue;
|
QString tmpLabel, tmpValue;
|
||||||
for (uint i = 0; i < numDefinitions; i++) {
|
for (uint i = 0; i < numDefinitions; i++)
|
||||||
|
{
|
||||||
type->getDefinition(i,l,v);
|
type->getDefinition(i,l,v);
|
||||||
tmpLabel = l.c_str();
|
tmpLabel = l.c_str();
|
||||||
tmpValue = v.c_str();
|
tmpValue = v.c_str();
|
||||||
if (type->getType() == UType::SignedInt) {
|
if (type->getType() == UType::SignedInt)
|
||||||
|
{
|
||||||
if (QString("%1").arg(value.c_str()).toDouble() == tmpValue.toDouble()) {
|
if (QString("%1").arg(value.c_str()).toDouble() == tmpValue.toDouble()) {
|
||||||
value = l;
|
value = l;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type->getType() == UType::String) {
|
if (type->getType() == UType::String)
|
||||||
if (QString(value.c_str()) == tmpValue) {
|
{
|
||||||
|
if (QString(value.c_str()) == tmpValue)
|
||||||
|
{
|
||||||
value = l;
|
value = l;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -307,11 +331,13 @@ namespace NLQT {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (elmt->isVirtualStruct()){
|
if (elmt->isVirtualStruct())
|
||||||
|
{
|
||||||
root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
|
root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
|
||||||
elmtType = "VirtualStruct";
|
elmtType = "VirtualStruct";
|
||||||
}
|
}
|
||||||
switch (*whereN) {
|
switch (*whereN)
|
||||||
|
{
|
||||||
case UFormElm::NodeForm:
|
case UFormElm::NodeForm:
|
||||||
elmtType.append("_fromForm"); break;
|
elmtType.append("_fromForm"); break;
|
||||||
case UFormElm::NodeParentForm:
|
case UFormElm::NodeParentForm:
|
||||||
|
@ -323,7 +349,8 @@ namespace NLQT {
|
||||||
default:
|
default:
|
||||||
elmtType.append("_noNode");
|
elmtType.append("_noNode");
|
||||||
}
|
}
|
||||||
switch (*whereV) {
|
switch (*whereV)
|
||||||
|
{
|
||||||
case UFormElm::ValueForm:
|
case UFormElm::ValueForm:
|
||||||
elmtType.append("_formValue"); break;
|
elmtType.append("_formValue"); break;
|
||||||
case UFormElm::ValueParentForm:
|
case UFormElm::ValueParentForm:
|
||||||
|
@ -341,36 +368,43 @@ namespace NLQT {
|
||||||
// parents << parents.last()->child(parents.last()->childCount()-1);
|
// parents << parents.last()->child(parents.last()->childCount()-1);
|
||||||
//}
|
//}
|
||||||
loadFormData(elmt, parent->child(parent->childCount()-1));
|
loadFormData(elmt, parent->child(parent->childCount()-1));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// add Defaults
|
// add Defaults
|
||||||
//columnData << QString(elmName.c_str()) << QString("default") << QString("default");
|
//columnData << QString(elmName.c_str()) << QString("default") << QString("default");
|
||||||
//parent->appendChild(new CFormItem(elmt, columnData, parent, UFormElm::ValueDefaultDfn, UFormElm::NodeDfn));
|
//parent->appendChild(new CFormItem(elmt, columnData, parent, UFormElm::ValueDefaultDfn, UFormElm::NodeDfn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (root->isArray()) {
|
if (root->isArray())
|
||||||
|
{
|
||||||
uint arraySize = 0;
|
uint arraySize = 0;
|
||||||
root->getArraySize(arraySize);
|
root->getArraySize(arraySize);
|
||||||
while (num < arraySize) {
|
while (num < arraySize)
|
||||||
|
{
|
||||||
std::string elmName;
|
std::string elmName;
|
||||||
if(root->getArrayNodeName(elmName, num)) {
|
if(root->getArrayNodeName(elmName, num))
|
||||||
|
{
|
||||||
QList<QVariant> columnData;
|
QList<QVariant> columnData;
|
||||||
std::string value;
|
std::string value;
|
||||||
QString elmtType = "";
|
QString elmtType = "";
|
||||||
//root->getValueByName(value, elmName.c_str());
|
//root->getValueByName(value, elmName.c_str());
|
||||||
|
|
||||||
UFormElm *elmt = 0;
|
UFormElm *elmt = 0;
|
||||||
if(root->getArrayNode(&elmt,0) && elmt) {
|
if(root->getArrayNode(&elmt,0) && elmt)
|
||||||
|
{
|
||||||
if (elmt->isArray())
|
if (elmt->isArray())
|
||||||
elmtType = "Array";
|
elmtType = "Array";
|
||||||
if (elmt->isStruct()) {
|
if (elmt->isStruct()) {
|
||||||
elmtType = "Struct";
|
elmtType = "Struct";
|
||||||
}
|
}
|
||||||
if (elmt->isAtom()) {
|
if (elmt->isAtom())
|
||||||
|
{
|
||||||
elmt->getValue(value);
|
elmt->getValue(value);
|
||||||
elmtType = "Atom";
|
elmtType = "Atom";
|
||||||
}
|
}
|
||||||
|
@ -388,14 +422,16 @@ namespace NLQT {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
void CGeorgesFormModel::loadFormHeader() {
|
void CGeorgesFormModel::loadFormHeader()
|
||||||
|
{
|
||||||
|
|
||||||
CFormItem *fi_pars = new CFormItem(_rootElm, QList<QVariant>() << "parents", _rootItem);
|
CFormItem *fi_pars = new CFormItem(_rootElm, QList<QVariant>() << "parents", _rootItem);
|
||||||
_rootItem->appendChild(fi_pars);
|
_rootItem->appendChild(fi_pars);
|
||||||
|
|
||||||
Q_FOREACH(QString str, _parents) {
|
Q_FOREACH(QString str, _parents)
|
||||||
fi_pars->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_pars));
|
{
|
||||||
}
|
fi_pars->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_pars));
|
||||||
|
}
|
||||||
|
|
||||||
/*QStringList dfns = _dependencies["dfn"];
|
/*QStringList dfns = _dependencies["dfn"];
|
||||||
QStringList typs = _dependencies["typ"];
|
QStringList typs = _dependencies["typ"];
|
||||||
|
@ -407,33 +443,34 @@ namespace NLQT {
|
||||||
_rootItem->appendChild(fi_dep);
|
_rootItem->appendChild(fi_dep);
|
||||||
|
|
||||||
if (!dfns.isEmpty()) {
|
if (!dfns.isEmpty()) {
|
||||||
CFormItem *fi_dfn = new CFormItem(_rootElm, QList<QVariant>() << "dfn", fi_dep);
|
CFormItem *fi_dfn = new CFormItem(_rootElm, QList<QVariant>() << "dfn", fi_dep);
|
||||||
fi_dep->appendChild(fi_dfn);
|
fi_dep->appendChild(fi_dfn);
|
||||||
foreach(QString str, dfns) {
|
foreach(QString str, dfns) {
|
||||||
fi_dfn->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_dfn));
|
fi_dfn->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_dfn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!typs.isEmpty()) {
|
if (!typs.isEmpty()) {
|
||||||
CFormItem *fi_typ = new CFormItem(_rootElm, QList<QVariant>() << "typ", fi_dep);
|
CFormItem *fi_typ = new CFormItem(_rootElm, QList<QVariant>() << "typ", fi_dep);
|
||||||
fi_dep->appendChild(fi_typ);
|
fi_dep->appendChild(fi_typ);
|
||||||
foreach(QString str, typs) {
|
foreach(QString str, typs) {
|
||||||
fi_typ->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_typ));
|
fi_typ->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_typ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!_dependencies.isEmpty()) {
|
if (!_dependencies.isEmpty()) {
|
||||||
CFormItem *fi_other = new CFormItem(_rootElm, QList<QVariant>() << "other", fi_dep);
|
CFormItem *fi_other = new CFormItem(_rootElm, QList<QVariant>() << "other", fi_dep);
|
||||||
fi_dep->appendChild(fi_other);
|
fi_dep->appendChild(fi_other);
|
||||||
foreach(QStringList list, _dependencies) {
|
foreach(QStringList list, _dependencies) {
|
||||||
foreach(QString str, list) {
|
foreach(QString str, list) {
|
||||||
fi_other->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_other));
|
fi_other->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_other));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
void CGeorgesFormModel::setupModelData() {
|
void CGeorgesFormModel::setupModelData()
|
||||||
|
{
|
||||||
loadFormHeader();
|
loadFormHeader();
|
||||||
loadFormData(_rootElm, _rootItem);
|
loadFormData(_rootElm, _rootItem);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,13 @@ namespace NLGEORGES {
|
||||||
class UFormElm;
|
class UFormElm;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
class CFormItem;
|
class CFormItem;
|
||||||
|
|
||||||
class CGeorgesFormModel : public QAbstractItemModel {
|
class CGeorgesFormModel : public QAbstractItemModel
|
||||||
Q_OBJECT
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CGeorgesFormModel(NLGEORGES::UFormElm *root, QMap< QString, QStringList> deps,
|
CGeorgesFormModel(NLGEORGES::UFormElm *root, QMap< QString, QStringList> deps,
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
// NeL includes
|
// NeL includes
|
||||||
#include <nel/misc/debug.h>
|
#include <nel/misc/debug.h>
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
bool CGeorgesFormProxyModel::filterAcceptsRow(int sourceRow,
|
bool CGeorgesFormProxyModel::filterAcceptsRow(int sourceRow,
|
||||||
const QModelIndex &sourceParent) const
|
const QModelIndex &sourceParent) const
|
||||||
|
|
|
@ -23,13 +23,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
|
class CGeorgesFormProxyModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
|
||||||
class CGeorgesFormProxyModel : public QSortFilterProxyModel {
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CGeorgesFormProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent){}
|
CGeorgesFormProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent)
|
||||||
~CGeorgesFormProxyModel() {}
|
{
|
||||||
|
}
|
||||||
|
~CGeorgesFormProxyModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool filterAcceptsColumn ( int source_column, const QModelIndex & source_parent ) const ;
|
virtual bool filterAcceptsColumn ( int source_column, const QModelIndex & source_parent ) const ;
|
||||||
|
|
|
@ -30,10 +30,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
// Project includes
|
// Project includes
|
||||||
#include "qt_displayer.h"
|
#include "qt_displayer.h"
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
CGeorgesLogDialog::CGeorgesLogDialog(QWidget *parent):
|
CGeorgesLogDialog::CGeorgesLogDialog(QWidget *parent):
|
||||||
QDockWidget(parent){
|
QDockWidget(parent)
|
||||||
|
{
|
||||||
|
|
||||||
_ui.setupUi(this);
|
_ui.setupUi(this);
|
||||||
|
|
||||||
|
@ -46,7 +48,8 @@ namespace NLQT {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CGeorgesLogDialog::~CGeorgesLogDialog() {
|
CGeorgesLogDialog::~CGeorgesLogDialog()
|
||||||
|
{
|
||||||
NLMISC::ErrorLog->removeDisplayer(_displayer);
|
NLMISC::ErrorLog->removeDisplayer(_displayer);
|
||||||
NLMISC::WarningLog->removeDisplayer(_displayer);
|
NLMISC::WarningLog->removeDisplayer(_displayer);
|
||||||
NLMISC::DebugLog->removeDisplayer(_displayer);
|
NLMISC::DebugLog->removeDisplayer(_displayer);
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LOG_DIALOG_H
|
#ifndef LOG_DIALOG_H
|
||||||
|
@ -30,24 +30,24 @@
|
||||||
// Project includes
|
// Project includes
|
||||||
#include "ui_log_form.h"
|
#include "ui_log_form.h"
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
class CQtDisplayer;
|
|
||||||
|
|
||||||
class CGeorgesLogDialog: public QDockWidget
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
class CQtDisplayer;
|
||||||
|
|
||||||
public:
|
class CGeorgesLogDialog: public QDockWidget
|
||||||
CGeorgesLogDialog(QWidget *parent = 0);
|
{
|
||||||
~CGeorgesLogDialog();
|
|
||||||
|
|
||||||
private:
|
public:
|
||||||
Ui::CGeorgesLogDialog _ui;
|
CGeorgesLogDialog(QWidget *parent = 0);
|
||||||
|
~CGeorgesLogDialog();
|
||||||
|
|
||||||
CQtDisplayer *_displayer;
|
private:
|
||||||
|
Ui::CGeorgesLogDialog _ui;
|
||||||
|
|
||||||
friend class CMainWindow;
|
CQtDisplayer *_displayer;
|
||||||
}; /* CGeorgesLogDialog */
|
|
||||||
|
friend class CMainWindow;
|
||||||
|
}; /* CGeorgesLogDialog */
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
|
|
@ -33,33 +33,37 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
namespace {
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
CFileDisplayer *s_FileDisplayer = NULL;
|
CFileDisplayer *s_FileDisplayer = NULL;
|
||||||
|
|
||||||
} /* anonymous namespace */
|
} /* anonymous namespace */
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
||||||
void messageHandler(QtMsgType p_type, const char* p_msg) {
|
void messageHandler(QtMsgType p_type, const char* p_msg)
|
||||||
|
{
|
||||||
|
|
||||||
fprintf(stderr, "%s\n", p_msg);
|
fprintf(stderr, "%s\n", p_msg);
|
||||||
|
|
||||||
QFile file("qt.log");
|
QFile file("qt.log");
|
||||||
file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
|
file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
|
||||||
|
|
||||||
QChar code;
|
QChar code;
|
||||||
switch (p_type) {
|
switch (p_type)
|
||||||
case QtDebugMsg: code = 'D'; break;
|
{
|
||||||
case QtWarningMsg: code = 'W'; break;
|
case QtDebugMsg: code = 'D'; break;
|
||||||
case QtCriticalMsg: code = 'C'; break;
|
case QtWarningMsg: code = 'W'; break;
|
||||||
case QtFatalMsg: code = 'F'; break;
|
case QtCriticalMsg: code = 'C'; break;
|
||||||
}
|
case QtFatalMsg: code = 'F'; break;
|
||||||
QString dt = QDateTime::currentDateTime().toString("yyyyMMdd hh:mm:ss");
|
}
|
||||||
|
QString dt = QDateTime::currentDateTime().toString("yyyyMMdd hh:mm:ss");
|
||||||
|
|
||||||
QTextStream(&file) << QString("%1 [%2] %3\n").arg(dt).arg(code).arg(QString(p_msg));
|
QTextStream(&file) << QString("%1 [%2] %3\n").arg(dt).arg(code).arg(QString(p_msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DATA_DIR
|
#ifndef DATA_DIR
|
||||||
|
@ -77,12 +81,12 @@ void messageHandler(QtMsgType p_type, const char* p_msg) {
|
||||||
|
|
||||||
sint main(int argc, char **argv)
|
sint main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// go nel!
|
// go nel!
|
||||||
{
|
{
|
||||||
// use log.log if NEL_LOG_IN_FILE and NLQT_USE_LOG_LOG defined as 1
|
// use log.log if NEL_LOG_IN_FILE and NLQT_USE_LOG_LOG defined as 1
|
||||||
createDebug(NULL, NLQT_USE_LOG_LOG, false);
|
createDebug(NULL, NLQT_USE_LOG_LOG, false);
|
||||||
if (QFile::exists("qt.log"))
|
if (QFile::exists("qt.log"))
|
||||||
QFile::remove("qt.log");
|
QFile::remove("qt.log");
|
||||||
|
|
||||||
qInstallMsgHandler(messageHandler);
|
qInstallMsgHandler(messageHandler);
|
||||||
#if NLQT_USE_LOG
|
#if NLQT_USE_LOG
|
||||||
|
@ -101,12 +105,12 @@ sint main(int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nlinfo("Welcome to NeL!");
|
nlinfo("Welcome to NeL!");
|
||||||
|
|
||||||
NLMISC::CPath::remapExtension("tga", "png", true);
|
NLMISC::CPath::remapExtension("tga", "png", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
Modules::init();
|
Modules::init();
|
||||||
//Modules::mainWin().resize(800,600);
|
//Modules::mainWin().resize(800,600);
|
||||||
Modules::mainWin().show();
|
Modules::mainWin().show();
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main_window.h"
|
#include "main_window.h"
|
||||||
|
@ -36,453 +36,473 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
|
||||||
|
|
||||||
CMainWindow::CMainWindow(QWidget *parent)
|
|
||||||
: QMainWindow(parent),
|
|
||||||
_GeorgesLogDialog(0), _ObjectViewerDialog(0),
|
|
||||||
_GeorgesDirTreeDialog(0)
|
|
||||||
{
|
{
|
||||||
setWindowTitle("Qt Georges Editor");
|
|
||||||
|
|
||||||
setDockNestingEnabled(true);
|
CMainWindow::CMainWindow(QWidget *parent)
|
||||||
setCentralWidget(0);
|
: QMainWindow(parent), _GeorgesLogDialog(0), _ObjectViewerDialog(0),
|
||||||
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
|
_GeorgesDirTreeDialog(0)
|
||||||
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
|
{
|
||||||
|
setWindowTitle("Qt Georges Editor");
|
||||||
|
|
||||||
// create log dock widget
|
setDockNestingEnabled(true);
|
||||||
_GeorgesLogDialog = new CGeorgesLogDialog(this);
|
setCentralWidget(0);
|
||||||
addDockWidget(Qt::RightDockWidgetArea, _GeorgesLogDialog);
|
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
|
||||||
|
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
|
||||||
|
|
||||||
// empty form view as placeholder
|
// create log dock widget
|
||||||
createEmptyView();
|
_GeorgesLogDialog = new CGeorgesLogDialog(this);
|
||||||
_currentView = 0;
|
addDockWidget(Qt::RightDockWidgetArea, _GeorgesLogDialog);
|
||||||
|
|
||||||
// load and set leveldesign path from config
|
// empty form view as placeholder
|
||||||
QString ldPath = Modules::config().configLeveldesignPath().c_str();
|
createEmptyView();
|
||||||
QFileInfo info(ldPath);
|
_currentView = 0;
|
||||||
if (!info.isDir()) ldPath = "";
|
|
||||||
|
|
||||||
// create georges dir dock widget
|
// load and set leveldesign path from config
|
||||||
_GeorgesDirTreeDialog = new CGeorgesDirTreeDialog(ldPath, this);
|
QString ldPath = Modules::config().configLeveldesignPath().c_str();
|
||||||
addDockWidget(Qt::LeftDockWidgetArea, _GeorgesDirTreeDialog);
|
QFileInfo info(ldPath);
|
||||||
if (ldPath == "") {
|
if (!info.isDir())
|
||||||
if (QMessageBox::information(this, tr("Missing leveldesign path"),
|
ldPath = "";
|
||||||
tr("Your leveldesign path seems to be empty or incorrect.\nDo you want to set it now?"),
|
|
||||||
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
|
|
||||||
settings();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// create NeL viewport dock widget
|
// create georges dir dock widget
|
||||||
_ObjectViewerDialog = new CObjectViewerDialog(this);
|
_GeorgesDirTreeDialog = new CGeorgesDirTreeDialog(ldPath, this);
|
||||||
//_ObjectViewerDialog->setAllowedAreas(Qt::LeftDockWidgetArea );
|
addDockWidget(Qt::LeftDockWidgetArea, _GeorgesDirTreeDialog);
|
||||||
//_ObjectViewerDialog->hide();
|
if (ldPath == "")
|
||||||
addDockWidget(Qt::LeftDockWidgetArea, _ObjectViewerDialog);
|
{
|
||||||
|
if (QMessageBox::information(this, tr("Missing leveldesign path"),
|
||||||
createActions();
|
tr("Your leveldesign path seems to be empty or incorrect.\nDo you want to set it now?"),
|
||||||
createMenus();
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok)
|
||||||
createToolBars();
|
{
|
||||||
createStatusBar();
|
settings();
|
||||||
|
|
||||||
//_ObjectViewerDialog->toggleViewAction()->trigger();
|
|
||||||
QSettings settings("georges_editor_qt.ini", QSettings::IniFormat);
|
|
||||||
settings.beginGroup("WindowSettings");
|
|
||||||
restoreState(settings.value("QtWindowState").toByteArray());
|
|
||||||
restoreGeometry(settings.value("QtWindowGeometry").toByteArray());
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
// setup Qt style and palette from config file
|
|
||||||
//_originalPalette = QApplication::palette();
|
|
||||||
//Modules::config().setAndCallback("QtStyle", CConfigCallback(this, &CMainWindow::cfcbQtStyle));
|
|
||||||
//Modules::config().setAndCallback("QtPalette", CConfigCallback(this, &CMainWindow::cfcbQtPalette));
|
|
||||||
|
|
||||||
setWindowIcon(QIcon(":/images/khead.png"));
|
|
||||||
|
|
||||||
_statusBarTimer = new QTimer(this);
|
|
||||||
connect(_statusBarTimer, SIGNAL(timeout()), this, SLOT(updateStatusBar()));
|
|
||||||
_statusBarTimer->start(5000);
|
|
||||||
|
|
||||||
connect(_GeorgesDirTreeDialog, SIGNAL(selectedForm(QString)),
|
|
||||||
this, SLOT(openTreeView(QString)));
|
|
||||||
}
|
|
||||||
|
|
||||||
CMainWindow::~CMainWindow()
|
|
||||||
{
|
|
||||||
// save state & geometry of window and widgets
|
|
||||||
QSettings settings("georges_editor_qt.ini", QSettings::IniFormat);
|
|
||||||
settings.beginGroup("WindowSettings");
|
|
||||||
settings.setValue("QtWindowState", saveState());
|
|
||||||
settings.setValue("QtWindowGeometry", saveGeometry());
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
//Modules::config().dropCallback("QtPalette");
|
|
||||||
//Modules::config().dropCallback("QtStyle");
|
|
||||||
|
|
||||||
_statusBarTimer->stop();
|
|
||||||
|
|
||||||
delete _ObjectViewerDialog;
|
|
||||||
delete _GeorgesDirTreeDialog;
|
|
||||||
delete _GeorgesLogDialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::openTreeView(QString file) {
|
|
||||||
// create or/and raise tree view dock widget for current file
|
|
||||||
|
|
||||||
setCurrentFile(file);
|
|
||||||
|
|
||||||
CGeorgesTreeViewDialog *newView = 0;
|
|
||||||
|
|
||||||
Q_FOREACH(CGeorgesTreeViewDialog* dlg, _treeViewList) {
|
|
||||||
if (dlg->loadedForm == file)
|
|
||||||
newView = dlg;
|
|
||||||
}
|
|
||||||
if (!newView) {
|
|
||||||
newView = new CGeorgesTreeViewDialog(this);
|
|
||||||
//newView->setAllowedAreas(Qt::TopDockWidgetArea | Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
|
||||||
newView->setWindowTitle(file);
|
|
||||||
|
|
||||||
if (_treeViewList.isEmpty()) {
|
|
||||||
_emptyView->deleteLater();
|
|
||||||
addDockWidget(Qt::TopDockWidgetArea, newView);
|
|
||||||
} else {
|
|
||||||
tabifyDockWidget(_treeViewList.first(),newView);
|
|
||||||
QTabBar* tb = Modules::mainWin().getTabBar();
|
|
||||||
if (tb) {
|
|
||||||
disconnect(tb, SIGNAL(currentChanged ( int ) ),
|
|
||||||
this,SLOT(tabChanged(int)));
|
|
||||||
connect(tb, SIGNAL(currentChanged ( int ) ),
|
|
||||||
this,SLOT(tabChanged(int)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_treeViewList.append(newView);
|
|
||||||
newView->selectedForm(file);
|
|
||||||
_currentView = newView;
|
|
||||||
|
|
||||||
connect(newView, SIGNAL(changeFile(QString)),
|
// create NeL viewport dock widget
|
||||||
_GeorgesDirTreeDialog, SLOT(changeFile(QString)));
|
_ObjectViewerDialog = new CObjectViewerDialog(this);
|
||||||
connect(newView, SIGNAL(modified(bool)),
|
//_ObjectViewerDialog->setAllowedAreas(Qt::LeftDockWidgetArea );
|
||||||
_saveAction, SLOT(setEnabled(bool)));
|
//_ObjectViewerDialog->hide();
|
||||||
|
addDockWidget(Qt::LeftDockWidgetArea, _ObjectViewerDialog);
|
||||||
|
|
||||||
|
createActions();
|
||||||
|
createMenus();
|
||||||
|
createToolBars();
|
||||||
|
createStatusBar();
|
||||||
|
|
||||||
|
//_ObjectViewerDialog->toggleViewAction()->trigger();
|
||||||
|
QSettings settings("georges_editor_qt.ini", QSettings::IniFormat);
|
||||||
|
settings.beginGroup("WindowSettings");
|
||||||
|
restoreState(settings.value("QtWindowState").toByteArray());
|
||||||
|
restoreGeometry(settings.value("QtWindowGeometry").toByteArray());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
// setup Qt style and palette from config file
|
||||||
|
//_originalPalette = QApplication::palette();
|
||||||
|
//Modules::config().setAndCallback("QtStyle", CConfigCallback(this, &CMainWindow::cfcbQtStyle));
|
||||||
|
//Modules::config().setAndCallback("QtPalette", CConfigCallback(this, &CMainWindow::cfcbQtPalette));
|
||||||
|
|
||||||
|
setWindowIcon(QIcon(":/images/khead.png"));
|
||||||
|
|
||||||
|
_statusBarTimer = new QTimer(this);
|
||||||
|
connect(_statusBarTimer, SIGNAL(timeout()), this, SLOT(updateStatusBar()));
|
||||||
|
_statusBarTimer->start(5000);
|
||||||
|
|
||||||
|
connect(_GeorgesDirTreeDialog, SIGNAL(selectedForm(QString)),
|
||||||
|
this, SLOT(openTreeView(QString)));
|
||||||
}
|
}
|
||||||
newView->raise();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::settings()
|
CMainWindow::~CMainWindow()
|
||||||
{
|
|
||||||
CSettingsDialog _settingsDialog(this);
|
|
||||||
|
|
||||||
connect(&_settingsDialog,SIGNAL(ldPathChanged(QString)),
|
|
||||||
_GeorgesDirTreeDialog,SLOT(ldPathChanged(QString)));
|
|
||||||
|
|
||||||
//_settingsDialog.show();
|
|
||||||
_settingsDialog.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::about()
|
|
||||||
{
|
|
||||||
QMessageBox::about(this, tr("About Georges Viewer Qt"),
|
|
||||||
tr("<h2>Georges Viewer Qt</h2>"
|
|
||||||
"Author: aquiles<br>Credits:Thx to dnk-88 for parts of his code"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::updateStatusBar()
|
|
||||||
{
|
|
||||||
//if (_isGraphicsInitialized)
|
|
||||||
// statusBar()->showMessage(QString(Modules::objView().getDriver()->getVideocardInformation()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::open()
|
|
||||||
{
|
|
||||||
/*QStringList fileNames = QFileDialog::getOpenFileNames(this,
|
|
||||||
tr("Open NeL data file"), _lastDir,
|
|
||||||
tr("All NeL files (*.shape *.ps);;"
|
|
||||||
"NeL shape files (*.shape);;"
|
|
||||||
"NeL particle system files (*.ps)"));
|
|
||||||
|
|
||||||
setCursor(Qt::WaitCursor);
|
|
||||||
if (!fileNames.isEmpty())
|
|
||||||
{
|
{
|
||||||
|
// save state & geometry of window and widgets
|
||||||
|
QSettings settings("georges_editor_qt.ini", QSettings::IniFormat);
|
||||||
|
settings.beginGroup("WindowSettings");
|
||||||
|
settings.setValue("QtWindowState", saveState());
|
||||||
|
settings.setValue("QtWindowGeometry", saveGeometry());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
//Modules::config().dropCallback("QtPalette");
|
||||||
|
//Modules::config().dropCallback("QtStyle");
|
||||||
|
|
||||||
|
_statusBarTimer->stop();
|
||||||
|
|
||||||
|
delete _ObjectViewerDialog;
|
||||||
|
delete _GeorgesDirTreeDialog;
|
||||||
|
delete _GeorgesLogDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::openTreeView(QString file)
|
||||||
|
{
|
||||||
|
// create or/and raise tree view dock widget for current file
|
||||||
|
|
||||||
|
setCurrentFile(file);
|
||||||
|
|
||||||
|
CGeorgesTreeViewDialog *newView = 0;
|
||||||
|
|
||||||
|
Q_FOREACH(CGeorgesTreeViewDialog* dlg, _treeViewList)
|
||||||
|
{
|
||||||
|
if (dlg->loadedForm == file)
|
||||||
|
newView = dlg;
|
||||||
|
}
|
||||||
|
if (!newView)
|
||||||
|
{
|
||||||
|
newView = new CGeorgesTreeViewDialog(this);
|
||||||
|
//newView->setAllowedAreas(Qt::TopDockWidgetArea | Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||||
|
newView->setWindowTitle(file);
|
||||||
|
|
||||||
|
if (_treeViewList.isEmpty())
|
||||||
|
{
|
||||||
|
_emptyView->deleteLater();
|
||||||
|
addDockWidget(Qt::TopDockWidgetArea, newView);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tabifyDockWidget(_treeViewList.first(),newView);
|
||||||
|
QTabBar* tb = Modules::mainWin().getTabBar();
|
||||||
|
if (tb)
|
||||||
|
{
|
||||||
|
disconnect(tb, SIGNAL(currentChanged ( int ) ),
|
||||||
|
this,SLOT(tabChanged(int)));
|
||||||
|
connect(tb, SIGNAL(currentChanged ( int ) ),
|
||||||
|
this,SLOT(tabChanged(int)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_treeViewList.append(newView);
|
||||||
|
newView->selectedForm(file);
|
||||||
|
_currentView = newView;
|
||||||
|
|
||||||
|
connect(newView, SIGNAL(changeFile(QString)),
|
||||||
|
_GeorgesDirTreeDialog, SLOT(changeFile(QString)));
|
||||||
|
connect(newView, SIGNAL(modified(bool)),
|
||||||
|
_saveAction, SLOT(setEnabled(bool)));
|
||||||
|
}
|
||||||
|
newView->raise();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::settings()
|
||||||
|
{
|
||||||
|
CSettingsDialog _settingsDialog(this);
|
||||||
|
|
||||||
|
connect(&_settingsDialog,SIGNAL(ldPathChanged(QString)),
|
||||||
|
_GeorgesDirTreeDialog,SLOT(ldPathChanged(QString)));
|
||||||
|
|
||||||
|
//_settingsDialog.show();
|
||||||
|
_settingsDialog.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::about()
|
||||||
|
{
|
||||||
|
QMessageBox::about(this, tr("About Georges Viewer Qt"),
|
||||||
|
tr("<h2>Georges Viewer Qt</h2>"
|
||||||
|
"Author: aquiles<br>Credits:Thx to dnk-88 for parts of his code"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::updateStatusBar()
|
||||||
|
{
|
||||||
|
//if (_isGraphicsInitialized)
|
||||||
|
// statusBar()->showMessage(QString(Modules::objView().getDriver()->getVideocardInformation()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::open()
|
||||||
|
{
|
||||||
|
/*QStringList fileNames = QFileDialog::getOpenFileNames(this,
|
||||||
|
tr("Open NeL data file"), _lastDir,
|
||||||
|
tr("All NeL files (*.shape *.ps);;"
|
||||||
|
"NeL shape files (*.shape);;"
|
||||||
|
"NeL particle system files (*.ps)"));
|
||||||
|
|
||||||
|
setCursor(Qt::WaitCursor);
|
||||||
|
if (!fileNames.isEmpty())
|
||||||
|
{
|
||||||
QStringList list = fileNames;
|
QStringList list = fileNames;
|
||||||
QStringList::Iterator it = list.begin();
|
QStringList::Iterator it = list.begin();
|
||||||
_lastDir = QFileInfo(*it).absolutePath();
|
_lastDir = QFileInfo(*it).absolutePath();
|
||||||
|
|
||||||
QString skelFileName = QFileDialog::getOpenFileName(this,
|
QString skelFileName = QFileDialog::getOpenFileName(this,
|
||||||
tr("Open skeleton file"), _lastDir,
|
tr("Open skeleton file"), _lastDir,
|
||||||
tr("NeL skeleton file (*.skel)"));
|
tr("NeL skeleton file (*.skel)"));
|
||||||
|
|
||||||
while(it != list.end())
|
while(it != list.end())
|
||||||
{
|
{
|
||||||
loadFile(*it, skelFileName);
|
loadFile(*it, skelFileName);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
_AnimationSetDialog->updateListObject();
|
_AnimationSetDialog->updateListObject();
|
||||||
_AnimationSetDialog->updateListAnim();
|
_AnimationSetDialog->updateListAnim();
|
||||||
_SlotManagerDialog->updateUiSlots();
|
_SlotManagerDialog->updateUiSlots();
|
||||||
}
|
|
||||||
setCursor(Qt::ArrowCursor);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::save()
|
|
||||||
{
|
|
||||||
if(!_currentView)
|
|
||||||
return;
|
|
||||||
|
|
||||||
setCursor(Qt::WaitCursor);
|
|
||||||
|
|
||||||
_currentView->write();
|
|
||||||
setWindowTitle(windowTitle().remove("*"));
|
|
||||||
_saveAction->setEnabled(false);
|
|
||||||
|
|
||||||
setCursor(Qt::ArrowCursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::create()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::createEmptyView()
|
|
||||||
{
|
|
||||||
_emptyView = new CGeorgesTreeViewDialog(this, true);
|
|
||||||
//_emptyView->setAllowedAreas(Qt::TopDockWidgetArea);
|
|
||||||
addDockWidget(Qt::TopDockWidgetArea,_emptyView);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::createActions()
|
|
||||||
{
|
|
||||||
_openAction = new QAction(tr("&Open..."), this);
|
|
||||||
_openAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogOpenButton));
|
|
||||||
_openAction->setShortcut(QKeySequence::Open);
|
|
||||||
_openAction->setStatusTip(tr("Open an existing file"));
|
|
||||||
connect(_openAction, SIGNAL(triggered()), this, SLOT(open()));
|
|
||||||
|
|
||||||
_createAction = new QAction(tr("&New..."), this);
|
|
||||||
_createAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileDialogNewFolder));
|
|
||||||
_createAction->setShortcut(QKeySequence::New);
|
|
||||||
_createAction->setStatusTip(tr("Create a new file"));
|
|
||||||
connect(_createAction, SIGNAL(triggered()), this, SLOT(create()));
|
|
||||||
|
|
||||||
_saveAction = new QAction(tr("&Save..."), this);
|
|
||||||
_saveAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogSaveButton));
|
|
||||||
_saveAction->setShortcut(QKeySequence::Save);
|
|
||||||
_saveAction->setStatusTip(tr("Saves the current file"));
|
|
||||||
_saveAction->setDisabled(true);
|
|
||||||
connect(_saveAction, SIGNAL(triggered()), this, SLOT(save()));
|
|
||||||
|
|
||||||
_exitAction = new QAction(tr("E&xit"), this);
|
|
||||||
_exitAction->setShortcut(QKeySequence::Close);
|
|
||||||
_exitAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogCloseButton));
|
|
||||||
_exitAction->setStatusTip(tr("Exit the application"));
|
|
||||||
connect(_exitAction, SIGNAL(triggered()), this, SLOT(close()));
|
|
||||||
|
|
||||||
_setBackColorAction = _ObjectViewerDialog->createSetBackgroundColor(this);
|
|
||||||
_setBackColorAction->setText(tr("Set &background color"));
|
|
||||||
_setBackColorAction->setStatusTip(tr("Set background color"));
|
|
||||||
|
|
||||||
_settingsAction = new QAction(tr("&Settings"), this);
|
|
||||||
_settingsAction->setIcon(QIcon(":/images/preferences.png"));
|
|
||||||
_settingsAction->setStatusTip(tr("Settings"));
|
|
||||||
connect(_settingsAction, SIGNAL(triggered()), this, SLOT(settings()));
|
|
||||||
|
|
||||||
_aboutAction = new QAction(tr("&About"), this);
|
|
||||||
_aboutAction->setStatusTip(tr("Show the application's About box"));
|
|
||||||
connect(_aboutAction, SIGNAL(triggered()), this, SLOT(about()));
|
|
||||||
|
|
||||||
_aboutQtAction = new QAction(tr("About &Qt"), this);
|
|
||||||
_aboutQtAction->setStatusTip(tr("Show the Qt library's About box"));
|
|
||||||
connect(_aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
|
||||||
|
|
||||||
for (int i = 0; i < MaxRecentFiles; ++i) {
|
|
||||||
recentFileActs[i] = new QAction(this);
|
|
||||||
recentFileActs[i]->setVisible(false);
|
|
||||||
connect(recentFileActs[i], SIGNAL(triggered()),
|
|
||||||
this, SLOT(openRecentFile()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::createMenus()
|
|
||||||
{
|
|
||||||
_fileMenu = menuBar()->addMenu(tr("&File"));
|
|
||||||
_fileMenu->addAction(_createAction);
|
|
||||||
_fileMenu->addAction(_openAction);
|
|
||||||
_fileMenu->addAction(_saveAction);
|
|
||||||
_separatorAction = _fileMenu->addSeparator();
|
|
||||||
for (int i = 0; i < MaxRecentFiles; ++i)
|
|
||||||
_fileMenu->addAction(recentFileActs[i]);
|
|
||||||
_fileMenu->addSeparator();
|
|
||||||
_fileMenu->addAction(_exitAction);
|
|
||||||
updateRecentFileActions();
|
|
||||||
|
|
||||||
_viewMenu = menuBar()->addMenu(tr("&View"));
|
|
||||||
_viewMenu->addAction(_setBackColorAction);
|
|
||||||
if (_GeorgesDirTreeDialog)
|
|
||||||
_viewMenu->addAction(_GeorgesDirTreeDialog->toggleViewAction());
|
|
||||||
|
|
||||||
_toolsMenu = menuBar()->addMenu(tr("&Tools"));
|
|
||||||
if (_ObjectViewerDialog) {
|
|
||||||
_toolsMenu->addAction(_ObjectViewerDialog->toggleViewAction());
|
|
||||||
_ObjectViewerDialog->toggleViewAction()->setIcon(QIcon(":/images/pqrticles.png"));
|
|
||||||
}
|
|
||||||
_toolsMenu->addSeparator();
|
|
||||||
_toolsMenu->addAction(_settingsAction);
|
|
||||||
|
|
||||||
menuBar()->addSeparator();
|
|
||||||
|
|
||||||
_helpMenu = menuBar()->addMenu(tr("&Help"));
|
|
||||||
_helpMenu->addAction(_aboutAction);
|
|
||||||
_helpMenu->addAction(_aboutQtAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::createToolBars()
|
|
||||||
{
|
|
||||||
_fileToolBar = addToolBar(tr("&File"));
|
|
||||||
_fileToolBar->addAction(_createAction);
|
|
||||||
_fileToolBar->addAction(_openAction);
|
|
||||||
_fileToolBar->addAction(_saveAction);
|
|
||||||
|
|
||||||
_toolsBar = addToolBar(tr("&Tools"));
|
|
||||||
if (_ObjectViewerDialog)
|
|
||||||
_toolsBar->addAction(_ObjectViewerDialog->toggleViewAction());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::createStatusBar()
|
|
||||||
{
|
|
||||||
statusBar()->showMessage(tr("StatusReady"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::cfcbQtStyle(NLMISC::CConfigFile::CVar &var)
|
|
||||||
{
|
|
||||||
QApplication::setStyle(QStyleFactory::create(var.asString().c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::cfcbQtPalette(NLMISC::CConfigFile::CVar &var)
|
|
||||||
{
|
|
||||||
if (var.asBool()) QApplication::setPalette(QApplication::style()->standardPalette());
|
|
||||||
else QApplication::setPalette(_originalPalette);
|
|
||||||
}
|
|
||||||
|
|
||||||
QTabBar* CMainWindow::getTabBar()
|
|
||||||
{
|
|
||||||
// get the QTabBar
|
|
||||||
QList<QTabBar *> tabList = findChildren<QTabBar *>();
|
|
||||||
//tabList = _mainWindow->findChildren<QTabBar *>();
|
|
||||||
//nlinfo(QString("%1 %2").arg(QString::number((int)this,16)).
|
|
||||||
// arg(QString::number((int)_mainWindow,16)).
|
|
||||||
// toStdString().c_str());
|
|
||||||
QTabBar *tb = 0;
|
|
||||||
Q_FOREACH(QTabBar *tabBar, tabList){
|
|
||||||
if (tabBar->parent() != this)
|
|
||||||
continue;
|
|
||||||
//nlinfo(QString("%1 %2 %3 %4").arg(tabBar->objectName()).
|
|
||||||
// arg(QString::number((int)tabBar,16)).
|
|
||||||
// arg(QString::number((int)tabBar->parentWidget(),16)).
|
|
||||||
// arg(QString::number((int)tabBar->parent(),16)).
|
|
||||||
// toStdString().c_str());
|
|
||||||
for (int i = 0; i < tabBar->count(); i++) {
|
|
||||||
QString currentTab = tabBar->tabText(i);
|
|
||||||
//nlinfo(currentTab.toStdString().c_str());
|
|
||||||
}
|
}
|
||||||
tb = tabBar;
|
setCursor(Qt::ArrowCursor);*/
|
||||||
}
|
|
||||||
return tb;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::tabChanged(int index)
|
|
||||||
{
|
|
||||||
if (index == -1) {
|
|
||||||
setWindowTitle("Qt Georges Editor");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTabBar *tb = getTabBar();
|
void CMainWindow::save()
|
||||||
//nlinfo(QString("%1").arg(index).toStdString().c_str());
|
{
|
||||||
|
if(!_currentView)
|
||||||
Q_FOREACH(CGeorgesTreeViewDialog* dlg, _treeViewList) {
|
return;
|
||||||
if (dlg->windowTitle() == tb->tabText(index)) {
|
|
||||||
//nlinfo(QString("%1 modified %2").arg(tb->tabText(index)).
|
setCursor(Qt::WaitCursor);
|
||||||
// arg(dlg->modified()).
|
|
||||||
|
_currentView->write();
|
||||||
|
setWindowTitle(windowTitle().remove("*"));
|
||||||
|
_saveAction->setEnabled(false);
|
||||||
|
|
||||||
|
setCursor(Qt::ArrowCursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::create()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::createEmptyView()
|
||||||
|
{
|
||||||
|
_emptyView = new CGeorgesTreeViewDialog(this, true);
|
||||||
|
//_emptyView->setAllowedAreas(Qt::TopDockWidgetArea);
|
||||||
|
addDockWidget(Qt::TopDockWidgetArea,_emptyView);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::createActions()
|
||||||
|
{
|
||||||
|
_openAction = new QAction(tr("&Open..."), this);
|
||||||
|
_openAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogOpenButton));
|
||||||
|
_openAction->setShortcut(QKeySequence::Open);
|
||||||
|
_openAction->setStatusTip(tr("Open an existing file"));
|
||||||
|
connect(_openAction, SIGNAL(triggered()), this, SLOT(open()));
|
||||||
|
|
||||||
|
_createAction = new QAction(tr("&New..."), this);
|
||||||
|
_createAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileDialogNewFolder));
|
||||||
|
_createAction->setShortcut(QKeySequence::New);
|
||||||
|
_createAction->setStatusTip(tr("Create a new file"));
|
||||||
|
connect(_createAction, SIGNAL(triggered()), this, SLOT(create()));
|
||||||
|
|
||||||
|
_saveAction = new QAction(tr("&Save..."), this);
|
||||||
|
_saveAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogSaveButton));
|
||||||
|
_saveAction->setShortcut(QKeySequence::Save);
|
||||||
|
_saveAction->setStatusTip(tr("Saves the current file"));
|
||||||
|
_saveAction->setDisabled(true);
|
||||||
|
connect(_saveAction, SIGNAL(triggered()), this, SLOT(save()));
|
||||||
|
|
||||||
|
_exitAction = new QAction(tr("E&xit"), this);
|
||||||
|
_exitAction->setShortcut(QKeySequence::Close);
|
||||||
|
_exitAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogCloseButton));
|
||||||
|
_exitAction->setStatusTip(tr("Exit the application"));
|
||||||
|
connect(_exitAction, SIGNAL(triggered()), this, SLOT(close()));
|
||||||
|
|
||||||
|
_setBackColorAction = _ObjectViewerDialog->createSetBackgroundColor(this);
|
||||||
|
_setBackColorAction->setText(tr("Set &background color"));
|
||||||
|
_setBackColorAction->setStatusTip(tr("Set background color"));
|
||||||
|
|
||||||
|
_settingsAction = new QAction(tr("&Settings"), this);
|
||||||
|
_settingsAction->setIcon(QIcon(":/images/preferences.png"));
|
||||||
|
_settingsAction->setStatusTip(tr("Settings"));
|
||||||
|
connect(_settingsAction, SIGNAL(triggered()), this, SLOT(settings()));
|
||||||
|
|
||||||
|
_aboutAction = new QAction(tr("&About"), this);
|
||||||
|
_aboutAction->setStatusTip(tr("Show the application's About box"));
|
||||||
|
connect(_aboutAction, SIGNAL(triggered()), this, SLOT(about()));
|
||||||
|
|
||||||
|
_aboutQtAction = new QAction(tr("About &Qt"), this);
|
||||||
|
_aboutQtAction->setStatusTip(tr("Show the Qt library's About box"));
|
||||||
|
connect(_aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
||||||
|
|
||||||
|
for (int i = 0; i < MaxRecentFiles; ++i) {
|
||||||
|
recentFileActs[i] = new QAction(this);
|
||||||
|
recentFileActs[i]->setVisible(false);
|
||||||
|
connect(recentFileActs[i], SIGNAL(triggered()),
|
||||||
|
this, SLOT(openRecentFile()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::createMenus()
|
||||||
|
{
|
||||||
|
_fileMenu = menuBar()->addMenu(tr("&File"));
|
||||||
|
_fileMenu->addAction(_createAction);
|
||||||
|
_fileMenu->addAction(_openAction);
|
||||||
|
_fileMenu->addAction(_saveAction);
|
||||||
|
_separatorAction = _fileMenu->addSeparator();
|
||||||
|
for (int i = 0; i < MaxRecentFiles; ++i)
|
||||||
|
_fileMenu->addAction(recentFileActs[i]);
|
||||||
|
_fileMenu->addSeparator();
|
||||||
|
_fileMenu->addAction(_exitAction);
|
||||||
|
updateRecentFileActions();
|
||||||
|
|
||||||
|
_viewMenu = menuBar()->addMenu(tr("&View"));
|
||||||
|
_viewMenu->addAction(_setBackColorAction);
|
||||||
|
if (_GeorgesDirTreeDialog)
|
||||||
|
_viewMenu->addAction(_GeorgesDirTreeDialog->toggleViewAction());
|
||||||
|
|
||||||
|
_toolsMenu = menuBar()->addMenu(tr("&Tools"));
|
||||||
|
if (_ObjectViewerDialog)
|
||||||
|
{
|
||||||
|
_toolsMenu->addAction(_ObjectViewerDialog->toggleViewAction());
|
||||||
|
_ObjectViewerDialog->toggleViewAction()->setIcon(QIcon(":/images/pqrticles.png"));
|
||||||
|
}
|
||||||
|
_toolsMenu->addSeparator();
|
||||||
|
_toolsMenu->addAction(_settingsAction);
|
||||||
|
|
||||||
|
menuBar()->addSeparator();
|
||||||
|
|
||||||
|
_helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||||
|
_helpMenu->addAction(_aboutAction);
|
||||||
|
_helpMenu->addAction(_aboutQtAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::createToolBars()
|
||||||
|
{
|
||||||
|
_fileToolBar = addToolBar(tr("&File"));
|
||||||
|
_fileToolBar->addAction(_createAction);
|
||||||
|
_fileToolBar->addAction(_openAction);
|
||||||
|
_fileToolBar->addAction(_saveAction);
|
||||||
|
|
||||||
|
_toolsBar = addToolBar(tr("&Tools"));
|
||||||
|
if (_ObjectViewerDialog)
|
||||||
|
_toolsBar->addAction(_ObjectViewerDialog->toggleViewAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::createStatusBar()
|
||||||
|
{
|
||||||
|
statusBar()->showMessage(tr("StatusReady"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::cfcbQtStyle(NLMISC::CConfigFile::CVar &var)
|
||||||
|
{
|
||||||
|
QApplication::setStyle(QStyleFactory::create(var.asString().c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::cfcbQtPalette(NLMISC::CConfigFile::CVar &var)
|
||||||
|
{
|
||||||
|
if (var.asBool())
|
||||||
|
QApplication::setPalette(QApplication::style()->standardPalette());
|
||||||
|
else
|
||||||
|
QApplication::setPalette(_originalPalette);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTabBar* CMainWindow::getTabBar()
|
||||||
|
{
|
||||||
|
// get the QTabBar
|
||||||
|
QList<QTabBar *> tabList = findChildren<QTabBar *>();
|
||||||
|
//tabList = _mainWindow->findChildren<QTabBar *>();
|
||||||
|
//nlinfo(QString("%1 %2").arg(QString::number((int)this,16)).
|
||||||
|
// arg(QString::number((int)_mainWindow,16)).
|
||||||
|
// toStdString().c_str());
|
||||||
|
QTabBar *tb = 0;
|
||||||
|
Q_FOREACH(QTabBar *tabBar, tabList)
|
||||||
|
{
|
||||||
|
if (tabBar->parent() != this)
|
||||||
|
continue;
|
||||||
|
//nlinfo(QString("%1 %2 %3 %4").arg(tabBar->objectName()).
|
||||||
|
// arg(QString::number((int)tabBar,16)).
|
||||||
|
// arg(QString::number((int)tabBar->parentWidget(),16)).
|
||||||
|
// arg(QString::number((int)tabBar->parent(),16)).
|
||||||
// toStdString().c_str());
|
// toStdString().c_str());
|
||||||
_currentView = dlg;
|
for (int i = 0; i < tabBar->count(); i++)
|
||||||
setWindowTitle("Qt Georges Editor - " + tb->tabText(index));
|
{
|
||||||
_saveAction->setEnabled(dlg->modified());
|
QString currentTab = tabBar->tabText(i);
|
||||||
|
//nlinfo(currentTab.toStdString().c_str());
|
||||||
|
}
|
||||||
|
tb = tabBar;
|
||||||
|
}
|
||||||
|
return tb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::tabChanged(int index)
|
||||||
|
{
|
||||||
|
if (index == -1)
|
||||||
|
{
|
||||||
|
setWindowTitle("Qt Georges Editor");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTabBar *tb = getTabBar();
|
||||||
|
//nlinfo(QString("%1").arg(index).toStdString().c_str());
|
||||||
|
|
||||||
|
Q_FOREACH(CGeorgesTreeViewDialog* dlg, _treeViewList)
|
||||||
|
{
|
||||||
|
if (dlg->windowTitle() == tb->tabText(index))
|
||||||
|
{
|
||||||
|
//nlinfo(QString("%1 modified %2").arg(tb->tabText(index)).
|
||||||
|
// arg(dlg->modified()).
|
||||||
|
// toStdString().c_str());
|
||||||
|
_currentView = dlg;
|
||||||
|
setWindowTitle("Qt Georges Editor - " + tb->tabText(index));
|
||||||
|
_saveAction->setEnabled(dlg->modified());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CMainWindow::openRecentFile()
|
void CMainWindow::openRecentFile()
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
if (action)
|
if (action)
|
||||||
loadFile(action->data().toString());
|
loadFile(action->data().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainWindow::setCurrentFile(const QString &fileName)
|
void CMainWindow::setCurrentFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
//curFile = fileName;
|
//curFile = fileName;
|
||||||
//setWindowFilePath(curFile);
|
//setWindowFilePath(curFile);
|
||||||
|
|
||||||
QSettings settings("georges_editor_qt.ini", QSettings::IniFormat);
|
QSettings settings("georges_editor_qt.ini", QSettings::IniFormat);
|
||||||
settings.beginGroup("RecentFileList");
|
settings.beginGroup("RecentFileList");
|
||||||
QStringList files = settings.value("List").toStringList();
|
QStringList files = settings.value("List").toStringList();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
files.removeAll(fileName);
|
files.removeAll(fileName);
|
||||||
files.prepend(fileName);
|
files.prepend(fileName);
|
||||||
while (files.size() > MaxRecentFiles)
|
while (files.size() > MaxRecentFiles)
|
||||||
files.removeLast();
|
files.removeLast();
|
||||||
|
|
||||||
settings.beginGroup("RecentFileList");
|
settings.beginGroup("RecentFileList");
|
||||||
settings.setValue("List",files);
|
settings.setValue("List",files);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
Q_FOREACH (QWidget *widget, QApplication::topLevelWidgets()) {
|
Q_FOREACH (QWidget *widget, QApplication::topLevelWidgets())
|
||||||
CMainWindow *mainWin = qobject_cast<CMainWindow *>(widget);
|
{
|
||||||
if (mainWin)
|
CMainWindow *mainWin = qobject_cast<CMainWindow *>(widget);
|
||||||
mainWin->updateRecentFileActions();
|
if (mainWin)
|
||||||
}
|
mainWin->updateRecentFileActions();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CMainWindow::updateRecentFileActions()
|
void CMainWindow::updateRecentFileActions()
|
||||||
{
|
{
|
||||||
QSettings settings("georges_editor_qt.ini", QSettings::IniFormat);
|
QSettings settings("georges_editor_qt.ini", QSettings::IniFormat);
|
||||||
settings.beginGroup("RecentFileList");
|
settings.beginGroup("RecentFileList");
|
||||||
QStringList files = settings.value("List").toStringList();
|
QStringList files = settings.value("List").toStringList();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
|
int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
|
||||||
|
|
||||||
for (int i = 0; i < numRecentFiles; ++i) {
|
for (int i = 0; i < numRecentFiles; ++i)
|
||||||
QString text = tr("&%1 %2").arg(i + 1).arg(QFileInfo(files[i]).fileName());
|
{
|
||||||
recentFileActs[i]->setText(text);
|
QString text = tr("&%1 %2").arg(i + 1).arg(QFileInfo(files[i]).fileName());
|
||||||
recentFileActs[i]->setData(files[i]);
|
recentFileActs[i]->setText(text);
|
||||||
recentFileActs[i]->setVisible(true);
|
recentFileActs[i]->setData(files[i]);
|
||||||
}
|
recentFileActs[i]->setVisible(true);
|
||||||
for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
|
}
|
||||||
recentFileActs[j]->setVisible(false);
|
for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
|
||||||
|
recentFileActs[j]->setVisible(false);
|
||||||
|
|
||||||
_separatorAction->setVisible(numRecentFiles > 0);
|
_separatorAction->setVisible(numRecentFiles > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainWindow::loadFile(const QString &fileName)
|
void CMainWindow::loadFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
/*QFile file(fileName);
|
/*QFile file(fileName);
|
||||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
QMessageBox::warning(this, tr("Recent Files"),
|
QMessageBox::warning(this, tr("Recent Files"),
|
||||||
tr("Cannot read file %1:\n%2.")
|
tr("Cannot read file %1:\n%2.")
|
||||||
.arg(fileName)
|
.arg(fileName)
|
||||||
.arg(file.errorString()));
|
.arg(file.errorString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
textEdit->setPlainText(in.readAll());
|
textEdit->setPlainText(in.readAll());
|
||||||
QApplication::restoreOverrideCursor();*/
|
QApplication::restoreOverrideCursor();*/
|
||||||
|
|
||||||
|
openTreeView(fileName);
|
||||||
|
setCurrentFile(fileName);
|
||||||
|
//statusBar()->showMessage(tr("File loaded"), 2000);
|
||||||
|
}
|
||||||
|
|
||||||
openTreeView(fileName);
|
|
||||||
setCurrentFile(fileName);
|
|
||||||
//statusBar()->showMessage(tr("File loaded"), 2000);
|
|
||||||
}
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
||||||
/* end of file */
|
/* end of file */
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -33,89 +33,90 @@
|
||||||
|
|
||||||
// Project includes
|
// Project includes
|
||||||
|
|
||||||
namespace NLMISC {
|
namespace NLMISC
|
||||||
|
{
|
||||||
class CConfigFile;
|
class CConfigFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
class CGeorgesLogDialog;
|
class CGeorgesLogDialog;
|
||||||
class CObjectViewerDialog;
|
class CObjectViewerDialog;
|
||||||
class CGeorgesDirTreeDialog;
|
class CGeorgesDirTreeDialog;
|
||||||
class CGeorgesTreeViewDialog;
|
class CGeorgesTreeViewDialog;
|
||||||
|
|
||||||
|
|
||||||
class CMainWindow : public QMainWindow
|
class CMainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CMainWindow(QWidget *parent = 0);
|
CMainWindow(QWidget *parent = 0);
|
||||||
~CMainWindow();
|
~CMainWindow();
|
||||||
|
|
||||||
CGeorgesTreeViewDialog* getEmptyView() { return _emptyView;}
|
CGeorgesTreeViewDialog* getEmptyView() { return _emptyView;}
|
||||||
QList<CGeorgesTreeViewDialog*>& getTreeViewList() { return _treeViewList; }
|
QList<CGeorgesTreeViewDialog*>& getTreeViewList() { return _treeViewList; }
|
||||||
QTabBar* getTabBar();
|
QTabBar* getTabBar();
|
||||||
void createEmptyView();
|
void createEmptyView();
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void open();
|
|
||||||
void create();
|
|
||||||
void save();
|
|
||||||
void settings();
|
|
||||||
void about();
|
|
||||||
void updateStatusBar();
|
|
||||||
void openTreeView(QString);
|
|
||||||
void tabChanged(int);
|
|
||||||
void openRecentFile();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void createActions();
|
|
||||||
void createMenus();
|
|
||||||
void createToolBars();
|
|
||||||
void createStatusBar();
|
|
||||||
void createDialogs();
|
|
||||||
|
|
||||||
void loadFile(const QString &fileName);
|
private Q_SLOTS:
|
||||||
void updateRecentFileActions();
|
void open();
|
||||||
void setCurrentFile(const QString &fileName);
|
void create();
|
||||||
|
void save();
|
||||||
void cfcbQtStyle(NLMISC::CConfigFile::CVar &var);
|
void settings();
|
||||||
void cfcbQtPalette(NLMISC::CConfigFile::CVar &var);
|
void about();
|
||||||
|
void updateStatusBar();
|
||||||
CGeorgesLogDialog *_GeorgesLogDialog;
|
void openTreeView(QString);
|
||||||
CObjectViewerDialog *_ObjectViewerDialog;
|
void tabChanged(int);
|
||||||
CGeorgesDirTreeDialog *_GeorgesDirTreeDialog;
|
void openRecentFile();
|
||||||
QList<CGeorgesTreeViewDialog*> _treeViewList;
|
|
||||||
CGeorgesTreeViewDialog *_emptyView;
|
|
||||||
CGeorgesTreeViewDialog *_currentView;
|
|
||||||
|
|
||||||
QPalette _originalPalette;
|
|
||||||
|
|
||||||
QTimer *_statusBarTimer;
|
private:
|
||||||
|
void createActions();
|
||||||
|
void createMenus();
|
||||||
|
void createToolBars();
|
||||||
|
void createStatusBar();
|
||||||
|
void createDialogs();
|
||||||
|
|
||||||
QMenu *_fileMenu;
|
void loadFile(const QString &fileName);
|
||||||
QMenu *_viewMenu;
|
void updateRecentFileActions();
|
||||||
QMenu *_toolsMenu;
|
void setCurrentFile(const QString &fileName);
|
||||||
QMenu *_helpMenu;
|
|
||||||
QToolBar *_fileToolBar;
|
void cfcbQtStyle(NLMISC::CConfigFile::CVar &var);
|
||||||
QToolBar *_editToolBar;
|
void cfcbQtPalette(NLMISC::CConfigFile::CVar &var);
|
||||||
QToolBar *_toolsBar;
|
|
||||||
QAction *_openAction;
|
CGeorgesLogDialog *_GeorgesLogDialog;
|
||||||
QAction *_createAction;
|
CObjectViewerDialog *_ObjectViewerDialog;
|
||||||
QAction *_saveAction;
|
CGeorgesDirTreeDialog *_GeorgesDirTreeDialog;
|
||||||
QAction *_exitAction;
|
QList<CGeorgesTreeViewDialog*> _treeViewList;
|
||||||
QAction *_setBackColorAction;
|
CGeorgesTreeViewDialog *_emptyView;
|
||||||
QAction *_settingsAction;
|
CGeorgesTreeViewDialog *_currentView;
|
||||||
QAction *_aboutAction;
|
|
||||||
QAction *_aboutQtAction;
|
QPalette _originalPalette;
|
||||||
QAction *_separatorAction;
|
|
||||||
|
QTimer *_statusBarTimer;
|
||||||
|
|
||||||
|
QMenu *_fileMenu;
|
||||||
|
QMenu *_viewMenu;
|
||||||
|
QMenu *_toolsMenu;
|
||||||
|
QMenu *_helpMenu;
|
||||||
|
QToolBar *_fileToolBar;
|
||||||
|
QToolBar *_editToolBar;
|
||||||
|
QToolBar *_toolsBar;
|
||||||
|
QAction *_openAction;
|
||||||
|
QAction *_createAction;
|
||||||
|
QAction *_saveAction;
|
||||||
|
QAction *_exitAction;
|
||||||
|
QAction *_setBackColorAction;
|
||||||
|
QAction *_settingsAction;
|
||||||
|
QAction *_aboutAction;
|
||||||
|
QAction *_aboutQtAction;
|
||||||
|
QAction *_separatorAction;
|
||||||
|
|
||||||
|
|
||||||
enum { MaxRecentFiles = 5 };
|
enum { MaxRecentFiles = 5 };
|
||||||
QAction *recentFileActs[MaxRecentFiles];
|
QAction *recentFileActs[MaxRecentFiles];
|
||||||
|
|
||||||
};/* class CMainWindow */
|
};/* class CMainWindow */
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "object_viewer.h"
|
#include "object_viewer.h"
|
||||||
|
@ -49,363 +49,364 @@ using namespace std;
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
using namespace NL3D;
|
using namespace NL3D;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
|
||||||
CObjectViewer::CObjectViewer()
|
|
||||||
: _Driver(NULL),
|
|
||||||
_phi(0), _psi(0),_dist(20),
|
|
||||||
_CurrentInstance("")
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
CObjectViewer::~CObjectViewer()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
CObjectViewer::CObjectViewer()
|
||||||
|
: _Driver(NULL),
|
||||||
void CObjectViewer::reinit(nlWindow wnd, uint16 w, uint16 h)
|
_phi(0), _psi(0),_dist(20),
|
||||||
{
|
_CurrentInstance("")
|
||||||
nldebug("CObjectViewert::reinit");
|
|
||||||
|
|
||||||
//release();
|
|
||||||
//init(wnd, w, h);
|
|
||||||
_Driver->setDisplay(wnd, NL3D::UDriver::CMode(w, h, 32));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::init(nlWindow wnd, uint16 w, uint16 h)
|
|
||||||
{
|
|
||||||
//H_AUTO2
|
|
||||||
nldebug("CObjectViewer::init");
|
|
||||||
|
|
||||||
// load and set remap extensions from config
|
|
||||||
//Modules::config().configRemapExtensions();
|
|
||||||
|
|
||||||
// load and set search paths from config
|
|
||||||
//Modules::config().configSearchPaths();
|
|
||||||
|
|
||||||
// set background color from config
|
|
||||||
Modules::config().setAndCallback("BackgroundColor", CConfigCallback(this, &CObjectViewer::cfcbBackgroundColor));
|
|
||||||
|
|
||||||
// set graphics driver from config
|
|
||||||
Modules::config().setAndCallback("GraphicsDriver",CConfigCallback(this,&CObjectViewer::cfcbGraphicsDriver));
|
|
||||||
|
|
||||||
// create the driver
|
|
||||||
nlassert(!_Driver);
|
|
||||||
|
|
||||||
_Driver = UDriver::createDriver(NULL, _Direct3D, NULL);
|
|
||||||
nlassert(_Driver);
|
|
||||||
|
|
||||||
// initialize the window with config file values
|
|
||||||
_Driver->setDisplay(wnd, NL3D::UDriver::CMode(w, h, 32));
|
|
||||||
|
|
||||||
_Light = ULight::createLight();
|
|
||||||
|
|
||||||
// set mode of the light
|
|
||||||
_Light->setMode(ULight::DirectionalLight);
|
|
||||||
|
|
||||||
// set position of the light
|
|
||||||
_Light->setPosition(CVector(-20.f, 30.f, 10.f));
|
|
||||||
|
|
||||||
// white light
|
|
||||||
_Light->setAmbiant(CRGBA(255, 255, 255));
|
|
||||||
|
|
||||||
// set and enable the light
|
|
||||||
_Driver->setLight(0, *_Light);
|
|
||||||
_Driver->enableLight(0);
|
|
||||||
|
|
||||||
// Create a scene
|
|
||||||
_Scene = _Driver->createScene(true);
|
|
||||||
|
|
||||||
_PlayListManager = _Scene->createPlayListManager();
|
|
||||||
|
|
||||||
_Scene->enableLightingSystem(true);
|
|
||||||
|
|
||||||
// create the camera
|
|
||||||
UCamera camera = _Scene->getCam();
|
|
||||||
|
|
||||||
camera.setTransformMode (UTransformable::DirectMatrix);
|
|
||||||
|
|
||||||
setSizeViewport(w, h);
|
|
||||||
|
|
||||||
// camera will look at entities
|
|
||||||
updateCamera(0,0,0);
|
|
||||||
|
|
||||||
NLMISC::CVector hotSpot=NLMISC::CVector(0,0,0);
|
|
||||||
|
|
||||||
_MouseListener = _Driver->create3dMouseListener();
|
|
||||||
_MouseListener->setMatrix(Modules::objView().getScene()->getCam().getMatrix());
|
|
||||||
_MouseListener->setFrustrum(Modules::objView().getScene()->getCam().getFrustum());
|
|
||||||
_MouseListener->setHotSpot(hotSpot);
|
|
||||||
_MouseListener->setMouseMode(U3dMouseListener::edit3d);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::release()
|
|
||||||
{
|
|
||||||
//H_AUTO2
|
|
||||||
nldebug("CObjectViewer::release");
|
|
||||||
|
|
||||||
Modules::config().dropCallback("BackgroundColor");
|
|
||||||
Modules::config().dropCallback("GraphicsDriver");
|
|
||||||
|
|
||||||
_Driver->delete3dMouseListener(_MouseListener);
|
|
||||||
|
|
||||||
// delete all entities
|
|
||||||
deleteEntities();
|
|
||||||
|
|
||||||
_Scene->deletePlayListManager(_PlayListManager);
|
|
||||||
|
|
||||||
// delete the scene
|
|
||||||
_Driver->deleteScene(_Scene);
|
|
||||||
|
|
||||||
// delete the light
|
|
||||||
delete _Light;
|
|
||||||
|
|
||||||
// release driver
|
|
||||||
nlassert(_Driver);
|
|
||||||
_Driver->release();
|
|
||||||
delete _Driver;
|
|
||||||
_Driver = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::updateInput()
|
|
||||||
{
|
|
||||||
_Driver->EventServer.pump();
|
|
||||||
|
|
||||||
// New matrix from camera
|
|
||||||
_Scene->getCam().setTransformMode(NL3D::UTransformable::DirectMatrix);
|
|
||||||
_Scene->getCam().setMatrix (_MouseListener->getViewMatrix());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::renderDriver()
|
|
||||||
{
|
|
||||||
_Driver->clearBuffers(_BackgroundColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::renderScene()
|
|
||||||
{
|
|
||||||
// render the scene
|
|
||||||
_Scene->render();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::renderDebug2D()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::saveScreenshot(const std::string &nameFile, bool jpg, bool png, bool tga)
|
|
||||||
{
|
|
||||||
//H_AUTO2
|
|
||||||
|
|
||||||
// FIXME: create screenshot path if it doesn't exist!
|
|
||||||
|
|
||||||
// empty bitmap
|
|
||||||
CBitmap bitmap;
|
|
||||||
// copy the driver buffer to the bitmap
|
|
||||||
_Driver->getBuffer(bitmap);
|
|
||||||
// create the file name
|
|
||||||
string filename = std::string("./") + nameFile;
|
|
||||||
// write the bitmap as a jpg, png or tga to the file
|
|
||||||
if (jpg)
|
|
||||||
{
|
{
|
||||||
string newfilename = CFile::findNewFile(filename + ".jpg");
|
|
||||||
COFile outputFile(newfilename);
|
|
||||||
bitmap.writeJPG(outputFile, 100);
|
|
||||||
nlinfo("Screenshot '%s' saved", newfilename.c_str());
|
|
||||||
}
|
|
||||||
if (png)
|
|
||||||
{
|
|
||||||
string newfilename = CFile::findNewFile(filename + ".png");
|
|
||||||
COFile outputFile(newfilename);
|
|
||||||
bitmap.writePNG(outputFile, 24);
|
|
||||||
nlinfo("Screenshot '%s' saved", newfilename.c_str());
|
|
||||||
}
|
|
||||||
if (tga)
|
|
||||||
{
|
|
||||||
string newfilename = CFile::findNewFile(filename + ".tga");
|
|
||||||
COFile outputFile(newfilename);
|
|
||||||
bitmap.writeTGA(outputFile, 24, false);
|
|
||||||
nlinfo("Screenshot '%s' saved", newfilename.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CObjectViewer::loadMesh(const std::string &meshFileName, const std::string &skelFileName)
|
|
||||||
{
|
|
||||||
CPath::addSearchPath(CFile::getPath(meshFileName), false, false);
|
|
||||||
|
|
||||||
// create instance of the mesh character
|
|
||||||
UInstance Entity = _Scene->createInstance(meshFileName);
|
|
||||||
|
|
||||||
USkeleton Skeleton = _Scene->createSkeleton(skelFileName);
|
|
||||||
|
|
||||||
// if we can't create entity, skip it
|
|
||||||
if (Entity.empty()) return false;
|
|
||||||
|
|
||||||
// create a new entity
|
|
||||||
EIT eit = (_Entities.insert (make_pair (CFile::getFilenameWithoutExtension(meshFileName), CEntity()))).first;
|
|
||||||
CEntity &entity = (*eit).second;
|
|
||||||
|
|
||||||
// set the entity up
|
|
||||||
entity._Name = CFile::getFilenameWithoutExtension(meshFileName);
|
|
||||||
entity._Instance = Entity;
|
|
||||||
if (!Skeleton.empty())
|
|
||||||
{
|
|
||||||
entity._Skeleton = Skeleton;
|
|
||||||
entity._Skeleton.bindSkin (entity._Instance);
|
|
||||||
}
|
|
||||||
entity._AnimationSet = _Driver->createAnimationSet(false);
|
|
||||||
entity._PlayList = _PlayListManager->createPlayList(entity._AnimationSet);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::resetScene()
|
|
||||||
{
|
|
||||||
deleteEntities();
|
|
||||||
|
|
||||||
// Reset camera.
|
|
||||||
//..
|
|
||||||
|
|
||||||
// to load files with the same name but located in different directories
|
|
||||||
//CPath::clearMap();
|
|
||||||
|
|
||||||
// load and set search paths from config
|
|
||||||
//Modules::config().configSearchPaths();
|
|
||||||
|
|
||||||
_CurrentInstance = "";
|
|
||||||
|
|
||||||
nlinfo("Scene cleared");
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::updateCamera(float deltaPsi, float deltaPhi, float deltaDist)
|
|
||||||
{
|
|
||||||
_phi += deltaPhi;
|
|
||||||
_psi += deltaPsi;
|
|
||||||
_dist += deltaDist;
|
|
||||||
|
|
||||||
if(_phi < -NLMISC::Pi/2) _phi -= deltaPhi;
|
|
||||||
if(_phi > NLMISC::Pi/2) _phi -= deltaPsi;
|
|
||||||
if (_dist < 1) _dist = 1;
|
|
||||||
|
|
||||||
NLMISC::CQuat q0,q1,q2;
|
|
||||||
NLMISC::CVector up(0,0,1);
|
|
||||||
NLMISC::CVector v(0,0,1);
|
|
||||||
|
|
||||||
q0.setAngleAxis(v,_psi);
|
|
||||||
v = NLMISC::CVector(0,1,0);
|
|
||||||
q1.setAngleAxis(v,_phi);
|
|
||||||
q2 = q0 * q1;
|
|
||||||
NLMISC::CMatrix m0;
|
|
||||||
m0.setRot(q2);
|
|
||||||
NLMISC::CVector camera = m0 * NLMISC::CVector(_dist,0,0);
|
|
||||||
|
|
||||||
_Scene->getCam().lookAt(camera, up);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::setBackgroundColor(NLMISC::CRGBA backgroundColor)
|
|
||||||
{
|
|
||||||
_BackgroundColor = backgroundColor;
|
|
||||||
|
|
||||||
// config file variable changes
|
|
||||||
Modules::config().getConfigFile().getVar("BackgroundColor").setAsInt(_BackgroundColor.R, 0);
|
|
||||||
Modules::config().getConfigFile().getVar("BackgroundColor").setAsInt(_BackgroundColor.G, 1);
|
|
||||||
Modules::config().getConfigFile().getVar("BackgroundColor").setAsInt(_BackgroundColor.B, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::setGraphicsDriver(bool Direct3D)
|
|
||||||
{
|
|
||||||
_Direct3D = Direct3D;
|
|
||||||
|
|
||||||
if (_Direct3D) Modules::config().getConfigFile().getVar("GraphicsDriver").setAsString("Direct3D");
|
|
||||||
else Modules::config().getConfigFile().getVar("GraphicsDriver").setAsString("OpenGL");
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::setSizeViewport(uint16 w, uint16 h)
|
|
||||||
{
|
|
||||||
_Scene->getCam().setPerspective((float)Pi/2.f, (float)w/h, 0.1f, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::getSizeViewport(float &left, float &right, float &bottom, float &top, float &znear, float &zfar)
|
|
||||||
{
|
|
||||||
//_Scene->getCam().setPerspective((float)Pi/2.f, (float)w/h, 0.1f, 1000);
|
|
||||||
_Scene->getCam().getFrustum(left, right, bottom, top, znear, zfar);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::setCurrentObject(const std::string &name)
|
|
||||||
{
|
|
||||||
if ((_Entities.count(name) != 0) || ( name.empty() )) _CurrentInstance = name;
|
|
||||||
else nlerror ("Entity %s not found", name.c_str());
|
|
||||||
nlinfo("set current entity %s", _CurrentInstance.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
CEntity& CObjectViewer::getEntity(const std::string &name)
|
|
||||||
{
|
|
||||||
if ( _Entities.count(name) == 0) nlerror("Entity %s not found", name.c_str());
|
|
||||||
EIT eit = _Entities.find (name);
|
|
||||||
return (*eit).second;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::getListObjects(std::vector<std::string> &listObj)
|
|
||||||
{
|
|
||||||
listObj.clear();
|
|
||||||
for (EIT eit = _Entities.begin(); eit != _Entities.end(); ++eit)
|
|
||||||
listObj.push_back((*eit).second._Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::deleteEntity(CEntity &entity)
|
|
||||||
{
|
|
||||||
if (entity._PlayList != NULL)
|
|
||||||
{
|
|
||||||
_PlayListManager->deletePlayList (entity._PlayList);
|
|
||||||
entity._PlayList = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity._AnimationSet != NULL)
|
CObjectViewer::~CObjectViewer()
|
||||||
{
|
{
|
||||||
_Driver->deleteAnimationSet(entity._AnimationSet);
|
|
||||||
entity._AnimationSet = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entity._Skeleton.empty())
|
void CObjectViewer::reinit(nlWindow wnd, uint16 w, uint16 h)
|
||||||
{
|
{
|
||||||
entity._Skeleton.detachSkeletonSon(entity._Instance);
|
nldebug("CObjectViewert::reinit");
|
||||||
|
|
||||||
_Scene->deleteSkeleton(entity._Skeleton);
|
//release();
|
||||||
entity._Skeleton = NULL;
|
//init(wnd, w, h);
|
||||||
|
_Driver->setDisplay(wnd, NL3D::UDriver::CMode(w, h, 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entity._Instance.empty())
|
void CObjectViewer::init(nlWindow wnd, uint16 w, uint16 h)
|
||||||
{
|
{
|
||||||
_Scene->deleteInstance(entity._Instance);
|
//H_AUTO2
|
||||||
entity._Instance = NULL;
|
nldebug("CObjectViewer::init");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::deleteEntities()
|
// load and set remap extensions from config
|
||||||
{
|
//Modules::config().configRemapExtensions();
|
||||||
for (EIT eit = _Entities.begin(); eit != _Entities.end(); ++eit)
|
|
||||||
|
// load and set search paths from config
|
||||||
|
//Modules::config().configSearchPaths();
|
||||||
|
|
||||||
|
// set background color from config
|
||||||
|
Modules::config().setAndCallback("BackgroundColor", CConfigCallback(this, &CObjectViewer::cfcbBackgroundColor));
|
||||||
|
|
||||||
|
// set graphics driver from config
|
||||||
|
Modules::config().setAndCallback("GraphicsDriver",CConfigCallback(this,&CObjectViewer::cfcbGraphicsDriver));
|
||||||
|
|
||||||
|
// create the driver
|
||||||
|
nlassert(!_Driver);
|
||||||
|
|
||||||
|
_Driver = UDriver::createDriver(NULL, _Direct3D, NULL);
|
||||||
|
nlassert(_Driver);
|
||||||
|
|
||||||
|
// initialize the window with config file values
|
||||||
|
_Driver->setDisplay(wnd, NL3D::UDriver::CMode(w, h, 32));
|
||||||
|
|
||||||
|
_Light = ULight::createLight();
|
||||||
|
|
||||||
|
// set mode of the light
|
||||||
|
_Light->setMode(ULight::DirectionalLight);
|
||||||
|
|
||||||
|
// set position of the light
|
||||||
|
_Light->setPosition(CVector(-20.f, 30.f, 10.f));
|
||||||
|
|
||||||
|
// white light
|
||||||
|
_Light->setAmbiant(CRGBA(255, 255, 255));
|
||||||
|
|
||||||
|
// set and enable the light
|
||||||
|
_Driver->setLight(0, *_Light);
|
||||||
|
_Driver->enableLight(0);
|
||||||
|
|
||||||
|
// Create a scene
|
||||||
|
_Scene = _Driver->createScene(true);
|
||||||
|
|
||||||
|
_PlayListManager = _Scene->createPlayListManager();
|
||||||
|
|
||||||
|
_Scene->enableLightingSystem(true);
|
||||||
|
|
||||||
|
// create the camera
|
||||||
|
UCamera camera = _Scene->getCam();
|
||||||
|
|
||||||
|
camera.setTransformMode (UTransformable::DirectMatrix);
|
||||||
|
|
||||||
|
setSizeViewport(w, h);
|
||||||
|
|
||||||
|
// camera will look at entities
|
||||||
|
updateCamera(0,0,0);
|
||||||
|
|
||||||
|
NLMISC::CVector hotSpot=NLMISC::CVector(0,0,0);
|
||||||
|
|
||||||
|
_MouseListener = _Driver->create3dMouseListener();
|
||||||
|
_MouseListener->setMatrix(Modules::objView().getScene()->getCam().getMatrix());
|
||||||
|
_MouseListener->setFrustrum(Modules::objView().getScene()->getCam().getFrustum());
|
||||||
|
_MouseListener->setHotSpot(hotSpot);
|
||||||
|
_MouseListener->setMouseMode(U3dMouseListener::edit3d);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::release()
|
||||||
{
|
{
|
||||||
|
//H_AUTO2
|
||||||
|
nldebug("CObjectViewer::release");
|
||||||
|
|
||||||
|
Modules::config().dropCallback("BackgroundColor");
|
||||||
|
Modules::config().dropCallback("GraphicsDriver");
|
||||||
|
|
||||||
|
_Driver->delete3dMouseListener(_MouseListener);
|
||||||
|
|
||||||
|
// delete all entities
|
||||||
|
deleteEntities();
|
||||||
|
|
||||||
|
_Scene->deletePlayListManager(_PlayListManager);
|
||||||
|
|
||||||
|
// delete the scene
|
||||||
|
_Driver->deleteScene(_Scene);
|
||||||
|
|
||||||
|
// delete the light
|
||||||
|
delete _Light;
|
||||||
|
|
||||||
|
// release driver
|
||||||
|
nlassert(_Driver);
|
||||||
|
_Driver->release();
|
||||||
|
delete _Driver;
|
||||||
|
_Driver = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::updateInput()
|
||||||
|
{
|
||||||
|
_Driver->EventServer.pump();
|
||||||
|
|
||||||
|
// New matrix from camera
|
||||||
|
_Scene->getCam().setTransformMode(NL3D::UTransformable::DirectMatrix);
|
||||||
|
_Scene->getCam().setMatrix (_MouseListener->getViewMatrix());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::renderDriver()
|
||||||
|
{
|
||||||
|
_Driver->clearBuffers(_BackgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::renderScene()
|
||||||
|
{
|
||||||
|
// render the scene
|
||||||
|
_Scene->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::renderDebug2D()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::saveScreenshot(const std::string &nameFile, bool jpg, bool png, bool tga)
|
||||||
|
{
|
||||||
|
//H_AUTO2
|
||||||
|
|
||||||
|
// FIXME: create screenshot path if it doesn't exist!
|
||||||
|
|
||||||
|
// empty bitmap
|
||||||
|
CBitmap bitmap;
|
||||||
|
// copy the driver buffer to the bitmap
|
||||||
|
_Driver->getBuffer(bitmap);
|
||||||
|
// create the file name
|
||||||
|
string filename = std::string("./") + nameFile;
|
||||||
|
// write the bitmap as a jpg, png or tga to the file
|
||||||
|
if (jpg)
|
||||||
|
{
|
||||||
|
string newfilename = CFile::findNewFile(filename + ".jpg");
|
||||||
|
COFile outputFile(newfilename);
|
||||||
|
bitmap.writeJPG(outputFile, 100);
|
||||||
|
nlinfo("Screenshot '%s' saved", newfilename.c_str());
|
||||||
|
}
|
||||||
|
if (png)
|
||||||
|
{
|
||||||
|
string newfilename = CFile::findNewFile(filename + ".png");
|
||||||
|
COFile outputFile(newfilename);
|
||||||
|
bitmap.writePNG(outputFile, 24);
|
||||||
|
nlinfo("Screenshot '%s' saved", newfilename.c_str());
|
||||||
|
}
|
||||||
|
if (tga)
|
||||||
|
{
|
||||||
|
string newfilename = CFile::findNewFile(filename + ".tga");
|
||||||
|
COFile outputFile(newfilename);
|
||||||
|
bitmap.writeTGA(outputFile, 24, false);
|
||||||
|
nlinfo("Screenshot '%s' saved", newfilename.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CObjectViewer::loadMesh(const std::string &meshFileName, const std::string &skelFileName)
|
||||||
|
{
|
||||||
|
CPath::addSearchPath(CFile::getPath(meshFileName), false, false);
|
||||||
|
|
||||||
|
// create instance of the mesh character
|
||||||
|
UInstance Entity = _Scene->createInstance(meshFileName);
|
||||||
|
|
||||||
|
USkeleton Skeleton = _Scene->createSkeleton(skelFileName);
|
||||||
|
|
||||||
|
// if we can't create entity, skip it
|
||||||
|
if (Entity.empty()) return false;
|
||||||
|
|
||||||
|
// create a new entity
|
||||||
|
EIT eit = (_Entities.insert (make_pair (CFile::getFilenameWithoutExtension(meshFileName), CEntity()))).first;
|
||||||
CEntity &entity = (*eit).second;
|
CEntity &entity = (*eit).second;
|
||||||
deleteEntity(entity);
|
|
||||||
|
// set the entity up
|
||||||
|
entity._Name = CFile::getFilenameWithoutExtension(meshFileName);
|
||||||
|
entity._Instance = Entity;
|
||||||
|
if (!Skeleton.empty())
|
||||||
|
{
|
||||||
|
entity._Skeleton = Skeleton;
|
||||||
|
entity._Skeleton.bindSkin (entity._Instance);
|
||||||
|
}
|
||||||
|
entity._AnimationSet = _Driver->createAnimationSet(false);
|
||||||
|
entity._PlayList = _PlayListManager->createPlayList(entity._AnimationSet);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
_Entities.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewer::cfcbBackgroundColor(NLMISC::CConfigFile::CVar &var)
|
void CObjectViewer::resetScene()
|
||||||
{
|
{
|
||||||
// read variable from config file
|
deleteEntities();
|
||||||
_BackgroundColor = CRGBA(var.asInt(0), var.asInt(1), var.asInt(2));
|
|
||||||
}
|
// Reset camera.
|
||||||
|
//..
|
||||||
|
|
||||||
|
// to load files with the same name but located in different directories
|
||||||
|
//CPath::clearMap();
|
||||||
|
|
||||||
|
// load and set search paths from config
|
||||||
|
//Modules::config().configSearchPaths();
|
||||||
|
|
||||||
|
_CurrentInstance = "";
|
||||||
|
|
||||||
|
nlinfo("Scene cleared");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::updateCamera(float deltaPsi, float deltaPhi, float deltaDist)
|
||||||
|
{
|
||||||
|
_phi += deltaPhi;
|
||||||
|
_psi += deltaPsi;
|
||||||
|
_dist += deltaDist;
|
||||||
|
|
||||||
|
if(_phi < -NLMISC::Pi/2) _phi -= deltaPhi;
|
||||||
|
if(_phi > NLMISC::Pi/2) _phi -= deltaPsi;
|
||||||
|
if (_dist < 1) _dist = 1;
|
||||||
|
|
||||||
|
NLMISC::CQuat q0,q1,q2;
|
||||||
|
NLMISC::CVector up(0,0,1);
|
||||||
|
NLMISC::CVector v(0,0,1);
|
||||||
|
|
||||||
|
q0.setAngleAxis(v,_psi);
|
||||||
|
v = NLMISC::CVector(0,1,0);
|
||||||
|
q1.setAngleAxis(v,_phi);
|
||||||
|
q2 = q0 * q1;
|
||||||
|
NLMISC::CMatrix m0;
|
||||||
|
m0.setRot(q2);
|
||||||
|
NLMISC::CVector camera = m0 * NLMISC::CVector(_dist,0,0);
|
||||||
|
|
||||||
|
_Scene->getCam().lookAt(camera, up);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::setBackgroundColor(NLMISC::CRGBA backgroundColor)
|
||||||
|
{
|
||||||
|
_BackgroundColor = backgroundColor;
|
||||||
|
|
||||||
|
// config file variable changes
|
||||||
|
Modules::config().getConfigFile().getVar("BackgroundColor").setAsInt(_BackgroundColor.R, 0);
|
||||||
|
Modules::config().getConfigFile().getVar("BackgroundColor").setAsInt(_BackgroundColor.G, 1);
|
||||||
|
Modules::config().getConfigFile().getVar("BackgroundColor").setAsInt(_BackgroundColor.B, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::setGraphicsDriver(bool Direct3D)
|
||||||
|
{
|
||||||
|
_Direct3D = Direct3D;
|
||||||
|
|
||||||
|
if (_Direct3D) Modules::config().getConfigFile().getVar("GraphicsDriver").setAsString("Direct3D");
|
||||||
|
else Modules::config().getConfigFile().getVar("GraphicsDriver").setAsString("OpenGL");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::setSizeViewport(uint16 w, uint16 h)
|
||||||
|
{
|
||||||
|
_Scene->getCam().setPerspective((float)Pi/2.f, (float)w/h, 0.1f, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::getSizeViewport(float &left, float &right, float &bottom, float &top, float &znear, float &zfar)
|
||||||
|
{
|
||||||
|
//_Scene->getCam().setPerspective((float)Pi/2.f, (float)w/h, 0.1f, 1000);
|
||||||
|
_Scene->getCam().getFrustum(left, right, bottom, top, znear, zfar);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::setCurrentObject(const std::string &name)
|
||||||
|
{
|
||||||
|
if ((_Entities.count(name) != 0) || ( name.empty() )) _CurrentInstance = name;
|
||||||
|
else nlerror ("Entity %s not found", name.c_str());
|
||||||
|
nlinfo("set current entity %s", _CurrentInstance.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
CEntity& CObjectViewer::getEntity(const std::string &name)
|
||||||
|
{
|
||||||
|
if ( _Entities.count(name) == 0) nlerror("Entity %s not found", name.c_str());
|
||||||
|
EIT eit = _Entities.find (name);
|
||||||
|
return (*eit).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::getListObjects(std::vector<std::string> &listObj)
|
||||||
|
{
|
||||||
|
listObj.clear();
|
||||||
|
for (EIT eit = _Entities.begin(); eit != _Entities.end(); ++eit)
|
||||||
|
listObj.push_back((*eit).second._Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::deleteEntity(CEntity &entity)
|
||||||
|
{
|
||||||
|
if (entity._PlayList != NULL)
|
||||||
|
{
|
||||||
|
_PlayListManager->deletePlayList (entity._PlayList);
|
||||||
|
entity._PlayList = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity._AnimationSet != NULL)
|
||||||
|
{
|
||||||
|
_Driver->deleteAnimationSet(entity._AnimationSet);
|
||||||
|
entity._AnimationSet = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entity._Skeleton.empty())
|
||||||
|
{
|
||||||
|
entity._Skeleton.detachSkeletonSon(entity._Instance);
|
||||||
|
|
||||||
|
_Scene->deleteSkeleton(entity._Skeleton);
|
||||||
|
entity._Skeleton = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entity._Instance.empty())
|
||||||
|
{
|
||||||
|
_Scene->deleteInstance(entity._Instance);
|
||||||
|
entity._Instance = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::deleteEntities()
|
||||||
|
{
|
||||||
|
for (EIT eit = _Entities.begin(); eit != _Entities.end(); ++eit)
|
||||||
|
{
|
||||||
|
CEntity &entity = (*eit).second;
|
||||||
|
deleteEntity(entity);
|
||||||
|
}
|
||||||
|
_Entities.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::cfcbBackgroundColor(NLMISC::CConfigFile::CVar &var)
|
||||||
|
{
|
||||||
|
// read variable from config file
|
||||||
|
_BackgroundColor = CRGBA(var.asInt(0), var.asInt(1), var.asInt(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewer::cfcbGraphicsDriver(NLMISC::CConfigFile::CVar &var)
|
||||||
|
{
|
||||||
|
// Choose driver opengl to work correctly under Linux example
|
||||||
|
_Direct3D = false; //_Driver = OpenGL;
|
||||||
|
|
||||||
void CObjectViewer::cfcbGraphicsDriver(NLMISC::CConfigFile::CVar &var)
|
|
||||||
{
|
|
||||||
// Choose driver opengl to work correctly under Linux example
|
|
||||||
_Direct3D = false; //_Driver = OpenGL;
|
|
||||||
|
|
||||||
#ifdef NL_OS_WINDOWS
|
#ifdef NL_OS_WINDOWS
|
||||||
std::string driver = var.asString();
|
std::string driver = var.asString();
|
||||||
if (driver == "Direct3D") _Direct3D = true; //m_Driver = Direct3D;
|
if (driver == "Direct3D") _Direct3D = true; //m_Driver = Direct3D;
|
||||||
else if (driver == "OpenGL") _Direct3D = false; //m_Driver = OpenGL;
|
else if (driver == "OpenGL") _Direct3D = false; //m_Driver = OpenGL;
|
||||||
else nlwarning("Invalid driver specified, defaulting to OpenGL");
|
else nlwarning("Invalid driver specified, defaulting to OpenGL");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OBJECT_VIEWER_H
|
#ifndef OBJECT_VIEWER_H
|
||||||
|
@ -33,7 +33,8 @@
|
||||||
// Project includes
|
// Project includes
|
||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
|
|
||||||
namespace NL3D {
|
namespace NL3D
|
||||||
|
{
|
||||||
class UDriver;
|
class UDriver;
|
||||||
class UScene;
|
class UScene;
|
||||||
class ULight;
|
class ULight;
|
||||||
|
@ -48,143 +49,144 @@ namespace NL3D {
|
||||||
namespace NLQT
|
namespace NLQT
|
||||||
@brief namespace NLQT
|
@brief namespace NLQT
|
||||||
*/
|
*/
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
|
||||||
/**
|
|
||||||
@class CObjectViewer
|
|
||||||
A CObjectViewer class loading and viewing shape, particle system files.
|
|
||||||
*/
|
|
||||||
class CObjectViewer
|
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
/// Default constructor.
|
|
||||||
CObjectViewer();
|
|
||||||
|
|
||||||
virtual ~CObjectViewer();
|
|
||||||
|
|
||||||
/// Init a driver and create scene.
|
/**
|
||||||
/// @param wnd - handle window.
|
@class CObjectViewer
|
||||||
/// @param w - width window.
|
A CObjectViewer class loading and viewing shape, particle system files.
|
||||||
/// @param h - height window.
|
*/
|
||||||
void init(nlWindow wnd, uint16 w, uint16 h);
|
class CObjectViewer
|
||||||
|
{
|
||||||
void reinit(nlWindow wnd, uint16 w, uint16 h);
|
public:
|
||||||
|
/// Default constructor.
|
||||||
|
CObjectViewer();
|
||||||
|
|
||||||
/// Release class.
|
virtual ~CObjectViewer();
|
||||||
void release();
|
|
||||||
|
|
||||||
/// Update mouse and keyboard events. And update camera matrix.
|
/// Init a driver and create scene.
|
||||||
void updateInput();
|
/// @param wnd - handle window.
|
||||||
|
/// @param w - width window.
|
||||||
/// Render Driver (clear all buffers and set background color).
|
/// @param h - height window.
|
||||||
void renderDriver();
|
void init(nlWindow wnd, uint16 w, uint16 h);
|
||||||
|
|
||||||
/// Render current scene.
|
|
||||||
void renderScene();
|
|
||||||
|
|
||||||
/// Render Debug 2D (stuff for dev).
|
|
||||||
void renderDebug2D();
|
|
||||||
|
|
||||||
/// Make a screenshot of the current scene and save.
|
void reinit(nlWindow wnd, uint16 w, uint16 h);
|
||||||
void saveScreenshot(const std::string &nameFile, bool jpg, bool png, bool tga);
|
|
||||||
|
|
||||||
/// Load a mesh or particle system and add to current scene.
|
|
||||||
/// @param meshFileName - name loading shape or ps file.
|
|
||||||
/// @param skelFileName - name loading skeletin file.
|
|
||||||
/// @return true if file have been loaded, false if file have not been loaded.
|
|
||||||
bool loadMesh (const std::string &meshFileName, const std::string &skelFileName);
|
|
||||||
|
|
||||||
/// Reset current scene.
|
|
||||||
void resetScene();
|
|
||||||
|
|
||||||
/// Update the navigation camera.
|
|
||||||
/// @param deltaPsi - delta angle horizontal (radians).
|
|
||||||
/// @param deltaPhi - delta angle vertical (radians).
|
|
||||||
/// @param deltaDist - delta distance.
|
|
||||||
void updateCamera(float deltaPsi, float deltaPhi, float deltaDist);
|
|
||||||
|
|
||||||
/// Set the background color.
|
|
||||||
/// @param backgroundColor - background color.
|
|
||||||
void setBackgroundColor(NLMISC::CRGBA backgroundColor);
|
|
||||||
|
|
||||||
/// Set type driver.
|
|
||||||
/// @param Direct3D - type driver (true - Direct3D) or (false -OpenGL)
|
|
||||||
void setGraphicsDriver(bool Direct3D);
|
|
||||||
|
|
||||||
/// Set size viewport for correct set perspective
|
|
||||||
/// @param w - width window.
|
|
||||||
/// @param h - height window.
|
|
||||||
void setSizeViewport(uint16 w, uint16 h);
|
|
||||||
void getSizeViewport(float &left, float &right, float &bottom, float &top, float &znear, float &zfar);
|
|
||||||
|
|
||||||
/// Select instance from the scene
|
|
||||||
/// @param name - name instance, "" if no instance edited
|
|
||||||
void setCurrentObject(const std::string &name);
|
|
||||||
|
|
||||||
/// Get current instance from the scene
|
|
||||||
/// @return name current instance, "" if no instance edited
|
|
||||||
const std::string& getCurrentObject() { return _CurrentInstance; }
|
|
||||||
|
|
||||||
/// Get entity from the scene
|
|
||||||
/// @return ref Entity
|
|
||||||
CEntity& getEntity(const std::string &name);
|
|
||||||
|
|
||||||
/// Get full list instances from the scene
|
|
||||||
/// @param listObj - ref of return list instances
|
|
||||||
void getListObjects(std::vector<std::string> &listObj);
|
|
||||||
|
|
||||||
/// Get value background color.
|
|
||||||
/// @return background color.
|
|
||||||
NLMISC::CRGBA getBackgroundColor() { return _BackgroundColor; }
|
|
||||||
|
|
||||||
/// Get type driver.
|
|
||||||
/// @return true if have used Direct3D driver, false OpenGL driver.
|
|
||||||
inline bool getDirect3D() { return _Direct3D; }
|
|
||||||
|
|
||||||
/// Get a pointer to the driver.
|
/// Release class.
|
||||||
/// @return pointer to the driver.
|
void release();
|
||||||
inline NL3D::UDriver *getDriver() { return _Driver; }
|
|
||||||
|
|
||||||
/// Get a pointer to the scene.
|
|
||||||
/// @return pointer to the scene.
|
|
||||||
inline NL3D::UScene *getScene() { return _Scene; }
|
|
||||||
|
|
||||||
/// Get a manager of playlist
|
|
||||||
/// @return pointer to the UPlayListManager
|
|
||||||
inline NL3D::UPlayListManager *getPlayListManager() { return _PlayListManager; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
void deleteEntity (CEntity &entity);
|
|
||||||
|
|
||||||
/// Delete all entities
|
/// Update mouse and keyboard events. And update camera matrix.
|
||||||
void deleteEntities();
|
void updateInput();
|
||||||
|
|
||||||
/// Load background color from config file, intended for CConfiguration.
|
|
||||||
void cfcbBackgroundColor(NLMISC::CConfigFile::CVar &var);
|
|
||||||
void cfcbGraphicsDriver(NLMISC::CConfigFile::CVar &var);
|
|
||||||
|
|
||||||
NLMISC::CRGBA _BackgroundColor;
|
|
||||||
|
|
||||||
NL3D::UDriver *_Driver;
|
/// Render Driver (clear all buffers and set background color).
|
||||||
NL3D::UScene *_Scene;
|
void renderDriver();
|
||||||
NL3D::UPlayListManager *_PlayListManager;
|
|
||||||
NL3D::ULight *_Light;
|
|
||||||
NL3D::UCamera *_Camera;
|
|
||||||
NL3D::U3dMouseListener *_MouseListener;
|
|
||||||
|
|
||||||
// The entities storage
|
/// Render current scene.
|
||||||
CEntities _Entities;
|
void renderScene();
|
||||||
|
|
||||||
/// Camera parameters.
|
|
||||||
float _phi, _psi, _dist;
|
|
||||||
|
|
||||||
bool _Direct3D;
|
|
||||||
|
|
||||||
std::string _CurrentInstance;
|
|
||||||
|
|
||||||
// a temporary solution, and later remove
|
/// Render Debug 2D (stuff for dev).
|
||||||
friend class CAnimationSetDialog;
|
void renderDebug2D();
|
||||||
};/* class CObjectViewer */
|
|
||||||
|
/// Make a screenshot of the current scene and save.
|
||||||
|
void saveScreenshot(const std::string &nameFile, bool jpg, bool png, bool tga);
|
||||||
|
|
||||||
|
/// Load a mesh or particle system and add to current scene.
|
||||||
|
/// @param meshFileName - name loading shape or ps file.
|
||||||
|
/// @param skelFileName - name loading skeletin file.
|
||||||
|
/// @return true if file have been loaded, false if file have not been loaded.
|
||||||
|
bool loadMesh (const std::string &meshFileName, const std::string &skelFileName);
|
||||||
|
|
||||||
|
/// Reset current scene.
|
||||||
|
void resetScene();
|
||||||
|
|
||||||
|
/// Update the navigation camera.
|
||||||
|
/// @param deltaPsi - delta angle horizontal (radians).
|
||||||
|
/// @param deltaPhi - delta angle vertical (radians).
|
||||||
|
/// @param deltaDist - delta distance.
|
||||||
|
void updateCamera(float deltaPsi, float deltaPhi, float deltaDist);
|
||||||
|
|
||||||
|
/// Set the background color.
|
||||||
|
/// @param backgroundColor - background color.
|
||||||
|
void setBackgroundColor(NLMISC::CRGBA backgroundColor);
|
||||||
|
|
||||||
|
/// Set type driver.
|
||||||
|
/// @param Direct3D - type driver (true - Direct3D) or (false -OpenGL)
|
||||||
|
void setGraphicsDriver(bool Direct3D);
|
||||||
|
|
||||||
|
/// Set size viewport for correct set perspective
|
||||||
|
/// @param w - width window.
|
||||||
|
/// @param h - height window.
|
||||||
|
void setSizeViewport(uint16 w, uint16 h);
|
||||||
|
void getSizeViewport(float &left, float &right, float &bottom, float &top, float &znear, float &zfar);
|
||||||
|
|
||||||
|
/// Select instance from the scene
|
||||||
|
/// @param name - name instance, "" if no instance edited
|
||||||
|
void setCurrentObject(const std::string &name);
|
||||||
|
|
||||||
|
/// Get current instance from the scene
|
||||||
|
/// @return name current instance, "" if no instance edited
|
||||||
|
const std::string& getCurrentObject() { return _CurrentInstance; }
|
||||||
|
|
||||||
|
/// Get entity from the scene
|
||||||
|
/// @return ref Entity
|
||||||
|
CEntity& getEntity(const std::string &name);
|
||||||
|
|
||||||
|
/// Get full list instances from the scene
|
||||||
|
/// @param listObj - ref of return list instances
|
||||||
|
void getListObjects(std::vector<std::string> &listObj);
|
||||||
|
|
||||||
|
/// Get value background color.
|
||||||
|
/// @return background color.
|
||||||
|
NLMISC::CRGBA getBackgroundColor() { return _BackgroundColor; }
|
||||||
|
|
||||||
|
/// Get type driver.
|
||||||
|
/// @return true if have used Direct3D driver, false OpenGL driver.
|
||||||
|
inline bool getDirect3D() { return _Direct3D; }
|
||||||
|
|
||||||
|
/// Get a pointer to the driver.
|
||||||
|
/// @return pointer to the driver.
|
||||||
|
inline NL3D::UDriver *getDriver() { return _Driver; }
|
||||||
|
|
||||||
|
/// Get a pointer to the scene.
|
||||||
|
/// @return pointer to the scene.
|
||||||
|
inline NL3D::UScene *getScene() { return _Scene; }
|
||||||
|
|
||||||
|
/// Get a manager of playlist
|
||||||
|
/// @return pointer to the UPlayListManager
|
||||||
|
inline NL3D::UPlayListManager *getPlayListManager() { return _PlayListManager; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void deleteEntity (CEntity &entity);
|
||||||
|
|
||||||
|
/// Delete all entities
|
||||||
|
void deleteEntities();
|
||||||
|
|
||||||
|
/// Load background color from config file, intended for CConfiguration.
|
||||||
|
void cfcbBackgroundColor(NLMISC::CConfigFile::CVar &var);
|
||||||
|
void cfcbGraphicsDriver(NLMISC::CConfigFile::CVar &var);
|
||||||
|
|
||||||
|
NLMISC::CRGBA _BackgroundColor;
|
||||||
|
|
||||||
|
NL3D::UDriver *_Driver;
|
||||||
|
NL3D::UScene *_Scene;
|
||||||
|
NL3D::UPlayListManager *_PlayListManager;
|
||||||
|
NL3D::ULight *_Light;
|
||||||
|
NL3D::UCamera *_Camera;
|
||||||
|
NL3D::U3dMouseListener *_MouseListener;
|
||||||
|
|
||||||
|
// The entities storage
|
||||||
|
CEntities _Entities;
|
||||||
|
|
||||||
|
/// Camera parameters.
|
||||||
|
float _phi, _psi, _dist;
|
||||||
|
|
||||||
|
bool _Direct3D;
|
||||||
|
|
||||||
|
std::string _CurrentInstance;
|
||||||
|
|
||||||
|
// a temporary solution, and later remove
|
||||||
|
friend class CAnimationSetDialog;
|
||||||
|
};/* class CObjectViewer */
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "objectviewer_dialog.h"
|
#include "objectviewer_dialog.h"
|
||||||
|
@ -39,370 +39,377 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace NL3D;
|
using namespace NL3D;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
|
||||||
CObjectViewerDialog::CObjectViewerDialog(QWidget *parent)
|
|
||||||
: _isGraphicsInitialized(false), _isGraphicsEnabled(false), QDockWidget(parent)
|
|
||||||
{
|
{
|
||||||
_ui.setupUi(this);
|
|
||||||
|
|
||||||
//widget = new QWidget(dockWidgetContents);
|
CObjectViewerDialog::CObjectViewerDialog(QWidget *parent)
|
||||||
//widget->setObjectName(QString::fromUtf8("widget"));
|
: _isGraphicsInitialized(false), _isGraphicsEnabled(false), QDockWidget(parent)
|
||||||
|
{
|
||||||
|
_ui.setupUi(this);
|
||||||
|
|
||||||
_nlw = new QNLWidget(_ui.dockWidgetContents);
|
//widget = new QWidget(dockWidgetContents);
|
||||||
_nlw->setObjectName(QString::fromUtf8("nlwidget"));
|
//widget->setObjectName(QString::fromUtf8("widget"));
|
||||||
_ui.gridLayout->addWidget(_nlw, 0, 0, 1, 1);
|
|
||||||
//nlw->setLayout(new QGridLayout(nlw));
|
|
||||||
//_ui.widget = nlw;
|
|
||||||
//QWidget * w = widget();
|
|
||||||
|
|
||||||
_isGraphicsEnabled = true;
|
|
||||||
|
|
||||||
// As a special case, a QTimer with a timeout of 0 will time out as soon as all the events in the window system's event queue have been processed.
|
_nlw = new QNLWidget(_ui.dockWidgetContents);
|
||||||
// This can be used to do heavy work while providing a snappy user interface.
|
_nlw->setObjectName(QString::fromUtf8("nlwidget"));
|
||||||
_mainTimer = new QTimer(this);
|
_ui.gridLayout->addWidget(_nlw, 0, 0, 1, 1);
|
||||||
connect(_mainTimer, SIGNAL(timeout()), this, SLOT(updateRender()));
|
//nlw->setLayout(new QGridLayout(nlw));
|
||||||
// timer->start(); // <- timeout 0
|
//_ui.widget = nlw;
|
||||||
// it's heavy on cpu, though, when no 3d driver initialized :)
|
//QWidget * w = widget();
|
||||||
_mainTimer->start(5); // 25fps
|
|
||||||
}
|
|
||||||
|
|
||||||
CObjectViewerDialog::~CObjectViewerDialog() {
|
_isGraphicsEnabled = true;
|
||||||
_mainTimer->stop();
|
|
||||||
}
|
// As a special case, a QTimer with a timeout of 0 will time out as soon as all the events in the window system's event queue have been processed.
|
||||||
|
// This can be used to do heavy work while providing a snappy user interface.
|
||||||
|
_mainTimer = new QTimer(this);
|
||||||
|
connect(_mainTimer, SIGNAL(timeout()), this, SLOT(updateRender()));
|
||||||
|
// timer->start(); // <- timeout 0
|
||||||
|
// it's heavy on cpu, though, when no 3d driver initialized :)
|
||||||
|
_mainTimer->start(5); // 25fps
|
||||||
|
}
|
||||||
|
|
||||||
|
CObjectViewerDialog::~CObjectViewerDialog()
|
||||||
|
{
|
||||||
|
_mainTimer->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewerDialog::init()
|
||||||
|
{
|
||||||
|
connect(this, SIGNAL(topLevelChanged(bool)),
|
||||||
|
this, SLOT(topLevelChanged(bool)));
|
||||||
|
//H_AUTO2
|
||||||
|
nldebug("CObjectViewerDialog::init %d",_nlw->winId());
|
||||||
|
|
||||||
void CObjectViewerDialog::init()
|
|
||||||
{
|
|
||||||
connect(this, SIGNAL(topLevelChanged(bool)),
|
|
||||||
this, SLOT(topLevelChanged(bool)));
|
|
||||||
//H_AUTO2
|
|
||||||
nldebug("CObjectViewerDialog::init %d",_nlw->winId());
|
|
||||||
|
|
||||||
#ifdef NL_OS_UNIX
|
#ifdef NL_OS_UNIX
|
||||||
dynamic_cast<QNLWidget*>(widget())->makeCurrent();
|
dynamic_cast<QNLWidget*>(widget())->makeCurrent();
|
||||||
#endif // NL_OS_UNIX
|
#endif // NL_OS_UNIX
|
||||||
|
|
||||||
Modules::objView().init((nlWindow)_nlw->winId(), 20, 20);
|
|
||||||
setMouseTracking(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewerDialog::setVisible(bool visible)
|
Modules::objView().init((nlWindow)_nlw->winId(), 20, 20);
|
||||||
{
|
setMouseTracking(true);
|
||||||
// called by show()
|
|
||||||
// code assuming visible window needed to init the 3d driver
|
|
||||||
if (visible != isVisible())
|
|
||||||
{
|
|
||||||
if (visible)
|
|
||||||
{
|
|
||||||
QDockWidget::setVisible(true);
|
|
||||||
updateInitialization(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
updateInitialization(false);
|
|
||||||
QDockWidget::setVisible(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewerDialog::updateInitialization(bool visible)
|
void CObjectViewerDialog::setVisible(bool visible)
|
||||||
{
|
|
||||||
//nldebug("CMainWindow::updateInitialization");
|
|
||||||
bool done;
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
done = true; // set false whenever change
|
// called by show()
|
||||||
bool wantGraphics = _isGraphicsEnabled && visible;
|
// code assuming visible window needed to init the 3d driver
|
||||||
// bool wantLandscape = wantGraphics && m_IsGraphicsInitialized && isLandscapeEnabled;
|
if (visible != isVisible())
|
||||||
|
|
||||||
// .. stuff that depends on other stuff goes on top to prioritize deinitialization
|
|
||||||
|
|
||||||
// Landscape
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// Graphics (Driver)
|
|
||||||
if (_isGraphicsInitialized)
|
|
||||||
{
|
{
|
||||||
if (!wantGraphics)
|
if (visible)
|
||||||
{
|
{
|
||||||
_isGraphicsInitialized = false;
|
QDockWidget::setVisible(true);
|
||||||
release();
|
updateInitialization(true);
|
||||||
_mainTimer->stop();
|
|
||||||
done = false;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (wantGraphics)
|
|
||||||
{
|
{
|
||||||
init();
|
updateInitialization(false);
|
||||||
_isGraphicsInitialized = true;
|
QDockWidget::setVisible(false);
|
||||||
_mainTimer->start(5);
|
|
||||||
done = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewerDialog::updateInitialization(bool visible)
|
||||||
} while (!done);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewerDialog::updateRender()
|
|
||||||
{
|
|
||||||
//nldebug("CMainWindow::updateRender");
|
|
||||||
updateInitialization(isVisible());
|
|
||||||
|
|
||||||
//QModelIndex index = _dirModel->setRootPath("D:/Dev/Ryzom/code/ryzom/common/data_leveldesign/leveldesign");
|
|
||||||
//_dirTree->setRootIndex(index);
|
|
||||||
|
|
||||||
if (isVisible())
|
|
||||||
{
|
{
|
||||||
// call all update functions
|
//nldebug("CMainWindow::updateInitialization");
|
||||||
// 01. Update Utilities (configuration etc)
|
bool done;
|
||||||
|
do
|
||||||
// 02. Update Time (deltas)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 03. Update Receive (network, servertime, receive messages)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 04. Update Input (keyboard controls, etc)
|
|
||||||
if (_isGraphicsInitialized)
|
|
||||||
Modules::objView().updateInput();
|
|
||||||
|
|
||||||
// 05. Update Weather (sky, snow, wind, fog, sun)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 06. Update Entities (movement, do after possible tp from incoming messages etc)
|
|
||||||
// - Move other entities
|
|
||||||
// - Update self entity
|
|
||||||
// - Move bullets
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 07. Update Landscape (async zone loading near entity)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 08. Update Collisions (entities)
|
|
||||||
// - Update entities
|
|
||||||
// - Update move container (swap with Update entities? todo: check code!)
|
|
||||||
// - Update bullets
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 09. Update Animations (playlists)
|
|
||||||
// - Needs to be either before or after entities, not sure,
|
|
||||||
// there was a problem with wrong order a while ago!!!
|
|
||||||
|
|
||||||
|
|
||||||
//Modules::objView().updateAnimation(_AnimationDialog->getTime());
|
|
||||||
|
|
||||||
// 10. Update Camera (depends on entities)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 11. Update Interface (login, ui, etc)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 12. Update Sound (sound driver)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 13. Update Send (network, send new position etc)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 14. Update Debug (stuff for dev)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
if (_isGraphicsInitialized && !Modules::objView().getDriver()->isLost())
|
|
||||||
{
|
{
|
||||||
// 01. Render Driver (background color)
|
done = true; // set false whenever change
|
||||||
Modules::objView().renderDriver(); // clear all buffers
|
bool wantGraphics = _isGraphicsEnabled && visible;
|
||||||
|
// bool wantLandscape = wantGraphics && m_IsGraphicsInitialized && isLandscapeEnabled;
|
||||||
// 02. Render Sky (sky scene)
|
|
||||||
// ...
|
// .. stuff that depends on other stuff goes on top to prioritize deinitialization
|
||||||
|
|
||||||
// 04. Render Scene (entity scene)
|
// Landscape
|
||||||
Modules::objView().renderScene();
|
|
||||||
|
|
||||||
// 05. Render Effects (flare)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// 06. Render Interface 3D (player names)
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
// 07. Render Debug 3D
|
// Graphics (Driver)
|
||||||
|
if (_isGraphicsInitialized)
|
||||||
|
{
|
||||||
|
if (!wantGraphics)
|
||||||
|
{
|
||||||
|
_isGraphicsInitialized = false;
|
||||||
|
release();
|
||||||
|
_mainTimer->stop();
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (wantGraphics)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
_isGraphicsInitialized = true;
|
||||||
|
_mainTimer->start(5);
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} while (!done);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewerDialog::updateRender()
|
||||||
|
{
|
||||||
|
//nldebug("CMainWindow::updateRender");
|
||||||
|
updateInitialization(isVisible());
|
||||||
|
|
||||||
|
//QModelIndex index = _dirModel->setRootPath("D:/Dev/Ryzom/code/ryzom/common/data_leveldesign/leveldesign");
|
||||||
|
//_dirTree->setRootIndex(index);
|
||||||
|
|
||||||
|
if (isVisible())
|
||||||
|
{
|
||||||
|
// call all update functions
|
||||||
|
// 01. Update Utilities (configuration etc)
|
||||||
|
|
||||||
|
// 02. Update Time (deltas)
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
// 08. Render Interface 2D (chatboxes etc, optionally does have 3d)
|
// 03. Update Receive (network, servertime, receive messages)
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
// 09. Render Debug 2D (stuff for dev)
|
|
||||||
Modules::objView().renderDebug2D();
|
|
||||||
|
|
||||||
// swap 3d buffers
|
// 04. Update Input (keyboard controls, etc)
|
||||||
Modules::objView().getDriver()->swapBuffers();
|
if (_isGraphicsInitialized)
|
||||||
|
Modules::objView().updateInput();
|
||||||
|
|
||||||
|
// 05. Update Weather (sky, snow, wind, fog, sun)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 06. Update Entities (movement, do after possible tp from incoming messages etc)
|
||||||
|
// - Move other entities
|
||||||
|
// - Update self entity
|
||||||
|
// - Move bullets
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 07. Update Landscape (async zone loading near entity)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 08. Update Collisions (entities)
|
||||||
|
// - Update entities
|
||||||
|
// - Update move container (swap with Update entities? todo: check code!)
|
||||||
|
// - Update bullets
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 09. Update Animations (playlists)
|
||||||
|
// - Needs to be either before or after entities, not sure,
|
||||||
|
// there was a problem with wrong order a while ago!!!
|
||||||
|
|
||||||
|
|
||||||
|
//Modules::objView().updateAnimation(_AnimationDialog->getTime());
|
||||||
|
|
||||||
|
// 10. Update Camera (depends on entities)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 11. Update Interface (login, ui, etc)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 12. Update Sound (sound driver)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 13. Update Send (network, send new position etc)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 14. Update Debug (stuff for dev)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
if (_isGraphicsInitialized && !Modules::objView().getDriver()->isLost())
|
||||||
|
{
|
||||||
|
// 01. Render Driver (background color)
|
||||||
|
Modules::objView().renderDriver(); // clear all buffers
|
||||||
|
|
||||||
|
// 02. Render Sky (sky scene)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 04. Render Scene (entity scene)
|
||||||
|
Modules::objView().renderScene();
|
||||||
|
|
||||||
|
// 05. Render Effects (flare)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 06. Render Interface 3D (player names)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 07. Render Debug 3D
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 08. Render Interface 2D (chatboxes etc, optionally does have 3d)
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// 09. Render Debug 2D (stuff for dev)
|
||||||
|
Modules::objView().renderDebug2D();
|
||||||
|
|
||||||
|
// swap 3d buffers
|
||||||
|
Modules::objView().getDriver()->swapBuffers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewerDialog::release()
|
void CObjectViewerDialog::release()
|
||||||
{
|
{
|
||||||
//H_AUTO2
|
//H_AUTO2
|
||||||
nldebug("CObjectViewerDialog::release");
|
nldebug("CObjectViewerDialog::release");
|
||||||
|
|
||||||
Modules::objView().release();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewerDialog::reinit()
|
Modules::objView().release();
|
||||||
{
|
}
|
||||||
//H_AUTO2
|
|
||||||
nldebug("CObjectViewerDialog::reinit");
|
|
||||||
|
|
||||||
Modules::objView().release();
|
|
||||||
//Modules::objView().reinit(_ui.frame->winId(), width(), height());
|
|
||||||
}
|
|
||||||
|
|
||||||
QAction *CObjectViewerDialog::createSaveScreenshotAction(QObject *parent)
|
void CObjectViewerDialog::reinit()
|
||||||
{
|
{
|
||||||
QAction *action = new QAction(parent);
|
//H_AUTO2
|
||||||
connect(action, SIGNAL(triggered()), this, SLOT(saveScreenshot()));
|
nldebug("CObjectViewerDialog::reinit");
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
QAction *CObjectViewerDialog::createSetBackgroundColor(QObject *parent)
|
Modules::objView().release();
|
||||||
{
|
//Modules::objView().reinit(_ui.frame->winId(), width(), height());
|
||||||
QAction *action = new QAction(parent);
|
}
|
||||||
connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundColor()));
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewerDialog::saveScreenshot()
|
QAction *CObjectViewerDialog::createSaveScreenshotAction(QObject *parent)
|
||||||
{
|
{
|
||||||
Modules::objView().saveScreenshot("screenshot", false, true, false);
|
QAction *action = new QAction(parent);
|
||||||
}
|
connect(action, SIGNAL(triggered()), this, SLOT(saveScreenshot()));
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
void CObjectViewerDialog::setBackgroundColor()
|
QAction *CObjectViewerDialog::createSetBackgroundColor(QObject *parent)
|
||||||
{
|
{
|
||||||
QColor color = QColorDialog::getColor(QColor(Modules::objView().getBackgroundColor().R,
|
QAction *action = new QAction(parent);
|
||||||
Modules::objView().getBackgroundColor().G,
|
connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundColor()));
|
||||||
Modules::objView().getBackgroundColor().B));
|
return action;
|
||||||
Modules::objView().setBackgroundColor(NLMISC::CRGBA(color.red(), color.green(), color.blue()));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewerDialog::topLevelChanged ( bool topLevel ) {
|
void CObjectViewerDialog::saveScreenshot()
|
||||||
//nldebug("CObjectViewerDialog::topLevelChanged topLevel:%d",topLevel);
|
{
|
||||||
nldebug("CObjectViewerDialog::topLevelChanged winId:%d",winId());
|
Modules::objView().saveScreenshot("screenshot", false, true, false);
|
||||||
// winId changing when re/docking
|
}
|
||||||
//Modules::georges().init();
|
|
||||||
Modules::objView().reinit((nlWindow)_nlw->winId(), _nlw->width(), _nlw->height());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewerDialog::resizeEvent(QResizeEvent *resizeEvent)
|
void CObjectViewerDialog::setBackgroundColor()
|
||||||
{
|
{
|
||||||
QDockWidget::resizeEvent(resizeEvent);
|
QColor color = QColorDialog::getColor(QColor(Modules::objView().getBackgroundColor().R,
|
||||||
if (Modules::objView().getDriver())
|
Modules::objView().getBackgroundColor().G,
|
||||||
Modules::objView().setSizeViewport(resizeEvent->size().width(), resizeEvent->size().height());
|
Modules::objView().getBackgroundColor().B));
|
||||||
|
Modules::objView().setBackgroundColor(NLMISC::CRGBA(color.red(), color.green(), color.blue()));
|
||||||
|
}
|
||||||
|
|
||||||
// The OpenGL driver does not resize automatically.
|
void CObjectViewerDialog::topLevelChanged ( bool topLevel ) {
|
||||||
// The Direct3D driver breaks the window mode to include window borders when calling setMode windowed.
|
//nldebug("CObjectViewerDialog::topLevelChanged topLevel:%d",topLevel);
|
||||||
|
nldebug("CObjectViewerDialog::topLevelChanged winId:%d",winId());
|
||||||
|
// winId changing when re/docking
|
||||||
|
//Modules::georges().init();
|
||||||
|
Modules::objView().reinit((nlWindow)_nlw->winId(), _nlw->width(), _nlw->height());
|
||||||
|
}
|
||||||
|
|
||||||
// Resizing the window after switching drivers a few times becomes slow.
|
void CObjectViewerDialog::resizeEvent(QResizeEvent *resizeEvent)
|
||||||
// There is probably something inside the drivers not being released properly.
|
{
|
||||||
}
|
QDockWidget::resizeEvent(resizeEvent);
|
||||||
|
if (Modules::objView().getDriver())
|
||||||
|
Modules::objView().setSizeViewport(resizeEvent->size().width(), resizeEvent->size().height());
|
||||||
|
|
||||||
void CObjectViewerDialog::wheelEvent(QWheelEvent *event)
|
// The OpenGL driver does not resize automatically.
|
||||||
{
|
// The Direct3D driver breaks the window mode to include window borders when calling setMode windowed.
|
||||||
//nldebug("CObjectViewerDialog::wheelEvent");
|
|
||||||
// Get relative positions.
|
|
||||||
float fX = 1.0f - (float)event->pos().x() / this->width();
|
|
||||||
float fY = 1.0f - (float)event->pos().y() / this->height();
|
|
||||||
|
|
||||||
// Set the buttons currently pressed.
|
|
||||||
NLMISC::TMouseButton buttons = (NLMISC::TMouseButton)getNelButtons(event);
|
|
||||||
if(event->delta() > 0)
|
|
||||||
Modules::objView().getDriver()->EventServer.postEvent(new NLMISC::CEventMouseWheel(-fX, fY, buttons, true, this));
|
|
||||||
else
|
|
||||||
Modules::objView().getDriver()->EventServer.postEvent(new NLMISC::CEventMouseWheel(-fX, fY, buttons, false, this));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 CObjectViewerDialog::getNelButtons(QMouseEvent *event) {
|
// Resizing the window after switching drivers a few times becomes slow.
|
||||||
//nldebug("CObjectViewerDialog::getNelButtons");
|
// There is probably something inside the drivers not being released properly.
|
||||||
uint32 buttons = NLMISC::noButton;
|
}
|
||||||
if(event->buttons() & Qt::LeftButton) buttons |= NLMISC::leftButton;
|
|
||||||
if(event->buttons() & Qt::RightButton) buttons |= NLMISC::rightButton;
|
|
||||||
if(event->buttons() & Qt::MidButton) buttons |= NLMISC::middleButton;
|
|
||||||
if(event->modifiers() & Qt::ControlModifier) buttons |= NLMISC::ctrlButton;
|
|
||||||
if(event->modifiers() & Qt::ShiftModifier) buttons |= NLMISC::shiftButton;
|
|
||||||
if(event->modifiers() & Qt::AltModifier) buttons |= NLMISC::altButton;
|
|
||||||
|
|
||||||
return buttons;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 CObjectViewerDialog::getNelButtons(QWheelEvent *event) {
|
void CObjectViewerDialog::wheelEvent(QWheelEvent *event)
|
||||||
//nldebug("CObjectViewerDialog::getNelButtons");
|
{
|
||||||
uint32 buttons = NLMISC::noButton;
|
//nldebug("CObjectViewerDialog::wheelEvent");
|
||||||
if(event->buttons() & Qt::LeftButton) buttons |= NLMISC::leftButton;
|
// Get relative positions.
|
||||||
if(event->buttons() & Qt::RightButton) buttons |= NLMISC::rightButton;
|
float fX = 1.0f - (float)event->pos().x() / this->width();
|
||||||
if(event->buttons() & Qt::MidButton) buttons |= NLMISC::middleButton;
|
float fY = 1.0f - (float)event->pos().y() / this->height();
|
||||||
if(event->modifiers() & Qt::ControlModifier) buttons |= NLMISC::ctrlButton;
|
|
||||||
if(event->modifiers() & Qt::ShiftModifier) buttons |= NLMISC::shiftButton;
|
|
||||||
if(event->modifiers() & Qt::AltModifier) buttons |= NLMISC::altButton;
|
|
||||||
|
|
||||||
return buttons;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CObjectViewerDialog::mousePressEvent(QMouseEvent *event) {
|
|
||||||
//nldebug("CObjectViewerDialog::mousePressEvent");
|
|
||||||
// Get relative positions.
|
|
||||||
float fX = 1.0f - (float)event->pos().x() / this->width();
|
|
||||||
float fY = 1.0f - (float)event->pos().y() / this->height();
|
|
||||||
|
|
||||||
// Set the buttons currently pressed.
|
|
||||||
NLMISC::TMouseButton buttons = (NLMISC::TMouseButton)getNelButtons(event);
|
|
||||||
|
|
||||||
if(event->button() == Qt::LeftButton)
|
// Set the buttons currently pressed.
|
||||||
Modules::objView().getDriver()->EventServer.postEvent(
|
NLMISC::TMouseButton buttons = (NLMISC::TMouseButton)getNelButtons(event);
|
||||||
|
if(event->delta() > 0)
|
||||||
|
Modules::objView().getDriver()->EventServer.postEvent(new NLMISC::CEventMouseWheel(-fX, fY, buttons, true, this));
|
||||||
|
else
|
||||||
|
Modules::objView().getDriver()->EventServer.postEvent(new NLMISC::CEventMouseWheel(-fX, fY, buttons, false, this));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 CObjectViewerDialog::getNelButtons(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
//nldebug("CObjectViewerDialog::getNelButtons");
|
||||||
|
uint32 buttons = NLMISC::noButton;
|
||||||
|
if(event->buttons() & Qt::LeftButton) buttons |= NLMISC::leftButton;
|
||||||
|
if(event->buttons() & Qt::RightButton) buttons |= NLMISC::rightButton;
|
||||||
|
if(event->buttons() & Qt::MidButton) buttons |= NLMISC::middleButton;
|
||||||
|
if(event->modifiers() & Qt::ControlModifier) buttons |= NLMISC::ctrlButton;
|
||||||
|
if(event->modifiers() & Qt::ShiftModifier) buttons |= NLMISC::shiftButton;
|
||||||
|
if(event->modifiers() & Qt::AltModifier) buttons |= NLMISC::altButton;
|
||||||
|
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 CObjectViewerDialog::getNelButtons(QWheelEvent *event)
|
||||||
|
{
|
||||||
|
//nldebug("CObjectViewerDialog::getNelButtons");
|
||||||
|
uint32 buttons = NLMISC::noButton;
|
||||||
|
if(event->buttons() & Qt::LeftButton) buttons |= NLMISC::leftButton;
|
||||||
|
if(event->buttons() & Qt::RightButton) buttons |= NLMISC::rightButton;
|
||||||
|
if(event->buttons() & Qt::MidButton) buttons |= NLMISC::middleButton;
|
||||||
|
if(event->modifiers() & Qt::ControlModifier) buttons |= NLMISC::ctrlButton;
|
||||||
|
if(event->modifiers() & Qt::ShiftModifier) buttons |= NLMISC::shiftButton;
|
||||||
|
if(event->modifiers() & Qt::AltModifier) buttons |= NLMISC::altButton;
|
||||||
|
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CObjectViewerDialog::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
//nldebug("CObjectViewerDialog::mousePressEvent");
|
||||||
|
// Get relative positions.
|
||||||
|
float fX = 1.0f - (float)event->pos().x() / this->width();
|
||||||
|
float fY = 1.0f - (float)event->pos().y() / this->height();
|
||||||
|
|
||||||
|
// Set the buttons currently pressed.
|
||||||
|
NLMISC::TMouseButton buttons = (NLMISC::TMouseButton)getNelButtons(event);
|
||||||
|
|
||||||
|
if(event->button() == Qt::LeftButton)
|
||||||
|
Modules::objView().getDriver()->EventServer.postEvent(
|
||||||
new NLMISC::CEventMouseDown( -fX, fY,
|
new NLMISC::CEventMouseDown( -fX, fY,
|
||||||
(NLMISC::TMouseButton)(NLMISC::leftButton|(buttons&~(NLMISC::leftButton|NLMISC::middleButton|NLMISC::rightButton))), this));
|
(NLMISC::TMouseButton)(NLMISC::leftButton|(buttons&~(NLMISC::leftButton|NLMISC::middleButton|NLMISC::rightButton))), this));
|
||||||
if(event->button() == Qt::MidButton)
|
if(event->button() == Qt::MidButton)
|
||||||
Modules::objView().getDriver()->EventServer.postEvent(
|
Modules::objView().getDriver()->EventServer.postEvent(
|
||||||
new NLMISC::CEventMouseDown( -fX, fY,
|
new NLMISC::CEventMouseDown( -fX, fY,
|
||||||
(NLMISC::TMouseButton)(NLMISC::middleButton|(buttons&~(NLMISC::middleButton|NLMISC::leftButton|NLMISC::rightButton))), this));
|
(NLMISC::TMouseButton)(NLMISC::middleButton|(buttons&~(NLMISC::middleButton|NLMISC::leftButton|NLMISC::rightButton))), this));
|
||||||
if(event->button() == Qt::RightButton)
|
if(event->button() == Qt::RightButton)
|
||||||
Modules::objView().getDriver()->EventServer.postEvent(
|
Modules::objView().getDriver()->EventServer.postEvent(
|
||||||
new NLMISC::CEventMouseDown( -fX, fY,
|
new NLMISC::CEventMouseDown( -fX, fY,
|
||||||
(NLMISC::TMouseButton)(NLMISC::rightButton|(buttons&~(NLMISC::rightButton|NLMISC::leftButton|NLMISC::middleButton))), this));
|
(NLMISC::TMouseButton)(NLMISC::rightButton|(buttons&~(NLMISC::rightButton|NLMISC::leftButton|NLMISC::middleButton))), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CObjectViewerDialog::mouseReleaseEvent(QMouseEvent *event) {
|
void CObjectViewerDialog::mouseReleaseEvent(QMouseEvent *event)
|
||||||
//nldebug("CObjectViewerDialog::mouseReleaseEvent");
|
{
|
||||||
// Get relative positions.
|
//nldebug("CObjectViewerDialog::mouseReleaseEvent");
|
||||||
float fX = 1.0f - (float)event->pos().x() / this->width();
|
// Get relative positions.
|
||||||
float fY = 1.0f - (float)event->pos().y() / this->height();
|
float fX = 1.0f - (float)event->pos().x() / this->width();
|
||||||
|
float fY = 1.0f - (float)event->pos().y() / this->height();
|
||||||
// Set the buttons currently pressed.
|
|
||||||
NLMISC::TMouseButton buttons = (NLMISC::TMouseButton)getNelButtons(event);
|
|
||||||
|
|
||||||
if(event->button() == Qt::LeftButton)
|
// Set the buttons currently pressed.
|
||||||
Modules::objView().getDriver()->EventServer.postEvent(
|
NLMISC::TMouseButton buttons = (NLMISC::TMouseButton)getNelButtons(event);
|
||||||
|
|
||||||
|
if(event->button() == Qt::LeftButton)
|
||||||
|
Modules::objView().getDriver()->EventServer.postEvent(
|
||||||
new NLMISC::CEventMouseUp( -fX, fY, NLMISC::leftButton, this));
|
new NLMISC::CEventMouseUp( -fX, fY, NLMISC::leftButton, this));
|
||||||
if(event->button() == Qt::MidButton)
|
if(event->button() == Qt::MidButton)
|
||||||
Modules::objView().getDriver()->EventServer.postEvent(
|
Modules::objView().getDriver()->EventServer.postEvent(
|
||||||
new NLMISC::CEventMouseUp( -fX, fY, NLMISC::middleButton, this));
|
new NLMISC::CEventMouseUp( -fX, fY, NLMISC::middleButton, this));
|
||||||
if(event->button() == Qt::RightButton)
|
if(event->button() == Qt::RightButton)
|
||||||
Modules::objView().getDriver()->EventServer.postEvent(
|
Modules::objView().getDriver()->EventServer.postEvent(
|
||||||
new NLMISC::CEventMouseUp( -fX, fY, NLMISC::rightButton, this));
|
new NLMISC::CEventMouseUp( -fX, fY, NLMISC::rightButton, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CObjectViewerDialog::mouseMoveEvent(QMouseEvent *event) {
|
void CObjectViewerDialog::mouseMoveEvent(QMouseEvent *event)
|
||||||
//nldebug("CObjectViewerDialog::mouseMoveEvent");
|
{
|
||||||
// Get relative positions.
|
//nldebug("CObjectViewerDialog::mouseMoveEvent");
|
||||||
float fX = 1.0f - (float)event->pos().x() / this->width();
|
// Get relative positions.
|
||||||
float fY = 1.0f - (float)event->pos().y() / this->height();
|
float fX = 1.0f - (float)event->pos().x() / this->width();
|
||||||
|
float fY = 1.0f - (float)event->pos().y() / this->height();
|
||||||
if ((fX == 0.5f) && (fY == 0.5f)) return;
|
|
||||||
NLMISC::TMouseButton buttons = (NLMISC::TMouseButton)getNelButtons(event);
|
if ((fX == 0.5f) && (fY == 0.5f)) return;
|
||||||
Modules::objView().getDriver()->EventServer.postEvent(new NLMISC::CEventMouseMove(-fX, fY, buttons, this));
|
NLMISC::TMouseButton buttons = (NLMISC::TMouseButton)getNelButtons(event);
|
||||||
}
|
Modules::objView().getDriver()->EventServer.postEvent(new NLMISC::CEventMouseMove(-fX, fY, buttons, this));
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OBJECTVIEWER_DIALOG_H
|
#ifndef OBJECTVIEWER_DIALOG_H
|
||||||
|
@ -45,63 +45,64 @@ typedef QGLWidget QNLWidget;
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
|
||||||
class CObjectViewerDialog: public QDockWidget, public NLMISC::IEventEmitter
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
class CObjectViewerDialog: public QDockWidget, public NLMISC::IEventEmitter
|
||||||
CObjectViewerDialog(QWidget *parent = 0);
|
{
|
||||||
~CObjectViewerDialog();
|
Q_OBJECT
|
||||||
|
|
||||||
virtual void setVisible(bool visible);
|
public:
|
||||||
// virtual QPaintEngine* paintEngine() const { return NULL; }
|
CObjectViewerDialog(QWidget *parent = 0);
|
||||||
|
~CObjectViewerDialog();
|
||||||
|
|
||||||
void init();
|
virtual void setVisible(bool visible);
|
||||||
void release();
|
// virtual QPaintEngine* paintEngine() const { return NULL; }
|
||||||
void reinit();
|
|
||||||
|
|
||||||
QAction *createSaveScreenshotAction(QObject *parent);
|
void init();
|
||||||
QAction *createSetBackgroundColor(QObject *parent);
|
void release();
|
||||||
|
void reinit();
|
||||||
|
|
||||||
private Q_SLOTS:
|
QAction *createSaveScreenshotAction(QObject *parent);
|
||||||
void updateRender();
|
QAction *createSetBackgroundColor(QObject *parent);
|
||||||
|
|
||||||
void saveScreenshot();
|
private Q_SLOTS:
|
||||||
void setBackgroundColor();
|
void updateRender();
|
||||||
|
|
||||||
void submitEvents(NLMISC::CEventServer &server, bool allWindows) { };
|
void saveScreenshot();
|
||||||
void emulateMouseRawMode(bool) { };
|
void setBackgroundColor();
|
||||||
|
|
||||||
void topLevelChanged(bool topLevel);
|
void submitEvents(NLMISC::CEventServer &server, bool allWindows) { };
|
||||||
|
void emulateMouseRawMode(bool) { };
|
||||||
|
|
||||||
protected:
|
void topLevelChanged(bool topLevel);
|
||||||
virtual void resizeEvent(QResizeEvent *resizeEvent);
|
|
||||||
virtual void mousePressEvent(QMouseEvent *event);
|
|
||||||
virtual void mouseReleaseEvent(QMouseEvent *event);
|
|
||||||
virtual void wheelEvent(QWheelEvent *event);
|
|
||||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
|
||||||
|
|
||||||
uint32 getNelButtons(QMouseEvent *event);
|
|
||||||
uint32 getNelButtons(QWheelEvent *event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
CObjectViewerDialog(const CObjectViewerDialog &);
|
|
||||||
CObjectViewerDialog &operator=(const CObjectViewerDialog &);
|
|
||||||
|
|
||||||
void updateInitialization(bool visible);
|
protected:
|
||||||
|
virtual void resizeEvent(QResizeEvent *resizeEvent);
|
||||||
|
virtual void mousePressEvent(QMouseEvent *event);
|
||||||
|
virtual void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
virtual void wheelEvent(QWheelEvent *event);
|
||||||
|
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
|
||||||
Ui::CObjectViewerDialog _ui;
|
uint32 getNelButtons(QMouseEvent *event);
|
||||||
|
uint32 getNelButtons(QWheelEvent *event);
|
||||||
// render stuff
|
|
||||||
QTimer *_mainTimer;
|
|
||||||
bool _isGraphicsInitialized, _isGraphicsEnabled;
|
|
||||||
|
|
||||||
QNLWidget * _nlw;
|
private:
|
||||||
|
CObjectViewerDialog(const CObjectViewerDialog &);
|
||||||
|
CObjectViewerDialog &operator=(const CObjectViewerDialog &);
|
||||||
|
|
||||||
friend class CMainWindow;
|
void updateInitialization(bool visible);
|
||||||
}; /* CObjectViewerDialog */
|
|
||||||
|
Ui::CObjectViewerDialog _ui;
|
||||||
|
|
||||||
|
// render stuff
|
||||||
|
QTimer *_mainTimer;
|
||||||
|
bool _isGraphicsInitialized, _isGraphicsEnabled;
|
||||||
|
|
||||||
|
QNLWidget * _nlw;
|
||||||
|
|
||||||
|
friend class CMainWindow;
|
||||||
|
}; /* CObjectViewerDialog */
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
|
|
@ -24,14 +24,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include <nel/misc/debug.h>
|
#include <nel/misc/debug.h>
|
||||||
#include <nel/misc/file.h>
|
#include <nel/misc/file.h>
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
CQtDisplayer::CQtDisplayer(QPlainTextEdit *dlgDebug, bool eraseLastLog, const char *displayerName, bool raw)
|
CQtDisplayer::CQtDisplayer(QPlainTextEdit *dlgDebug, bool eraseLastLog, const char *displayerName, bool raw)
|
||||||
: NLMISC::IDisplayer (displayerName), _NeedHeader(true), _LastLogSizeChecked(0), _Raw(raw) {
|
: NLMISC::IDisplayer (displayerName), _NeedHeader(true), _LastLogSizeChecked(0), _Raw(raw)
|
||||||
setParam(dlgDebug,eraseLastLog);
|
{
|
||||||
|
setParam(dlgDebug,eraseLastLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
CQtDisplayer::CQtDisplayer() : IDisplayer (""), _NeedHeader(true), _LastLogSizeChecked(0), _Raw(false) {
|
CQtDisplayer::CQtDisplayer()
|
||||||
|
: IDisplayer (""), _NeedHeader(true), _LastLogSizeChecked(0), _Raw(false)
|
||||||
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,12 +43,14 @@ namespace NLQT {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CQtDisplayer::setParam (QPlainTextEdit *dlgDebug, bool eraseLastLog) {
|
void CQtDisplayer::setParam (QPlainTextEdit *dlgDebug, bool eraseLastLog)
|
||||||
|
{
|
||||||
m_DlgDebug=dlgDebug;
|
m_DlgDebug=dlgDebug;
|
||||||
//dlgDebug->dlgDbgText->WriteText("test");
|
//dlgDebug->dlgDbgText->WriteText("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CQtDisplayer::doDisplay ( const NLMISC::CLog::TDisplayInfo& args, const char *message ) {
|
void CQtDisplayer::doDisplay ( const NLMISC::CLog::TDisplayInfo& args, const char *message )
|
||||||
|
{
|
||||||
bool needSpace = false;
|
bool needSpace = false;
|
||||||
std::string str;
|
std::string str;
|
||||||
|
|
||||||
|
@ -58,7 +64,8 @@ namespace NLQT {
|
||||||
needSpace = true;
|
needSpace = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.LogType != NLMISC::CLog::LOG_NO && !_Raw) {
|
if (args.LogType != NLMISC::CLog::LOG_NO && !_Raw)
|
||||||
|
{
|
||||||
if (needSpace) { str += " "; needSpace = false; }
|
if (needSpace) { str += " "; needSpace = false; }
|
||||||
str += logTypeToString(args.LogType);
|
str += logTypeToString(args.LogType);
|
||||||
if (args.LogType == NLMISC::CLog::LOG_WARNING)
|
if (args.LogType == NLMISC::CLog::LOG_WARNING)
|
||||||
|
@ -70,14 +77,14 @@ namespace NLQT {
|
||||||
|
|
||||||
// Write thread identifier
|
// Write thread identifier
|
||||||
/*if ( args.ThreadId != 0 && !_Raw) {
|
/*if ( args.ThreadId != 0 && !_Raw) {
|
||||||
if (needSpace) { str += " "; needSpace = false; }
|
if (needSpace) { str += " "; needSpace = false; }
|
||||||
str += NLMISC::toString(args.ThreadId);
|
str += NLMISC::toString(args.ThreadId);
|
||||||
needSpace = true;
|
needSpace = true;
|
||||||
}*/
|
}*/
|
||||||
/*if (!args.ProcessName.empty() && !_Raw) {
|
/*if (!args.ProcessName.empty() && !_Raw) {
|
||||||
if (needSpace) { str += " "; needSpace = false; }
|
if (needSpace) { str += " "; needSpace = false; }
|
||||||
str += args.ProcessName;
|
str += args.ProcessName;
|
||||||
needSpace = true;
|
needSpace = true;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
//if (args.FileName != NULL && !_Raw) {
|
//if (args.FileName != NULL && !_Raw) {
|
||||||
|
@ -87,22 +94,29 @@ namespace NLQT {
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/*if (args.Line != -1 && !_Raw) {
|
/*if (args.Line != -1 && !_Raw) {
|
||||||
if (needSpace) { str += " "; needSpace = false; }
|
if (needSpace) { str += " "; needSpace = false; }
|
||||||
str += NLMISC::toString(args.Line);
|
str += NLMISC::toString(args.Line);
|
||||||
needSpace = true;
|
needSpace = true;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (args.FuncName != NULL && !_Raw) {
|
if (args.FuncName != NULL && !_Raw)
|
||||||
if (needSpace) { str += " "; needSpace = false; }
|
{
|
||||||
|
if (needSpace)
|
||||||
|
{
|
||||||
|
str += " "; needSpace = false;
|
||||||
|
}
|
||||||
str += args.FuncName;
|
str += args.FuncName;
|
||||||
needSpace = true;
|
needSpace = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needSpace) { str += " : "; needSpace = false; }
|
if (needSpace)
|
||||||
|
{
|
||||||
|
str += " : "; needSpace = false;
|
||||||
|
}
|
||||||
str += message;
|
str += message;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m_DlgDebug->textCursor().insertText(str.c_str(), format);
|
m_DlgDebug->textCursor().insertText(str.c_str(), format);
|
||||||
//m_DlgDebug->setCenterOnScroll(true);
|
//m_DlgDebug->setCenterOnScroll(true);
|
||||||
m_DlgDebug->centerCursor();
|
m_DlgDebug->centerCursor();
|
||||||
|
|
|
@ -28,10 +28,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
class CQtDisplayer : virtual public NLMISC::IDisplayer
|
class CQtDisplayer : virtual public NLMISC::IDisplayer
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CQtDisplayer(QPlainTextEdit *dlgDebug, bool eraseLastLog = false, const char *displayerName = "", bool raw = false);
|
CQtDisplayer(QPlainTextEdit *dlgDebug, bool eraseLastLog = false, const char *displayerName = "", bool raw = false);
|
||||||
CQtDisplayer();
|
CQtDisplayer();
|
||||||
|
@ -42,7 +44,7 @@ namespace NLQT {
|
||||||
virtual void doDisplay ( const NLMISC::CLog::TDisplayInfo& args, const char *message );
|
virtual void doDisplay ( const NLMISC::CLog::TDisplayInfo& args, const char *message );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPlainTextEdit *m_DlgDebug;
|
QPlainTextEdit *m_DlgDebug;
|
||||||
bool _NeedHeader;
|
bool _NeedHeader;
|
||||||
uint _LastLogSizeChecked;
|
uint _LastLogSizeChecked;
|
||||||
bool _Raw;
|
bool _Raw;
|
||||||
|
|
|
@ -31,7 +31,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
CSettingsDialog::CSettingsDialog(QWidget *parent)
|
CSettingsDialog::CSettingsDialog(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
|
@ -72,7 +73,8 @@ namespace NLQT {
|
||||||
QFileDialog dialog(this);
|
QFileDialog dialog(this);
|
||||||
dialog.setOption(QFileDialog::ShowDirsOnly, true);
|
dialog.setOption(QFileDialog::ShowDirsOnly, true);
|
||||||
dialog.setFileMode(QFileDialog::Directory);
|
dialog.setFileMode(QFileDialog::Directory);
|
||||||
if (dialog.exec()) {
|
if (dialog.exec())
|
||||||
|
{
|
||||||
QString newPath = dialog.selectedFiles().first();
|
QString newPath = dialog.selectedFiles().first();
|
||||||
if (!newPath.isEmpty())
|
if (!newPath.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -137,9 +139,12 @@ namespace NLQT {
|
||||||
list.push_back(str);
|
list.push_back(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.empty()) {
|
if (list.empty())
|
||||||
|
{
|
||||||
Modules::config().getConfigFile().getVar("SearchPaths").forceAsString("");
|
Modules::config().getConfigFile().getVar("SearchPaths").forceAsString("");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Modules::config().getConfigFile().getVar("SearchPaths").forceAsString("");
|
Modules::config().getConfigFile().getVar("SearchPaths").forceAsString("");
|
||||||
Modules::config().getConfigFile().getVar("SearchPaths").setAsString(list);
|
Modules::config().getConfigFile().getVar("SearchPaths").setAsString(list);
|
||||||
}
|
}
|
||||||
|
@ -197,4 +202,5 @@ namespace NLQT {
|
||||||
ui.leveldesignPath->setText(QFileDialog::getExistingDirectory(this, tr("Open Directory"),
|
ui.leveldesignPath->setText(QFileDialog::getExistingDirectory(this, tr("Open Directory"),
|
||||||
QDir::currentPath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
|
QDir::currentPath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
|
||||||
}
|
}
|
||||||
} /* namespace NLQT */
|
|
||||||
|
} /* namespace NLQT */
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
Georges Editor Qt
|
Georges Editor Qt
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SETTINGS_DIALOG_H
|
#ifndef SETTINGS_DIALOG_H
|
||||||
|
@ -29,36 +29,37 @@
|
||||||
|
|
||||||
// Project includes
|
// Project includes
|
||||||
|
|
||||||
namespace NLQT {
|
namespace NLQT
|
||||||
|
|
||||||
class CSettingsDialog: public QDialog
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
class CSettingsDialog: public QDialog
|
||||||
CSettingsDialog(QWidget *parent = 0);
|
{
|
||||||
~CSettingsDialog();
|
Q_OBJECT
|
||||||
|
|
||||||
Q_SIGNALS:
|
public:
|
||||||
void ldPathChanged(QString);
|
CSettingsDialog(QWidget *parent = 0);
|
||||||
|
~CSettingsDialog();
|
||||||
|
|
||||||
private Q_SLOTS:
|
Q_SIGNALS:
|
||||||
void addPath();
|
void ldPathChanged(QString);
|
||||||
void removePath();
|
|
||||||
void upPath();
|
|
||||||
void downPath();
|
|
||||||
void applyPressed();
|
|
||||||
void browseLeveldesignPath();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void cfcbGraphicsDrivers(NLMISC::CConfigFile::CVar &var);
|
|
||||||
void cfcbSoundDrivers(NLMISC::CConfigFile::CVar &var);
|
|
||||||
void cfcbSearchPaths(NLMISC::CConfigFile::CVar &var);
|
|
||||||
void cfcbLeveldesignPath(NLMISC::CConfigFile::CVar &var);
|
|
||||||
|
|
||||||
Ui::CSettingsDialog ui;
|
|
||||||
|
|
||||||
}; /* class CSettingsDialog */
|
private Q_SLOTS:
|
||||||
|
void addPath();
|
||||||
|
void removePath();
|
||||||
|
void upPath();
|
||||||
|
void downPath();
|
||||||
|
void applyPressed();
|
||||||
|
void browseLeveldesignPath();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void cfcbGraphicsDrivers(NLMISC::CConfigFile::CVar &var);
|
||||||
|
void cfcbSoundDrivers(NLMISC::CConfigFile::CVar &var);
|
||||||
|
void cfcbSearchPaths(NLMISC::CConfigFile::CVar &var);
|
||||||
|
void cfcbLeveldesignPath(NLMISC::CConfigFile::CVar &var);
|
||||||
|
|
||||||
|
Ui::CSettingsDialog ui;
|
||||||
|
|
||||||
|
}; /* class CSettingsDialog */
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
|
|
@ -1,275 +0,0 @@
|
||||||
/*
|
|
||||||
Georges Editor Qt
|
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU 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 General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "spindelegate.h"
|
|
||||||
|
|
||||||
// NeL includes
|
|
||||||
#include <nel/misc/debug.h>
|
|
||||||
#include <nel/georges/u_type.h>
|
|
||||||
#include <nel/georges/u_form_elm.h>
|
|
||||||
|
|
||||||
// Qt includes
|
|
||||||
#include <QSpinBox>
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QDoubleSpinBox>
|
|
||||||
#include <QColorDialog>
|
|
||||||
#include <QComboBox>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QTextDocument>
|
|
||||||
#include <QAbstractTextDocumentLayout>
|
|
||||||
#include <QPainter>
|
|
||||||
// Project includes
|
|
||||||
#include "georgesform_model.h"
|
|
||||||
#include "formitem.h"
|
|
||||||
|
|
||||||
namespace NLQT {
|
|
||||||
|
|
||||||
SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
|
|
||||||
: QStyledItemDelegate(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
|
|
||||||
const QStyleOptionViewItem & option ,
|
|
||||||
const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
CFormItem *item = static_cast<CFormItem*>(index.internalPointer());
|
|
||||||
QString value = item->data(1).toString();
|
|
||||||
|
|
||||||
if (value.isEmpty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
const NLGEORGES::UType *type = qobject_cast<const CGeorgesFormModel *>(index.model())->
|
|
||||||
getItem(index)->getFormElm()->getType();
|
|
||||||
if(type) {
|
|
||||||
int numDefinitions = type->getNumDefinition();
|
|
||||||
|
|
||||||
if (numDefinitions) {
|
|
||||||
std::string l, v;
|
|
||||||
QString label,value;
|
|
||||||
|
|
||||||
QComboBox *editor = new QComboBox(parent);
|
|
||||||
for (int i = 0; i < numDefinitions; i++) {
|
|
||||||
type->getDefinition(i,l,v);
|
|
||||||
label = l.c_str();
|
|
||||||
value = v.c_str();
|
|
||||||
editor->addItem(label);
|
|
||||||
}
|
|
||||||
return editor;
|
|
||||||
} else {
|
|
||||||
switch (type->getType()) {
|
|
||||||
case NLGEORGES::UType::UnsignedInt:
|
|
||||||
case NLGEORGES::UType::SignedInt:
|
|
||||||
{
|
|
||||||
QSpinBox *editor = new QSpinBox(parent);
|
|
||||||
|
|
||||||
//QString min = QString(type->getMin().c_str());
|
|
||||||
//QString max = QString(type->getMax().c_str());
|
|
||||||
//QString inc = QString(type->getIncrement().c_str());
|
|
||||||
//nldebug(QString("min %1 max %2 inc %3").arg(min).arg(max).arg(inc).toStdString().c_str());
|
|
||||||
|
|
||||||
// TODO: use saved min/max values
|
|
||||||
editor->setMinimum(-99999);
|
|
||||||
editor->setMaximum(99999);
|
|
||||||
editor->setSingleStep(1);
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
case NLGEORGES::UType::Double:
|
|
||||||
{
|
|
||||||
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
|
|
||||||
|
|
||||||
//QString min = QString(type->getMin().c_str());
|
|
||||||
//QString max = QString(type->getMax().c_str());
|
|
||||||
//QString inc = QString(type->getIncrement().c_str());
|
|
||||||
//nldebug(QString("min %1 max %2 inc %3").arg(min).arg(max).arg(inc).toStdString().c_str());
|
|
||||||
|
|
||||||
// TODO: use saved min/max values
|
|
||||||
editor->setMinimum(-99999);
|
|
||||||
editor->setMaximum(99999);
|
|
||||||
editor->setSingleStep(0.1);
|
|
||||||
editor->setDecimals(1);
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
case NLGEORGES::UType::Color:
|
|
||||||
{
|
|
||||||
return new QColorDialog();
|
|
||||||
}
|
|
||||||
default: // UType::String
|
|
||||||
{
|
|
||||||
QLineEdit *editor = new QLineEdit(parent);
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpinBoxDelegate::setEditorData(QWidget *editor,
|
|
||||||
const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
const NLGEORGES::UType *type = qobject_cast<const CGeorgesFormModel *>(index.model())->
|
|
||||||
getItem(index)->getFormElm()->getType();
|
|
||||||
int numDefinitions = type->getNumDefinition();
|
|
||||||
QString value = index.model()->data(index, Qt::DisplayRole).toString();
|
|
||||||
|
|
||||||
if (numDefinitions) {
|
|
||||||
QComboBox *cb = static_cast<QComboBox*>(editor);
|
|
||||||
cb->setCurrentIndex(cb->findText(value));
|
|
||||||
//cb->setIconSize()
|
|
||||||
} else {
|
|
||||||
switch (type->getType()) {
|
|
||||||
case NLGEORGES::UType::UnsignedInt:
|
|
||||||
case NLGEORGES::UType::SignedInt:
|
|
||||||
{
|
|
||||||
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
|
||||||
spinBox->setValue((int)value.toDouble());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NLGEORGES::UType::Double:
|
|
||||||
{
|
|
||||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
|
||||||
spinBox->setValue(value.toDouble());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NLGEORGES::UType::Color:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
QLineEdit *textEdit = static_cast<QLineEdit*>(editor);
|
|
||||||
textEdit->setText(value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
|
||||||
const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
const NLGEORGES::UType *type = qobject_cast<const CGeorgesFormModel *>(index.model())->
|
|
||||||
getItem(index)->getFormElm()->getType();
|
|
||||||
int numDefinitions = type->getNumDefinition();
|
|
||||||
|
|
||||||
if (numDefinitions) {
|
|
||||||
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
|
||||||
QString value = comboBox->currentText();
|
|
||||||
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
|
|
||||||
if (value == oldValue) {
|
|
||||||
// nothing's changed
|
|
||||||
} else {
|
|
||||||
nldebug(QString("setModelData from %1 to %2")
|
|
||||||
.arg(oldValue).arg(value).toStdString().c_str());
|
|
||||||
model->setData(index, value, Qt::EditRole);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch (type->getType()) {
|
|
||||||
case NLGEORGES::UType::UnsignedInt:
|
|
||||||
case NLGEORGES::UType::SignedInt:
|
|
||||||
{
|
|
||||||
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
|
||||||
int value = spinBox->value();
|
|
||||||
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
|
|
||||||
if (QString("%1").arg(value) == oldValue) {
|
|
||||||
// nothing's changed
|
|
||||||
} else {
|
|
||||||
nldebug(QString("setModelData from %1 to %2")
|
|
||||||
.arg(oldValue).arg(value).toStdString().c_str());
|
|
||||||
model->setData(index, value, Qt::EditRole);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NLGEORGES::UType::Double:
|
|
||||||
{
|
|
||||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
|
||||||
double value = spinBox->value();
|
|
||||||
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
|
|
||||||
if (QString("%1").arg(value) == oldValue) {
|
|
||||||
// nothing's changed
|
|
||||||
} else {
|
|
||||||
nldebug(QString("setModelData from %1 to %2")
|
|
||||||
.arg(oldValue).arg(value).toStdString().c_str());
|
|
||||||
model->setData(index, value, Qt::EditRole);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NLGEORGES::UType::Color:
|
|
||||||
{
|
|
||||||
break; // TODO
|
|
||||||
}
|
|
||||||
default: // UType::String
|
|
||||||
{
|
|
||||||
QLineEdit *textEdit = static_cast<QLineEdit*>(editor);
|
|
||||||
QString value = textEdit->text();
|
|
||||||
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
|
|
||||||
if (value == oldValue) {
|
|
||||||
// nothing's changed
|
|
||||||
} else {
|
|
||||||
nldebug(QString("setModelData from %1 to %2")
|
|
||||||
.arg(oldValue).arg(value).toStdString().c_str());
|
|
||||||
model->setData(index, value, Qt::EditRole);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
|
|
||||||
const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
QRect r = option.rect;
|
|
||||||
editor->setGeometry(r);
|
|
||||||
//option.decorationAlignment = QStyleOptionViewItem::Right;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpinBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
QStyleOptionViewItemV4 optionV4 = option;
|
|
||||||
optionV4.decorationPosition = QStyleOptionViewItem::Right;
|
|
||||||
//optionV4.decorationSize = QSize(32,32);
|
|
||||||
initStyleOption(&optionV4, index);
|
|
||||||
|
|
||||||
QStyledItemDelegate::paint(painter,optionV4,index);
|
|
||||||
|
|
||||||
//QStyle *style = optionV4.widget? optionV4.widget->style() : QApplication::style();
|
|
||||||
|
|
||||||
//QTextDocument doc;
|
|
||||||
//doc.setHtml(optionV4.text);
|
|
||||||
|
|
||||||
///// Painting item without text
|
|
||||||
//optionV4.text = QString();
|
|
||||||
//style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
|
|
||||||
|
|
||||||
//QAbstractTextDocumentLayout::PaintContext ctx;
|
|
||||||
|
|
||||||
//// Highlighting text if item is selected
|
|
||||||
//if (optionV4.state & QStyle::State_Selected)
|
|
||||||
// ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));
|
|
||||||
|
|
||||||
//QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4);
|
|
||||||
//painter->save();
|
|
||||||
//painter->translate(textRect.topLeft());
|
|
||||||
//painter->setClipRect(textRect.translated(-textRect.topLeft()));
|
|
||||||
//doc.documentLayout()->draw(painter, ctx);
|
|
||||||
//painter->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/*
|
|
||||||
Georges Editor Qt
|
|
||||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU 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 General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DELEGATE_H
|
|
||||||
#define DELEGATE_H
|
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
|
||||||
|
|
||||||
namespace NLQT {
|
|
||||||
|
|
||||||
class SpinBoxDelegate : public QStyledItemDelegate
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
SpinBoxDelegate(QObject *parent = 0);
|
|
||||||
|
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
|
||||||
const QModelIndex &index) const;
|
|
||||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
|
||||||
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
|
||||||
const QModelIndex &index) const;
|
|
||||||
void updateEditorGeometry(QWidget *editor,
|
|
||||||
const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
|
||||||
void paint ( QPainter * painter, const QStyleOptionViewItem & option,
|
|
||||||
const QModelIndex & index ) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
Loading…
Reference in a new issue