From 61767661e6209442fea3c7d4556c8ec41e48d72d Mon Sep 17 00:00:00 2001 From: Vargha Csongor Date: Mon, 26 Jun 2023 22:48:45 +0200 Subject: [PATCH] Add QDebug --- src/main.cpp | 104 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 76 insertions(+), 28 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4c49d67..c2dfdca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,11 +19,13 @@ Description: #include #include #include +#include #include #include #include #include #include +#include #include #include #include "tv_denoising.hpp" @@ -89,33 +91,46 @@ int main(int argc, char **argv) // Create the layout QGridLayout *layout = new QGridLayout(&window); - layout->setColumnStretch(1, 1); // Make the second column (sliders) expand // Create the original image label - originalImageLabel = new QLabel("Original Image"); - layout->addWidget(originalImageLabel, 0, 0, 1, 3); // Span 3 columns + QLabel *originalImageLabel = new QLabel("Original Image"); + layout->addWidget(originalImageLabel, 0, 0, 1, 2); // Row 0, spanning 1 row, 2 columns + + // Create the original image display widget + QLabel *originalImageDisplay = new QLabel(); + originalImageDisplay->setAlignment(Qt::AlignCenter); + layout->addWidget(originalImageDisplay, 1, 0, 1, 2); // Row 1, spanning 1 row, 2 columns // Create the result image label - resultImageLabel = new QLabel("Result Image"); - layout->addWidget(resultImageLabel, 1, 0, 1, 3); // Span 3 columns + QLabel *resultImageLabel = new QLabel("Result Image"); + layout->addWidget(resultImageLabel, 0, 2, 1, 2); // Row 0, spanning 1 row, 2 columns + + // Create the result image display widget + QLabel *resultImageDisplay = new QLabel(); + resultImageDisplay->setAlignment(Qt::AlignCenter); + layout->addWidget(resultImageDisplay, 1, 2, 1, 2); // Row 1, spanning 1 row, 2 columns // Create the input image path input field + QHBoxLayout *inputLayout = new QHBoxLayout; QLabel *inputLabel = new QLabel("Input Image:"); - inputImagePathEdit = new QLineEdit; + QLineEdit *inputImagePathEdit = new QLineEdit; QPushButton *inputBrowseButton = new QPushButton("Browse"); QObject::connect(inputBrowseButton, &QPushButton::clicked, openInputImage); - layout->addWidget(inputLabel, 2, 0); - layout->addWidget(inputImagePathEdit, 2, 1); - layout->addWidget(inputBrowseButton, 2, 2); + inputLayout->addWidget(inputLabel); + inputLayout->addWidget(inputImagePathEdit); + inputLayout->addWidget(inputBrowseButton); + layout->addLayout(inputLayout, 2, 0, 1, 4); // Row 2, spanning 1 row, 4 columns // Create the output image path input field + QHBoxLayout *outputLayout = new QHBoxLayout; QLabel *outputLabel = new QLabel("Output Image:"); - outputImagePathEdit = new QLineEdit; + QLineEdit *outputImagePathEdit = new QLineEdit; QPushButton *outputBrowseButton = new QPushButton("Browse"); QObject::connect(outputBrowseButton, &QPushButton::clicked, openOutputImage); - layout->addWidget(outputLabel, 3, 0); - layout->addWidget(outputImagePathEdit, 3, 1); - layout->addWidget(outputBrowseButton, 3, 2); + outputLayout->addWidget(outputLabel); + outputLayout->addWidget(outputImagePathEdit); + outputLayout->addWidget(outputBrowseButton); + layout->addLayout(outputLayout, 3, 0, 1, 4); // Row 3, spanning 1 row, 4 columns // Create the lambda slider QLabel *lambdaLabel = new QLabel("Lambda:"); @@ -123,9 +138,6 @@ int main(int argc, char **argv) lambdaSlider->setObjectName("LambdaSlider"); // Set object name for styling lambdaSlider->setMinimum(0); lambdaSlider->setMaximum(100); - lambdaSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); // Allow horizontal expansion - layout->addWidget(lambdaLabel, 4, 0); - layout->addWidget(lambdaSlider, 4, 1); // Create the iterations slider QLabel *iterationsLabel = new QLabel("Iterations:"); @@ -133,34 +145,70 @@ int main(int argc, char **argv) iterationsSlider->setObjectName("IterationsSlider"); // Set object name for styling iterationsSlider->setMinimum(1); iterationsSlider->setMaximum(100); - iterationsSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); // Allow horizontal expansion - layout->addWidget(iterationsLabel, 5, 0); - layout->addWidget(iterationsSlider, 5, 1); // Create labels to display slider values QLabel *lambdaValueLabel = new QLabel(); QLabel *iterationsValueLabel = new QLabel(); - layout->addWidget(lambdaValueLabel, 4, 2); - layout->addWidget(iterationsValueLabel, 5, 2); // Set stylesheet for dark design QString styleSheet = "QLabel { color: white; }" // Set label text color to white "QSlider::groove:horizontal { background-color: #555555; height: 6px; }" // Set groove color and height "QSlider::handle:horizontal { background-color: #ffffff; width: 10px; margin: -6px 0; }"; // Set handle color and size + lambdaSlider->setStyleSheet(styleSheet); iterationsSlider->setStyleSheet(styleSheet); - // Connect slider value changes to label updates - QObject::connect(lambdaSlider, &QSlider::valueChanged, [=](int value) - { lambdaValueLabel->setText(QString::number(value)); }); - - QObject::connect(iterationsSlider, &QSlider::valueChanged, [=](int value) - { iterationsValueLabel->setText(QString::number(value)); }); + // Set size policies for sliders + lambdaSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + iterationsSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); // Create the denoise button QPushButton *denoiseButton = new QPushButton("Denoise"); QObject::connect(denoiseButton, &QPushButton::clicked, updateDenoisedImage); - layout->addWidget(denoiseButton, 6, 0, 1, 3); // Span 3 columns + + // Add the lambda slider and its label + layout->addWidget(lambdaLabel, 4, 0); // Row 4, column 0 + layout->addWidget(lambdaSlider, 4, 1); // Row 4, column 1 + layout->addWidget(lambdaValueLabel, 5, 0); // Row 5, column 0 + + // Add the iterations slider and its label + layout->addWidget(iterationsLabel, 4, 2); // Row 4, column 2 + layout->addWidget(iterationsSlider, 4, 3); // Row 4, column 3 + layout->addWidget(iterationsValueLabel, 5, 2); // Row 5, column 2 + + // Add the denoise button + layout->addWidget(denoiseButton, 6, 0, 1, 4); // Row 6, spanning 1 row, 4 columns + + QList supportedFormats = QImageReader::supportedImageFormats(); + qDebug() << "Supported image formats:" << supportedFormats; + + // Load and display the input image + QString inputImagePath = inputImagePathEdit->text(); + QImage inputImage(inputImagePath); + if (inputImage.isNull()) + { + qDebug() << "Failed to load input image"; + } + else + { + qDebug() << "Input image loaded successfully"; + } + QPixmap inputPixmap = QPixmap::fromImage(inputImage); + originalImageDisplay->setPixmap(inputPixmap.scaled(originalImageDisplay->size(), Qt::KeepAspectRatio)); + + // Load and display the output image + QString outputImagePath = outputImagePathEdit->text(); + QImage outputImage(outputImagePath); + if (outputImage.isNull()) + { + qDebug() << "Failed to load input image"; + } + else + { + qDebug() << "Input image loaded successfully"; + } + QPixmap outputPixmap = QPixmap::fromImage(outputImage); + resultImageDisplay->setPixmap(outputPixmap.scaled(resultImageDisplay->size(), Qt::KeepAspectRatio)); // Show the main window window.show();