2021-03-25 05:01:12 +13:00
|
|
|
from PyQt5.QtCore import QSize
|
2021-04-09 07:00:18 +12:00
|
|
|
from PyQt5.QtWidgets import QTabBar, QToolButton
|
2022-01-06 03:44:29 +13:00
|
|
|
|
|
|
|
from rare.utils.utils import icon
|
2021-03-25 05:01:12 +13:00
|
|
|
|
|
|
|
|
2021-11-19 09:44:11 +13:00
|
|
|
class MainTabBar(QTabBar):
|
2021-03-25 05:01:12 +13:00
|
|
|
def __init__(self, expanded):
|
2021-11-19 09:44:11 +13:00
|
|
|
super(MainTabBar, self).__init__()
|
2021-03-25 05:01:12 +13:00
|
|
|
self._expanded = expanded
|
2021-11-19 09:44:11 +13:00
|
|
|
self.setObjectName("MainTabBar")
|
2021-12-05 04:15:35 +13:00
|
|
|
font = self.font()
|
2021-12-24 22:09:50 +13:00
|
|
|
font.setPointSize(font.pointSize() + 2)
|
2021-12-05 04:15:35 +13:00
|
|
|
font.setBold(True)
|
|
|
|
self.setFont(font)
|
2021-03-25 05:01:12 +13:00
|
|
|
# self.setContentsMargins(0,10,0,10)
|
|
|
|
|
|
|
|
def tabSizeHint(self, index):
|
2021-11-19 09:44:11 +13:00
|
|
|
size = super(MainTabBar, self).tabSizeHint(index)
|
2021-03-25 05:01:12 +13:00
|
|
|
if index == self._expanded:
|
|
|
|
offset = self.width()
|
|
|
|
for index in range(self.count()):
|
2021-11-19 09:44:11 +13:00
|
|
|
offset -= super(MainTabBar, self).tabSizeHint(index).width()
|
2021-03-25 05:01:12 +13:00
|
|
|
size.setWidth(max(size.width(), size.width() + offset))
|
|
|
|
return size
|
|
|
|
|
|
|
|
|
|
|
|
class TabButtonWidget(QToolButton):
|
2022-01-06 03:44:29 +13:00
|
|
|
def __init__(self, button_icon: str, tool_tip: str, fallback_icon=None):
|
2021-03-25 05:01:12 +13:00
|
|
|
super(TabButtonWidget, self).__init__()
|
|
|
|
self.setText("Icon")
|
|
|
|
self.setPopupMode(QToolButton.InstantPopup)
|
2022-01-06 03:44:29 +13:00
|
|
|
self.setIcon(icon(button_icon, fallback_icon, scale_factor=1.25))
|
2021-04-09 07:00:18 +12:00
|
|
|
self.setToolTip(tool_tip)
|
2021-03-25 05:01:12 +13:00
|
|
|
self.setIconSize(QSize(25, 25))
|