Переглянути джерело

【偏好设置】批注模块,线条类型设置项处理

tangchao 1 рік тому
батько
коміт
0bb8fb2d69

+ 11 - 0
PDF Office/PDF Master/Class/Preference/Controller/KMNotesPreferences.swift

@@ -324,6 +324,9 @@ class KMNotesPreferences: NSViewController {
         self.fontWell2.action = #selector(anchoredFontWellAction)
         self.alignmentSegmentControl.target = self
         self.alignmentSegmentControl.action = #selector(alignmentSegmentAction)
+        
+        self.circleLineWell.target = self
+        self.circleLineWell.action = #selector(circleLineWellAction)
     }
     
     @objc func textColorWellAction(_ sender: NSColorWell) {
@@ -396,6 +399,14 @@ class KMNotesPreferences: NSViewController {
             KMPreference.shared.markupFontTextAligment = .right
         }
     }
+    
+    // MARK: - LineWell
+    
+    @objc func circleLineWellAction(_ sender: KMLineWell) {
+        KMPreference.shared.circleNoteLineWidth = Float(sender.lineWidth)
+        KMPreference.shared.circleNoteLineStyle = sender.style.rawValue
+        KMPreference.shared.circleNoteDashPattern = sender.dashPattern as? [CGFloat] ?? []
+    }
 }
 
 extension KMNotesPreferences: KMPreferencePane {

+ 318 - 3
PDF Office/PDF Master/Class/Preference/Tools/KMPreferenceManager.swift

@@ -88,6 +88,26 @@ private let KMMarkupFontNoteStringKey: KMPreferenceKey = "KMMarkupFontNoteString
 private let KMMarkupTextFontSizeKey: KMPreferenceKey = "KMMarkupTextFontSizeKey"
 private let KMMarkupNoteFontSizeKey: KMPreferenceKey = "KMMarkupNoteFontSizeKey"
 
+private let KMFreeTextNoteLineWidthKey: KMPreferenceKey = "KMFreeTextNoteLineWidthKey"
+private let KMFreeTextNoteLineStyleKey: KMPreferenceKey = "KMFreeTextNoteLineStyleKey"
+private let KMFreeTextNoteDashPatternKey: KMPreferenceKey = "KMFreeTextNoteDashPatternKey"
+private let KMCircleNoteLineWidthKey: KMPreferenceKey = "KMCircleNoteLineWidthKey"
+private let KMCircleNoteLineStyleKey: KMPreferenceKey = "KMCircleNoteLineStyleKey"
+private let KMCircleNoteDashPatternKey: KMPreferenceKey = "KMCircleNoteDashPatternKey"
+
+private let KMSquareNoteLineWidthKey: KMPreferenceKey = "KMSquareNoteLineWidthKey"
+private let KMSquareNoteLineStyleKey: KMPreferenceKey = "KMSquareNoteLineStyleKey"
+private let KMSquareNoteDashPatternKey: KMPreferenceKey = "KMSquareNoteDashPatternKey"
+private let KMLineNoteLineWidthKey: KMPreferenceKey = "KMLineNoteLineWidthKey"
+private let KMLineNoteLineStyleKey: KMPreferenceKey = "KMLineNoteLineStyleKey"
+private let KMLineNoteDashPatternKey: KMPreferenceKey = "KMLineNoteDashPatternKey"
+private let KMLineNoteStartLineStyleKey: KMPreferenceKey = "KMLineNoteStartLineStyleKey"
+private let KMLineNoteEndLineStyleKey: KMPreferenceKey = "KMLineNoteEndLineStyleKey"
+
+private let KMInkNoteLineWidthKey: KMPreferenceKey = "KMInkNoteLineWidthKey"
+private let KMInkNoteLineStyleKey: KMPreferenceKey = "KMInkNoteLineStyleKey"
+private let KMInkNoteDashPatternKey: KMPreferenceKey = "KMInkNoteDashPatternKey"
+
 /// 偏好设置已改变
 private let KMPreferenceDidChangeNotificationName = "KMPreferenceDidChangeNotificationName"
 
@@ -176,6 +196,25 @@ typealias KMPreference = KMPreferenceManager
     public static let markupTextFontSizeKey                     = KMMarkupTextFontSizeKey
     public static let markupNoteFontSizeKey                     = KMMarkupNoteFontSizeKey
     
+    public static let freeTextNoteLineWidthKey                  = KMFreeTextNoteLineWidthKey
+    public static let freeTextNoteLineStyleKey                  = KMFreeTextNoteLineStyleKey
+    public static let freeTextNoteDashPatternKey                = KMFreeTextNoteDashPatternKey
+    public static let circleNoteLineWidthKey                    = KMCircleNoteLineWidthKey
+    public static let circleNoteLineStyleKey                    = KMCircleNoteLineStyleKey
+    public static let circleNoteDashPatternKey                  = KMCircleNoteDashPatternKey
+    
+    public static let squareNoteLineWidthKey                    = KMSquareNoteLineWidthKey
+    public static let squareNoteLineStyleKey                    = KMSquareNoteLineStyleKey
+    public static let squareNoteDashPatternKey                  = KMSquareNoteDashPatternKey
+    public static let lineNoteLineWidthKey                      = KMLineNoteLineWidthKey
+    public static let lineNoteLineStyleKey                      = KMLineNoteLineStyleKey
+    public static let lineNoteDashPatternKey                    = KMLineNoteDashPatternKey
+    public static let lineNoteStartLineStyleKey                 = KMLineNoteStartLineStyleKey
+    public static let lineNoteEndLineStyleKey                   = KMLineNoteEndLineStyleKey
+    public static let inkNoteLineWidthKey                       = KMInkNoteLineWidthKey
+    public static let inkNoteLineStyleKey                       = KMInkNoteLineStyleKey
+    public static let inkNoteDashPatternKey                     = KMInkNoteDashPatternKey
+    
     override init() {
         super.init()
         
@@ -353,7 +392,12 @@ typealias KMPreference = KMPreferenceManager
                     KMMarkupFontTextAligmentKey,
                     KMMarkupFontNoteStringKey,
                     // 新补充
-                    KMMarkupTextFontSizeKey, KMMarkupNoteFontSizeKey]
+                    KMMarkupTextFontSizeKey, KMMarkupNoteFontSizeKey,
+                    KMFreeTextNoteLineWidthKey, KMFreeTextNoteLineStyleKey, KMFreeTextNoteDashPatternKey,
+                    KMCircleNoteLineWidthKey, KMCircleNoteLineStyleKey, KMCircleNoteDashPatternKey,
+                    KMSquareNoteLineWidthKey, KMSquareNoteLineStyleKey, KMSquareNoteDashPatternKey,
+                    KMLineNoteLineWidthKey, KMLineNoteLineStyleKey, KMLineNoteDashPatternKey, KMLineNoteStartLineStyleKey, KMLineNoteEndLineStyleKey,
+                    KMInkNoteLineWidthKey, KMInkNoteLineStyleKey, KMInkNoteDashPatternKey]
         }
         return []
     }
