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 #include "widgets/pattern_picker_dialog.h" 18 #include "tileset_model.h" 19 #include <QDebug> 20 21 namespace SolarusEditor { 22 23 /** 24 * @brief Creates a pattern picker dialog. 25 * @param tileset The tileset to show. 26 * @param parent Parent object or nullptr. 27 */ PatternPickerDialog(TilesetModel & tileset,QWidget * parent)28PatternPickerDialog::PatternPickerDialog( 29 TilesetModel& tileset, 30 QWidget* parent) : 31 QDialog(parent) { 32 33 ui.setupUi(this); 34 35 ui.tileset_view->set_model(&tileset); 36 ui.tileset_view->set_read_only(true); 37 ui.tileset_view->set_multi_selection_enabled(false); 38 } 39 40 /** 41 * @brief Returns the pattern picked by the user. 42 * @return The pattern id or an empty string. 43 */ get_pattern_id() const44QString PatternPickerDialog::get_pattern_id() const { 45 46 TilesetModel* tileset = ui.tileset_view->get_model(); 47 if (tileset == nullptr) { 48 return QString(); 49 } 50 int pattern_index = tileset->get_selected_index(); 51 52 return tileset->index_to_id(pattern_index); 53 } 54 55 /** 56 * @brief Closes the dialog. 57 * @param result Result code of the dialog. 58 */ done(int result)59void PatternPickerDialog::done(int result) { 60 61 QDialog::done(result); 62 } 63 64 } 65