Fixed mainwidget.cpp
[irwi] / src / mainwidget.cpp
index 4425f5b..76c6231 100644 (file)
@@ -1,8 +1,10 @@
 #include "mainwidget.h"
 
-#include <QtGui/qinputdialog.h>
+#include <QInputDialog>
+#include <QPainter>
 #include <QGridLayout>
-#include <QPushButton>
+#include <QToolButton>
+#include <QSettings>
 
 #include "settingsdlg.h"
 
@@ -11,50 +13,62 @@ 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/statusarea_volumelevel3.png",
-        "/usr/share/icons/hicolor/48x48/hildon/rss_move_up.png",
-        "/usr/share/icons/hicolor/48x48/hildon/rss_move_down.png",
+        "/usr/share/icons/hicolor/48x48/hildon/rss_reader_move_up.png",
+        "/usr/share/icons/hicolor/48x48/hildon/rss_reader_move_down.png",
         "/usr/share/icons/hicolor/48x48/hildon/location_applet_on.png",
         "/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)
     {
-        QPushButton *button = new QPushButton(
-                QIcon(QString(iconNames[i])), 
-                QString(buttonTitles[i]), this);
+        QToolButton *button = new QToolButton(this);
+        button->setIcon(QIcon(QString(
+            settings->value(QString("buttonIcon") + QString::number(i),
+                iconNames[i]).toString()))); 
         buttons[i] = button;
         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*)
+{
+    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
 }
 
 
+