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 // in test mode, we don't have UI, so we don't do any font resolving
m_settings->registerSetting("ConsoleFont", defaultMonospace); m_settings->registerSetting("ConsoleFont", defaultMonospace);
} }
m_settings->registerSetting("ConsoleFontSize", 11);
// FTB // FTB
m_settings->registerSetting("TrackFTBInstances", false); m_settings->registerSetting("TrackFTBInstances", false);

View File

@ -21,7 +21,13 @@ LogPage::LogPage(MinecraftProcess *proc, QWidget *parent)
// create the format and set its font // create the format and set its font
defaultFormat = new QTextCharFormat(ui->text->currentCharFormat()); defaultFormat = new QTextCharFormat(ui->text->currentCharFormat());
QString fontFamily = MMC->settings()->get("ConsoleFont").toString(); 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); auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this);
connect(findShortcut, SIGNAL(activated()), SLOT(findActivated())); connect(findShortcut, SIGNAL(activated()), SLOT(findActivated()));

View File

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

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>545</width> <width>545</width>
<height>609</height> <height>270</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -83,14 +83,20 @@
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="labelWindowHeight"> <widget class="QLabel" name="labelWindowHeight">
<property name="text"> <property name="text">
<string>Window height:</string> <string>Window hei&amp;ght:</string>
</property>
<property name="buddy">
<cstring>windowHeightSpinBox</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="labelWindowWidth"> <widget class="QLabel" name="labelWindowWidth">
<property name="text"> <property name="text">
<string>Window width:</string> <string>W&amp;indow width:</string>
</property>
<property name="buddy">
<cstring>windowWidthSpinBox</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -128,29 +134,6 @@
</layout> </layout>
</widget> </widget>
</item> </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> <item>
<spacer name="verticalSpacerMinecraft"> <spacer name="verticalSpacerMinecraft">
<property name="orientation"> <property name="orientation">
@ -158,8 +141,8 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>0</width>
<height>40</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
@ -176,8 +159,6 @@
<tabstop>maximizedCheckBox</tabstop> <tabstop>maximizedCheckBox</tabstop>
<tabstop>windowWidthSpinBox</tabstop> <tabstop>windowWidthSpinBox</tabstop>
<tabstop>windowHeightSpinBox</tabstop> <tabstop>windowHeightSpinBox</tabstop>
<tabstop>showConsoleCheck</tabstop>
<tabstop>autoCloseConsoleCheck</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -19,6 +19,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QDir> #include <QDir>
#include <QTextCharFormat>
#include <pathutils.h> #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->groupBox->layout(), 1);
resizer->addWidgetsFromLayout(ui->foldersBox->layout(), 1); resizer->addWidgetsFromLayout(ui->foldersBox->layout(), 1);
defaultFormat = new QTextCharFormat(ui->fontPreview->currentCharFormat());
loadSettings(); loadSettings();
QObject::connect(MMC->updateChecker().get(), &UpdateChecker::channelListLoaded, this, 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); MMC->updateChecker()->updateChanList(false);
} }
connect(ui->fontSizeBox, SIGNAL(valueChanged(int)), SLOT(refreshFontPreview()));
connect(ui->consoleFont, SIGNAL(currentFontChanged(QFont)), SLOT(refreshFontPreview()));
} }
MultiMCPage::~MultiMCPage() MultiMCPage::~MultiMCPage()
@ -295,8 +300,11 @@ void MultiMCPage::applySettings()
} }
// Console settings // Console settings
s->set("ShowConsole", ui->showConsoleCheck->isChecked());
s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
QString consoleFontFamily = ui->consoleFont->currentFont().family(); QString consoleFontFamily = ui->consoleFont->currentFont().family();
s->set("ConsoleFont", consoleFontFamily); s->set("ConsoleFont", consoleFontFamily);
s->set("ConsoleFontSize", ui->fontSizeBox->value());
// FTB // FTB
s->set("TrackFTBInstances", ui->trackFtbBox->isChecked()); s->set("TrackFTBInstances", ui->trackFtbBox->isChecked());
@ -372,10 +380,21 @@ void MultiMCPage::loadSettings()
} }
// Console settings // Console settings
ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool());
ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool());
QString fontFamily = MMC->settings()->get("ConsoleFont").toString(); QString fontFamily = MMC->settings()->get("ConsoleFont").toString();
QFont consoleFont(fontFamily); QFont consoleFont(fontFamily);
ui->consoleFont->setCurrentFont(consoleFont); 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 // FTB
ui->trackFtbBox->setChecked(s->get("TrackFTBInstances").toBool()); ui->trackFtbBox->setChecked(s->get("TrackFTBInstances").toBool());
ui->ftbLauncherBox->setText(s->get("FTBLauncherRoot").toString()); ui->ftbLauncherBox->setText(s->get("FTBLauncherRoot").toString());
@ -398,3 +417,37 @@ void MultiMCPage::loadSettings()
ui->sortByNameBtn->setChecked(true); 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 "logic/java/JavaChecker.h"
#include "gui/pages/BasePage.h" #include "gui/pages/BasePage.h"
class QTextCharFormat;
class SettingsObject; class SettingsObject;
namespace Ui namespace Ui
@ -78,7 +79,12 @@ slots:
*/ */
void refreshUpdateChannelDesc(); void refreshUpdateChannelDesc();
void updateChannelSelectionChanged(int index); /*!
* Updates the font preview
*/
void refreshFontPreview();
void updateChannelSelectionChanged(int index);
private: private:
Ui::MultiMCPage *ui; Ui::MultiMCPage *ui;
@ -87,4 +93,7 @@ private:
* Stores the currently selected update channel. * Stores the currently selected update channel.
*/ */
QString m_currentUpdateChannel; QString m_currentUpdateChannel;
// default format for the font preview...
QTextCharFormat *defaultFormat;
}; };

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>556</width> <width>487</width>
<height>559</height> <height>519</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -65,7 +65,10 @@
<item> <item>
<widget class="QLabel" name="updateChannelLabel"> <widget class="QLabel" name="updateChannelLabel">
<property name="text"> <property name="text">
<string>Update Channel:</string> <string>Up&amp;date Channel:</string>
</property>
<property name="buddy">
<cstring>updateChannelComboBox</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -98,7 +101,10 @@
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Launcher:</string> <string>&amp;Launcher:</string>
</property>
<property name="buddy">
<cstring>ftbLauncherBox</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -117,6 +123,9 @@
<property name="text"> <property name="text">
<string>Files:</string> <string>Files:</string>
</property> </property>
<property name="buddy">
<cstring>ftbBox</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="3" column="2"> <item row="3" column="2">
@ -161,7 +170,10 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="labelInstDir"> <widget class="QLabel" name="labelInstDir">
<property name="text"> <property name="text">
<string>Instances:</string> <string>I&amp;nstances:</string>
</property>
<property name="buddy">
<cstring>instDirTextBox</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -178,7 +190,10 @@
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="labelModsDir"> <widget class="QLabel" name="labelModsDir">
<property name="text"> <property name="text">
<string>Mods:</string> <string>&amp;Mods:</string>
</property>
<property name="buddy">
<cstring>modsDirTextBox</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -198,7 +213,10 @@
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="labelLWJGLDir"> <widget class="QLabel" name="labelLWJGLDir">
<property name="text"> <property name="text">
<string>LWJGL:</string> <string>LW&amp;JGL:</string>
</property>
<property name="buddy">
<cstring>lwjglDirTextBox</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -215,7 +233,10 @@
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="labelIconsDir"> <widget class="QLabel" name="labelIconsDir">
<property name="text"> <property name="text">
<string>Icons:</string> <string>&amp;Icons:</string>
</property>
<property name="buddy">
<cstring>iconsDirTextBox</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -236,8 +257,8 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>0</width>
<height>40</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
@ -369,13 +390,81 @@
</layout> </layout>
</widget> </widget>
</item> </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> <item>
<widget class="QGroupBox" name="themeBox_2"> <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"> <property name="title">
<string>Console font</string> <string>Console font</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item> <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"> <widget class="QFontComboBox" name="consoleFont">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -385,22 +474,22 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
</widget> </widget>
@ -429,6 +518,11 @@
<tabstop>sortByNameBtn</tabstop> <tabstop>sortByNameBtn</tabstop>
<tabstop>languageBox</tabstop> <tabstop>languageBox</tabstop>
<tabstop>themeComboBox</tabstop> <tabstop>themeComboBox</tabstop>
<tabstop>showConsoleCheck</tabstop>
<tabstop>autoCloseConsoleCheck</tabstop>
<tabstop>consoleFont</tabstop>
<tabstop>fontSizeBox</tabstop>
<tabstop>fontPreview</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections/>