diff options
author | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2014-02-19 10:06:25 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2014-02-19 10:06:25 +0100 |
commit | 30fd22b9574def54726e7b193127cc0c901c1b4c (patch) | |
tree | 96dfc923044db0515064ba39d052d9ed577e3e40 /tests/manual | |
parent | d7b0581c1c2ef60c08d238dae39298af6904918f (diff) | |
parent | 6aa09bbce59828d028f6d1e81d2bfc6ba537aae1 (diff) |
Merge remote-tracking branch 'origin/dev' into stable
Change-Id: Ice524edcc51373509f0023ae7f7c2963f4602f88
Diffstat (limited to 'tests/manual')
20 files changed, 1617 insertions, 18 deletions
diff --git a/tests/manual/bearerex/bearerex.cpp b/tests/manual/bearerex/bearerex.cpp index 185dbe123e..97a98bebc9 100644 --- a/tests/manual/bearerex/bearerex.cpp +++ b/tests/manual/bearerex/bearerex.cpp @@ -142,8 +142,8 @@ void BearerEx::on_showDetailsButton_clicked() } QNetworkConfiguration networkConfiguration = qvariant_cast<QNetworkConfiguration>(item->data(Qt::UserRole)); - DetailedInfoDialog infoDialog(&networkConfiguration,this); - infoDialog.exec(); + DetailedInfoDialog infoDialog(&networkConfiguration,this); + infoDialog.exec(); } void BearerEx::on_createSessionButton_clicked() @@ -236,12 +236,12 @@ DetailedInfoDialog::DetailedInfoDialog(QNetworkConfiguration* apNetworkConfigura rowCount = rowCount + apNetworkConfiguration->children().count(); } - tableWidget->setRowCount(rowCount); - tableWidget->setColumnWidth(1,250); - tableWidget->setItem(0, 0, new QTableWidgetItem(tr("Name"))); - tableWidget->setItem(0, 1, new QTableWidgetItem(apNetworkConfiguration->name())); - tableWidget->setItem(1, 0, new QTableWidgetItem(tr("Id"))); - tableWidget->setItem(1, 1, new QTableWidgetItem(apNetworkConfiguration->identifier())); + tableWidget->setRowCount(rowCount); + tableWidget->setColumnWidth(1,250); + tableWidget->setItem(0, 0, new QTableWidgetItem(tr("Name"))); + tableWidget->setItem(0, 1, new QTableWidgetItem(apNetworkConfiguration->name())); + tableWidget->setItem(1, 0, new QTableWidgetItem(tr("Id"))); + tableWidget->setItem(1, 1, new QTableWidgetItem(apNetworkConfiguration->identifier())); if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { for (int i=0; i<apNetworkConfiguration->children().count(); i++) { tableWidget->setItem(i+2, 0, new QTableWidgetItem(QString("IAP")+QString::number(i+1))); diff --git a/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm b/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm index d276961b93..6919562ddc 100644 --- a/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm +++ b/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm @@ -42,6 +42,7 @@ #import "TestMouseMovedNSView.h" #include <QtGui> +#include <QtWidgets> #include <QMacCocoaViewContainer> class MyWidget : public QWidget diff --git a/tests/manual/dialogs/printdialogpanel.cpp b/tests/manual/dialogs/printdialogpanel.cpp index d0684f6e35..5c89055e22 100644 --- a/tests/manual/dialogs/printdialogpanel.cpp +++ b/tests/manual/dialogs/printdialogpanel.cpp @@ -47,6 +47,7 @@ #include <QPrinter> #include <QPrintDialog> #include <QPrintPreviewDialog> +#include <QPageSetupDialog> #include <QApplication> #include <QDesktopWidget> #include <QGroupBox> @@ -211,15 +212,9 @@ static void print(QPrinter *printer) QPainter painter(printer); const QRectF pageF = printer->pageRect(); - painter.drawRect(pageF); - - drawHorizCmRuler(painter, pageF.x(), pageF.right(), pageF.height() /2); - drawVertCmRuler(painter, pageF.x() + pageF.width() / 2, pageF.top(), pageF.bottom()); - QFont font = painter.font(); font.setFamily("Courier"); font.setPointSize(10); - painter.setFont(font); // Format message. const int charHeight = QFontMetrics(font).boundingRect('X').height(); @@ -233,6 +228,17 @@ static void print(QPrinter *printer) << "\nFont: " << font.family() << ' ' << font.pointSize() << '\n' << *printer; + if (!painter.device()->logicalDpiY() || !painter.device()->logicalDpiX()) { + qWarning() << Q_FUNC_INFO << "Bailing out due to invalid DPI: " << msg; + return; + } + + painter.drawRect(pageF); + + drawHorizCmRuler(painter, pageF.x(), pageF.right(), pageF.height() /2); + drawVertCmRuler(painter, pageF.x() + pageF.width() / 2, pageF.top(), pageF.bottom()); + + painter.setFont(font); QPointF textPoint = pageF.topLeft() + QPoint(10, charHeight + 10); foreach (const QString &line, msg.split('\n')) { painter.drawText(textPoint, line); @@ -330,6 +336,9 @@ PrintDialogPanel::PrintDialogPanel(QWidget *parent) button = new QPushButton(tr("Preview..."), m_dialogsGroupBox); connect(button, SIGNAL(clicked()), this, SLOT(showPreviewDialog())); vBoxLayout->addWidget(button); + button = new QPushButton(tr("Page Setup..."), m_dialogsGroupBox); + connect(button, SIGNAL(clicked()), this, SLOT(showPageSetupDialog())); + vBoxLayout->addWidget(button); QGridLayout *gridLayout = new QGridLayout(this); gridLayout->addWidget(m_creationGroupBox, 0, 0); @@ -414,6 +423,14 @@ void PrintDialogPanel::showPreviewDialog() retrieveSettings(m_printer.data()); } +void PrintDialogPanel::showPageSetupDialog() +{ + applySettings(m_printer.data()); + QPageSetupDialog dialog(m_printer.data(), this); + if (dialog.exec() == QDialog::Accepted) + retrieveSettings(m_printer.data()); +} + #include "printdialogpanel.moc" #endif // !QT_NO_PRINTER diff --git a/tests/manual/dialogs/printdialogpanel.h b/tests/manual/dialogs/printdialogpanel.h index 4999504a3c..c869782769 100644 --- a/tests/manual/dialogs/printdialogpanel.h +++ b/tests/manual/dialogs/printdialogpanel.h @@ -69,6 +69,7 @@ private slots: void deletePrinter(); void showPrintDialog(); void showPreviewDialog(); + void showPageSetupDialog(); void enableCustomSizeControl(); private: diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index 381922288f..62722ea62b 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -25,6 +25,7 @@ qnetworkreply \ qpainfo \ qscreen \ qssloptions \ +qsslsocket \ qtabletevent \ qtexteditlist \ qtbug-8933 \ @@ -47,6 +48,8 @@ unc !contains(QT_CONFIG, openssl):!contains(QT_CONFIG, openssl-linked):SUBDIRS -= qssloptions +contains(QT_CONFIG, opengl):SUBDIRS += qopengltextureblitter + win32 { SUBDIRS -= network_remote_stresstest network_stresstest # disable some tests on wince because of missing dependencies diff --git a/tests/manual/qopengltextureblitter/main.cpp b/tests/manual/qopengltextureblitter/main.cpp new file mode 100644 index 0000000000..3e9c30932a --- /dev/null +++ b/tests/manual/qopengltextureblitter/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopengltextureblitwindow.h" +#include <QtGui/QGuiApplication> + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + QOpenGLTextureBlitWindow window; + window.show(); + + return app.exec(); +} diff --git a/tests/manual/qopengltextureblitter/qopengltextureblitter.pro b/tests/manual/qopengltextureblitter/qopengltextureblitter.pro new file mode 100644 index 0000000000..95f1c14e5a --- /dev/null +++ b/tests/manual/qopengltextureblitter/qopengltextureblitter.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +TARGET = qopengltextureblitter +INCLUDEPATH += . + +QT+=gui-private +# Input +HEADERS += \ + qopengltextureblitwindow.h + +SOURCES += \ + main.cpp \ + qopengltextureblitwindow.cpp diff --git a/tests/manual/qopengltextureblitter/qopengltextureblitwindow.cpp b/tests/manual/qopengltextureblitter/qopengltextureblitwindow.cpp new file mode 100644 index 0000000000..8f51f511c9 --- /dev/null +++ b/tests/manual/qopengltextureblitter/qopengltextureblitwindow.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopengltextureblitwindow.h" + +#include <QtGui/QPainter> +#include <QtGui/QOpenGLTexture> +#include <QtGui/QMatrix4x4> + +#include <QtCore/QCoreApplication> +#include <QtCore/QDebug> + +QOpenGLTextureBlitWindow::QOpenGLTextureBlitWindow() + : QWindow() + , m_context(new QOpenGLContext(this)) +{ + resize(500,500); + setSurfaceType(OpenGLSurface); + QSurfaceFormat surfaceFormat = format(); + if (QCoreApplication::arguments().contains(QStringLiteral("-coreprofile"))) { + surfaceFormat.setVersion(3,2); + surfaceFormat.setProfile(QSurfaceFormat::CoreProfile); + } + + setFormat(surfaceFormat); + create(); + m_context->setFormat(surfaceFormat); + m_context->create(); + + m_context->makeCurrent(this); + + m_blitter.create(); +} + +void QOpenGLTextureBlitWindow::render() +{ + m_context->makeCurrent(this); + + QRect viewport(0,0,dWidth(),dHeight()); + glViewport(0,0,dWidth(), dHeight()); + + glClearColor(0.f, .6f, .0f, 0.f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + QOpenGLTexture texture(m_image); + texture.setWrapMode(QOpenGLTexture::ClampToEdge); + texture.create(); + + QOpenGLTexture texture_mirrored(m_image_mirrord); + texture_mirrored.setWrapMode(QOpenGLTexture::ClampToEdge); + texture_mirrored.create(); + + QRectF topLeftOriginTopLeft(QPointF(0,0), QPointF(dWidth()/2.0, dHeight()/2.0)); + QRectF topRightOriginTopLeft(QPointF(dWidth()/2.0,0), QPointF(dWidth(), dHeight()/2.0)); + QRectF bottomLeftOriginTopLeft(QPointF(0, dHeight()/2.0), QPointF(dWidth() /2.0, dHeight())); + QRectF bottomRightOriginTopLeft(QPoint(dWidth()/2.0, dHeight()/2.0), QPointF(dWidth(), dHeight())); + + QRectF topLeftOriginBottomLeft = bottomLeftOriginTopLeft; Q_UNUSED(topLeftOriginBottomLeft); + QRectF topRightOriginBottomLeft = bottomRightOriginTopLeft; Q_UNUSED(topRightOriginBottomLeft); + QRectF bottomLeftOriginBottomLeft = topLeftOriginTopLeft; + QRectF bottomRightOriginBottomLeft = topRightOriginTopLeft; + + QOpenGLTextureBlitter::Origin topLeftOrigin = QOpenGLTextureBlitter::OriginTopLeft; + QOpenGLTextureBlitter::Origin bottomLeftOrigin = QOpenGLTextureBlitter::OriginBottomLeft; + + QMatrix4x4 topRightOriginTopLeftVertex = QOpenGLTextureBlitter::targetTransform(topRightOriginTopLeft, viewport); + QMatrix4x4 bottomLeftOriginTopLeftVertex = QOpenGLTextureBlitter::targetTransform(bottomLeftOriginTopLeft, viewport); + QMatrix4x4 bottomRightOriginTopLeftVertex = QOpenGLTextureBlitter::targetTransform(bottomRightOriginTopLeft, viewport); + + QMatrix3x3 texTopLeftOriginTopLeft = QOpenGLTextureBlitter::sourceTransform(topLeftOriginTopLeft, m_image.size(), topLeftOrigin); + QMatrix3x3 texTopRightOriginBottomLeft = QOpenGLTextureBlitter::sourceTransform(topRightOriginBottomLeft, m_image.size(), bottomLeftOrigin); + QMatrix3x3 texBottomLeftOriginBottomLeft = QOpenGLTextureBlitter::sourceTransform(bottomLeftOriginBottomLeft, m_image.size(), bottomLeftOrigin); + QMatrix3x3 texBottomRightOriginBottomLeft = QOpenGLTextureBlitter::sourceTransform(bottomRightOriginBottomLeft, m_image.size(), bottomLeftOrigin); + + QSizeF subSize(topLeftOriginTopLeft.width()/2, topLeftOriginTopLeft.height()/2); + QRectF subTopLeftOriginTopLeft(topLeftOriginTopLeft.topLeft(), subSize); + QRectF subTopRightOriginTopLeft(QPointF(topLeftOriginTopLeft.topLeft().x() + topLeftOriginTopLeft.width() / 2, + topLeftOriginTopLeft.topLeft().y()), subSize); + QRectF subBottomLeftOriginTopLeft(QPointF(topLeftOriginTopLeft.topLeft().x(), + topLeftOriginTopLeft.topLeft().y() + topLeftOriginTopLeft.height() / 2), subSize); + QRectF subBottomRightOriginTopLeft(QPointF(topLeftOriginTopLeft.topLeft().x() + topLeftOriginTopLeft.width() / 2, + topLeftOriginTopLeft.topLeft().y() + topLeftOriginTopLeft.height() / 2), subSize); + + QMatrix4x4 subTopLeftOriginTopLeftVertex = QOpenGLTextureBlitter::targetTransform(subTopLeftOriginTopLeft, viewport); + QMatrix4x4 subTopRightOriginTopLeftVertex = QOpenGLTextureBlitter::targetTransform(subTopRightOriginTopLeft, viewport); + QMatrix4x4 subBottomLeftOriginTopLeftVertex = QOpenGLTextureBlitter::targetTransform(subBottomLeftOriginTopLeft, viewport); + QMatrix4x4 subBottomRightOriginTopLeftVertex = QOpenGLTextureBlitter::targetTransform(subBottomRightOriginTopLeft, viewport); + + m_blitter.bind(); + m_blitter.blit(texture_mirrored.textureId(), subTopLeftOriginTopLeftVertex, texBottomRightOriginBottomLeft); + m_blitter.blit(texture_mirrored.textureId(), subTopRightOriginTopLeftVertex, texBottomLeftOriginBottomLeft); + m_blitter.blit(texture.textureId(), subBottomLeftOriginTopLeftVertex, texTopRightOriginBottomLeft); + m_blitter.blit(texture.textureId(), subBottomRightOriginTopLeftVertex, texTopLeftOriginTopLeft); + + m_blitter.blit(texture.textureId(), topRightOriginTopLeftVertex, topLeftOrigin); + m_blitter.blit(texture_mirrored.textureId(), bottomLeftOriginTopLeftVertex, topLeftOrigin); + + m_blitter.setSwizzleRB(true); + m_blitter.blit(texture.textureId(), bottomRightOriginTopLeftVertex, texTopLeftOriginTopLeft); + m_blitter.setSwizzleRB(false); + m_blitter.release(); + + m_context->swapBuffers(this); +} + + +void QOpenGLTextureBlitWindow::exposeEvent(QExposeEvent *event) +{ + Q_UNUSED(event); + render(); +} + +void QOpenGLTextureBlitWindow::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event); + m_image = QImage(size() * devicePixelRatio(), QImage::Format_ARGB32_Premultiplied); + + m_image.fill(Qt::gray); + + QPainter p(&m_image); + + QPen pen(Qt::red); + pen.setWidth(5); + p.setPen(pen); + + QFont font = p.font(); + font.setPixelSize(qMin(m_image.height(), m_image.width()) / 20); + p.setFont(font); + + int dx = dWidth() / 5; + int dy = dHeight() / 5; + for (int y = 0; y < 5; y++) { + for (int x = 0; x < 5; x++) { + QRect textRect(x * dx, y*dy, dx,dy); + QString text = QString("[%1,%2]").arg(x).arg(y); + p.drawText(textRect,text); + } + } + + p.drawRect(QRectF(2.5,2.5,dWidth() - 5, dHeight() - 5)); + + m_image_mirrord = m_image.mirrored(false,true); +} + diff --git a/tests/manual/qopengltextureblitter/qopengltextureblitwindow.h b/tests/manual/qopengltextureblitter/qopengltextureblitwindow.h new file mode 100644 index 0000000000..31532db2cd --- /dev/null +++ b/tests/manual/qopengltextureblitter/qopengltextureblitwindow.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENGLTEXTUREBLITWINDOW_H +#define QOPENGLTEXTUREBLITWINDOW_H + +#include <QtGui/QWindow> +#include <QtGui/QOpenGLContext> +#include <QtGui/private/qopengltextureblitter_p.h> + +class QOpenGLTextureBlitWindow : public QWindow +{ + Q_OBJECT +public: + QOpenGLTextureBlitWindow(); + + void render(); +protected: + void exposeEvent(QExposeEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + qreal dWidth() const { return width() * devicePixelRatio(); } + qreal dHeight() const { return height() * devicePixelRatio(); } + + QScopedPointer<QOpenGLContext> m_context; + QOpenGLTextureBlitter m_blitter; + QImage m_image; + QImage m_image_mirrord; +}; + +#endif diff --git a/tests/manual/qopenglwidget/openglwidget/main.cpp b/tests/manual/qopenglwidget/openglwidget/main.cpp new file mode 100644 index 0000000000..68f9be7199 --- /dev/null +++ b/tests/manual/qopenglwidget/openglwidget/main.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "openglwidget.h" +#include <QApplication> +#include <QPushButton> +#include <QMdiArea> +#include <QLCDNumber> +#include <QTimer> + + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QMdiArea w; + w.resize(400,400); + + OpenGLWidget *glw = new OpenGLWidget; + w.addSubWindow(glw); + glw->setMinimumSize(100,100); + + OpenGLWidget *glw2 = new OpenGLWidget; + glw2->setMinimumSize(100,100); + w.addSubWindow(glw2); + + QLCDNumber *lcd = new QLCDNumber; + lcd->display(1337); + lcd->setMinimumSize(300,100); + w.addSubWindow(lcd); + + w.show(); + + return a.exec(); +} diff --git a/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp b/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp new file mode 100644 index 0000000000..5752326911 --- /dev/null +++ b/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#define GL_GLEXT_PROTOTYPES + +#include "openglwidget.h" +#include <QtWidgets/private/qwidget_p.h> +#include <QOpenGLFramebufferObject> +#include <QWindow> +#include <qpa/qplatformwindow.h> +#include <QDebug> +#include <QTimer> + +#include <QtGui/QOpenGLFunctions> +#include <QtGui/QGuiApplication> +#include <QtGui/QMatrix4x4> +#include <QtGui/QOpenGLShaderProgram> +#include <QtGui/QScreen> + +#include <QtCore/qmath.h> +#include <qopengl.h> + +class OpenGLWidgetPrivate +{ +public: + OpenGLWidgetPrivate() + : m_program(0), m_frame(0) + { + + } + + void initialize(); + void render(); + + + int width() {return w;} + int height() {return h;} + + GLuint m_posAttr; + GLuint m_colAttr; + GLuint m_matrixUniform; + + QOpenGLShaderProgram *m_program; + int m_frame; + + int w,h; +}; + + +OpenGLWidget::OpenGLWidget(QWidget *parent) + : QOpenGLWidget(parent) +{ + d = new OpenGLWidgetPrivate; + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(updateGL())); + timer->start(30); +} + +OpenGLWidget::~OpenGLWidget() +{ + +} + +void OpenGLWidget::initializeGL() +{ +// qDebug("*initializeGL*"); + d->initialize(); +} + +void OpenGLWidget::resizeGL(int w, int h) +{ +// qDebug("*resizeGL*"); + d->w = w; + d->h = h; +} +void OpenGLWidget::paintGL() +{ +// qDebug("*paintGL* %d", d->m_frame); + d->render(); +} + + +static const char *vertexShaderSource = + "attribute highp vec4 posAttr;\n" + "attribute lowp vec4 colAttr;\n" + "varying lowp vec4 col;\n" + "uniform highp mat4 matrix;\n" + "void main() {\n" + " col = colAttr;\n" + " gl_Position = matrix * posAttr;\n" + "}\n"; + +static const char *fragmentShaderSource = + "varying lowp vec4 col;\n" + "void main() {\n" + " gl_FragColor = col;\n" + "}\n"; + +void OpenGLWidgetPrivate::initialize() +{ + m_program = new QOpenGLShaderProgram; + m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); + m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); + m_program->link(); + m_posAttr = m_program->attributeLocation("posAttr"); + m_colAttr = m_program->attributeLocation("colAttr"); + m_matrixUniform = m_program->uniformLocation("matrix"); +} + +void OpenGLWidgetPrivate::render() +{ + const qreal retinaScale = 1.0;//devicePixelRatio(); + glViewport(0, 0, width() * retinaScale, height() * retinaScale); + + glClearColor(0.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + m_program->bind(); + + QMatrix4x4 matrix; + matrix.perspective(60, 4.0/3.0, 0.1, 100.0); + matrix.translate(0, 0, -2); + matrix.rotate(100.0f * m_frame / 30/*screen()->refreshRate()*/, 0, 1, 0); + + m_program->setUniformValue(m_matrixUniform, matrix); + + GLfloat vertices[] = { + 0.0f, 0.707f, + -0.5f, -0.5f, + 0.5f, -0.5f + }; + + GLfloat colors[] = { + 1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f + }; + + glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices); + glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors); + + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + + glDrawArrays(GL_TRIANGLES, 0, 3); + + glDisableVertexAttribArray(1); + glDisableVertexAttribArray(0); + + m_program->release(); + + ++m_frame; +} diff --git a/tests/manual/qopenglwidget/openglwidget/openglwidget.h b/tests/manual/qopenglwidget/openglwidget/openglwidget.h new file mode 100644 index 0000000000..eaba27df26 --- /dev/null +++ b/tests/manual/qopenglwidget/openglwidget/openglwidget.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef OPENGLWIDGET_H +#define OPENGLWIDGET_H + +#include <QtWidgets/private/qopenglwidget_p.h> + +class OpenGLWidgetPrivate; +class OpenGLWidget : public QOpenGLWidget +{ + Q_OBJECT +public: + OpenGLWidget(QWidget *parent = 0); + ~OpenGLWidget(); + + void initializeGL(); + void resizeGL(int w, int h); + void paintGL(); + +private: + OpenGLWidgetPrivate *d; +}; + +#endif // OPENGLWIDGET_H diff --git a/tests/manual/qopenglwidget/openglwidget/openglwidget.pro b/tests/manual/qopenglwidget/openglwidget/openglwidget.pro new file mode 100644 index 0000000000..63d877e7b0 --- /dev/null +++ b/tests/manual/qopenglwidget/openglwidget/openglwidget.pro @@ -0,0 +1,9 @@ +QT += widgets widgets-private gui-private core-private + +TARGET = openglwidget +TEMPLATE = app + +SOURCES += main.cpp \ + openglwidget.cpp + +HEADERS += openglwidget.h diff --git a/tests/manual/qpainfo/main.cpp b/tests/manual/qpainfo/main.cpp index 0f5119bab3..c51ca6323b 100644 --- a/tests/manual/qpainfo/main.cpp +++ b/tests/manual/qpainfo/main.cpp @@ -116,10 +116,8 @@ int main(int argc, char **argv) QGuiApplication app(argc, argv); const QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration(); - std::cout << "Qt " << QT_VERSION_STR << " on \"" << QGuiApplication::platformName().toStdString() << "\" " - << QSysInfo::WordSize << " bit/" + std::cout << QLibraryInfo::build() << " on \"" << QGuiApplication::platformName().toStdString() << "\" " << (QSysInfo::ByteOrder == QSysInfo::LittleEndian ? "little endian" : "big endian") << '/' - << (QLibraryInfo::isDebugBuild() ? "debug" : "release") << '\n'; #if defined(Q_OS_WIN) @@ -180,7 +178,8 @@ int main(int argc, char **argv) << " startDragVelocity=" << styleHints->startDragVelocity() << " keyboardInputInterval=" << styleHints->keyboardInputInterval() << " keyboardAutoRepeatRate=" << styleHints->keyboardAutoRepeatRate() << " cursorFlashTime=" << styleHints->cursorFlashTime() << " showIsFullScreen=" << styleHints->showIsFullScreen() << " passwordMaskDelay=" << styleHints->passwordMaskDelay() - << " fontSmoothingGamma=" << styleHints->fontSmoothingGamma() << " useRtlExtensions=" << styleHints->useRtlExtensions() << '\n'; + << " fontSmoothingGamma=" << styleHints->fontSmoothingGamma() << " useRtlExtensions=" << styleHints->useRtlExtensions() + << " mousePressAndHoldInterval=" << styleHints->mousePressAndHoldInterval() << '\n'; const QPlatformTheme *platformTheme = QGuiApplicationPrivate::platformTheme(); std::cout << "\nTheme:\n Styles: " << platformTheme->themeHint(QPlatformTheme::StyleNames).toStringList(); diff --git a/tests/manual/qsslsocket/main.cpp b/tests/manual/qsslsocket/main.cpp new file mode 100644 index 0000000000..67726b5897 --- /dev/null +++ b/tests/manual/qsslsocket/main.cpp @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BlackBerry Limited. All rights reserved. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtNetwork/qsslconfiguration.h> +#include <QtNetwork/qsslsocket.h> +#include <QtTest/QtTest> + +#ifndef QT_NO_SSL +Q_DECLARE_METATYPE(QSslConfiguration::NextProtocolNegotiationStatus) +#endif + +class tst_QSslSocket : public QObject +{ + Q_OBJECT + +#ifndef QT_NO_SSL +private slots: + void nextProtocolNegotiation_data(); + void nextProtocolNegotiation(); +#endif // QT_NO_SSL +}; + +#ifndef QT_NO_SSL +void tst_QSslSocket::nextProtocolNegotiation_data() +{ + QTest::addColumn<bool>("setConfiguration"); + QTest::addColumn<QString>("host"); + QTest::addColumn<QList<QByteArray> >("allowedProtocols"); + QTest::addColumn<QByteArray>("expectedProtocol"); + QTest::addColumn<QSslConfiguration::NextProtocolNegotiationStatus>("expectedStatus"); + + QList<QString> hosts = QList<QString>() + << QStringLiteral("www.google.com") + << QStringLiteral("www.facebook.com") + << QStringLiteral("www.twitter.com") + << QStringLiteral("graph.facebook.com") + << QStringLiteral("api.twitter.com"); + + foreach (QString host, hosts) { + QByteArray tag = host.toLocal8Bit(); + tag.append("-none"); + QTest::newRow(tag) + << false + << host + << QList<QByteArray>() + << QByteArray() + << QSslConfiguration::NextProtocolNegotiationNone; + + tag = host.toLocal8Bit(); + tag.append("-none-explicit"); + QTest::newRow(tag) + << true + << host + << QList<QByteArray>() + << QByteArray() + << QSslConfiguration::NextProtocolNegotiationNone; + + tag = host.toLocal8Bit(); + tag.append("-http/1.1"); + QTest::newRow(tag) + << true + << host + << (QList<QByteArray>() << QSslConfiguration::NextProtocolHttp1_1) + << QByteArray(QSslConfiguration::NextProtocolHttp1_1) + << QSslConfiguration::NextProtocolNegotiationNegotiated; + + tag = host.toLocal8Bit(); + tag.append("-spdy/3"); + QTest::newRow(tag) + << true + << host + << (QList<QByteArray>() << QSslConfiguration::NextProtocolSpdy3_0) + << QByteArray(QSslConfiguration::NextProtocolSpdy3_0) + << QSslConfiguration::NextProtocolNegotiationNegotiated; + + tag = host.toLocal8Bit(); + tag.append("-spdy/3-and-http/1.1"); + QTest::newRow(tag) + << true + << host + << (QList<QByteArray>() << QSslConfiguration::NextProtocolSpdy3_0 << QSslConfiguration::NextProtocolHttp1_1) + << QByteArray(QSslConfiguration::NextProtocolSpdy3_0) + << QSslConfiguration::NextProtocolNegotiationNegotiated; + } +} + +void tst_QSslSocket::nextProtocolNegotiation() +{ + if (!QSslSocket::supportsSsl()) + return; + + QSslSocket socket; + + QFETCH(bool, setConfiguration); + + if (setConfiguration) { + QSslConfiguration conf = socket.sslConfiguration(); + QFETCH(QList<QByteArray>, allowedProtocols); + conf.setAllowedNextProtocols(allowedProtocols); + socket.setSslConfiguration(conf); + } + + QFETCH(QString, host); + + socket.connectToHostEncrypted(host, 443); + socket.ignoreSslErrors(); + + QVERIFY(socket.waitForEncrypted(10000)); + + QFETCH(QByteArray, expectedProtocol); + QCOMPARE(socket.sslConfiguration().nextNegotiatedProtocol(), expectedProtocol); + + QFETCH(QSslConfiguration::NextProtocolNegotiationStatus, expectedStatus); + QCOMPARE(socket.sslConfiguration().nextProtocolNegotiationStatus(), expectedStatus); + + socket.disconnectFromHost(); + QVERIFY(socket.waitForDisconnected()); + +} + +#endif // QT_NO_SSL + +QTEST_MAIN(tst_QSslSocket) + +#include "main.moc" diff --git a/tests/manual/qsslsocket/qsslsocket.pro b/tests/manual/qsslsocket/qsslsocket.pro new file mode 100644 index 0000000000..c297d887ba --- /dev/null +++ b/tests/manual/qsslsocket/qsslsocket.pro @@ -0,0 +1,6 @@ +CONFIG += testcase + +SOURCES += main.cpp +QT = core network testlib + +TARGET = tst_qsslsocket diff --git a/tests/manual/windowchildgeometry/controllerwidget.cpp b/tests/manual/windowchildgeometry/controllerwidget.cpp new file mode 100644 index 0000000000..f1cdfbf855 --- /dev/null +++ b/tests/manual/windowchildgeometry/controllerwidget.cpp @@ -0,0 +1,536 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "controllerwidget.h" +#include <controls.h> + +#if QT_VERSION >= 0x050000 +# include <QtWidgets> +# include <QWindow> +# include <QBackingStore> +# include <QPaintDevice> +# include <QPainter> +#else +# include <QtGui> +#endif + +#include <QResizeEvent> + +CoordinateControl::CoordinateControl(const QString &sep) : m_x(new QSpinBox), m_y(new QSpinBox) +{ + m_x->setMinimum(-2000); + m_x->setMaximum(2000); + connect(m_x, SIGNAL(valueChanged(int)), this, SLOT(spinBoxChanged())); + m_y->setMinimum(-2000); + m_y->setMaximum(2000); + connect(m_y, SIGNAL(valueChanged(int)), this, SLOT(spinBoxChanged())); + QHBoxLayout *l = new QHBoxLayout(this); + l->setSpacing(2); + l->addWidget(m_x); + l->addWidget(new QLabel(sep)); + l->addWidget(m_y); +} + +void CoordinateControl::setCoordinates(int x, int y) +{ + m_x->blockSignals(true); + m_y->blockSignals(true); + m_x->setValue(x); + m_y->setValue(y); + m_x->blockSignals(false); + m_y->blockSignals(false); +} + +QPair<int, int> CoordinateControl::coordinates() const +{ + return QPair<int, int>(m_x->value(), m_y->value()); +} + +void CoordinateControl::spinBoxChanged() +{ + const int x = m_x->value(); + const int y = m_y->value(); + emit pointValueChanged(QPoint(x, y)); + emit sizeValueChanged(QSize(x, y)); +} + +RectControl::RectControl() + : m_point(new CoordinateControl(QLatin1String("+"))) + , m_size(new CoordinateControl(QLatin1String("x"))) +{ + QHBoxLayout *l = new QHBoxLayout(this); + l->setSpacing(0); + l->setMargin(ControlLayoutMargin); + connect(m_point, SIGNAL(pointValueChanged(QPoint)), this, SLOT(handleChanged())); + connect(m_point, SIGNAL(pointValueChanged(QPoint)), this, SIGNAL(positionChanged(QPoint))); + l->addWidget(m_point); + l->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored)); + connect(m_size, SIGNAL(sizeValueChanged(QSize)), this, SLOT(handleChanged())); + connect(m_size, SIGNAL(sizeValueChanged(QSize)), this, SIGNAL(sizeChanged(QSize))); + l->addWidget(m_size); +} + +void RectControl::setRectValue(const QRect &r) +{ + m_point->setPointValue(r.topLeft()); + m_size->setSizeValue(r.size()); +} + +QRect RectControl::rectValue() const +{ + return QRect(m_point->pointValue(), m_size->sizeValue()); +} + +void RectControl::handleChanged() +{ + emit changed(rectValue()); +} + +BaseWindowControl::BaseWindowControl(QObject *w) + : m_layout(new QGridLayout(this)) + , m_object(w) + , m_geometry(new RectControl) + , m_framePosition(new CoordinateControl(QLatin1String("x"))) + , m_moveEventLabel(new QLabel(tr("Move events"))) + , m_resizeEventLabel(new QLabel(tr("Resize events"))) + , m_mouseEventLabel(new QLabel(tr("Mouse events"))) + , m_moveCount(0) + , m_resizeCount(0) +{ + m_object->installEventFilter(this); + m_geometry->setTitle(tr("Geometry")); + int row = 0; + m_layout->addWidget(m_geometry, row, 0, 1, 2); + m_layout->setMargin(ControlLayoutMargin); + QGroupBox *frameGB = new QGroupBox(tr("Frame")); + QVBoxLayout *frameL = new QVBoxLayout(frameGB); + frameL->setSpacing(0); + frameL->setMargin(ControlLayoutMargin); + frameL->addWidget(m_framePosition); + m_layout->addWidget(frameGB, row, 2); + + QGroupBox *eventGroupBox = new QGroupBox(tr("Events")); + QVBoxLayout *l = new QVBoxLayout(eventGroupBox); + l->setSpacing(0); + l->setMargin(ControlLayoutMargin); + l->addWidget(m_moveEventLabel); + l->addWidget(m_resizeEventLabel); + l->addWidget(m_mouseEventLabel); + m_layout->addWidget(eventGroupBox, ++row, 2); + + connect(m_geometry, SIGNAL(positionChanged(QPoint)), this, SLOT(posChanged(QPoint))); + connect(m_geometry, SIGNAL(sizeChanged(QSize)), this, SLOT(sizeChanged(QSize))); + connect(m_framePosition, SIGNAL(pointValueChanged(QPoint)), this, SLOT(framePosChanged(QPoint))); +} + +bool BaseWindowControl::eventFilter(QObject *, QEvent *e) +{ + switch (e->type()) { + case QEvent::Resize: { + const QResizeEvent *re = static_cast<const QResizeEvent *>(e); + m_resizeEventLabel->setText(tr("Resize %1x%2 (#%3)") + .arg(re->size().width()).arg(re->size().height()) + .arg(++m_resizeCount)); + refresh(); + } + break; + case QEvent::Move: { + const QMoveEvent *me = static_cast<const QMoveEvent *>(e); + m_moveEventLabel->setText(tr("Move %1,%2 (#%3)") + .arg(me->pos().x()).arg(me->pos().y()) + .arg(++m_moveCount)); + refresh(); + } + break; + case QEvent::MouseMove: { + const QMouseEvent *me = static_cast<const QMouseEvent *>(e); + const QPoint pos = me->pos(); + QPoint globalPos = objectMapToGlobal(m_object, pos); + m_mouseEventLabel->setText(tr("Mouse: %1,%2 Global: %3,%4 "). + arg(pos.x()).arg(pos.y()).arg(globalPos.x()).arg(globalPos.y())); + } + break; + case QEvent::WindowStateChange: + refresh(); + default: + break; + } + return false; +} + +void BaseWindowControl::posChanged(const QPoint &p) +{ + QRect geom = objectGeometry(m_object); + geom.moveTopLeft(p); + setObjectGeometry(m_object, geom); +} + +void BaseWindowControl::sizeChanged(const QSize &s) +{ + QRect geom = objectGeometry(m_object); + geom.setSize(s); + setObjectGeometry(m_object, geom); +} + +void BaseWindowControl::framePosChanged(const QPoint &p) +{ + setObjectFramePosition(m_object, p); +} + +void BaseWindowControl::refresh() +{ + m_geometry->setRectValue(objectGeometry(m_object)); + m_framePosition->setPointValue(objectFramePosition(m_object)); +} + +// A control for a QWidget +class WidgetWindowControl : public BaseWindowControl +{ + Q_OBJECT +public: + explicit WidgetWindowControl(QWidget *w); + + virtual void refresh(); + +private slots: + void statesChanged(); + +private: + virtual QRect objectGeometry(const QObject *o) const + { return static_cast<const QWidget *>(o)->geometry(); } + virtual void setObjectGeometry(QObject *o, const QRect &r) const + { static_cast<QWidget *>(o)->setGeometry(r); } + virtual QPoint objectFramePosition(const QObject *o) const + { return static_cast<const QWidget *>(o)->pos(); } + virtual void setObjectFramePosition(QObject *o, const QPoint &p) const + { static_cast<QWidget *>(o)->move(p); } + virtual QPoint objectMapToGlobal(const QObject *o, const QPoint &p) const + { return static_cast<const QWidget *>(o)->mapToGlobal(p); } + virtual Qt::WindowFlags objectWindowFlags(const QObject *o) const + { return static_cast<const QWidget *>(o)->windowFlags(); } + virtual void setObjectWindowFlags(QObject *o, Qt::WindowFlags f); + + WindowStatesControl *m_statesControl; +}; + +WidgetWindowControl::WidgetWindowControl(QWidget *w ) + : BaseWindowControl(w) + , m_statesControl(new WindowStatesControl(WindowStatesControl::WantVisibleCheckBox | WindowStatesControl::WantActiveCheckBox)) +{ + setTitle(w->windowTitle()); + m_layout->addWidget(m_statesControl, 2, 0); + connect(m_statesControl, SIGNAL(changed()), this, SLOT(statesChanged())); +} + +void WidgetWindowControl::setObjectWindowFlags(QObject *o, Qt::WindowFlags f) +{ + QWidget *w = static_cast<QWidget *>(o); + const bool visible = w->isVisible(); + w->setWindowFlags(f); // hides. + if (visible) + w->show(); +} + +void WidgetWindowControl::refresh() +{ + const QWidget *w = static_cast<const QWidget *>(m_object); + m_statesControl->setVisibleValue(w->isVisible()); + m_statesControl->setStates(w->windowState()); + BaseWindowControl::refresh(); +} + +void WidgetWindowControl::statesChanged() +{ + QWidget *w = static_cast<QWidget *>(m_object); + w->setVisible(m_statesControl->visibleValue()); + w->setWindowState(m_statesControl->states()); +} + +#if QT_VERSION >= 0x050000 + +// Test window drawing diagonal lines +class Window : public QWindow +{ +public: + explicit Window(QWindow *parent = 0) + : QWindow(parent) + , m_backingStore(new QBackingStore(this)) + , m_color(Qt::GlobalColor(qrand() % 18)) + { + setObjectName(QStringLiteral("window")); + setTitle(tr("TestWindow")); + setFlags(flags() | Qt::MacUseNSWindow); + } + +protected: + void mouseMoveEvent(QMouseEvent * ev); + void mousePressEvent(QMouseEvent * ev); + void mouseReleaseEvent(QMouseEvent * e); + void exposeEvent(QExposeEvent *) + { render(); } + +private: + QBackingStore *m_backingStore; + Qt::GlobalColor m_color; + QPoint m_mouseDownPosition; + void render(); +}; + +void Window::mouseMoveEvent(QMouseEvent * ev) +{ + if (m_mouseDownPosition.isNull()) + return; + + QPoint delta = ev->pos() - m_mouseDownPosition; + QPoint newPosition = position() + delta; + setPosition(newPosition); +// qDebug() << "diff" << delta << newPosition; +} + +void Window::mousePressEvent(QMouseEvent * ev) +{ + m_mouseDownPosition = ev->pos(); +} + +void Window::mouseReleaseEvent(QMouseEvent * e) +{ + m_mouseDownPosition = QPoint(); +} + +void Window::render() +{ + QRect rect(QPoint(), geometry().size()); + m_backingStore->resize(rect.size()); + m_backingStore->beginPaint(rect); + if (!rect.size().isEmpty()) { + QPaintDevice *device = m_backingStore->paintDevice(); + QPainter p(device); + p.fillRect(rect, m_color); + p.drawLine(0, 0, rect.width(), rect.height()); + p.drawLine(0, rect.height(), rect.width(), 0); + } + m_backingStore->endPaint(); + m_backingStore->flush(rect); +} + +// A control for a QWindow +class WindowControl : public BaseWindowControl +{ + Q_OBJECT +public: + explicit WindowControl(QWindow *w); + + virtual void refresh(); + +private slots: + void showWindow(); + void hideWindow(); + void raiseWindow(); + void lowerWindow(); + void toggleAttachWindow(); + void addChildWindow(); +private: + virtual QRect objectGeometry(const QObject *o) const + { return static_cast<const QWindow *>(o)->geometry(); } + virtual void setObjectGeometry(QObject *o, const QRect &r) const + { static_cast<QWindow *>(o)->setGeometry(r); } + virtual QPoint objectFramePosition(const QObject *o) const + { return static_cast<const QWindow *>(o)->framePosition(); } + virtual void setObjectFramePosition(QObject *o, const QPoint &p) const + { static_cast<QWindow *>(o)->setFramePosition(p); } + virtual QPoint objectMapToGlobal(const QObject *o, const QPoint &p) const + { return static_cast<const QWindow *>(o)->mapToGlobal(p); } + virtual void setObjectWindowFlags(QObject *o, Qt::WindowFlags f) + { static_cast<QWindow *>(o)->setFlags(f); } + + WindowStateControl *m_stateControl; + QWindow *m_window; + QWindow *m_detachedParent; // set when this window is detached. This is the window we should re-attach to. +}; + +WindowControl::WindowControl(QWindow *w ) + : BaseWindowControl(w) + , m_stateControl(new WindowStateControl(WindowStateControl::WantVisibleCheckBox | WindowStateControl::WantMinimizeRadioButton)) + , m_window(w) + , m_detachedParent(0) +{ + setTitle(w->title()); + + QPushButton *button = new QPushButton("Show Window"); + connect(button, SIGNAL(clicked()), SLOT(showWindow())); + m_layout->addWidget(button, 1, 0); + + button = new QPushButton("hide Window"); + connect(button, SIGNAL(clicked()), SLOT(hideWindow())); + m_layout->addWidget(button, 1, 1); + + button = new QPushButton("Rase Window"); + connect(button, SIGNAL(clicked()), SLOT(raiseWindow())); + m_layout->addWidget(button, 2, 0); + + button = new QPushButton("Lower Window"); + connect(button, SIGNAL(clicked()), SLOT(lowerWindow())); + m_layout->addWidget(button, 2, 1); + + button = new QPushButton("Toggle attach"); + connect(button, SIGNAL(clicked()), SLOT(toggleAttachWindow())); + m_layout->addWidget(button, 3, 0); + + button = new QPushButton("Add Child Window"); + connect(button, SIGNAL(clicked()), SLOT(addChildWindow())); + m_layout->addWidget(button, 3, 1); +} + +void WindowControl::refresh() +{ + const QWindow *w = static_cast<const QWindow *>(m_object); + BaseWindowControl::refresh(); +} + +void WindowControl::showWindow() +{ + m_window->show(); +} + +void WindowControl::hideWindow() +{ + m_window->hide(); +} + +void WindowControl::raiseWindow() +{ + m_window->raise(); +} + +void WindowControl::lowerWindow() +{ + m_window->lower(); +} + +void WindowControl::toggleAttachWindow() +{ + if (m_detachedParent) { + m_window->hide(); + m_window->setParent(m_detachedParent); + m_window->show(); + m_detachedParent = 0; + } else { + m_detachedParent = m_window->parent(); + m_window->hide(); + m_window->setParent(0); + m_window->show(); + } +} + +void WindowControl::addChildWindow() +{ + qDebug() << "WindowControl::addChildWindow"; + Window *childWindow = new Window(m_window); + + QRect childGeometry(50, 50, 40, 40); + childWindow->setGeometry(childGeometry); + WindowControl *control = new WindowControl(childWindow); + control->show(); +} + +#endif + +ControllerWidget::ControllerWidget(QWidget *parent) + : QMainWindow(parent) + , m_testWindow(new Window) +{ + QMenu *fileMenu = menuBar()->addMenu(tr("File")); + QAction *exitAction = fileMenu->addAction(tr("Exit")); + exitAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q)); + connect(exitAction, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); + + QString title = QLatin1String("Child Window Geometry test, (Qt "); + title += QLatin1String(QT_VERSION_STR); + title += QLatin1String(", "); + title += qApp->platformName(); + title += QLatin1Char(')'); + setWindowTitle(title); + + int x = 100; + int y = 100; + const QStringList args = QApplication::arguments(); + const int offsetArgIndex = args.indexOf(QLatin1String("-offset")); + if (offsetArgIndex >=0 && offsetArgIndex < args.size() - 1) { + y += args.at(offsetArgIndex + 1).toInt(); + } else { + if (QT_VERSION < 0x050000) + y += 400; + } + + move(x, y); + + x += 800; + + x += 300; + m_testWindow->setFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint + | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint + | Qt::WindowTitleHint | Qt::WindowFullscreenButtonHint); + m_testWindow->setFramePosition(QPoint(x, y)); + m_testWindow->resize(200, 200); + m_testWindow->setTitle(tr("TestWindow")); + + QWidget *central = new QWidget ; + QVBoxLayout *l = new QVBoxLayout(central); + + const QString labelText = tr( + "<html><head/><body><p>This example lets you control the geometry" + " of QWindows and child QWindows"); + + l->addWidget(new QLabel(labelText)); + + WindowControl *windowControl = new WindowControl(m_testWindow.data()); + l->addWidget(windowControl); + + setCentralWidget(central); +} + +ControllerWidget::~ControllerWidget() +{ + + +} + +#include "controllerwidget.moc" diff --git a/tests/manual/windowchildgeometry/controllerwidget.h b/tests/manual/windowchildgeometry/controllerwidget.h new file mode 100644 index 0000000000..9774ca408c --- /dev/null +++ b/tests/manual/windowchildgeometry/controllerwidget.h @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CONTROLLERWIDGET_H +#define CONTROLLERWIDGET_H + +#include <QMainWindow> +#include <QGroupBox> +#include <QScopedPointer> + +QT_BEGIN_NAMESPACE +class QSpinBox; +class QLabel; +class QGridLayout; +QT_END_NAMESPACE + +class TypeControl; +class HintControl; + +// A control for editing points or sizes +class CoordinateControl : public QWidget +{ + Q_OBJECT + +public: + CoordinateControl(const QString &sep); + + void setPointValue(const QPoint &p) { setCoordinates(p.x(), p.y()); } + QPoint pointValue() const { const QPair<int, int> t = coordinates(); return QPoint(t.first, t.second); } + + void setSizeValue(const QSize &s) { setCoordinates(s.width(), s.height()); } + QSize sizeValue() const { const QPair<int, int> t = coordinates(); return QSize(t.first, t.second); } + +signals: + void pointValueChanged(const QPoint &p); + void sizeValueChanged(const QSize &s); + +private slots: + void spinBoxChanged(); + +private: + void setCoordinates(int x, int y); + QPair<int, int> coordinates() const; + + QSpinBox *m_x; + QSpinBox *m_y; +}; + +// A control for editing QRect +class RectControl : public QGroupBox +{ + Q_OBJECT +public: + RectControl(); + void setRectValue(const QRect &r); + QRect rectValue() const; + +signals: + void changed(const QRect &r); + void sizeChanged(const QSize &s); + void positionChanged(const QPoint &s); + +private slots: + void handleChanged(); + +private: + CoordinateControl *m_point; + CoordinateControl *m_size; +}; + +// Base class for controlling the position of a Window (QWindow or QWidget) +class BaseWindowControl : public QGroupBox +{ + Q_OBJECT + +protected: + explicit BaseWindowControl(QObject *w); + +public: + virtual bool eventFilter(QObject *, QEvent *); + virtual void refresh(); + +private slots: + void posChanged(const QPoint &); + void sizeChanged(const QSize &); + void framePosChanged(const QPoint &); + +protected: + QGridLayout *m_layout; + QObject *m_object; + +private: + virtual QRect objectGeometry(const QObject *o) const = 0; + virtual void setObjectGeometry(QObject *o, const QRect &) const = 0; + + virtual QPoint objectFramePosition(const QObject *o) const = 0; + virtual void setObjectFramePosition(QObject *o, const QPoint &) const = 0; + + virtual QPoint objectMapToGlobal(const QObject *o, const QPoint &) const = 0; + + RectControl *m_geometry; + CoordinateControl *m_framePosition; + QLabel *m_moveEventLabel; + QLabel *m_resizeEventLabel; + QLabel *m_mouseEventLabel; + unsigned m_moveCount; + unsigned m_resizeCount; +}; + +class ControllerWidget : public QMainWindow +{ + Q_OBJECT +public: + explicit ControllerWidget(QWidget *parent = 0); + ~ControllerWidget(); +private: + QScopedPointer<QWindow> m_testWindow; +}; + +#endif // CONTROLLERWIDGET_H diff --git a/tests/manual/windowchildgeometry/main.cpp b/tests/manual/windowchildgeometry/main.cpp new file mode 100644 index 0000000000..42266b777a --- /dev/null +++ b/tests/manual/windowchildgeometry/main.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include "controllerwidget.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ControllerWidget controller; + controller.show(); + return a.exec(); +} diff --git a/tests/manual/windowchildgeometry/windowchildgeometry.pro b/tests/manual/windowchildgeometry/windowchildgeometry.pro new file mode 100644 index 0000000000..921acd8a4e --- /dev/null +++ b/tests/manual/windowchildgeometry/windowchildgeometry.pro @@ -0,0 +1,10 @@ +QT += core gui +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +TARGET = windowchildgeometry +TEMPLATE = app + +INCLUDEPATH += ../windowflags +SOURCES += $$PWD/main.cpp controllerwidget.cpp ../windowflags/controls.cpp +HEADERS += controllerwidget.h ../windowflags/controls.h + +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 |