A couple of UI additions
[pierogi] / mainwindow.cpp
index afad5e4..d7e9921 100644 (file)
 #include "pirselectkeysetform.h"
 #include "pirselectdeviceform.h"
 #include "pirpanelselectionform.h"
+#include "pirpreferencesform.h"
 #include "pirdocumentationform.h"
 #include "piraboutform.h"
 #include "pirkeysetmanager.h"
 #include "pirpanelmanager.h"
 
 //#define DEBUGGING
+//#include <iostream>
 
 // Some ugly globals used for thread communications:
 
@@ -40,9 +42,10 @@ MainWindow::MainWindow(QWidget *parent)
     selectKeysetForm(0),
     selectDeviceForm(0),
     panelSelectionForm(0),
+    preferencesForm(0),
     documentationForm(0),
     aboutForm(0),
-    currentKeyset(0)
+    currentKeyset(1) // Zero is not a valid keyset any more
 {
   ui->setupUi(this);
 
@@ -53,23 +56,22 @@ MainWindow::MainWindow(QWidget *parent)
   myKeysets = new PIRKeysetManager();
   myPanels = new PIRPanelManager(this);
 
-  // Set up the keyset selection window:
+  // Construct the forms:
+  panelSelectionForm = new PIRPanelSelectionForm(this);
+  myPanels->setupPanels(panelSelectionForm);
+
   selectKeysetForm = new PIRSelectKeysetForm(this);
   myKeysets->populateSelectionWidget(selectKeysetForm);
 
-  // Set up the device selection window:
   selectDeviceForm = new PIRSelectDeviceForm(this);
   PIRKeysetMetaData::populateDevices(selectDeviceForm);
 
-  // Set up the panel selection window:
-  panelSelectionForm = new PIRPanelSelectionForm(this);
-
-//  myPanels->setupPanels(panelSelectionForm);
+  preferencesForm = new PIRPreferencesForm(this, myKeysets);
 
   // Remember any favorites the user has already set:
   populateFavorites();
 
-  // Retrieve the user's most recent keyset (if any):
+  // Retrieve the user's preferences:
   QSettings settings("pietrzak.org", "Pierogi");
   if (settings.contains("currentKeysetName"))
   {
@@ -77,7 +79,6 @@ MainWindow::MainWindow(QWidget *parent)
       settings.value("currentKeysetMake").toString(),
       settings.value("currentKeysetName").toString(),
       currentKeyset);
-//    currentKeyset = settings.value("currentKeyset").toInt();
   }
 
   enableButtons();
@@ -232,7 +233,47 @@ void MainWindow::enableButtons()
   // Just to be sure, check to see if the keyset has been populated:
   myKeysets->populateKeyset(this, currentKeyset);
 
-  myPanels->enableButtons(myKeysets, currentKeyset);
+  if (preferencesForm)
+  {
+    unsigned int dk = preferencesForm->getDefaultKeyset();
+    if (preferencesForm->defaultControlsVolume() && dk)
+    {
+      myKeysets->populateKeyset(this, dk);
+      myPanels->enableButtons(myKeysets, currentKeyset, dk);
+    }
+    else
+    {
+      myPanels->enableButtons(myKeysets, currentKeyset);
+    }
+  }
+  else
+  {
+    myPanels->enableButtons(myKeysets, currentKeyset);
+  }
+}
+
+
+void MainWindow::useMainPanel()
+{
+  myPanels->useMainPanel();
+}
+
+
+void MainWindow::useAltMainPanel()
+{
+  myPanels->useAltMainPanel();
+}
+
+
+QString MainWindow::getCurrentMake()
+{
+  return makeManager.getMakeString(myKeysets->getMake(currentKeyset));
+}
+
+
+QString MainWindow::getCurrentName()
+{
+  return myKeysets->getDisplayName(currentKeyset);
 }
 
 
@@ -263,6 +304,11 @@ void MainWindow::on_actionArrange_Button_Panels_triggered()
   panelSelectionForm->show();
 }
 
+void MainWindow::on_actionPreferences_triggered()
+{
+  preferencesForm->show();
+}
+
 void MainWindow::on_actionAbout_triggered()
 {
   if (!aboutForm)
@@ -466,6 +512,19 @@ void MainWindow::startRepeating(
 }
 
 
+void MainWindow::startRepeating(
+  PIRKeyName name,
+  unsigned int keysetID)
+{
+  QMutexLocker locker(&commandIFMutex);
+  if (!commandInFlight)
+  {
+    commandInFlight = true;
+    emit buttonPressed(keysetID, name);
+  }
+}
+
+
 void MainWindow::stopRepeating()
 {
   QMutexLocker locker(&stopRepeatingMutex);
@@ -485,6 +544,13 @@ void MainWindow::selectNextFavKeyset()
 }
 
 
+void MainWindow::selectPanel(
+  int index)
+{
+  ui->selectPanelComboBox->setCurrentIndex(index);
+}
+
+
 void MainWindow::managePanel(
   PIRPanelName name,
   int state)
@@ -498,8 +564,8 @@ void MainWindow::insertPanel(
   QWidget *panel,
   const QString &displayName)
 {
-  ui->stackedButtonsWidget->insertWidget(index, panel);
   ui->selectPanelComboBox->insertItem(index, displayName);
+  ui->stackedButtonsWidget->insertWidget(index, panel);
 }