ImageWidget::ImageWidget(QWidget *parent) : QWidget(parent), m_stack(new QUndoStack(this)), m_filePath(QString()), m_imageLabel(new QLabel(this)), m_magnification(1.), m_flagAutoImageResize(true) { // m_stack->setUndoLimit(5); // 別に制限しなくていいんじゃね? connect(m_stack, SIGNAL(canUndoChanged(bool)), this, SIGNAL(canUndoChanged(bool))); connect(m_stack, SIGNAL(canRedoChanged(bool)), this, SIGNAL(canRedoChanged(bool))); connect(m_stack, SIGNAL(cleanChanged(bool)), this, SIGNAL(cleanChanged(bool))); connect(m_stack, SIGNAL(undoTextChanged(QString)), this, SIGNAL(undoTextChanged(QString))); connect(m_stack, SIGNAL(redoTextChanged(QString)), this, SIGNAL(redoTextChanged(QString))); m_imageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); QVBoxLayout *layout = new QVBoxLayout(this); layout->setMargin(0); QScrollArea *scrollArea = new QScrollArea(this); scrollArea->setWidgetResizable(true); scrollArea->setBackgroundRole(QPalette::Midlight); scrollArea->setWidget(m_imageLabel); layout->addWidget(scrollArea); setLayout(layout); }
UndoManager::UndoManager (QObject * parentManager) : QObject (parentManager), m_undoStack (new QUndoStack (this)), m_clipboardEmpty (true) { connect (m_undoStack, SIGNAL (canRedoChanged (bool)), this, SIGNAL (canRedoChanged ())); connect (m_undoStack, SIGNAL (canUndoChanged (bool)), this, SIGNAL (canUndoChanged ())); connect (m_undoStack, SIGNAL (redoTextChanged (QString)), this, SIGNAL (redoTextChanged ())); connect (m_undoStack, SIGNAL (undoTextChanged (QString)), this, SIGNAL (undoTextChanged ())); m_clipboard = QApplication::clipboard (); }
void WindowsManager::setActiveWindow(int index) { if (index < 0 || index >= m_tabBar->count()) { index = 0; } if (index != m_tabBar->currentIndex()) { m_tabBar->setCurrentIndex(index); return; } Window *window = m_mdi->getActiveWindow(); if (window) { if (window->getContentsWidget()->getUndoStack()) { disconnect(window->getContentsWidget()->getUndoStack(), SIGNAL(undoTextChanged(QString)), this, SIGNAL(actionsChanged())); disconnect(window->getContentsWidget()->getUndoStack(), SIGNAL(redoTextChanged(QString)), this, SIGNAL(actionsChanged())); disconnect(window->getContentsWidget()->getUndoStack(), SIGNAL(canUndoChanged(bool)), this, SIGNAL(actionsChanged())); disconnect(window->getContentsWidget()->getUndoStack(), SIGNAL(canRedoChanged(bool)), this, SIGNAL(actionsChanged())); } disconnect(window, SIGNAL(actionsChanged()), this, SIGNAL(actionsChanged())); disconnect(window, SIGNAL(statusMessageChanged(QString)), m_statusBar, SLOT(showMessage(QString))); disconnect(window, SIGNAL(zoomChanged(int)), m_statusBar, SLOT(setZoom(int))); disconnect(window, SIGNAL(canZoomChanged(bool)), m_statusBar, SLOT(setZoomEnabled(bool))); disconnect(m_statusBar, SIGNAL(requestedZoomChange(int)), window->getContentsWidget(), SLOT(setZoom(int))); }
void KUndo2QStack::setIndex(int idx, bool clean) { bool was_clean = m_index == m_clean_index; if (m_lastMergedIndex <= idx) { m_lastMergedSetCount = idx - m_lastMergedIndex; } else { m_lastMergedSetCount = 1; m_lastMergedIndex = idx-1; } if(idx == 0){ m_lastMergedSetCount = 0; m_lastMergedIndex = 0; } if (idx != m_index) { m_index = idx; emit indexChanged(m_index); emit canUndoChanged(canUndo()); emit undoTextChanged(undoText()); emit canRedoChanged(canRedo()); emit redoTextChanged(redoText()); } if (clean) m_clean_index = m_index; bool is_clean = m_index == m_clean_index; if (is_clean != was_clean) emit cleanChanged(is_clean); }
void QUndoStack::clear() { Q_D(QUndoStack); if (d->command_list.isEmpty()) return; bool was_clean = isClean(); d->macro_stack.clear(); qDeleteAll(d->command_list); d->command_list.clear(); d->index = 0; d->clean_index = 0; emit indexChanged(0); emit canUndoChanged(false); emit undoTextChanged(QString()); emit canRedoChanged(false); emit redoTextChanged(QString()); if (!was_clean) emit cleanChanged(true); }
void KUndo2Group::setActiveStack(KUndo2QStack *stack) { if (m_active == stack) return; if (m_active != 0) { disconnect(m_active, SIGNAL(canUndoChanged(bool)), this, SIGNAL(canUndoChanged(bool))); disconnect(m_active, SIGNAL(undoTextChanged(QString)), this, SIGNAL(undoTextChanged(QString))); disconnect(m_active, SIGNAL(canRedoChanged(bool)), this, SIGNAL(canRedoChanged(bool))); disconnect(m_active, SIGNAL(redoTextChanged(QString)), this, SIGNAL(redoTextChanged(QString))); disconnect(m_active, SIGNAL(indexChanged(int)), this, SIGNAL(indexChanged(int))); disconnect(m_active, SIGNAL(cleanChanged(bool)), this, SIGNAL(cleanChanged(bool))); }
void QUndoGroup::setActiveStack(QUndoStack *stack) { Q_D(QUndoGroup); if (d->active == stack) return; if (d->active != 0) { disconnect(d->active, SIGNAL(canUndoChanged(bool)), this, SIGNAL(canUndoChanged(bool))); disconnect(d->active, SIGNAL(undoTextChanged(QString)), this, SIGNAL(undoTextChanged(QString))); disconnect(d->active, SIGNAL(canRedoChanged(bool)), this, SIGNAL(canRedoChanged(bool))); disconnect(d->active, SIGNAL(redoTextChanged(QString)), this, SIGNAL(redoTextChanged(QString))); disconnect(d->active, SIGNAL(indexChanged(int)), this, SIGNAL(indexChanged(int))); disconnect(d->active, SIGNAL(cleanChanged(bool)), this, SIGNAL(cleanChanged(bool))); }
QAction *KUndo2QStack::createUndoAction(QObject *parent) const { KUndo2Action *result = new KUndo2Action(i18n("Undo %1"), i18nc("Default text for undo action", "Undo"), parent); result->setEnabled(canUndo()); result->setPrefixedText(undoText()); connect(this, SIGNAL(canUndoChanged(bool)), result, SLOT(setEnabled(bool))); connect(this, SIGNAL(undoTextChanged(QString)), result, SLOT(setPrefixedText(QString))); connect(result, SIGNAL(triggered()), this, SLOT(undo())); return result; }
void UndoStack::execCmd(UndoCommand* cmd, bool autoMerge) throw (Exception) { Q_CHECK_PTR(cmd); if (mCommandActive) { delete cmd; throw RuntimeError(__FILE__, __LINE__, QString(), tr("Another command is active " "at the moment. Please finish that command to continue.")); } if (mCleanIndex > mCurrentIndex) mCleanIndex = -1; // the clean state will no longer exist -> make the index invalid // first, delete all commands above the current index (make redo impossible) // --> in reverse order (from top to bottom)! while (mCurrentIndex < mCommands.count()) delete mCommands.takeLast(); Q_ASSERT(mCurrentIndex == mCommands.count()); try { cmd->redo(); // throws an exception on error } catch (Exception& e) { // delete the command because this UndoStack object will NOT take the ownership // over the failed command! and then rethrow the exception... delete cmd; throw; } // command successfully executed, try to merge it with the last executed command bool merged = false; if ((autoMerge) && (mCurrentIndex > 0)) merged = mCommands[mCurrentIndex-1]->mergeWith(cmd); // try merging the commands if (!merged) { // command was not merged --> add it to the command stack and emit signals mCommands.append(cmd); mCurrentIndex++; // emit signals emit undoTextChanged(QString(tr("Undo: %1")).arg(cmd->getText())); emit redoTextChanged(tr("Redo")); emit canUndoChanged(true); emit canRedoChanged(false); emit cleanChanged(false); } }
KoUndoStackAction::KoUndoStackAction(KUndo2Stack* stack, Type type) : QAction(stack) , m_type(type) { if (m_type == UNDO) { connect(this, SIGNAL(triggered()), stack, SLOT(undo())); connect(stack, SIGNAL(canUndoChanged(bool)), this, SLOT(setEnabled(bool))); connect(stack, SIGNAL(undoTextChanged(QString)), this, SLOT(slotUndoTextChanged(QString))); setIcon(koIcon("edit-undo")); setText(i18n("Undo")); setShortcuts(KStandardShortcut::undo()); setEnabled(stack->canUndo()); } else {
QAction *QUndoStack::createUndoAction(QObject *parent, const QString &prefix) const { QString pref = prefix.isEmpty() ? tr("Undo") : prefix; QUndoAction *result = new QUndoAction(pref, parent); result->setEnabled(canUndo()); result->setPrefixedText(undoText()); connect(this, SIGNAL(canUndoChanged(bool)), result, SLOT(setEnabled(bool))); connect(this, SIGNAL(undoTextChanged(QString)), result, SLOT(setPrefixedText(QString))); connect(result, SIGNAL(triggered()), this, SLOT(undo())); return result; }
QAction *QUndoStack::createUndoAction(QObject *parent, const QString &prefix) const { QUndoAction *result = new QUndoAction(prefix, parent); if (prefix.isEmpty()) result->setTextFormat(tr("Undo %1"), tr("Undo", "Default text for undo action")); result->setEnabled(canUndo()); result->setPrefixedText(undoText()); connect(this, SIGNAL(canUndoChanged(bool)), result, SLOT(setEnabled(bool))); connect(this, SIGNAL(undoTextChanged(QString)), result, SLOT(setPrefixedText(QString))); connect(result, SIGNAL(triggered()), this, SLOT(undo())); return result; }
void UndoStack::undo() throw (Exception) { if ((!canUndo()) || (mCommandActive)) // if a command is active, undo() is not allowed return; mCommands[mCurrentIndex-1]->undo(); // throws an exception on error mCurrentIndex--; // emit signals emit undoTextChanged(getUndoText()); emit redoTextChanged(getRedoText()); emit canUndoChanged(canUndo()); emit canRedoChanged(canRedo()); emit cleanChanged(isClean()); }
void UndoStack::redo() throw (Exception) { if (!canRedo()) return; mCommands[mCurrentIndex]->redo(); // throws an exception on error mCurrentIndex++; // emit signals emit undoTextChanged(getUndoText()); emit redoTextChanged(getRedoText()); emit canUndoChanged(canUndo()); emit canRedoChanged(canRedo()); emit cleanChanged(isClean()); }
void QUndoStack::push(QUndoCommand *cmd) { Q_D(QUndoStack); cmd->redo(); bool macro = !d->macro_stack.isEmpty(); QUndoCommand *cur = 0; if (macro) { QUndoCommand *macro_cmd = d->macro_stack.last(); if (!macro_cmd->d->child_list.isEmpty()) cur = macro_cmd->d->child_list.last(); } else { if (d->index > 0) cur = d->command_list.at(d->index - 1); while (d->index < d->command_list.size()) delete d->command_list.takeLast(); if (d->clean_index > d->index) d->clean_index = -1; // we've deleted the clean state } bool try_merge = cur != 0 && cur->id() != -1 && cur->id() == cmd->id() && (macro || d->index != d->clean_index); if (try_merge && cur->mergeWith(cmd)) { delete cmd; if (!macro) { emit indexChanged(d->index); emit canUndoChanged(canUndo()); emit undoTextChanged(undoText()); emit canRedoChanged(canRedo()); emit redoTextChanged(redoText()); } } else { if (macro) { d->macro_stack.last()->d->child_list.append(cmd); } else { d->command_list.append(cmd); d->checkUndoLimit(); d->setIndex(d->index + 1, false); } } }
void KUndo2QStack::push(KUndo2Command *cmd) { cmd->redo(); bool macro = !m_macro_stack.isEmpty(); KUndo2Command *cur = 0; if (macro) { KUndo2Command *macro_cmd = m_macro_stack.last(); if (!macro_cmd->d->child_list.isEmpty()) cur = macro_cmd->d->child_list.last(); } else { if (m_index > 0) cur = m_command_list.at(m_index - 1); while (m_index < m_command_list.size()) delete m_command_list.takeLast(); if (m_clean_index > m_index) m_clean_index = -1; // we've deleted the clean state } bool try_merge = cur != 0 && cur->id() != -1 && cur->id() == cmd->id() && (macro || m_index != m_clean_index); if (try_merge && cur->mergeWith(cmd)) { delete cmd; if (!macro) { emit indexChanged(m_index); emit canUndoChanged(canUndo()); emit undoTextChanged(undoText()); emit canRedoChanged(canRedo()); emit redoTextChanged(redoText()); } } else { if (macro) { m_macro_stack.last()->d->child_list.append(cmd); } else { m_command_list.append(cmd); checkUndoLimit(); setIndex(m_index + 1, false); } } }
KAction* Editor::createUndoAction(KActionCollection *actionCollection) { UndoAction *action = new UndoAction(i18n("Undo"), actionCollection); action->setEnabled(canUndo()); action->setPrefixedText(undoText()); connect(this, SIGNAL(canUndoChanged(bool)), action, SLOT(setEnabled(bool))); connect(this, SIGNAL(undoTextChanged(QString)), action, SLOT(setPrefixedText(QString))); connect(action, SIGNAL(triggered()), this, SLOT(undo())); action->setIcon(KIcon("edit-undo")); action->setIconText(i18n("Undo")); action->setShortcuts(KStandardShortcut::undo()); actionCollection->addAction(KStandardAction::name(KStandardAction::Undo), action); return action; }
void UndoStack::abortCommand() throw (Exception) { Q_ASSERT(mCurrentIndex == mCommands.count()); if (!mCommandActive) throw LogicError(__FILE__, __LINE__, QString(), tr("No command active!")); mCommands.last()->undo(); // throws an exception on error mCurrentIndex--; mCommandActive = false; delete mCommands.takeLast(); // delete and remove the aborted command from the stack // emit signals emit undoTextChanged(getUndoText()); emit redoTextChanged(tr("Redo")); emit canUndoChanged(canUndo()); emit canRedoChanged(false); emit cleanChanged(isClean()); emit commandAborted(); // this is important! }
void KUndo2QStack::setIndex(int idx, bool clean) { bool was_clean = m_index == m_clean_index; if (idx != m_index) { m_index = idx; emit indexChanged(m_index); emit canUndoChanged(canUndo()); emit undoTextChanged(undoText()); emit canRedoChanged(canRedo()); emit redoTextChanged(redoText()); } if (clean) m_clean_index = m_index; bool is_clean = m_index == m_clean_index; if (is_clean != was_clean) emit cleanChanged(is_clean); }
void KUndo2QStack::clear() { if (m_command_list.isEmpty()) return; bool was_clean = isClean(); m_macro_stack.clear(); qDeleteAll(m_command_list); m_command_list.clear(); m_index = 0; m_clean_index = 0; emit indexChanged(0); emit canUndoChanged(false); emit undoTextChanged(QString()); emit canRedoChanged(false); emit redoTextChanged(QString()); if (!was_clean) emit cleanChanged(true); }
void QtUndoStack::beginMacro(const QString &text) { QtUndoCommand *cmd = new QtUndoCommand(); cmd->setText(text); if (d_ptr->macro_stack.isEmpty()) { while (d_ptr->index < d_ptr->command_list.size()) delete d_ptr->command_list.takeLast(); if (d_ptr->clean_index > d_ptr->index) d_ptr->clean_index = -1; // we've deleted the clean state d_ptr->command_list.append(cmd); } else { d_ptr->macro_stack.last()->d_ptr->child_list.append(cmd); } d_ptr->macro_stack.append(cmd); if (d_ptr->macro_stack.count() == 1) { emit canUndoChanged(false); emit undoTextChanged(QString()); emit canRedoChanged(false); emit redoTextChanged(QString()); } }
void UndoStack::clear() noexcept { if (mCommands.isEmpty()) return; if (mCommandActive) try {abortCommand();} catch (...) {} // delete all commands in the stack from top to bottom (newest first, oldest last)! while (!mCommands.isEmpty()) delete mCommands.takeLast(); mCurrentIndex = 0; mCleanIndex = 0; mCommandActive = false; // emit signals emit undoTextChanged(tr("Undo")); emit redoTextChanged(tr("Redo")); emit canUndoChanged(false); emit canRedoChanged(false); emit cleanChanged(true); }
void KUndo2QStack::beginMacro(const KUndo2MagicString &text) { KUndo2Command *cmd = new KUndo2Command(); cmd->setText(text); if (m_macro_stack.isEmpty()) { while (m_index < m_command_list.size()) delete m_command_list.takeLast(); if (m_clean_index > m_index) m_clean_index = -1; // we've deleted the clean state m_command_list.append(cmd); } else { m_macro_stack.last()->d->child_list.append(cmd); } m_macro_stack.append(cmd); if (m_macro_stack.count() == 1) { emit canUndoChanged(false); emit undoTextChanged(QString()); emit canRedoChanged(false); emit redoTextChanged(QString()); } }
int QUndoGroup::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: activeStackChanged((*reinterpret_cast< QUndoStack*(*)>(_a[1]))); break; case 1: indexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 2: cleanChanged((*reinterpret_cast< bool(*)>(_a[1]))); break; case 3: canUndoChanged((*reinterpret_cast< bool(*)>(_a[1]))); break; case 4: canRedoChanged((*reinterpret_cast< bool(*)>(_a[1]))); break; case 5: undoTextChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 6: redoTextChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 7: undo(); break; case 8: redo(); break; case 9: setActiveStack((*reinterpret_cast< QUndoStack*(*)>(_a[1]))); break; default: ; } _id -= 10; } return _id; }
void tst_QUndoGroup::checkSignals() { QUndoGroup group; QAction *undo_action = group.createUndoAction(0, QString("foo")); QAction *redo_action = group.createRedoAction(0, QString("bar")); QSignalSpy indexChangedSpy(&group, SIGNAL(indexChanged(int))); QSignalSpy cleanChangedSpy(&group, SIGNAL(cleanChanged(bool))); QSignalSpy canUndoChangedSpy(&group, SIGNAL(canUndoChanged(bool))); QSignalSpy undoTextChangedSpy(&group, SIGNAL(undoTextChanged(QString))); QSignalSpy canRedoChangedSpy(&group, SIGNAL(canRedoChanged(bool))); QSignalSpy redoTextChangedSpy(&group, SIGNAL(redoTextChanged(QString))); QString str; CHECK_STATE(0, // activeStack true, // clean false, // canUndo "", // undoText false, // canRedo "", // redoText false, // cleanChanged false, // indexChanged false, // undoChanged false) // redoChanged group.undo(); CHECK_STATE(0, // activeStack true, // clean false, // canUndo "", // undoText false, // canRedo "", // redoText false, // cleanChanged false, // indexChanged false, // undoChanged false) // redoChanged group.redo(); CHECK_STATE(0, // activeStack true, // clean false, // canUndo "", // undoText false, // canRedo "", // redoText false, // cleanChanged false, // indexChanged false, // undoChanged false) // redoChanged QUndoStack *stack1 = new QUndoStack(&group); CHECK_STATE(0, // activeStack true, // clean false, // canUndo "", // undoText false, // canRedo "", // redoText false, // cleanChanged false, // indexChanged false, // undoChanged false) // redoChanged stack1->push(new AppendCommand(&str, "foo")); CHECK_STATE(0, // activeStack true, // clean false, // canUndo "", // undoText false, // canRedo "", // redoText false, // cleanChanged false, // indexChanged false, // undoChanged false) // redoChanged stack1->setActive(); CHECK_STATE(stack1, // activeStack false, // clean true, // canUndo "append", // undoText false, // canRedo "", // redoText true, // cleanChanged true, // indexChanged true, // undoChanged true) // redoChanged stack1->push(new InsertCommand(&str, 0, "bar")); CHECK_STATE(stack1, // activeStack false, // clean true, // canUndo "insert", // undoText false, // canRedo "", // redoText false, // cleanChanged true, // indexChanged true, // undoChanged true) // redoChanged stack1->undo(); CHECK_STATE(stack1, // activeStack false, // clean true, // canUndo "append", // undoText true, // canRedo "insert", // redoText false, // cleanChanged true, // indexChanged true, // undoChanged true) // redoChanged stack1->undo(); CHECK_STATE(stack1, // activeStack true, // clean false, // canUndo "", // undoText true, // canRedo "append", // redoText true, // cleanChanged true, // indexChanged true, // undoChanged true) // redoChanged stack1->undo(); CHECK_STATE(stack1, // activeStack true, // clean false, // canUndo "", // undoText true, // canRedo "append", // redoText false, // cleanChanged false, // indexChanged false, // undoChanged false) // redoChanged group.undo(); CHECK_STATE(stack1, // activeStack true, // clean false, // canUndo "", // undoText true, // canRedo "append", // redoText false, // cleanChanged false, // indexChanged false, // undoChanged false) // redoChanged group.redo(); CHECK_STATE(stack1, // activeStack false, // clean true, // canUndo "append", // undoText true, // canRedo "insert", // redoText true, // cleanChanged true, // indexChanged true, // undoChanged true) // redoChanged stack1->setActive(false); CHECK_STATE(0, // activeStack true, // clean false, // canUndo "", // undoText false, // canRedo "", // redoText true, // cleanChanged true, // indexChanged true, // undoChanged true) // redoChanged QUndoStack *stack2 = new QUndoStack(&group); CHECK_STATE(0, // activeStack true, // clean false, // canUndo "", // undoText false, // canRedo "", // redoText false, // cleanChanged false, // indexChanged false, // undoChanged false) // redoChanged stack2->setActive(); CHECK_STATE(stack2, // activeStack true, // clean false, // canUndo "", // undoText false, // canRedo "", // redoText true, // cleanChanged true, // indexChanged true, // undoChanged true) // redoChanged stack1->setActive(); CHECK_STATE(stack1, // activeStack false, // clean true, // canUndo "append", // undoText true, // canRedo "insert", // redoText true, // cleanChanged true, // indexChanged true, // undoChanged true) // redoChanged delete stack1; CHECK_STATE(0, // activeStack true, // clean false, // canUndo "", // undoText false, // canRedo "", // redoText true, // cleanChanged true, // indexChanged true, // undoChanged true) // redoChanged delete undo_action; delete redo_action; }
bool KUndo2QStack::push(KUndo2Command *cmd) { cmd->redoMergedCommands(); cmd->setEndTime(); bool macro = !m_macro_stack.isEmpty(); KUndo2Command *cur = 0; if (macro) { KUndo2Command *macro_cmd = m_macro_stack.last(); if (!macro_cmd->d->child_list.isEmpty()) cur = macro_cmd->d->child_list.last(); } else { if (m_index > 0) cur = m_command_list.at(m_index - 1); while (m_index < m_command_list.size()) delete m_command_list.takeLast(); if (m_clean_index > m_index) m_clean_index = -1; // we've deleted the clean state } bool try_merge = cur != 0 && cur->id() != -1 && cur->id() == cmd->id() && (macro || m_index != m_clean_index); /*! *Here we are going to try to merge several commands together using the QVector field in the commands using *3 parameters. N : Number of commands that should remain individual at the top of the stack. T1 : Time lapsed between current command and previously merged command -- signal to *merge throughout the stack. T2 : Time lapsed between two commands signalling both commands belong to the same set *Whenever a KUndo2Command is initialized -- it consists of a start-time and when it is pushed --an end time. *Every time a command is pushed -- it checks whether the command pushed was pushed after T1 seconds of the last merged command *Then the merging begins with each group depending on the time in between each command (T2). * *@TODO : Currently it is not able to merge two merged commands together. */ if (!macro && m_command_list.size() > 1 && cmd->timedId() != -1 && m_useCumulativeUndoRedo) { KUndo2Command* lastcmd = m_command_list.last(); if (qAbs(cmd->time().msecsTo(lastcmd->endTime())) < m_timeT2 * 1000) { m_lastMergedSetCount++; } else { m_lastMergedSetCount = 0; m_lastMergedIndex = m_index-1; } if (lastcmd->timedId() == -1){ m_lastMergedSetCount = 0; m_lastMergedIndex = m_index; } if (m_lastMergedSetCount > m_strokesN) { KUndo2Command* toMerge = m_command_list.at(m_lastMergedIndex); if (toMerge && m_command_list.size() >= m_lastMergedIndex + 1 && m_command_list.at(m_lastMergedIndex + 1)) { if(toMerge->timedMergeWith(m_command_list.at(m_lastMergedIndex + 1))){ m_command_list.removeAt(m_lastMergedIndex + 1); } m_lastMergedSetCount--; m_lastMergedIndex = m_command_list.indexOf(toMerge); } } m_index = m_command_list.size(); if(m_lastMergedIndex<m_index){ if (cmd->time().msecsTo(m_command_list.at(m_lastMergedIndex)->endTime()) < -m_timeT1 * 1000) { //T1 time elapsed QListIterator<KUndo2Command*> it(m_command_list); it.toBack(); m_lastMergedSetCount = 1; while (it.hasPrevious()) { KUndo2Command* curr = it.previous(); KUndo2Command* lastCmdInCurrent = curr; if (!lastcmd->mergeCommandsVector().isEmpty()) { if (qAbs(lastcmd->mergeCommandsVector().last()->time().msecsTo(lastCmdInCurrent->endTime())) < int(m_timeT2 * 1000) && lastcmd != lastCmdInCurrent && lastcmd != curr) { if(lastcmd->timedMergeWith(curr)){ if (m_command_list.contains(curr)) { m_command_list.removeOne(curr); } } } else { lastcmd = curr; //end of a merge set } } else { if (qAbs(lastcmd->time().msecsTo(lastCmdInCurrent->endTime())) < int(m_timeT2 * 1000) && lastcmd != lastCmdInCurrent &&lastcmd!=curr) { if(lastcmd->timedMergeWith(curr)){ if (m_command_list.contains(curr)){ m_command_list.removeOne(curr); } } } else { lastcmd = curr; //end of a merge set } } } m_lastMergedIndex = m_command_list.size()-1; } } m_index = m_command_list.size(); } if (try_merge && cur->mergeWith(cmd)) { delete cmd; cmd = 0; if (!macro) { emit indexChanged(m_index); emit canUndoChanged(canUndo()); emit undoTextChanged(undoText()); emit canRedoChanged(canRedo()); emit redoTextChanged(redoText()); } } else { if (macro) { m_macro_stack.last()->d->child_list.append(cmd); } else { m_command_list.append(cmd); if(checkUndoLimit()) { m_lastMergedIndex = m_index - m_strokesN; } setIndex(m_index + 1, false); } } return cmd; }
EventView::EventView( QToolBar* toolBar, QWidget* parent ) : QWidget( parent ) , m_model( 0 ) , m_actionUndo( this ) , m_actionRedo( this ) , m_actionNewEvent( this ) , m_actionEditEvent( this ) , m_actionDeleteEvent( this ) , m_actionCreateTimeSheet( this ) , m_comboBox( new QComboBox( this ) ) , m_labelTotal( new QLabel( this ) ) , m_listView( new QListView( this ) ) { QVBoxLayout* layout = new QVBoxLayout( this ); layout->setContentsMargins( 0, 0, 0, 0 ); layout->addWidget( m_listView ); m_listView->setAlternatingRowColors( true ); m_listView->setContextMenuPolicy( Qt::CustomContextMenu ); connect( m_listView, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( slotContextMenuRequested( const QPoint& ) ) ); connect( m_listView, SIGNAL( doubleClicked( const QModelIndex& ) ), SLOT( slotEventDoubleClicked( const QModelIndex& ) ) ); connect( &m_actionNewEvent, SIGNAL( triggered() ), SLOT( slotNewEvent() ) ); connect( &m_actionEditEvent, SIGNAL( triggered() ), SLOT( slotEditEvent() ) ); connect( &m_actionDeleteEvent, SIGNAL( triggered() ), SLOT( slotDeleteEvent() ) ); // connect( &m_commitTimer, SIGNAL( timeout() ), // SLOT( slotCommitTimeout() ) ); // m_commitTimer.setSingleShot( true ); m_actionUndo.setText(tr("Undo")); m_actionUndo.setToolTip(tr("Undo the latest change")); m_actionUndo.setShortcut(QKeySequence::Undo); m_actionUndo.setEnabled(false); m_actionRedo.setText(tr("Redo")); m_actionRedo.setToolTip(tr("Redo the last undone change.")); m_actionRedo.setShortcut(QKeySequence::Redo); m_actionRedo.setEnabled(false); m_undoStack = new QUndoStack(this); connect(m_undoStack, SIGNAL(canUndoChanged(bool)), &m_actionUndo, SLOT(setEnabled(bool))); connect(m_undoStack, SIGNAL(undoTextChanged(QString)), this, SLOT(slotUndoTextChanged(QString))); connect(&m_actionUndo, SIGNAL(triggered()), m_undoStack, SLOT(undo())); connect(m_undoStack, SIGNAL(canRedoChanged(bool)), &m_actionRedo, SLOT(setEnabled(bool))); connect(m_undoStack, SIGNAL(redoTextChanged(QString)), this, SLOT(slotRedoTextChanged(QString))); connect(&m_actionRedo, SIGNAL(triggered()), m_undoStack, SLOT(redo())); m_actionNewEvent.setText( tr( "New Event..." ) ); m_actionNewEvent.setToolTip( tr( "Create a new Event" ) ); m_actionNewEvent.setIcon( Data::newTaskIcon() ); m_actionNewEvent.setShortcut( QKeySequence::New ); toolBar->addAction( &m_actionNewEvent ); m_actionEditEvent.setText( tr( "Edit Event...") ); m_actionEditEvent.setShortcut( Qt::CTRL + Qt::Key_E ); m_actionEditEvent.setIcon( Data::editEventIcon() ); toolBar->addAction( &m_actionEditEvent ); m_actionDeleteEvent.setText( tr( "Delete Event..." ) ); QList<QKeySequence> deleteShortcuts; deleteShortcuts << QKeySequence::Delete; #ifdef Q_WS_MAC deleteShortcuts << Qt::Key_Backspace; #endif m_actionDeleteEvent.setShortcuts(deleteShortcuts); m_actionDeleteEvent.setIcon( Data::deleteTaskIcon() ); toolBar->addAction( &m_actionDeleteEvent ); // disable all actions, action state will be set when the current // item changes: m_actionNewEvent.setEnabled( true ); // always on m_actionEditEvent.setEnabled( false ); m_actionDeleteEvent.setEnabled( false ); toolBar->addWidget( m_comboBox ); connect( m_comboBox, SIGNAL( currentIndexChanged( int ) ), SLOT( timeFrameChanged( int ) ) ); QWidget *spacer = new QWidget( this ); QSizePolicy spacerSizePolicy = spacer->sizePolicy(); spacerSizePolicy.setHorizontalPolicy( QSizePolicy::Expanding ); spacer->setSizePolicy( spacerSizePolicy ); toolBar->addWidget( spacer ); toolBar->addWidget( m_labelTotal ); QTimer::singleShot( 0, this, SLOT( delayedInitialization() ) ); // I hate doing this but the stupid default view sizeHints suck badly. setMinimumHeight( 200 ); }
void PopupView::createActions() { // Remove the Shift+Delete shortcut from the cut action, since it's used for deleting files KAction *cut = KStandardAction::cut(this, SLOT(cut()), this); KShortcut cutShortCut = cut->shortcut(); cutShortCut.remove(Qt::SHIFT + Qt::Key_Delete); cut->setShortcut(cutShortCut); KAction *copy = KStandardAction::copy(this, SLOT(copy()), this); KIO::FileUndoManager *manager = KIO::FileUndoManager::self(); KAction *undo = KStandardAction::undo(manager, SLOT(undo()), this); connect(manager, SIGNAL(undoAvailable(bool)), undo, SLOT(setEnabled(bool))); connect(manager, SIGNAL(undoTextChanged(QString)), SLOT(undoTextChanged(QString))); undo->setEnabled(manager->undoAvailable()); KAction *paste = KStandardAction::paste(this, SLOT(paste()), this); KAction *pasteTo = KStandardAction::paste(this, SLOT(pasteTo()), this); pasteTo->setEnabled(false); // Only enabled during popupMenu() QString actionText = KIO::pasteActionText(); if (!actionText.isEmpty()) { paste->setText(actionText); } else { paste->setEnabled(false); } KAction *rename = new KAction(KIcon("edit-rename"), i18n("&Rename"), this); rename->setShortcut(Qt::Key_F2); connect(rename, SIGNAL(triggered()), SLOT(renameSelectedIcon())); KAction *trash = new KAction(KIcon("user-trash"), i18n("&Move to Trash"), this); trash->setShortcut(Qt::Key_Delete); connect(trash, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), SLOT(moveToTrash(Qt::MouseButtons,Qt::KeyboardModifiers))); KAction *emptyTrash = new KAction(KIcon("trash-empty"), i18n("&Empty Trash Bin"), this); KConfig trashConfig("trashrc", KConfig::SimpleConfig); emptyTrash->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); connect(emptyTrash, SIGNAL(triggered()), SLOT(emptyTrashBin())); KAction *del = new KAction(i18n("&Delete"), this); del->setIcon(KIcon("edit-delete")); del->setShortcut(Qt::SHIFT + Qt::Key_Delete); connect(del, SIGNAL(triggered()), SLOT(deleteSelectedIcons())); // Create the new menu m_newMenu = new KNewFileMenu(&m_actionCollection, "new_menu", this); connect(m_newMenu->menu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowCreateNew())); m_actionCollection.addAction("undo", undo); m_actionCollection.addAction("cut", cut); m_actionCollection.addAction("copy", copy); m_actionCollection.addAction("paste", paste); m_actionCollection.addAction("pasteto", pasteTo); m_actionCollection.addAction("rename", rename); m_actionCollection.addAction("trash", trash); m_actionCollection.addAction("del", del); m_actionCollection.addAction("empty_trash", emptyTrash); }