コード例 #1
0
/** Intializes the PartResizerWidget
	@param d the Device the Partition is on
	@param p the Partition to show and/or resize
	@param minFirst the minimum value for the first sector
	@param maxLast the maximum value for the last sector
*/
void PartResizerWidget::init(Device& d, Partition& p, qint64 minFirst, qint64 maxLast, bool read_only, bool move_allowed)
{
    setDevice(d);
    setPartition(p);

    setMinimumFirstSector(minFirst);
    setMaximumLastSector(maxLast);

    setReadOnly(read_only);
    setMoveAllowed(move_allowed);

    setMinimumLength(qMax(partition().sectorsUsed(), partition().minimumSectors()));
    setMaximumLength(qMin(totalSectors(), partition().maximumSectors()));

    // set margins to accommodate to top/bottom button asymmetric layouts
    QStyleOptionButton bOpt;
    bOpt.initFrom(this);

    QRect buttonRect(style()->subElementRect(QStyle::SE_PushButtonContents, &bOpt));

    int asym = (rect().bottom() - buttonRect.bottom()) - (buttonRect.top() - rect().top());
    if (asym > 0)
        setContentsMargins(0, asym, 0, 0);
    else
        setContentsMargins(0, 0, 0, asym);

    if (!readOnly())
    {
        QPixmap pixmap(handleWidth(), handleHeight());
        pixmap.fill(Qt::transparent);
        QPainter p(&pixmap);
        QStyleOption opt;
        opt.state |= QStyle::State_Horizontal;
        opt.rect = pixmap.rect().adjusted(0, 2, 0, -2);
        style()->drawControl(QStyle::CE_Splitter, &opt, &p, this);

        leftHandle().setPixmap(pixmap);
        rightHandle().setPixmap(pixmap);

        leftHandle().setFixedSize(handleWidth(), handleHeight());
        rightHandle().setFixedSize(handleWidth(), handleHeight());
    }

    delete m_PartWidget;
    m_PartWidget = new PartWidget(this, &partition());

    if (!readOnly())
    {
        leftHandle().setCursor(Qt::SizeHorCursor);
        rightHandle().setCursor(Qt::SizeHorCursor);
    }

    if (moveAllowed())
        partWidget().setCursor(Qt::SizeAllCursor);

    partWidget().setToolTip(QString());

    updatePositions();
}
コード例 #2
0
void PartResizerWidget::mouseMoveEvent(QMouseEvent* event)
{
    int x = event->pos().x() - m_Hotspot;

    if (draggedWidget() == &leftHandle())
    {
        const qint64 newFirstSector = qMax(minimumFirstSector() + x * sectorsPerPixel(), 0LL);
        updateFirstSector(newFirstSector);
    }
    else if (draggedWidget() == &rightHandle())
    {
        const qint64 newLastSector = qMin(minimumFirstSector() + (x - rightHandle().width()) * sectorsPerPixel(), maximumLastSector());
        updateLastSector(newLastSector);
    }
    else if (draggedWidget() == &partWidget() && moveAllowed())
    {
        const qint64 newFirstSector = qMax(minimumFirstSector() + (x - handleWidth()) * sectorsPerPixel(), 0LL);
        movePartition(newFirstSector);
    }
}
コード例 #3
0
ファイル: main.c プロジェクト: Torrib/TDT4258
int main(int argc, const char * argv[])
{
    //Interaction with the user (From the driver) Use the FILE pointer?

    //hasTurn is 1 when it is player 1, and 2 when it is player two
    int hasTurn = 1;
    int play = 1;
    int column, row;
    char board[3][3];

    initializeBoard(board);
    while (play == 1) {
        while (hasTurn == 1) {
            printBoard(board);
            printf("Player 1 - Choose column 0 - 2 :\n");
            scanf("%d", &column);
            printf("Player 1 - Choose row 0 - 2 :\n");
            scanf("%d", &row);

            //Check if the column and row is allowed
            //Should be in a method

            if(moveAllowed(board, &column, &row) == 1)
                board[column][row] = 'X';
            else
                printf("Column or row not valid - try again.\n");

            //Check if player 1 won
            if (hasWon(board,hasTurn) == 1){
                printf("%s", "Player 1 won!");
                play = 0;
            }
            else
                hasTurn = 2;
        }

        //Do the same for player two - is there a way to do this without the loops?

        while (hasTurn == 2) {
            printBoard(board);
            printf("Player 2 - Choose column 0 - 2 :\n");
            scanf("%d", &column);
            printf("Player 2 - Choose row 0 - 2 :\n");
            scanf("%d", &row);

            //Check if the column and row is allowed
            if(moveAllowed(board, &column, &row) == 1)
                board[column][row] = '0';
            else
                printf("Column or row not valid - try again.\n");

            //Check if player 2 has won
            if (hasWon(board,hasTurn) == 1){
                printf("%s", "Player 1 won!");
                play = 0;
            }
            else
                hasTurn = 1;

        }
    }

     return 0;
}