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)
This commit is contained in:
Jonas Schnelli 2016-01-28 10:23:12 +01:00
commit cdcbc59a42
No known key found for this signature in database
GPG key ID: 29D4BCB6416F53EC
9 changed files with 203 additions and 30 deletions

View file

@ -21,6 +21,7 @@ License: GPL-3+
Files: src/qt/res/icons/add.png Files: src/qt/res/icons/add.png
src/qt/res/icons/address-book.png src/qt/res/icons/address-book.png
src/qt/res/icons/chevron.png
src/qt/res/icons/configure.png src/qt/res/icons/configure.png
src/qt/res/icons/debugwindow.png src/qt/res/icons/debugwindow.png
src/qt/res/icons/edit.png src/qt/res/icons/edit.png
@ -56,6 +57,8 @@ Comment: Inspired by Stephan Hutchings Typicons
Files: src/qt/res/icons/tx_mined.png Files: src/qt/res/icons/tx_mined.png
src/qt/res/src/mine.svg src/qt/res/src/mine.svg
src/qt/res/icons/fontbigger.png
src/qt/res/icons/fontsmaller.png
Copyright: Jonas Schnelli Copyright: Jonas Schnelli
License: Expat License: Expat
Comment: Comment:

View file

@ -225,6 +225,7 @@ RES_ICONS = \
qt/res/icons/about_qt.png \ qt/res/icons/about_qt.png \
qt/res/icons/bitcoin.ico \ qt/res/icons/bitcoin.ico \
qt/res/icons/bitcoin.png \ qt/res/icons/bitcoin.png \
qt/res/icons/chevron.png \
qt/res/icons/clock1.png \ qt/res/icons/clock1.png \
qt/res/icons/clock2.png \ qt/res/icons/clock2.png \
qt/res/icons/clock3.png \ qt/res/icons/clock3.png \
@ -245,6 +246,8 @@ RES_ICONS = \
qt/res/icons/eye_minus.png \ qt/res/icons/eye_minus.png \
qt/res/icons/eye_plus.png \ qt/res/icons/eye_plus.png \
qt/res/icons/filesave.png \ qt/res/icons/filesave.png \
qt/res/icons/fontbigger.png \
qt/res/icons/fontsmaller.png \
qt/res/icons/history.png \ qt/res/icons/history.png \
qt/res/icons/info.png \ qt/res/icons/info.png \
qt/res/icons/key.png \ qt/res/icons/key.png \

View file

@ -46,6 +46,9 @@
<file alias="about_qt">res/icons/about_qt.png</file> <file alias="about_qt">res/icons/about_qt.png</file>
<file alias="verify">res/icons/verify.png</file> <file alias="verify">res/icons/verify.png</file>
<file alias="warning">res/icons/warning.png</file> <file alias="warning">res/icons/warning.png</file>
<file alias="fontbigger">res/icons/fontbigger.png</file>
<file alias="fontsmaller">res/icons/fontsmaller.png</file>
<file alias="prompticon">res/icons/chevron.png</file>
</qresource> </qresource>
<qresource prefix="/movies"> <qresource prefix="/movies">
<file alias="spinner-000">res/movies/spinner-000.png</file> <file alias="spinner-000">res/movies/spinner-000.png</file>

View file

@ -450,6 +450,125 @@
<property name="spacing"> <property name="spacing">
<number>3</number> <number>3</number>
</property> </property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>4</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="fontSmallerButton">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="toolTip">
<string>Decrease font size</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/fontsmaller</normaloff>:/icons/fontsmaller</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>16</height>
</size>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fontBiggerButton">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolTip">
<string>Increase font size</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/fontbigger</normaloff>:/icons/fontbigger</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>16</height>
</size>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearButton">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolTip">
<string>Clear console</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
</property>
<property name="shortcut">
<string notr="true">Ctrl+L</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<widget class="QTextEdit" name="messagesWidget"> <widget class="QTextEdit" name="messagesWidget">
<property name="minimumSize"> <property name="minimumSize">
@ -470,44 +589,48 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayoutPrompt">
<property name="spacing"> <property name="spacing">
<number>3</number> <number>3</number>
</property> </property>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QPushButton" name="promptIcon">
<property name="text"> <property name="enabled">
<string notr="true">&gt;</string> <bool>false</bool>
</property> </property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="clearButton">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>24</width> <width>16</width>
<height>24</height> <height>24</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>Clear console</string>
</property>
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../bitcoin.qrc"> <iconset resource="../bitcoin.qrc">
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset> <normaloff>:/icons/prompticon</normaloff>
<disabledoff>:/icons/prompticon</disabledoff>:/icons/prompticon</iconset>
</property> </property>
<property name="shortcut"> <property name="iconSize">
<string notr="true">Ctrl+L</string> <size>
<width>14</width>
<height>14</height>
</size>
</property> </property>
<property name="autoDefault"> <property name="autoDefault">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="placeholderText">
<string/>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 951 B

