mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
qt: Add -debug-ui command line parameter (#3558)
* qt: Set parents properly to inherit css and remove redundant loading The stylesheet is inherited from the parent so its enough to set it for the main window and use this as parent for all other windows. Except for the ShutdownDialog. This needs to have its own stylesheet set because we can't have the main window as parent of the ShutdownDialog. * qt: Adding Qt::Window flag to the constructor of RPCConsole This is required now as RPCConsole does not longer show as extra window with a parent set (For stylesheet inheritance). * qt: Add UI debug mode (-debug-ui) If this mode is enabled the content of the css files will become pushed to the UI if there were any changes made to the stylesheet files in the custom css directory. It also forces some UI elements to show up which are actually only shown under special conditions (e.g. watch balance labels). Its required to set a custom css directory with -custom-css-dir to enable this. * qt: Adjust the description of -debug-ui
This commit is contained in:
parent
dde4ab5f84
commit
f371e4771c
@ -131,8 +131,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
|
||||
spinnerFrame(0),
|
||||
platformStyle(_platformStyle)
|
||||
{
|
||||
/* Open CSS when configured */
|
||||
this->setStyleSheet(GUIUtil::loadStyleSheet());
|
||||
GUIUtil::loadStyleSheet(this);
|
||||
|
||||
QSettings settings;
|
||||
if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
|
||||
@ -163,7 +162,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
|
||||
setUnifiedTitleAndToolBarOnMac(true);
|
||||
#endif
|
||||
|
||||
rpcConsole = new RPCConsole(_platformStyle, 0);
|
||||
rpcConsole = new RPCConsole(_platformStyle, this);
|
||||
helpMessageDialog = new HelpMessageDialog(this, HelpMessageDialog::cmdline);
|
||||
#ifdef ENABLE_WALLET
|
||||
if(enableWallet)
|
||||
@ -1542,8 +1541,7 @@ void BitcoinGUI::showProgress(const QString &title, int nProgress)
|
||||
{
|
||||
if (nProgress == 0)
|
||||
{
|
||||
progressDialog = new QProgressDialog(title, "", 0, 100);
|
||||
progressDialog->setStyleSheet(GUIUtil::loadStyleSheet());
|
||||
progressDialog = new QProgressDialog(title, "", 0, 100, this);
|
||||
progressDialog->setWindowModality(Qt::ApplicationModal);
|
||||
progressDialog->setMinimumDuration(0);
|
||||
progressDialog->setCancelButton(0);
|
||||
|
@ -51,9 +51,6 @@ CoinControlDialog::CoinControlDialog(const PlatformStyle *_platformStyle, QWidge
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
/* Open CSS when configured */
|
||||
this->setStyleSheet(GUIUtil::loadStyleSheet());
|
||||
|
||||
GUIUtil::setFont({ui->labelCoinControlQuantityText,
|
||||
ui->labelCoinControlBytesText,
|
||||
ui->labelCoinControlAmountText,
|
||||
@ -245,9 +242,8 @@ void CoinControlDialog::buttonToggleLockClicked()
|
||||
CoinControlDialog::updateLabels(model, this);
|
||||
}
|
||||
else{
|
||||
QMessageBox msgBox;
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setObjectName("lockMessageBox");
|
||||
msgBox.setStyleSheet(GUIUtil::loadStyleSheet());
|
||||
msgBox.setText(tr("Please switch to \"List mode\" to use this function."));
|
||||
msgBox.exec();
|
||||
}
|
||||
|
@ -810,6 +810,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
GUIUtil::setStyleSheetDirectory(strCustomDir);
|
||||
}
|
||||
// Validate -debug-ui
|
||||
if (gArgs.GetBoolArg("-debug-ui", false)) {
|
||||
QMessageBox::warning(0, QObject::tr(PACKAGE_NAME),
|
||||
"Warning: UI debug mode (-debug-ui) enabled" + QString(gArgs.IsArgSet("-custom-css-dir") ? "." : " without a custom css directory set with -custom-css-dir."));
|
||||
}
|
||||
|
||||
// Subscribe to global signals from core
|
||||
uiInterface.InitMessage.connect(InitMessage);
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include <QSettings>
|
||||
#include <QTextDocument> // for Qt::mightBeRichText
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
@ -87,6 +88,7 @@ void ForceActivation();
|
||||
|
||||
namespace GUIUtil {
|
||||
|
||||
static CCriticalSection cs_css;
|
||||
// The default stylesheet directory
|
||||
static const QString defaultStylesheetDirectory = ":css";
|
||||
// The actual stylesheet directory
|
||||
@ -1052,43 +1054,92 @@ const std::vector<QString> listThemes()
|
||||
return vecThemes;
|
||||
}
|
||||
|
||||
// Open CSS when configured
|
||||
QString loadStyleSheet()
|
||||
void loadStyleSheet(QWidget* widget, bool fDebugWidget)
|
||||
{
|
||||
AssertLockNotHeld(cs_css);
|
||||
LOCK(cs_css);
|
||||
|
||||
static std::unique_ptr<QString> stylesheet;
|
||||
static std::set<QWidget*> setWidgets;
|
||||
|
||||
if (stylesheet == nullptr) {
|
||||
stylesheet = std::make_unique<QString>();
|
||||
bool fDebugCustomStyleSheets = gArgs.GetBoolArg("-debug-ui", false) && isStyleSheetDirectoryCustom();
|
||||
bool fStyleSheetChanged = false;
|
||||
|
||||
QSettings settings;
|
||||
QDir themes(":css");
|
||||
QString theme = settings.value("theme", "").toString();
|
||||
if (stylesheet == nullptr || fDebugCustomStyleSheets) {
|
||||
auto hasModified = [](const std::vector<QString>& vecFiles) -> bool {
|
||||
static std::map<const QString, QDateTime> mapLastModified;
|
||||
|
||||
// Make sure settings are pointing to an existent theme
|
||||
if (!isStyleSheetDirectoryCustom() && (theme.isEmpty() || !themes.exists(theme))) {
|
||||
theme = defaultTheme;
|
||||
settings.setValue("theme", theme);
|
||||
}
|
||||
|
||||
auto loadFile = [&](const QString& name) {
|
||||
QFile qFile(stylesheetDirectory + "/" + name + (isStyleSheetDirectoryCustom() ? ".css" : ""));
|
||||
if (qFile.open(QFile::ReadOnly)) {
|
||||
stylesheet->append(QLatin1String(qFile.readAll()));
|
||||
bool fModified = false;
|
||||
for (auto file = vecFiles.begin(); file != vecFiles.end() && !fModified; ++file) {
|
||||
QFileInfo info(*file);
|
||||
QDateTime lastModified = info.lastModified(), prevLastModified;
|
||||
auto it = mapLastModified.emplace(std::make_pair(*file, lastModified));
|
||||
prevLastModified = it.second ? QDateTime() : it.first->second;
|
||||
it.first->second = lastModified;
|
||||
fModified = prevLastModified != lastModified;
|
||||
}
|
||||
return fModified;
|
||||
};
|
||||
|
||||
auto loadFiles = [&](const std::vector<QString>& vecFiles) -> bool {
|
||||
if (fDebugCustomStyleSheets && !hasModified(vecFiles)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
stylesheet = std::make_unique<QString>();
|
||||
|
||||
for (const auto& file : vecFiles) {
|
||||
QFile qFile(file);
|
||||
if (!qFile.open(QFile::ReadOnly)) {
|
||||
throw std::runtime_error(strprintf("%s: Failed to open file: %s", __func__, file.toStdString()));
|
||||
}
|
||||
stylesheet->append(QLatin1String(qFile.readAll()));
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
auto pathToFile = [&](const QString& file) -> QString {
|
||||
return stylesheetDirectory + "/" + file + (isStyleSheetDirectoryCustom() ? ".css" : "");
|
||||
};
|
||||
|
||||
std::vector<QString> vecFiles;
|
||||
// If light/dark theme is used load general styles first
|
||||
if (dashThemeActive()) {
|
||||
loadFile("general");
|
||||
#ifndef Q_OS_MAC
|
||||
loadFile("scrollbars");
|
||||
vecFiles.push_back(pathToFile("scrollbars"));
|
||||
#endif
|
||||
vecFiles.push_back(pathToFile("general"));
|
||||
}
|
||||
vecFiles.push_back(pathToFile(getActiveTheme()));
|
||||
|
||||
loadFile(theme);
|
||||
fStyleSheetChanged = loadFiles(vecFiles);
|
||||
}
|
||||
|
||||
return *stylesheet;
|
||||
bool fUpdateStyleSheet = fDebugCustomStyleSheets && fStyleSheetChanged;
|
||||
|
||||
if (fDebugWidget) {
|
||||
setWidgets.insert(widget);
|
||||
QWidgetList allWidgets = QApplication::allWidgets();
|
||||
auto it = setWidgets.begin();
|
||||
while (it != setWidgets.end()) {
|
||||
if (!allWidgets.contains(*it)) {
|
||||
it = setWidgets.erase(it);
|
||||
continue;
|
||||
}
|
||||
if (fUpdateStyleSheet && *it != widget) {
|
||||
(*it)->setStyleSheet(*stylesheet);
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
if (widget) {
|
||||
widget->setStyleSheet(*stylesheet);
|
||||
}
|
||||
|
||||
if (!ShutdownRequested() && fDebugCustomStyleSheets) {
|
||||
QTimer::singleShot(200, [] { loadStyleSheet(); });
|
||||
}
|
||||
}
|
||||
|
||||
FontFamily fontFamilyFromString(const QString& strFamily)
|
||||
@ -1460,12 +1511,15 @@ QFont getFont(FontWeight weight, bool fItalic, int nPointSize)
|
||||
font.setWeight(qWeight);
|
||||
font.setStyle(fItalic ? QFont::StyleItalic : QFont::StyleNormal);
|
||||
}
|
||||
qDebug() << "GUIUtil::getFont() - " << font.toString() << " family: " << font.family() << ", style: " << font.styleName() << " match: " << font.exactMatch();
|
||||
|
||||
if (nPointSize != -1) {
|
||||
font.setPointSizeF(getScaledFontSize(nPointSize));
|
||||
}
|
||||
|
||||
if (gArgs.GetBoolArg("-debug-ui", false)) {
|
||||
qDebug() << __func__ << ": font size: " << font.pointSizeF() << " family: " << font.family() << ", style: " << font.styleName() << " match: " << font.exactMatch();
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
@ -1479,6 +1533,12 @@ QFont getFontBold()
|
||||
return getFont(FontWeight::Bold);
|
||||
}
|
||||
|
||||
QString getActiveTheme()
|
||||
{
|
||||
QSettings settings;
|
||||
return settings.value("theme", defaultTheme).toString();
|
||||
}
|
||||
|
||||
bool dashThemeActive()
|
||||
{
|
||||
QSettings settings;
|
||||
|
@ -243,8 +243,10 @@ namespace GUIUtil
|
||||
/** Return a list of all theme css files */
|
||||
const std::vector<QString> listThemes();
|
||||
|
||||
/** Load global CSS theme */
|
||||
QString loadStyleSheet();
|
||||
/** Updates the widgets stylesheet and adds it to the list of ui debug elements
|
||||
if fDebugWidget is true. Beeing on that list means the stylesheet of the
|
||||
widget gets updated if the related css files has been changed if -debug-ui mode is active. */
|
||||
void loadStyleSheet(QWidget* widget = nullptr, bool fDebugWidget = true);
|
||||
|
||||
enum class FontFamily {
|
||||
SystemDefault,
|
||||
@ -317,7 +319,10 @@ namespace GUIUtil
|
||||
/** Get the default bold QFont */
|
||||
QFont getFontBold();
|
||||
|
||||
/** Check if a dash specific theme is activated (light/dark) */
|
||||
/** Return the name of the currently active theme.*/
|
||||
QString getActiveTheme();
|
||||
|
||||
/** Check if a dash specific theme is activated (light/dark).*/
|
||||
bool dashThemeActive();
|
||||
|
||||
/** Disable the OS default focus rect for macOS because we have custom focus rects
|
||||
|
@ -81,7 +81,7 @@ MasternodeList::MasternodeList(const PlatformStyle* platformStyle, QWidget* pare
|
||||
|
||||
QAction* copyProTxHashAction = new QAction(tr("Copy ProTx Hash"), this);
|
||||
QAction* copyCollateralOutpointAction = new QAction(tr("Copy Collateral Outpoint"), this);
|
||||
contextMenuDIP3 = new QMenu();
|
||||
contextMenuDIP3 = new QMenu(this);
|
||||
contextMenuDIP3->addAction(copyProTxHashAction);
|
||||
contextMenuDIP3->addAction(copyCollateralOutpointAction);
|
||||
connect(ui->tableWidgetMasternodesDIP3, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenuDIP3(const QPoint&)));
|
||||
|
@ -232,10 +232,11 @@ void OverviewPage::setBalance(const CAmount& balance, const CAmount& unconfirmed
|
||||
ui->labelWatchImmature->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, watchImmatureBalance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelWatchTotal->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, watchOnlyBalance + watchUnconfBalance + watchImmatureBalance, false, BitcoinUnits::separatorAlways));
|
||||
|
||||
// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
|
||||
// only show immature (newly mined) balance if it's non-zero or in UI debug mode, so as not to complicate things
|
||||
// for the non-mining users
|
||||
bool showImmature = immatureBalance != 0;
|
||||
bool showWatchOnlyImmature = watchImmatureBalance != 0;
|
||||
bool fDebugUI = gArgs.GetBoolArg("-debug-ui", false);
|
||||
bool showImmature = fDebugUI || immatureBalance != 0;
|
||||
bool showWatchOnlyImmature = fDebugUI || watchImmatureBalance != 0;
|
||||
|
||||
// for symmetry reasons also show immature label when the watch-only one is shown
|
||||
ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature);
|
||||
@ -298,7 +299,7 @@ void OverviewPage::setWalletModel(WalletModel *model)
|
||||
connect(model, SIGNAL(balanceChanged(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)), this, SLOT(setBalance(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)));
|
||||
|
||||
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
|
||||
updateWatchOnlyLabels(model->haveWatchOnly());
|
||||
updateWatchOnlyLabels(model->haveWatchOnly() || gArgs.GetBoolArg("-debug-ui", false));
|
||||
connect(model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyLabels(bool)));
|
||||
|
||||
// explicitly update PS frame and transaction list to reflect actual settings
|
||||
|
@ -454,7 +454,7 @@ void RPCExecutor::request(const QString &command)
|
||||
}
|
||||
|
||||
RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
QWidget(parent, Qt::Window),
|
||||
ui(new Ui::RPCConsole),
|
||||
clientModel(0),
|
||||
historyPtr(0),
|
||||
@ -465,9 +465,6 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
/* Open CSS when configured */
|
||||
this->setStyleSheet(GUIUtil::loadStyleSheet());
|
||||
|
||||
GUIUtil::setFont({ui->label_9,
|
||||
ui->labelNetwork,
|
||||
ui->label_10,
|
||||
|
@ -899,7 +899,7 @@ void SendCoinsDialog::coinControlFeatureChanged(bool checked)
|
||||
// Coin Control: button inputs -> show actual coin control dialog
|
||||
void SendCoinsDialog::coinControlButtonClicked()
|
||||
{
|
||||
CoinControlDialog dlg(platformStyle);
|
||||
CoinControlDialog dlg(platformStyle, this);
|
||||
dlg.setModel(model);
|
||||
dlg.exec();
|
||||
coinControlUpdateLabels();
|
||||
|
@ -18,9 +18,6 @@ TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *pa
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowTitle(tr("Details for %1").arg(idx.data(TransactionTableModel::TxIDRole).toString()));
|
||||
/* Open CSS when configured */
|
||||
this->setStyleSheet(GUIUtil::loadStyleSheet());
|
||||
|
||||
QString desc = idx.data(TransactionTableModel::LongDescriptionRole).toString();
|
||||
ui->detailText->setHtml(desc);
|
||||
}
|
||||
|
@ -561,7 +561,7 @@ void TransactionView::showDetails()
|
||||
QModelIndexList selection = transactionView->selectionModel()->selectedRows();
|
||||
if(!selection.isEmpty())
|
||||
{
|
||||
TransactionDescDialog *dlg = new TransactionDescDialog(selection.at(0));
|
||||
TransactionDescDialog* dlg = new TransactionDescDialog(selection.at(0), this);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dlg->show();
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, HelpMode helpMode) :
|
||||
strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changed in the GUI").toStdString());
|
||||
if (showDebug) {
|
||||
strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM));
|
||||
strUsage += HelpMessageOpt("-debug-ui", "Updates the UI's stylesheets in realtime with changes made to the css files in -custom-css-dir and forces some widgets to show up which are usually only visible under certain circumstances. (default: 0)");
|
||||
}
|
||||
QString coreOptions = QString::fromStdString(strUsage);
|
||||
text = version + "\n" + header + "\n" + coreOptions;
|
||||
@ -209,8 +210,7 @@ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
|
||||
{
|
||||
setObjectName("ShutdownWindow");
|
||||
|
||||
/* Open CSS when configured */
|
||||
this->setStyleSheet(GUIUtil::loadStyleSheet());
|
||||
GUIUtil::loadStyleSheet(this, false);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout();
|
||||
layout->addWidget(new QLabel(
|
||||
|
@ -379,8 +379,7 @@ void WalletView::showProgress(const QString &title, int nProgress)
|
||||
{
|
||||
if (nProgress == 0)
|
||||
{
|
||||
progressDialog = new QProgressDialog(title, "", 0, 100);
|
||||
progressDialog->setStyleSheet(GUIUtil::loadStyleSheet());
|
||||
progressDialog = new QProgressDialog(title, "", 0, 100, this);
|
||||
progressDialog->setWindowModality(Qt::ApplicationModal);
|
||||
progressDialog->setMinimumDuration(0);
|
||||
progressDialog->setCancelButton(0);
|
||||
|
Loading…
Reference in New Issue
Block a user