mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-03 06:08:39 +00:00
调整窗口显示大小
This commit is contained in:
parent
1defdc66ab
commit
3a390b02fa
1 changed files with 14 additions and 10 deletions
|
@ -44,12 +44,7 @@ VideoForm::VideoForm(QWidget *parent) :
|
||||||
if (success) {
|
if (success) {
|
||||||
// update ui
|
// update ui
|
||||||
setWindowTitle(deviceName);
|
setWindowTitle(deviceName);
|
||||||
updateShowSize(size);
|
updateShowSize(size);
|
||||||
QDesktopWidget* desktop = QApplication::desktop();
|
|
||||||
if (desktop) {
|
|
||||||
QRect mainScreenRc = desktop->availableGeometry();
|
|
||||||
move((mainScreenRc.width() - width())/2, (mainScreenRc.height() - height())/2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// init decode
|
// init decode
|
||||||
m_decoder.setDeviceSocket(m_server->getDeviceSocket());
|
m_decoder.setDeviceSocket(m_server->getDeviceSocket());
|
||||||
|
@ -74,7 +69,7 @@ VideoForm::VideoForm(QWidget *parent) :
|
||||||
QObject::connect(&m_decoder, &Decoder::onNewFrame, this, [this](){
|
QObject::connect(&m_decoder, &Decoder::onNewFrame, this, [this](){
|
||||||
m_frames.lock();
|
m_frames.lock();
|
||||||
const AVFrame *frame = m_frames.consumeRenderedFrame();
|
const AVFrame *frame = m_frames.consumeRenderedFrame();
|
||||||
qDebug() << "widthxheight:" << frame->width << "x" << frame->height;
|
//qDebug() << "widthxheight:" << frame->width << "x" << frame->height;
|
||||||
updateShowSize(QSize(frame->width, frame->height));
|
updateShowSize(QSize(frame->width, frame->height));
|
||||||
ui->videoWidget->setFrameSize(QSize(frame->width, frame->height));
|
ui->videoWidget->setFrameSize(QSize(frame->width, frame->height));
|
||||||
ui->videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2], frame->linesize[0], frame->linesize[1], frame->linesize[2]);
|
ui->videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2], frame->linesize[0], frame->linesize[1], frame->linesize[2]);
|
||||||
|
@ -101,17 +96,26 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
||||||
if (frameSize != newSize) {
|
if (frameSize != newSize) {
|
||||||
frameSize = newSize;
|
frameSize = newSize;
|
||||||
|
|
||||||
|
bool vertical = newSize.height() > newSize.width();
|
||||||
QSize showSize = newSize;
|
QSize showSize = newSize;
|
||||||
QDesktopWidget* desktop = QApplication::desktop();
|
QDesktopWidget* desktop = QApplication::desktop();
|
||||||
if (desktop) {
|
if (desktop) {
|
||||||
QRect screenRect = desktop->availableGeometry();
|
QRect screenRect = desktop->availableGeometry();
|
||||||
showSize.setWidth(qMin(newSize.width(), screenRect.width()));
|
if (vertical) {
|
||||||
showSize.setHeight(qMin(newSize.height(), screenRect.height() - 100));
|
showSize.setHeight(qMin(newSize.height(), screenRect.height()));
|
||||||
|
showSize.setWidth(showSize.height()/2);
|
||||||
|
} else {
|
||||||
|
showSize.setWidth(qMin(newSize.width(), screenRect.width()));
|
||||||
|
showSize.setHeight(showSize.width()/2);
|
||||||
|
}
|
||||||
|
|
||||||
// 窗口居中
|
// 窗口居中
|
||||||
move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center());
|
move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
|
||||||
|
// 减去标题栏高度
|
||||||
|
showSize.setHeight(showSize.height() - titleBarHeight);
|
||||||
if (showSize != size()) {
|
if (showSize != size()) {
|
||||||
resize(showSize);
|
resize(showSize);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue