Skip to content

Commit

Permalink
Add custom icons
Browse files Browse the repository at this point in the history
* Use custom icons on platforms which do not provide theme
* Old zoom icons credits to "schollidesign" from icon pack Office and Entertainment (GPL licence).
* Exchange icon credit to Jason Cho (Unknown license).
* Use hack to resize viewers on first show() as well
  • Loading branch information
glubsy committed Jul 15, 2020
1 parent 95b8406 commit 58c675d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 23 deletions.
Binary file added images/exchange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/exchange_purple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/old_zoom_best_fit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/old_zoom_in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/old_zoom_original.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/old_zoom_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions qt/dg.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
<file alias="plus">../images/plus_8.png</file>
<file alias="minus">../images/minus_8.png</file>
<file alias="search_clear_13">../qtlib/images/search_clear_13.png</file>
<file alias="exchange">../images/exchange_purple.png</file>
<file alias="zoom_in">../images/old_zoom_in.png</file>
<file alias="zoom_out">../images/old_zoom_out.png</file>
<file alias="zoom_original">../images/old_zoom_original.png</file>
<file alias="zoom_best_fit">../images/old_zoom_best_fit.png</file>
</qresource>
</RCC>
38 changes: 21 additions & 17 deletions qt/pe/details_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,7 @@ def _update(self):

# --- Override
def resizeEvent(self, event):
# HACK referenceViewer might be 1 pixel shorter in width
# due to the toolbar in the middle keeping the same width,
# so resizing in the GridLayout's engine leads to not enough space
# left for the panel on the right.
# This ensures same size while shrinking at least:
self.horizontalLayout.setColumnMinimumWidth(
0, self.selectedImageViewer.size().width())
self.horizontalLayout.setColumnMinimumWidth(
2, self.selectedImageViewer.size().width())
# This works when expanding but it's ugly:
if self.selectedImageViewer.size().width() > self.referenceImageViewer.size().width():
# print(f"""Before selected size: {self.selectedImageViewer.size()}\n""",
# f"""Before reference size: {self.referenceImageViewer.size()}""")
self.selectedImageViewer.resize(self.referenceImageViewer.size())
# print(f"""After selected size: {self.selectedImageViewer.size()}\n""",
# f"""After reference size: {self.referenceImageViewer.size()}""")

self.ensure_same_sizes()
if self.vController is None or not self.vController.bestFit:
return
# Only update the scaled down pixmaps
Expand All @@ -122,8 +106,28 @@ def show(self):
# Windows seems to add a few pixels more to the table somehow
+ 5 if ISWINDOWS else 0)
DetailsDialogBase.show(self)
self.ensure_same_sizes()
self._update()

def ensure_same_sizes(self):
# HACK referenceViewer might be 1 pixel shorter in width
# due to the toolbar in the middle keeping the same width,
# so resizing in the GridLayout's engine leads to not enough space
# left for the panel on the right.
# This ensures same size while shrinking at least:
self.horizontalLayout.setColumnMinimumWidth(
0, self.selectedImageViewer.size().width())
self.horizontalLayout.setColumnMinimumWidth(
2, self.selectedImageViewer.size().width())

# This works when expanding but it's ugly:
if self.selectedImageViewer.size().width() > self.referenceImageViewer.size().width():
# print(f"""Before selected size: {self.selectedImageViewer.size()}\n""",
# f"""Before reference size: {self.referenceImageViewer.size()}""")
self.selectedImageViewer.resize(self.referenceImageViewer.size())
# print(f"""After selected size: {self.selectedImageViewer.size()}\n""",
# f"""After reference size: {self.referenceImageViewer.size()}""")

# model --> view
def refresh(self):
DetailsDialogBase.refresh(self)
Expand Down
19 changes: 13 additions & 6 deletions qt/pe/image_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
QToolBar, QToolButton, QAction, QWidget, QScrollArea,
QApplication, QAbstractScrollArea, QStyle)
from hscommon.trans import trget
from hscommon.plat import ISLINUX
tr = trget("ui")

MAX_SCALE = 12.0
Expand All @@ -21,7 +22,7 @@ def createActions(actions, target):
for name, shortcut, icon, desc, func in actions:
action = QAction(target)
if icon:
action.setIcon(QIcon.fromTheme(icon))
action.setIcon(icon)
if shortcut:
action.setShortcut(shortcut)
action.setText(desc)
Expand All @@ -48,28 +49,32 @@ def setupActions(self, controller):
(
"actionZoomIn",
QKeySequence.ZoomIn,
"zoom-in",
QIcon.fromTheme("zoom-in") if ISLINUX
else QIcon(QPixmap(":/" + "zoom_in")),
tr("Increase zoom"),
controller.zoomIn,
),
(
"actionZoomOut",
QKeySequence.ZoomOut,
"zoom-out",
QIcon.fromTheme("zoom-out") if ISLINUX
else QIcon(QPixmap(":/" + "zoom_out")),
tr("Decrease zoom"),
controller.zoomOut,
),
(
"actionNormalSize",
tr("Ctrl+/"),
"zoom-original",
QIcon.fromTheme("zoom-original") if ISLINUX
else QIcon(QPixmap(":/" + "zoom_original")),
tr("Normal size"),
controller.zoomNormalSize,
),
(
"actionBestFit",
tr("Ctrl+*"),
"zoom-best-fit",
QIcon.fromTheme("zoom-best-fit") if ISLINUX
else QIcon(QPixmap(":/" + "zoom_best_fit")),
tr("Best fit"),
controller.zoomBestFit,
)
Expand All @@ -83,7 +88,9 @@ def createButtons(self):
self.buttonImgSwap.setToolButtonStyle(Qt.ToolButtonIconOnly)
self.buttonImgSwap.setIcon(
QIcon.fromTheme('view-refresh',
self.style().standardIcon(QStyle.SP_BrowserReload)))
self.style().standardIcon(QStyle.SP_BrowserReload))
if ISLINUX
else QIcon(QPixmap(":/" + "exchange")))
self.buttonImgSwap.setText('Swap images')
self.buttonImgSwap.setToolTip('Swap images')
self.buttonImgSwap.pressed.connect(self.controller.swapImages)
Expand Down

0 comments on commit 58c675d

Please sign in to comment.