void PaintArea::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::RightButton) _right = true; else _right = false; if (_tool != 0) { _redo.clear(); emit noRedo(); } if (_isselect) { Undo(); _isselect = false; emit noCopy(); } lastPoint = event->pos(); if (_tool == 7) { _history.push_back(image); emit enableUndo(); drawWord(lastPoint); } else if (_tool == 6) { _history.push_back(image); emit enableUndo(); drawBucket(event->pos()); } else if (_tool == 10) { _history.push_back(image); emit enableUndo(); Paste(event->pos()); } else if (_tool == 12) { if (event->button() == Qt::LeftButton) zoomIn(); else zoomOut(); } else { _history.push_back(image); emit enableUndo(); _scroll = image; scribbling = true; if (_tool == 1) drawLineTo(event->pos()); else if (_tool == 2) drawEraser(event->pos()); else if (_tool == 11) drawSpray(event->pos()); } }
void GameWidget::mouseReleaseEvent(QMouseEvent *event) { if(selection.size() < 2 or !selection.contains(getGridPos(event->x(), event->y()))) return; //nothing selected or mouse pointer not in selection //backup oldscore = score; for(int x = 0; x < grid_size; x++) for(int y = 0; y < grid_size; y++) old_grid[x][y] = grid[x][y]; foreach(Box pos, selection) { if(use_animations) old_grid[pos.x][pos.y].scale_step = num_scale_steps-1; grid[pos.x][pos.y] = Bubble(); //remove bubbles } score += selection.size()*selection.size(); selection.clear(); emit enableUndo(true); emit activity(); compressBubbles(); #ifndef Q_WS_MAEMO_5 mouseMoveEvent(event); //draw selection if there's a new set of connected bubbles #endif }
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); }
//undo the last move void GameWidget::undo() { emit enableUndo(false); score = oldscore; selection.clear(); if(use_animations) { int shift = 0; //number of new collums in the action we want to undo for(int x = grid_size-1; x >= shift; x--) { bool not_found = false; for(int y = 1; y < grid_size; y++) { if(grid[x][y].id == old_grid[x-shift][y].id) break; //nothing changed not_found = true; for(int y_old = y-1; y_old >= 0; y_old--) { //search upward if(grid[x][y].id == old_grid[x-shift][y_old].id) { old_grid[x-shift][y_old].yoffset = y_old - y; old_grid[x-shift][y_old].yspeed = -initial_speed; not_found = false; break; //ids are unique } } } if(not_found) {//we couldn't find any bubbles in their old collumn shift++; //so it must have been the whole collumn that moved } if(shift > 0) { for(int y = 0; y < grid_size; y++) { old_grid[x-shift][y].xoffset = -shift; old_grid[x-shift][y].xspeed = -initial_speed; } } //don't skip collumns //TODO: only fixes special case shift=2 if(not_found and shift > 1) { for(int y = 0; y < grid_size; y++) { old_grid[x-shift+1][y].xoffset = -shift; old_grid[x-shift+1][y].xspeed = -initial_speed; } } } timer->start(); } for(int x = 0; x < grid_size; x++) for(int y = 0; y < grid_size; y++) grid[x][y] = old_grid[x][y]; update(); }
void PaintArea::Copy() { QRect select(_select.x() + 1, _select.y() + 1, _select.width() - 1, _select.height() - 1); _copy = image.copy(select); Undo(); _history.push_back(image); emit enableUndo(); emit canPaste(); emit noCopy(); }
void PaintArea::Cut() { Copy(); QPainter painter(&image); painter.setBrush(Qt::white); painter.setPen(QPen(Qt::white, 1, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin)); painter.drawRect(_select); update(); _history.push_back(image); emit enableUndo(); emit canPaste(); emit noCopy(); }
void PaintArea::Redo() { if (_redo.size() != 0) { _history.push_back(image); emit enableUndo(); image = _redo.back(); _redo.pop_back(); update(); } if (_redo.size() == 0) emit noRedo(); }
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 kMancalaMain::loadGame(QList<kMancalaHistoryItem*> history) { _historyListWidget->init(history); kMancalaHistoryItem *last = history.last(); qDebug("loading game ... "); if ( last ) { _init(last->getPlayers()); _startGame(last->getBoard(), last->getPlayerOnTurn()); if ( !_controller->gameOn(_board) ) _historyListWidget->setCurrentRow(_historyListWidget->count()-1); emit disableRedo(); if ( _historyListWidget->count() > 1 ) emit enableUndo(); qDebug("Game loaded"); } else { qDebug("Cannot load game, history missing"); } }
//start new game, fill grid with bubbles void GameWidget::restart() { emit enableUndo(false); score = 0; selection.clear(); //seed field with random non-empty bubbles (values 1..num_colors) for(int x = 0; x < grid_size; x++) { for(int y = 0; y < grid_size; y++) { grid[x][y] = Bubble(double(rand())/(RAND_MAX+1.0)*num_colors+1); if(use_animations) { grid[x][y].xoffset = grid_size + (width() - grid_size*(bubblesize+margin))/bubblesize/2; grid[x][y].xspeed = initial_speed; } } } if(use_animations) timer->start(); update(); }
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); } }