Skip to content

Commit cdcbc59

Browse files
committed
Merge #7396: [Qt] Add option to increase/decrease font size in the console window
43abb02 [Qt] Add a new chevron/arrow icon for the console prompt line (Jonas Schnelli) 56c9e66 [Qt] keep scroll position in GUI console after changing font size (Jonas Schnelli) 3a3a927 [Qt] Add option to increase/decrease font size in the console window (Jonas Schnelli)
2 parents 9189e30 + 43abb02 commit cdcbc59

File tree

9 files changed

+203
-30
lines changed

9 files changed

+203
-30
lines changed

contrib/debian/copyright

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ License: GPL-3+
2121

2222
Files: src/qt/res/icons/add.png
2323
src/qt/res/icons/address-book.png
24+
src/qt/res/icons/chevron.png
2425
src/qt/res/icons/configure.png
2526
src/qt/res/icons/debugwindow.png
2627
src/qt/res/icons/edit.png
@@ -56,6 +57,8 @@ Comment: Inspired by Stephan Hutchings Typicons
5657

5758
Files: src/qt/res/icons/tx_mined.png
5859
src/qt/res/src/mine.svg
60+
src/qt/res/icons/fontbigger.png
61+
src/qt/res/icons/fontsmaller.png
5962
Copyright: Jonas Schnelli
6063
License: Expat
6164
Comment:

src/Makefile.qt.include

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ RES_ICONS = \
225225
qt/res/icons/about_qt.png \
226226
qt/res/icons/bitcoin.ico \
227227
qt/res/icons/bitcoin.png \
228+
qt/res/icons/chevron.png \
228229
qt/res/icons/clock1.png \
229230
qt/res/icons/clock2.png \
230231
qt/res/icons/clock3.png \
@@ -245,6 +246,8 @@ RES_ICONS = \
245246
qt/res/icons/eye_minus.png \
246247
qt/res/icons/eye_plus.png \
247248
qt/res/icons/filesave.png \
249+
qt/res/icons/fontbigger.png \
250+
qt/res/icons/fontsmaller.png \
248251
qt/res/icons/history.png \
249252
qt/res/icons/info.png \
250253
qt/res/icons/key.png \

src/qt/bitcoin.qrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
<file alias="about_qt">res/icons/about_qt.png</file>
4747
<file alias="verify">res/icons/verify.png</file>
4848
<file alias="warning">res/icons/warning.png</file>
49+
<file alias="fontbigger">res/icons/fontbigger.png</file>
50+
<file alias="fontsmaller">res/icons/fontsmaller.png</file>
51+
<file alias="prompticon">res/icons/chevron.png</file>
4952
</qresource>
5053
<qresource prefix="/movies">
5154
<file alias="spinner-000">res/movies/spinner-000.png</file>

src/qt/forms/debugwindow.ui

