00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved. 00004 ** 00005 ** This file is part of the demonstration applications of the Qt Toolkit. 00006 ** 00007 ** This file may be used under the terms of the GNU General Public 00008 ** License version 2.0 as published by the Free Software Foundation 00009 ** and appearing in the file LICENSE.GPL included in the packaging of 00010 ** this file. Please review the following information to ensure GNU 00011 ** General Public Licensing requirements will be met: 00012 ** http://www.trolltech.com/products/qt/opensource.html 00013 ** 00014 ** If you are unsure which license is appropriate for your use, please 00015 ** review the following information: 00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the 00017 ** sales department at sales@trolltech.com. 00018 ** 00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00021 ** 00022 ****************************************************************************/ 00023 00024 #include "mainwindow.h" 00025 #include "view.h" 00026 #include "chip.h" 00027 00028 #include <QtGui> 00029 00030 MainWindow::MainWindow(QWidget *parent) 00031 : QWidget(parent) 00032 { 00033 populateScene(); 00034 00035 h1Splitter = new QSplitter; 00036 h2Splitter = new QSplitter; 00037 00038 QSplitter *vSplitter = new QSplitter; 00039 vSplitter->setOrientation(Qt::Vertical); 00040 vSplitter->addWidget(h1Splitter); 00041 vSplitter->addWidget(h2Splitter); 00042 00043 View *view = new View("Top left view"); 00044 view->view()->setScene(scene); 00045 h1Splitter->addWidget(view); 00046 00047 view = new View("Top right view"); 00048 view->view()->setScene(scene); 00049 h1Splitter->addWidget(view); 00050 00051 view = new View("Bottom left view"); 00052 view->view()->setScene(scene); 00053 h2Splitter->addWidget(view); 00054 00055 view = new View("Bottom right view"); 00056 view->view()->setScene(scene); 00057 h2Splitter->addWidget(view); 00058 00059 QHBoxLayout *layout = new QHBoxLayout; 00060 layout->addWidget(vSplitter); 00061 setLayout(layout); 00062 00063 setWindowTitle(tr("Chip Demo")); 00064 } 00065 00066 void MainWindow::populateScene() 00067 { 00068 scene = new QGraphicsScene; 00069 00070 QImage image(":/qt4logo.png"); 00071 00072 // Populate scene 00073 int xx = 0; 00074 int nitems = 0; 00075 for (int i = -11000; i < 11000; i += 110) { 00076 ++xx; 00077 int yy = 0; 00078 for (int j = -7000; j < 7000; j += 70) { 00079 ++yy; 00080 qreal x = (i + 11000) / 22000.0; 00081 qreal y = (j + 7000) / 14000.0; 00082 00083 QColor color(image.pixel(int(image.width() * x), int(image.height() * y))); 00084 QGraphicsItem *item = new Chip(color, xx, yy); 00085 item->setPos(QPointF(i, j)); 00086 scene->addItem(item); 00087 00088 ++nitems; 00089 } 00090 } 00091 }
1.5.1