Commit c3228c2c by Yuhaibo

Merge remote-tracking branch 'origin/Liuqingjun'

parents 46f8dd34 63a0675e
......@@ -211,6 +211,22 @@ class DrawableLabel(QtWidgets.QLabel):
if rect_index >= 0:
# 创建右键菜单
menu = QtWidgets.QMenu(self)
menu.setStyleSheet("""
QMenu {
background-color: #ffffff;
color: #000000;
border: 1px solid #dcdcdc;
padding: 4px;
}
QMenu::item {
background-color: transparent;
color: #000000;
padding: 6px 12px;
}
QMenu::item:selected {
background-color: #f0f0f0;
}
""")
# 添加删除动作
delete_action = menu.addAction(f"删除区域 {rect_index + 1}")
......@@ -1152,6 +1168,31 @@ class VideoPreviewWithControls(QtWidgets.QWidget):
)
class VideoGridItemDelegate(QtWidgets.QStyledItemDelegate):
"""
自定义委托,确保列表项在被选中时也能保持自身的前景颜色。
"""
def paint(self, painter, option, index):
opt = QtWidgets.QStyleOptionViewItem(option)
foreground = index.data(Qt.ForegroundRole)
if foreground:
brush = foreground
if isinstance(foreground, QtGui.QColor):
brush = QtGui.QBrush(foreground)
for group in (
QtGui.QPalette.Active,
QtGui.QPalette.Inactive,
QtGui.QPalette.Disabled,
):
opt.palette.setBrush(group, QtGui.QPalette.Text, brush)
opt.palette.setBrush(group, QtGui.QPalette.HighlightedText, brush)
super(VideoGridItemDelegate, self).paint(painter, opt, index)
class DataPreprocessHandler(QtCore.QObject):
"""
数据预处理处理器
......@@ -1269,6 +1310,12 @@ class DataPreprocessHandler(QtCore.QObject):
# 替换普通Label为可绘制Label
self._replaceVideoPreviewWithDrawable()
# 让视频网格在选中时保持自定义颜色
if hasattr(self._panel, 'video_grid'):
self._panel.video_grid.setItemDelegate(
VideoGridItemDelegate(self._panel.video_grid)
)
# 初始化裁剪预览处理器
self._initCropPreviewHandler()
......@@ -1455,7 +1502,6 @@ class DataPreprocessHandler(QtCore.QObject):
QListWidget::item:selected {
background-color: #e3f2fd;
border: 2px solid #0078d7;
color: #000;
}
QListWidget::item:hover {
background-color: #f5f5f5;
......
......@@ -468,7 +468,6 @@ class CropPreviewPanel(QtWidgets.QWidget):
# 添加等待提示
placeholder_item = QtWidgets.QListWidgetItem(grid)
placeholder_item.setText("\n\n等待新的裁剪任务...\n\n监控已准备就绪")
placeholder_item.setTextAlignment(Qt.AlignCenter)
placeholder_item.setFlags(Qt.NoItemFlags) # 不可选择
......
......@@ -219,11 +219,13 @@ class DataPreprocessPanel(QtWidgets.QWidget):
self.btn_add_folder = QtWidgets.QPushButton("新增文件夹")
if TextButtonStyleManager:
TextButtonStyleManager.applyToButton(self.btn_add_folder, "新增文件夹")
self.btn_add_folder.setVisible(False)
button_layout.addWidget(self.btn_add_folder)
self.btn_delete_folder = QtWidgets.QPushButton("删除文件夹")
if TextButtonStyleManager:
TextButtonStyleManager.applyToButton(self.btn_delete_folder, "删除文件夹")
self.btn_delete_folder.setVisible(False)
button_layout.addWidget(self.btn_delete_folder)
layout.addLayout(button_layout)
......@@ -297,7 +299,6 @@ class DataPreprocessPanel(QtWidgets.QWidget):
QListWidget::item:selected {
background-color: #e3f2fd;
border: 2px solid #0078d7;
color: #000;
}
QListWidget::item:hover {
background-color: #f5f5f5;
......@@ -569,6 +570,12 @@ class DataPreprocessPanel(QtWidgets.QWidget):
return panel
def _getDefaultCropFolder(self):
"""获取裁剪结果默认保存路径"""
default_path = osp.join(get_project_root(), 'database', 'Corp_picture')
os.makedirs(default_path, exist_ok=True)
return default_path
def _loadCropConfig(self):
"""加载裁剪配置"""
try:
......@@ -577,10 +584,7 @@ class DataPreprocessPanel(QtWidgets.QWidget):
if saved_path:
self.crop_path_edit.setText(saved_path)
else:
# 设置默认保存路径
default_path = osp.join(get_project_root(), 'database', 'Corp_picture')
os.makedirs(default_path, exist_ok=True)
self.crop_path_edit.setText(default_path)
self.crop_path_edit.setText(self._getDefaultCropFolder())
saved_freq = settings.value("frequency", 1)
try:
......@@ -864,19 +868,8 @@ class DataPreprocessPanel(QtWidgets.QWidget):
self.folderSelected.emit(folder_path)
def _onFolderDoubleClicked(self, item):
"""文件夹被双击"""
folder_name = item.data(Qt.UserRole)
folder_path = osp.join(self._root_path, folder_name)
# 在系统文件管理器中打开
try:
if os.name == 'nt': # Windows
os.startfile(folder_path)
elif os.name == 'posix': # macOS, Linux
import subprocess
subprocess.Popen(['open', folder_path])
except Exception as e:
pass
"""需求调整:双击目录不执行任何操作"""
return
def _onAddFolder(self):
"""新增文件夹"""
......@@ -1031,15 +1024,8 @@ class DataPreprocessPanel(QtWidgets.QWidget):
menu = QtWidgets.QMenu(self)
if item:
# 在文件夹上右键:显示删除选项
action_delete = menu.addAction("删除当前文件夹")
# 显示菜单并获取选择的动作
action = menu.exec_(self.folder_list.mapToGlobal(position))
# 处理选择的动作
if action == action_delete:
self._onDeleteFolder()
# 需求调整:不再提供右键删除入口,直接返回
return
else:
# 在空白处右键:显示新建和刷新选项
action_new_folder = menu.addAction("新建文件夹")
......@@ -1498,13 +1484,7 @@ class DataPreprocessPanel(QtWidgets.QWidget):
# 获取当前路径
current_path = self.crop_path_edit.text().strip()
if not current_path or not osp.exists(current_path):
# 使用默认路径
try:
from database.config import get_project_root
project_root = get_project_root()
current_path = osp.join(project_root, 'database', 'Corp_picture')
except:
current_path = osp.expanduser("~")
current_path = self._getDefaultCropFolder()
# 打开文件夹选择对话框
folder_path = QtWidgets.QFileDialog.getExistingDirectory(
......@@ -1520,28 +1500,8 @@ class DataPreprocessPanel(QtWidgets.QWidget):
def _onOpenCropFolder(self):
"""打开裁剪图片保存文件夹"""
# 获取保存路径
save_path = self.crop_path_edit.text().strip()
if not save_path:
# 如果没有设置路径,使用默认路径
try:
from database.config import get_project_root
save_path = osp.join(get_project_root(), 'database', 'Corp_picture')
except:
save_path = osp.join(osp.expanduser("~"), 'Corp_picture')
# 确保路径存在
if not osp.exists(save_path):
try:
os.makedirs(save_path, exist_ok=True)
print(f"[DataPreprocess] 创建文件夹: {save_path}")
except Exception as e:
QtWidgets.QMessageBox.warning(
self, "警告",
f"无法创建文件夹:\n{save_path}\n\n错误:{str(e)}"
)
return
# 无论当前设置为何,均打开默认的裁剪结果根目录
save_path = self._getDefaultCropFolder()
# 打开文件夹
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment