mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-11 20:04:46 +00:00
Don't reload the pixmaps every time they are displayed... -.-
This commit is contained in:
parent
2ddd7e1035
commit
66c8b95e2d
3 changed files with 59 additions and 12 deletions
|
@ -264,23 +264,71 @@ void TileTypeNode::reindex()
|
|||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
|
||||
class TileItemNodePvt
|
||||
{
|
||||
public:
|
||||
|
||||
bool loadImage( TileModel::TTileChannel channel, const QString &fn )
|
||||
{
|
||||
QPixmap temp;
|
||||
bool b = temp.load( fn );
|
||||
|
||||
if( !b )
|
||||
return false;
|
||||
|
||||
pixmaps[ channel ] = temp;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void clearImage( TileModel::TTileChannel channel )
|
||||
{
|
||||
pixmaps[ channel ] = QPixmap();
|
||||
}
|
||||
|
||||
const QPixmap& pixMap( TileModel::TTileChannel channel ) const{
|
||||
return pixmaps[ channel ];
|
||||
}
|
||||
|
||||
private:
|
||||
QPixmap pixmaps[ TileModel::TileChannelCount ];
|
||||
|
||||
};
|
||||
|
||||
TileModel::TTileChannel TileItemNode::s_displayChannel = TileModel::TileDiffuse;
|
||||
|
||||
TileItemNode::TileItemNode(int tileId, TileModel::TTileChannel channel, QString filename, Node *parent) : m_tileId(tileId)
|
||||
{
|
||||
m_tileFilename[channel] = filename;
|
||||
m_parentItem = parent;
|
||||
//nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileModel::TileDiffuse].toAscii().data());
|
||||
|
||||
pvt = new TileItemNodePvt();
|
||||
|
||||
setTileFilename( channel, filename );
|
||||
}
|
||||
|
||||
TileItemNode::~TileItemNode()
|
||||
{
|
||||
delete pvt;
|
||||
pvt = NULL;
|
||||
|
||||
qDeleteAll(m_childItems);
|
||||
}
|
||||
|
||||
void TileItemNode::setTileFilename(TileModel::TTileChannel channel, QString filename)
|
||||
bool TileItemNode::setTileFilename(TileModel::TTileChannel channel, QString filename)
|
||||
{
|
||||
QString fn = filename;
|
||||
|
||||
if( filename.isEmpty() || ( filename == "empty" ) )
|
||||
fn = ":/placeHolder/images/empty_image.png";
|
||||
|
||||
bool b = pvt->loadImage( channel, fn );
|
||||
if( !b )
|
||||
return false;
|
||||
|
||||
m_tileFilename[channel] = filename;
|
||||
return true;
|
||||
}
|
||||
|
||||
QString TileItemNode::getTileFilename(TileModel::TTileChannel channel)
|
||||
|
@ -295,8 +343,7 @@ QString TileItemNode::getTileFilename(TileModel::TTileChannel channel)
|
|||
|
||||
QVariant TileItemNode::data(int column, int role) const
|
||||
{
|
||||
// find some way to know which file/bitmap to display
|
||||
QString tileFilename = m_tileFilename[s_displayChannel];
|
||||
QString tileFilename = m_tileFilename[ TileItemNode::s_displayChannel ];
|
||||
|
||||
if(role == TileModel::TilePixmapRole || role == Qt::DecorationRole)
|
||||
{
|
||||
|
@ -307,18 +354,13 @@ QVariant TileItemNode::data(int column, int role) const
|
|||
// Retrieve the target tile size.
|
||||
uint32 tileSize = TileModel::getTileTypeSize(parent->getTileType());
|
||||
|
||||
if(tileFilename.isEmpty() || tileFilename == "empty")
|
||||
tileFilename = ":/placeHolder/images/empty_image.png";
|
||||
|
||||
QPixmap pixmap;// = new QPixmap();
|
||||
if(!pixmap.load(tileFilename))
|
||||
nlinfo("failed to load %s", tileFilename.toAscii().data());
|
||||
|
||||
if(TileModel::CurrentZoomFactor == TileModel::TileZoom200)
|
||||
tileSize *= 2;
|
||||
else if(TileModel::CurrentZoomFactor == TileModel::TileZoom50)
|
||||
tileSize /= 2;
|
||||
|
||||
QPixmap pixmap = pvt->pixMap( TileItemNode::s_displayChannel );
|
||||
|
||||
pixmap.scaled(tileSize, tileSize);
|
||||
|
||||
return pixmap;
|
||||
|
|
|
@ -104,6 +104,8 @@ private:
|
|||
TileModel::TNodeTileType m_nodeTileType;
|
||||
};
|
||||
|
||||
class TileItemNodePvt;
|
||||
|
||||
class TileItemNode : public Node
|
||||
{
|
||||
public:
|
||||
|
@ -111,7 +113,7 @@ public:
|
|||
virtual ~TileItemNode();
|
||||
QVariant data(int column, int role) const;
|
||||
int columnCount() const;
|
||||
void setTileFilename(TileModel::TTileChannel channel, QString filename);
|
||||
bool setTileFilename(TileModel::TTileChannel channel, QString filename);
|
||||
QString getTileFilename(TileModel::TTileChannel channel);
|
||||
void setId( int id ){ m_tileId = id; }
|
||||
int id() const{ return m_tileId; }
|
||||
|
@ -125,6 +127,8 @@ private:
|
|||
QMap<TileModel::TTileChannel, TileWidget*> m_tileWidget;
|
||||
|
||||
static TileModel::TTileChannel s_displayChannel;
|
||||
|
||||
TileItemNodePvt *pvt;
|
||||
};
|
||||
|
||||
#endif // TILE_ITEM_H
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
TileDiffuse = 0,
|
||||
TileAdditive = 1,
|
||||
TileAlpha = 2,
|
||||
TileChannelCount = 3
|
||||
};
|
||||
|
||||
enum TNodeTileType
|
||||
|
|
Loading…
Reference in a new issue