2 #include <KConfigGroup>
7 #include <QButtonGroup>
10 #include <QHBoxLayout>
11 #include <QVBoxLayout>
12 #include <QPushButton>
14 #include "FingerManagerWindow.h"
15 #include "FMDbusConn.h"
16 #include "FingerNames.h"
20 void FingerManagerWindow::fingerSelected(int idx
) {
21 qDebug("fingers[%d]: %d", idx
, fingers
[idx
]->isChecked());
24 void FingerManagerWindow::addDevices() {
25 qDebug("Devices were discovered...");
28 QCheckBox
* FingerManagerWindow::createCheckBox(int idx
, int x
, int y
) {
29 QCheckBox
*cb
= new QCheckBox(handsPanel
);
30 QSize size
= cb
->sizeHint();
31 cb
->setGeometry(QRect(x
- (size
.width()/2),
32 y_base
+ y
- (size
.height()/2),
35 cb
->setWhatsThis(i18n(fingerNames
[idx
]));
36 btng
->addButton(cb
, idx
);
40 void FingerManagerWindow::load(KConfig
*settings
) {
42 KConfigGroup cfgGroup
;
45 cfgGroup
= settings
->group("image");
46 y_base
= cfgGroup
.readEntry("base", 20);
48 QString filename
= cfgGroup
.readEntry("filename", "/home/djaara/.config/djaara.net/hands.png");
49 cfgGroup
.writeEntry("filename", "/home/djaara/.config/djaara.net/hands.png");
50 QPixmap image
= QPixmap(filename
);
51 if (!image
.isNull()) {
52 handsLabel
->setPixmap(image
);
54 handsLabel
->setText("File not found: " + filename
);
56 handsLabel
->setGeometry(QRect(0, y_base
, image
.width(), image
.height()));
58 // Set handsPanel dimension
59 handsPanel
->setFixedWidth(handsLabel
->width());
60 handsPanel
->setFixedHeight(handsLabel
->height());
63 cfgGroup
= settings
->group("fingers");
64 fingersCount
= cfgGroup
.readEntry("count", 0);
65 for (int i
= 0; i
< fingersCount
&& i
< MAX_FINGERS
; i
++) {
68 name
.sprintf("%d/x", i
+1);
69 int x
= cfgGroup
.readEntry(name
, 0);
71 name
.sprintf("%d/y", i
+1);
72 int y
= cfgGroup
.readEntry(name
, 0);
74 name
.sprintf("%d/idx", i
+1);
75 unsigned int idx
= cfgGroup
.readEntry(name
, i
);
77 if (x
&& y
&& idx
< MAX_FINGERS
) {
78 qDebug("Adding new checkbox[%d]", idx
);
79 fingers
[idx
] = createCheckBox(idx
, x
, y
);
81 qDebug("Checkbox[%d] skipped", idx
);
88 FingerManagerWindow::FingerManagerWindow(QWidget
*parent
,
89 Qt::WindowFlags wflags
) : KDialog(parent
, wflags
) {
90 // Only OK button, precedent by separator
91 setButtons(KDialog::Ok
);
92 showButtonSeparator(true);
95 setWindowTitle("Finger manager...");
98 setWhatsThis(i18n("Finger Manager Application"));
104 // Connect to FMDbusConn
105 QObject::connect(dbc
, SIGNAL(devicesDiscovered()), this, SLOT(addDevices()));
108 // Dialog's main widget
109 setMainWidget(mainPanel
);
111 // Handle all check buttons
112 btng
->setExclusive(false);
113 QObject::connect(btng
, SIGNAL(buttonClicked(int)), SLOT(fingerSelected(int)));
116 mainPanelLayout
->addWidget(handsPanel
);
117 mainPanelLayout
->addWidget(separator
);
118 devicesLayout
->addWidget(deviceLabel
);
119 devicesLayout
->addWidget(devices
);
120 devicesLayout
->addStretch();
121 mainPanelLayout
->addLayout(devicesLayout
);
122 mainPanel
->setLayout(mainPanelLayout
);
124 setMaximumSize(minimumSizeHint());
128 * void initComponents()
129 * Initialize main components of FingerManagerWindow
131 void FingerManagerWindow::initComponents() {
132 dbc
= new FMDbusConn
;
133 mainPanel
= new QWidget();
134 handsPanel
= new QWidget();
135 btng
= new QButtonGroup(handsPanel
);
136 settings
= new KConfig("kfingerrc");
137 handsLabel
= new QLabel(handsPanel
);
138 deviceLabel
= new QLabel(i18n("Select device:"));
139 devices
= new QComboBox
;
140 devices
->addItem("test", "test");
141 devices
->addItem("UPEK TouchStrip", "UPEK TouchStrip");
142 devicesLayout
= new QHBoxLayout();
143 mainPanelLayout
= new QVBoxLayout();
144 mainPanelLayout
->setSizeConstraint(QLayout::SetFixedSize
);
145 separator
= new KSeparator(mainPanel
);
148 FingerManagerWindow::~FingerManagerWindow() {
153 for (int i
= 0; i
< fingersCount
; i
++) {
154 if (fingers
[i
]) delete fingers
[i
];
156 if (settings
) delete settings
;
157 if (btng
) delete btng
;
158 if (devices
) delete devices
;
159 if (handsLabel
) delete handsLabel
;
160 if (separator
) delete separator
;
161 if (devicesLayout
) delete devicesLayout
;
162 if (handsPanel
) delete handsPanel
;
163 if (mainPanelLayout
) delete mainPanelLayout
;
164 if (mainPanel
) delete mainPanel
;