Make macOS tabs left-aligned, and manually add close button

This commit is contained in:
Micah Lee 2020-08-20 21:23:05 -07:00
parent 7688fd5d45
commit 1c8f22f31b
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
5 changed files with 28 additions and 7 deletions

View File

@ -61,6 +61,9 @@ class GuiCommon:
self.css = {
# OnionShareGui styles
"tab_widget": """
QTabBar::tab { width: 170px; height: 30px; }
""",
"tab_widget_new_tab_button": """
QPushButton {
font-weight: bold;

View File

@ -228,7 +228,7 @@ class Tab(QtWidgets.QWidget):
self.share_mode.server_status.url_copied.connect(self.copy_url)
self.share_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth)
self.change_title.emit(self.tab_id, strings._("gui_new_tab_share_button"))
self.change_title.emit(self.tab_id, strings._("gui_tab_name_share"))
self.update_server_status_indicator()
self.timer.start(500)
@ -265,7 +265,7 @@ class Tab(QtWidgets.QWidget):
self.copy_hidservauth
)
self.change_title.emit(self.tab_id, strings._("gui_new_tab_receive_button"))
self.change_title.emit(self.tab_id, strings._("gui_tab_name_receive"))
self.update_server_status_indicator()
self.timer.start(500)
@ -302,7 +302,7 @@ class Tab(QtWidgets.QWidget):
self.copy_hidservauth
)
self.change_title.emit(self.tab_id, strings._("gui_new_tab_website_button"))
self.change_title.emit(self.tab_id, strings._("gui_tab_name_website"))
self.update_server_status_indicator()
self.timer.start(500)
@ -335,7 +335,7 @@ class Tab(QtWidgets.QWidget):
self.chat_mode.server_status.url_copied.connect(self.copy_url)
self.chat_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth)
self.change_title.emit(self.tab_id, strings._("gui_new_tab_chat_button"))
self.change_title.emit(self.tab_id, strings._("gui_tab_name_chat"))
self.update_server_status_indicator()
self.timer.start(500)

View File

@ -48,8 +48,7 @@ class TabWidget(QtWidgets.QTabWidget):
# Define the new tab button
self.new_tab_button = QtWidgets.QPushButton("+", parent=self)
self.new_tab_button.setFlat(True)
self.new_tab_button.setAutoFillBackground(True)
self.new_tab_button.setFixedSize(30, 30)
self.new_tab_button.setFixedSize(40, 30)
self.new_tab_button.clicked.connect(self.new_tab_clicked)
self.new_tab_button.setStyleSheet(
self.common.gui.css["tab_widget_new_tab_button"]
@ -66,6 +65,8 @@ class TabWidget(QtWidgets.QTabWidget):
self.setMovable(True)
self.setTabsClosable(True)
self.setUsesScrollButtons(True)
self.setDocumentMode(True)
self.setStyleSheet(self.common.gui.css["tab_widget"])
self.tabCloseRequested.connect(self.close_tab)
@ -99,7 +100,7 @@ class TabWidget(QtWidgets.QTabWidget):
# If there are so many tabs it scrolls, move the button to the left of the scroll buttons
if tabs_width > self.width():
pos.setX(self.width() - 61)
pos.setX(self.width() - 65)
else:
# Otherwise move the button to the right of the tabs
pos.setX(self.tabBar().sizeHint().width())
@ -152,6 +153,19 @@ class TabWidget(QtWidgets.QTabWidget):
index = self.addTab(tab, strings._("gui_new_tab"))
self.setCurrentIndex(index)
# Create a close button
def close_tab():
self.tabBar().tabCloseRequested.emit(self.indexOf(tab))
close_button = QtWidgets.QPushButton()
close_button.setFlat(True)
close_button.setFixedWidth(40)
close_button.setIcon(
QtGui.QIcon(self.common.get_resource_path("images/close_tab.png"))
)
close_button.clicked.connect(close_tab)
self.tabBar().setTabButton(index, QtWidgets.QTabBar.RightSide, close_button)
tab.init(mode_settings)
# If it's persistent, set the persistent image in the tab
self.change_persistent(tab.tab_id, tab.settings.get("persistent", "enabled"))

BIN
share/images/close_tab.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 688 B

View File

@ -188,6 +188,10 @@
"gui_new_tab_receive_button": "Receive Files",
"gui_new_tab_website_button": "Host a Website",
"gui_new_tab_chat_button": "Chat Anonymously",
"gui_tab_name_share": "Share",
"gui_tab_name_receive": "Receive",
"gui_tab_name_website": "Website",
"gui_tab_name_chat": "Chat",
"gui_close_tab_warning_title": "Are you sure?",
"gui_close_tab_warning_persistent_description": "This tab is persistent. If you close it you'll lose the onion address that it's using. Are you sure you want to close it?",
"gui_close_tab_warning_share_description": "You're in the process of sending files. Are you sure you want to close this tab?",