culturered_client/PhotoVideoPlayer/PhotoDisplay.cpp

42 lines
1.0 KiB
C++
Raw Normal View History

2024-09-07 03:34:44 +00:00
#include "PhotoDisplay.h"
#include <QPixmap>
#include <QGridLayout>
#include "MainWindow.h"
#include "ui_PhotoDisplay.h"
PhotoDisplay::PhotoDisplay(QWidget* parent) : QWidget(parent)
, ui(new Ui::PhotoDisplay) {
ui->setupUi(this);
setWindowFlags( Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_TranslucentBackground);
ui->label->setAlignment(Qt::AlignCenter);
}
void PhotoDisplay::ShowPhoto(const QString& path) {
qDebug() << __FUNCTION__ << path;
m_pixmap.load(path);
QPixmap showPixmap = m_pixmap.scaled(size(), Qt::KeepAspectRatio);
ui->label->setPixmap(showPixmap);
show();
}
void PhotoDisplay::MoveCenter() {
const QSize& size = MainWindow::Get().size();
move((size.width() - width()) / 2, (size.height() - height()) / 2);
}
void PhotoDisplay::resizeEvent(QResizeEvent* event) {
if (!m_pixmap.isNull()) {
QPixmap showPixmap = m_pixmap.scaledToWidth(size().width() , Qt::SmoothTransformation);
ui->label->setPixmap(showPixmap);
}
}