1 /*
2  * Copyright (C) 2014-2018 Christopho, Solarus - http://www.solarus-games.org
3  *
4  * Solarus Quest Editor is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Solarus Quest Editor is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef SOLARUSEDITOR_SPRITE_EDITOR_H
18 #define SOLARUSEDITOR_SPRITE_EDITOR_H
19 
20 #include "widgets/editor.h"
21 #include "ui_sprite_editor.h"
22 #include <QMenu>
23 #include <memory>
24 
25 namespace SolarusEditor {
26 
27 class SpriteModel;
28 
29 /**
30  * \brief A widget to edit graphically a sprite file.
31  */
32 class SpriteEditor : public Editor {
33   Q_OBJECT
34 
35 public:
36 
37   SpriteEditor(Quest& quest, const QString& path, QWidget* parent = nullptr);
38 
39   SpriteModel& get_model();
40 
41   void save() override;
42   void reload_settings() override;
43 
44 public slots:
45 
46   void update();
47 
48   void update_sprite_id_field();
49 
50   void update_description_to_gui();
51   void set_description_from_gui();
52 
53   void update_selection();
54   void create_requested();
55   void create_animation_requested();
56   void rename_animation_requested();
57   void create_direction_requested();
58   void add_direction_requested(
59     const QRect& frame, int num_frames, int num_columns);
60   void duplicate_requested();
61   void duplicate_selected_direction_requested(const QPoint &position);
62   void move_up_requested();
63   void move_down_requested();
64   void delete_requested();
65   void delete_direction_requested();
66 
67   void update_animation_view();
68   void update_default_animation_field();
69   void change_default_animation_requested();
70   void update_animation_source_image_field();
71   void change_animation_source_image_requested();
72   void refresh_animation_source_image();
73   void tileset_selector_activated();
74   void update_animation_frame_delay_field();
75   void change_animation_frame_delay_requested();
76   void update_animation_loop_on_frame_field();
77   void change_animation_loop_on_frame_requested();
78 
79   void update_direction_view();
80   void update_direction_size_field();
81   void change_direction_size_requested();
82   void update_direction_position_field();
83   void change_direction_position_requested_from_field();
84   void change_direction_position_requested(const QPoint& position);
85   void update_direction_origin_field();
86   void change_direction_origin_requested();
87   void update_direction_num_frames_field();
88   void change_direction_num_frames_requested();
89   void update_direction_num_columns_field();
90   void change_direction_num_columns_requested();
91   void change_direction_num_frames_columns_requested(
92     int num_frames, int num_columns);
93 
94 private:
95 
96   void load_settings();
97 
98   void auto_detect_grid_size();
99 
100   Ui::SpriteEditor ui;          /**< The sprite editor widgets. */
101   QString sprite_id;            /**< Id of the sprite being edited. */
102   std::unique_ptr<SpriteModel>
103       model;                    /**< Sprite model being edited. */
104   Quest& quest;                 /**< The quest. */
105   QMenu create_context_menu;    /**< The create context menu. */
106   QAction* create_animation;    /**< The create animation action. */
107   QAction* create_direction;    /**< The create direction action. */
108   bool auto_detect_grid;        /**< The grid auto detection option. */
109 
110 };
111 
112 }
113 
114 #endif
115