mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2024-11-27 14:38:28 +08:00
50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
// Copyright (C) 2016 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
#include "mainwindow.h"
|
|
#include "view.h"
|
|
#include "chip.h"
|
|
|
|
#include <QtGui>
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QWidget(parent)
|
|
{
|
|
populateScene();
|
|
|
|
View *view = new View("Top left view");
|
|
view->view()->setScene(scene);
|
|
QHBoxLayout *layout = new QHBoxLayout;
|
|
layout->addWidget(view);
|
|
setLayout(layout);
|
|
|
|
setWindowTitle(tr("Chip Example"));
|
|
}
|
|
|
|
void MainWindow::populateScene()
|
|
{
|
|
scene = new QGraphicsScene;
|
|
|
|
QImage image(":/qt4logo.png");
|
|
|
|
// Populate scene
|
|
int xx = 0;
|
|
int nitems = 0;
|
|
for (int i = -11000; i < 11000; i += 110) {
|
|
++xx;
|
|
int yy = 0;
|
|
for (int j = -7000; j < 7000; j += 70) {
|
|
++yy;
|
|
qreal x = (i + 11000) / 22000.0;
|
|
qreal y = (j + 7000) / 14000.0;
|
|
|
|
QColor color(image.pixel(int(image.width() * x), int(image.height() * y)));
|
|
QGraphicsItem *item = new Chip(color, xx, yy);
|
|
item->setPos(QPointF(i, j));
|
|
scene->addItem(item);
|
|
|
|
++nitems;
|
|
}
|
|
}
|
|
}
|