Fixed mainwidget.cpp
[irwi] / src / mainwidget.cpp
index 3b34f1b..76c6231 100644 (file)
@@ -4,6 +4,7 @@
 #include <QPainter>
 #include <QGridLayout>
 #include <QToolButton>
+#include <QSettings>
 
 #include "settingsdlg.h"
 
@@ -12,7 +13,9 @@ MainWidget::MainWidget (QWidget *parent)
 {
     layout = new QGridLayout(this);
 
-    char *iconNames[] = {
+    settings = new QSettings(this);
+
+    char iconNames[][128] = {
         "/usr/share/icons/hicolor/48x48/hildon/statusarea_volumelevel4.png",
         "/usr/share/icons/hicolor/48x48/hildon/statusarea_volumelevel1.png",
         "/usr/share/icons/hicolor/48x48/hildon/rss_reader_move_up.png",
@@ -21,53 +24,51 @@ MainWidget::MainWidget (QWidget *parent)
         "/usr/share/icons/hicolor/48x48/hildon/statusarea_volume_mute.png"
     };
 
-    char *buttonTitles[] = {
-        "Vol Up",
-        "Vol Down",
-        "Ch Up",
-        "Ch Down",
-        "Power Off",
-        "Mute"
-    };
-
     for (int i = 0; i < BUTTON_COUNT; ++i)
     {
         QToolButton *button = new QToolButton(this);
-        button->setIcon(QIcon(QString(iconNames[i]))); 
+        button->setIcon(QIcon(QString(
+            settings->value(QString("buttonIcon") + QString::number(i),
+                iconNames[i]).toString()))); 
         buttons[i] = button;
-        button->setPalette(QPalette(QColor(0, 0, 0, 192)));
         layout->addWidget(button, i%2, i/2);
     }
 
-    connect(buttons[0], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd0(bool)));
-    connect(buttons[1], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd1(bool)));
-    connect(buttons[2], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd2(bool)));
-    connect(buttons[3], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd3(bool)));
-    connect(buttons[4], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd4(bool)));
-    connect(buttons[5], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd5(bool)));
+    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()));
 
     this->setContentsMargins(0, 0, 0, 0);
     layout->setContentsMargins(0, 0, 0, 0);
     this->setLayout(layout);
     this->setAttribute(Qt::WA_TranslucentBackground);
+    this->setAttribute(Qt::WA_OpaquePaintEvent);
+}
+
+MainWidget::~MainWidget()
+{
+    delete settings;
 }
 
- void MainWidget::paintEvent(QPaintEvent *event)
- {
-     QPainter p(this);
-     p.setBrush(QColor(0, 0, 0, 128));
-     p.setPen(Qt::NoPen);
-     p.drawRoundRect(rect(), 0, 0);
-     p.end();
- }
+void MainWidget::paintEvent(QPaintEvent*)
+{
+    int bgAlpha = settings->value("bgAlpha", "192").toInt();
+    QPainter p(this);
+    p.setBrush(QColor(0, 0, 0, bgAlpha));
+    p.setPen(Qt::NoPen);
+    p.drawRect(rect());
+    p.end();
+}
  
 void MainWidget::showSettingsDialog()
 {
-    SettingsDlg dlg(this);
-    if (dlg.exec() == QDialog::Accepted)
-    {
-        irCtrl.setRemoteName(dlg.getRemoteName());
-    }
+    SettingsDlg dlg;
+    dlg.exec();
+    update(); // Repaint required if bgAlpha value was changed
 }
 
 
+