Browse Source

【BOTA】缩图悬浮效果完善

lizhe 1 year ago
parent
commit
04967c6010

+ 16 - 0
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -1755,6 +1755,9 @@
 		ADE8BC2A29F7CDB000570F89 /* KMPageNumberDisplayView.xib in Resources */ = {isa = PBXBuildFile; fileRef = ADE8BC2929F7CDB000570F89 /* KMPageNumberDisplayView.xib */; };
 		ADE8BC2B29F7CDB000570F89 /* KMPageNumberDisplayView.xib in Resources */ = {isa = PBXBuildFile; fileRef = ADE8BC2929F7CDB000570F89 /* KMPageNumberDisplayView.xib */; };
 		ADE8BC2C29F7CDB000570F89 /* KMPageNumberDisplayView.xib in Resources */ = {isa = PBXBuildFile; fileRef = ADE8BC2929F7CDB000570F89 /* KMPageNumberDisplayView.xib */; };
+		ADE8BC2F29F8CD7200570F89 /* KMPDFThumbnailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADE8BC2E29F8CD7200570F89 /* KMPDFThumbnailModel.swift */; };
+		ADE8BC3029F8CD7200570F89 /* KMPDFThumbnailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADE8BC2E29F8CD7200570F89 /* KMPDFThumbnailModel.swift */; };
+		ADE8BC3129F8CD7200570F89 /* KMPDFThumbnailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADE8BC2E29F8CD7200570F89 /* KMPDFThumbnailModel.swift */; };
 		ADEC7A7E299397F8009A8256 /* NSFont+SFProText.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADEC7A7B299397F8009A8256 /* NSFont+SFProText.swift */; };
 		ADEC7A7F299397F8009A8256 /* NSFont+SFProText.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADEC7A7B299397F8009A8256 /* NSFont+SFProText.swift */; };
 		ADEC7A80299397F8009A8256 /* NSFont+SFProText.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADEC7A7B299397F8009A8256 /* NSFont+SFProText.swift */; };
