From ca225b7bd525ea961bf5aec2fa3f8c05e8307e4e Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 22 Aug 2017 13:35:07 -0400 Subject: Get 90% of the work for adding profiles to lumina-xconfig finished. Still need to work out a few small issues when loading a profile into the preview pane. --- src-qt5/core-utils/lumina-xconfig/MainUI.cpp | 62 +++++++++- src-qt5/core-utils/lumina-xconfig/MainUI.h | 9 +- src-qt5/core-utils/lumina-xconfig/MainUI.ui | 125 +++++++++++++++++---- .../core-utils/lumina-xconfig/ScreenSettings.cpp | 108 +++++++++++------- src-qt5/core-utils/lumina-xconfig/ScreenSettings.h | 5 +- 5 files changed, 240 insertions(+), 69 deletions(-) (limited to 'src-qt5/core-utils') diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.cpp b/src-qt5/core-utils/lumina-xconfig/MainUI.cpp index 1a3662fe..aecc5122 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.cpp +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.cpp @@ -11,6 +11,8 @@ #include #include +#include +#include MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); @@ -28,6 +30,10 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ singleTileMenu->addAction(tr("Align Horizontal then Vertical"))->setWhatsThis("XY"); singleTileMenu->addAction(tr("Align Vertical then Horizontal"))->setWhatsThis("YX"); ui->mdiArea->setContextMenuPolicy(Qt::CustomContextMenu); + + profilesMenu = new QMenu(this); + ui->tool_save->setMenu(profilesMenu); + connect(ui->mdiArea, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu()) ); connect(singleTileMenu, SIGNAL(triggered(QAction*)), this, SLOT(tileSingleScreen(QAction*)) ); @@ -43,6 +49,12 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(ui->tool_tileY, SIGNAL(clicked()), this, SLOT(tileScreensY()) ); connect(ui->tool_tile, SIGNAL(clicked()), this, SLOT(tileScreens()) ); connect(ui->combo_availscreens, SIGNAL(currentIndexChanged(int)), this, SLOT(updateNewScreenResolutions()) ); + + connect(ui->tool_profile_load, SIGNAL(clicked()), this, SLOT(loadProfile()) ); + connect(ui->tool_profile_remove, SIGNAL(clicked()), this, SLOT(removeProfile()) ); + connect(profilesMenu, SIGNAL(triggered(QAction*)), this, SLOT(saveAsProfile(QAction*)) ); + + updateProfiles(); QTimer::singleShot(0, this, SLOT(UpdateScreens()) ); } @@ -126,9 +138,11 @@ void MainUI::SyncBackend(){ } } -void MainUI::UpdateScreens(){ +void MainUI::UpdateScreens(QString profile){ //First probe the server for current screens - SCREENS = RRSettings::CurrentScreens(); + if(profile.isEmpty()){ SCREENS = RRSettings::CurrentScreens(); } + else{ SCREENS = RRSettings::PreviousSettings(profile); } + //Determine the scale factor for putting these into the UI QRegion tot; for(int i=0; icombo_profiles->currentText(); + RRSettings::removeProfile(cur); + updateProfiles(); +} + +void MainUI::updateProfiles(){ + QStringList profiles = RRSettings::savedProfiles(); + ui->combo_profiles->clear(); + profiles.sort(); + ui->combo_profiles->addItems(profiles); + //Update the profiles menu as needed + profilesMenu->clear(); + for(int i=0; iaddAction(profiles[i])->setWhatsThis(profiles[i]); + } + if(!profiles.isEmpty()){ profilesMenu->addSeparator(); } + profilesMenu->addAction(tr("New Profile") ); + + //Now update the tab as needed + ui->tabWidget->setTabEnabled(2,!profiles.isEmpty()); + if(ui->tabWidget->currentIndex()==2){ ui->tabWidget->setCurrentIndex(0); } +} + +void MainUI::loadProfile(){ + QString cur = ui->combo_profiles->currentText(); + UpdateScreens(cur); +} + +void MainUI::saveAsProfile(QAction *act){ + QString profile = act->whatsThis(); + if(profile.isEmpty()){ + //Need to prompt for a profile name + QStringList known = RRSettings::savedProfiles(); + while(known.contains(profile) || profile.isEmpty()){ + bool ok = false; + profile = QInputDialog::getText(this, tr("Create Screen Profile"), profile.isEmpty() ? tr("Profile Name") : tr("Profile exists - different name:"), QLineEdit::Normal, profile, &ok); + if(!ok || profile.isEmpty()){ return; } //cancelled + } + } + RRSettings::SaveScreens(SCREENS, profile); + updateProfiles(); +} diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.h b/src-qt5/core-utils/lumina-xconfig/MainUI.h index d1abc153..53bf06db 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.h +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.h @@ -39,7 +39,7 @@ private: Ui::MainUI *ui; QList SCREENS; double scaleFactor; - QMenu *singleTileMenu; + QMenu *singleTileMenu, *profilesMenu; ScreenInfo currentScreenInfo(); @@ -50,7 +50,7 @@ private: void SyncBackend(); //sync backend structures to current settings private slots: - void UpdateScreens(); + void UpdateScreens(QString profile = ""); void ScreenSelected(); void updateNewScreenResolutions(); void tileScreensY(bool activeonly = false); @@ -64,6 +64,11 @@ private slots: void ApplyChanges(); //config changes void SaveSettings(); void RestartFluxbox(); + + void removeProfile(); + void updateProfiles(); + void loadProfile(); + void saveAsProfile(QAction *); }; #endif diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.ui b/src-qt5/core-utils/lumina-xconfig/MainUI.ui index 872df95b..b6ef4383 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.ui +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.ui @@ -29,6 +29,19 @@ + + + + Refresh Screens + + + Refresh Screens + + + + + + @@ -37,6 +50,9 @@ ... + + + @@ -71,7 +87,8 @@ ... - + + .. @@ -81,7 +98,8 @@ ... - + + .. @@ -106,7 +124,7 @@ - 1 + 2 @@ -219,6 +237,53 @@ + + + Profiles + + + + + + Profiles + + + + + + + + + + + + Preview + + + + + + Qt::ToolButtonTextBesideIcon + + + + + + + Delete + + + + + + Qt::ToolButtonTextBesideIcon + + + + + + + @@ -236,28 +301,14 @@ - - - - Refresh Screens - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - + + + 0 + 0 + + Apply @@ -268,6 +319,12 @@ + + + 0 + 0 + + Save current settings as user defaults @@ -278,13 +335,35 @@ .. + + QToolButton::MenuButtonPopup + Qt::ToolButtonTextBesideIcon + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + 0 + 0 + + Close diff --git a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp index 99cfc918..f962f7d7 100644 --- a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp +++ b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp @@ -11,46 +11,11 @@ //Reset current screen config to match previously-saved settings void RRSettings::ApplyPrevious(){ + QList screens; QSettings set("lumina-desktop","lumina-xconfig"); - set.beginGroup("MonitorSettings"); - //Setup a couple lists - QStringList devs = set.childGroups(); //known/saved devices - QList screens = RRSettings::CurrentScreens(); - QStringList lastactive = set.value("lastActive",QStringList()).toStringList(); - //Now go through all the saved settings and put that info into the array - QString primary; - QStringList avail; - for(int i=0; i RRSettings::CurrentScreens(){ return SCREENS; } +QList RRSettings::PreviousSettings(QString profile){ + QSettings set("lumina-desktop","lumina-xconfig"); + if(profile.isEmpty()){ set.beginGroup("MonitorSettings"); } + else{ set.beginGroup("MonitorProfiles/"+profile); } + //Setup a couple lists + QStringList devs = set.childGroups(); //known/saved devices + QList screens = RRSettings::CurrentScreens(); + QStringList lastactive = set.value("lastActive",QStringList()).toStringList(); + //Now go through all the saved settings and put that info into the array + QString primary; + QStringList avail; + for(int i=0; i screens){ +bool RRSettings::SaveScreens(QList screens, QString profile){ QSettings set("lumina-desktop","lumina-xconfig"); - set.beginGroup("MonitorSettings"); + if(profile.isEmpty()){ set.beginGroup("MonitorSettings"); } + else{ set.beginGroup("MonitorProfiles/"+profile); } //Setup a couple lists QStringList olddevs = set.childGroups(); QStringList active; diff --git a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h index b1b9cad9..ab480a97 100644 --- a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h +++ b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h @@ -42,9 +42,12 @@ public: //Read the current screen config from xrandr static QList CurrentScreens(); //reads xrandr information + static QList PreviousSettings(QString profile=""); + static QStringList savedProfiles(); + static void removeProfile(QString profile); //Save the screen config for later - static bool SaveScreens(QList screens); + static bool SaveScreens(QList screens, QString profile = ""); //Apply screen configuration static void Apply(QList screens); -- cgit