Text alignment implemented
This commit is contained in:
25
TODO
25
TODO
@@ -47,30 +47,31 @@ TODO
|
||||
Set context menu for definitions and the like
|
||||
Search document using QTextCursor?
|
||||
Cache multiple images
|
||||
Graphical themes
|
||||
Comic view keyboard shortcuts
|
||||
Comic view modes
|
||||
Continuous paging
|
||||
Double pages
|
||||
Pagination
|
||||
Use embedded fonts
|
||||
Scrolling: Smooth / By Line
|
||||
Filetypes:
|
||||
✓ cbz, cbr support
|
||||
✓ Keep font settings enabled but only for background color
|
||||
Cache next and previous images
|
||||
epub support
|
||||
mobi, azw support
|
||||
txt, doc, chm, djvu, fb2 support
|
||||
? Plugin system for parsers
|
||||
? pdf support
|
||||
Internet:
|
||||
Goodreads API: Ratings, Read, Recommendations
|
||||
Get ISBN using python-isbnlib
|
||||
Other:
|
||||
✓ Define every widget in code
|
||||
✓ Include icons for emblems
|
||||
Shift to logging instead of print statements
|
||||
Bugs:
|
||||
If there are files open and the database is deleted, TypeErrors result
|
||||
Closing a fullscreened contentView does not save settings
|
||||
Closing a fullscreened contentView does not save settings
|
||||
|
||||
Secondary:
|
||||
Graphical themes
|
||||
Goodreads API: Ratings, Read, Recommendations
|
||||
Get ISBN using python-isbnlib
|
||||
Pagination
|
||||
Use embedded fonts
|
||||
Scrolling: Smooth / By Line
|
||||
Shift to logging instead of print statements
|
||||
? Plugin system for parsers
|
||||
? pdf support
|
||||
txt, doc, chm, djvu, fb2 support
|
28
__main__.py
28
__main__.py
@@ -145,6 +145,19 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
self.bookToolBar.paddingDown.triggered.connect(self.modify_font)
|
||||
self.bookToolBar.resetProfile.triggered.connect(self.reset_profile)
|
||||
|
||||
alignment_dict = {
|
||||
'left': self.bookToolBar.alignLeft,
|
||||
'right': self.bookToolBar.alignRight,
|
||||
'center': self.bookToolBar.alignCenter,
|
||||
'justify': self.bookToolBar.alignJustify}
|
||||
|
||||
profile_index = self.bookToolBar.profileBox.currentIndex()
|
||||
current_profile = self.bookToolBar.profileBox.itemData(
|
||||
profile_index, QtCore.Qt.UserRole)
|
||||
for i in alignment_dict.items():
|
||||
i[1].triggered.connect(self.modify_font)
|
||||
alignment_dict[current_profile['text_alignment']].setChecked(True)
|
||||
|
||||
self.bookToolBar.zoomIn.triggered.connect(self.modify_comic_view)
|
||||
self.bookToolBar.zoomOut.triggered.connect(self.modify_comic_view)
|
||||
self.bookToolBar.fitWidth.triggered.connect(self.modify_comic_view)
|
||||
@@ -770,6 +783,14 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
if signal_sender == 'paddingDown':
|
||||
current_profile['padding'] -= 5
|
||||
|
||||
alignment_dict = {
|
||||
'alignLeft': 'left',
|
||||
'alignRight': 'right',
|
||||
'alignCenter': 'center',
|
||||
'alignJustify': 'justify'}
|
||||
if signal_sender in alignment_dict:
|
||||
current_profile['text_alignment'] = alignment_dict[signal_sender]
|
||||
|
||||
self.bookToolBar.profileBox.setItemData(
|
||||
profile_index, current_profile, QtCore.Qt.UserRole)
|
||||
self.format_contentView()
|
||||
@@ -842,7 +863,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
'background-color: %s' % background.name())
|
||||
|
||||
current_tab.format_view(
|
||||
None, None, None, background, padding, None)
|
||||
None, None, None, background, padding, None, None)
|
||||
|
||||
else:
|
||||
profile_index = self.bookToolBar.profileBox.currentIndex()
|
||||
@@ -855,6 +876,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
padding = current_profile['padding']
|
||||
font_size = current_profile['font_size']
|
||||
line_spacing = current_profile['line_spacing']
|
||||
text_alignment = current_profile['text_alignment']
|
||||
|
||||
# Change toolbar widgets to match new settings
|
||||
self.bookToolBar.fontBox.blockSignals(True)
|
||||
@@ -872,7 +894,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
'background-color: %s' % background.name())
|
||||
|
||||
current_tab.format_view(
|
||||
font, font_size, foreground, background, padding, line_spacing)
|
||||
font, font_size, foreground,
|
||||
background, padding, line_spacing,
|
||||
text_alignment)
|
||||
|
||||
def reset_profile(self):
|
||||
current_profile_index = self.bookToolBar.profileBox.currentIndex()
|
||||
|
23
settings.py
23
settings.py
@@ -12,28 +12,31 @@ class Settings:
|
||||
self.settings = QtCore.QSettings('Lector', 'Lector')
|
||||
|
||||
default_profile1 = {
|
||||
'font': 'Noto Sans',
|
||||
'font': 'Noto Sans Fallback',
|
||||
'foreground': QtGui.QColor().fromRgb(0, 0, 0),
|
||||
'background': QtGui.QColor().fromRgb(216, 216, 216),
|
||||
'padding': 140,
|
||||
'font_size': 20,
|
||||
'line_spacing': 110}
|
||||
'padding': 150,
|
||||
'font_size': 30,
|
||||
'line_spacing': 110,
|
||||
'text_alignment': 'justify'}
|
||||
|
||||
default_profile2 = {
|
||||
'font': 'Roboto',
|
||||
'foreground': QtGui.QColor().fromRgb(194, 194, 194),
|
||||
'background': QtGui.QColor().fromRgb(22, 22, 22),
|
||||
'padding': 140,
|
||||
'font_size': 20,
|
||||
'line_spacing': 110}
|
||||
'padding': 150,
|
||||
'font_size': 30,
|
||||
'line_spacing': 110,
|
||||
'text_alignment': 'justify'}
|
||||
|
||||
default_profile3 = {
|
||||
'font': 'Clear Sans',
|
||||
'foreground': QtGui.QColor().fromRgb(101, 123, 131),
|
||||
'background': QtGui.QColor().fromRgb(0, 43, 54),
|
||||
'padding': 140,
|
||||
'padding': 150,
|
||||
'font_size': 30,
|
||||
'line_spacing': 110}
|
||||
'line_spacing': 110,
|
||||
'text_alignment': 'justify'}
|
||||
|
||||
self.default_profiles = [
|
||||
default_profile1, default_profile2, default_profile3]
|
||||
@@ -88,7 +91,7 @@ class Settings:
|
||||
self.parent.settings['scan_library'] = literal_eval(self.settings.value(
|
||||
'scanLibraryAtStart', 'False').capitalize())
|
||||
self.parent.settings['remember_files'] = literal_eval(self.settings.value(
|
||||
'rememberFiles', 'False').capitalize())
|
||||
'rememberFiles', 'True').capitalize())
|
||||
self.parent.settings['perform_culling'] = literal_eval(self.settings.value(
|
||||
'performCulling', 'True').capitalize())
|
||||
self.settings.endGroup()
|
||||
|
42
toolbars.py
42
toolbars.py
@@ -81,7 +81,7 @@ class BookToolBar(QtWidgets.QToolBar):
|
||||
'Increase padding', self)
|
||||
self.paddingUp.setObjectName('paddingUp')
|
||||
self.paddingDown = QtWidgets.QAction(
|
||||
QtGui.QIcon.fromTheme('format-justify-fill'),
|
||||
QtGui.QIcon.fromTheme('format-indent-more'),
|
||||
'Decrease padding', self)
|
||||
self.paddingDown.setObjectName('paddingDown')
|
||||
|
||||
@@ -94,6 +94,37 @@ class BookToolBar(QtWidgets.QToolBar):
|
||||
'Decrease line spacing', self)
|
||||
self.lineSpacingDown.setObjectName('lineSpacingDown')
|
||||
|
||||
self.alignLeft = QtWidgets.QAction(
|
||||
QtGui.QIcon.fromTheme('format-justify-left'),
|
||||
'Left align text', self)
|
||||
self.alignLeft.setObjectName('alignLeft')
|
||||
self.alignLeft.setCheckable(True)
|
||||
|
||||
self.alignRight = QtWidgets.QAction(
|
||||
QtGui.QIcon.fromTheme('format-justify-right'),
|
||||
'Right align text', self)
|
||||
self.alignRight.setObjectName('alignRight')
|
||||
self.alignRight.setCheckable(True)
|
||||
|
||||
self.alignCenter = QtWidgets.QAction(
|
||||
QtGui.QIcon.fromTheme('format-justify-center'),
|
||||
'Center align text', self)
|
||||
self.alignCenter.setObjectName('alignCenter')
|
||||
self.alignCenter.setCheckable(True)
|
||||
|
||||
self.alignJustify = QtWidgets.QAction(
|
||||
QtGui.QIcon.fromTheme('format-justify-fill'),
|
||||
'Justify text', self)
|
||||
self.alignJustify.setObjectName('alignJustify')
|
||||
self.alignJustify.setCheckable(True)
|
||||
|
||||
self.alignButtons = QtWidgets.QActionGroup(self)
|
||||
self.alignButtons.setExclusive(True)
|
||||
self.alignButtons.addAction(self.alignLeft)
|
||||
self.alignButtons.addAction(self.alignRight)
|
||||
self.alignButtons.addAction(self.alignCenter)
|
||||
self.alignButtons.addAction(self.alignJustify)
|
||||
|
||||
self.fontBox = QtWidgets.QFontComboBox()
|
||||
self.fontBox.setFontFilters(QtWidgets.QFontComboBox.ScalableFonts)
|
||||
self.fontBox.setObjectName('fontBox')
|
||||
@@ -122,6 +153,11 @@ class BookToolBar(QtWidgets.QToolBar):
|
||||
self.fontSeparator4 = self.addSeparator()
|
||||
self.addAction(self.paddingUp)
|
||||
self.addAction(self.paddingDown)
|
||||
self.fontSeparator4 = self.addSeparator()
|
||||
self.addAction(self.alignLeft)
|
||||
self.addAction(self.alignRight)
|
||||
self.addAction(self.alignCenter)
|
||||
self.addAction(self.alignJustify)
|
||||
|
||||
self.fontActions = [
|
||||
self.fontBoxAction,
|
||||
@@ -132,6 +168,10 @@ class BookToolBar(QtWidgets.QToolBar):
|
||||
self.lineSpacingDown,
|
||||
self.paddingUp,
|
||||
self.paddingDown,
|
||||
self.alignLeft,
|
||||
self.alignRight,
|
||||
self.alignCenter,
|
||||
self.alignJustify,
|
||||
self.profileAction,
|
||||
self.fontSeparator1,
|
||||
self.fontSeparator2,
|
||||
|
19
widgets.py
19
widgets.py
@@ -230,7 +230,10 @@ class Tab(QtWidgets.QWidget):
|
||||
self.contentView.clear()
|
||||
self.contentView.setHtml(required_content)
|
||||
|
||||
def format_view(self, font, font_size, foreground, background, padding, line_spacing):
|
||||
def format_view(self, font, font_size, foreground,
|
||||
background, padding, line_spacing,
|
||||
text_alignment):
|
||||
|
||||
if self.are_we_doing_images_only:
|
||||
# Tab color does not need to be set separately in case
|
||||
# no padding is set for the viewport of a QGraphicsView
|
||||
@@ -253,9 +256,13 @@ class Tab(QtWidgets.QWidget):
|
||||
block_format.setLineHeight(
|
||||
line_spacing, QtGui.QTextBlockFormat.ProportionalHeight)
|
||||
|
||||
# TODO
|
||||
# Give options for alignment
|
||||
# block_format.setAlignment(QtCore.Qt.AlignJustify)
|
||||
alignment_dict = {
|
||||
'left': QtCore.Qt.AlignLeft,
|
||||
'right': QtCore.Qt.AlignRight,
|
||||
'center': QtCore.Qt.AlignCenter,
|
||||
'justify': QtCore.Qt.AlignJustify}
|
||||
block_format.setAlignment(alignment_dict[text_alignment])
|
||||
|
||||
# Also for padding
|
||||
# Using setViewPortMargins for this disables scrolling in the margins
|
||||
@@ -625,12 +632,8 @@ class BookmarkDelegate(QtWidgets.QStyledItemDelegate):
|
||||
chapter_index = index.data(QtCore.Qt.UserRole)
|
||||
chapter_name = self.parent.window().bookToolBar.tocBox.itemText(chapter_index - 1)
|
||||
|
||||
painter.save()
|
||||
painter.translate(0, -10)
|
||||
QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
|
||||
painter.restore()
|
||||
|
||||
painter.drawText(
|
||||
option.rect,
|
||||
QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeft|QtCore.Qt.TextWordWrap,
|
||||
QtCore.Qt.AlignBottom|QtCore.Qt.AlignRight|QtCore.Qt.TextWordWrap,
|
||||
' ' + chapter_name)
|
||||
|
Reference in New Issue
Block a user