qt 6.5.1 original

This commit is contained in:
kleuter
2023-10-29 23:33:08 +01:00
parent 71d22ab6b0
commit 85d238dfda
21202 changed files with 5499099 additions and 0 deletions

View File

@ -0,0 +1,73 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(notepad LANGUAGES CXX)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/notepad")
find_package(Qt6
REQUIRED COMPONENTS Core Gui Widgets
OPTIONAL_COMPONENTS PrintSupport
)
qt_standard_project_setup()
qt_add_executable(notepad
main.cpp
notepad.cpp notepad.h notepad.ui
)
set_target_properties(notepad PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(notepad PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Widgets
)
if(TARGET Qt6::PrintSupport)
target_link_libraries(notepad PRIVATE Qt6::PrintSupport)
endif()
# Resources:
set(notepad_resource_files
"images/bold.png"
"images/copy.png"
"images/create.png"
"images/cut.png"
"images/edit_redo.png"
"images/edit_undo.png"
"images/exit.png"
"images/font.png"
"images/info.png"
"images/italic.png"
"images/new.png"
"images/open.png"
"images/paste.png"
"images/pencil.png"
"images/print.png"
"images/save.png"
"images/save_as.png"
"images/underline.png"
)
qt_add_resources(notepad "notepad"
PREFIX
"/"
FILES
${notepad_resource_files}
)
install(TARGETS notepad
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

View File

@ -0,0 +1,14 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "notepad.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Notepad w;
w.show();
return a.exec();
}

View File

@ -0,0 +1,178 @@
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QMessageBox>
#if defined(QT_PRINTSUPPORT_LIB)
#include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printer)
#if QT_CONFIG(printdialog)
#include <QPrintDialog>
#endif // QT_CONFIG(printdialog)
#include <QPrinter>
#endif // QT_CONFIG(printer)
#endif // QT_PRINTSUPPORT_LIB
#include <QFont>
#include <QFontDialog>
#include "notepad.h"
#include "ui_notepad.h"
Notepad::Notepad(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Notepad)
{
ui->setupUi(this);
connect(ui->actionNew, &QAction::triggered, this, &Notepad::newDocument);
connect(ui->actionOpen, &QAction::triggered, this, &Notepad::open);
connect(ui->actionSave, &QAction::triggered, this, &Notepad::save);
connect(ui->actionSave_as, &QAction::triggered, this, &Notepad::saveAs);
connect(ui->actionPrint, &QAction::triggered, this, &Notepad::print);
connect(ui->actionExit, &QAction::triggered, this, &QWidget::close);
#if QT_CONFIG(clipboard)
connect(ui->textEdit, &QTextEdit::copyAvailable, ui->actionCopy, &QAction::setEnabled);
connect(ui->actionCopy, &QAction::triggered, ui->textEdit, &QTextEdit::copy);
connect(ui->actionCut, &QAction::triggered, ui->textEdit, &QTextEdit::cut);
connect(ui->actionPaste, &QAction::triggered, ui->textEdit, &QTextEdit::paste);
#endif
connect(ui->textEdit, &QTextEdit::undoAvailable, ui->actionUndo, &QAction::setEnabled);
connect(ui->actionUndo, &QAction::triggered, ui->textEdit, &QTextEdit::undo);
connect(ui->textEdit, &QTextEdit::redoAvailable, ui->actionRedo, &QAction::setEnabled);
connect(ui->actionRedo, &QAction::triggered, ui->textEdit, &QTextEdit::redo);
connect(ui->actionFont, &QAction::triggered, this, &Notepad::selectFont);
connect(ui->actionBold, &QAction::triggered, this, &Notepad::setFontBold);
connect(ui->actionUnderline, &QAction::triggered, this, &Notepad::setFontUnderline);
connect(ui->actionItalic, &QAction::triggered, this, &Notepad::setFontItalic);
connect(ui->actionAbout, &QAction::triggered, this, &Notepad::about);
// Disable menu actions for unavailable features
#if !defined(QT_PRINTSUPPORT_LIB) || !QT_CONFIG(printer)
ui->actionPrint->setEnabled(false);
#endif
#if !QT_CONFIG(clipboard)
ui->actionCut->setEnabled(false);
ui->actionCopy->setEnabled(false);
ui->actionPaste->setEnabled(false);
#endif
}
Notepad::~Notepad()
{
delete ui;
}
void Notepad::newDocument()
{
currentFile.clear();
ui->textEdit->setText(QString());
}
void Notepad::open()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open the file");
if (fileName.isEmpty())
return;
QFile file(fileName);
currentFile = fileName;
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, "Warning", "Cannot open file: " + file.errorString());
return;
}
setWindowTitle(fileName);
QTextStream in(&file);
QString text = in.readAll();
ui->textEdit->setText(text);
file.close();
}
void Notepad::save()
{
QString fileName;
// If we don't have a filename from before, get one.
if (currentFile.isEmpty()) {
fileName = QFileDialog::getSaveFileName(this, "Save");
if (fileName.isEmpty())
return;
currentFile = fileName;
} else {
fileName = currentFile;
}
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QFile::Text)) {
QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
return;
}
setWindowTitle(fileName);
QTextStream out(&file);
QString text = ui->textEdit->toPlainText();
out << text;
file.close();
}
void Notepad::saveAs()
{
QString fileName = QFileDialog::getSaveFileName(this, "Save as");
if (fileName.isEmpty())
return;
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
return;
}
currentFile = fileName;
setWindowTitle(fileName);
QTextStream out(&file);
QString text = ui->textEdit->toPlainText();
out << text;
file.close();
}
void Notepad::print()
{
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
QPrinter printDev;
#if QT_CONFIG(printdialog)
QPrintDialog dialog(&printDev, this);
if (dialog.exec() == QDialog::Rejected)
return;
#endif // QT_CONFIG(printdialog)
ui->textEdit->print(&printDev);
#endif // QT_CONFIG(printer)
}
void Notepad::selectFont()
{
bool fontSelected;
QFont font = QFontDialog::getFont(&fontSelected, this);
if (fontSelected)
ui->textEdit->setFont(font);
}
void Notepad::setFontUnderline(bool underline)
{
ui->textEdit->setFontUnderline(underline);
}
void Notepad::setFontItalic(bool italic)
{
ui->textEdit->setFontItalic(italic);
}
void Notepad::setFontBold(bool bold)
{
bold ? ui->textEdit->setFontWeight(QFont::Bold) :
ui->textEdit->setFontWeight(QFont::Normal);
}
void Notepad::about()
{
QMessageBox::about(this, tr("About Notepad"),
tr("The <b>Notepad</b> example demonstrates how to code a basic "
"text editor using QtWidgets"));
}

