diff options
Diffstat (limited to 'examples')
25 files changed, 225 insertions, 26 deletions
diff --git a/examples/ipc/ipc.pro b/examples/ipc/ipc.pro index f302b836af..4b4b3870a4 100644 --- a/examples/ipc/ipc.pro +++ b/examples/ipc/ipc.pro @@ -3,4 +3,4 @@ requires(qtHaveModule(widgets)) TEMPLATE = subdirs # no QSharedMemory !vxworks:!qnx:SUBDIRS = sharedmemory -!wince*: SUBDIRS += localfortuneserver localfortuneclient +!wince*:qtHaveModule(network): SUBDIRS += localfortuneserver localfortuneclient diff --git a/examples/network/network.pro b/examples/network/network.pro index 342297528b..be4ccdbddf 100644 --- a/examples/network/network.pro +++ b/examples/network/network.pro @@ -1,3 +1,5 @@ +requires(qtHaveModule(network)) + TEMPLATE = subdirs SUBDIRS = \ dnslookup \ diff --git a/examples/touch/fingerpaint/scribblearea.cpp b/examples/touch/fingerpaint/scribblearea.cpp index f672a3fdd1..0d13e4579d 100644 --- a/examples/touch/fingerpaint/scribblearea.cpp +++ b/examples/touch/fingerpaint/scribblearea.cpp @@ -154,7 +154,7 @@ void ScribbleArea::resizeImage(QImage *image, const QSize &newSize) //! [21] void ScribbleArea::print() { -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) QPrinter printer(QPrinter::HighResolution); QPrintDialog printDialog(&printer, this); diff --git a/examples/widgets/animation/sub-attaq/qanimationstate.h b/examples/widgets/animation/sub-attaq/qanimationstate.h index 9d733c10ee..68eac43e13 100644 --- a/examples/widgets/animation/sub-attaq/qanimationstate.h +++ b/examples/widgets/animation/sub-attaq/qanimationstate.h @@ -50,8 +50,6 @@ # include "qabstractanimation.h" #endif -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -86,6 +84,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QANIMATIONSTATE_H diff --git a/examples/widgets/dialogs/dialogs.pro b/examples/widgets/dialogs/dialogs.pro index c31c37222d..d30c29778f 100644 --- a/examples/widgets/dialogs/dialogs.pro +++ b/examples/widgets/dialogs/dialogs.pro @@ -9,5 +9,6 @@ SUBDIRS = classwizard \ extension \ findfiles +!qtHaveModule(printsupport): SUBDIRS -= licensewizard contains(DEFINES, QT_NO_WIZARD): SUBDIRS -= trivialwizard licensewizard classwizard wince*: SUBDIRS += sipdialog diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.cpp b/examples/widgets/dialogs/licensewizard/licensewizard.cpp index e6bb506494..8f63583a7c 100644 --- a/examples/widgets/dialogs/licensewizard/licensewizard.cpp +++ b/examples/widgets/dialogs/licensewizard/licensewizard.cpp @@ -352,7 +352,7 @@ void ConclusionPage::setVisible(bool visible) void ConclusionPage::printButtonClicked() { -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) QPrinter printer; QPrintDialog dialog(&printer, this); if (dialog.exec()) diff --git a/examples/widgets/doc/src/i18n.qdoc b/examples/widgets/doc/src/i18n.qdoc index 69b458c882..068995fc90 100644 --- a/examples/widgets/doc/src/i18n.qdoc +++ b/examples/widgets/doc/src/i18n.qdoc @@ -32,7 +32,9 @@ \brief The Internationalization (I18N) example demonstrates Qt's support for translated text. Developers can write the initial application text in one language, and - translations can be provided later without any modifications to the code. + translations can be provided later without any modifications to the code. It also + demonstrates how to detect the system language settings and show the UI in the appropriate + language. \image i18n-example.png */ diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp index 4b5b608163..a439c837de 100644 --- a/examples/widgets/graphicsview/chip/view.cpp +++ b/examples/widgets/graphicsview/chip/view.cpp @@ -252,7 +252,7 @@ void View::toggleAntialiasing() void View::print() { -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) QPrinter printer; QPrintDialog dialog(&printer, this); if (dialog.exec() == QDialog::Accepted) { diff --git a/examples/widgets/itemviews/pixelator/mainwindow.cpp b/examples/widgets/itemviews/pixelator/mainwindow.cpp index dec9ee4084..0d34dbf190 100644 --- a/examples/widgets/itemviews/pixelator/mainwindow.cpp +++ b/examples/widgets/itemviews/pixelator/mainwindow.cpp @@ -154,7 +154,7 @@ void MainWindow::openImage(const QString &fileName) void MainWindow::printImage() { -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) if (model->rowCount(QModelIndex())*model->columnCount(QModelIndex()) > 90000) { QMessageBox::StandardButton answer; answer = QMessageBox::question(this, tr("Large Image Size"), diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp index 39dd35e342..59d29f0e61 100644 --- a/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp +++ b/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp @@ -627,7 +627,7 @@ QString encode_pos(int row, int col) void SpreadSheet::print() { -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) QPrinter printer(QPrinter::ScreenResolution); QPrintPreviewDialog dlg(&printer); PrintView view; diff --git a/examples/widgets/painting/fontsampler/mainwindow.cpp b/examples/widgets/painting/fontsampler/mainwindow.cpp index 645a2b1a9a..516ba5e2bc 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.cpp +++ b/examples/widgets/painting/fontsampler/mainwindow.cpp @@ -241,7 +241,7 @@ QMap<QString, StyleItems> MainWindow::currentPageMap() return pageMap; } -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) void MainWindow::on_printAction_triggered() { pageMap = currentPageMap(); diff --git a/examples/widgets/painting/fontsampler/mainwindow.h b/examples/widgets/painting/fontsampler/mainwindow.h index f9e06c8b89..f4ad448480 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.h +++ b/examples/widgets/painting/fontsampler/mainwindow.h @@ -62,12 +62,12 @@ public: public slots: void on_clearAction_triggered(); void on_markAction_triggered(); -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) void on_printAction_triggered(); void on_printPreviewAction_triggered(); #endif void on_unmarkAction_triggered(); -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) void printDocument(QPrinter *printer); void printPage(int index, QPainter *painter, QPrinter *printer); #endif diff --git a/examples/widgets/painting/shared/shared.pri b/examples/widgets/painting/shared/shared.pri index 1b8be82d03..af027e081a 100644 --- a/examples/widgets/painting/shared/shared.pri +++ b/examples/widgets/painting/shared/shared.pri @@ -1,6 +1,6 @@ INCLUDEPATH += $$PWD -qtHaveModule(opengl) { +qtHaveModule(opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2) { DEFINES += QT_OPENGL_SUPPORT QT += opengl widgets } diff --git a/examples/widgets/richtext/orderform/mainwindow.cpp b/examples/widgets/richtext/orderform/mainwindow.cpp index b99dfd86df..7c0aa666fd 100644 --- a/examples/widgets/richtext/orderform/mainwindow.cpp +++ b/examples/widgets/richtext/orderform/mainwindow.cpp @@ -235,7 +235,7 @@ void MainWindow::openDialog() //! [17] void MainWindow::printFile() { -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) QTextEdit *editor = static_cast<QTextEdit*>(letters->currentWidget()); //! [18] QPrinter printer; diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp index 0398493250..c7edd1b550 100644 --- a/examples/widgets/richtext/textedit/textedit.cpp +++ b/examples/widgets/richtext/textedit/textedit.cpp @@ -511,7 +511,7 @@ bool TextEdit::fileSaveAs() void TextEdit::filePrint() { -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) QPrinter printer(QPrinter::HighResolution); QPrintDialog *dlg = new QPrintDialog(&printer, this); if (textEdit->textCursor().hasSelection()) @@ -525,7 +525,7 @@ void TextEdit::filePrint() void TextEdit::filePrintPreview() { -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) QPrinter printer(QPrinter::HighResolution); QPrintPreviewDialog preview(&printer, this); connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(printPreview(QPrinter*))); diff --git a/examples/widgets/tools/i18n/languagechooser.cpp b/examples/widgets/tools/i18n/languagechooser.cpp index 14c66a079b..15cc906fb8 100644 --- a/examples/widgets/tools/i18n/languagechooser.cpp +++ b/examples/widgets/tools/i18n/languagechooser.cpp @@ -49,7 +49,7 @@ extern void qt_mac_set_menubar_merge(bool merge); QT_END_NAMESPACE #endif -LanguageChooser::LanguageChooser(QWidget *parent) +LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent) : QDialog(parent, Qt::WindowStaysOnTopHint) { groupBox = new QGroupBox("Languages"); @@ -61,6 +61,8 @@ LanguageChooser::LanguageChooser(QWidget *parent) QCheckBox *checkBox = new QCheckBox(languageName(qmFiles[i])); qmFileForCheckBoxMap.insert(checkBox, qmFiles[i]); connect(checkBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled())); + if (languageMatch(defaultLang, qmFiles[i])) + checkBox->setCheckState(Qt::Checked); groupBoxLayout->addWidget(checkBox, i / 2, i % 2); } groupBox->setLayout(groupBoxLayout); @@ -87,6 +89,14 @@ LanguageChooser::LanguageChooser(QWidget *parent) setWindowTitle("I18N"); } +bool LanguageChooser::languageMatch(const QString& lang, const QString& qmFile) +{ + //qmFile: i18n_xx.qm + const QString prefix = "i18n_"; + const int langTokenLength = 2; /*FIXME: is checking two chars enough?*/ + return qmFile.midRef(qmFile.indexOf(prefix) + prefix.length(), langTokenLength) == lang.leftRef(langTokenLength); +} + bool LanguageChooser::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::Close) { diff --git a/examples/widgets/tools/i18n/languagechooser.h b/examples/widgets/tools/i18n/languagechooser.h index 13a7c3570a..a2282cdaf5 100644 --- a/examples/widgets/tools/i18n/languagechooser.h +++ b/examples/widgets/tools/i18n/languagechooser.h @@ -58,7 +58,7 @@ class LanguageChooser : public QDialog Q_OBJECT public: - LanguageChooser(QWidget *parent = 0); + explicit LanguageChooser(const QString& defaultLang = QString(), QWidget *parent = 0); protected: bool eventFilter(QObject *object, QEvent *event); @@ -73,6 +73,7 @@ private: QStringList findQmFiles(); QString languageName(const QString &qmFile); QColor colorForLanguage(const QString &language); + static bool languageMatch(const QString& lang, const QString& qmFile); QGroupBox *groupBox; QDialogButtonBox *buttonBox; diff --git a/examples/widgets/tools/i18n/main.cpp b/examples/widgets/tools/i18n/main.cpp index 9d78876460..59e3081c03 100644 --- a/examples/widgets/tools/i18n/main.cpp +++ b/examples/widgets/tools/i18n/main.cpp @@ -39,7 +39,7 @@ ****************************************************************************/ #include <QApplication> - +#include <QLocale> #include "languagechooser.h" #include "mainwindow.h" @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(i18n); QApplication app(argc, argv); - LanguageChooser chooser; + LanguageChooser chooser(QLocale::system().name()); chooser.show(); return app.exec(); } diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro index 768b602e61..726494ffd6 100644 --- a/examples/widgets/widgets.pro +++ b/examples/widgets/widgets.pro @@ -19,7 +19,8 @@ SUBDIRS = \ statemachine \ tools \ tutorials \ - widgets + widgets \ + windowcontainer contains(DEFINES, QT_NO_CURSOR): SUBDIRS -= mainwindows contains(DEFINES, QT_NO_DRAGANDDROP): SUBDIRS -= draganddrop diff --git a/examples/widgets/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp index ef200bc15f..77ec92d57a 100644 --- a/examples/widgets/widgets/imageviewer/imageviewer.cpp +++ b/examples/widgets/widgets/imageviewer/imageviewer.cpp @@ -99,7 +99,7 @@ void ImageViewer::print() //! [5] //! [6] { Q_ASSERT(imageLabel->pixmap()); -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) //! [6] //! [7] QPrintDialog dialog(&printer, this); //! [7] //! [8] diff --git a/examples/widgets/widgets/lineedits/window.cpp b/examples/widgets/widgets/lineedits/window.cpp index 0749e8d4fd..a0871e7c77 100644 --- a/examples/widgets/widgets/lineedits/window.cpp +++ b/examples/widgets/widgets/lineedits/window.cpp @@ -55,6 +55,7 @@ Window::Window() echoComboBox->addItem(tr("No Echo")); echoLineEdit = new QLineEdit; + echoLineEdit->setPlaceholderText("Placeholder Text"); echoLineEdit->setFocus(); //! [0] @@ -68,6 +69,7 @@ Window::Window() validatorComboBox->addItem(tr("Double validator")); validatorLineEdit = new QLineEdit; + validatorLineEdit->setPlaceholderText("Placeholder Text"); //! [1] //! [2] @@ -80,6 +82,7 @@ Window::Window() alignmentComboBox->addItem(tr("Right")); alignmentLineEdit = new QLineEdit; + alignmentLineEdit->setPlaceholderText("Placeholder Text"); //! [2] //! [3] @@ -93,6 +96,7 @@ Window::Window() inputMaskComboBox->addItem(tr("License key")); inputMaskLineEdit = new QLineEdit; + inputMaskLineEdit->setPlaceholderText("Placeholder Text"); //! [3] //! [4] @@ -104,6 +108,7 @@ Window::Window() accessComboBox->addItem(tr("True")); accessLineEdit = new QLineEdit; + accessLineEdit->setPlaceholderText("Placeholder Text"); //! [4] //! [5] diff --git a/examples/widgets/widgets/scribble/scribblearea.cpp b/examples/widgets/widgets/scribble/scribblearea.cpp index 2492476d38..24e2b2b159 100644 --- a/examples/widgets/widgets/scribble/scribblearea.cpp +++ b/examples/widgets/widgets/scribble/scribblearea.cpp @@ -200,7 +200,7 @@ void ScribbleArea::resizeImage(QImage *image, const QSize &newSize) //! [21] void ScribbleArea::print() { -#ifndef QT_NO_PRINTER +#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) QPrinter printer(QPrinter::HighResolution); QPrintDialog printDialog(&printer, this); diff --git a/examples/widgets/windowcontainer/windowcontainer.cpp b/examples/widgets/windowcontainer/windowcontainer.cpp new file mode 100644 index 0000000000..42523a53d0 --- /dev/null +++ b/examples/widgets/windowcontainer/windowcontainer.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "openglwindow.h" + +#include <QPainter> +#include <QMouseEvent> +#include <QKeyEvent> +#include <QFocusEvent> + +#include <QApplication> +#include <QWidget> +#include <QHBoxLayout> +#include <QLineEdit> + + + +// Making use of the class from the opengl example in gui. +class Window : public OpenGLWindow +{ + Q_OBJECT +public: + Window() + : m_mouseDown(false) + , m_focus(false) + { + } + + void render(QPainter *p) { + QLinearGradient g(0, 0, 0, height()); + g.setColorAt(0, QColor("lightsteelblue")); + g.setColorAt(1, Qt::black); + p->fillRect(0, 0, width(), height(), g); + + p->setPen(Qt::white); + + p->drawText(20, 30, QLatin1String("This is an OpenGL based QWindow")); + + if (m_key.trimmed().length() > 0) { + QRect bounds = p->boundingRect(QRect(0, 0, width(), height()), Qt::AlignTop | Qt::AlignLeft, m_key); + p->save(); + p->translate(width() / 2.0, height() / 2.0); + p->scale(10, 10); + p->translate(-bounds.width() / 2.0, -bounds.height() / 2.0); + p->drawText(bounds, Qt::AlignCenter, m_key); + p->restore(); + } + + if (m_focus) { + p->drawText(20, height() - 20, QLatin1String("Window has focus!")); + } + + p->setRenderHint(QPainter::Antialiasing); + p->drawPolyline(m_polygon); + } + + void mousePressEvent(QMouseEvent *e) { + m_mouseDown = true; + m_polygon.clear(); + m_polygon.append(e->pos()); + renderLater(); + } + + void mouseMoveEvent(QMouseEvent *e) { + if (m_mouseDown) { + m_polygon.append(e->pos()); + renderLater(); + } + } + + void mouseReleaseEvent(QMouseEvent *e) { + m_mouseDown = false; + m_polygon.append(e->pos()); + renderLater(); + } + + void focusInEvent(QFocusEvent *) { + m_focus = true; + renderLater(); + } + + void focusOutEvent(QFocusEvent *) { + m_focus = false; + m_polygon.clear(); + renderLater(); + } + + void keyPressEvent(QKeyEvent *e) { + m_key = e->text(); + renderLater(); + } + + void keyReleaseEvent(QKeyEvent *) { + m_key = QString(); + renderLater(); + } +private: + QPolygon m_polygon; + bool m_mouseDown; + + bool m_focus; + + QString m_key; +}; + + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QWidget *widget = new QWidget; + QHBoxLayout *layout = new QHBoxLayout(widget); + + Window *window = new Window(); + + QWidget *container = QWidget::createWindowContainer(window); + container->setMinimumSize(300, 300); + container->setMaximumSize(600, 600); + container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + container->setFocusPolicy(Qt::StrongFocus); + + window->setGeometry(100, 100, 300, 200); + + layout->addWidget(new QLineEdit(QLatin1String("A QLineEdit"))); + layout->addWidget(container); + layout->addWidget(new QLineEdit(QLatin1String("A QLabel"))); + + widget->show(); + + return app.exec(); +} + +#include "windowcontainer.moc" diff --git a/examples/widgets/windowcontainer/windowcontainer.pro b/examples/widgets/windowcontainer/windowcontainer.pro new file mode 100644 index 0000000000..9ac7e4a5ab --- /dev/null +++ b/examples/widgets/windowcontainer/windowcontainer.pro @@ -0,0 +1,9 @@ +SOURCES = windowcontainer.cpp + +QT += widgets + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/windowcontainer +INSTALLS += target + +include(../../gui/openglwindow/openglwindow.pri) diff --git a/examples/xml/xml.pro b/examples/xml/xml.pro index bc8686a475..72bf95b2ea 100644 --- a/examples/xml/xml.pro +++ b/examples/xml/xml.pro @@ -4,7 +4,9 @@ SUBDIRS = htmlinfo \ qtHaveModule(widgets) { SUBDIRS += dombookmarks \ - rsslisting \ saxbookmarks \ streambookmarks + + qtHaveModule(network): SUBDIRS += \ + rsslisting } |