diff --git a/__main__.py b/__main__.py index d24ae14..49860a5 100755 --- a/__main__.py +++ b/__main__.py @@ -199,14 +199,16 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): # ListView self.listView.setGridSize(QtCore.QSize(175, 240)) self.listView.setMouseTracking(True) - self.listView.verticalScrollBar().setSingleStep(7) - self.listView.doubleClicked.connect(self.list_doubleclick) + self.listView.verticalScrollBar().setSingleStep(9) + self.listView.doubleClicked.connect(self.library_doubleclick) self.listView.setItemDelegate(LibraryDelegate(self.temp_dir.path())) # TableView self.tableView.horizontalHeader().setSectionResizeMode( - QtWidgets.QHeaderView.ResizeToContents) + QtWidgets.QHeaderView.ResizeToContents) # TODO Change this to manual column sizing self.tableView.horizontalHeader().setStretchLastSection(True) + self.tableView.horizontalHeader().setSortIndicator(0, QtCore.Qt.AscendingOrder) + self.tableView.doubleClicked.connect(self.library_doubleclick) # Keyboard shortcuts self.ks_close_tab = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+W'), self) @@ -281,8 +283,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): def delete_books(self): # TODO - # Use maptosource() here to get the view_model + # Use maptosource() here to get the view_model # indices selected in the listView + # Implement this for the tableview selected_books = self.listView.selectedIndexes() if selected_books: @@ -409,9 +412,15 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): current_tab_widget = self.tabWidget.widget(current_tab) current_tab_widget.go_fullscreen() - def list_doubleclick(self, myindex): - index = self.listView.model().index(myindex.row(), 0) - metadata = self.listView.model().data(index, QtCore.Qt.UserRole + 3) + def library_doubleclick(self, myindex): + sender = self.sender().objectName() + + if sender == 'listView': + index = self.lib_ref.proxy_model.index(myindex.row(), 0) + metadata = self.lib_ref.proxy_model.data(index, QtCore.Qt.UserRole + 3) + elif sender == 'tableView': + index = self.lib_ref.table_proxy_model.index(myindex.row(), 0) + metadata = self.lib_ref.table_proxy_model.data(index, QtCore.Qt.UserRole) # Shift focus to the tab that has the book open (if there is one) for i in range(1, self.tabWidget.count()): diff --git a/library.py b/library.py index fa49a7c..8036d0a 100644 --- a/library.py +++ b/library.py @@ -14,6 +14,7 @@ class Library: self.view_model = None self.proxy_model = None self.table_model = None + self.table_proxy_model = None self.table_rows = [] def generate_model(self, mode, parsed_books=None): @@ -111,6 +112,10 @@ class Library: img_pixmap = img_pixmap.scaled(420, 600, QtCore.Qt.IgnoreAspectRatio) item = QtGui.QStandardItem() item.setToolTip(tooltip_string) + + # TODO + # Simplify this mess + # The following order is needed to keep sorting working item.setData(title, QtCore.Qt.UserRole) item.setData(author, QtCore.Qt.UserRole + 1) @@ -123,19 +128,20 @@ class Library: item.setIcon(QtGui.QIcon(img_pixmap)) self.view_model.appendRow(item) - # Path is just being sent. It is not being displayed + # all_metadata is just being sent. It is not being displayed + # It will be correlated to the current row as its first userrole self.table_rows.append( - (title, author, year, tags, path)) + (title, author, year, tags, all_metadata)) def create_table_model(self): table_header = ['Title', 'Author', 'Year', 'Tags'] - # self.table_rows.sort(key=lambda x: x[0]) self.table_model = LibraryTableModel(table_header, self.table_rows) self.create_table_proxy_model() def create_table_proxy_model(self): self.table_proxy_model = TableProxyModel() self.table_proxy_model.setSourceModel(self.table_model) + self.table_proxy_model.setSortCaseSensitivity(False) self.parent_window.tableView.setModel(self.table_proxy_model) def update_table_proxy_model(self): @@ -153,6 +159,7 @@ class Library: def create_proxymodel(self): self.proxy_model = QtCore.QSortFilterProxyModel() self.proxy_model.setSourceModel(self.view_model) + self.proxy_model.setSortCaseSensitivity(False) s = QtCore.QSize(160, 250) # Set icon sizing here self.parent_window.listView.setIconSize(s) self.parent_window.listView.setModel(self.proxy_model) diff --git a/models.py b/models.py index 2084886..6efbc28 100644 --- a/models.py +++ b/models.py @@ -11,10 +11,11 @@ class LibraryItemModel(QtGui.QStandardItemModel, QtCore.QAbstractItemModel): class LibraryTableModel(QtCore.QAbstractTableModel): # TODO - # Speed up sorting - # Double clicking # Auto resize with emphasis on Name + # Sorting is taken care of by the QSortFilterProxy model + # which has an inbuilt sort method + def __init__(self, header_data, display_data, parent=None): super(LibraryTableModel, self).__init__(parent) self.header_data = header_data @@ -33,6 +34,10 @@ class LibraryTableModel(QtCore.QAbstractTableModel): if role == QtCore.Qt.DisplayRole: value = self.display_data[index.row()][index.column()] return value + elif role == QtCore.Qt.UserRole: + # The rest of the roles can be accomodated here. + value = self.display_data[index.row()][4] + return value else: return QtCore.QVariant() @@ -41,14 +46,6 @@ class LibraryTableModel(QtCore.QAbstractTableModel): return self.header_data[col] return None - def sort(self, col, order): - # self.emit(SIGNAL("layoutAboutToBeChanged()")) - self.display_data.sort(key=lambda x: x[col]) - if order == QtCore.Qt.DescendingOrder: - self.display_data.sort(key=lambda x: x[col], reverse=True) - - # self.emit(SIGNAL("layoutChanged()")) - class TableProxyModel(QtCore.QSortFilterProxyModel): def __init__(self, parent=None): diff --git a/resources/raw/settings.ui b/resources/raw/settings.ui index a375d66..669b342 100644 --- a/resources/raw/settings.ui +++ b/resources/raw/settings.ui @@ -27,15 +27,15 @@ - - - - Search for Paths, Names, Tags... - - - + + + + Search for Paths, Names, Tags... + + + @@ -93,6 +93,13 @@ + + + + Cover Shadows + + + diff --git a/resources/settingswindow.py b/resources/settingswindow.py index 0150728..cf2f40a 100644 --- a/resources/settingswindow.py +++ b/resources/settingswindow.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'raw/settings.ui' # -# Created by: PyQt5 UI code generator 5.9.1 +# Created by: PyQt5 UI code generator 5.9.2 # # WARNING! All changes made in this file will be lost! @@ -25,11 +25,11 @@ class Ui_Dialog(object): self.tableView = QtWidgets.QTableView(self.groupBox_2) self.tableView.setObjectName("tableView") self.verticalLayout.addWidget(self.tableView) - self.lineEdit = QtWidgets.QLineEdit(self.groupBox_2) - self.lineEdit.setObjectName("lineEdit") - self.verticalLayout.addWidget(self.lineEdit) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") + self.lineEdit = QtWidgets.QLineEdit(self.groupBox_2) + self.lineEdit.setObjectName("lineEdit") + self.horizontalLayout.addWidget(self.lineEdit) self.addButton = QtWidgets.QPushButton(self.groupBox_2) self.addButton.setObjectName("addButton") self.horizontalLayout.addWidget(self.addButton) @@ -57,6 +57,9 @@ class Ui_Dialog(object): self.checkBox_2 = QtWidgets.QCheckBox(self.groupBox) self.checkBox_2.setObjectName("checkBox_2") self.horizontalLayout_3.addWidget(self.checkBox_2) + self.checkBox_3 = QtWidgets.QCheckBox(self.groupBox) + self.checkBox_3.setObjectName("checkBox_3") + self.horizontalLayout_3.addWidget(self.checkBox_3) self.gridLayout.addLayout(self.horizontalLayout_3, 0, 0, 1, 1) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") @@ -85,6 +88,7 @@ class Ui_Dialog(object): self.checkBox.setText(_translate("Dialog", "Auto add files")) self.fileRemember.setText(_translate("Dialog", "Remember open files")) self.checkBox_2.setText(_translate("Dialog", "Show Library")) + self.checkBox_3.setText(_translate("Dialog", "Cover Shadows")) self.aboutButton.setText(_translate("Dialog", "About")) self.okButton.setText(_translate("Dialog", "OK"))