initial fluent-widgets ui
This commit is contained in:
71
app/components/link_card.py
Normal file
71
app/components/link_card.py
Normal file
@ -0,0 +1,71 @@
|
||||
# coding:utf-8
|
||||
from PySide6.QtCore import Qt, Signal, QUrl
|
||||
from PySide6.QtGui import QPixmap, QDesktopServices
|
||||
from PySide6.QtWidgets import QFrame, QLabel, QVBoxLayout, QWidget, QHBoxLayout
|
||||
|
||||
from qfluentwidgets import IconWidget, FluentIcon, TextWrap, SingleDirectionScrollArea
|
||||
from ..common.style_sheet import StyleSheet
|
||||
|
||||
|
||||
class LinkCard(QFrame):
|
||||
|
||||
def __init__(self, icon, title, content, url, parent=None):
|
||||
super().__init__(parent=parent)
|
||||
self.url = QUrl(url)
|
||||
self.setFixedSize(198, 220)
|
||||
self.iconWidget = IconWidget(icon, self)
|
||||
self.titleLabel = QLabel(title, self)
|
||||
self.contentLabel = QLabel(TextWrap.wrap(content, 28, False)[0], self)
|
||||
self.urlWidget = IconWidget(FluentIcon.LINK, self)
|
||||
|
||||
self.__initWidget()
|
||||
|
||||
def __initWidget(self):
|
||||
self.setCursor(Qt.PointingHandCursor)
|
||||
|
||||
self.iconWidget.setFixedSize(54, 54)
|
||||
self.urlWidget.setFixedSize(16, 16)
|
||||
|
||||
self.vBoxLayout = QVBoxLayout(self)
|
||||
self.vBoxLayout.setSpacing(0)
|
||||
self.vBoxLayout.setContentsMargins(24, 24, 0, 13)
|
||||
self.vBoxLayout.addWidget(self.iconWidget)
|
||||
self.vBoxLayout.addSpacing(16)
|
||||
self.vBoxLayout.addWidget(self.titleLabel)
|
||||
self.vBoxLayout.addSpacing(8)
|
||||
self.vBoxLayout.addWidget(self.contentLabel)
|
||||
self.vBoxLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
self.urlWidget.move(170, 192)
|
||||
|
||||
self.titleLabel.setObjectName('titleLabel')
|
||||
self.contentLabel.setObjectName('contentLabel')
|
||||
|
||||
def mouseReleaseEvent(self, e):
|
||||
super().mouseReleaseEvent(e)
|
||||
QDesktopServices.openUrl(self.url)
|
||||
|
||||
|
||||
class LinkCardView(SingleDirectionScrollArea):
|
||||
""" Link card view """
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent, Qt.Horizontal)
|
||||
self.view = QWidget(self)
|
||||
self.hBoxLayout = QHBoxLayout(self.view)
|
||||
|
||||
self.hBoxLayout.setContentsMargins(36, 0, 0, 0)
|
||||
self.hBoxLayout.setSpacing(12)
|
||||
self.hBoxLayout.setAlignment(Qt.AlignLeft)
|
||||
|
||||
self.setWidget(self.view)
|
||||
self.setWidgetResizable(True)
|
||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
|
||||
self.view.setObjectName('view')
|
||||
StyleSheet.LINK_CARD.apply(self)
|
||||
|
||||
def addCard(self, icon, title, content, url):
|
||||
""" add link card """
|
||||
card = LinkCard(icon, title, content, url, self.view)
|
||||
self.hBoxLayout.addWidget(card, 0, Qt.AlignLeft)
|
||||
75
app/components/sample_card.py
Normal file
75
app/components/sample_card.py
Normal file
@ -0,0 +1,75 @@
|
||||
# coding:utf-8
|
||||
from PySide6.QtCore import Qt, Signal
|
||||
from PySide6.QtGui import QPixmap
|
||||
from PySide6.QtWidgets import QWidget, QFrame, QLabel, QVBoxLayout, QHBoxLayout
|
||||
|
||||
from qfluentwidgets import IconWidget, TextWrap, FlowLayout, CardWidget
|
||||
from ..common.signal_bus import signalBus
|
||||
from ..common.style_sheet import StyleSheet
|
||||
|
||||
|
||||
class SampleCard(CardWidget):
|
||||
""" Sample card """
|
||||
|
||||
def __init__(self, icon, title, content, routeKey, index, parent=None):
|
||||
super().__init__(parent=parent)
|
||||
self.index = index
|
||||
self.routekey = routeKey
|
||||
|
||||
self.iconWidget = IconWidget(icon, self)
|
||||
self.titleLabel = QLabel(title, self)
|
||||
self.contentLabel = QLabel(TextWrap.wrap(content, 45, False)[0], self)
|
||||
|
||||
self.hBoxLayout = QHBoxLayout(self)
|
||||
self.vBoxLayout = QVBoxLayout()
|
||||
|
||||
self.setFixedSize(360, 90)
|
||||
self.iconWidget.setFixedSize(48, 48)
|
||||
|
||||
self.hBoxLayout.setSpacing(28)
|
||||
self.hBoxLayout.setContentsMargins(20, 0, 0, 0)
|
||||
self.vBoxLayout.setSpacing(2)
|
||||
self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
|
||||
self.vBoxLayout.setAlignment(Qt.AlignVCenter)
|
||||
|
||||
self.hBoxLayout.setAlignment(Qt.AlignVCenter)
|
||||
self.hBoxLayout.addWidget(self.iconWidget)
|
||||
self.hBoxLayout.addLayout(self.vBoxLayout)
|
||||
self.vBoxLayout.addStretch(1)
|
||||
self.vBoxLayout.addWidget(self.titleLabel)
|
||||
self.vBoxLayout.addWidget(self.contentLabel)
|
||||
self.vBoxLayout.addStretch(1)
|
||||
|
||||
self.titleLabel.setObjectName('titleLabel')
|
||||
self.contentLabel.setObjectName('contentLabel')
|
||||
|
||||
def mouseReleaseEvent(self, e):
|
||||
super().mouseReleaseEvent(e)
|
||||
signalBus.switchToSampleCard.emit(self.routekey, self.index)
|
||||
|
||||
|
||||
class SampleCardView(QWidget):
|
||||
""" Sample card view """
|
||||
|
||||
def __init__(self, title: str, parent=None):
|
||||
super().__init__(parent=parent)
|
||||
self.titleLabel = QLabel(title, self)
|
||||
self.vBoxLayout = QVBoxLayout(self)
|
||||
self.flowLayout = FlowLayout()
|
||||
|
||||
self.vBoxLayout.setContentsMargins(36, 0, 36, 0)
|
||||
self.vBoxLayout.setSpacing(10)
|
||||
self.flowLayout.setContentsMargins(0, 0, 0, 0)
|
||||
self.flowLayout.setHorizontalSpacing(12)
|
||||
self.flowLayout.setVerticalSpacing(12)
|
||||
|
||||
self.vBoxLayout.addWidget(self.titleLabel)
|
||||
self.vBoxLayout.addLayout(self.flowLayout, 1)
|
||||
|
||||
self.titleLabel.setObjectName('viewTitleLabel')
|
||||
StyleSheet.SAMPLE_CARD.apply(self)
|
||||
|
||||
def addSampleCard(self, icon, title, content, routeKey, index):
|
||||
""" add sample card """
|
||||
card = SampleCard(icon, title, content, routeKey, index, self)
|
||||
self.flowLayout.addWidget(card)
|
||||
Reference in New Issue
Block a user