summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-26 13:31:48 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-26 23:15:01 +0200
commit288c7ef5570f2badf5781a744ab2ba2d6f18b183 (patch)
tree700dee979706fee86726a383ea75edf4f9870f80 /examples/widgets
parentf3cf1fd760e9960d599be165f5369d305b442d16 (diff)
Move calendar example to manual test
Pick-to: 6.5 6.6 Change-Id: Ie2215ae0feeb322888619aed632e20db9b69e20b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/doc/images/calendar-example.pngbin13539 -> 0 bytes
-rw-r--r--examples/widgets/doc/src/calendar.qdoc202
-rw-r--r--examples/widgets/richtext/CMakeLists.txt1
-rw-r--r--examples/widgets/richtext/calendar/CMakeLists.txt37
-rw-r--r--examples/widgets/richtext/calendar/calendar.pro10
-rw-r--r--examples/widgets/richtext/calendar/main.cpp15
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.cpp179
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.h36
-rw-r--r--examples/widgets/richtext/richtext.pro3
9 files changed, 1 insertions, 482 deletions
diff --git a/examples/widgets/doc/images/calendar-example.png b/examples/widgets/doc/images/calendar-example.png
deleted file mode 100644
index 895ce76b09..0000000000
--- a/examples/widgets/doc/images/calendar-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/src/calendar.qdoc b/examples/widgets/doc/src/calendar.qdoc
deleted file mode 100644
index 218ea5ea0c..0000000000
--- a/examples/widgets/doc/src/calendar.qdoc
+++ /dev/null
@@ -1,202 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example richtext/calendar
- \title Calendar Example
- \ingroup examples-richtext
- \brief The Calendar example shows how to create rich text content
- and display it using a rich text editor.
-
- \brief The Calendar example shows how to create rich text content and display it using
- a rich text editor.
-
- \image calendar-example.png
-
- Specifically, the example demonstrates the following:
-
- \list
- \li Use of a text editor with a text document
- \li Insertion of tables and frames into a document
- \li Navigation within a table
- \li Insert text in different styles
- \endlist
-
- The rich text editor used to display the document is used within a main window
- application.
-
- \section1 MainWindow Class Definition
-
- The \c MainWindow class provides a text editor widget and some controls to
- allow the user to change the month and year shown. The font size used for the
- text can also be adjusted.
-
- \snippet richtext/calendar/mainwindow.h 0
-
- The private \c insertCalendar() function performs most of the work, relying on
- the \c fontSize and \c selectedDate variables to write useful information to
- the \c editor.
-
- \section1 MainWindow Class Implementation
-
- The \c MainWindow constructor sets up the user interface and initializes
- variables used to generate a calendar for each month.
-
- \snippet richtext/calendar/mainwindow.cpp 0
-
- We begin by setting default values for the selected date that will be highlighted
- in the calendar and the font size to be used. Since we are using a QMainWindow
- for the user interface, we construct a widget for use as the central widget.
-
- The user interface will include a line of controls above the generated calendar;
- we construct a label and a combobox to allow the month to be selected, and a
- spin box for the year. These widgets are configured to provide a reasonable range
- of values for the user to try:
-
- \snippet richtext/calendar/mainwindow.cpp 1
-
- We use the \c selectedDate object to obtain the current month and year, and we
- set these in the combobox and spin box:
-
- The font size is displayed in a spin box which we restrict to a sensible range
- of values:
-
- \snippet richtext/calendar/mainwindow.cpp 2
-
- We construct an editor and use the \c insertCalendar() function to create
- a calendar for it. Each calendar is displayed in the same text editor; in
- this example we use a QTextBrowser since we do not allow the calendar to be
- edited.
-
- The controls used to set the month, year, and font size will not have any
- effect on the appearance of the calendar unless we make some signal-slot
- connections:
-
- \snippet richtext/calendar/mainwindow.cpp 3
-
- The signals are connected to some simple slots in the \c MainWindow class
- which we will describe later.
-
- We create layouts to manage the widgets we constructed:
-
- \snippet richtext/calendar/mainwindow.cpp 4
-
- Finally, the central widget is set for the window.
-
- Each calendar is created for the editor by the \c insertCalendar() function
- which uses the date and font size, defined by the private \a selectedDate
- and \c fontSize variables, to produce a suitable plan for the specified
- month and year.
-
- \snippet richtext/calendar/mainwindow.cpp 5
-
- We begin by clearing the editor's rich text document, and obtain a text
- cursor from the editor that we will use to add content. We also create a
- QDate object based on the currently selected date.
-
- The calendar is made up of a table with a gray background color that contains
- seven columns: one for each day of the week. It is placed in the center of the
- page with equal space to the left and right of it. All of these properties are
- set in a QTextTableFormat object:
-
- \snippet richtext/calendar/mainwindow.cpp 6
-
- Each cell in the table will be padded and spaced to make the text easier to
- read.
-
- We want the columns to have equal widths, so we provide a list containing
- percentage widths for each of them and set the constraints in the
- QTextTableFormat:
-
- \snippet richtext/calendar/mainwindow.cpp 7
-
- The constraints used for the column widths are only useful if the table has
- an appropriate number of columns. With the format for the table defined, we
- construct a new table with one row and seven columns at the current cursor
- position:
-
- \snippet richtext/calendar/mainwindow.cpp 8
-
- We only need one row to start with; more can be added as we need them. Using
- this approach means that we do not need to perform any date calculations
- until we add cells to the table.
-
- When inserting objects into a document with the cursor's insertion functions,
- the cursor is automatically moved inside the newly inserted object. This means
- that we can immediately start modifying the table from within:
-
- \snippet richtext/calendar/mainwindow.cpp 9
-
- Since the table has an outer frame, we obtain the frame and its format so that
- we can customize it. After making the changes we want, we set the frame's format
- using the modified format object. We have given the table an outer border one
- pixel wide.
-
- \snippet richtext/calendar/mainwindow.cpp 10
-
- In a similar way, we obtain the cursor's current character format and
- create customized formats based on it.
-
- We do not set the format on the cursor because this would change the default
- character format; instead, we use the customized formats explicitly when we
- insert text. The following loop inserts the days of the week into the table
- as bold text:
-
- \snippet richtext/calendar/mainwindow.cpp 11
-
- For each day of the week, we obtain an existing table cell in the first row
- (row 0) using the table's \l{QTextTable::cellAt()}{cellAt()} function. Since
- we start counting the days of the week at day 1 (Monday), we subtract 1 from
- \c weekDay to ensure that we obtain the cell for the correct column of the
- table.
-
- Before text can be inserted into a cell, we must obtain a cursor with the
- correct position in the document. The cell provides a function for this
- purpose, and we use this cursor to insert text using the \c boldFormat
- character format that we created earlier:
-
- \snippet richtext/calendar/mainwindow.cpp 12
-
- Inserting text into document objects usually follows the same pattern.
- Each object can provide a new cursor that corresponds to the first valid
- position within itself, and this can be used to insert new content. We
- continue to use this pattern as we insert the days of the month into the
- table.
-
- Since every month has more than seven days, we insert a single row to begin
- and add days until we reach the end of the month. If the current date is
- encountered, it is inserted with a special format (created earlier) that
- makes it stand out:
-
- \snippet richtext/calendar/mainwindow.cpp 13
-
- We add a new row to the table at the end of each week only if the next week
- falls within the currently selected month.
-
- For each calendar that we create, we change the window title to reflect the
- currently selected month and year:
-
- \snippet richtext/calendar/mainwindow.cpp 14
-
- The \c insertCalendar() function relies on up-to-date values for the month,
- year, and font size. These are set in the following slots:
-
- \snippet richtext/calendar/mainwindow.cpp 15
-
- The \c setFontSize() function simply changes the private \c fontSize variable
- before updating the calendar.
-
- \snippet richtext/calendar/mainwindow.cpp 16
-
- The \c setMonth slot is called when the QComboBox used to select the month is
- updated. The value supplied is the currently selected row in the combobox.
- We add 1 to this value to obtain a valid month number, and create a new QDate
- based on the existing one. The calendar is then updated to use this new date.
-
- \snippet richtext/calendar/mainwindow.cpp 17
-
- The \c setYear() slot is called when the QDateTimeEdit used to select the
- year is updated. The value supplied is a QDate object; this makes
- the construction of a new value for \c selectedDate simple. We update the
- calendar afterwards to use this new date.
-*/
diff --git a/examples/widgets/richtext/CMakeLists.txt b/examples/widgets/richtext/CMakeLists.txt
index ea4165b764..6fe7ea0c5e 100644
--- a/examples/widgets/richtext/CMakeLists.txt
+++ b/examples/widgets/richtext/CMakeLists.txt
@@ -1,7 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-qt_internal_add_example(calendar)
qt_internal_add_example(orderform)
qt_internal_add_example(syntaxhighlighter)
qt_internal_add_example(textedit)
diff --git a/examples/widgets/richtext/calendar/CMakeLists.txt b/examples/widgets/richtext/calendar/CMakeLists.txt
deleted file mode 100644
index 569e508af4..0000000000
--- a/examples/widgets/richtext/calendar/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(calendar LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/richtext/calendar")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(calendar
- main.cpp
- mainwindow.cpp mainwindow.h
-)
-
-set_target_properties(calendar PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(calendar PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS calendar
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/richtext/calendar/calendar.pro b/examples/widgets/richtext/calendar/calendar.pro
deleted file mode 100644
index 199c1dbb8d..0000000000
--- a/examples/widgets/richtext/calendar/calendar.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-QT += widgets
-requires(qtConfig(combobox))
-
-HEADERS = mainwindow.h
-SOURCES = main.cpp \
- mainwindow.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/richtext/calendar
-INSTALLS += target
diff --git a/examples/widgets/richtext/calendar/main.cpp b/examples/widgets/richtext/calendar/main.cpp
deleted file mode 100644
index 5641ae527a..0000000000
--- a/examples/widgets/richtext/calendar/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.resize(640, 256);
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/richtext/calendar/mainwindow.cpp b/examples/widgets/richtext/calendar/mainwindow.cpp
deleted file mode 100644
index 0b44c96d46..0000000000
--- a/examples/widgets/richtext/calendar/mainwindow.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-
-#include <QtWidgets>
-
-//! [0]
-MainWindow::MainWindow()
-{
- selectedDate = QDate::currentDate();
- fontSize = 10;
-
- QWidget *centralWidget = new QWidget;
-//! [0]
-
-//! [1]
- QLabel *dateLabel = new QLabel(tr("Date:"));
- QComboBox *monthCombo = new QComboBox;
-
- for (int month = 1; month <= 12; ++month)
- monthCombo->addItem(QLocale::system().monthName(month));
-
- QDateTimeEdit *yearEdit = new QDateTimeEdit;
- yearEdit->setDisplayFormat("yyyy");
- yearEdit->setDateRange(QDate(1753, 1, 1), QDate(8000, 1, 1));
-//! [1]
-
- monthCombo->setCurrentIndex(selectedDate.month() - 1);
- yearEdit->setDate(selectedDate);
-
-//! [2]
- QLabel *fontSizeLabel = new QLabel(tr("Font size:"));
- QSpinBox *fontSizeSpinBox = new QSpinBox;
- fontSizeSpinBox->setRange(1, 64);
-
- editor = new QTextBrowser;
- insertCalendar();
-//! [2]
-
-//! [3]
- connect(monthCombo, &QComboBox::activated,
- this, &MainWindow::setMonth);
- connect(yearEdit, &QDateTimeEdit::dateChanged,
- this, &MainWindow::setYear);
- connect(fontSizeSpinBox, &QSpinBox::valueChanged,
- this, &MainWindow::setFontSize);
-//! [3]
-
- fontSizeSpinBox->setValue(10);
-
-//! [4]
- QHBoxLayout *controlsLayout = new QHBoxLayout;
- controlsLayout->addWidget(dateLabel);
- controlsLayout->addWidget(monthCombo);
- controlsLayout->addWidget(yearEdit);
- controlsLayout->addSpacing(24);
- controlsLayout->addWidget(fontSizeLabel);
- controlsLayout->addWidget(fontSizeSpinBox);
- controlsLayout->addStretch(1);
-
- QVBoxLayout *centralLayout = new QVBoxLayout;
- centralLayout->addLayout(controlsLayout);
- centralLayout->addWidget(editor, 1);
- centralWidget->setLayout(centralLayout);
-
- setCentralWidget(centralWidget);
-//! [4]
-}
-
-//! [5]
-void MainWindow::insertCalendar()
-{
- editor->clear();
- QTextCursor cursor = editor->textCursor();
- cursor.beginEditBlock();
-
- QDate date(selectedDate.year(), selectedDate.month(), 1);
-//! [5]
-
-//! [6]
- QTextTableFormat tableFormat;
- tableFormat.setAlignment(Qt::AlignHCenter);
- tableFormat.setBackground(QColor("#e0e0e0"));
- tableFormat.setCellPadding(2);
- tableFormat.setCellSpacing(4);
-//! [6] //! [7]
- QList<QTextLength> constraints;
- constraints << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14);
- tableFormat.setColumnWidthConstraints(constraints);
-//! [7]
-
-//! [8]
- QTextTable *table = cursor.insertTable(1, 7, tableFormat);
-//! [8]
-
-//! [9]
- QTextFrame *frame = cursor.currentFrame();
- QTextFrameFormat frameFormat = frame->frameFormat();
- frameFormat.setBorder(1);
- frame->setFrameFormat(frameFormat);
-//! [9]
-
-//! [10]
- QTextCharFormat format = cursor.charFormat();
- format.setFontPointSize(fontSize);
-
- QTextCharFormat boldFormat = format;
- boldFormat.setFontWeight(QFont::Bold);
-
- QTextCharFormat highlightedFormat = boldFormat;
- highlightedFormat.setBackground(Qt::yellow);
-//! [10]
-
-//! [11]
- for (int weekDay = 1; weekDay <= 7; ++weekDay) {
- QTextTableCell cell = table->cellAt(0, weekDay-1);
-//! [11] //! [12]
- QTextCursor cellCursor = cell.firstCursorPosition();
- cellCursor.insertText(QLocale::system().dayName(weekDay), boldFormat);
- }
-//! [12]
-
-//! [13]
- table->insertRows(table->rows(), 1);
-//! [13]
-
- while (date.month() == selectedDate.month()) {
- int weekDay = date.dayOfWeek();
- QTextTableCell cell = table->cellAt(table->rows()-1, weekDay-1);
- QTextCursor cellCursor = cell.firstCursorPosition();
-
- if (date == QDate::currentDate())
- cellCursor.insertText(QString("%1").arg(date.day()), highlightedFormat);
- else
- cellCursor.insertText(QString("%1").arg(date.day()), format);
-
- date = date.addDays(1);
- if (weekDay == 7 && date.month() == selectedDate.month())
- table->insertRows(table->rows(), 1);
- }
-
- cursor.endEditBlock();
-//! [14]
- setWindowTitle(tr("Calendar for %1 %2"
- ).arg(QLocale::system().monthName(selectedDate.month())
- ).arg(selectedDate.year()));
-}
-//! [14]
-
-//! [15]
-void MainWindow::setFontSize(int size)
-{
- fontSize = size;
- insertCalendar();
-}
-//! [15]
-
-//! [16]
-void MainWindow::setMonth(int month)
-{
- selectedDate = QDate(selectedDate.year(), month + 1, selectedDate.day());
- insertCalendar();
-}
-//! [16]
-
-//! [17]
-void MainWindow::setYear(QDate date)
-{
- selectedDate = QDate(date.year(), selectedDate.month(), selectedDate.day());
- insertCalendar();
-}
-//! [17]
diff --git a/examples/widgets/richtext/calendar/mainwindow.h b/examples/widgets/richtext/calendar/mainwindow.h
deleted file mode 100644
index 76632820d6..0000000000
--- a/examples/widgets/richtext/calendar/mainwindow.h
+++ /dev/null
@@ -1,36 +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 <QDate>
-#include <QMainWindow>
-
-QT_BEGIN_NAMESPACE
-class QTextBrowser;
-QT_END_NAMESPACE
-
-//! [0]
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
-public slots:
- void setFontSize(int size);
- void setMonth(int month);
- void setYear(QDate date);
-
-private:
- void insertCalendar();
-
- int fontSize;
- QDate selectedDate;
- QTextBrowser *editor;
-};
-//! [0]
-
-#endif // MAINWINDOW_H
diff --git a/examples/widgets/richtext/richtext.pro b/examples/widgets/richtext/richtext.pro
index 499733ecec..40b41ff81b 100644
--- a/examples/widgets/richtext/richtext.pro
+++ b/examples/widgets/richtext/richtext.pro
@@ -1,5 +1,4 @@
TEMPLATE = subdirs
-SUBDIRS = calendar \
- orderform \
+SUBDIRS = orderform \
syntaxhighlighter \
textedit