signalbar.cpp revision 1f69aa52ea2e0a73ac502565df8c666ee49cab6a
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 15#include <cstdio> 16#include <qapplication.h> 17 18#include "signalbar.h" 19 20 21SignalBar::SignalBar(QObject *parent) 22 : QStyledItemDelegate(parent) 23{ 24} 25 26 27SignalBar::~SignalBar() 28{ 29} 30 31 32void SignalBar::paint(QPainter *painter, 33 const QStyleOptionViewItem &option, 34 const QModelIndex &index) const 35{ 36 QStyleOptionProgressBar opts; 37 int signal; 38 39 if (index.column() != 3) { 40 QStyledItemDelegate::paint(painter, option, index); 41 return; 42 } 43 44 if (index.data().toInt() > 0) 45 signal = 0 - (256 - index.data().toInt()); 46 else 47 signal = index.data().toInt(); 48 49 opts.minimum = -95; 50 opts.maximum = -35; 51 if (signal < opts.minimum) 52 opts.progress = opts.minimum; 53 else if (signal > opts.maximum) 54 opts.progress = opts.maximum; 55 else 56 opts.progress = signal; 57 58 opts.text = QString::number(signal) + " dBm"; 59 opts.textVisible = true; 60 opts.rect = option.rect; 61 62 QApplication::style()->drawControl(QStyle::CE_ProgressBar, 63 &opts, painter); 64} 65