qt5base-lts/examples/widgets/graphicsview/chip/mainwindow.cpp
Lucie Gérard 05fc3aef53 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-05-16 16:37:38 +02:00

69 lines
1.7 KiB
C++

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "chip.h"
#include "mainwindow.h"
#include "view.h"
#include <QHBoxLayout>
#include <QSplitter>
MainWindow::MainWindow(QWidget *parent)
: QWidget(parent), scene(new QGraphicsScene(this))
, h1Splitter(new QSplitter(this)), h2Splitter(new QSplitter(this))
{
populateScene();
QSplitter *vSplitter = new QSplitter;
vSplitter->setOrientation(Qt::Vertical);
vSplitter->addWidget(h1Splitter);
vSplitter->addWidget(h2Splitter);
View *view = new View("Top left view");
view->view()->setScene(scene);
h1Splitter->addWidget(view);
view = new View("Top right view");
view->view()->setScene(scene);
h1Splitter->addWidget(view);
view = new View("Bottom left view");
view->view()->setScene(scene);
h2Splitter->addWidget(view);
view = new View("Bottom right view");
view->view()->setScene(scene);
h2Splitter->addWidget(view);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(vSplitter);
setLayout(layout);
setWindowTitle(tr("Chip Example"));
}
void MainWindow::populateScene()
{
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;
}
}
}