182 lines
5.6 KiB
C++
182 lines
5.6 KiB
C++
#include "ContentWidget.h"
|
|
|
|
#include <QDebug>
|
|
#include <QPixmap>
|
|
#include <QScrollBar>
|
|
#include <QScroller>
|
|
|
|
#include "PageBaseWidget.h"
|
|
#include "MainWindow.h"
|
|
|
|
#include "ui_ContentWidget.h"
|
|
|
|
const QString GetResoucePath() {
|
|
const QString configPath = QApplication::applicationDirPath() + "/resouce/TouchScreen/";
|
|
return configPath;
|
|
}
|
|
|
|
ContentWidget::ContentWidget(MainWindow *parent) :
|
|
PageBaseWidget(parent),
|
|
ui(new Ui::ContentWidget)
|
|
{
|
|
ui->setupUi(this);
|
|
// m_showDisc = new QLabel(this);
|
|
connect(ui->btn_return, &QPushButton::clicked, []() {
|
|
MainWindow::Get().PlayAudio();
|
|
MainWindow::Get().SwitchToPage(PageBaseWidget::PageType::PT_DetailedTown);
|
|
}
|
|
);
|
|
connect(ui->btn_last, &QPushButton::clicked, this, &ContentWidget::ShowLastImage);
|
|
connect(ui->btn_next, &QPushButton::clicked, this, &ContentWidget::ShowNextImage);
|
|
|
|
//ui->textBrowser->setTextInteractionFlags(Qt::NoTextInteraction);
|
|
|
|
ui->btn_last->hide();
|
|
ui->btn_next->hide();
|
|
//ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
// ui->scrollAreaWidgetContents->setHorizontalScrollMode(QListWidget::ScrollPerPixel);
|
|
|
|
// ui->scrollAreaWidgetContents->setVerticalScrollMode(QListWidget::ScrollPerPixel);
|
|
// QScroller::grabGesture();
|
|
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
|
|
QScrollerProperties propertiesOne = QScroller::scroller(ui->scrollArea)->scrollerProperties();
|
|
QVariant overshootPolicyOne = QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff);
|
|
propertiesOne.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, overshootPolicyOne);
|
|
// propertiesOne.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, overshootPolicyOne);
|
|
QScroller::scroller(ui->scrollArea)->setScrollerProperties(propertiesOne);
|
|
|
|
QScroller::grabGesture(ui->lb_content, QScroller::TouchGesture);
|
|
|
|
// ui->textBrowser->setAlignment(Qt::AlignCenter);
|
|
}
|
|
|
|
ContentWidget::~ContentWidget()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void ContentWidget::SetContent(int32_t detailedType, const QString& btnName, const QString& name, const QString& describe, const QStringList& images) {
|
|
ui->lb_title->setText(name);
|
|
// ui->lb_content->setText(describe);
|
|
ui->lb_content->setText(describe);
|
|
const DetailedType dt = static_cast<DetailedType>(detailedType);
|
|
const QString detailTypeName = MainWindow::Get().GetDetailedTypeName(dt);
|
|
//const QString path = QString("%1%2/%3/%4").arg(GetResoucePath(), detailTypeName, btnName).arg(describe);
|
|
//QPixmap pixmap(path);
|
|
//if (!pixmap.isNull()) {
|
|
// QPixmap scaledPixmap = pixmap.scaledToWidth(ui->scrollArea->width());
|
|
// m_showDisc->setPixmap(scaledPixmap);
|
|
// m_showDisc->adjustSize();
|
|
// //m_showDisc->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|
// ui->scrollArea->show();
|
|
// QScrollBar* bar = ui->scrollArea->verticalScrollBar();
|
|
// if (nullptr != bar) {
|
|
// bar->setValue(0);
|
|
// }
|
|
// ui->scrollArea->setWidget(m_showDisc);
|
|
//} else {
|
|
// ui->scrollArea->hide();
|
|
//}
|
|
|
|
MediaInfo mediaInfo;
|
|
if (!MainWindow::Get().GetMediaInfo(detailedType, btnName, mediaInfo)) {
|
|
qDebug() << "not get item: " << detailedType << " or text: " << btnName;
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
if (images.isEmpty()) {
|
|
int32_t btnId = mediaInfo.id;
|
|
const QString cmd = QString("%1|%2|%3").arg(detailedType).arg(btnId).arg(m_current);
|
|
MainWindow::Get().SendCmd(cmd);
|
|
ui->lb_showImage->clear();
|
|
ui->lb_showImage->update();
|
|
ui->btn_last->hide();
|
|
ui->lb_showImage->show();
|
|
ui->btn_next->hide();
|
|
qDebug() << __FUNCTION__ << " image is empty";
|
|
return;
|
|
}
|
|
|
|
m_detailedType = detailedType;
|
|
m_btnName = btnName;
|
|
m_current = 0;
|
|
m_images = images;
|
|
|
|
ShowCurrentImage();
|
|
|
|
/* */
|
|
}
|
|
|
|
void ContentWidget::ShowLastImage() {
|
|
MainWindow::Get().PlayAudio();
|
|
|
|
if (m_current <= 0 ) {
|
|
return;
|
|
}
|
|
|
|
--m_current;
|
|
ShowCurrentImage();
|
|
}
|
|
|
|
void ContentWidget::ShowNextImage() {
|
|
MainWindow::Get().PlayAudio();
|
|
if (m_current >= m_images.count()) {
|
|
return;
|
|
}
|
|
|
|
++m_current;
|
|
ShowCurrentImage();
|
|
}
|
|
|
|
void ContentWidget::ShowCurrentImage() {
|
|
if (m_current < 0 || m_current >= m_images.count()) {
|
|
return;
|
|
}
|
|
|
|
const DetailedType dt = static_cast<DetailedType>(m_detailedType);
|
|
const QString detailTypeName = MainWindow::Get().GetDetailedTypeName(dt);
|
|
|
|
MediaInfo mediaInfo;
|
|
if (!MainWindow::Get().GetMediaInfo(m_detailedType, m_btnName, mediaInfo)) {
|
|
qDebug() << "not get item: " << m_detailedType << " or text: " << m_btnName;
|
|
return;
|
|
}
|
|
|
|
const QString path = QString("%1%2/%3/%4").arg(GetResoucePath(), detailTypeName, m_btnName).arg(m_images[m_current]);
|
|
|
|
int32_t btnId = mediaInfo.id;
|
|
const QString cmd = QString("%1|%2|%3").arg(m_detailedType).arg(btnId).arg(m_current);
|
|
MainWindow::Get().SendCmd(cmd);
|
|
|
|
QPixmap pixmap(path);
|
|
if (pixmap.isNull()) {
|
|
return;
|
|
}
|
|
|
|
const QSize s = ui->lb_showImage->size();
|
|
ui->lb_showImage->setPixmap(pixmap.scaled(s, Qt::KeepAspectRatio));
|
|
/*if (pixmap.width() > ui->lb_showImage->size().width()) {
|
|
ui->lb_showImage->setPixmap(pixmap.scaledToWidth(ui->lb_showImage->size().width()));
|
|
} else {
|
|
ui->lb_showImage->setPixmap(pixmap);
|
|
}*/
|
|
|
|
ui->lb_showImage->setAlignment(Qt::AlignCenter);
|
|
|
|
if (m_current > 0) {
|
|
ui->btn_last->show();
|
|
}
|
|
else {
|
|
ui->btn_last->hide();
|
|
}
|
|
|
|
if (m_current >= m_images.count() - 1) {
|
|
ui->btn_next->hide();
|
|
}
|
|
else {
|
|
ui->btn_next->show();
|
|
}
|
|
}
|