Skip to content

Commit

Permalink
Fixing lock icon view in coincontrol (#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
firstcryptoman authored and levonpetrosyan93 committed May 17, 2023
1 parent 3d0c3fc commit 202ae26
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void CoinControlDialog::lockCoin()
COutPoint outpt(uint256S(contextMenuItem->text(COLUMN_TXHASH).toStdString()), contextMenuItem->text(COLUMN_VOUT_INDEX).toUInt());
model->lockCoin(outpt);
contextMenuItem->setDisabled(true);
contextMenuItem->setIcon(COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed"));
contextMenuItem->setIcon(COLUMN_CHECKBOX, platformStyle->LockIcon(":/icons/lock_closed"));
updateLabelLocked();
}

Expand Down Expand Up @@ -778,7 +778,7 @@ void CoinControlDialog::updateView()
COutPoint outpt(txhash, out.i);
coinControl->UnSelect(outpt); // just to be sure
itemOutput->setDisabled(true);
itemOutput->setIcon(COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed"));
itemOutput->setIcon(COLUMN_CHECKBOX, platformStyle->LockIcon(":/icons/lock_closed"));
}

// set checkbox
Expand Down
33 changes: 33 additions & 0 deletions src/qt/platformstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ void MakeSingleColorImage(QImage& img, const QColor& colorbase)
}
}

void MakeLockColorImage(QImage& img, const QColor& colorbase)
{
img = img.convertToFormat(QImage::Format_ARGB32);
for (int x = img.width(); x--; )
{
for (int y = img.height(); y--; )
{
const QRgb rgb = img.pixel(x, y);
img.setPixel(x, y, qRgba(colorbase.red(), colorbase.green(), colorbase.blue(), qAlpha(rgb)));
}
}
}

QIcon ColorizeIcon(const QIcon& ico, const QColor& colorbase)
{
QIcon new_ico;
Expand All @@ -59,18 +72,31 @@ QIcon ColorizeIcon(const QIcon& ico, const QColor& colorbase)
return new_ico;
}


QImage ColorizeImage(const QString& filename, const QColor& colorbase)
{
QImage img(filename);
MakeSingleColorImage(img, colorbase);
return img;
}

QImage ColorizeLockImage(const QString& filename, const QColor& colorbase)
{
QImage img(filename);
MakeLockColorImage(img, colorbase);
return img;
}

QIcon ColorizeIcon(const QString& filename, const QColor& colorbase)
{
return QIcon(QPixmap::fromImage(ColorizeImage(filename, colorbase)));
}

QIcon ColorizeLockIcon(const QString& filename, const QColor& colorbase)
{
return QIcon(QPixmap::fromImage(ColorizeLockImage(filename, colorbase)));
}

}


Expand Down Expand Up @@ -120,6 +146,13 @@ QIcon PlatformStyle::SingleColorIcon(const QIcon& icon) const
return ColorizeIcon(icon, SingleColor());
}

QIcon PlatformStyle::LockIcon(const QString& filename) const
{
if (!colorizeIcons)
return QIcon(filename);
return ColorizeLockIcon(filename, SingleColor());
}

QIcon PlatformStyle::TextColorIcon(const QString& filename) const
{
return ColorizeIcon(filename, TextColor());
Expand Down
3 changes: 3 additions & 0 deletions src/qt/platformstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class PlatformStyle
/** Colorize an icon (given object) with the text color */
QIcon TextColorIcon(const QIcon& icon) const;

/** Coincontrol lock icon */
QIcon LockIcon(const QString& filename) const;

private:
PlatformStyle(const QString &name, bool imagesOnButtons, bool colorizeIcons, bool useExtraSpacing);

Expand Down

0 comments on commit 202ae26

Please sign in to comment.