@@ -417,11 +461,27 @@ typealias KMPreference = KMPreferenceManager
                                                      KMMarkupFontNoteStringKey : KMDefaultFontName,
                                                      // 新补充
                                                        KMMarkupTextFontSizeKey : self.textFontSizeDefaultValue(),
-                                                       KMMarkupNoteFontSizeKey : self.noteFontSizeDefaultValue()],
+                                                       KMMarkupNoteFontSizeKey : self.noteFontSizeDefaultValue(),
+                                                    KMFreeTextNoteLineWidthKey : self.freeTextNoteLineWidthDefaultValue(),
+                                                    KMFreeTextNoteLineStyleKey : self.freeTextNoteLineStyleDefaultValue(),
+                                                  KMFreeTextNoteDashPatternKey : self.freeTextNoteDashPatternDefaultValue(),
+                                                      KMCircleNoteLineWidthKey : self.circleNoteLineWidthDefaultValue(),
+                                                      KMCircleNoteLineStyleKey : self.circleNoteLineStyleDefaultValue(),
+                                                    KMCircleNoteDashPatternKey : self.circleNoteDashPatternDefaultValue(),
+                                                      KMSquareNoteLineWidthKey : self.squareNoteLineWidthDefaultValue(),
+                                                      KMSquareNoteLineStyleKey : self.squareNoteLineStyleDefaultValue(),
+                                                    KMSquareNoteDashPatternKey : self.squareNoteDashPatternDefaultValue(),
+                                                        KMLineNoteLineWidthKey : self.lineNoteLineWidthDefaultValue(),
+                                                        KMLineNoteLineStyleKey : self.lineNoteLineStyleDefaultValue(),
+                                                      KMLineNoteDashPatternKey : self.lineNoteDashPatternDefaultValue(),
+                                                   KMLineNoteStartLineStyleKey : self.lineNoteStartLineStyleDefaultValue(),
+                                                     KMLineNoteEndLineStyleKey : self.lineNoteEndLineStyleDefaultValue(),
+                                                         KMInkNoteLineWidthKey : self.inkNoteLineWidthDefaultValue(),
+                                                         KMInkNoteLineStyleKey : self.inkNoteLineStyleDefaultValue(),
+                                                       KMInkNoteDashPatternKey : self.inkNoteDashPatternDefaultValue()],
                 KMPreferenceGroup.infomation.rawValue : [:],
                 KMPreferenceGroup.other.rawValue : [:]]
     }
-    
 }
 
 // MARK: - 默认值
