136 lines
3.9 KiB
C++
136 lines
3.9 KiB
C++
|
#include "DisplayWidget.h"
|
||
|
|
||
|
#include <QApplication>
|
||
|
#include <QPalette>
|
||
|
#include <QImageReader>
|
||
|
#include <QPainter>
|
||
|
#include <QResizeEvent>
|
||
|
#include <QScreen>
|
||
|
|
||
|
#include "PaperWidget.h"
|
||
|
|
||
|
#include "ui_DisplayWidget.h"
|
||
|
|
||
|
DisplayWidget::DisplayWidget(const Widget& widget, QWidget *parent) :
|
||
|
QWidget(parent),
|
||
|
ui(new Ui::DisplayWidget),
|
||
|
m_widget(widget)
|
||
|
{
|
||
|
ui->setupUi(this);
|
||
|
setWindowFlags(Qt::FramelessWindowHint);
|
||
|
|
||
|
// resize(widget.width, widget.height);
|
||
|
|
||
|
setAutoFillBackground(true);
|
||
|
const QString pxPath = QApplication::applicationDirPath() + "/PhotoDisplay/" + m_widget.bg;
|
||
|
int m1 = QImageReader::allocationLimit();
|
||
|
QImageReader::setAllocationLimit(250);
|
||
|
int m2 = QImageReader::allocationLimit();
|
||
|
m_bg.load(pxPath);
|
||
|
/*QPixmap px(pxPath);
|
||
|
QPalette pal = palette();
|
||
|
pal.setBrush(QPalette::Window, QBrush(px.scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
|
||
|
setPalette(pal);*/
|
||
|
|
||
|
m_paperWidget = new PaperWidget(this);
|
||
|
m_paperWidget->resize(widget.width, widget.height);
|
||
|
|
||
|
m_animation = new QPropertyAnimation(m_paperWidget, "pos", this);
|
||
|
m_animation->setDuration(m_widget.duration * 1000);
|
||
|
|
||
|
m_animation->setEasingCurve(QEasingCurve::InOutQuad);
|
||
|
|
||
|
|
||
|
|
||
|
// SetPaper("D:/Project/culturered/culturered/Client/PhotoPrintServer/static/uploads/1.jpg", "test");
|
||
|
QRect rect(widget.x, widget.y, widget.width, widget.height);
|
||
|
QScreen* sc = QApplication::screenAt(rect.center());
|
||
|
connect(screen(), &QScreen::availableGeometryChanged, this, &DisplayWidget::OnGeometryChanged);
|
||
|
|
||
|
}
|
||
|
|
||
|
DisplayWidget::~DisplayWidget()
|
||
|
{
|
||
|
delete ui;
|
||
|
}
|
||
|
|
||
|
void DisplayWidget::SizeChange() {
|
||
|
QPoint start;
|
||
|
if (0 == m_widget.anim) {
|
||
|
start = QPoint(-width(), 0);
|
||
|
} else if (1 == m_widget.anim) {
|
||
|
start = QPoint(width(), 0);
|
||
|
} else if (2 == m_widget.anim) {
|
||
|
start = QPoint(0, -height());
|
||
|
} else {
|
||
|
start = QPoint(0, height());
|
||
|
}
|
||
|
m_paperWidget->move(start);
|
||
|
m_paperWidget->hide();
|
||
|
|
||
|
// SetPaper("D:/Project/culturered/culturered/Client/PhotoPrintServer/static/uploads/1.jpg", "test");
|
||
|
QRect rect(widget.x, widget.y, widget.width, widget.height);
|
||
|
QScreen* sc = QApplication::screenAt(rect.center());
|
||
|
connect(screen(), &QScreen::availableGeometryChanged, this, &DisplayWidget::OnGeometryChanged);
|
||
|
|
||
|
}
|
||
|
|
||
|
DisplayWidget::~DisplayWidget()
|
||
|
{
|
||
|
delete ui;
|
||
|
}
|
||
|
|
||
|
void DisplayWidget::SetPaper(const QString& path, const QString& url, const QString& tag) {
|
||
|
qDebug() << __FUNCTION__ << "tag:" << tag << " widget tag:" << m_widget.tag;
|
||
|
if (tag != m_widget.tag) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
QPoint start, end;
|
||
|
if (0 == m_widget.anim) {
|
||
|
start = QPoint(-width(), 0);
|
||
|
end = QPoint(0, 0);
|
||
|
} else if (1 == m_widget.anim) {
|
||
|
start = QPoint(width(), 0);
|
||
|
end = QPoint(0, 0);
|
||
|
} else if (2 == m_widget.anim) {
|
||
|
start = QPoint(0, -height());
|
||
|
end = QPoint(0, 0);
|
||
|
} else {
|
||
|
start = QPoint(0, height());
|
||
|
end = QPoint(0, 0);
|
||
|
}
|
||
|
|
||
|
qDebug() << __FUNCTION__ << "start:" << start << " end:" << end;
|
||
|
m_animation->setStartValue(start); // 起始位置
|
||
|
m_animation->setEndValue(end); // 结束位置
|
||
|
m_animation->stop();
|
||
|
m_animation->start();
|
||
|
m_paperWidget->SetBackground(path, url);
|
||
|
m_paperWidget->show();
|
||
|
|
||
|
}
|
||
|
|
||
|
void DisplayWidget::paintEvent(QPaintEvent* e) {
|
||
|
QWidget::paintEvent(e);
|
||
|
//if (m_bg.isNull()) {
|
||
|
// return;
|
||
|
//}
|
||
|
|
||
|
QPainter painter(this);
|
||
|
|
||
|
const QRect rt = rect();
|
||
|
qDebug() << rt << " " << m_widget.tag;
|
||
|
painter.drawImage(rt, m_bg, m_bg.rect());
|
||
|
}
|
||
|
|
||
|
void DisplayWidget::resizeEvent(QResizeEvent* event) {
|
||
|
m_paperWidget->setFixedSize(event->size());
|
||
|
}
|
||
|
|
||
|
void DisplayWidget::OnGeometryChanged(const QRect& geometry) {
|
||
|
qDebug() << __FUNCTION__ << geometry << "screen name:" << reinterpret_cast<QScreen*>(sender())->name();
|
||
|
emit ScreenGeometryChanged();
|
||
|
//resize(geometry.width(), geometry.height());
|
||
|
}
|