Browse Source

qt: Introduce PlatformStyle

Introduce a PlatformStyle to handle platform-specific customization of
the UI.

This replaces 'scicon', as well as #ifdefs to determine whether to place
icons on buttons.

The selected PlatformStyle defaults to the platform that the application
was compiled on, but can be overridden from the command line with
`-uiplatform=<x>`.

Also fixes the warning from #6328.
pull/1/head
Wladimir J. van der Laan 7 years ago
parent
commit
eec7757445
  1. 4
      src/Makefile.qt.include
  2. 3
      src/init.cpp
  3. 26
      src/qt/addressbookpage.cpp
  4. 3
      src/qt/addressbookpage.h
  5. 26
      src/qt/bitcoin.cpp
  6. 69
      src/qt/bitcoingui.cpp
  7. 7
      src/qt/bitcoingui.h
  8. 11
      src/qt/coincontroldialog.cpp
  9. 5
      src/qt/coincontroldialog.h
  10. 3
      src/qt/intro.cpp
  11. 1
      src/qt/networkstyle.cpp
  12. 15
      src/qt/overviewpage.cpp
  13. 3
      src/qt/overviewpage.h
  14. 147
      src/qt/platformstyle.cpp
  15. 55
      src/qt/platformstyle.h
  16. 31
      src/qt/receivecoinsdialog.cpp
  17. 5
      src/qt/receivecoinsdialog.h
  18. 17
      src/qt/rpcconsole.cpp
  19. 4
      src/qt/rpcconsole.h
  20. 98
      src/qt/scicon.cpp
  21. 24
      src/qt/scicon.h
  22. 29
      src/qt/sendcoinsdialog.cpp
  23. 4
      src/qt/sendcoinsdialog.h
  24. 24
      src/qt/sendcoinsentry.cpp
  25. 4
      src/qt/sendcoinsentry.h
  26. 27
      src/qt/signverifymessagedialog.cpp
  27. 4
      src/qt/signverifymessagedialog.h
  28. 9
      src/qt/transactiontablemodel.cpp
  29. 4
      src/qt/transactiontablemodel.h
  30. 63
      src/qt/transactionview.cpp
  31. 3
      src/qt/transactionview.h
  32. 7
      src/qt/walletframe.cpp
  33. 5
      src/qt/walletframe.h
  34. 4
      src/qt/walletmodel.cpp
  35. 3
      src/qt/walletmodel.h
  36. 29
      src/qt/walletview.cpp
  37. 4
      src/qt/walletview.h

4
src/Makefile.qt.include

@ -185,13 +185,13 @@ BITCOIN_QT_H = \ @@ -185,13 +185,13 @@ BITCOIN_QT_H = \
qt/paymentrequestplus.h \
qt/paymentserver.h \
qt/peertablemodel.h \
qt/platformstyle.h \
qt/qvalidatedlineedit.h \
qt/qvaluecombobox.h \
qt/receivecoinsdialog.h \
qt/receiverequestdialog.h \
qt/recentrequeststablemodel.h \
qt/rpcconsole.h \
qt/scicon.h \
qt/sendcoinsdialog.h \
qt/sendcoinsentry.h \
qt/signverifymessagedialog.h \
@ -273,10 +273,10 @@ BITCOIN_QT_CPP = \ @@ -273,10 +273,10 @@ BITCOIN_QT_CPP = \
qt/optionsdialog.cpp \
qt/optionsmodel.cpp \
qt/peertablemodel.cpp \
qt/platformstyle.cpp \
qt/qvalidatedlineedit.cpp \
qt/qvaluecombobox.cpp \
qt/rpcconsole.cpp \
qt/scicon.cpp \
qt/splashscreen.cpp \
qt/trafficgraphwidget.cpp \
qt/utilitydialog.cpp

3
src/init.cpp

@ -441,6 +441,9 @@ std::string HelpMessage(HelpMessageMode mode) @@ -441,6 +441,9 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-min", _("Start minimized"));
strUsage += HelpMessageOpt("-rootcertificates=<file>", _("Set SSL root certificates for payment request (default: -system-)"));
strUsage += HelpMessageOpt("-splash", _("Show splash screen on startup (default: 1)"));
if (showDebug) {
strUsage += HelpMessageOpt("-uiplatform", "Select platform to customize UI for (one of windows, macosx, other; default: platform compiled on)");
}
}
return strUsage;

26
src/qt/addressbookpage.cpp

@ -14,14 +14,14 @@ @@ -14,14 +14,14 @@
#include "csvmodelwriter.h"
#include "editaddressdialog.h"
#include "guiutil.h"
#include "scicon.h"
#include "platformstyle.h"
#include <QIcon>
#include <QMenu>
#include <QMessageBox>
#include <QSortFilterProxyModel>
AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode mode, Tabs tab, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddressBookPage),
model(0),
@ -30,17 +30,17 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : @@ -30,17 +30,17 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
{
ui->setupUi(this);
#ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
ui->newAddress->setIcon(QIcon());
ui->copyAddress->setIcon(QIcon());
ui->deleteAddress->setIcon(QIcon());
ui->exportButton->setIcon(QIcon());
#else
ui->newAddress->setIcon(SingleColorIcon(":/icons/add"));
ui->copyAddress->setIcon(SingleColorIcon(":/icons/editcopy"));
ui->deleteAddress->setIcon(SingleColorIcon(":/icons/remove"));
ui->exportButton->setIcon(SingleColorIcon(":/icons/export"));
#endif
if (!platformStyle->getImagesOnButtons()) {
ui->newAddress->setIcon(QIcon());
ui->copyAddress->setIcon(QIcon());
ui->deleteAddress->setIcon(QIcon());
ui->exportButton->setIcon(QIcon());
} else {
ui->newAddress->setIcon(platformStyle->SingleColorIcon(":/icons/add"));
ui->copyAddress->setIcon(platformStyle->SingleColorIcon(":/icons/editcopy"));
ui->deleteAddress->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
ui->exportButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
}
switch(mode)
{

3
src/qt/addressbookpage.h

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
class AddressTableModel;
class OptionsModel;
class PlatformStyle;
namespace Ui {
class AddressBookPage;
@ -39,7 +40,7 @@ public: @@ -39,7 +40,7 @@ public:
ForEditing /**< Open address book for editing */
};
explicit AddressBookPage(Mode mode, Tabs tab, QWidget *parent);
explicit AddressBookPage(const PlatformStyle *platformStyle, Mode mode, Tabs tab, QWidget *parent);
~AddressBookPage();
void setModel(AddressTableModel *model);

26
src/qt/bitcoin.cpp

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
#include "intro.h"
#include "networkstyle.h"
#include "optionsmodel.h"
#include "platformstyle.h"
#include "splashscreen.h"
#include "utilitydialog.h"
#include "winshutdownmonitor.h"
@ -241,6 +242,7 @@ private: @@ -241,6 +242,7 @@ private:
WalletModel *walletModel;
#endif
int returnValue;
const PlatformStyle *platformStyle;
void startThread();
};
@ -310,6 +312,22 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv): @@ -310,6 +312,22 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv):
returnValue(0)
{
setQuitOnLastWindowClosed(false);
// UI per-platform customization
// This must be done inside the BitcoinApplication constructor, or after it, because
// PlatformStyle::instantiate requires a QApplication
#if defined(Q_OS_MAC)
std::string platformName = "macosx";
#elif defined(Q_OS_WIN)
std::string platformName = "windows";
#else
std::string platformName = "other";
#endif
platformName = GetArg("-uiplatform", platformName);
platformStyle = PlatformStyle::instantiate(QString::fromStdString(platformName));
if (!platformStyle) // Fall back to "other" if specified name not found
platformStyle = PlatformStyle::instantiate("other");
assert(platformStyle);
}
BitcoinApplication::~BitcoinApplication()
@ -330,6 +348,8 @@ BitcoinApplication::~BitcoinApplication() @@ -330,6 +348,8 @@ BitcoinApplication::~BitcoinApplication()
#endif
delete optionsModel;
optionsModel = 0;
delete platformStyle;
platformStyle = 0;
}
#ifdef ENABLE_WALLET
@ -346,7 +366,7 @@ void BitcoinApplication::createOptionsModel() @@ -346,7 +366,7 @@ void BitcoinApplication::createOptionsModel()
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
{
window = new BitcoinGUI(networkStyle, 0);
window = new BitcoinGUI(platformStyle, networkStyle, 0);
pollShutdownTimer = new QTimer(window);
connect(pollShutdownTimer, SIGNAL(timeout()), window, SLOT(detectShutdown()));
@ -421,6 +441,8 @@ void BitcoinApplication::initializeResult(int retval) @@ -421,6 +441,8 @@ void BitcoinApplication::initializeResult(int retval)
returnValue = retval ? 0 : 1;
if(retval)
{
// Log this only after AppInit2 finishes, as then logging setup is guaranteed complete
qWarning() << "Platform customization:" << platformStyle->getName();
#ifdef ENABLE_WALLET
PaymentServer::LoadRootCAs();
paymentServer->setOptionsModel(optionsModel);
@ -432,7 +454,7 @@ void BitcoinApplication::initializeResult(int retval) @@ -432,7 +454,7 @@ void BitcoinApplication::initializeResult(int retval)
#ifdef ENABLE_WALLET
if(pwalletMain)
{
walletModel = new WalletModel(pwalletMain, optionsModel);
walletModel = new WalletModel(platformStyle, pwalletMain, optionsModel);
window->addWallet(BitcoinGUI::DEFAULT_WALLET, walletModel);
window->setCurrentWallet(BitcoinGUI::DEFAULT_WALLET);

69
src/qt/bitcoingui.cpp

@ -13,8 +13,8 @@ @@ -13,8 +13,8 @@
#include "openuridialog.h"
#include "optionsdialog.h"
#include "optionsmodel.h"
#include "platformstyle.h"
#include "rpcconsole.h"
#include "scicon.h"
#include "utilitydialog.h"
#ifdef ENABLE_WALLET
@ -60,7 +60,7 @@ @@ -60,7 +60,7 @@
const QString BitcoinGUI::DEFAULT_WALLET = "~Default";
BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) :
BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
QMainWindow(parent),
clientModel(0),
walletFrame(0),
@ -98,7 +98,8 @@ BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) : @@ -98,7 +98,8 @@ BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) :
notificator(0),
rpcConsole(0),
prevBlocks(0),
spinnerFrame(0)
spinnerFrame(0),
platformStyle(platformStyle)
{
GUIUtil::restoreWindowGeometry("nWindow", QSize(850, 550), this);
@ -130,12 +131,12 @@ BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) : @@ -130,12 +131,12 @@ BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) :
setUnifiedTitleAndToolBarOnMac(true);
#endif
rpcConsole = new RPCConsole(0);
rpcConsole = new RPCConsole(platformStyle, 0);
#ifdef ENABLE_WALLET
if(enableWallet)
{
/** Create wallet frame and make it the central widget */
walletFrame = new WalletFrame(this);
walletFrame = new WalletFrame(platformStyle, this);
setCentralWidget(walletFrame);
} else
#endif // ENABLE_WALLET
@ -175,7 +176,7 @@ BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) : @@ -175,7 +176,7 @@ BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) :
QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
frameBlocksLayout->setContentsMargins(3,0,3,0);
frameBlocksLayout->setSpacing(3);
unitDisplayControl = new UnitDisplayStatusBarControl();
unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
labelEncryptionIcon = new QLabel();
labelConnectionsIcon = new QLabel();
labelBlocksIcon = new QLabel();
@ -247,36 +248,36 @@ void BitcoinGUI::createActions() @@ -247,36 +248,36 @@ void BitcoinGUI::createActions()
{
QActionGroup *tabGroup = new QActionGroup(this);
overviewAction = new QAction(SingleColorIcon(":/icons/overview"), tr("&Overview"), this);
overviewAction = new QAction(platformStyle->SingleColorIcon(":/icons/overview"), tr("&Overview"), this);
overviewAction->setStatusTip(tr("Show general overview of wallet"));
overviewAction->setToolTip(overviewAction->statusTip());
overviewAction->setCheckable(true);
overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
tabGroup->addAction(overviewAction);
sendCoinsAction = new QAction(SingleColorIcon(":/icons/send"), tr("&Send"), this);
sendCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/send"), tr("&Send"), this);
sendCoinsAction->setStatusTip(tr("Send coins to a Bitcoin address"));
sendCoinsAction->setToolTip(sendCoinsAction->statusTip());
sendCoinsAction->setCheckable(true);
sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
tabGroup->addAction(sendCoinsAction);
sendCoinsMenuAction = new QAction(TextColorIcon(":/icons/send"), sendCoinsAction->text(), this);
sendCoinsMenuAction = new QAction(platformStyle->TextColorIcon(":/icons/send"), sendCoinsAction->text(), this);
sendCoinsMenuAction->setStatusTip(sendCoinsAction->statusTip());
sendCoinsMenuAction->setToolTip(sendCoinsMenuAction->statusTip());
receiveCoinsAction = new QAction(SingleColorIcon(":/icons/receiving_addresses"), tr("&Receive"), this);
receiveCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/receiving_addresses"), tr("&Receive"), this);
receiveCoinsAction->setStatusTip(tr("Request payments (generates QR codes and bitcoin: URIs)"));
receiveCoinsAction->setToolTip(receiveCoinsAction->statusTip());
receiveCoinsAction->setCheckable(true);
receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
tabGroup->addAction(receiveCoinsAction);
receiveCoinsMenuAction = new QAction(TextColorIcon(":/icons/receiving_addresses"), receiveCoinsAction->text(), this);
receiveCoinsMenuAction = new QAction(platformStyle->TextColorIcon(":/icons/receiving_addresses"), receiveCoinsAction->text(), this);
receiveCoinsMenuAction->setStatusTip(receiveCoinsAction->statusTip());
receiveCoinsMenuAction->setToolTip(receiveCoinsMenuAction->statusTip());
historyAction = new QAction(SingleColorIcon(":/icons/history"), tr("&Transactions"), this);
historyAction = new QAction(platformStyle->SingleColorIcon(":/icons/history"), tr("&Transactions"), this);
historyAction->setStatusTip(tr("Browse transaction history"));
historyAction->setToolTip(historyAction->statusTip());
historyAction->setCheckable(true);
@ -300,46 +301,46 @@ void BitcoinGUI::createActions() @@ -300,46 +301,46 @@ void BitcoinGUI::createActions()
connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
#endif // ENABLE_WALLET
quitAction = new QAction(TextColorIcon(":/icons/quit"), tr("E&xit"), this);
quitAction = new QAction(platformStyle->TextColorIcon(":/icons/quit"), tr("E&xit"), this);
quitAction->setStatusTip(tr("Quit application"));
quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
quitAction->setMenuRole(QAction::QuitRole);
aboutAction = new QAction(TextColorIcon(":/icons/about"), tr("&About Bitcoin Core"), this);
aboutAction = new QAction(platformStyle->TextColorIcon(":/icons/about"), tr("&About Bitcoin Core"), this);
aboutAction->setStatusTip(tr("Show information about Bitcoin Core"));
aboutAction->setMenuRole(QAction::AboutRole);
aboutQtAction = new QAction(TextColorIcon(":/icons/about_qt"), tr("About &Qt"), this);
aboutQtAction = new QAction(platformStyle->TextColorIcon(":/icons/about_qt"), tr("About &Qt"), this);
aboutQtAction->setStatusTip(tr("Show information about Qt"));
aboutQtAction->setMenuRole(QAction::AboutQtRole);
optionsAction = new QAction(TextColorIcon(":/icons/options"), tr("&Options..."), this);
optionsAction = new QAction(platformStyle->TextColorIcon(":/icons/options"), tr("&Options..."), this);
optionsAction->setStatusTip(tr("Modify configuration options for Bitcoin Core"));
optionsAction->setMenuRole(QAction::PreferencesRole);
toggleHideAction = new QAction(TextColorIcon(":/icons/about"), tr("&Show / Hide"), this);
toggleHideAction = new QAction(platformStyle->TextColorIcon(":/icons/about"), tr("&Show / Hide"), this);
toggleHideAction->setStatusTip(tr("Show or hide the main Window"));
encryptWalletAction = new QAction(TextColorIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
encryptWalletAction = new QAction(platformStyle->TextColorIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
encryptWalletAction->setStatusTip(tr("Encrypt the private keys that belong to your wallet"));
encryptWalletAction->setCheckable(true);
backupWalletAction = new QAction(TextColorIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
backupWalletAction = new QAction(platformStyle->TextColorIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
changePassphraseAction = new QAction(TextColorIcon(":/icons/key"), tr("&Change Passphrase..."), this);
changePassphraseAction = new QAction(platformStyle->TextColorIcon(":/icons/key"), tr("&Change Passphrase..."), this);
changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
signMessageAction = new QAction(TextColorIcon(":/icons/edit"), tr("Sign &message..."), this);
signMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/edit"), tr("Sign &message..."), this);
signMessageAction->setStatusTip(tr("Sign messages with your Bitcoin addresses to prove you own them"));
verifyMessageAction = new QAction(TextColorIcon(":/icons/verify"), tr("&Verify message..."), this);
verifyMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/verify"), tr("&Verify message..."), this);
verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Bitcoin addresses"));
openRPCConsoleAction = new QAction(TextColorIcon(":/icons/debugwindow"), tr("&Debug window"), this);
openRPCConsoleAction = new QAction(platformStyle->TextColorIcon(":/icons/debugwindow"), tr("&Debug window"), this);
openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
usedSendingAddressesAction = new QAction(TextColorIcon(":/icons/address-book"), tr("&Sending addresses..."), this);
usedSendingAddressesAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("&Sending addresses..."), this);
usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels"));
usedReceivingAddressesAction = new QAction(TextColorIcon(":/icons/address-book"), tr("&Receiving addresses..."), this);
usedReceivingAddressesAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("&Receiving addresses..."), this);
usedReceivingAddressesAction->setStatusTip(tr("Show the list of used receiving addresses and labels"));
openAction = new QAction(TextColorIcon(":/icons/open"), tr("Open &URI..."), this);
openAction = new QAction(platformStyle->TextColorIcon(":/icons/open"), tr("Open &URI..."), this);
openAction->setStatusTip(tr("Open a bitcoin: URI or payment request"));
showHelpMessageAction = new QAction(TextColorIcon(":/icons/info"), tr("&Command-line options"), this);
showHelpMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/info"), tr("&Command-line options"), this);
showHelpMessageAction->setMenuRole(QAction::NoRole);
showHelpMessageAction->setStatusTip(tr("Show the Bitcoin Core help message to get a list with possible Bitcoin command-line options"));
@ -650,7 +651,7 @@ void BitcoinGUI::setNumConnections(int count) @@ -650,7 +651,7 @@ void BitcoinGUI::setNumConnections(int count)
case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
default: icon = ":/icons/connect_4"; break;
}
labelConnectionsIcon->setPixmap(SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelConnectionsIcon->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
}
@ -691,7 +692,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate) @@ -691,7 +692,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate)
if(secs < 90*60)
{
tooltip = tr("Up to date") + QString(".<br>") + tooltip;
labelBlocksIcon->setPixmap(SingleColorIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
#ifdef ENABLE_WALLET
if(walletFrame)
@ -737,7 +738,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate) @@ -737,7 +738,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate)
tooltip = tr("Catching up...") + QString("<br>") + tooltip;
if(count != prevBlocks)
{
labelBlocksIcon->setPixmap(SingleColorIcon(QString(
labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(QString(
":/movies/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')))
.pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
spinnerFrame = (spinnerFrame + 1) % SPINNER_FRAMES;
@ -931,7 +932,7 @@ void BitcoinGUI::setEncryptionStatus(int status) @@ -931,7 +932,7 @@ void BitcoinGUI::setEncryptionStatus(int status)
break;
case WalletModel::Unlocked:
labelEncryptionIcon->show();
labelEncryptionIcon->setPixmap(SingleColorIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
encryptWalletAction->setChecked(true);
changePassphraseAction->setEnabled(true);
@ -939,7 +940,7 @@ void BitcoinGUI::setEncryptionStatus(int status) @@ -939,7 +940,7 @@ void BitcoinGUI::setEncryptionStatus(int status)
break;
case WalletModel::Locked:
labelEncryptionIcon->show();
labelEncryptionIcon->setPixmap(SingleColorIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
encryptWalletAction->setChecked(true);
changePassphraseAction->setEnabled(true);
@ -1041,7 +1042,7 @@ void BitcoinGUI::unsubscribeFromCoreSignals() @@ -1041,7 +1042,7 @@ void BitcoinGUI::unsubscribeFromCoreSignals()
uiInterface.ThreadSafeMessageBox.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
}
UnitDisplayStatusBarControl::UnitDisplayStatusBarControl() :
UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
optionsModel(0),
menu(0)
{
@ -1056,7 +1057,7 @@ UnitDisplayStatusBarControl::UnitDisplayStatusBarControl() : @@ -1056,7 +1057,7 @@ UnitDisplayStatusBarControl::UnitDisplayStatusBarControl() :
}
setMinimumSize(max_width, 0);
setAlignment(Qt::AlignRight | Qt::AlignVCenter);
setStyleSheet(QString("QLabel { color : %1 }").arg(SingleColor().name()));
setStyleSheet(QString("QLabel { color : %1 }").arg(platformStyle->SingleColor().name()));
}
/** So that it responds to button clicks */

7
src/qt/bitcoingui.h

@ -22,6 +22,7 @@ class ClientModel; @@ -22,6 +22,7 @@ class ClientModel;
class NetworkStyle;
class Notificator;
class OptionsModel;
class PlatformStyle;
class RPCConsole;
class SendCoinsRecipient;
class UnitDisplayStatusBarControl;
@ -47,7 +48,7 @@ class BitcoinGUI : public QMainWindow @@ -47,7 +48,7 @@ class BitcoinGUI : public QMainWindow
public:
static const QString DEFAULT_WALLET;
explicit BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent = 0);
explicit BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = 0);
~BitcoinGUI();
/** Set the client model.
@ -117,6 +118,8 @@ private: @@ -117,6 +118,8 @@ private:
int prevBlocks;
int spinnerFrame;
const PlatformStyle *platformStyle;
/** Create the main UI actions. */
void createActions();
/** Create the menu bar and sub-menus. */
@ -215,7 +218,7 @@ class UnitDisplayStatusBarControl : public QLabel @@ -215,7 +218,7 @@ class UnitDisplayStatusBarControl : public QLabel
Q_OBJECT
public:
explicit UnitDisplayStatusBarControl();
explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
/** Lets the control know about the Options Model (and its signals) */
void setOptionsModel(OptionsModel *optionsModel);

11
src/qt/coincontroldialog.cpp

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
#include "bitcoinunits.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "scicon.h"
#include "platformstyle.h"
#include "txmempool.h"
#include "walletmodel.h"
@ -35,10 +35,11 @@ QList<CAmount> CoinControlDialog::payAmounts; @@ -35,10 +35,11 @@ QList<CAmount> CoinControlDialog::payAmounts;
CCoinControl* CoinControlDialog::coinControl = new CCoinControl();
bool CoinControlDialog::fSubtractFeeFromAmount = false;
CoinControlDialog::CoinControlDialog(QWidget *parent) :
CoinControlDialog::CoinControlDialog(const PlatformStyle *platformStyle, QWidget *parent) :
QDialog(parent),
ui(new Ui::CoinControlDialog),
model(0)
model(0),
platformStyle(platformStyle)
{
ui->setupUi(this);
@ -280,7 +281,7 @@ void CoinControlDialog::lockCoin() @@ -280,7 +281,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, SingleColorIcon(":/icons/lock_closed"));
contextMenuItem->setIcon(COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed"));
updateLabelLocked();
}
@ -791,7 +792,7 @@ void CoinControlDialog::updateView() @@ -791,7 +792,7 @@ void CoinControlDialog::updateView()
COutPoint outpt(txhash, out.i);
coinControl->UnSelect(outpt); // just to be sure
itemOutput->setDisabled(true);
itemOutput->setIcon(COLUMN_CHECKBOX, SingleColorIcon(":/icons/lock_closed"));
itemOutput->setIcon(COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed"));
}
// set checkbox

5
src/qt/coincontroldialog.h

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
#include <QString>
#include <QTreeWidgetItem>
class PlatformStyle;
class WalletModel;
class CCoinControl;
@ -32,7 +33,7 @@ class CoinControlDialog : public QDialog @@ -32,7 +33,7 @@ class CoinControlDialog : public QDialog
Q_OBJECT
public:
explicit CoinControlDialog(QWidget *parent = 0);
explicit CoinControlDialog(const PlatformStyle *platformStyle, QWidget *parent = 0);
~CoinControlDialog();
void setModel(WalletModel *model);
@ -57,6 +58,8 @@ private: @@ -57,6 +58,8 @@ private:
QAction *lockAction;
QAction *unlockAction;
const PlatformStyle *platformStyle;
QString strPad(QString, int, QString);
void sortView(int, Qt::SortOrder);
void updateView();

3
src/qt/intro.cpp

@ -6,7 +6,6 @@ @@ -6,7 +6,6 @@
#include "ui_intro.h"
#include "guiutil.h"
#include "scicon.h"
#include "util.h"
@ -168,7 +167,7 @@ void Intro::pickDataDirectory() @@ -168,7 +167,7 @@ void Intro::pickDataDirectory()
/* If current default data directory does not exist, let the user choose one */
Intro intro;
intro.setDataDirectory(dataDir);
intro.setWindowIcon(SingleColorIcon(":icons/bitcoin"));
intro.setWindowIcon(QIcon(":icons/bitcoin"));
while(true)
{

1
src/qt/networkstyle.cpp

@ -5,7 +5,6 @@ @@ -5,7 +5,6 @@
#include "networkstyle.h"
#include "guiconstants.h"
#include "scicon.h"
#include <QApplication>

15
src/qt/overviewpage.cpp

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
#include "guiconstants.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "scicon.h"
#include "platformstyle.h"
#include "transactionfilterproxy.h"
#include "transactiontablemodel.h"
#include "walletmodel.h"
@ -25,7 +25,9 @@ class TxViewDelegate : public QAbstractItemDelegate @@ -25,7 +25,9 @@ class TxViewDelegate : public QAbstractItemDelegate
{
Q_OBJECT
public:
TxViewDelegate(): QAbstractItemDelegate(), unit(BitcoinUnits::BTC)
TxViewDelegate(const PlatformStyle *platformStyle):
QAbstractItemDelegate(), unit(BitcoinUnits::BTC),
platformStyle(platformStyle)
{
}
@ -43,7 +45,7 @@ public: @@ -43,7 +45,7 @@ public:
int halfheight = (mainRect.height() - 2*ypad)/2;
QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight);
QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight);
icon = SingleColorIcon(icon, SingleColor());
icon = platformStyle->SingleColorIcon(icon);
icon.paint(painter, decorationRect);
QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime();
@ -101,11 +103,12 @@ public: @@ -101,11 +103,12 @@ public:
}
int unit;
const PlatformStyle *platformStyle;
};
#include "overviewpage.moc"
OverviewPage::OverviewPage(QWidget *parent) :
OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) :
QWidget(parent),
ui(new Ui::OverviewPage),
clientModel(0),
@ -116,13 +119,13 @@ OverviewPage::OverviewPage(QWidget *parent) : @@ -116,13 +119,13 @@ OverviewPage::OverviewPage(QWidget *parent) :
currentWatchOnlyBalance(-1),
currentWatchUnconfBalance(-1),
currentWatchImmatureBalance(-1),
txdelegate(new TxViewDelegate()),
txdelegate(new TxViewDelegate(platformStyle)),
filter(0)
{
ui->setupUi(this);
// use a SingleColorIcon for the "out of sync warning" icon
QIcon icon = SingleColorIcon(":/icons/warning");
QIcon icon = platformStyle->SingleColorIcon(":/icons/warning");
icon.addPixmap(icon.pixmap(QSize(64,64), QIcon::Normal), QIcon::Disabled); // also set the disabled icon because we are using a disabled QPushButton to work around missing HiDPI support of QLabel (https://bugreports.qt.io/browse/QTBUG-42503)
ui->labelTransactionsStatus->setIcon(icon);
ui->labelWalletStatus->setIcon(icon);

3
src/qt/overviewpage.h

@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
class ClientModel;
class TransactionFilterProxy;
class TxViewDelegate;
class PlatformStyle;
class WalletModel;
namespace Ui {
@ -28,7 +29,7 @@ class OverviewPage : public QWidget @@ -28,7 +29,7 @@ class OverviewPage : public QWidget
Q_OBJECT
public:
explicit OverviewPage(QWidget *parent = 0);
explicit OverviewPage(const PlatformStyle *platformStyle, QWidget *parent = 0);
~OverviewPage();
void setClientModel(ClientModel *clientModel);

147
src/qt/platformstyle.cpp

@ -0,0 +1,147 @@ @@ -0,0 +1,147 @@
// Copyright (c) 2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "platformstyle.h"
#include "guiconstants.h"
#include <QApplication>
#include <QColor>
#include <QIcon>
#include <QImage>
#include <QPalette>
#include <QPixmap>
static const struct {
const char *platformId;
/** Show images on push buttons */
const bool imagesOnButtons;
/** Colorize single-color icons */
const bool colorizeIcons;
/** Extra padding/spacing in transactionview */
const bool useExtraSpacing;
} platform_styles[] = {
{"macosx", false, false, true},
{"windows", true, false, false},
/* Other: linux, unix, ... */
{"other", true, true, false}
};
static const unsigned platform_styles_count = sizeof(platform_styles)/sizeof(*platform_styles);
namespace {
/* Local functions for colorizing single-color images */
void MakeSingleColorImage(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;
QSize sz;
Q_FOREACH(sz, ico.availableSizes())
{
QImage img(ico.pixmap(sz).toImage());
MakeSingleColorImage(img, colorbase);
new_ico.addPixmap(QPixmap::fromImage(img));
}
return new_ico;
}
QImage ColorizeImage(const QString& filename, const QColor& colorbase)
{
QImage img(filename);
MakeSingleColorImage(img, colorbase);
return img;
}
QIcon ColorizeIcon(const QString& filename, const QColor& colorbase)
{
return QIcon(QPixmap::fromImage(ColorizeImage(filename, colorbase)));
}
}
PlatformStyle::PlatformStyle(const QString &name, bool imagesOnButtons, bool colorizeIcons, bool useExtraSpacing):
name(name),
imagesOnButtons(imagesOnButtons),
colorizeIcons(colorizeIcons),
useExtraSpacing(useExtraSpacing),
singleColor(0,0,0),
textColor(0,0,0)
{
// Determine icon highlighting color
if (colorizeIcons) {
const QColor colorHighlightBg(QApplication::palette().color(QPalette::Highlight));
const QColor colorHighlightFg(QApplication::palette().color(QPalette::HighlightedText));
const QColor colorText(QApplication::palette().color(QPalette::WindowText));
const int colorTextLightness = colorText.lightness();
QColor colorbase;
if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness))
colorbase = colorHighlightBg;
else
colorbase = colorHighlightFg;
singleColor = colorbase;
}
// Determine text color
textColor = QColor(QApplication::palette().color(QPalette::WindowText));
}
QImage PlatformStyle::SingleColorImage(const QString& filename) const
{
if (!colorizeIcons)
return QImage(filename);
return ColorizeImage(filename, SingleColor());
}
QIcon PlatformStyle::SingleColorIcon(const QString& filename) const
{
if (!colorizeIcons)
return QIcon(filename);
return ColorizeIcon(filename, SingleColor());
}
QIcon PlatformStyle::SingleColorIcon(const QIcon& icon) const
{
if (!colorizeIcons)
return icon;
return ColorizeIcon(icon, SingleColor());
}
QIcon PlatformStyle::TextColorIcon(const QString& filename) const
{
return ColorizeIcon(filename, TextColor());
}
QIcon PlatformStyle::TextColorIcon(const QIcon& icon) const
{
return ColorizeIcon(icon, TextColor());
}
const PlatformStyle *PlatformStyle::instantiate(const QString &platformId)
{
for (unsigned x=0; x<platform_styles_count; ++x)
{
if (platformId == platform_styles[x].platformId)
{
return new PlatformStyle(
platform_styles[x].platformId,
platform_styles[x].imagesOnButtons,
platform_styles[x].colorizeIcons,
platform_styles[x].useExtraSpacing);
}
}
return 0;
}

55
src/qt/platformstyle.h

@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
// Copyright (c) 2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_PLATFORMSTYLE_H
#define BITCOIN_QT_PLATFORMSTYLE_H
#include <QIcon>
#include <QPixmap>
#include <QString>
/* Coin network-specific GUI style information */
class PlatformStyle
{
public:
/** Get style associated with provided platform name, or 0 if not known */
static const PlatformStyle *instantiate(const QString &platformId);
const QString &getName() const { return name; }
bool getImagesOnButtons() const { return imagesOnButtons; }
bool getUseExtraSpacing() const { return useExtraSpacing; }
QColor TextColor() const { return textColor; }
QColor SingleColor() const { return singleColor; }
/** Colorize an image (given filename) with the icon color */
QImage SingleColorImage(const QString& filename) const;
/** Colorize an icon (given filename) with the icon color */
QIcon SingleColorIcon(const QString& filename) const;
/** Colorize an icon (given object) with the icon color */
QIcon SingleColorIcon(const QIcon& icon) const;
/** Colorize an icon (given filename) with the text color */
QIcon TextColorIcon(const QString& filename) const;
/** Colorize an icon (given object) with the text color */
QIcon TextColorIcon(const QIcon& icon) const;
private:
PlatformStyle(const QString &name, bool imagesOnButtons, bool colorizeIcons, bool useExtraSpacing);
QString name;
bool imagesOnButtons;
bool colorizeIcons;
bool useExtraSpacing;
QColor singleColor;
QColor textColor;
/* ... more to come later */
};
#endif // BITCOIN_QT_PLATFORMSTYLE_H

31
src/qt/receivecoinsdialog.cpp

@ -10,9 +10,9 @@ @@ -10,9 +10,9 @@
#include "bitcoinunits.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "platformstyle.h"
#include "receiverequestdialog.h"
#include "recentrequeststablemodel.h"
#include "scicon.h"
#include "walletmodel.h"
#include <QAction>
@ -22,24 +22,25 @@ @@ -22,24 +22,25 @@
#include <QScrollBar>
#include <QTextDocument>
ReceiveCoinsDialog::ReceiveCoinsDialog(QWidget *parent) :
ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent) :
QDialog(parent),
ui(new Ui::ReceiveCoinsDialog),
model(0)
model(0),
platformStyle(platformStyle)
{
ui->setupUi(this);
#ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
ui->clearButton->setIcon(QIcon());
ui->receiveButton->setIcon(QIcon());
ui->showRequestButton->setIcon(QIcon());
ui->removeRequestButton->setIcon(QIcon());
#else
ui->clearButton->setIcon(SingleColorIcon(":/icons/remove"));
ui->receiveButton->setIcon(SingleColorIcon(":/icons/receiving_addresses"));
ui->showRequestButton->setIcon(SingleColorIcon(":/icons/edit"));
ui->removeRequestButton->setIcon(SingleColorIcon(":/icons/remove"));
#endif
if (!platformStyle->getImagesOnButtons()) {
ui->clearButton->setIcon(QIcon());
ui->receiveButton->setIcon(QIcon());
ui->showRequestButton->setIcon(QIcon());
ui->removeRequestButton->setIcon(QIcon());
} else {
ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
ui->receiveButton->setIcon(platformStyle->SingleColorIcon(":/icons/receiving_addresses"));
ui->showRequestButton->setIcon(platformStyle->SingleColorIcon(":/icons/edit"));
ui->removeRequestButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
}
// context menu actions
QAction *copyLabelAction = new QAction(tr("Copy label"), this);
@ -132,7 +133,7 @@ void ReceiveCoinsDialog::on_receiveButton_clicked() @@ -132,7 +133,7 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
if(ui->reuseAddress->isChecked())
{
/* Choose existing receiving address */
AddressBookPage dlg(AddressBookPage::ForSelection, AddressBookPage::ReceivingTab, this);
AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::ReceivingTab, this);
dlg.setModel(model->getAddressTableModel());
if(dlg.exec())
{

5
src/qt/receivecoinsdialog.h

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
#include <QVariant>
class OptionsModel;
class PlatformStyle;
class WalletModel;
namespace Ui {
@ -39,7 +40,7 @@ public: @@ -39,7 +40,7 @@ public:
MINIMUM_COLUMN_WIDTH = 130
};
explicit ReceiveCoinsDialog(QWidget *parent = 0);
explicit ReceiveCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent = 0);
~ReceiveCoinsDialog();
void setModel(WalletModel *model);
@ -57,6 +58,8 @@ private: @@ -57,6 +58,8 @@ private:
GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer;
WalletModel *model;
QMenu *contextMenu;
const PlatformStyle *platformStyle;
void copyColumnToClipboard(int column);
virtual void resizeEvent(QResizeEvent *event);

17
src/qt/rpcconsole.cpp

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
#include "clientmodel.h"
#include "guiutil.h"
#include "peertablemodel.h"
#include "scicon.h"
#include "platformstyle.h"
#include "chainparams.h"
#include "rpcserver.h"
@ -200,21 +200,22 @@ void RPCExecutor::request(const QString &command) @@ -200,21 +200,22 @@ void RPCExecutor::request(const QString &command)
}
}
RPCConsole::RPCConsole(QWidget *parent) :
RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) :
QWidget(parent),
ui(new Ui::RPCConsole),
clientModel(0),
historyPtr(0),
cachedNodeid(-1),
contextMenu(0)
contextMenu(0),
platformStyle(platformStyle)
{
ui->setupUi(this);
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this);
#ifndef Q_OS_MAC
ui->openDebugLogfileButton->setIcon(SingleColorIcon(":/icons/export"));
#endif
ui->clearButton->setIcon(SingleColorIcon(":/icons/remove"));
if (platformStyle->getImagesOnButtons()) {
ui->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
}
ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
// Install event filter for up and down arrow
ui->lineEdit->installEventFilter(this);
@ -363,7 +364,7 @@ void RPCConsole::clear() @@ -363,7 +364,7 @@ void RPCConsole::clear()
ui->messagesWidget->document()->addResource(
QTextDocument::ImageResource,
QUrl(ICON_MAPPING[i].url),
SingleColorImage(ICON_MAPPING[i].source, SingleColor()).scaled(ICON_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(ICON_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
// Set default style sheet

4
src/qt/rpcconsole.h

@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
#include <QWidget>
class ClientModel;
class PlatformStyle;
namespace Ui {
class RPCConsole;
@ -29,7 +30,7 @@ class RPCConsole: public QWidget @@ -29,7 +30,7 @@ class RPCConsole: public QWidget
Q_OBJECT
public:
explicit RPCConsole(QWidget *parent);
explicit RPCConsole(const PlatformStyle *platformStyle, QWidget *parent);
~RPCConsole();
void setClientModel(ClientModel *model);
@ -106,6 +107,7 @@ private: @@ -106,6 +107,7 @@ private:
int historyPtr;
NodeId cachedNodeid;
QMenu *contextMenu;
const PlatformStyle *platformStyle;
};
#endif // BITCOIN_QT_RPCCONSOLE_H

98
src/qt/scicon.cpp

@ -1,98 +0,0 @@ @@ -1,98 +0,0 @@
// Copyright (c) 2014 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "scicon.h"
#include <QApplication>
#include <QColor>
#include <QIcon>
#include <QImage>
#include <QPalette>
#include <QPixmap>
namespace {
void MakeSingleColorImage(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)));
}
}
}
}
QImage SingleColorImage(const QString& filename, const QColor& colorbase)
{
QImage img(filename);
#if !defined(WIN32) && !defined(MAC_OSX)
MakeSingleColorImage(img, colorbase);
#endif
return img;
}
QIcon SingleColorIcon(const QIcon& ico, const QColor& colorbase)
{
#if defined(WIN32) || defined(MAC_OSX)
return ico;
#else
QIcon new_ico;
QSize sz;
Q_FOREACH(sz, ico.availableSizes())
{
QImage img(ico.pixmap(sz).toImage());
MakeSingleColorImage(img, colorbase);
new_ico.addPixmap(QPixmap::fromImage(img));
}
return new_ico;
#endif
}
QIcon SingleColorIcon(const QString& filename, const QColor& colorbase)
{
return QIcon(QPixmap::fromImage(SingleColorImage(filename, colorbase)));
}
QColor SingleColor()
{
#if defined(WIN32) || defined(MAC_OSX)
return QColor(0,0,0);
#else
const QColor colorHighlightBg(QApplication::palette().color(QPalette::Highlight));
const QColor colorHighlightFg(QApplication::palette().color(QPalette::HighlightedText));
const QColor colorText(QApplication::palette().color(QPalette::WindowText));
const int colorTextLightness = colorText.lightness();
QColor colorbase;
if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness))
colorbase = colorHighlightBg;
else
colorbase = colorHighlightFg;
return colorbase;
#endif
}
QIcon SingleColorIcon(const QString& filename)
{
return SingleColorIcon(filename, SingleColor());
}
static QColor TextColor()
{
return QColor(QApplication::palette().color(QPalette::WindowText));
}
QIcon TextColorIcon(const QString& filename)
{
return SingleColorIcon(filename, TextColor());
}
QIcon TextColorIcon(const QIcon& ico)
{
return SingleColorIcon(ico, TextColor());
}

