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   // Make sure the user can only select one device at a time:
20   ui->deviceListWidget->setSelectionMode(
21     QAbstractItemView::SingleSelection);
23   // Don't want to start with the line editor visible:
24   ui->searchStringLineEdit->hide();
25   ui->searchStringLineEdit->lower();
26   ui->ssClosePushButton->hide();
28   // Set some initial flags:
29   setAttribute(Qt::WA_Maemo5StackedWindow);
30   setWindowFlags(windowFlags() | Qt::Window);
32   // push the list of makers into the make combo box:
33   makeManager.populateComboBox(ui->makeComboBox);
34   deviceTypeManager.populateComboBox(ui->deviceComboBox);
36   // Connection telling main window that keyset has been selected:
37   connect(
38     ui->deviceListWidget,
39     SIGNAL(itemActivated(QListWidgetItem *)),
40     parent,
41     SLOT(keysetSelectionChanged(QListWidgetItem *)),
42     Qt::QueuedConnection);
44   // Connection used to filter keyset list:
45   connect(
46     ui->makeComboBox,
47     SIGNAL(currentIndexChanged(int)),
48     this,
49     SLOT(filterListByMake(int)),
50     Qt::QueuedConnection);
52   connect(
53     ui->deviceComboBox,
54     SIGNAL(currentIndexChanged(int)),
55     this,
56     SLOT(filterListByDeviceType(int)),
57     Qt::QueuedConnection);
58 }
60 PIRSelectDeviceForm::~PIRSelectDeviceForm()
61 {
62   delete ui;
63 }
65 /*
66 void PIRSelectDeviceForm::addNameToList(
67   QString name,
68   unsigned int index,
69   PIRMakeName make)
70 {
71   ui->deviceListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
72 }
73 */
76 void PIRSelectDeviceForm::addWidgetItem(
77   PIRKeysetWidgetItem *kwi)
78 {
79   ui->deviceListWidget->addItem(kwi);
80 }
83 QListWidget *PIRSelectDeviceForm::getDeviceListWidget()
84 {
85   return ui->deviceListWidget;
86 }
89 void PIRSelectDeviceForm::keyPressEvent(
90   QKeyEvent *event)
91 {
92   ui->searchStringLineEdit->show();
93   ui->searchStringLineEdit->raise();
94   ui->ssClosePushButton->show();
96   ui->searchStringLineEdit->setText(event->text());
97   ui->searchStringLineEdit->setFocus();
98 }
101 void PIRSelectDeviceForm::on_searchStringLineEdit_textChanged(
102   const QString &arg1)
104   filterListByString(arg1);
108 void PIRSelectDeviceForm::on_ssClosePushButton_clicked()
110   ui->searchStringLineEdit->hide();
111   ui->searchStringLineEdit->lower();
112   ui->ssClosePushButton->hide();
113   ui->searchStringLineEdit->clear();
117 void PIRSelectDeviceForm::filterListByMake(
118   int make)
120   currentMake = (PIRMakeName) make;
121   refilterList();
125 void PIRSelectDeviceForm::filterListByDeviceType(
126   int deviceType)
128   currentDevice = (PIRDeviceTypeName) deviceType;
129   refilterList();
133 void PIRSelectDeviceForm::filterListByString(
134   QString string)
136   searchString = string;
137   refilterList();
141 void PIRSelectDeviceForm::refilterList()
143   int index = 0;
144   int count = ui->deviceListWidget->count();
145   PIRKeysetWidgetItem *item;
146   while (index < count)
147   {
148     item = dynamic_cast<PIRKeysetWidgetItem *>(
149       ui->deviceListWidget->item(index));
151     // Does the keylist have the required make?
152     if ((currentMake == Any_Make) || (item->getMake() == currentMake))
153     {
154       // And does it have the required type?
155       if ( (currentDevice == Any_Device)
156         || (item->getDeviceType() == currentDevice))
157      {
158         // Does it match the search string?
159         if ( searchString.isEmpty()
160           || item->text().contains(searchString, Qt::CaseInsensitive))
161         {
162           // Yes, we can show this keylist:
163           item->setHidden(false);
164         }
165         else
166         {
167           item->setHidden(true);
168         }
169       }
170       else
171       {
172         item->setHidden(true);
173       }
174     }
175     else
176     {
177       item->setHidden(true);
178     }
180     ++index;
181   }

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment