Prototype of the texture chooser.

This commit is contained in:
dfighter1985 2014-07-05 02:55:46 +02:00
parent cf2e18143f
commit 95defff448
6 changed files with 263 additions and 0 deletions

View file

@ -31,6 +31,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR
editor_selection_watcher.h editor_selection_watcher.h
editor_message_processor.h editor_message_processor.h
action_list.h action_list.h
texture_chooser.h
) )
SET(OVQT_PLUGIN_GUI_EDITOR_UIS SET(OVQT_PLUGIN_GUI_EDITOR_UIS
@ -47,6 +48,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_UIS
new_widget_widget.ui new_widget_widget.ui
add_widget_widget.ui add_widget_widget.ui
action_list.ui action_list.ui
texture_chooser.ui
) )
SET(QT_USE_QTGUI TRUE) SET(QT_USE_QTGUI TRUE)

View file

@ -44,6 +44,7 @@
#include "editor_selection_watcher.h" #include "editor_selection_watcher.h"
#include "editor_message_processor.h" #include "editor_message_processor.h"
#include "add_widget_widget.h" #include "add_widget_widget.h"
#include "texture_chooser.h"
namespace GUIEditor namespace GUIEditor
{ {
@ -70,6 +71,8 @@ namespace GUIEditor
widgetInfoTree = new CWidgetInfoTree; widgetInfoTree = new CWidgetInfoTree;
tc = new TextureChooser();
createMenus(); createMenus();
readSettings(); readSettings();
@ -115,6 +118,9 @@ namespace GUIEditor
removeMenus(); removeMenus();
delete tc;
tc = NULL;
delete messageProcessor; delete messageProcessor;
messageProcessor = NULL; messageProcessor = NULL;
@ -353,6 +359,12 @@ namespace GUIEditor
GUICtrl->show(); GUICtrl->show();
} }
void GUIEditorWindow::onTCClicked()
{
tc->load();
tc->exec();
}
void GUIEditorWindow::createMenus() void GUIEditorWindow::createMenus()
{ {
Core::MenuManager *mm = Core::ICore::instance()->menuManager(); Core::MenuManager *mm = Core::ICore::instance()->menuManager();
@ -399,6 +411,10 @@ namespace GUIEditor
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onAddWidgetClicked() ) ); connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onAddWidgetClicked() ) );
m->addAction( a ); m->addAction( a );
a = new QAction( "Texture Chooser", this );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onTCClicked() ) );
m->addAction( a );
menu = m; menu = m;
} }
} }

View file

@ -28,6 +28,8 @@ class QtTreePropertyBrowser;
class QMenu; class QMenu;
class TextureChooser;
namespace GUIEditor namespace GUIEditor
{ {
@ -65,6 +67,7 @@ private Q_SLOTS:
void onGUILoaded(); void onGUILoaded();
void onAddWidgetClicked(); void onAddWidgetClicked();
void onTreeChanged(); void onTreeChanged();
void onTCClicked();
protected: protected:
@ -98,6 +101,8 @@ private:
QString currentProjectFile; QString currentProjectFile;
QMenu *menu; QMenu *menu;
TextureChooser *tc;
}; };
} }

View file

@ -0,0 +1,98 @@
#include "texture_chooser.h"
#include "nel/misc/path.h"
#include "nel/misc/bitmap.h"
#include "nel/misc/file.h"
#include <vector>
#include <string>
#include <QPixMap>
#include <QImage>
TextureChooser::TextureChooser( QDialog *parent ) :
QDialog( parent )
{
setupUi( this );
setupConnections();
data = NULL;
}
TextureChooser::~TextureChooser()
{
delete data;
data = NULL;
}
void TextureChooser::load()
{
listWidget->clear();
std::vector< std::string > textures;
NLMISC::CPath::getFileList( "tga", textures );
std::vector< std::string >::const_iterator itr = textures.begin();
while( itr != textures.end() )
{
listWidget->addItem( itr->c_str() );
++itr;
}
}
void TextureChooser::onCurrentRowChanged( int row )
{
if( row < 0 )
return;
QListWidgetItem *item = listWidget->item( row );
QString fn = item->text();
std::string rfn = fn.toUtf8().constData();
rfn = NLMISC::CPath::lookup( rfn );
NLMISC::CIFile f;
bool b = f.open( rfn );
if( !b )
{
return;
}
NLMISC::CBitmap bm;
uint8 depth = bm.load( f );
f.close();
uint32 size = bm.getSize() * ( 32 / 8 ); // should be depth, but CBitmap always uses 32 bit to store the image
if( data != NULL )
delete data;
data = new uint8[ size ];
bm.getData( data );
/// Convert from ABGR to ARGB
{
int i = 0;
while( i < size )
{
uint8 t = 0;
/// ABGR
t = data[ i ];
data[ i ] = data[ i + 2 ];
data[ i + 2 ] = t;
i += 4;
}
}
QImage img( data, bm.getWidth(), bm.getHeight(), QImage::Format_ARGB32 );
label->setPixmap( QPixmap::fromImage( img ) );
}
void TextureChooser::setupConnections()
{
connect( listWidget, SIGNAL( currentRowChanged( int ) ), this, SLOT( onCurrentRowChanged( int ) ) );
}

View file

@ -0,0 +1,26 @@
#ifndef TEXTURE_CHOOSER_H
#define TEXTURE_CHOOSER_H
#include "ui_texture_chooser.h"
class TextureChooser : public QDialog, public Ui::TextureChooser
{
Q_OBJECT
public:
TextureChooser( QDialog *parent = NULL );
~TextureChooser();
void load();
private Q_SLOTS:
void onCurrentRowChanged( int row );
private:
void setupConnections();
unsigned char *data;
};
#endif

View file

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TextureChooser</class>
<widget class="QDialog" name="TextureChooser">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>686</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Texture Chooser</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QListWidget" name="listWidget"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>351</width>
<height>231</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>131</width>
<height>31</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okButton">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>okButton</sender>
<signal>clicked()</signal>
<receiver>TextureChooser</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>278</x>
<y>253</y>
</hint>
<hint type="destinationlabel">
<x>96</x>
<y>254</y>
</hint>
</hints>
</connection>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>TextureChooser</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>369</x>
<y>253</y>
</hint>
<hint type="destinationlabel">
<x>179</x>
<y>282</y>
</hint>
</hints>
</connection>
</connections>
</ui>