Skip to content

Commit

Permalink
[SquashMe] use default QCheckBox instead of custom image
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#8550
Rebased-From: 251ee28
  • Loading branch information
jonasschnelli authored and luke-jr committed Dec 21, 2016
1 parent 71bfbf0 commit 67c1eb8
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 85 deletions.
4 changes: 0 additions & 4 deletions src/Makefile.qt.include
Expand Up @@ -245,10 +245,6 @@ RES_ICONS = \
qt/res/icons/bitcoin.ico \
qt/res/icons/bitcoin_testnet.ico \
qt/res/icons/bitcoin.png \
qt/res/icons/button_off.png \
qt/res/icons/button_on_blue.png \
qt/res/icons/button_on_green.png \
qt/res/icons/button_on_red.png \
qt/res/icons/chart.png \
qt/res/icons/chevron.png \
qt/res/icons/clock1.png \
Expand Down
4 changes: 0 additions & 4 deletions src/qt/bitcoin.qrc
Expand Up @@ -50,10 +50,6 @@
<file alias="fontsmaller">res/icons/fontsmaller.png</file>
<file alias="prompticon">res/icons/chevron.png</file>
<file alias="transaction_abandoned">res/icons/transaction_abandoned.png</file>
<file alias="button_on_blue">res/icons/button_on_blue.png</file>
<file alias="button_on_red">res/icons/button_on_red.png</file>
<file alias="button_on_green">res/icons/button_on_green.png</file>
<file alias="button_off">res/icons/button_off.png</file>
<file alias="chart">res/icons/chart.png</file>
</qresource>
<qresource prefix="/movies">
Expand Down
92 changes: 32 additions & 60 deletions src/qt/mempoolstats.cpp
Expand Up @@ -26,8 +26,6 @@ static const int GRAPH_PADDING_TOP_LABEL = 150;
static const int GRAPH_PADDING_BOTTOM = 50;
static const int LABEL_HEIGHT = 15;

static QSize buttonSize(30,14);

void ClickableTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_EMIT objectClicked(this);
Expand All @@ -41,19 +39,6 @@ void ClickableTextItem::setEnabled(bool state)
setDefaultTextColor(QColor(100,100,100, 200));
}

void ClickableSwitchItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_EMIT objectClicked(this);
}

void ClickableSwitchItem::setState(bool state)
{
if (state)
setPixmap(QIcon(QString::fromStdString(":/icons/button_on_"+iconPrefix)).pixmap(buttonSize));
else
setPixmap(QIcon(":/icons/button_off").pixmap(buttonSize));
}

MempoolStats::MempoolStats(QWidget *parent) :
QWidget(parent, Qt::Window),
clientModel(0),
Expand Down Expand Up @@ -98,37 +83,39 @@ void MempoolStats::drawChart()
if (!isVisible())
return;

QGraphicsProxyWidget *proxyW;
if (!titleItem)
{
// create labels (only once)
titleItem = scene->addText(tr("Mempool Statistics"));
titleItem->setFont(QFont(LABEL_FONT, LABEL_TITLE_SIZE, QFont::Light));
titleLine = scene->addLine(0,0,100,100);
titleLine->setPen(QPen(QColor(100,100,100, 200), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
dynMemUsageSwitch = new ClickableSwitchItem();
scene->addItem(dynMemUsageSwitch);
dynMemUsageSwitch->iconPrefix = "blue";
connect(dynMemUsageSwitch, SIGNAL(objectClicked(QGraphicsItem*)), this, SLOT(objectClicked(QGraphicsItem*)));
dynMemUsageItem = scene->addText(tr("Dynamic Memory Usage"));
dynMemUsageItem->setFont(QFont(LABEL_FONT, LABEL_KV_SIZE, QFont::Light));


QCheckBox *cb0 = new QCheckBox("Dynamic Memory Usage");
cb0->setStyleSheet("background-color: rgb(255,255,255);");
dynMemUsageSwitch = scene->addWidget(cb0);
connect(cb0, &QCheckBox::stateChanged, [cb0, this](){ drawDynMemUsage = cb0->isChecked(); drawChart(); });
cb0->setFont(QFont(LABEL_FONT, LABEL_KV_SIZE, QFont::Light));
dynMemUsageValueItem = scene->addText("N/A");
dynMemUsageValueItem->setFont(QFont(LABEL_FONT, LABEL_KV_SIZE, QFont::Bold));

txCountSwitch = new ClickableSwitchItem();
QCheckBox *cb1 = new QCheckBox("Amount of Transactions");
cb1->setStyleSheet("background-color: rgb(255,255,255);");
txCountSwitch = scene->addWidget(cb1);
scene->addItem(txCountSwitch);
txCountSwitch->iconPrefix = "red";
connect(txCountSwitch, SIGNAL(objectClicked(QGraphicsItem*)), this, SLOT(objectClicked(QGraphicsItem*)));
txCountItem = scene->addText("Amount of Transactions");
txCountItem->setFont(QFont(LABEL_FONT, LABEL_KV_SIZE, QFont::Light));
connect(cb1, &QCheckBox::stateChanged, [cb1, this](){ drawTxCount = cb1->isChecked(); drawChart(); });
cb1->setFont(QFont(LABEL_FONT, LABEL_KV_SIZE, QFont::Light));
txCountValueItem = scene->addText("N/A");
txCountValueItem->setFont(QFont(LABEL_FONT, LABEL_KV_SIZE, QFont::Bold));

minFeeSwitch = new ClickableSwitchItem();
minFeeSwitch->iconPrefix = "green";
QCheckBox *cb2 = new QCheckBox("MinRelayFee per KB");
cb2->setStyleSheet("background-color: rgb(255,255,255);");
minFeeSwitch = scene->addWidget(cb2);
scene->addItem(minFeeSwitch);
connect(minFeeSwitch, SIGNAL(objectClicked(QGraphicsItem*)), this, SLOT(objectClicked(QGraphicsItem*)));
minFeeItem = scene->addText(tr("MinRelayFee per KB"));
minFeeItem->setFont(QFont(LABEL_FONT, LABEL_KV_SIZE, QFont::Light));
connect(cb2, &QCheckBox::stateChanged, [cb2, this](){ drawMinFee = cb2->isChecked(); drawChart(); });
cb2->setFont(QFont(LABEL_FONT, LABEL_KV_SIZE, QFont::Light));
minFeeValueItem = scene->addText(tr("N/A"));
minFeeValueItem->setFont(QFont(LABEL_FONT, LABEL_KV_SIZE, QFont::Bold));

Expand All @@ -155,9 +142,9 @@ void MempoolStats::drawChart()
}

// set button states
dynMemUsageSwitch->setState(drawDynMemUsage);
txCountSwitch->setState(drawTxCount);
minFeeSwitch->setState(drawMinFee);
((QCheckBox *)dynMemUsageSwitch->widget())->setChecked(drawDynMemUsage);
((QCheckBox *)txCountSwitch->widget())->setChecked(drawTxCount);
((QCheckBox *)minFeeSwitch->widget())->setChecked(drawMinFee);

last10MinLabel->setEnabled((timeFilter == TEN_MINS));
lastHourLabel->setEnabled((timeFilter == ONE_HOUR));
Expand Down Expand Up @@ -194,22 +181,19 @@ void MempoolStats::drawChart()

// set dynamic label positions
int maxValueSize = std::max(std::max(txCountValueItem->boundingRect().width(), dynMemUsageValueItem->boundingRect().width()), minFeeValueItem->boundingRect().width());
maxValueSize = ceil(maxValueSize*0.13)*10; //use size steps of 10dip
maxValueSize = ceil(maxValueSize*0.11)*10; //use size steps of 10dip

int rightPaddingLabels = std::max(std::max(dynMemUsageItem->boundingRect().width(), txCountItem->boundingRect().width()), minFeeItem->boundingRect().width())+maxValueSize;
int rightPaddingLabels = std::max(std::max(dynMemUsageSwitch->boundingRect().width(), txCountSwitch->boundingRect().width()), minFeeSwitch->boundingRect().width())+maxValueSize;
int rightPadding = 10;
dynMemUsageItem->setPos(width()-rightPaddingLabels-rightPadding, dynMemUsageItem->pos().y());
dynMemUsageSwitch->setPos(dynMemUsageItem->pos().x()-buttonSize.width(), dynMemUsageItem->pos().y()+dynMemUsageSwitch->boundingRect().height()/3.0);

txCountItem->setPos(width()-rightPaddingLabels-rightPadding, dynMemUsageItem->pos().y()+dynMemUsageItem->boundingRect().height());
txCountSwitch->setPos(txCountItem->pos().x()-buttonSize.width(), txCountItem->pos().y()+txCountSwitch->boundingRect().height()/3.0);

minFeeItem->setPos(width()-rightPaddingLabels-rightPadding, dynMemUsageItem->pos().y()+dynMemUsageItem->boundingRect().height()+txCountItem->boundingRect().height());
minFeeSwitch->setPos(minFeeItem->pos().x()-buttonSize.width(), minFeeItem->pos().y()+minFeeSwitch->boundingRect().height()/3.0);
dynMemUsageSwitch->setPos(width()-rightPaddingLabels-rightPadding, 5);

txCountSwitch->setPos(width()-rightPaddingLabels-rightPadding, dynMemUsageSwitch->pos().y()+dynMemUsageSwitch->boundingRect().height());

minFeeSwitch->setPos(width()-rightPaddingLabels-rightPadding, txCountSwitch->pos().y()+txCountSwitch->boundingRect().height());

dynMemUsageValueItem->setPos(width()-dynMemUsageValueItem->boundingRect().width()-rightPadding, dynMemUsageItem->pos().y());
txCountValueItem->setPos(width()-txCountValueItem->boundingRect().width()-rightPadding, txCountItem->pos().y());
minFeeValueItem->setPos(width()-minFeeValueItem->boundingRect().width()-rightPadding, minFeeItem->pos().y());
dynMemUsageValueItem->setPos(width()-dynMemUsageValueItem->boundingRect().width()-rightPadding, dynMemUsageSwitch->pos().y());
txCountValueItem->setPos(width()-txCountValueItem->boundingRect().width()-rightPadding, txCountSwitch->pos().y());
minFeeValueItem->setPos(width()-minFeeValueItem->boundingRect().width()-rightPadding, minFeeSwitch->pos().y());

titleItem->setPos(5,minFeeSwitch->pos().y()+minFeeSwitch->boundingRect().height()-titleItem->boundingRect().height()+10);
titleLine->setLine(10, titleItem->pos().y()+titleItem->boundingRect().height(), width()-10, titleItem->pos().y()+titleItem->boundingRect().height());
Expand Down Expand Up @@ -396,15 +380,6 @@ void MempoolStats::showEvent(QShowEvent *event)

void MempoolStats::objectClicked(QGraphicsItem *item)
{
if (item == dynMemUsageSwitch)
drawDynMemUsage = !drawDynMemUsage;

if (item == txCountSwitch)
drawTxCount = !drawTxCount;

if (item == minFeeSwitch)
drawMinFee = !drawMinFee;

if (item == last10MinLabel)
timeFilter = 600;

Expand Down Expand Up @@ -434,11 +409,8 @@ MempoolStats::~MempoolStats()
delete titleItem;
delete titleLine;
delete noDataItem;
delete dynMemUsageItem;
delete dynMemUsageValueItem;
delete txCountItem;
delete txCountValueItem;
delete minFeeItem;
delete minFeeValueItem;
delete last10MinLabel;
delete lastHourLabel;
Expand All @@ -449,4 +421,4 @@ MempoolStats::~MempoolStats()
delete dynMemUsageSwitch;
delete scene;
}
}
}
22 changes: 5 additions & 17 deletions src/qt/mempoolstats.h
Expand Up @@ -9,6 +9,8 @@
#include <QGraphicsLineItem>
#include <QGraphicsPixmapItem>

