Adaptive layout

This commit is contained in:
Andrey 2022-03-02 18:55:29 +04:00 committed by GitHub
parent 32db1c1e43
commit f81eba4924
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 1894 additions and 0 deletions

32
QuteSample.pro Normal file
View file

@ -0,0 +1,32 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
TRANSLATIONS += \
QuteSample_ru_RU.ts
CONFIG += lrelease
CONFIG += embed_translations
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
pictures.qrc

1265
QuteSample.pro.user Normal file

File diff suppressed because it is too large Load diff

BIN
QuteSample_ru_RU.qm Normal file

Binary file not shown.

130
QuteSample_ru_RU.ts Normal file
View file

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="ru_RU">
<context>
<name>MainWindow</name>
<message>
<location filename="mainwindow.ui" line="14"/>
<source>MainWindow</source>
<translation>Окошечко</translation>
</message>
<message>
<location filename="mainwindow.ui" line="192"/>
<source>Name</source>
<translation>Имя</translation>
</message>
<message>
<location filename="mainwindow.ui" line="215"/>
<source>Birthday:</source>
<translation>Дата рождения:</translation>
</message>
<message>
<location filename="mainwindow.ui" line="179"/>
<source>I&apos;m a developer</source>
<translation>Я - разработчик</translation>
</message>
<message>
<location filename="mainwindow.ui" line="161"/>
<source>Start</source>
<translation>Старт</translation>
</message>
<message>
<location filename="mainwindow.ui" line="30"/>
<source>Wait: %p%</source>
<oldsource>Ждите: %p%</oldsource>
<translation>Ждите: %p%</translation>
</message>
<message>
<location filename="mainwindow.ui" line="53"/>
<source>Text result</source>
<translation>Текст</translation>
</message>
<message>
<location filename="mainwindow.ui" line="70"/>
<location filename="mainwindow.ui" line="97"/>
<source>TextLabel</source>
<translation></translation>
</message>
<message>
<location filename="mainwindow.ui" line="138"/>
<source>Picture</source>
<translation>Картинка</translation>
</message>
<message>
<location filename="mainwindow.ui" line="234"/>
<source>File</source>
<translation>Файл</translation>
</message>
<message>
<location filename="mainwindow.ui" line="242"/>
<source>Options</source>
<translation>Опции</translation>
</message>
<message>
<location filename="mainwindow.ui" line="248"/>
<source>About</source>
<translation>Справка</translation>
</message>
<message>
<location filename="mainwindow.ui" line="259"/>
<source>Choose a config</source>
<translation>Выбрать конфиг</translation>
</message>
<message>
<location filename="mainwindow.ui" line="264"/>
<source>Exit</source>
<translation>Выход</translation>
</message>
<message>
<location filename="mainwindow.ui" line="267"/>
<source>Ctrl+Q</source>
<translation></translation>
</message>
<message>
<location filename="mainwindow.ui" line="272"/>
<source>Application</source>
<translation>Приложение</translation>
</message>
<message>
<location filename="mainwindow.ui" line="277"/>
<source>Developer&apos;s GitHub</source>
<translation>GitHub разработчика</translation>
</message>
<message>
<location filename="mainwindow.ui" line="288"/>
<source>Random Picture</source>
<translation>Случайная картинка</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="49"/>
<source>Hello %1!</source>
<translation>Привет, %1!</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="50"/>
<source>Your next birthday is on: %2</source>
<oldsource>NextBirthday</oldsource>
<translation>Следующий др: %2</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="101"/>
<source>About this app</source>
<translation>О приложении</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="102"/>
<source>This application written just for learning
Qt for Desktop and Mobile.
by DarkCat09</source>
<oldsource>This application written just for learning Qt for Desktop and Mobile
by DarkCat09</oldsource>
<translation>Программа написана чисто для изучения
Qt для десктопа и мобильных устройств.
Создано DarkCat09</translation>
</message>
<message>
<source>Just debug</source>
<translation type="vanished">Просто отладка</translation>
</message>
</context>
</TS>

23
main.cpp Normal file
View file

@ -0,0 +1,23 @@
#include "mainwindow.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "QuteSample_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
app.installTranslator(&translator);
break;
}
}
MainWindow win;
win.show();
return app.exec();
}

108
mainwindow.cpp Normal file
View file

