-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
247 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
# This file is part of BeeRef. | ||
# | ||
# BeeRef is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# BeeRef is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with BeeRef. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import logging | ||
import os.path | ||
|
||
from PyQt6 import QtCore, QtGui, QtWidgets | ||
from PyQt6.QtCore import Qt | ||
|
||
from beeref.config import BeeSettings | ||
from beeref.main_controls import MainControlsMixin | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RecentFilesModel(QtCore.QAbstractListModel): | ||
"""An entry in the 'Recent Files' list.""" | ||
|
||
def __init__(self, files): | ||
super().__init__() | ||
self.files = files | ||
|
||
def rowCount(self, parent): | ||
return len(self.files) | ||
|
||
def data(self, index, role): | ||
if role == QtCore.Qt.ItemDataRole.DisplayRole: | ||
return os.path.basename(self.files[index.row()]) | ||
if role == QtCore.Qt.ItemDataRole.FontRole: | ||
font = QtGui.QFont() | ||
font.setUnderline(True) | ||
return font | ||
|
||
|
||
class RecentFilesView(QtWidgets.QListView): | ||
|
||
def __init__(self, parent, files=None): | ||
super().__init__(parent) | ||
self.files = files or [] | ||
self.clicked.connect(self.on_clicked) | ||
self.setModel(RecentFilesModel(self.files)) | ||
self.setMouseTracking(True) | ||
|
||
def on_clicked(self, index): | ||
self.parent().parent().open_from_file(self.files[index.row()]) | ||
|
||
def update_files(self, files): | ||
self.files = files | ||
self.model().files = files | ||
self.reset() | ||
|
||
def sizeHint(self): | ||
size = QtCore.QSize() | ||
height = sum( | ||
(self.sizeHintForRow(i) + 2) for i in range(len(self.files))) | ||
width = max(self.sizeHintForColumn(i) for i in range(len(self.files))) | ||
size.setHeight(height) | ||
size.setWidth(width + 2) | ||
return size | ||
|
||
def mouseMoveEvent(self, event): | ||
index = self.indexAt( | ||
QtCore.QPoint(int(event.position().x()), | ||
int(event.position().y()))) | ||
if index.isValid(): | ||
self.setCursor(Qt.CursorShape.PointingHandCursor) | ||
else: | ||
self.setCursor(Qt.CursorShape.ArrowCursor) | ||
|
||
super().mouseMoveEvent(event) | ||
|
||
|
||
class WelcomeOverlay(MainControlsMixin, QtWidgets.QWidget): | ||
"""Some basic info to be displayed when the scene is empty.""" | ||
|
||
txt = """<p>Paste or drop images here.</p> | ||
<p>Right-click for more options.</p>""" | ||
|
||
def __init__(self, parent): | ||
super().__init__(parent) | ||
self.control_target = parent | ||
self.setAttribute(Qt.WidgetAttribute.WA_NoSystemBackground) | ||
self.init_main_controls(main_window=parent.parent) | ||
|
||
# Recent files | ||
self.files_layout = QtWidgets.QVBoxLayout() | ||
self.files_layout.addStretch(50) | ||
self.files_layout.addWidget( | ||
QtWidgets.QLabel('<h3>Recent Files</h3>', self)) | ||
self.files_view = RecentFilesView(self) | ||
self.files_layout.addWidget(self.files_view) | ||
self.files_layout.addStretch(50) | ||
|
||
# Help text | ||
self.label = QtWidgets.QLabel(self.txt, self) | ||
self.label.setAlignment(Qt.AlignmentFlag.AlignVCenter | ||
| Qt.AlignmentFlag.AlignCenter) | ||
self.layout = QtWidgets.QHBoxLayout() | ||
self.layout.addStretch(50) | ||
self.layout.addWidget(self.label) | ||
self.layout.addStretch(50) | ||
self.setLayout(self.layout) | ||
|
||
def show(self): | ||
files = BeeSettings().get_recent_files(existing_only=True) | ||
self.files_view.update_files(files) | ||
if files and self.layout.indexOf(self.files_layout) < 0: | ||
self.layout.insertLayout(0, self.files_layout) | ||
super().show() | ||
|
||
def disable_mouse_events(self): | ||
self.files_view.setAttribute( | ||
Qt.WidgetAttribute.WA_TransparentForMouseEvents) | ||
self.label.setAttribute( | ||
Qt.WidgetAttribute.WA_TransparentForMouseEvents) | ||
|
||
def enable_mouse_events(self): | ||
self.files_view.setAttribute( | ||
Qt.WidgetAttribute.WA_TransparentForMouseEvents, | ||
on=False) | ||
self.label.setAttribute( | ||
Qt.WidgetAttribute.WA_TransparentForMouseEvents, | ||
on=False) | ||
|
||
def mousePressEvent(self, event): | ||
if self.mousePressEventMainControls(event): | ||
return | ||
super().mousePressEvent(event) | ||
|
||
def mouseMoveEvent(self, event): | ||
if self.mouseMoveEventMainControls(event): | ||
return | ||
super().mouseMoveEvent(event) | ||
|
||
def mouseReleaseEvent(self, event): | ||
if self.mouseReleaseEventMainControls(event): | ||
return | ||
super().mouseReleaseEvent(event) | ||
|
||
def keyPressEvent(self, event): | ||
if self.keyPressEventMainControls(event): | ||
return | ||
super().keyPressEvent(event) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.