24
src/qt/scicon.h

@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
// Copyright (c) 2014 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_SCICON_H
#define BITCOIN_QT_SCICON_H
#include <QtCore>
QT_BEGIN_NAMESPACE
class QColor;
class QIcon;
class QString;
QT_END_NAMESPACE
QImage SingleColorImage(const QString& filename, const QColor&);
QIcon SingleColorIcon(const QIcon&, const QColor&);
QIcon SingleColorIcon(const QString& filename, const QColor&);
QColor SingleColor();
QIcon SingleColorIcon(const QString& filename);
QIcon TextColorIcon(const QIcon&);
QIcon TextColorIcon(const QString& filename);
#endif // BITCOIN_QT_SCICON_H

29
src/qt/sendcoinsdialog.cpp

@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
#include "coincontroldialog.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "scicon.h"
#include "platformstyle.h"
#include "sendcoinsentry.h"
#include "walletmodel.h"
@ -27,25 +27,26 @@ @@ -27,25 +27,26 @@
#include <QSettings>
#include <QTextDocument>
SendCoinsDialog::SendCoinsDialog(QWidget *parent) :
SendCoinsDialog::SendCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent) :
QDialog(parent),
ui(new Ui::SendCoinsDialog),
clientModel(0),
model(0),
fNewRecipientAllowed(true),
fFeeMinimized(true)
fFeeMinimized(true),
platformStyle(platformStyle)
{
ui->setupUi(this);
#ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
ui->addButton->setIcon(QIcon());
ui->clearButton->setIcon(QIcon());
ui->sendButton->setIcon(QIcon());
#else
ui->addButton->setIcon(SingleColorIcon(":/icons/add"));
ui->clearButton->setIcon(SingleColorIcon(":/icons/remove"));
ui->sendButton->setIcon(SingleColorIcon(":/icons/send"));
#endif
if (!platformStyle->getImagesOnButtons()) {
ui->addButton->setIcon(QIcon());
ui->clearButton->setIcon(QIcon());
ui->sendButton->setIcon(QIcon());
} else {
ui->addButton->setIcon(platformStyle->SingleColorIcon(":/icons/add"));
ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
ui->sendButton->setIcon(platformStyle->SingleColorIcon(":/icons/send"));
}
GUIUtil::setupAddressWidget(ui->lineEditCoinControlChange, this);
@ -364,7 +365,7 @@ void SendCoinsDialog::accept() @@ -364,7 +365,7 @@ void SendCoinsDialog::accept()
SendCoinsEntry *SendCoinsDialog::addEntry()
{
SendCoinsEntry *entry = new SendCoinsEntry(this);
SendCoinsEntry *entry = new SendCoinsEntry(platformStyle, this);
entry->setModel(model);
ui->entries->addWidget(entry);
connect(entry, SIGNAL(removeEntry(SendCoinsEntry*)), this, SLOT(removeEntry(SendCoinsEntry*)));
@ -711,7 +712,7 @@ void SendCoinsDialog::coinControlFeatureChanged(bool checked) @@ -711,7 +712,7 @@ void SendCoinsDialog::coinControlFeatureChanged(bool checked)
// Coin Control: button inputs -> show actual coin control dialog
void SendCoinsDialog::coinControlButtonClicked()
{
CoinControlDialog dlg;
CoinControlDialog dlg(platformStyle);
dlg.setModel(model);
dlg.exec();
coinControlUpdateLabels();

4
src/qt/sendcoinsdialog.h

@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
class ClientModel;
class OptionsModel;
class PlatformStyle;
class SendCoinsEntry;
class SendCoinsRecipient;
@ -31,7 +32,7 @@ class SendCoinsDialog : public QDialog @@ -31,7 +32,7 @@ class SendCoinsDialog : public QDialog
Q_OBJECT
public:
explicit SendCoinsDialog(QWidget *parent = 0);
explicit SendCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent = 0);
~SendCoinsDialog();
void setClientModel(ClientModel *clientModel);
@ -60,6 +61,7 @@ private: @@ -60,6 +61,7 @@ private:
WalletModel *model;
bool fNewRecipientAllowed;
bool fFeeMinimized;
const PlatformStyle *platformStyle;
// Process WalletModel::SendCoinsReturn and generate a pair consisting
// of a message and message flags for use in Q_EMIT message().