From 7b4fef59b3345deb22e4313e0cc80aaf206be7dd Mon Sep 17 00:00:00 2001 From: ruxton Date: Tue, 8 Nov 2022 18:51:15 +0800 Subject: [PATCH] Basic TX panel resize/align --- src/mainwidgets/txwidget.cpp | 28 ++++++++ src/mainwidgets/txwidget.h | 1 + src/mainwidgets/txwidget.ui | 121 ++++++++++++++++++++++++++++++++++- src/widgets/imageviewer.cpp | 76 ++++++++++++++++++++-- src/widgets/imageviewer.h | 2 + 5 files changed, 223 insertions(+), 5 deletions(-) diff --git a/src/mainwidgets/txwidget.cpp b/src/mainwidgets/txwidget.cpp index 309284f..4aa936d 100644 --- a/src/mainwidgets/txwidget.cpp +++ b/src/mainwidgets/txwidget.cpp @@ -44,6 +44,7 @@ txWidget::txWidget(QWidget *parent) : QWidget(parent), ui(new Ui::txWidget) connect(ui->sstvModeComboBox,SIGNAL(activated(int)),SLOT(slotModeChanged(int ))); connect(ui->sstvResizeComboBox,SIGNAL(activated(int)),SLOT(slotResizeChanged(int))); + connect(ui->alignImageButtonGroup,SIGNAL(buttonClicked(QAbstractButton*)),SLOT(slotAlignmentChange(QAbstractButton*))); connect(ui->drmTxBandwidthComboBox,SIGNAL(activated(int)),SLOT(slotGetTXParams())); connect(ui->drmTxInterleaveComboBox,SIGNAL(activated(int)),SLOT(slotGetTXParams())); @@ -636,20 +637,47 @@ void txWidget::slotModeChanged(int m) void txWidget::slotResizeChanged(int i) { + QList buttons = ui->alignImageButtonGroup->buttons(); switch (i) { case 0: // Stretch + for( int s=0; ssetEnabled(false); + } imageViewerPtr->setAspectMode(Qt::IgnoreAspectRatio); break; case 1: // Crop + for( int s=0; ssetEnabled(true); + } imageViewerPtr->setAspectMode(Qt::KeepAspectRatioByExpanding); break; case 2: // Fit + for( int s=0; ssetEnabled(true); + } imageViewerPtr->setAspectMode(Qt::KeepAspectRatio); break; } applyTemplate(); } +void txWidget::slotAlignmentChange(QAbstractButton* button) { + int i = 4; + if (button->objectName() == "alignButtonTopCenter") { + i = 1; + }else if (button->objectName() == "alignButtonCenterLeft") { + i = 3; + }else if (button->objectName() == "alignButtonCenterRight") { + i = 5; + }else if (button->objectName() == "alignButtonBottomCenter") { + i = 7; + } + imageViewerPtr->setImageAlignment(i); + applyTemplate(); +} diff --git a/src/mainwidgets/txwidget.h b/src/mainwidgets/txwidget.h index 73b3980..9096baa 100644 --- a/src/mainwidgets/txwidget.h +++ b/src/mainwidgets/txwidget.h @@ -101,6 +101,7 @@ public slots: void slotModeChanged(int); void slotResizeChanged(int); + void slotAlignmentChange(QAbstractButton*); void slotBinary(); void slotHybridToggled(); void slotNotifyTimeout(); diff --git a/src/mainwidgets/txwidget.ui b/src/mainwidgets/txwidget.ui index 12634b6..1544c09 100644 --- a/src/mainwidgets/txwidget.ui +++ b/src/mainwidgets/txwidget.ui @@ -864,7 +864,7 @@ 20 - 19 + 10 @@ -889,6 +889,122 @@ + + + + Qt::Horizontal + + + + + + + Image Alignment + + + + + + + 0 + + + 1 + + + + + false + + + + 0 + 0 + + + + + + + alignImageButtonGroup + + + + + + + false + + + + 0 + 0 + + + + + + + alignImageButtonGroup + + + + + + + false + + + + 0 + 0 + + + + + + + alignImageButtonGroup + + + + + + + false + + + + 0 + 0 + + + + + + + true + + + alignImageButtonGroup + + + + + + + false + + + + + + alignImageButtonGroup + + + + + @@ -1640,4 +1756,7 @@ + + + diff --git a/src/widgets/imageviewer.cpp b/src/widgets/imageviewer.cpp index b6f4f42..244498a 100644 --- a/src/widgets/imageviewer.cpp +++ b/src/widgets/imageviewer.cpp @@ -900,6 +900,11 @@ void imageViewer::setAspectMode(Qt::AspectRatioMode mode) aspectRatioMode = mode; } +void imageViewer::setImageAlignment(int align) +{ + imageAlignment = align; +} + int imageViewer::applyTemplate() { // qDebug() << "applyTemplate"; @@ -969,10 +974,41 @@ int imageViewer::applyTemplate() Qt::SmoothTransformation ) ); + int locX = (scaledImage.width()-tWidth)/2; + int locY = (scaledImage.height()-tHeight)/2; + switch (imageAlignment) { + case 0: + locX = 0; + locY = 0; + break; + case 2: + locX = (scaledImage.width()-tWidth); + case 1: + locY = 0; + break; + case 3: + locX = 0; + break; + case 5: + locX = (scaledImage.width()-tWidth); + break; + case 6: + locX = 0; + locY = (scaledImage.height()-tHeight); + break; + case 8: + locX = (scaledImage.width()-tWidth); + case 7: + locY = (scaledImage.height()-tHeight); + break; + default: + break; + } + // Crop to intended dimensions at the centre of the image displayedImage = QImage(scaledImage - .copy((scaledImage.width()-tWidth)/2, - (scaledImage.height()-tHeight)/2, + .copy(locX, + locY, tWidth, tHeight ) @@ -1024,10 +1060,42 @@ int imageViewer::applyTemplate() Qt::SmoothTransformation ) ); + + int locX = (scaledImage.width()-tWidth)/2; + int locY = (scaledImage.height()-tHeight)/2; + switch (imageAlignment) { + case 0: + locX = 0; + locY = 0; + break; + case 2: + locX = (scaledImage.width()-tWidth); + case 1: + locY = 0; + break; + case 3: + locX = 0; + break; + case 5: + locX = (scaledImage.width()-tWidth); + break; + case 6: + locX = 0; + locY = (scaledImage.height()-tHeight); + break; + case 8: + locX = (scaledImage.width()-tWidth); + case 7: + locY = (scaledImage.height()-tHeight); + break; + default: + break; + } + scaledImage=scaledImage.convertToFormat(QImage::Format_ARGB32); overlayedImage= QImage(scaledImage - .copy((scaledImage.width()-tWidth)/2, - (scaledImage.height()-tHeight)/2, + .copy(locX, + locY, tWidth, tHeight ) diff --git a/src/widgets/imageviewer.h b/src/widgets/imageviewer.h index 3da1728..b9aa9da 100644 --- a/src/widgets/imageviewer.h +++ b/src/widgets/imageviewer.h @@ -90,6 +90,7 @@ class imageViewer : public QLabel // int calcSize(int &sizeRatio); uint setSize(int tcommpressSize,bool usesCompression); void setAspectMode(Qt::AspectRatioMode mode); + void setImageAlignment(int align); int getFileSize(){return fileSize;} QString toCall; QString toOperator; @@ -169,6 +170,7 @@ private slots: bool useCompression; QString templateFileName; Qt::AspectRatioMode aspectRatioMode; + int imageAlignment; bool useTemplate; int targetWidth; int targetHeight;