1 #include "pirselectdeviceform.h"
2 #include "ui_pirselectdeviceform.h"
3 #include "pirkeysetwidgetitem.h"
6 PIRDeviceTypeMgr deviceTypeManager;
8 extern PIRMakeMgr makeManager;
10 PIRSelectDeviceForm::PIRSelectDeviceForm(
13 ui(new Ui::PIRSelectDeviceForm),
14 currentMake(Any_Make),
15 currentDevice(Any_Device)
19 // Make sure the user can only select one device at a time:
20 ui->deviceListWidget->setSelectionMode(
21 QAbstractItemView::SingleSelection);
23 // Don't want to start with the line editor visible:
24 ui->searchStringLineEdit->hide();
25 ui->searchStringLineEdit->lower();
26 ui->ssClosePushButton->hide();
28 // Set some initial flags:
29 setAttribute(Qt::WA_Maemo5StackedWindow);
30 setWindowFlags(windowFlags() | Qt::Window);
32 // push the list of makers into the make combo box:
33 makeManager.populateComboBox(ui->makeComboBox);
34 deviceTypeManager.populateComboBox(ui->deviceComboBox);
36 // Connection telling main window that keyset has been selected:
39 SIGNAL(itemActivated(QListWidgetItem *)),
41 SLOT(keysetSelectionChanged(QListWidgetItem *)),
42 Qt::QueuedConnection);
44 // Connection used to filter keyset list:
47 SIGNAL(currentIndexChanged(int)),
49 SLOT(filterListByMake(int)),
50 Qt::QueuedConnection);
54 SIGNAL(currentIndexChanged(int)),
56 SLOT(filterListByDeviceType(int)),
57 Qt::QueuedConnection);
60 PIRSelectDeviceForm::~PIRSelectDeviceForm()
66 void PIRSelectDeviceForm::addNameToList(
71 ui->deviceListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
76 void PIRSelectDeviceForm::addWidgetItem(
77 PIRKeysetWidgetItem *kwi)
79 ui->deviceListWidget->addItem(kwi);
83 QListWidget *PIRSelectDeviceForm::getDeviceListWidget()
85 return ui->deviceListWidget;
89 void PIRSelectDeviceForm::keyPressEvent(
92 ui->searchStringLineEdit->show();
93 ui->searchStringLineEdit->raise();
94 ui->ssClosePushButton->show();
96 ui->searchStringLineEdit->setText(event->text());
97 ui->searchStringLineEdit->setFocus();
101 void PIRSelectDeviceForm::on_searchStringLineEdit_textChanged(
104 filterListByString(arg1);
108 void PIRSelectDeviceForm::on_ssClosePushButton_clicked()
110 ui->searchStringLineEdit->hide();
111 ui->searchStringLineEdit->lower();
112 ui->ssClosePushButton->hide();
113 ui->searchStringLineEdit->clear();
117 void PIRSelectDeviceForm::filterListByMake(
120 currentMake = (PIRMakeName) make;
125 void PIRSelectDeviceForm::filterListByDeviceType(
128 currentDevice = (PIRDeviceTypeName) deviceType;
133 void PIRSelectDeviceForm::filterListByString(
136 searchString = string;
141 void PIRSelectDeviceForm::refilterList()
144 int count = ui->deviceListWidget->count();
145 PIRKeysetWidgetItem *item;
146 while (index < count)
148 item = dynamic_cast<PIRKeysetWidgetItem *>(
149 ui->deviceListWidget->item(index));
151 // Does the keylist have the required make?
152 if ((currentMake == Any_Make) || (item->getMake() == currentMake))
154 // And does it have the required type?
155 if ( (currentDevice == Any_Device)
156 || (item->getDeviceType() == currentDevice))
158 // Does it match the search string?
159 if ( searchString.isEmpty()
160 || item->text().contains(searchString, Qt::CaseInsensitive))
162 // Yes, we can show this keylist:
163 item->setHidden(false);
167 item->setHidden(true);
172 item->setHidden(true);
177 item->setHidden(true);