Implement image rotation

This commit is contained in:
BasioMeusPuga
2019-03-16 00:06:53 -04:00
parent 38de0dcd13
commit 4cf0a9e78c
12 changed files with 9489 additions and 8710 deletions

View File

@@ -204,6 +204,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.bookToolBar.doublePageButton.triggered.connect(self.change_page_view)
self.bookToolBar.mangaModeButton.triggered.connect(self.change_page_view)
self.bookToolBar.invertButton.triggered.connect(self.change_page_view)
self.bookToolBar.rotateRightButton.triggered.connect(self.change_page_view)
self.bookToolBar.rotateLeftButton.triggered.connect(self.change_page_view)
if self.settings['double_page_mode']:
self.bookToolBar.doublePageButton.setChecked(True)
if self.settings['manga_mode']:
@@ -766,12 +768,27 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
#=================================================================
def change_page_view(self, key_pressed=False):
# Switch page to whatever index is selected in the tocBox
current_tab = self.tabWidget.currentWidget()
chapter_number = current_tab.metadata['position']['current_chapter']
# Set zoom mode to best fit to
# make the transition less jarring
# if the sender isn't the invert colors button
if self.sender() != self.bookToolBar.invertButton:
self.comic_profile['zoom_mode'] = 'bestFit'
# Rotate the image left or right
# The double page mode is incompatible with this
if self.sender() == self.bookToolBar.rotateLeftButton:
current_tab.generate_rotation(-90)
self.bookToolBar.doublePageButton.setChecked(False)
if self.sender() == self.bookToolBar.rotateRightButton:
current_tab.generate_rotation(90)
self.bookToolBar.doublePageButton.setChecked(False)
if self.sender() == self.bookToolBar.doublePageButton:
current_tab.image_rotation = 0
# Toggle Double page mode / manga mode on keypress
if key_pressed == QtCore.Qt.Key_D:
self.bookToolBar.doublePageButton.setChecked(
@@ -786,9 +803,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.settings['manga_mode'] = self.bookToolBar.mangaModeButton.isChecked()
self.settings['invert_colors'] = self.bookToolBar.invertButton.isChecked()
# Switch page to whatever index is selected in the tocBox
current_tab = self.tabWidget.currentWidget()
chapter_number = current_tab.metadata['position']['current_chapter']
current_tab.set_content(chapter_number, False)
def generate_library_context_menu(self, position):

View File

@@ -196,6 +196,8 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
else:
return_pixmap = load_page(current_page)
# Final pixmap transformations may take place here
## Color inversion
if self.main_window.settings['invert_colors']:
qImg = return_pixmap.toImage()
qImg.invertPixels()
@@ -204,6 +206,12 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
else:
logger.error('Color inversion failed: ' + current_page)
## Image rotation
if not self.parent.image_rotation == 0:
transformation = QtGui.QTransform()
transformation.rotate(self.parent.image_rotation)
return_pixmap = return_pixmap.transformed(transformation)
self.image_pixmap = return_pixmap
self.resizeEvent()
@@ -350,6 +358,14 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
mangaModeAction.setCheckable(True)
mangaModeAction.setChecked(
self.main_window.bookToolBar.mangaModeButton.isChecked())
invertColorsAction = viewSubMenu.addAction(
self.main_window.QImageFactory.get_image('invert'),
self._translate('PliantQGraphicsView', 'Invert page colors'))
invertColorsAction.setCheckable(True)
invertColorsAction.setChecked(
self.main_window.bookToolBar.invertButton.isChecked())
viewSubMenu.addSeparator()
zoominAction = viewSubMenu.addAction(
@@ -386,6 +402,8 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
self.main_window.bookToolBar.doublePageButton.trigger()
if action == mangaModeAction:
self.main_window.bookToolBar.mangaModeButton.trigger()
if action == invertColorsAction:
self.main_window.bookToolBar.invertButton.trigger()
if action == saveAction:
dialog_prompt = self._translate('Main_UI', 'Save page as...')

View File

@@ -131,7 +131,8 @@ class CoverLoadingAndCulling:
img_pixmap.loadFromData(cover)
else:
img_pixmap.load(':/images/NotFound.png')
img_pixmap = img_pixmap.scaled(420, 600, QtCore.Qt.IgnoreAspectRatio)
img_pixmap = img_pixmap.scaled(
420, 600, QtCore.Qt.IgnoreAspectRatio)
item.setIcon(QtGui.QIcon(img_pixmap))
item.setData(True, QtCore.Qt.UserRole + 8)

View File

@@ -1,8 +1,62 @@
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22">
<defs>
<style id="current-color-scheme" type="text/css">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="22"
height="22"
viewBox="0 0 22 22"
version="1.1"
id="svg7"
sodipodi:docname="invert.svg"
inkscape:version="0.92.4 5da689c313, 2019-01-14">
<metadata
id="metadata11">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="855"
inkscape:window-height="480"
id="namedview9"
showgrid="false"
inkscape:zoom="10.727273"
inkscape:cx="11"
inkscape:cy="11"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="svg7" />
<defs
id="defs3">
<style
id="current-color-scheme"
type="text/css">
.ColorScheme-Text { color:#444444; } .ColorScheme-Highlight { color:#5294e2; }
</style>
</defs>
<path style="fill:currentColor" class="ColorScheme-Text" d="M 2 1 L 2 15 L 9 15 L 9 13 A 5 5 0 0 1 4 8 A 5 5 0 0 1 9 3 L 9 1 L 2 1 z M 9 3 L 9 13 C 11.7614 13 14 10.7614 14 8 C 14 5.2386 11.7614 3 9 3 z" transform="translate(3 3)"/>
</defs>
<path
style="fill:#5c616c;fill-opacity:1"
class="ColorScheme-Text"
d="M 2 1 L 2 15 L 9 15 L 9 13 A 5 5 0 0 1 4 8 A 5 5 0 0 1 9 3 L 9 1 L 2 1 z M 9 3 L 9 13 C 11.7614 13 14 10.7614 14 8 C 14 5.2386 11.7614 3 9 3 z"
transform="translate(3 3)"
id="path5" />
</svg>

Before

Width:  |  Height:  |  Size: 487 B

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="22"
height="22"
viewBox="0 0 22 22"
version="1.1"
id="svg7"
sodipodi:docname="rotate-left.svg"
inkscape:version="0.92.4 5da689c313, 2019-01-14">
<metadata
id="metadata11">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="855"
inkscape:window-height="480"
id="namedview9"
showgrid="false"
inkscape:zoom="10.727273"
inkscape:cx="11"
inkscape:cy="11"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="svg7" />
<defs
id="defs3">
<style
id="current-color-scheme"
type="text/css">
.ColorScheme-Text { color:#444444; } .ColorScheme-Highlight { color:#4285f4; }
</style>
</defs>
<path
style="fill:#5c616c;fill-opacity:1"
class="ColorScheme-Text"
d="M 8.0292969 0.001953125 L 4.0292969 3.0019531 L 8.0292969 6.0019531 L 8.0292969 4.0019531 C 10.238397 4.0019531 12.029297 5.7928531 12.029297 8.0019531 C 12.029297 10.211053 10.238397 12.001953 8.0292969 12.001953 C 5.8201969 12.001953 4.0292969 10.211053 4.0292969 8.0019531 A 1 1 0 0 0 3.0292969 7.0019531 A 1 1 0 0 0 2.0292969 8.0019531 A 1 1 0 0 0 2.0351562 8.1015625 C 2.0889563 11.368762 4.7491969 14.001953 8.0292969 14.001953 C 11.342997 14.001953 14.029297 11.315653 14.029297 8.0019531 C 14.029297 4.6882531 11.342997 2.0019531 8.0292969 2.0019531 L 8.0292969 0.001953125 z"
transform="translate(3 3)"
id="path5" />
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="22"
height="22"
viewBox="0 0 22 22"
version="1.1"
id="svg7"
sodipodi:docname="rotate-right.svg"
inkscape:version="0.92.4 5da689c313, 2019-01-14">
<metadata
id="metadata11">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="855"
inkscape:window-height="480"
id="namedview9"
showgrid="false"
inkscape:zoom="10.727273"
inkscape:cx="11"
inkscape:cy="11"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="svg7" />
<defs
id="defs3">
<style
id="current-color-scheme"
type="text/css">
.ColorScheme-Text { color:#444444; } .ColorScheme-Highlight { color:#4285f4; }
</style>
</defs>
<path
style="fill:#5c616c;fill-opacity:1"
class="ColorScheme-Text"
d="M 7.9804688 0.001953125 L 7.9804688 2.0019531 C 4.6667688 2.0019531 1.9804688 4.6882531 1.9804688 8.0019531 C 1.9804688 11.315653 4.6667688 14.001953 7.9804688 14.001953 C 11.260569 14.001953 13.920809 11.368762 13.974609 8.1015625 A 1 1 0 0 0 13.980469 8.0019531 A 1 1 0 0 0 12.980469 7.0019531 A 1 1 0 0 0 11.980469 8.0019531 C 11.980469 10.211053 10.189569 12.001953 7.9804688 12.001953 C 5.7713688 12.001953 3.9804688 10.211053 3.9804688 8.0019531 C 3.9804688 5.7928531 5.7713688 4.0019531 7.9804688 4.0019531 L 7.9804688 6.0019531 L 11.980469 3.0019531 L 7.9804688 0.001953125 z"
transform="translate(3 3)"
id="path5" />
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22">
<defs>
<style id="current-color-scheme" type="text/css">
.ColorScheme-Text { color:#dfdfdf; } .ColorScheme-Highlight { color:#4285f4; }
</style>
</defs>
<path style="fill:currentColor" class="ColorScheme-Text" d="M 8.0292969 0.001953125 L 4.0292969 3.0019531 L 8.0292969 6.0019531 L 8.0292969 4.0019531 C 10.238397 4.0019531 12.029297 5.7928531 12.029297 8.0019531 C 12.029297 10.211053 10.238397 12.001953 8.0292969 12.001953 C 5.8201969 12.001953 4.0292969 10.211053 4.0292969 8.0019531 A 1 1 0 0 0 3.0292969 7.0019531 A 1 1 0 0 0 2.0292969 8.0019531 A 1 1 0 0 0 2.0351562 8.1015625 C 2.0889563 11.368762 4.7491969 14.001953 8.0292969 14.001953 C 11.342997 14.001953 14.029297 11.315653 14.029297 8.0019531 C 14.029297 4.6882531 11.342997 2.0019531 8.0292969 2.0019531 L 8.0292969 0.001953125 z" transform="translate(3 3)"/>
</svg>

After

Width:  |  Height:  |  Size: 928 B

View File

@@ -0,0 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22">
<defs>
<style id="current-color-scheme" type="text/css">
.ColorScheme-Text { color:#dfdfdf; } .ColorScheme-Highlight { color:#4285f4; }
</style>
</defs>
<path style="fill:currentColor" class="ColorScheme-Text" d="M 7.9804688 0.001953125 L 7.9804688 2.0019531 C 4.6667688 2.0019531 1.9804688 4.6882531 1.9804688 8.0019531 C 1.9804688 11.315653 4.6667688 14.001953 7.9804688 14.001953 C 11.260569 14.001953 13.920809 11.368762 13.974609 8.1015625 A 1 1 0 0 0 13.980469 8.0019531 A 1 1 0 0 0 12.980469 7.0019531 A 1 1 0 0 0 11.980469 8.0019531 C 11.980469 10.211053 10.189569 12.001953 7.9804688 12.001953 C 5.7713688 12.001953 3.9804688 10.211053 3.9804688 8.0019531 C 3.9804688 5.7928531 5.7713688 4.0019531 7.9804688 4.0019531 L 7.9804688 6.0019531 L 11.980469 3.0019531 L 7.9804688 0.001953125 z" transform="translate(3 3)"/>
</svg>

After

Width:  |  Height:  |  Size: 928 B

View File

@@ -1,5 +1,9 @@
<RCC>
<qresource prefix="images">
<file>DarkIcons/rotate-left.svg</file>
<file>DarkIcons/rotate-right.svg</file>
<file>LightIcons/rotate-left.svg</file>
<file>LightIcons/rotate-right.svg</file>
<file>DarkIcons/invert.svg</file>
<file>LightIcons/invert.svg</file>
<file>DarkIcons/manga-mode.svg</file>

File diff suppressed because it is too large Load Diff

View File

@@ -234,6 +234,15 @@ class BookToolBar(QtWidgets.QToolBar):
self.invertButton.setObjectName('mangaModeButton')
self.invertButton.setCheckable(True)
self.rotateRightButton = QtWidgets.QAction(
image_factory.get_image('rotate-right'),
self._translate('BookToolBar', 'Rotate image clockwise'),
self)
self.rotateLeftButton = QtWidgets.QAction(
image_factory.get_image('rotate-left'),
self._translate('BookToolBar', 'Rotate image anti-clockwise'),
self)
self.zoomIn = QtWidgets.QAction(
image_factory.get_image('zoom-in'),
self._translate('BookToolBar', 'Zoom in (+)'),
@@ -273,12 +282,15 @@ class BookToolBar(QtWidgets.QToolBar):
self.addAction(self.mangaModeButton)
self.addAction(self.invertButton)
self.comicSeparator2 = self.addSeparator()
self.addAction(self.rotateRightButton)
self.addAction(self.rotateLeftButton)
self.comicSeparator3 = self.addSeparator()
self.addAction(self.zoomIn)
self.addAction(self.zoomOut)
self.addAction(self.fitWidth)
self.addAction(self.bestFit)
self.addAction(self.originalSize)
self.comicSeparator3 = self.addSeparator()
self.comicSeparator4 = self.addSeparator()
self.comicBGColorAction = self.addWidget(self.comicBGColor)
self.comicActions = [
@@ -286,6 +298,8 @@ class BookToolBar(QtWidgets.QToolBar):
self.mangaModeButton,
self.invertButton,
self.comicBGColorAction,
self.rotateLeftButton,
self.rotateRightButton,
self.zoomIn,
self.zoomOut,
self.fitWidth,
@@ -293,7 +307,8 @@ class BookToolBar(QtWidgets.QToolBar):
self.originalSize,
self.comicSeparator1,
self.comicSeparator2,
self.comicSeparator3]
self.comicSeparator3,
self.comicSeparator4]
for i in self.comicActions:
i.setVisible(False)

View File

@@ -78,6 +78,7 @@ class Tab(QtWidgets.QWidget):
if self.are_we_doing_images_only:
self.contentView = PliantQGraphicsView(
self.metadata['path'], self.main_window, self)
self.image_rotation = 0
else:
self.contentView = PliantQTextBrowser(
@@ -202,6 +203,15 @@ class Tab(QtWidgets.QWidget):
self.sideDock.sideDockTabWidget.setCurrentIndex(tab_required)
def generate_rotation(self, delta_angle):
self.image_rotation += delta_angle
# Set bounds for rotation angle
if self.image_rotation == 360:
self.image_rotation = 0
if self.image_rotation == -90:
self.image_rotation = 270
def update_last_accessed_time(self):
self.metadata['last_accessed'] = QtCore.QDateTime().currentDateTime()