mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-06-04 01:28:58 -04:00
refactor: Move to using colors from QtC theme palette
This commit is contained in:
parent
9db61119aa
commit
1d64d2afc9
@ -62,8 +62,6 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
&ChatRootView::autosave);
|
&ChatRootView::autosave);
|
||||||
|
|
||||||
connect(m_chatModel, &ChatModel::modelReseted, [this]() { m_recentFilePath = QString(); });
|
connect(m_chatModel, &ChatModel::modelReseted, [this]() { m_recentFilePath = QString(); });
|
||||||
|
|
||||||
generateColors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatModel *ChatRootView::chatModel() const
|
ChatModel *ChatRootView::chatModel() const
|
||||||
@ -71,11 +69,6 @@ ChatModel *ChatRootView::chatModel() const
|
|||||||
return m_chatModel;
|
return m_chatModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor ChatRootView::backgroundColor() const
|
|
||||||
{
|
|
||||||
return Utils::creatorColor(Utils::Theme::BackgroundColorNormal);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatRootView::sendMessage(const QString &message, bool sharingCurrentFile)
|
void ChatRootView::sendMessage(const QString &message, bool sharingCurrentFile)
|
||||||
{
|
{
|
||||||
if (m_chatModel->totalTokens() > m_chatModel->tokensThreshold()) {
|
if (m_chatModel->totalTokens() > m_chatModel->tokensThreshold()) {
|
||||||
@ -116,49 +109,6 @@ void ChatRootView::clearAttachmentFiles()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatRootView::generateColors()
|
|
||||||
{
|
|
||||||
QColor baseColor = backgroundColor();
|
|
||||||
bool isDarkTheme = baseColor.lightness() < 128;
|
|
||||||
|
|
||||||
if (isDarkTheme) {
|
|
||||||
m_primaryColor = generateColor(baseColor, 0.1, 1.2, 1.4);
|
|
||||||
m_secondaryColor = generateColor(baseColor, -0.1, 1.1, 1.2);
|
|
||||||
m_codeColor = generateColor(baseColor, 0.05, 0.8, 1.1);
|
|
||||||
} else {
|
|
||||||
m_primaryColor = generateColor(baseColor, 0.05, 1.05, 1.1);
|
|
||||||
m_secondaryColor = generateColor(baseColor, -0.05, 1.1, 1.2);
|
|
||||||
m_codeColor = generateColor(baseColor, 0.02, 0.95, 1.05);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor ChatRootView::generateColor(const QColor &baseColor,
|
|
||||||
float hueShift,
|
|
||||||
float saturationMod,
|
|
||||||
float lightnessMod)
|
|
||||||
{
|
|
||||||
float h, s, l, a;
|
|
||||||
baseColor.getHslF(&h, &s, &l, &a);
|
|
||||||
bool isDarkTheme = l < 0.5;
|
|
||||||
|
|
||||||
h = fmod(h + hueShift + 1.0, 1.0);
|
|
||||||
|
|
||||||
s = qBound(0.0f, s * saturationMod, 1.0f);
|
|
||||||
|
|
||||||
if (isDarkTheme) {
|
|
||||||
l = qBound(0.0f, l * lightnessMod, 1.0f);
|
|
||||||
} else {
|
|
||||||
l = qBound(0.0f, l / lightnessMod, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
h = qBound(0.0f, h, 1.0f);
|
|
||||||
s = qBound(0.0f, s, 1.0f);
|
|
||||||
l = qBound(0.0f, l, 1.0f);
|
|
||||||
a = qBound(0.0f, a, 1.0f);
|
|
||||||
|
|
||||||
return QColor::fromHslF(h, s, l, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ChatRootView::getChatsHistoryDir() const
|
QString ChatRootView::getChatsHistoryDir() const
|
||||||
{
|
{
|
||||||
QString path;
|
QString path;
|
||||||
@ -185,21 +135,6 @@ QString ChatRootView::currentTemplate() const
|
|||||||
return settings.caModel();
|
return settings.caModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor ChatRootView::primaryColor() const
|
|
||||||
{
|
|
||||||
return m_primaryColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor ChatRootView::secondaryColor() const
|
|
||||||
{
|
|
||||||
return m_secondaryColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor ChatRootView::codeColor() const
|
|
||||||
{
|
|
||||||
return m_codeColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ChatRootView::isSharingCurrentFile() const
|
bool ChatRootView::isSharingCurrentFile() const
|
||||||
{
|
{
|
||||||
return Settings::chatAssistantSettings().sharingCurrentFile();
|
return Settings::chatAssistantSettings().sharingCurrentFile();
|
||||||
|
@ -31,10 +31,6 @@ class ChatRootView : public QQuickItem
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QodeAssist::Chat::ChatModel *chatModel READ chatModel NOTIFY chatModelChanged FINAL)
|
Q_PROPERTY(QodeAssist::Chat::ChatModel *chatModel READ chatModel NOTIFY chatModelChanged FINAL)
|
||||||
Q_PROPERTY(QString currentTemplate READ currentTemplate NOTIFY currentTemplateChanged FINAL)
|
Q_PROPERTY(QString currentTemplate READ currentTemplate NOTIFY currentTemplateChanged FINAL)
|
||||||
Q_PROPERTY(QColor backgroundColor READ backgroundColor CONSTANT FINAL)
|
|
||||||
Q_PROPERTY(QColor primaryColor READ primaryColor CONSTANT FINAL)
|
|
||||||
Q_PROPERTY(QColor secondaryColor READ secondaryColor CONSTANT FINAL)
|
|
||||||
Q_PROPERTY(QColor codeColor READ codeColor CONSTANT FINAL)
|
|
||||||
Q_PROPERTY(bool isSharingCurrentFile READ isSharingCurrentFile NOTIFY
|
Q_PROPERTY(bool isSharingCurrentFile READ isSharingCurrentFile NOTIFY
|
||||||
isSharingCurrentFileChanged FINAL)
|
isSharingCurrentFileChanged FINAL)
|
||||||
Q_PROPERTY(QStringList attachmentFiles MEMBER m_attachmentFiles NOTIFY attachmentFilesChanged)
|
Q_PROPERTY(QStringList attachmentFiles MEMBER m_attachmentFiles NOTIFY attachmentFilesChanged)
|
||||||
@ -47,12 +43,6 @@ public:
|
|||||||
ChatModel *chatModel() const;
|
ChatModel *chatModel() const;
|
||||||
QString currentTemplate() const;
|
QString currentTemplate() const;
|
||||||
|
|
||||||
QColor backgroundColor() const;
|
|
||||||
QColor primaryColor() const;
|
|
||||||
QColor secondaryColor() const;
|
|
||||||
|
|
||||||
QColor codeColor() const;
|
|
||||||
|
|
||||||
bool isSharingCurrentFile() const;
|
bool isSharingCurrentFile() const;
|
||||||
|
|
||||||
void saveHistory(const QString &filePath);
|
void saveHistory(const QString &filePath);
|
||||||
@ -79,21 +69,12 @@ signals:
|
|||||||
void attachmentFilesChanged();
|
void attachmentFilesChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void generateColors();
|
|
||||||
QColor generateColor(const QColor &baseColor,
|
|
||||||
float hueShift,
|
|
||||||
float saturationMod,
|
|
||||||
float lightnessMod);
|
|
||||||
|
|
||||||
QString getChatsHistoryDir() const;
|
QString getChatsHistoryDir() const;
|
||||||
QString getSuggestedFileName() const;
|
QString getSuggestedFileName() const;
|
||||||
|
|
||||||
ChatModel *m_chatModel;
|
ChatModel *m_chatModel;
|
||||||
ClientInterface *m_clientInterface;
|
ClientInterface *m_clientInterface;
|
||||||
QString m_currentTemplate;
|
QString m_currentTemplate;
|
||||||
QColor m_primaryColor;
|
|
||||||
QColor m_secondaryColor;
|
|
||||||
QColor m_codeColor;
|
|
||||||
QString m_recentFilePath;
|
QString m_recentFilePath;
|
||||||
QStringList m_attachmentFiles;
|
QStringList m_attachmentFiles;
|
||||||
};
|
};
|
||||||
|
@ -27,9 +27,6 @@ Rectangle {
|
|||||||
|
|
||||||
property alias msgModel: msgCreator.model
|
property alias msgModel: msgCreator.model
|
||||||
property alias messageAttachments: attachmentsModel.model
|
property alias messageAttachments: attachmentsModel.model
|
||||||
property color fontColor
|
|
||||||
property color codeBgColor
|
|
||||||
property color selectionColor
|
|
||||||
|
|
||||||
height: msgColumn.implicitHeight + 10
|
height: msgColumn.implicitHeight + 10
|
||||||
radius: 8
|
radius: 8
|
||||||
@ -100,14 +97,16 @@ Rectangle {
|
|||||||
height: attachText.implicitHeight + 8
|
height: attachText.implicitHeight + 8
|
||||||
width: attachText.implicitWidth + 16
|
width: attachText.implicitWidth + 16
|
||||||
radius: 4
|
radius: 4
|
||||||
color: root.codeBgColor
|
color: palette.button
|
||||||
|
border.width: 1
|
||||||
|
border.color: palette.mid
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: attachText
|
id: attachText
|
||||||
|
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
text: modelData
|
text: modelData
|
||||||
color: root.fontColor
|
color: palette.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,8 +119,6 @@ Rectangle {
|
|||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
leftPadding: 10
|
leftPadding: 10
|
||||||
text: itemData.text
|
text: itemData.text
|
||||||
color: root.fontColor
|
|
||||||
selectionColor: root.selectionColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -136,8 +133,5 @@ Rectangle {
|
|||||||
|
|
||||||
code: itemData.text
|
code: itemData.text
|
||||||
language: itemData.language
|
language: itemData.language
|
||||||
color: root.codeBgColor
|
|
||||||
selectionColor: root.selectionColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,7 @@ ChatRootView {
|
|||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
spacing: 0
|
||||||
|
|
||||||
TopBar {
|
TopBar {
|
||||||
id: topBar
|
id: topBar
|
||||||
@ -91,12 +92,8 @@ ChatRootView {
|
|||||||
width: ListView.view.width - scroll.width
|
width: ListView.view.width - scroll.width
|
||||||
msgModel: root.chatModel.processMessageContent(model.content)
|
msgModel: root.chatModel.processMessageContent(model.content)
|
||||||
messageAttachments: model.attachments
|
messageAttachments: model.attachments
|
||||||
color: model.roleType === ChatModel.User ? root.primaryColor : root.secondaryColor
|
color: model.roleType === ChatModel.User ? palette.alternateBase
|
||||||
fontColor: root.primaryColor.hslLightness > 0.5 ? "black" : "white"
|
: palette.base
|
||||||
codeBgColor: root.codeColor
|
|
||||||
selectionColor: root.primaryColor.hslLightness > 0.5 ? Qt.darker(root.primaryColor, 1.5)
|
|
||||||
: Qt.lighter(root.primaryColor, 1.5)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
header: Item {
|
header: Item {
|
||||||
@ -130,15 +127,26 @@ ChatRootView {
|
|||||||
id: messageInput
|
id: messageInput
|
||||||
|
|
||||||
placeholderText: qsTr("Type your message here...")
|
placeholderText: qsTr("Type your message here...")
|
||||||
placeholderTextColor: "#888"
|
placeholderTextColor: palette.mid
|
||||||
color: root.primaryColor.hslLightness > 0.5 ? "black" : "white"
|
color: palette.text
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
radius: 2
|
radius: 2
|
||||||
color: root.primaryColor
|
color: palette.base
|
||||||
border.color: root.primaryColor.hslLightness > 0.5 ? Qt.lighter(root.primaryColor, 1.5)
|
border.color: messageInput.activeFocus ? palette.highlight : palette.button
|
||||||
: Qt.darker(root.primaryColor, 1.5)
|
|
||||||
border.width: 1
|
border.width: 1
|
||||||
|
|
||||||
|
Behavior on border.color {
|
||||||
|
ColorAnimation { duration: 150 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
anchors.fill: parent
|
||||||
|
color: palette.highlight
|
||||||
|
opacity: messageInput.hovered ? 0.1 : 0
|
||||||
|
radius: parent.radius
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Keys.onPressed: function(event) {
|
Keys.onPressed: function(event) {
|
||||||
if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && !(event.modifiers & Qt.ShiftModifier)) {
|
if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && !(event.modifiers & Qt.ShiftModifier)) {
|
||||||
root.sendChatMessage()
|
root.sendChatMessage()
|
||||||
|
@ -26,7 +26,6 @@ Rectangle {
|
|||||||
|
|
||||||
property string code: ""
|
property string code: ""
|
||||||
property string language: ""
|
property string language: ""
|
||||||
property color selectionColor
|
|
||||||
|
|
||||||
readonly property string monospaceFont: {
|
readonly property string monospaceFont: {
|
||||||
switch (Qt.platform.os) {
|
switch (Qt.platform.os) {
|
||||||
@ -41,6 +40,7 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
border.width: 2
|
border.width: 2
|
||||||
@ -62,10 +62,10 @@ Rectangle {
|
|||||||
readOnly: true
|
readOnly: true
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
font.family: root.monospaceFont
|
font.family: root.monospaceFont
|
||||||
font.pointSize: 12
|
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: root.selectionColor
|
selectionColor: palette.highlight
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEdit {
|
TextEdit {
|
||||||
@ -80,7 +80,7 @@ Rectangle {
|
|||||||
font.pointSize: 8
|
font.pointSize: 8
|
||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
QoAButton {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.margins: 5
|
anchors.margins: 5
|
||||||
|
@ -26,4 +26,6 @@ TextEdit {
|
|||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
textFormat: Text.StyledText
|
textFormat: Text.StyledText
|
||||||
|
selectionColor: palette.highlight
|
||||||
|
color: palette.text
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ Flow {
|
|||||||
spacing: 5
|
spacing: 5
|
||||||
leftPadding: 5
|
leftPadding: 5
|
||||||
rightPadding: 5
|
rightPadding: 5
|
||||||
|
topPadding: attachRepeater.model.length > 0 ? 2 : 0
|
||||||
|
bottomPadding: attachRepeater.model.length > 0 ? 2 : 0
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
id: attachRepeater
|
id: attachRepeater
|
||||||
@ -42,6 +44,8 @@ Flow {
|
|||||||
width: fileNameText.width + closeButton.width + 20
|
width: fileNameText.width + closeButton.width + 20
|
||||||
radius: 4
|
radius: 4
|
||||||
color: palette.button
|
color: palette.button
|
||||||
|
border.width: 1
|
||||||
|
border.color: palette.mid
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
spacing: 5
|
spacing: 5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user