zoomableimageoptpanel.cpp 3.43 KB
Newer Older
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
#include <QVBoxLayout>
#include <QPushButton>
#include <QCheckBox>

#include "zoomableimageoptpanel.hpp"
#include "../util/util.hpp"
#include "util.hpp"

namespace cvv
{
namespace qtutil
{

ZoomableOptPanel::ZoomableOptPanel(const ZoomableImage &zoomIm, bool showHideButton, QWidget *parent)
    : QWidget{ parent }
{
	auto basicLayout = cvv::util::make_unique<QVBoxLayout>();

	basicLayout->setContentsMargins(0,0,0,0);

	auto zoomSpin = cvv::util::make_unique<QDoubleSpinBox>();
	auto labelConvert = cvv::util::make_unique<QLabel>();
	auto labelDim = cvv::util::make_unique<QLabel>();
	auto labelType = cvv::util::make_unique<QLabel>();
	auto labelChannel = cvv::util::make_unique<QLabel>();
	auto labelSize = cvv::util::make_unique<QLabel>();
	auto labelDepth = cvv::util::make_unique<QLabel>();
	auto buttonFullImage =
	    cvv::util::make_unique<QPushButton>("show full Image");

	// ConversionResult+ update mat
	connect(&zoomIm, SIGNAL(updateConversionResult(const cv::Mat &,
						       ImageConversionResult)),
		this, SLOT(updateConvertStatus(const cv::Mat &,
					       ImageConversionResult)));

	// getzoom from image
	connect(&zoomIm, SIGNAL(updateArea(QRectF, qreal)), this,
		SLOT(setZoom(QRectF, qreal)));

	// set zoom to image
	connect(zoomSpin.get(), SIGNAL(valueChanged(double)), &zoomIm,
		SLOT(setZoom(qreal)));

	// fullimage
	connect(buttonFullImage.get(), SIGNAL(clicked()), &zoomIm,
		SLOT(showFullImage()));



	zoomSpin->setMinimum(0.0);
	zoomSpin->setMaximum(2000.0);

	zoomSpin_ = zoomSpin.get();
	labelConvert_ = labelConvert.get();
	labelDim_ = labelDim.get();
	labelType_ = labelType.get();
	labelChannel_ = labelChannel.get();
	labelSize_ = labelSize.get();
	labelDepth_ = labelDepth.get();

	basicLayout->addWidget(zoomSpin.release());
	if(showHideButton)
	{
		auto checkboxShowImage= util::make_unique<QCheckBox>("Show image");
		//connect show image
		checkboxShowImage->setChecked(true);
		QObject::connect(checkboxShowImage.get(),SIGNAL(clicked(bool)),
				 &zoomIm,SLOT(setVisible(bool)));
		basicLayout->addWidget(checkboxShowImage.release());
	}
	basicLayout->addWidget(labelConvert.release());
	basicLayout->addWidget(labelSize.release());
	basicLayout->addWidget(labelDim.release());
	basicLayout->addWidget(labelType.release());
	basicLayout->addWidget(labelDepth.release());
	basicLayout->addWidget(labelChannel.release());
	basicLayout->addWidget(buttonFullImage.release());

	setLayout(basicLayout.release());

	updateMat(zoomIm.mat());
	updateConvertStatus(zoomIm.mat(),zoomIm.lastConversionResult());
}

void ZoomableOptPanel::updateConvertStatus(const cv::Mat &mat, ImageConversionResult result)
{
	labelConvert_->setText(
		QString{ "Convert Status: " }.append(conversionResultToString(result)));

	updateMat(mat);
}

void ZoomableOptPanel::updateMat(cv::Mat mat)
{
	if (mat.empty())
	{
		labelDim_->setText("empty");
		labelType_->setText("empty");
		labelChannel_->setText("empty");
		labelSize_->setText("empty");
		labelDepth_->setText("empty");
	}
	else
	{
		labelDim_->setText(QString("Dimension: %1").arg(mat.dims));
		labelChannel_->setText(
		    QString("Number of Channels: %1").arg(mat.channels()));
		labelSize_->setText(
		    QString("Size: %1/%2").arg(mat.rows).arg((mat.cols)));
		labelDepth_->setText(QString("Depth type: %1").arg(mat.depth()));

		auto type=typeToQString(mat);
		labelType_->setText(QString{"Type: "}.append(type.second));
	}
}

void ZoomableOptPanel::setZoom(QRectF, qreal zoomfac)
{
	zoomSpin_->setValue(zoomfac);
}
}
}