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 QString PIRSelectKeysetForm::getKeysetName()
147 QListWidgetItem *item = ui->keysetListWidget->currentItem();
160 void PIRSelectKeysetForm::keyPressEvent(
163 ui->searchStringLineEdit->show();
164 ui->searchStringLineEdit->raise();
165 ui->ssClosePushButton->show();
167 ui->searchStringLineEdit->setText(event->text());
168 ui->searchStringLineEdit->setFocus();
172 void PIRSelectKeysetForm::on_searchStringLineEdit_textChanged(
175 filterListByString(arg1);
179 void PIRSelectKeysetForm::on_ssClosePushButton_clicked()
181 ui->searchStringLineEdit->hide();
182 ui->searchStringLineEdit->lower();
183 ui->ssClosePushButton->hide();
184 ui->searchStringLineEdit->clear();
188 void PIRSelectKeysetForm::filterListByMake(
191 currentMake = (PIRMakeName) make;
196 void PIRSelectKeysetForm::filterListByString(
199 searchString = string;
204 void PIRSelectKeysetForm::refilterList()
207 int count = ui->keysetListWidget->count();
208 PIRKeysetWidgetItem *item;
209 while (index < count)
211 item = dynamic_cast<PIRKeysetWidgetItem *>(
212 ui->keysetListWidget->item(index));
214 // Does the keylist have the required make?
215 if ((currentMake == Any_Make) || (item->getMake() == currentMake))
217 // If required, is the keyset a favorite?
218 if (!showOnlyFavorites || (item->isFavorite()))
220 // Does this keylist match the search string?
221 if ( searchString.isEmpty()
222 || item->text().contains(searchString, Qt::CaseInsensitive))
224 // Yes, we can show this keylist:
225 item->setHidden(false);
229 item->setHidden(true);
234 item->setHidden(true);
239 item->setHidden(true);
247 void PIRSelectKeysetForm::openKeysetDialog(
248 QListWidgetItem *item)
250 PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *>(item);
252 editDialog->setupDialog(kwi);
258 void PIRSelectKeysetForm::on_showFavoritesCheckBox_toggled(bool checked)
260 showOnlyFavorites = checked;