Add console font size setting and a preview\

Also moves the console settings from the minecraft page.
This commit is contained in:
Petr Mrázek 2014-11-11 00:50:17 +01:00
parent 5711b1be95
commit 41bd2a6634
7 changed files with 201 additions and 65 deletions

View File

@ -407,6 +407,7 @@ void MultiMC::initGlobalSettings(bool test_mode)
// in test mode, we don't have UI, so we don't do any font resolving
m_settings->registerSetting("ConsoleFont", defaultMonospace);
}
m_settings->registerSetting("ConsoleFontSize", 11);
// FTB
m_settings->registerSetting("TrackFTBInstances", false);

View File

@ -21,7 +21,13 @@ LogPage::LogPage(MinecraftProcess *proc, QWidget *parent)
// create the format and set its font
defaultFormat = new QTextCharFormat(ui->text->currentCharFormat());
QString fontFamily = MMC->settings()->get("ConsoleFont").toString();
defaultFormat->setFont(QFont(fontFamily));
bool conversionOk = false;
int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk);
if(!conversionOk)
{
fontSize = 11;
}
defaultFormat->setFont(QFont(fontFamily, fontSize));
auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this);
connect(findShortcut, SIGNAL(activated()), SLOT(findActivated()));

View File

@ -77,10 +77,6 @@ void MinecraftPage::applySettings()
// Minecraft version updates
s->set("AutoUpdateMinecraftVersions", ui->autoupdateMinecraft->isChecked());
// Console
s->set("ShowConsole", ui->showConsoleCheck->isChecked());
s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
// Window Size
s->set("LaunchMaximized", ui->maximizedCheckBox->isChecked());
s->set("MinecraftWinWidth", ui->windowWidthSpinBox->value());
@ -92,10 +88,6 @@ void MinecraftPage::loadSettings()
auto s = MMC->settings();
// Minecraft version updates
ui->autoupdateMinecraft->setChecked(s->get("AutoUpdateMinecraftVersions").toBool());
// Console
ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool());
ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool());
// Window Size
ui->maximizedCheckBox->setChecked(s->get("LaunchMaximized").toBool());

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>545</width>
<height>609</height>
<height>270</height>
</rect>
</property>
<property name="sizePolicy">
@ -83,14 +83,20 @@
<item row="1" column="0">
<widget class="QLabel" name="labelWindowHeight">
<property name="text">
<string>Window height:</string>
<string>Window hei&amp;ght:</string>
</property>
<property name="buddy">
<cstring>windowHeightSpinBox</cstring>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelWindowWidth">
<property name="text">
<string>Window width:</string>
<string>W&amp;indow width:</string>
</property>
<property name="buddy">
<cstring>windowWidthSpinBox</cstring>
</property>
</widget>
</item>
@ -128,29 +134,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="consoleSettingsBox">
<property name="title">
<string>Console Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="showConsoleCheck">
<property name="text">
<string>Show console while the game is running?</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoCloseConsoleCheck">
<property name="text">
<string>Automatically close console when the game quits?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacerMinecraft">
<property name="orientation">
@ -158,8 +141,8 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
@ -176,8 +159,6 @@
<tabstop>maximizedCheckBox</tabstop>
<tabstop>windowWidthSpinBox</tabstop>
<tabstop>windowHeightSpinBox</tabstop>
<tabstop>showConsoleCheck</tabstop>
<tabstop>autoCloseConsoleCheck</tabstop>
</tabstops>
<resources/>
<connections/>

View File

@ -19,6 +19,7 @@
#include <QFileDialog>
#include <QMessageBox>
#include <QDir>
#include <QTextCharFormat>
#include <pathutils.h>
@ -59,6 +60,8 @@ MultiMCPage::MultiMCPage(QWidget *parent) : QWidget(parent), ui(new Ui::MultiMCP
resizer->addWidgetsFromLayout(ui->groupBox->layout(), 1);
resizer->addWidgetsFromLayout(ui->foldersBox->layout(), 1);
defaultFormat = new QTextCharFormat(ui->fontPreview->currentCharFormat());
loadSettings();
QObject::connect(MMC->updateChecker().get(), &UpdateChecker::channelListLoaded, this,
@ -72,6 +75,8 @@ MultiMCPage::MultiMCPage(QWidget *parent) : QWidget(parent), ui(new Ui::MultiMCP
{
MMC->updateChecker()->updateChanList(false);
}
connect(ui->fontSizeBox, SIGNAL(valueChanged(int)), SLOT(refreshFontPreview()));
connect(ui->consoleFont, SIGNAL(currentFontChanged(QFont)), SLOT(refreshFontPreview()));
}
MultiMCPage::~MultiMCPage()
@ -295,8 +300,11 @@ void MultiMCPage::applySettings()
}
// Console settings
s->set("ShowConsole", ui->showConsoleCheck->isChecked());
s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
QString consoleFontFamily = ui->consoleFont->currentFont().family();
s->set("ConsoleFont", consoleFontFamily);
s->set("ConsoleFontSize", ui->fontSizeBox->value());
// FTB
s->set("TrackFTBInstances", ui->trackFtbBox->isChecked());
@ -372,10 +380,21 @@ void MultiMCPage::loadSettings()
}
// Console settings
ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool());
ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool());
QString fontFamily = MMC->settings()->get("ConsoleFont").toString();
QFont consoleFont(fontFamily);
ui->consoleFont->setCurrentFont(consoleFont);
bool conversionOk = true;
int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk);
if(!conversionOk)
{
fontSize = 11;
}
ui->fontSizeBox->setValue(fontSize);
refreshFontPreview();
// FTB
ui->trackFtbBox->setChecked(s->get("TrackFTBInstances").toBool());
ui->ftbLauncherBox->setText(s->get("FTBLauncherRoot").toString());
@ -398,3 +417,37 @@ void MultiMCPage::loadSettings()
ui->sortByNameBtn->setChecked(true);
}
}
void MultiMCPage::refreshFontPreview()
{
int fontSize = ui->fontSizeBox->value();
QString fontFamily = ui->consoleFont->currentFont().family();
ui->fontPreview->clear();
defaultFormat->setFont(QFont(fontFamily, fontSize));
{
QTextCharFormat format(*defaultFormat);
format.setForeground(QColor("red"));
// append a paragraph/line
auto workCursor = ui->fontPreview->textCursor();
workCursor.movePosition(QTextCursor::End);
workCursor.insertText(tr("[Something/ERROR] A spooky error!"), format);
workCursor.insertBlock();
}
{
QTextCharFormat format(*defaultFormat);
// append a paragraph/line
auto workCursor = ui->fontPreview->textCursor();
workCursor.movePosition(QTextCursor::End);
workCursor.insertText(tr("[Test/INFO] A harmless message..."), format);
workCursor.insertBlock();
}
{
QTextCharFormat format(*defaultFormat);
format.setForeground(QColor("orange"));
// append a paragraph/line
auto workCursor = ui->fontPreview->textCursor();
workCursor.movePosition(QTextCursor::End);
workCursor.insertText(tr("[Something/WARN] A not so spooky warning."), format);
workCursor.insertBlock();
}
}

View File

@ -21,6 +21,7 @@
#include "logic/java/JavaChecker.h"
#include "gui/pages/BasePage.h"
class QTextCharFormat;
class SettingsObject;
namespace Ui
@ -78,7 +79,12 @@ slots:
*/
void refreshUpdateChannelDesc();
void updateChannelSelectionChanged(int index);
/*!
* Updates the font preview
*/
void refreshFontPreview();
void updateChannelSelectionChanged(int index);
private:
Ui::MultiMCPage *ui;
@ -87,4 +93,7 @@ private:
* Stores the currently selected update channel.
*/
QString m_currentUpdateChannel;
// default format for the font preview...
QTextCharFormat *defaultFormat;
};

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>556</width>
<height>559</height>
<width>487</width>
<height>519</height>
</rect>
</property>
<property name="sizePolicy">
@ -65,7 +65,10 @@
<item>
<widget class="QLabel" name="updateChannelLabel">
<property name="text">
<string>Update Channel:</string>
<string>Up&amp;date Channel:</string>
</property>
<property name="buddy">
<cstring>updateChannelComboBox</cstring>
</property>
</widget>
</item>
@ -98,7 +101,10 @@
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Launcher:</string>
<string>&amp;Launcher:</string>
</property>
<property name="buddy">
<cstring>ftbLauncherBox</cstring>
</property>
</widget>
</item>
@ -117,6 +123,9 @@
<property name="text">
<string>Files:</string>
</property>
<property name="buddy">
<cstring>ftbBox</cstring>
</property>
</widget>
</item>
<item row="3" column="2">
@ -161,7 +170,10 @@
<item row="0" column="0">
<widget class="QLabel" name="labelInstDir">
<property name="text">
<string>Instances:</string>
<string>I&amp;nstances:</string>
</property>
<property name="buddy">
<cstring>instDirTextBox</cstring>
</property>
</widget>
</item>
@ -178,7 +190,10 @@
<item row="1" column="0">
<widget class="QLabel" name="labelModsDir">
<property name="text">
<string>Mods:</string>
<string>&amp;Mods:</string>
</property>
<property name="buddy">
<cstring>modsDirTextBox</cstring>
</property>
</widget>
</item>
@ -198,7 +213,10 @@
<item row="2" column="0">
<widget class="QLabel" name="labelLWJGLDir">
<property name="text">
<string>LWJGL:</string>
<string>LW&amp;JGL:</string>
</property>
<property name="buddy">
<cstring>lwjglDirTextBox</cstring>
</property>
</widget>
</item>
@ -215,7 +233,10 @@
<item row="3" column="0">
<widget class="QLabel" name="labelIconsDir">
<property name="text">
<string>Icons:</string>
<string>&amp;Icons:</string>
</property>
<property name="buddy">
<cstring>iconsDirTextBox</cstring>
</property>
</widget>
</item>
@ -236,8 +257,8 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
@ -369,13 +390,81 @@
</layout>
</widget>
</item>
<item>
<spacer name="generalTabSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Console</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="consoleSettingsBox">
<property name="title">
<string>Console Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="showConsoleCheck">
<property name="text">
<string>Show console while the game is running?</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoCloseConsoleCheck">
<property name="text">
<string>Automatically close console when the game quits?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="themeBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Console font</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0" colspan="2">
<widget class="QTextEdit" name="fontPreview">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QFontComboBox" name="consoleFont">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -385,22 +474,22 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="fontSizeBox">
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<number>16</number>
</property>
<property name="value">
<number>11</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="generalTabSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
@ -429,6 +518,11 @@
<tabstop>sortByNameBtn</tabstop>
<tabstop>languageBox</tabstop>
<tabstop>themeComboBox</tabstop>
<tabstop>showConsoleCheck</tabstop>
<tabstop>autoCloseConsoleCheck</tabstop>
<tabstop>consoleFont</tabstop>
<tabstop>fontSizeBox</tabstop>
<tabstop>fontPreview</tabstop>
</tabstops>
<resources/>
<connections/>