Commit aab086da91f7fed5516765d8875311db38f74ce3
- Diff rendering mode:
- inline
- side by side
src/tiled/mainwindow.cpp
(22 / 3)
|   | |||
| 74 | 74 | #include <QUndoGroup> | |
| 75 | 75 | #include <QUndoStack> | |
| 76 | 76 | #include <QUndoView> | |
| 77 | #include <QImageReader> | ||
| 77 | 78 | ||
| 78 | 79 | using namespace Tiled; | |
| 79 | 80 | using namespace Tiled::Internal; | |
| … | … | ||
| 342 | 342 | ||
| 343 | 343 | void MainWindow::dropEvent(QDropEvent *e) | |
| 344 | 344 | { | |
| 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); | ||
| 346 | 360 | } | |
| 347 | 361 | ||
| 348 | 362 | void MainWindow::newMap() | |
| … | … | ||
| 742 | 742 | preferencesDialog.exec(); | |
| 743 | 743 | } | |
| 744 | 744 | ||
| 745 | void MainWindow::newTileset() | ||
| 745 | void MainWindow::newTileset(const QString &path) | ||
| 746 | 746 | { | |
| 747 | 747 | if (!mMapDocument) | |
| 748 | 748 | return; | |
| 749 | 749 | ||
| 750 | 750 | Map *map = mMapDocument->map(); | |
| 751 | 751 | ||
| 752 | NewTilesetDialog newTileset(fileDialogStartLocation(), this); | ||
| 752 | QString startLocation = path.isEmpty() | ||
| 753 | ? fileDialogStartLocation() | ||
| 754 | : path; | ||
| 755 | |||
| 756 | NewTilesetDialog newTileset(startLocation, this); | ||
| 753 | 757 | newTileset.setTileWidth(map->tileWidth()); | |
| 754 | 758 | newTileset.setTileHeight(map->tileHeight()); | |
| 755 | 759 |
src/tiled/mainwindow.h
(1 / 1)
|   | |||
| 105 | 105 | void paste(); | |
| 106 | 106 | void openPreferences(); | |
| 107 | 107 | ||
| 108 | void newTileset(); | ||
| 108 | void newTileset(const QString &path = QString()); | ||
| 109 | 109 | void addExternalTileset(); | |
| 110 | 110 | void resizeMap(); | |
| 111 | 111 | void offsetMap(); |
|   | |||
| 29 | 29 | #include <QImage> | |
| 30 | 30 | #include <QMessageBox> | |
| 31 | 31 | #include <QSettings> | |
| 32 | #include <QFileInfo> | ||
| 32 | 33 | ||
| 33 | 34 | #include <memory> | |
| 34 | 35 | ||
| … | … | ||
| 67 | 67 | connect(mUi->name, SIGNAL(textEdited(QString)), SLOT(nameEdited(QString))); | |
| 68 | 68 | connect(mUi->name, SIGNAL(textChanged(QString)), SLOT(updateOkButton())); | |
| 69 | 69 | 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 | } | ||
| 70 | 77 | ||
| 71 | 78 | updateOkButton(); | |
| 72 | 79 | } |
src/tiled/newtilesetdialog.h
(5 / 0)
|   | |||
| 41 | 41 | Q_OBJECT | |
| 42 | 42 | ||
| 43 | 43 | public: | |
| 44 | /** | ||
| 45 | * Constructs a new tileset dialog | ||
| 46 | * | ||
| 47 | * @param path the path to start in by default, or an image file | ||
| 48 | */ | ||
| 44 | 49 | NewTilesetDialog(const QString &path, QWidget *parent = 0); | |
| 45 | 50 | ~NewTilesetDialog(); | |
| 46 | 51 |

