Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Pierogi
Summary Forums Tracker Lists Tasks Docs News SCM Files
1 #include "pirselectdeviceform.h"
2 #include "ui_pirselectdeviceform.h"
3 #include "pirkeysetwidgetitem.h"
4 #include <QKeyEvent>
6 PIRDeviceTypeMgr deviceTypeManager;
8 extern PIRMakeMgr makeManager;
10 PIRSelectDeviceForm::PIRSelectDeviceForm(
11   QWidget *parent)
12   : QWidget(parent),
13     ui(new Ui::PIRSelectDeviceForm),
14     currentMake(Any_Make),
15     currentDevice(Any_Device)
16 {
17   ui->setupUi(this);
19   // Don't want to start with the line editor visible:
20   ui->searchStringLineEdit->hide();
21   ui->searchStringLineEdit->lower();
22   ui->ssClosePushButton->hide();
24   // Set some initial flags:
25   setAttribute(Qt::WA_Maemo5StackedWindow);
26   setWindowFlags(windowFlags() | Qt::Window);
28   // push the list of makers into the make combo box:
29   makeManager.populateComboBox(ui->makeComboBox);
30   deviceTypeManager.populateComboBox(ui->deviceComboBox);
32   // Connection telling main window that keyset has been selected:
33   connect(
34     ui->deviceListWidget,
35     SIGNAL(itemActivated(QListWidgetItem *)),
36     parent,
37     SLOT(keysetSelectionChanged(QListWidgetItem *)),
38     Qt::QueuedConnection);
40   // Connection used to filter keyset list:
41   connect(
42     ui->makeComboBox,
43     SIGNAL(currentIndexChanged(int)),
44     this,
45     SLOT(filterListByMake(int)),
46     Qt::QueuedConnection);
48   connect(
49     ui->deviceComboBox,
50     SIGNAL(currentIndexChanged(int)),
51     this,
52     SLOT(filterListByDeviceType(int)),
53     Qt::QueuedConnection);
54 }
56 PIRSelectDeviceForm::~PIRSelectDeviceForm()
57 {
58   delete ui;
59 }
61 /*
62 void PIRSelectDeviceForm::addNameToList(
63   QString name,
64   unsigned int index,
65   PIRMakeName make)
66 {
67   ui->deviceListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
68 }
69 */
72 void PIRSelectDeviceForm::addWidgetItem(
73   PIRKeysetWidgetItem *kwi)
74 {
75   ui->deviceListWidget->addItem(kwi);
76 }
79 QListWidget *PIRSelectDeviceForm::getDeviceListWidget()
80 {
81   return ui->deviceListWidget;
82 }
85 void PIRSelectDeviceForm::keyPressEvent(
86   QKeyEvent *event)
87 {
88   ui->searchStringLineEdit->show();
89   ui->searchStringLineEdit->raise();
90   ui->ssClosePushButton->show();
92   ui->searchStringLineEdit->setText(event->text());
93   ui->searchStringLineEdit->setFocus();
94 }
97 void PIRSelectDeviceForm::on_searchStringLineEdit_textChanged(const QString &arg1)
98 {
99   filterListByString(arg1);
103 void PIRSelectDeviceForm::on_ssClosePushButton_clicked()
105   ui->searchStringLineEdit->hide();
106   ui->searchStringLineEdit->lower();
107   ui->ssClosePushButton->hide();
108   ui->searchStringLineEdit->clear();
112 void PIRSelectDeviceForm::filterListByMake(
113   int make)
115   currentMake = (PIRMakeName) make;
116   refilterList();
120 void PIRSelectDeviceForm::filterListByDeviceType(
121   int deviceType)
123   currentDevice = (PIRDeviceTypeName) deviceType;
124   refilterList();
128 void PIRSelectDeviceForm::filterListByString(
129   QString string)
131   searchString = string;
132   refilterList();
136 void PIRSelectDeviceForm::refilterList()
138   int index = 0;
139   int count = ui->deviceListWidget->count();
140   PIRKeysetWidgetItem *item;
141   while (index < count)
142   {
143     item = dynamic_cast<PIRKeysetWidgetItem *>(
144       ui->deviceListWidget->item(index));
146     // Does the keylist have the required make?
147     if ((currentMake == Any_Make) || (item->getMake() == currentMake))
148     {
149       // And does it have the required type?
150       if ( (currentDevice == Any_Device)
151         || (item->getDeviceType() == currentDevice))
152      {
153         // Does it match the search string?
154         if ( searchString.isEmpty()
155           || item->text().contains(searchString, Qt::CaseInsensitive))
156         {
157           // Yes, we can show this keylist:
158           item->setHidden(false);
159         }
160         else
161         {
162           item->setHidden(true);
163         }
164       }
165       else
166       {
167         item->setHidden(true);
168       }
169     }
170     else
171     {
172       item->setHidden(true);
173     }
175     ++index;
176   }

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment