First commit
[hidecallerid] / src / idwidget.cpp
diff --git a/src/idwidget.cpp b/src/idwidget.cpp
new file mode 100644 (file)
index 0000000..08fac3f
--- /dev/null
@@ -0,0 +1,42 @@
+#include "idwidget.h"
+
+IdWidget::IdWidget(tpSession *tp)
+    : QPushButton()
+{
+    this->tp = tp;
+    setAttribute(Qt::WA_TranslucentBackground);
+    QObject::connect(this, SIGNAL(clicked()), this, SLOT(changeState()));
+    QObject::connect(tp, SIGNAL(privacyUpdated(bool)), this, SLOT(setButtonState(bool)));
+    pHidden = new QPixmap(":/icons/hidden.png");
+    pShown = new QPixmap(":/icons/shown.png");
+}
+
+void IdWidget::setButtonState(bool showId)
+{
+    QPixmap *pixmap;
+    this->showId = showId;
+
+    if(showId) {
+        pixmap = pShown;
+        setText("Id Shown");
+    }
+    else {
+        pixmap = pHidden;
+        setText("Id Hidden");
+    }
+
+    QIcon icon(*pixmap);
+    QSize iconSize(pixmap->width(), pixmap->height());
+    setIconSize(iconSize);
+    setIcon(icon);
+}
+
+void IdWidget::changeState()
+{
+    if(showId) {
+        tp->setPrivacy(false);
+    }
+    else {
+        tp->setPrivacy(true);
+    }
+}