A couple of UI additions
[pierogi] / pirselectkeysetform.cpp
index eab0504..39ac645 100644 (file)
@@ -1,26 +1,30 @@
 #include "pirselectkeysetform.h"
 #include "ui_pirselectkeysetform.h"
 #include "pirkeysetwidgetitem.h"
-#include <QListWidget>
+//#include <QListWidget>
+#include <QKeyEvent>
 
 extern PIRMakeMgr makeManager;
-extern PIRDeviceTypeMgr deviceManager;
 
 PIRSelectKeysetForm::PIRSelectKeysetForm(
   QWidget *parent)
   : QWidget(parent),
     ui(new Ui::PIRSelectKeysetForm),
-    currentMake(Any_Make),
-    currentDevice(Any_Device)
+    currentMake(Any_Make)
 {
   ui->setupUi(this);
 
+  // Don't want to start with the line editor visible:
+  ui->searchStringLineEdit->hide();
+  ui->searchStringLineEdit->lower();
+  ui->ssClosePushButton->hide();
+
+  // Set some initial flags:
   setAttribute(Qt::WA_Maemo5StackedWindow);
   setWindowFlags(windowFlags() | Qt::Window);
 
   // push the list of makers into the make combo box:
   makeManager.populateComboBox(ui->makeComboBox);
-  deviceManager.populateComboBox(ui->deviceComboBox);
 
   // Connection telling main window that keyset has been selected:
   connect(
@@ -37,20 +41,16 @@ PIRSelectKeysetForm::PIRSelectKeysetForm(
     this,
     SLOT(filterListByMake(int)),
     Qt::QueuedConnection);
-
-  connect(
-    ui->deviceComboBox,
-    SIGNAL(currentIndexChanged(int)),
-    this,
-    SLOT(filterListByDeviceType(int)),
-    Qt::QueuedConnection);
 }
 
+
 PIRSelectKeysetForm::~PIRSelectKeysetForm()
 {
   delete ui;
 }
 
+
+/*
 void PIRSelectKeysetForm::addNameToList(
   QString name,
   unsigned int index,
@@ -58,6 +58,8 @@ void PIRSelectKeysetForm::addNameToList(
 {
   ui->keysetListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
 }
+*/
+
 
 void PIRSelectKeysetForm::addWidgetItem(
   PIRKeysetWidgetItem *kwi)
@@ -65,11 +67,41 @@ void PIRSelectKeysetForm::addWidgetItem(
   ui->keysetListWidget->addItem(kwi);
 }
 
+
 QListWidget *PIRSelectKeysetForm::getKeysetListWidget()
 {
   return ui->keysetListWidget;
 }
 
+
+void PIRSelectKeysetForm::keyPressEvent(
+  QKeyEvent *event)
+{
+  ui->searchStringLineEdit->show();
+  ui->searchStringLineEdit->raise();
+  ui->ssClosePushButton->show();
+
+  ui->searchStringLineEdit->setText(event->text());
+  ui->searchStringLineEdit->setFocus();
+}
+
+
+void PIRSelectKeysetForm::on_searchStringLineEdit_textChanged(
+  const QString &arg1)
+{
+  filterListByString(arg1);
+}
+
+
+void PIRSelectKeysetForm::on_ssClosePushButton_clicked()
+{
+  ui->searchStringLineEdit->hide();
+  ui->searchStringLineEdit->lower();
+  ui->ssClosePushButton->hide();
+  ui->searchStringLineEdit->clear();
+}
+
+
 void PIRSelectKeysetForm::filterListByMake(
   int make)
 {
@@ -77,13 +109,15 @@ void PIRSelectKeysetForm::filterListByMake(
   refilterList();
 }
 
-void PIRSelectKeysetForm::filterListByDeviceType(
-  int deviceType)
+
+void PIRSelectKeysetForm::filterListByString(
+  QString string)
 {
-  currentDevice = (PIRDeviceTypeName) deviceType;
+  searchString = string;
   refilterList();
 }
 
+
 void PIRSelectKeysetForm::refilterList()
 {
   int index = 0;
@@ -97,9 +131,9 @@ void PIRSelectKeysetForm::refilterList()
     // Does the keylist have the required make?
     if ((currentMake == Any_Make) || (item->getMake() == currentMake))
     {
-      // And, does the keylist have the required device type?
-      if ((currentDevice == Any_Device)
-          || (item->supportsDeviceType(currentDevice)))
+      // 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);