From 3a3a9273255f1caa68c96c327489938f7f310806 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 22 Jan 2016 18:00:36 +0100 Subject: [PATCH] [Qt] Add option to increase/decrease font size in the console window --- src/Makefile.qt.include | 2 + src/qt/bitcoin.qrc | 2 + src/qt/forms/debugwindow.ui | 136 +++++++++++++++++++++++++------ src/qt/res/icons/fontbigger.png | Bin 0 -> 1180 bytes src/qt/res/icons/fontsmaller.png | Bin 0 -> 951 bytes src/qt/rpcconsole.cpp | 59 +++++++++++--- src/qt/rpcconsole.h | 4 + 7 files changed, 168 insertions(+), 35 deletions(-) create mode 100644 src/qt/res/icons/fontbigger.png create mode 100644 src/qt/res/icons/fontsmaller.png diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index a390d96a9..82e95abcf 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -245,6 +245,8 @@ RES_ICONS = \ qt/res/icons/eye_minus.png \ qt/res/icons/eye_plus.png \ qt/res/icons/filesave.png \ + qt/res/icons/fontbigger.png \ + qt/res/icons/fontsmaller.png \ qt/res/icons/history.png \ qt/res/icons/info.png \ qt/res/icons/key.png \ diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc index c899e9550..3c9b9d283 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -46,6 +46,8 @@ res/icons/about_qt.png res/icons/verify.png res/icons/warning.png + res/icons/fontbigger.png + res/icons/fontsmaller.png res/movies/spinner-000.png diff --git a/src/qt/forms/debugwindow.ui b/src/qt/forms/debugwindow.ui index 247147036..045eb80d9 100644 --- a/src/qt/forms/debugwindow.ui +++ b/src/qt/forms/debugwindow.ui @@ -450,39 +450,90 @@ 3 - - - - - 0 - 100 - - - - true - - - false - - - 2 - - - + + 5 + - 3 + 4 - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 24 + 24 + + + + Decrease Font Size + - > + + + + + :/icons/fontsmaller:/icons/fontsmaller + + + + 24 + 16 + + + + false + + + true - + + + + 24 + 24 + + + + Increase Font Size + + + + + + + :/icons/fontbigger:/icons/fontbigger + + + + 24 + 16 + + + + false + + + true + + @@ -495,6 +546,9 @@ Clear console + + Qt::LeftToRight + @@ -508,6 +562,42 @@ false + + true + + + + + + + + + + 0 + 100 + + + + true + + + false + + + 2 + + + + + + + 3 + + + + + > + diff --git a/src/qt/res/icons/fontbigger.png b/src/qt/res/icons/fontbigger.png new file mode 100644 index 0000000000000000000000000000000000000000..5ca5c563b25ecc2b90a064db3f86e02aa759bb66 GIT binary patch literal 1180 zcmV;N1Y`S&P)qpXJ000DINklA_IpxrUdgwZ&!Liq~JNrkPfg#{Xt6lxPqy2VvWi(9#@%Fmh1OY5AfW-x{xBwOp z5wHcT0W?JKn_gT1^8(Hc;5Gn80yu2IV?)3-fJ6X?2{GvJjqu>iIQICTJbWlb!A?Ex+v0j>nFAHX&7naZk( z1+X2!nSt!7IW@5WwgZ@=ea8l&U0V}7TD1ZIuK^4Jd{91ApBbBPz*Oy~*=NXy6j?4uJ0(b-aiX zaAx_r*&~)$cm%u+;H<5HDcX10$d?kPYma~v0H221V2`op}Ph3E*2B0aHOF z8a;wi?${IH7XXgi2)MKf;ekzTet8_oq@%V0PHl(L2R5)7{+R(k2QY0LVAkY-L6|N* z&18MlsN1<3aYq4|HN9srLZ7RNiEUg{J#LZjs=uE#>h%-An|tRh@-?4;soHndMeEe- z6o!CP0Podv^Oz3p0B{E2+R?Hj9lxH9 zTU-H7z%bLaz(zI(bDC}318@}(+?ihi*mDJ#Wv-YZOpghGhXKN!`Op<$mTV70GUGo@ ztl7qcfB_%40L+%JWeU@|0A3An0iLPJWky}ERZ56n4R9Us4OsZ>mqFI@#%B@2y&JuY zOj_RfaioB23lklcO6Z@ewBU&f|5E^;02~7Ntx=a-0AJL!=2Vq`4B)FO`%GQS?L-Io z_xo~tW;j*3qvntk09z_OxS^5^&y*jokZgFW&Rth!ZK|@j)wSGCRf2!NFSn1FlMPQ) zPu2na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#include +#include #include #include #include @@ -41,9 +42,9 @@ // TODO: receive errors and debug messages through ClientModel const int CONSOLE_HISTORY = 50; -const QSize ICON_SIZE(24, 24); - const int INITIAL_TRAFFIC_GRAPH_MINS = 30; +const QSize FONT_RANGE(4, 40); +const char fontSizeSettingsKey[] = "consoleFontSize"; const struct { const char *url; @@ -245,7 +246,8 @@ RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) : cachedNodeid(-1), platformStyle(platformStyle), peersTableContextMenu(0), - banTableContextMenu(0) + banTableContextMenu(0), + consoleFontSize(0) { ui->setupUi(this); GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this); @@ -254,12 +256,16 @@ RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) : ui->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export")); } ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove")); + ui->fontBiggerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontbigger")); + ui->fontSmallerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontsmaller")); // Install event filter for up and down arrow ui->lineEdit->installEventFilter(this); ui->messagesWidget->installEventFilter(this); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); + connect(ui->fontBiggerButton, SIGNAL(clicked()), this, SLOT(fontBigger())); + connect(ui->fontSmallerButton, SIGNAL(clicked()), this, SLOT(fontSmaller())); connect(ui->btnClearTrafficGraph, SIGNAL(clicked()), ui->trafficGraph, SLOT(clear())); // set library version labels @@ -288,6 +294,8 @@ RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) : ui->detailWidget->hide(); ui->peerHeading->setText(tr("Select a peer to view detailed information.")); + QSettings settings; + consoleFontSize = settings.value(fontSizeSettingsKey, QFontInfo(QFont()).pointSize()).toInt(); clear(); } @@ -453,6 +461,39 @@ static QString categoryClass(int category) } } +void RPCConsole::fontBigger() +{ + setFontSize(consoleFontSize+1); +} + +void RPCConsole::fontSmaller() +{ + setFontSize(consoleFontSize-1); +} + +void RPCConsole::setFontSize(int newSize) +{ + QSettings settings; + + //don't allow a insane font size + if (newSize < FONT_RANGE.width() || newSize > FONT_RANGE.height()) + return; + + // temp. store the console content + QString str = ui->messagesWidget->toHtml(); + + // replace font tags size in current content + str.replace(QString("font-size:%1pt").arg(consoleFontSize), QString("font-size:%1pt").arg(newSize)); + + // store the new font size + consoleFontSize = newSize; + settings.setValue(fontSizeSettingsKey, consoleFontSize); + + // clear console (reset icon sizes, default stylesheet) and re-add the content + clear(); + ui->messagesWidget->setHtml(str); +} + void RPCConsole::clear() { ui->messagesWidget->clear(); @@ -468,26 +509,20 @@ void RPCConsole::clear() ui->messagesWidget->document()->addResource( QTextDocument::ImageResource, QUrl(ICON_MAPPING[i].url), - platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(ICON_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(QSize(consoleFontSize*2, consoleFontSize*2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } // Set default style sheet QFontInfo fixedFontInfo(GUIUtil::fixedPitchFont()); - // Try to make fixed font adequately large on different OS -#ifdef WIN32 - QString ptSize = QString("%1pt").arg(QFontInfo(QFont()).pointSize() * 10 / 8); -#else - QString ptSize = QString("%1pt").arg(QFontInfo(QFont()).pointSize() * 8.5 / 9); -#endif ui->messagesWidget->document()->setDefaultStyleSheet( QString( "table { }" - "td.time { color: #808080; padding-top: 3px; } " + "td.time { color: #808080; font-size: %2; padding-top: 3px; } " "td.message { font-family: %1; font-size: %2; white-space:pre-wrap; } " "td.cmd-request { color: #006060; } " "td.cmd-error { color: red; } " "b { color: #006060; } " - ).arg(fixedFontInfo.family(), ptSize) + ).arg(fixedFontInfo.family(), QString("%1pt").arg(consoleFontSize)) ); message(CMD_REPLY, (tr("Welcome to the Bitcoin Core RPC console.") + "
" + diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 8a48179c5..83b543e54 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -78,6 +78,9 @@ private Q_SLOTS: public Q_SLOTS: void clear(); + void fontBigger(); + void fontSmaller(); + void setFontSize(int newSize); /** Append the message to the message widget */ void message(int category, const QString &message, bool html = false); /** Set number of connections shown in the UI */ @@ -134,6 +137,7 @@ private: RPCTimerInterface *rpcTimerInterface; QMenu *peersTableContextMenu; QMenu *banTableContextMenu; + int consoleFontSize; }; #endif // BITCOIN_QT_RPCCONSOLE_H