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 // Don't want to start with the line editor visible:
29 ui->searchStringLineEdit->hide();
30 ui->searchStringLineEdit->lower();
31 ui->ssClosePushButton->hide();
33 // Set some initial flags:
34 setAttribute(Qt::WA_Maemo5StackedWindow);
35 setWindowFlags(windowFlags() | Qt::Window);
37 // push the list of makers into the make combo box:
38 makeManager.populateComboBox(ui->makeComboBox);
40 // Connection telling main window that keyset has been selected:
43 SIGNAL(itemActivated(QListWidgetItem *)),
45 SLOT(keysetSelectionChanged(QListWidgetItem *)),
46 Qt::QueuedConnection);
48 // Connection used to filter keyset list:
51 SIGNAL(currentIndexChanged(int)),
53 SLOT(filterListByMake(int)),
54 Qt::QueuedConnection);
56 // Open editor dialog for indivual keysets:
59 SIGNAL(itemClicked(QListWidgetItem *)),
61 SLOT(openKeysetDialog(QListWidgetItem *)),
62 Qt::QueuedConnection);
64 // Go ahead and construct the dialog window right now:
65 editDialog = new PIREditKeysetDialog(mainWindow);
69 PIRSelectKeysetForm::~PIRSelectKeysetForm()
76 void PIRSelectKeysetForm::addNameToList(
81 ui->keysetListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
86 void PIRSelectKeysetForm::addWidgetItem(
87 PIRKeysetWidgetItem *kwi)
89 ui->keysetListWidget->addItem(kwi);
93 QListWidget *PIRSelectKeysetForm::getKeysetListWidget()
95 return ui->keysetListWidget;
99 void PIRSelectKeysetForm::keyPressEvent(
102 ui->searchStringLineEdit->show();
103 ui->searchStringLineEdit->raise();
104 ui->ssClosePushButton->show();
106 ui->searchStringLineEdit->setText(event->text());
107 ui->searchStringLineEdit->setFocus();
111 void PIRSelectKeysetForm::on_searchStringLineEdit_textChanged(
114 filterListByString(arg1);
118 void PIRSelectKeysetForm::on_ssClosePushButton_clicked()
120 ui->searchStringLineEdit->hide();
121 ui->searchStringLineEdit->lower();
122 ui->ssClosePushButton->hide();
123 ui->searchStringLineEdit->clear();
127 void PIRSelectKeysetForm::filterListByMake(
130 currentMake = (PIRMakeName) make;
135 void PIRSelectKeysetForm::filterListByString(
138 searchString = string;
143 void PIRSelectKeysetForm::refilterList()
146 int count = ui->keysetListWidget->count();
147 PIRKeysetWidgetItem *item;
148 while (index < count)
150 item = dynamic_cast<PIRKeysetWidgetItem *>(
151 ui->keysetListWidget->item(index));
153 // Does the keylist have the required make?
154 if ((currentMake == Any_Make) || (item->getMake() == currentMake))
156 // If required, is the keyset a favorite?
157 if (!showOnlyFavorites || (item->isFavorite()))
159 // Does this keylist match the search string?
160 if ( searchString.isEmpty()
161 || item->text().contains(searchString, Qt::CaseInsensitive))
163 // Yes, we can show this keylist:
164 item->setHidden(false);
168 item->setHidden(true);
173 item->setHidden(true);
178 item->setHidden(true);
186 void PIRSelectKeysetForm::openKeysetDialog(
187 QListWidgetItem *item)
189 PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *>(item);
191 editDialog->setupDialog(kwi);
197 void PIRSelectKeysetForm::on_showFavoritesCheckBox_toggled(bool checked)
199 showOnlyFavorites = checked;