Tab reordering

This commit is contained in:
BasioMeusPuga
2019-01-17 21:53:04 +05:30
parent 5d35319164
commit 2185e9fcf7
3 changed files with 33 additions and 20 deletions

View File

@@ -233,8 +233,10 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.tab_switch()
self.tabWidget.currentChanged.connect(self.tab_switch)
# Tab closing
# Tab Widget formatting
self.tabWidget.setTabsClosable(True)
self.tabWidget.setDocumentMode(True)
self.tabWidget.tabBarClicked.connect(self.tab_disallow_library_movement)
# Get list of available parsers
self.available_parsers = '*.' + ' *.'.join(sorter.available_parsers)
@@ -243,6 +245,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# The Library tab gets no button
self.tabWidget.tabBar().setTabButton(
0, QtWidgets.QTabBar.RightSide, None)
self.tabWidget.widget(0).is_library = True
self.tabWidget.tabCloseRequested.connect(self.tab_close)
self.tabWidget.setTabBarAutoHide(True)
@@ -607,6 +610,12 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
def tab_switch(self):
try:
# Disallow library tab movement
# Does not need to be looped since the library
# tab can only ever go to position 1
if not self.tabWidget.widget(0).is_library:
self.tabWidget.tabBar().moveTab(1, 0)
if self.current_tab != 0:
self.tabWidget.widget(
self.current_tab).update_last_accessed_time()
@@ -692,6 +701,13 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.tabWidget.widget(tab_index).setParent(None)
gc.collect()
def tab_disallow_library_movement(self, tab_index):
# Makes the library tab immovable
if tab_index == 0:
self.tabWidget.setMovable(False)
else:
self.tabWidget.setMovable(True)
def set_toc_position(self, event=None):
current_tab = self.tabWidget.currentWidget()

View File

@@ -41,6 +41,7 @@ class Tab(QtWidgets.QWidget):
self.metadata = metadata # Save progress data into this dictionary
self.are_we_doing_images_only = self.metadata['images_only']
self.is_fullscreen = False
self.is_library = False
self.masterLayout = QtWidgets.QHBoxLayout(self)
self.masterLayout.setContentsMargins(0, 0, 0, 0)
@@ -534,23 +535,18 @@ class Tab(QtWidgets.QWidget):
def generate_annotation_model(self):
saved_annotations = self.main_window.settings['annotations']
if not saved_annotations:
return
def add_to_model(annotation):
item = QtGui.QStandardItem()
item.setText(annotation['name'])
item.setData(annotation, QtCore.Qt.UserRole)
self.annotationModel.appendRow(item)
# Prevent annotation mixup
# Create annotation model
# TODO
# Annotation previews will require creation of a
# QStyledItemDelegate
for i in saved_annotations:
if self.are_we_doing_images_only and i['applicable_to'] == 'images':
add_to_model(i)
elif not self.are_we_doing_images_only and i['applicable_to'] == 'text':
add_to_model(i)
item = QtGui.QStandardItem()
item.setText(i['name'])
item.setData(i, QtCore.Qt.UserRole)
self.annotationModel.appendRow(item)
self.annotationListView.setModel(self.annotationModel)
def add_bookmark(self, position=None):