signalbar.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * wpa_gui - SignalBar class
  3. * Copyright (c) 2011, Kel Modderman <kel@otaku42.de>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include <cstdio>
  9. #include <qapplication.h>
  10. #include "signalbar.h"
  11. SignalBar::SignalBar(QObject *parent)
  12. : QStyledItemDelegate(parent)
  13. {
  14. }
  15. SignalBar::~SignalBar()
  16. {
  17. }
  18. void SignalBar::paint(QPainter *painter,
  19. const QStyleOptionViewItem &option,
  20. const QModelIndex &index) const
  21. {
  22. QStyleOptionProgressBar opts;
  23. int signal;
  24. if (index.column() != 3) {
  25. QStyledItemDelegate::paint(painter, option, index);
  26. return;
  27. }
  28. if (index.data().toInt() > 0)
  29. signal = 0 - (256 - index.data().toInt());
  30. else
  31. signal = index.data().toInt();
  32. opts.minimum = -95;
  33. opts.maximum = -35;
  34. if (signal < opts.minimum)
  35. opts.progress = opts.minimum;
  36. else if (signal > opts.maximum)
  37. opts.progress = opts.maximum;
  38. else
  39. opts.progress = signal;
  40. opts.text = QString::number(signal) + " dBm";
  41. opts.textVisible = true;
  42. opts.rect = option.rect;
  43. QApplication::style()->drawControl(QStyle::CE_ProgressBar,
  44. &opts, painter);
  45. }