00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "asset.h"
00022
00023 #include <QtCore/QStringList>
00024 #include <QtCore/QFile>
00025 #include <QtCore/QDir>
00026 #include <QtCore/QMimeData>
00027 #include <QtGui/QAction>
00028
00029 REGISTER_OBJECTTYPE( GluonEngine, Asset )
00030
00031 using namespace GluonEngine;
00032
00033 class GluonEngine::AssetPrivate
00034 {
00035 public:
00036 AssetPrivate()
00037 {
00038 loaded = false;
00039 mime = 0;
00040 }
00041
00042 QUrl file;
00043 bool loaded;
00044 QMimeData* mime;
00045 };
00046
00047 Asset::Asset( QObject* parent )
00048 : GluonObject( parent )
00049 , d( new AssetPrivate )
00050 {
00051 d->mime = new QMimeData;
00052 }
00053
00054 Asset::~Asset()
00055 {
00056 delete d->mime;
00057 delete d;
00058 }
00059
00060 void
00061 Asset::setName( const QString& newName )
00062 {
00063 QString oldName( name() );
00064
00065 GluonCore::GluonObject::setName( newName );
00066
00067
00068 if( !d->file.isEmpty() )
00069 {
00070
00071 if( QDir( QDir::currentPath() ).exists( d->file.toLocalFile() ) )
00072 {
00073 QUrl newFile( QString( "Assets/%1.%2" ).arg( fullyQualifiedName() ).arg( QFileInfo( d->file.toLocalFile() ).completeSuffix() ) );
00074 if( QDir::current().rename( d->file.toLocalFile(), newFile.toLocalFile() ) )
00075 {
00076 setFile( newFile );
00077 }
00078 }
00079 }
00080 }
00081
00082 void
00083 Asset::setFile( const QUrl& newFile )
00084 {
00085 d->file = newFile;
00086 emit dataChanged();
00087 }
00088
00089 QUrl
00090 Asset::file() const
00091 {
00092 return d->file;
00093 }
00094
00095 QString
00096 Asset::absolutePath() const
00097 {
00098 QString filePath = d->file.toLocalFile();
00099 QString projectPath = gameProject()->property( "filename" ).toUrl().toLocalFile();
00100
00101 projectPath = projectPath.left( projectPath.lastIndexOf( '/' ) );
00102
00103 return projectPath + '/' + filePath;
00104 }
00105
00106 QIcon
00107 Asset::icon() const
00108 {
00109 return QIcon();
00110 }
00111
00112 const QMimeData *
00113 Asset::data() const
00114 {
00115 return d->mime;
00116 }
00117
00118 const QList<AssetTemplate*>
00119 Asset::templates()
00120 {
00121 QList<AssetTemplate*> templates;
00122 return templates;
00123 }
00124
00125 QList<QAction*>
00126 Asset::actions()
00127 {
00128 QList<QAction*> actions;
00129 actions.append( new QAction( "No actions defined.", this ) );
00130 actions.at( 0 )->setEnabled( false );
00131 return actions;
00132 }
00133
00134 bool
00135 Asset::isLoaded() const
00136 {
00137 return d->loaded;
00138 }
00139
00140 void
00141 Asset::load()
00142 {
00143 d->loaded = true;
00144 }
00145
00146 QString
00147 Asset::childrenToGDL( int indentLevel ) const
00148 {
00149 Q_UNUSED( indentLevel )
00150
00151
00152 return QString();
00153 }
00154
00155 QMimeData *
00156 Asset::mimeData() const
00157 {
00158 return d->mime;
00159 }
00160
00161 void
00162 Asset::setLoaded( bool loaded )
00163 {
00164 d->loaded = loaded;
00165 }
00166
00167 #include "asset.moc"