22/05/2021

This commit is contained in:
VFX - Visual Effects
2021-05-22 11:55:06 -03:00
parent fdb9ff7277
commit fecd7eda27
7 changed files with 144 additions and 27 deletions

View File

@@ -99,6 +99,23 @@ class SetupMainWindow:
}
]
# ADD TITLE BAR MENUS
# ///////////////////////////////////////////////////////////////
add_title_bar_menus = [
{
"btn_icon" : "icon_search.svg",
"btn_id" : "btn_search",
"btn_tooltip" : "Search",
"is_active" : False
},
{
"btn_icon" : "icon_more_options.svg",
"btn_id" : "btn_top_settings",
"btn_tooltip" : "Top settings",
"is_active" : False
}
]
# SETUP MAIN WINDOW WITH CUSTOM PARAMETERS
# ///////////////////////////////////////////////////////////////
def setup(self):

View File

@@ -179,6 +179,7 @@ class UI_MainWindow(object):
radius = 8,
font_family = self.settings["font"]["family"],
title_size = self.settings["font"]["title_size"],
is_custom_title_bar = self.settings["custom_title_bar"]
)
self.title_bar_layout.addWidget(self.title_bar)

View File

@@ -30,6 +30,7 @@ from gui.core.functions import *
# PY LEFT MENU
# ///////////////////////////////////////////////////////////////
class PyLeftMenu(QWidget):
# SIGNALS
clicked = Signal(object)
released = Signal(object)
@@ -37,7 +38,6 @@ class PyLeftMenu(QWidget):
self,
parent = None,
app_parent = None,
buttons = None,
dark_one = "#1b1e23",
dark_three = "#21252d",
dark_four = "#272c36",
@@ -56,7 +56,7 @@ class PyLeftMenu(QWidget):
icon_path = "icon_menu.svg",
icon_path_close = "icon_menu_close.svg",
toggle_text = "Hide Menu",
toggle_tooltip = "Expand/Retract menu"
toggle_tooltip = "Show menu"
):
super(PyLeftMenu, self).__init__()
@@ -123,10 +123,6 @@ class PyLeftMenu(QWidget):
self.div_bottom.hide()
self.bottom_layout.addWidget(self.div_bottom)
# ADD BUTTONS
# ///////////////////////////////////////////////////////////////
self.add_menus(buttons)
# ADD BUTTONS TO LEFT MENU
# Add btns and emit signals
# ///////////////////////////////////////////////////////////////

View File

