summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/gestures/imageviewer/imagewidget.cpp10
-rw-r--r--examples/multimedia/audio/audiodevices/audiodevicesbase.ui444
-rw-r--r--examples/opengl/opengl.pro6
-rw-r--r--examples/opengl/textures/glwidget.cpp110
-rw-r--r--examples/opengl/textures/glwidget.h10
5 files changed, 310 insertions, 270 deletions
diff --git a/examples/gestures/imageviewer/imagewidget.cpp b/examples/gestures/imageviewer/imagewidget.cpp
index 53a9eb2..e17d746 100644
--- a/examples/gestures/imageviewer/imagewidget.cpp
+++ b/examples/gestures/imageviewer/imagewidget.cpp
@@ -71,8 +71,12 @@ ImageWidget::ImageWidget(QWidget *parent)
connect(pinchGesture, SIGNAL(cancelled()), this, SLOT(pinchTriggered()));
connect(pinchGesture, SIGNAL(triggered()), this, SLOT(pinchTriggered()));
+//! [construct swipe gesture]
QGesture *swipeGesture = new QSwipeGesture(this);
+//! [construct swipe gesture]
+//! [connect swipe gesture]
connect(swipeGesture, SIGNAL(triggered()), this, SLOT(swipeTriggered()));
+//! [connect swipe gesture]
}
void ImageWidget::paintEvent(QPaintEvent*)
@@ -130,12 +134,15 @@ void ImageWidget::pinchTriggered()
update();
}
+//! [swipe slot start]
void ImageWidget::swipeTriggered()
{
QSwipeGesture *pg = qobject_cast<QSwipeGesture*>(sender());
+//! [swipe slot start]
qDebug() << (int) pg->horizontalDirection();
qDebug() << pg->swipeAngle();
+//! [swipe slot finish]
if (pg->horizontalDirection() == QSwipeGesture::Left
|| pg->verticalDirection() == QSwipeGesture::Up)
goPrevImage();
@@ -143,6 +150,7 @@ void ImageWidget::swipeTriggered()
goNextImage();
update();
}
+//! [swipe slot finish]
void ImageWidget::resizeEvent(QResizeEvent*)
{
@@ -245,5 +253,3 @@ void ImageWidget::goToImage(int index)
nextImage = QImage();
update();
}
-
-#include "moc_imagewidget.cpp"
diff --git a/examples/multimedia/audio/audiodevices/audiodevicesbase.ui b/examples/multimedia/audio/audiodevices/audiodevicesbase.ui
index 674f201..29dd40e 100644
--- a/examples/multimedia/audio/audiodevices/audiodevicesbase.ui
+++ b/examples/multimedia/audio/audiodevices/audiodevicesbase.ui
@@ -1,7 +1,8 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
<class>AudioDevicesBase</class>
- <widget class="QMainWindow" name="AudioDevicesBase" >
- <property name="geometry" >
+ <widget class="QMainWindow" name="AudioDevicesBase">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
@@ -9,246 +10,223 @@
<height>702</height>
</rect>
</property>
- <property name="windowTitle" >
+ <property name="windowTitle">
<string>AudioDevicesBase</string>
</property>
- <widget class="QWidget" name="centralwidget" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>28</y>
- <width>504</width>
- <height>653</height>
- </rect>
- </property>
- <widget class="QWidget" name="layoutWidget" >
- <property name="geometry" >
- <rect>
- <x>40</x>
- <y>21</y>
- <width>321</width>
- <height>506</height>
- </rect>
- </property>
- <layout class="QGridLayout" name="gridLayout" >
- <item row="0" column="0" >
- <widget class="QLabel" name="deviceLabel" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
- <horstretch>1</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text" >
- <string>Device</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1" >
- <widget class="QLabel" name="modeLabel" >
- <property name="text" >
- <string>Mode</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0" >
- <widget class="QComboBox" name="deviceBox" />
- </item>
- <item row="1" column="1" >
- <widget class="QComboBox" name="modeBox" />
- </item>
- <item row="2" column="0" >
- <widget class="QLabel" name="actualLabel" >
- <property name="frameShape" >
- <enum>QFrame::Panel</enum>
- </property>
- <property name="frameShadow" >
- <enum>QFrame::Raised</enum>
- </property>
- <property name="text" >
- <string>Actual Settings</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item row="2" column="1" >
- <widget class="QLabel" name="nearestLabel" >
- <property name="frameShape" >
- <enum>QFrame::Panel</enum>
- </property>
- <property name="frameShadow" >
- <enum>QFrame::Raised</enum>
- </property>
- <property name="text" >
- <string>Nearest Settings</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item row="3" column="0" >
- <widget class="QLabel" name="actualFreqLabel" >
- <property name="text" >
- <string>Frequency</string>
- </property>
- </widget>
- </item>
- <item row="3" column="1" >
- <widget class="QLabel" name="nearestFreqLabel" >
- <property name="text" >
- <string>Frequency</string>
- </property>
- </widget>
- </item>
- <item row="4" column="0" >
- <widget class="QComboBox" name="frequencyBox" />
- </item>
- <item row="4" column="1" >
- <widget class="QLineEdit" name="nearestFreq" />
- </item>
- <item row="5" column="0" >
- <widget class="QLabel" name="actualChannelsLabel" >
- <property name="text" >
- <string>Channels</string>
- </property>
- </widget>
- </item>
- <item row="5" column="1" >
- <widget class="QLabel" name="nearestChannelLabel" >
- <property name="text" >
- <string>Channel</string>
- </property>
- </widget>
- </item>
- <item row="6" column="0" >
- <widget class="QComboBox" name="channelsBox" />
- </item>
- <item row="6" column="1" >
- <widget class="QLineEdit" name="nearestChannel" />
- </item>
- <item row="7" column="0" >
- <widget class="QLabel" name="actualCodecLabel" >
- <property name="text" >
- <string>Codecs</string>
- </property>
- </widget>
- </item>
- <item row="7" column="1" >
- <widget class="QLabel" name="nearestCodecLabel" >
- <property name="text" >
- <string>Codec</string>
- </property>
- </widget>
- </item>
- <item row="8" column="0" >
- <widget class="QComboBox" name="codecsBox" />
- </item>
- <item row="8" column="1" >
- <widget class="QLineEdit" name="nearestCodec" />
- </item>
- <item row="9" column="0" >
- <widget class="QLabel" name="actualSampleSizeLabel" >
- <property name="text" >
- <string>SampleSize</string>
- </property>
- </widget>
- </item>
- <item row="9" column="1" >
- <widget class="QLabel" name="nearestSampleSizeLabel" >
- <property name="text" >
- <string>SampleSize</string>
- </property>
- </widget>
- </item>
- <item row="10" column="0" >
- <widget class="QComboBox" name="sampleSizesBox" />
- </item>
- <item row="10" column="1" >
- <widget class="QLineEdit" name="nearestSampleSize" />
- </item>
- <item row="11" column="0" >
- <widget class="QLabel" name="actualSampleTypeLabel" >
- <property name="text" >
- <string>SampleType</string>
- </property>
- </widget>
- </item>
- <item row="11" column="1" >
- <widget class="QLabel" name="nearestSampleTypeLabel" >
- <property name="text" >
- <string>SampleType</string>
- </property>
- </widget>
- </item>
- <item row="12" column="0" >
- <widget class="QComboBox" name="sampleTypesBox" />
- </item>
- <item row="12" column="1" >
- <widget class="QLineEdit" name="nearestSampleType" />
- </item>
- <item row="13" column="0" >
- <widget class="QLabel" name="actualEndianLabel" >
- <property name="text" >
- <string>Endianess</string>
- </property>
- </widget>
- </item>
- <item row="13" column="1" >
- <widget class="QLabel" name="nearestEndianLabel" >
- <property name="text" >
- <string>Endianess</string>
- </property>
- </widget>
- </item>
- <item row="14" column="0" >
- <widget class="QComboBox" name="endianBox" />
- </item>
- <item row="14" column="1" >
- <widget class="QLineEdit" name="nearestEndian" />
- </item>
- <item row="15" column="0" colspan="2" >
- <widget class="QTextEdit" name="logOutput" >
- <property name="minimumSize" >
- <size>
- <width>0</width>
- <height>40</height>
- </size>
- </property>
- </widget>
- </item>
- <item row="16" column="0" colspan="2" >
- <widget class="QPushButton" name="testButton" >
- <property name="text" >
- <string>Test</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="deviceLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Device</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="modeLabel">
+ <property name="text">
+ <string>Mode</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QComboBox" name="deviceBox"/>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="modeBox"/>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="actualLabel">
+ <property name="frameShape">
+ <enum>QFrame::Panel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Raised</enum>
+ </property>
+ <property name="text">
+ <string>Actual Settings</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLabel" name="nearestLabel">
+ <property name="frameShape">
+ <enum>QFrame::Panel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Raised</enum>
+ </property>
+ <property name="text">
+ <string>Nearest Settings</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="actualFreqLabel">
+ <property name="text">
+ <string>Frequency</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLabel" name="nearestFreqLabel">
+ <property name="text">
+ <string>Frequency</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0">
+ <widget class="QComboBox" name="frequencyBox"/>
+ </item>
+ <item row="4" column="1">
+ <widget class="QLineEdit" name="nearestFreq"/>
+ </item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="actualChannelsLabel">
+ <property name="text">
+ <string>Channels</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QLabel" name="nearestChannelLabel">
+ <property name="text">
+ <string>Channel</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QComboBox" name="channelsBox"/>
+ </item>
+ <item row="6" column="1">
+ <widget class="QLineEdit" name="nearestChannel"/>
+ </item>
+ <item row="7" column="0">
+ <widget class="QLabel" name="actualCodecLabel">
+ <property name="text">
+ <string>Codecs</string>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="1">
+ <widget class="QLabel" name="nearestCodecLabel">
+ <property name="text">
+ <string>Codec</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="0">
+ <widget class="QComboBox" name="codecsBox"/>
+ </item>
+ <item row="8" column="1">
+ <widget class="QLineEdit" name="nearestCodec"/>
+ </item>
+ <item row="9" column="0">
+ <widget class="QLabel" name="actualSampleSizeLabel">
+ <property name="text">
+ <string>SampleSize</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="1">
+ <widget class="QLabel" name="nearestSampleSizeLabel">
+ <property name="text">
+ <string>SampleSize</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="0">
+ <widget class="QComboBox" name="sampleSizesBox"/>
+ </item>
+ <item row="10" column="1">
+ <widget class="QLineEdit" name="nearestSampleSize"/>
+ </item>
+ <item row="11" column="0">
+ <widget class="QLabel" name="actualSampleTypeLabel">
+ <property name="text">
+ <string>SampleType</string>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="1">
+ <widget class="QLabel" name="nearestSampleTypeLabel">
+ <property name="text">
+ <string>SampleType</string>
+ </property>
+ </widget>
+ </item>
+ <item row="12" column="0">
+ <widget class="QComboBox" name="sampleTypesBox"/>
+ </item>
+ <item row="12" column="1">
+ <widget class="QLineEdit" name="nearestSampleType"/>
+ </item>
+ <item row="13" column="0">
+ <widget class="QLabel" name="actualEndianLabel">
+ <property name="text">
+ <string>Endianess</string>
+ </property>
+ </widget>
+ </item>
+ <item row="13" column="1">
+ <widget class="QLabel" name="nearestEndianLabel">
+ <property name="text">
+ <string>Endianess</string>
+ </property>
+ </widget>
+ </item>
+ <item row="14" column="0">
+ <widget class="QComboBox" name="endianBox"/>
+ </item>
+ <item row="14" column="1">
+ <widget class="QLineEdit" name="nearestEndian"/>
+ </item>
+ <item row="15" column="0" colspan="2">
+ <widget class="QTextEdit" name="logOutput">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>40</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item row="16" column="0" colspan="2">
+ <widget class="QPushButton" name="testButton">
+ <property name="text">
+ <string>Test</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
</widget>
- <widget class="QMenuBar" name="menubar" >
- <property name="geometry" >
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>504</width>
- <height>28</height>
- </rect>
- </property>
- </widget>
- <widget class="QStatusBar" name="statusbar" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>681</y>
- <width>504</width>
- <height>21</height>
+ <height>22</height>
</rect>
</property>
</widget>
+ <widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
diff --git a/examples/opengl/opengl.pro b/examples/opengl/opengl.pro
index b86e0ba..2cb8227 100644
--- a/examples/opengl/opengl.pro
+++ b/examples/opengl/opengl.pro
@@ -5,9 +5,9 @@ contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles1cl)|contains(QT_CONF
SUBDIRS = hellogl_es2
} else {
SUBDIRS = hellogl_es
- !contains(QT_CONFIG, opengles1cl) {
- SUBDIRS += textures
- }
+ }
+ !contains(QT_CONFIG, opengles1cl) {
+ SUBDIRS += textures
}
} else {
SUBDIRS = 2dpainting \
diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp
index 024133b..6efd31a 100644
--- a/examples/opengl/textures/glwidget.cpp
+++ b/examples/opengl/textures/glwidget.cpp
@@ -44,16 +44,6 @@
#include "glwidget.h"
-class CubeObject
-{
-public:
- GLuint textures[6];
- QVector<QVector3D> vertices;
- QVector<QVector2D> texCoords;
-
- void draw();
-};
-
GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget)
: QGLWidget(parent, shareWidget)
{
@@ -61,12 +51,13 @@ GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget)
xRot = 0;
yRot = 0;
zRot = 0;
- cube = 0;
+#ifdef QT_OPENGL_ES_2
+ program = 0;
+#endif
}
GLWidget::~GLWidget()
{
- delete cube;
}
QSize GLWidget::minimumSizeHint() const
@@ -99,19 +90,90 @@ void GLWidget::initializeGL()
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
+#ifndef QT_OPENGL_ES_2
glEnable(GL_TEXTURE_2D);
+#endif
+
+#ifdef QT_OPENGL_ES_2
+
+#define PROGRAM_VERTEX_ATTRIBUTE 0
+#define PROGRAM_TEXCOORD_ATTRIBUTE 1
+
+ QGLShader *vshader = new QGLShader(QGLShader::VertexShader, this);
+ const char *vsrc =
+ "attribute highp vec4 vertex;\n"
+ "attribute mediump vec4 texCoord;\n"
+ "varying mediump vec4 texc;\n"
+ "uniform mediump mat4 matrix;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_Position = matrix * vertex;\n"
+ " texc = texCoord;\n"
+ "}\n";
+ vshader->compile(vsrc);
+
+ QGLShader *fshader = new QGLShader(QGLShader::FragmentShader, this);
+ const char *fsrc =
+ "uniform sampler2D texture;\n"
+ "varying mediump vec4 texc;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_FragColor = texture2D(texture, texc.st);\n"
+ "}\n";
+ fshader->compile(fsrc);
+
+ program = new QGLShaderProgram(this);
+ program->addShader(vshader);
+ program->addShader(fshader);
+ program->bindAttributeLocation("vertex", PROGRAM_VERTEX_ATTRIBUTE);
+ program->bindAttributeLocation("texCoord", PROGRAM_TEXCOORD_ATTRIBUTE);
+ program->link();
+
+ program->enable();
+ program->setUniformValue("texture", 0);
+
+#endif
}
void GLWidget::paintGL()
{
qglClearColor(clearColor);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+#if !defined(QT_OPENGL_ES_2)
+
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -10.0f);
glRotatef(xRot / 16.0f, 1.0f, 0.0f, 0.0f);
glRotatef(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
glRotatef(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
- cube->draw();
+
+ glVertexPointer(3, GL_FLOAT, 0, vertices.constData());
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords.constData());
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+#else
+
+ QMatrix4x4 m;
+ m.ortho(-0.5f, +0.5f, +0.5f, -0.5f, 4.0f, 15.0f);
+ m.translate(0.0f, 0.0f, -10.0f);
+ m.rotate(xRot / 16.0f, 1.0f, 0.0f, 0.0f);
+ m.rotate(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
+ m.rotate(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
+
+ program->setUniformValue("matrix", m);
+ program->setAttributeArray
+ (PROGRAM_VERTEX_ATTRIBUTE, vertices.constData());
+ program->setAttributeArray
+ (PROGRAM_TEXCOORD_ATTRIBUTE, texCoords.constData());
+
+#endif
+
+ for (int i = 0; i < 6; ++i) {
+ glBindTexture(GL_TEXTURE_2D, textures[i]);
+ glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4);
+ }
}
void GLWidget::resizeGL(int width, int height)
@@ -119,6 +181,7 @@ void GLWidget::resizeGL(int width, int height)
int side = qMin(width, height);
glViewport((width - side) / 2, (height - side) / 2, side, side);
+#if !defined(QT_OPENGL_ES_2)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
#ifndef QT_OPENGL_ES
@@ -127,6 +190,7 @@ void GLWidget::resizeGL(int width, int height)
glOrthof(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
#endif
glMatrixMode(GL_MODELVIEW);
+#endif
}
void GLWidget::mousePressEvent(QMouseEvent *event)
@@ -163,32 +227,18 @@ void GLWidget::makeObject()
{ { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } }
};
- cube = new CubeObject();
-
for (int j=0; j < 6; ++j) {
- cube->textures[j] = bindTexture
+ textures[j] = bindTexture
(QPixmap(QString(":/images/side%1.png").arg(j + 1)), GL_TEXTURE_2D);
}
for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 4; ++j) {
- cube->texCoords.append
+ texCoords.append
(QVector2D(j == 0 || j == 3, j == 0 || j == 1));
- cube->vertices.append
+ vertices.append
(QVector3D(0.2 * coords[i][j][0], 0.2 * coords[i][j][1],
0.2 * coords[i][j][2]));
}
}
}
-
-void CubeObject::draw()
-{
- glVertexPointer(3, GL_FLOAT, 0, vertices.constData());
- glTexCoordPointer(2, GL_FLOAT, 0, texCoords.constData());
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- for (int i = 0; i < 6; ++i) {
- glBindTexture(GL_TEXTURE_2D, textures[i]);
- glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4);
- }
-}
diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h
index 46507ce..4dcff3b 100644
--- a/examples/opengl/textures/glwidget.h
+++ b/examples/opengl/textures/glwidget.h
@@ -42,9 +42,10 @@
#ifndef GLWIDGET_H
#define GLWIDGET_H
+#include <QtGui>
#include <QGLWidget>
-class CubeObject;
+class QGLShaderProgram;
class GLWidget : public QGLWidget
{
@@ -78,7 +79,12 @@ private:
int xRot;
int yRot;
int zRot;
- CubeObject *cube;
+ GLuint textures[6];
+ QVector<QVector3D> vertices;
+ QVector<QVector2D> texCoords;
+#ifdef QT_OPENGL_ES_2
+ QGLShaderProgram *program;
+#endif
};
#endif