KMAnnotationModel.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // KMAnnotationModel.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/4/3.
  6. //
  7. import Cocoa
  8. class KMAnnotationModel: NSObject {
  9. weak var anno: CPDFAnnotation?
  10. }
  11. class KMBotaAnnotationBaseModel: KMAnnotationModel {
  12. var isExpand = false
  13. var animated = false
  14. var isSelected = false
  15. }
  16. class KMBotaAnnotationModel: KMBotaAnnotationBaseModel {
  17. var showPage = true
  18. var showTime = true
  19. var showAuthor = true
  20. var foldType: KMFoldType = .none
  21. var foldH: CGFloat = 30
  22. weak var sectionModel: KMBotaAnnotationSectionModel?
  23. weak var footerModel: KMBotaAnnotationFooterModel?
  24. var replyAnnos: [KMBotaAnnotationReplyModel] = []
  25. func isFold() -> Bool {
  26. if self.foldType == .unfold {
  27. return false
  28. }
  29. return true
  30. }
  31. func canFold() -> Bool {
  32. guard let data = self.anno else {
  33. return false
  34. }
  35. if data is CPDFMarkupAnnotation {
  36. return true
  37. }
  38. if data is CPDFTextAnnotation {
  39. return true
  40. }
  41. return false
  42. }
  43. }
  44. class KMBotaAnnotationFooterModel: KMBotaAnnotationBaseModel {
  45. weak var annoModel: KMBotaAnnotationModel?
  46. weak var replyModel: KMBotaAnnotationReplyModel?
  47. var inputContent: String?
  48. var isFirstResp = false
  49. }
  50. class KMBotaAnnotationReplyModel: KMBotaAnnotationBaseModel {
  51. // weak
  52. var replyAnno: CPDFAnnotation?
  53. weak var annoModel: KMBotaAnnotationModel?
  54. }
  55. class KMBotaAnnotationSectionModel: NSObject {
  56. var items: [KMBotaAnnotationBaseModel] = []
  57. var itemCount: Int {
  58. get {
  59. return self.items.count
  60. }
  61. }
  62. var isExpand = true
  63. }
  64. class KMAnnotationListModel: NSObject {
  65. var datas: [KMBotaAnnotationSectionModel] = []
  66. // 默认全部折叠
  67. var foldType: KMFoldType {
  68. set {
  69. for model in self.canFoldModel() {
  70. if newValue != .none {
  71. model.foldType = newValue
  72. }
  73. }
  74. }
  75. get {
  76. let canFolds = self.canFoldModel()
  77. if canFolds.isEmpty {
  78. return .none
  79. }
  80. // 是否全部折叠
  81. var isAll = true
  82. for model in canFolds {
  83. if model.isFold() == false {
  84. isAll = false
  85. break
  86. }
  87. }
  88. if isAll {
  89. return .fold
  90. }
  91. // 是否全部展开
  92. for model in canFolds {
  93. if model.isFold() {
  94. isAll = false
  95. break
  96. }
  97. }
  98. return isAll ? .unfold : .none
  99. }
  100. }
  101. func canFoldModel() -> [KMBotaAnnotationModel] {
  102. var models: [KMBotaAnnotationModel] = []
  103. for model in self.datas {
  104. for itemM in model.items {
  105. if let data = itemM as? KMBotaAnnotationModel {
  106. if data.canFold() {
  107. models.append(data)
  108. }
  109. }
  110. }
  111. }
  112. return models
  113. }
  114. func isAllFold() -> Bool {
  115. for model in self.canFoldModel() {
  116. if model.isFold() == false {
  117. return false
  118. }
  119. }
  120. return true
  121. }
  122. }