2011-11-19 19:10:37 +01:00
|
|
|
/*
|
|
|
|
* wpa_gui - SignalBar class
|
|
|
|
* Copyright (c) 2011, Kel Modderman <kel@otaku42.de>
|
|
|
|
*
|
2012-07-02 19:48:24 +02:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2011-11-19 19:10:37 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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);
|
|
|
|
}
|