Search for Power Button Panel
[pierogi] / pirselectkeysetform.cpp
index f4c2cb7..e191da9 100644 (file)
@@ -9,6 +9,9 @@
 #include "pirkeysetwidgetitem.h"
 #include "dialogs/pireditkeysetdialog.h"
 
+// Debugging include:
+//#include <iostream>
+
 extern PIRMakeMgr makeManager;
 
 PIRSelectKeysetForm::PIRSelectKeysetForm(
@@ -17,10 +20,15 @@ PIRSelectKeysetForm::PIRSelectKeysetForm(
     ui(new Ui::PIRSelectKeysetForm),
     mainWindow(mw),
     editDialog(0),
+    showOnlyFavorites(false),
     currentMake(Any_Make)
 {
   ui->setupUi(this);
 
+  // Make sure the user can only select one keyset at a time:
+  ui->keysetListWidget->setSelectionMode(
+    QAbstractItemView::SingleSelection);
+
   // Don't want to start with the line editor visible:
   ui->searchStringLineEdit->hide();
   ui->searchStringLineEdit->lower();
@@ -92,6 +100,63 @@ QListWidget *PIRSelectKeysetForm::getKeysetListWidget()
 }
 
 
+bool PIRSelectKeysetForm::selectNextKeyset()
+{
+  int currentRow = ui->keysetListWidget->currentRow();
+
+  // If we're at the end of the list, give up:
+  if (currentRow >= (ui->keysetListWidget->count() -1))
+  {
+    return false;
+  }
+
+  ui->keysetListWidget->setCurrentRow(
+    currentRow + 1,
+    QItemSelectionModel::ClearAndSelect);
+
+  mainWindow->keysetSelectionChanged(
+    ui->keysetListWidget->currentItem());
+
+  return true;
+}
+
+
+bool PIRSelectKeysetForm::selectPrevKeyset()
+{
+  int currentRow = ui->keysetListWidget->currentRow();
+
+  // If we're at the beginning of the list, give up:
+  if (currentRow <= 0)
+  {
+    return false;
+  }
+
+  ui->keysetListWidget->setCurrentRow(
+    currentRow - 1,
+    QItemSelectionModel::ClearAndSelect);
+
+  mainWindow->keysetSelectionChanged(
+    ui->keysetListWidget->currentItem());
+
+  return true;
+}
+
+
+QString PIRSelectKeysetForm::getKeysetName()
+{
+  QListWidgetItem *item = ui->keysetListWidget->currentItem();
+
+  if (item)
+  {
+    return item->text();
+  }
+  else
+  {
+    return "";
+  }
+}
+
+
 void PIRSelectKeysetForm::keyPressEvent(
   QKeyEvent *event)
 {
@@ -149,12 +214,20 @@ void PIRSelectKeysetForm::refilterList()
     // Does the keylist have the required make?
     if ((currentMake == Any_Make) || (item->getMake() == currentMake))
     {
-      // Does this keylist match the search string?
-      if ( searchString.isEmpty()
-        || item->text().contains(searchString, Qt::CaseInsensitive))
+      // If required, is the keyset a favorite?
+      if (!showOnlyFavorites || (item->isFavorite()))
       {
-        // Yes, we can show this keylist:
-        item->setHidden(false);
+        // Does this keylist match the search string?
+        if ( searchString.isEmpty()
+          || item->text().contains(searchString, Qt::CaseInsensitive))
+        {
+          // Yes, we can show this keylist:
+          item->setHidden(false);
+        }
+        else
+        {
+          item->setHidden(true);
+        }
       }
       else
       {
@@ -180,3 +253,10 @@ void PIRSelectKeysetForm::openKeysetDialog(
 
   editDialog->exec();
 }
+
+
+void PIRSelectKeysetForm::on_showFavoritesCheckBox_toggled(bool checked)
+{
+  showOnlyFavorites = checked;
+  refilterList();
+}