2 #include <KConfigGroup>
6 #include <QButtonGroup>
9 #include "FingerManagerWindow.h"
10 #include "FMDbusConn.h"
11 #include "FingerNames.h"
15 void FingerManagerWindow::fingerSelected(int idx
) {
16 qDebug() << "fingers[" <<idx
<< "]: " << fingers
[idx
]->isChecked();
19 QCheckBox
* FingerManagerWindow::createCheckBox(int idx
, int x
, int y
) {
20 QCheckBox
*cb
= new QCheckBox(this);
21 QSize size
= cb
->sizeHint();
22 cb
->setGeometry(QRect(x
- (size
.width()/2),
23 y_base
+ y
- (size
.height()/2),
26 cb
->setWhatsThis(i18n(fingerNames
[idx
]));
27 btng
->addButton(cb
, idx
);
31 void FingerManagerWindow::load(KConfig
*settings
) {
33 KConfigGroup cfgGroup
;
36 cfgGroup
= settings
->group("image");
37 y_base
= cfgGroup
.readEntry("base", 20);
39 QString filename
= cfgGroup
.readEntry("filename", "/home/djaara/.config/djaara.net/hands.png");
40 cfgGroup
.writeEntry("filename", "/home/djaara/.config/djaara.net/hands.png");
41 QPixmap image
= QPixmap(filename
);
42 if (!image
.isNull()) {
43 handsLabel
->setPixmap(image
);
45 handsLabel
->setText("File not found: " + filename
);
47 handsLabel
->setGeometry(QRect(0, y_base
, image
.width(), image
.height()));
50 cfgGroup
= settings
->group("fingers");
51 fingersCount
= cfgGroup
.readEntry("count", 0);
52 for (int i
= 0; i
< fingersCount
&& i
< MAX_FINGERS
; i
++) {
55 name
.sprintf("%d/x", i
+1);
56 int x
= cfgGroup
.readEntry(name
, 0);
58 name
.sprintf("%d/y", i
+1);
59 int y
= cfgGroup
.readEntry(name
, 0);
61 name
.sprintf("%d/idx", i
+1);
62 unsigned int idx
= cfgGroup
.readEntry(name
, i
);
64 if (x
&& y
&& idx
< MAX_FINGERS
) {
65 qDebug() << "Adding new checkbox[" << idx
<< "]";
66 fingers
[idx
] = createCheckBox(idx
, x
, y
);
68 qDebug() << "Checkbox[" << idx
<< "] skipped";
75 FingerManagerWindow::FingerManagerWindow(QWidget
*parent
,
76 Qt::WindowFlags wflags
) : KDialog(parent
, wflags
) {
77 // No OK or Cancel buttons
78 setButtons(KDialog::None
);
81 setWindowTitle("Finger manager...");
83 setWhatsThis(i18n("Finger Manager Application"));
89 // Handle all check buttons
90 btng
->setExclusive(false);
91 QObject::connect(btng
, SIGNAL(buttonClicked(int)), SLOT(fingerSelected(int)));
94 setMinimumWidth(handsLabel
->width());
95 setMinimumHeight(handsLabel
->height());
96 setMaximumWidth(handsLabel
->width());
97 setMaximumHeight(handsLabel
->height());
103 * void initComponents()
104 * Initialize main components of FingerManagerWindow
106 void FingerManagerWindow::initComponents() {
107 btng
= new QButtonGroup(this);
108 settings
= new KConfig("kfingerrc");
109 handsLabel
= new QLabel(this);
112 FingerManagerWindow::~FingerManagerWindow() {
113 for (int i
= 0; i
< fingersCount
; i
++) {
114 if (fingers
[i
]) delete fingers
[i
];
116 if (settings
) delete settings
;
117 if (btng
) delete btng
;
118 if (handsLabel
) delete handsLabel
;