瀏覽代碼

【综合】BOTA,缩略图列表,缩放,多次点击放大按钮,最后几次放大时效果不明显(已修复)

tangchao 1 年之前
父節點
當前提交
26ab9bec29

+ 4 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Snapshot.swift

@@ -7,6 +7,10 @@
 
 import Foundation
 
+extension KMLeftSideViewController.Key {
+    static let snapshotSizeScaling = "KMSnapshotSizeScalingKey"
+}
+
 // MARK: - Actions
 
 extension KMLeftSideViewController {

+ 8 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Thumbnail.swift

@@ -7,6 +7,10 @@
 
 import Foundation
 
+extension KMLeftSideViewController.Key {
+    static let thumbSizeScaling = "KMThumbnailSizeScalingKey"
+}
+
 // MARK: - Actions
 
 extension KMLeftSideViewController {
@@ -144,6 +148,10 @@ extension KMLeftSideViewController {
     }
 }
 
+// MARK: - Others
+
+extension KMLeftSideViewController {}
+
 // MARK: - KMThumbnailTableViewDelegate
 
 extension KMLeftSideViewController: KMThumbnailTableViewDelegate {

+ 20 - 24
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -36,6 +36,10 @@ class KMLeftSideViewController: KMSideViewController {
     let noteColumnId = NSUserInterfaceItemIdentifier(rawValue: "note")
     let authorColumnId = NSUserInterfaceItemIdentifier(rawValue: "author")
     
+    struct Key {}
+    
+    let scalingIncrement: Float = 0.1
+    
     deinit {
         KMPrint("KMLeftSideViewController deinit.")
         
@@ -787,40 +791,40 @@ class KMLeftSideViewController: KMSideViewController {
         
         let tag = sender.tag
         if (tag == 0 || tag == 1) {
-            var scaling = sud.float(forKey: "KMThumbnailSizeScalingKey")
+            var scaling = KMDataManager.ud_float(forKey: Self.Key.thumbSizeScaling)
             if (scaling <= 0) {
                 scaling = 1
             }
-            if (tag == 0) { // thumbnail Zoom In
-                scaling += 0.1
+            if (tag == 0) { // Zoom In
+                scaling += self.scalingIncrement
                 if scaling >= 2.2 {
                     return
                 }
-            } else if (tag == 1) { // thumbnail Zoom Out
-                scaling -= 0.1
+            } else if (tag == 1) { // Zoom Out
+                scaling -= self.scalingIncrement
                 if scaling <= 0.4 {
                     return
                 }
             }
-            sud.setValue(scaling, forKey: "KMThumbnailSizeScalingKey")
+            KMDataManager.ud_set(scaling, forKey: Self.Key.thumbSizeScaling)
 
             let selectRow = self.thumbnailTableView.selectedRow
             self.thumbnailTableView.reloadData()
             
             self.thumbnailTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
         } else if (tag == 2 || tag == 3) {
-            var scaling = sud.float(forKey: "KMSnapshotSizeScalingKey")
+            var scaling = KMDataManager.ud_float(forKey: Self.Key.snapshotSizeScaling)
             if (scaling <= 0) {
                 scaling = 1
             }
             
-            if (tag == 2) { // snapshot Zoom In
-                scaling += 0.1
-            } else if (tag == 3) { // snapshot Zoom Out
-                scaling -= 0.1
+            if (tag == 2) { // Zoom In
+                scaling += self.scalingIncrement
+            } else if (tag == 3) { // Zoom Out
+                scaling -= self.scalingIncrement
             }
             
-            sud.setValue(scaling, forKey: "KMSnapshotSizeScalingKey")
+            KMDataManager.ud_set(scaling, forKey: Self.Key.snapshotSizeScaling)
             
             let selectRow = self.snapshotTableView.selectedRow
             self.snapshotTableView.reloadData()
@@ -1285,7 +1289,7 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
     
     func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
         if tableView.isEqual(to: self.thumbnailTableView) {
-            let scaling = KMDataManager.ud_float(forKey: "KMThumbnailSizeScalingKey")
+            let scaling = KMDataManager.ud_float(forKey: Self.Key.thumbSizeScaling)
 //            let thumbnailSize = self.thumbnails[row].size
             let thumbnailSize = NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize)
             
@@ -1307,24 +1311,16 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
             } else {
                 labelHeight = 41.5
             }
-            let  cellHeight = thumbnailSize.height + labelHeight
+            let cellHeight = thumbnailSize.height + labelHeight
             var thumbSize: NSSize = .zero
-            if (scaling != nil && scaling > 0) {
+            if (scaling > 0) {
                 thumbSize = NSMakeSize(thumbnailSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
             } else {
                 thumbSize = NSMakeSize(thumbnailSize.width, cellHeight)
             }
             return thumbSize.height
-            
-    //        NSSize cellSize = NSMakeSize([[tv tableColumnWithIdentifier:IMAGE_COLUMNID] width], fmin(thumbSize.height, roundedThumbnailSize));
-    //        if (thumbSize.height < [tv rowHeight])
-    //            return [tv rowHeight];
-    //        else if (thumbSize.width / thumbSize.height < cellSize.width / cellSize.height)
-    //            return cellSize.height;
-    //        else
-    //            return fmax([tv rowHeight], fmin(cellSize.width, thumbSize.width) * thumbSize.height / thumbSize.width);
         } else if tableView.isEqual(to: self.snapshotTableView) {
-            let scaling = UserDefaults.standard.float(forKey: "KMSnapshotSizeScalingKey")
+            let scaling = KMDataManager.ud_float(forKey: Self.Key.snapshotSizeScaling)
             let snapshotSize = (self.snapshots.safe_element(for: row) as? KMSnapshotModel)?.windowC?.thumbnail?.size ?? CGSizeMake(120, 63)
             var newScaling = scaling + 0.1
             let newSnapshotHeight = snapshotSize.width * newScaling.cgFloat;

+ 2 - 17
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMThumbnailTableviewCell.swift

@@ -63,29 +63,13 @@ class KMThumbnailTableviewCell: NSTableCellView {
         let width = NSWidth(self.bounds)
         let height = NSHeight(self.bounds)
         
-//        iconImageView.frame = view.bounds
-//        backgroundView.frame = view.bounds
-        
         let flodSize: CGFloat = 28
-//        expandButton.frame = NSMakeRect(width-flodSize-10, height-flodSize-10, flodSize, flodSize)
-        
-//        pageRangeButton.frame = NSMakeRect(15, 10+20+10, width-30, 28)
-        
-//        selectedView.frame = NSMakeRect(15, 20, width-30, height-20)
-        
-//        nameLabel.frame = NSMakeRect(0, 0, width, 20)
-        
         let border: CGFloat = 10
         var bounds: NSRect = NSZeroRect
-//        if (myModel != nil) {
-//            bounds = myModel.page.bounds
-//        }
         bounds = self.pageView.page?.bounds ?? .zero
-        
         if (bounds.size.width == 0) {
             return
         }
-        
         if (bounds.size.height == 0) {
             return
         }
@@ -93,7 +77,8 @@ class KMThumbnailTableviewCell: NSTableCellView {
         var pageSelectionSize = CGSize(width: self.frame.size.width-30, height: self.frame.size.height-40)
 //        pageSelectionSize.height -= 40
         var size = NSMakeSize(pageSelectionSize.width - 2 * border, pageSelectionSize.height - 2 * border)
-        let minScale = min(size.width/bounds.size.width, size.height/bounds.size.height)
+//        let minScale = min(size.width/bounds.size.width, size.height/bounds.size.height)
+        let minScale = size.height/bounds.size.height
         size.width = bounds.size.width * minScale
         size.height = bounds.size.height * minScale