mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
feat: Add chat font settings
This commit is contained in:
parent
155153a763
commit
6116284324
@ -102,6 +102,26 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
connect(
|
||||||
|
&Settings::chatAssistantSettings().textFontFamily,
|
||||||
|
&Utils::BaseAspect::changed,
|
||||||
|
this,
|
||||||
|
&ChatRootView::textFamilyChanged);
|
||||||
|
connect(
|
||||||
|
&Settings::chatAssistantSettings().codeFontFamily,
|
||||||
|
&Utils::BaseAspect::changed,
|
||||||
|
this,
|
||||||
|
&ChatRootView::codeFamilyChanged);
|
||||||
|
connect(
|
||||||
|
&Settings::chatAssistantSettings().textFontSize,
|
||||||
|
&Utils::BaseAspect::changed,
|
||||||
|
this,
|
||||||
|
&ChatRootView::textFontSizeChanged);
|
||||||
|
connect(
|
||||||
|
&Settings::chatAssistantSettings().codeFontSize,
|
||||||
|
&Utils::BaseAspect::changed,
|
||||||
|
this,
|
||||||
|
&ChatRootView::codeFontSizeChanged);
|
||||||
|
|
||||||
updateInputTokensCount();
|
updateInputTokensCount();
|
||||||
}
|
}
|
||||||
@ -552,4 +572,24 @@ bool ChatRootView::shouldIgnoreFileForAttach(const Utils::FilePath &filePath)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ChatRootView::textFontFamily() const
|
||||||
|
{
|
||||||
|
return Settings::chatAssistantSettings().textFontFamily.stringValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ChatRootView::codeFontFamily() const
|
||||||
|
{
|
||||||
|
return Settings::chatAssistantSettings().codeFontFamily.stringValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ChatRootView::codeFontSize() const
|
||||||
|
{
|
||||||
|
return Settings::chatAssistantSettings().codeFontSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ChatRootView::textFontSize() const
|
||||||
|
{
|
||||||
|
return Settings::chatAssistantSettings().textFontSize();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -38,6 +38,10 @@ class ChatRootView : public QQuickItem
|
|||||||
Q_PROPERTY(QStringList linkedFiles READ linkedFiles NOTIFY linkedFilesChanged FINAL)
|
Q_PROPERTY(QStringList linkedFiles READ linkedFiles NOTIFY linkedFilesChanged FINAL)
|
||||||
Q_PROPERTY(int inputTokensCount READ inputTokensCount NOTIFY inputTokensCountChanged FINAL)
|
Q_PROPERTY(int inputTokensCount READ inputTokensCount NOTIFY inputTokensCountChanged FINAL)
|
||||||
Q_PROPERTY(QString chatFileName READ chatFileName NOTIFY chatFileNameChanged FINAL)
|
Q_PROPERTY(QString chatFileName READ chatFileName NOTIFY chatFileNameChanged FINAL)
|
||||||
|
Q_PROPERTY(QString textFontFamily READ textFontFamily NOTIFY textFamilyChanged FINAL)
|
||||||
|
Q_PROPERTY(QString codeFontFamily READ codeFontFamily NOTIFY codeFamilyChanged FINAL)
|
||||||
|
Q_PROPERTY(int codeFontSize READ codeFontSize NOTIFY codeFontSizeChanged FINAL)
|
||||||
|
Q_PROPERTY(int textFontSize READ textFontSize NOTIFY textFontSizeChanged FINAL)
|
||||||
|
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
|
|
||||||
@ -80,6 +84,12 @@ public:
|
|||||||
void setRecentFilePath(const QString &filePath);
|
void setRecentFilePath(const QString &filePath);
|
||||||
bool shouldIgnoreFileForAttach(const Utils::FilePath &filePath);
|
bool shouldIgnoreFileForAttach(const Utils::FilePath &filePath);
|
||||||
|
|
||||||
|
QString textFontFamily() const;
|
||||||
|
QString codeFontFamily() const;
|
||||||
|
|
||||||
|
int codeFontSize() const;
|
||||||
|
int textFontSize() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void sendMessage(const QString &message);
|
void sendMessage(const QString &message);
|
||||||
void copyToClipboard(const QString &text);
|
void copyToClipboard(const QString &text);
|
||||||
@ -95,6 +105,10 @@ signals:
|
|||||||
void inputTokensCountChanged();
|
void inputTokensCountChanged();
|
||||||
void isSyncOpenFilesChanged();
|
void isSyncOpenFilesChanged();
|
||||||
void chatFileNameChanged();
|
void chatFileNameChanged();
|
||||||
|
void textFamilyChanged();
|
||||||
|
void codeFamilyChanged();
|
||||||
|
void codeFontSizeChanged();
|
||||||
|
void textFontSizeChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString getChatsHistoryDir() const;
|
QString getChatsHistoryDir() const;
|
||||||
|
@ -27,6 +27,22 @@ Rectangle {
|
|||||||
|
|
||||||
property alias msgModel: msgCreator.model
|
property alias msgModel: msgCreator.model
|
||||||
property alias messageAttachments: attachmentsModel.model
|
property alias messageAttachments: attachmentsModel.model
|
||||||
|
property string textFontFamily: Qt.application.font.family
|
||||||
|
property string codeFontFamily: {
|
||||||
|
switch (Qt.platform.os) {
|
||||||
|
case "windows":
|
||||||
|
return "Consolas";
|
||||||
|
case "osx":
|
||||||
|
return "Menlo";
|
||||||
|
case "linux":
|
||||||
|
return "DejaVu Sans Mono";
|
||||||
|
default:
|
||||||
|
return "monospace";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
property int textFontSize: Qt.application.font.pointSize
|
||||||
|
property int codeFontSize: Qt.application.font.pointSize
|
||||||
|
|
||||||
property bool isUserMessage: false
|
property bool isUserMessage: false
|
||||||
property int messageIndex: -1
|
property int messageIndex: -1
|
||||||
property real listViewContentY: 0
|
property real listViewContentY: 0
|
||||||
@ -159,6 +175,8 @@ Rectangle {
|
|||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
leftPadding: 10
|
leftPadding: 10
|
||||||
text: utils.getSafeMarkdownText(itemData.text)
|
text: utils.getSafeMarkdownText(itemData.text)
|
||||||
|
font.family: root.textFontFamily
|
||||||
|
font.pointSize: root.textFontSize
|
||||||
|
|
||||||
ChatUtils {
|
ChatUtils {
|
||||||
id: utils
|
id: utils
|
||||||
@ -178,5 +196,7 @@ Rectangle {
|
|||||||
|
|
||||||
code: itemData.text
|
code: itemData.text
|
||||||
language: itemData.language
|
language: itemData.language
|
||||||
|
codeFontFamily: root.codeFontFamily
|
||||||
|
codeFontSize: root.codeFontSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,10 @@ ChatRootView {
|
|||||||
isUserMessage: model.roleType === ChatModel.User
|
isUserMessage: model.roleType === ChatModel.User
|
||||||
messageIndex: index
|
messageIndex: index
|
||||||
listViewContentY: chatListView.contentY
|
listViewContentY: chatListView.contentY
|
||||||
|
textFontFamily: root.textFontFamily
|
||||||
|
codeFontFamily: root.codeFontFamily
|
||||||
|
codeFontSize: root.codeFontSize
|
||||||
|
textFontSize: root.textFontSize
|
||||||
|
|
||||||
onResetChatToMessage: function(index) {
|
onResetChatToMessage: function(index) {
|
||||||
messageInput.text = model.content
|
messageInput.text = model.content
|
||||||
|
@ -30,6 +30,9 @@ Rectangle {
|
|||||||
property real currentContentY: 0
|
property real currentContentY: 0
|
||||||
property real blockStart: 0
|
property real blockStart: 0
|
||||||
|
|
||||||
|
property alias codeFontFamily: codeText.font.family
|
||||||
|
property alias codeFontSize: codeText.font.pointSize
|
||||||
|
|
||||||
readonly property real buttonTopMargin: 5
|
readonly property real buttonTopMargin: 5
|
||||||
readonly property real blockEnd: blockStart + root.height
|
readonly property real blockEnd: blockStart + root.height
|
||||||
readonly property real maxButtonOffset: Math.max(0, root.height - copyButton.height - buttonTopMargin)
|
readonly property real maxButtonOffset: Math.max(0, root.height - copyButton.height - buttonTopMargin)
|
||||||
@ -45,19 +48,6 @@ Rectangle {
|
|||||||
return buttonTopMargin;
|
return buttonTopMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property string monospaceFont: {
|
|
||||||
switch (Qt.platform.os) {
|
|
||||||
case "windows":
|
|
||||||
return "Consolas";
|
|
||||||
case "osx":
|
|
||||||
return "Menlo";
|
|
||||||
case "linux":
|
|
||||||
return "DejaVu Sans Mono";
|
|
||||||
default:
|
|
||||||
return "monospace";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
color: palette.alternateBase
|
color: palette.alternateBase
|
||||||
border.color: root.color.hslLightness > 0.5 ? Qt.darker(root.color, 1.3)
|
border.color: root.color.hslLightness > 0.5 ? Qt.darker(root.color, 1.3)
|
||||||
: Qt.lighter(root.color, 1.3)
|
: Qt.lighter(root.color, 1.3)
|
||||||
@ -77,8 +67,6 @@ Rectangle {
|
|||||||
text: root.code
|
text: root.code
|
||||||
readOnly: true
|
readOnly: true
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
font.family: root.monospaceFont
|
|
||||||
font.pointSize: Qt.application.font.pointSize
|
|
||||||
color: parent.color.hslLightness > 0.5 ? "black" : "white"
|
color: parent.color.hslLightness > 0.5 ? "black" : "white"
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
selectionColor: palette.highlight
|
selectionColor: palette.highlight
|
||||||
@ -93,7 +81,7 @@ Rectangle {
|
|||||||
text: root.language
|
text: root.language
|
||||||
color: root.color.hslLightness > 0.5 ? Qt.darker(root.color, 1.1)
|
color: root.color.hslLightness > 0.5 ? Qt.darker(root.color, 1.1)
|
||||||
: Qt.lighter(root.color, 1.1)
|
: Qt.lighter(root.color, 1.1)
|
||||||
font.pointSize: 8
|
font.pointSize: codeText.font.pointSize - 4
|
||||||
}
|
}
|
||||||
|
|
||||||
QoAButton {
|
QoAButton {
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QFontDatabase>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "SettingsConstants.hpp"
|
#include "SettingsConstants.hpp"
|
||||||
@ -137,6 +139,57 @@ ChatAssistantSettings::ChatAssistantSettings()
|
|||||||
contextWindow.setRange(-1, 10000);
|
contextWindow.setRange(-1, 10000);
|
||||||
contextWindow.setDefaultValue(2048);
|
contextWindow.setDefaultValue(2048);
|
||||||
|
|
||||||
|
autosave.setDefaultValue(true);
|
||||||
|
autosave.setLabelText(Tr::tr("Enable autosave when message received"));
|
||||||
|
|
||||||
|
textFontFamily.setSettingsKey(Constants::CA_TEXT_FONT_FAMILY);
|
||||||
|
textFontFamily.setLabelText(Tr::tr("Text Font:"));
|
||||||
|
textFontFamily.setDisplayStyle(Utils::SelectionAspect::DisplayStyle::ComboBox);
|
||||||
|
const QStringList families = QFontDatabase::families();
|
||||||
|
for (const QString &family : families) {
|
||||||
|
textFontFamily.addOption(family);
|
||||||
|
}
|
||||||
|
textFontFamily.setDefaultValue(QApplication::font().family());
|
||||||
|
|
||||||
|
textFontSize.setSettingsKey(Constants::CA_TEXT_FONT_SIZE);
|
||||||
|
textFontSize.setLabelText(Tr::tr("Text Font Size:"));
|
||||||
|
textFontSize.setDefaultValue(QApplication::font().pointSize());
|
||||||
|
|
||||||
|
codeFontFamily.setSettingsKey(Constants::CA_CODE_FONT_FAMILY);
|
||||||
|
codeFontFamily.setLabelText(Tr::tr("Code Font:"));
|
||||||
|
codeFontFamily.setDisplayStyle(Utils::SelectionAspect::DisplayStyle::ComboBox);
|
||||||
|
const QStringList monospaceFamilies = QFontDatabase::families(QFontDatabase::Latin);
|
||||||
|
for (const QString &family : monospaceFamilies) {
|
||||||
|
if (QFontDatabase::isFixedPitch(family)) {
|
||||||
|
codeFontFamily.addOption(family);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString defaultMonoFont;
|
||||||
|
QStringList fixedPitchFamilies;
|
||||||
|
|
||||||
|
for (const QString &family : monospaceFamilies) {
|
||||||
|
if (QFontDatabase::isFixedPitch(family)) {
|
||||||
|
fixedPitchFamilies.append(family);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fixedPitchFamilies.contains("Consolas")) {
|
||||||
|
defaultMonoFont = "Consolas";
|
||||||
|
} else if (fixedPitchFamilies.contains("Courier New")) {
|
||||||
|
defaultMonoFont = "Courier New";
|
||||||
|
} else if (fixedPitchFamilies.contains("Monospace")) {
|
||||||
|
defaultMonoFont = "Monospace";
|
||||||
|
} else if (!fixedPitchFamilies.isEmpty()) {
|
||||||
|
defaultMonoFont = fixedPitchFamilies.first();
|
||||||
|
} else {
|
||||||
|
defaultMonoFont = QApplication::font().family();
|
||||||
|
}
|
||||||
|
codeFontFamily.setDefaultValue(defaultMonoFont);
|
||||||
|
codeFontSize.setSettingsKey(Constants::CA_CODE_FONT_SIZE);
|
||||||
|
codeFontSize.setLabelText(Tr::tr("Code Font Size:"));
|
||||||
|
codeFontSize.setDefaultValue(QApplication::font().pointSize());
|
||||||
|
|
||||||
resetToDefaults.m_buttonText = TrConstants::RESET_TO_DEFAULTS;
|
resetToDefaults.m_buttonText = TrConstants::RESET_TO_DEFAULTS;
|
||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
@ -160,6 +213,10 @@ ChatAssistantSettings::ChatAssistantSettings()
|
|||||||
ollamaGrid.addRow({ollamaLivetime});
|
ollamaGrid.addRow({ollamaLivetime});
|
||||||
ollamaGrid.addRow({contextWindow});
|
ollamaGrid.addRow({contextWindow});
|
||||||
|
|
||||||
|
auto chatViewSettingsGrid = Grid{};
|
||||||
|
chatViewSettingsGrid.addRow({textFontFamily, textFontSize});
|
||||||
|
chatViewSettingsGrid.addRow({codeFontFamily, codeFontSize});
|
||||||
|
|
||||||
return Column{
|
return Column{
|
||||||
Row{Stretch{1}, resetToDefaults},
|
Row{Stretch{1}, resetToDefaults},
|
||||||
Space{8},
|
Space{8},
|
||||||
@ -181,6 +238,7 @@ ChatAssistantSettings::ChatAssistantSettings()
|
|||||||
systemPrompt,
|
systemPrompt,
|
||||||
}},
|
}},
|
||||||
Group{title(Tr::tr("Ollama Settings")), Column{Row{ollamaGrid, Stretch{1}}}},
|
Group{title(Tr::tr("Ollama Settings")), Column{Row{ollamaGrid, Stretch{1}}}},
|
||||||
|
Group{title(Tr::tr("Chat Settings")), Row{chatViewSettingsGrid, Stretch{1}}},
|
||||||
Stretch{1}};
|
Stretch{1}};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -221,6 +279,10 @@ void ChatAssistantSettings::resetSettingsToDefaults()
|
|||||||
resetAspect(ollamaLivetime);
|
resetAspect(ollamaLivetime);
|
||||||
resetAspect(contextWindow);
|
resetAspect(contextWindow);
|
||||||
resetAspect(linkOpenFiles);
|
resetAspect(linkOpenFiles);
|
||||||
|
resetAspect(textFontFamily);
|
||||||
|
resetAspect(codeFontFamily);
|
||||||
|
resetAspect(textFontSize);
|
||||||
|
resetAspect(codeFontSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,12 @@ public:
|
|||||||
Utils::StringAspect ollamaLivetime{this};
|
Utils::StringAspect ollamaLivetime{this};
|
||||||
Utils::IntegerAspect contextWindow{this};
|
Utils::IntegerAspect contextWindow{this};
|
||||||
|
|
||||||
|
// Visuals settings
|
||||||
|
Utils::SelectionAspect textFontFamily{this};
|
||||||
|
Utils::IntegerAspect textFontSize{this};
|
||||||
|
Utils::SelectionAspect codeFontFamily{this};
|
||||||
|
Utils::IntegerAspect codeFontSize{this};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupConnections();
|
void setupConnections();
|
||||||
void resetSettingsToDefaults();
|
void resetSettingsToDefaults();
|
||||||
|
@ -151,5 +151,9 @@ const char CA_USE_FREQUENCY_PENALTY[] = "QodeAssist.chatUseFrequencyPenalty";
|
|||||||
const char CA_FREQUENCY_PENALTY[] = "QodeAssist.chatFrequencyPenalty";
|
const char CA_FREQUENCY_PENALTY[] = "QodeAssist.chatFrequencyPenalty";
|
||||||
const char CA_OLLAMA_LIVETIME[] = "QodeAssist.chatOllamaLivetime";
|
const char CA_OLLAMA_LIVETIME[] = "QodeAssist.chatOllamaLivetime";
|
||||||
const char CA_OLLAMA_CONTEXT_WINDOW[] = "QodeAssist.caOllamaContextWindow";
|
const char CA_OLLAMA_CONTEXT_WINDOW[] = "QodeAssist.caOllamaContextWindow";
|
||||||
|
const char CA_TEXT_FONT_FAMILY[] = "QodeAssist.caTextFontFamily";
|
||||||
|
const char CA_TEXT_FONT_SIZE[] = "QodeAssist.caTextFontSize";
|
||||||
|
const char CA_CODE_FONT_FAMILY[] = "QodeAssist.caCodeFontFamily";
|
||||||
|
const char CA_CODE_FONT_SIZE[] = "QodeAssist.caCodeFontSize";
|
||||||
|
|
||||||
} // namespace QodeAssist::Constants
|
} // namespace QodeAssist::Constants
|
||||||
|
Loading…
Reference in New Issue
Block a user