@@ -44,6 +44,10 @@ _old_size = QSize()
# close buttons and extra buttons
# ///////////////////////////////////////////////////////////////
class PyTitleBar(QWidget):
# SIGNALS
clicked = Signal(object)
released = Signal(object)
def __init__(
self,
parent,
@@ -65,7 +69,8 @@ class PyTitleBar(QWidget):
text_foreground = "#8a95aa",
radius = 8,
font_family = "Segoe UI",
title_size = 10
title_size = 10,
is_custom_title_bar = True,
):
super(PyTitleBar, self).__init__()
@@ -89,6 +94,7 @@ class PyTitleBar(QWidget):
self._font_family = font_family
self._title_size = title_size
self._text_foreground = text_foreground
self._is_custom_title_bar = is_custom_title_bar
# SETUP UI
self.setup_ui()
@@ -101,9 +107,6 @@ class PyTitleBar(QWidget):
self.top_logo.setMaximumWidth(logo_width)
self.top_logo.setPixmap(Functions.set_svg_image(logo_image))
# ADD TITLE TEXT
self.title_label.setText(self.settings["app_name"])
# MOVE WINDOW / MAXIMIZE / RESTORE
# ///////////////////////////////////////////////////////////////
def moveWindow(event):
@@ -121,16 +124,19 @@ class PyTitleBar(QWidget):
event.accept()
# MOVE APP WIDGETS
self.top_logo.mouseMoveEvent = moveWindow
self.div_1.mouseMoveEvent = moveWindow
self.title_label.mouseMoveEvent = moveWindow
self.div_2.mouseMoveEvent = moveWindow
if is_custom_title_bar:
self.top_logo.mouseMoveEvent = moveWindow
self.div_1.mouseMoveEvent = moveWindow
self.title_label.mouseMoveEvent = moveWindow
self.div_2.mouseMoveEvent = moveWindow
self.div_3.mouseMoveEvent = moveWindow
# MAXIMIZE / RESTORE
self.top_logo.mouseDoubleClickEvent = self.maximize_restore
self.div_1.mouseDoubleClickEvent = self.maximize_restore
self.title_label.mouseDoubleClickEvent = self.maximize_restore
self.div_2.mouseDoubleClickEvent = self.maximize_restore
if is_custom_title_bar:
self.top_logo.mouseDoubleClickEvent = self.maximize_restore
self.div_1.mouseDoubleClickEvent = self.maximize_restore
self.title_label.mouseDoubleClickEvent = self.maximize_restore
self.div_2.mouseDoubleClickEvent = self.maximize_restore
# ADD WIDGETS TO TITLE BAR
# ///////////////////////////////////////////////////////////////
@@ -145,10 +151,67 @@ class PyTitleBar(QWidget):
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())
# Extra BTNs layout
self.bg_layout.addLayout(self.custom_buttons_layout)
# ADD Buttons
self.bg_layout.addWidget(self.minimize_button)
self.bg_layout.addWidget(self.maximize_restore_button)
self.bg_layout.addWidget(self.close_button)
if is_custom_title_bar:
self.bg_layout.addWidget(self.minimize_button)
self.bg_layout.addWidget(self.maximize_restore_button)
self.bg_layout.addWidget(self.close_button)
# ADD BUTTONS TO TITLE BAR
# Add btns and emit signals
# ///////////////////////////////////////////////////////////////
def add_menus(self, parameters):
if parameters != None and len(parameters) > 0:
for parameter in parameters:
_btn_icon = Functions.set_svg_icon(parameter['btn_icon'])
_btn_id = parameter['btn_id']
_btn_tooltip = parameter['btn_tooltip']
_is_active = parameter['is_active']
self.menu = PyTitleButton(
self._parent,
self._app_parent,
btn_id = _btn_id,
tooltip_text = _btn_tooltip,
dark_one = self._dark_one,
bg_color = self._bg_color,
bg_color_hover = self._btn_bg_color_hover,
bg_color_pressed = self._btn_bg_color_pressed,
icon_color = self._icon_color,
icon_color_hover = self._icon_color_active,
icon_color_pressed = self._icon_color_pressed,
icon_color_active = self._icon_color_active,
context_color = self._context_color,
text_foreground = self._text_foreground,
icon_path = _btn_icon,
is_active = _is_active
)
self.menu.clicked.connect(self.btn_clicked)
self.menu.released.connect(self.btn_released)
# ADD TO LAYOUT
self.custom_buttons_layout.addWidget(self.menu)
# ADD DIV
if self._is_custom_title_bar:
self.custom_buttons_layout.addWidget(self.div_3)
# TITLE BAR MENU EMIT SIGNALS
# ///////////////////////////////////////////////////////////////
def btn_clicked(self):
self.clicked.emit(self.menu)
def btn_released(self):
self.released.emit(self.menu)
# SET TITLE BAR TEXT
# ///////////////////////////////////////////////////////////////
def set_title(self, title):
self.title_label.setText(title)
# MAXIMIZE / RESTORE
# maximize and restore parent window
@@ -201,6 +264,7 @@ class PyTitleBar(QWidget):
# DIVS
self.div_1 = PyDiv(self._div_color)
self.div_2 = PyDiv(self._div_color)
self.div_3 = PyDiv(self._div_color)
# LEFT FRAME WITH MOVE APP
self.top_logo = QLabel()
@@ -210,6 +274,11 @@ class PyTitleBar(QWidget):
self.title_label.setAlignment(Qt.AlignVCenter)
self.title_label.setStyleSheet(f'font: {self._title_size}pt "{self._font_family}"')
# CUSTOM BUTTONS LAYOUT
self.custom_buttons_layout = QHBoxLayout()
self.custom_buttons_layout.setContentsMargins(0,0,0,0)
self.custom_buttons_layout.setSpacing(3)
# MINIMIZE BUTTON
self.minimize_button = PyTitleButton(
self._parent,

View File

@@ -26,6 +26,7 @@ class PyTitleButton(QPushButton):
parent,
app_parent = None,
tooltip_text = "",
btn_id = None,
width = 30,
height = 30,
radius = 8,
@@ -47,6 +48,7 @@ class PyTitleButton(QPushButton):
# SET DEFAULT PARAMETERS
self.setFixedSize(width, height)
self.setCursor(Qt.PointingHandCursor)
self.setObjectName(btn_id)
# PROPERTIES
self._bg_color = bg_color
@@ -56,7 +58,8 @@ 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
self._context_color = context_color
self._top_margin = self.height() + 6
# Set Parameters
self._set_bg_color = bg_color
self._set_icon_path = icon_path
@@ -107,6 +110,7 @@ class PyTitleButton(QPushButton):
# CHANGE STYLES
# Functions with custom styles
# ///////////////////////////////////////////////////////////////
def change_style(self, event):
if event == QEvent.Enter:
self._set_bg_color = self._bg_color_hover
@@ -118,7 +122,7 @@ class PyTitleButton(QPushButton):
self.repaint()
elif event == QEvent.MouseButtonPress:
self._set_bg_color = self._bg_color_pressed
self._set_icon_color = self._icon_color_pressed
self._set_icon_color = self._context_color
self.repaint()
elif event == QEvent.MouseButtonRelease:
self._set_bg_color = self._bg_color_hover
@@ -127,6 +131,7 @@ class PyTitleButton(QPushButton):
# MOUSE OVER
# Event triggered when the mouse is over the BTN
# ///////////////////////////////////////////////////////////////
def enterEvent(self, event):
self.change_style(QEvent.Enter)
self.move_tooltip()
@@ -134,6 +139,7 @@ class PyTitleButton(QPushButton):
# MOUSE LEAVE
# Event fired when the mouse leaves the BTN
# ///////////////////////////////////////////////////////////////
def leaveEvent(self, event):
self.change_style(QEvent.Leave)
self.move_tooltip()
@@ -141,6 +147,7 @@ class PyTitleButton(QPushButton):
# MOUSE PRESS
# Event triggered when the left button is pressed
# ///////////////////////////////////////////////////////////////
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.change_style(QEvent.MouseButtonPress)
@@ -151,6 +158,7 @@ class PyTitleButton(QPushButton):
# MOUSE RELEASED
# Event triggered after the mouse button is released
# ///////////////////////////////////////////////////////////////
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.change_style(QEvent.MouseButtonRelease)
@@ -196,6 +204,8 @@ class PyTitleButton(QPushButton):
# Move tooltip position
self._tooltip.move(pos_x, pos_y)
# TOOLTIP
# ///////////////////////////////////////////////////////////////
class _ToolTip(QLabel):
# TOOLTIP / LABEL StyleSheet
style_tooltip = """
@@ -210,7 +220,6 @@ class _ToolTip(QLabel):
font: 800 9pt "Segoe UI";
}}
"""
def __init__(
self,
parent,