void Feld::load (const KSimpleConfig& config) { if(moving) killTimers(); mol->load(config); QString key; for (int j = 0; j < FIELD_SIZE; j++) { key.sprintf("feld_%02d", j); QString line = config.readEntry(key); for (int i = 0; i < FIELD_SIZE; i++) feld[i][j] = atom2int(line[i].latin1()); } moves = 0; chosen = false; moving = false; undoSize = redoSize = undoBegin = 0; emit enableUndo(false); emit enableRedo(false); xpos = ypos = 0; nextAtom(); }
void Feld::doRedo () { if (moving || !chosen || undoSize == redoSize) return; UndoInfo &undo_info = undo[(undoBegin + undoSize++) % MAX_UNDO]; emit enableUndo(true); emit enableRedo(undoSize != redoSize); ++moves; emit sendMoves(moves); moving = true; resetValidDirs (); cx = undo_info.oldxpos; cy = undo_info.oldypos; xpos = undo_info.xpos; ypos = undo_info.ypos; feld[cx][cy] = 0; feld[xpos][ypos] = undo_info.atom; cx *= 30; cy *= 30; framesbak = frames = 30 * (abs (undo_info.xpos - undo_info.oldxpos) + abs (undo_info.ypos - undo_info.oldypos) ); startTimer (10); dir = undo_info.dir; bitBlt (&sprite, 0, 0, this, cx, cy, 30, 30, CopyROP); }
void PaintArea::Undo() { if (_history.size() != 0) { _redo.push_back(image); emit enableRedo(); image = _history.back(); _history.pop_back(); update(); } if (_history.size() == 0) emit noUndo(); }
void kMancalaMain::_manageToolbarItems() { if ( _historyListWidget->currentRow() > 0 || _historyListWidget->count() > 0 ) { emit enableUndo(); } if ( _historyListWidget->currentRow() == 0 ) { emit disableUndo(); } if ( _historyListWidget->currentRow() >= 0 && (_historyListWidget->currentRow() < _historyListWidget->count()-1 )) { emit enableRedo(); } else { emit disableRedo(); } }
void Feld::startAnimation (Direction d) { // if animation is already started, return if (moving || !chosen) return; switch (d) { case MoveUp: if (ypos == 0 || feld [xpos] [ypos-1] != 150) return; break; case MoveDown: if (ypos == FIELD_SIZE-1 || feld [xpos] [ypos+1] != 152) return; break; case MoveLeft: if (xpos == 0 || feld [xpos-1] [ypos] != 151) return; break; case MoveRight: if (xpos == FIELD_SIZE-1 || feld [xpos+1] [ypos] != 153) return; break; default: break; } // reset validDirs now so that arrows don't get drawn resetValidDirs(); int x = 0, y = 0; moves++; emit sendMoves(moves); dir = d; switch (dir) { case MoveUp : for (x = xpos, y = ypos-1, anz = 0; y >= 0 && feld [x] [y] == 0; anz++, y--); if (anz != 0) { feld [x] [++y] = feld [xpos] [ypos]; } break; case MoveDown : for (x = xpos, y = ypos+1, anz = 0; y <= FIELD_SIZE-1 && feld [x] [y] == 0; anz++, y++); if (anz != 0) { feld [x] [--y] = feld [xpos] [ypos]; } break; case MoveRight : for (x = xpos+1, y = ypos, anz = 0; x <= FIELD_SIZE-1 && feld [x] [y] == 0; anz++, x++); if (anz != 0) { feld [--x] [y] = feld [xpos] [ypos]; } break; case MoveLeft : for (x = xpos-1, y = ypos, anz = 0; x >= 0 && feld [x] [y] == 0; anz++, x--); if (anz != 0) { feld [++x] [y] = feld [xpos] [ypos]; } break; default: return; } if (anz != 0) { moving = true; // BEGIN: Insert undo informations uint undoChunk = (undoBegin + undoSize) % MAX_UNDO; undo[undoChunk].atom = feld[xpos][ypos]; undo[undoChunk].oldxpos = xpos; undo[undoChunk].oldypos = ypos; undo[undoChunk].xpos = x; undo[undoChunk].ypos = y; undo[undoChunk].dir = dir; if (undoSize == MAX_UNDO) undoBegin = (undoBegin + 1) % MAX_UNDO; else ++undoSize; redoSize = undoSize; emit enableUndo(true); emit enableRedo(false); // END: Insert undo informations feld [xpos] [ypos] = 0; // absolutkoordinaten des zu verschiebenden bildes cx = xpos * 30; cy = ypos * 30; xpos = x; ypos = y; // 30 animationsstufen framesbak = frames = anz * 30; // 10 mal pro sek startTimer (10); bitBlt (&sprite, 0, 0, this, cx, cy, 30, 30, CopyROP); } }