diff options
Diffstat (limited to 'src-qt5/core-utils/lumina-config/mainWindow.cpp')
-rw-r--r-- | src-qt5/core-utils/lumina-config/mainWindow.cpp | 73 |
1 files changed, 58 insertions, 15 deletions
diff --git a/src-qt5/core-utils/lumina-config/mainWindow.cpp b/src-qt5/core-utils/lumina-config/mainWindow.cpp index 31d746d5..95a420e8 100644 --- a/src-qt5/core-utils/lumina-config/mainWindow.cpp +++ b/src-qt5/core-utils/lumina-config/mainWindow.cpp @@ -15,7 +15,13 @@ //============= mainWindow::mainWindow() : QMainWindow(), ui(new Ui::mainWindow()){ ui->setupUi(this); + cpage = "somerandomjunktostartwith"; + //Need to insert a spacer action in the toolbar + QWidget *tmp = new QWidget(this); + tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + ui->toolBar->insertWidget(ui->actionSave, tmp); //after the save button setupIcons(); + loadMonitors(); changePage(""); //load the default main page } @@ -33,27 +39,53 @@ void mainWindow::slotSingleInstance(){ void mainWindow::setupIcons(){ ui->actionSave->setIcon( LXDG::findIcon("document-save","") ); ui->actionBack->setIcon( LXDG::findIcon("go-previous-view","") ); + ui->actionMonitor->setIcon(LXDG::findIcon("preferences-desktop-display","") ); +} + +void mainWindow::loadMonitors(){ + if(ui->actionMonitor->menu()==0){ + ui->actionMonitor->setMenu( new QMenu(this) ); + ui->actionMonitor->setWhatsThis("0"); + connect( ui->actionMonitor->menu(), SIGNAL(triggered(QAction*)), this, SLOT(changeMonitor(QAction*)) ); + QToolButton *b = static_cast<QToolButton*>(ui->toolBar->widgetForAction(ui->actionMonitor)); + b->setPopupMode(QToolButton::InstantPopup); + } + int cnum = ui->actionMonitor->whatsThis().toInt(); + ui->actionMonitor->menu()->clear(); + QList<QScreen*> SL = QApplication::screens(); + for(int i=0; i<SL.length(); i++){ + QAction *tmp = ui->actionMonitor->menu()->addAction( QString("%1: %2").arg(QString::number(i), SL[i]->name()) ); + tmp->setWhatsThis(QString::number(i)); + if(i==cnum || (i==0 && cnum>= SL.length()) ){ + ui->actionMonitor->setText( tmp->text() ); + ui->actionMonitor->setWhatsThis(tmp->whatsThis() ); + } + } + } //============= // PRIVATE //============= void mainWindow::changePage(QString id){ - PageWidget *page = GetNewPage(id, this); - if(page==0){ return; } - qDebug() << "Changing page:" << id; - cpage = id; - QWidget *old = this->centralWidget(); - this->setCentralWidget(page); - if(old!=0 && old!=ui->centralwidget){ old->disconnect(); old->deleteLater(); } - //Connect the new page - connect(page, SIGNAL(HasPendingChanges(bool)), this, SLOT(pageCanSave(bool)) ); - connect(page, SIGNAL(ChangePageTitle(QString)), this, SLOT(pageSetTitle(QString)) ); - connect(page, SIGNAL(ChangePage(QString)), this, SLOT(page_change(QString)) ); + PageWidget *page = 0; + if(id!=cpage){ + page = GetNewPage(id, this); + if(page==0){ return; } + qDebug() << "Changing page:" << id; + cpage = id; + QWidget *old = this->centralWidget(); + this->setCentralWidget(page); + if(old!=0 && old!=ui->centralwidget){ old->disconnect(); old->deleteLater(); } + //Connect the new page + connect(page, SIGNAL(HasPendingChanges(bool)), this, SLOT(pageCanSave(bool)) ); + connect(page, SIGNAL(ChangePageTitle(QString)), this, SLOT(pageSetTitle(QString)) ); + connect(page, SIGNAL(ChangePage(QString)), this, SLOT(page_change(QString)) ); + } //Now load the new page - page->LoadSettings(0); //need to make this show the current screen as needed + page->LoadSettings(ui->actionMonitor->whatsThis().toInt()); //need to make this show the current screen as needed //Now update this UI a bit based on page settings - bool needscreen = page->needsScreenSelector(); + ui->actionMonitor->setVisible( page->needsScreenSelector() );// && ui->actionMonitor->menu()->actions().length()>1 ); this->showNormal(); } @@ -70,12 +102,15 @@ void mainWindow::pageSetTitle(QString title){ this->setWindowTitle(title); } -void mainWindow::page_change(QString id){ +bool mainWindow::page_change(QString id){ if(ui->actionSave->isEnabled()){ //unsaved changed available - prompt to save first - // TO-DO + QMessageBox::StandardButton result = QMessageBox::question(this, tr("Unsaved Changes"), tr("This page currently has unsaved changes, do you wish to save them now?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No); + if(result == QMessageBox::Yes){ on_actionSave_triggered(); } + else if(result == QMessageBox::Cancel){ return false; } //stop now } changePage(id); + return true; } void mainWindow::on_actionSave_triggered(){ @@ -89,3 +124,11 @@ void mainWindow::on_actionBack_triggered(){ else{ page_change(""); } //Use the interactive wrapper (check for save state, etc). } +void mainWindow::changeMonitor(QAction *act){ + QString oldWT = ui->actionMonitor->whatsThis(); + //Update the current selection shown on the button + ui->actionMonitor->setWhatsThis( act->whatsThis() ); + //Now prompt the current page to re-load settings + if( page_change(cpage) ){ ui->actionMonitor->setText(act->text()); } + else{ ui->actionMonitor->setWhatsThis(oldWT); } //cancelled - go back to old setting +} |