KMAnnotationModel.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. weak var editAnnoModel: KMBotaAnnotationModel?
  48. var inputContent: String?
  49. var isFirstResp = false
  50. }
  51. class KMBotaAnnotationReplyModel: KMBotaAnnotationBaseModel {
  52. // weak
  53. var replyAnno: CPDFAnnotation?
  54. weak var annoModel: KMBotaAnnotationModel?
  55. }
  56. class KMBotaAnnotationSectionModel: NSObject {
  57. var items: [KMBotaAnnotationBaseModel] = []
  58. var itemCount: Int {
  59. get {
  60. return self.items.count
  61. }
  62. }
  63. var isExpand = true
  64. }
  65. class KMAnnotationListModel: NSObject {
  66. var datas: [KMBotaAnnotationSectionModel] = []
  67. // 默认全部折叠
  68. var foldType: KMFoldType {
  69. set {
  70. for model in self.canFoldModel() {
  71. if newValue != .none {
  72. model.foldType = newValue
  73. }
  74. }
  75. }
  76. get {
  77. let canFolds = self.canFoldModel()
  78. if canFolds.isEmpty {
  79. return .none
  80. }
  81. // 是否全部折叠
  82. var isAll = true
  83. for model in canFolds {
  84. if model.isFold() == false {
  85. isAll = false
  86. break
  87. }
  88. }
  89. if isAll {
  90. return .fold
  91. }
  92. // 是否全部展开
  93. for model in canFolds {
  94. if model.isFold() {
  95. isAll = false
  96. break
  97. }
  98. }
  99. return isAll ? .unfold : .none
  100. }
  101. }
  102. func canFoldModel() -> [KMBotaAnnotationModel] {
  103. var models: [KMBotaAnnotationModel] = []
  104. for model in self.datas {
  105. for itemM in model.items {
  106. if let data = itemM as? KMBotaAnnotationModel {
  107. if data.canFold() {
  108. models.append(data)
  109. }
  110. }
  111. }
  112. }
  113. return models
  114. }
  115. func isAllFold() -> Bool {
  116. for model in self.canFoldModel() {
  117. if model.isFold() == false {
  118. return false
  119. }
  120. }
  121. return true
  122. }
  123. }