Keyset update
[pierogi] / pirselectkeysetform.cpp
1 #include "pirselectkeysetform.h"
2 #include "ui_pirselectkeysetform.h"
3 #include "pirkeysetwidgetitem.h"
4 #include <QListWidget>
5
6 extern PIRMakeMgr makeManager;
7
8 PIRSelectKeysetForm::PIRSelectKeysetForm(
9   QWidget *parent)
10   : QWidget(parent),
11     ui(new Ui::PIRSelectKeysetForm),
12     currentMake(Any_Make)
13 {
14   ui->setupUi(this);
15
16   setAttribute(Qt::WA_Maemo5StackedWindow);
17   setWindowFlags(windowFlags() | Qt::Window);
18
19   // push the list of makers into the make combo box:
20   makeManager.populateComboBox(ui->makeComboBox);
21
22   // Connection telling main window that keyset has been selected:
23   connect(
24     ui->keysetListWidget,
25     SIGNAL(itemActivated(QListWidgetItem *)),
26     parent,
27     SLOT(keysetSelectionChanged(QListWidgetItem *)),
28     Qt::QueuedConnection);
29
30   // Connection used to filter keyset list:
31   connect(
32     ui->makeComboBox,
33     SIGNAL(currentIndexChanged(int)),
34     this,
35     SLOT(filterListByMake(int)),
36     Qt::QueuedConnection);
37 }
38
39 PIRSelectKeysetForm::~PIRSelectKeysetForm()
40 {
41   delete ui;
42 }
43
44 /*
45 void PIRSelectKeysetForm::addNameToList(
46   QString name,
47   unsigned int index,
48   PIRMakeName make)
49 {
50   ui->keysetListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
51 }
52 */
53
54 void PIRSelectKeysetForm::addWidgetItem(
55   PIRKeysetWidgetItem *kwi)
56 {
57   ui->keysetListWidget->addItem(kwi);
58 }
59
60 QListWidget *PIRSelectKeysetForm::getKeysetListWidget()
61 {
62   return ui->keysetListWidget;
63 }
64
65 void PIRSelectKeysetForm::filterListByMake(
66   int make)
67 {
68   currentMake = (PIRMakeName) make;
69   refilterList();
70 }
71
72 void PIRSelectKeysetForm::refilterList()
73 {
74   int index = 0;
75   int count = ui->keysetListWidget->count();
76   PIRKeysetWidgetItem *item;
77   while (index < count)
78   {
79     item = dynamic_cast<PIRKeysetWidgetItem *>(
80       ui->keysetListWidget->item(index));
81
82     // Does the keylist have the required make?
83     if ((currentMake == Any_Make) || (item->getMake() == currentMake))
84     {
85       // Yes, we can show this keylist:
86       item->setHidden(false);
87     }
88     else
89     {
90       item->setHidden(true);
91     }
92
93     ++index;
94   }
95 }