@ -0,0 +1,108 @@
#include <thread>
#include <chrono>
#include "QRandomGenerator"
#include "QDesktopServices"
#include "QMessageBox"
#include "mainwindow.h"
#include "ui_mainwindow.h"
QRandomGenerator64 gen(std::rand());
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_plainTextEdit_2_textChanged()
{
//
}
void MainWindow::on_pushButton_clicked()
{
std::thread t1([&]()
{
for (int i = 0; i <= 100; i+=5) {
ui->progressBar->setValue(i);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
});
std::thread t2([&]()
{
// read
QString name = ui->plainTextEdit_2->toPlainText();
QDate birth = ui->dateEdit_2->date();
// compute
QDate next = QDate::currentDate();
next.setDate(next.year(), birth.month(), birth.day());
// strings
QString hello = tr("Hello %1!").arg(name);
QString nextb = tr("Your next birthday is on: %2").arg(next.toString());
// check if there are my data
bool namedev = (name.contains("Andre") or name.contains("Андрей"));
bool datedev = (birth.year() == 2009 and
birth.month() == 7 and
birth.day() == 13);
if (namedev and datedev)
ui->checkBox_2->setEnabled(true);
// print
ui->label_greeting->setText(hello);
ui->label_birthday->setText(nextb);
ui->lcdNumber->display(next.year() - birth.year());
// picture
if (ui->actionRandom_Picture->isChecked())
{
int randpic = -1;
if (!ui->checkBox_2->isChecked())
randpic = gen.bounded(1, 6);
QString tmpl = ":/prefix/pics/%1.jpg";
QString file = tmpl.arg(randpic);
QPixmap pixmap(file);
ui->label_image->setPixmap(pixmap.scaled(
ui->label_image->width(),
ui->label_image->height(),
Qt::KeepAspectRatio
)
);
}
});
t1.join();
t2.join();
}
void MainWindow::on_actionExit_triggered()
{
QApplication::exit(0);
}
void MainWindow::on_actionDeveloper_s_GitHub_triggered()
{
QDesktopServices::openUrl(QUrl("https://github.com/DarkCat09"));
}
void MainWindow::on_actionApplication_triggered()
{
QMessageBox msg(
QMessageBox::Icon::Information,
tr("About this app"),
tr("This application written just for learning\n"
"Qt for Desktop and Mobile.\n"
"by DarkCat09"),
QMessageBox::Ok);
msg.exec();
}

32
mainwindow.h Normal file
View file

@ -0,0 +1,32 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_plainTextEdit_2_textChanged();
void on_pushButton_clicked();
void on_actionExit_triggered();
void on_actionDeveloper_s_GitHub_triggered();
void on_actionApplication_triggered();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

294
mainwindow.ui Normal file
View file

@ -0,0 +1,294 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>624</width>
<height>394</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0">
<widget class="QProgressBar" name="progressBar">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="value">
<number>0</number>
</property>
<property name="format">
<string>Wait: %p%</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Text result</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_greeting">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_birthday">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLCDNumber" name="lcdNumber">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="digitCount">
<number>3</number>
</property>
<property name="segmentStyle">
<enum>QLCDNumber::Flat</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Picture</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_image">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pushButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="3">
<widget class="QCheckBox" name="checkBox_2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>I'm a developer</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPlainTextEdit" name="plainTextEdit_2">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
<property name="placeholderText">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QDateEdit" name="dateEdit_2">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_2">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Birthday:</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>624</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionChoose_a_config"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuOptions">
<property name="title">
<string>Options</string>
</property>
<addaction name="actionRandom_Picture"/>
</widget>
<widget class="QMenu" name="menuAbout">
<property name="title">
<string>About</string>
</property>
<addaction name="actionApplication"/>
<addaction name="actionDeveloper_s_GitHub"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuOptions"/>
<addaction name="menuAbout"/>
</widget>
<action name="actionChoose_a_config">
<property name="text">
<string>Choose a config</string>
</property>
</action>
<action name="actionExit">
<property name="text">
<string>Exit</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionApplication">
<property name="text">
<string>Application</string>
</property>
</action>
<action name="actionDeveloper_s_GitHub">
<property name="text">
<string>Developer's GitHub</string>
</property>
</action>
<action name="actionRandom_Picture">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Random Picture</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

10
pictures.qrc Normal file
View file

@ -0,0 +1,10 @@
<RCC>
<qresource prefix="/prefix">
<file>pics/1.jpg</file>
<file>pics/2.jpg</file>
<file>pics/3.jpg</file>
<file>pics/4.jpg</file>
<file>pics/5.jpg</file>
<file>pics/-1.jpg</file>
</qresource>
</RCC>