// after changes are made void Editor::indexChanged(int index) { if (activeStack_ != activeStack() || index > activeStack()->count()) { return; } int s, e; bool redo; if (lastIndex_ < index) { // Redo redo = true; s = lastIndex_ + 1; e = index; } else if (lastIndex_ > index) { // Undo redo = false; s = index + 1; e = lastIndex_; } else { // Merge redo = true; s = index; e = index; } for (int i = s; i <= e; ++i) { const CommandBase *cmd = dynamic_cast<const CommandBase *>(activeStack_->command(i - 1)); if (cmd->needRepaint()) { emit needRepaint(); break; } } for (int i = s; i <= e; ++i) { const CommandBase *cmd = dynamic_cast<const CommandBase *>(activeStack_->command(i - 1)); if (cmd->needUpdateDimension()) { const_cast<CommandBase *>(cmd)->model()->update_custom_data<ldraw::metrics>(); break; } } for (int i = s; i <= e; ++i) { const CommandBase *cmd = dynamic_cast<const CommandBase *>(activeStack_->command(i - 1)); QPair<CommandBase::AffectedRow, QSet<int> > affected = cmd->affectedRows(); if (affected.second.size()) { if (!redo) { // flip if (affected.first == CommandBase::Inserted) affected.first = CommandBase::Removed; else affected.first = CommandBase::Inserted; } emit rowsChanged(affected); } } lastIndex_ = index; }
void Editor::rotateByZCounterClockwise() { if (!activeStack() || selection_->empty()) return; activeStack()->push(new CommandTransformLinear(CommandTransformLinear::Rotation, AxisZ, pivot_, -gridDensityAngle(), *selection_, model_)); emit modified(); }
void Editor::insert(const QString &filename, const ldraw::matrix &matrix, const ldraw::color &color) { if (selection_) activeStack()->push(new CommandInsert(filename, matrix, color, *selection_, model_)); else activeStack()->push(new CommandInsert(filename, matrix, color, QSet<int>(), model_)); emit modified(); }
void Editor::deleteSelected() { if (!activeStack() || selection_->empty()) return; activeStack()->push(new CommandRemove(*selection_, model_)); emit modified(); }
void Editor::moveByZNegative() { if (!activeStack() || selection_->empty()) return; activeStack()->push(new CommandTransformLinear(CommandTransformLinear::Position, AxisZ, pivot_, -gridDensity(), *selection_, model_)); emit modified(); }
void Editor::move(const ldraw::vector &vector) { if (!activeStack() || selection_->empty()) return; ldraw::matrix m; m.set_translation_vector(vector); activeStack()->push(new CommandTransform(m, ldraw::matrix(), *selection_, model_)); emit modified(); }
void Editor::editColor() { if (!activeStack() || selection_->empty()) return; KMenu menu(i18n("Select Color")); menu.addTitle(i18n("Shortcuts")); ColorManager *cm = Application::self()->colorManager(); foreach (const ldraw::color &it, cm->colorList()) { QAction *action = menu.addAction(QIcon(ColorManager::colorPixmap(it)), it.get_entity()->name.c_str()); action->setData(it.get_id()); } menu.addTitle(i18n("Recently Used")); foreach (const ColorManager::RecentColorPair &it, cm->recentlyUsed()) { QAction *action = menu.addAction(QIcon(ColorManager::colorPixmap(it.first)), it.first.get_entity()->name.c_str()); action->setData(it.first.get_id()); } menu.addSeparator(); QAction *customize = menu.addAction(i18n("&More...")); QAction *result = menu.exec(QCursor::pos()); if (result) { if (result == customize) { ColorDialog *colordialog = new ColorDialog(Application::self()->rootWindow()); if (colordialog->exec() == QDialog::Accepted) { activeStack()->push(new CommandColor(colordialog->getSelected(), *selection_, model_)); cm->hit(colordialog->getSelected()); emit modified(); } delete colordialog; } else { ldraw::color selected(result->data().toInt()); activeStack()->push(new CommandColor(selected, *selection_, model_)); cm->hit(selected); emit modified(); } } }
void Editor::cut() { if (!activeStack() || selection_->empty()) return; copy(); deleteSelected(); }
void Editor::paste() { if (!activeStack()) return; QClipboard *clipboard = kapp->clipboard(); const QMimeData *mimeData = clipboard->mimeData(QClipboard::Clipboard); if (!mimeData) return; else if (!mimeData->hasFormat(ObjectList::mimeType)) return; ObjectList list = ObjectList::deserialize(mimeData->data(ObjectList::mimeType)); activeStack()->push(new CommandPaste(list, *selection_, model_)); emit modified(); }
void Editor::copy() { if (!activeStack() || selection_->empty()) return; ObjectList ol(*selection_, model_); QClipboard *clipboard = kapp->clipboard(); clipboard->setMimeData(ol.mimeData(), QClipboard::Clipboard); }
void UndoManager::beginMacro(const QString &text) { activeStack()->beginMacro(text); }
void UndoManager::setClean() { activeStack()->setClean(); }
void UndoManager::push(QUndoCommand *cmd) { activeStack()->push(cmd); }
void UndoManager::endMacro() { activeStack()->endMacro(); }