/** * @brief This function is called when the user checks or unchecks a button of * the entity creation toolbar. * @param type Type of entity corresponding to the button. * @param checked Whether the button is checked or unchecked. */ void MapEditor::entity_creation_button_triggered(EntityType type, bool checked) { if (checked) { // Create a new entity of this type. EntityModels entities; entities.emplace_back(EntityModel::create(*map, type)); const bool guess_layer = true; ui.map_view->start_state_adding_entities(std::move(entities), guess_layer); // Unselect patterns in the tileset. TilesetModel* tileset = map->get_tileset_model(); if (tileset != nullptr) { // But don't react to this unselection, it does not come from the user. ignore_tileset_selection_changes = true; tileset->clear_selection(); ignore_tileset_selection_changes = false; } // Uncheck other entity creation buttons. for (QAction* action : entity_creation_toolbar->actions()) { bool ok = false; EntityType action_type = static_cast<EntityType>(action->data().toInt(&ok)); if (ok) { bool action_checked = (action_type == type); action->setChecked(action_checked); } } } else { // Stop adding entities. ui.map_view->start_state_doing_nothing(); uncheck_entity_creation_buttons(); } }
void TilesetEditor::updateTilesetView(Tileset *tileset) { if (!mCurrentTilesetDocument) return; if (mCurrentTilesetDocument->tileset().data() != tileset) return; TilesetModel *model = currentTilesetView()->tilesetModel(); model->tilesetChanged(); }
int TilesetView::sizeHintForRow(int row) const { Q_UNUSED(row) const TilesetModel *model = tilesetModel(); if (!model) return -1; const int tileHeight = model->tileset()->tileHeight(); return tileHeight * scale() + (mDrawGrid ? 1 : 0); }
int TilesetView::sizeHintForColumn(int column) const { Q_UNUSED(column) const TilesetModel *model = tilesetModel(); if (!model) return -1; const int tileWidth = model->tileset()->tileWidth(); return tileWidth * scale() + (mDrawGrid ? 1 : 0); }
int TilesetView::sizeHintForRow(int row) const { Q_UNUSED(row) const TilesetModel *model = tilesetModel(); if (!model) return -1; if (model->tileset()->isCollection()) return QTableView::sizeHintForRow(row); const int tileHeight = model->tileset()->tileHeight(); return qRound(tileHeight * scale()) + (mDrawGrid ? 1 : 0); }
int TilesetView::sizeHintForColumn(int column) const { Q_UNUSED(column) const TilesetModel *model = tilesetModel(); if (!model) return -1; if (model->tileset()->isCollection()) return QTableView::sizeHintForColumn(column); const int tileWidth = model->tileset()->tileWidth(); return qRound(tileWidth * scale()) + (mDrawGrid ? 1 : 0); }
int TilesetView::sizeHintForRow(int row) const { Q_UNUSED(row) const TilesetModel *model = tilesetModel(); if (!model) return -1; #if QT_VERSION >= 0x050200 if (model->tileset()->imageSource().isEmpty()) return QTableView::sizeHintForRow(row); #endif const int tileHeight = model->tileset()->tileHeight(); return qRound(tileHeight * scale()) + (mDrawGrid ? 1 : 0); }
int TilesetView::sizeHintForColumn(int column) const { Q_UNUSED(column) const TilesetModel *model = tilesetModel(); if (!model) return -1; #if QT_VERSION >= 0x050200 if (model->tileset()->imageSource().isEmpty()) return QTableView::sizeHintForColumn(column); #endif const int tileWidth = model->tileset()->tileWidth(); return qRound(tileWidth * scale()) + (mDrawGrid ? 1 : 0); }
/** * @brief Slot called when another tileset is set on the map. * @param tileset_id The new tileset id. */ void MapEditor::tileset_id_changed(const QString& tileset_id) { // Show the correct tileset in the combobox. update_tileset_field(); // Notify the tileset view. update_tileset_view(); // Watch the selection of the tileset to correctly add new tiles. TilesetModel* tileset = map->get_tileset_model(); if (tileset != nullptr) { connect(&tileset->get_selection_model(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(tileset_selection_changed())); } // Notify the map view. ui.map_view->tileset_id_changed(tileset_id); }