1 #include "pirselectkeysetform.h"
2 #include "ui_pirselectkeysetform.h"
4 //#include <QListWidget>
5 //#include <QListWidgetItem>
8 #include "mainwindow.h"
9 #include "pirkeysetwidgetitem.h"
10 #include "dialogs/pireditkeysetdialog.h"
15 extern PIRMakeMgr makeManager;
17 PIRSelectKeysetForm::PIRSelectKeysetForm(
19 : QWidget(mw), // is this right?
20 ui(new Ui::PIRSelectKeysetForm),
23 showOnlyFavorites(false),
28 // Make sure the user can only select one keyset at a time:
29 ui->keysetListWidget->setSelectionMode(
30 QAbstractItemView::SingleSelection);
32 // Don't want to start with the line editor visible:
33 ui->searchStringLineEdit->hide();
34 ui->searchStringLineEdit->lower();
35 ui->ssClosePushButton->hide();
37 // Set some initial flags:
38 setAttribute(Qt::WA_Maemo5StackedWindow);
39 setWindowFlags(windowFlags() | Qt::Window);
41 // push the list of makers into the make combo box:
42 makeManager.populateComboBox(ui->makeComboBox);
44 // Connection telling main window that keyset has been selected:
47 SIGNAL(itemActivated(QListWidgetItem *)),
49 SLOT(keysetSelectionChanged(QListWidgetItem *)),
50 Qt::QueuedConnection);
52 // Connection used to filter keyset list:
55 SIGNAL(currentIndexChanged(int)),
57 SLOT(filterListByMake(int)),
58 Qt::QueuedConnection);
60 // Open editor dialog for indivual keysets:
63 SIGNAL(itemClicked(QListWidgetItem *)),
65 SLOT(openKeysetDialog(QListWidgetItem *)),
66 Qt::QueuedConnection);
68 // Go ahead and construct the dialog window right now:
69 editDialog = new PIREditKeysetDialog(mainWindow);
73 PIRSelectKeysetForm::~PIRSelectKeysetForm()
80 void PIRSelectKeysetForm::addNameToList(
85 ui->keysetListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
90 void PIRSelectKeysetForm::addWidgetItem(
91 PIRKeysetWidgetItem *kwi)
93 ui->keysetListWidget->addItem(kwi);
97 QListWidget *PIRSelectKeysetForm::getKeysetListWidget()
99 return ui->keysetListWidget;
103 bool PIRSelectKeysetForm::selectNextKeyset()
105 int currentRow = ui->keysetListWidget->currentRow();
107 // If we're at the end of the list, give up:
108 if (currentRow >= (ui->keysetListWidget->count() -1))
113 ui->keysetListWidget->setCurrentRow(
115 QItemSelectionModel::ClearAndSelect);
117 mainWindow->keysetSelectionChanged(
118 ui->keysetListWidget->currentItem());
124 bool PIRSelectKeysetForm::selectPrevKeyset()
126 int currentRow = ui->keysetListWidget->currentRow();
128 // If we're at the beginning of the list, give up:
134 ui->keysetListWidget->setCurrentRow(
136 QItemSelectionModel::ClearAndSelect);
138 mainWindow->keysetSelectionChanged(
139 ui->keysetListWidget->currentItem());
145 bool PIRSelectKeysetForm::selectFirstKeyset()
147 if (ui->keysetListWidget->count() == 0)
152 if (ui->keysetListWidget->currentRow() != 0)
154 ui->keysetListWidget->setCurrentRow(
155 0, QItemSelectionModel::ClearAndSelect);
157 mainWindow->keysetSelectionChanged(
158 ui->keysetListWidget->currentItem());
165 QString PIRSelectKeysetForm::getKeysetName()
167 QListWidgetItem *item = ui->keysetListWidget->currentItem();
180 void PIRSelectKeysetForm::keyPressEvent(
183 ui->searchStringLineEdit->show();
184 ui->searchStringLineEdit->raise();
185 ui->ssClosePushButton->show();
187 ui->searchStringLineEdit->setText(event->text());
188 ui->searchStringLineEdit->setFocus();
192 void PIRSelectKeysetForm::on_searchStringLineEdit_textChanged(
195 filterListByString(arg1);
199 void PIRSelectKeysetForm::on_ssClosePushButton_clicked()
201 ui->searchStringLineEdit->hide();
202 ui->searchStringLineEdit->lower();
203 ui->ssClosePushButton->hide();
204 ui->searchStringLineEdit->clear();
208 void PIRSelectKeysetForm::filterListByMake(
211 currentMake = (PIRMakeName) make;
216 void PIRSelectKeysetForm::filterListByString(
219 searchString = string;
224 void PIRSelectKeysetForm::refilterList()
227 int count = ui->keysetListWidget->count();
228 PIRKeysetWidgetItem *item;
229 while (index < count)
231 item = dynamic_cast<PIRKeysetWidgetItem *>(
232 ui->keysetListWidget->item(index));
234 // Does the keylist have the required make?
235 if ((currentMake == Any_Make) || (item->getMake() == currentMake))
237 // If required, is the keyset a favorite?
238 if (!showOnlyFavorites || (item->isFavorite()))
240 // Does this keylist match the search string?
241 if ( searchString.isEmpty()
242 || item->text().contains(searchString, Qt::CaseInsensitive))
244 // Yes, we can show this keylist:
245 item->setHidden(false);
249 item->setHidden(true);
254 item->setHidden(true);
259 item->setHidden(true);
267 void PIRSelectKeysetForm::openKeysetDialog(
268 QListWidgetItem *item)
270 PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *>(item);
272 editDialog->setupDialog(kwi);
278 void PIRSelectKeysetForm::openCurrentKeysetDialog()
280 PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *> (
281 ui->keysetListWidget->currentItem());
283 editDialog->setupDialog(kwi);
289 void PIRSelectKeysetForm::on_showFavoritesCheckBox_toggled(bool checked)
291 showOnlyFavorites = checked;
296 void PIRSelectKeysetForm::selectKeyset(
297 unsigned int targetID)
299 int count = ui->keysetListWidget->count();
306 QListWidgetItem *localItem;
307 PIRKeysetWidgetItem *kwi;
312 localItem = ui->keysetListWidget->item(row);
316 kwi = dynamic_cast<PIRKeysetWidgetItem *> (localItem);
318 if (kwi->getID() == targetID)
320 ui->keysetListWidget->setCurrentRow(
321 row, QItemSelectionModel::ClearAndSelect);
323 mainWindow->keysetSelectionChanged(
324 ui->keysetListWidget->currentItem());