From 806dda08d685bc5f9ed71dfe8b61f21848d48066 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 17 Aug 2012 13:23:19 +0200 Subject: Moving .qdoc files under examples/widgets/doc Updated those .qdoc files to refer to the new relative examples emplacement. Images and snippets to be moved later. Also grouped all widgets related examples under widgets. Change-Id: Ib29696e2d8948524537f53e8dda88f9ee26a597f Reviewed-by: J-P Nurmi --- examples/widgets/widgets/icons/iconpreviewarea.cpp | 141 +++++++ examples/widgets/widgets/icons/iconpreviewarea.h | 77 ++++ examples/widgets/widgets/icons/icons.desktop | 11 + examples/widgets/widgets/icons/icons.pro | 29 ++ examples/widgets/widgets/icons/iconsizespinbox.cpp | 70 ++++ examples/widgets/widgets/icons/iconsizespinbox.h | 59 +++ examples/widgets/widgets/icons/imagedelegate.cpp | 105 +++++ examples/widgets/widgets/icons/imagedelegate.h | 68 ++++ examples/widgets/widgets/icons/images/designer.png | Bin 0 -> 4205 bytes .../widgets/widgets/icons/images/find_disabled.png | Bin 0 -> 501 bytes .../widgets/widgets/icons/images/find_normal.png | Bin 0 -> 838 bytes .../widgets/icons/images/monkey_off_128x128.png | Bin 0 -> 7045 bytes .../widgets/icons/images/monkey_off_16x16.png | Bin 0 -> 683 bytes .../widgets/icons/images/monkey_off_32x32.png | Bin 0 -> 1609 bytes .../widgets/icons/images/monkey_off_64x64.png | Bin 0 -> 3533 bytes .../widgets/icons/images/monkey_on_128x128.png | Bin 0 -> 6909 bytes .../widgets/icons/images/monkey_on_16x16.png | Bin 0 -> 681 bytes .../widgets/icons/images/monkey_on_32x32.png | Bin 0 -> 1577 bytes .../widgets/icons/images/monkey_on_64x64.png | Bin 0 -> 3479 bytes .../widgets/icons/images/qt_extended_16x16.png | Bin 0 -> 834 bytes .../widgets/icons/images/qt_extended_32x32.png | Bin 0 -> 1892 bytes .../widgets/icons/images/qt_extended_48x48.png | Bin 0 -> 3672 bytes examples/widgets/widgets/icons/main.cpp | 51 +++ examples/widgets/widgets/icons/mainwindow.cpp | 442 +++++++++++++++++++++ examples/widgets/widgets/icons/mainwindow.h | 116 ++++++ 25 files changed, 1169 insertions(+) create mode 100644 examples/widgets/widgets/icons/iconpreviewarea.cpp create mode 100644 examples/widgets/widgets/icons/iconpreviewarea.h create mode 100644 examples/widgets/widgets/icons/icons.desktop create mode 100644 examples/widgets/widgets/icons/icons.pro create mode 100644 examples/widgets/widgets/icons/iconsizespinbox.cpp create mode 100644 examples/widgets/widgets/icons/iconsizespinbox.h create mode 100644 examples/widgets/widgets/icons/imagedelegate.cpp create mode 100644 examples/widgets/widgets/icons/imagedelegate.h create mode 100644 examples/widgets/widgets/icons/images/designer.png create mode 100644 examples/widgets/widgets/icons/images/find_disabled.png create mode 100644 examples/widgets/widgets/icons/images/find_normal.png create mode 100644 examples/widgets/widgets/icons/images/monkey_off_128x128.png create mode 100644 examples/widgets/widgets/icons/images/monkey_off_16x16.png create mode 100644 examples/widgets/widgets/icons/images/monkey_off_32x32.png create mode 100644 examples/widgets/widgets/icons/images/monkey_off_64x64.png create mode 100644 examples/widgets/widgets/icons/images/monkey_on_128x128.png create mode 100644 examples/widgets/widgets/icons/images/monkey_on_16x16.png create mode 100644 examples/widgets/widgets/icons/images/monkey_on_32x32.png create mode 100644 examples/widgets/widgets/icons/images/monkey_on_64x64.png create mode 100644 examples/widgets/widgets/icons/images/qt_extended_16x16.png create mode 100644 examples/widgets/widgets/icons/images/qt_extended_32x32.png create mode 100644 examples/widgets/widgets/icons/images/qt_extended_48x48.png create mode 100644 examples/widgets/widgets/icons/main.cpp create mode 100644 examples/widgets/widgets/icons/mainwindow.cpp create mode 100644 examples/widgets/widgets/icons/mainwindow.h (limited to 'examples/widgets/widgets/icons') diff --git a/examples/widgets/widgets/icons/iconpreviewarea.cpp b/examples/widgets/widgets/icons/iconpreviewarea.cpp new file mode 100644 index 0000000000..53391c7f4f --- /dev/null +++ b/examples/widgets/widgets/icons/iconpreviewarea.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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 + +#include "iconpreviewarea.h" + +//! [0] +IconPreviewArea::IconPreviewArea(QWidget *parent) + : QWidget(parent) +{ + QGridLayout *mainLayout = new QGridLayout; + setLayout(mainLayout); + + stateLabels[0] = createHeaderLabel(tr("Off")); + stateLabels[1] = createHeaderLabel(tr("On")); + Q_ASSERT(NumStates == 2); + + modeLabels[0] = createHeaderLabel(tr("Normal")); + modeLabels[1] = createHeaderLabel(tr("Active")); + modeLabels[2] = createHeaderLabel(tr("Disabled")); + modeLabels[3] = createHeaderLabel(tr("Selected")); + Q_ASSERT(NumModes == 4); + + for (int j = 0; j < NumStates; ++j) + mainLayout->addWidget(stateLabels[j], j + 1, 0); + + for (int i = 0; i < NumModes; ++i) { + mainLayout->addWidget(modeLabels[i], 0, i + 1); + + for (int j = 0; j < NumStates; ++j) { + pixmapLabels[i][j] = createPixmapLabel(); + mainLayout->addWidget(pixmapLabels[i][j], j + 1, i + 1); + } + } +} +//! [0] + +//! [1] +void IconPreviewArea::setIcon(const QIcon &icon) +{ + this->icon = icon; + updatePixmapLabels(); +} +//! [1] + +//! [2] +void IconPreviewArea::setSize(const QSize &size) +{ + if (size != this->size) { + this->size = size; + updatePixmapLabels(); + } +} +//! [2] + +//! [3] +QLabel *IconPreviewArea::createHeaderLabel(const QString &text) +{ + QLabel *label = new QLabel(tr("%1").arg(text)); + label->setAlignment(Qt::AlignCenter); + return label; +} +//! [3] + +//! [4] +QLabel *IconPreviewArea::createPixmapLabel() +{ + QLabel *label = new QLabel; + label->setEnabled(false); + label->setAlignment(Qt::AlignCenter); + label->setFrameShape(QFrame::Box); + label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + label->setBackgroundRole(QPalette::Base); + label->setAutoFillBackground(true); + label->setMinimumSize(132, 132); + return label; +} +//! [4] + +//! [5] +void IconPreviewArea::updatePixmapLabels() +{ + for (int i = 0; i < NumModes; ++i) { + QIcon::Mode mode; + if (i == 0) { + mode = QIcon::Normal; + } else if (i == 1) { + mode = QIcon::Active; + } else if (i == 2) { + mode = QIcon::Disabled; + } else { + mode = QIcon::Selected; + } + + for (int j = 0; j < NumStates; ++j) { + QIcon::State state = (j == 0) ? QIcon::Off : QIcon::On; + QPixmap pixmap = icon.pixmap(size, mode, state); + pixmapLabels[i][j]->setPixmap(pixmap); + pixmapLabels[i][j]->setEnabled(!pixmap.isNull()); + } + } +} +//! [5] diff --git a/examples/widgets/widgets/icons/iconpreviewarea.h b/examples/widgets/widgets/icons/iconpreviewarea.h new file mode 100644 index 0000000000..4c6bc92dbc --- /dev/null +++ b/examples/widgets/widgets/icons/iconpreviewarea.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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$ +** +****************************************************************************/ + +#ifndef ICONPREVIEWAREA_H +#define ICONPREVIEWAREA_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QLabel; +QT_END_NAMESPACE + +//! [0] +class IconPreviewArea : public QWidget +{ + Q_OBJECT + +public: + IconPreviewArea(QWidget *parent = 0); + + void setIcon(const QIcon &icon); + void setSize(const QSize &size); + +private: + QLabel *createHeaderLabel(const QString &text); + QLabel *createPixmapLabel(); + void updatePixmapLabels(); + + enum { NumModes = 4, NumStates = 2 }; + + QIcon icon; + QSize size; + QLabel *stateLabels[NumStates]; + QLabel *modeLabels[NumModes]; + QLabel *pixmapLabels[NumModes][NumStates]; +}; +//! [0] + +#endif diff --git a/examples/widgets/widgets/icons/icons.desktop b/examples/widgets/widgets/icons/icons.desktop new file mode 100644 index 0000000000..df90cc5e6f --- /dev/null +++ b/examples/widgets/widgets/icons/icons.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Icons +Exec=/opt/usr/bin/icons +Icon=icons +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/widgets/icons/icons.pro b/examples/widgets/widgets/icons/icons.pro new file mode 100644 index 0000000000..8b0831117c --- /dev/null +++ b/examples/widgets/widgets/icons/icons.pro @@ -0,0 +1,29 @@ +HEADERS = iconpreviewarea.h \ + iconsizespinbox.h \ + imagedelegate.h \ + mainwindow.h +SOURCES = iconpreviewarea.cpp \ + iconsizespinbox.cpp \ + imagedelegate.cpp \ + main.cpp \ + mainwindow.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/icons +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS icons.pro images +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/icons +INSTALLS += target sources + + +wince*: { + imageFiles.files = images/* + wincewm*: { + imageFiles.path = "/My Documents/My Pictures" + } else { + imageFiles.path = images + } + DEPLOYMENT += imageFiles +} +QT += widgets + +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/widgets/widgets/icons/iconsizespinbox.cpp b/examples/widgets/widgets/icons/iconsizespinbox.cpp new file mode 100644 index 0000000000..bc3609ccb3 --- /dev/null +++ b/examples/widgets/widgets/icons/iconsizespinbox.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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 + +#include "iconsizespinbox.h" + +//! [0] +IconSizeSpinBox::IconSizeSpinBox(QWidget *parent) + : QSpinBox(parent) +{ +} +//! [0] + +//! [1] +int IconSizeSpinBox::valueFromText(const QString &text) const +{ + QRegExp regExp(tr("(\\d+)(\\s*[xx]\\s*\\d+)?")); + + if (regExp.exactMatch(text)) { + return regExp.cap(1).toInt(); + } else { + return 0; + } +} +//! [1] + +//! [2] +QString IconSizeSpinBox::textFromValue(int value) const +{ + return tr("%1 x %1").arg(value); +} +//! [2] diff --git a/examples/widgets/widgets/icons/iconsizespinbox.h b/examples/widgets/widgets/icons/iconsizespinbox.h new file mode 100644 index 0000000000..c163c0f597 --- /dev/null +++ b/examples/widgets/widgets/icons/iconsizespinbox.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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$ +** +****************************************************************************/ + +#ifndef ICONSIZESPINBOX_H +#define ICONSIZESPINBOX_H + +#include + +//! [0] +class IconSizeSpinBox : public QSpinBox +{ + Q_OBJECT + +public: + IconSizeSpinBox(QWidget *parent = 0); + + int valueFromText(const QString &text) const; + QString textFromValue(int value) const; +}; +//! [0] + +#endif diff --git a/examples/widgets/widgets/icons/imagedelegate.cpp b/examples/widgets/widgets/icons/imagedelegate.cpp new file mode 100644 index 0000000000..b801fc2171 --- /dev/null +++ b/examples/widgets/widgets/icons/imagedelegate.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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 + +#include "imagedelegate.h" + +//! [0] +ImageDelegate::ImageDelegate(QObject *parent) + : QItemDelegate(parent) +{ +} +//! [0] + +//! [1] +QWidget *ImageDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem & /* option */, + const QModelIndex &index) const +{ + QComboBox *comboBox = new QComboBox(parent); + if (index.column() == 1) { + comboBox->addItem(tr("Normal")); + comboBox->addItem(tr("Active")); + comboBox->addItem(tr("Disabled")); + comboBox->addItem(tr("Selected")); + } else if (index.column() == 2) { + comboBox->addItem(tr("Off")); + comboBox->addItem(tr("On")); + } + + connect(comboBox, SIGNAL(activated(int)), this, SLOT(emitCommitData())); + + return comboBox; +} +//! [1] + +//! [2] +void ImageDelegate::setEditorData(QWidget *editor, + const QModelIndex &index) const +{ + QComboBox *comboBox = qobject_cast(editor); + if (!comboBox) + return; + + int pos = comboBox->findText(index.model()->data(index).toString(), + Qt::MatchExactly); + comboBox->setCurrentIndex(pos); +} +//! [2] + +//! [3] +void ImageDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + QComboBox *comboBox = qobject_cast(editor); + if (!comboBox) + return; + + model->setData(index, comboBox->currentText()); +} +//! [3] + +//! [4] +void ImageDelegate::emitCommitData() +{ + emit commitData(qobject_cast(sender())); +} +//! [4] diff --git a/examples/widgets/widgets/icons/imagedelegate.h b/examples/widgets/widgets/icons/imagedelegate.h new file mode 100644 index 0000000000..a07dc4b9ad --- /dev/null +++ b/examples/widgets/widgets/icons/imagedelegate.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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$ +** +****************************************************************************/ + +#ifndef IMAGEDELEGATE_H +#define IMAGEDELEGATE_H + +#include + +//! [0] +class ImageDelegate : public QItemDelegate +{ + Q_OBJECT + +public: + ImageDelegate(QObject *parent = 0); +//! [0] + +//! [1] + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + +//! [1] //! [2] +private slots: + void emitCommitData(); +}; +//! [2] + +#endif diff --git a/examples/widgets/widgets/icons/images/designer.png b/examples/widgets/widgets/icons/images/designer.png new file mode 100644 index 0000000000..0988fcee3f Binary files /dev/null and b/examples/widgets/widgets/icons/images/designer.png differ diff --git a/examples/widgets/widgets/icons/images/find_disabled.png b/examples/widgets/widgets/icons/images/find_disabled.png new file mode 100644 index 0000000000..e85e33fe05 Binary files /dev/null and b/examples/widgets/widgets/icons/images/find_disabled.png differ diff --git a/examples/widgets/widgets/icons/images/find_normal.png b/examples/widgets/widgets/icons/images/find_normal.png new file mode 100644 index 0000000000..728c27f905 Binary files /dev/null and b/examples/widgets/widgets/icons/images/find_normal.png differ diff --git a/examples/widgets/widgets/icons/images/monkey_off_128x128.png b/examples/widgets/widgets/icons/images/monkey_off_128x128.png new file mode 100644 index 0000000000..f878267287 Binary files /dev/null and b/examples/widgets/widgets/icons/images/monkey_off_128x128.png differ diff --git a/examples/widgets/widgets/icons/images/monkey_off_16x16.png b/examples/widgets/widgets/icons/images/monkey_off_16x16.png new file mode 100644 index 0000000000..0ac57d7d4f Binary files /dev/null and b/examples/widgets/widgets/icons/images/monkey_off_16x16.png differ diff --git a/examples/widgets/widgets/icons/images/monkey_off_32x32.png b/examples/widgets/widgets/icons/images/monkey_off_32x32.png new file mode 100644 index 0000000000..1f7fab694c Binary files /dev/null and b/examples/widgets/widgets/icons/images/monkey_off_32x32.png differ diff --git a/examples/widgets/widgets/icons/images/monkey_off_64x64.png b/examples/widgets/widgets/icons/images/monkey_off_64x64.png new file mode 100644 index 0000000000..47d8f6de35 Binary files /dev/null and b/examples/widgets/widgets/icons/images/monkey_off_64x64.png differ diff --git a/examples/widgets/widgets/icons/images/monkey_on_128x128.png b/examples/widgets/widgets/icons/images/monkey_on_128x128.png new file mode 100644 index 0000000000..8e1c7468bf Binary files /dev/null and b/examples/widgets/widgets/icons/images/monkey_on_128x128.png differ diff --git a/examples/widgets/widgets/icons/images/monkey_on_16x16.png b/examples/widgets/widgets/icons/images/monkey_on_16x16.png new file mode 100644 index 0000000000..082e8527f1 Binary files /dev/null and b/examples/widgets/widgets/icons/images/monkey_on_16x16.png differ diff --git a/examples/widgets/widgets/icons/images/monkey_on_32x32.png b/examples/widgets/widgets/icons/images/monkey_on_32x32.png new file mode 100644 index 0000000000..bf9acc6cae Binary files /dev/null and b/examples/widgets/widgets/icons/images/monkey_on_32x32.png differ diff --git a/examples/widgets/widgets/icons/images/monkey_on_64x64.png b/examples/widgets/widgets/icons/images/monkey_on_64x64.png new file mode 100644 index 0000000000..990f604d98 Binary files /dev/null and b/examples/widgets/widgets/icons/images/monkey_on_64x64.png differ diff --git a/examples/widgets/widgets/icons/images/qt_extended_16x16.png b/examples/widgets/widgets/icons/images/qt_extended_16x16.png new file mode 100644 index 0000000000..95d3bae838 Binary files /dev/null and b/examples/widgets/widgets/icons/images/qt_extended_16x16.png differ diff --git a/examples/widgets/widgets/icons/images/qt_extended_32x32.png b/examples/widgets/widgets/icons/images/qt_extended_32x32.png new file mode 100644 index 0000000000..7b7a790c12 Binary files /dev/null and b/examples/widgets/widgets/icons/images/qt_extended_32x32.png differ diff --git a/examples/widgets/widgets/icons/images/qt_extended_48x48.png b/examples/widgets/widgets/icons/images/qt_extended_48x48.png new file mode 100644 index 0000000000..8434dc26db Binary files /dev/null and b/examples/widgets/widgets/icons/images/qt_extended_48x48.png differ diff --git a/examples/widgets/widgets/icons/main.cpp b/examples/widgets/widgets/icons/main.cpp new file mode 100644 index 0000000000..e96d256e9b --- /dev/null +++ b/examples/widgets/widgets/icons/main.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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 + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow mainWin; + mainWin.show(); + return app.exec(); +} diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp new file mode 100644 index 0000000000..00f5a21854 --- /dev/null +++ b/examples/widgets/widgets/icons/mainwindow.cpp @@ -0,0 +1,442 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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 + +#include "iconpreviewarea.h" +#include "iconsizespinbox.h" +#include "imagedelegate.h" +#include "mainwindow.h" + +//! [0] +MainWindow::MainWindow() +{ + centralWidget = new QWidget; + setCentralWidget(centralWidget); + + createPreviewGroupBox(); + createImagesGroupBox(); + createIconSizeGroupBox(); + + createActions(); + createMenus(); + createContextMenu(); + + QGridLayout *mainLayout = new QGridLayout; + mainLayout->addWidget(previewGroupBox, 0, 0, 1, 2); + mainLayout->addWidget(imagesGroupBox, 1, 0); + mainLayout->addWidget(iconSizeGroupBox, 1, 1); + centralWidget->setLayout(mainLayout); + + setWindowTitle(tr("Icons")); + checkCurrentStyle(); + otherRadioButton->click(); + + resize(minimumSizeHint()); +} +//! [0] + +//! [1] +void MainWindow::about() +{ + QMessageBox::about(this, tr("About Icons"), + tr("The Icons example illustrates how Qt renders an icon in " + "different modes (active, normal, disabled, and selected) and " + "states (on and off) based on a set of images.")); +} +//! [1] + +//! [2] +void MainWindow::changeStyle(bool checked) +{ + if (!checked) + return; + + QAction *action = qobject_cast(sender()); +//! [2] //! [3] + QStyle *style = QStyleFactory::create(action->data().toString()); +//! [3] //! [4] + Q_ASSERT(style); + QApplication::setStyle(style); + + smallRadioButton->setText(tr("Small (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_SmallIconSize))); + largeRadioButton->setText(tr("Large (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_LargeIconSize))); + toolBarRadioButton->setText(tr("Toolbars (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_ToolBarIconSize))); + listViewRadioButton->setText(tr("List views (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_ListViewIconSize))); + iconViewRadioButton->setText(tr("Icon views (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_IconViewIconSize))); + tabBarRadioButton->setText(tr("Tab bars (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_TabBarIconSize))); + + changeSize(); +} +//! [4] + +//! [5] +void MainWindow::changeSize(bool checked) +{ + if (!checked) + return; + + int extent; + + if (otherRadioButton->isChecked()) { + extent = otherSpinBox->value(); + } else { + QStyle::PixelMetric metric; + + if (smallRadioButton->isChecked()) { + metric = QStyle::PM_SmallIconSize; + } else if (largeRadioButton->isChecked()) { + metric = QStyle::PM_LargeIconSize; + } else if (toolBarRadioButton->isChecked()) { + metric = QStyle::PM_ToolBarIconSize; + } else if (listViewRadioButton->isChecked()) { + metric = QStyle::PM_ListViewIconSize; + } else if (iconViewRadioButton->isChecked()) { + metric = QStyle::PM_IconViewIconSize; + } else { + metric = QStyle::PM_TabBarIconSize; + } + extent = QApplication::style()->pixelMetric(metric); + } + previewArea->setSize(QSize(extent, extent)); + otherSpinBox->setEnabled(otherRadioButton->isChecked()); +} +//! [5] + +//! [6] +void MainWindow::changeIcon() +{ + QIcon icon; + + for (int row = 0; row < imagesTable->rowCount(); ++row) { + QTableWidgetItem *item0 = imagesTable->item(row, 0); + QTableWidgetItem *item1 = imagesTable->item(row, 1); + QTableWidgetItem *item2 = imagesTable->item(row, 2); + + if (item0->checkState() == Qt::Checked) { + QIcon::Mode mode; + if (item1->text() == tr("Normal")) { + mode = QIcon::Normal; + } else if (item1->text() == tr("Active")) { + mode = QIcon::Active; + } else if (item1->text() == tr("Disabled")) { + mode = QIcon::Disabled; + } else { + mode = QIcon::Selected; + } + + QIcon::State state; + if (item2->text() == tr("On")) { + state = QIcon::On; + } else { + state = QIcon::Off; +//! [6] //! [7] + } +//! [7] + +//! [8] + QString fileName = item0->data(Qt::UserRole).toString(); + QImage image(fileName); + if (!image.isNull()) + icon.addPixmap(QPixmap::fromImage(image), mode, state); +//! [8] //! [9] + } +//! [9] //! [10] + } +//! [10] + +//! [11] + previewArea->setIcon(icon); +} +//! [11] + +//! [12] +void MainWindow::addImages() +{ + QStringList fileNames = QFileDialog::getOpenFileNames(this, + tr("Open Images"), "", + tr("Images (*.png *.xpm *.jpg);;" + "All Files (*)")); + if (!fileNames.isEmpty()) { + foreach (QString fileName, fileNames) { + int row = imagesTable->rowCount(); + imagesTable->setRowCount(row + 1); +//! [12] + +//! [13] + QString imageName = QFileInfo(fileName).baseName(); +//! [13] //! [14] + QTableWidgetItem *item0 = new QTableWidgetItem(imageName); + item0->setData(Qt::UserRole, fileName); + item0->setFlags(item0->flags() & ~Qt::ItemIsEditable); +//! [14] + +//! [15] + QTableWidgetItem *item1 = new QTableWidgetItem(tr("Normal")); +//! [15] //! [16] + QTableWidgetItem *item2 = new QTableWidgetItem(tr("Off")); + + if (guessModeStateAct->isChecked()) { + if (fileName.contains("_act")) { + item1->setText(tr("Active")); + } else if (fileName.contains("_dis")) { + item1->setText(tr("Disabled")); + } else if (fileName.contains("_sel")) { + item1->setText(tr("Selected")); + } + + if (fileName.contains("_on")) + item2->setText(tr("On")); +//! [16] //! [17] + } +//! [17] + +//! [18] + imagesTable->setItem(row, 0, item0); +//! [18] //! [19] + imagesTable->setItem(row, 1, item1); + imagesTable->setItem(row, 2, item2); + imagesTable->openPersistentEditor(item1); + imagesTable->openPersistentEditor(item2); + + item0->setCheckState(Qt::Checked); + } + } +} +//! [19] + +//! [20] +void MainWindow::removeAllImages() +{ + imagesTable->setRowCount(0); + changeIcon(); +} +//! [20] + +void MainWindow::createPreviewGroupBox() +{ + previewGroupBox = new QGroupBox(tr("Preview")); + + previewArea = new IconPreviewArea; + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(previewArea); + previewGroupBox->setLayout(layout); +} + +//! [21] +void MainWindow::createImagesGroupBox() +{ + imagesGroupBox = new QGroupBox(tr("Images")); + + imagesTable = new QTableWidget; + imagesTable->setSelectionMode(QAbstractItemView::NoSelection); + imagesTable->setItemDelegate(new ImageDelegate(this)); +//! [21] + +//! [22] + QStringList labels; +//! [22] //! [23] + labels << tr("Image") << tr("Mode") << tr("State"); + + imagesTable->horizontalHeader()->setDefaultSectionSize(90); + imagesTable->setColumnCount(3); + imagesTable->setHorizontalHeaderLabels(labels); + imagesTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + imagesTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed); + imagesTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed); + imagesTable->verticalHeader()->hide(); +//! [23] + +//! [24] + connect(imagesTable, SIGNAL(itemChanged(QTableWidgetItem*)), +//! [24] //! [25] + this, SLOT(changeIcon())); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(imagesTable); + imagesGroupBox->setLayout(layout); +} +//! [25] + +//! [26] +void MainWindow::createIconSizeGroupBox() +{ + iconSizeGroupBox = new QGroupBox(tr("Icon Size")); + + smallRadioButton = new QRadioButton; + largeRadioButton = new QRadioButton; + toolBarRadioButton = new QRadioButton; + listViewRadioButton = new QRadioButton; + iconViewRadioButton = new QRadioButton; + tabBarRadioButton = new QRadioButton; + otherRadioButton = new QRadioButton(tr("Other:")); + + otherSpinBox = new IconSizeSpinBox; + otherSpinBox->setRange(8, 128); + otherSpinBox->setValue(64); +//! [26] + +//! [27] + connect(smallRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(largeRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(toolBarRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(listViewRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(iconViewRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(tabBarRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(otherRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(otherSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeSize())); + + QHBoxLayout *otherSizeLayout = new QHBoxLayout; + otherSizeLayout->addWidget(otherRadioButton); + otherSizeLayout->addWidget(otherSpinBox); + otherSizeLayout->addStretch(); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(smallRadioButton, 0, 0); + layout->addWidget(largeRadioButton, 1, 0); + layout->addWidget(toolBarRadioButton, 2, 0); + layout->addWidget(listViewRadioButton, 0, 1); + layout->addWidget(iconViewRadioButton, 1, 1); + layout->addWidget(tabBarRadioButton, 2, 1); + layout->addLayout(otherSizeLayout, 3, 0, 1, 2); + layout->setRowStretch(4, 1); + iconSizeGroupBox->setLayout(layout); +} +//! [27] + +//! [28] +void MainWindow::createActions() +{ + addImagesAct = new QAction(tr("&Add Images..."), this); + addImagesAct->setShortcut(tr("Ctrl+A")); + connect(addImagesAct, SIGNAL(triggered()), this, SLOT(addImages())); + + removeAllImagesAct = new QAction(tr("&Remove All Images"), this); + removeAllImagesAct->setShortcut(tr("Ctrl+R")); + connect(removeAllImagesAct, SIGNAL(triggered()), + this, SLOT(removeAllImages())); + + exitAct = new QAction(tr("&Quit"), this); + exitAct->setShortcuts(QKeySequence::Quit); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + styleActionGroup = new QActionGroup(this); + foreach (QString styleName, QStyleFactory::keys()) { + QAction *action = new QAction(styleActionGroup); + action->setText(tr("%1 Style").arg(styleName)); + action->setData(styleName); + action->setCheckable(true); + connect(action, SIGNAL(triggered(bool)), this, SLOT(changeStyle(bool))); + } + + guessModeStateAct = new QAction(tr("&Guess Image Mode/State"), this); + guessModeStateAct->setCheckable(true); + guessModeStateAct->setChecked(true); + + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} +//! [28] + +//! [29] +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(addImagesAct); + fileMenu->addAction(removeAllImagesAct); + fileMenu->addSeparator(); + fileMenu->addAction(exitAct); + + viewMenu = menuBar()->addMenu(tr("&View")); + foreach (QAction *action, styleActionGroup->actions()) + viewMenu->addAction(action); + viewMenu->addSeparator(); + viewMenu->addAction(guessModeStateAct); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); +} +//! [29] + +//! [30] +void MainWindow::createContextMenu() +{ + imagesTable->setContextMenuPolicy(Qt::ActionsContextMenu); + imagesTable->addAction(addImagesAct); + imagesTable->addAction(removeAllImagesAct); +} +//! [30] + +//! [31] +void MainWindow::checkCurrentStyle() +{ + foreach (QAction *action, styleActionGroup->actions()) { + QString styleName = action->data().toString(); + QStyle *candidate = QStyleFactory::create(styleName); + Q_ASSERT(candidate); + if (candidate->metaObject()->className() + == QApplication::style()->metaObject()->className()) { + action->trigger(); + return; + } + delete candidate; + } +} +//! [31] diff --git a/examples/widgets/widgets/icons/mainwindow.h b/examples/widgets/widgets/icons/mainwindow.h new file mode 100644 index 0000000000..8afaf9496e --- /dev/null +++ b/examples/widgets/widgets/icons/mainwindow.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QAction; +class QActionGroup; +class QGroupBox; +class QMenu; +class QRadioButton; +class QTableWidget; +QT_END_NAMESPACE +class IconPreviewArea; +class IconSizeSpinBox; + +//! [0] +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private slots: + void about(); + void changeStyle(bool checked); + void changeSize(bool checked = true); + void changeIcon(); + void addImages(); + void removeAllImages(); + +private: + void createPreviewGroupBox(); + void createImagesGroupBox(); + void createIconSizeGroupBox(); + void createActions(); + void createMenus(); + void createContextMenu(); + void checkCurrentStyle(); + + QWidget *centralWidget; + + QGroupBox *previewGroupBox; + IconPreviewArea *previewArea; + + QGroupBox *imagesGroupBox; + QTableWidget *imagesTable; + + QGroupBox *iconSizeGroupBox; + QRadioButton *smallRadioButton; + QRadioButton *largeRadioButton; + QRadioButton *toolBarRadioButton; + QRadioButton *listViewRadioButton; + QRadioButton *iconViewRadioButton; + QRadioButton *tabBarRadioButton; + QRadioButton *otherRadioButton; + IconSizeSpinBox *otherSpinBox; + + QMenu *fileMenu; + QMenu *viewMenu; + QMenu *helpMenu; + QAction *addImagesAct; + QAction *removeAllImagesAct; + QAction *exitAct; + QAction *guessModeStateAct; + QActionGroup *styleActionGroup; + QAction *aboutAct; + QAction *aboutQtAct; +}; +//! [0] + +#endif -- cgit v1.2.3