Lines changed: 141 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,125 @@
450450
<property name="spacing">
451451
<number>3</number>
452452
</property>
453+
<property name="bottomMargin">
454+
<number>5</number>
455+
</property>
456+
<item>
457+
<layout class="QHBoxLayout" name="horizontalLayout">
458+
<property name="spacing">
459+
<number>4</number>
460+
</property>
461+
<item>
462+
<spacer name="horizontalSpacer">
463+
<property name="orientation">
464+
<enum>Qt::Horizontal</enum>
465+
</property>
466+
<property name="sizeHint" stdset="0">
467+
<size>
468+
<width>40</width>
469+
<height>20</height>
470+
</size>
471+
</property>
472+
</spacer>
473+
</item>
474+
<item>
475+
<widget class="QPushButton" name="fontSmallerButton">
476+
<property name="maximumSize">
477+
<size>
478+
<width>24</width>
479+
<height>24</height>
480+
</size>
481+
</property>
482+
<property name="text">
483+
<string/>
484+
</property>
485+
<property name="toolTip">
486+
<string>Decrease font size</string>
487+
</property>
488+
<property name="icon">
489+
<iconset resource="../bitcoin.qrc">
490+
<normaloff>:/icons/fontsmaller</normaloff>:/icons/fontsmaller</iconset>
491+
</property>
492+
<property name="iconSize">
493+
<size>
494+
<width>24</width>
495+
<height>16</height>
496+
</size>
497+
</property>
498+
<property name="autoDefault">
499+
<bool>false</bool>
500+
</property>
501+
<property name="flat">
502+
<bool>true</bool>
503+
</property>
504+
</widget>
505+
</item>
506+
<item>
507+
<widget class="QPushButton" name="fontBiggerButton">
508+
<property name="maximumSize">
509+
<size>
510+
<width>24</width>
511+
<height>24</height>
512+
</size>
513+
</property>
514+
<property name="toolTip">
515+
<string>Increase font size</string>
516+
</property>
517+
<property name="text">
518+
<string/>
519+
</property>
520+
<property name="icon">
521+
<iconset resource="../bitcoin.qrc">
522+
<normaloff>:/icons/fontbigger</normaloff>:/icons/fontbigger</iconset>
523+
</property>
524+
<property name="iconSize">
525+
<size>
526+
<width>24</width>
527+
<height>16</height>
528+
</size>
529+
</property>
530+
<property name="autoDefault">
531+
<bool>false</bool>
532+
</property>
533+
<property name="flat">
534+
<bool>true</bool>
535+
</property>
536+
</widget>
537+
</item>
538+
<item>
539+
<widget class="QPushButton" name="clearButton">
540+
<property name="maximumSize">
541+
<size>
542+
<width>24</width>
543+
<height>24</height>
544+
</size>
545+
</property>
546+
<property name="toolTip">
547+
<string>Clear console</string>
548+
</property>
549+
<property name="layoutDirection">
550+
<enum>Qt::LeftToRight</enum>
551+
</property>
552+
<property name="text">
553+
<string/>
554+
</property>
555+
<property name="icon">
556+
<iconset resource="../bitcoin.qrc">
557+
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
558+
</property>
559+
<property name="shortcut">
560+
<string notr="true">Ctrl+L</string>
561+
</property>
562+
<property name="autoDefault">
563+
<bool>false</bool>
564+
</property>
565+
<property name="flat">
566+
<bool>true</bool>
567+
</property>
568+
</widget>
569+
</item>
570+
</layout>
571+
</item>
453572
<item>
454573
<widget class="QTextEdit" name="messagesWidget">
455574
<property name="minimumSize">
@@ -470,44 +589,48 @@
470589
</widget>
471590
</item>
472591
<item>
473-
<layout class="QHBoxLayout" name="horizontalLayout">
592+
<layout class="QHBoxLayout" name="horizontalLayoutPrompt">
474593
<property name="spacing">
475594
<number>3</number>
476595
</property>
477596
<item>
478-
<widget class="QLabel" name="label">
479-
<property name="text">
480-
<string notr="true">&gt;</string>
597+
<widget class="QPushButton" name="promptIcon">
598+
<property name="enabled">
599+
<bool>false</bool>
481600
</property>
482-
</widget>
483-
</item>
484-
<item>
485-
<widget class="QLineEdit" name="lineEdit"/>
486-
</item>
487-
<item>
488-
<widget class="QPushButton" name="clearButton">
489601
<property name="maximumSize">
490602
<size>
491-
<width>24</width>
603+
<width>16</width>
492604
<height>24</height>
493605
</size>
494606
</property>
495-
<property name="toolTip">
496-
<string>Clear console</string>
497-
</property>
498607
<property name="text">
499608
<string/>
500609
</property>
501610
<property name="icon">
502611
<iconset resource="../bitcoin.qrc">
503-
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
612+
<normaloff>:/icons/prompticon</normaloff>
613+
<disabledoff>:/icons/prompticon</disabledoff>:/icons/prompticon</iconset>
504614
</property>
505-
<property name="shortcut">
506-
<string notr="true">Ctrl+L</string>
615+
<property name="iconSize">
616+
<size>
617+
<width>14</width>
618+
<height>14</height>
619+
</size>
507620
</property>
508621
<property name="autoDefault">
509622
<bool>false</bool>
510623
</property>
624+
<property name="flat">
625+
<bool>true</bool>
626+
</property>
627+
</widget>
628+
</item>
629+
<item>
630+
<widget class="QLineEdit" name="lineEdit">
631+
<property name="placeholderText">
632+
<string/>
633+
</property>
511634
</widget>
512635
</item>
513636
</layout>

src/qt/res/icons/chevron.png

1.88 KB
Loading

src/qt/res/icons/fontbigger.png

1.15 KB
Loading

src/qt/res/icons/fontsmaller.png

951 Bytes
Loading

src/qt/rpcconsole.cpp

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <QKeyEvent>
2828
#include <QMenu>
2929
#include <QScrollBar>
30+
#include <QSettings>
3031
#include <QSignalMapper>
3132
#include <QThread>
3233
#include <QTime>
@@ -41,9 +42,9 @@
4142
// TODO: receive errors and debug messages through ClientModel
4243

4344
const int CONSOLE_HISTORY = 50;
44-
const QSize ICON_SIZE(24, 24);
45-
4645
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
46+
const QSize FONT_RANGE(4, 40);
47+
const char fontSizeSettingsKey[] = "consoleFontSize";
4748

4849
const struct {
4950
const char *url;
@@ -245,7 +246,8 @@ RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) :
245246
cachedNodeid(-1),
246247
platformStyle(platformStyle),
247248
peersTableContextMenu(0),
248-
banTableContextMenu(0)
249+
banTableContextMenu(0),
250+
consoleFontSize(0)
249251
{
250252
ui->setupUi(this);
251253
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this);
@@ -254,12 +256,16 @@ RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) :
254256
ui->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
255257
}
256258
ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
259+
ui->fontBiggerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontbigger"));
260+
ui->fontSmallerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontsmaller"));
257261

