@@ -56,48 +56,16 @@ QString DeviceMonitor::parseMonitorSize(const QString &sizeDescription, double &
5656 // 根据不同的正则表达式解析屏幕大小字符串
5757 QString res = sizeDescription;
5858
59- #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
60- QRegExp re (" ^([\\ d]*)x([\\ d]*) mm$" );
61- if (re.exactMatch (sizeDescription)) {
62- qCDebug (appLog) << " Matched size description with format: ^([\\ d]*)x([\\ d]*) mm$" ;
63- // 获取屏幕宽高 int
64- m_Width = re.cap (1 ).toInt ();
65- m_Height = re.cap (2 ).toInt ();
66- retSize = QSize (m_Width, m_Height);
67-
68- // 获取屏幕尺寸大小 inch
69- double width = m_Width / 2.54 ;
70- double height = m_Height / 2.54 ;
71- inch = std::sqrt (width * width + height * height) / 10.0 ;
72- res = QString::number (inch, 10 , 1 ) + " " + translateStr (" inch" ) + " (" ;
73- res += sizeDescription;
74- res += " )" ;
75- }
76-
77- re.setPattern (" ([0-9]\\ d*)mm x ([0-9]\\ d*)mm" );
78- if (re.exactMatch (sizeDescription)) {
79- qCDebug (appLog) << " Matched size description with format: ([0-9]\\ d*)mm x ([0-9]\\ d*)mm" ;
80- // 获取屏幕宽高 int
81- m_Width = re.cap (1 ).toInt ();
82- m_Height = re.cap (2 ).toInt ();
83- retSize = QSize (m_Width, m_Height);
84-
85- double width = m_Width / 2.54 ;
86- double height = m_Height / 2.54 ;
87- inch = std::sqrt (width * width + height * height) / 10.0 ;
88- res = QString::number (inch, 10 , 1 ) + " " + translateStr (" inch" ) + " (" ;
89- res += sizeDescription;
90- res += " )" ;
91- }
92- #else
9359 QRegularExpression re (" ^([\\ d]*)x([\\ d]*) mm$" );
9460 QRegularExpressionMatch match = re.match (sizeDescription);
9561 if (match.hasMatch ()) {
9662 qCDebug (appLog) << " Matched size description with format: ^([\\ d]*)x([\\ d]*) mm$" ;
63+ // 获取屏幕宽高 int
9764 m_Width = match.captured (1 ).toInt ();
9865 m_Height = match.captured (2 ).toInt ();
9966 retSize = QSize (m_Width, m_Height);
10067
68+ // 获取屏幕尺寸大小 inch
10169 double width = m_Width / 2.54 ;
10270 double height = m_Height / 2.54 ;
10371 inch = std::sqrt (width * width + height * height) / 10.0 ;
@@ -110,6 +78,7 @@ QString DeviceMonitor::parseMonitorSize(const QString &sizeDescription, double &
11078 match = re.match (sizeDescription);
11179 if (match.hasMatch ()) {
11280 qCDebug (appLog) << " Matched size description with format: ([0-9]\\ d*)mm x ([0-9]\\ d*)mm" ;
81+ // 获取屏幕宽高 int
11382 m_Width = match.captured (1 ).toInt ();
11483 m_Height = match.captured (2 ).toInt ();
11584 retSize = QSize (m_Width, m_Height);
@@ -121,7 +90,6 @@ QString DeviceMonitor::parseMonitorSize(const QString &sizeDescription, double &
12190 res += sizeDescription;
12291 res += " )" ;
12392 }
124- #endif
12593
12694 qCDebug (appLog) << " Finished parsing monitor size. Result:" << res;
12795 return res;
@@ -164,11 +132,7 @@ void DeviceMonitor::setInfoFromHwinfo(const QMap<QString, QString> &mapInfo)
164132 caculateScreenRatio ();
165133
166134 if (Common::isHwPlatform ()){
167- #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
168- m_SupportResolution.replace (QRegExp (" , $" ), " " );
169- #else
170135 m_SupportResolution.replace (QRegularExpression (" , $" ), " " );
171- #endif
172136 }
173137 qCDebug (appLog) << " Supported resolutions processed:" << m_SupportResolution;
174138
@@ -288,7 +252,7 @@ bool DeviceMonitor::setInfoFromXradr(const QString &main, const QString &edid, c
288252 // 设置当前分辨率
289253 if (m_CurrentResolution.isEmpty ()) {
290254 qCDebug (appLog) << " Current resolution is empty, extracting from main string" ;
291- QRegularExpression reScreenSize (" .*([0-9]{1,5}x[0-9]{1,5}).*" );
255+ QRegularExpression reScreenSize (" .*connected.* \\ s ([0-9]{1,5}x[0-9]{1,5})\\ + .*" );
292256 QRegularExpressionMatch match = reScreenSize.match (main);
293257 if (match.hasMatch ()) {
294258 qCDebug (appLog) << " Matched screen size from main string:" << match.captured (1 );
@@ -320,11 +284,7 @@ bool DeviceMonitor::setInfoFromXradr(const QString &main, const QString &edid, c
320284 m_SupportResolution.append (" , " );
321285 }
322286 }
323- #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
324- m_SupportResolution.remove (QRegExp (" , $" ));
325- #else
326287 m_SupportResolution.remove (QRegularExpression (" , $" ));
327- #endif
328288 }
329289 }
330290 qCDebug (appLog) << " Interface already processed, returning false" ;
@@ -494,7 +454,7 @@ bool DeviceMonitor::setMainInfoFromXrandr(const QString &info, const QString &ra
494454 }
495455
496456 // 设置当前分辨率
497- QRegularExpression reScreenSize (" .*([0-9]{1,5}x[0-9]{1,5}).*" );
457+ QRegularExpression reScreenSize (" .*connected.* \\ s ([0-9]{1,5}x[0-9]{1,5})\\ + .*" );
498458 match = reScreenSize.match (info);
499459 if (match.hasMatch ()) {
500460 qCDebug (appLog) << " Found screen size in xrandr info:" << match.captured (1 );
@@ -516,9 +476,9 @@ bool DeviceMonitor::setMainInfoFromXrandr(const QString &info, const QString &ra
516476 m_RefreshRate = QString (" %1" ).arg (curRate);
517477 }
518478 if (Common::specialComType == 5 || Common::specialComType == 6 ) {
519- m_CurrentResolution = QString (" %1" ).arg (QT_REGEXP_CAPTURE (reScreenSize, 1 , info )).replace (" x" , " ×" , Qt::CaseInsensitive);
479+ m_CurrentResolution = QString (" %1" ).arg (match. captured ( 1 )).replace (" x" , " ×" , Qt::CaseInsensitive);
520480 } else {
521- m_CurrentResolution = QString (" %1 @%2" ).arg (QT_REGEXP_CAPTURE (reScreenSize, 1 , info )).arg (curRate).replace (" x" , " ×" , Qt::CaseInsensitive);
481+ m_CurrentResolution = QString (" %1 @%2" ).arg (match. captured ( 1 )).arg (curRate).replace (" x" , " ×" , Qt::CaseInsensitive);
522482 }
523483 } else {
524484 qCDebug (appLog) << " Rate is empty, setting current resolution without rate" ;
0 commit comments