#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"
+
+// Debugging include:
+//#include <iostream>
extern PIRMakeMgr makeManager;
-extern PIRDeviceTypeMgr deviceManager;
PIRSelectKeysetForm::PIRSelectKeysetForm(
- QWidget *parent)
- : QWidget(parent),
+ MainWindow *mw)
+ : QWidget(mw), // is this right?
ui(new Ui::PIRSelectKeysetForm),
- currentMake(Any_Make),
- currentDevice(Any_Device)
+ 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();
+ 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(
ui->keysetListWidget,
SIGNAL(itemActivated(QListWidgetItem *)),
- parent,
+ mainWindow,
SLOT(keysetSelectionChanged(QListWidgetItem *)),
Qt::QueuedConnection);
SLOT(filterListByMake(int)),
Qt::QueuedConnection);
+ // Open editor dialog for indivual keysets:
connect(
- ui->deviceComboBox,
- SIGNAL(currentIndexChanged(int)),
+ ui->keysetListWidget,
+ SIGNAL(itemClicked(QListWidgetItem *)),
this,
- SLOT(filterListByDeviceType(int)),
+ 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,
unsigned int index,
{
ui->keysetListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
}
+*/
+
void PIRSelectKeysetForm::addWidgetItem(
PIRKeysetWidgetItem *kwi)
ui->keysetListWidget->addItem(kwi);
}
+
QListWidget *PIRSelectKeysetForm::getKeysetListWidget()
{
return ui->keysetListWidget;
}
+
+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)
+{
+ 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)
{
refilterList();
}
-void PIRSelectKeysetForm::filterListByDeviceType(
- int deviceType)
+
+void PIRSelectKeysetForm::filterListByString(
+ QString string)
{
- currentDevice = (PIRDeviceTypeName) deviceType;
+ searchString = string;
refilterList();
}
+
void PIRSelectKeysetForm::refilterList()
{
int index = 0;
// 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)))
+ // 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
{
++index;
}
}
+
+
+void PIRSelectKeysetForm::openKeysetDialog(
+ QListWidgetItem *item)
+{
+ PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *>(item);
+
+ editDialog->setupDialog(kwi);
+
+ editDialog->exec();
+}
+
+
+void PIRSelectKeysetForm::on_showFavoritesCheckBox_toggled(bool checked)
+{
+ showOnlyFavorites = checked;
+ refilterList();
+}