Adjust vertical tabbar width
This commit is contained in:
parent
7bcd8192a7
commit
6289ef7981
@ -428,6 +428,12 @@ DATA = OrderedDict([
|
|||||||
('show-favicons',
|
('show-favicons',
|
||||||
SettingValue(types.Bool(), 'true'),
|
SettingValue(types.Bool(), 'true'),
|
||||||
"Whether to show favicons in the tab bar."),
|
"Whether to show favicons in the tab bar."),
|
||||||
|
|
||||||
|
('width',
|
||||||
|
SettingValue(types.PercOrInt(minperc=0, maxperc=100, minint=1),
|
||||||
|
'20%'),
|
||||||
|
"The width of the tab bar if it's vertical, in px or as percentage "
|
||||||
|
"of the window."),
|
||||||
)),
|
)),
|
||||||
|
|
||||||
('storage', sect.KeyValue(
|
('storage', sect.KeyValue(
|
||||||
|
@ -165,6 +165,7 @@ class MainWindow(QWidget):
|
|||||||
super().resizeEvent(e)
|
super().resizeEvent(e)
|
||||||
self.resize_completion()
|
self.resize_completion()
|
||||||
self.downloadview.updateGeometry()
|
self.downloadview.updateGeometry()
|
||||||
|
self.tabs.tabBar().updateGeometry()
|
||||||
|
|
||||||
def closeEvent(self, e):
|
def closeEvent(self, e):
|
||||||
"""Override closeEvent to display a confirmation if needed."""
|
"""Override closeEvent to display a confirmation if needed."""
|
||||||
|
@ -29,7 +29,8 @@ import functools
|
|||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QSize, QRect
|
from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QSize, QRect
|
||||||
from PyQt5.QtWidgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle,
|
from PyQt5.QtWidgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle,
|
||||||
QStyle, QStylePainter, QStyleOptionTab)
|
QStyle, QStylePainter, QStyleOptionTab,
|
||||||
|
QApplication)
|
||||||
from PyQt5.QtGui import QIcon, QPalette, QColor
|
from PyQt5.QtGui import QIcon, QPalette, QColor
|
||||||
|
|
||||||
import qutebrowser.config.config as config
|
import qutebrowser.config.config as config
|
||||||
@ -86,12 +87,16 @@ class TabWidget(QTabWidget):
|
|||||||
'right': QTabBar.SelectRightTab,
|
'right': QTabBar.SelectRightTab,
|
||||||
'previous': QTabBar.SelectPreviousTab,
|
'previous': QTabBar.SelectPreviousTab,
|
||||||
}
|
}
|
||||||
|
tabbar = self.tabBar()
|
||||||
self.setMovable(config.get('tabbar', 'movable'))
|
self.setMovable(config.get('tabbar', 'movable'))
|
||||||
self.setTabsClosable(config.get('tabbar', 'close-buttons'))
|
self.setTabsClosable(config.get('tabbar', 'close-buttons'))
|
||||||
posstr = config.get('tabbar', 'position')
|
posstr = config.get('tabbar', 'position')
|
||||||
selstr = config.get('tabbar', 'select-on-remove')
|
selstr = config.get('tabbar', 'select-on-remove')
|
||||||
self.setTabPosition(position_conv[posstr])
|
position = position_conv[posstr]
|
||||||
self.tabBar().setSelectionBehaviorOnRemove(select_conv[selstr])
|
self.setTabPosition(position)
|
||||||
|
tabbar.vertical = position in (QTabWidget.West, QTabWidget.East)
|
||||||
|
tabbar.setSelectionBehaviorOnRemove(select_conv[selstr])
|
||||||
|
tabbar.updateGeometry()
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def on_config_changed(self, section, _option):
|
def on_config_changed(self, section, _option):
|
||||||
@ -108,6 +113,9 @@ class TabBar(QTabBar):
|
|||||||
are enabled. However, fixing this would be a lot of effort, so we'll
|
are enabled. However, fixing this would be a lot of effort, so we'll
|
||||||
postpone it until we're reimplementing drag&drop for other reasons.
|
postpone it until we're reimplementing drag&drop for other reasons.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
vertical: When the tab bar is currently vertical.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
tab_rightclicked: Emitted when a tab was right-clicked and should be
|
tab_rightclicked: Emitted when a tab was right-clicked and should be
|
||||||
closed. We use this rather than tabCloseRequested
|
closed. We use this rather than tabCloseRequested
|
||||||
@ -122,6 +130,7 @@ class TabBar(QTabBar):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setStyle(TabBarStyle(self.style()))
|
self.setStyle(TabBarStyle(self.style()))
|
||||||
|
self.vertical = False
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<{} with {} tabs>'.format(self.__class__.__name__,
|
return '<{} with {} tabs>'.format(self.__class__.__name__,
|
||||||
@ -193,14 +202,22 @@ class TabBar(QTabBar):
|
|||||||
A QSize.
|
A QSize.
|
||||||
"""
|
"""
|
||||||
minimum_size = self.minimumTabSizeHint(index)
|
minimum_size = self.minimumTabSizeHint(index)
|
||||||
if self.count() * minimum_size.width() > self.width():
|
height = self.fontMetrics().height()
|
||||||
|
if self.vertical:
|
||||||
|
confwidth = str(config.get('tabbar', 'width'))
|
||||||
|
if confwidth.endswith('%'):
|
||||||
|
perc = int(confwidth.rstrip('%'))
|
||||||
|
width = QApplication.instance().mainwindow.width() * perc / 100
|
||||||
|
else:
|
||||||
|
width = int(confwidth)
|
||||||
|
size = QSize(max(minimum_size.width(), width), height)
|
||||||
|
elif self.count() * minimum_size.width() > self.width():
|
||||||
# If we don't have enough space, we return the minimum size so we
|
# If we don't have enough space, we return the minimum size so we
|
||||||
# get scroll buttons as soon as needed.
|
# get scroll buttons as soon as needed.
|
||||||
size = minimum_size
|
size = minimum_size
|
||||||
else:
|
else:
|
||||||
# If we *do* have enough space, tabs should occupy the whole window
|
# If we *do* have enough space, tabs should occupy the whole window
|
||||||
# width.
|
# width.
|
||||||
height = self.fontMetrics().height()
|
|
||||||
size = QSize(self.width() / self.count(), height)
|
size = QSize(self.width() / self.count(), height)
|
||||||
qt_ensure_valid(size)
|
qt_ensure_valid(size)
|
||||||
return size
|
return size
|
||||||
|
Loading…
Reference in New Issue
Block a user