A couple of UI additions
[pierogi] / pirselectdeviceform.cpp
index 5ea463e..021cc07 100644 (file)
@@ -1,9 +1,11 @@
 #include "pirselectdeviceform.h"
 #include "ui_pirselectdeviceform.h"
 #include "pirkeysetwidgetitem.h"
+#include <QKeyEvent>
+
+PIRDeviceTypeMgr deviceTypeManager;
 
 extern PIRMakeMgr makeManager;
-extern PIRDeviceTypeMgr deviceManager;
 
 PIRSelectDeviceForm::PIRSelectDeviceForm(
   QWidget *parent)
@@ -14,12 +16,18 @@ PIRSelectDeviceForm::PIRSelectDeviceForm(
 {
   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);
+  deviceTypeManager.populateComboBox(ui->deviceComboBox);
 
   // Connection telling main window that keyset has been selected:
   connect(
@@ -50,6 +58,7 @@ PIRSelectDeviceForm::~PIRSelectDeviceForm()
   delete ui;
 }
 
+/*
 void PIRSelectDeviceForm::addNameToList(
   QString name,
   unsigned int index,
@@ -57,6 +66,8 @@ void PIRSelectDeviceForm::addNameToList(
 {
   ui->deviceListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
 }
+*/
+
 
 void PIRSelectDeviceForm::addWidgetItem(
   PIRKeysetWidgetItem *kwi)
@@ -64,11 +75,40 @@ void PIRSelectDeviceForm::addWidgetItem(
   ui->deviceListWidget->addItem(kwi);
 }
 
+
 QListWidget *PIRSelectDeviceForm::getDeviceListWidget()
 {
   return ui->deviceListWidget;
 }
 
+
+void PIRSelectDeviceForm::keyPressEvent(
+  QKeyEvent *event)
+{
+  ui->searchStringLineEdit->show();
+  ui->searchStringLineEdit->raise();
+  ui->ssClosePushButton->show();
+
+  ui->searchStringLineEdit->setText(event->text());
+  ui->searchStringLineEdit->setFocus();
+}
+
+
+void PIRSelectDeviceForm::on_searchStringLineEdit_textChanged(const QString &arg1)
+{
+  filterListByString(arg1);
+}
+
+
+void PIRSelectDeviceForm::on_ssClosePushButton_clicked()
+{
+  ui->searchStringLineEdit->hide();
+  ui->searchStringLineEdit->lower();
+  ui->ssClosePushButton->hide();
+  ui->searchStringLineEdit->clear();
+}
+
+
 void PIRSelectDeviceForm::filterListByMake(
   int make)
 {
@@ -76,6 +116,7 @@ void PIRSelectDeviceForm::filterListByMake(
   refilterList();
 }
 
+
 void PIRSelectDeviceForm::filterListByDeviceType(
   int deviceType)
 {
@@ -83,6 +124,15 @@ void PIRSelectDeviceForm::filterListByDeviceType(
   refilterList();
 }
 
+
+void PIRSelectDeviceForm::filterListByString(
+  QString string)
+{
+  searchString = string;
+  refilterList();
+}
+
+
 void PIRSelectDeviceForm::refilterList()
 {
   int index = 0;
@@ -100,8 +150,17 @@ void PIRSelectDeviceForm::refilterList()
       if ( (currentDevice == Any_Device)
         || (item->getDeviceType() == currentDevice))
      {
-        // Yes, we can show this keylist:
-        item->setHidden(false);
+        // Does it 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
       {