summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-26 15:02:51 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-30 08:50:55 +0200
commit921337f98c54d3c4a252569acd2152a1dea8c4bb (patch)
tree7305e86b5dd0976e66199a1f01b0c3244667ae23 /examples/widgets
parent22a8335d681fd1fbdeffe62da37d4f2526c0d504 (diff)
Move pixelator example to manual test
Pick-to: 6.5 6.6 Change-Id: I3ce2bc269a9f77bce3dd41f0127d01091c1408f6 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/doc/src/pixelator.qdoc231
-rw-r--r--examples/widgets/itemviews/CMakeLists.txt1
-rw-r--r--examples/widgets/itemviews/itemviews.pro1
-rw-r--r--examples/widgets/itemviews/pixelator/CMakeLists.txt58
-rw-r--r--examples/widgets/itemviews/pixelator/imagemodel.cpp53
-rw-r--r--examples/widgets/itemviews/pixelator/imagemodel.h31
-rw-r--r--examples/widgets/itemviews/pixelator/images.qrc5
-rw-r--r--examples/widgets/itemviews/pixelator/images/qt.pngbin1506 -> 0 bytes
-rw-r--r--examples/widgets/itemviews/pixelator/main.cpp15
-rw-r--r--examples/widgets/itemviews/pixelator/mainwindow.cpp214
-rw-r--r--examples/widgets/itemviews/pixelator/mainwindow.h37
-rw-r--r--examples/widgets/itemviews/pixelator/pixelator.pro16
-rw-r--r--examples/widgets/itemviews/pixelator/pixeldelegate.cpp68
-rw-r--r--examples/widgets/itemviews/pixelator/pixeldelegate.h41
14 files changed, 0 insertions, 771 deletions
diff --git a/examples/widgets/doc/src/pixelator.qdoc b/examples/widgets/doc/src/pixelator.qdoc
deleted file mode 100644
index ab6f639d87..0000000000
--- a/examples/widgets/doc/src/pixelator.qdoc
+++ /dev/null
@@ -1,231 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example itemviews/pixelator
- \title Pixelator Example
- \ingroup examples-itemviews
- \brief The Pixelator example shows how delegates can be used to customize the way that
- items are rendered in standard item views.
-
- \image pixelator-example.png
-
- By default, QTreeView, QTableView, and QListView use a standard item delegate
- to display and edit a set of common data types that are sufficient for many
- applications. However, an application may need to represent items of data in a
- particular way, or provide support for rendering more specialized data types,
- and this often requires the use of a custom delegate.
-
- In this example, we show how to use custom delegates to modify the appearance
- of standard views. To do this, we implement the following components:
-
- \list
- \li A model which represents each pixel in an image as an item of data, where each
- item contains a value for the brightness of the corresponding pixel.
- \li A custom delegate that uses the information supplied by the model to represent
- each pixel as a black circle on a white background, where the radius of the
- circle corresponds to the darkness of the pixel.
- \endlist
-
- This example may be useful for developers who want to implement their own table
- models or custom delegates. The process of creating custom delegates for editing
- item data is covered in the \l{Spin Box Delegate Example}{Spin Box Delegate}
- example.
-
- \section1 ImageModel Class Definition
-
- The \c ImageModel class is defined as follows:
-
- \snippet itemviews/pixelator/imagemodel.h 0
-
- Since we only require a simple, read-only table model, we only need to implement
- functions to indicate the dimensions of the image and supply data to other
- components.
-
- \section1 ImageModel Class Implementation
-
- The constructor is trivial:
-
- \snippet itemviews/pixelator/imagemodel.cpp 0
-
- The \c setImage() function sets the image that will be used by the model:
-
- \snippet itemviews/pixelator/imagemodel.cpp 1
-
- The QAbstractItemModel::reset() call tells the view(s) that the model
- has changed.
-
- The \c rowCount() and \c columnCount() functions return the height and width of
- the image respectively:
-
- \snippet itemviews/pixelator/imagemodel.cpp 2
- \snippet itemviews/pixelator/imagemodel.cpp 3
-
- Since the image is a simple two-dimensional structure, the \c parent arguments
- to these functions are unused. They both simply return the relevant size from
- the underlying image object.
-
- The \c data() function returns data for the item that corresponds to a given
- model index in a format that is suitable for a particular role:
-
- \snippet itemviews/pixelator/imagemodel.cpp 4
-
- In this implementation, we only check that the model index is valid, and that
- the role requested is the \l{Qt::ItemDataRole}{DisplayRole}. If so, the function
- returns the grayscale value of the relevant pixel in the image; otherwise, a null
- model index is returned.
-
- This model can be used with QTableView to display the integer brightness values
- for the pixels in the image. However, we will implement a custom delegate to
- display this information in a more artistic way.
-
- The \c headerData() function is also reimplemented:
-
- \snippet itemviews/pixelator/imagemodel.cpp 5
-
- We return (1, 1) as the size hint for a header item. If we
- didn't, the headers would default to a larger size, preventing
- us from displaying really small items (which can be specified
- using the \uicontrol{Pixel size} combobox).
-
- \section1 PixelDelegate Class Definition
-
- The \c PixelDelegate class is defined as follows:
-
- \snippet itemviews/pixelator/pixeldelegate.h 0
-
- This class provides only basic features for a delegate so, unlike the
- \l{Spin Box Delegate Example}{Spin Box Delegate} example, we subclass
- QAbstractItemDelegate instead of QItemDelegate.
-
- We only need to reimplement \l{QAbstractItemDelegate::paint()}{paint()} and
- \l{QAbstractItemDelegate::sizeHint()}{sizeHint()} in this class.
- However, we also provide a delegate-specific \c setPixelSize() function so
- that we can change the delegate's behavior via the signals and slots mechanism.
-
- \section1 PixelDelegate Class Implementation
-
- The \c PixelDelegate constructor is used to set up a default value for
- the size of each "pixel" that it renders. The base class constructor is
- also called to ensure that the delegate is set up with a parent object,
- if one is supplied:
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 0
-
- Each item is rendered by the delegate's
- \l{QAbstractItemDelegate::paint()}{paint()} function. The view calls this
- function with a ready-to-use QPainter object, style information that the
- delegate should use to correctly draw the item, and an index to the item in
- the model:
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 1
-
- The first task the delegate has to perform is to draw the item's background
- correctly. Usually, selected items appear differently to non-selected items,
- so we begin by testing the state passed in the style option and filling the
- background if necessary.
-
- The radius of each circle is calculated in the following lines of code:
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 3
- \snippet itemviews/pixelator/pixeldelegate.cpp 4
-
- First, the largest possible radius of the circle is determined by taking the
- smallest dimension of the style option's \c rect attribute.
- Using the model index supplied, we obtain a value for the brightness of the
- relevant pixel in the image. The radius of the circle is calculated by
- scaling the brightness to fit within the item and subtracting it from the
- largest possible radius.
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 5
- \snippet itemviews/pixelator/pixeldelegate.cpp 6
- \snippet itemviews/pixelator/pixeldelegate.cpp 7
-
- We save the painter's state, turn on antialiasing (to obtain smoother
- curves), and turn off the pen.
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 8
- \snippet itemviews/pixelator/pixeldelegate.cpp 9
-
- The foreground of the item (the circle representing a pixel) must be
- rendered using an appropriate brush. For unselected items, we will use a
- solid black brush; selected items are drawn using a predefined brush from
- the style option's palette.
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 10
-
- Finally, we paint the circle within the rectangle specified by the style
- option and we call \l{QPainter::}{restore()} on the painter.
-
- The \c paint() function does not have to be particularly complicated; it is
- only necessary to ensure that the state of the painter when the function
- returns is the same as it was when it was called. This usually
- means that any transformations applied to the painter must be preceded by
- a call to QPainter::save() and followed by a call to QPainter::restore().
-
- The delegate's \l{QAbstractItemDelegate::}{sizeHint()} function
- returns a size for the item based on the predefined pixel size, initially set
- up in the constructor:
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 11
-
- The delegate's size is updated whenever the pixel size is changed.
- We provide a custom slot to do this:
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 12
-
- \section1 Using The Custom Delegate
-
- In this example, we use a main window to display a table of data, using the
- custom delegate to render each cell in a particular way. Much of the
- \c MainWindow class performs tasks that are not related to item views. Here,
- we only quote the parts that are relevant. You can look at the rest of the
- implementation by following the links to the code at the top of this
- document.
-
- In the constructor, we set up a table view, turn off its grid, and hide its
- headers:
-
- \snippet itemviews/pixelator/mainwindow.cpp 0
- \dots
- \snippet itemviews/pixelator/mainwindow.cpp 1
-
- This enables the items to be drawn without any gaps between them. Removing
- the headers also prevents the user from adjusting the sizes of individual
- rows and columns.
-
- We also set the minimum section size to 1 on the headers. If we
- didn't, the headers would default to a larger size, preventing
- us from displaying really small items (which can be specified
- using the \uicontrol{Pixel size} combobox).
-
- The custom delegate is constructed with the main window as its parent, so
- that it will be deleted correctly later, and we set it on the table view.
-
- \snippet itemviews/pixelator/mainwindow.cpp 2
-
- Each item in the table view will be rendered by the \c PixelDelegate
- instance.
-
- We construct a spin box to allow the user to change the size of each "pixel"
- drawn by the delegate:
-
- \snippet itemviews/pixelator/mainwindow.cpp 3
-
- This spin box is connected to the custom slot we implemented in the
- \c PixelDelegate class. This ensures that the delegate always draws each
- pixel at the currently specified size:
-
- \snippet itemviews/pixelator/mainwindow.cpp 4
- \dots
- \snippet itemviews/pixelator/mainwindow.cpp 5
-
- We also connect the spin box to a slot in the \c MainWindow class. This
- forces the view to take into account the new size hints for each item;
- these are provided by the delegate in its \c sizeHint() function.
-
- \snippet itemviews/pixelator/mainwindow.cpp 6
-
- We explicitly resize the columns and rows to match the
- \uicontrol{Pixel size} combobox.
-*/
diff --git a/examples/widgets/itemviews/CMakeLists.txt b/examples/widgets/itemviews/CMakeLists.txt
index 93c36368ce..02b531f932 100644
--- a/examples/widgets/itemviews/CMakeLists.txt
+++ b/examples/widgets/itemviews/CMakeLists.txt
@@ -9,7 +9,6 @@ qt_internal_add_example(customsortfiltermodel)
qt_internal_add_example(editabletreemodel)
qt_internal_add_example(fetchmore)
qt_internal_add_example(frozencolumn)
-qt_internal_add_example(pixelator)
qt_internal_add_example(simpletreemodel)
qt_internal_add_example(simplewidgetmapper)
qt_internal_add_example(spinboxdelegate)
diff --git a/examples/widgets/itemviews/itemviews.pro b/examples/widgets/itemviews/itemviews.pro
index 3b99ff9606..9fa7e6c9c9 100644
--- a/examples/widgets/itemviews/itemviews.pro
+++ b/examples/widgets/itemviews/itemviews.pro
@@ -7,7 +7,6 @@ SUBDIRS = addressbook \
editabletreemodel \
fetchmore \
frozencolumn \
- pixelator \
simpledommodel \
simpletreemodel \
simplewidgetmapper \
diff --git a/examples/widgets/itemviews/pixelator/CMakeLists.txt b/examples/widgets/itemviews/pixelator/CMakeLists.txt
deleted file mode 100644
index 956599973e..0000000000
--- a/examples/widgets/itemviews/pixelator/CMakeLists.txt
+++ /dev/null
@@ -1,58 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(pixelator LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/pixelator")
-
-find_package(Qt6
- REQUIRED COMPONENTS Core Gui Widgets
- OPTIONAL_COMPONENTS PrintSupport
-)
-
-qt_standard_project_setup()
-
-qt_add_executable(pixelator
- imagemodel.cpp imagemodel.h
- main.cpp
- mainwindow.cpp mainwindow.h
- pixeldelegate.cpp pixeldelegate.h
-)
-
-set_target_properties(pixelator PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(pixelator PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-if(TARGET Qt6::PrintSupport)
- target_link_libraries(pixelator PRIVATE Qt6::PrintSupport)
-endif()
-
-# Resources:
-set(images_resource_files
- "images/qt.png"
-)
-
-qt_add_resources(pixelator "images"
- PREFIX
- "/"
- FILES
- ${images_resource_files}
-)
-
-install(TARGETS pixelator
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/pixelator/imagemodel.cpp b/examples/widgets/itemviews/pixelator/imagemodel.cpp
deleted file mode 100644
index 6b5b866522..0000000000
--- a/examples/widgets/itemviews/pixelator/imagemodel.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "imagemodel.h"
-
-//! [0]
-ImageModel::ImageModel(QObject *parent)
- : QAbstractTableModel(parent)
-{
-}
-//! [0]
-
-//! [1]
-void ImageModel::setImage(const QImage &image)
-{
- beginResetModel();
- modelImage = image;
- endResetModel();
-}
-//! [1]
-
-//! [2]
-int ImageModel::rowCount(const QModelIndex & /* parent */) const
-{
- return modelImage.height();
-}
-
-int ImageModel::columnCount(const QModelIndex & /* parent */) const
-//! [2] //! [3]
-{
- return modelImage.width();
-}
-//! [3]
-
-//! [4]
-QVariant ImageModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid() || role != Qt::DisplayRole)
- return QVariant();
- return qGray(modelImage.pixel(index.column(), index.row()));
-}
-//! [4]
-
-//! [5]
-QVariant ImageModel::headerData(int /* section */,
- Qt::Orientation /* orientation */,
- int role) const
-{
- if (role == Qt::SizeHintRole)
- return QSize(1, 1);
- return QVariant();
-}
-//! [5]
diff --git a/examples/widgets/itemviews/pixelator/imagemodel.h b/examples/widgets/itemviews/pixelator/imagemodel.h
deleted file mode 100644
index 050ac6b790..0000000000
--- a/examples/widgets/itemviews/pixelator/imagemodel.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef IMAGEMODEL_H
-#define IMAGEMODEL_H
-
-#include <QAbstractTableModel>
-#include <QImage>
-
-//! [0]
-class ImageModel : public QAbstractTableModel
-{
- Q_OBJECT
-
-public:
- ImageModel(QObject *parent = nullptr);
-
- void setImage(const QImage &image);
-
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- int columnCount(const QModelIndex &parent = QModelIndex()) const override;
-
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
-
-private:
- QImage modelImage;
-};
-//! [0]
-
-#endif // IMAGEMODEL_H
diff --git a/examples/widgets/itemviews/pixelator/images.qrc b/examples/widgets/itemviews/pixelator/images.qrc
deleted file mode 100644
index c105e13895..0000000000
--- a/examples/widgets/itemviews/pixelator/images.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>images/qt.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/itemviews/pixelator/images/qt.png b/examples/widgets/itemviews/pixelator/images/qt.png
deleted file mode 100644
index dd197cb59c..0000000000
--- a/examples/widgets/itemviews/pixelator/images/qt.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/itemviews/pixelator/main.cpp b/examples/widgets/itemviews/pixelator/main.cpp
deleted file mode 100644
index 26783b02fc..0000000000
--- a/examples/widgets/itemviews/pixelator/main.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- MainWindow window;
- window.show();
- window.openImage(":/images/qt.png");
- return app.exec();
-}
diff --git a/examples/widgets/itemviews/pixelator/mainwindow.cpp b/examples/widgets/itemviews/pixelator/mainwindow.cpp
deleted file mode 100644
index 42f0a43844..0000000000
--- a/examples/widgets/itemviews/pixelator/mainwindow.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-#include "imagemodel.h"
-#include "pixeldelegate.h"
-
-#include <QtWidgets>
-#if defined(QT_PRINTSUPPORT_LIB)
-#include <QtPrintSupport/qtprintsupportglobal.h>
-#if QT_CONFIG(printdialog)
-#include <QPrinter>
-#include <QPrintDialog>
-#endif
-#endif
-
-//! [0]
-MainWindow::MainWindow()
-{
-//! [0]
- currentPath = QDir::homePath();
- model = new ImageModel(this);
-
- QWidget *centralWidget = new QWidget;
-
-//! [1]
- view = new QTableView;
- view->setShowGrid(false);
- view->horizontalHeader()->hide();
- view->verticalHeader()->hide();
- view->horizontalHeader()->setMinimumSectionSize(1);
- view->verticalHeader()->setMinimumSectionSize(1);
- view->setModel(model);
-//! [1]
-
-//! [2]
- PixelDelegate *delegate = new PixelDelegate(this);
- view->setItemDelegate(delegate);
-//! [2]
-
-//! [3]
- QLabel *pixelSizeLabel = new QLabel(tr("Pixel size:"));
- QSpinBox *pixelSizeSpinBox = new QSpinBox;
- pixelSizeSpinBox->setMinimum(4);
- pixelSizeSpinBox->setMaximum(32);
- pixelSizeSpinBox->setValue(12);
-//! [3]
-
- QMenu *fileMenu = new QMenu(tr("&File"), this);
- QAction *openAction = fileMenu->addAction(tr("&Open..."));
- openAction->setShortcuts(QKeySequence::Open);
-
- printAction = fileMenu->addAction(tr("&Print..."));
- printAction->setEnabled(false);
- printAction->setShortcut(QKeySequence::Print);
-
- QAction *quitAction = fileMenu->addAction(tr("E&xit"));
- quitAction->setShortcuts(QKeySequence::Quit);
-
- QMenu *helpMenu = new QMenu(tr("&Help"), this);
- QAction *aboutAction = helpMenu->addAction(tr("&About"));
-
- menuBar()->addMenu(fileMenu);
- menuBar()->addSeparator();
- menuBar()->addMenu(helpMenu);
-
- connect(openAction, &QAction::triggered, this, &MainWindow::chooseImage);
- connect(printAction, &QAction::triggered, this, &MainWindow::printImage);
- connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
- connect(aboutAction, &QAction::triggered, this, &MainWindow::showAboutBox);
-//! [4]
- connect(pixelSizeSpinBox, &QSpinBox::valueChanged,
- delegate, &PixelDelegate::setPixelSize);
- connect(pixelSizeSpinBox, &QSpinBox::valueChanged,
- this, &MainWindow::updateView);
-//! [4]
-
- QHBoxLayout *controlsLayout = new QHBoxLayout;
- controlsLayout->addWidget(pixelSizeLabel);
- controlsLayout->addWidget(pixelSizeSpinBox);
- controlsLayout->addStretch(1);
-
- QVBoxLayout *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(view);
- mainLayout->addLayout(controlsLayout);
- centralWidget->setLayout(mainLayout);
-
- setCentralWidget(centralWidget);
-
- setWindowTitle(tr("Pixelator"));
- resize(640, 480);
-//! [5]
-}
-//! [5]
-
-void MainWindow::chooseImage()
-{
- QString fileName = QFileDialog::getOpenFileName(this,
- tr("Choose an image"), currentPath, "*");
-
- if (!fileName.isEmpty())
- openImage(fileName);
-}
-
-void MainWindow::openImage(const QString &fileName)
-{
- QImage image;
-
- if (image.load(fileName)) {
- model->setImage(image);
- if (!fileName.startsWith(":/")) {
- currentPath = fileName;
- setWindowTitle(tr("%1 - Pixelator").arg(currentPath));
- }
-
- printAction->setEnabled(true);
- updateView();
- }
-}
-
-void MainWindow::printImage()
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
- if (model->rowCount(QModelIndex())*model->columnCount(QModelIndex()) > 90000) {
- QMessageBox::StandardButton answer;
- answer = QMessageBox::question(this, tr("Large Image Size"),
- tr("The printed image may be very large. Are you sure that "
- "you want to print it?"),
- QMessageBox::Yes | QMessageBox::No);
- if (answer == QMessageBox::No)
- return;
- }
-
- QPrinter printer(QPrinter::HighResolution);
-
- QPrintDialog dlg(&printer, this);
- dlg.setWindowTitle(tr("Print Image"));
-
- if (dlg.exec() != QDialog::Accepted) {
- return;
- }
-
- QPainter painter;
- painter.begin(&printer);
-
- int rows = model->rowCount(QModelIndex());
- int columns = model->columnCount(QModelIndex());
- int sourceWidth = (columns + 1) * ItemSize;
- int sourceHeight = (rows + 1) * ItemSize;
-
- painter.save();
-
- double xscale = printer.pageRect(QPrinter::DevicePixel).width() / double(sourceWidth);
- double yscale = printer.pageRect(QPrinter::DevicePixel).height() / double(sourceHeight);
- double scale = qMin(xscale, yscale);
-
- painter.translate(printer.paperRect(QPrinter::DevicePixel).x() + printer.pageRect(QPrinter::DevicePixel).width() / 2,
- printer.paperRect(QPrinter::DevicePixel).y() + printer.pageRect(QPrinter::DevicePixel).height() / 2);
- painter.scale(scale, scale);
- painter.translate(-sourceWidth / 2, -sourceHeight / 2);
-
- QStyleOptionViewItem option;
- QModelIndex parent = QModelIndex();
-
- QProgressDialog progress(tr("Printing..."), tr("Cancel"), 0, rows, this);
- progress.setWindowModality(Qt::ApplicationModal);
- float y = ItemSize / 2;
-
- for (int row = 0; row < rows; ++row) {
- progress.setValue(row);
- qApp->processEvents();
- if (progress.wasCanceled())
- break;
-
- float x = ItemSize / 2;
-
- for (int column = 0; column < columns; ++column) {
- option.rect = QRect(int(x), int(y), ItemSize, ItemSize);
- view->itemDelegate()->paint(&painter, option,
- model->index(row, column, parent));
- x = x + ItemSize;
- }
- y = y + ItemSize;
- }
- progress.setValue(rows);
-
- painter.restore();
- painter.end();
-
- if (progress.wasCanceled()) {
- QMessageBox::information(this, tr("Printing canceled"),
- tr("The printing process was canceled."), QMessageBox::Cancel);
- }
-#else
- QMessageBox::information(this, tr("Printing canceled"),
- tr("Printing is not supported on this Qt build"), QMessageBox::Cancel);
-#endif
-}
-
-void MainWindow::showAboutBox()
-{
- QMessageBox::about(this, tr("About the Pixelator example"),
- tr("This example demonstrates how a standard view and a custom\n"
- "delegate can be used to produce a specialized representation\n"
- "of data in a simple custom model."));
-}
-
-//! [6]
-void MainWindow::updateView()
-{
- view->resizeColumnsToContents();
- view->resizeRowsToContents();
-}
-//! [6]
diff --git a/examples/widgets/itemviews/pixelator/mainwindow.h b/examples/widgets/itemviews/pixelator/mainwindow.h
deleted file mode 100644
index 9929e2f5af..0000000000
--- a/examples/widgets/itemviews/pixelator/mainwindow.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-
-class ImageModel;
-QT_BEGIN_NAMESPACE
-class QAction;
-class QTableView;
-QT_END_NAMESPACE
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
- void openImage(const QString &fileName);
-
-public slots:
- void chooseImage();
- void printImage();
- void showAboutBox();
- void updateView();
-
-private:
- ImageModel *model;
- QAction *printAction;
- QString currentPath;
- QTableView *view;
-};
-
-#endif // MAINWINDOW_H
diff --git a/examples/widgets/itemviews/pixelator/pixelator.pro b/examples/widgets/itemviews/pixelator/pixelator.pro
deleted file mode 100644
index 421f626e28..0000000000
--- a/examples/widgets/itemviews/pixelator/pixelator.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-QT += widgets
-requires(qtConfig(tableview))
-qtHaveModule(printsupport): QT += printsupport
-
-HEADERS = imagemodel.h \
- mainwindow.h \
- pixeldelegate.h
-SOURCES = imagemodel.cpp \
- main.cpp \
- mainwindow.cpp \
- pixeldelegate.cpp
-RESOURCES += images.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/pixelator
-INSTALLS += target
diff --git a/examples/widgets/itemviews/pixelator/pixeldelegate.cpp b/examples/widgets/itemviews/pixelator/pixeldelegate.cpp
deleted file mode 100644
index 3a104cd2c2..0000000000
--- a/examples/widgets/itemviews/pixelator/pixeldelegate.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "pixeldelegate.h"
-
-#include <QPainter>
-
-//! [0]
-PixelDelegate::PixelDelegate(QObject *parent)
- : QAbstractItemDelegate(parent), pixelSize(12)
-{}
-//! [0]
-
-//! [1]
-void PixelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const
-{
-//! [2]
- if (option.state & QStyle::State_Selected)
- painter->fillRect(option.rect, option.palette.highlight());
-//! [1]
-
-//! [3]
- const int size = qMin(option.rect.width(), option.rect.height());
-//! [3] //! [4]
- const int brightness = index.model()->data(index, Qt::DisplayRole).toInt();
- const double radius = (size / 2.0) - (brightness / 255.0 * size / 2.0);
- if (qFuzzyIsNull(radius))
- return;
-//! [4]
-
-//! [5]
- painter->save();
-//! [5] //! [6]
- painter->setRenderHint(QPainter::Antialiasing, true);
-//! [6] //! [7]
- painter->setPen(Qt::NoPen);
-//! [7] //! [8]
- if (option.state & QStyle::State_Selected)
-//! [8] //! [9]
- painter->setBrush(option.palette.highlightedText());
- else
-//! [2]
- painter->setBrush(option.palette.text());
-//! [9]
-
-//! [10]
- painter->drawEllipse(QRectF(option.rect.x() + option.rect.width() / 2 - radius,
- option.rect.y() + option.rect.height() / 2 - radius,
- 2 * radius, 2 * radius));
- painter->restore();
-}
-//! [10]
-
-//! [11]
-QSize PixelDelegate::sizeHint(const QStyleOptionViewItem & /* option */,
- const QModelIndex & /* index */) const
-{
- return QSize(pixelSize, pixelSize);
-}
-//! [11]
-
-//! [12]
-void PixelDelegate::setPixelSize(int size)
-{
- pixelSize = size;
-}
-//! [12]
diff --git a/examples/widgets/itemviews/pixelator/pixeldelegate.h b/examples/widgets/itemviews/pixelator/pixeldelegate.h
deleted file mode 100644
index a4c435ce69..0000000000
--- a/examples/widgets/itemviews/pixelator/pixeldelegate.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PIXELDELEGATE_H
-#define PIXELDELEGATE_H
-
-#include <QAbstractItemDelegate>
-#include <QModelIndex>
-#include <QSize>
-
-QT_BEGIN_NAMESPACE
-class QAbstractItemModel;
-class QObject;
-class QPainter;
-QT_END_NAMESPACE
-
-static constexpr int ItemSize = 256;
-
-//! [0]
-class PixelDelegate : public QAbstractItemDelegate
-{
- Q_OBJECT
-
-public:
- PixelDelegate(QObject *parent = nullptr);
-
- void paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
-
- QSize sizeHint(const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
-
-public slots:
- void setPixelSize(int size);
-
-private:
- int pixelSize;
-};
-//! [0]
-
-#endif // PIXELDELEGATE_H