Changed: #1150 Code Cleanup

This commit is contained in:
aquiles 2010-11-02 15:25:36 +01:00
parent eb3f1737c2
commit 9e7ef3a859
32 changed files with 2476 additions and 2250 deletions

View file

@ -2,8 +2,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${LI
INCLUDE( ${QT_USE_FILE} )
FILE(GLOB GEORGES_EDITOR_SRC *.cpp)
SET(GEORGES_EDITOR_HDR georges_dirtree_dialog.h georges_treeview_dialog.h georgesform_model.h main_window.h
log_dialog.h objectviewer_dialog.h settings_dialog.h)
SET(GEORGES_EDITOR_HDR georges_dirtree_dialog.h georges_treeview_dialog.h main_window.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_RCS georges_editor_qt.qrc)

View file

@ -21,26 +21,31 @@
#include <QtGui/QApplication>
#include <QtGui/QStyle>
namespace NLQT {
namespace NLQT
{
CFileSystemModel::CFileSystemModel(QString ldPath, QObject *parent)
: QFileSystemModel(parent),
_ldPath(ldPath){
_ldPath(ldPath)
{
}
CFileSystemModel::~CFileSystemModel() {
CFileSystemModel::~CFileSystemModel()
{
}
QVariant CFileSystemModel::data(const QModelIndex& index, int role) const {
if (role == Qt::DecorationRole) {
if (role == Qt::DecorationRole)
{
if (_ldPath.isEmpty())
return QVariant();
if (isDir(index))
return QApplication::style()->standardIcon(QStyle::SP_DirIcon);
}
if (_ldPath.isEmpty() && role == Qt::DisplayRole) {
if (_ldPath.isEmpty() && role == Qt::DisplayRole)
{
if (index.parent().isValid())
return QVariant();
return QString("Set a correct leveldesign path ...");
@ -55,10 +60,14 @@ namespace NLQT {
int CFileSystemModel::rowCount(const QModelIndex &parent) const
{
if (_ldPath.isEmpty()) {
if(parent.isValid()) {
if (_ldPath.isEmpty())
{
if(parent.isValid())
{
return 0;
} else {
}
else
{
return qMin(QFileSystemModel::rowCount(parent),1);
}
}

View file

@ -21,7 +21,8 @@
#include <QtGui/QFileSystemModel>
namespace NLQT {
namespace NLQT
{
class CFileSystemModel : public QFileSystemModel
{

View file

@ -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 */

View file

@ -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

View file

@ -24,10 +24,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// NeL includes
#include <nel/georges/u_type.h>
namespace NLQT {
namespace NLQT
{
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;
itemData = data;
formElm = elm;
@ -35,27 +37,33 @@ namespace NLQT {
whereN = wN;
}
CFormItem::~CFormItem() {
CFormItem::~CFormItem()
{
qDeleteAll(childItems);
}
void CFormItem::appendChild(CFormItem *item) {
void CFormItem::appendChild(CFormItem *item)
{
childItems.append(item);
}
CFormItem *CFormItem::child(int row) {
CFormItem *CFormItem::child(int row)
{
return childItems.value(row);
}
int CFormItem::childCount() const {
int CFormItem::childCount() const
{
return childItems.count();
}
int CFormItem::columnCount() const {
int CFormItem::columnCount() const
{
return itemData.count();
}
QVariant CFormItem::data(int column) const {
QVariant CFormItem::data(int column) const
{
return itemData.value(column);
}
@ -64,22 +72,27 @@ namespace NLQT {
return parentItem;
}
int CFormItem::row() const {
int CFormItem::row() const
{
if (parentItem)
return parentItem->childItems.indexOf(const_cast<CFormItem*>(this));
return 0;
}
bool CFormItem::setData(int column, const QVariant &value) {
bool CFormItem::setData(int column, const QVariant &value)
{
if (column < 0 || column >= itemData.size())
return false;
itemData[column] = value;
if (formElm->isAtom()) {
if (formElm->isAtom())
{
const NLGEORGES::UType *type = formElm->getType();
if (type) {
switch (type->getType()) {
if (type)
{
switch (type->getType())
{
case NLGEORGES::UType::UnsignedInt:
case NLGEORGES::UType::SignedInt:
case NLGEORGES::UType::Double:

View file

@ -26,7 +26,8 @@
#include <QList>
#include <QVariant>
namespace NLQT {
namespace NLQT
{
class CFormItem
@ -48,10 +49,12 @@ namespace NLQT {
CFormItem *parent();
bool setData(int column, const QVariant &value);
NLGEORGES::UFormElm* getFormElm() {return formElm;};
NLGEORGES::UFormElm::TWhereIsValue CFormItem::valueFrom() {
NLGEORGES::UFormElm::TWhereIsValue CFormItem::valueFrom()
{
return whereV;
}
NLGEORGES::UFormElm::TWhereIsNode CFormItem::nodeFrom() {
NLGEORGES::UFormElm::TWhereIsNode CFormItem::nodeFrom()
{
return whereN;
}

View file

@ -29,15 +29,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using namespace NLGEORGES;
namespace NLQT {
namespace NLQT
{
CGeorges::CGeorges(): FormLoader(0) {
CGeorges::CGeorges(): FormLoader(0)
{
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());
return form;

View file

@ -38,7 +38,8 @@ namespace NLGEORGES
using namespace NLGEORGES;
namespace NLQT {
namespace NLQT
{
/**
@class CGeorges

View file

@ -30,11 +30,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using namespace NLMISC;
namespace NLQT {
namespace NLQT
{
CGeorgesDirTreeDialog::CGeorgesDirTreeDialog(QString ldPath, QWidget *parent):
QDockWidget(parent),
_ldPath(ldPath){
CGeorgesDirTreeDialog::CGeorgesDirTreeDialog(QString ldPath, QWidget *parent)
:QDockWidget(parent), _ldPath(ldPath)
{
_ui.setupUi(this);
@ -72,10 +73,13 @@ namespace NLQT {
QFileInfo info(_ldPath);
if (!_ldPath.isEmpty() && info.isDir()) {
if (!_ldPath.isEmpty() && info.isDir())
{
_dirModel->setRootPath(_ldPath);
_ui.dirTree->setRootIndex(_dirModel->index(_ldPath));
} else {
}
else
{
_dirModel->setRootPath(QDir::currentPath());
}
@ -89,18 +93,22 @@ namespace NLQT {
this, SLOT(fileSelected(QModelIndex)));
}
CGeorgesDirTreeDialog::~CGeorgesDirTreeDialog() {
CGeorgesDirTreeDialog::~CGeorgesDirTreeDialog()
{
delete _dirModel;
}
void CGeorgesDirTreeDialog::fileSelected(QModelIndex index) {
void CGeorgesDirTreeDialog::fileSelected(QModelIndex index)
{
QString name;
if (index.isValid() && !_dirModel->isDir(index)) {
if (index.isValid() && !_dirModel->isDir(index))
{
Q_EMIT selectedForm(_dirModel->fileName(index));
}
}
void CGeorgesDirTreeDialog::changeFile(QString file) {
void CGeorgesDirTreeDialog::changeFile(QString file)
{
QModelIndex index = _dirModel->index(file);
//_dirModel->;
_ui.dirTree->selectionModel()->select(index,QItemSelectionModel::ClearAndSelect);
@ -108,18 +116,22 @@ void CGeorgesDirTreeDialog::changeFile(QString file) {
fileSelected(index);
}
void CGeorgesDirTreeDialog::ldPathChanged(QString path) {
void CGeorgesDirTreeDialog::ldPathChanged(QString path)
{
_ldPath = path;
QFileInfo info(_ldPath);
delete _dirModel;
if (!_ldPath.isEmpty() && info.isDir()) {
if (!_ldPath.isEmpty() && info.isDir())
{
_dirModel = new CFileSystemModel(_ldPath);
_ui.dirTree->setModel(_dirModel);
_dirModel->setRootPath(_ldPath);
_ui.dirTree->setRootIndex(_dirModel->index(_ldPath));
} else {
}
else
{
_dirModel = new CFileSystemModel("");
_ui.dirTree->setModel(_dirModel);
_dirModel->setRootPath(QDir::currentPath());

View file

@ -30,7 +30,8 @@
#include "ui_georges_dirtree_form.h"
#include "filesystem_model.h"
namespace NLQT {
namespace NLQT
{
class CGeorgesDirTreeDialog: public QDockWidget
{

View file

@ -34,12 +34,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "georgesform_model.h"
#include "georgesform_proxy_model.h"
#include "formitem.h"
#include "spindelegate.h"
#include "formdelegate.h"
using namespace NLMISC;
using namespace NLGEORGES;
namespace NLQT {
namespace NLQT
{
CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/, bool emptyView /*= false*/)
: QDockWidget(parent)
@ -50,7 +51,8 @@ namespace NLQT {
_ui.setupUi(this);
_ui.treeViewTabWidget->setTabEnabled (2,false);
if (emptyView) {
if (emptyView)
{
_ui.treeViewTabWidget->clear();
setWindowTitle("Form Area");
}
@ -59,8 +61,8 @@ namespace NLQT {
_ui.checkBoxDefaults->setStyleSheet("background-color: rgba(255,0,0,30)");
_form = 0;
SpinBoxDelegate *spindelegate = new SpinBoxDelegate(this);
_ui.treeView->setItemDelegateForColumn(1, spindelegate);
FormDelegate *formdelegate = new FormDelegate(this);
_ui.treeView->setItemDelegateForColumn(1, formdelegate);
connect(_ui.treeView, SIGNAL(doubleClicked (QModelIndex)),
@ -77,15 +79,18 @@ namespace NLQT {
//settings.setValue("dirViewGeometry", saveGeometry());
}
void CGeorgesTreeViewDialog::selectedForm(QString formName) {
void CGeorgesTreeViewDialog::selectedForm(QString formName)
{
_form = Modules::georges().loadForm(formName.toStdString());
if (_form) {
if (_form)
{
UFormElm *root = 0;
root = &_form->getRootNode();
QStringList parents;
for (uint i = 0; i < _form->getNumParent(); i++) {
for (uint i = 0; i < _form->getNumParent(); i++)
{
UForm *u = _form->getParentForm(i);
parents << u->getFilename().c_str();
}
@ -93,7 +98,8 @@ namespace NLQT {
QString comments;
comments = _form->getComment().c_str();
if (!comments.isEmpty()) {
if (!comments.isEmpty())
{
_ui.treeViewTabWidget->setTabEnabled (1,true);
_ui.commentEdit->setPlainText(comments);
}
@ -103,7 +109,8 @@ namespace NLQT {
_form->getDependencies(dependencies);
QMap< QString, QStringList> deps;
Q_FOREACH(std::string str, dependencies) {
Q_FOREACH(std::string str, dependencies)
{
QString file = str.c_str();
if (file == formName) continue;
deps[file.remove(0,file.indexOf(".")+1)] << str.c_str();
@ -112,7 +119,8 @@ namespace NLQT {
nlinfo("dfn's %d",deps["dfn"].count());
//nlwarning(strList.join(";").toStdString().c_str());
if (root) {
if (root)
{
loadedForm = formName;
CGeorgesFormModel *model = new CGeorgesFormModel(root,deps,comments,parents);
@ -137,8 +145,10 @@ namespace NLQT {
}
}
void CGeorgesTreeViewDialog::modifiedFile( ) {
if (!_modified) {
void CGeorgesTreeViewDialog::modifiedFile( )
{
if (!_modified)
{
_modified = true;
setWindowTitle(windowTitle()+"*");
Modules::mainWin().setWindowTitle(Modules::mainWin().windowTitle()+"*");
@ -146,13 +156,17 @@ namespace NLQT {
}
}
void CGeorgesTreeViewDialog::write( ) {
void CGeorgesTreeViewDialog::write( )
{
COFile file;
std::string s = CPath::lookup(loadedForm.toStdString());
if (file.open (s)) {
try {
if (loadedForm.contains(".typ")) {
if (file.open (s))
{
try
{
if (loadedForm.contains(".typ"))
{
//nlassert (Type != NULL);
//// Write the file
@ -167,7 +181,9 @@ namespace NLQT {
//flushValueChange ();
//UpdateAllViews (NULL);
//return TRUE;
} else if (loadedForm.contains(".dfn")) {
}
else if (loadedForm.contains(".dfn"))
{
//nlassert (Dfn != NULL);
//// Write the file
@ -180,7 +196,9 @@ namespace NLQT {
//modify (NULL, NULL, false);
//UpdateAllViews (NULL);
//return TRUE;
} else {
}
else
{
nlassert (_form != NULL);
// Write the file
@ -205,16 +223,23 @@ namespace NLQT {
// Get the left view
//CView* pView = getLeftView ();
}
} catch (Exception &e) {
}
catch (Exception &e)
{
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);
}
}
void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index ) {
if (index.column() == 1) return;
void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index )
{
if (index.column() == 1)
return;
CFormItem *item = static_cast<CFormItem*>(index.internalPointer());
QString value = item->data(1).toString();
@ -222,7 +247,8 @@ namespace NLQT {
if (!path.isEmpty() && !path.contains(".shape"))
Q_EMIT changeFile(path);
if (path.contains(".shape")) {
if (path.contains(".shape"))
{
Modules::objView().resetScene();
Modules::config().configRemapExtensions();
Modules::objView().loadMesh(path.toStdString(),"");
@ -230,37 +256,55 @@ namespace NLQT {
int i = 0;
}
void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) {
if (Modules::mainWin().getEmptyView() == this) {
void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event)
{
if (Modules::mainWin().getEmptyView() == this)
{
event->ignore();
} else {
}
else
{
Modules::mainWin().getTreeViewList().removeOne(this);
if(!Modules::mainWin().getTreeViewList().size()) {
if(!Modules::mainWin().getTreeViewList().size())
{
Modules::mainWin().createEmptyView();
}
deleteLater();
}
}
void CGeorgesTreeViewDialog::showParentRows(int newState) {
void CGeorgesTreeViewDialog::showParentRows(int newState)
{
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);
if (m->getItem(in)->nodeFrom() == UFormElm::NodeParentForm) {
if (newState == Qt::Checked) {
if (m->getItem(in)->nodeFrom() == UFormElm::NodeParentForm)
{
if (newState == Qt::Checked)
{
_ui.treeView->setRowHidden(in.row(),in.parent(),false);
} else {
}
else
{
_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);
if (m->getItem(in2)->nodeFrom() == UFormElm::NodeParentForm) {
if (newState == Qt::Checked) {
if (m->getItem(in2)->nodeFrom() == UFormElm::NodeParentForm)
{
if (newState == Qt::Checked)
{
_ui.treeView->setRowHidden(in2.row(),in,false);
} else {
}
else
{
_ui.treeView->setRowHidden(in2.row(),in,true);
}
}
@ -268,4 +312,5 @@ namespace NLQT {
} // end of search childs
}
}
} /* namespace NLQT */

View file

@ -37,7 +37,8 @@ namespace NLGEORGES
using namespace NLGEORGES;
namespace NLQT {
namespace NLQT
{
class CGeorgesTreeViewDialog: public QDockWidget
{

View file

@ -38,11 +38,12 @@
using namespace NLGEORGES;
namespace NLQT {
namespace NLQT
{
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;
@ -55,18 +56,20 @@ namespace NLQT {
setupModelData();
}
CGeorgesFormModel::~CGeorgesFormModel() {
CGeorgesFormModel::~CGeorgesFormModel()
{
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())
return QVariant();
switch (p_role) {
switch (p_role)
{
case Qt::DisplayRole:
{
return getItem(p_index)->data(p_index.column());
@ -81,7 +84,8 @@ namespace NLQT {
}
case Qt::DecorationRole:
{
if (p_index.column() == 2) {
if (p_index.column() == 2)
{
//p_index.
QModelIndex in = index(p_index.row(),p_index.column()-1,p_index.parent());
CFormItem *item = getItem(in);
@ -89,9 +93,12 @@ namespace NLQT {
QString value = item->data(1).toString();
//QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str();
if (value.contains(".shape")) {
if (value.contains(".shape"))
{
return QIcon(":/images/pqrticles.png");
} else if(value.contains(".tga") || value.contains(".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");
@ -107,10 +114,13 @@ namespace NLQT {
/******************************************************************************/
CFormItem *CGeorgesFormModel::getItem(const QModelIndex &index) const {
if (index.isValid()) {
CFormItem *CGeorgesFormModel::getItem(const QModelIndex &index) const
{
if (index.isValid())
{
CFormItem *item = static_cast<CFormItem*>(index.internalPointer());
if (item) return item;
if (item)
return item;
}
return _rootItem;
}
@ -118,7 +128,8 @@ namespace NLQT {
/******************************************************************************/
bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value,
int role) {
int role)
{
if (role != Qt::EditRole)
return false;
@ -230,20 +241,24 @@ namespace NLQT {
void CGeorgesFormModel::loadFormData(UFormElm *root, CFormItem *parent) {
if (!root) return;
if (!root)
return;
uint num = 0;
UFormElm::TWhereIsNode *whereN = new UFormElm::TWhereIsNode;
UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue;
if (root->isStruct()) {
if (root->isStruct())
{
//((CFormElm*)root)->getForm()->getComment();
uint structSize = 0;
root->getStructSize(structSize);
while (num < structSize) {
while (num < structSize)
{
// Append a new item to the current parent's list of children.
std::string elmName;
if(root->getStructNodeName(num, elmName)) {
if(root->getStructNodeName(num, elmName))
{
QList<QVariant> columnData;
//QVariant value;
std::string value;
@ -253,8 +268,10 @@ namespace NLQT {
//double value_double;
QString elmtType = "";
UFormElm *elmt = 0;
if(root->getNodeByName(&elmt, elmName.c_str(), whereN, true)) {
if (elmt) {
if(root->getNodeByName(&elmt, elmName.c_str(), whereN, true))
{
if (elmt)
{
if (elmt->isArray())
elmtType = "Array";
if (elmt->isStruct())
@ -263,10 +280,12 @@ namespace NLQT {
elmtType = "Atom";
uint numDefinitions = 0;
const UType *type = elmt->getType();
if (type) {
if (type)
{
numDefinitions = type->getNumDefinition();
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();
elmtType.append("_uint");break;
@ -285,21 +304,26 @@ namespace NLQT {
}
}
if (numDefinitions) {
if (numDefinitions)
{
std::string l, v;
QString tmpLabel, tmpValue;
for (uint i = 0; i < numDefinitions; i++) {
for (uint i = 0; i < numDefinitions; i++)
{
type->getDefinition(i,l,v);
tmpLabel = l.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()) {
value = l;
break;
}
}
if (type->getType() == UType::String) {
if (QString(value.c_str()) == tmpValue) {
if (type->getType() == UType::String)
{
if (QString(value.c_str()) == tmpValue)
{
value = l;
break;
}
@ -307,11 +331,13 @@ namespace NLQT {
}
}
}
if (elmt->isVirtualStruct()){
if (elmt->isVirtualStruct())
{
root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
elmtType = "VirtualStruct";
}
switch (*whereN) {
switch (*whereN)
{
case UFormElm::NodeForm:
elmtType.append("_fromForm"); break;
case UFormElm::NodeParentForm:
@ -323,7 +349,8 @@ namespace NLQT {
default:
elmtType.append("_noNode");
}
switch (*whereV) {
switch (*whereV)
{
case UFormElm::ValueForm:
elmtType.append("_formValue"); break;
case UFormElm::ValueParentForm:
@ -341,7 +368,9 @@ namespace NLQT {
// parents << parents.last()->child(parents.last()->childCount()-1);
//}
loadFormData(elmt, parent->child(parent->childCount()-1));
} else {
}
else
{
// add Defaults
//columnData << QString(elmName.c_str()) << QString("default") << QString("default");
//parent->appendChild(new CFormItem(elmt, columnData, parent, UFormElm::ValueDefaultDfn, UFormElm::NodeDfn));
@ -352,25 +381,30 @@ namespace NLQT {
num++;
}
}
if (root->isArray()) {
if (root->isArray())
{
uint arraySize = 0;
root->getArraySize(arraySize);
while (num < arraySize) {
while (num < arraySize)
{
std::string elmName;
if(root->getArrayNodeName(elmName, num)) {
if(root->getArrayNodeName(elmName, num))
{
QList<QVariant> columnData;
std::string value;
QString elmtType = "";
//root->getValueByName(value, elmName.c_str());
UFormElm *elmt = 0;
if(root->getArrayNode(&elmt,0) && elmt) {
if(root->getArrayNode(&elmt,0) && elmt)
{
if (elmt->isArray())
elmtType = "Array";
if (elmt->isStruct()) {
elmtType = "Struct";
}
if (elmt->isAtom()) {
if (elmt->isAtom())
{
elmt->getValue(value);
elmtType = "Atom";
}
@ -388,12 +422,14 @@ namespace NLQT {
/******************************************************************************/
void CGeorgesFormModel::loadFormHeader() {
void CGeorgesFormModel::loadFormHeader()
{
CFormItem *fi_pars = new CFormItem(_rootElm, QList<QVariant>() << "parents", _rootItem);
_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));
}
@ -433,7 +469,8 @@ namespace NLQT {
/******************************************************************************/
void CGeorgesFormModel::setupModelData() {
void CGeorgesFormModel::setupModelData()
{
loadFormHeader();
loadFormData(_rootElm, _rootItem);
}

View file

@ -32,12 +32,13 @@ namespace NLGEORGES {
class UFormElm;
}
namespace NLQT {
namespace NLQT
{
class CFormItem;
class CGeorgesFormModel : public QAbstractItemModel {
Q_OBJECT
class CGeorgesFormModel : public QAbstractItemModel
{
public:
CGeorgesFormModel(NLGEORGES::UFormElm *root, QMap< QString, QStringList> deps,

View file

@ -21,7 +21,8 @@
// NeL includes
#include <nel/misc/debug.h>
namespace NLQT {
namespace NLQT
{
bool CGeorgesFormProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const

View file

@ -23,13 +23,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Qt includes
#include <QSortFilterProxyModel>
namespace NLQT {
namespace NLQT
{
class CGeorgesFormProxyModel : public QSortFilterProxyModel {
class CGeorgesFormProxyModel : public QSortFilterProxyModel
{
public:
CGeorgesFormProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent){}
~CGeorgesFormProxyModel() {}
CGeorgesFormProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent)
{
}
~CGeorgesFormProxyModel()
{
}
protected:
virtual bool filterAcceptsColumn ( int source_column, const QModelIndex & source_parent ) const ;

View file

@ -30,10 +30,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Project includes
#include "qt_displayer.h"
namespace NLQT {
namespace NLQT
{
CGeorgesLogDialog::CGeorgesLogDialog(QWidget *parent):
QDockWidget(parent){
QDockWidget(parent)
{
_ui.setupUi(this);
@ -46,7 +48,8 @@ namespace NLQT {
}
CGeorgesLogDialog::~CGeorgesLogDialog() {
CGeorgesLogDialog::~CGeorgesLogDialog()
{
NLMISC::ErrorLog->removeDisplayer(_displayer);
NLMISC::WarningLog->removeDisplayer(_displayer);
NLMISC::DebugLog->removeDisplayer(_displayer);

View file

@ -30,12 +30,12 @@
// Project includes
#include "ui_log_form.h"
namespace NLQT {
namespace NLQT
{
class CQtDisplayer;
class CGeorgesLogDialog: public QDockWidget
{
Q_OBJECT
public:
CGeorgesLogDialog(QWidget *parent = 0);

View file

@ -33,9 +33,11 @@
using namespace std;
using namespace NLMISC;
namespace NLQT {
namespace NLQT
{
namespace {
namespace
{
CFileDisplayer *s_FileDisplayer = NULL;
@ -43,7 +45,8 @@ CFileDisplayer *s_FileDisplayer = NULL;
} /* 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);
@ -51,7 +54,8 @@ void messageHandler(QtMsgType p_type, const char* p_msg) {
file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
QChar code;
switch (p_type) {
switch (p_type)
{
case QtDebugMsg: code = 'D'; break;
case QtWarningMsg: code = 'W'; break;
case QtCriticalMsg: code = 'C'; break;

View file

@ -36,12 +36,11 @@
using namespace std;
using namespace NLMISC;
namespace NLQT {
namespace NLQT
{
CMainWindow::CMainWindow(QWidget *parent)
: QMainWindow(parent),
_GeorgesLogDialog(0), _ObjectViewerDialog(0),
: QMainWindow(parent), _GeorgesLogDialog(0), _ObjectViewerDialog(0),
_GeorgesDirTreeDialog(0)
{
setWindowTitle("Qt Georges Editor");
@ -62,15 +61,18 @@ CMainWindow::CMainWindow(QWidget *parent)
// load and set leveldesign path from config
QString ldPath = Modules::config().configLeveldesignPath().c_str();
QFileInfo info(ldPath);
if (!info.isDir()) ldPath = "";
if (!info.isDir())
ldPath = "";
// create georges dir dock widget
_GeorgesDirTreeDialog = new CGeorgesDirTreeDialog(ldPath, this);
addDockWidget(Qt::LeftDockWidgetArea, _GeorgesDirTreeDialog);
if (ldPath == "") {
if (ldPath == "")
{
if (QMessageBox::information(this, tr("Missing leveldesign path"),
tr("Your leveldesign path seems to be empty or incorrect.\nDo you want to set it now?"),
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok)
{
settings();
}
}
@ -127,29 +129,36 @@ CMainWindow::~CMainWindow()
delete _GeorgesLogDialog;
}
void CMainWindow::openTreeView(QString file) {
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) {
Q_FOREACH(CGeorgesTreeViewDialog* dlg, _treeViewList)
{
if (dlg->loadedForm == file)
newView = dlg;
}
if (!newView) {
if (!newView)
{
newView = new CGeorgesTreeViewDialog(this);
//newView->setAllowedAreas(Qt::TopDockWidgetArea | Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
newView->setWindowTitle(file);
if (_treeViewList.isEmpty()) {
if (_treeViewList.isEmpty())
{
_emptyView->deleteLater();
addDockWidget(Qt::TopDockWidgetArea, newView);
} else {
}
else
{
tabifyDockWidget(_treeViewList.first(),newView);
QTabBar* tb = Modules::mainWin().getTabBar();
if (tb) {
if (tb)
{
disconnect(tb, SIGNAL(currentChanged ( int ) ),
this,SLOT(tabChanged(int)));
connect(tb, SIGNAL(currentChanged ( int ) ),
@ -320,7 +329,8 @@ void CMainWindow::createMenus()
_viewMenu->addAction(_GeorgesDirTreeDialog->toggleViewAction());
_toolsMenu = menuBar()->addMenu(tr("&Tools"));
if (_ObjectViewerDialog) {
if (_ObjectViewerDialog)
{
_toolsMenu->addAction(_ObjectViewerDialog->toggleViewAction());
_ObjectViewerDialog->toggleViewAction()->setIcon(QIcon(":/images/pqrticles.png"));
}
@ -358,8 +368,10 @@ void CMainWindow::cfcbQtStyle(NLMISC::CConfigFile::CVar &var)
void CMainWindow::cfcbQtPalette(NLMISC::CConfigFile::CVar &var)
{
if (var.asBool()) QApplication::setPalette(QApplication::style()->standardPalette());
else QApplication::setPalette(_originalPalette);
if (var.asBool())
QApplication::setPalette(QApplication::style()->standardPalette());
else
QApplication::setPalette(_originalPalette);
}
QTabBar* CMainWindow::getTabBar()
@ -371,7 +383,8 @@ QTabBar* CMainWindow::getTabBar()
// arg(QString::number((int)_mainWindow,16)).
// toStdString().c_str());
QTabBar *tb = 0;
Q_FOREACH(QTabBar *tabBar, tabList){
Q_FOREACH(QTabBar *tabBar, tabList)
{
if (tabBar->parent() != this)
continue;
//nlinfo(QString("%1 %2 %3 %4").arg(tabBar->objectName()).
@ -379,7 +392,8 @@ QTabBar* CMainWindow::getTabBar()
// 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++) {
for (int i = 0; i < tabBar->count(); i++)
{
QString currentTab = tabBar->tabText(i);
//nlinfo(currentTab.toStdString().c_str());
}
@ -390,7 +404,8 @@ QTabBar* CMainWindow::getTabBar()
void CMainWindow::tabChanged(int index)
{
if (index == -1) {
if (index == -1)
{
setWindowTitle("Qt Georges Editor");
return;
}
@ -398,8 +413,10 @@ void CMainWindow::tabChanged(int index)
QTabBar *tb = getTabBar();
//nlinfo(QString("%1").arg(index).toStdString().c_str());
Q_FOREACH(CGeorgesTreeViewDialog* dlg, _treeViewList) {
if (dlg->windowTitle() == tb->tabText(index)) {
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());
@ -436,7 +453,8 @@ void CMainWindow::tabChanged(int index)
settings.setValue("List",files);
settings.endGroup();
Q_FOREACH (QWidget *widget, QApplication::topLevelWidgets()) {
Q_FOREACH (QWidget *widget, QApplication::topLevelWidgets())
{
CMainWindow *mainWin = qobject_cast<CMainWindow *>(widget);
if (mainWin)
mainWin->updateRecentFileActions();
@ -451,7 +469,8 @@ void CMainWindow::tabChanged(int index)
settings.endGroup();
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);
recentFileActs[i]->setData(files[i]);
@ -483,6 +502,7 @@ void CMainWindow::tabChanged(int index)
setCurrentFile(fileName);
//statusBar()->showMessage(tr("File loaded"), 2000);
}
} /* namespace NLQT */
/* end of file */

View file

@ -33,18 +33,19 @@
// Project includes
namespace NLMISC {
namespace NLMISC
{
class CConfigFile;
}
namespace NLQT {
namespace NLQT
{
class CGeorgesLogDialog;
class CObjectViewerDialog;
class CGeorgesDirTreeDialog;
class CGeorgesTreeViewDialog;
class CMainWindow : public QMainWindow
{
Q_OBJECT

View file

@ -49,7 +49,8 @@ using namespace std;
using namespace NLMISC;
using namespace NL3D;
namespace NLQT {
namespace NLQT
{
CObjectViewer::CObjectViewer()
: _Driver(NULL),

View file

@ -33,7 +33,8 @@
// Project includes
#include "entity.h"
namespace NL3D {
namespace NL3D
{
class UDriver;
class UScene;
class ULight;
@ -48,7 +49,8 @@ namespace NL3D {
namespace NLQT
@brief namespace NLQT
*/
namespace NLQT {
namespace NLQT
{
/**
@class CObjectViewer

View file

@ -39,7 +39,8 @@
using namespace std;
using namespace NL3D;
namespace NLQT {
namespace NLQT
{
CObjectViewerDialog::CObjectViewerDialog(QWidget *parent)
: _isGraphicsInitialized(false), _isGraphicsEnabled(false), QDockWidget(parent)
@ -68,7 +69,8 @@ CObjectViewerDialog::CObjectViewerDialog(QWidget *parent)
_mainTimer->start(5); // 25fps
}
CObjectViewerDialog::~CObjectViewerDialog() {
CObjectViewerDialog::~CObjectViewerDialog()
{
_mainTimer->stop();
}
@ -325,7 +327,8 @@ void CObjectViewerDialog::wheelEvent(QWheelEvent *event)
}
uint32 CObjectViewerDialog::getNelButtons(QMouseEvent *event) {
uint32 CObjectViewerDialog::getNelButtons(QMouseEvent *event)
{
//nldebug("CObjectViewerDialog::getNelButtons");
uint32 buttons = NLMISC::noButton;
if(event->buttons() & Qt::LeftButton) buttons |= NLMISC::leftButton;
@ -338,7 +341,8 @@ uint32 CObjectViewerDialog::getNelButtons(QMouseEvent *event) {
return buttons;
}
uint32 CObjectViewerDialog::getNelButtons(QWheelEvent *event) {
uint32 CObjectViewerDialog::getNelButtons(QWheelEvent *event)
{
//nldebug("CObjectViewerDialog::getNelButtons");
uint32 buttons = NLMISC::noButton;
if(event->buttons() & Qt::LeftButton) buttons |= NLMISC::leftButton;
@ -351,7 +355,8 @@ uint32 CObjectViewerDialog::getNelButtons(QWheelEvent *event) {
return buttons;
}
void CObjectViewerDialog::mousePressEvent(QMouseEvent *event) {
void CObjectViewerDialog::mousePressEvent(QMouseEvent *event)
{
//nldebug("CObjectViewerDialog::mousePressEvent");
// Get relative positions.
float fX = 1.0f - (float)event->pos().x() / this->width();
@ -374,7 +379,8 @@ void CObjectViewerDialog::mousePressEvent(QMouseEvent *event) {
(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.
float fX = 1.0f - (float)event->pos().x() / this->width();
@ -394,7 +400,8 @@ void CObjectViewerDialog::mouseReleaseEvent(QMouseEvent *event) {
new NLMISC::CEventMouseUp( -fX, fY, NLMISC::rightButton, this));
}
void CObjectViewerDialog::mouseMoveEvent(QMouseEvent *event) {
void CObjectViewerDialog::mouseMoveEvent(QMouseEvent *event)
{
//nldebug("CObjectViewerDialog::mouseMoveEvent");
// Get relative positions.
float fX = 1.0f - (float)event->pos().x() / this->width();

View file

@ -45,7 +45,8 @@ typedef QGLWidget QNLWidget;
class QAction;
namespace NLQT {
namespace NLQT
{
class CObjectViewerDialog: public QDockWidget, public NLMISC::IEventEmitter
{

View file

@ -24,14 +24,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <nel/misc/debug.h>
#include <nel/misc/file.h>
namespace NLQT {
namespace NLQT
{
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);
}
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;
//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;
std::string str;
@ -58,7 +64,8 @@ namespace NLQT {
needSpace = true;
}
if (args.LogType != NLMISC::CLog::LOG_NO && !_Raw) {
if (args.LogType != NLMISC::CLog::LOG_NO && !_Raw)
{
if (needSpace) { str += " "; needSpace = false; }
str += logTypeToString(args.LogType);
if (args.LogType == NLMISC::CLog::LOG_WARNING)
@ -92,13 +99,20 @@ namespace NLQT {
needSpace = true;
}*/
if (args.FuncName != NULL && !_Raw) {
if (needSpace) { str += " "; needSpace = false; }
if (args.FuncName != NULL && !_Raw)
{
if (needSpace)
{
str += " "; needSpace = false;
}
str += args.FuncName;
needSpace = true;
}
if (needSpace) { str += " : "; needSpace = false; }
if (needSpace)
{
str += " : "; needSpace = false;
}
str += message;

View file

@ -28,10 +28,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Qt includes
#include <QPlainTextEdit>
namespace NLQT {
namespace NLQT
{
class CQtDisplayer : virtual public NLMISC::IDisplayer
{
public:
CQtDisplayer(QPlainTextEdit *dlgDebug, bool eraseLastLog = false, const char *displayerName = "", bool raw = false);
CQtDisplayer();

View file

@ -31,7 +31,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using namespace NLMISC;
namespace NLQT {
namespace NLQT
{
CSettingsDialog::CSettingsDialog(QWidget *parent)
: QDialog(parent)
@ -72,7 +73,8 @@ namespace NLQT {
QFileDialog dialog(this);
dialog.setOption(QFileDialog::ShowDirsOnly, true);
dialog.setFileMode(QFileDialog::Directory);
if (dialog.exec()) {
if (dialog.exec())
{
QString newPath = dialog.selectedFiles().first();
if (!newPath.isEmpty())
{
@ -137,9 +139,12 @@ namespace NLQT {
list.push_back(str);
}
if (list.empty()) {
if (list.empty())
{
Modules::config().getConfigFile().getVar("SearchPaths").forceAsString("");
} else {
}
else
{
Modules::config().getConfigFile().getVar("SearchPaths").forceAsString("");
Modules::config().getConfigFile().getVar("SearchPaths").setAsString(list);
}
@ -197,4 +202,5 @@ namespace NLQT {
ui.leveldesignPath->setText(QFileDialog::getExistingDirectory(this, tr("Open Directory"),
QDir::currentPath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
}
} /* namespace NLQT */

View file

@ -29,7 +29,8 @@
// Project includes
namespace NLQT {
namespace NLQT
{
class CSettingsDialog: public QDialog
{

View file

@ -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();
}
}

View file

@ -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