diff options
Diffstat (limited to 'examples/widgets/widgets/charactermap')
-rw-r--r-- | examples/widgets/widgets/charactermap/CMakeLists.txt | 41 | ||||
-rw-r--r-- | examples/widgets/widgets/charactermap/charactermap.pro | 12 | ||||
-rw-r--r-- | examples/widgets/widgets/charactermap/characterwidget.cpp | 192 | ||||
-rw-r--r-- | examples/widgets/widgets/charactermap/characterwidget.h | 97 | ||||
-rw-r--r-- | examples/widgets/widgets/charactermap/main.cpp | 61 | ||||
-rw-r--r-- | examples/widgets/widgets/charactermap/mainwindow.cpp | 311 | ||||
-rw-r--r-- | examples/widgets/widgets/charactermap/mainwindow.h | 97 |
7 files changed, 0 insertions, 811 deletions
diff --git a/examples/widgets/widgets/charactermap/CMakeLists.txt b/examples/widgets/widgets/charactermap/CMakeLists.txt deleted file mode 100644 index 33980ce3b5..0000000000 --- a/examples/widgets/widgets/charactermap/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# Generated from charactermap.pro. - -cmake_minimum_required(VERSION 3.16) -project(charactermap 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/charactermap") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(charactermap - characterwidget.cpp characterwidget.h - main.cpp - mainwindow.cpp mainwindow.h -) -set_target_properties(charactermap PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(charactermap PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets -) - -install(TARGETS charactermap - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/widgets/charactermap/charactermap.pro b/examples/widgets/widgets/charactermap/charactermap.pro deleted file mode 100644 index 373aabca73..0000000000 --- a/examples/widgets/widgets/charactermap/charactermap.pro +++ /dev/null @@ -1,12 +0,0 @@ -QT += widgets -requires(qtConfig(combobox)) - -HEADERS = characterwidget.h \ - mainwindow.h -SOURCES = characterwidget.cpp \ - mainwindow.cpp \ - main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/charactermap -INSTALLS += target diff --git a/examples/widgets/widgets/charactermap/characterwidget.cpp b/examples/widgets/widgets/charactermap/characterwidget.cpp deleted file mode 100644 index a9d5a06164..0000000000 --- a/examples/widgets/widgets/charactermap/characterwidget.cpp +++ /dev/null @@ -1,192 +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 "characterwidget.h" - -#include <QFontDatabase> -#include <QMouseEvent> -#include <QPainter> -#include <QToolTip> - -//! [0] -CharacterWidget::CharacterWidget(QWidget *parent) - : QWidget(parent) -{ - calculateSquareSize(); - setMouseTracking(true); -} -//! [0] - -//! [1] -void CharacterWidget::updateFont(const QFont &font) -{ - displayFont.setFamily(font.family()); - calculateSquareSize(); - adjustSize(); - update(); -} -//! [1] - -//! [2] -void CharacterWidget::updateSize(const QString &fontSize) -{ - displayFont.setPointSize(fontSize.toInt()); - calculateSquareSize(); - adjustSize(); - update(); -} -//! [2] - -void CharacterWidget::updateStyle(const QString &fontStyle) -{ - const QFont::StyleStrategy oldStrategy = displayFont.styleStrategy(); - displayFont = QFontDatabase::font(displayFont.family(), fontStyle, displayFont.pointSize()); - displayFont.setStyleStrategy(oldStrategy); - calculateSquareSize(); - adjustSize(); - update(); -} - -void CharacterWidget::updateFontMerging(bool enable) -{ - if (enable) - displayFont.setStyleStrategy(QFont::PreferDefault); - else - displayFont.setStyleStrategy(QFont::NoFontMerging); - adjustSize(); - update(); -} - -void CharacterWidget::calculateSquareSize() -{ - squareSize = qMax(16, 4 + QFontMetrics(displayFont, this).height()); -} - -//! [3] -QSize CharacterWidget::sizeHint() const -{ - return QSize(columns*squareSize, (65536 / columns) * squareSize); -} -//! [3] - -//! [4] -void CharacterWidget::mouseMoveEvent(QMouseEvent *event) -{ - QPoint widgetPosition = mapFromGlobal(event->globalPosition().toPoint()); - uint key = (widgetPosition.y() / squareSize) * columns + widgetPosition.x() / squareSize; - - QString text = QString::fromLatin1("<p>Character: <span style=\"font-size: 24pt; font-family: %1\">").arg(displayFont.family()) - + QChar(key) - + QString::fromLatin1("</span><p>Value: 0x") - + QString::number(key, 16); - QToolTip::showText(event->globalPosition().toPoint(), text, this); -} -//! [4] - -//! [5] -void CharacterWidget::mousePressEvent(QMouseEvent *event) -{ - if (event->button() == Qt::LeftButton) { - lastKey = (event->position().toPoint().y() / squareSize) * columns + event->position().toPoint().x() / squareSize; - if (QChar(lastKey).category() != QChar::Other_NotAssigned) - emit characterSelected(QString(QChar(lastKey))); - update(); - } - else - QWidget::mousePressEvent(event); -} -//! [5] - -//! [6] -void CharacterWidget::paintEvent(QPaintEvent *event) -{ - QPainter painter(this); - painter.fillRect(event->rect(), QBrush(Qt::white)); - painter.setFont(displayFont); -//! [6] - -//! [7] - QRect redrawRect = event->rect(); - int beginRow = redrawRect.top() / squareSize; - int endRow = redrawRect.bottom() / squareSize; - int beginColumn = redrawRect.left() / squareSize; - int endColumn = redrawRect.right() / squareSize; -//! [7] - -//! [8] - painter.setPen(QPen(Qt::gray)); - for (int row = beginRow; row <= endRow; ++row) { - for (int column = beginColumn; column <= endColumn; ++column) { - painter.drawRect(column * squareSize, row * squareSize, squareSize, squareSize); - } -//! [8] //! [9] - } -//! [9] - -//! [10] - QFontMetrics fontMetrics(displayFont); - painter.setPen(QPen(Qt::black)); - for (int row = beginRow; row <= endRow; ++row) { - for (int column = beginColumn; column <= endColumn; ++column) { - int key = row * columns + column; - painter.setClipRect(column * squareSize, row * squareSize, squareSize, squareSize); - - if (key == lastKey) - painter.fillRect(column * squareSize + 1, row * squareSize + 1, - squareSize, squareSize, QBrush(Qt::red)); - - painter.drawText(column * squareSize + (squareSize / 2) - - fontMetrics.horizontalAdvance(QChar(key)) / 2, - row * squareSize + 4 + fontMetrics.ascent(), - QString(QChar(key))); - } - } -} -//! [10] diff --git a/examples/widgets/widgets/charactermap/characterwidget.h b/examples/widgets/widgets/charactermap/characterwidget.h deleted file mode 100644 index 67ac8a30bf..0000000000 --- a/examples/widgets/widgets/charactermap/characterwidget.h +++ /dev/null @@ -1,97 +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 CHARACTERWIDGET_H -#define CHARACTERWIDGET_H - -#include <QFont> -#include <QSize> -#include <QString> -#include <QWidget> - -QT_BEGIN_NAMESPACE -class QMouseEvent; -class QPaintEvent; -QT_END_NAMESPACE - -//! [0] -class CharacterWidget : public QWidget -{ - Q_OBJECT - -public: - CharacterWidget(QWidget *parent = nullptr); - QSize sizeHint() const override; - -public slots: - void updateFont(const QFont &font); - void updateSize(const QString &fontSize); - void updateStyle(const QString &fontStyle); - void updateFontMerging(bool enable); - -signals: - void characterSelected(const QString &character); - -protected: - void mouseMoveEvent(QMouseEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; - void paintEvent(QPaintEvent *event) override; - -private: - void calculateSquareSize(); - - QFont displayFont; - int columns = 16; - int lastKey = -1; - int squareSize = 0; -}; -//! [0] - -#endif diff --git a/examples/widgets/widgets/charactermap/main.cpp b/examples/widgets/widgets/charactermap/main.cpp deleted file mode 100644 index 1bf46b226f..0000000000 --- a/examples/widgets/widgets/charactermap/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 window; - window.show(); - return app.exec(); -} diff --git a/examples/widgets/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp deleted file mode 100644 index cfe0be96ca..0000000000 --- a/examples/widgets/widgets/charactermap/mainwindow.cpp +++ /dev/null @@ -1,311 +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 "characterwidget.h" - -#include <QApplication> -#include <QBoxLayout> -#include <QCheckBox> -#include <QClipboard> -#include <QDialog> -#include <QDialogButtonBox> -#include <QFontComboBox> -#include <QLabel> -#include <QLineEdit> -#include <QMenuBar> -#include <QPlainTextEdit> -#include <QPushButton> -#include <QScreen> -#include <QScrollArea> -#include <QStatusBar> -#include <QTextStream> - -//! [0] -Q_DECLARE_METATYPE(QFontComboBox::FontFilter) - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) -{ - QMenu *fileMenu = menuBar()->addMenu(tr("File")); - fileMenu->addAction(tr("Quit"), this, &QWidget::close); - QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); - helpMenu->addAction(tr("Show Font Info"), this, &MainWindow::showInfo); - helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); - - QWidget *centralWidget = new QWidget; - - QLabel *filterLabel = new QLabel(tr("Filter:")); - filterCombo = new QComboBox; - filterCombo->addItem(tr("All"), QVariant::fromValue(QFontComboBox::AllFonts)); - filterCombo->addItem(tr("Scalable"), QVariant::fromValue(QFontComboBox::ScalableFonts)); - filterCombo->addItem(tr("Monospaced"), QVariant::fromValue(QFontComboBox::MonospacedFonts)); - filterCombo->addItem(tr("Proportional"), QVariant::fromValue(QFontComboBox::ProportionalFonts)); - filterCombo->setCurrentIndex(0); - connect(filterCombo, &QComboBox::currentIndexChanged, - this, &MainWindow::filterChanged); - - QLabel *fontLabel = new QLabel(tr("Font:")); - fontCombo = new QFontComboBox; - QLabel *sizeLabel = new QLabel(tr("Size:")); - sizeCombo = new QComboBox; - QLabel *styleLabel = new QLabel(tr("Style:")); - styleCombo = new QComboBox; - QLabel *fontMergingLabel = new QLabel(tr("Automatic Font Merging:")); - fontMerging = new QCheckBox; - fontMerging->setChecked(true); - - scrollArea = new QScrollArea; - characterWidget = new CharacterWidget; - scrollArea->setWidget(characterWidget); -//! [0] - -//! [1] - findStyles(fontCombo->currentFont()); -//! [1] - findSizes(fontCombo->currentFont()); - -//! [2] - lineEdit = new QLineEdit; - lineEdit->setClearButtonEnabled(true); -#ifndef QT_NO_CLIPBOARD - QPushButton *clipboardButton = new QPushButton(tr("&To clipboard")); -//! [2] - -#endif - -//! [4] - connect(fontCombo, &QFontComboBox::currentFontChanged, - this, &MainWindow::findStyles); - connect(fontCombo, &QFontComboBox::currentFontChanged, - this, &MainWindow::findSizes); - connect(fontCombo, &QFontComboBox::currentFontChanged, - characterWidget, &CharacterWidget::updateFont); - connect(sizeCombo, &QComboBox::currentTextChanged, - characterWidget, &CharacterWidget::updateSize); - connect(styleCombo, &QComboBox::currentTextChanged, - characterWidget, &CharacterWidget::updateStyle); -//! [4] //! [5] - connect(characterWidget, &CharacterWidget::characterSelected, - this, &MainWindow::insertCharacter); - -#ifndef QT_NO_CLIPBOARD - connect(clipboardButton, &QAbstractButton::clicked, this, &MainWindow::updateClipboard); -#endif -//! [5] - connect(fontMerging, &QAbstractButton::toggled, characterWidget, &CharacterWidget::updateFontMerging); - -//! [6] - QHBoxLayout *controlsLayout = new QHBoxLayout; - controlsLayout->addWidget(filterLabel); - controlsLayout->addWidget(filterCombo, 1); - controlsLayout->addWidget(fontLabel); - controlsLayout->addWidget(fontCombo, 1); - controlsLayout->addWidget(sizeLabel); - controlsLayout->addWidget(sizeCombo, 1); - controlsLayout->addWidget(styleLabel); - controlsLayout->addWidget(styleCombo, 1); - controlsLayout->addWidget(fontMergingLabel); - controlsLayout->addWidget(fontMerging, 1); - controlsLayout->addStretch(1); - - QHBoxLayout *lineLayout = new QHBoxLayout; - lineLayout->addWidget(lineEdit, 1); - lineLayout->addSpacing(12); -#ifndef QT_NO_CLIPBOARD - lineLayout->addWidget(clipboardButton); -#endif - - QVBoxLayout *centralLayout = new QVBoxLayout; - centralLayout->addLayout(controlsLayout); - centralLayout->addWidget(scrollArea, 1); - centralLayout->addSpacing(4); - centralLayout->addLayout(lineLayout); - centralWidget->setLayout(centralLayout); - - setCentralWidget(centralWidget); - setWindowTitle(tr("Character Map")); -} -//! [6] - -//! [7] -void MainWindow::findStyles(const QFont &font) -{ - QString currentItem = styleCombo->currentText(); - styleCombo->clear(); -//! [7] - -//! [8] - const QStringList styles = QFontDatabase::styles(font.family()); - for (const QString &style : styles) - styleCombo->addItem(style); - - int styleIndex = styleCombo->findText(currentItem); - - if (styleIndex == -1) - styleCombo->setCurrentIndex(0); - else - styleCombo->setCurrentIndex(styleIndex); -} -//! [8] - -void MainWindow::filterChanged(int f) -{ - const QFontComboBox::FontFilter filter = - qvariant_cast<QFontComboBox::FontFilter>(filterCombo->itemData(f)); - fontCombo->setFontFilters(filter); - statusBar()->showMessage(tr("%n font(s) found", nullptr, fontCombo->count())); -} - -void MainWindow::findSizes(const QFont &font) -{ - QString currentSize = sizeCombo->currentText(); - - { - const QSignalBlocker blocker(sizeCombo); - // sizeCombo signals are now blocked until end of scope - sizeCombo->clear(); - - if (QFontDatabase::isSmoothlyScalable(font.family(), QFontDatabase::styleString(font))) { - const QList<int> sizes = QFontDatabase::standardSizes(); - for (const int size : sizes) { - sizeCombo->addItem(QVariant(size).toString()); - sizeCombo->setEditable(true); - } - - } else { - const QList<int> sizes = QFontDatabase::smoothSizes(font.family(), QFontDatabase::styleString(font)); - for (const int size : sizes ) { - sizeCombo->addItem(QVariant(size).toString()); - sizeCombo->setEditable(false); - } - } - } - - int sizeIndex = sizeCombo->findText(currentSize); - - if(sizeIndex == -1) - sizeCombo->setCurrentIndex(qMax(0, sizeCombo->count() / 3)); - else - sizeCombo->setCurrentIndex(sizeIndex); -} - -//! [9] -void MainWindow::insertCharacter(const QString &character) -{ - lineEdit->insert(character); -} -//! [9] - -//! [10] -#ifndef QT_NO_CLIPBOARD -void MainWindow::updateClipboard() -{ -//! [11] - QGuiApplication::clipboard()->setText(lineEdit->text(), QClipboard::Clipboard); -//! [11] - QGuiApplication::clipboard()->setText(lineEdit->text(), QClipboard::Selection); -} -#endif - -class FontInfoDialog : public QDialog -{ -public: - explicit FontInfoDialog(QWidget *parent = nullptr); - -private: - QString text() const; -}; - -FontInfoDialog::FontInfoDialog(QWidget *parent) : QDialog(parent) -{ - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - QVBoxLayout *mainLayout = new QVBoxLayout(this); - QPlainTextEdit *textEdit = new QPlainTextEdit(text(), this); - textEdit->setReadOnly(true); - textEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); - mainLayout->addWidget(textEdit); - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this); - connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); - mainLayout->addWidget(buttonBox); -} - -QString FontInfoDialog::text() const -{ - QString text; - QTextStream str(&text); - const QFont defaultFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont); - const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); - const QFont titleFont = QFontDatabase::systemFont(QFontDatabase::TitleFont); - const QFont smallestReadableFont = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont); - - str << "Qt " << QT_VERSION_STR << " on " << QGuiApplication::platformName() - << ", " << logicalDpiX() << "DPI"; - if (!qFuzzyCompare(devicePixelRatio(), qreal(1))) - str << ", device pixel ratio: " << devicePixelRatio(); - str << "\n\nDefault font : " << defaultFont.family() << ", " << defaultFont.pointSizeF() << "pt\n" - << "Fixed font : " << fixedFont.family() << ", " << fixedFont.pointSizeF() << "pt\n" - << "Title font : " << titleFont.family() << ", " << titleFont.pointSizeF() << "pt\n" - << "Smallest font: " << smallestReadableFont.family() << ", " << smallestReadableFont.pointSizeF() << "pt\n"; - - return text; -} - -void MainWindow::showInfo() -{ - const QRect screenGeometry = screen()->geometry(); - FontInfoDialog *dialog = new FontInfoDialog(this); - dialog->setWindowTitle(tr("Fonts")); - dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->resize(screenGeometry.width() / 4, screenGeometry.height() / 4); - dialog->show(); -} - -//! [10] diff --git a/examples/widgets/widgets/charactermap/mainwindow.h b/examples/widgets/widgets/charactermap/mainwindow.h deleted file mode 100644 index 79fe9f9cc8..0000000000 --- a/examples/widgets/widgets/charactermap/mainwindow.h +++ /dev/null @@ -1,97 +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 <QMainWindow> -#include <QString> - -QT_BEGIN_NAMESPACE -class QClipboard; -class QComboBox; -class QFontComboBox; -class QLineEdit; -class QScrollArea; -class QCheckBox; -QT_END_NAMESPACE -class CharacterWidget; - -//! [0] -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = nullptr); - -public slots: - void filterChanged(int); - void findStyles(const QFont &font); - void findSizes(const QFont &font); - void insertCharacter(const QString &character); -#ifndef QT_NO_CLIPBOARD - void updateClipboard(); -#endif - void showInfo(); - -private: - CharacterWidget *characterWidget; - QComboBox *filterCombo; - QComboBox *styleCombo; - QComboBox *sizeCombo; - QFontComboBox *fontCombo; - QLineEdit *lineEdit; - QScrollArea *scrollArea; - QCheckBox *fontMerging; -}; -//! [0] - -#endif |