Commit aab086da91f7fed5516765d8875311db38f74ce3

Allow dragging an image onto Tiled to add a tileset

Mantis-issue: 46
  
7474#include <QUndoGroup>
7575#include <QUndoStack>
7676#include <QUndoView>
77#include <QImageReader>
7778
7879using namespace Tiled;
7980using namespace Tiled::Internal;
342342
343343void MainWindow::dropEvent(QDropEvent *e)
344344{
345 openFile(e->mimeData()->urls().at(0).toLocalFile());
345 const QString file = e->mimeData()->urls().at(0).toLocalFile();
346 const QString extension = QFileInfo(file).suffix();
347
348 // Treat file as a tileset if it is an image. Use the extension here because
349 // QImageReader::imageFormat() treats tmx files as svg
350 const QList<QByteArray> formats = QImageReader::supportedImageFormats();
351 foreach (const QByteArray &format, formats) {
352 if (extension.compare(QString::fromLatin1(format), Qt::CaseInsensitive) == 0) {
353 newTileset(file);
354 return;
355 }
356 }
357
358 // Treat file as a map otherwise
359 openFile(file);
346360}
347361
348362void MainWindow::newMap()
742742 preferencesDialog.exec();
743743}
744744
745void MainWindow::newTileset()
745void MainWindow::newTileset(const QString &path)
746746{
747747 if (!mMapDocument)
748748 return;
749749
750750 Map *map = mMapDocument->map();
751751
752 NewTilesetDialog newTileset(fileDialogStartLocation(), this);
752 QString startLocation = path.isEmpty()
753 ? fileDialogStartLocation()
754 : path;
755
756 NewTilesetDialog newTileset(startLocation, this);
753757 newTileset.setTileWidth(map->tileWidth());
754758 newTileset.setTileHeight(map->tileHeight());
755759
  
105105 void paste();
106106 void openPreferences();
107107
108 void newTileset();
108 void newTileset(const QString &path = QString());
109109 void addExternalTileset();
110110 void resizeMap();
111111 void offsetMap();
  
2929#include <QImage>
3030#include <QMessageBox>
3131#include <QSettings>
32#include <QFileInfo>
3233
3334#include <memory>
3435
6767 connect(mUi->name, SIGNAL(textEdited(QString)), SLOT(nameEdited(QString)));
6868 connect(mUi->name, SIGNAL(textChanged(QString)), SLOT(updateOkButton()));
6969 connect(mUi->image, SIGNAL(textChanged(QString)), SLOT(updateOkButton()));
70
71 // Set the image and name fields if the given path is a file
72 const QFileInfo fileInfo(path);
73 if (fileInfo.isFile()) {
74 mUi->image->setText(path);
75 mUi->name->setText(fileInfo.completeBaseName());
76 }
7077
7178 updateOkButton();
7279}
  
4141 Q_OBJECT
4242
4343public:
44 /**
45 * Constructs a new tileset dialog
46 *
47 * @param path the path to start in by default, or an image file
48 */
4449 NewTilesetDialog(const QString &path, QWidget *parent = 0);
4550 ~NewTilesetDialog();
4651