Adding per-keyset editable data
[pierogi] / pirselectkeysetform.cpp
index 67c9e61..f4c2cb7 100644 (file)
@@ -1,18 +1,32 @@
 #include "pirselectkeysetform.h"
 #include "ui_pirselectkeysetform.h"
+
+//#include <QListWidget>
+//#include <QListWidgetItem>
+#include <QKeyEvent>
+
+#include "mainwindow.h"
 #include "pirkeysetwidgetitem.h"
-#include <QListWidget>
+#include "dialogs/pireditkeysetdialog.h"
 
 extern PIRMakeMgr makeManager;
 
 PIRSelectKeysetForm::PIRSelectKeysetForm(
-  QWidget *parent)
-  : QWidget(parent),
+  MainWindow *mw)
+  : QWidget(mw), // is this right?
     ui(new Ui::PIRSelectKeysetForm),
+    mainWindow(mw),
+    editDialog(0),
     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);
 
@@ -23,7 +37,7 @@ PIRSelectKeysetForm::PIRSelectKeysetForm(
   connect(
     ui->keysetListWidget,
     SIGNAL(itemActivated(QListWidgetItem *)),
-    parent,
+    mainWindow,
     SLOT(keysetSelectionChanged(QListWidgetItem *)),
     Qt::QueuedConnection);
 
@@ -34,13 +48,26 @@ PIRSelectKeysetForm::PIRSelectKeysetForm(
     this,
     SLOT(filterListByMake(int)),
     Qt::QueuedConnection);
+
+  // Open editor dialog for indivual keysets:
+  connect(
+    ui->keysetListWidget,
+    SIGNAL(itemClicked(QListWidgetItem *)),
+    this,
+    SLOT(openKeysetDialog(QListWidgetItem *)),
+    Qt::QueuedConnection);
+
+  // Go ahead and construct the dialog window right now:
+  editDialog = new PIREditKeysetDialog(mainWindow);
 }
 
+
 PIRSelectKeysetForm::~PIRSelectKeysetForm()
 {
   delete ui;
 }
 
+
 /*
 void PIRSelectKeysetForm::addNameToList(
   QString name,
@@ -51,17 +78,48 @@ void PIRSelectKeysetForm::addNameToList(
 }
 */
 
+
 void PIRSelectKeysetForm::addWidgetItem(
   PIRKeysetWidgetItem *kwi)
 {
   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)
 {
@@ -69,6 +127,15 @@ void PIRSelectKeysetForm::filterListByMake(
   refilterList();
 }
 
+
+void PIRSelectKeysetForm::filterListByString(
+  QString string)
+{
+  searchString = string;
+  refilterList();
+}
+
+
 void PIRSelectKeysetForm::refilterList()
 {
   int index = 0;
@@ -82,8 +149,17 @@ void PIRSelectKeysetForm::refilterList()
     // Does the keylist have the required make?
     if ((currentMake == Any_Make) || (item->getMake() == currentMake))
     {
-      // 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
     {
@@ -93,3 +169,14 @@ void PIRSelectKeysetForm::refilterList()
     ++index;
   }
 }
+
+
+void PIRSelectKeysetForm::openKeysetDialog(
+  QListWidgetItem *item)
+{
+  PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *>(item);
+
+  editDialog->setupDialog(kwi);
+
+  editDialog->exec();
+}