UI improvements

This commit is contained in:
BasioMeusPuga
2017-11-12 21:54:14 +05:30
parent 405ea3547c
commit e2ec7e680e
3 changed files with 180 additions and 44 deletions

View File

@@ -11,11 +11,8 @@ class BookToolBar(QtWidgets.QToolBar):
spacer.setSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
# Size policy
# TODO
# Prevent resizing
sizePolicy = QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
self.setMovable(False)
self.setIconSize(QtCore.QSize(22, 22))
@@ -43,40 +40,61 @@ class BookToolBar(QtWidgets.QToolBar):
self.fontSizeUp = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-font-size-more'),
'Increase font size', self)
self.fontSizeUp.setObjectName('fontSizeUp')
self.fontSizeDown = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-font-size-less'),
'Decrease font size', self)
self.fontSizeDown.setObjectName('fontSizeDown')
self.marginsUp = QtWidgets.QAction(
self.paddingUp = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-justify-fill'),
'Increase margins', self)
self.marginsDown = QtWidgets.QAction(
'Increase padding', self)
self.paddingUp.setObjectName('paddingUp')
self.paddingDown = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-indent-less'),
'Decrease margins', self)
'Decrease padding', self)
self.paddingDown.setObjectName('paddingDown')
self.lineSpacingUp = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-line-spacing-triple'),
'Increase line spacing', self)
self.lineSpacingUp.setObjectName('lineSpacingUp')
self.lineSpacingDown = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-line-spacing-double'),
'Decrease line spacing', self)
self.lineSpacingDown.setObjectName('lineSpacingDown')
self.fontBox = QtWidgets.QFontComboBox()
self.colorBoxFG = QtWidgets.QPushButton()
self.colorBoxBG = QtWidgets.QPushButton()
self.fontBox.setObjectName('fontBox')
self.colorBoxFG = FixedPushButton(self)
self.colorBoxFG.setObjectName('fgColor')
self.colorBoxFG.setToolTip('Set foreground color')
self.colorBoxBG = FixedPushButton(self)
self.colorBoxBG.setToolTip('Set background color')
self.colorBoxBG.setObjectName('bgColor')
# TODO
# Get color profiles from settings
# Generate default profiles
profiles = ['Profile 1', 'Profile 2', 'Profile 3']
self.profileBox = QtWidgets.QComboBox(self)
self.profileBox.addItems(profiles)
self.profileAction = self.addWidget(self.profileBox)
self.fontSeparator1 = self.addSeparator()
self.fontBoxAction = self.addWidget(self.fontBox)
self.addAction(self.fontSizeUp)
self.addAction(self.fontSizeDown)
self.fontSeparator1 = self.addSeparator()
self.fontSeparator2 = self.addSeparator()
self.fgColorAction = self.addWidget(self.colorBoxFG)
self.bgColorAction = self.addWidget(self.colorBoxBG)
self.fontSeparator2 = self.addSeparator()
self.fontSeparator3 = self.addSeparator()
self.addAction(self.lineSpacingUp)
self.addAction(self.lineSpacingDown)
self.fontSeparator3 = self.addSeparator()
self.addAction(self.marginsUp)
self.addAction(self.marginsDown)
self.fontSeparator4 = self.addSeparator()
self.addAction(self.paddingUp)
self.addAction(self.paddingDown)
self.fontBoxAction.setVisible(False)
self.fontSizeUp.setVisible(False)
@@ -85,24 +103,24 @@ class BookToolBar(QtWidgets.QToolBar):
self.bgColorAction.setVisible(False)
self.lineSpacingUp.setVisible(False)
self.lineSpacingDown.setVisible(False)
self.marginsUp.setVisible(False)
self.marginsDown.setVisible(False)
self.paddingUp.setVisible(False)
self.paddingDown.setVisible(False)
self.profileAction.setVisible(False)
self.fontSeparator1.setVisible(False)
self.fontSeparator2.setVisible(False)
self.fontSeparator3.setVisible(False)
self.fontSeparator4.setVisible(False)
self.searchBar = QtWidgets.QLineEdit()
self.searchBar.setPlaceholderText('Search...')
self.searchBar = FixedLineEdit(self)
self.searchBar.setPlaceholderText(
'Search...')
self.searchBar.setSizePolicy(sizePolicy)
self.searchBar.setContentsMargins(10, 0, 0, 0)
self.searchBar.setMinimumWidth(150)
self.searchBar.setObjectName('searchBar')
# Sorter
self.tocBox = QtWidgets.QComboBox()
self.tocBox = FixedComboBox(self)
self.tocBox.setObjectName('sortingBox')
self.tocBox.setSizePolicy(sizePolicy)
self.tocBox.setMinimumContentsLength(10)
self.tocBox.setToolTip('Table of Contents')
# All of these will be put after the spacer
@@ -130,11 +148,14 @@ class BookToolBar(QtWidgets.QToolBar):
self.bgColorAction.setVisible(True)
self.lineSpacingUp.setVisible(True)
self.lineSpacingDown.setVisible(True)
self.marginsUp.setVisible(True)
self.marginsDown.setVisible(True)
self.paddingUp.setVisible(True)
self.paddingDown.setVisible(True)
self.profileAction.setVisible(True)
self.fontSeparator1.setVisible(True)
self.fontSeparator2.setVisible(True)
self.fontSeparator3.setVisible(True)
self.fontSeparator3.setVisible(True)
self.fontSeparator4.setVisible(False)
self.tocBoxAction.setVisible(False)
self.searchBarAction.setVisible(False)
@@ -150,11 +171,13 @@ class BookToolBar(QtWidgets.QToolBar):
self.bgColorAction.setVisible(False)
self.lineSpacingUp.setVisible(False)
self.lineSpacingDown.setVisible(False)
self.marginsUp.setVisible(False)
self.marginsDown.setVisible(False)
self.paddingUp.setVisible(False)
self.paddingDown.setVisible(False)
self.profileAction.setVisible(False)
self.fontSeparator1.setVisible(False)
self.fontSeparator2.setVisible(False)
self.fontSeparator3.setVisible(False)
self.fontSeparator4.setVisible(False)
self.tocBoxAction.setVisible(True)
self.searchBarAction.setVisible(True)
@@ -189,30 +212,54 @@ class LibraryToolBar(QtWidgets.QToolBar):
# Filter
sizePolicy = QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
self.filterEdit = QtWidgets.QLineEdit()
self.filterEdit.setPlaceholderText(
# self.searchBar = QtWidgets.QLineEdit()
self.searchBar = FixedLineEdit(self)
self.searchBar.setPlaceholderText(
'Search for Title, Author, Tags...')
self.filterEdit.setSizePolicy(sizePolicy)
self.filterEdit.setContentsMargins(10, 0, 0, 0)
self.filterEdit.setMinimumWidth(150)
self.filterEdit.setObjectName('filterEdit')
self.searchBar.setSizePolicy(sizePolicy)
self.searchBar.setContentsMargins(10, 0, 0, 0)
self.searchBar.setObjectName('searchBar')
# Sorter
sorting_choices = ['Title', 'Author', 'Year']
self.sortingBox = QtWidgets.QComboBox()
self.sortingBox = FixedComboBox(self)
self.sortingBox.addItems(sorting_choices)
self.sortingBox.setObjectName('sortingBox')
self.sortingBox.setSizePolicy(sizePolicy)
# self.sortingBox.setContentsMargins(30, 0, 0, 0)
self.sortingBox.setMinimumContentsLength(10)
self.sortingBox.setToolTip('Sort by')
# Add widgets
self.addWidget(spacer)
self.addWidget(self.sortingBox)
self.addWidget(self.filterEdit)
self.addWidget(self.searchBar)
# Sublassing these widgets out prevents them from resizing
class FixedComboBox(QtWidgets.QComboBox):
def __init__(self, parent=None):
super(FixedComboBox, self).__init__(parent)
def sizeHint(self):
return QtCore.QSize(400, 22)
class FixedLineEdit(QtWidgets.QLineEdit):
def __init__(self, parent=None):
super(FixedLineEdit, self).__init__(parent)
def sizeHint(self):
return QtCore.QSize(400, 22)
class FixedPushButton(QtWidgets.QPushButton):
def __init__(self, parent=None):
super(FixedPushButton, self).__init__(parent)
def sizeHint(self):
return QtCore.QSize(36, 30)
class Tab(QtWidgets.QWidget):
@@ -227,7 +274,7 @@ class Tab(QtWidgets.QWidget):
super(Tab, self).__init__(parent)
self.parent = parent
self.metadata = metadata # Save progress data into this dictionary
self.setStyleSheet("background-color: black")
# self.setStyleSheet("background-color: black")
title = self.metadata['title']
path = self.metadata['path']