From d49e71b054fe72c51cd7b364fa62cb005883a50a Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 1 Dec 2015 09:59:38 -0500 Subject: Add the ability to change monitor resolutions in lumina-xconfig. --- lumina-xconfig/MainUI.cpp | 50 ++++++++++++- lumina-xconfig/MainUI.h | 2 + lumina-xconfig/MainUI.ui | 187 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 192 insertions(+), 47 deletions(-) diff --git a/lumina-xconfig/MainUI.cpp b/lumina-xconfig/MainUI.cpp index 4fa9236f..afa65323 100644 --- a/lumina-xconfig/MainUI.cpp +++ b/lumina-xconfig/MainUI.cpp @@ -26,6 +26,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(ui->tool_deactivate, SIGNAL(clicked()), this, SLOT(DeactivateScreen()) ); connect(ui->tool_moveleft, SIGNAL(clicked()), this, SLOT(MoveScreenLeft()) ); connect(ui->tool_moveright, SIGNAL(clicked()), this, SLOT(MoveScreenRight()) ); + connect(ui->tool_applyconfig, SIGNAL(clicked()), this, SLOT(ApplyChanges()) ); connect(ui->list_screens, SIGNAL(itemSelectionChanged()),this, SLOT(ScreenSelected()) ); QTimer::singleShot(0, this, SLOT(UpdateScreens()) ); } @@ -42,6 +43,20 @@ void MainUI::loadIcons(){ ui->push_activate->setIcon( LXDG::findIcon("list-add","") ); ui->push_rescan->setIcon( LXDG::findIcon("view-refresh","") ); ui->push_close->setIcon( LXDG::findIcon("window-close","") ); + ui->tabWidget->setTabIcon(0, LXDG::findIcon("preferences-desktop-display","") ); + ui->tabWidget->setTabIcon(1, LXDG::findIcon("list-add","") ); + ui->tool_applyconfig->setIcon( LXDG::findIcon("dialog-ok-apply","") ); +} + +ScreenInfo MainUI::currentScreenInfo(){ + QListWidgetItem *item = ui->list_screens->currentItem(); + if(item!=0){ + for(int i=0; iwhatsThis()){ return SCREENS[i]; } + } + } + //Fallback when nothing found/selected + return ScreenInfo(); } void MainUI::UpdateScreens(){ @@ -95,6 +110,8 @@ void MainUI::UpdateScreens(){ bool found = true; int xoffset = 0; //start at 0 int cnum = 0; + QString csel = ""; + if(ui->list_screens->currentItem()!=0){ csel = ui->list_screens->currentItem()->whatsThis(); } ui->list_screens->clear(); while(found){ found = false; //make sure to break out if a screen is not found @@ -110,6 +127,7 @@ void MainUI::UpdateScreens(){ it->setText( SCREENS[i].ID+"\n ("+QString::number(SCREENS[i].geom.width())+"x"+QString::number(SCREENS[i].geom.height())+") " ); it->setWhatsThis(SCREENS[i].ID); ui->list_screens->addItem(it); + if(SCREENS[i].ID==csel){ ui->list_screens->setCurrentItem(it); } } } } @@ -124,7 +142,15 @@ void MainUI::UpdateScreens(){ ui->combo_cscreens->addItem(SCREENS[i].ID); } } - ui->group_avail->setVisible( ui->combo_availscreens->count()>0 ); + if(ui->combo_availscreens->count()<1){ + ui->group_avail->setVisible(false); + ui->tabWidget->setCurrentIndex(0); + ui->tabWidget->setTabEnabled(1,false); + }else{ + ui->group_avail->setVisible(true); + ui->tabWidget->setTabEnabled(1,true); + } + if(ui->list_screens->currentItem()==0){ ui->list_screens->setCurrentRow(0); } ScreenSelected(); //update buttons } @@ -135,11 +161,23 @@ void MainUI::ScreenSelected(){ ui->tool_deactivate->setEnabled(false); ui->tool_moveleft->setEnabled(false); ui->tool_moveright->setEnabled(false); + ui->tab_config->setEnabled(false); }else{ //Item selected ui->tool_deactivate->setEnabled(ui->list_screens->count()>1); ui->tool_moveleft->setEnabled(ui->list_screens->row(item) > 0); ui->tool_moveright->setEnabled(ui->list_screens->row(item) < (ui->list_screens->count()-1)); + ui->tab_config->setEnabled(true); + //Update the info available on the config tab + ScreenInfo cur = currentScreenInfo(); + ui->combo_resolution->clear(); + QString cres = QString::number(cur.geom.width())+"x"+QString::number(cur.geom.height()); + for(int i=0; icombo_resolution->addItem( QString(tr("%1 (Recommended)")).arg(res), res); } + else{ui->combo_resolution->addItem(res, res); } + if(cur.resList[i].contains(cres)){ ui->combo_resolution->setCurrentIndex(i); } + } } } @@ -193,3 +231,13 @@ void MainUI::ActivateScreen(){ LUtils::runCmd("xrandr", QStringList() << "--output" << ID << loc << DID <<"--auto"); QTimer::singleShot(500, this, SLOT(UpdateScreens()) ); } + +void MainUI::ApplyChanges(){ + QListWidgetItem *it = ui->list_screens->currentItem(); + if(it==0){ return; } //nothing to do + QString newres = ui->combo_resolution->currentData().toString(); + if(newres.isEmpty()){ return; } //nothing to do + qDebug() << "Apply Screen Changes" << it->whatsThis() << "->" << newres; + LUtils::runCmd("xrandr", QStringList() << "--output" << it->whatsThis() << "--mode" << newres); + QTimer::singleShot(500, this, SLOT(UpdateScreens()) ); +} \ No newline at end of file diff --git a/lumina-xconfig/MainUI.h b/lumina-xconfig/MainUI.h index d7b9f2ea..363cf257 100644 --- a/lumina-xconfig/MainUI.h +++ b/lumina-xconfig/MainUI.h @@ -44,6 +44,7 @@ public slots: private: Ui::MainUI *ui; QList SCREENS; + ScreenInfo currentScreenInfo(); private slots: void UpdateScreens(); @@ -52,6 +53,7 @@ private slots: void MoveScreenRight(); void DeactivateScreen(QString device = ""); void ActivateScreen(); + void ApplyChanges(); //config changes }; #endif diff --git a/lumina-xconfig/MainUI.ui b/lumina-xconfig/MainUI.ui index 02df4b94..c1c4b614 100644 --- a/lumina-xconfig/MainUI.ui +++ b/lumina-xconfig/MainUI.ui @@ -6,8 +6,8 @@ 0 0 - 424 - 255 + 408 + 316 @@ -95,51 +95,146 @@ - - - - - - 0 - 0 - + + + 0 + + + + Configure Screen + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - Available Screens - - - - - - Screen which is not in user - - - - - - - Location to insert the screen - - - - - - - Current screens - - - - - - - Activate Screen - - - - - - - + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 75 + true + + + + Resolution: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Apply Settings + + + Qt::ToolButtonTextBesideIcon + + + + + + + + + + Add Screen + + + + + + + 0 + 0 + + + + Available Screens + + + + + + Screen which is not in user + + + + + + + Location to insert the screen + + + + + + + Current screens + + + + + + + Enable Screen + + + + + + + + + -- cgit