Implement spacer and separator count change

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-06-26 16:28:08 +02:00
parent 631334219c
commit 32fae6fb82
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07

View File

@ -36,6 +36,9 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
self.config.settingsFile = os.path.join(settingsPath, "ToolbarTools", "settings.ini")
self.config.load()
self.config.spacerCountChanged.connect(self.onSpacerCountChanged)
self.config.separatorCountChanged.connect(self.onSeparatorCountChanged)
plugins = Falkon.MainApplication.instance().plugins()
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
@ -58,23 +61,65 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
settings = SettingsDialog(self.config, parent)
settings.exec_()
def onMainWindowCreated(self, window):
for id in range(1, self.config.spacerCount + 1):
def addSpacer(self, window, id):
spacer = Spacer(id, self.config.spacerMaxWidth)
self.config.spacerMaxWidthChanged.connect(spacer.setMaximumWidth)
window.navigationBar().addWidget(spacer, spacer.id(), spacer.name())
if window not in self.spacers:
self.spacers[window] = {}
if id not in self.spacers[window]:
self.spacers[window][id] = spacer
for id in range(1, self.config.separatorCount + 1):
def addSeparator(self, window, id):
separator = Separator(id, self.config.separatorWidth)
self.config.separatorWidthChanged.connect(separator.setMinimumWidth)
window.navigationBar().addWidget(separator, separator.id(), separator.name())
if window not in self.separators:
self.separators[window] = {}
if id not in self.separators[window]:
self.separators[window][id] = separator
def onSpacerCountChanged(self, count):
count = count + 1
for window in Falkon.MainApplication.instance().windows():
if window in self.spacers:
lenght = len(self.spacers[window]) + 1
if count > lenght:
for id in range(lenght, count):
self.addSpacer(window, id)
elif count < lenght:
for id in range(count, lenght):
if id in self.spacers[window]:
window.navigationBar().removeWidget(self.spacers[window][id].id())
del self.spacers[window][id]
def onSeparatorCountChanged(self, count):
count = count + 1
for window in Falkon.MainApplication.instance().windows():
if window in self.separators:
lenght = len(self.separators[window]) + 1
if count > lenght:
for id in range(lenght, count):
self.addSeparator(window, id)
elif count < lenght:
for id in range(count, lenght):
if id in self.separators[window]:
window.navigationBar().removeWidget(self.separators[window][id].id())
del self.separators[window][id]
def onMainWindowCreated(self, window):
for id in range(1, self.config.spacerCount + 1):
self.addSpacer(window, id)
for id in range(1, self.config.separatorCount + 1):
self.addSeparator(window, id)
def mainWindowDeleted(self, window):
if window in self.spacers:
for id, spacer in list(self.spacers[window].items()):