1 /*
2  * tileanimationeditor.h
3  * Copyright 2014, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
4  *
5  * This file is part of Tiled.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 
23 #include <QDialog>
24 #include <QModelIndex>
25 
26 namespace Ui {
27 class TileAnimationEditor;
28 }
29 
30 namespace Tiled {
31 
32 class Object;
33 class Tile;
34 class TileAnimationDriver;
35 class Tileset;
36 
37 class FrameListModel;
38 class TilesetDocument;
39 
40 class TileAnimationEditor : public QDialog
41 {
42     Q_OBJECT
43 
44 public:
45     explicit TileAnimationEditor(QWidget *parent = nullptr);
46     ~TileAnimationEditor();
47 
48     void setTilesetDocument(TilesetDocument *tilesetDocument);
49 
50 signals:
51     void closed();
52 
53 public slots:
54     void setTile(Tile *tile);
55 
56 protected:
57     void closeEvent(QCloseEvent *) override;
58     void changeEvent(QEvent *e) override;
59 
60     void showEvent(QShowEvent *) override;
61     void hideEvent(QHideEvent *) override;
62 
63 private:
64     void framesEdited();
65     void tileAnimationChanged(Tile *tile);
66     void currentObjectChanged(Object *object);
67 
68     void addFrameForTileAt(const QModelIndex &index);
69 
70     void setFrameTime();
71     void setDefaultFrameTime(int duration);
72     void undo();
73     void redo();
74     void delete_();
75 
76     void advancePreviewAnimation(int ms);
77     void resetPreview();
78     bool updatePreviewPixmap();
79 
80     Ui::TileAnimationEditor *mUi;
81 
82     TilesetDocument *mTilesetDocument = nullptr;
83     Tile *mTile = nullptr;
84     FrameListModel *mFrameListModel;
85     bool mApplyingChanges = false;
86     bool mSuppressUndo = false;
87 
88     TileAnimationDriver *mPreviewAnimationDriver;
89     int mPreviewFrameIndex = 0;
90     int mPreviewUnusedTime = 0;
91 };
92 
93 } // namespace Tiled
94