Commit d71929ff authored by David Hurka's avatar David Hurka 🐬
Browse files

Config dialog: Make screen combo box update in realtime

Makes PreferredScreenSelector repopulate itself when screens are added or removed;
using QApplication::screenAdded/Removed() signals.
parent 7ffd08aa
Pipeline #54980 passed with stage
in 10 minutes and 35 seconds
...@@ -151,8 +151,25 @@ PreferredScreenSelector::PreferredScreenSelector(QWidget *parent) ...@@ -151,8 +151,25 @@ PreferredScreenSelector::PreferredScreenSelector(QWidget *parent)
: QComboBox(parent) : QComboBox(parent)
, m_disconnectedScreenNumber(k_noDisconnectedScreenNumber) , m_disconnectedScreenNumber(k_noDisconnectedScreenNumber)
{ {
repopulateList();
connect(qApp, &QGuiApplication::screenAdded, this, &PreferredScreenSelector::repopulateList);
connect(qApp, &QGuiApplication::screenRemoved, this, &PreferredScreenSelector::repopulateList);
// KConfigWidgets setup:
setProperty("kcfg_property", QByteArray("preferredScreen"));
connect(this, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) { emit preferredScreenChanged(index - k_specialScreenCount); });
}
void PreferredScreenSelector::repopulateList()
{
// Remember which index was selected before:
const int screenBeforeRepopulation = preferredScreen();
QSignalBlocker signalBlocker(this);
clear();
// Populate list: // Populate list:
static_assert(k_specialScreenCount == 2, "Special screens unknown to PreferredScreenSelector constructor."); static_assert(k_specialScreenCount == 2, "Special screens unknown to PreferredScreenSelector::repopulateList().");
addItem(i18nc("@item:inlistbox Config dialog, presentation page, preferred screen", "Current Screen")); addItem(i18nc("@item:inlistbox Config dialog, presentation page, preferred screen", "Current Screen"));
addItem(i18nc("@item:inlistbox Config dialog, presentation page, preferred screen", "Default Screen")); addItem(i18nc("@item:inlistbox Config dialog, presentation page, preferred screen", "Default Screen"));
...@@ -170,21 +187,24 @@ PreferredScreenSelector::PreferredScreenSelector(QWidget *parent) ...@@ -170,21 +187,24 @@ PreferredScreenSelector::PreferredScreenSelector(QWidget *parent)
// If a disconnected screen is configured, it will be appended last: // If a disconnected screen is configured, it will be appended last:
m_disconnectedScreenIndex = count(); m_disconnectedScreenIndex = count();
// KConfigWidgets setup: // If a screen of currently disconnected index was selected, keep its list item:
setProperty("kcfg_property", QByteArray("preferredScreen")); if (m_disconnectedScreenNumber >= m_disconnectedScreenIndex - k_specialScreenCount) {
connect(this, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) { emit preferredScreenChanged(index - k_specialScreenCount); }); addItem(i18nc("@item:inlistbox Config dialog, presentation page, preferred screen. %1 is the screen number (0, 1, ...), hopefully not 0.", "Screen %1 (disconnected)", m_disconnectedScreenNumber));
}
// Select the index that was selected before:
setPreferredScreen(screenBeforeRepopulation);
} }
void PreferredScreenSelector::setPreferredScreen(int newScreen) void PreferredScreenSelector::setPreferredScreen(int newScreen)
{ {
// Check whether the new screen is not in the list of connected screens: // Check whether the new screen is not in the list of connected screens:
if (newScreen >= m_disconnectedScreenIndex - k_specialScreenCount) { if (newScreen >= m_disconnectedScreenIndex - k_specialScreenCount) {
if (m_disconnectedScreenNumber == k_noDisconnectedScreenNumber) { if (m_disconnectedScreenNumber != newScreen) {
addItem(QString()); m_disconnectedScreenNumber = newScreen;
repopulateList();
} }
setItemText(m_disconnectedScreenIndex, i18nc("@item:inlistbox Config dialog, presentation page, preferred screen. %1 is the screen number (0, 1, ...), hopefully not 0.", "Screen %1 (disconnected)", newScreen));
setCurrentIndex(m_disconnectedScreenIndex); setCurrentIndex(m_disconnectedScreenIndex);
m_disconnectedScreenNumber = newScreen;
return; return;
} }
......
...@@ -59,6 +59,14 @@ protected: ...@@ -59,6 +59,14 @@ protected:
* Until @c m_disconnectedScreenIndex entry is created, this is @c k_noDisconnectedScreenNumber. * Until @c m_disconnectedScreenIndex entry is created, this is @c k_noDisconnectedScreenNumber.
*/ */
int m_disconnectedScreenNumber; int m_disconnectedScreenNumber;
protected Q_SLOTS:
/**
* Populates the combobox list with items for the special screens,
* and for every connected screen.
* If @c m_disconnectedScreenNumber is set, adds an item for this disconnected screen.
*/
void repopulateList();
}; };
/** “Current” and “Default” */ /** “Current” and “Default” */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment