void PrinterWidget::discolor()
{
    if (ui->print_list->count() == 0)
    {
        return;
    }

    const QString& path = currentItem->data(3).toString();

    addToHistory(path, *work_pix);

    QImage img = work_pix->toImage();
    for( int w = 0; w < img.width(); ++w )
    {
        for( int h = 0; h < img.height(); ++h )
        {
            QColor col( img.pixel(w,h) );
            col.setHsv(col.hue(), 0, col.value(), col.alpha());
            img.setPixel(w,h,col.rgb());
        }
    }
    QPixmap* pix = new QPixmap( QPixmap::fromImage(img) );
    resetCurrentState(path,*pix);
    delete work_pix;
    work_pix = pix;
    if (cut_rect_show_pix != NULL)
    {
        delete cut_rect_show_pix;
    }
    cut_rect_show_pix = new QPixmap(*work_pix);
    setRedBox(cut_rect_show_pix, cut_rect_show_pix->rect());
    QLabel* l = dynamic_cast<QLabel*>(ui->monitor_area->widget());
    l->setPixmap(*cut_rect_show_pix);
    resetCutParameters(cut_rect_show_pix->width(), cut_rect_show_pix->height());
}
void PrinterWidget::scale()
{
    if (ui->print_list->count() == 0)
    {
        return;
    }

    double sx, sy;
    sx = (sender() == ui->scale_plus_button) ? sy = 1.1 : sy = 0.9;

    const QString& path = currentItem->data(3).toString();

    addToHistory(path, *work_pix);

    QSize size(sx*work_pix->width(),sy*work_pix->height());
    QPixmap* pix = new QPixmap( work_pix->scaled(size,Qt::KeepAspectRatio) );

    resetCurrentState(path,*pix);
    delete work_pix;
    work_pix = pix;
    if (cut_rect_show_pix != NULL)
    {
        delete cut_rect_show_pix;
    }
    cut_rect_show_pix = new QPixmap(*work_pix);
    setRedBox(cut_rect_show_pix, cut_rect_show_pix->rect());
    QLabel* l = dynamic_cast<QLabel*>(ui->monitor_area->widget());
    l->setPixmap(*cut_rect_show_pix);
    resetCutParameters(cut_rect_show_pix->width(), cut_rect_show_pix->height());
}
void PrinterWidget::rotateRight()
{
    if (ui->print_list->count() == 0)
    {
        return;
    }

    const QString& path = currentItem->data(3).toString();

    addToHistory(path, *work_pix);

    QPixmap* pix = new QPixmap(work_pix->height(), work_pix->width());
    QPainter p(pix);
    p.translate(work_pix->height(),0);
    p.rotate(90);
    p.drawPixmap(work_pix->rect(), *work_pix);

    resetCurrentState(path,*pix);
    delete work_pix;
    work_pix = pix;
    if (cut_rect_show_pix != NULL)
    {
        delete cut_rect_show_pix;
    }
    cut_rect_show_pix = new QPixmap(*work_pix);
    setRedBox(cut_rect_show_pix, cut_rect_show_pix->rect());
    QLabel* l = dynamic_cast<QLabel*>(ui->monitor_area->widget());
    l->setPixmap(*cut_rect_show_pix);
    resetCutParameters(cut_rect_show_pix->width(), cut_rect_show_pix->height());
}
void PrinterWidget::undo()
{
    if (ui->print_list->count() == 0 || edit_history == NULL)
    {
        return;
    }
    const QString& path = currentItem->data(3).toString();
    QMap<QString,QList<QPixmap*> >::iterator it = edit_history->find(path);
    if (it == edit_history->end())
    {
        return;
    }
    if (it->empty())
    {
        return;
    }

    QPixmap* pix = it->back();
    it->pop_back();

    resetCurrentState(path,*pix);
    delete work_pix;
    work_pix = pix;

    QLabel* l = dynamic_cast<QLabel*>(ui->monitor_area->widget());
    if (cut_rect_show_pix != NULL)
    {
        delete cut_rect_show_pix;
    }
    cut_rect_show_pix = new QPixmap(*work_pix);
    setRedBox(cut_rect_show_pix, QRect(0,0,cut_rect_show_pix->width()-1,cut_rect_show_pix->height()-1));
    l->setPixmap(*cut_rect_show_pix);

    resetCutParameters(work_pix->width(), work_pix->height());
}
void PrinterWidget::cut()
{
    if (ui->print_list->count() == 0)
    {
        return;
    }

    int x = ui->corner_coord_x->value();
    int y = ui->corner_coord_y->value();
    int w = ui->new_size_x->value();
    int h = ui->new_size_y->value();

    if (x == 0 && y == 0 && w == work_pix->width() && h == work_pix->height())
    {
        return;
    }

    const QString& path = currentItem->data(3).toString();
    QPixmap* p = new QPixmap(work_pix->copy(x,y,w,h));

    addToHistory(path, *work_pix);
    resetCurrentState(path, *p);
    delete work_pix;
    work_pix = p;
    if (cut_rect_show_pix != NULL)
    {
        delete cut_rect_show_pix;
    }
    cut_rect_show_pix = new QPixmap(*work_pix);
    setRedBox(cut_rect_show_pix, cut_rect_show_pix->rect());
    QLabel* l = dynamic_cast<QLabel*>(ui->monitor_area->widget());
    l->setPixmap(*cut_rect_show_pix);

    resetCutParameters(work_pix->width(), work_pix->height());
}
Beispiel #6
0
void initWithLifFile(board *gameBoard, char *fileName) {
    char name[8];
    char ver[8];
    int x, y, newX, newY;
    FILE *file = NULL;

    resetCurrentState(gameBoard);
    openLifFile(fileName, &file);

    if(fscanf(file, "%s %s", name, ver) != 2) {
        fprintf(stderr, "ERROR: not a Life 1.06 file\n");
        exit(EXIT_FAILURE);
    }

    while (fscanf(file, "%d %d", &x, &y) != EOF) {
        newX = wrapCoord(x, WIDTH);
        newY = wrapCoord(y, HEIGHT);
        gameBoard->currentState[newY * WIDTH + newX] = LIFE;
    }

    fclose(file);
}