|
|
@@ -6,6 +6,7 @@
|
|
|
#include "buttonclickthread.h"
|
|
|
#include <QPainter>
|
|
|
#include "pdu_ctrl.h"
|
|
|
+#include <QResizeEvent>
|
|
|
|
|
|
Widget::Widget(QWidget *parent) :
|
|
|
QWidget(parent),
|
|
|
@@ -46,6 +47,8 @@ Widget::Widget(QWidget *parent) :
|
|
|
//ui->stackedWidget_Main->setCurrentWidget(ui->page_7);
|
|
|
m_pMSGWidget=new MSGWidget(this);
|
|
|
m_pMSGWidget->hide();
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
Widget::~Widget()
|
|
|
@@ -443,10 +446,11 @@ void Widget::ShowMSGWidget(QString strShowData)
|
|
|
if(m_pMSGWidget&&m_pMSGWidget->isHidden())
|
|
|
{
|
|
|
m_pMSGWidget->SetText(strShowData);
|
|
|
- QRect parentRect = this->geometry();
|
|
|
- m_pMSGWidget->setFixedWidth(parentRect.width()-4);
|
|
|
- m_pMSGWidget->move(parentRect.center() - m_pMSGWidget->rect().center());
|
|
|
- m_pMSGWidget->show();
|
|
|
+ adjustMSGWidgetPosition(false);
|
|
|
+ if (m_pMSGWidget->isHidden()) {
|
|
|
+ m_pMSGWidget->show();
|
|
|
+ }
|
|
|
+
|
|
|
qDebug()<<"MSGWidget_Show geometry("<<m_pMSGWidget->geometry().x()<<","<<m_pMSGWidget->geometry().y()<<","<<m_pMSGWidget->geometry().width()<<","<<m_pMSGWidget->geometry().height()<<")";
|
|
|
}
|
|
|
}
|
|
|
@@ -459,3 +463,108 @@ void Widget::ClickMSGBtn()
|
|
|
emit signal_ClickMSG();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+void Widget::adjustMSGWidgetPosition(bool isAuto)
|
|
|
+{
|
|
|
+ if(isAuto)
|
|
|
+ {
|
|
|
+ if(!(m_pMSGWidget&&!m_pMSGWidget->isHidden()))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 获取主窗口的逻辑尺寸
|
|
|
+ QRect mainWindowSize = this->geometry();
|
|
|
+ int mainWidth = mainWindowSize.width();
|
|
|
+ int mainHeight = mainWindowSize.height();
|
|
|
+ qDebug()<<"Widget geometry("<<mainWindowSize.x()<<","<<mainWindowSize.y()<<","<<mainWindowSize.width()<<","<<mainWindowSize.height()<<")";
|
|
|
+ // 根据旋转角度确定实际显示尺寸
|
|
|
+ int displayWidth, displayHeight;
|
|
|
+ //if(m_nAngle == 90 || m_nAngle == 270) {
|
|
|
+ displayWidth = mainWidth;
|
|
|
+ displayHeight = mainHeight;
|
|
|
+ //} else {
|
|
|
+ // 90或270度旋转时,宽高交换
|
|
|
+ // displayWidth = mainHeight;
|
|
|
+ // displayHeight = mainWidth;
|
|
|
+ //}
|
|
|
+ // 设置弹窗宽度(略小于显示宽度)
|
|
|
+ m_pMSGWidget->setFW(displayWidth - 4);
|
|
|
+
|
|
|
+ // 根据旋转角度计算弹窗位置
|
|
|
+ QPoint popupPos;
|
|
|
+ int offset=5;
|
|
|
+ if(m_nAngle==0||m_nAngle==180)
|
|
|
+ {
|
|
|
+ if(m_nAngle==0)
|
|
|
+ {
|
|
|
+ popupPos = QPoint(offset,(displayHeight - m_pMSGWidget->height()) / 2);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ popupPos = QPoint(offset,-(displayHeight - m_pMSGWidget->height()) / 2);
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ if(m_nAngle==90)
|
|
|
+ {
|
|
|
+ popupPos = QPoint(-(displayHeight - m_pMSGWidget->height()) / 2,offset);
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ //popupPos = QPoint(2,-(displayHeight - m_pMSGWidget->height()) / 2);
|
|
|
+ popupPos = QPoint((displayHeight - m_pMSGWidget->height()) / 2,offset);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ popupPos += QPoint(mainWindowSize.x(), mainWindowSize.y());
|
|
|
+ /*
|
|
|
+ switch(m_nAngle) {
|
|
|
+ case 0: // 0度旋转
|
|
|
+ popupPos = QPoint(
|
|
|
+ 2,
|
|
|
+ (displayHeight - m_pMSGWidget->height()) / 2
|
|
|
+ );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 90: // 90度旋转
|
|
|
+ popupPos = QPoint(
|
|
|
+ 2,
|
|
|
+ (displayHeight - m_pMSGWidget->height()) / 2
|
|
|
+ );
|
|
|
+ // 调整坐标系偏移
|
|
|
+ popupPos += QPoint(mainWidth, 0);
|
|
|
+ break;
|
|
|
+ case 180: // 180度旋转
|
|
|
+ popupPos = QPoint(
|
|
|
+ 2,
|
|
|
+ (displayHeight - m_pMSGWidget->height()) / 2
|
|
|
+ );
|
|
|
+ // 调整坐标系偏移
|
|
|
+ popupPos += QPoint(mainWidth, mainHeight);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 270: // 270度旋转
|
|
|
+ popupPos = QPoint(
|
|
|
+ 2,
|
|
|
+ (displayHeight - m_pMSGWidget->height()) / 2
|
|
|
+ );
|
|
|
+ // 调整坐标系偏移
|
|
|
+ popupPos += QPoint(0, mainHeight);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+ // 应用位置
|
|
|
+ m_pMSGWidget->move(popupPos);
|
|
|
+ // 调试输出
|
|
|
+ qDebug() << "Rotation:" << m_nAngle;
|
|
|
+ qDebug() << "MSGWidget position:" << popupPos;
|
|
|
+ qDebug() << "MSGWidget geometry:" << m_pMSGWidget->geometry();
|
|
|
+}
|
|
|
+
|
|
|
+void Widget::resizeEvent(QResizeEvent *event)
|
|
|
+{
|
|
|
+ if(m_pMSGWidget&&!m_pMSGWidget->isHidden())
|
|
|
+ {
|
|
|
+ adjustMSGWidgetPosition();
|
|
|
+ }
|
|
|
+}
|