Changed: #1409 Adding zoom functionality to views, trying to fix icon size problem.

--HG--
branch : branch-tile-edit-ovqt-plugin
This commit is contained in:
sfb 2012-03-02 14:17:38 -06:00
parent f6f664452d
commit 5eb9d2f2a0
6 changed files with 77 additions and 32 deletions

View file

@ -139,7 +139,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
m_zoomSignalMapper->setMapping(m_ui->actionZoom100, 1);
connect(m_ui->actionZoom200, SIGNAL(triggered()), m_zoomSignalMapper, SLOT(map()));
m_zoomSignalMapper->setMapping(m_ui->actionZoom200, 2);
connect(m_zoomSignalMapper, SIGNAL(mapped(int)), m_model, SLOT(onZoomFactor(int)));
connect(m_zoomSignalMapper, SIGNAL(mapped(int)), this, SLOT(onZoomFactor(int)));
}
TileEditorMainWindow::~TileEditorMainWindow()
@ -158,6 +158,53 @@ TileEditorMainWindow::~TileEditorMainWindow()
delete m_zoomSignalMapper;
}
void TileEditorMainWindow::onZoomFactor(int level)
{
int tile128Scaled=TileModel::TILE_128_BASE_SIZE;
int tile256Scaled=TileModel::TILE_256_BASE_SIZE;
int tileTransScaled=TileModel::TILE_TRANSITION_BASE_SIZE;
int tileDispScaled=TileModel::TILE_DISPLACE_BASE_SIZE;
switch(level)
{
// Zoom Level 50%
case 0:
nlinfo("zooming to 50%");
TileModel::CurrentZoomFactor = TileModel::TileZoom50;
tile128Scaled /= 2;
tile256Scaled /= 2;
tileTransScaled /= 2;
tileDispScaled /= 2;
break;
case 1:
nlinfo("zooming to 100%");
TileModel::CurrentZoomFactor = TileModel::TileZoom100;
break;
case 2:
nlinfo("zooming to 200%");
TileModel::CurrentZoomFactor = TileModel::TileZoom200;
tile128Scaled *= 2;
tile256Scaled *= 2;
tileTransScaled *= 2;
tileDispScaled *= 2;
break;
default:
nlwarning("Invalid Time Zoom Factor passed.");
break;
};
nlinfo("resizing transition view. base size: %d factor %d to: %d", TileModel::TILE_TRANSITION_BASE_SIZE, level, tileTransScaled);
m_ui->listView128->setIconSize(QSize(tile128Scaled, tile128Scaled));
m_ui->listView128->setCurrentIndex(m_ui->listView128->model()->index(0, 0, m_ui->listView128->rootIndex()));
m_ui->listView256->setIconSize(QSize(tile256Scaled, tile256Scaled));
m_ui->listView256->setCurrentIndex(m_ui->listView256->model()->index(0, 0, m_ui->listView256->rootIndex()));
m_ui->listViewTransition->setIconSize(QSize(tileTransScaled, tileTransScaled));
m_ui->listViewTransition->setCurrentIndex(m_ui->listViewTransition->model()->index(0, 0, m_ui->listViewTransition->rootIndex()));
m_ui->listViewDisplacement->setIconSize(QSize(tileDispScaled, tileDispScaled));
m_ui->listViewDisplacement->setCurrentIndex(m_ui->listViewDisplacement->model()->index(0, 0, m_ui->listViewDisplacement->rootIndex()));
m_ui->listViewTransition->repaint();
}
void TileEditorMainWindow::onActionAddTile(bool triggered)
{
onActionAddTile(m_ui->tileViewTabWidget->currentIndex());

View file

@ -40,7 +40,7 @@ public:
explicit TileEditorMainWindow(QWidget *parent = 0);
~TileEditorMainWindow();
QUndoStack *getUndoStack() { return m_undoStack; }
QUndoStack *getUndoStack() { return m_undoStack; }
public Q_SLOTS:
void onActionAddTile(bool triggered);
@ -48,7 +48,8 @@ public Q_SLOTS:
void onActionReplaceImage(bool triggered);
void onActionDeleteImage(bool triggered);
void onTileSetAdd();
void changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex);
void changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex);
void onZoomFactor(int level);
private:
void onActionAddTile(int tabId);

