signalbar.cpp 1.3 KB

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