@@ -511,6 +571,74 @@ extension KMPreferenceManager {
     @inline (__always) func noteFontSizeDefaultValue() -> Float {
         return 12.0
     }
+    
+    @inline (__always) func freeTextNoteLineWidthDefaultValue() -> Float {
+        return 0.0
+    }
+    
+    @inline (__always) func freeTextNoteLineStyleDefaultValue() -> Int {
+        return 0
+    }
+    
+    @inline (__always) func freeTextNoteDashPatternDefaultValue() -> [CGFloat] {
+        return []
+    }
+    
+    @inline (__always) func circleNoteLineWidthDefaultValue() -> Float {
+        return 2.0
+    }
+    
+    @inline (__always) func circleNoteLineStyleDefaultValue() -> Int {
+        return 0
+    }
+    
+    @inline (__always) func circleNoteDashPatternDefaultValue() -> [CGFloat] {
+        return []
+    }
+    
+    @inline (__always) func squareNoteLineWidthDefaultValue() -> Float {
+        return 2.0
+    }
+    
+    @inline (__always) func squareNoteLineStyleDefaultValue() -> Int {
+        return 0
+    }
+    
+    @inline (__always) func squareNoteDashPatternDefaultValue() -> [CGFloat] {
+        return []
+    }
+    
+    @inline (__always) func lineNoteLineWidthDefaultValue() -> Float {
+        return 2.0
+    }
+    
+    @inline (__always) func lineNoteLineStyleDefaultValue() -> Int {
+        return 0
+    }
+    
+    @inline (__always) func lineNoteDashPatternDefaultValue() -> [CGFloat] {
+        return []
+    }
+    
+    @inline (__always) func lineNoteStartLineStyleDefaultValue() -> Int {
+        return 0
+    }
+    
+    @inline (__always) func lineNoteEndLineStyleDefaultValue() -> Int {
+        return 0
+    }
+    
+    @inline (__always) func inkNoteLineWidthDefaultValue() -> Float {
+        return 2.0
+    }
+    
+    @inline (__always) func inkNoteLineStyleDefaultValue() -> Int {
+        return 0
+    }
+    
+    @inline (__always) func inkNoteDashPatternDefaultValue() -> [CGFloat] {
+        return []
+    }
 }
 
 //protocol KMPreferenceManagerColorPart: NSObjectProtocol {
@@ -1237,6 +1365,193 @@ extension KMPreferenceManager {
             _ = self.setData(data: newValue, forKey: KMPreference.markupNoteFontSizeKey)
         }
     }