View file

@ -155,6 +155,9 @@
<height>64</height>
</size>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
@ -226,6 +229,9 @@
<height>32</height>
</size>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>

View file

@ -223,7 +223,7 @@ TileItemNode::TileItemNode(int tileId, TileModel::TTileChannel channel, QString
{
m_tileFilename[channel] = filename;
m_parentItem = parent;
nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileModel::TileDiffuse].toStdString().c_str());
//nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileModel::TileDiffuse].toStdString().c_str());
}
TileItemNode::~TileItemNode()
@ -257,7 +257,12 @@ QVariant TileItemNode::data(int column, int role) const
if(!pixmap.load(tileFilename))
nlinfo("failed to load %s", tileFilename.toStdString().c_str());
//pixmap.scaled(tileSize*100, tileSize*100);
if(TileModel::CurrentZoomFactor == TileModel::TileZoom200)
tileSize *= 2;
else if(TileModel::CurrentZoomFactor == TileModel::TileZoom50)
tileSize /= 2;
pixmap.scaled(tileSize, tileSize);
return pixmap;
}

View file

@ -21,6 +21,9 @@
#include <nel/misc/debug.h>
// Initialize the static members
TileModel::TTileZoomFactor TileModel::CurrentZoomFactor;
TileModel::TileModel(const QStringList &headers, QObject *parent) : QAbstractItemModel(parent)
{
QVector<QVariant> rootData;
@ -29,7 +32,7 @@ TileModel::TileModel(const QStringList &headers, QObject *parent) : QAbstractIte
rootItem = new Node(rootData);
m_tileZoomFactor = TileZoom100;
TileModel::CurrentZoomFactor = TileModel::TileZoom100;
m_indexDisplay = true;
m_fileDisplay = true;
}
@ -224,27 +227,4 @@ void TileModel::selectFilenameDisplay(bool selected)
void TileModel::selectIndexDisplay(bool selected)
{
m_indexDisplay = selected;
}
void TileModel::onZoomFactor(int level)
{
switch(level)
{
// Zoom Level 50%
case 0:
nlinfo("zooming to 50%");
m_tileZoomFactor = TileZoom50;
break;
case 1:
nlinfo("zooming to 100%");
m_tileZoomFactor = TileZoom100;
break;
case 2:
nlinfo("zooming to 200%");
m_tileZoomFactor = TileZoom200;
break;
default:
nlwarning("Invalid Time Zoom Factor passed.");
break;
};
}

View file

@ -59,6 +59,11 @@ public:
TileZoom200 = 2
};
static const int TILE_DISPLACE_BASE_SIZE = 32;
static const int TILE_TRANSITION_BASE_SIZE = 64;
static const int TILE_128_BASE_SIZE = 128;
static const int TILE_256_BASE_SIZE = 256;
TileModel(const QStringList &headers, QObject *parent);
~TileModel();
@ -80,17 +85,18 @@ public:
static const char *getTileTypeName(TNodeTileType type);
static uint32 getTileTypeSize(TileModel::TNodeTileType type);
static TTileZoomFactor CurrentZoomFactor;
public Q_SLOTS:
void selectFilenameDisplay(bool selected);
void selectIndexDisplay(bool selected);
void onZoomFactor(int level);
void selectIndexDisplay(bool selected);
private:
Node *getItem(const QModelIndex &index) const;
bool m_fileDisplay;
bool m_indexDisplay;
TTileZoomFactor m_tileZoomFactor;
//TTileZoomFactor m_tileZoomFactor;
//QList<TileItem*> m_tiles;
//int m_activeEditChannel;