Connected IrCtrl to MainWidget
[irwi] / src / mainwidget.cpp
index cb0f2c3..c4b635a 100644 (file)
@@ -1,4 +1,5 @@
 #include "mainwidget.h"
+#include "settingsdlg.h"
 
 #include <QInputDialog>
 #include <QPainter>
@@ -6,8 +7,6 @@
 #include <QToolButton>
 #include <QSettings>
 
-#include "settingsdlg.h"
-
 MainWidget::MainWidget (QWidget *parent)
     : QWidget(parent)
 {
@@ -24,8 +23,7 @@ MainWidget::MainWidget (QWidget *parent)
         "/usr/share/icons/hicolor/48x48/hildon/statusarea_volume_mute.png"
     };
 
-    for (int i = 0; i < BUTTON_COUNT; ++i)
-    {
+    for (int i = 0; i < BUTTON_COUNT; ++i) {
         QToolButton *button = new QToolButton(this);
         button->setIcon(QIcon(QString(
             settings->value(QString("buttonIcon") + QString::number(i),
@@ -36,18 +34,18 @@ MainWidget::MainWidget (QWidget *parent)
         layout->addWidget(button, i%2, i/2);
     }
 
-    connect(buttons[0], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd0()));
-    connect(buttons[1], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd1()));
-    connect(buttons[2], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd2()));
-    connect(buttons[3], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd3()));
-    connect(buttons[4], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd4()));
-    connect(buttons[5], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd5()));
+    connect(buttons[0], SIGNAL(clicked()), this, SLOT(sendCmdVolUp()));
+    connect(buttons[1], SIGNAL(clicked()), this, SLOT(sendCmdVolDown()));
+    connect(buttons[2], SIGNAL(clicked()), this, SLOT(sendCmdChUp()));
+    connect(buttons[3], SIGNAL(clicked()), this, SLOT(sendCmdChDown()));
+    connect(buttons[4], SIGNAL(clicked()), this, SLOT(sendCmdPower()));
+    connect(buttons[5], SIGNAL(clicked()), this, SLOT(sendCmdMute()));
 
-    this->setContentsMargins(0, 0, 0, 0);
+    setContentsMargins(0, 0, 0, 0);
     layout->setContentsMargins(0, 0, 0, 0);
-    this->setLayout(layout);
-    this->setAttribute(Qt::WA_TranslucentBackground);
-    this->setAttribute(Qt::WA_OpaquePaintEvent);
+    setLayout(layout);
+    setAttribute(Qt::WA_TranslucentBackground);
+    setAttribute(Qt::WA_OpaquePaintEvent);
     resize();
 }
 
@@ -56,6 +54,36 @@ MainWidget::~MainWidget()
     delete settings;
 }
 
+void MainWidget::sendCmdVolUp()
+{
+    irCtrl.sendCmd(settings->value("volUpCmd", "VOLUP").toString());
+}
+
+void MainWidget::sendCmdVolDown()
+{
+    irCtrl.sendCmd(settings->value("volDownCmd", "VOLDOWN").toString());
+}
+
+void MainWidget::sendCmdChUp()
+{
+    irCtrl.sendCmd(settings->value("chUpCmd", "CHUP").toString());
+}
+
+void MainWidget::sendCmdChDown()
+{
+    irCtrl.sendCmd(settings->value("chDownCmd", "CHDOWN").toString());
+}
+
+void MainWidget::sendCmdPower()
+{
+    irCtrl.sendCmd(settings->value("powerCmd", "POWER").toString());
+}
+
+void MainWidget::sendCmdMute()
+{
+    irCtrl.sendCmd(settings->value("muteCmd", "MUTE").toString());
+}
+
 void MainWidget::paintEvent(QPaintEvent*)
 {
     int bgAlpha = settings->value("bgAlpha", "192").toInt();
@@ -66,7 +94,7 @@ void MainWidget::paintEvent(QPaintEvent*)
  
 void MainWidget::showSettingsDialog()
 {
-    SettingsDlg dlg;
+    SettingsDlg dlg(this);
     dlg.exec();
     update(); // Repaint required if bgAlpha value was changed
     resize();
@@ -74,7 +102,13 @@ void MainWidget::showSettingsDialog()
 
 void MainWidget::resize()
 {
-    QWidget::resize(settings->value("width", "250").toInt(),
-                    settings->value("height", "148").toInt());
+    int w = settings->value("width", "250").toInt();
+    int h = settings->value("height", "148").toInt();
+    if (w < 1)
+        w = 250;
+    if (h < 1)
+        h = 148;
+    QWidget::resize(w, h);
 }
 
+