Continues migration with DDS, Common

This commit is contained in:
torsten committed 2026-07-17 12:41:42 +02:00
1 parent 9b15cee841
commit fa48db111e
668 files changed
+111841 -2

No files matched your search

+221
View File
@@ -0,0 +1,221 @@
#include "lts_picture_editing.h"
#include "ui_lts_picture_editing.h"
#include "lts_picture_view.h"
#include <QFileDialog>
#include <QPixmap>
#include <QMessageBox>
#include <QImage>
#include <QGraphicsPixmapItem>
#include <QDebug>
#include <QTimer>
LtsPictureEditing::LtsPictureEditing(QWidget *parent)
: QMainWindow(parent)
, m_gvPicture(nullptr)
, m_ui(new Ui::PictureEditing)
{
m_ui->setupUi(this);
connect(m_ui->actionOpen, &QAction::triggered, this, &LtsPictureEditing::onOpenImage);
connect(m_ui->actionSave, &QAction::triggered, this, &LtsPictureEditing::onSavePicture);
connect(m_ui->actionQuit, &QAction::triggered, this, &LtsPictureEditing::close);
connect(m_ui->pbSetSize, &QPushButton::clicked, this, &LtsPictureEditing::onSetSize);
connect(m_ui->sbHeight, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onRatioChanged);
connect(m_ui->sbWidth, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onRatioChanged);
connect(m_ui->chbRatio, &QPushButton::clicked, this, &LtsPictureEditing::onRatioClicked);
connect(m_ui->sbXMin, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onLeftChanged);
connect(m_ui->sbXMax, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onRightChanged);
connect(m_ui->sbYMin, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onTopChanged);
connect(m_ui->sbYMax, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onBottomChanged);
addViewToFrame();
connect(this, &LtsPictureEditing::leftChanged, m_gvPicture, &LtsWidgets::LtsPictureView::leftChanged);
connect(this, &LtsPictureEditing::rightChanged, m_gvPicture, &LtsWidgets::LtsPictureView::rightChanged);
connect(this, &LtsPictureEditing::topChanged, m_gvPicture, &LtsWidgets::LtsPictureView::topChanged);
connect(this, &LtsPictureEditing::bottomChanged, m_gvPicture, &LtsWidgets::LtsPictureView::bottomChanged);
connect(this, &LtsPictureEditing::setAspectRatio, m_gvPicture, &LtsWidgets::LtsPictureView::setAspectRatio);
connect(this, &LtsPictureEditing::ratioClicked, m_gvPicture, &LtsWidgets::LtsPictureView::ratioClicked);
connect(m_gvPicture, &LtsWidgets::LtsPictureView::mouseMoved, this, &LtsPictureEditing::setSpinboxValues);
connect(m_gvPicture, &LtsWidgets::LtsPictureView::setLimits, this, &LtsPictureEditing::setSpinboxLimits);
connect(this, &LtsPictureEditing::setPicture, m_gvPicture, &LtsWidgets::LtsPictureView::setPicture);
onRatioChanged();
}
LtsPictureEditing::~LtsPictureEditing()
{
delete m_ui;
}
void LtsPictureEditing::addViewToFrame()
{
QHBoxLayout *layout(new QHBoxLayout(m_ui->frPicFrame));
m_gvPicture = new LtsWidgets::LtsPictureView(m_ui->frPicFrame);
layout->addWidget(m_gvPicture);
m_gvPicture->setEnabled(false);
}
void LtsPictureEditing::onOpenImage()
{
const QStringList filter ({
tr("Images (*.jpg *.jpeg *.png)")
});
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"),
QStringLiteral("../picture_editing"),
filter.join(QStringLiteral(";;")));
if (fileName.isEmpty())
return;
QFileInfo fi(fileName);
if (!fi.isReadable())
{
QMessageBox::warning(this, tr("Error!"), tr("An error occurred while loading the file.\n"
"The loaded file is not readable."));
return;
}
QImage pic;
pic.load(fileName);
if (pic.isNull())
{
QMessageBox::warning(this, tr("Error!"), tr("An error occurred while loading the file.\n"
"The loaded file is no picture file.\n"
"Please load *.jpg, *.jpeg, *.png files only."));
return;
}
m_image = pic;
emit setPicture(pic, QPoint(0, 0), true);
m_gvPicture->setEnabled(true);
m_gvPicture->newRubberBand();
}
void LtsPictureEditing::onSetSize()
{
if (m_image.isNull())
return;
m_gvPicture->hideRubberband();
int xMin = m_ui->sbXMin->value() - 1;
int yMin = m_ui->sbYMin->value() - 1;
int xMax = m_ui->sbXMax->value() - 1;
int yMax = m_ui->sbYMax->value() - 1;
if (xMax < xMin || yMax < yMin || xMax == xMin || yMax == yMin)
{
clear();
return;
}
QRect picRect(xMin,
yMin,
xMax - xMin,
yMax - yMin);
QImage newPic = m_image.copy(picRect);
emit setPicture(newPic, QPoint(xMin, yMin), false);
}
void LtsPictureEditing::onSavePicture()
{
if (m_gvPicture->getImage()->pixmap().isNull())
{
QMessageBox::warning(this, tr("Error!"), tr("An error occurred while saving the picture\n"
"Please load a picture before saving it."));
return;
}
else
{
QString filename = QFileDialog::getSaveFileName(this, tr("Open Image"), QLatin1String("../picture_editing"),
tr("Images (*.jpg *.jpeg *.png)"));
if (filename.isEmpty())
{
QMessageBox::warning(this, tr("Error!"), tr("An error occurred while saving the picture.\n"
"Please choose a valid path to save the picture."));
return;
}
m_gvPicture->getImage()->pixmap().save(filename, "PNG");
}
}
void LtsPictureEditing::setSpinboxLimits(const QSize &picSize, bool setValues)
{
m_ui->sbXMin->setMaximum(picSize.width());
m_ui->sbXMax->setMaximum(picSize.width());
m_ui->sbYMin->setMaximum(picSize.height());
m_ui->sbYMax->setMaximum(picSize.height());
if (setValues)
{
m_ui->sbXMin->setValue(0);
m_ui->sbYMin->setValue(0);
m_ui->sbXMax->setValue(picSize.width() - 1);
m_ui->sbYMax->setValue(picSize.height() - 1);
}
}
void LtsPictureEditing::setSpinboxValues(const QRect &picRect)
{
m_ui->sbXMin->setValue(picRect.left());
m_ui->sbYMin->setValue(picRect.top());
m_ui->sbXMax->setValue(picRect.right());
m_ui->sbYMax->setValue(picRect.bottom());
}
void LtsPictureEditing::onRatioChanged()
{
double ratio = double(m_ui->sbWidth->value()) / double(m_ui->sbHeight->value());
emit setAspectRatio(ratio);
}
void LtsPictureEditing::onRatioClicked()
{
if (m_ui->chbRatio->isChecked())
{
m_ui->sbHeight->setEnabled(true);
m_ui->sbWidth->setEnabled(true);
emit ratioClicked(true);
}
else
{
m_ui->sbHeight->setEnabled(false);
m_ui->sbWidth->setEnabled(false);
emit ratioClicked(false);
}
}
void LtsPictureEditing::onLeftChanged(int left)
{
emit leftChanged(left);
}
void LtsPictureEditing::onRightChanged(int right)
{
emit rightChanged(right);
}
void LtsPictureEditing::onTopChanged(int top)
{
emit topChanged(top);
}
void LtsPictureEditing::onBottomChanged(int bottom)
{
emit bottomChanged(bottom);
}
void LtsPictureEditing::clear()
{
emit setPicture(QImage(), QPoint(), false);
}
+60
View File
@@ -0,0 +1,60 @@
#pragma once
#include <QMainWindow>
namespace Ui
{
class PictureEditing;
}
namespace LtsWidgets{
class LtsPictureView;
}
class LtsPictureEditing : public QMainWindow
{
Q_OBJECT
public:
explicit LtsPictureEditing(QWidget *parent = nullptr);
~LtsPictureEditing();
private:
QImage m_grayImage;
QImage m_image;
LtsWidgets::LtsPictureView *m_gvPicture;
Ui::PictureEditing *m_ui;
private:
void setSpinboxLimits(const QSize &picSize, bool setValues = true);
void clear();
void addViewToFrame();
void initRatio();
private slots:
void onOpenImage();
void onSetSize();
void setSpinboxValues(const QRect &picRect);
void onRatioChanged();
void onRatioClicked();
void onSavePicture();
void onLeftChanged(int left);
void onRightChanged(int right);
void onTopChanged(int top);
void onBottomChanged(int bottom);
signals:
void setPicture(const QImage &, const QPoint &, const bool flag);
void setAspectRatio(double ratio);
void ratioClicked(bool enabled);
int leftChanged(int left);
int rightChanged(int right);
int topChanged(int top);
int bottomChanged(int bottom);
};
+363
View File
@@ -0,0 +1,363 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PictureEditing</class>
<widget class="QMainWindow" name="PictureEditing">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>492</width>
<height>364</height>
</rect>
</property>
<property name="windowTitle">
<string>PictureEditing</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="lbxXMin">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>32</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>xMin</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="sbXMin">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="10">
<widget class="QFrame" name="frPicFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbxXMax">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>32</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>xMax</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="sbXMax">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbxYMin">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>32</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>yMin</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="sbYMin">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbxYMax">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>32</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>yMax</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="sbYMax">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="chbRatio">
<property name="text">
<string>aspect ratio</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QSpinBox" name="sbWidth">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>93</width>
<height>33</height>
</size>
</property>
<property name="toolTip">
<string>width</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="value">
<number>1600</number>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QSpinBox" name="sbHeight">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>93</width>
<height>33</height>
</size>
</property>
<property name="toolTip">
<string>height</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="value">
<number>900</number>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QPushButton" name="pbSetSize">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>88</width>
<height>33</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>93</width>
<height>33</height>
</size>
</property>
<property name="text">
<string>Cut Picture</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>492</width>
<height>21</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>Fi&amp;le</string>
</property>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<addaction name="menuFile"/>
</widget>
<action name="actionOpen">
<property name="text">
<string>&amp;Open</string>
</property>
<property name="toolTip">
<string>Open a new image</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="actionQuit">
<property name="text">
<string>&amp;Quit</string>
</property>
<property name="toolTip">
<string>Quit the Application</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionSave">
<property name="text">
<string>&amp;Save</string>
</property>
<property name="toolTip">
<string>Save Picture to PNG</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
+39
View File
@@ -0,0 +1,39 @@
#include "lts_picture_editing.h"
#include <QApplication>
#include <iostream>
static void qtMsgHandler(QtMsgType type, const QMessageLogContext &, const QString &msg)
{
switch (type)
{
case QtDebugMsg:
std::cout << "DEBUG: " << qPrintable(msg) << std::endl;
break;
case QtInfoMsg:
std::cout << "INFO: " << qPrintable(msg) << std::endl;
break;
case QtWarningMsg:
std::cout << "WARN: " << qPrintable(msg) << std::endl;
break;
case QtCriticalMsg:
std::cerr << "ERROR: " << qPrintable(msg) << std::endl;
break;
case QtFatalMsg:
std::cerr << "FATAL: " << qPrintable(msg) << std::endl;
break;
}
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qInstallMessageHandler(&qtMsgHandler);
LtsPictureEditing w;
w.show();
return a.exec();
}
+31
View File
@@ -0,0 +1,31 @@
#include <QApplication>
#include "window.h"
#include <LtsWidgets/lts_date_time_edit.h>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
LtsWidgets::LtsDateTimeEdit dte;
dte.activateWindow();
dte.show();
return app.exec();
}
+59
View File
@@ -0,0 +1,59 @@
#include "window.h"
#include <LtsWidgets/lts_notification_box.h>
#include <QApplication>
#include <QHBoxLayout>
namespace LtsWidgets
{
Window::Window(QWidget *parent)
: QWidget(parent)
{
setGeometry(x(), y(), 300, 300);
QHBoxLayout *lay = new QHBoxLayout;
lay->setMargin(0);
auto x1 = new LtsWidgets::LtsNotificationBox;
lay->addWidget(x1);
if (qApp->arguments().count() < 2)
abort();
LtsNotificationBox::MessageType type;
if (qApp->arguments().at(1) == QStringLiteral("e"))
type = LtsNotificationBox::MessageType::Error;
else if (qApp->arguments().at(1) == QStringLiteral("w"))
type = LtsNotificationBox::MessageType::Warning;
else if (qApp->arguments().at(1) == QStringLiteral("i"))
type = LtsNotificationBox::MessageType::Info;
else if (qApp->arguments().at(1) == QStringLiteral("s"))
type = LtsNotificationBox::MessageType::Success;
else
abort();
x1->message(QStringLiteral("Title Message"), QStringLiteral("A text that consists of a lot of characters and also even has<br />two lines."), type);
connect(x1, &LtsNotificationBox::signalClose, this, &QWidget::close);
setLayout(lay);
setAttribute(Qt::WA_TranslucentBackground);
}
Window::~Window()
{
}
}
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include <QWidget>
namespace LtsWidgets
{
class Window : public QWidget
{
Q_OBJECT
public:
Window(QWidget *parent = nullptr);
~Window();
};
}