├── FileSelector
├── image.png
├── linux.png
├── windows.png
├── +mac
│ ├── image.png
│ └── main.qml
├── +linux
│ ├── image.png
│ └── main.qml
├── +windows
│ ├── image.png
│ └── main.qml
├── FileSelector.pro
├── qml.qrc
├── main.qml
└── main.cpp
├── QRandomGenerator
├── README.md
├── randomdemo1
│ ├── randomdemo1.pro
│ └── randomdemo1.cpp
└── randomdemo2
│ ├── main.cpp
│ ├── randomdemo2.pro
│ ├── mainwindow.h
│ ├── mainwindow.ui
│ └── mainwindow.cpp
├── MultiLanguageApp
├── i18n
│ ├── lang_en_US.qm
│ ├── lang_fr_FR.qm
│ ├── lang_ru_RU.qm
│ ├── lang_en_US.ts
│ ├── lang_ru_RU.ts
│ └── lang_fr_FR.ts
├── images
│ └── down_24.png
├── README.md
├── multiLangTest.qrc
├── main.cpp
├── mainwindow.h
├── multiLangTest.pro
├── translation.h
├── dialog.h
├── TranslatorManager.h
├── translation.cpp
├── mainwindow.cpp
├── TranslatorManager.cpp
├── mainwindow.ui
└── dialog.cpp
├── QtForPython
├── mdieditor
│ ├── images
│ │ ├── copy.png
│ │ ├── cut.png
│ │ ├── icon.png
│ │ ├── new.png
│ │ ├── open.png
│ │ ├── save.png
│ │ ├── paste.png
│ │ └── document.png
│ ├── mdieditor.qrc
│ └── Makefile
├── spreadsheet
│ ├── images
│ │ ├── copy.png
│ │ ├── cut.png
│ │ ├── find.png
│ │ ├── icon.png
│ │ ├── new.png
│ │ ├── open.png
│ │ ├── save.png
│ │ ├── paste.png
│ │ └── gotocell.png
│ ├── original
│ │ ├── images
│ │ │ ├── cut.png
│ │ │ ├── new.png
│ │ │ ├── copy.png
│ │ │ ├── find.png
│ │ │ ├── icon.png
│ │ │ ├── open.png
│ │ │ ├── paste.png
│ │ │ ├── save.png
│ │ │ └── gotocell.png
│ │ ├── main.cpp
│ │ ├── sortdialog.h
│ │ ├── gotocelldialog.h
│ │ ├── spreadsheet.qrc
│ │ ├── gotocelldialog.cpp
│ │ ├── spreadsheet.pro
│ │ ├── finddialog.h
│ │ ├── cell.h
│ │ ├── sortdialog.cpp
│ │ ├── spreadsheet.h
│ │ ├── gotocelldialog.ui
│ │ ├── finddialog.cpp
│ │ ├── mainwindow.h
│ │ └── cell.cpp
│ ├── spreadsheet.qrc
│ ├── Makefile
│ └── gotocelldialog.ui
└── README.md
├── CppBinding
├── example1
│ ├── qml.qrc
│ ├── main.qml
│ ├── example1.pro
│ ├── main.cpp
│ ├── rectanglemanager.cpp
│ ├── rectanglemanager.h
│ └── CMakeLists.txt
└── example2
│ ├── exclass.cpp
│ ├── exclass.h
│ ├── CMakeLists.txt
│ ├── example2.pro
│ └── main.cpp
├── QCompleter
└── completerdemo
│ ├── resources.qrc
│ ├── main.cpp
│ ├── mainwindow.h
│ ├── completerdemo.pro
│ ├── mainwindow.cpp
│ └── mainwindow.ui
├── PythonPlugin
├── README.md
├── ledplugin.py
└── ledwidget.py
├── calculator-qml
├── qml
│ ├── qml.qrc
│ ├── Button.qml
│ └── Calculator.qml
├── calculator-qml.pro
├── main.cpp
├── calculator.h
└── calculator.cpp
├── widgetsandqml
├── README.md
├── main.cpp
├── widgetsandqml.pro
├── mainwindow.h
├── main.qml
├── mainwindow.cpp
└── mainwindow.ui
├── gpio
├── part9
│ ├── CMakeLists.txt
│ └── example.c
├── part4
│ ├── simple.py
│ ├── simple2.py
│ ├── pwm.py
│ ├── pwm2.py
│ └── demo.py
├── part5
│ ├── Makefile
│ ├── demo2.c
│ ├── demo3.c
│ ├── demo4.c
│ └── demo1.c
└── part8
│ ├── Makefile
│ ├── demo1.cpp
│ └── demo2.cpp
├── MasksValidators
├── MasksValidators.pro
├── inputmaskdemo
│ ├── main.cpp
│ ├── mainwindow.h
│ ├── inputmaskdemo.pro
│ ├── mainwindow.ui
│ └── mainwindow.cpp
├── validatordemo
│ ├── main.cpp
│ ├── mainwindow.h
│ ├── validatordemo.pro
│ └── mainwindow.cpp
├── maskandvalidatordemo
│ ├── main.cpp
│ ├── mainwindow.h
│ ├── maskandvalidatordemo.pro
│ └── mainwindow.cpp
├── qmldemo
│ ├── qtquickcontrols2.conf
│ ├── qml.qrc
│ ├── main.cpp
│ ├── main.qml
│ ├── qmldemo.pro
│ ├── Page3.qml
│ ├── Page1.qml
│ └── Page2.qml
└── qml
│ ├── inputmask1.qml
│ ├── validator3.qml
│ ├── validator1.qml
│ ├── inputmask2.qml
│ └── validator2.qml
├── README.md
├── calendardemo
├── main.cpp
├── mainwindow.h
├── calendardemo.pro
└── mainwindow.cpp
├── Timers
├── basictimer
│ ├── main.cpp
│ ├── mainwindow.h
│ ├── basictimer.pro
│ ├── mainwindow.cpp
│ └── mainwindow.ui
├── elapsedtimer
│ ├── main.cpp
│ ├── mainwindow.h
│ ├── elapsedtimer.pro
│ ├── mainwindow.cpp
│ └── mainwindow.ui
└── qml
│ └── Example.qml
├── MoveToTrash
└── trashdemo
│ ├── main.cpp
│ ├── mainwindow.h
│ ├── trashdemo.pro
│ ├── mainwindow.cpp
│ └── mainwindow.ui
└── LICENSE.txt
/FileSelector/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/FileSelector/image.png
--------------------------------------------------------------------------------
/FileSelector/linux.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/FileSelector/linux.png
--------------------------------------------------------------------------------
/QRandomGenerator/README.md:
--------------------------------------------------------------------------------
1 | See https://www.ics.com/blog/whats-new-qt-510-qrandomgenerator
2 |
--------------------------------------------------------------------------------
/FileSelector/windows.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/FileSelector/windows.png
--------------------------------------------------------------------------------
/FileSelector/+mac/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/FileSelector/+mac/image.png
--------------------------------------------------------------------------------
/FileSelector/+linux/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/FileSelector/+linux/image.png
--------------------------------------------------------------------------------
/FileSelector/+windows/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/FileSelector/+windows/image.png
--------------------------------------------------------------------------------
/MultiLanguageApp/i18n/lang_en_US.qm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/MultiLanguageApp/i18n/lang_en_US.qm
--------------------------------------------------------------------------------
/MultiLanguageApp/i18n/lang_fr_FR.qm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/MultiLanguageApp/i18n/lang_fr_FR.qm
--------------------------------------------------------------------------------
/MultiLanguageApp/i18n/lang_ru_RU.qm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/MultiLanguageApp/i18n/lang_ru_RU.qm
--------------------------------------------------------------------------------
/MultiLanguageApp/images/down_24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/MultiLanguageApp/images/down_24.png
--------------------------------------------------------------------------------
/QtForPython/mdieditor/images/copy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/mdieditor/images/copy.png
--------------------------------------------------------------------------------
/QtForPython/mdieditor/images/cut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/mdieditor/images/cut.png
--------------------------------------------------------------------------------
/QtForPython/mdieditor/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/mdieditor/images/icon.png
--------------------------------------------------------------------------------
/QtForPython/mdieditor/images/new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/mdieditor/images/new.png
--------------------------------------------------------------------------------
/QtForPython/mdieditor/images/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/mdieditor/images/open.png
--------------------------------------------------------------------------------
/QtForPython/mdieditor/images/save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/mdieditor/images/save.png
--------------------------------------------------------------------------------
/QtForPython/mdieditor/images/paste.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/mdieditor/images/paste.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/images/copy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/images/copy.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/images/cut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/images/cut.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/images/find.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/images/find.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/images/icon.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/images/new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/images/new.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/images/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/images/open.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/images/save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/images/save.png
--------------------------------------------------------------------------------
/QtForPython/mdieditor/images/document.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/mdieditor/images/document.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/images/paste.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/images/paste.png
--------------------------------------------------------------------------------
/CppBinding/example1/qml.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | main.qml
4 |
5 |
6 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/images/gotocell.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/images/gotocell.png
--------------------------------------------------------------------------------
/QCompleter/completerdemo/resources.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | words
4 |
5 |
6 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/images/cut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/original/images/cut.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/images/new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/original/images/new.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/images/copy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/original/images/copy.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/images/find.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/original/images/find.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/original/images/icon.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/images/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/original/images/open.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/images/paste.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/original/images/paste.png
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/images/save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/original/images/save.png
--------------------------------------------------------------------------------
/MultiLanguageApp/README.md:
--------------------------------------------------------------------------------
1 | This is the example code that was mentioned in this blog post:
2 | https://www.ics.com/blog/dynamic-language-selection-qt
3 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/images/gotocell.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranter/blogs/HEAD/QtForPython/spreadsheet/original/images/gotocell.png
--------------------------------------------------------------------------------
/QtForPython/README.md:
--------------------------------------------------------------------------------
1 | This is the example code that was mentioned in this blog post:
2 | https://www.ics.com/blog/we-ported-qt-app-c-python-heres-what-happened
3 |
--------------------------------------------------------------------------------
/PythonPlugin/README.md:
--------------------------------------------------------------------------------
1 | This is the example code that was mentioned in this blog post:
2 | https://www.ics.com/blog/integrating-python-based-custom-widget-qt-designer
3 |
--------------------------------------------------------------------------------
/calculator-qml/qml/qml.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | Button.qml
4 | Calculator.qml
5 |
6 |
7 |
--------------------------------------------------------------------------------
/widgetsandqml/README.md:
--------------------------------------------------------------------------------
1 | This is the example code that was mentioned in this blog post:
2 | https://www.ics.com/blog/combining-qt-widgets-and-qml-qwidgetcreatewindowcontainer
3 |
--------------------------------------------------------------------------------
/gpio/part9/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 |
3 | project(example LANGUAGES C)
4 |
5 | add_executable(${PROJECT_NAME} example.c)
6 | target_link_libraries(${PROJECT_NAME} gpiod)
7 |
--------------------------------------------------------------------------------
/MasksValidators/MasksValidators.pro:
--------------------------------------------------------------------------------
1 | lessThan(QT_MAJOR_VERSION, 5): error(This project requires Qt 5 or later)
2 | TEMPLATE = subdirs
3 | SUBDIRS = inputmaskdemo validatordemo maskandvalidatordemo qmldemo
4 |
--------------------------------------------------------------------------------
/FileSelector/FileSelector.pro:
--------------------------------------------------------------------------------
1 | lessThan(QT_MAJOR_VERSION, 5): error(This project requires Qt 5 or later)
2 |
3 | TEMPLATE = app
4 | QT += qml quick
5 | CONFIG += c++11
6 | SOURCES += main.cpp
7 | RESOURCES += qml.qrc
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # blogs
2 | Files associated with Jeff Tranter's ICS [blog posts](https://www.ics.com/author/jeff-tranter).
3 |
4 | Unless otherwise indicated, the files are released under the license
5 | conditions listed in the file LICENSE.txt.
6 |
--------------------------------------------------------------------------------
/QRandomGenerator/randomdemo1/randomdemo1.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | TARGET = randomdemo1
3 |
4 | lessThan(QT_MAJOR_VERSION, 5) | lessThan(QT_MINOR_VERSION, 10): error(This project requires Qt 5.10 or later)
5 |
6 | # Input
7 | SOURCES += randomdemo1.cpp
8 |
--------------------------------------------------------------------------------
/widgetsandqml/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 |
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/MasksValidators/inputmaskdemo/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 | return a.exec();
10 | }
11 |
--------------------------------------------------------------------------------
/MasksValidators/validatordemo/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 | return a.exec();
10 | }
11 |
--------------------------------------------------------------------------------
/calendardemo/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return QApplication::exec();
11 | }
12 |
--------------------------------------------------------------------------------
/MasksValidators/maskandvalidatordemo/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 | return a.exec();
10 | }
11 |
--------------------------------------------------------------------------------
/QRandomGenerator/randomdemo2/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 |
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/Timers/basictimer/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 |
10 | return QApplication::exec();
11 | }
12 |
--------------------------------------------------------------------------------
/Timers/elapsedtimer/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 |
10 | return QApplication::exec();
11 | }
12 |
--------------------------------------------------------------------------------
/MoveToTrash/trashdemo/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return QApplication::exec();
11 | }
12 |
--------------------------------------------------------------------------------
/QCompleter/completerdemo/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 |
10 | return QApplication::exec();
11 | }
12 |
--------------------------------------------------------------------------------
/MasksValidators/qmldemo/qtquickcontrols2.conf:
--------------------------------------------------------------------------------
1 | ; This file can be edited to change the style of the application
2 | ; Read "Qt Quick Controls 2 Configuration File" for details:
3 | ; http://doc.qt.io/qt-5/qtquickcontrols2-configuration.html
4 |
5 | [Controls]
6 | Style=Default
7 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "mainwindow.h"
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication app(argc, argv);
8 | MainWindow mainWin;
9 | mainWin.show();
10 | return app.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/MasksValidators/qmldemo/qml.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | main.qml
4 | Page1.qml
5 | Page2.qml
6 | Page3.qml
7 | qtquickcontrols2.conf
8 |
9 |
10 |
--------------------------------------------------------------------------------
/gpio/part4/simple.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import RPi.GPIO as GPIO
4 | import time
5 |
6 | led1 = 18
7 |
8 | GPIO.setmode(GPIO.BOARD)
9 | GPIO.setup(led1, GPIO.OUT)
10 |
11 | while True:
12 | GPIO.output(led1, GPIO.HIGH)
13 | time.sleep(0.2)
14 | GPIO.output(led1, GPIO.LOW)
15 | time.sleep(0.2)
16 |
--------------------------------------------------------------------------------
/widgetsandqml/widgetsandqml.pro:
--------------------------------------------------------------------------------
1 | lessThan(QT_MAJOR_VERSION, 5): error(This project requires Qt 5 or later)
2 |
3 | QT += core gui widgets quick
4 |
5 | TARGET = widgetsandqml
6 | TEMPLATE = app
7 |
8 | SOURCES += main.cpp mainwindow.cpp
9 |
10 | HEADERS += mainwindow.h
11 |
12 | FORMS += mainwindow.ui
13 |
14 | OTHER_FILES += main.qml
15 |
--------------------------------------------------------------------------------
/CppBinding/example1/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.15
2 | import QtQuick.Window 2.15
3 |
4 | Window {
5 | width: 640
6 | height: 480
7 | visible: true
8 | title: qsTr("Binding Example")
9 | Text {
10 | id: name
11 | text: rectangleManager.rectangleCount
12 | font.pixelSize: 30
13 | anchors.centerIn: parent
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/gpio/part5/Makefile:
--------------------------------------------------------------------------------
1 | all: demo1 demo2 demo3 demo4
2 |
3 | demo1: demo1.c
4 | gcc -Wall -O2 -o demo1 demo1.c
5 |
6 | demo2: demo2.c
7 | gcc -Wall -o demo2 demo2.c -lwiringPi
8 |
9 | demo3: demo3.c
10 | gcc -Wall -o demo3 demo3.c -lwiringPi
11 |
12 | demo4: demo4.c
13 | gcc -Wall -o demo4 demo4.c -lwiringPi
14 |
15 | clean:
16 | $(RM) demo1 demo2 demo3 demo4
17 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/sortdialog.h:
--------------------------------------------------------------------------------
1 | #ifndef SORTDIALOG_H
2 | #define SORTDIALOG_H
3 |
4 | #include
5 |
6 | #include "ui_sortdialog.h"
7 |
8 | class SortDialog : public QDialog, public Ui::SortDialog
9 | {
10 | Q_OBJECT
11 |
12 | public:
13 | SortDialog(QWidget *parent = 0);
14 |
15 | void setColumnRange(QChar first, QChar last);
16 | };
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/FileSelector/qml.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | main.qml
4 | +linux/main.qml
5 | +mac/main.qml
6 | +windows/main.qml
7 | image.png
8 | +linux/image.png
9 | +mac/image.png
10 | +windows/image.png
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MultiLanguageApp/multiLangTest.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/down_24.png
4 | i18n/lang_en_US.qm
5 | i18n/lang_en_US.ts
6 | i18n/lang_ru_RU.qm
7 | i18n/lang_ru_RU.ts
8 | i18n/lang_fr_FR.qm
9 | i18n/lang_fr_FR.ts
10 |
11 |
12 |
--------------------------------------------------------------------------------
/calculator-qml/calculator-qml.pro:
--------------------------------------------------------------------------------
1 | TARGET = calculator
2 | TEMPLATE = app
3 |
4 | QT += qml quick
5 |
6 | OBJECTS_DIR = build
7 | MOC_DIR = build
8 | RCC_DIR = build
9 |
10 | SOURCES += \
11 | main.cpp\
12 | calculator.cpp
13 |
14 | HEADERS += \
15 | calculator.h
16 |
17 | OTHER_FILES += \
18 | qml/Button.qml \
19 | qml/Calculator.qml
20 |
21 | RESOURCES += \
22 | qml/qml.qrc
23 |
24 |
--------------------------------------------------------------------------------
/QtForPython/mdieditor/mdieditor.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/copy.png
4 | images/cut.png
5 | images/document.png
6 | images/icon.png
7 | images/new.png
8 | images/open.png
9 | images/paste.png
10 | images/save.png
11 |
12 |
13 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/gotocelldialog.h:
--------------------------------------------------------------------------------
1 | #ifndef GOTOCELLDIALOG_H
2 | #define GOTOCELLDIALOG_H
3 |
4 | #include
5 |
6 | #include "ui_gotocelldialog.h"
7 |
8 | class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
9 | {
10 | Q_OBJECT
11 |
12 | public:
13 | GoToCellDialog(QWidget *parent = 0);
14 |
15 | private slots:
16 | void textChanged();
17 | };
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/widgetsandqml/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class MainWindow;
8 | }
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit MainWindow(QWidget *parent = 0);
16 | ~MainWindow();
17 |
18 | private:
19 | Ui::MainWindow *ui;
20 | };
21 |
22 | #endif // MAINWINDOW_H
23 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/spreadsheet.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/icon.png
4 | images/new.png
5 | images/open.png
6 | images/save.png
7 | images/cut.png
8 | images/copy.png
9 | images/paste.png
10 | images/find.png
11 | images/gotocell.png
12 |
13 |
14 |
--------------------------------------------------------------------------------
/gpio/part4/simple2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | import RPi.GPIO as GPIO
4 | import time
5 |
6 | led = 18
7 | switch = 31
8 |
9 | GPIO.setmode(GPIO.BOARD)
10 | GPIO.setup(led, GPIO.OUT)
11 | GPIO.setup(switch, GPIO.IN)
12 |
13 | for i in range(10):
14 | GPIO.output(led, GPIO.HIGH)
15 | time.sleep(0.2)
16 | GPIO.output(led, GPIO.LOW)
17 | time.sleep(0.2)
18 | print('Switch status = ', GPIO.input(switch))
19 |
20 | GPIO.cleanup()
21 |
--------------------------------------------------------------------------------
/FileSelector/+mac/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.3
2 | import QtQuick.Window 2.2
3 |
4 | Window {
5 | visible: true
6 |
7 | MouseArea {
8 | anchors.fill: parent
9 | onClicked: {
10 | Qt.quit();
11 | }
12 | }
13 |
14 | Column {
15 | Text {
16 | text: "This is the Mac QML file."
17 | }
18 |
19 | Image {
20 | source: "qrc:/image.png"
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/FileSelector/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.3
2 | import QtQuick.Window 2.2
3 |
4 | Window {
5 | visible: true
6 |
7 | MouseArea {
8 | anchors.fill: parent
9 | onClicked: {
10 | Qt.quit();
11 | }
12 | }
13 |
14 | Column {
15 | Text {
16 | text: "This is the default QML file."
17 | }
18 |
19 | Image {
20 | source: "qrc:/image.png"
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/MasksValidators/qmldemo/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
7 | QGuiApplication app(argc, argv);
8 | QQmlApplicationEngine engine;
9 |
10 | engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
11 | if (engine.rootObjects().isEmpty())
12 | return -1;
13 |
14 | return app.exec();
15 | }
16 |
--------------------------------------------------------------------------------
/QRandomGenerator/randomdemo2/randomdemo2.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | lessThan(QT_MAJOR_VERSION, 5) | lessThan(QT_MINOR_VERSION, 10): error(This project requires Qt 5.10 or later)
4 |
5 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
6 |
7 | TARGET = randomdemo2
8 | TEMPLATE = app
9 |
10 | SOURCES += \
11 | main.cpp \
12 | mainwindow.cpp
13 |
14 | HEADERS += \
15 | mainwindow.h
16 |
17 | FORMS += \
18 | mainwindow.ui
19 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/spreadsheet.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/icon.png
4 | images/new.png
5 | images/open.png
6 | images/save.png
7 | images/cut.png
8 | images/copy.png
9 | images/paste.png
10 | images/find.png
11 | images/gotocell.png
12 |
13 |
14 |
--------------------------------------------------------------------------------
/FileSelector/+linux/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.3
2 | import QtQuick.Window 2.2
3 |
4 | Window {
5 | visible: true
6 |
7 | MouseArea {
8 | anchors.fill: parent
9 | onClicked: {
10 | Qt.quit();
11 | }
12 | }
13 |
14 | Column {
15 | Text {
16 | text: "This is the Linux QML file."
17 | }
18 |
19 | Image {
20 | source: "qrc:/image.png"
21 | }
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/FileSelector/+windows/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.3
2 | import QtQuick.Window 2.2
3 |
4 | Window {
5 | visible: true
6 |
7 | MouseArea {
8 | anchors.fill: parent
9 | onClicked: {
10 | Qt.quit();
11 | }
12 | }
13 |
14 | Column {
15 | Text {
16 | text: "This is the Windows QML file."
17 | }
18 |
19 | Image {
20 | source: "qrc:/image.png"
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/CppBinding/example2/exclass.cpp:
--------------------------------------------------------------------------------
1 | #include "exclass.h"
2 |
3 | ExClass::ExClass(QObject *parent)
4 | : QObject(parent)
5 | , m_string("init value")
6 | , stringProperty("init value") // for Qt 6+
7 | {
8 |
9 | }
10 |
11 | void ExClass::setStringText(QString str)
12 | {
13 | if(str != m_string){
14 | m_string = str;
15 | emit stringChanged(m_string);
16 | }
17 |
18 | }
19 |
20 | QString ExClass::getString()
21 | {
22 | return m_string;
23 | }
24 |
--------------------------------------------------------------------------------
/CppBinding/example2/exclass.h:
--------------------------------------------------------------------------------
1 | #ifndef EXCLASS_H
2 | #define EXCLASS_H
3 |
4 | #include
5 | class ExClass : public QObject{
6 | Q_OBJECT
7 | public:
8 | QProperty stringProperty; // for Qt 6+
9 |
10 | explicit ExClass(QObject *parent = nullptr);
11 |
12 | void setStringText(QString str);
13 | QString getString();
14 | signals:
15 | void stringChanged(QString string);
16 | private:
17 | QString m_string;
18 | };
19 |
20 | #endif // EXCLASS_H
21 |
--------------------------------------------------------------------------------
/MultiLanguageApp/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "mainwindow.h"
3 | #include "TranslatorManager.h"
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | Q_INIT_RESOURCE(multiLangTest);
8 |
9 | QApplication a(argc, argv);
10 |
11 | // Translator must be created before the application's widgets.
12 | TranslatorManager* manager = TranslatorManager::instance();
13 | Q_UNUSED(manager)
14 |
15 | MainWindow w;
16 | w.show();
17 |
18 | return a.exec();
19 | }
20 |
--------------------------------------------------------------------------------
/QRandomGenerator/randomdemo2/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class MainWindow;
8 | }
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit MainWindow(QWidget *parent = 0);
16 | ~MainWindow();
17 |
18 | protected:
19 | void paintEvent(QPaintEvent *event) override;
20 |
21 | private:
22 | Ui::MainWindow *ui;
23 | };
24 |
25 | #endif // MAINWINDOW_H
26 |
--------------------------------------------------------------------------------
/Timers/elapsedtimer/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class MainWindow;
9 | }
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit MainWindow(QWidget *parent = nullptr);
17 | ~MainWindow() override;
18 | void Start();
19 | void Info();
20 |
21 | private:
22 | Ui::MainWindow *ui;
23 | };
24 |
25 | #endif // MAINWINDOW_H
26 |
--------------------------------------------------------------------------------
/MasksValidators/inputmaskdemo/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class MainWindow;
8 | }
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit MainWindow(QWidget *parent = 0);
16 | ~MainWindow();
17 |
18 | private:
19 | void clear();
20 | void help();
21 | void updateStatusBar();
22 |
23 | Ui::MainWindow *ui;
24 | };
25 |
26 | #endif // MAINWINDOW_H
27 |
--------------------------------------------------------------------------------
/MultiLanguageApp/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class MainWindow;
8 | }
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit MainWindow(QWidget *parent = 0);
16 | ~MainWindow();
17 |
18 | protected:
19 | void changeEvent(QEvent *event);
20 |
21 | private slots:
22 | void slotSelectLanguage();
23 |
24 | private:
25 | Ui::MainWindow* m_ui;
26 | };
27 |
28 | #endif // MAINWINDOW_H
29 |
--------------------------------------------------------------------------------
/FileSelector/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | int main(int argc, char *argv[])
7 | {
8 | QGuiApplication app(argc, argv);
9 | QQmlApplicationEngine engine;
10 |
11 | // Create and display a file selector, just for interest.
12 | QFileSelector sel;
13 | qDebug() << sel.allSelectors();
14 |
15 | // Load and execute the main QML file.
16 | engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
17 | return app.exec();
18 | }
19 |
--------------------------------------------------------------------------------
/calendardemo/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | QT_BEGIN_NAMESPACE
8 | namespace Ui { class MainWindow; }
9 | QT_END_NAMESPACE
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | MainWindow(QWidget *parent = nullptr);
17 | ~MainWindow();
18 |
19 | public slots:
20 | void setSystem(int);
21 | void update();
22 |
23 | private:
24 | Ui::MainWindow *ui;
25 | QCalendar *calendar;
26 | };
27 | #endif // MAINWINDOW_H
28 |
--------------------------------------------------------------------------------
/MoveToTrash/trashdemo/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | public slots:
19 | void selectFile();
20 | void moveToTrash();
21 | void restore();
22 |
23 | private:
24 | Ui::MainWindow *ui;
25 | QString m_filename;
26 | };
27 | #endif // MAINWINDOW_H
28 |
--------------------------------------------------------------------------------
/CppBinding/example2/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.14)
2 |
3 | project(cppBindingExample2 LANGUAGES CXX)
4 |
5 | set(CMAKE_INCLUDE_CURRENT_DIR ON)
6 |
7 | set(CMAKE_AUTOUIC ON)
8 | set(CMAKE_AUTOMOC ON)
9 | set(CMAKE_AUTORCC ON)
10 |
11 | set(CMAKE_CXX_STANDARD 11)
12 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
13 |
14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
16 |
17 | add_executable(cppBindingExample2
18 | main.cpp
19 | exclass.cpp
20 | )
21 | target_link_libraries(cppBindingExample2 Qt${QT_VERSION_MAJOR}::Core stdc++)
22 |
--------------------------------------------------------------------------------
/QCompleter/completerdemo/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class MainWindow;
9 | }
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit MainWindow(QWidget *parent = nullptr);
17 | ~MainWindow() override;
18 | void UpdateSettings();
19 | void Highlighted(const QString &text);
20 | void Activated(const QString &text);
21 |
22 | private:
23 | Ui::MainWindow *ui;
24 | QCompleter *completer;
25 | };
26 |
27 | #endif // MAINWINDOW_H
28 |
--------------------------------------------------------------------------------
/MultiLanguageApp/multiLangTest.pro:
--------------------------------------------------------------------------------
1 | TARGET = multilangtest
2 | TEMPLATE = app
3 | QT += core gui
4 |
5 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
6 |
7 | CONFIG += c++11
8 |
9 | lessThan(QT_MAJOR_VERSION, 5): unix: QMAKE_CXXFLAGS += -std=c++11
10 |
11 | SOURCES += \
12 | main.cpp\
13 | mainwindow.cpp \
14 | translation.cpp \
15 | dialog.cpp \
16 | TranslatorManager.cpp
17 |
18 | HEADERS += \
19 | mainwindow.h \
20 | translation.h \
21 | dialog.h \
22 | TranslatorManager.h
23 |
24 | FORMS += \
25 | mainwindow.ui
26 |
27 | RESOURCES += \
28 | multiLangTest.qrc
29 |
--------------------------------------------------------------------------------
/Timers/basictimer/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class MainWindow;
9 | }
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit MainWindow(QWidget *parent = nullptr);
17 | ~MainWindow() override;
18 | void Clear();
19 | void Start();
20 |
21 | protected:
22 | void timerEvent(QTimerEvent *event) override;
23 |
24 | private:
25 | Ui::MainWindow *ui;
26 | QBasicTimer *timer;
27 | long count;
28 | };
29 |
30 | #endif // MAINWINDOW_H
31 |
--------------------------------------------------------------------------------
/gpio/part8/Makefile:
--------------------------------------------------------------------------------
1 | # Typical values for compiling natively on Raspberry Pi
2 | CXX = g++
3 | CFLAGS =
4 |
5 | # Typical values for cross-compiling for Toradex
6 | #CXX = arm-angstrom-linux-gnueabi-g++ -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/oecore-x86_64/sysroots/cortexa9t2hf-neon-angstrom-linux-gnueabi
7 | #CFLAGS = -O2 -pipe -g -feliminate-unused-debug-types
8 |
9 | all: demo1 demo2
10 |
11 | demo1: demo1.cpp
12 | ${CXX} ${CFLAGS} -o demo1 demo1.cpp -lsoc
13 |
14 | demo2: demo2.cpp
15 | ${CXX} ${CFLAGS} -o demo2 demo2.cpp -lsoc
16 |
17 | clean:
18 | $(RM) demo1 demo2
19 |
--------------------------------------------------------------------------------
/MultiLanguageApp/translation.h:
--------------------------------------------------------------------------------
1 | #ifndef TRANSLATION_H
2 | #define TRANSLATION_H
3 |
4 | extern const char* ID_APP_TITLE;
5 | extern const char* ID_LABEL_TEXT;
6 | extern const char* ID_COMBO_ITEM_1;
7 | extern const char* ID_COMBO_ITEM_2;
8 | extern const char* ID_COMBO_ITEM_3;
9 | extern const char* ID_BUTTON_TEXT_1;
10 | extern const char* ID_MENU_FILE;
11 | extern const char* ID_MENU_FILE_OPEN;
12 | extern const char* ID_MENU_FILE_SAVE;
13 | extern const char* ID_MENU_FILE_CLOSE;
14 | extern const char* ID_MENU_FILE_EXIT;
15 | extern const char* ID_MENU_SETTINGS;
16 | extern const char* ID_MENU_SETTINGS_SELECT;
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/QtForPython/mdieditor/Makefile:
--------------------------------------------------------------------------------
1 | # Python 2
2 | #RCC = $(HOME)/.local/lib/python2.7/site-packages/PySide2/pyside2-rcc
3 | #UIC = $(HOME)/.local/lib/python2.7/site-packages/PySide2/scripts/uic.py
4 |
5 | # Python 3
6 | RCC = $(HOME)/.local/lib/python3.6/site-packages/PySide2/pyside2-rcc
7 | UIC = $(HOME)/.local/lib/python3.6/site-packages/PySide2/scripts/uic.py
8 |
9 | all: mdieditor_rc.py
10 |
11 | mdieditor_rc.py: mdieditor.qrc
12 | $(RCC) mdieditor.qrc >mdieditor_rc.py
13 |
14 | check: flake8
15 |
16 | pep8: flake8
17 |
18 | flake8:
19 | flake8 --max-line-length=132 mdieditor.py
20 |
21 | distclean: clean
22 |
23 | clean:
24 | $(RM) *_rc.py *.pyc
25 | $(RM) -rf __pycache__
26 |
27 |
--------------------------------------------------------------------------------
/gpio/part5/demo2.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Example of programming GPIO from C or C++ using the WiringPi library
4 | on a Raspberry Pi.
5 |
6 | Will continuously toggle GPIO24 (physical pin 18) at a 500 millisecond
7 | rate.
8 |
9 | Jeff Tranter
10 |
11 | */
12 |
13 | #include
14 |
15 | int main(void)
16 | {
17 | // Red LED: Physical pin 18, BCM GPIO24, and WiringPi pin 5.
18 | const int led = 5;
19 |
20 | wiringPiSetup();
21 |
22 | pinMode(led, OUTPUT);
23 |
24 | while (1) {
25 | digitalWrite(led, HIGH);
26 | delay(500);
27 | digitalWrite(led, LOW);
28 | delay(500);
29 | }
30 |
31 | return 0;
32 | }
33 |
--------------------------------------------------------------------------------
/gpio/part4/pwm.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import RPi.GPIO as GPIO
4 | import time
5 | import atexit
6 |
7 | def cleanup():
8 | print("Cleaning up")
9 | GPIO.cleanup()
10 |
11 | atexit.register(cleanup)
12 |
13 | led1 = 24
14 | led2 = 25
15 | led3 = 5
16 |
17 | GPIO.setmode(GPIO.BCM)
18 | GPIO.setup(led1, GPIO.OUT)
19 | GPIO.setup(led2, GPIO.OUT)
20 | GPIO.setup(led3, GPIO.OUT)
21 |
22 | while True:
23 | for pin in [led1, led2, led3]:
24 | p = GPIO.PWM(pin, 50)
25 | p.start(0)
26 | for dc in range(0, 101, 5):
27 | p.ChangeDutyCycle(dc)
28 | time.sleep(0.05)
29 | for dc in range(100, -1, -5):
30 | p.ChangeDutyCycle(dc)
31 | time.sleep(0.05)
32 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (C) 2019-2020 Integrated Computer Solutions, Inc.
2 |
3 | Permission to use, copy, modify, and/or distribute this software for
4 | any purpose with or without fee is hereby granted.
5 |
6 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
7 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
8 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
9 | AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
10 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
11 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13 | PERFORMANCE OF THIS SOFTWARE.
14 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/gotocelldialog.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "gotocelldialog.h"
4 |
5 | GoToCellDialog::GoToCellDialog(QWidget *parent)
6 | : QDialog(parent)
7 | {
8 | setupUi(this);
9 |
10 | QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
11 | lineEdit->setValidator(new QRegExpValidator(regExp, this));
12 |
13 | connect(okButton, &QPushButton::clicked, this, &GoToCellDialog::accept);
14 | connect(cancelButton, &QPushButton::clicked, this, &GoToCellDialog::reject);
15 | connect(lineEdit, &QLineEdit::textChanged, this, &GoToCellDialog::textChanged);
16 | }
17 |
18 | void GoToCellDialog::textChanged()
19 | {
20 | okButton->setEnabled(lineEdit->hasAcceptableInput());
21 | }
22 |
--------------------------------------------------------------------------------
/MultiLanguageApp/dialog.h:
--------------------------------------------------------------------------------
1 | #ifndef DIALOG_H
2 | #define DIALOG_H
3 |
4 | #include
5 |
6 | class QComboBox;
7 | class QLabel;
8 | class QToolButton;
9 |
10 | class Dialog : public QDialog
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | Dialog(QWidget *parent = 0);
16 | ~Dialog();
17 |
18 | private slots:
19 | void slotAcceptParameters();
20 | void slotComboChanged(int ind);
21 |
22 | private:
23 | QComboBox* createCombobox(QStringList& list, QWidget* parent = nullptr);
24 | void updateUI();
25 | QToolButton* createButton();
26 |
27 | // Data members.
28 | QLabel* m_label;
29 | QComboBox* m_combo;
30 | QToolButton* m_cancelBtn;
31 | };
32 |
33 | #endif // DIALOG_H
34 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/spreadsheet.pro:
--------------------------------------------------------------------------------
1 | lessThan(QT_MAJOR_VERSION, 5): error(This project requires Qt 5 or later)
2 |
3 | TEMPLATE = app
4 |
5 | QT += widgets
6 |
7 | HEADERS = cell.h \
8 | finddialog.h \
9 | gotocelldialog.h \
10 | mainwindow.h \
11 | sortdialog.h \
12 | spreadsheet.h
13 | SOURCES = cell.cpp \
14 | finddialog.cpp \
15 | gotocelldialog.cpp \
16 | main.cpp \
17 | mainwindow.cpp \
18 | sortdialog.cpp \
19 | spreadsheet.cpp
20 | FORMS = gotocelldialog.ui \
21 | sortdialog.ui
22 | RESOURCES = spreadsheet.qrc
23 |
--------------------------------------------------------------------------------
/widgetsandqml/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.1
2 |
3 | Rectangle {
4 | id: rectangle
5 | color: "red"
6 | width: 200
7 | height: 200
8 |
9 | Text {
10 | id: text
11 | text: "This is QML code.\n(Click to pause)"
12 | font.pointSize: 14
13 | anchors.centerIn: parent
14 | PropertyAnimation {
15 | id: animation
16 | target: text
17 | property: "rotation"
18 | from: 0; to: 360; duration: 5000
19 | loops: Animation.Infinite
20 | }
21 | }
22 | MouseArea {
23 | anchors.fill: parent
24 | onClicked: animation.paused ? animation.resume() : animation.pause()
25 | }
26 | Component.onCompleted: animation.start()
27 | }
28 |
--------------------------------------------------------------------------------
/widgetsandqml/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "mainwindow.h"
3 | #include "ui_mainwindow.h"
4 |
5 | MainWindow::MainWindow(QWidget *parent) :
6 | QMainWindow(parent),
7 | ui(new Ui::MainWindow)
8 | {
9 | ui->setupUi(this);
10 |
11 | connect(ui->pushButton, SIGNAL(clicked()), qApp, SLOT(quit()));
12 |
13 | QQuickView *view = new QQuickView();
14 | QWidget *container = QWidget::createWindowContainer(view, this);
15 | container->setMinimumSize(200, 200);
16 | container->setMaximumSize(200, 200);
17 | container->setFocusPolicy(Qt::TabFocus);
18 | view->setSource(QUrl("main.qml"));
19 | ui->verticalLayout->addWidget(container);
20 | }
21 |
22 | MainWindow::~MainWindow()
23 | {
24 | delete ui;
25 | }
26 |
--------------------------------------------------------------------------------
/calculator-qml/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include "calculator.h"
8 |
9 | int main(int argc, char *argv[])
10 | {
11 | QGuiApplication app(argc, argv);
12 |
13 | // create view window
14 | QQuickView *view = new QQuickView;
15 | view->setSource(QUrl("qrc:/Calculator.qml"));
16 | view->setResizeMode(QQuickView::SizeRootObjectToView);
17 | view->resize(300, 400);
18 |
19 | // create Calculator object
20 | Calculator calculator;
21 | calculator.setRootObject(view->rootObject());
22 |
23 | QObject::connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
24 | view->show();
25 |
26 | return app.exec();
27 | }
28 |
--------------------------------------------------------------------------------
/MasksValidators/validatordemo/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | namespace Ui {
10 | class MainWindow;
11 | }
12 |
13 | class MainWindow : public QMainWindow
14 | {
15 | Q_OBJECT
16 |
17 | public:
18 | explicit MainWindow(QWidget *parent = 0);
19 | ~MainWindow();
20 |
21 | private:
22 | void setValidator();
23 | void updateStatusBar();
24 | void checkRegularExpression();
25 |
26 | Ui::MainWindow *ui;
27 | QIntValidator *intValidator;
28 | QDoubleValidator *doubleValidator;
29 | QRegularExpressionValidator *regularExpressionValidator;
30 | };
31 |
32 | #endif // MAINWINDOW_H
33 |
--------------------------------------------------------------------------------
/MasksValidators/maskandvalidatordemo/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | namespace Ui {
10 | class MainWindow;
11 | }
12 |
13 | class MainWindow : public QMainWindow
14 | {
15 | Q_OBJECT
16 |
17 | public:
18 | explicit MainWindow(QWidget *parent = 0);
19 | ~MainWindow();
20 |
21 | private:
22 | void setValidator();
23 | void updateStatusBar();
24 | void checkRegularExpression();
25 |
26 | Ui::MainWindow *ui;
27 | QIntValidator *intValidator;
28 | QDoubleValidator *doubleValidator;
29 | QRegularExpressionValidator *regularExpressionValidator;
30 | };
31 |
32 | #endif // MAINWINDOW_H
33 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/Makefile:
--------------------------------------------------------------------------------
1 | # Python 2
2 | #VER=2.7
3 |
4 | # Python 3
5 | VER=3.6
6 |
7 | RCC = $(HOME)/.local/lib/python${VER}/site-packages/PySide2/pyside2-rcc
8 | UIC = $(HOME)/.local/lib/python${VER}/site-packages/PySide2/scripts/uic.py
9 |
10 | all: spreadsheet_rc.py ui_sortdialog.py ui_gotocelldialog.py
11 |
12 | spreadsheet_rc.py: spreadsheet.qrc
13 | $(RCC) spreadsheet.qrc >spreadsheet_rc.py
14 |
15 | ui_sortdialog.py: sortdialog.ui
16 | $(UIC) sortdialog.ui >ui_sortdialog.py
17 |
18 | ui_gotocelldialog.py: gotocelldialog.ui
19 | $(UIC) gotocelldialog.ui >ui_gotocelldialog.py
20 |
21 | check: flake8
22 |
23 | pep8: flake8
24 |
25 | flake8:
26 | flake8 --max-line-length=132 spreadsheet.py
27 |
28 | distclean: clean
29 |
30 | clean:
31 | $(RM) ui_*.py *_rc.py *.pyc
32 | $(RM) -rf __pycache__
33 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/finddialog.h:
--------------------------------------------------------------------------------
1 | #ifndef FINDDIALOG_H
2 | #define FINDDIALOG_H
3 |
4 | #include
5 |
6 | class QCheckBox;
7 | class QLabel;
8 | class QLineEdit;
9 | class QPushButton;
10 |
11 | class FindDialog : public QDialog
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | FindDialog(QWidget *parent = 0);
17 |
18 | signals:
19 | void findNext(const QString &str, Qt::CaseSensitivity cs);
20 | void findPrevious(const QString &str, Qt::CaseSensitivity cs);
21 |
22 | private slots:
23 | void findClicked();
24 | void enableFindButton(const QString &text);
25 |
26 | private:
27 | QLabel *label;
28 | QLineEdit *lineEdit;
29 | QCheckBox *caseCheckBox;
30 | QCheckBox *backwardCheckBox;
31 | QPushButton *findButton;
32 | QPushButton *closeButton;
33 | };
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/cell.h:
--------------------------------------------------------------------------------
1 | #ifndef CELL_H
2 | #define CELL_H
3 |
4 | #include
5 |
6 | class Cell : public QTableWidgetItem
7 | {
8 | public:
9 | Cell();
10 |
11 | QTableWidgetItem *clone() const;
12 | void setData(int role, const QVariant &value);
13 | QVariant data(int role) const;
14 | void setFormula(const QString &formula);
15 | QString formula() const;
16 | void setDirty();
17 |
18 | private:
19 | QVariant value() const;
20 | QVariant evalExpression(const QString &str, int &pos) const;
21 | QVariant evalTerm(const QString &str, int &pos) const;
22 | QVariant evalFactor(const QString &str, int &pos) const;
23 |
24 | mutable QVariant cachedValue;
25 | mutable bool cacheIsDirty;
26 | const QVariant Invalid = QVariant();
27 | };
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/CppBinding/example2/example2.pro:
--------------------------------------------------------------------------------
1 | QT += quick
2 |
3 | CONFIG += c++11
4 |
5 | # You can make your code fail to compile if it uses deprecated APIs.
6 | # In order to do so, uncomment the following line.
7 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
8 |
9 | SOURCES += \
10 | main.cpp \
11 | exclass.cpp
12 |
13 | # Additional import path used to resolve QML modules in Qt Creator's code model
14 | QML_IMPORT_PATH =
15 |
16 | # Additional import path used to resolve QML modules just for Qt Quick Designer
17 | QML_DESIGNER_IMPORT_PATH =
18 |
19 | # Default rules for deployment.
20 | qnx: target.path = /tmp/$${TARGET}/bin
21 | else: unix:!android: target.path = /opt/$${TARGET}/bin
22 | !isEmpty(target.path): INSTALLS += target
23 |
24 | HEADERS += \
25 | exclass.h
26 |
--------------------------------------------------------------------------------
/gpio/part5/demo3.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Example of programming GPIO from C or C++ using the WiringPi library
4 | on a Raspberry Pi.
5 |
6 | Will read a pushbutton switch on GPIO6 (physical pin 31) every 500
7 | milliseconds and report the status. seconds and then exit.
8 |
9 | Jeff Tranter
10 |
11 | */
12 |
13 | #include
14 | #include
15 |
16 | int main(void)
17 | {
18 | // Switch: Physical pin 31, BCM GPIO6, and WiringPi pin 22.
19 | const int button = 22;
20 |
21 | wiringPiSetup();
22 |
23 | pinMode(button, INPUT);
24 |
25 | while (1) {
26 | if (digitalRead(button) == LOW) {
27 | fprintf(stderr, "Switch is pressed\n");
28 | } else {
29 | fprintf(stderr, "Switch is released\n");
30 | }
31 | delay(500);
32 | }
33 |
34 | return 0;
35 | }
36 |
--------------------------------------------------------------------------------
/MasksValidators/qmldemo/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.6
2 | import QtQuick.Controls 2.1
3 |
4 | ApplicationWindow {
5 | visible: true
6 | width: 400
7 | height: 480
8 | title: qsTr("Validator Demo")
9 |
10 | SwipeView {
11 | id: swipeView
12 | anchors.fill: parent
13 | currentIndex: tabBar.currentIndex
14 |
15 | Page1 {
16 | }
17 |
18 | Page2 {
19 | }
20 |
21 | Page3 {
22 | }
23 | }
24 |
25 | footer: TabBar {
26 | id: tabBar
27 | currentIndex: swipeView.currentIndex
28 |
29 | TabButton {
30 | text: qsTr("IntValidator")
31 | }
32 |
33 | TabButton {
34 | text: qsTr("DoubleValidator")
35 | }
36 |
37 | TabButton {
38 | text: qsTr("RegExpValidator")
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/MasksValidators/qml/inputmask1.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.9
2 | import QtQuick.Window 2.2
3 | import QtQuick.Layouts 1.0
4 |
5 | Window {
6 | visible: true
7 | width: 300
8 | height: 100
9 | title: qsTr("Input Mask Demo")
10 |
11 | GridLayout {
12 | columns: 2
13 |
14 | Text {
15 | id: label1
16 | text: qsTr("Input Text:")
17 | }
18 |
19 | TextInput {
20 | id: input
21 | text: qsTr("1")
22 | inputMask: mask.text
23 | onTextChanged: acceptableInput ? print("Input acceptable") : print("Input not acceptable")
24 | }
25 |
26 | Text {
27 | id: label2
28 | text: qsTr("Input Mask:")
29 | }
30 |
31 | TextInput {
32 | id: mask
33 | text: qsTr("999999")
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/CppBinding/example1/example1.pro:
--------------------------------------------------------------------------------
1 | QT += quick
2 |
3 | CONFIG += c++11
4 |
5 | # You can make your code fail to compile if it uses deprecated APIs.
6 | # In order to do so, uncomment the following line.
7 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
8 |
9 | SOURCES += \
10 | main.cpp \
11 | rectanglemanager.cpp
12 |
13 | RESOURCES += qml.qrc
14 |
15 | # Additional import path used to resolve QML modules in Qt Creator's code model
16 | QML_IMPORT_PATH =
17 |
18 | # Additional import path used to resolve QML modules just for Qt Quick Designer
19 | QML_DESIGNER_IMPORT_PATH =
20 |
21 | # Default rules for deployment.
22 | qnx: target.path = /tmp/$${TARGET}/bin
23 | else: unix:!android: target.path = /opt/$${TARGET}/bin
24 | !isEmpty(target.path): INSTALLS += target
25 |
26 | HEADERS += \
27 | rectanglemanager.h
28 |
--------------------------------------------------------------------------------
/CppBinding/example1/main.cpp:
--------------------------------------------------------------------------------
1 | #include "rectanglemanager.h"
2 |
3 | #include
4 | #include
5 | #include
6 | int main(int argc, char *argv[])
7 | {
8 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
9 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
10 | #endif
11 |
12 | QGuiApplication app(argc, argv);
13 |
14 | QQmlApplicationEngine engine;
15 | RectangleManager rectManager;
16 | engine.rootContext()->setContextProperty("rectangleManager", &rectManager);
17 |
18 | const QUrl url(QStringLiteral("qrc:/main.qml"));
19 | QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
20 | &app, [url](QObject *obj, const QUrl &objUrl) {
21 | if (!obj && url == objUrl)
22 | QCoreApplication::exit(-1);
23 | }, Qt::QueuedConnection);
24 | engine.load(url);
25 |
26 | return app.exec();
27 | }
28 |
--------------------------------------------------------------------------------
/MultiLanguageApp/TranslatorManager.h:
--------------------------------------------------------------------------------
1 | #ifndef TRANSLATORMANAGER_H
2 | #define TRANSLATORMANAGER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | typedef QMap TranslatorMap;
10 |
11 | class TranslatorManager
12 | {
13 | public:
14 | static TranslatorManager* instance();
15 | ~TranslatorManager();
16 |
17 | bool setTranslator(QString& lang);
18 | inline QString getCurrentLang() { return m_keyLang; }
19 |
20 | private:
21 | TranslatorManager();
22 |
23 | // Hide copy constructor and assignment operator.
24 | TranslatorManager(const TranslatorManager &);
25 | TranslatorManager& operator=(const TranslatorManager &);
26 |
27 | // Class instance.
28 | static TranslatorManager* m_Instance;
29 |
30 | TranslatorMap m_translators;
31 | QString m_keyLang;
32 | };
33 |
34 | #endif // TRANSLATORMANAGER_H
35 |
--------------------------------------------------------------------------------
/gpio/part4/pwm2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | import sys
4 | import time
5 | import RPi.GPIO as GPIO
6 |
7 |
8 | # Callback called when switch is pressed.
9 | def switch_callback(channel):
10 | print('Switch pressed, exiting.')
11 | GPIO.cleanup()
12 | sys.exit(0)
13 |
14 |
15 | led1 = 18 # Red
16 | led2 = 22 # Green
17 | led3 = 29 # Yellow
18 | switch = 31
19 |
20 | GPIO.setmode(GPIO.BOARD)
21 | GPIO.setup(led1, GPIO.OUT)
22 | GPIO.setup(led2, GPIO.OUT)
23 | GPIO.setup(led3, GPIO.OUT)
24 | GPIO.setup(switch, GPIO.IN)
25 |
26 | GPIO.add_event_detect(switch, GPIO.FALLING, callback=switch_callback)
27 |
28 | while True:
29 | for pin in [led1, led2, led3]:
30 | p = GPIO.PWM(pin, 50)
31 | p.start(0)
32 | for dc in range(0, 101, 5):
33 | p.ChangeDutyCycle(dc)
34 | time.sleep(0.05)
35 | for dc in range(100, -1, -5):
36 | p.ChangeDutyCycle(dc)
37 | time.sleep(0.05)
38 |
--------------------------------------------------------------------------------
/Timers/qml/Example.qml:
--------------------------------------------------------------------------------
1 | // Simple QML Timer example
2 |
3 | import QtQuick 2.6
4 | import QtQuick.Controls 2.4
5 |
6 | Rectangle {
7 | height: 200
8 | width: 250
9 |
10 | property int count: 0
11 |
12 | Timer {
13 | id: timer
14 | interval: 100
15 | running: false
16 | repeat: true
17 | onTriggered: count += 1
18 |
19 | }
20 |
21 | Column {
22 | anchors.fill: parent
23 | Text {
24 | id: text
25 | font.pixelSize: 100
26 | text: (count / 10).toFixed(1)
27 | }
28 | Row {
29 | spacing: 10
30 |
31 | Button {
32 | text: timer.running ? "Stop" : "Start"
33 | onClicked: timer.running = !timer.running
34 | }
35 | Button {
36 | text: "Reset"
37 | onClicked: count = 0
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/MasksValidators/qml/validator3.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.9
2 | import QtQuick.Window 2.2
3 | import QtQuick.Layouts 1.0
4 |
5 | Window {
6 | visible: true
7 | width: 300
8 | height: 100
9 | title: qsTr("Regular Expression Validator Demo")
10 |
11 | GridLayout {
12 | columns: 2
13 |
14 | Text {
15 | id: label1
16 | text: qsTr("Input Text:")
17 | }
18 |
19 | TextInput {
20 | id: input
21 | text: qsTr("1")
22 | validator: RegExpValidator {
23 | regExp: RegExp(regexp.text)
24 | }
25 | onTextChanged: acceptableInput ? print("Input acceptable") : print("Input not acceptable")
26 | }
27 |
28 | Text {
29 | id: label2
30 | text: qsTr("Regular Expression:")
31 | }
32 |
33 | TextInput {
34 | id: regexp
35 | text: "[a-zA-Z0-9]+"
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/MasksValidators/inputmaskdemo/inputmaskdemo.pro:
--------------------------------------------------------------------------------
1 | lessThan(QT_MAJOR_VERSION, 5): error(This project requires Qt 5 or later)
2 |
3 | QT += gui widgets
4 |
5 | TARGET = inputmaskdemo
6 | TEMPLATE = app
7 |
8 | # The following define makes your compiler emit warnings if you use
9 | # any feature of Qt which has been marked as deprecated (the exact warnings
10 | # depend on your compiler). Please consult the documentation of the
11 | # deprecated API in order to know how to port your code away from it.
12 | DEFINES += QT_DEPRECATED_WARNINGS
13 |
14 | # You can also make your code fail to compile if you use deprecated APIs.
15 | # In order to do so, uncomment the following line.
16 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
17 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
18 |
19 | SOURCES += \
20 | main.cpp \
21 | mainwindow.cpp
22 |
23 | HEADERS += \
24 | mainwindow.h
25 |
26 | FORMS += \
27 | mainwindow.ui
28 |
--------------------------------------------------------------------------------
/calculator-qml/calculator.h:
--------------------------------------------------------------------------------
1 | #ifndef CALCULATOR_H
2 | #define CALCULATOR_H
3 |
4 | #include
5 |
6 | class Calculator : public QObject
7 | {
8 | Q_OBJECT
9 | Q_PROPERTY(QString display READ display WRITE setDisplay NOTIFY displayChanged)
10 |
11 | public:
12 | Calculator(QObject *parent = 0);
13 | ~Calculator();
14 |
15 | void setRootObject(QObject *root);
16 |
17 | QString display() const { return mDisplay; }
18 |
19 | public slots:
20 | void setDisplay(const QString &display);
21 |
22 | void keyClicked(int key);
23 | void editCut();
24 | void editCopy();
25 | void editPaste();
26 |
27 | signals:
28 | void displayChanged();
29 |
30 | private:
31 | void clearAll();
32 | double calculate(double rightoperand, int operation);
33 |
34 | private slots:
35 | void onDisplayChanged();
36 |
37 | private:
38 | QObject *mRoot;
39 | QString mDisplay;
40 | double mResult;
41 | bool mExpectingOperand;
42 | int mPendingOperator;
43 | };
44 |
45 | #endif // CALCULATOR_H
46 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/sortdialog.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "sortdialog.h"
4 |
5 | SortDialog::SortDialog(QWidget *parent)
6 | : QDialog(parent)
7 | {
8 | setupUi(this);
9 |
10 | secondaryGroupBox->hide();
11 | tertiaryGroupBox->hide();
12 | layout()->setSizeConstraint(QLayout::SetFixedSize);
13 |
14 | setColumnRange('A', 'Z');
15 | }
16 |
17 | void SortDialog::setColumnRange(QChar first, QChar last)
18 | {
19 | primaryColumnCombo->clear();
20 | secondaryColumnCombo->clear();
21 | tertiaryColumnCombo->clear();
22 |
23 | secondaryColumnCombo->addItem(tr("None"));
24 | tertiaryColumnCombo->addItem(tr("None"));
25 |
26 | primaryColumnCombo->setMinimumSize(
27 | secondaryColumnCombo->sizeHint());
28 |
29 | QChar ch = first;
30 | while (ch <= last) {
31 | primaryColumnCombo->addItem(QString(ch));
32 | secondaryColumnCombo->addItem(QString(ch));
33 | tertiaryColumnCombo->addItem(QString(ch));
34 | ch = ch.unicode() + 1;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MultiLanguageApp/translation.cpp:
--------------------------------------------------------------------------------
1 | #include "translation.h"
2 | #include
3 |
4 | const char* ID_APP_TITLE = QT_TRID_NOOP("id_app_title");
5 | const char* ID_LABEL_TEXT = QT_TRID_NOOP("id_label_text");
6 | const char* ID_COMBO_ITEM_1 = QT_TRID_NOOP("id_combo_item_1");
7 | const char* ID_COMBO_ITEM_2 = QT_TRID_NOOP("id_combo_item_2");
8 | const char* ID_COMBO_ITEM_3 = QT_TRID_NOOP("id_combo_item_3");
9 | const char* ID_BUTTON_TEXT_1 = QT_TRID_NOOP("id_button_text_1");
10 | const char* ID_MENU_FILE = QT_TRID_NOOP("id_menu_file");
11 | const char* ID_MENU_FILE_OPEN = QT_TRID_NOOP("id_menu_file_open");
12 | const char* ID_MENU_FILE_SAVE = QT_TRID_NOOP("id_menu_file_save");
13 | const char* ID_MENU_FILE_CLOSE = QT_TRID_NOOP("id_menu_file_close");
14 | const char* ID_MENU_FILE_EXIT = QT_TRID_NOOP("id_menu_file_exit");
15 | const char* ID_MENU_SETTINGS = QT_TRID_NOOP("id_menu_settings");
16 | const char* ID_MENU_SETTINGS_SELECT = QT_TRID_NOOP("id_menu_settings_select");
17 |
--------------------------------------------------------------------------------
/MasksValidators/validatordemo/validatordemo.pro:
--------------------------------------------------------------------------------
1 | QT += core gui widgets
2 |
3 | lessThan(QT_MAJOR_VERSION, 5) | lessThan(QT_MINOR_VERSION, 7): error(This project requires Qt 5.7 or later)
4 |
5 | TARGET = validatordemo
6 | TEMPLATE = app
7 |
8 | # The following define makes your compiler emit warnings if you use
9 | # any feature of Qt which has been marked as deprecated (the exact warnings
10 | # depend on your compiler). Please consult the documentation of the
11 | # deprecated API in order to know how to port your code away from it.
12 | DEFINES += QT_DEPRECATED_WARNINGS
13 |
14 | # You can also make your code fail to compile if you use deprecated APIs.
15 | # In order to do so, uncomment the following line.
16 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
17 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
18 |
19 |
20 | SOURCES += \
21 | main.cpp \
22 | mainwindow.cpp
23 |
24 | HEADERS += \
25 | mainwindow.h
26 |
27 | FORMS += \
28 | mainwindow.ui
29 |
--------------------------------------------------------------------------------
/MasksValidators/maskandvalidatordemo/maskandvalidatordemo.pro:
--------------------------------------------------------------------------------
1 | QT += core gui widgets
2 |
3 | lessThan(QT_MAJOR_VERSION, 5) | lessThan(QT_MINOR_VERSION, 7): error(This project requires Qt 5.7 or later)
4 |
5 | TARGET = maskandvalidatordemo
6 | TEMPLATE = app
7 |
8 | # The following define makes your compiler emit warnings if you use
9 | # any feature of Qt which has been marked as deprecated (the exact warnings
10 | # depend on your compiler). Please consult the documentation of the
11 | # deprecated API in order to know how to port your code away from it.
12 | DEFINES += QT_DEPRECATED_WARNINGS
13 |
14 | # You can also make your code fail to compile if you use deprecated APIs.
15 | # In order to do so, uncomment the following line.
16 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
17 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
18 |
19 |
20 | SOURCES += \
21 | main.cpp \
22 | mainwindow.cpp
23 |
24 | HEADERS += \
25 | mainwindow.h
26 |
27 | FORMS += \
28 | mainwindow.ui
29 |
--------------------------------------------------------------------------------
/widgetsandqml/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 400
10 | 300
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 | -
19 |
20 |
21 | Quit
22 |
23 |
24 |
25 | -
26 |
27 |
28 | This is a widget.
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/QCompleter/completerdemo/completerdemo.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | lessThan(QT_MAJOR_VERSION, 5) | lessThan(QT_MINOR_VERSION, 7): error(This project requires Qt 5.7 or later)
4 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
5 |
6 | TARGET = completerdemo
7 | TEMPLATE = app
8 |
9 | # The following define makes your compiler emit warnings if you use
10 | # any feature of Qt which has been marked as deprecated (the exact warnings
11 | # depend on your compiler). Please consult the documentation of the
12 | # deprecated API in order to know how to port your code away from it.
13 | DEFINES += QT_DEPRECATED_WARNINGS
14 |
15 | # You can also make your code fail to compile if you use deprecated APIs.
16 | # In order to do so, uncomment the following line.
17 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
18 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
19 |
20 |
21 | SOURCES += \
22 | main.cpp \
23 | mainwindow.cpp
24 |
25 | HEADERS += \
26 | mainwindow.h
27 |
28 | FORMS += \
29 | mainwindow.ui
30 |
31 | RESOURCES += \
32 | resources.qrc
33 |
--------------------------------------------------------------------------------
/gpio/part4/demo.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import RPi.GPIO as GPIO
4 | import time
5 | import atexit
6 |
7 | def cleanup():
8 | print("Cleaning up")
9 | GPIO.cleanup()
10 |
11 | led1 = 24
12 | led2 = 25
13 | led3 = 5
14 | sw1 = 6
15 |
16 | atexit.register(cleanup)
17 |
18 | #print(GPIO.RPI_INFO)
19 |
20 | print("Platform info:")
21 | for key in GPIO.RPI_INFO:
22 | print(" {} = {}".format(key, GPIO.RPI_INFO[key]))
23 |
24 | GPIO.setmode(GPIO.BCM)
25 | #GPIO.setwarnings(False)
26 | GPIO.setup(led1, GPIO.OUT)
27 | GPIO.setup(led2, GPIO.OUT)
28 | GPIO.setup(led3, GPIO.OUT)
29 | GPIO.setup(sw1, GPIO.IN)
30 |
31 | while True:
32 | # Make LEDs cycle in a binary count pattern.
33 | for i in range(8):
34 | if (i & 1):
35 | GPIO.output(led3, GPIO.HIGH)
36 | else:
37 | GPIO.output(led3, GPIO.LOW)
38 | if (i & 2):
39 | GPIO.output(led2, GPIO.HIGH)
40 | else:
41 | GPIO.output(led2, GPIO.LOW)
42 | if (i & 4):
43 | GPIO.output(led1, GPIO.HIGH)
44 | else:
45 | GPIO.output(led1, GPIO.LOW)
46 |
47 | time.sleep(0.2)
48 |
49 | # Wait if button is pressed (is high).
50 | while GPIO.input(sw1) == GPIO.LOW:
51 | pass
52 |
--------------------------------------------------------------------------------
/Timers/basictimer/basictimer.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | TARGET = basictimer
6 | TEMPLATE = app
7 |
8 | # The following define makes your compiler emit warnings if you use
9 | # any feature of Qt which has been marked as deprecated (the exact warnings
10 | # depend on your compiler). Please consult the documentation of the
11 | # deprecated API in order to know how to port your code away from it.
12 | DEFINES += QT_DEPRECATED_WARNINGS
13 |
14 | # You can also make your code fail to compile if you use deprecated APIs.
15 | # In order to do so, uncomment the following line.
16 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
17 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
18 |
19 |
20 | SOURCES += \
21 | main.cpp \
22 | mainwindow.cpp
23 |
24 | HEADERS += \
25 | mainwindow.h
26 |
27 | FORMS += \
28 | mainwindow.ui
29 |
30 | # Default rules for deployment.
31 | qnx: target.path = /tmp/$${TARGET}/bin
32 | else: unix:!android: target.path = /opt/$${TARGET}/bin
33 | !isEmpty(target.path): INSTALLS += target
34 |
--------------------------------------------------------------------------------
/Timers/elapsedtimer/elapsedtimer.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | TARGET = elapsedtimer
6 | TEMPLATE = app
7 |
8 | # The following define makes your compiler emit warnings if you use
9 | # any feature of Qt which has been marked as deprecated (the exact warnings
10 | # depend on your compiler). Please consult the documentation of the
11 | # deprecated API in order to know how to port your code away from it.
12 | DEFINES += QT_DEPRECATED_WARNINGS
13 |
14 | # You can also make your code fail to compile if you use deprecated APIs.
15 | # In order to do so, uncomment the following line.
16 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
17 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
18 |
19 |
20 | SOURCES += \
21 | main.cpp \
22 | mainwindow.cpp
23 |
24 | HEADERS += \
25 | mainwindow.h
26 |
27 | FORMS += \
28 | mainwindow.ui
29 |
30 | # Default rules for deployment.
31 | qnx: target.path = /tmp/$${TARGET}/bin
32 | else: unix:!android: target.path = /opt/$${TARGET}/bin
33 | !isEmpty(target.path): INSTALLS += target
34 |
--------------------------------------------------------------------------------
/calculator-qml/qml/Button.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.0
2 | import QtQuick.Layouts 1.0
3 |
4 | Rectangle {
5 | id: button
6 |
7 | Layout.minimumWidth: 32
8 | Layout.minimumHeight: 32
9 | Layout.preferredWidth: 128
10 | Layout.preferredHeight: 32
11 | Layout.fillWidth: true
12 | Layout.fillHeight: false
13 | radius: Math.min(height, width) / 6
14 |
15 | signal clicked()
16 |
17 | property alias text: label.text
18 | property string startColor: "lightblue"
19 | property string endColor: "cadetblue"
20 |
21 | gradient:
22 | Gradient {
23 | GradientStop { position: 0.0; color: mousearea.pressed ? button.endColor : button.startColor }
24 | GradientStop { position: 1.0; color: mousearea.pressed ? button.startColor : button.endColor }
25 | }
26 |
27 | Text {
28 | id: label
29 | anchors.centerIn: parent
30 | anchors.margins: 4
31 | font.pixelSize: Math.min(button.height, button.width) - 4*2
32 | font.bold: true
33 | }
34 |
35 | MouseArea {
36 | id: mousearea
37 | anchors.fill: parent
38 | onClicked: {
39 | button.clicked();
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/MasksValidators/qmldemo/qmldemo.pro:
--------------------------------------------------------------------------------
1 | QT += quick
2 | CONFIG += c++11
3 |
4 | # The following define makes your compiler emit warnings if you use
5 | # any feature of Qt which as been marked deprecated (the exact warnings
6 | # depend on your compiler). Please consult the documentation of the
7 | # deprecated API in order to know how to port your code away from it.
8 | DEFINES += QT_DEPRECATED_WARNINGS
9 |
10 | # You can also make your code fail to compile if you use deprecated APIs.
11 | # In order to do so, uncomment the following line.
12 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
13 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
14 |
15 | SOURCES += \
16 | main.cpp
17 |
18 | RESOURCES += qml.qrc
19 |
20 | # Additional import path used to resolve QML modules in Qt Creator's code model
21 | QML_IMPORT_PATH =
22 |
23 | # Additional import path used to resolve QML modules just for Qt Quick Designer
24 | QML_DESIGNER_IMPORT_PATH =
25 |
26 | # Default rules for deployment.
27 | qnx: target.path = /tmp/$${TARGET}/bin
28 | else: unix:!android: target.path = /opt/$${TARGET}/bin
29 | !isEmpty(target.path): INSTALLS += target
30 |
--------------------------------------------------------------------------------
/MoveToTrash/trashdemo/trashdemo.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | lessThan(QT_MAJOR_VERSION, 5) | lessThan(QT_MINOR_VERSION, 15): error(This project requires Qt 5.15 or later)
4 |
5 | QT += widgets
6 |
7 | CONFIG += c++11
8 |
9 | # The following define makes your compiler emit warnings if you use
10 | # any Qt feature that has been marked deprecated (the exact warnings
11 | # depend on your compiler). Please consult the documentation of the
12 | # deprecated API in order to know how to port your code away from it.
13 | DEFINES += QT_DEPRECATED_WARNINGS
14 |
15 | # You can also make your code fail to compile if it uses deprecated APIs.
16 | # In order to do so, uncomment the following line.
17 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
18 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
19 |
20 | SOURCES += \
21 | main.cpp \
22 | mainwindow.cpp
23 |
24 | HEADERS += \
25 | mainwindow.h
26 |
27 | FORMS += \
28 | mainwindow.ui
29 |
30 | # Default rules for deployment.
31 | qnx: target.path = /tmp/$${TARGET}/bin
32 | else: unix:!android: target.path = /opt/$${TARGET}/bin
33 | !isEmpty(target.path): INSTALLS += target
34 |
--------------------------------------------------------------------------------
/calendardemo/calendardemo.pro:
--------------------------------------------------------------------------------
1 | lessThan(QT_MAJOR_VERSION, 5) | lessThan(QT_MINOR_VERSION, 14): error(This project requires Qt 5.14 or later)
2 |
3 | QT += core gui
4 |
5 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
--------------------------------------------------------------------------------
/MasksValidators/qml/validator1.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.9
2 | import QtQuick.Window 2.2
3 | import QtQuick.Layouts 1.0
4 |
5 | Window {
6 | visible: true
7 | width: 300
8 | height: 100
9 | title: qsTr("Int Validator Demo")
10 |
11 | GridLayout {
12 | columns: 2
13 |
14 | Text {
15 | id: label1
16 | text: qsTr("Input Text:")
17 | }
18 |
19 | TextInput {
20 | id: input
21 | text: qsTr("1")
22 | validator: IntValidator {
23 | bottom: parseInt(bottom.text)
24 | top: parseInt(top.text)
25 | }
26 | onTextChanged: acceptableInput ? print("Input acceptable") : print("Input not acceptable")
27 | }
28 |
29 | Text {
30 | id: label2
31 | text: qsTr("Bottom:")
32 | }
33 |
34 | TextInput {
35 | id: bottom
36 | inputMask: "00000000"
37 | text: qsTr("1")
38 | }
39 |
40 | Text {
41 | id: label3
42 | text: qsTr("Top:")
43 | }
44 |
45 | TextInput {
46 | id: top
47 | inputMask: "00000000"
48 | text: qsTr("100")
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/CppBinding/example2/main.cpp:
--------------------------------------------------------------------------------
1 | #include "exclass.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QCoreApplication a(argc, argv);
7 | ExClass *object1 = new ExClass();
8 | ExClass *relatedObject2 = new ExClass();
9 |
10 | QObject::connect(object1, &ExClass::stringChanged,
11 | relatedObject2, &ExClass::setStringText);
12 |
13 | // for < Qt 6.0
14 | qDebug()<< "relatedObject2 value before object1 sets value: " << relatedObject2->getString();
15 |
16 | object1->setStringText("new object1 Hi");
17 | qDebug()<< "relatedObject2 value after object1 sets value: " << relatedObject2->getString();
18 |
19 | // for >= Qt 6.0
20 | qDebug()<< "\nBEYOND Qt 6.0";
21 | object1->stringProperty = "object1 Hi";
22 | qDebug()<< "relatedObject2 value before binding: " << relatedObject2->stringProperty;
23 |
24 | relatedObject2->stringProperty.setBinding([&](){return object1->stringProperty.value();});
25 | qDebug()<< "relatedObject2 value after binding: " << relatedObject2->stringProperty;
26 |
27 | object1->stringProperty = "New object1 Hi";
28 | qDebug()<< "relatedObject2 value after object1's value changed: " << relatedObject2->stringProperty;
29 |
30 | return a.exec();
31 | }
32 |
--------------------------------------------------------------------------------
/CppBinding/example1/rectanglemanager.cpp:
--------------------------------------------------------------------------------
1 | #include "rectanglemanager.h"
2 |
3 | #include
4 |
5 | RectangleManager::RectangleManager(QObject *parent) : QObject(parent)
6 | {
7 | QTimer * timer = new QTimer(this);
8 | timer->setInterval(1000);
9 | timer->start();
10 | connect(timer, &QTimer::timeout, this, [&](){
11 | static int i = 0;
12 | b_rectangleCount = 10 + i;
13 |
14 | // Before Qt 6 Equivalent action:
15 | // setRectangleCount(10+i);
16 |
17 | i++;
18 | });
19 | }
20 |
21 | int RectangleManager::rectangleCount() const
22 | {
23 | // NOTE:
24 | // The following lines can the same if the
25 | // private member variable name is the same.
26 | // For the purpose of demonstrating bindings,
27 | // the variable name is slightly changed
28 |
29 | // Before Qt 6
30 | // return m_rectangleCount;
31 |
32 | // Qt 6 +
33 | return b_rectangleCount;
34 | }
35 |
36 | void RectangleManager::setRectangleCount(int rectangleCount)
37 | {
38 | // Before Qt 6:
39 | // if (m_rectangleCount == rectangleCount)
40 | // return;
41 |
42 | // m_rectangleCount = rectangleCount;
43 | // emit rectangleCountChanged();
44 |
45 |
46 | // Qt 6+ :
47 | b_rectangleCount = rectangleCount;
48 | }
49 |
--------------------------------------------------------------------------------
/QRandomGenerator/randomdemo2/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 500
10 | 500
11 |
12 |
13 |
14 | Random Demo
15 |
16 |
17 |
18 |
19 |
20 | 30
21 | 9
22 | 500
23 | 500
24 |
25 |
26 |
27 |
28 |
38 |
39 |
40 | TopToolBarArea
41 |
42 |
43 | false
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/MasksValidators/qml/inputmask2.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.9
2 | import QtQuick.Window 2.2
3 | import QtQuick.Layouts 1.0
4 | import QtQuick.Controls 2.4
5 |
6 | ApplicationWindow {
7 | visible: true
8 | width: 300
9 | height: 200
10 | title: qsTr("Input Mask Demo")
11 | footer: ToolBar {
12 | Label {
13 | Text {
14 | id: statusLine
15 | }
16 | }
17 | }
18 |
19 | GridLayout {
20 | columns: 2
21 |
22 | Text {
23 | id: label1
24 | text: qsTr("Input Text:")
25 | }
26 |
27 | TextField {
28 | id: input
29 | text: qsTr("1")
30 | inputMask: mask.text
31 | onTextChanged: acceptableInput ? statusLine.text = qsTr("Input acceptable") : statusLine.text = qsTr("Input not acceptable")
32 | }
33 |
34 | Text {
35 | id: label2
36 | text: qsTr("Input Mask:")
37 | }
38 |
39 | TextField {
40 | id: mask
41 | text: qsTr("999999")
42 | }
43 |
44 | Button {
45 | text: qsTr("&Clear")
46 | onClicked: {
47 | input.clear()
48 | mask.clear()
49 | }
50 | }
51 | Button {
52 | text: qsTr("&Quit")
53 | onClicked: {
54 | Qt.quit()
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/CppBinding/example1/rectanglemanager.h:
--------------------------------------------------------------------------------
1 | #ifndef RECTANGLEMANAGER_H
2 | #define RECTANGLEMANAGER_H
3 |
4 | #include
5 |
6 | class RectangleManager : public QObject
7 | {
8 | Q_OBJECT
9 | // Before Qt 6 : The Q_PROPERTY without binding:
10 | // Q_PROPERTY(int rectangleCount READ rectangleCount
11 | // WRITE setRectangleCount
12 | // NOTIFY rectangleCountChanged
13 | // )
14 |
15 | // Qt 6+ : The Q_PROPERTY with binding
16 | Q_PROPERTY(int rectangleCount READ rectangleCount
17 | WRITE setRectangleCount
18 | BINDABLE bindableRectangleCount
19 | )
20 |
21 | public:
22 | explicit RectangleManager(QObject *parent = nullptr);
23 | int rectangleCount() const;
24 |
25 | // Qt 6+ : Function passed to Q_PROPERTY for the BINDABLE macro
26 | QBindable bindableRectangleCount() { return &b_rectangleCount; }
27 |
28 | public slots:
29 | void setRectangleCount(int rectangleCount);
30 |
31 | signals:
32 | void rectangleCountChanged();
33 |
34 | private:
35 | // Before Qt 6:
36 | // int m_rectangleCount;
37 |
38 |
39 | // Qt 6+ :
40 | Q_OBJECT_BINDABLE_PROPERTY(RectangleManager,
41 | int,
42 | b_rectangleCount,
43 | &RectangleManager::rectangleCountChanged)
44 | };
45 |
46 | #endif // RECTANGLEMANAGER_H
47 |
--------------------------------------------------------------------------------
/MultiLanguageApp/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include "dialog.h"
4 | #include "translation.h"
5 |
6 | MainWindow::MainWindow(QWidget *parent) :
7 | QMainWindow(parent),
8 | m_ui(new Ui::MainWindow)
9 | {
10 | m_ui->setupUi(this);
11 | connect(m_ui->actionSelect_Language,SIGNAL(triggered()), this, SLOT(slotSelectLanguage()));
12 | }
13 |
14 | MainWindow::~MainWindow()
15 | {
16 | delete m_ui;
17 | }
18 |
19 | void MainWindow::slotSelectLanguage()
20 | {
21 | Dialog dlg(this);
22 | dlg.exec();
23 | }
24 |
25 | /* If you dynamically change the language in your application,
26 | * a changeEvent of type QEvent::LanguageChange is emitted.
27 | * You have to catch that and reset your text everywhere.
28 | */
29 | void MainWindow::changeEvent(QEvent *event)
30 | {
31 | if (event->type() == QEvent::LanguageChange)
32 | {
33 | // Set all text.
34 | setWindowTitle(qtTrId(ID_APP_TITLE));
35 | m_ui->menuFile->setTitle(qtTrId(ID_MENU_FILE));
36 | m_ui->menuSettings->setTitle(qtTrId(ID_MENU_SETTINGS));
37 | m_ui->actionOpen->setText(qtTrId(ID_MENU_FILE_OPEN));
38 | m_ui->actionSave->setText(qtTrId(ID_MENU_FILE_SAVE));
39 | m_ui->actionClose->setText(qtTrId(ID_MENU_FILE_CLOSE));
40 | m_ui->action_Exit->setText(qtTrId(ID_MENU_FILE_EXIT));
41 | m_ui->actionSelect_Language->setText(qtTrId(ID_MENU_SETTINGS_SELECT));
42 | }
43 | else
44 | {
45 | QMainWindow::changeEvent(event);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/MasksValidators/qml/validator2.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.9
2 | import QtQuick.Window 2.2
3 | import QtQuick.Layouts 1.0
4 |
5 | Window {
6 | visible: true
7 | width: 300
8 | height: 100
9 | title: qsTr("Double Validator Demo")
10 |
11 | GridLayout {
12 | columns: 2
13 |
14 | Text {
15 | id: label1
16 | text: qsTr("Input Text:")
17 | }
18 |
19 | TextInput {
20 | id: input
21 | text: qsTr("1")
22 | validator: DoubleValidator {
23 | bottom: parseInt(bottom.text)
24 | top: parseInt(top.text)
25 | decimals: parseInt(decimals.text)
26 | }
27 | onTextChanged: acceptableInput ? print("Input acceptable") : print("Input not acceptable")
28 | }
29 |
30 | Text {
31 | id: label2
32 | text: qsTr("Bottom:")
33 | }
34 |
35 | TextInput {
36 | id: bottom
37 | inputMask: "00000000"
38 | text: qsTr("1")
39 | }
40 |
41 | Text {
42 | id: label3
43 | text: qsTr("Top:")
44 | }
45 |
46 | TextInput {
47 | id: top
48 | inputMask: "00000000"
49 | text: qsTr("100")
50 | }
51 |
52 | Text {
53 | id: label4
54 | text: qsTr("Decimals:")
55 | }
56 |
57 | TextInput {
58 | id: decimals
59 | inputMask: "00"
60 | text: qsTr("2")
61 | }
62 |
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/spreadsheet.h:
--------------------------------------------------------------------------------
1 | #ifndef SPREADSHEET_H
2 | #define SPREADSHEET_H
3 |
4 | #include
5 |
6 | class Cell;
7 | class SpreadsheetCompare;
8 |
9 | class Spreadsheet : public QTableWidget
10 | {
11 | Q_OBJECT
12 |
13 | public:
14 | Spreadsheet(QWidget *parent = 0);
15 |
16 | bool autoRecalculate() const { return autoRecalc; }
17 | QString currentLocation() const;
18 | QString currentFormula() const;
19 | QTableWidgetSelectionRange selectedRange() const;
20 | void clear();
21 | bool readFile(const QString &fileName);
22 | bool writeFile(const QString &fileName);
23 | void sort(const SpreadsheetCompare &compare);
24 |
25 | public slots:
26 | void cut();
27 | void copy();
28 | void paste();
29 | void del();
30 | void selectCurrentRow();
31 | void selectCurrentColumn();
32 | void recalculate();
33 | void setAutoRecalculate(bool recalc);
34 | void findNext(const QString &str, Qt::CaseSensitivity cs);
35 | void findPrevious(const QString &str, Qt::CaseSensitivity cs);
36 |
37 | signals:
38 | void modified();
39 |
40 | private slots:
41 | void somethingChanged();
42 |
43 | private:
44 | enum { MagicNumber = 0x7F51C883, RowCount = 999, ColumnCount = 26 };
45 |
46 | Cell *cell(int row, int column) const;
47 | QString text(int row, int column) const;
48 | QString formula(int row, int column) const;
49 | void setFormula(int row, int column, const QString &formula);
50 |
51 | bool autoRecalc;
52 | };
53 |
54 | class SpreadsheetCompare
55 | {
56 | public:
57 | bool operator()(const QStringList &row1,
58 | const QStringList &row2) const;
59 |
60 | enum { KeyCount = 3 };
61 | int keys[KeyCount];
62 | bool ascending[KeyCount];
63 | };
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/CppBinding/example1/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.14)
2 |
3 | project(cppBindingExample LANGUAGES CXX)
4 |
5 | set(CMAKE_INCLUDE_CURRENT_DIR ON)
6 |
7 | set(CMAKE_AUTOUIC ON)
8 | set(CMAKE_AUTOMOC ON)
9 | set(CMAKE_AUTORCC ON)
10 |
11 | set(CMAKE_CXX_STANDARD 17)
12 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
13 |
14 | # QtCreator supports the following variables for Android, which are identical to qmake Android variables.
15 | # Check https://doc.qt.io/qt/deployment-android.html for more information.
16 | # They need to be set before the find_package(...) calls below.
17 |
18 | #if(ANDROID)
19 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
20 | # if (ANDROID_ABI STREQUAL "armeabi-v7a")
21 | # set(ANDROID_EXTRA_LIBS
22 | # ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
23 | # ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
24 | # endif()
25 | #endif()
26 |
27 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick REQUIRED)
28 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED)
29 |
30 | set(PROJECT_SOURCES
31 | main.cpp
32 | rectanglemanager.cpp
33 | qml.qrc
34 | )
35 |
36 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
37 | qt_add_executable(cppBindingExample
38 | ${PROJECT_SOURCES}
39 | )
40 | else()
41 | if(ANDROID)
42 | add_library(cppBindingExample SHARED
43 | ${PROJECT_SOURCES}
44 | )
45 | else()
46 | add_executable(cppBindingExample
47 | ${PROJECT_SOURCES}
48 | )
49 | endif()
50 | endif()
51 |
52 | target_compile_definitions(cppBindingExample
53 | PRIVATE $<$,$>:QT_QML_DEBUG>)
54 | target_link_libraries(cppBindingExample
55 | PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick stdc++)
56 |
--------------------------------------------------------------------------------
/MasksValidators/qmldemo/Page3.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.6
2 | import QtQuick.Controls 2.2
3 | import QtQuick.Layouts 1.3
4 |
5 | Page {
6 | width: 400
7 | height: 400
8 |
9 | property int fontSize: Qt.application.font.pixelSize * 1.5
10 |
11 | header: Label {
12 | text: qsTr("RegExpValidator")
13 | font.bold: true
14 | font.pixelSize: Qt.application.font.pixelSize * 2
15 | horizontalAlignment: Text.AlignHCenter
16 | padding: 10
17 | }
18 |
19 | GridLayout {
20 | columns: 2
21 |
22 | Text {
23 | id: label1
24 | font.pixelSize: fontSize
25 | text: qsTr("Input Text:")
26 | }
27 |
28 | TextField {
29 | id: input
30 | text: qsTr("1")
31 | font.pixelSize: fontSize
32 | validator: RegExpValidator {
33 | id: validator
34 | regExp: /[a-zA-Z0-9]+/
35 | }
36 | onTextChanged: acceptableInput ? status.text = qsTr("Input acceptable") : status.text = qsTr("Input not acceptable")
37 | }
38 |
39 | Text {
40 | id: label2
41 | text: qsTr("Regular Expression:")
42 | font.pixelSize: fontSize
43 | }
44 |
45 | TextField {
46 | id: regexp
47 | text: "[a-zA-Z0-9]+"
48 | font.pixelSize: fontSize
49 | onTextChanged: validator.regExp = RegExp(text)
50 | }
51 |
52 | Text {
53 | id: label4
54 | text: qsTr("Status:")
55 | font.pixelSize: fontSize
56 | Layout.topMargin: 16
57 | }
58 |
59 | Text {
60 | id: status
61 | font.pixelSize: fontSize
62 | font.bold: true
63 | Layout.topMargin: 16
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/PythonPlugin/ledplugin.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | from PyQt5.QtGui import QIcon
4 | from PyQt5.QtDesigner import QPyDesignerCustomWidgetPlugin
5 |
6 | from ledwidget import LedWidget
7 |
8 |
9 | class LedPlugin(QPyDesignerCustomWidgetPlugin):
10 |
11 | def __init__(self, parent=None):
12 | super(LedPlugin, self).__init__(parent)
13 |
14 | self.initialized = False
15 |
16 | def initialize(self, core):
17 | if self.initialized:
18 | return
19 |
20 | self.initialized = True
21 |
22 | def isInitialized(self):
23 | return self.initialized
24 |
25 | def createWidget(self, parent):
26 | return LedWidget(parent)
27 |
28 | def name(self):
29 | return "LedWidget"
30 |
31 | def group(self):
32 | return "ICS Custom Widgets"
33 |
34 | def icon(self):
35 | return QIcon()
36 |
37 | def toolTip(self):
38 | return ""
39 |
40 | def whatsThis(self):
41 | return ""
42 |
43 | def isContainer(self):
44 | return False
45 |
46 | # Returns an XML description of a custom widget instance that describes
47 | # default values for its properties. Each custom widget created by this
48 | # plugin will be configured using this description.
49 | # def domXml(self):
50 | # return '\n' \
51 | # ' \n' \
52 | # ' The current time\n' \
53 | # ' \n' \
54 | # ' \n' \
55 | # ' The analog clock widget displays the current ' \
56 | # 'time.\n' \
57 | # ' \n' \
58 | # '\n'
59 |
60 | def includeFile(self):
61 | return "ledwidget"
62 |
--------------------------------------------------------------------------------
/Timers/basictimer/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent) :
5 | QMainWindow(parent),
6 | ui(new Ui::MainWindow), count(0)
7 | {
8 | ui->setupUi(this);
9 |
10 | timer = new QBasicTimer();
11 | statusBar()->showMessage(tr("Created timer %1").arg(timer->timerId()), 1000);
12 |
13 | connect(ui->quitButton, &QPushButton::clicked, qApp, &QApplication::quit);
14 | connect(ui->clearButton, &QPushButton::clicked, this, &MainWindow::Clear);
15 | connect(ui->startButton, &QPushButton::clicked, this, &MainWindow::Start);
16 | }
17 |
18 | MainWindow::~MainWindow()
19 | {
20 | delete timer;
21 | delete ui;
22 | }
23 |
24 | void MainWindow::Clear()
25 | {
26 | count = 0;
27 | ui->lcdNumber->display(count / 10.0);
28 | }
29 |
30 | void MainWindow::Start()
31 | {
32 | if (timer->isActive()) {
33 | timer->stop();
34 | ui->startButton->setText(tr("Start"));
35 | ui->timerTypeComboBox->setEnabled(true);
36 | } else {
37 | Qt::TimerType type = Qt::PreciseTimer;
38 | if (ui->timerTypeComboBox->currentText() == QLatin1String("Precise")) {
39 | type = Qt::PreciseTimer;
40 | } else if (ui->timerTypeComboBox->currentText() == QLatin1String("Coarse")) {
41 | type = Qt::CoarseTimer;
42 | } else if (ui->timerTypeComboBox->currentText() == QLatin1String("Very Coarse")) {
43 | type = Qt::VeryCoarseTimer;
44 | } else {
45 | Q_ASSERT(false);
46 | }
47 | timer->start(100, type, this);
48 | ui->startButton->setText(tr("Stop"));
49 | ui->timerTypeComboBox->setEnabled(false);
50 | }
51 | }
52 |
53 | void MainWindow::timerEvent(QTimerEvent *event)
54 | {
55 | count++;
56 | ui->lcdNumber->display(count / 10.0);
57 | event->accept();
58 | }
59 |
--------------------------------------------------------------------------------
/gpio/part5/demo4.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Example of programming GPIO from C or C++ using the WiringPi library
4 | on a Raspberry Pi.
5 |
6 | Will cycle through three LEDs in a binary pattern. If the pushbutton is
7 | pressed, it will turn off all LEDs and exit.
8 |
9 | Jeff Tranter
10 |
11 | */
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | int main(void)
18 | {
19 | // Red LED: Physical pin 18, BCM GPIO24, and WiringPi pin 5.
20 | const int led1 = 5;
21 |
22 | // Green LED: Physical pin 22, BCM GPIO25, and WiringPi pin 6.
23 | const int led2 = 6;
24 |
25 | // Yellow LED: Physical pin 29, BCM GPIO5, and WiringPi pin 21.
26 | const int led3 = 21;
27 |
28 | // Switch: Physical pin 31, BCM GPIO6, and WiringPi pin 22.
29 | const int button = 22;
30 |
31 | wiringPiSetup();
32 |
33 | pinMode(led1, OUTPUT);
34 | pinMode(led2, OUTPUT);
35 | pinMode(led3, OUTPUT);
36 | pinMode(button, INPUT);
37 |
38 | fprintf(stderr, "Running on Raspberry Pi revision %d\n", piBoardRev());
39 |
40 | while (1) {
41 | for (int i = 0; i < 8; i++) {
42 | if (i & 1) {
43 | digitalWrite(led1, HIGH);
44 | } else {
45 | digitalWrite(led1, LOW);
46 | }
47 | if (i & 2) {
48 | digitalWrite(led2, HIGH);
49 | } else {
50 | digitalWrite(led2, LOW);
51 | }
52 | if (i & 4) {
53 | digitalWrite(led3, HIGH);
54 | } else {
55 | digitalWrite(led3, LOW);
56 | }
57 |
58 | delay(100);
59 | }
60 |
61 | if (digitalRead(button) == LOW) {
62 | digitalWrite(led1, LOW);
63 | digitalWrite(led2, LOW);
64 | digitalWrite(led3, LOW);
65 | exit(1);
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/MultiLanguageApp/TranslatorManager.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "TranslatorManager.h"
4 |
5 | TranslatorManager* TranslatorManager::m_Instance = 0;
6 |
7 | TranslatorManager::TranslatorManager()
8 | {
9 | QString defaultLang = "en_US";
10 | QStringList resources;
11 | resources << "i18n/lang_en_US" << "i18n/lang_fr_FR" << "i18n/lang_ru_RU";
12 |
13 | QStringList languages;
14 | languages << "en_US" << "fr_FR" << "ru_RU";
15 |
16 | for (int j = 0; j < resources.size(); j++)
17 | {
18 | QTranslator* pTranslator = new QTranslator;
19 | if (pTranslator->load(resources[j], ":/"))
20 | {
21 | if (languages[j] == defaultLang)
22 | {
23 | qApp->installTranslator(pTranslator);
24 | m_keyLang = languages[j];
25 | }
26 |
27 | m_translators.insert(languages[j], pTranslator);
28 | }
29 | }
30 | }
31 |
32 | TranslatorManager::~TranslatorManager()
33 | {
34 | TranslatorMap::const_iterator i = m_translators.begin();
35 | while (i != m_translators.end())
36 | {
37 | QTranslator* pTranslator = i.value();
38 | delete pTranslator;
39 | ++i;
40 | }
41 |
42 | m_translators.clear();
43 | }
44 |
45 | TranslatorManager* TranslatorManager::instance()
46 | {
47 | static QMutex mutex;
48 | if (!m_Instance)
49 | {
50 | mutex.lock();
51 |
52 | if (!m_Instance)
53 | m_Instance = new TranslatorManager;
54 |
55 | mutex.unlock();
56 | }
57 |
58 | return m_Instance;
59 | }
60 |
61 | bool TranslatorManager::setTranslator(QString& lang)
62 | {
63 | bool rc = false;
64 | if (lang != m_keyLang && m_translators.contains(lang))
65 | {
66 | QTranslator* pTranslator = m_translators[m_keyLang];
67 | QCoreApplication::removeTranslator(pTranslator);
68 | pTranslator = m_translators[lang];
69 | QCoreApplication::installTranslator(pTranslator);
70 | m_keyLang = lang;
71 | rc = true;
72 | }
73 |
74 | return rc;
75 | }
76 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/gotocelldialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | GoToCellDialog
6 |
7 |
8 | Go to Cell
9 |
10 |
11 | -
12 |
13 |
-
14 |
15 |
16 | &Cell Location:
17 |
18 |
19 | lineEdit
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 | -
29 |
30 |
-
31 |
32 |
33 | Qt::Horizontal
34 |
35 |
36 |
37 | 40
38 | 20
39 |
40 |
41 |
42 |
43 | -
44 |
45 |
46 | false
47 |
48 |
49 | OK
50 |
51 |
52 | true
53 |
54 |
55 |
56 | -
57 |
58 |
59 | Cancel
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | lineEdit
70 | okButton
71 | cancelButton
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/gotocelldialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | GoToCellDialog
6 |
7 |
8 | Go to Cell
9 |
10 |
11 | -
12 |
13 |
-
14 |
15 |
16 | &Cell Location:
17 |
18 |
19 | lineEdit
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 | -
29 |
30 |
-
31 |
32 |
33 | Qt::Horizontal
34 |
35 |
36 |
37 | 40
38 | 20
39 |
40 |
41 |
42 |
43 | -
44 |
45 |
46 | false
47 |
48 |
49 | OK
50 |
51 |
52 | true
53 |
54 |
55 |
56 | -
57 |
58 |
59 | Cancel
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | lineEdit
70 | okButton
71 | cancelButton
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/MasksValidators/qmldemo/Page1.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.6
2 | import QtQuick.Controls 2.1
3 | import QtQuick.Layouts 1.3
4 |
5 | Page {
6 | width: 400
7 | height: 400
8 |
9 | property int fontSize: Qt.application.font.pixelSize * 1.5
10 |
11 | header: Label {
12 | text: qsTr("IntValidator")
13 | font.bold: true
14 | font.pixelSize: Qt.application.font.pixelSize * 2
15 | horizontalAlignment: Text.AlignHCenter
16 | padding: 10
17 | }
18 |
19 | GridLayout {
20 | columns: 2
21 |
22 | Text {
23 | id: label1
24 | font.pixelSize: fontSize
25 | text: qsTr("Input Text:")
26 | }
27 |
28 | TextField {
29 | id: input
30 | text: qsTr("1")
31 | font.pixelSize: fontSize
32 | validator: IntValidator {
33 | bottom: parseInt(bottom.text)
34 | top: parseInt(top.text)
35 | }
36 | onTextChanged: acceptableInput ? status.text = qsTr("Input acceptable") : status.text = qsTr("Input not acceptable")
37 | }
38 |
39 | Text {
40 | id: label2
41 | text: qsTr("Bottom:")
42 | font.pixelSize: fontSize
43 | }
44 |
45 | TextField {
46 | id: bottom
47 | inputMask: "00000000"
48 | text: qsTr("1")
49 | font.pixelSize: fontSize
50 | }
51 |
52 | Text {
53 | id: label3
54 | text: qsTr("Top:")
55 | font.pixelSize: fontSize
56 | }
57 |
58 | TextField {
59 | id: top
60 | inputMask: "00000000"
61 | text: qsTr("100")
62 | font.pixelSize: fontSize
63 | }
64 |
65 | Text {
66 | id: label4
67 | text: qsTr("Status:")
68 | font.pixelSize: fontSize
69 | Layout.topMargin: 16
70 | }
71 |
72 | Text {
73 | id: status
74 | font.pixelSize: fontSize
75 | font.bold: true
76 | Layout.topMargin: 16
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/finddialog.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #if QT_VERSION >= 0x050000
3 | #include
4 | #endif
5 |
6 | #include "finddialog.h"
7 |
8 | FindDialog::FindDialog(QWidget *parent)
9 | : QDialog(parent)
10 | {
11 | label = new QLabel(tr("Find &what:"));
12 | lineEdit = new QLineEdit;
13 | label->setBuddy(lineEdit);
14 |
15 | caseCheckBox = new QCheckBox(tr("Match &case"));
16 | backwardCheckBox = new QCheckBox(tr("Search &backward"));
17 |
18 | findButton = new QPushButton(tr("&Find"));
19 | findButton->setDefault(true);
20 | findButton->setEnabled(false);
21 |
22 | closeButton = new QPushButton(tr("Close"));
23 |
24 | connect(lineEdit, &QLineEdit::textChanged, this, &FindDialog::enableFindButton);
25 | connect(findButton, &QPushButton::clicked, this, &FindDialog::findClicked);
26 | connect(closeButton, &QPushButton::clicked, this, &FindDialog::close);
27 |
28 | QHBoxLayout *topLeftLayout = new QHBoxLayout;
29 | topLeftLayout->addWidget(label);
30 | topLeftLayout->addWidget(lineEdit);
31 |
32 | QVBoxLayout *leftLayout = new QVBoxLayout;
33 | leftLayout->addLayout(topLeftLayout);
34 | leftLayout->addWidget(caseCheckBox);
35 | leftLayout->addWidget(backwardCheckBox);
36 |
37 | QVBoxLayout *rightLayout = new QVBoxLayout;
38 | rightLayout->addWidget(findButton);
39 | rightLayout->addWidget(closeButton);
40 | rightLayout->addStretch();
41 |
42 | QHBoxLayout *mainLayout = new QHBoxLayout;
43 | mainLayout->addLayout(leftLayout);
44 | mainLayout->addLayout(rightLayout);
45 | setLayout(mainLayout);
46 |
47 | setWindowTitle(tr("Find"));
48 | setFixedHeight(sizeHint().height());
49 | }
50 |
51 | void FindDialog::findClicked()
52 | {
53 | QString text = lineEdit->text();
54 | Qt::CaseSensitivity cs =
55 | caseCheckBox->isChecked() ? Qt::CaseSensitive
56 | : Qt::CaseInsensitive;
57 | if (backwardCheckBox->isChecked()) {
58 | emit findPrevious(text, cs);
59 | } else {
60 | emit findNext(text, cs);
61 | }
62 | }
63 |
64 | void FindDialog::enableFindButton(const QString &text)
65 | {
66 | findButton->setEnabled(!text.isEmpty());
67 | }
68 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | class QAction;
7 | class QLabel;
8 | class FindDialog;
9 | class Spreadsheet;
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | MainWindow();
17 |
18 | protected:
19 | void closeEvent(QCloseEvent *event);
20 |
21 | private slots:
22 | void newFile();
23 | void open();
24 | bool save();
25 | bool saveAs();
26 | void find();
27 | void goToCell();
28 | void sort();
29 | void about();
30 | void openRecentFile();
31 | void updateStatusBar();
32 | void spreadsheetModified();
33 |
34 | private:
35 | void createActions();
36 | void createMenus();
37 | void createContextMenu();
38 | void createToolBars();
39 | void createStatusBar();
40 | void readSettings();
41 | void writeSettings();
42 | bool okToContinue();
43 | bool loadFile(const QString &fileName);
44 | bool saveFile(const QString &fileName);
45 | void setCurrentFile(const QString &fileName);
46 | void updateRecentFileActions();
47 | QString strippedName(const QString &fullFileName);
48 |
49 | Spreadsheet *spreadsheet;
50 | FindDialog *findDialog;
51 | QLabel *locationLabel;
52 | QLabel *formulaLabel;
53 | QStringList recentFiles;
54 | QString curFile;
55 |
56 | enum { MaxRecentFiles = 5 };
57 | QAction *recentFileActions[MaxRecentFiles];
58 | QAction *separatorAction;
59 |
60 | QMenu *fileMenu;
61 | QMenu *editMenu;
62 | QMenu *selectSubMenu;
63 | QMenu *toolsMenu;
64 | QMenu *optionsMenu;
65 | QMenu *helpMenu;
66 | QToolBar *fileToolBar;
67 | QToolBar *editToolBar;
68 | QAction *newAction;
69 | QAction *openAction;
70 | QAction *saveAction;
71 | QAction *saveAsAction;
72 | QAction *exitAction;
73 | QAction *cutAction;
74 | QAction *copyAction;
75 | QAction *pasteAction;
76 | QAction *deleteAction;
77 | QAction *selectRowAction;
78 | QAction *selectColumnAction;
79 | QAction *selectAllAction;
80 | QAction *findAction;
81 | QAction *goToCellAction;
82 | QAction *recalculateAction;
83 | QAction *sortAction;
84 | QAction *showGridAction;
85 | QAction *autoRecalcAction;
86 | QAction *aboutAction;
87 | QAction *aboutQtAction;
88 | };
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/MoveToTrash/trashdemo/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include
4 | #include
5 | #include
6 |
7 | MainWindow::MainWindow(QWidget *parent)
8 | : QMainWindow(parent)
9 | , ui(new Ui::MainWindow)
10 | {
11 | ui->setupUi(this);
12 |
13 | ui->moveToTrashButton->setEnabled(false);
14 | ui->restoreButton->setEnabled(false);
15 |
16 | connect(ui->selectFileButton, &QAbstractButton::clicked, this, &MainWindow::selectFile);
17 | connect(ui->moveToTrashButton, &QAbstractButton::clicked, this, &MainWindow::moveToTrash);
18 | connect(ui->restoreButton, &QAbstractButton::clicked, this, &MainWindow::restore);
19 | }
20 |
21 | MainWindow::~MainWindow()
22 | {
23 | delete ui;
24 | }
25 |
26 | void MainWindow::selectFile()
27 | {
28 | QString filename = QFileDialog::getOpenFileName(this, tr("Select File"));
29 | m_filename = filename;
30 | ui->filename->setText(filename);
31 | ui->trashpath->clear();
32 | ui->moveToTrashButton->setEnabled(true);
33 | ui->restoreButton->setEnabled(false);
34 | }
35 |
36 | void MainWindow::moveToTrash()
37 | {
38 | QString pathInTrash;
39 |
40 | if (ui->filename->text().isEmpty()) {
41 | return;
42 | }
43 |
44 | if (QMessageBox::question(this,
45 | tr("Confirmation"),
46 | tr("Are you sure you want to move\n%1\nto the trash?").arg(ui->filename->text()))
47 | == QMessageBox::Yes) {
48 | if (QFile::moveToTrash(ui->filename->text(), &pathInTrash)) {
49 | ui->filename->clear();
50 | ui->trashpath->setText(pathInTrash);
51 | ui->moveToTrashButton->setEnabled(false);
52 | ui->restoreButton->setEnabled(true);
53 | } else {
54 | QMessageBox::warning(this, tr("Warning"), tr("Move to trash failed."));
55 | }
56 | }
57 | }
58 |
59 | void MainWindow::restore()
60 | {
61 | if (ui->trashpath->text().isEmpty() || m_filename.isEmpty()) {
62 | return;
63 | }
64 |
65 | if (QFile::rename(ui->trashpath->text(), m_filename)) {
66 | ui->filename->setText(m_filename);
67 | ui->trashpath->clear();
68 | ui->moveToTrashButton->setEnabled(true);
69 | ui->restoreButton->setEnabled(false);
70 | } else {
71 | QMessageBox::warning(this, tr("Warning"), tr("File restore failed."));
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/QRandomGenerator/randomdemo2/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "mainwindow.h"
8 | #include "ui_mainwindow.h"
9 |
10 | MainWindow::MainWindow(QWidget *parent) :
11 | QMainWindow(parent),
12 | ui(new Ui::MainWindow)
13 | {
14 | ui->setupUi(this);
15 |
16 | // Refresh every second.
17 | QTimer *timer = new QTimer(this);
18 | connect(timer, SIGNAL(timeout()), this, SLOT(update()));
19 | timer->start(1000);
20 | }
21 |
22 | MainWindow::~MainWindow()
23 | {
24 | delete ui;
25 | }
26 |
27 | void MainWindow::paintEvent(QPaintEvent *)
28 | {
29 | QPainter painter(this);
30 | QElapsedTimer timer;
31 | //QRandomGenerator gen = QRandomGenerator();
32 |
33 | timer.start();
34 |
35 | #if 1
36 | // Plot random colors
37 | for (int x = 0; x < this->width(); ++x) {
38 | for (int y = 0; y < this->height(); ++y) {
39 |
40 | // Code using rand()
41 | //QColor color = QColor(rand() % 256, rand() % 256, rand() % 256);
42 |
43 | // Code using qrand()
44 | //QColor color = QColor(qrand() % 256, qrand() % 256, qrand() % 256);
45 |
46 | // Code using default QRandomGenerator() with a seed, so data is the same every iteration.
47 | //QColor color = QColor(gen.bounded(256), gen.bounded(256), gen.bounded(256));
48 |
49 | // Code using system QRandomGenerator()
50 | //QColor color = QColor(QRandomGenerator::system()->bounded(256), QRandomGenerator::system()->bounded(256), QRandomGenerator::system()->bounded(256));
51 |
52 | // Code using global QRandomGenerator()
53 | QColor color = QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256));
54 |
55 | painter.setPen(color);
56 | painter.drawPoint(x, y);
57 | }
58 | }
59 | #endif
60 |
61 | #if 0
62 | // Alternate code - plot random pixels
63 | for (int i = 0; i < (this->width() * this->height()) / 2; i++) {
64 |
65 | int x = qrand() % this-> width();
66 | int y = qrand() % this-> height();
67 |
68 | painter.setPen(Qt::black);
69 | painter.drawPoint(x, y);
70 |
71 | }
72 | #endif
73 |
74 | qDebug() << "Paint event took" << timer.elapsed() << "milliseconds.";
75 | }
76 |
--------------------------------------------------------------------------------
/MasksValidators/qmldemo/Page2.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.6
2 | import QtQuick.Controls 2.1
3 | import QtQuick.Layouts 1.3
4 |
5 | Page {
6 | width: 400
7 | height: 400
8 |
9 | property int fontSize: Qt.application.font.pixelSize * 1.5
10 |
11 | header: Label {
12 | text: qsTr("DoubleValidator")
13 | font.bold: true
14 | font.pixelSize: Qt.application.font.pixelSize * 2
15 | horizontalAlignment: Text.AlignHCenter
16 | padding: 10
17 | }
18 |
19 | GridLayout {
20 | columns: 2
21 |
22 | Text {
23 | id: label1
24 | font.pixelSize: fontSize
25 | text: qsTr("Input Text:")
26 | }
27 |
28 | TextField {
29 | id: input
30 | text: qsTr("1")
31 | font.pixelSize: fontSize
32 | validator: DoubleValidator {
33 | bottom: parseInt(bottom.text)
34 | top: parseInt(top.text)
35 | decimals: parseInt(decimals.text)
36 | }
37 | onTextChanged: acceptableInput ? status.text = qsTr("Input acceptable") : status.text = qsTr("Input not acceptable")
38 | }
39 |
40 | Text {
41 | id: label2
42 | text: qsTr("Bottom:")
43 | font.pixelSize: fontSize
44 | }
45 |
46 | TextField {
47 | id: bottom
48 | inputMask: "00000000"
49 | text: qsTr("1")
50 | font.pixelSize: fontSize
51 | }
52 |
53 | Text {
54 | id: label3
55 | text: qsTr("Top:")
56 | font.pixelSize: fontSize
57 | }
58 |
59 | TextField {
60 | id: top
61 | inputMask: "00000000"
62 | text: qsTr("100")
63 | font.pixelSize: fontSize
64 | }
65 |
66 | Text {
67 | id: label5
68 | text: qsTr("Decimals:")
69 | font.pixelSize: fontSize
70 | }
71 |
72 | TextField {
73 | id: decimals
74 | inputMask: "00"
75 | text: qsTr("2")
76 | font.pixelSize: fontSize
77 | }
78 |
79 | Text {
80 | id: label4
81 | text: qsTr("Status:")
82 | font.pixelSize: fontSize
83 | Layout.topMargin: 16
84 | }
85 |
86 | Text {
87 | id: status
88 | font.pixelSize: fontSize
89 | font.bold: true
90 | Layout.topMargin: 16
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/gpio/part5/demo1.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Example of programming GPIO from C or C++ using the sysfs interface on
4 | a Raspberry Pi.
5 |
6 | Will toggle GPIO24 (physical pin 18) at a 100 millisecond rate for 10
7 | seconds and then exit.
8 |
9 | Jeff Tranter
10 |
11 | */
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | int main()
22 | {
23 | // Export the desired pin by writing to /sys/class/gpio/export
24 |
25 | int fd = open("/sys/class/gpio/export", O_WRONLY);
26 | if (fd == -1) {
27 | perror("Unable to open /sys/class/gpio/export");
28 | exit(1);
29 | }
30 |
31 | if (write(fd, "24", 2) != 2) {
32 | perror("Error writing to /sys/class/gpio/export");
33 | exit(1);
34 | }
35 |
36 | close(fd);
37 |
38 | // Set the pin to be an output by writing "out" to /sys/class/gpio/gpio24/direction
39 |
40 | fd = open("/sys/class/gpio/gpio24/direction", O_WRONLY);
41 | if (fd == -1) {
42 | perror("Unable to open /sys/class/gpio/gpio24/direction");
43 | exit(1);
44 | }
45 |
46 | if (write(fd, "out", 3) != 3) {
47 | perror("Error writing to /sys/class/gpio/gpio24/direction");
48 | exit(1);
49 | }
50 |
51 | close(fd);
52 |
53 | fd = open("/sys/class/gpio/gpio24/value", O_WRONLY);
54 | if (fd == -1) {
55 | perror("Unable to open /sys/class/gpio/gpio24/value");
56 | exit(1);
57 | }
58 |
59 | // Toggle LED 50 ms on, 50ms off, 100 times (10 seconds)
60 |
61 | for (int i = 0; i < 100; i++) {
62 | if (write(fd, "1", 1) != 1) {
63 | perror("Error writing to /sys/class/gpio/gpio24/value");
64 | exit(1);
65 | }
66 | usleep(50000);
67 |
68 | if (write(fd, "0", 1) != 1) {
69 | perror("Error writing to /sys/class/gpio/gpio24/value");
70 | exit(1);
71 | }
72 | usleep(50000);
73 | }
74 |
75 | close(fd);
76 |
77 | // Unexport the pin by writing to /sys/class/gpio/unexport
78 |
79 | fd = open("/sys/class/gpio/unexport", O_WRONLY);
80 | if (fd == -1) {
81 | perror("Unable to open /sys/class/gpio/unexport");
82 | exit(1);
83 | }
84 |
85 | if (write(fd, "24", 2) != 2) {
86 | perror("Error writing to /sys/class/gpio/unexport");
87 | exit(1);
88 | }
89 |
90 | close(fd);
91 |
92 | // And exit
93 | return 0;
94 | }
95 |
--------------------------------------------------------------------------------
/MultiLanguageApp/i18n/lang_en_US.ts:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Qt Multi-Language Support
10 |
11 |
12 |
13 |
14 | Text Label in English
15 |
16 |
17 |
18 |
19 | English
20 |
21 |
22 |
23 |
24 | French
25 |
26 |
27 |
28 |
29 | Russian
30 |
31 |
32 |
33 |
34 | Accept
35 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/MultiLanguageApp/i18n/lang_ru_RU.ts:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Многоязыковая поддержка
10 |
11 |
12 |
13 |
14 | Текст на Русском
15 |
16 |
17 |
18 |
19 | Английский
20 |
21 |
22 |
23 |
24 | Французский
25 |
26 |
27 |
28 |
29 | Русский
30 |
31 |
32 |
33 |
34 | принимать
35 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/MultiLanguageApp/i18n/lang_fr_FR.ts:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Prise en charge multi - langue
10 |
11 |
12 |
13 |
14 | Étiquette du texte en français
15 |
16 |
17 |
18 |
19 | Anglais
20 |
21 |
22 |
23 |
24 | Français
25 |
26 |
27 |
28 |
29 | Russe
30 |
31 |
32 |
33 |
34 | Accepter
35 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/calendardemo/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "mainwindow.h"
4 | #include "ui_mainwindow.h"
5 |
6 | MainWindow::MainWindow(QWidget *parent)
7 | : QMainWindow(parent)
8 | , ui(new Ui::MainWindow)
9 | {
10 | ui->setupUi(this);
11 |
12 | calendar = nullptr;
13 |
14 | ui->comboBox->insertItem(0, tr("Gregorian"), int(QCalendar::System::Gregorian));
15 | ui->comboBox->insertItem(1, tr("Julian"), int(QCalendar::System::Julian));
16 | ui->comboBox->insertItem(2, tr("Milankovic"), int(QCalendar::System::Milankovic));
17 | ui->comboBox->insertItem(3, tr("Jalali"), int(QCalendar::System::Jalali));
18 | ui->comboBox->insertItem(4, tr("Islamic Civil"), int(QCalendar::System::IslamicCivil));
19 |
20 | connect(ui->comboBox, qOverload(&QComboBox::activated), this, &MainWindow::setSystem);
21 | connect(ui->yearSpinBox, qOverload(&QSpinBox::valueChanged), this, &MainWindow::update);
22 | connect(ui->monthSpinBox, qOverload(&QSpinBox::valueChanged), this, &MainWindow::update);
23 | connect(ui->daySpinBox, qOverload(&QSpinBox::valueChanged), this, &MainWindow::update);
24 |
25 | ui->comboBox->setCurrentIndex(0);
26 | setSystem(0);
27 | ui->yearSpinBox->setValue(QDate::currentDate().year());
28 | ui->monthSpinBox->setValue(QDate::currentDate().month());
29 | ui->daySpinBox->setValue(QDate::currentDate().day());
30 | }
31 |
32 | MainWindow::~MainWindow()
33 | {
34 | delete ui;
35 | delete calendar;
36 | }
37 |
38 | void MainWindow::setSystem(int)
39 | {
40 | delete calendar;
41 | calendar = new QCalendar(QCalendar::System(ui->comboBox->currentData().toInt()));
42 | update();
43 | }
44 |
45 | void MainWindow::update()
46 | {
47 | int year = ui->yearSpinBox->value();
48 | int month = ui->monthSpinBox->value();
49 | int day = ui->daySpinBox->value();
50 | ui->label2->setText(calendar->name());
51 | ui->label4->setText(calendar->hasYearZero() ? tr("Yes") : tr("No"));
52 | ui->label6->setText(calendar->isGregorian() ? tr("Yes") : tr("No"));
53 | ui->label8->setText(calendar->isLunar() ? tr("Yes") : tr("No"));
54 | ui->label10->setText(calendar->isSolar() ? tr("Yes") : tr("No"));
55 | ui->label12->setText(calendar->isLuniSolar() ? tr("Yes") : tr("No"));
56 | ui->label14->setText(calendar->isProleptic() ? tr("Yes") : tr("No"));
57 | ui->label16->setText(QString::number(calendar->minimumDaysInMonth()));
58 | ui->label18->setText(QString::number(calendar->maximumDaysInMonth()));
59 | ui->label20->setText(QString::number(calendar->maximumMonthsInYear()));
60 | ui->label22->setText(calendar->isDateValid(year, month, day) ? tr("Yes") : tr("No"));
61 | ui->label24->setText(calendar->isLeapYear(year) ? tr("Yes") : tr("No"));
62 | ui->label26->setText(QString::number(calendar->monthsInYear(year)));
63 | QDate date = calendar->dateFromParts(year, month, day);
64 | ui->label28->setText(calendar->monthName(QLocale::system(), month, year)); // or standaloneMonthName()
65 | ui->label30->setText(date.toString());
66 | }
67 |
--------------------------------------------------------------------------------
/MultiLanguageApp/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 500
10 | 400
11 |
12 |
13 |
14 | Qt Multi-Language Support
15 |
16 |
17 |
46 |
47 |
48 | TopToolBarArea
49 |
50 |
51 | false
52 |
53 |
54 |
55 |
56 |
57 | Open
58 |
59 |
60 |
61 |
62 | Save
63 |
64 |
65 |
66 |
67 | Close
68 |
69 |
70 |
71 |
72 | Exit
73 |
74 |
75 |
76 |
77 | &Exit
78 |
79 |
80 |
81 |
82 | Select Language
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | action_Exit
91 | triggered()
92 | MainWindow
93 | close()
94 |
95 |
96 | -1
97 | -1
98 |
99 |
100 | 199
101 | 149
102 |
103 |
104 |
105 |
106 |
107 |
--------------------------------------------------------------------------------
/MoveToTrash/trashdemo/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 560
10 | 195
11 |
12 |
13 |
14 | Trash Demo
15 |
16 |
17 |
18 | -
19 |
20 |
-
21 |
22 |
23 | Filename:
24 |
25 |
26 |
27 | -
28 |
29 |
30 | true
31 |
32 |
33 |
34 | -
35 |
36 |
37 | Trash Path:
38 |
39 |
40 |
41 | -
42 |
43 |
44 | true
45 |
46 |
47 |
48 |
49 |
50 | -
51 |
52 |
53 | Qt::Vertical
54 |
55 |
56 |
57 | 20
58 | 40
59 |
60 |
61 |
62 |
63 | -
64 |
65 |
-
66 |
67 |
68 | &Select File...
69 |
70 |
71 |
72 | -
73 |
74 |
75 | &Move to Trash
76 |
77 |
78 |
79 | -
80 |
81 |
82 | &Restore
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/QRandomGenerator/randomdemo1/randomdemo1.cpp:
--------------------------------------------------------------------------------
1 | // QRandomGenerator class demo and examples.
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | int main()
9 | {
10 | quint32 value32;
11 | quint64 value64;
12 | int valueInt;
13 | double valueDouble;
14 | QRandomGenerator::result_type result;
15 |
16 | // Constructors
17 | QRandomGenerator gen1 = QRandomGenerator(); // Default, seeded with value of 1.
18 |
19 | QRandomGenerator gen2 = QRandomGenerator(0x1234); // Default, seeded with value of 0x1234.
20 |
21 | const quint32 array[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
22 | QRandomGenerator gen3 = QRandomGenerator(&array[0], &array[9]); // Generate a number of values.
23 |
24 | QRandomGenerator gen4 = QRandomGenerator(gen1); // Copying another generator.
25 |
26 | QRandomGenerator gen5 = QRandomGenerator::securelySeeded(); // Securely seeded generator.
27 |
28 | QRandomGenerator *gen6 = QRandomGenerator::system(); // System generator.
29 |
30 | QRandomGenerator *gen7 = QRandomGenerator::global(); // Global generator.
31 |
32 | // Bounded values
33 | valueDouble = gen1.bounded(100.0);
34 | qDebug() << "Random double from 0 to 100:" << valueDouble;
35 | value32 = gen1.bounded(100);
36 | qDebug() << "Random 32-bit from 0 to 100:" << value32;
37 | valueInt = gen1.bounded(100);
38 | qDebug() << "Random int from 0 to 100:" << valueInt;
39 | value32 = gen1.bounded(50, 100);
40 | qDebug() << "Random 32-bit from 50 to 100:" << value32;
41 | valueInt = gen1.bounded(50, 100);
42 | qDebug() << "Random int from 50 to 100:" << valueInt;
43 |
44 | // Generate methods
45 | value32 = gen5.generate();
46 | qDebug() << "Random 32-bit:" << value32;
47 | value64 = gen5.generate64();
48 | qDebug() << "Random 64-bit:" << value64;
49 | valueDouble = gen5.generateDouble();
50 | qDebug() << "Random double:" << valueDouble;
51 |
52 | // fillRange
53 | QVector vector;
54 | vector.resize(10);
55 | gen6->fillRange(vector.data(), vector.size());
56 | qDebug() << "Random vector of" << vector.size() << "32-bit elements:" << vector;
57 |
58 | // Operator()
59 | result = gen5();
60 | qDebug() << "operator() returned" << result;
61 |
62 | // Seeding
63 | gen2.seed(); // Default seed is 1
64 | gen2.seed(1234);
65 | std::seed_seq seq{1,2,3,4,5}; // C++11 standard seed sequence
66 | gen2.seed(seq);
67 |
68 | // Min/max
69 | result = gen3.min();
70 | qDebug() << "Min value:" << result;
71 | result = gen4.max();
72 | qDebug() << "Max value:" << result;
73 |
74 | // Discard next 10 values
75 | gen7->discard(10);
76 |
77 | // Comparison
78 | if (gen1 == gen2)
79 | qDebug() << "gen1 and gen2 are the same";
80 | if (gen1 != gen2)
81 | qDebug() << "gen1 and gen2 are different";
82 |
83 | // Assignment
84 | gen2 = gen1;
85 | if (gen1 == gen2)
86 | qDebug() << "gen1 and gen2 are the same";
87 |
88 | // QRandomGenerator64
89 | QRandomGenerator64 gen8 = QRandomGenerator64();
90 | result = gen8();
91 | qDebug() << "operator() returned" << result;
92 |
93 | return 0;
94 | }
95 |
--------------------------------------------------------------------------------
/MasksValidators/inputmaskdemo/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 440
10 | 164
11 |
12 |
13 |
14 | Input Mask Demo
15 |
16 |
17 |
18 | -
19 |
20 |
-
21 |
22 |
23 | Input Text:
24 |
25 |
26 |
27 | -
28 |
29 |
30 | input text
31 |
32 |
33 |
34 |
35 |
36 | -
37 |
38 |
-
39 |
40 |
41 | Input Mask:
42 |
43 |
44 |
45 | -
46 |
47 |
48 | input mask
49 |
50 |
51 |
52 |
53 |
54 | -
55 |
56 |
-
57 |
58 |
59 | Help
60 |
61 |
62 | F1
63 |
64 |
65 |
66 | -
67 |
68 |
69 | &Clear
70 |
71 |
72 |
73 | -
74 |
75 |
76 | &Quit
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
94 |
95 |
96 | TopToolBarArea
97 |
98 |
99 | false
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/gpio/part9/example.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Simple gpiod example of toggling three LEDs connected to GPIO lines.
4 | Exits when pushbutton connected to GPIO line is pressed. Written
5 | for Raspberry Pi platform with LEDs on GPIO pins 24, 25, and 5 and
6 | pushbutton on GPIO 6.
7 |
8 | */
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | int main(int argc, char **argv)
15 | {
16 | const char *chipname = "gpiochip0";
17 | struct gpiod_chip *chip;
18 | struct gpiod_line *lineRed; // Red LED
19 | struct gpiod_line *lineGreen; // Green LED
20 | struct gpiod_line *lineYellow; // Yellow LED
21 | struct gpiod_line *lineButton; // Pushbutton
22 | int i, ret, val;
23 |
24 | // Open GPIO chip
25 | chip = gpiod_chip_open_by_name(chipname);
26 | if (!chip) {
27 | perror("Open chip failed\n");
28 | return 1;
29 | }
30 |
31 | // Open GPIO lines
32 | lineRed = gpiod_chip_get_line(chip, 24);
33 | if (!lineRed) {
34 | perror("Get line failed\n");
35 | return 1;
36 | }
37 |
38 | lineGreen = gpiod_chip_get_line(chip, 25);
39 | if (!lineGreen) {
40 | perror("Get line failed\n");
41 | return 1;
42 | }
43 |
44 | lineYellow = gpiod_chip_get_line(chip, 5);
45 | if (!lineYellow) {
46 | perror("Get line failed\n");
47 | return 1;
48 | }
49 |
50 | lineButton = gpiod_chip_get_line(chip, 6);
51 | if (!lineButton) {
52 | perror("Get line failed\n");
53 | return 1;
54 | }
55 |
56 | // Open LED lines for output
57 | ret = gpiod_line_request_output(lineRed, "example1", 0);
58 | if (ret < 0) {
59 | perror("Request line as output failed\n");
60 | return 1;
61 | }
62 |
63 | ret = gpiod_line_request_output(lineGreen, "example1", 0);
64 | if (ret < 0) {
65 | perror("Request line as output failed\n");
66 | return 1;
67 | }
68 |
69 | ret = gpiod_line_request_output(lineYellow, "example1", 0);
70 | if (ret < 0) {
71 | perror("Request line as output failed\n");
72 | return 1;
73 | }
74 |
75 | // Open switch line for input
76 | ret = gpiod_line_request_input(lineButton, "example1");
77 | if (ret < 0) {
78 | perror("Request line as input failed\n");
79 | return 1;
80 | }
81 |
82 | // Blink LEDs in a binary pattern
83 | i = 0;
84 | while (true) {
85 | ret = gpiod_line_set_value(lineRed, (i & 1) != 0);
86 | if (ret < 0) {
87 | perror("Set line output failed\n");
88 | return 1;
89 | }
90 | ret = gpiod_line_set_value(lineGreen, (i & 2) != 0);
91 | if (ret < 0) {
92 | perror("Set line output failed\n");
93 | return 1;
94 | }
95 | ret = gpiod_line_set_value(lineYellow, (i & 4) != 0);
96 | if (ret < 0) {
97 | perror("Set line output failed\n");
98 | return 1;
99 | }
100 |
101 | val = gpiod_line_get_value(lineButton);
102 | if (val < 0) {
103 | perror("Read line input failed\n");
104 | return 1;
105 | }
106 |
107 | // Exit if button pressed
108 | if (val == 0) {
109 | break;
110 | }
111 |
112 | usleep(100000);
113 | i++;
114 | }
115 |
116 | // Release lines and chip
117 | gpiod_line_release(lineRed);
118 | gpiod_line_release(lineGreen);
119 | gpiod_line_release(lineYellow);
120 | gpiod_line_release(lineButton);
121 | gpiod_chip_close(chip);
122 | return 0;
123 | }
124 |
--------------------------------------------------------------------------------
/Timers/basictimer/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 272
10 | 270
11 |
12 |
13 |
14 | QBasicTimer Demo
15 |
16 |
17 |
18 | -
19 |
20 |
21 |
22 | 0
23 | 131
24 |
25 |
26 |
27 |
28 | 75
29 | true
30 |
31 |
32 |
33 | false
34 |
35 |
36 | QLCDNumber::Dec
37 |
38 |
39 |
40 | -
41 |
42 |
-
43 |
44 |
45 | Timer type:
46 |
47 |
48 |
49 | -
50 |
51 |
-
52 |
53 | Precise
54 |
55 |
56 | -
57 |
58 | Coarse
59 |
60 |
61 | -
62 |
63 | Very Coarse
64 |
65 |
66 |
67 |
68 |
69 |
70 | -
71 |
72 |
-
73 |
74 |
75 | Start
76 |
77 |
78 |
79 | -
80 |
81 |
82 | Clear
83 |
84 |
85 |
86 | -
87 |
88 |
89 | Quit
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
107 |
108 |
109 | TopToolBarArea
110 |
111 |
112 | false
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/calculator-qml/qml/Calculator.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.1
2 | import QtQuick.Layouts 1.0
3 |
4 | Rectangle {
5 | id: calculator
6 |
7 | property alias displayText: displayText.text
8 | signal keyClicked(int key)
9 | signal cutTriggered()
10 | signal copyTriggered()
11 | signal pasteTriggered()
12 |
13 | color: "ghostwhite"
14 |
15 | Keys.onPressed: {
16 | if (event.modifiers & Qt.ControlModifier) {
17 | if (event.key === Qt.Key_X) {
18 | cutTriggered();
19 | event.accepted = true;
20 | }
21 | else if (event.key === Qt.Key_C) {
22 | copyTriggered();
23 | event.accepted = true;
24 | }
25 | else if (event.key === Qt.Key_V) {
26 | pasteTriggered();
27 | event.accepted = true;
28 | }
29 | }
30 | }
31 |
32 | // main layout ///////////////////////////////////////////////////////////
33 |
34 | GridLayout {
35 | id: mainLayout
36 | columns: 4
37 | anchors.fill: parent
38 | anchors.leftMargin: columnSpacing
39 | anchors.rightMargin: columnSpacing
40 | anchors.topMargin: rowSpacing
41 | anchors.bottomMargin: rowSpacing
42 |
43 | Rectangle {
44 | id: display
45 | color: "aliceblue"
46 | border.color: "cadetblue"
47 | border.width: 2
48 | height: 56
49 | radius: 8
50 | Layout.columnSpan: 4
51 | Layout.fillWidth: true
52 |
53 | Text {
54 | id: displayText
55 | text: "0"
56 | font.pixelSize: parent.height - 4*2
57 | font.bold: true
58 | elide: Text.ElideLeft
59 | horizontalAlignment: Text.AlignRight
60 | verticalAlignment: Text.AlignVCenter
61 | anchors.fill: parent
62 | anchors.rightMargin: 4
63 | }
64 | }
65 |
66 | Repeater {
67 | Button {
68 | id: key
69 | text: modelData.text
70 |
71 | Layout.preferredWidth: 48
72 | Layout.preferredHeight: 40
73 | Layout.fillWidth: true
74 | Layout.fillHeight: true
75 |
76 | Layout.rowSpan: (modelData.rowSpan !== undefined)? modelData.rowSpan: 1
77 | Layout.columnSpan: (modelData.columnSpan !== undefined)? modelData.columnSpan: 1
78 |
79 | onClicked: calculator.keyClicked(modelData.key)
80 | }
81 |
82 | model: [
83 | { text: "C", key: Qt.Key_Delete },
84 | { text: "/", key: Qt.Key_Slash },
85 | { text: "*", key: Qt.Key_Asterisk },
86 | { text: "-", key: Qt.Key_Minus },
87 |
88 | { text: "7", key: Qt.Key_7 },
89 | { text: "8", key: Qt.Key_8 },
90 | { text: "9", key: Qt.Key_9 },
91 | { text: "+", key: Qt.Key_Plus, rowSpan: 2 },
92 |
93 | { text: "4", key: Qt.Key_4 },
94 | { text: "5", key: Qt.Key_5 },
95 | { text: "6", key: Qt.Key_6 },
96 |
97 | { text: "1", key: Qt.Key_1 },
98 | { text: "2", key: Qt.Key_2 },
99 | { text: "3", key: Qt.Key_3 },
100 | { text: "=", key: Qt.Key_Enter, rowSpan: 2 },
101 |
102 | { text: "0", key: Qt.Key_0, columnSpan: 2 },
103 | { text: ".", key: Qt.Key_Period }
104 | ]
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/Timers/elapsedtimer/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include "mainwindow.h"
6 | #include "ui_mainwindow.h"
7 |
8 | MainWindow::MainWindow(QWidget *parent) :
9 | QMainWindow(parent),
10 | ui(new Ui::MainWindow)
11 | {
12 | ui->setupUi(this);
13 |
14 | connect(ui->quitButton, &QPushButton::clicked, qApp, &QApplication::quit);
15 | connect(ui->infoButton, &QPushButton::clicked, this, &MainWindow::Info);
16 | connect(ui->startButton, &QPushButton::clicked, this, &MainWindow::Start);
17 | }
18 |
19 | MainWindow::~MainWindow()
20 | {
21 | delete ui;
22 | }
23 |
24 | void MainWindow::Info()
25 | {
26 | QString msg;
27 |
28 | msg += "Clock Type: ";
29 | switch (QElapsedTimer::clockType()) {
30 | case QElapsedTimer::SystemTime:
31 | msg += "System Time";
32 | break;
33 | case QElapsedTimer::MonotonicClock:
34 | msg += "Monotonic Clock";
35 | break;
36 | case QElapsedTimer::TickCounter:
37 | msg += "Tick Counter";
38 | break;
39 | case QElapsedTimer::MachAbsoluteTime:
40 | msg += "Mach Absolute Time";
41 | break;
42 | case QElapsedTimer::PerformanceCounter:
43 | msg += "Performance Counter";
44 | break;
45 | }
46 |
47 | msg += "\n";
48 |
49 | if (QElapsedTimer::isMonotonic()) {
50 | msg += "Is Monotonic: Yes";
51 | } else {
52 | msg += "Is Monotonic: No";
53 | }
54 |
55 | QMessageBox::information(this, tr("Timer Info"), msg);
56 | }
57 |
58 | void MainWindow::Start()
59 | {
60 | long repetitions = ui->repetitionSpinBox->value();
61 | double result = 0.0;
62 |
63 | QElapsedTimer timer;
64 | timer.start();
65 |
66 | if (ui->operationComboBox->currentText() == "Multiply") {
67 | for (long i = 0; i < repetitions; i++) {
68 | result = double(rand()) * double(rand());
69 | // Example of how to check for timer expiring. Give up if 1 second has elapsed.
70 | if (timer.hasExpired(1000)) {
71 | break;
72 | }
73 | }
74 | } else if (ui->operationComboBox->currentText() == "Divide") {
75 | for (long i = 0; i < repetitions; i++) {
76 | result = double(rand()) / double(rand());
77 | }
78 | } else if (ui->operationComboBox->currentText() == "Sine") {
79 | for (long i = 0; i < repetitions; i++) {
80 | result = sin(double((rand())));
81 | }
82 | } else if (ui->operationComboBox->currentText() == "Cosine") {
83 | for (long i = 0; i < repetitions; i++) {
84 | result = cos(double((rand())));
85 | }
86 | } else if (ui->operationComboBox->currentText() == "Nothing") {
87 | for (long i = 0; i < repetitions; i++) {
88 | ;
89 | }
90 | } else {
91 | Q_ASSERT(false);
92 | }
93 |
94 | qint64 elapsedNsec = timer.nsecsElapsed();
95 | qint64 elapsedMsec = timer.elapsed();
96 | QString msg;
97 | msg += tr("The operation took %1 nanoseconds\n").arg(elapsedNsec);
98 | msg += tr("or %1 milliseconds.\n").arg(elapsedMsec);
99 | msg += tr("Time since reference: %1 milliseconds.\n").arg(timer.msecsSinceReference());
100 | msg += "Has 100 msec expired? ";
101 | timer.hasExpired(100) ? msg += "yes" : msg += "no";
102 | msg += ".\n";
103 | msg += "Timer valid? ";
104 | timer.isValid() ? msg += "yes" : msg += "no";
105 | msg += ".\n";
106 | msg += tr("Result was %1.").arg(result);
107 |
108 | QMessageBox::information(this, tr("Elapsed Time"), msg);
109 | timer.invalidate();
110 | }
111 |
--------------------------------------------------------------------------------
/MasksValidators/inputmaskdemo/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "mainwindow.h"
3 | #include "ui_mainwindow.h"
4 |
5 | MainWindow::MainWindow(QWidget *parent) :
6 | QMainWindow(parent),
7 | ui(new Ui::MainWindow)
8 | {
9 | ui->setupUi(this);
10 |
11 | // Connect buttons to slots.
12 | connect(ui->quitButton, &QPushButton::clicked, qApp, &QApplication::quit);
13 | connect(ui->clearButton, &QPushButton::clicked, this, &MainWindow::clear);
14 | connect(ui->helpButton, &QPushButton::clicked, this, &MainWindow::help);
15 |
16 | // Update input mask when it changes. Only need to do one thing, so we use a lambda function.
17 | connect(ui->maskLineEdit, &QLineEdit::textChanged, [=](const QString &newMask) { ui->inputLineEdit->setInputMask(newMask); });
18 |
19 | // Update status bar when line edit changes.
20 | connect(ui->inputLineEdit, &QLineEdit::textChanged, this, &MainWindow::updateStatusBar);
21 |
22 | // Update status bar when return pressed.
23 | connect(ui->inputLineEdit, &QLineEdit::returnPressed, [=]() { this->statusBar()->showMessage(tr("Return pressed")); });
24 |
25 | // Update status bar when editing finished.
26 | connect(ui->inputLineEdit, &QLineEdit::editingFinished, [=]() { this->statusBar()->showMessage(tr("Editing finished")); });
27 | }
28 |
29 | MainWindow::~MainWindow()
30 | {
31 | delete ui;
32 | }
33 |
34 | void MainWindow::clear()
35 | {
36 | ui->inputLineEdit->clear();
37 | ui->maskLineEdit->clear();
38 | }
39 |
40 | void MainWindow::updateStatusBar()
41 | {
42 | if (ui->inputLineEdit->hasAcceptableInput()) {
43 | this->statusBar()->showMessage(tr("Input acceptable"));
44 | } else {
45 | this->statusBar()->showMessage(tr("Input not acceptable"));
46 | }
47 | }
48 |
49 | void MainWindow::help()
50 | {
51 | QString helpString =
52 | tr("Help on Mask String
"
53 | "
"
54 | "The mask consists of a string of mask characters and separators, "
55 | "optionally followed by a semicolon and the character used for blanks. "
56 | "The blank characters are always removed from the text after editing. "
57 | "A space character, the default character for a blank, is needed for "
58 | "cases where a character is permitted but not required. "
59 | "The following characters that can be used in an input mask:
"
60 | "
"
61 | "A - ASCII alphabetic character required. A-Z, a-z.
"
62 | "a - ASCII alphabetic character permitted but not required.
"
63 | "N - ASCII alphanumeric character required. A-Z, a-z, 0-9.
"
64 | "n - ASCII alphanumeric character permitted but not required.
"
65 | "X - Any character required.
"
66 | "x - Any character permitted but not required.
"
67 | "9 - ASCII digit required. 0-9.
"
68 | "0 - ASCII digit permitted but not required.
"
69 | "D - ASCII digit required. 1-9.
"
70 | "d - ASCII digit permitted but not required (1-9).
"
71 | "# - ASCII digit or plus/minus sign permitted but not required.
"
72 | "H - Hexadecimal character required. A-F, a-f, 0-9.
"
73 | "h - Hexadecimal character permitted but not required.
"
74 | "B - Binary character required. 0-1.
"
75 | "b - Binary character permitted but not required.
"
76 | "> - All following alphabetic characters are uppercased.
"
77 | "< - All following alphabetic characters are lowercased.
"
78 | "! - Switch off case conversion.
"
79 | "[ ] { } - Reserved.
"
80 | "
"
81 | "Use \\ to escape the special characters listed above to use them as separators.");
82 |
83 | QMessageBox::information(this, tr("Help"), helpString);
84 | }
85 |
--------------------------------------------------------------------------------
/Timers/elapsedtimer/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 272
10 | 163
11 |
12 |
13 |
14 | QElapsedTimer Demo
15 |
16 |
17 |
18 | -
19 |
20 |
-
21 |
22 |
23 | Operation:
24 |
25 |
26 |
27 | -
28 |
29 |
-
30 |
31 | Multiply
32 |
33 |
34 | -
35 |
36 | Divide
37 |
38 |
39 | -
40 |
41 | Sine
42 |
43 |
44 | -
45 |
46 | Cosine
47 |
48 |
49 | -
50 |
51 | Nothing
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 | Repetition count:
60 |
61 |
62 |
63 | -
64 |
65 |
66 | 1
67 |
68 |
69 | 99999999
70 |
71 |
72 | 1000000
73 |
74 |
75 |
76 |
77 |
78 | -
79 |
80 |
-
81 |
82 |
83 | Start
84 |
85 |
86 |
87 | -
88 |
89 |
90 | Info
91 |
92 |
93 |
94 | -
95 |
96 |
97 | Quit
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
115 |
116 |
117 | TopToolBarArea
118 |
119 |
120 | false
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/QCompleter/completerdemo/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "mainwindow.h"
5 | #include "ui_mainwindow.h"
6 |
7 | MainWindow::MainWindow(QWidget *parent) :
8 | QMainWindow(parent),
9 | ui(new Ui::MainWindow)
10 | {
11 | ui->setupUi(this);
12 |
13 | QFile file(QStringLiteral(":/words"));
14 | if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
15 | qDebug() << "Unable to open dictionary file";
16 | return;
17 | }
18 |
19 | QTextStream in(&file);
20 | QString s = in.readAll();
21 | QStringList list = s.split('\n');
22 | statusBar()->showMessage(tr("Loaded %1 words from dictionary file.").arg(list.count()), 3000);
23 |
24 | completer = new QCompleter(list, this);
25 | connect(completer, qOverload(&QCompleter::activated), this, &MainWindow::Activated);
26 | connect(completer, qOverload(&QCompleter::highlighted), this, &MainWindow::Highlighted);
27 |
28 | ui->lineEdit->setCompleter(completer);
29 |
30 | ui->comboBox->setEditable(true);
31 | ui->comboBox->addItems(list);
32 | ui->comboBox->setCompleter(completer);
33 |
34 | connect(ui->completionModeComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::UpdateSettings);
35 | connect(ui->modelSortingComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::UpdateSettings);
36 | connect(ui->filterModeComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::UpdateSettings);
37 | connect(ui->maxVisibleItemsSpinBox, qOverload(&QSpinBox::valueChanged), this, &MainWindow::UpdateSettings);
38 | connect(ui->caseSensitiveCheckBox, &QCheckBox::stateChanged, this, &MainWindow::UpdateSettings);
39 |
40 | UpdateSettings();
41 | }
42 |
43 | MainWindow::~MainWindow()
44 | {
45 | delete completer;
46 | delete ui;
47 | }
48 |
49 | void MainWindow::UpdateSettings()
50 | {
51 | if (ui->completionModeComboBox->currentText() == QLatin1String("Popup")) {
52 | completer->setCompletionMode(QCompleter::PopupCompletion);
53 | } else if (ui->completionModeComboBox->currentText() == QLatin1String("Inline")) {
54 | completer->setCompletionMode(QCompleter::InlineCompletion);
55 | } else if (ui->completionModeComboBox->currentText() == QLatin1String("Unfiltered Popup")) {
56 | completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
57 | } else {
58 | Q_ASSERT(false);
59 | }
60 |
61 | if (ui->modelSortingComboBox->currentText() == QLatin1String("Unsorted")) {
62 | completer->setModelSorting(QCompleter::UnsortedModel);
63 | } else if (ui->modelSortingComboBox->currentText() == QLatin1String("Case Sensitively Sorted")) {
64 | completer->setModelSorting(QCompleter::CaseSensitivelySortedModel);
65 | } else if (ui->modelSortingComboBox->currentText() == QLatin1String("Case Insensitively Sorted")) {
66 | completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
67 | } else {
68 | Q_ASSERT(false);
69 | }
70 |
71 | if (ui->filterModeComboBox->currentText() == QLatin1String("Starts With")) {
72 | completer->setFilterMode(Qt::MatchStartsWith);
73 | } else if (ui->filterModeComboBox->currentText() == QLatin1String("Contains")) {
74 | completer->setFilterMode(Qt::MatchContains);
75 | } else if (ui->filterModeComboBox->currentText() == QLatin1String("Ends With")) {
76 | completer->setFilterMode(Qt::MatchEndsWith);
77 | } else {
78 | Q_ASSERT(false);
79 | }
80 |
81 | completer->setMaxVisibleItems(ui->maxVisibleItemsSpinBox->value());
82 |
83 | if (ui->caseSensitiveCheckBox->isChecked()) {
84 | completer->setCaseSensitivity(Qt::CaseSensitive);
85 | } else {
86 | completer->setCaseSensitivity(Qt::CaseInsensitive);
87 | }
88 | }
89 |
90 | void MainWindow::Highlighted(const QString &text)
91 | {
92 | statusBar()->showMessage(tr("Highlighted '%1'.").arg(text), 3000);
93 | }
94 |
95 | void MainWindow::Activated(const QString &text)
96 | {
97 | statusBar()->showMessage(tr("Activated '%1'.").arg(text), 3000);
98 | }
99 |
--------------------------------------------------------------------------------
/gpio/part8/demo1.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Example of using libsoc for GPIO programming.
4 |
5 | Toggles three LEDs in a "Cylon" pattern until the pushbutton is
6 | pressed, and then exits. Will run on Raspberry Pi or Toradex Colibri
7 | platforms.
8 |
9 | */
10 |
11 | #include
12 | #include
13 | #include "libsoc_gpio.h"
14 | #include "libsoc_debug.h"
15 |
16 | // Uncomment the appropriate lines below for the hardware it is
17 | // running on.
18 |
19 | // Raspberry Pi
20 | //const int led1 = 24; // Red LED
21 | //const int led2 = 25; // Green LED
22 | //const int led3 = 5; // Yellow LED
23 | //const int button = 6; // Pushbutton
24 |
25 | // Toradex Colibri
26 | const int led1 = 52; // Red LED
27 | const int led2 = 53; // Green LED
28 | const int led3 = 63; // Yellow LED
29 | const int button = 93; // Pushbutton
30 |
31 | // Delay (in microseconds)
32 | const int delay = 100000;
33 |
34 | int main(void)
35 | {
36 | // Uncomment the next line to enable debug output if desired.
37 | //libsoc_set_debug(1);
38 |
39 | // Request gpios. May need to use LS_SHARED with older versions
40 | // of libsoc.
41 | gpio *gpio_led1 = libsoc_gpio_request(led1, LS_GPIO_SHARED);
42 | gpio *gpio_led2 = libsoc_gpio_request(led2, LS_GPIO_SHARED);
43 | gpio *gpio_led3 = libsoc_gpio_request(led3, LS_GPIO_SHARED);
44 | gpio *gpio_button = libsoc_gpio_request(button, LS_GPIO_SHARED);
45 |
46 | // Ensure gpios were successfully requested.
47 | if (gpio_led1 == NULL) {
48 | printf("Failed gpio_led1 request.\n");
49 | exit(EXIT_FAILURE);
50 | }
51 | if (gpio_led2 == NULL) {
52 | printf("Failed gpio_led2 request.\n");
53 | exit(EXIT_FAILURE);
54 | }
55 | if (gpio_led3 == NULL) {
56 | printf("Failed gpio_led3 request.\n");
57 | exit(EXIT_FAILURE);
58 | }
59 | if (gpio_button == NULL) {
60 | printf("Failed gpio_button request.\n");
61 | exit(EXIT_FAILURE);
62 | }
63 |
64 | // Set directions.
65 | libsoc_gpio_set_direction(gpio_led1, OUTPUT);
66 | libsoc_gpio_set_direction(gpio_led2, OUTPUT);
67 | libsoc_gpio_set_direction(gpio_led3, OUTPUT);
68 | libsoc_gpio_set_direction(gpio_button, INPUT);
69 |
70 | // Check directions.
71 | if (libsoc_gpio_get_direction(gpio_led1) != OUTPUT) {
72 | printf("Failed to set direction of gpio_led1\n");
73 | exit(EXIT_FAILURE);
74 | }
75 | if (libsoc_gpio_get_direction(gpio_led2) != OUTPUT) {
76 | printf("Failed to set direction of gpio_led2\n");
77 | exit(EXIT_FAILURE);
78 | }
79 | if (libsoc_gpio_get_direction(gpio_led3) != OUTPUT) {
80 | printf("Failed to set direction of gpio_led3\n");
81 | exit(EXIT_FAILURE);
82 | }
83 | if (libsoc_gpio_get_direction(gpio_button) != INPUT) {
84 | printf("Failed to set direction of gpio_button\n");
85 | exit(EXIT_FAILURE);
86 | }
87 |
88 | while (1) {
89 |
90 | // Turn LEDs on and off in desired sequence.
91 | libsoc_gpio_set_level(gpio_led1, HIGH);
92 | libsoc_gpio_set_level(gpio_led2, LOW);
93 | libsoc_gpio_set_level(gpio_led3, LOW);
94 | usleep(delay);
95 |
96 | libsoc_gpio_set_level(gpio_led1, LOW);
97 | libsoc_gpio_set_level(gpio_led2, HIGH);
98 | libsoc_gpio_set_level(gpio_led3, LOW);
99 | usleep(delay);
100 |
101 | libsoc_gpio_set_level(gpio_led1, LOW);
102 | libsoc_gpio_set_level(gpio_led2, LOW);
103 | libsoc_gpio_set_level(gpio_led3, HIGH);
104 | usleep(delay);
105 |
106 | libsoc_gpio_set_level(gpio_led1, LOW);
107 | libsoc_gpio_set_level(gpio_led2, HIGH);
108 | libsoc_gpio_set_level(gpio_led3, LOW);
109 | usleep(delay);
110 |
111 | // Check for switch being pressed.
112 | int status = libsoc_gpio_get_level(gpio_button);
113 | printf("Button status is %d\n", status);
114 | if (status == LOW) {
115 | break;
116 | }
117 | }
118 |
119 | // Turn all LEDs off.
120 | libsoc_gpio_set_level(gpio_led1, LOW);
121 | libsoc_gpio_set_level(gpio_led2, LOW);
122 | libsoc_gpio_set_level(gpio_led3, LOW);
123 |
124 | // Clean up.
125 | libsoc_gpio_free(gpio_led1);
126 | libsoc_gpio_free(gpio_led2);
127 | libsoc_gpio_free(gpio_led3);
128 | libsoc_gpio_free(gpio_button);
129 |
130 | return EXIT_SUCCESS;
131 | }
132 |
--------------------------------------------------------------------------------
/MasksValidators/validatordemo/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "mainwindow.h"
4 | #include "ui_mainwindow.h"
5 |
6 | MainWindow::MainWindow(QWidget *parent) :
7 | QMainWindow(parent),
8 | ui(new Ui::MainWindow)
9 | {
10 | ui->setupUi(this);
11 |
12 | // Create validators.
13 | intValidator = new QIntValidator(this);
14 | doubleValidator = new QDoubleValidator(this);
15 | regularExpressionValidator = new QRegularExpressionValidator(this);
16 |
17 | // Initialize.
18 | setValidator();
19 |
20 | // Connect the buttons.
21 | connect(ui->quitButton, &QPushButton::clicked, qApp, &QApplication::quit);
22 | connect(ui->clearButton, &QPushButton::clicked, [=]() { ui->inputLineEdit->clear(); });
23 |
24 | // Handle validator type combo box changing.
25 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
26 | connect(ui->validatorTypeComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::setValidator);
27 | #else
28 | connect(ui->validatorTypeComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::setValidator);
29 | #endif
30 |
31 | // If any settings change, update the validator.
32 | connect(ui->intTopSpinBox, qOverload(&QSpinBox::valueChanged), this, &MainWindow::setValidator);
33 | connect(ui->intBottomSpinBox, qOverload(&QSpinBox::valueChanged), this, &MainWindow::setValidator);
34 | connect(ui->doubleTopSpinBox, qOverload(&QDoubleSpinBox::valueChanged), this, &MainWindow::setValidator);
35 | connect(ui->doubleBottomSpinBox, qOverload(&QDoubleSpinBox::valueChanged), this, &MainWindow::setValidator);
36 | connect(ui->decimalsSpinBox, qOverload(&QSpinBox::valueChanged), this, &MainWindow::setValidator);
37 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
38 | connect(ui->notationComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::setValidator);
39 | #else
40 | connect(ui->notationComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::setValidator);
41 | #endif
42 | connect(ui->regularExpressionLineEdit, &QLineEdit::textChanged, this, &MainWindow::setValidator);
43 |
44 | // Update status bar when line edit changes.
45 | connect(ui->inputLineEdit, &QLineEdit::textChanged, this, &MainWindow::updateStatusBar);
46 |
47 | // Check for validity when regular expression changes.
48 | connect(ui->regularExpressionLineEdit, &QLineEdit::textChanged, this, &MainWindow::checkRegularExpression);
49 | }
50 |
51 | MainWindow::~MainWindow()
52 | {
53 | delete ui;
54 | }
55 |
56 | void MainWindow::setValidator()
57 | {
58 | // Set stacked widget to appropriate index from combo box.
59 | ui->stackedWidget->setCurrentIndex(ui->validatorTypeComboBox->currentIndex());
60 |
61 | // Set the validator to the correct type.
62 | switch (ui->validatorTypeComboBox->currentIndex()) {
63 |
64 | case 0: // Integer
65 | intValidator->setRange(ui->intBottomSpinBox->value(), ui->intTopSpinBox->value());
66 | ui->inputLineEdit->setValidator(intValidator);
67 | break;
68 |
69 | case 1: // Double
70 | doubleValidator->setRange(ui->doubleBottomSpinBox->value(), ui->doubleTopSpinBox->value());
71 | doubleValidator->setDecimals(ui->decimalsSpinBox->value());
72 | doubleValidator->setNotation(static_cast(ui->notationComboBox->currentIndex()));
73 | ui->inputLineEdit->setValidator(doubleValidator);
74 | break;
75 |
76 | case 2: // Regular expression
77 | regularExpressionValidator->setRegularExpression(QRegularExpression(ui->regularExpressionLineEdit->text()));
78 | ui->inputLineEdit->setValidator(regularExpressionValidator);
79 | break;
80 | }
81 | }
82 |
83 | void MainWindow::updateStatusBar()
84 | {
85 | if (ui->inputLineEdit->hasAcceptableInput()) {
86 | this->statusBar()->showMessage(tr("Input is acceptable"));
87 | } else {
88 | this->statusBar()->showMessage(tr("Input is not acceptable"));
89 | }
90 |
91 | }
92 |
93 | void MainWindow::checkRegularExpression()
94 | {
95 | QRegularExpression regexp(ui->regularExpressionLineEdit->text());
96 |
97 | if (!regexp.isValid()) {
98 | this->statusBar()->showMessage(tr("Regular expression is not valid"));
99 | } else {
100 | this->statusBar()->clearMessage();
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/PythonPlugin/ledwidget.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | from PyQt5.QtCore import *
4 | from PyQt5.QtGui import *
5 | from PyQt5.QtWidgets import *
6 |
7 |
8 | class LedWidget(QWidget):
9 |
10 | def __init__(self, parent=None):
11 |
12 | super(LedWidget, self).__init__(parent)
13 |
14 | self._diamX = 0
15 | self._diamY = 0
16 | self._diameter = 30
17 | self._color = QColor("red")
18 | self._alignment = Qt.AlignCenter
19 | self._state = True
20 | self._flashing = False
21 | self._flashRate = 200
22 |
23 | self._timer = QTimer()
24 | self._timer.timeout.connect(self.toggleState)
25 |
26 | self.setDiameter(self._diameter)
27 |
28 | def paintEvent(self, event):
29 | painter = QPainter()
30 | x = 0
31 | y = 0
32 | if self._alignment & Qt.AlignLeft:
33 | x = 0
34 | elif self._alignment & Qt.AlignRight:
35 | x = self.width() - self._diameter
36 | elif self._alignment & Qt.AlignHCenter:
37 | x = (self.width() - self._diameter) / 2
38 | elif self._alignment & Qt.AlignJustify:
39 | x = 0
40 |
41 | if self._alignment & Qt.AlignTop:
42 | y = 0
43 | elif self._alignment & Qt.AlignBottom:
44 | y = self.height() - self._diameter
45 | elif self._alignment & Qt.AlignVCenter:
46 | y = (self.height() - self._diameter) / 2
47 |
48 | gradient = QRadialGradient(x + self._diameter / 2, y + self._diameter / 2,
49 | self._diameter * 0.4, self._diameter * 0.4, self._diameter * 0.4)
50 | gradient.setColorAt(0, Qt.white)
51 |
52 | if self._state:
53 | gradient.setColorAt(1, self._color)
54 | else:
55 | gradient.setColorAt(1, Qt.black)
56 |
57 | painter.begin(self)
58 | brush = QBrush(gradient)
59 | painter.setPen(self._color)
60 | painter.setRenderHint(QPainter.Antialiasing, True)
61 | painter.setBrush(brush)
62 | painter.drawEllipse(x, y, self._diameter - 1, self._diameter - 1)
63 |
64 | if self._flashRate > 0 and self._flashing:
65 | self._timer.start(self._flashRate)
66 | else:
67 | self._timer.stop()
68 |
69 | painter.end()
70 |
71 | def minimumSizeHint(self):
72 | return QSize(self._diameter, self._diameter)
73 |
74 | def sizeHint(self):
75 | return QSize(self._diameter, self._diameter)
76 |
77 | def getDiameter(self):
78 | return self._diameter
79 |
80 | @pyqtSlot(int)
81 | def setDiameter(self, value):
82 | self._diameter = value
83 | self.update()
84 |
85 | def getColor(self):
86 | return self._color
87 |
88 | @pyqtSlot(QColor)
89 | def setColor(self, value):
90 | self._color = value
91 | self.update()
92 |
93 | def getAlignment(self):
94 | return self._alignment
95 |
96 | @pyqtSlot(Qt.Alignment)
97 | def setAlignment(self, value):
98 | self._alignment = value
99 | self.update()
100 |
101 | def getState(self):
102 | return self._alignment
103 |
104 | @pyqtSlot(bool)
105 | def setState(self, value):
106 | self._state = value
107 | self.update()
108 |
109 | @pyqtSlot()
110 | def toggleState(self):
111 | self._state = not self._state
112 | self.update()
113 |
114 | def isFlashing(self):
115 | return self._flashing
116 |
117 | @pyqtSlot(bool)
118 | def setFlashing(self, value):
119 | self._flashing = value
120 | self.update()
121 |
122 | def getFlashRate(self):
123 | return self._flashRate
124 |
125 | @pyqtSlot(int)
126 | def setFlashRate(self, value):
127 | self._flashRate = value
128 | self.update()
129 |
130 | @pyqtSlot()
131 | def startFlashing(self):
132 | self.setFlashing(True)
133 |
134 | @pyqtSlot()
135 | def stopFlashing(self):
136 | self.setFlashing(False)
137 |
138 | diameter = pyqtProperty(int, getDiameter, setDiameter)
139 | color = pyqtProperty(QColor, getColor, setColor)
140 | alignment = pyqtProperty(Qt.Alignment, getAlignment, setAlignment)
141 | state = pyqtProperty(bool, getState, setState)
142 | flashing = pyqtProperty(bool, isFlashing, setFlashing)
143 | flashRate = pyqtProperty(int, getFlashRate, setFlashRate)
144 |
145 | if __name__ == "__main__":
146 |
147 | import sys
148 |
149 | app = QApplication(sys.argv)
150 | led = LedWidget()
151 | led.show()
152 | sys.exit(app.exec_())
--------------------------------------------------------------------------------
/MasksValidators/maskandvalidatordemo/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "mainwindow.h"
3 | #include "ui_mainwindow.h"
4 |
5 | MainWindow::MainWindow(QWidget *parent) :
6 | QMainWindow(parent),
7 | ui(new Ui::MainWindow)
8 | {
9 | ui->setupUi(this);
10 |
11 | // Create validators.
12 | intValidator = new QIntValidator(this);
13 | doubleValidator = new QDoubleValidator(this);
14 | regularExpressionValidator = new QRegularExpressionValidator(this);
15 |
16 | // Initialize.
17 | setValidator();
18 |
19 | // Connect the buttons.
20 | connect(ui->quitButton, &QPushButton::clicked, qApp, &QApplication::quit);
21 | connect(ui->clearButton, &QPushButton::clicked, [=]() { ui->inputLineEdit->clear(); });
22 | connect(ui->clearButton, &QPushButton::clicked, [=]() { ui->maskLineEdit->clear(); });
23 |
24 | // Update input mask when it changes.
25 | connect(ui->maskLineEdit, &QLineEdit::textChanged, [=](const QString &newMask) { ui->inputLineEdit->setInputMask(newMask); });
26 |
27 | // Handle validator type combo box changing.
28 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
29 | connect(ui->validatorTypeComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::setValidator);
30 | #else
31 | connect(ui->validatorTypeComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::setValidator);
32 | #endif
33 |
34 | // If any settings change, update the validator.
35 | connect(ui->intTopSpinBox, qOverload(&QSpinBox::valueChanged), this, &MainWindow::setValidator);
36 | connect(ui->intBottomSpinBox, qOverload(&QSpinBox::valueChanged), this, &MainWindow::setValidator);
37 | connect(ui->doubleTopSpinBox, qOverload(&QDoubleSpinBox::valueChanged), this, &MainWindow::setValidator);
38 | connect(ui->doubleBottomSpinBox, qOverload(&QDoubleSpinBox::valueChanged), this, &MainWindow::setValidator);
39 | connect(ui->decimalsSpinBox, qOverload(&QSpinBox::valueChanged), this, &MainWindow::setValidator);
40 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
41 | connect(ui->notationComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::setValidator);
42 | #else
43 | connect(ui->notationComboBox, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::setValidator);
44 | #endif
45 | connect(ui->regularExpressionLineEdit, &QLineEdit::textChanged, this, &MainWindow::setValidator);
46 |
47 | // Update status bar when line edit changes.
48 | connect(ui->inputLineEdit, &QLineEdit::textChanged, this, &MainWindow::updateStatusBar);
49 |
50 | // Check for validity when regular expression changes.
51 | connect(ui->regularExpressionLineEdit, &QLineEdit::textChanged, this, &MainWindow::checkRegularExpression);
52 | }
53 |
54 | MainWindow::~MainWindow()
55 | {
56 | delete ui;
57 | }
58 |
59 | void MainWindow::setValidator()
60 | {
61 | // Set stacked widget to appropriate index from combo box.
62 | ui->stackedWidget->setCurrentIndex(ui->validatorTypeComboBox->currentIndex());
63 |
64 | // Set the validator to the correct type.
65 | switch (ui->validatorTypeComboBox->currentIndex()) {
66 |
67 | case 0: // Integer
68 | intValidator->setRange(ui->intBottomSpinBox->value(), ui->intTopSpinBox->value());
69 | ui->inputLineEdit->setValidator(intValidator);
70 | break;
71 |
72 | case 1: // Double
73 | doubleValidator->setRange(ui->doubleBottomSpinBox->value(), ui->doubleTopSpinBox->value());
74 | doubleValidator->setDecimals(ui->decimalsSpinBox->value());
75 | doubleValidator->setNotation(static_cast(ui->notationComboBox->currentIndex()));
76 | ui->inputLineEdit->setValidator(doubleValidator);
77 | break;
78 |
79 | case 2: // Regular expression
80 | regularExpressionValidator->setRegularExpression(QRegularExpression(ui->regularExpressionLineEdit->text()));
81 | ui->inputLineEdit->setValidator(regularExpressionValidator);
82 | break;
83 | }
84 | }
85 |
86 | void MainWindow::updateStatusBar()
87 | {
88 | if (ui->inputLineEdit->hasAcceptableInput()) {
89 | this->statusBar()->showMessage(tr("Input is acceptable"));
90 | } else {
91 | this->statusBar()->showMessage(tr("Input is not acceptable"));
92 | }
93 | }
94 |
95 | void MainWindow::checkRegularExpression()
96 | {
97 | QRegularExpression regexp(ui->regularExpressionLineEdit->text());
98 |
99 | if (!regexp.isValid()) {
100 | this->statusBar()->showMessage(tr("Regular expression is not valid"));
101 | } else {
102 | this->statusBar()->clearMessage();
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/MultiLanguageApp/dialog.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | #include "dialog.h"
16 | #include "TranslatorManager.h"
17 | #include "translation.h"
18 |
19 | bool myglobal = true;
20 |
21 | Dialog::Dialog(QWidget *parent)
22 | : QDialog(parent)
23 | {
24 |
25 | m_label = new QLabel();
26 | if (m_label)
27 | {
28 | QFont font("Sans Serif", 18, QFont::Bold);
29 | m_label->setFont(font);
30 | m_label->setAlignment(Qt::AlignCenter);
31 | m_label->setText(qtTrId(ID_LABEL_TEXT));
32 | }
33 | QStringList list;
34 | list.append(qtTrId(ID_COMBO_ITEM_1));
35 | list.append(qtTrId(ID_COMBO_ITEM_2));
36 | list.append(qtTrId(ID_COMBO_ITEM_3));
37 |
38 | m_combo = createCombobox(list);
39 | if (m_combo)
40 | {
41 | connect(m_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComboChanged(int)));
42 | }
43 |
44 | m_cancelBtn = createButton();
45 | if (m_cancelBtn)
46 | {
47 | connect(m_cancelBtn, SIGNAL(clicked()), this, SLOT(slotAcceptParameters()));
48 | }
49 |
50 | QVBoxLayout *mainLayout = new QVBoxLayout;
51 | mainLayout->addWidget(m_combo);
52 | mainLayout->addWidget(m_label);
53 | mainLayout->addWidget(m_cancelBtn);
54 | setLayout(mainLayout);
55 | resize(400, 300);
56 | }
57 |
58 | Dialog::~Dialog()
59 | {
60 | }
61 |
62 | void Dialog::slotAcceptParameters()
63 | {
64 | close();
65 | }
66 |
67 | QComboBox* Dialog::createCombobox(QStringList& list, QWidget* parent)
68 | {
69 | QComboBox* comboBox = new QComboBox(parent);
70 |
71 | if (comboBox)
72 | {
73 | QFont font("Sans Serif", 18, QFont::Bold);
74 | comboBox->setFont(font);
75 | // Populate the combo box.
76 | foreach(QString s, list)
77 | {
78 | comboBox->addItem(s, s);
79 | }
80 |
81 | QString btStyle = "QComboBox { background-color: black; color: #29ABE2; " \
82 | "border: 2px solid #8f8f91; border-color: #29ABE2; border-radius: 5px;" \
83 | "padding: 1px 28px 1px 3px;}" \
84 | "QComboBox::drop-down {"
85 | "width: 47px;"
86 | "border: 0px;} "
87 | "QComboBox::down-arrow { "
88 | "image: url(:/images/down_24.png);"
89 | "width: 42px;"
90 | "height: 42px;}";
91 |
92 | comboBox->setStyleSheet(btStyle);
93 |
94 | QString lang = TranslatorManager::instance()->getCurrentLang();
95 | int index = 0;
96 | if (lang.compare("fr_FR") == 0)
97 | {
98 | index = 1;
99 | }
100 | else if (lang.compare("ru_RU") == 0)
101 | {
102 | index = 2;
103 | }
104 |
105 | comboBox->setCurrentIndex(index);
106 | }
107 |
108 | return comboBox;
109 | }
110 |
111 | void Dialog::slotComboChanged(int n)
112 | {
113 | QString lang;
114 |
115 | if (n == 1)
116 | {
117 | lang = "fr_FR";
118 | }
119 | else if (n == 2)
120 | {
121 | lang = "ru_RU";
122 | }
123 | else
124 | {
125 | lang = "en_US";
126 | }
127 |
128 | TranslatorManager::instance()->setTranslator(lang);
129 | this->updateUI();
130 | }
131 |
132 | void Dialog::updateUI()
133 | {
134 | if (m_label)
135 | {
136 | m_label->setText(qtTrId(ID_LABEL_TEXT));
137 | }
138 |
139 | if (m_cancelBtn)
140 | {
141 | m_cancelBtn->setText(qtTrId(ID_BUTTON_TEXT_1));
142 | m_cancelBtn->update();
143 | }
144 |
145 |
146 | if (m_combo)
147 | {
148 | m_combo->setItemText(0, qtTrId(ID_COMBO_ITEM_1));
149 | m_combo->setItemText(1, qtTrId(ID_COMBO_ITEM_2));
150 | m_combo->setItemText(2, qtTrId(ID_COMBO_ITEM_3));
151 | m_combo->update();
152 | }
153 | }
154 |
155 | QToolButton* Dialog::createButton()
156 | {
157 | QToolButton* saveBtn = new QToolButton();
158 | if (saveBtn)
159 | {
160 | saveBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
161 | QFont font("Sans Serif", 30, QFont::Bold);
162 | saveBtn->setFont(font);
163 | saveBtn->setText(qtTrId(ID_BUTTON_TEXT_1));
164 | QString btStyle = "background-color: black; color: #29ABE2; border: 2px solid #8f8f91; border-color: #29ABE2; border-radius: 10px;";
165 | saveBtn->setStyleSheet(btStyle);
166 | saveBtn->setMinimumSize(500, 60);
167 | saveBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
168 | }
169 |
170 | return saveBtn;
171 | }
172 |
--------------------------------------------------------------------------------
/gpio/part8/demo2.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Example of using libsoc for GPIO programming.
4 |
5 | Toggles three LEDs in a "Cylon" pattern until the pushbutton is
6 | pressed, and then exits. Will run on Raspberry Pi or Toradex Colibri
7 | platforms.
8 |
9 | This version reads the switch status using interrupts and a callback.
10 |
11 | */
12 |
13 | #include
14 | #include
15 | #include "libsoc_gpio.h"
16 | #include "libsoc_debug.h"
17 |
18 | // Uncomment the appropriate lines below for the hardware it is
19 | // running on.
20 |
21 | // Raspberry Pi
22 | //const int led1 = 24; // Red LED
23 | //const int led2 = 25; // Green LED
24 | //const int led3 = 5; // Yellow LED
25 | //const int button = 6; // Pushbutton
26 |
27 | // Toradex Colibri
28 | const int led1 = 52; // Red LED
29 | const int led2 = 53; // Green LED
30 | const int led3 = 63; // Yellow LED
31 | const int button = 93; // Pushbutton
32 |
33 | // Delay (in microseconds)
34 | const int delay = 100000;
35 |
36 | // Exit flag
37 | bool exitLoop = false;
38 |
39 |
40 | // Callback invoked when button is pressed. Set flag to exit.
41 | int buttonCallback(void* arg)
42 | {
43 | printf("Button pressed\n");
44 | exitLoop = true;
45 | return 0;
46 | }
47 |
48 |
49 | // Main program
50 | int main(void)
51 | {
52 | // Uncomment the next line to enable debug output if desired.
53 | //libsoc_set_debug(1);
54 |
55 | // Request gpios. May need to use LS_SHARED with older versions
56 | // of libsoc.
57 | gpio *gpio_led1 = libsoc_gpio_request(led1, LS_GPIO_SHARED);
58 | gpio *gpio_led2 = libsoc_gpio_request(led2, LS_GPIO_SHARED);
59 | gpio *gpio_led3 = libsoc_gpio_request(led3, LS_GPIO_SHARED);
60 | gpio *gpio_button = libsoc_gpio_request(button, LS_GPIO_SHARED);
61 |
62 | // Ensure gpios were successfully requested.
63 | if (gpio_led1 == NULL) {
64 | printf("Failed gpio_led1 request.\n");
65 | exit(EXIT_FAILURE);
66 | }
67 | if (gpio_led2 == NULL) {
68 | printf("Failed gpio_led2 request.\n");
69 | exit(EXIT_FAILURE);
70 | }
71 | if (gpio_led3 == NULL) {
72 | printf("Failed gpio_led3 request.\n");
73 | exit(EXIT_FAILURE);
74 | }
75 | if (gpio_button == NULL) {
76 | printf("Failed gpio_button request.\n");
77 | exit(EXIT_FAILURE);
78 | }
79 |
80 | // Set directions.
81 | libsoc_gpio_set_direction(gpio_led1, OUTPUT);
82 | libsoc_gpio_set_direction(gpio_led2, OUTPUT);
83 | libsoc_gpio_set_direction(gpio_led3, OUTPUT);
84 | libsoc_gpio_set_direction(gpio_button, INPUT);
85 |
86 | // Check directions.
87 | if (libsoc_gpio_get_direction(gpio_led1) != OUTPUT) {
88 | printf("Failed to set direction of gpio_led1\n");
89 | exit(EXIT_FAILURE);
90 | }
91 | if (libsoc_gpio_get_direction(gpio_led2) != OUTPUT) {
92 | printf("Failed to set direction of gpio_led2\n");
93 | exit(EXIT_FAILURE);
94 | }
95 | if (libsoc_gpio_get_direction(gpio_led3) != OUTPUT) {
96 | printf("Failed to set direction of gpio_led3\n");
97 | exit(EXIT_FAILURE);
98 | }
99 | if (libsoc_gpio_get_direction(gpio_button) != INPUT) {
100 | printf("Failed to set direction of gpio_button\n");
101 | exit(EXIT_FAILURE);
102 | }
103 |
104 | // Set input edge to FALLING.
105 | libsoc_gpio_set_edge(gpio_button, FALLING);
106 |
107 | // Set up callback when button status changes.
108 | libsoc_gpio_callback_interrupt(gpio_button, &buttonCallback, (void *) 0);
109 |
110 | while (!exitLoop) {
111 |
112 | // Turn LEDs on and off in desired sequence.
113 | libsoc_gpio_set_level(gpio_led1, HIGH);
114 | libsoc_gpio_set_level(gpio_led2, LOW);
115 | libsoc_gpio_set_level(gpio_led3, LOW);
116 | usleep(delay);
117 |
118 | libsoc_gpio_set_level(gpio_led1, LOW);
119 | libsoc_gpio_set_level(gpio_led2, HIGH);
120 | libsoc_gpio_set_level(gpio_led3, LOW);
121 | usleep(delay);
122 |
123 | libsoc_gpio_set_level(gpio_led1, LOW);
124 | libsoc_gpio_set_level(gpio_led2, LOW);
125 | libsoc_gpio_set_level(gpio_led3, HIGH);
126 | usleep(delay);
127 |
128 | libsoc_gpio_set_level(gpio_led1, LOW);
129 | libsoc_gpio_set_level(gpio_led2, HIGH);
130 | libsoc_gpio_set_level(gpio_led3, LOW);
131 | usleep(delay);
132 | }
133 |
134 | // Cancel the callback as it is no longer needed.
135 | libsoc_gpio_callback_interrupt_cancel(gpio_button);
136 |
137 | // Turn all LEDs off.
138 | libsoc_gpio_set_level(gpio_led1, LOW);
139 | libsoc_gpio_set_level(gpio_led2, LOW);
140 | libsoc_gpio_set_level(gpio_led3, LOW);
141 |
142 | // Clean up.
143 | libsoc_gpio_free(gpio_led1);
144 | libsoc_gpio_free(gpio_led2);
145 | libsoc_gpio_free(gpio_led3);
146 | libsoc_gpio_free(gpio_button);
147 |
148 | return EXIT_SUCCESS;
149 | }
150 |
--------------------------------------------------------------------------------
/QtForPython/spreadsheet/original/cell.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "cell.h"
4 |
5 | Cell::Cell()
6 | {
7 | setDirty();
8 | }
9 |
10 | QTableWidgetItem *Cell::clone() const
11 | {
12 | return new Cell(*this);
13 | }
14 |
15 | void Cell::setData(int role, const QVariant &value)
16 | {
17 | QTableWidgetItem::setData(role, value);
18 | if (role == Qt::EditRole)
19 | setDirty();
20 | }
21 |
22 | QVariant Cell::data(int role) const
23 | {
24 | if (role == Qt::DisplayRole) {
25 | if (value().isValid()) {
26 | return value().toString();
27 | } else {
28 | return "####";
29 | }
30 | } else if (role == Qt::TextAlignmentRole) {
31 | if (value().type() == QVariant::String) {
32 | return int(Qt::AlignLeft | Qt::AlignVCenter);
33 | } else {
34 | return int(Qt::AlignRight | Qt::AlignVCenter);
35 | }
36 | } else {
37 | return QTableWidgetItem::data(role);
38 | }
39 | }
40 |
41 | void Cell::setFormula(const QString &formula)
42 | {
43 | setData(Qt::EditRole, formula);
44 | }
45 |
46 | QString Cell::formula() const
47 | {
48 | return data(Qt::EditRole).toString();
49 | }
50 |
51 | void Cell::setDirty()
52 | {
53 | cacheIsDirty = true;
54 | }
55 |
56 | QVariant Cell::value() const
57 | {
58 | if (cacheIsDirty) {
59 | cacheIsDirty = false;
60 |
61 | QString formulaStr = formula();
62 | if (formulaStr.startsWith('\'')) {
63 | cachedValue = formulaStr.mid(1);
64 | } else if (formulaStr.startsWith('=')) {
65 | cachedValue = Invalid;
66 | QString expr = formulaStr.mid(1);
67 | expr.replace(" ", "");
68 | expr.append(QChar::Null);
69 |
70 | int pos = 0;
71 | cachedValue = evalExpression(expr, pos);
72 | if (expr[pos] != QChar::Null)
73 | cachedValue = Invalid;
74 | } else {
75 | bool ok;
76 | double d = formulaStr.toDouble(&ok);
77 | if (ok) {
78 | cachedValue = d;
79 | } else {
80 | cachedValue = formulaStr;
81 | }
82 | }
83 | }
84 | return cachedValue;
85 | }
86 |
87 | QVariant Cell::evalExpression(const QString &str, int &pos) const
88 | {
89 | QVariant result = evalTerm(str, pos);
90 | while (str[pos] != QChar::Null) {
91 | QChar op = str[pos];
92 | if (op != '+' && op != '-')
93 | return result;
94 | ++pos;
95 |
96 | QVariant term = evalTerm(str, pos);
97 | if (result.type() == QVariant::Double
98 | && term.type() == QVariant::Double) {
99 | if (op == '+') {
100 | result = result.toDouble() + term.toDouble();
101 | } else {
102 | result = result.toDouble() - term.toDouble();
103 | }
104 | } else {
105 | result = Invalid;
106 | }
107 | }
108 | return result;
109 | }
110 |
111 | QVariant Cell::evalTerm(const QString &str, int &pos) const
112 | {
113 | QVariant result = evalFactor(str, pos);
114 | while (str[pos] != QChar::Null) {
115 | QChar op = str[pos];
116 | if (op != '*' && op != '/')
117 | return result;
118 | ++pos;
119 |
120 | QVariant factor = evalFactor(str, pos);
121 | if (result.type() == QVariant::Double
122 | && factor.type() == QVariant::Double) {
123 | if (op == '*') {
124 | result = result.toDouble() * factor.toDouble();
125 | } else {
126 | if (factor.toDouble() == 0.0) {
127 | result = Invalid;
128 | } else {
129 | result = result.toDouble() / factor.toDouble();
130 | }
131 | }
132 | } else {
133 | result = Invalid;
134 | }
135 | }
136 | return result;
137 | }
138 |
139 | QVariant Cell::evalFactor(const QString &str, int &pos) const
140 | {
141 | QVariant result;
142 | bool negative = false;
143 |
144 | if (str[pos] == '-') {
145 | negative = true;
146 | ++pos;
147 | }
148 |
149 | if (str[pos] == '(') {
150 | ++pos;
151 | result = evalExpression(str, pos);
152 | if (str[pos] != ')')
153 | result = Invalid;
154 | ++pos;
155 | } else {
156 | QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
157 | QString token;
158 |
159 | while (str[pos].isLetterOrNumber() || str[pos] == '.') {
160 | token += str[pos];
161 | ++pos;
162 | }
163 |
164 | if (regExp.exactMatch(token)) {
165 | int column = token[0].toUpper().unicode() - 'A';
166 | int row = token.midRef(1).toInt() - 1;
167 |
168 | Cell *c = static_cast(
169 | tableWidget()->item(row, column));
170 | if (c) {
171 | result = c->value();
172 | } else {
173 | result = 0.0;
174 | }
175 | } else {
176 | bool ok;
177 | result = token.toDouble(&ok);
178 | if (!ok)
179 | result = Invalid;
180 | }
181 | }
182 |
183 | if (negative) {
184 | if (result.type() == QVariant::Double) {
185 | result = -result.toDouble();
186 | } else {
187 | result = Invalid;
188 | }
189 | }
190 | return result;
191 | }
192 |
--------------------------------------------------------------------------------
/QCompleter/completerdemo/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 339
10 | 357
11 |
12 |
13 |
14 | QCompleter Example
15 |
16 |
17 |
18 | -
19 |
20 |
21 | Input Fields
22 |
23 |
24 |
-
25 |
26 |
27 | Line edit:
28 |
29 |
30 |
31 | -
32 |
33 |
34 | -
35 |
36 |
37 | Combo box:
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 |
47 | -
48 |
49 |
50 | Settings
51 |
52 |
53 |
-
54 |
55 |
56 | Completion mode:
57 |
58 |
59 |
60 | -
61 |
62 |
-
63 |
64 | Popup
65 |
66 |
67 | -
68 |
69 | Inline
70 |
71 |
72 | -
73 |
74 | Unfiltered Popup
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 | Model sorting:
83 |
84 |
85 |
86 | -
87 |
88 |
-
89 |
90 | Unsorted
91 |
92 |
93 | -
94 |
95 | Case Sensitively Sorted
96 |
97 |
98 | -
99 |
100 | Case Insensitively Sorted
101 |
102 |
103 |
104 |
105 | -
106 |
107 |
108 | Filter mode:
109 |
110 |
111 |
112 | -
113 |
114 |
-
115 |
116 | Starts With
117 |
118 |
119 | -
120 |
121 | Contains
122 |
123 |
124 | -
125 |
126 | Ends With
127 |
128 |
129 |
130 |
131 | -
132 |
133 |
134 | Max visible items:
135 |
136 |
137 |
138 | -
139 |
140 |
141 | 1
142 |
143 |
144 | 7
145 |
146 |
147 |
148 | -
149 |
150 |
151 | Case sensitive
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
170 |
171 |
172 | TopToolBarArea
173 |
174 |
175 | false
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
--------------------------------------------------------------------------------
/calculator-qml/calculator.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | #include "calculator.h"
8 |
9 | // Constructor ///////////////////////////////////////////////////////////////
10 |
11 | Calculator::Calculator(QObject *parent)
12 | : QObject(parent), mRoot(0), mDisplay()
13 | {
14 | connect(this, SIGNAL(displayChanged()), this, SLOT(onDisplayChanged()));
15 | }
16 |
17 | // Destructor ////////////////////////////////////////////////////////////////
18 |
19 | Calculator::~Calculator()
20 | {
21 | }
22 |
23 | // setDisplay() //////////////////////////////////////////////////////////////
24 |
25 | void Calculator::setDisplay(const QString &display)
26 | {
27 | if (mDisplay != display) {
28 | mDisplay = display;
29 | emit displayChanged();
30 | }
31 | }
32 |
33 | // onDisplayChanged() ////////////////////////////////////////////////////////
34 |
35 | void Calculator::onDisplayChanged()
36 | {
37 | // push the new display value to QML
38 | if (mRoot) mRoot->setProperty("displayText", mDisplay);
39 | }
40 |
41 | // setRootObject() ///////////////////////////////////////////////////////////
42 |
43 | void Calculator::setRootObject(QObject *root)
44 | {
45 | // disconnect from previous root
46 | if (mRoot != 0) mRoot->disconnect(this);
47 |
48 | mRoot = root;
49 |
50 | if (mRoot) {
51 | // setup new connections
52 | connect(mRoot, SIGNAL(keyClicked(int)), this, SLOT(keyClicked(int)));
53 | connect(mRoot, SIGNAL(cutTriggered()), this, SLOT(editCut()));
54 | connect(mRoot, SIGNAL(copyTriggered()), this, SLOT(editCopy()));
55 | connect(mRoot, SIGNAL(pasteTriggered()), this, SLOT(editPaste()));
56 |
57 | // set initial state
58 | clearAll();
59 | }
60 | }
61 |
62 | // buttonClicked() ///////////////////////////////////////////////////////////
63 |
64 | void Calculator::keyClicked(int key)
65 | {
66 | // Note: This method uses immediate execution mode. There is no operator precedence.
67 |
68 | if (!mRoot) return;
69 |
70 | double operand = mDisplay.toDouble();
71 |
72 | switch (key) {
73 | case Qt::Key_0:
74 | case Qt::Key_1:
75 | case Qt::Key_2:
76 | case Qt::Key_3:
77 | case Qt::Key_4:
78 | case Qt::Key_5:
79 | case Qt::Key_6:
80 | case Qt::Key_7:
81 | case Qt::Key_8:
82 | case Qt::Key_9: // digit pressed
83 | if ((mDisplay == "0") && key == Qt::Key_0) return;
84 |
85 | if (mExpectingOperand) {
86 | mDisplay.clear();
87 | mExpectingOperand = false;
88 | }
89 |
90 | mDisplay += QString::number(key-Qt::Key_0);
91 | break;
92 |
93 | case Qt::Key_Period:
94 | if (mExpectingOperand) {
95 | mDisplay = "0";
96 | }
97 |
98 | if (!mDisplay.contains('.')) {
99 | mDisplay += '.';
100 | }
101 |
102 | mExpectingOperand = false;
103 | break;
104 |
105 | case Qt::Key_Minus:
106 | case Qt::Key_Plus:
107 | case Qt::Key_Asterisk:
108 | case Qt::Key_Slash:
109 | case Qt::Key_Enter:
110 | if (mPendingOperator != 0) {
111 | try {
112 | mResult = calculate(operand, mPendingOperator);
113 | mDisplay = QString::number(mResult);
114 | } catch (std::range_error e) {
115 | clearAll();
116 | mDisplay = e.what();
117 | emit displayChanged();
118 | return;
119 | }
120 | } else {
121 | mResult = operand;
122 | }
123 | if (key == Qt::Key_Enter) mPendingOperator = 0;
124 | else mPendingOperator = key;
125 | mExpectingOperand = true;
126 | break;
127 |
128 | case Qt::Key_Delete:
129 | if ((mDisplay == "0") && mExpectingOperand) {
130 | // already cleared so clear all
131 | mPendingOperator = 0;
132 | mResult = 0.0;
133 | }
134 |
135 | mDisplay = "0";
136 | mExpectingOperand = true;
137 | break;
138 |
139 | default:
140 | return;
141 | }
142 |
143 | emit displayChanged();
144 | }
145 |
146 | // calculate() ///////////////////////////////////////////////////////////////
147 |
148 | double Calculator::calculate(double operand, int operation)
149 | {
150 | switch (operation) {
151 | case Qt::Key_Minus:
152 | return mResult - operand;
153 |
154 | case Qt::Key_Plus:
155 | return mResult + operand;
156 |
157 | case Qt::Key_Asterisk:
158 | return mResult * operand;
159 |
160 | case Qt::Key_Slash:
161 | if (qFuzzyCompare(operand + 1.0, 0.0 + 1.0)) throw std::range_error("nan");
162 | return mResult / operand;
163 |
164 | default:
165 | return 0.0;
166 | }
167 | }
168 |
169 | // clearAll() ////////////////////////////////////////////////////////////////
170 |
171 | void Calculator::clearAll()
172 | {
173 | if (mRoot) {
174 | mDisplay = "0";
175 | mResult = 0.0;
176 | mExpectingOperand = true;
177 | mPendingOperator = 0;
178 | emit displayChanged();
179 | }
180 | }
181 |
182 | // editCut() /////////////////////////////////////////////////////////////////
183 |
184 | void Calculator::editCut()
185 | {
186 | // copy and delete
187 | if (mRoot) {
188 | editCopy();
189 | clearAll();
190 | }
191 | }
192 |
193 | // editCopy() ////////////////////////////////////////////////////////////////
194 |
195 | void Calculator::editCopy()
196 | {
197 | if (mRoot) {
198 | QGuiApplication::clipboard()->setText(mDisplay);
199 | }
200 | }
201 |
202 | // editPaste() ///////////////////////////////////////////////////////////////
203 |
204 | void Calculator::editPaste()
205 | {
206 | if (mRoot) {
207 | setDisplay(QGuiApplication::clipboard()->text());
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
|