View File

@ -0,0 +1,40 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef NOTEPAD_H
#define NOTEPAD_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui {
class Notepad;
}
QT_END_NAMESPACE
class Notepad : public QMainWindow
{
Q_OBJECT
public:
explicit Notepad(QWidget *parent = nullptr);
~Notepad();
private slots:
void newDocument();
void open();
void save();
void saveAs();
void print();
void selectFont();
void setFontBold(bool bold);
void setFontUnderline(bool underline);
void setFontItalic(bool italic);
void about();
private:
Ui::Notepad *ui;
QString currentFile;
};
#endif // NOTEPAD_H

View File

@ -0,0 +1,23 @@
TEMPLATE = app
TARGET = notepad
QT += widgets
qtHaveModule(printsupport): QT += printsupport
requires(qtConfig(fontdialog))
SOURCES += \
main.cpp\
notepad.cpp
HEADERS += notepad.h
FORMS += notepad.ui
RESOURCES += \
notepad.qrc
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/notepad
INSTALLS += target

View File

@ -0,0 +1,22 @@
<RCC>
<qresource prefix="/">
<file>images/info.png</file>
<file>images/new.png</file>
<file>images/open.png</file>
<file>images/paste.png</file>
<file>images/pencil.png</file>
<file>images/print.png</file>
<file>images/save.png</file>
<file>images/save_as.png</file>
<file>images/exit.png</file>
<file>images/font.png</file>
<file>images/copy.png</file>
<file>images/create.png</file>
<file>images/cut.png</file>
<file>images/edit_redo.png</file>
<file>images/edit_undo.png</file>
<file>images/bold.png</file>
<file>images/italic.png</file>
<file>images/underline.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,326 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Notepad</class>
<widget class="QMainWindow" name="Notepad">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Notepad</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="textEdit"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionNew"/>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSave_as"/>
<addaction name="actionPrint"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>Edit</string>
</property>
<addaction name="actionCopy"/>
<addaction name="actionCut"/>
<addaction name="actionPaste"/>
<addaction name="separator"/>
<addaction name="actionUndo"/>
<addaction name="actionRedo"/>
<addaction name="actionFont"/>
</widget>
<widget class="QMenu" name="menuAbout">
<property name="title">
<string>About</string>
</property>
<addaction name="actionAbout"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuAbout"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionNew"/>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSave_as"/>
<addaction name="actionPrint"/>
<addaction name="separator"/>
<addaction name="actionCopy"/>
<addaction name="actionCut"/>
<addaction name="actionPaste"/>
<addaction name="actionUndo"/>
<addaction name="actionRedo"/>
<addaction name="separator"/>
<addaction name="actionFont"/>
<addaction name="actionBold"/>
<addaction name="actionItalic"/>
<addaction name="actionUnderline"/>
<addaction name="separator"/>
<addaction name="actionAbout"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionNew">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/new.png</normaloff>:/images/new.png</iconset>
</property>
<property name="text">
<string>New</string>
</property>
<property name="toolTip">
<string>New text document</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
</property>
</action>
<action name="actionOpen">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/open.png</normaloff>:/images/open.png</iconset>
</property>
<property name="text">
<string>Open</string>
</property>
<property name="toolTip">
<string>Open file</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="actionSave">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/save.png</normaloff>:/images/save.png</iconset>
</property>
<property name="text">
<string>Save</string>
</property>
<property name="toolTip">
<string>Save file</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionSave_as">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/save_as.png</normaloff>:/images/save_as.png</iconset>
</property>
<property name="text">
<string>Save as</string>
</property>
<property name="toolTip">
<string>Save file as</string>
</property>
<property name="shortcut">
<string>Alt+S</string>
</property>
</action>
<action name="actionPrint">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/print.png</normaloff>:/images/print.png</iconset>
</property>
<property name="text">
<string>Print</string>
</property>
<property name="toolTip">
<string>Print file</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
<action name="actionExit">
<property name="icon">
<iconset theme="exit.png" resource="notepad.qrc">
<normaloff>:/images/exit.png</normaloff>:/images/exit.png</iconset>
</property>
<property name="text">
<string>Exit</string>
</property>
<property name="toolTip">
<string>Exit notepad</string>
</property>
</action>
<action name="actionCopy">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/copy.png</normaloff>:/images/copy.png</iconset>
</property>
<property name="text">
<string>Copy</string>
</property>
<property name="shortcut">
<string>Ctrl+C</string>
</property>
</action>
<action name="actionCut">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/cut.png</normaloff>:/images/cut.png</iconset>
</property>
<property name="text">
<string>Cut</string>
</property>
<property name="shortcut">
<string>Ctrl+X</string>
</property>
</action>
<action name="actionPaste">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/paste.png</normaloff>:/images/paste.png</iconset>
</property>
<property name="text">
<string>Paste</string>
</property>
<property name="shortcut">
<string>Ctrl+V</string>
</property>
</action>
<action name="actionUndo">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/edit_undo.png</normaloff>:/images/edit_undo.png</iconset>
</property>
<property name="text">
<string>Undo</string>
</property>
<property name="shortcut">
<string>Ctrl+Z</string>
</property>
</action>
<action name="actionRedo">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/edit_redo.png</normaloff>:/images/edit_redo.png</iconset>
</property>
<property name="text">
<string>Redo</string>
</property>
<property name="shortcut">
<string>Ctrl+Y</string>
</property>
</action>
<action name="actionFont">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/font.png</normaloff>:/images/font.png</iconset>
</property>
<property name="text">
<string>Font</string>
</property>
<property name="shortcut">
<string>Ctrl+F</string>
</property>
</action>
<action name="actionItalic">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/italic.png</normaloff>:/images/italic.png</iconset>
</property>
<property name="text">
<string>Italic</string>
</property>
<property name="toolTip">
<string>Italic font</string>
</property>
<property name="shortcut">
<string>Ctrl+I</string>
</property>
</action>
<action name="actionBold">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/bold.png</normaloff>:/images/bold.png</iconset>
</property>
<property name="text">
<string>actionBold</string>
</property>
<property name="toolTip">
<string>Bold</string>
</property>
<property name="shortcut">
<string>Ctrl+B</string>
</property>
</action>
<action name="actionUnderline">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/underline.png</normaloff>:/images/underline.png</iconset>
</property>
<property name="text">
<string>Underline</string>
</property>
<property name="toolTip">
<string>Underline</string>
</property>
<property name="shortcut">
<string>Ctrl+U</string>
</property>
</action>
<action name="actionAbout">
<property name="icon">
<iconset resource="notepad.qrc">
<normaloff>:/images/info.png</normaloff>:/images/info.png</iconset>
</property>
<property name="text">
<string>About</string>
</property>
<property name="toolTip">
<string>About Notepad</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="notepad.qrc"/>
</resources>
<connections/>
</ui>