aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core-utils/lumina-config/mainWindow.cpp
blob: 31d746d501513e7e0a466218d15c7676c5e86d50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//===========================================
//  Lumina Desktop Source Code
//  Copyright (c) 2016, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "mainWindow.h"
#include "ui_mainWindow.h"
#include "globals.h"

#include "pages/getPage.h"

//=============
//      PUBLIC
//=============
mainWindow::mainWindow() : QMainWindow(), ui(new Ui::mainWindow()){
  ui->setupUi(this);
  setupIcons();
  changePage(""); //load the default main page
}

mainWindow::~mainWindow(){

}

//==============
//  PUBLIC SLOTS
//==============
void mainWindow::slotSingleInstance(){
  this->showNormal(); //just in case it is hidden/minimized
}

void mainWindow::setupIcons(){
  ui->actionSave->setIcon( LXDG::findIcon("document-save","") );
  ui->actionBack->setIcon( LXDG::findIcon("go-previous-view","") );
}

//=============
//      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)) );
  //Now load the new page
  page->LoadSettings(0); //need to make this show the current screen as needed
  //Now update this UI a bit based on page settings
  bool needscreen = page->needsScreenSelector();

  this->showNormal();
}
//================
//  PRIVATE SLOTS
//================
//Page signal handling
void mainWindow::pageCanSave(bool save){
  ui->actionSave->setVisible(save);
  ui->actionSave->setEnabled(save);
}

void mainWindow::pageSetTitle(QString title){
  this->setWindowTitle(title);
}

void mainWindow::page_change(QString id){
  if(ui->actionSave->isEnabled()){
    //unsaved changed available - prompt to save first
    // TO-DO
  }
  changePage(id);
}

void mainWindow::on_actionSave_triggered(){
  pageCanSave(false); //disable for the moment (page might re-enable later)
  static_cast<PageWidget*>(this->centralWidget())->SaveSettings();

}

void mainWindow::on_actionBack_triggered(){
  if(cpage.isEmpty()){ this->close(); } //main menu - go ahead and close it
  else{ page_change(""); } //Use the interactive wrapper (check for save state, etc).
}

bgstack15