summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2020-06-17 12:33:40 +0200
committerKarsten Heimrich <karsten.heimrich@qt.io>2020-06-20 02:04:38 +0200
commit18ec53156ee704fdb4977436fccfdc85333e614b (patch)
treedf734ce7893d570f4a90f923fcfe9c80ddc3de05 /examples
parent4455de24d453138411c57bae55af18f3fba58d4b (diff)
Move QTextCodec support out of QtCore
* Assume UTF-8 on all Unix like systems * Export some functions to be able to compile QTextCodec once moved to Qt5Compat. Task-number: QTBUG-75665 Change-Id: I52ec47a848bc0ba72e9c7689668b1bcc5d736c29 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/widgets/tools/.prev_CMakeLists.txt1
-rw-r--r--examples/widgets/tools/CMakeLists.txt1
-rw-r--r--examples/widgets/tools/codecs/CMakeLists.txt47
-rw-r--r--examples/widgets/tools/codecs/codecs.pro19
-rw-r--r--examples/widgets/tools/codecs/codecs.qrc5
-rw-r--r--examples/widgets/tools/codecs/doc/images/codecs-example.pngbin20593 -> 0 bytes
-rw-r--r--examples/widgets/tools/codecs/doc/src/codecs.qdoc38
-rw-r--r--examples/widgets/tools/codecs/encodedfiles/iso-8859-1.txt6
-rw-r--r--examples/widgets/tools/codecs/encodedfiles/iso-8859-15.txt8
-rw-r--r--examples/widgets/tools/codecs/encodedfiles/utf-16.txtbin162 -> 0 bytes
-rw-r--r--examples/widgets/tools/codecs/encodedfiles/utf-16be.txtbin160 -> 0 bytes
-rw-r--r--examples/widgets/tools/codecs/encodedfiles/utf-16le.txtbin160 -> 0 bytes
-rw-r--r--examples/widgets/tools/codecs/encodedfiles/utf-8.txt6
-rw-r--r--examples/widgets/tools/codecs/encodingdialog.cpp333
-rw-r--r--examples/widgets/tools/codecs/encodingdialog.h73
-rw-r--r--examples/widgets/tools/codecs/images/editcopy.pngbin1325 -> 0 bytes
-rw-r--r--examples/widgets/tools/codecs/main.cpp61
-rw-r--r--examples/widgets/tools/codecs/mainwindow.cpp225
-rw-r--r--examples/widgets/tools/codecs/mainwindow.h91
-rw-r--r--examples/widgets/tools/codecs/previewform.cpp248
-rw-r--r--examples/widgets/tools/codecs/previewform.h95
-rw-r--r--examples/widgets/tools/tools.pro1
22 files changed, 0 insertions, 1258 deletions
diff --git a/examples/widgets/tools/.prev_CMakeLists.txt b/examples/widgets/tools/.prev_CMakeLists.txt
index d2fe6aa5ca..29e7f8f9e8 100644
--- a/examples/widgets/tools/.prev_CMakeLists.txt
+++ b/examples/widgets/tools/.prev_CMakeLists.txt
@@ -1,6 +1,5 @@
# Generated from tools.pro.
-add_subdirectory(codecs)
add_subdirectory(completer)
add_subdirectory(customcompleter)
add_subdirectory(regularexpression)
diff --git a/examples/widgets/tools/CMakeLists.txt b/examples/widgets/tools/CMakeLists.txt
index 80c8f43007..022f4a2b8f 100644
--- a/examples/widgets/tools/CMakeLists.txt
+++ b/examples/widgets/tools/CMakeLists.txt
@@ -1,6 +1,5 @@
# Generated from tools.pro.
-add_subdirectory(codecs)
add_subdirectory(completer)
add_subdirectory(customcompleter)
if(QT_FEATURE_translation) # special case
diff --git a/examples/widgets/tools/codecs/CMakeLists.txt b/examples/widgets/tools/codecs/CMakeLists.txt
deleted file mode 100644
index 7e2714fc4b..0000000000
--- a/examples/widgets/tools/codecs/CMakeLists.txt
+++ /dev/null
@@ -1,47 +0,0 @@
-# Generated from codecs.pro.
-
-cmake_minimum_required(VERSION 3.14)
-project(codecs LANGUAGES CXX)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
-
-set(INSTALL_EXAMPLEDIR "examples/widgets/tools/codecs")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
-
-add_qt_gui_executable(codecs
- encodingdialog.cpp encodingdialog.h
- main.cpp
- mainwindow.cpp mainwindow.h
- previewform.cpp previewform.h
-)
-target_link_libraries(codecs PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Widgets
-)
-
-
-# Resources:
-set(codecs_resource_files
- "images/editcopy.png"
-)
-
-qt6_add_resources(codecs "codecs"
- PREFIX
- "/"
- FILES
- ${codecs_resource_files}
-)
-
-install(TARGETS codecs
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/tools/codecs/codecs.pro b/examples/widgets/tools/codecs/codecs.pro
deleted file mode 100644
index 6f4b0742a9..0000000000
--- a/examples/widgets/tools/codecs/codecs.pro
+++ /dev/null
@@ -1,19 +0,0 @@
-QT += widgets
-requires(qtConfig(filedialog))
-
-HEADERS += mainwindow.h \
- previewform.h \
- encodingdialog.h
-
-SOURCES += main.cpp \
- mainwindow.cpp \
- previewform.cpp \
- encodingdialog.cpp
-
-RESOURCES += codecs.qrc
-
-EXAMPLE_FILES = encodedfiles
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/codecs
-INSTALLS += target
diff --git a/examples/widgets/tools/codecs/codecs.qrc b/examples/widgets/tools/codecs/codecs.qrc
deleted file mode 100644
index 65fa1aa64d..0000000000
--- a/examples/widgets/tools/codecs/codecs.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/" >
- <file>images/editcopy.png</file>
- </qresource>
-</RCC>
diff --git a/examples/widgets/tools/codecs/doc/images/codecs-example.png b/examples/widgets/tools/codecs/doc/images/codecs-example.png
deleted file mode 100644
index 8e7ae95317..0000000000
--- a/examples/widgets/tools/codecs/doc/images/codecs-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/tools/codecs/doc/src/codecs.qdoc b/examples/widgets/tools/codecs/doc/src/codecs.qdoc
deleted file mode 100644
index 78f4f7396b..0000000000
--- a/examples/widgets/tools/codecs/doc/src/codecs.qdoc
+++ /dev/null
@@ -1,38 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** 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.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example tools/codecs
- \title Text Codecs Example
- \brief How to import and export text using text codecs.
-
- The Text Codecs example demonstrates the principles behind importing and exporting text
- using codecs to ensure that characters are encoded properly, avoiding loss of data
- and retaining the correct symbols used in various scripts.
-
- \image codecs-example.png
-*/
diff --git a/examples/widgets/tools/codecs/encodedfiles/iso-8859-1.txt b/examples/widgets/tools/codecs/encodedfiles/iso-8859-1.txt
deleted file mode 100644
index d7fcacae66..0000000000
--- a/examples/widgets/tools/codecs/encodedfiles/iso-8859-1.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-Paulo Coelho: O Gênio e as Rosas
-Anna Hallström, Urban Östberg: Svår svenska
-Darrell Huff: How to Lie with Statistics
-Franz Kafka: Das Schloß
-Walter Moers: Die 13½ Leben des Käpt'n Blaubär
-Dag Solstad: Forsøk på å beskrive det ugjennomtrengelige
diff --git a/examples/widgets/tools/codecs/encodedfiles/iso-8859-15.txt b/examples/widgets/tools/codecs/encodedfiles/iso-8859-15.txt
deleted file mode 100644
index be2d83c98d..0000000000
--- a/examples/widgets/tools/codecs/encodedfiles/iso-8859-15.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-Paulo Coelho: O Gênio e as Rosas
-Jean-Pierre Coffe: À table en famille avec 15 ¤ par jour
-Anna Hallström, Urban Östberg: Svår svenska
-Darrell Huff: How to Lie with Statistics
-Franz Kafka: Das Schloß
-Helena Lehecková: T¨ekkiä suomalaisille
-Arthur Rimbaud: ¼uvres complètes
-Dag Solstad: Forsøk på å beskrive det ugjennomtrengelige
diff --git a/examples/widgets/tools/codecs/encodedfiles/utf-16.txt b/examples/widgets/tools/codecs/encodedfiles/utf-16.txt
deleted file mode 100644
index 371f06f7fa..0000000000
--- a/examples/widgets/tools/codecs/encodedfiles/utf-16.txt
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/tools/codecs/encodedfiles/utf-16be.txt b/examples/widgets/tools/codecs/encodedfiles/utf-16be.txt
deleted file mode 100644
index d8ae6428bc..0000000000
--- a/examples/widgets/tools/codecs/encodedfiles/utf-16be.txt
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/tools/codecs/encodedfiles/utf-16le.txt b/examples/widgets/tools/codecs/encodedfiles/utf-16le.txt
deleted file mode 100644
index 3779264c7c..0000000000
--- a/examples/widgets/tools/codecs/encodedfiles/utf-16le.txt
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/tools/codecs/encodedfiles/utf-8.txt b/examples/widgets/tools/codecs/encodedfiles/utf-8.txt
deleted file mode 100644
index a5e4ae6fa7..0000000000
--- a/examples/widgets/tools/codecs/encodedfiles/utf-8.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-Språk: Norsk
-Γλώσσα: Ελληνικά
-Язык: РуÑÑкий
-언어 : 한국어
-言語: 日本語
-Langage : Français
diff --git a/examples/widgets/tools/codecs/encodingdialog.cpp b/examples/widgets/tools/codecs/encodingdialog.cpp
deleted file mode 100644
index aa57d47dc7..0000000000
--- a/examples/widgets/tools/codecs/encodingdialog.cpp
+++ /dev/null
@@ -1,333 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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 "encodingdialog.h"
-
-#if QT_CONFIG(action)
-# include <QAction>
-#endif
-#include <QDialogButtonBox>
-#include <QFormLayout>
-#include <QLabel>
-#include <QLineEdit>
-#include <QVBoxLayout>
-
-#if QT_CONFIG(clipboard)
-# include <QGuiApplication>
-# include <QClipboard>
-#endif
-
-#include <QTextStream>
-
-// Helpers for formatting character sequences
-
-// Format a special character like '\x0a'
-template <class Int>
-static void formatEscapedNumber(QTextStream &str, Int value, int base,
- int width = 0,char prefix = 0)
-{
- str << '\\';
- if (prefix)
- str << prefix;
- const auto oldPadChar = str.padChar();
- const auto oldFieldWidth = str.fieldWidth();
- const auto oldFieldAlignment = str.fieldAlignment();
- const auto oldIntegerBase = str.integerBase();
- str.setPadChar(QLatin1Char('0'));
- str.setFieldWidth(width);
- str.setFieldAlignment(QTextStream::AlignRight);
- str.setIntegerBase(base);
- str << value;
- str.setIntegerBase(oldIntegerBase);
- str.setFieldAlignment(oldFieldAlignment);
- str.setFieldWidth(oldFieldWidth);
- str.setPadChar(oldPadChar);
-}
-
-template <class Int>
-static bool formatSpecialCharacter(QTextStream &str, Int value)
-{
- bool result = true;
- switch (value) {
- case '\\':
- str << "\\\\";
- break;
- case '\"':
- str << "\\\"";
- break;
- case '\n':
- str << "\\n";
- break;
- default:
- result = false;
- break;
- }
- return result;
-}
-
-// Format a sequence of characters (QChar, ushort (UTF-16), uint (UTF-32)
-// or just char (Latin1, Utf-8)) with the help of traits specifying
-// how to obtain the code for checking the printable-ness and how to
-// stream out the plain ASCII values.
-
-template <EncodingDialog::Encoding>
-struct FormattingTraits
-{
-};
-
-template <>
-struct FormattingTraits<EncodingDialog::Unicode>
-{
- static ushort code(QChar c) { return c.unicode(); }
- static char toAscii(QChar c) { return c.toLatin1(); }
-};
-
-template <>
-struct FormattingTraits<EncodingDialog::Utf8>
-{
- static ushort code(char c) { return uchar(c); }
- static char toAscii(char c) { return c; }
-};
-
-template <>
-struct FormattingTraits<EncodingDialog::Utf16>
-{
- static ushort code(ushort c) { return c; }
- static char toAscii(ushort c) { return char(c); }
-};
-
-template <>
-struct FormattingTraits<EncodingDialog::Utf32>
-{
- static uint code(uint c) { return c; }
- static char toAscii(uint c) { return char(c); }
-};
-
-template <>
-struct FormattingTraits<EncodingDialog::Latin1>
-{
- static uchar code(char c) { return uchar(c); }
- static char toAscii(char c) { return c; }
-};
-
-static bool isHexDigit(char c)
-{
- return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')
- || (c >= 'A' && c <= 'F');
-}
-
-template <EncodingDialog::Encoding encoding, class Iterator>
-static void formatStringSequence(QTextStream &str, Iterator i1, Iterator i2,
- int escapeIntegerBase, int escapeWidth,
- char escapePrefix = 0)
-{
- str << '"';
- bool separateHexEscape = false;
- for (; i1 != i2; ++i1) {
- const auto code = FormattingTraits<encoding>::code(*i1);
- if (code >= 0x80) {
- formatEscapedNumber(str, code, escapeIntegerBase, escapeWidth, escapePrefix);
- separateHexEscape = escapeIntegerBase == 16 && escapeWidth == 0;
- } else {
- if (!formatSpecialCharacter(str, code)) {
- const char c = FormattingTraits<encoding>::toAscii(*i1);
- // For variable width/hex: Terminate the literal to stop digit parsing
- // ("\x12" "34...").
- if (separateHexEscape && isHexDigit(c))
- str << "\" \"";
- str << c;
- }
- separateHexEscape = false;
- }
- }
- str << '"';
-}
-
-static QString encodedString(const QString &value, EncodingDialog::Encoding e)
-{
- QString result;
- QTextStream str(&result);
- switch (e) {
- case EncodingDialog::Unicode:
- formatStringSequence<EncodingDialog::Unicode>(str, value.cbegin(), value.cend(),
- 16, 4, 'u');
- break;
- case EncodingDialog::Utf8: {
- const QByteArray utf8 = value.toUtf8();
- str << "u8";
- formatStringSequence<EncodingDialog::Utf8>(str, utf8.cbegin(), utf8.cend(),
- 8, 3);
- }
- break;
- case EncodingDialog::Utf16: {
- auto utf16 = value.utf16();
- auto utf16End = utf16 + value.size();
- str << 'u';
- formatStringSequence<EncodingDialog::Utf16>(str, utf16, utf16End,
- 16, 0, 'x');
- }
- break;
- case EncodingDialog::Utf32: {
- auto utf32 = value.toUcs4();
- str << 'U';
- formatStringSequence<EncodingDialog::Utf32>(str, utf32.cbegin(), utf32.cend(),
- 16, 0, 'x');
- }
- break;
- case EncodingDialog::Latin1: {
- const QByteArray latin1 = value.toLatin1();
- formatStringSequence<EncodingDialog::Latin1>(str, latin1.cbegin(), latin1.cend(),
- 16, 0, 'x');
- }
- break;
- case EncodingDialog::EncodingCount:
- break;
- }
- return result;
-}
-
-// Dialog helpers
-
-static const char *encodingLabels[]
-{
- QT_TRANSLATE_NOOP("EncodingDialog", "Unicode:"),
- QT_TRANSLATE_NOOP("EncodingDialog", "UTF-8:"),
- QT_TRANSLATE_NOOP("EncodingDialog", "UTF-16:"),
- QT_TRANSLATE_NOOP("EncodingDialog", "UTF-32:"),
- QT_TRANSLATE_NOOP("EncodingDialog", "Latin1:")
-};
-
-static const char *encodingToolTips[]
-{
- QT_TRANSLATE_NOOP("EncodingDialog", "Unicode points for use with any encoding (C++, Python)"),
- QT_TRANSLATE_NOOP("EncodingDialog", "QString::fromUtf8()"),
- QT_TRANSLATE_NOOP("EncodingDialog", "wchar_t on Windows, char16_t everywhere"),
- QT_TRANSLATE_NOOP("EncodingDialog", "wchar_t on Unix (Ucs4)"),
- QT_TRANSLATE_NOOP("EncodingDialog", "QLatin1String")
-};
-
-// A read-only line edit with a tool button to copy the contents
-class DisplayLineEdit : public QLineEdit
-{
- Q_OBJECT
-public:
- explicit DisplayLineEdit(const QIcon &icon, QWidget *parent = nullptr);
-
-public slots:
- void copyAll();
-};
-
-DisplayLineEdit::DisplayLineEdit(const QIcon &icon, QWidget *parent) :
- QLineEdit(parent)
-{
- setReadOnly(true);
-#if QT_CONFIG(clipboard) && QT_CONFIG(action)
- auto copyAction = addAction(icon, QLineEdit::TrailingPosition);
- connect(copyAction, &QAction::triggered, this, &DisplayLineEdit::copyAll);
-#endif
-}
-
-void DisplayLineEdit::copyAll()
-{
-#if QT_CONFIG(clipboard)
- QGuiApplication::clipboard()->setText(text());
-#endif
-}
-
-static void addFormLayoutRow(QFormLayout *formLayout, const QString &text,
- QWidget *w, const QString &toolTip)
-{
- auto label = new QLabel(text);
- label->setToolTip(toolTip);
- w->setToolTip(toolTip);
- label->setBuddy(w);
- formLayout->addRow(label, w);
-}
-
-EncodingDialog::EncodingDialog(QWidget *parent) :
- QDialog(parent)
-{
- setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
- setWindowTitle(tr("Encodings"));
-
- auto formLayout = new QFormLayout;
- auto sourceLineEdit = new QLineEdit(this);
- sourceLineEdit->setClearButtonEnabled(true);
- connect(sourceLineEdit, &QLineEdit::textChanged, this, &EncodingDialog::textChanged);
-
- addFormLayoutRow(formLayout, tr("&Source:"), sourceLineEdit, tr("Enter text"));
-
- const auto copyIcon = QIcon::fromTheme(QLatin1String("edit-copy"),
- QIcon(QLatin1String(":/images/editcopy")));
- for (int i = 0; i < EncodingCount; ++i) {
- m_lineEdits[i] = new DisplayLineEdit(copyIcon, this);
- addFormLayoutRow(formLayout, tr(encodingLabels[i]),
- m_lineEdits[i], tr(encodingToolTips[i]));
- }
-
- auto mainLayout = new QVBoxLayout(this);
- mainLayout->addLayout(formLayout);
- auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
- connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
- mainLayout->addWidget(buttonBox);
-}
-
-void EncodingDialog::textChanged(const QString &t)
-{
- if (t.isEmpty()) {
- for (auto lineEdit : m_lineEdits)
- lineEdit->clear();
- } else {
- for (int i = 0; i < EncodingCount; ++i)
- m_lineEdits[i]->setText(encodedString(t, static_cast<Encoding>(i)));
- }
-}
-
-#include "encodingdialog.moc"
diff --git a/examples/widgets/tools/codecs/encodingdialog.h b/examples/widgets/tools/codecs/encodingdialog.h
deleted file mode 100644
index 3f82da84af..0000000000
--- a/examples/widgets/tools/codecs/encodingdialog.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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 ENCODINGDIALOG_H
-#define ENCODINGDIALOG_H
-
-#include <QDialog>
-
-QT_FORWARD_DECLARE_CLASS(QLineEdit)
-
-class EncodingDialog : public QDialog
-{
- Q_OBJECT
-public:
- explicit EncodingDialog(QWidget *parent = nullptr);
-
- enum Encoding { Unicode, Utf8, Utf16, Utf32, Latin1, EncodingCount };
-
-private slots:
- void textChanged(const QString &t);
-
-private:
- QLineEdit *m_lineEdits[EncodingCount];
-};
-
-#endif // ENCODINGDIALOG_H
diff --git a/examples/widgets/tools/codecs/images/editcopy.png b/examples/widgets/tools/codecs/images/editcopy.png
deleted file mode 100644
index 1121b47d8b..0000000000
--- a/examples/widgets/tools/codecs/images/editcopy.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/tools/codecs/main.cpp b/examples/widgets/tools/codecs/main.cpp
deleted file mode 100644
index ced1069dcb..0000000000
--- a/examples/widgets/tools/codecs/main.cpp
+++ /dev/null
@@ -1,61 +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 "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- MainWindow mainWin;
- mainWin.show();
- return app.exec();
-}
diff --git a/examples/widgets/tools/codecs/mainwindow.cpp b/examples/widgets/tools/codecs/mainwindow.cpp
deleted file mode 100644
index 2379eaf5cc..0000000000
--- a/examples/widgets/tools/codecs/mainwindow.cpp
+++ /dev/null
@@ -1,225 +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 "encodingdialog.h"
-#include "previewform.h"
-
-#include <QAction>
-#include <QApplication>
-#include <QFileDialog>
-#include <QMenuBar>
-#include <QMessageBox>
-#include <QPlainTextEdit>
-#include <QRegularExpression>
-#include <QScreen>
-#include <QTextCodec>
-#include <QTextStream>
-
-MainWindow::MainWindow()
-{
- textEdit = new QPlainTextEdit;
- textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
- setCentralWidget(textEdit);
-
- findCodecs();
-
- previewForm = new PreviewForm(this);
- previewForm->setCodecList(codecs);
-
- createMenus();
-
- setWindowTitle(tr("Codecs"));
-
- const QRect screenGeometry = screen()->geometry();
- resize(screenGeometry.width() / 2, screenGeometry.height() * 2 / 3);
-}
-
-void MainWindow::open()
-{
- const QString fileName = QFileDialog::getOpenFileName(this);
- if (fileName.isEmpty())
- return;
- QFile file(fileName);
- if (!file.open(QFile::ReadOnly)) {
- QMessageBox::warning(this, tr("Codecs"),
- tr("Cannot read file %1:\n%2")
- .arg(QDir::toNativeSeparators(fileName),
- file.errorString()));
- return;
- }
-
- const QByteArray data = file.readAll();
-
- previewForm->setWindowTitle(tr("Choose Encoding for %1").arg(QFileInfo(fileName).fileName()));
- previewForm->setEncodedData(data);
- if (previewForm->exec())
- textEdit->setPlainText(previewForm->decodedString());
-}
-
-void MainWindow::save()
-{
- const QAction *action = qobject_cast<const QAction *>(sender());
- const QByteArray codecName = action->data().toByteArray();
- const QString title = tr("Save As (%1)").arg(QLatin1String(codecName));
-
- QString fileName = QFileDialog::getSaveFileName(this, title);
- if (fileName.isEmpty())
- return;
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("Codecs"),
- tr("Cannot write file %1:\n%2")
- .arg(QDir::toNativeSeparators(fileName),
- file.errorString()));
- return;
- }
-
- QTextCodec *codec = QTextCodec::codecForName(codecName.constData());
- QByteArray text = codec->fromUnicode(textEdit->toPlainText());
- file.write(text);
-}
-
-void MainWindow::about()
-{
- QMessageBox::about(this, tr("About Codecs"),
- tr("The <b>Codecs</b> example demonstrates how to read and write "
- "files using various encodings."));
-}
-
-void MainWindow::aboutToShowSaveAsMenu()
-{
- const QString currentText = textEdit->toPlainText();
- for (QAction *action : qAsConst(saveAsActs)) {
- const QByteArray codecName = action->data().toByteArray();
- const QTextCodec *codec = QTextCodec::codecForName(codecName);
- action->setVisible(codec && codec->canEncode(currentText));
- }
-}
-
-void MainWindow::findCodecs()
-{
- QMap<QString, QTextCodec *> codecMap;
- QRegularExpression iso8859RegExp("^ISO[- ]8859-([0-9]+).*$");
- QRegularExpressionMatch match;
-
- const QList<int> mibs = QTextCodec::availableMibs();
- for (int mib : mibs) {
- QTextCodec *codec = QTextCodec::codecForMib(mib);
-
- QString sortKey = codec->name().toUpper();
- char rank;
-
- if (sortKey.startsWith(QLatin1String("UTF-8"))) {
- rank = 1;
- } else if (sortKey.startsWith(QLatin1String("UTF-16"))) {
- rank = 2;
- } else if ((match = iso8859RegExp.match(sortKey)).hasMatch()) {
- if (match.capturedView(1).size() == 1)
- rank = 3;
- else
- rank = 4;
- } else {
- rank = 5;
- }
- sortKey.prepend(QLatin1Char('0' + rank));
-
- codecMap.insert(sortKey, codec);
- }
- for (const auto &codec : qAsConst(codecMap))
- codecs += codec;
-}
-
-void MainWindow::createMenus()
-{
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
- QAction *openAct =
- fileMenu->addAction(tr("&Open..."), this, &MainWindow::open);
- openAct->setShortcuts(QKeySequence::Open);
-
- QMenu *saveAsMenu = fileMenu->addMenu(tr("&Save As"));
- connect(saveAsMenu, &QMenu::aboutToShow,
- this, &MainWindow::aboutToShowSaveAsMenu);
- for (const QTextCodec *codec : qAsConst(codecs)) {
- const QByteArray name = codec->name();
- QAction *action = saveAsMenu->addAction(tr("%1...").arg(QLatin1String(name)));
- action->setData(QVariant(name));
- connect(action, &QAction::triggered, this, &MainWindow::save);
- saveAsActs.append(action);
- }
-
- fileMenu->addSeparator();
- QAction *exitAct = fileMenu->addAction(tr("E&xit"), this, &QWidget::close);
- exitAct->setShortcuts(QKeySequence::Quit);
-
- auto toolMenu = menuBar()->addMenu(tr("&Tools"));
- auto encodingAction = toolMenu->addAction(tr("Encodings"), this, &MainWindow::encodingDialog);
- encodingAction->setShortcut(Qt::CTRL + Qt::Key_E);
- encodingAction->setToolTip(tr("Shows a dialog allowing to convert to common encoding in programming languages."));
-
-
- menuBar()->addSeparator();
-
- QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
- helpMenu->addAction(tr("&About"), this, &MainWindow::about);
- helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
-}
-
-void MainWindow::encodingDialog()
-{
- if (!m_encodingDialog) {
- m_encodingDialog = new EncodingDialog(this);
- const QRect screenGeometry = screen()->geometry();
- m_encodingDialog->setMinimumWidth(screenGeometry.width() / 4);
- }
- m_encodingDialog->show();
- m_encodingDialog->raise();
-
-}
diff --git a/examples/widgets/tools/codecs/mainwindow.h b/examples/widgets/tools/codecs/mainwindow.h
deleted file mode 100644
index cf18222520..0000000000
--- a/examples/widgets/tools/codecs/mainwindow.h
+++ /dev/null
@@ -1,91 +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 <QVector>
-#include <QMainWindow>
-
-QT_BEGIN_NAMESPACE
-class QAction;
-class QTextCodec;
-class QPlainTextEdit;
-QT_END_NAMESPACE
-
-class EncodingDialog;
-class PreviewForm;
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
-private slots:
- void open();
- void save();
- void about();
- void aboutToShowSaveAsMenu();
- void encodingDialog();
-
-private:
- void findCodecs();
- void createMenus();
-
- QVector<QAction *> saveAsActs;
- QPlainTextEdit *textEdit;
- PreviewForm *previewForm;
- QVector<QTextCodec *> codecs;
- EncodingDialog *m_encodingDialog = nullptr;
-};
-
-#endif
diff --git a/examples/widgets/tools/codecs/previewform.cpp b/examples/widgets/tools/codecs/previewform.cpp
deleted file mode 100644
index 80a99bf271..0000000000
--- a/examples/widgets/tools/codecs/previewform.cpp
+++ /dev/null
@@ -1,248 +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 "previewform.h"
-
-#include <QApplication>
-#include <QComboBox>
-#include <QDialogButtonBox>
-#include <QGridLayout>
-#include <QLabel>
-#include <QPlainTextEdit>
-#include <QPushButton>
-#include <QScreen>
-#include <QTextCodec>
-#include <QTextStream>
-
-// Helpers for creating hex dumps
-static void indent(QTextStream &str, int indent)
-{
- for (int i = 0; i < indent; ++i)
- str << ' ';
-}
-
-static void formatHex(QTextStream &str, const QByteArray &data)
-{
- const int fieldWidth = str.fieldWidth();
- const QTextStream::FieldAlignment alignment = str.fieldAlignment();
- const int base = str.integerBase();
- const QChar padChar = str.padChar();
- str.setIntegerBase(16);
- str.setPadChar(QLatin1Char('0'));
- str.setFieldAlignment(QTextStream::AlignRight);
-
- const unsigned char *p = reinterpret_cast<const unsigned char *>(data.constBegin());
- for (const unsigned char *end = p + data.size(); p < end; ++p) {
- str << ' ';
- str.setFieldWidth(2);
- str << unsigned(*p);
- str.setFieldWidth(fieldWidth);
- }
- str.setFieldAlignment(alignment);
- str.setPadChar(padChar);
- str.setIntegerBase(base);
-}
-
-static void formatPrintableCharacters(QTextStream &str, const QByteArray &data)
-{
- for (const char c : data) {
- switch (c) {
- case '\0':
- str << "\\0";
- break;
- case '\t':
- str << "\\t";
- break;
- case '\r':
- str << "\\r";
- break;
- case '\n':
- str << "\\n";
- break;
- default:
- if (c >= 32 && uchar(c) < 127)
- str << ' ' << c;
- else
- str << "..";
- break;
- }
- }
-}
-
-static QString formatHexDump(const QByteArray &data)
-{
- enum { lineWidth = 16 };
- QString result;
- QTextStream str(&result);
- str.setIntegerBase(16);
- str.setPadChar(QLatin1Char('0'));
- const int fieldWidth = str.fieldWidth();
- const QTextStream::FieldAlignment alignment = str.fieldAlignment();
- for (int a = 0, size = data.size(); a < size; a += lineWidth) {
- str.setFieldAlignment(QTextStream::AlignRight);
- str.setFieldWidth(8);
- str << a;
- str.setFieldWidth(fieldWidth);
- str.setFieldAlignment(alignment);
-
- const int end = qMin(a + lineWidth, size);
- const QByteArray line = data.mid(a, end - a);
-
- formatHex(str, line);
- indent(str, 3 * (lineWidth - line.size()));
-
- str << ' ';
- formatPrintableCharacters(str, line);
- indent(str, 2 * (lineWidth - line.size()));
- str << '\n';
- }
- return result;
-}
-
-PreviewForm::PreviewForm(QWidget *parent)
- : QDialog(parent)
-{
- setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
- encodingComboBox = new QComboBox;
-
- QLabel *encodingLabel = new QLabel(tr("&Encoding:"));
- encodingLabel->setBuddy(encodingComboBox);
-
- textEdit = new QPlainTextEdit;
- textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
- textEdit->setReadOnly(true);
- hexDumpEdit = new QPlainTextEdit;
- hexDumpEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
- hexDumpEdit->setReadOnly(true);
- hexDumpEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
-
- QDialogButtonBox *buttonBox =
- new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
- okButton = buttonBox->button(QDialogButtonBox::Ok);
-
- connect(encodingComboBox, &QComboBox::activated,
- this, &PreviewForm::updateTextEdit);
- connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
- connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
-
- QGridLayout *mainLayout = new QGridLayout(this);
- mainLayout->addWidget(encodingLabel, 0, 0);
- mainLayout->addWidget(encodingComboBox, 0, 1);
- tabWidget = new QTabWidget;
- tabWidget->addTab(textEdit, tr("Preview"));
- tabWidget->addTab(hexDumpEdit, tr("Hex Dump"));
- mainLayout->addWidget(tabWidget, 1, 0, 1, 2);
- statusLabel = new QLabel;
- mainLayout->addWidget(statusLabel, 2, 0, 1, 2);
- mainLayout->addWidget(buttonBox, 3, 0, 1, 2);
-
- const QRect screenGeometry = screen()->geometry();
- resize(screenGeometry.width() * 2 / 5, screenGeometry.height() / 2);
-}
-
-void PreviewForm::setCodecList(const QVector<QTextCodec *> &list)
-{
- encodingComboBox->clear();
- for (const QTextCodec *codec : list) {
- encodingComboBox->addItem(QLatin1String(codec->name()),
- QVariant(codec->mibEnum()));
- }
-}
-
-void PreviewForm::reset()
-{
- decodedStr.clear();
- textEdit->clear();
- hexDumpEdit->clear();
- statusLabel->clear();
- statusLabel->setStyleSheet(QString());
- okButton->setEnabled(false);
- tabWidget->setCurrentIndex(0);
-}
-
-void PreviewForm::setEncodedData(const QByteArray &data)
-{
- reset();
- encodedData = data;
- hexDumpEdit->setPlainText(formatHexDump(data));
- updateTextEdit();
-}
-
-void PreviewForm::updateTextEdit()
-{
- int mib = encodingComboBox->itemData(
- encodingComboBox->currentIndex()).toInt();
- const QTextCodec *codec = QTextCodec::codecForMib(mib);
- const QString name = QLatin1String(codec->name());
-
- QTextCodec::ConverterState state;
- decodedStr = codec->toUnicode(encodedData.constData(), encodedData.size(), &state);
-
- bool success = true;
- if (state.remainingChars) {
- success = false;
- const QString message =
- tr("%1: conversion error at character %2")
- .arg(name).arg(encodedData.size() - state.remainingChars + 1);
- statusLabel->setText(message);
- statusLabel->setStyleSheet(QStringLiteral("background-color: \"red\";"));
- } else if (state.invalidChars) {
- statusLabel->setText(tr("%1: %n invalid characters", nullptr, state.invalidChars).arg(name));
- statusLabel->setStyleSheet(QStringLiteral("background-color: \"yellow\";"));
- } else {
- statusLabel->setText(tr("%1: %n bytes converted", nullptr, encodedData.size()).arg(name));
- statusLabel->setStyleSheet(QString());
- }
- if (success)
- textEdit->setPlainText(decodedStr);
- else
- textEdit->clear();
- okButton->setEnabled(success);
-}
diff --git a/examples/widgets/tools/codecs/previewform.h b/examples/widgets/tools/codecs/previewform.h
deleted file mode 100644
index 02eb3533f3..0000000000
--- a/examples/widgets/tools/codecs/previewform.h
+++ /dev/null
@@ -1,95 +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 PREVIEWFORM_H
-#define PREVIEWFORM_H
-
-#include <QDialog>
-#include <QVector>
-
-QT_BEGIN_NAMESPACE
-class QComboBox;
-class QDialogButtonBox;
-class QLabel;
-class QPlainTextEdit;
-class QPushButton;
-class QTabWidget;
-class QTextCodec;
-QT_END_NAMESPACE
-
-class PreviewForm : public QDialog
-{
- Q_OBJECT
-
-public:
- explicit PreviewForm(QWidget *parent = nullptr);
-
- void setCodecList(const QVector<QTextCodec *> &list);
- void setEncodedData(const QByteArray &data);
- QString decodedString() const { return decodedStr; }
-
-private slots:
- void updateTextEdit();
-
-private:
- void reset();
-
- QByteArray encodedData;
- QString decodedStr;
-
- QPushButton *okButton;
- QTabWidget *tabWidget;
- QComboBox *encodingComboBox;
- QPlainTextEdit *textEdit;
- QPlainTextEdit *hexDumpEdit;
- QLabel *statusLabel;
-};
-
-#endif
diff --git a/examples/widgets/tools/tools.pro b/examples/widgets/tools/tools.pro
index 0e572a632b..d2a02deb6b 100644
--- a/examples/widgets/tools/tools.pro
+++ b/examples/widgets/tools/tools.pro
@@ -1,6 +1,5 @@
TEMPLATE = subdirs
SUBDIRS = \
- codecs \
completer \
customcompleter \
echoplugin \