New GUI, many changes
[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 void PIRSelectKeysetForm::addNameToList(
45   QString name,
46   unsigned int index,
47   PIRMakeName make)
48 {
49   ui->keysetListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
50 }
51
52 void PIRSelectKeysetForm::addWidgetItem(
53   PIRKeysetWidgetItem *kwi)
54 {
55   ui->keysetListWidget->addItem(kwi);
56 }
57
58 QListWidget *PIRSelectKeysetForm::getKeysetListWidget()
59 {
60   return ui->keysetListWidget;
61 }
62
63 void PIRSelectKeysetForm::filterListByMake(
64   int make)
65 {
66   currentMake = (PIRMakeName) make;
67   refilterList();
68 }
69
70 void PIRSelectKeysetForm::refilterList()
71 {
72   int index = 0;
73   int count = ui->keysetListWidget->count();
74   PIRKeysetWidgetItem *item;
75   while (index < count)
76   {
77     item = dynamic_cast<PIRKeysetWidgetItem *>(
78       ui->keysetListWidget->item(index));
79
80     // Does the keylist have the required make?
81     if ((currentMake == Any_Make) || (item->getMake() == currentMake))
82     {
83       // Yes, we can show this keylist:
84       item->setHidden(false);
85     }
86     else
87     {
88       item->setHidden(true);
89     }
90
91     ++index;
92   }
93 }