+    
+    var freeTextNoteLineWidth: Float {
+        get {
+            return self.getData(forKey: KMPreference.freeTextNoteLineWidthKey) as? Float ?? self.freeTextNoteLineWidthDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.freeTextNoteLineWidthKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.freeTextNoteLineWidthKey)
+        }
+    }
+    
+    var freeTextNoteLineStyle: Int {
+        get {
+            return self.getData(forKey: KMPreference.freeTextNoteLineStyleKey) as? Int ?? self.freeTextNoteLineStyleDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.freeTextNoteLineStyleKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.freeTextNoteLineStyleKey)
+        }
+    }
+    
+    var freeTextNoteDashPattern: [CGFloat] {
+        get {
+            return self.getData(forKey: KMPreference.freeTextNoteDashPatternKey) as? [CGFloat] ?? self.freeTextNoteDashPatternDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.freeTextNoteDashPatternKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.freeTextNoteDashPatternKey)
+        }
+    }
+    
+    var circleNoteLineWidth: Float {
+        get {
+            return self.getData(forKey: KMPreference.circleNoteLineWidthKey) as? Float ?? self.circleNoteLineWidthDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.circleNoteLineWidthKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.circleNoteLineWidthKey)
+        }
+    }
+    
+    var circleNoteLineStyle: Int {
+        get {
+            return self.getData(forKey: KMPreference.circleNoteLineStyleKey) as? Int ?? self.circleNoteLineStyleDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.circleNoteLineStyleKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.circleNoteLineStyleKey)
+        }
+    }
+    
+    var circleNoteDashPattern: [CGFloat] {
+        get {
+            return self.getData(forKey: KMPreference.circleNoteDashPatternKey) as? [CGFloat] ?? self.circleNoteDashPatternDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.circleNoteDashPatternKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.circleNoteDashPatternKey)
+        }
+    }
+    
+    var squareNoteLineWidth: Float {
+        get {
+            return self.getData(forKey: KMPreference.squareNoteLineWidthKey) as? Float ?? self.squareNoteLineWidthDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.squareNoteLineWidthKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.squareNoteLineWidthKey)
+        }
+    }
+    
+    var squareNoteLineStyle: Int {
+        get {
+            return self.getData(forKey: KMPreference.squareNoteLineStyleKey) as? Int ?? self.squareNoteLineStyleDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.squareNoteLineStyleKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.squareNoteLineStyleKey)
+        }
+    }
+    
+    var squareNoteDashPattern: [CGFloat] {
+        get {
+            return self.getData(forKey: KMPreference.squareNoteDashPatternKey) as? [CGFloat] ?? self.squareNoteDashPatternDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.squareNoteDashPatternKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.squareNoteDashPatternKey)
+        }
+    }
+    
+    var lineNoteLineWidth: Float {
+        get {
+            return self.getData(forKey: KMPreference.lineNoteLineWidthKey) as? Float ?? self.lineNoteLineWidthDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.lineNoteLineWidthKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.lineNoteLineWidthKey)
+        }
+    }
+    
+    var lineNoteLineStyle: Int {
+        get {
+            return self.getData(forKey: KMPreference.lineNoteLineStyleKey) as? Int ?? self.lineNoteLineStyleDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.lineNoteLineStyleKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.lineNoteLineStyleKey)
+        }
+    }
+    
+    var lineNoteDashPattern: [CGFloat] {
+        get {
+            return self.getData(forKey: KMPreference.lineNoteDashPatternKey) as? [CGFloat] ?? self.lineNoteDashPatternDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.lineNoteDashPatternKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.lineNoteDashPatternKey)
+        }
+    }
+    
+    var lineNoteStartLineStyle: Int {
+        get {
+            return self.getData(forKey: KMPreference.lineNoteStartLineStyleKey) as? Int ?? self.lineNoteStartLineStyleDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.lineNoteStartLineStyleKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.lineNoteStartLineStyleKey)
+        }
+    }
+    
+    var lineNoteEndLineStyle: Int {
+        get {
+            return self.getData(forKey: KMPreference.lineNoteEndLineStyleKey) as? Int ?? self.lineNoteEndLineStyleDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.lineNoteEndLineStyleKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.lineNoteEndLineStyleKey)
+        }
+    }
+    
+    var inkNoteLineWidth: Float {
+        get {
+            return self.getData(forKey: KMPreference.inkNoteLineWidthKey) as? Float ?? self.inkNoteLineWidthDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.inkNoteLineWidthKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.inkNoteLineWidthKey)
+        }
+    }
+    
+    var inkNoteLineStyle: Int {
+        get {
+            return self.getData(forKey: KMPreference.inkNoteLineStyleKey) as? Int ?? self.inkNoteLineStyleDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.inkNoteLineStyleKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.inkNoteLineStyleKey)
+        }
+    }
+    
+    var inkNoteDashPattern: [CGFloat] {
+        get {
+            return self.getData(forKey: KMPreference.inkNoteDashPatternKey) as? [CGFloat] ?? self.inkNoteDashPatternDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.inkNoteDashPatternKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.inkNoteDashPatternKey)
+        }
+    }
 }
 
 // MARK: -

+ 41 - 4
PDF Office/PDF Master/Class/Preference/View/KMLineWell.swift

@@ -161,6 +161,9 @@ class KMLineWell: NSControl {
         }
     }
     
+    private var _pri_target: AnyObject?
+    private var _pri_action: Selector?
+    
     deinit {
         KMPrint("KMLineWell deinit.")
         
@@ -340,6 +343,24 @@ class KMLineWell: NSControl {
         
     }
     
+    override var target: AnyObject? {
+        get {
+            return self._pri_target
+        }
+        set {
+            self._pri_target = newValue
+        }
+    }
+    
+    override var action: Selector? {
+        get {
+            return self._pri_action
+        }
+        set {
+            self._pri_action = newValue
+        }
+    }
+    
     func takeValue(for key: String, from object: AnyObject) {
         if let inspector = object as? KMLineInspector {
             if key == Self.widthKey {
@@ -801,14 +822,30 @@ extension KMLineWell {
     }
     
     @objc private func _lineInspectorLineAttributeChanged(_ notification: Notification) {
+        guard let inspector = notification.object as? KMLineInspector else {
+            return
+        }
+        let action = inspector.currentLineChangeAction
+        var key: String?
+        if action == .lineWidth {
+            key = Self.widthKey
+        } else if action == .style {
+            key = Self.styleKey
+        } else if action == .dashPattern {
+            key = Self.dashPatternKey
+        } else if action == .startLineStyle {
+            key = Self.startLineStyleKey
+        } else if action == .endLineStyle {
+            key = Self.endLineStyleKey
+        }
         
+        if let _key = key {
+            self.takeValue(for: _key, from: inspector)
+            self.sendAction(self._pri_action, to: self._pri_target)
+        }
     }
     
     private func _existsActiveLineWell() {
         __lwFlags.existsActiveLineWell = 1
     }
-    
-    /*
-
-     */
 }