Forráskód Böngészése

【手绘注释】属性面板边框调试

tangchao 7 hónapja
szülő
commit
d38e08e01a

+ 7 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFAnnotationModel.m

@@ -669,6 +669,13 @@
     if (_annotation && self.annotations.count == 1) {
         return _annotation.dashPattern;
     }
+    if (_annotationType == CAnnotationTypeInk) {
+        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
+        NSArray *dashs = [userDefaults objectForKey:CInkNoteDashPatternKey];
+        if (dashs.count > 0) {
+            return  dashs;
+        }
+    }
     return @[@5];
 }
 

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMGeneralAnnotationViewController.swift

@@ -163,7 +163,7 @@ let KMColorPickerViewHeight: CGFloat = 64
 
     @IBOutlet private weak var borderAndLineView: NSView!  // 边框
     @IBOutlet private weak var borderLabel: NSTextField!
-    @IBOutlet private weak var borderButton: NSButton!
+    @IBOutlet weak var borderButton: NSButton!
     @IBOutlet private weak var lineWidthComboBox: KMComboBox!
     @IBOutlet private weak var lineWidthSlider: NSSlider!
     @IBOutlet private weak var lineTypeLabel: NSTextField!

+ 96 - 11
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/Freehand/Controller/KMFreehandAnnotationController.swift

@@ -18,19 +18,19 @@ import Cocoa
         self.init(nibName: "KMGeneralAnnotationViewController", bundle: nil)
     }
     
+    override func awakeFromNib() {
+        super.awakeFromNib()
+        
+        self.initSubviews()
+    }
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         
         self.initDefaultValue()
     }
     
-    func initDefaultValue() {
-        self.borderItemButtonHeightConst.constant = 64
-        self.lineStyleBox.isHidden = true
-        self.lineStyleButton.isHidden = true
-        self.dottedLineStyleBox.isHidden = true
-        self.dottedLineStyleButton.isHidden = true
-        
+    func initSubviews() {
         let view = KMLineAndBorderItemView.createFromNib()
         self.lineAndBorderItemView = view
         let borderAndLineView = self.kBorderAndLineView
@@ -39,11 +39,96 @@ import Cocoa
         view?.autoresizingMask = [.width]
         self.kBorderAndLineView.addSubview(view!)
         
-        view?.lineImageButon.imagePosition = .imageOnly
-        view?.lineImageButon.image = self.borderStyleSolid(false)
+        self.lineAndBorderItemView?.lineRadio.target = self
+        self.lineAndBorderItemView?.lineRadio.action = #selector(lineRadioAction)
+        
+        self.lineAndBorderItemView?.dashRadio.target = self
+        self.lineAndBorderItemView?.dashRadio.action = #selector(dashRadioAction)
+        
+        self.lineAndBorderItemView?.dashComboBox.target = self
+        self.lineAndBorderItemView?.dashComboBox.action = #selector(dashComboAction)
+    }
+    
+    func initDefaultValue() {
+        self.borderItemButtonHeightConst.constant = 64
+        self.lineStyleBox.isHidden = true
+        self.lineStyleButton.isHidden = true
+        self.dottedLineStyleBox.isHidden = true
+        self.dottedLineStyleButton.isHidden = true
+        
+        self.borderButton.isHidden = true
+        
+        self.lineAndBorderItemView?.lineImageButon.imagePosition = .imageOnly
+        self.lineAndBorderItemView?.lineImageButon.image = self.borderStyleSolid(false)
+        
+        self.lineAndBorderItemView?.dashImageButton.imagePosition = .imageOnly
+        self.lineAndBorderItemView?.dashImageButton.image = self.borderStyleDashed(false)
+    }
+    
+    override func reloadData() {
+        super.reloadData()
+        
+        let style = self.annotationModel?.style() ?? .solid
+        self.selectBorderStyle(style)
+        
+        if let datas = self.annotationModel?.dashPattern() {
+            if let data = datas.first as? CGFloat {
+                self.lineAndBorderItemView?.dashComboBox.stringValue = String(format: "%0.1f pt", data)
+            }
+        }
+    }
+    
+    func selectBorderStyle(_ style: CPDFBorderStyle) {
+        if style == .dashed {
+            self.lineAndBorderItemView?.lineRadio.state = .off
+            self.lineAndBorderItemView?.dashRadio.state = .on
+            
+            self.lineAndBorderItemView?.dashComboBox.isEnabled = true
+        } else {
+            self.lineAndBorderItemView?.lineRadio.state = .on
+            self.lineAndBorderItemView?.dashRadio.state = .off
+            
+            self.lineAndBorderItemView?.dashComboBox.isEnabled = false
+        }
+    }
+    
+    // MARK: - Actions
+    
+    @objc func lineRadioAction(_ sender: NSButton) {
+        self.annotationModel?.setStyle(.solid)
+        
+        self.selectBorderStyle(.solid)
+        
+        self.reloadData()
+    }
+    
+    @objc func dashRadioAction(_ sender: NSButton) {
+        self.annotationModel?.setStyle(.dashed)
+        
+        self.selectBorderStyle(.dashed)
+        
+        self.reloadData()
+    }
+    
+    @IBAction func dashComboAction(_ sender: Any) {
+        var lineWidth = self.lineAndBorderItemView?.dashComboBox.floatValue ?? 0
+        if lineWidth > 18 {
+            lineWidth = 18
+        } else if lineWidth < 0.5 {
+            lineWidth = 0.5
+        }
+
+        if let data = self.annotationModel?.annotation {
+            data.setDashPattern([lineWidth])
+            
+            self.pdfView?.setNeedsDisplayAnnotationViewFor(data.page)
+        } else {
+            let userDefaults = UserDefaults.standard
+            userDefaults.set([lineWidth], forKey: CInkNoteDashPatternKey)
+        }
         
-        view?.dashImageButton.imagePosition = .imageOnly
-        view?.dashImageButton.image = self.borderStyleDashed(false)
+//        self.updateAnnotation()
+        self.reloadData()
     }
     
     override func borderStyleSolid(_ isSelect: Bool) -> NSImage {