Commit fc28dc88 authored by dmMaze's avatar dmMaze
Browse files

frameless window rework

parent a46c34e2
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -25,16 +25,17 @@ def main():
    from qtpy.QtWidgets import QApplication
    from qtpy.QtCore import QTranslator, QLocale, Qt
    from qtpy.QtGui import QIcon
    from qtpy.QtGui import  QGuiApplication, QIcon, QFont

    from ui import constants
    from ui import constants as C
    if qtpy.API_NAME[-1] == '6':
        constants.FLAG_QT6 = True
        C.FLAG_QT6 = True
    else:
        QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) #enable highdpi scaling
        QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) #use highdpi icons
        QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)

    os.chdir(constants.PROGRAM_PATH)
    os.chdir(C.PROGRAM_PATH)
    app = QApplication(sys.argv)
    translator = QTranslator()
    translator.load(
@@ -44,9 +45,14 @@ def main():
    app.installTranslator(translator)
    # app.setAttribute(Qt.AA_UseHighDpiPixmaps, True) #use highdpi icons

    C.LDPI = QGuiApplication.primaryScreen().logicalDotsPerInch()
    yahei = QFont('Microsoft YaHei UI')
    if yahei.exactMatch():
        QGuiApplication.setFont(yahei)

    from ui.mainwindow import MainWindow
    ballontrans = MainWindow(app, open_dir=args.proj_dir)
    ballontrans.setWindowIcon(QIcon(constants.ICON_PATH))
    ballontrans.setWindowIcon(QIcon(C.ICON_PATH))
    ballontrans.show()
    sys.exit(app.exec())

+0 −6
Original line number Diff line number Diff line
@@ -42,10 +42,4 @@ TITLEBAR_HEIGHT = 30
PAGELIST_THUMBNAIL_MAXNUM = 100
PAGELIST_THUMBNAIL_SIZE = 48

DRAG_DIR_NONE = -1
DRAG_DIR_HOR = 0
DRAG_DIR_VER = 1
DRAG_DIR_FDIAG = 2
DRAG_DIR_BDIAG = 3

FLAG_QT6 = False
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
# modified from https://github.com/zhiyiYo/PyQt-Frameless-Window

from .. import constants as C

if C.FLAG_QT6:
    from .fw_qt6.utils import startSystemMove
    from .fw_qt6 import FramelessWindow
else:
    from .fw_qt5.utils import startSystemMove
    from .fw_qt5 import FramelessWindow
 No newline at end of file
+15 −0
Original line number Diff line number Diff line
import sys

if sys.platform == "win32":
    from .windows import AcrylicWindow
    from .windows import WindowsFramelessWindow as FramelessWindow
    from .windows import WindowsWindowEffect as WindowEffect
elif sys.platform == "darwin":
    from .mac import AcrylicWindow
    from .mac import MacFramelessWindow as FramelessWindow
    from .mac import MacWindowEffect as WindowEffect
else:
    from .linux import LinuxFramelessWindow as FramelessWindow
    from .linux import LinuxWindowEffect as WindowEffect

    AcrylicWindow = FramelessWindow
+76 −0
Original line number Diff line number Diff line
# coding:utf-8
from PyQt5.QtCore import QCoreApplication, QEvent, Qt
from PyQt5.QtGui import QMouseEvent
from PyQt5.QtWidgets import QWidget

# from ..titlebar import TitleBar
from ..utils.linux_utils import LinuxMoveResize
from .window_effect import LinuxWindowEffect


class LinuxFramelessWindow(QWidget):
    """ Frameless window for Linux system """

    BORDER_WIDTH = 5

    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self.windowEffect = LinuxWindowEffect(self)
        # self.titleBar = TitleBar(self)

        self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
        QCoreApplication.instance().installEventFilter(self)

        # self.titleBar.raise_()
        # self.resize(500, 500)

    # def resizeEvent(self, e):
    #     super().resizeEvent(e)
    #     self.titleBar.resize(self.width(), self.titleBar.height())

    # def setTitleBar(self, titleBar):
    #     """ set custom title bar

    #     Parameters
    #     ----------
    #     titleBar: TitleBar
    #         title bar
    #     """
    #     self.titleBar.deleteLater()
    #     self.titleBar = titleBar
    #     self.titleBar.setParent(self)
    #     self.titleBar.raise_()

    def eventFilter(self, obj, event):
        et = event.type()
        if et != QEvent.MouseButtonPress and et != QEvent.MouseMove:
            return False

        edges = Qt.Edges()
        pos = QMouseEvent(event).globalPos() - self.pos()
        if pos.x() < self.BORDER_WIDTH:
            edges |= Qt.LeftEdge
        if pos.x() >= self.width()-self.BORDER_WIDTH:
            edges |= Qt.RightEdge
        if pos.y() < self.BORDER_WIDTH:
            edges |= Qt.TopEdge
        if pos.y() >= self.height()-self.BORDER_WIDTH:
            edges |= Qt.BottomEdge

        # change cursor
        if et == QEvent.MouseMove and self.windowState() == Qt.WindowNoState:
            if edges in (Qt.LeftEdge | Qt.TopEdge, Qt.RightEdge | Qt.BottomEdge):
                self.setCursor(Qt.SizeFDiagCursor)
            elif edges in (Qt.RightEdge | Qt.TopEdge, Qt.LeftEdge | Qt.BottomEdge):
                self.setCursor(Qt.SizeBDiagCursor)
            elif edges in (Qt.TopEdge, Qt.BottomEdge):
                self.setCursor(Qt.SizeVerCursor)
            elif edges in (Qt.LeftEdge, Qt.RightEdge):
                self.setCursor(Qt.SizeHorCursor)
            else:
                self.setCursor(Qt.ArrowCursor)

        elif obj in (self, self.titleBar) and et == QEvent.MouseButtonPress and edges:
            LinuxMoveResize.starSystemResize(self, event.globalPos(), edges)

        return super().eventFilter(obj, event)
Loading