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