258262
// Install event filter for up and down arrow
259263
ui->lineEdit->installEventFilter(this);
260264
ui->messagesWidget->installEventFilter(this);
261265

262266
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
267+
connect(ui->fontBiggerButton, SIGNAL(clicked()), this, SLOT(fontBigger()));
268+
connect(ui->fontSmallerButton, SIGNAL(clicked()), this, SLOT(fontSmaller()));
263269
connect(ui->btnClearTrafficGraph, SIGNAL(clicked()), ui->trafficGraph, SLOT(clear()));
264270

265271
// set library version labels
@@ -288,6 +294,8 @@ RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) :
288294
ui->detailWidget->hide();
289295
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
290296

297+
QSettings settings;
298+
consoleFontSize = settings.value(fontSizeSettingsKey, QFontInfo(QFont()).pointSize()).toInt();
291299
clear();
292300
}
293301

@@ -453,6 +461,41 @@ static QString categoryClass(int category)
453461
}
454462
}
455463

464+
void RPCConsole::fontBigger()
465+
{
466+
setFontSize(consoleFontSize+1);
467+
}
468+
469+
void RPCConsole::fontSmaller()
470+
{
471+
setFontSize(consoleFontSize-1);
472+
}
473+
474+
void RPCConsole::setFontSize(int newSize)
475+
{
476+
QSettings settings;
477+
478+
//don't allow a insane font size
479+
if (newSize < FONT_RANGE.width() || newSize > FONT_RANGE.height())
480+
return;
481+
482+
// temp. store the console content
483+
QString str = ui->messagesWidget->toHtml();
484+
485+
// replace font tags size in current content
486+
str.replace(QString("font-size:%1pt").arg(consoleFontSize), QString("font-size:%1pt").arg(newSize));
487+
488+
// store the new font size
489+
consoleFontSize = newSize;
490+
settings.setValue(fontSizeSettingsKey, consoleFontSize);
491+
492+
// clear console (reset icon sizes, default stylesheet) and re-add the content
493+
float oldPosFactor = 1.0 / ui->messagesWidget->verticalScrollBar()->maximum() * ui->messagesWidget->verticalScrollBar()->value();
494+
clear();
495+
ui->messagesWidget->setHtml(str);
496+
ui->messagesWidget->verticalScrollBar()->setValue(oldPosFactor * ui->messagesWidget->verticalScrollBar()->maximum());
497+
}
498+
456499
void RPCConsole::clear()
457500
{
458501
ui->messagesWidget->clear();
@@ -468,26 +511,20 @@ void RPCConsole::clear()
468511
ui->messagesWidget->document()->addResource(
469512
QTextDocument::ImageResource,
470513
QUrl(ICON_MAPPING[i].url),
471-
platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(ICON_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
514+
platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(QSize(consoleFontSize*2, consoleFontSize*2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
472515
}
473516

474517
// Set default style sheet
475518
QFontInfo fixedFontInfo(GUIUtil::fixedPitchFont());
476-
// Try to make fixed font adequately large on different OS
477-
#ifdef WIN32
478-
QString ptSize = QString("%1pt").arg(QFontInfo(QFont()).pointSize() * 10 / 8);
479-
#else
480-
QString ptSize = QString("%1pt").arg(QFontInfo(QFont()).pointSize() * 8.5 / 9);
481-
#endif
482519
ui->messagesWidget->document()->setDefaultStyleSheet(
483520
QString(
484521
"table { }"
485-
"td.time { color: #808080; padding-top: 3px; } "
522+
"td.time { color: #808080; font-size: %2; padding-top: 3px; } "
486523
"td.message { font-family: %1; font-size: %2; white-space:pre-wrap; } "
487524
"td.cmd-request { color: #006060; } "
488525
"td.cmd-error { color: red; } "
489526
"b { color: #006060; } "
490-
).arg(fixedFontInfo.family(), ptSize)
527+
).arg(fixedFontInfo.family(), QString("%1pt").arg(consoleFontSize))
491528
);
492529

493530
message(CMD_REPLY, (tr("Welcome to the Bitcoin Core RPC console.") + "<br>" +

src/qt/rpcconsole.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ private Q_SLOTS:
7878

7979
public Q_SLOTS:
8080
void clear();
81+
void fontBigger();
82+
void fontSmaller();
83+
void setFontSize(int newSize);
8184
/** Append the message to the message widget */
8285
void message(int category, const QString &message, bool html = false);
8386
/** Set number of connections shown in the UI */
@@ -134,6 +137,7 @@ public Q_SLOTS:
134137
RPCTimerInterface *rpcTimerInterface;
135138
QMenu *peersTableContextMenu;
136139
QMenu *banTableContextMenu;
140+
int consoleFontSize;
137141
};
138142

139143
#endif // BITCOIN_QT_RPCCONSOLE_H

0 commit comments

Comments
 (0)