aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/wpa_gui-qt4/signalbar.cpp
blob: 2bba582175e53fe90918d4b035533924873c311d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * wpa_gui - SignalBar class
 * Copyright (c) 2011, Kel Modderman <kel@otaku42.de>
 *
 * This software may be distributed under the terms of the BSD license.
 * See README for more details.
 */

#include <cstdio>
#include <qapplication.h>

#include "signalbar.h"


SignalBar::SignalBar(QObject *parent)
	: QStyledItemDelegate(parent)
{
}


SignalBar::~SignalBar()
{
}


void SignalBar::paint(QPainter *painter,
		      const QStyleOptionViewItem &option,
		      const QModelIndex &index) const
{
	QStyleOptionProgressBar opts;
	int signal;

	if (index.column() != 3) {
		QStyledItemDelegate::paint(painter, option, index);
		return;
	}

	if (index.data().toInt() > 0)
		signal = 0 - (256 - index.data().toInt());
	else
		signal = index.data().toInt();

	opts.minimum = -95;
	opts.maximum = -35;
	if (signal < opts.minimum)
		opts.progress = opts.minimum;
	else if (signal > opts.maximum)
		opts.progress = opts.maximum;
	else
		opts.progress = signal;

	opts.text = QString::number(signal) + " dBm";
	opts.textVisible = true;
	opts.rect = option.rect;

	QApplication::style()->drawControl(QStyle::CE_ProgressBar,
					   &opts, painter);
}