source: trunk/examples/opengl/grabber/mainwindow.cpp@ 641

Last change on this file since 641 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 7.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the examples of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtGui>
43#include <QtOpenGL>
44
45#include "glwidget.h"
46#include "mainwindow.h"
47
48MainWindow::MainWindow()
49{
50 centralWidget = new QWidget;
51 setCentralWidget(centralWidget);
52
53 glWidget = new GLWidget;
54 pixmapLabel = new QLabel;
55
56 glWidgetArea = new QScrollArea;
57 glWidgetArea->setWidget(glWidget);
58 glWidgetArea->setWidgetResizable(true);
59 glWidgetArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
60 glWidgetArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
61 glWidgetArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
62 glWidgetArea->setMinimumSize(50, 50);
63
64 pixmapLabelArea = new QScrollArea;
65 pixmapLabelArea->setWidget(pixmapLabel);
66 pixmapLabelArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
67 pixmapLabelArea->setMinimumSize(50, 50);
68
69 xSlider = createSlider(SIGNAL(xRotationChanged(int)),
70 SLOT(setXRotation(int)));
71 ySlider = createSlider(SIGNAL(yRotationChanged(int)),
72 SLOT(setYRotation(int)));
73 zSlider = createSlider(SIGNAL(zRotationChanged(int)),
74 SLOT(setZRotation(int)));
75
76 createActions();
77 createMenus();
78
79 QGridLayout *centralLayout = new QGridLayout;
80 centralLayout->addWidget(glWidgetArea, 0, 0);
81 centralLayout->addWidget(pixmapLabelArea, 0, 1);
82 centralLayout->addWidget(xSlider, 1, 0, 1, 2);
83 centralLayout->addWidget(ySlider, 2, 0, 1, 2);
84 centralLayout->addWidget(zSlider, 3, 0, 1, 2);
85 centralWidget->setLayout(centralLayout);
86
87 xSlider->setValue(15 * 16);
88 ySlider->setValue(345 * 16);
89 zSlider->setValue(0 * 16);
90
91 setWindowTitle(tr("Grabber"));
92 resize(400, 300);
93}
94
95void MainWindow::renderIntoPixmap()
96{
97 QSize size = getSize();
98 if (size.isValid()) {
99 QPixmap pixmap = glWidget->renderPixmap(size.width(), size.height());
100 setPixmap(pixmap);
101 }
102}
103
104void MainWindow::grabFrameBuffer()
105{
106 QImage image = glWidget->grabFrameBuffer();
107 setPixmap(QPixmap::fromImage(image));
108}
109
110void MainWindow::clearPixmap()
111{
112 setPixmap(QPixmap());
113}
114
115void MainWindow::about()
116{
117 QMessageBox::about(this, tr("About Grabber"),
118 tr("The <b>Grabber</b> example demonstrates two approaches for "
119 "rendering OpenGL into a Qt pixmap."));
120}
121
122void MainWindow::createActions()
123{
124 renderIntoPixmapAct = new QAction(tr("&Render into Pixmap..."), this);
125 renderIntoPixmapAct->setShortcut(tr("Ctrl+R"));
126 connect(renderIntoPixmapAct, SIGNAL(triggered()),
127 this, SLOT(renderIntoPixmap()));
128
129 grabFrameBufferAct = new QAction(tr("&Grab Frame Buffer"), this);
130 grabFrameBufferAct->setShortcut(tr("Ctrl+G"));
131 connect(grabFrameBufferAct, SIGNAL(triggered()),
132 this, SLOT(grabFrameBuffer()));
133
134 clearPixmapAct = new QAction(tr("&Clear Pixmap"), this);
135 clearPixmapAct->setShortcut(tr("Ctrl+L"));
136 connect(clearPixmapAct, SIGNAL(triggered()), this, SLOT(clearPixmap()));
137
138 exitAct = new QAction(tr("E&xit"), this);
139 exitAct->setShortcuts(QKeySequence::Quit);
140 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
141
142 aboutAct = new QAction(tr("&About"), this);