mirror of
https://github.com/LC044/WeChatMsg
synced 2025-04-08 05:28:03 +08:00
优化pyqt群聊显示
This commit is contained in:
parent
cc281fb352
commit
4a8556a3e0
@ -3,7 +3,6 @@ import os
|
||||
|
||||
from app.DataBase import msg_db
|
||||
from app.DataBase.output import ExporterBase
|
||||
from app.DataBase.package_msg import PackageMsg
|
||||
|
||||
|
||||
class CSVExporter(ExporterBase):
|
||||
|
@ -11,7 +11,6 @@ from docx.oxml.ns import qn
|
||||
|
||||
from app.DataBase import msg_db, hard_link_db
|
||||
from app.DataBase.output import ExporterBase, escape_js_and_html
|
||||
from app.DataBase.package_msg import PackageMsg
|
||||
from app.person import Me
|
||||
from app.util.compress_content import parser_reply, share_card, music_share
|
||||
from app.util.image import get_image_abs_path
|
||||
|
@ -8,7 +8,6 @@ from PyQt5.QtCore import pyqtSignal, QThread
|
||||
|
||||
from app.DataBase import msg_db, hard_link_db, media_msg_db
|
||||
from app.DataBase.output import ExporterBase, escape_js_and_html
|
||||
from app.DataBase.package_msg import PackageMsg
|
||||
from app.log import logger
|
||||
from app.person import Me
|
||||
from app.util import path
|
||||
|
@ -2,7 +2,6 @@ import os
|
||||
|
||||
from app.DataBase import msg_db
|
||||
from app.DataBase.output import ExporterBase
|
||||
from app.DataBase.package_msg import PackageMsg
|
||||
from app.util.compress_content import parser_reply, share_card
|
||||
|
||||
|
||||
|
@ -58,25 +58,35 @@ class TextMessage(QLabel):
|
||||
|
||||
|
||||
class Triangle(QLabel):
|
||||
def __init__(self, Type, is_send=False, parent=None):
|
||||
def __init__(self, Type, is_send=False, position=(0, 0), parent=None):
|
||||
"""
|
||||
|
||||
@param Type:
|
||||
@param is_send:
|
||||
@param position:(x,y)
|
||||
@param parent:
|
||||
"""
|
||||
super().__init__(parent)
|
||||
self.Type = Type
|
||||
self.is_send = is_send
|
||||
self.setFixedSize(6, 45)
|
||||
self.position = position
|
||||
|
||||
def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
|
||||
|
||||
super(Triangle, self).paintEvent(a0)
|
||||
if self.Type == MessageType.Text:
|
||||
self.setFixedSize(6, 45)
|
||||
painter = QPainter(self)
|
||||
triangle = QPolygon()
|
||||
x, y = self.position
|
||||
if self.is_send:
|
||||
painter.setPen(QColor('#b2e281'))
|
||||
painter.setBrush(QColor('#b2e281'))
|
||||
triangle.setPoints(0, 20, 0, 34, 6, 27)
|
||||
triangle.setPoints(0, 20+y, 0, 34+y, 6, 27+y)
|
||||
else:
|
||||
painter.setPen(QColor('white'))
|
||||
painter.setBrush(QColor('white'))
|
||||
triangle.setPoints(0, 27, 6, 20, 6, 34)
|
||||
triangle.setPoints(0, 27+y, 6, 20+y, 6, 34+y)
|
||||
painter.drawPolygon(triangle)
|
||||
|
||||
|
||||
@ -145,6 +155,7 @@ class ImageMessage(QLabel):
|
||||
self.set_image(pixmap)
|
||||
if image_link:
|
||||
self.image_path = image_link
|
||||
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
|
||||
if is_send:
|
||||
self.setAlignment(Qt.AlignCenter | Qt.AlignRight)
|
||||
@ -156,7 +167,7 @@ class ImageMessage(QLabel):
|
||||
adjusted_height = min(pixmap.height(), self.max_height)
|
||||
self.setPixmap(pixmap.scaled(adjusted_width, adjusted_height, Qt.KeepAspectRatio))
|
||||
# 调整QLabel的大小以适应图片的宽高,但不超过最大宽高
|
||||
self.setFixedSize(adjusted_width, adjusted_height)
|
||||
# self.setFixedSize(adjusted_width, adjusted_height)
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
if event.buttons() == Qt.LeftButton: # 左键按下
|
||||
@ -166,7 +177,7 @@ class ImageMessage(QLabel):
|
||||
|
||||
|
||||
class BubbleMessage(QWidget):
|
||||
def __init__(self, str_content, avatar, Type,is_send=False, display_name=None, parent=None):
|
||||
def __init__(self, str_content, avatar, Type, is_send=False, display_name=None, parent=None):
|
||||
super().__init__(parent)
|
||||
self.isSend = is_send
|
||||
# self.set
|
||||
@ -180,7 +191,7 @@ class BubbleMessage(QWidget):
|
||||
layout.setContentsMargins(0, 5, 5, 5)
|
||||
# self.resize(QSize(200, 50))
|
||||
self.avatar = Avatar(avatar)
|
||||
triangle = Triangle(Type, is_send)
|
||||
triangle = Triangle(Type, is_send, (0, 0))
|
||||
if Type == MessageType.Text:
|
||||
self.message = TextMessage(str_content, is_send)
|
||||
# self.message.setMaximumWidth(int(self.width() * 0.6))
|
||||
@ -189,18 +200,24 @@ class BubbleMessage(QWidget):
|
||||
else:
|
||||
raise ValueError("未知的消息类型")
|
||||
if display_name:
|
||||
label_name = QLabel(display_name,self)
|
||||
triangle = Triangle(Type, is_send, (0, 10))
|
||||
label_name = QLabel(display_name, self)
|
||||
label_name.setFont(QFont('微软雅黑', 10))
|
||||
if is_send:
|
||||
label_name.setAlignment(Qt.AlignRight)
|
||||
vlayout = QVBoxLayout()
|
||||
vlayout.setSpacing(0)
|
||||
vlayout.addWidget(label_name)
|
||||
vlayout.addWidget(self.message)
|
||||
if is_send:
|
||||
vlayout.addWidget(label_name, 0, Qt.AlignTop | Qt.AlignRight)
|
||||
vlayout.addWidget(self.message, 0, Qt.AlignTop | Qt.AlignRight)
|
||||
else:
|
||||
vlayout.addWidget(label_name)
|
||||
vlayout.addWidget(self.message)
|
||||
self.spacerItem = QSpacerItem(45 + 6, 45, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
||||
if is_send:
|
||||
layout.addItem(self.spacerItem)
|
||||
if display_name:
|
||||
layout.addLayout(vlayout,1)
|
||||
layout.addLayout(vlayout, 1)
|
||||
else:
|
||||
layout.addWidget(self.message, 1)
|
||||
layout.addWidget(triangle, 0, Qt.AlignTop | Qt.AlignLeft)
|
||||
@ -209,7 +226,7 @@ class BubbleMessage(QWidget):
|
||||
layout.addWidget(self.avatar, 0, Qt.AlignTop | Qt.AlignRight)
|
||||
layout.addWidget(triangle, 0, Qt.AlignTop | Qt.AlignRight)
|
||||
if display_name:
|
||||
layout.addLayout(vlayout,1)
|
||||
layout.addLayout(vlayout, 1)
|
||||
else:
|
||||
layout.addWidget(self.message, 1)
|
||||
layout.addItem(self.spacerItem)
|
||||
|
@ -3,8 +3,7 @@ from typing import List
|
||||
|
||||
from PyQt5 import QtWidgets
|
||||
from PyQt5.QtCore import QTimer, QThread, pyqtSignal
|
||||
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QDialog, QVBoxLayout, QCheckBox, QHBoxLayout, \
|
||||
QProgressBar, QLabel, QMessageBox
|
||||
from PyQt5.QtWidgets import QApplication, QDialog, QCheckBox, QMessageBox
|
||||
|
||||
from app.DataBase import micro_msg_db, misc_db
|
||||
from app.DataBase.output_pc import Output
|
||||
|
Loading…
Reference in New Issue
Block a user