Commit 0341530d authored by Jan Möbius's avatar Jan Möbius

Show texture image in texturesettings dialog

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5708 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 533ba0eb
......@@ -51,6 +51,8 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil
{
std::cerr << "slotLocalTextureAdded " << _textureName.toStdString() << std::endl;
// TODO: Load texture?! ...
// Get the new object
BaseObjectData* obj;
if (! PluginFunctions::getObject( _id , obj ) ) {
......@@ -77,12 +79,26 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil
void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _filename , uint _dimension)
{
std::cerr << "slotGlobalTextureAdded " << _textureName.toStdString() << std::endl;
// Add this texture to the list of global textures
if ( ! globalTextures_.textureExists(_textureName) ) {
globalTextures_.addTexture(_textureName,_filename,_dimension,0);
globalTextures_.texture(_textureName).enabled = false;
QString loadFilename;
if ( _filename.startsWith("/") )
loadFilename = _filename;
else
loadFilename = OpenFlipper::Options::textureDirStr() + QDir::separator() + _filename;
QImage textureImage;
if ( !textureImage.load( loadFilename ) ){
emit log(LOGERR, "Cannot load texture " + _filename );
textureImage.load(OpenFlipper::Options::textureDirStr() + QDir::separator() + "unknown.png");
}
globalTextures_.texture(_textureName).textureImage = textureImage;
} else {
emit log(LOGERR,"Trying to add already existing global texture " + _textureName );
return;
......@@ -97,13 +113,13 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil
new_texture->setChecked(true);
textureActions_.push_back(new_texture);
}
void TextureControlPlugin::fileOpened( int _id ) {
// TODO:: Store original texture coords in a new property!
std::cerr << "File opened : " << _id << std::endl;
// Get the new object
BaseObjectData* obj;
if (! PluginFunctions::getObject( _id , obj ) ) {
......@@ -126,20 +142,22 @@ void TextureControlPlugin::fileOpened( int _id ) {
// Iterate over all available global textures and add them to the object
for ( uint i = 0 ; i < globalTextures_.textures().size() ; ++i) {
std::cerr << "Adding texture " << i << " " << globalTextures_.textures()[i].name.toStdString() << std::endl;
// ================================================================================
// Get the image file
// ================================================================================
// TODO: support arbitrary paths!
QString filename = OpenFlipper::Options::textureDir().absolutePath() +
OpenFlipper::Options::dirSeparator() +
globalTextures_.textures()[i].filename;
QString loadFilename;
if ( globalTextures_.textures()[i].filename.startsWith("/") )
loadFilename = globalTextures_.textures()[i].filename;
else
loadFilename = OpenFlipper::Options::textureDirStr() + QDir::separator() + globalTextures_.textures()[i].filename;
QImage textureImage;
if ( !textureImage.load( filename ) ){
emit log(LOGERR, "Cannot load texture " + filename );
continue;
if ( !textureImage.load( loadFilename ) ){
emit log(LOGERR, "Cannot load texture " + globalTextures_.textures()[i].filename );
textureImage.load(OpenFlipper::Options::textureDirStr() + QDir::separator() + "unknown.png");
}
// ================================================================================
......@@ -158,8 +176,15 @@ void TextureControlPlugin::fileOpened( int _id ) {
// Store texture information in objects metadata
// ================================================================================
if (glName != 0)
if (glName != 0) {
texData->addTexture(globalTextures_.textures()[i], glName);
texData->setImage(globalTextures_.textures()[i].name,textureImage);
}
else {
emit log(LOGERR,"Unable to bind Texture");
continue;
}
// ================================================================================
// Update texture mapping in meshNode
......
......@@ -155,6 +155,20 @@ int TextureData::addTexture ( Texture _texture, GLuint _glName ) {
return _texture.id;
}
/// Stores the given image in the texture information
bool TextureData::setImage( QString _textureName , QImage& _image ) {
int textureid = -1;
textureid = getTextureIndex(_textureName);
if ( textureid == -1) {
std::cerr << "setImage: Unknown Texture!" << std::endl;
return true;
}
textures_[textureid].textureImage = _image;
return false;
}
//-----------------------------------------------------------------------------------
/** \brief Delete a given texture
......
......@@ -35,6 +35,7 @@
#include <OpenFlipper/common/perObjectData.hh>
#include <QString>
#include <QImage>
#include <ACG/GL/gl.hh>
#include <vector>
#include <map>
......@@ -90,6 +91,8 @@ struct Texture {
uint type;
// Parameters
TexParameters parameters;
QImage textureImage;
};
class TextureData : public PerObjectData
......@@ -123,6 +126,9 @@ class TextureData : public PerObjectData
/// Add a Texture ( Based on an existing specification )
int addTexture ( Texture _texture, GLuint _glName );
/// Stores the given image in the texture information
bool setImage( QString _textureName , QImage& _image );
/*
/// Delete a given texture
void deleteTexture(QString _textureName);
......
......@@ -43,6 +43,7 @@
#include <float.h>
#include <QtGui>
#include <OpenFlipper/common/GlobalOptions.hh>
texturePropertiesWidget::texturePropertiesWidget(QWidget *parent)
: QDialog(parent)
......@@ -184,6 +185,15 @@ void texturePropertiesWidget::textureChanged(QListWidgetItem* _item){
clamp_min->setValue( texture.parameters.clamp_min );
clamp_max->setValue( texture.parameters.clamp_max );
// Show the texture Image
imageLabel->setPixmap(QPixmap::fromImage(texture.textureImage));
imageLabel->setScaledContents(true);
if ( !texture.filename.startsWith("/") )
fileLabel->setText( "File: " + texture.filename );
else
fileLabel->setText( "File: " + OpenFlipper::Options::textureDirStr() + QDir::separator() + texture.filename );
// update plot only when dimension is 1
if ( texture.dimension == 1) {
std::vector< double > x,y;
......
......@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>666</width>
<height>548</height>
<width>1186</width>
<height>633</height>
</rect>
</property>
<property name="minimumSize" >
......@@ -24,141 +24,199 @@
<property name="windowTitle" >
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" >
<item>
<layout class="QGridLayout" name="gridLayout_2" >
<item rowspan="2" row="0" column="0" >
<widget class="QSplitter" name="splitter" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="" >
<layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
<widget class="QLabel" name="textureLabel" >
<property name="text" >
<string>Textures:</string>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
<widget class="QLabel" name="textureLabel" >
<property name="text" >
<string>Textures:</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="textureList" >
<property name="alternatingRowColors" >
<bool>false</bool>
</property>
<property name="selectionBehavior" >
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="textureList" >
<property name="alternatingRowColors" >
<bool>false</bool>
</property>
<property name="selectionBehavior" >
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="" >
<layout class="QVBoxLayout" name="verticalLayout_3" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QCheckBox" name="repeatBox" >
<property name="text" >
<string>Repeat Texture</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item row="0" column="1" >
<layout class="QVBoxLayout" name="verticalLayout_3" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QLabel" name="label_3" >
<widget class="QCheckBox" name="repeatBox" >
<property name="text" >
<string>Maximum:</string>
<string>Repeat Texture</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="max_val" />
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Maximum:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="max_val" />
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="clampBox" >
<property name="text" >
<string>Clamp Texture</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QLabel" name="label" >
<widget class="QCheckBox" name="clampBox" >
<property name="text" >
<string>Minimum:</string>
<string>Clamp Texture</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="clamp_min" />
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Minimum:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="clamp_min" />
</item>
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Maximum:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="clamp_max" />
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2" >
<widget class="QCheckBox" name="centerBox" >
<property name="text" >
<string>Maximum:</string>
<string>Center</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="clamp_max" />
<widget class="QCheckBox" name="absBox" >
<property name="text" >
<string>Use Absolute values</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="scaleBox" >
<property name="text" >
<string>Scale</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="centerBox" >
<property name="text" >
<string>Center</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="absBox" >
<property name="text" >
<string>Use Absolute values</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="scaleBox" >
<property name="text" >
<string>Scale</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="originalData" >
<property name="minimumSize" >
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="title" >
<string>original Data</string>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="originalData" >
<property name="minimumSize" >
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="title" >
<string>original Data</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<item row="1" column="1" >
<spacer name="verticalSpacer" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>277</width>
<height>250</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" >
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="standardButtons" >
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QGroupBox" name="imageBox" >
<property name="minimumSize" >
<size>
<width>280</width>
<height>280</height>
</size>
</property>
<property name="title" >
<string>Image</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" >
<item>
<widget class="QLabel" name="imageLabel" >
<property name="minimumSize" >
<size>
<width>250</width>
<height>250</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>250</width>
<height>250</height>
</size>
</property>
<property name="text" >
<string>Image</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="fileLabel" >
<property name="text" >
<string>File:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment