21/05/2021

This commit is contained in:
VFX - Visual Effects
2021-05-21 11:14:56 -03:00
parent 4a1a4d59d8
commit fdb9ff7277
5 changed files with 148 additions and 14 deletions

View File

@@ -55,7 +55,7 @@ class SetupMainWindow:
"btn_text" : "Open Widgets",
"btn_tooltip" : "Show custom widgets",
"show_top" : True,
"is_active" : False
"is_active" : True
},
{
"btn_icon" : "icon_add_user.svg",

View File

@@ -162,10 +162,23 @@ class UI_MainWindow(object):
# ADD CUSTOM TITLE BAR TO LAYOUT
self.title_bar = PyTitleBar(
parent,
app_parent = self.central_widget,
logo_image = "logo_top_100x22.svg",
bg_color = self.themes["app_color"]["bg_two"],
div_color = self.themes["app_color"]["bg_three"],
btn_bg_color = self.themes["app_color"]["bg_two"],
btn_bg_color_hover = self.themes["app_color"]["bg_three"],
btn_bg_color_pressed = self.themes["app_color"]["bg_one"],
icon_color = self.themes["app_color"]["icon_color"],
icon_color_hover = self.themes["app_color"]["icon_hover"],
icon_color_pressed = self.themes["app_color"]["icon_pressed"],
icon_color_active = self.themes["app_color"]["icon_active"],
context_color = self.themes["app_color"]["context_color"],
dark_one = self.themes["app_color"]["dark_one"],
text_foreground = self.themes["app_color"]["text_foreground"],
radius = 8,
font_family = self.settings["font"]["family"],
title_size = self.settings["font"]["title_size"]
title_size = self.settings["font"]["title_size"],
)
self.title_bar_layout.addWidget(self.title_bar)

View File

@@ -30,8 +30,8 @@ from gui.core.functions import *
# PY LEFT MENU
# ///////////////////////////////////////////////////////////////
class PyLeftMenu(QWidget):
clicked = Signal(str)
released = Signal(str)
clicked = Signal(object)
released = Signal(object)
def __init__(
self,

View File

@@ -47,9 +47,11 @@ class PyTitleBar(QWidget):
def __init__(
self,
parent,
app_parent,
logo_image = "logo_top_100x22.svg",
logo_width = 100,
buttons = None,
dark_one = "#1b1e23",
bg_color = "#343b48",
div_color = "#3c4454",
btn_bg_color = "#343b48",
@@ -60,6 +62,7 @@ class PyTitleBar(QWidget):
icon_color_pressed = "#edf0f5",
icon_color_active = "#f5f6f9",
context_color = "#6c99f4",
text_foreground = "#8a95aa",
radius = 8,
font_family = "Segoe UI",
title_size = 10
@@ -70,19 +73,22 @@ class PyTitleBar(QWidget):
self.settings = settings.items
# PARAMETERS
self._dark_one = dark_one
self._bg_color = bg_color
self._div_color = div_color
self._font_family = font_family
self._title_size = title_size
self._parent = parent
self._app_parent = app_parent
self._btn_bg_color = btn_bg_color
self._btn_bg_color_hover = btn_bg_color_hover
self._btn_bg_color_pressed = btn_bg_color_pressed
self._context_color = context_color
self._context_color = context_color
self._icon_color = icon_color
self._icon_color_hover = icon_color_hover
self._icon_color_pressed = icon_color_pressed
self._icon_color_active = icon_color_active
self._font_family = font_family
self._title_size = title_size
self._text_foreground = text_foreground
# SETUP UI
self.setup_ui()
@@ -136,9 +142,9 @@ class PyTitleBar(QWidget):
# ADD BUTTONS BUTTONS
# ///////////////////////////////////////////////////////////////
# Functions
self.minimize_button.clicked.connect(lambda: parent.showMinimized())
self.maximize_restore_button.clicked.connect(lambda: self.maximize_restore())
self.close_button.clicked.connect(lambda: parent.close())
self.minimize_button.released.connect(lambda: parent.showMinimized())
self.maximize_restore_button.released.connect(lambda: self.maximize_restore())
self.close_button.released.connect(lambda: parent.close())
# ADD Buttons
self.bg_layout.addWidget(self.minimize_button)
self.bg_layout.addWidget(self.maximize_restore_button)
@@ -156,9 +162,15 @@ class PyTitleBar(QWidget):
if _is_maximized:
self._parent.ui.central_widget_layout.setContentsMargins(0,0,0,0)
self._parent.ui.window.set_stylesheet(border_radius = 0, border_size = 0)
self.maximize_restore_button.set_icon(
Functions.set_svg_icon("icon_restore.svg")
)
else:
self._parent.ui.central_widget_layout.setContentsMargins(10,10,10,10)
self._parent.ui.window.set_stylesheet(border_radius = 10, border_size = 2)
self.maximize_restore_button.set_icon(
Functions.set_svg_icon("icon_maximize.svg")
)
# CHECK EVENT
if self._parent.isMaximized():
@@ -200,7 +212,10 @@ class PyTitleBar(QWidget):
# MINIMIZE BUTTON
self.minimize_button = PyTitleButton(
self._parent,
self._app_parent,
tooltip_text = "Close app",
dark_one = self._dark_one,
bg_color = self._btn_bg_color,
bg_color_hover = self._btn_bg_color_hover,
bg_color_pressed = self._btn_bg_color_pressed,
@@ -208,12 +223,18 @@ class PyTitleBar(QWidget):
icon_color_hover = self._icon_color_hover,
icon_color_pressed = self._icon_color_pressed,
icon_color_active = self._icon_color_active,
context_color = self._context_color,
text_foreground = self._text_foreground,
radius = 6,
icon_path = Functions.set_svg_icon("icon_minimize.svg")
)
# MAXIMIZE / RESTORE BUTTON
self.maximize_restore_button = PyTitleButton(
self._parent,
self._app_parent,
tooltip_text = "Maximize app",
dark_one = self._dark_one,
bg_color = self._btn_bg_color,
bg_color_hover = self._btn_bg_color_hover,
bg_color_pressed = self._btn_bg_color_pressed,
@@ -221,12 +242,18 @@ class PyTitleBar(QWidget):
icon_color_hover = self._icon_color_hover,
icon_color_pressed = self._icon_color_pressed,
icon_color_active = self._icon_color_active,
context_color = self._context_color,
text_foreground = self._text_foreground,
radius = 6,
icon_path = Functions.set_svg_icon("icon_maximize.svg")
)
# CLOSE BUTTON
self.close_button = PyTitleButton(
self._parent,
self._app_parent,
tooltip_text = "Close app",
dark_one = self._dark_one,
bg_color = self._btn_bg_color,
bg_color_hover = self._btn_bg_color_hover,
bg_color_pressed = self._context_color,
@@ -234,6 +261,9 @@ class PyTitleBar(QWidget):
icon_color_hover = self._icon_color_hover,
icon_color_pressed = self._icon_color_pressed,
icon_color_active = self._icon_color_active,
context_color = self._context_color,
text_foreground = self._text_foreground,
radius = 6,
icon_path = Functions.set_svg_icon("icon_close.svg")
)

View File

@@ -23,6 +23,8 @@ from qt_core import *
class PyTitleButton(QPushButton):
def __init__(
self,
parent,
app_parent = None,
tooltip_text = "",
width = 30,
height = 30,
@@ -35,6 +37,9 @@ class PyTitleButton(QPushButton):
icon_color_pressed = "#edf0f5",
icon_color_active = "#f5f6f9",
icon_path = "no_icon.svg",
dark_one = "#1b1e23",
context_color = "#568af2",
text_foreground = "#8a95aa",
is_active = False
):
super(PyTitleButton, self).__init__()
@@ -51,11 +56,26 @@ class PyTitleButton(QPushButton):
self._icon_color_hover = icon_color_hover
self._icon_color_pressed = icon_color_pressed
self._icon_color_active = icon_color_active
self._top_margin = self.height() + 3
# Set Parameters
self._set_bg_color = bg_color
self._set_icon_path = icon_path
self._set_icon_color = icon_color
self._set_border_radius = radius
# Parent
self._parent = parent
self._app_parent = app_parent
# TOOLTIP
self._tooltip_text = tooltip_text
self._tooltip = _ToolTip(
app_parent,
tooltip_text,
dark_one,
context_color,
text_foreground
)
self._tooltip.hide()
# PAINT EVENT
# painting the button and the icon
@@ -109,15 +129,15 @@ class PyTitleButton(QPushButton):
# Event triggered when the mouse is over the BTN
def enterEvent(self, event):
self.change_style(QEvent.Enter)
#self.move_tooltip()
#self.tooltip.show()
self.move_tooltip()
self._tooltip.show()
# MOUSE LEAVE
# Event fired when the mouse leaves the BTN
def leaveEvent(self, event):
self.change_style(QEvent.Leave)
#self.move_tooltip()
#self.tooltip.hide()
self.move_tooltip()
self._tooltip.hide()
# MOUSE PRESS
# Event triggered when the left button is pressed
@@ -150,3 +170,74 @@ class PyTitleButton(QPushButton):
icon
)
painter.end()
# SET ICON
# ///////////////////////////////////////////////////////////////
def set_icon(self, icon_path):
self._set_icon_path = icon_path
self.repaint()
# MOVE TOOLTIP
# ///////////////////////////////////////////////////////////////
def move_tooltip(self):
# GET MAIN WINDOW PARENT
gp = self.mapToGlobal(QPoint(0, 0))
# SET WIDGET TO GET POSTION
# Return absolute position of widget inside app
pos = self._parent.mapFromGlobal(gp)
# FORMAT POSITION
# Adjust tooltip position with offset
pos_x = (pos.x() - self._tooltip.width()) + self.width() + 5
pos_y = pos.y() + self._top_margin
# SET POSITION TO WIDGET
# Move tooltip position
self._tooltip.move(pos_x, pos_y)
class _ToolTip(QLabel):
# TOOLTIP / LABEL StyleSheet
style_tooltip = """
QLabel {{
background-color: {_dark_one};
color: {_text_foreground};
padding-left: 10px;
padding-right: 10px;
border-radius: 17px;
border: 0px solid transparent;
border-right: 3px solid {_context_color};
font: 800 9pt "Segoe UI";
}}
"""
def __init__(
self,
parent,
tooltip,
dark_one,
context_color,
text_foreground
):
QLabel.__init__(self)
# LABEL SETUP
style = self.style_tooltip.format(
_dark_one = dark_one,
_context_color = context_color,
_text_foreground = text_foreground
)
self.setObjectName(u"label_tooltip")
self.setStyleSheet(style)
self.setMinimumHeight(34)
self.setParent(parent)
self.setText(tooltip)
self.adjustSize()
# SET DROP SHADOW
self.shadow = QGraphicsDropShadowEffect(self)
self.shadow.setBlurRadius(30)
self.shadow.setXOffset(0)
self.shadow.setYOffset(0)
self.shadow.setColor(QColor(0, 0, 0, 80))
self.setGraphicsEffect(self.shadow)