KMEditPDFPopGuideView.swift 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // KMEditPDFPopGuideView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/6/19.
  6. //
  7. import Cocoa
  8. class KMEditPDFPopGuideView: NSView {
  9. private lazy var targetView_: KMGuideTargetView = {
  10. let view = KMGuideTargetView(frame: NSRect(x: 0, y: 0, width: 56, height: 56))
  11. view.lineWidth = 2
  12. view.strokeColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7)
  13. return view
  14. }()
  15. private lazy var contentView_: NSView = {
  16. let view = NSView()
  17. view.wantsLayer = true
  18. view.layer?.borderWidth = 2
  19. view.layer?.cornerRadius = 8
  20. view.layer?.masksToBounds = true
  21. view.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
  22. view.layer?.backgroundColor = NSColor.white.cgColor
  23. return view
  24. }()
  25. private lazy var shadowView_: NSView = {
  26. let view = NSView()
  27. view.wantsLayer = true
  28. view.layer?.borderWidth = 0
  29. // view.layer?.shadowColor = NSColor.black.withAlphaComponent(0.55).cgColor
  30. view.layer?.shadowColor = NSColor.red.cgColor
  31. view.layer?.shadowOpacity = 0.1
  32. view.layer?.shadowRadius = 3.0
  33. return view
  34. }()
  35. private lazy var titleLabel_: NSTextField = {
  36. let view = NSTextField(labelWithString: NSLocalizedString("Add a new hover quick entrance.", comment: ""))
  37. return view
  38. }()
  39. private lazy var despLabel_: NSTextField = {
  40. let view = NSTextField(wrappingLabelWithString: NSLocalizedString("You can hide the hover bar in Settings.", comment: ""))
  41. return view
  42. }()
  43. private lazy var settingBtn_: NSButton = {
  44. let view = NSButton()
  45. view.isBordered = false
  46. let title = NSLocalizedString("Settings", comment: "")
  47. var attri = NSAttributedString(string: title)
  48. view.attributedTitle = NSAttributedString(string: title, attributes: [.underlineStyle : true, .foregroundColor : NSColor.km_init(hex: "#4982E6")])
  49. view.target = self
  50. view.action = #selector(buttonClick)
  51. return view
  52. }()
  53. private lazy var okBtnBox_: NSBox = {
  54. let view = NSBox()
  55. view.boxType = .custom
  56. view.titlePosition = .noTitle
  57. view.contentViewMargins = .zero
  58. view.borderColor = NSColor.clear
  59. view.cornerRadius = 2
  60. view.fillColor = NSColor.km_init(hex: "#4982E6")
  61. return view
  62. }()
  63. private lazy var okBtn_: NSButton = {
  64. let view = NSButton()
  65. view.isBordered = false
  66. view.title = NSLocalizedString("Got it", comment: "")
  67. view.setTitleColor(.white)
  68. view.target = self
  69. view.action = #selector(buttonClick)
  70. return view
  71. }()
  72. var itemClick: KMCommonClickBlock?
  73. static let kWidth: CGFloat = 300
  74. static let kHeight: CGFloat = 152+56+5
  75. var contentTop: Bool = false
  76. override func draw(_ dirtyRect: NSRect) {
  77. super.draw(dirtyRect)
  78. // Drawing code here.
  79. }
  80. convenience init(contentTop: Bool = true) {
  81. self.init(frame: .init(x: 0, y: 0, width: Self.kWidth, height: Self.kHeight))
  82. self.contentTop = contentTop
  83. self.initSubView()
  84. }
  85. func initSubView() {
  86. if self.contentTop { // 内容显示在上面
  87. self.addSubview(self.targetView_)
  88. self.targetView_.km_add_bottom_constraint()
  89. self.targetView_.km_add_centerX_constraint()
  90. self.targetView_.km_add_size_constraint(size: .init(width: 56, height: 56))
  91. self.addSubview(self.contentView_)
  92. self.contentView_.km_add_centerX_constraint()
  93. self.contentView_.km_add_bottom_constraint(equalTo: self.targetView_, attribute: .top, constant: -5)
  94. self.contentView_.km_add_size_constraint(size: .init(width: 300, height: 152))
  95. } else {
  96. self.addSubview(self.targetView_)
  97. self.targetView_.km_add_top_constraint()
  98. self.targetView_.km_add_centerX_constraint()
  99. self.targetView_.km_add_size_constraint(size: .init(width: 56, height: 56))
  100. self.addSubview(self.contentView_)
  101. self.contentView_.km_add_centerX_constraint()
  102. self.contentView_.km_add_top_constraint(equalTo: self.targetView_, attribute: .bottom, constant: 5)
  103. self.contentView_.km_add_size_constraint(size: .init(width: 300, height: 152))
  104. }
  105. // self.addSubview(self.shadowView_)
  106. // self.wantsLayer = true
  107. // self.shadow = NSShadow()
  108. // self.shadowView_.frame = self.bounds.insetBy(dx: 5, dy: 0)
  109. // let shadowPath = NSBezierPath(rect: self.shadowView_.bounds)
  110. // if #available(macOS 14.0, *) {
  111. // self.shadowView_.layer?.shadowPath = shadowPath.kmCGPath()
  112. // }
  113. self.contentView_.addSubview(self.titleLabel_)
  114. self.contentView_.addSubview(self.despLabel_)
  115. self.contentView_.addSubview(self.settingBtn_)
  116. self.contentView_.addSubview(self.okBtnBox_)
  117. self.okBtnBox_.contentView?.addSubview(self.okBtn_)
  118. self.titleLabel_.km_add_top_constraint(constant: 20)
  119. self.titleLabel_.km_add_left_constraint(constant: 20)
  120. self.despLabel_.km_add_left_constraint(constant: 20)
  121. self.despLabel_.km_add_top_constraint(equalTo: self.titleLabel_, attribute: .bottom, constant: 14)
  122. self.despLabel_.km_add_width_constraint(constant: 260)
  123. self.okBtn_.km_add_inset_constraint(inset: .init(top: 4, left: 8, bottom: 4, right: 8))
  124. self.okBtnBox_.km_add_right_constraint(constant: -20)
  125. self.okBtnBox_.km_add_bottom_constraint(constant: -16)
  126. self.settingBtn_.km_add_bottom_constraint(constant: -20)
  127. self.settingBtn_.km_add_right_constraint(equalTo: self.okBtn_, attribute: .left, constant: -20)
  128. }
  129. @objc func buttonClick(_ sender: NSButton) {
  130. if sender.isEqual(to: self.okBtn_) {
  131. self.itemClick?(1)
  132. } else {
  133. self.itemClick?(0)
  134. }
  135. }
  136. override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
  137. if appearance == .darkAqua {
  138. self.contentView_.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor
  139. self.contentView_.layer?.backgroundColor = NSColor.black.cgColor
  140. self.titleLabel_.textColor = KMAppearance.Layout.w0Color()
  141. self.despLabel_.textColor = KMAppearance.Layout.h1Color()
  142. self.targetView_.strokeColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7)
  143. } else {
  144. self.contentView_.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
  145. self.contentView_.layer?.backgroundColor = NSColor.white.cgColor
  146. self.titleLabel_.textColor = KMAppearance.Layout.mColor()
  147. self.despLabel_.textColor = KMAppearance.Layout.h0Color()
  148. self.targetView_.strokeColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4)
  149. }
  150. }
  151. }