当前位置: 首页>>代码示例>>C++>>正文


C++ ImageItem::mapToScene方法代码示例

本文整理汇总了C++中ImageItem::mapToScene方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageItem::mapToScene方法的具体用法?C++ ImageItem::mapToScene怎么用?C++ ImageItem::mapToScene使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageItem的用法示例。


在下文中一共展示了ImageItem::mapToScene方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: on_filesTable_currentCellChanged

void MainWindow::on_filesTable_currentCellChanged(int currentRow, int /*currentColumn*/, int /*previousRow*/, int /*previousColumn*/)
{
    ui->stackedWidget->setCurrentWidget(ui->emptyPage);

    QString resourceName = ui->filesTable->item(currentRow, 0)->text();
    QRectF boundingBox;
    m_scene.clear();

    if(resourceName.endsWith(".pcx")) {
        ImageItem *item = new ImageItem(readPCXimage(resourceName));
        m_scene.addItem(item);
        boundingBox = item->boundingRect();
        ui->stackedWidget->setCurrentWidget(ui->graphicsPage);
    }

    if(resourceName.endsWith(".gob")) {
        std::vector<GobImage> gobImages = m_resourceContainer.readGOB( resourceName.toStdString() );

        QPointF coordinates;
        for(const GobImage &gobImage : gobImages) {
            ImageItem *item = new ImageItem(readGobImage(gobImage));
            m_scene.addItem(item);
            item->setPos(coordinates);
            coordinates.rx() += gobImage.width() + 2;

            QRectF itemBB = item->mapToScene(item->boundingRect()).boundingRect();
            boundingBox.setRight( qMax( boundingBox.right(), itemBB.right() ) );
            boundingBox.setBottom( qMax( boundingBox.bottom(), item->boundingRect().bottom() ) );
            m_scene.addRect(itemBB, QPen(QColor(127, 127, 127, 200)));
        }
        ui->stackedWidget->setCurrentWidget(ui->graphicsPage);
    }

    if(resourceName == "levelmap.txt") {
        ImageItem *item = new ImageItem(readPCXimage("level.pcx"));
        m_scene.addItem(item);
        boundingBox = item->boundingRect();

        std::vector<char> entryData = m_resourceContainer.readLevel( resourceName.toStdString() );
        std::vector<char>::size_type index = 0;
        for(int row = 0; row < 16; row++) {
            for(int column = 0; column < 22; column++) {
                QColor blockColor;

                switch( entryData[index] ) {
                case '0':
                    blockColor.setRgb(0, 0, 0, 0);
                    break;

                case '1':
                    blockColor.setRgb(200, 100, 0, 200);
                    break;

                case '2':
                    blockColor.setRgb(0, 60, 85, 200);
                    break;

                case '3':
                    blockColor.setRgb(140, 220, 255, 200);
                    break;

                case '4':
                    blockColor.setRgb(200, 200, 0, 200);
                    break;

                default:
                    blockColor.setRgb(200, 0, 0, 200);
                }

                QPen pen;
                pen.setWidth(0);
                m_scene.addRect(QRect(column * 16, row * 16, 16, 16), QPen(pen), QBrush(blockColor));
                index++;
            }
            index += 2; // Skip "\r\n" at the end of line;
        }
        ui->stackedWidget->setCurrentWidget(ui->graphicsPage);
    }

    m_scene.setSceneRect(boundingBox);
    ui->graphicsView->setZoom(1.0);
    ui->graphicsView->centerOn(boundingBox.center());

    if(resourceName.endsWith(".smp")) {
        ui->stackedWidget->setCurrentWidget(ui->soundPage);
        ui->soundPage->setSoundData(readSMP(resourceName));
        ui->soundPage->setSoundDescription("Raw 8 bit signed 22050Hz");
    }

    if(resourceName.endsWith(".mod")) {
        ui->stackedWidget->setCurrentWidget(ui->musicPage);
        ui->musicPage->setMusicData(readMOD(resourceName));
    }
}
开发者ID:Telecrab,项目名称:jnb3d,代码行数:94,代码来源:mainwindow.cpp


注:本文中的ImageItem::mapToScene方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。