Skip to content

Commit b5d907b

Browse files
committed
♻️ refractor design rules
1 parent 7bd805b commit b5d907b

10 files changed

Lines changed: 201 additions & 135 deletions

File tree

CMakeLists.txt

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
1111
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
1212
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
1313

14-
# 包含 src 目录及其所有子目录
14+
# Include the src directory and all its subdirectories
1515
set(SRC_DIR "${CMAKE_SOURCE_DIR}/src")
1616

17-
# 查找 src 目录下的所有直接子目录
17+
# Find all direct subdirectories under the src directory
1818
file(GLOB SUBDIRS RELATIVE ${SRC_DIR} ${SRC_DIR}/*)
1919
foreach(subdir ${SUBDIRS})
2020
if(IS_DIRECTORY ${SRC_DIR}/${subdir})
@@ -26,55 +26,50 @@ include_directories("external/json/include")
2626
include_directories("external/asio/asio/include")
2727
include_directories("external/ollama/include")
2828

29-
# 设置主文件
29+
# Set the main file
3030
if(APPLE)
31-
# 设置 macOS 上的应用图标
31+
# Set the application icon on macOS
3232
set(MACOSX_BUNDLE_ICON_FILE icon.icns)
3333
set(app_icon_macos ${CMAKE_SOURCE_DIR}/resources/icon.icns)
34-
# 输出图标路径以便调试
34+
# Output icon path for debugging
3535
message(STATUS "Icon file path: ${app_icon_macos}")
3636

37-
# 确保图标文件路径正确
37+
# Ensure the icon file path is correct
3838
if(NOT EXISTS ${app_icon_macos})
3939
message(FATAL_ERROR "Icon file not found: ${app_icon_macos}")
4040
else()
4141
message(STATUS "Icon file found: ${app_icon_macos}")
4242
endif()
43-
43+
4444
set_source_files_properties(${app_icon_macos} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
45-
46-
# 设置 Info.plist 文件
45+
46+
# Set the Info.plist file
4747
set(MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/resources/Info.plist)
4848

4949
set(PROJECT_MAIN_FILE "src/main.mm")
5050
else()
5151
set(PROJECT_MAIN_FILE "src/main.cpp")
5252
endif()
5353

54-
55-
# 查找 src 目录下所有子目录中的所有源文件和头文件
54+
# Find all source and header files in all subdirectories under the src directory
5655
file(GLOB_RECURSE PROJECT_SOURCES
5756
"${SRC_DIR}/*/*.cpp"
5857
"${SRC_DIR}/*/*.h"
5958
)
6059

61-
# 将主文件添加到 PROJECT_SOURCES
60+
# Add the main file to PROJECT_SOURCES
6261
list(APPEND PROJECT_SOURCES ${PROJECT_MAIN_FILE})
6362

6463
if(APPLE)
6564
list(APPEND PROJECT_SOURCES ${app_icon_macos})
6665
endif()
6766

68-
# 创建可执行文件
67+
# Create the executable
6968
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
7069
qt_add_executable(qollama
7170
MANUAL_FINALIZATION
7271
${PROJECT_SOURCES}
7372
resources/resources.qrc
74-
src/objects/initializer.h src/objects/initializer.cpp
75-
src/container/iscrollarea.h src/container/iscrollarea.cpp
76-
src/buttons/ioverlaybutton.cpp
77-
src/display/imessagebox.h src/display/imessagebox.cpp
7873
)
7974
else()
8075
if(ANDROID)
@@ -88,14 +83,14 @@ else()
8883
endif()
8984
endif()
9085

91-
# 只在 Windows 上链接 ws2_32 库
86+
# Link ws2_32 library only on Windows
9287
if(WIN32)
9388
target_link_libraries(qollama PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network ws2_32)
9489
else()
9590
target_link_libraries(qollama PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network)
9691
endif()
9792

98-
# 设置 macOS 下的一些属性
93+
# Set some properties on macOS
9994
if(${QT_VERSION} VERSION_LESS 6.1.0)
10095
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.qollama)
10196
endif()
@@ -108,14 +103,11 @@ set_target_properties(qollama PROPERTIES
108103
WIN32_EXECUTABLE TRUE
109104
)
110105

111-
112-
113106
if(APPLE)
114107
install(FILES ${app_icon_macos} DESTINATION ${CMAKE_INSTALL_PREFIX}/Contents/Resources)
115108
install(FILES ${MACOSX_BUNDLE_INFO_PLIST} DESTINATION ${CMAKE_INSTALL_PREFIX}/Contents)
116109
endif()
117110

118-
119111
include(GNUInstallDirs)
120112
install(TARGETS qollama
121113
BUNDLE DESTINATION .

design/README.md

Lines changed: 102 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,112 @@
1+
### UI Design Guidelines
12

2-
使用84, 210, 99 (一种亮绿色)作为主题色,你可以生成一组和谐的颜色,用于UI设计。这组颜色包括主色、浅色、深色、背景色、边框色和一些对比色。
3+
#### Color Palette
4+
- **Primary Color**:
5+
- Bright Green: `#54D263` (84, 210, 99)
36

4-
以下是一个颜色盘:
7+
- **Light Shades**:
8+
- Very Light Green: `#E7F8E9` (231, 248, 233)
9+
- Light Green: `#A6E6B3` (166, 230, 179)
10+
- Pale Green: `#78D999` (120, 217, 153)
511

6-
### 主题色 (Primary Color)
7-
- 亮绿色: `#54D263` (84, 210, 99)
12+
- **Dark Shades**:
13+
- Dark Green: `#42A352` (66, 163, 82)
14+
- Deeper Green: `#2D7B3C` (45, 123, 60)
15+
- Deep Forest Green: `#1C562B` (28, 86, 43)
816

9-
### 浅色 (Light Shades)
10-
- 非常浅的绿色: `#E7F8E9` (231, 248, 233)
11-
- 浅绿色: `#A6E6B3` (166, 230, 179)
12-
- 淡绿色: `#78D999` (120, 217, 153)
17+
- **Contrast Colors**:
18+
- Bright Orange: `#FFA726` (255, 167, 38)
19+
- Bright Yellow: `#FFEB3B` (255, 235, 59)
20+
- Bright Blue: `#29B6F6` (41, 182, 246)
1321

14-
### 深色 (Dark Shades)
15-
- 深绿色: `#42A352` (66, 163, 82)
16-
- 更深的绿色: `#2D7B3C` (45, 123, 60)
17-
- 深森林绿: `#1C562B` (28, 86, 43)
22+
- **Neutral Colors**:
23+
- White: `#FFFFFF` (255, 255, 255)
24+
- Light Gray: `#F0F0F0` (240, 240, 240)
25+
- Gray: `#BDBDBD` (189, 189, 189)
26+
- Dark Gray: `#757575` (117, 117, 117)
27+
- Black: `#212121` (33, 33, 33)
1828

19-
### 对比色 (Contrast Colors)
20-
- 亮橙色: `#FFA726` (255, 167, 38)
21-
- 亮黄色: `#FFEB3B` (255, 235, 59)
22-
- 亮蓝色: `#29B6F6` (41, 182, 246)
29+
- **Background Colors**:
30+
- Light Background: `#F5F5F5` (245, 245, 245)
31+
- Neutral Background: `#E0E0E0` (224, 224, 224)
32+
- Dark Background: `#BDBDBD` (189, 189, 189)
2333

24-
### 中性色 (Neutral Colors)
25-
- 白色: `#FFFFFF` (255, 255, 255)
26-
- 淡灰色: `#F0F0F0` (240, 240, 240)
27-
- 灰色: `#BDBDBD` (189, 189, 189)
28-
- 深灰色: `#757575` (117, 117, 117)
29-
- 黑色: `#212121` (33, 33, 33)
34+
- **Border Colors**:
35+
- Light Border: `#E0E0E0` (224, 224, 224)
36+
- Neutral Border: `#9E9E9E` (158, 158, 158)
37+
- Dark Border: `#616161` (97, 97, 97)
3038

31-
### 背景色 (Background Colors)
32-
- 浅背景色: `#F5F5F5` (245, 245, 245)
33-
- 中性背景色: `#E0E0E0` (224, 224, 224)
34-
- 深背景色: `#BDBDBD` (189, 189, 189)
39+
#### Typography
40+
- **Font Family**:
41+
- Use a legible and scalable font family such as Roboto, Open Sans, or Helvetica Neue for consistency across platforms.
3542

36-
### 边框色 (Border Colors)
37-
- 浅边框色: `#E0E0E0` (224, 224, 224)
38-
- 中性边框色: `#9E9E9E` (158, 158, 158)
39-
- 深边框色: `#616161` (97, 97, 97)
43+
- **Font Sizes**:
44+
- Headings: 24px - 32px
45+
- Subheadings: 18px - 24px
46+
- Body Text: 14px - 18px
47+
- Button Text: 14px - 16px
4048

41-
这些颜色搭配可以为你的UI设计提供多样性和和谐美。你可以根据不同的需求使用这些颜色来设计按钮、背景、文本和其他UI元素。
49+
- **Font Styles**:
50+
- Use bold for headings and important text.
51+
- Use italics or different font weights for emphasis.
52+
53+
#### Layout
54+
- **Spacing**:
55+
- Maintain consistent spacing between elements (padding and margins).
56+
- Use grid systems or guidelines for alignment.
57+
58+
- **Responsive Design**:
59+
- Ensure the UI adapts to different screen sizes and orientations.
60+
- Use media queries or adaptive layouts for responsiveness.
61+
62+
- **Hierarchy**:
63+
- Use visual hierarchy to guide user attention (size, color, contrast).
64+
- Group related elements and use whitespace effectively.
65+
66+
#### Interaction
67+
- **Buttons**:
68+
- Use consistent button styles for primary actions (e.g., filled buttons for primary actions, outlined buttons for secondary actions).
69+
- Provide visual feedback on button press (e.g., change in color, animation).
70+
71+
- **Forms**:
72+
- Use clear labels and placeholders for input fields.
73+
- Validate input in real-time and provide helpful error messages.
74+
75+
- **Navigation**:
76+
- Use intuitive navigation patterns (e.g., top bar, side menu) for easy access to different sections.
77+
- Highlight the current page or section in the navigation menu.
78+
79+
#### Visuals
80+
- **Icons**:
81+
- Use simple and recognizable icons for actions and navigation.
82+
- Ensure icons are scalable and clear on different screen sizes.
83+
84+
- **Images**:
85+
- Optimize images for fast loading without compromising quality.
86+
- Use images strategically to enhance content and visual appeal.
87+
88+
- **Color Usage**:
89+
- Maintain consistency in color usage throughout the UI.
90+
- Use color sparingly for emphasis and visual hierarchy.
91+
92+
#### Accessibility
93+
- **Contrast Ratio**:
94+
- Ensure sufficient color contrast for readability (WCAG guidelines recommend a minimum contrast ratio of 4.5:1 for normal text and 3:1 for large text).
95+
96+
- **Keyboard Navigation**:
97+
- Ensure all interactive elements are accessible via keyboard navigation.
98+
- Use focus states to indicate keyboard focus.
99+
100+
#### Branding
101+
- **Logo Usage**:
102+
- Use the brand logo consistently and prominently.
103+
- Ensure the logo is scalable and recognizable on different backgrounds.
104+
105+
- **Color Palette**:
106+
- Use the defined color palette for brand consistency.
107+
- Avoid using colors that clash with the brand identity.
108+
109+
#### Guidelines
110+
- **UI Style Guide**:
111+
- Create and maintain a UI style guide for consistency in design elements, colors, typography, and interactions.
112+
- Document UI patterns and best practices for reference by designers and developers.

src/container/IChatsScrollArea.cpp

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/container/IChatsScrollArea.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/container/ichatscrollarea.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "ichatscrollarea.h"
2+
#include <QScrollBar>
3+
4+
IChatScrollArea::IChatScrollArea(QWidget *parent)
5+
: QScrollArea(parent), m_latestMessageWidget(nullptr),
6+
m_chatContainer(new QWidget(this)) {
7+
setupUI();
8+
}
9+
10+
void IChatScrollArea::setupUI() {
11+
setWidgetResizable(true);
12+
setContentsMargins(0, 0, 0, 0);
13+
14+
QVBoxLayout *chatLayout = new QVBoxLayout(m_chatContainer);
15+
chatLayout->setContentsMargins(40, 0, 40, 0);
16+
chatLayout->setSpacing(0);
17+
chatLayout->setAlignment(Qt::AlignTop);
18+
m_chatContainer->setLayout(chatLayout);
19+
m_chatContainer->setObjectName("chatContainer");
20+
m_chatContainer->setStyleSheet("background-color:white;");
21+
setWidget(m_chatContainer);
22+
}
23+
24+
void IChatScrollArea::addMessage(const QString &message,
25+
const QString &userName,
26+
const QPixmap &avatar) {
27+
IMessageBox *messageWidget =
28+
new IMessageBox(userName, avatar.scaledToWidth(30), message, this);
29+
m_chatContainer->layout()->addWidget(messageWidget);
30+
m_latestMessageWidget = messageWidget;
31+
32+
QTimer::singleShot(0, this, &IChatScrollArea::scrollToBottom);
33+
}
34+
35+
bool IChatScrollArea::isNew() const { return m_latestMessageWidget == nullptr; }
36+
37+
IMessageBox *IChatScrollArea::getLatestMessageWidget() const {
38+
return m_latestMessageWidget;
39+
}
40+
41+
void IChatScrollArea::scrollToBottom() {
42+
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
43+
}

0 commit comments

Comments
 (0)