void KPrMatrixWipeStrategy::paintStep( QPainter &p, int currPos, const KPrPageEffect::Data &data ) { int width = data.m_widget->width(); int height = data.m_widget->height(); int curSquare = currPos / (m_smooth ? framesPerSquare : 1); for (int i = 0; i < m_squaresPerRow; ++i) { for (int j = 0; j < m_squaresPerCol; ++j) { QRect rect(floor(qreal(width) / m_squaresPerRow * i), floor(qreal(height) / m_squaresPerCol * j), ceil(qreal(width) / m_squaresPerRow), ceil(qreal(height) / m_squaresPerCol)); int square = squareIndex(i, j, m_squaresPerRow, m_squaresPerCol); if (square <= curSquare) { if (square == curSquare && m_smooth) { int squarePos = currPos % framesPerSquare; p.drawPixmap( rect.topLeft(), data.m_oldPage, rect ); rect = tileRect(squareDirection(i, j, m_squaresPerRow, m_squaresPerCol), squarePos, rect); if (rect.width() > 0 && rect.height() > 0) { p.drawPixmap( rect.topLeft(), data.m_newPage, rect ); } } else { p.drawPixmap( rect.topLeft(), data.m_newPage, rect ); } } else { p.drawPixmap( rect.topLeft(), data.m_oldPage, rect ); } } } }
void GraphicsBoard::movePiece(const Chess::Square& source, const Chess::Square& target) { GraphicsPiece* piece = pieceAt(source); Q_ASSERT(piece != nullptr); m_squares[squareIndex(source)] = nullptr; setSquare(target, piece); }
GraphicsPiece* GraphicsBoard::pieceAt(const Chess::Square& square) const { if (!square.isValid()) return nullptr; GraphicsPiece* piece = m_squares.at(squareIndex(square)); Q_ASSERT(piece == nullptr || piece->container() == this); return piece; }
GraphicsPiece* GraphicsBoard::takePieceAt(const Chess::Square& square) { int index = squareIndex(square); if (index == -1) return nullptr; GraphicsPiece* piece = m_squares.at(index); if (piece == nullptr) return nullptr; m_squares[index] = nullptr; piece->setParentItem(nullptr); piece->setContainer(nullptr); return piece; }
void GraphicsBoard::setSquare(const Chess::Square& square, GraphicsPiece* piece) { Q_ASSERT(square.isValid()); int index = squareIndex(square); delete m_squares[index]; if (piece == nullptr) m_squares[index] = nullptr; else { m_squares[index] = piece; piece->setContainer(this); piece->setParentItem(this); piece->setPos(squarePos(square)); } }
void KPrMatrixWipeStrategy::next( const KPrPageEffect::Data &data ) { int lastPos = data.m_timeLine.frameForTime( data.m_lastTime ); int currPos = data.m_timeLine.frameForTime( data.m_currentTime ); int width = data.m_widget->width(); int height = data.m_widget->height(); int curSquare = currPos / (m_smooth ? framesPerSquare : 1); int lastSquare = lastPos / (m_smooth ? framesPerSquare : 1); for (int i = 0; i < m_squaresPerRow; ++i) { for (int j = 0; j < m_squaresPerCol; ++j) { QRect rect(floor(qreal(width) / m_squaresPerRow * i), floor(qreal(height) / m_squaresPerCol * j), ceil(qreal(width) / m_squaresPerRow), ceil(qreal(height) / m_squaresPerCol)); int square = squareIndex(i, j, m_squaresPerRow, m_squaresPerCol); if (square <= curSquare && square >= lastSquare) { data.m_widget->update(rect); } } } }