Skip to content

Commit

Permalink
Allowed adding of new external tilesets
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn committed Jun 21, 2010
1 parent 01058d1 commit 244689c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
mUi->mapView->zoomable(), SLOT(resetZoom()));

connect(mUi->actionNewTileset, SIGNAL(triggered()), SLOT(newTileset()));
connect(mUi->actionAddExternalTileset, SIGNAL(triggered()),
SLOT(addExternalTileset()));
connect(mUi->actionResizeMap, SIGNAL(triggered()), SLOT(resizeMap()));
connect(mUi->actionOffsetMap, SIGNAL(triggered()), SLOT(offsetMap()));
connect(mUi->actionMapProperties, SIGNAL(triggered()),
Expand Down Expand Up @@ -626,6 +628,28 @@ void MainWindow::newTileset()
mMapDocument->undoStack()->push(new AddTileset(mMapDocument, tileset));
}

void MainWindow::addExternalTileset()
{
if (!mMapDocument)
return;

const QString start = fileDialogStartLocation();
const QString fileName =
QFileDialog::getOpenFileName(this, tr("Add External Tileset"),
start,
tr("Tiled tileset files (*.tsx)"));
if (fileName.isEmpty())
return;

TmxMapReader reader;
if (Tileset *tileset = reader.readTileset(fileName)) {
mMapDocument->undoStack()->push(new AddTileset(mMapDocument, tileset));
} else {
QMessageBox::critical(this, tr("Error Reading Tileset"),
reader.errorString());
}
}

void MainWindow::resizeMap()
{
if (!mMapDocument)
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private slots:
void openPreferences();

void newTileset();
void addExternalTileset();
void resizeMap();
void offsetMap();
void editMapProperties();
Expand Down
6 changes: 6 additions & 0 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<string>&amp;Map</string>
</property>
<addaction name="actionNewTileset"/>
<addaction name="actionAddExternalTileset"/>
<addaction name="separator"/>
<addaction name="actionResizeMap"/>
<addaction name="actionOffsetMap"/>
Expand Down Expand Up @@ -354,6 +355,11 @@
<string>&amp;Export As...</string>
</property>
</action>
<action name="actionAddExternalTileset">
<property name="text">
<string>&amp;Add External Tileset...</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
12 changes: 12 additions & 0 deletions src/tmxmapreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,15 @@ Map *TmxMapReader::fromString(const QString &string)

return map;
}

Tileset *TmxMapReader::readTileset(const QString &fileName)
{
mError.clear();

TmxReader reader;
Tileset *tileset = reader.readTileset(fileName);
if (!tileset)
mError = reader.errorString();

return tileset;
}
5 changes: 5 additions & 0 deletions src/tmxmapreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <QString>

namespace Tiled {

class Tileset;

namespace Internal {

/**
Expand All @@ -47,6 +50,8 @@ class TmxMapReader : public MapReaderInterface
*/
Map *fromString(const QString &string);

Tileset *readTileset(const QString &fileName);

QString nameFilter() const { return tr("Tiled map files (*.tmx)"); }

QString errorString() const { return mError; }
Expand Down

0 comments on commit 244689c

Please sign in to comment.