2 #include <KConfigGroup>
6 #include <QButtonGroup>
10 #include "FingerManagerWindow.h"
11 #include "FMDbusConn.h"
12 #include "FingerNames.h"
16 void FingerManagerWindow::fingerSelected(int idx
) {
17 qDebug("fingers[%d]: %d", idx
, fingers
[idx
]->isChecked());
20 QCheckBox
* FingerManagerWindow::createCheckBox(int idx
, int x
, int y
) {
21 QCheckBox
*cb
= new QCheckBox(this);
22 QSize size
= cb
->sizeHint();
23 cb
->setGeometry(QRect(x
- (size
.width()/2),
24 y_base
+ y
- (size
.height()/2),
27 cb
->setWhatsThis(i18n(fingerNames
[idx
]));
28 btng
->addButton(cb
, idx
);
32 void FingerManagerWindow::load(KConfig
*settings
) {
34 KConfigGroup cfgGroup
;
37 cfgGroup
= settings
->group("image");
38 y_base
= cfgGroup
.readEntry("base", 20);
40 QString filename
= cfgGroup
.readEntry("filename", "/home/djaara/.config/djaara.net/hands.png");
41 cfgGroup
.writeEntry("filename", "/home/djaara/.config/djaara.net/hands.png");
42 QPixmap image
= QPixmap(filename
);
43 if (!image
.isNull()) {
44 handsLabel
->setPixmap(image
);
46 handsLabel
->setText("File not found: " + filename
);
48 handsLabel
->setGeometry(QRect(0, y_base
, image
.width(), image
.height()));
51 cfgGroup
= settings
->group("fingers");
52 fingersCount
= cfgGroup
.readEntry("count", 0);
53 for (int i
= 0; i
< fingersCount
&& i
< MAX_FINGERS
; i
++) {
56 name
.sprintf("%d/x", i
+1);
57 int x
= cfgGroup
.readEntry(name
, 0);
59 name
.sprintf("%d/y", i
+1);
60 int y
= cfgGroup
.readEntry(name
, 0);
62 name
.sprintf("%d/idx", i
+1);
63 unsigned int idx
= cfgGroup
.readEntry(name
, i
);
65 if (x
&& y
&& idx
< MAX_FINGERS
) {
66 qDebug("Adding new checkbox[%d]", idx
);
67 fingers
[idx
] = createCheckBox(idx
, x
, y
);
69 qDebug("Checkbox[%d] skipped", idx
);
76 FingerManagerWindow::FingerManagerWindow(QWidget
*parent
,
77 Qt::WindowFlags wflags
) : KDialog(parent
, wflags
) {
78 // No OK or Cancel buttons
79 setButtons(KDialog::None
);
82 setWindowTitle("Finger manager...");
84 setWhatsThis(i18n("Finger Manager Application"));
90 // Handle all check buttons
91 btng
->setExclusive(false);
92 QObject::connect(btng
, SIGNAL(buttonClicked(int)), SLOT(fingerSelected(int)));
95 setMinimumWidth(handsLabel
->width());
96 setMinimumHeight(handsLabel
->height());
97 setMaximumWidth(handsLabel
->width());
98 setMaximumHeight(handsLabel
->height());
104 * void initComponents()
105 * Initialize main components of FingerManagerWindow
107 void FingerManagerWindow::initComponents() {
108 btng
= new QButtonGroup(this);
109 settings
= new KConfig("kfingerrc");
110 handsLabel
= new QLabel(this);
113 FingerManagerWindow::~FingerManagerWindow() {
114 for (int i
= 0; i
< fingersCount
; i
++) {
115 if (fingers
[i
]) delete fingers
[i
];
117 if (settings
) delete settings
;
118 if (btng
) delete btng
;
119 if (handsLabel
) delete handsLabel
;