@@ -3907,6 +3910,7 @@
 		ADE614BE298620C000F62ED7 /* ImageToPDF.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = ImageToPDF.xcassets; sourceTree = "<group>"; };
 		ADE8BC2429F7CCA600570F89 /* KMPageNumberDisplayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPageNumberDisplayView.swift; sourceTree = "<group>"; };
 		ADE8BC2929F7CDB000570F89 /* KMPageNumberDisplayView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMPageNumberDisplayView.xib; sourceTree = "<group>"; };
+		ADE8BC2E29F8CD7200570F89 /* KMPDFThumbnailModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KMPDFThumbnailModel.swift; sourceTree = "<group>"; };
 		ADEC7A7B299397F8009A8256 /* NSFont+SFProText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSFont+SFProText.swift"; sourceTree = "<group>"; };
 		ADEC7A7C299397F8009A8256 /* SF-Pro-Text-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SF-Pro-Text-Regular.otf"; sourceTree = "<group>"; };
 		ADEC7A7D299397F8009A8256 /* SF-Pro-Text-Semibold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SF-Pro-Text-Semibold.otf"; sourceTree = "<group>"; };
@@ -4849,6 +4853,7 @@
 		899700EF28F40308009AF911 /* Thumbnail */ = {
 			isa = PBXGroup;
 			children = (
+				ADE8BC2D29F8CD7200570F89 /* model */,
 				89D2D2E1294C452B00BFF5FE /* KMPDFThumbnailView.swift */,
 				89D2D2F9294C806000BFF5FE /* KMPDFThumbnailItem.swift */,
 				89D2D2FA294C806000BFF5FE /* KMPDFThumbnailItem.xib */,
@@ -6799,6 +6804,14 @@
 			path = KMPageNumberDisplayView;
 			sourceTree = "<group>";
 		};
+		ADE8BC2D29F8CD7200570F89 /* model */ = {
+			isa = PBXGroup;
+			children = (
+				ADE8BC2E29F8CD7200570F89 /* KMPDFThumbnailModel.swift */,
+			);
+			path = model;
+			sourceTree = "<group>";
+		};
 		ADEC7A7A299397F8009A8256 /* Fonts */ = {
 			isa = PBXGroup;
 			children = (
@@ -10414,6 +10427,7 @@
 				F37322FF292DF9410013862C /* CPDFAnnotation+PDFListView.m in Sources */,
 				ADB1FEAE297543C000ED072D /* KMBatchSettingView.swift in Sources */,
 				BB897218294AED6C0045787C /* KMWatermarkAdjectivePreViewBaseController.swift in Sources */,
+				ADE8BC2F29F8CD7200570F89 /* KMPDFThumbnailModel.swift in Sources */,
 				BB4EEF4029764FCC003A3537 /* KMWatermarkColorView.swift in Sources */,
 				AD4B4548293ED7DA0076FA14 /* KMImageToPDFManager.swift in Sources */,
 				BB146FC9299DC0D100784A6A /* GTMSessionFetcher.m in Sources */,
@@ -11173,6 +11187,7 @@
 				9F8DDF2729237910006CDC73 /* Array+KMExtensions.swift in Sources */,
 				ADB1FEAF297543C000ED072D /* KMBatchSettingView.swift in Sources */,
 				8942F7EA2925E1C400389627 /* KMLiftSideCellView.swift in Sources */,
+				ADE8BC3029F8CD7200570F89 /* KMPDFThumbnailModel.swift in Sources */,
 				BB4EEF4129764FCC003A3537 /* KMWatermarkColorView.swift in Sources */,
 				AD4B455729408CB00076FA14 /* KMOCRChooseView.swift in Sources */,
 				BB146FCA299DC0D100784A6A /* GTMSessionFetcher.m in Sources */,
@@ -11339,6 +11354,7 @@
 				BB897230294B08DE0045787C /* KMWatermarkViewController.swift in Sources */,
 				BB8B17342907B63D001C5EA5 /* CipherTextView.swift in Sources */,
 				ADBC375229CAE27900D93208 /* KMComparativeOutlineRowView.swift in Sources */,
+				ADE8BC3129F8CD7200570F89 /* KMPDFThumbnailModel.swift in Sources */,
 				BB89DD802953F863007C3FFA /* KMWatermarkFileOutsideView.swift in Sources */,
 				BB6B4C0A292F53CE0071CA06 /* KMMergeFileModel.swift in Sources */,
 				9F0CB4B72977BC1000007028 /* KMPropertiesPanelPreviewSubVC.swift in Sources */,

+ 2 - 3
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/KMNoteOutlineFilterViewController.xib

@@ -1,8 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
-        <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>

+ 50 - 62
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMPDFThumbnailItem.swift

@@ -12,6 +12,7 @@ let textBoxSpace = 2
 let textLabelHeight = 15
 
 typealias KMPDFThumbnailItemMouseDown = (_ view: KMPDFThumbnailItem, _ event: NSEvent) -> Void
+typealias KMPDFThumbnailItemHover = (_ view: KMPDFThumbnailItem, _ mouseEntered: Bool) -> Void
 typealias KMPDFThumbnailItemRightMouseDown = (_ view: KMPDFThumbnailItem, _ event: NSEvent) -> Void
 
 class KMPDFThumbnailItem: NSCollectionViewItem {
@@ -55,12 +56,18 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
     
     lazy var pageView = KMPDFThumbnialPageView()
     
-    var page : CPDFPage = CPDFPage()
+    var page : CPDFPage = CPDFPage() {
+        didSet {
+            self.pageView.page = page
+            self.updatePageState(page: page)
+        }
+    }
     
     var thumbnailView : KMPDFThumbnailView = KMPDFThumbnailView()
     
     var mouseDownAction: KMPDFThumbnailItemMouseDown?
     var rightMouseDownAction: KMPDFThumbnailItemRightMouseDown?
+    var hoverCallBack: KMPDFThumbnailItemHover?
     
     var contentBox: KMBox?
     
@@ -79,6 +86,12 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
         }
     }
     
+    var hover: Bool = false {
+        didSet {
+            self.updateItemState()
+        }
+    }
+    
     override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
         super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
     }
@@ -114,30 +127,32 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
         }
         set {
             super.isSelected = newValue
-            if (newValue) {
-                self.view.layer?.backgroundColor = NSColor(hex: "#CED0D4", alpha: 0.6).cgColor
-                self.view.layer?.borderColor = NSColor(hex: "#CED0D4").cgColor
-            } else {
-                self.view.layer?.backgroundColor = NSColor.clear.cgColor
-                self.view.layer?.borderColor = NSColor.clear.cgColor
-            }
+//            if (newValue) {
+//                self.view.layer?.backgroundColor = NSColor(hex: "#CED0D4", alpha: 0.6).cgColor
+//                self.view.layer?.borderColor = NSColor(hex: "#CED0D4").cgColor
+//            } else {
+//                self.view.layer?.backgroundColor = NSColor.clear.cgColor
+//                self.view.layer?.borderColor = NSColor.clear.cgColor
+//            }
+            self.updateItemState()
         }
     }
     
-    func setPage(page:CPDFPage!) {
-        self.page = page
-        self.pageView.page = page
-        let index = page.document.index(for: page) + 1
-        self.pageTextLabel.stringValue = "\(index)"
-        
-        let bounds = self.page.bounds
-        if page.rotation == 90 || page.rotation == 270 {
-            self.pageSizeTextLabel.stringValue = "\(Int(bounds.size.height))*\(Int(bounds.size.width)) mm"
-        } else {
-            self.pageSizeTextLabel.stringValue = "\(Int(bounds.size.width))*\(Int(bounds.size.height)) mm"
+    func updatePageState(page: CPDFPage!) {
+        if page != nil {
+            let index = page.document.index(for: page) + 1
+            self.pageTextLabel.stringValue = "\(index)"
+            
+            let bounds = self.page.bounds
+            if page.rotation == 90 || page.rotation == 270 {
+                self.pageSizeTextLabel.stringValue = "\(Int(bounds.size.height))*\(Int(bounds.size.width)) mm"
+            } else {
+                self.pageSizeTextLabel.stringValue = "\(Int(bounds.size.width))*\(Int(bounds.size.height)) mm"
+            }
+            
+            self.updateFrame()
+            self.updateItemState()
         }
-        
-        self.updateFrame()
     }
     
     class func sizeToFit(size:NSSize,page:CPDFPage,isShow:Bool) -> CGFloat {
@@ -227,14 +242,23 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
         self.pageView.frame = NSMakeRect(pageX, pageY, size.width, size.height)
     }
     
+    func updateItemState() {
+        if isSelected {
+            self.view.layer?.backgroundColor = NSColor(hex: "#CED0D4", alpha: 0.6).cgColor
+            self.view.layer?.borderColor = NSColor(hex: "#CED0D4").cgColor
+        } else if hover {
+            self.view.layer?.backgroundColor = NSColor(hex: "#EDEEF0").cgColor
+            self.view.layer?.borderColor = NSColor.clear.cgColor
+        } else {
+            self.view.layer?.backgroundColor = NSColor.clear.cgColor
+            self.view.layer?.borderColor = NSColor.clear.cgColor
+        }
+    }
     
     
     func addContentBox() {
         if self.contentBox == nil {
-            var rect = self.view.bounds
-//            rect.origin.x = self.bounds.origin.x + 8.0
-//            rect.size.width = self.bounds.size.width - 16.0
-            
+            let rect = self.view.bounds
             self.contentBox?.wantsLayer = true
             self.contentBox?.layer?.masksToBounds = true
             self.contentBox = KMBox(frame: rect)
@@ -245,21 +269,7 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
             self.view.addSubview(self.contentBox!, positioned: NSWindow.OrderingMode.below, relativeTo: self.view)
             self.contentBox?.autoresizingMask = [.width, .height]
             self.contentBox?.moveCallback = { [unowned self] (mouseEntered, mouseBox) in
-                if mouseEntered {
-                    if self.isSelected {
-
-                    } else {
-                        self.view.layer?.backgroundColor = NSColor(hex: "#EDEEF0").cgColor
-                        self.view.layer?.borderColor = NSColor.clear.cgColor
-                    }
-                } else {
-                    if self.isSelected {
-                        
-                    } else {
-                        self.view.layer?.backgroundColor = NSColor.clear.cgColor
-                        self.view.layer?.borderColor = NSColor.clear.cgColor
-                    }
-                }
+                self.hoverCallBack?(self, mouseEntered)
             }
             
             self.contentBox?.rightDownCallback = { [unowned self] (downEntered, mouseBox, event) in
@@ -268,30 +278,8 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
         }
     }
     
-//    override func mouseExited(with event: NSEvent) {
-//        super.mouseExited(with: event)
-//        if self.isSelected {
-//
-//        } else {
-//            self.view.layer?.backgroundColor = NSColor.clear.cgColor
-//            self.view.layer?.borderColor = NSColor.clear.cgColor
-//        }
-//    }
-    
-//    override func mouseEntered(with event: NSEvent) {
-//        super.mouseEntered(with: event)
-//        print("mouseEntered")
-//        if self.isSelected {
-//
-//        } else {
-//            self.view.layer?.backgroundColor = NSColor(hex: "#EDEEF0").cgColor
-//            self.view.layer?.borderColor = NSColor.clear.cgColor
-//        }
-//    }
-    
     override func mouseMoved(with event: NSEvent) {
         super.mouseMoved(with: event)
-        
     }
     
     override func mouseDown(with event: NSEvent) {

+ 25 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMPDFThumbnailView.swift

@@ -50,6 +50,8 @@ class KMPDFThumbnailView: NSView {
             self.collectionView.reloadData()
         }
     }
+    //悬浮
+    var hoverIndex: Int = -1
     
     override func draw(_ dirtyRect: NSRect) {
         super.draw(dirtyRect)
@@ -169,7 +171,12 @@ extension KMPDFThumbnailView : NSCollectionViewDataSource {
         cellView.thumbnailView = self
         cellView.page = self.document.page(at: UInt(indexPath.item))
         cellView.annotationShowState = self.annotationShowState
-        cellView.setPage(page: self.document.page(at: UInt(indexPath.item)))
+        if indexPath.item == hoverIndex {
+            cellView.hover = true
+        } else {
+            cellView.hover = false
+        }
+        
         cellView.mouseDownAction = { [unowned self] (view, event) in
             self.delegate?.thumbnailView?(thumbanView: self, didSelectPageAtIndex: UInt(indexPath.item), event: event)
         }
@@ -178,9 +185,25 @@ extension KMPDFThumbnailView : NSCollectionViewDataSource {
             self.delegate?.thumbnailView?(thumbanView: self, item: view, rightMouseDidSelect: UInt(indexPath.item), event: event)
         }
         
+        cellView.hoverCallBack = { [unowned self] view, mouseEntered in
+            if self.collectionView.item(at: hoverIndex)?.view != nil {
+                let tempCell = self.collectionView.item(at: hoverIndex) as? KMPDFThumbnailItem
+                tempCell!.hover = false
+            }
+            
+            if mouseEntered {
+                hoverIndex = indexPath.item
+                if self.collectionView.item(at: hoverIndex)?.view != nil {
+                    let tempCell = self.collectionView.item(at: hoverIndex) as? KMPDFThumbnailItem
+                    tempCell!.hover = true
+                }
+            } else {
+                hoverIndex = -1
+            }
+        }
+        
         return cellView
     }
-    
 }
 
 extension KMPDFThumbnailView: NSCollectionViewDelegateFlowLayout {

+ 14 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/model/KMPDFThumbnailModel.swift

@@ -0,0 +1,14 @@
+//
+//  KMPDFThumbnailModel.swift
+//  PDF Master
+//
+//  Created by lizhe on 2023/4/25.
+//
+
+import Cocoa
+
+class KMPDFThumbnailModel: NSObject {
+    var page: CPDFPage = CPDFPage()
+    var select: Bool = false
+    var hover: Bool = false
+}