From 8468d6df5794ede71a39905e2d31f4cadda244b7 Mon Sep 17 00:00:00 2001
From: luoqing <luoqing@kylinsec.com.cn>
Date: Wed, 23 Aug 2023 11:11:09 +0800
Subject: [PATCH 2/5] feature(display):When switching resolutions, refresh rate
 preferentially selects the recommended refresh rate
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 切换分辨率时，刷新率优先选择推荐的刷新率

Related #13283
---
 plugins/display/src/display-page.cpp | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/plugins/display/src/display-page.cpp b/plugins/display/src/display-page.cpp
index a885b8b..23b5e8e 100644
--- a/plugins/display/src/display-page.cpp
+++ b/plugins/display/src/display-page.cpp
@@ -263,22 +263,35 @@ void DisplayPage::initExtraComboBoxRefreshRate(QComboBox *comboBox, const QList<
 {
     comboBox->clear();
 
-    QString recommend;
     QList<DisplayModesStu> list = m_displayConfig->listPreferredModes(m_curMonitorPath);
+    double recommendRefreshRate;
     if (!list.isEmpty())
     {
-        double refreshRate = list.first().refreshRate;
-        recommend = QString("%1HZ").arg(QString::asprintf("%.2f", refreshRate));
+        recommendRefreshRate = list.first().refreshRate;
     }
 
+    QString strPostfix = tr(" (recommended)");
     QList<double> t_refreshRateList = refreshRateList;
     std::sort(t_refreshRateList.begin(), t_refreshRateList.end(), std::greater<double>());
     foreach (double r, t_refreshRateList)
     {
         QString text = QString("%1HZ").arg(QString::asprintf("%.2f", r));
-        if (text == recommend) text += tr(" (recommended)");
+        if (QString::asprintf("%.2f", r) == QString::asprintf("%.2f", recommendRefreshRate)) 
+        {
+            text.append(strPostfix);
+        }
         comboBox->addItem(text, r);
     }
+
+    for (size_t i = 0; i < comboBox->count(); i++)
+    {
+        double refreshRate = comboBox->itemData(i).toDouble();
+        if(QString::asprintf("%.2f", refreshRate) == QString::asprintf("%.2f", recommendRefreshRate))
+        {
+            comboBox->setCurrentIndex(i);
+            break;
+        }
+    }
 }
 
 void DisplayPage::selectResolutionComboboxItem(QComboBox *comboBox, const int &w, const int &h)
-- 
2.33.0