View file

@ -27,6 +27,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <QScrollBar> #include <QScrollBar>
#include <QSettings>
#include <QSignalMapper> #include <QSignalMapper>
#include <QThread> #include <QThread>
#include <QTime> #include <QTime>
@ -41,9 +42,9 @@
// TODO: receive errors and debug messages through ClientModel // TODO: receive errors and debug messages through ClientModel
const int CONSOLE_HISTORY = 50; const int CONSOLE_HISTORY = 50;
const QSize ICON_SIZE(24, 24);
const int INITIAL_TRAFFIC_GRAPH_MINS = 30; const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
const QSize FONT_RANGE(4, 40);
const char fontSizeSettingsKey[] = "consoleFontSize";
const struct { const struct {
const char *url; const char *url;
@ -245,7 +246,8 @@ RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) :
cachedNodeid(-1), cachedNodeid(-1),
platformStyle(platformStyle), platformStyle(platformStyle),
peersTableContextMenu(0), peersTableContextMenu(0),
banTableContextMenu(0) banTableContextMenu(0),
consoleFontSize(0)
{ {
ui->setupUi(this); ui->setupUi(this);
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), 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->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
} }
ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove")); 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 // Install event filter for up and down arrow
ui->lineEdit->installEventFilter(this); ui->lineEdit->installEventFilter(this);
ui->messagesWidget->installEventFilter(this); ui->messagesWidget->installEventFilter(this);
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); 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())); connect(ui->btnClearTrafficGraph, SIGNAL(clicked()), ui->trafficGraph, SLOT(clear()));
// set library version labels // set library version labels
@ -288,6 +294,8 @@ RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) :
ui->detailWidget->hide(); ui->detailWidget->hide();
ui->peerHeading->setText(tr("Select a peer to view detailed information.")); ui->peerHeading->setText(tr("Select a peer to view detailed information."));
QSettings settings;
consoleFontSize = settings.value(fontSizeSettingsKey, QFontInfo(QFont()).pointSize()).toInt();
clear(); clear();
} }
@ -453,6 +461,41 @@ 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
float oldPosFactor = 1.0 / ui->messagesWidget->verticalScrollBar()->maximum() * ui->messagesWidget->verticalScrollBar()->value();
clear();
ui->messagesWidget->setHtml(str);
ui->messagesWidget->verticalScrollBar()->setValue(oldPosFactor * ui->messagesWidget->verticalScrollBar()->maximum());
}
void RPCConsole::clear() void RPCConsole::clear()
{ {
ui->messagesWidget->clear(); ui->messagesWidget->clear();
@ -468,26 +511,20 @@ void RPCConsole::clear()
ui->messagesWidget->document()->addResource( ui->messagesWidget->document()->addResource(
QTextDocument::ImageResource, QTextDocument::ImageResource,
QUrl(ICON_MAPPING[i].url), 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 // Set default style sheet
QFontInfo fixedFontInfo(GUIUtil::fixedPitchFont()); 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( ui->messagesWidget->document()->setDefaultStyleSheet(
QString( QString(
"table { }" "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.message { font-family: %1; font-size: %2; white-space:pre-wrap; } "
"td.cmd-request { color: #006060; } " "td.cmd-request { color: #006060; } "
"td.cmd-error { color: red; } " "td.cmd-error { color: red; } "
"b { color: #006060; } " "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.") + "<br>" + message(CMD_REPLY, (tr("Welcome to the Bitcoin Core RPC console.") + "<br>" +

View file

@ -78,6 +78,9 @@ private Q_SLOTS:
public Q_SLOTS: public Q_SLOTS:
void clear(); void clear();
void fontBigger();
void fontSmaller();
void setFontSize(int newSize);
/** Append the message to the message widget */ /** Append the message to the message widget */
void message(int category, const QString &message, bool html = false); void message(int category, const QString &message, bool html = false);
/** Set number of connections shown in the UI */ /** Set number of connections shown in the UI */
@ -134,6 +137,7 @@ private:
RPCTimerInterface *rpcTimerInterface; RPCTimerInterface *rpcTimerInterface;
QMenu *peersTableContextMenu; QMenu *peersTableContextMenu;
QMenu *banTableContextMenu; QMenu *banTableContextMenu;
int consoleFontSize;
}; };
#endif // BITCOIN_QT_RPCCONSOLE_H #endif // BITCOIN_QT_RPCCONSOLE_H