diff options
Diffstat (limited to 'examples/widgets/widgets/icons')
26 files changed, 0 insertions, 1452 deletions
diff --git a/examples/widgets/widgets/icons/.prev_CMakeLists.txt b/examples/widgets/widgets/icons/.prev_CMakeLists.txt deleted file mode 100644 index ff25b3eaef..0000000000 --- a/examples/widgets/widgets/icons/.prev_CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# Generated from icons.pro. - -cmake_minimum_required(VERSION 3.14) -project(icons LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/icons") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(icons - iconpreviewarea.cpp iconpreviewarea.h - iconsizespinbox.cpp iconsizespinbox.h - imagedelegate.cpp imagedelegate.h - main.cpp - mainwindow.cpp mainwindow.h -) -set_target_properties(icons PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_compile_definitions(icons PUBLIC - SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/\\\" -) - -target_link_libraries(icons PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets -) - -install(TARGETS icons - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/widgets/icons/CMakeLists.txt b/examples/widgets/widgets/icons/CMakeLists.txt deleted file mode 100644 index e14272e777..0000000000 --- a/examples/widgets/widgets/icons/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# Generated from icons.pro. - -cmake_minimum_required(VERSION 3.14) -project(icons LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/icons") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(icons - iconpreviewarea.cpp iconpreviewarea.h - iconsizespinbox.cpp iconsizespinbox.h - imagedelegate.cpp imagedelegate.h - main.cpp - mainwindow.cpp mainwindow.h -) -set_target_properties(icons PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_compile_definitions(icons PUBLIC - SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}" # special case -) - -target_link_libraries(icons PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets -) - -install(TARGETS icons - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/widgets/icons/iconpreviewarea.cpp b/examples/widgets/widgets/icons/iconpreviewarea.cpp deleted file mode 100644 index d0ee50fbb1..0000000000 --- a/examples/widgets/widgets/icons/iconpreviewarea.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 "iconpreviewarea.h" - -#include <QGridLayout> -#include <QLabel> - -//! [0] -IconPreviewArea::IconPreviewArea(QWidget *parent) - : QWidget(parent) -{ - QGridLayout *mainLayout = new QGridLayout(this); - - for (int row = 0; row < NumStates; ++row) { - stateLabels[row] = createHeaderLabel(IconPreviewArea::iconStateNames().at(row)); - mainLayout->addWidget(stateLabels[row], row + 1, 0); - } - Q_ASSERT(NumStates == 2); - - for (int column = 0; column < NumModes; ++column) { - modeLabels[column] = createHeaderLabel(IconPreviewArea::iconModeNames().at(column)); - mainLayout->addWidget(modeLabels[column], 0, column + 1); - } - Q_ASSERT(NumModes == 4); - - for (int column = 0; column < NumModes; ++column) { - for (int row = 0; row < NumStates; ++row) { - pixmapLabels[column][row] = createPixmapLabel(); - mainLayout->addWidget(pixmapLabels[column][row], row + 1, column + 1); - } - } -} -//! [0] - -//! [42] -QList<QIcon::Mode> IconPreviewArea::iconModes() -{ - static const QList<QIcon::Mode> result = { QIcon::Normal, QIcon::Active, QIcon::Disabled, - QIcon::Selected }; - return result; -} - -QList<QIcon::State> IconPreviewArea::iconStates() -{ - static const QList<QIcon::State> result = { QIcon::Off, QIcon::On }; - return result; -} - -QStringList IconPreviewArea::iconModeNames() -{ - static const QStringList result = {tr("Normal"), tr("Active"), tr("Disabled"), tr("Selected")}; - return result; -} - -QStringList IconPreviewArea::iconStateNames() -{ - static const QStringList result = {tr("Off"), tr("On")}; - return result; -} -//! [42] - -//! [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("<b>%1</b>").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() -{ - QWindow *window = nullptr; - if (const QWidget *nativeParent = nativeParentWidget()) - window = nativeParent->windowHandle(); - for (int column = 0; column < NumModes; ++column) { - for (int row = 0; row < NumStates; ++row) { - const QPixmap pixmap = - icon.pixmap(window, size, IconPreviewArea::iconModes().at(column), - IconPreviewArea::iconStates().at(row)); - QLabel *pixmapLabel = pixmapLabels[column][row]; - pixmapLabel->setPixmap(pixmap); - pixmapLabel->setEnabled(!pixmap.isNull()); - QString toolTip; - if (!pixmap.isNull()) { - const QSize actualSize = icon.actualSize(size); - toolTip = - tr("Size: %1x%2\nActual size: %3x%4\nDevice pixel ratio: %5") - .arg(size.width()).arg(size.height()) - .arg(actualSize.width()).arg(actualSize.height()) - .arg(pixmap.devicePixelRatio()); - } - pixmapLabel->setToolTip(toolTip); - } - } -} -//! [5] diff --git a/examples/widgets/widgets/icons/iconpreviewarea.h b/examples/widgets/widgets/icons/iconpreviewarea.h deleted file mode 100644 index 5387cb9f6d..0000000000 --- a/examples/widgets/widgets/icons/iconpreviewarea.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 <QIcon> -#include <QWidget> -#include <QStringList> -#include <QList> - -QT_BEGIN_NAMESPACE -class QLabel; -QT_END_NAMESPACE - -//! [0] -class IconPreviewArea : public QWidget -{ - Q_OBJECT - -public: - explicit IconPreviewArea(QWidget *parent = nullptr); - - void setIcon(const QIcon &icon); - void setSize(const QSize &size); - - static QList<QIcon::Mode> iconModes(); - static QList<QIcon::State> iconStates(); - static QStringList iconModeNames(); - static QStringList iconStateNames(); - -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.pro b/examples/widgets/widgets/icons/icons.pro deleted file mode 100644 index 243ce6b092..0000000000 --- a/examples/widgets/widgets/icons/icons.pro +++ /dev/null @@ -1,20 +0,0 @@ -QT += widgets -requires(qtConfig(combobox)) - -HEADERS = iconpreviewarea.h \ - iconsizespinbox.h \ - imagedelegate.h \ - mainwindow.h -SOURCES = iconpreviewarea.cpp \ - iconsizespinbox.cpp \ - imagedelegate.cpp \ - main.cpp \ - mainwindow.cpp - -DEFINES += SRCDIR=\\\"$$PWD/\\\" - -EXAMPLE_FILES = images/* - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/icons -INSTALLS += target diff --git a/examples/widgets/widgets/icons/iconsizespinbox.cpp b/examples/widgets/widgets/icons/iconsizespinbox.cpp deleted file mode 100644 index 8e6c654686..0000000000 --- a/examples/widgets/widgets/icons/iconsizespinbox.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 "iconsizespinbox.h" - -#include <QRegularExpression> - -//! [0] -IconSizeSpinBox::IconSizeSpinBox(QWidget *parent) - : QSpinBox(parent) -{ -} -//! [0] - -//! [1] -int IconSizeSpinBox::valueFromText(const QString &text) const -{ - static const QRegularExpression regExp(tr("(\\d+)(\\s*[xx]\\s*\\d+)?")); - Q_ASSERT(regExp.isValid()); - - const QRegularExpressionMatch match = regExp.match(text); - if (match.isValid()) - return match.captured(1).toInt(); - 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 deleted file mode 100644 index 87415ac5d6..0000000000 --- a/examples/widgets/widgets/icons/iconsizespinbox.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 <QSpinBox> - -//! [0] -class IconSizeSpinBox : public QSpinBox -{ - Q_OBJECT - -public: - explicit IconSizeSpinBox(QWidget *parent = nullptr); - - int valueFromText(const QString &text) const override; - QString textFromValue(int value) const override; -}; -//! [0] - -#endif diff --git a/examples/widgets/widgets/icons/imagedelegate.cpp b/examples/widgets/widgets/icons/imagedelegate.cpp deleted file mode 100644 index 9f1e19c9eb..0000000000 --- a/examples/widgets/widgets/icons/imagedelegate.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 "imagedelegate.h" -#include "iconpreviewarea.h" - -#include <QComboBox> - -//! [0] -ImageDelegate::ImageDelegate(QObject *parent) - : QStyledItemDelegate(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->addItems(IconPreviewArea::iconModeNames()); - else if (index.column() == 2) - comboBox->addItems(IconPreviewArea::iconStateNames()); - - connect(comboBox, &QComboBox::activated, - this, &ImageDelegate::emitCommitData); - - return comboBox; -} -//! [1] - -//! [2] -void ImageDelegate::setEditorData(QWidget *editor, - const QModelIndex &index) const -{ - QComboBox *comboBox = qobject_cast<QComboBox *>(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<QComboBox *>(editor); - if (!comboBox) - return; - - model->setData(index, comboBox->currentText()); -} -//! [3] - -//! [4] -void ImageDelegate::emitCommitData() -{ - emit commitData(qobject_cast<QWidget *>(sender())); -} -//! [4] diff --git a/examples/widgets/widgets/icons/imagedelegate.h b/examples/widgets/widgets/icons/imagedelegate.h deleted file mode 100644 index 9d65304e2c..0000000000 --- a/examples/widgets/widgets/icons/imagedelegate.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 <QStyledItemDelegate> - -//! [0] -class ImageDelegate : public QStyledItemDelegate -{ - Q_OBJECT - -public: - explicit ImageDelegate(QObject *parent = nullptr); -//! [0] - -//! [1] - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const override; - void setEditorData(QWidget *editor, const QModelIndex &index) const override; - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const override; - -//! [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 Binary files differdeleted file mode 100644 index 9f8578b49e..0000000000 --- a/examples/widgets/widgets/icons/images/designer.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/find_disabled.png b/examples/widgets/widgets/icons/images/find_disabled.png Binary files differdeleted file mode 100644 index e85e33fe05..0000000000 --- a/examples/widgets/widgets/icons/images/find_disabled.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/find_normal.png b/examples/widgets/widgets/icons/images/find_normal.png Binary files differdeleted file mode 100644 index 728c27f905..0000000000 --- a/examples/widgets/widgets/icons/images/find_normal.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/monkey_off_128x128.png b/examples/widgets/widgets/icons/images/monkey_off_128x128.png Binary files differdeleted file mode 100644 index f878267287..0000000000 --- a/examples/widgets/widgets/icons/images/monkey_off_128x128.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/monkey_off_16x16.png b/examples/widgets/widgets/icons/images/monkey_off_16x16.png Binary files differdeleted file mode 100644 index 0ac57d7d4f..0000000000 --- a/examples/widgets/widgets/icons/images/monkey_off_16x16.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/monkey_off_32x32.png b/examples/widgets/widgets/icons/images/monkey_off_32x32.png Binary files differdeleted file mode 100644 index 1f7fab694c..0000000000 --- a/examples/widgets/widgets/icons/images/monkey_off_32x32.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/monkey_off_64x64.png b/examples/widgets/widgets/icons/images/monkey_off_64x64.png Binary files differdeleted file mode 100644 index 47d8f6de35..0000000000 --- a/examples/widgets/widgets/icons/images/monkey_off_64x64.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/monkey_on_128x128.png b/examples/widgets/widgets/icons/images/monkey_on_128x128.png Binary files differdeleted file mode 100644 index 8e1c7468bf..0000000000 --- a/examples/widgets/widgets/icons/images/monkey_on_128x128.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/monkey_on_16x16.png b/examples/widgets/widgets/icons/images/monkey_on_16x16.png Binary files differdeleted file mode 100644 index 082e8527f1..0000000000 --- a/examples/widgets/widgets/icons/images/monkey_on_16x16.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/monkey_on_32x32.png b/examples/widgets/widgets/icons/images/monkey_on_32x32.png Binary files differdeleted file mode 100644 index bf9acc6cae..0000000000 --- a/examples/widgets/widgets/icons/images/monkey_on_32x32.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/monkey_on_64x64.png b/examples/widgets/widgets/icons/images/monkey_on_64x64.png Binary files differdeleted file mode 100644 index 990f604d98..0000000000 --- a/examples/widgets/widgets/icons/images/monkey_on_64x64.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/qt_extended_16x16.png b/examples/widgets/widgets/icons/images/qt_extended_16x16.png Binary files differdeleted file mode 100644 index 30bcb45ed2..0000000000 --- a/examples/widgets/widgets/icons/images/qt_extended_16x16.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/qt_extended_32x32.png b/examples/widgets/widgets/icons/images/qt_extended_32x32.png Binary files differdeleted file mode 100644 index d609c1e1e5..0000000000 --- a/examples/widgets/widgets/icons/images/qt_extended_32x32.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/images/qt_extended_48x48.png b/examples/widgets/widgets/icons/images/qt_extended_48x48.png Binary files differdeleted file mode 100644 index 0e524fed5f..0000000000 --- a/examples/widgets/widgets/icons/images/qt_extended_48x48.png +++ /dev/null diff --git a/examples/widgets/widgets/icons/main.cpp b/examples/widgets/widgets/icons/main.cpp deleted file mode 100644 index aff2d2013e..0000000000 --- a/examples/widgets/widgets/icons/main.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 <QApplication> -#include <QCommandLineParser> -#include <QScreen> - -#include "mainwindow.h" - -//! [45] -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - QCoreApplication::setApplicationName(MainWindow::tr("Icons")); - QCoreApplication::setApplicationVersion(QT_VERSION_STR); - QCommandLineParser commandLineParser; - commandLineParser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); - commandLineParser.addHelpOption(); - commandLineParser.addVersionOption(); - commandLineParser.addPositionalArgument(MainWindow::tr("[file]"), MainWindow::tr("Icon file(s) to open.")); - commandLineParser.process(QCoreApplication::arguments()); - - MainWindow mainWin; - if (!commandLineParser.positionalArguments().isEmpty()) - mainWin.loadImages(commandLineParser.positionalArguments()); - - const QRect availableGeometry = mainWin.screen()->availableGeometry(); - mainWin.resize(availableGeometry.width() / 2, availableGeometry.height() * 2 / 3); - mainWin.move((availableGeometry.width() - mainWin.width()) / 2, (availableGeometry.height() - mainWin.height()) / 2); - - mainWin.show(); - return app.exec(); -} -//! [45] diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp deleted file mode 100644 index 7280ba9a42..0000000000 --- a/examples/widgets/widgets/icons/mainwindow.cpp +++ /dev/null @@ -1,525 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 "mainwindow.h" -#include "iconpreviewarea.h" -#include "iconsizespinbox.h" -#include "imagedelegate.h" - -#include <QActionGroup> -#include <QApplication> -#include <QButtonGroup> -#include <QCheckBox> -#include <QFileDialog> -#include <QHeaderView> -#include <QFormLayout> -#include <QGridLayout> -#include <QGroupBox> -#include <QImageReader> -#include <QLabel> -#include <QMenuBar> -#include <QMessageBox> -#include <QRadioButton> -#include <QScreen> -#include <QStandardPaths> -#include <QStyleFactory> -#include <QTableWidget> -#include <QWindow> - -//! [40] -enum { OtherSize = QStyle::PM_CustomBase }; -//! [40] - -//! [0] -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) -{ - QWidget *centralWidget = new QWidget(this); - setCentralWidget(centralWidget); - - createActions(); - - QGridLayout *mainLayout = new QGridLayout(centralWidget); - - QGroupBox *previewGroupBox = new QGroupBox(tr("Preview")); - previewArea = new IconPreviewArea(previewGroupBox); - QVBoxLayout *previewLayout = new QVBoxLayout(previewGroupBox); - previewLayout->addWidget(previewArea); - - mainLayout->addWidget(previewGroupBox, 0, 0, 1, 2); - mainLayout->addWidget(createImagesGroupBox(), 1, 0); - QVBoxLayout *vBox = new QVBoxLayout; - vBox->addWidget(createIconSizeGroupBox()); - vBox->addWidget(createHighDpiIconSizeGroupBox()); - vBox->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); - mainLayout->addLayout(vBox, 1, 1); - createContextMenu(); - - setWindowTitle(tr("Icons")); - checkCurrentStyle(); - sizeButtonGroup->button(OtherSize)->click(); -} -//! [0] - -//! [44] -void MainWindow::show() -{ - QMainWindow::show(); - connect(windowHandle(), &QWindow::screenChanged, this, &MainWindow::screenChanged); - screenChanged(); -} -//! [44] - -//! [1] -void MainWindow::about() -{ - QMessageBox::about(this, tr("About Icons"), - tr("The <b>Icons</b> 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; - - const QAction *action = qobject_cast<QAction *>(sender()); -//! [2] //! [3] - QStyle *style = QStyleFactory::create(action->data().toString()); -//! [3] //! [4] - Q_ASSERT(style); - QApplication::setStyle(style); - - const QList<QAbstractButton*> buttons = sizeButtonGroup->buttons(); - for (QAbstractButton *button : buttons) { - const QStyle::PixelMetric metric = static_cast<QStyle::PixelMetric>(sizeButtonGroup->id(button)); - const int value = style->pixelMetric(metric); - switch (metric) { - case QStyle::PM_SmallIconSize: - button->setText(tr("Small (%1 x %1)").arg(value)); - break; - case QStyle::PM_LargeIconSize: - button->setText(tr("Large (%1 x %1)").arg(value)); - break; - case QStyle::PM_ToolBarIconSize: - button->setText(tr("Toolbars (%1 x %1)").arg(value)); - break; - case QStyle::PM_ListViewIconSize: - button->setText(tr("List views (%1 x %1)").arg(value)); - break; - case QStyle::PM_IconViewIconSize: - button->setText(tr("Icon views (%1 x %1)").arg(value)); - break; - case QStyle::PM_TabBarIconSize: - button->setText(tr("Tab bars (%1 x %1)").arg(value)); - break; - default: - break; - } - } - - triggerChangeSize(); -} -//! [4] - -//! [5] -void MainWindow::changeSize(QAbstractButton *button, bool checked) -{ - if (!checked) - return; - - const int index = sizeButtonGroup->id(button); - const bool other = index == int(OtherSize); - const int extent = other - ? otherSpinBox->value() - : QApplication::style()->pixelMetric(static_cast<QStyle::PixelMetric>(index)); - - previewArea->setSize(QSize(extent, extent)); - otherSpinBox->setEnabled(other); -} - -void MainWindow::triggerChangeSize() -{ - changeSize(sizeButtonGroup->checkedButton(), true); -} -//! [5] - -//! [6] -void MainWindow::changeIcon() -{ - QIcon icon; - - for (int row = 0; row < imagesTable->rowCount(); ++row) { - const QTableWidgetItem *fileItem = imagesTable->item(row, 0); - const QTableWidgetItem *modeItem = imagesTable->item(row, 1); - const QTableWidgetItem *stateItem = imagesTable->item(row, 2); - - if (fileItem->checkState() == Qt::Checked) { - const int modeIndex = IconPreviewArea::iconModeNames().indexOf(modeItem->text()); - Q_ASSERT(modeIndex >= 0); - const int stateIndex = IconPreviewArea::iconStateNames().indexOf(stateItem->text()); - Q_ASSERT(stateIndex >= 0); - const QIcon::Mode mode = IconPreviewArea::iconModes().at(modeIndex); - const QIcon::State state = IconPreviewArea::iconStates().at(stateIndex); -//! [6] - -//! [8] - const QString fileName = fileItem->data(Qt::UserRole).toString(); - QImage image(fileName); - if (!image.isNull()) - icon.addPixmap(QPixmap::fromImage(image), mode, state); -//! [8] - } - } -//! [11] - previewArea->setIcon(icon); -//! [11] -} - -void MainWindow::addSampleImages() -{ - addImages(QLatin1String(SRCDIR) + QLatin1String("/images")); -} - -void MainWindow::addOtherImages() -{ - static bool firstInvocation = true; - QString directory; - if (firstInvocation) { - firstInvocation = false; - directory = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QString()); - } - addImages(directory); -} - -//! [12] -void MainWindow::addImages(const QString &directory) -{ - QFileDialog fileDialog(this, tr("Open Images"), directory); - QStringList mimeTypeFilters; - const QList<QByteArray> mimeTypes = QImageReader::supportedMimeTypes(); - for (const QByteArray &mimeTypeName : mimeTypes) - mimeTypeFilters.append(mimeTypeName); - mimeTypeFilters.sort(); - fileDialog.setMimeTypeFilters(mimeTypeFilters); - fileDialog.selectMimeTypeFilter(QLatin1String("image/png")); - fileDialog.setAcceptMode(QFileDialog::AcceptOpen); - fileDialog.setFileMode(QFileDialog::ExistingFiles); - if (!nativeFileDialogAct->isChecked()) - fileDialog.setOption(QFileDialog::DontUseNativeDialog); - if (fileDialog.exec() == QDialog::Accepted) - loadImages(fileDialog.selectedFiles()); -//! [12] -} - -void MainWindow::loadImages(const QStringList &fileNames) -{ - for (const QString &fileName : fileNames) { - const int row = imagesTable->rowCount(); - imagesTable->setRowCount(row + 1); -//! [13] - const QFileInfo fileInfo(fileName); - const QString imageName = fileInfo.baseName(); - const QString fileName2x = fileInfo.absolutePath() - + QLatin1Char('/') + imageName + QLatin1String("@2x.") + fileInfo.suffix(); - const QFileInfo fileInfo2x(fileName2x); - const QImage image(fileName); - const QString toolTip = - tr("Directory: %1\nFile: %2\nFile@2x: %3\nSize: %4x%5") - .arg(QDir::toNativeSeparators(fileInfo.absolutePath()), fileInfo.fileName()) - .arg(fileInfo2x.exists() ? fileInfo2x.fileName() : tr("<None>")) - .arg(image.width()).arg(image.height()); - QTableWidgetItem *fileItem = new QTableWidgetItem(imageName); - fileItem->setData(Qt::UserRole, fileName); - fileItem->setIcon(QPixmap::fromImage(image)); - fileItem->setFlags((fileItem->flags() | Qt::ItemIsUserCheckable) & ~Qt::ItemIsEditable); - fileItem->setToolTip(toolTip); -//! [13] - -//! [15] - QIcon::Mode mode = QIcon::Normal; - QIcon::State state = QIcon::Off; - if (guessModeStateAct->isChecked()) { - if (imageName.contains(QLatin1String("_act"), Qt::CaseInsensitive)) - mode = QIcon::Active; - else if (imageName.contains(QLatin1String("_dis"), Qt::CaseInsensitive)) - mode = QIcon::Disabled; - else if (imageName.contains(QLatin1String("_sel"), Qt::CaseInsensitive)) - mode = QIcon::Selected; - - if (imageName.contains(QLatin1String("_on"), Qt::CaseInsensitive)) - state = QIcon::On; -//! [15] - } - -//! [18] - imagesTable->setItem(row, 0, fileItem); - QTableWidgetItem *modeItem = - new QTableWidgetItem(IconPreviewArea::iconModeNames().at(IconPreviewArea::iconModes().indexOf(mode))); - modeItem->setToolTip(toolTip); - imagesTable->setItem(row, 1, modeItem); - QTableWidgetItem *stateItem = - new QTableWidgetItem(IconPreviewArea::iconStateNames().at(IconPreviewArea::iconStates().indexOf(state))); - stateItem->setToolTip(toolTip); - imagesTable->setItem(row, 2, stateItem); - imagesTable->openPersistentEditor(modeItem); - imagesTable->openPersistentEditor(stateItem); - - fileItem->setCheckState(Qt::Checked); -//! [18] - } -} - -//! [20] -void MainWindow::removeAllImages() -{ - imagesTable->setRowCount(0); - changeIcon(); -} -//! [20] - -//! [21] -QWidget *MainWindow::createImagesGroupBox() -{ - QGroupBox *imagesGroupBox = new QGroupBox(tr("Images")); - - imagesTable = new QTableWidget; - imagesTable->setSelectionMode(QAbstractItemView::NoSelection); - imagesTable->setItemDelegate(new ImageDelegate(this)); -//! [21] - -//! [22] - const QStringList 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(); -//! [22] - -//! [24] - connect(imagesTable, &QTableWidget::itemChanged, - this, &MainWindow::changeIcon); - - QVBoxLayout *layout = new QVBoxLayout(imagesGroupBox); - layout->addWidget(imagesTable); - return imagesGroupBox; -//! [24] -} - -//! [26] -QWidget *MainWindow::createIconSizeGroupBox() -{ - QGroupBox *iconSizeGroupBox = new QGroupBox(tr("Icon Size")); - - sizeButtonGroup = new QButtonGroup(this); - sizeButtonGroup->setExclusive(true); - - connect(sizeButtonGroup, &QButtonGroup::buttonToggled, - this, &MainWindow::changeSize); - - QRadioButton *smallRadioButton = new QRadioButton; - sizeButtonGroup->addButton(smallRadioButton, QStyle::PM_SmallIconSize); - QRadioButton *largeRadioButton = new QRadioButton; - sizeButtonGroup->addButton(largeRadioButton, QStyle::PM_LargeIconSize); - QRadioButton *toolBarRadioButton = new QRadioButton; - sizeButtonGroup->addButton(toolBarRadioButton, QStyle::PM_ToolBarIconSize); - QRadioButton *listViewRadioButton = new QRadioButton; - sizeButtonGroup->addButton(listViewRadioButton, QStyle::PM_ListViewIconSize); - QRadioButton *iconViewRadioButton = new QRadioButton; - sizeButtonGroup->addButton(iconViewRadioButton, QStyle::PM_IconViewIconSize); - QRadioButton *tabBarRadioButton = new QRadioButton; - sizeButtonGroup->addButton(tabBarRadioButton, QStyle::PM_TabBarIconSize); - QRadioButton *otherRadioButton = new QRadioButton(tr("Other:")); - sizeButtonGroup->addButton(otherRadioButton, OtherSize); - otherSpinBox = new IconSizeSpinBox; - otherSpinBox->setRange(8, 256); - const QString spinBoxToolTip = - tr("Enter a custom size within %1..%2") - .arg(otherSpinBox->minimum()).arg(otherSpinBox->maximum()); - otherSpinBox->setValue(64); - otherSpinBox->setToolTip(spinBoxToolTip); - otherRadioButton->setToolTip(spinBoxToolTip); -//! [26] - -//! [27] - connect(otherSpinBox, &QSpinBox::valueChanged, - this, &MainWindow::triggerChangeSize); - - QHBoxLayout *otherSizeLayout = new QHBoxLayout; - otherSizeLayout->addWidget(otherRadioButton); - otherSizeLayout->addWidget(otherSpinBox); - otherSizeLayout->addStretch(); - - QGridLayout *layout = new QGridLayout(iconSizeGroupBox); - 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); - return iconSizeGroupBox; -//! [27] -} - -void MainWindow::screenChanged() -{ - devicePixelRatioLabel->setText(QString::number(devicePixelRatio())); - if (const QWindow *window = windowHandle()) { - const QScreen *screen = window->screen(); - const QString screenDescription = - tr("\"%1\" (%2x%3)").arg(screen->name()) - .arg(screen->geometry().width()).arg(screen->geometry().height()); - screenNameLabel->setText(screenDescription); - } - changeIcon(); -} - -QWidget *MainWindow::createHighDpiIconSizeGroupBox() -{ - QGroupBox *highDpiGroupBox = new QGroupBox(tr("High DPI Scaling")); - QFormLayout *layout = new QFormLayout(highDpiGroupBox); - devicePixelRatioLabel = new QLabel(highDpiGroupBox); - screenNameLabel = new QLabel(highDpiGroupBox); - layout->addRow(tr("Screen:"), screenNameLabel); - layout->addRow(tr("Device pixel ratio:"), devicePixelRatioLabel); - return highDpiGroupBox; -} - -//! [28] -void MainWindow::createActions() -{ - QMenu *fileMenu = menuBar()->addMenu(tr("&File")); - - addSampleImagesAct = new QAction(tr("Add &Sample Images..."), this); - addSampleImagesAct->setShortcut(tr("Ctrl+A")); - connect(addSampleImagesAct, &QAction::triggered, this, &MainWindow::addSampleImages); - fileMenu->addAction(addSampleImagesAct); - - addOtherImagesAct = new QAction(tr("&Add Images..."), this); - addOtherImagesAct->setShortcut(QKeySequence::Open); - connect(addOtherImagesAct, &QAction::triggered, this, &MainWindow::addOtherImages); - fileMenu->addAction(addOtherImagesAct); - - removeAllImagesAct = new QAction(tr("&Remove All Images"), this); - removeAllImagesAct->setShortcut(tr("Ctrl+R")); - connect(removeAllImagesAct, &QAction::triggered, - this, &MainWindow::removeAllImages); - fileMenu->addAction(removeAllImagesAct); - - fileMenu->addSeparator(); - - QAction *exitAct = fileMenu->addAction(tr("&Quit"), this, &QWidget::close); - exitAct->setShortcuts(QKeySequence::Quit); - - QMenu *viewMenu = menuBar()->addMenu(tr("&View")); - - styleActionGroup = new QActionGroup(this); - const QStringList styleKeys = QStyleFactory::keys(); - for (const QString &styleName : styleKeys) { - QAction *action = new QAction(tr("%1 Style").arg(styleName), styleActionGroup); - action->setData(styleName); - action->setCheckable(true); - connect(action, &QAction::triggered, this, &MainWindow::changeStyle); - viewMenu->addAction(action); - } - - QMenu *settingsMenu = menuBar()->addMenu(tr("&Settings")); - - guessModeStateAct = new QAction(tr("&Guess Image Mode/State"), this); - guessModeStateAct->setCheckable(true); - guessModeStateAct->setChecked(true); - settingsMenu->addAction(guessModeStateAct); - - nativeFileDialogAct = new QAction(tr("&Use Native File Dialog"), this); - nativeFileDialogAct->setCheckable(true); - nativeFileDialogAct->setChecked(true); - settingsMenu->addAction(nativeFileDialogAct); - - QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); - helpMenu->addAction(tr("&About"), this, &MainWindow::about); - helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); -} -//! [28] - -//! [30] -void MainWindow::createContextMenu() -{ - imagesTable->setContextMenuPolicy(Qt::ActionsContextMenu); - imagesTable->addAction(addSampleImagesAct); - imagesTable->addAction(addOtherImagesAct); - imagesTable->addAction(removeAllImagesAct); -} -//! [30] - -//! [31] -void MainWindow::checkCurrentStyle() -{ - const QList<QAction *> actions = styleActionGroup->actions(); - for (QAction *action : actions) { - const QString styleName = action->data().toString(); - const std::unique_ptr<QStyle> candidate{QStyleFactory::create(styleName)}; - Q_ASSERT(candidate); - if (candidate->metaObject()->className() - == QApplication::style()->metaObject()->className()) { - action->trigger(); - return; - } - } -} -//! [31] diff --git a/examples/widgets/widgets/icons/mainwindow.h b/examples/widgets/widgets/icons/mainwindow.h deleted file mode 100644 index cd77dae8e8..0000000000 --- a/examples/widgets/widgets/icons/mainwindow.h +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 <QIcon> -#include <QList> -#include <QMainWindow> -#include <QPixmap> - -QT_BEGIN_NAMESPACE -class QAction; -class QActionGroup; -class QLabel; -class QButtonGroup; -class QTableWidget; -class QAbstractButton; -QT_END_NAMESPACE -class IconPreviewArea; -class IconSizeSpinBox; - -//! [0] -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = nullptr); - - void loadImages(const QStringList &fileNames); - - void show(); - -private slots: - void about(); - void changeStyle(bool checked); - void changeSize(QAbstractButton *button, bool); - void triggerChangeSize(); - void changeIcon(); - void addSampleImages(); - void addOtherImages(); - void removeAllImages(); - void screenChanged(); - -private: - QWidget *createImagesGroupBox(); - QWidget *createIconSizeGroupBox(); - QWidget *createHighDpiIconSizeGroupBox(); - void createActions(); - void createContextMenu(); - void checkCurrentStyle(); - void addImages(const QString &directory); - - IconPreviewArea *previewArea; - - QTableWidget *imagesTable; - - QButtonGroup *sizeButtonGroup; - IconSizeSpinBox *otherSpinBox; - - QLabel *devicePixelRatioLabel; - QLabel *screenNameLabel; - - QAction *addOtherImagesAct; - QAction *addSampleImagesAct; - QAction *removeAllImagesAct; - QAction *guessModeStateAct; - QAction *nativeFileDialogAct; - QActionGroup *styleActionGroup; -}; -//! [0] - -#endif |