#include <QCheckBox>
#include <QGraphicsProxyWidget>

#include <QEvent>

Expand All @@ -25,17 +27,6 @@ class ClickableTextItem : public QGraphicsTextItem
void objectClicked(QGraphicsItem*);
};

class ClickableSwitchItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
public:
std::string iconPrefix;
void setState(bool state);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
Q_SIGNALS:
void objectClicked(QGraphicsItem*);
};

namespace Ui {
class MempoolStats;
Expand Down Expand Up @@ -65,21 +56,18 @@ public Q_SLOTS:
QGraphicsLineItem *titleLine;
QGraphicsTextItem *noDataItem;

QGraphicsTextItem *dynMemUsageItem;
QGraphicsTextItem *dynMemUsageValueItem;
QGraphicsTextItem *txCountItem;
QGraphicsTextItem *txCountValueItem;
QGraphicsTextItem *minFeeItem;
QGraphicsTextItem *minFeeValueItem;

ClickableTextItem *last10MinLabel;
ClickableTextItem *lastHourLabel;
ClickableTextItem *lastDayLabel;
ClickableTextItem *allDataLabel;

ClickableSwitchItem *txCountSwitch;
ClickableSwitchItem *minFeeSwitch;
ClickableSwitchItem *dynMemUsageSwitch;
QGraphicsProxyWidget *txCountSwitch;
QGraphicsProxyWidget *minFeeSwitch;
QGraphicsProxyWidget *dynMemUsageSwitch;

QGraphicsScene *scene;
QVector<QGraphicsItem*> redrawItems;
Expand Down
Binary file removed src/qt/res/icons/button_off.png
Binary file not shown.
Binary file removed src/qt/res/icons/button_on_blue.png
Binary file not shown.
Binary file removed src/qt/res/icons/button_on_green.png
Binary file not shown.
Binary file removed src/qt/res/icons/button_on_red.png
Binary file not shown.

0 comments on commit 67c1eb8

Please sign in to comment.