Files
qt5-legatus-legacy/Lts/Plugins/FileManagement/Gui/Explorer/flm_preview_playback.cpp
T
2026-08-13 18:33:10 +02:00

271 lines
8.7 KiB
C++
Executable File

/**
* @RDE_HEADER@
* The FileContentPreviewPlaybackWidget offers an UI to preview a FileContent
* $Id$
* $HeadURL$
* $Author$
* Created by Iuliana Ojog, SLSE, 2017-06-02
*/
#include "flm_preview_playback.h"
#include "ui_flm_preview_playback.h"
#include <LtsUtilsCore/dds_vector_to_pixmap.h>
#include <LtsUtilsCore/dds_vector.h>
#include <LtsWidgets/lts_message_dialog.h>
#include <nglwidgets/nglpdfwidget.h>
namespace FileManagement
{
static Poppler::Page::Rotation getRotationFromValue(int rotation);
//------------------------------------------------------------------------------------
FileContentPreviewPlaybackWidget::FileContentPreviewPlaybackWidget(const std::shared_ptr<Interface::Ftc> &ftc, QWidget *parent)
: QWidget(parent)
, m_ui(new Ui::FileContentPreviewPlaybackWidget)
, m_getContent(new FileManagement::GetFileContent(ftc, this))
, m_closeTimer(new QTimer(this))
, m_logger(getLogger("FileContentPreviewPlaybackWidget"))
{
m_ui->setupUi(this);
m_ui->lblPixmap->setVisible(false);
m_ui->teText->setVisible(false);
// setup pdf widget
m_pdfWidget = new NGL::PDFWidget(this);
m_pdfWidget->setObjectName(QStringLiteral("pdfWidget"));
m_pdfWidget->setSizePolicy(QSizePolicy::Policy::MinimumExpanding, QSizePolicy::Policy::MinimumExpanding);
connect(m_pdfWidget, &NGL::PDFWidget::currentPageChanged, this, &FileContentPreviewPlaybackWidget::setPage);
connect(m_pdfWidget, &NGL::PDFWidget::rotationChanged, this, [this](Poppler::Page::Rotation rot)
{
switch (rot)
{
case Poppler::Page::Rotate90:
setRotation(90);
break;
case Poppler::Page::Rotate180:
setRotation(180);
break;
case Poppler::Page::Rotate270:
setRotation(270);
break;
case Poppler::Page::Rotate0:
setRotation(0);
break;
}
});
m_ui->horizontalLayout->addWidget(m_pdfWidget);
}
//------------------------------------------------------------------------------------
FileContentPreviewPlaybackWidget::~FileContentPreviewPlaybackWidget()
{
delete m_getContent;
delete m_ui;
}
//------------------------------------------------------------------------------------
bool FileContentPreviewPlaybackWidget::init(const FileContent &data, int pageNo,
double zoomFactor, int rotation,
int duration, const QString &userText)
{
m_data = data;
m_duration = (duration > 0) ? duration : 0;
m_pageNo = pageNo;
m_zoomFactor = (zoomFactor >= ZOOM_MIN && zoomFactor <= ZOOM_MAX) ? zoomFactor : ZOOM_DEFAULT;
m_rotation = rotation;
m_userText = userText;
DEBUG_LOG(m_logger) << "FileContentPreviewPlaybackWidget::init - (fileId, pageNo, zoomFactor, rotation) = ("
<< m_data.id() << "," << m_pageNo << "," << m_zoomFactor << ", " << m_rotation << ")";
if (m_userText.isEmpty() && m_data.id() > 0)
m_getContent->getContent(m_data.id(), m_content);
DEBUG_LOG(m_logger) << "Content size: " << m_content.size() << ", " << m_pageNo;
if (m_duration > 0)
startTimer();
m_ui->lblPixmap->setVisible(false);
m_ui->teText->setVisible(false);
m_pdfWidget->setVisible(false);
switch (data.fileType().underlying())
{
case FileManagement::FileType_def::Png:
case FileManagement::FileType_def::Jpg:
{
m_ui->lblPixmap->setPixmap(LtsUtils::getPixmap(m_content));
m_ui->lblPixmap->setVisible(true);
break;
}
case FileManagement::FileType_def::Text:
{
if (!m_userText.isEmpty() && m_data.id() == 0)
{
m_ui->teText->setHtml(m_userText);
m_ui->teText->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_ui->teText->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_ui->teText->setVisible(true);
}
break;
}
case FileManagement::FileType_def::Xml:
case FileManagement::FileType_def::TacticalPlan:
case FileManagement::FileType_def::OperatorFavourite:
case FileManagement::FileType_def::EvaluationSchema:
{
m_ui->teText->setHtml(QString::fromUtf8(LtsUtils::toQByteArray(m_content)));
m_ui->teText->setVisible(true);
break;
}
case FileManagement::FileType_def::Pdf:
{
m_pdfWidget->setVisible(true);
m_pdfWidget->setZoomFactor(m_zoomFactor);
m_pdfWidget->setPage(m_pageNo); // before setRotation since there currentPageChanged is emitted
m_pdfWidget->setRotation(getRotationFromValue(rotation));
m_pdfWidget->showPDF(LtsUtils::toQByteArray(m_content));
break;
}
case FileManagement::FileType_def::OperatorDefinedSymbol:
case FileManagement::FileType_def::MSOfficeDocument:
case FileManagement::FileType_def::MSOfficeDocument97:
case FileManagement::FileType_def::MSOfficePresentation:
case FileManagement::FileType_def::MSOfficePresentation97:
case FileManagement::FileType_def::MSOfficeSpreadsheet:
case FileManagement::FileType_def::MSOfficeSpreadsheet97:
case FileManagement::FileType_def::OpenOfficeDocument:
case FileManagement::FileType_def::OpenOfficePresentation:
case FileManagement::FileType_def::OpenOfficeSpreadsheet:
{
new LtsWidgets::LtsMessageDialogNew(this, tr("Not yet implemented"));
close();
break;
}
case FileManagement::FileType_def::Unknown:
default:
{
if (!m_userText.isEmpty() && m_data.id() == 0)
{
m_ui->teText->setHtml(m_userText);
m_ui->teText->setVisible(true);
}
else
{
new LtsWidgets::LtsMessageDialogNew(this, tr("Unknown file type! Playback not available."));
close();
}
break;
}
}
return true;
}
//-----------------------------------------------------------------------------------------------------------
bool FileContentPreviewPlaybackWidget::pauseTimer()
{
m_closeTimer.stop();
DEBUG_LOG(m_logger) << "Timer stopped ";
return true;
}
//-----------------------------------------------------------------------------------------------------------
bool FileContentPreviewPlaybackWidget::startTimer()
{
m_closeTimer.setInterval(m_duration * 1000); // duration is in secs, timer interval in msecs
connect(&m_closeTimer, &QTimer::timeout, this, &FileContentPreviewPlaybackWidget::close);
m_closeTimer.start();
DEBUG_LOG(m_logger) << "Timer started interval = " << m_closeTimer.interval();
return true;
}
//-----------------------------------------------------------------------------------------------------------
int FileContentPreviewPlaybackWidget::getNumPages() const
{
return m_pdfWidget->numPages();
}
//-----------------------------------------------------------------------------------------------------------
int FileContentPreviewPlaybackWidget::getCurPage() const
{
return m_pdfWidget->curPage();
}
//-----------------------------------------------------------------------------------------------------------
void FileContentPreviewPlaybackWidget::setPage(int pageNo)
{
if (m_pageNo == pageNo)
return;
DEBUG_LOG(m_logger) << "setPage = " << pageNo;
m_pageNo = pageNo;
m_pdfWidget->setPage(pageNo);
emit currentPageChanged(m_pageNo);
}
//-----------------------------------------------------------------------------------------------------------
void FileContentPreviewPlaybackWidget::setZoomFactor(double zoomFactor)
{
if (qFuzzyCompare(m_zoomFactor, zoomFactor))
return;
DEBUG_LOG(m_logger) << "setZoomFactor = " << zoomFactor;
m_zoomFactor = zoomFactor;
m_pdfWidget->setZoomFactor(zoomFactor);
}
//-----------------------------------------------------------------------------------------------------------
void FileContentPreviewPlaybackWidget::setRotation(int rotation)
{
if (m_rotation == rotation)
return;
DEBUG_LOG(m_logger) << "setRotation = " << rotation;
m_rotation = rotation;
m_pdfWidget->setRotation(getRotationFromValue(m_rotation));
emit rotationChanged(rotation);
}
//-----------------------------------------------------------------------------------------------------------
void FileContentPreviewPlaybackWidget::ensureDataIsSet()
{
if (m_pdfWidget->isVisible() && m_pageNo > 0)
{
m_pdfWidget->setZoomFactor(m_zoomFactor);
m_pdfWidget->setRotation(getRotationFromValue(m_rotation));
m_pdfWidget->setPage(m_pageNo);
}
}
//-----------------------------------------------------------------------------------------------------------
void FileContentPreviewPlaybackWidget::showEvent(QShowEvent *e)
{
QWidget::showEvent(e);
ensureDataIsSet();
}
//-----------------------------------------------------------------------------------------------------------
Poppler::Page::Rotation getRotationFromValue(int rotation)
{
Poppler::Page::Rotation rot;
switch (rotation)
{
case 90:
rot = Poppler::Page::Rotate90;
break;
case 180:
rot = Poppler::Page::Rotate180;
break;
case 270:
rot = Poppler::Page::Rotate270;
break;
case 0:
default:
rot = Poppler::Page::Rotate0;
break;
}
return rot;
}
} // namespace FileManagement