#include <QtCore/QCoreApplication>
#include <QMutex>
#include <QtGui/QMessageBox>
-//#include <QtGui>
+#include <QPushButton>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QScrollArea>
#include <QSettings>
+#include "pirkeysetmetadata.h"
+
#include "pirkeysetwidgetitem.h"
#include "pirselectkeysetform.h"
#include "pirselectdeviceform.h"
-#include "pirpanelselectionform.h"
+#include "pirpreferencesform.h"
#include "pirdocumentationform.h"
#include "piraboutform.h"
+#include "dialogs/pirtabschoicedialog.h"
+
#include "pirkeysetmanager.h"
#include "pirpanelmanager.h"
//#define DEBUGGING
+//#include <iostream>
// Some ugly globals used for thread communications:
ui(new Ui::MainWindow),
selectKeysetForm(0),
selectDeviceForm(0),
- panelSelectionForm(0),
+ preferencesForm(0),
documentationForm(0),
aboutForm(0),
- currentKeyset(0)
+ myKeysets(0),
+ myPanels(0),
+ currentKeyset(1) // Zero is not a valid keyset any more
{
ui->setupUi(this);
myKeysets = new PIRKeysetManager();
myPanels = new PIRPanelManager(this);
- // Set up the keyset selection window:
+ // Display the panels:
+ myPanels->updateTabSet();
+
+ // Add the corner button:
+ insertCornerButton();
+
+ // Construct the rest of the forms:
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);
-
- myKeysets->populateSelectionWidgets(selectKeysetForm, selectDeviceForm);
-// 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"))
{
settings.value("currentKeysetMake").toString(),
settings.value("currentKeysetName").toString(),
currentKeyset);
-// currentKeyset = settings.value("currentKeyset").toInt();
}
enableButtons();
delete myKeysets;
if (selectKeysetForm) delete selectKeysetForm;
if (selectDeviceForm) delete selectDeviceForm;
- if (panelSelectionForm) delete panelSelectionForm;
+// if (panelSelectionForm) delete panelSelectionForm;
if (documentationForm) delete documentationForm;
if (aboutForm) delete aboutForm;
delete ui;
// 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);
}
selectDeviceForm->show();
}
-void MainWindow::on_actionArrange_Button_Panels_triggered()
+void MainWindow::on_actionPreferences_triggered()
{
- panelSelectionForm->show();
+ preferencesForm->show();
}
void MainWindow::on_actionAbout_triggered()
currentKeyset = kwi->getID();
QSettings settings("pietrzak.org", "Pierogi");
-// settings.setValue("currentKeyset", currentKeyset);
settings.setValue(
"currentKeysetMake",
settings.beginWriteArray("favorites");
settings.setArrayIndex(favSettingsSize);
-// settings.setValue("keysetID", currentKeyset);
settings.setValue(
"keysetMake",
kwi = dynamic_cast<PIRKeysetWidgetItem *>(qlw->item(index));
settings.setArrayIndex(index);
-// settings.setValue("keysetID", kwi->getID());
id = kwi->getID();
settings.setValue(
}
+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);
}
-void MainWindow::managePanel(
- PIRPanelName name,
- int state)
+void MainWindow::insertCornerButton()
{
- myPanels->managePanel(name, state);
-}
+ // Set up the dialog box:
+ PIRTabsChoiceDialog *tcd = new PIRTabsChoiceDialog(this);
+ // Next, set up the corner button itself:
+ QPushButton *button =
+ new QPushButton(QIcon(":/icons/align_just_icon&32.png"), "");
-void MainWindow::insertPanel(
- int index,
- QWidget *panel,
- const QString &displayName)
-{
- ui->stackedButtonsWidget->insertWidget(index, panel);
- ui->selectPanelComboBox->insertItem(index, displayName);
-}
+ button->setFlat(true);
+ connect(
+ button,
+ SIGNAL(clicked()),
+ tcd,
+ SLOT(exec()),
+ Qt::QueuedConnection);
-void MainWindow::removePanel(
- int index,
- QWidget *panel)
-{
- ui->stackedButtonsWidget->removeWidget(panel);
- ui->selectPanelComboBox->removeItem(index);
+ ui->mainTabWidget->setCornerWidget(button);
}
-void MainWindow::on_prevPanelButton_clicked()
+void MainWindow::disableUpdates()
{
- int count = ui->selectPanelComboBox->count();
-
- // No need to do anything if there are less than two panels available:
- if (count < 2) return;
+ ui->mainTabWidget->setUpdatesEnabled(false);
+}
- int index = ui->selectPanelComboBox->currentIndex();
- if (index == 0)
- {
- index = count - 1;
- }
- else
- {
- --index;
- }
- ui->selectPanelComboBox->setCurrentIndex(index);
+void MainWindow::enableUpdates()
+{
+ ui->mainTabWidget->setUpdatesEnabled(true);
}
-void MainWindow::on_nextPanelButton_clicked()
+void MainWindow::clearTabs()
{
- int count = ui->selectPanelComboBox->count();
-
- // No need to do anything if there are less than two panels available:
- if (count < 2) return;
+ ui->mainTabWidget->clear();
+}
- int index = ui->selectPanelComboBox->currentIndex();
- if (index == count - 1)
- {
- index = 0;
- }
- else
- {
- ++index;
- }
- ui->selectPanelComboBox->setCurrentIndex(index);
+void MainWindow::addTab(
+ QWidget *page,
+ QString label)
+{
+ ui->mainTabWidget->addTab(page, label);
}
-
-void MainWindow::on_selectPanelComboBox_currentIndexChanged(int index)
+void MainWindow::setupTabs(
+ PIRTabBarName name)
{
- ui->stackedButtonsWidget->setCurrentIndex(index);
+ myPanels->setupTabs(name);
}