KMAnnotationModel.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 footerModel: KMBotaAnnotationFooterModel?
  23. var replyAnnos: [KMBotaAnnotationReplyModel] = []
  24. func isFold() -> Bool {
  25. if self.foldType == .unfold {
  26. return false
  27. }
  28. return true
  29. }
  30. func canFold() -> Bool {
  31. guard let data = self.anno else {
  32. return false
  33. }
  34. if data is CPDFMarkupAnnotation {
  35. return true
  36. }
  37. if data is CPDFTextAnnotation {
  38. return true
  39. }
  40. return false
  41. }
  42. }
  43. class KMBotaAnnotationFooterModel: KMBotaAnnotationBaseModel {
  44. weak var annoModel: KMBotaAnnotationModel?
  45. weak var replyModel: KMBotaAnnotationReplyModel?
  46. }
  47. class KMBotaAnnotationReplyModel: KMBotaAnnotationBaseModel {
  48. // weak
  49. var replyAnno: CPDFAnnotation?
  50. weak var annoModel: KMBotaAnnotationModel?
  51. }
  52. class KMBotaAnnotationSectionModel: NSObject {
  53. var items: [KMBotaAnnotationBaseModel] = []
  54. var itemCount: Int {
  55. get {
  56. return self.items.count
  57. }
  58. }
  59. var isExpand = true
  60. }
  61. class KMAnnotationListModel: NSObject {
  62. var datas: [KMBotaAnnotationSectionModel] = []
  63. // 默认全部折叠
  64. var foldType: KMFoldType {
  65. set {
  66. for model in self.canFoldModel() {
  67. if newValue != .none {
  68. model.foldType = newValue
  69. }
  70. }
  71. }
  72. get {
  73. let canFolds = self.canFoldModel()
  74. if canFolds.isEmpty {
  75. return .none
  76. }
  77. // 是否全部折叠
  78. var isAll = true
  79. for model in canFolds {
  80. if model.isFold() == false {
  81. isAll = false
  82. break
  83. }
  84. }
  85. if isAll {
  86. return .fold
  87. }
  88. // 是否全部展开
  89. for model in canFolds {
  90. if model.isFold() {
  91. isAll = false
  92. break
  93. }
  94. }
  95. return isAll ? .unfold : .none
  96. }
  97. }
  98. func canFoldModel() -> [KMBotaAnnotationModel] {
  99. var models: [KMBotaAnnotationModel] = []
  100. for model in self.datas {
  101. for itemM in model.items {
  102. if let data = itemM as? KMBotaAnnotationModel {
  103. if data.canFold() {
  104. models.append(data)
  105. }
  106. }
  107. }
  108. }
  109. return models
  110. }
  111. func isAllFold() -> Bool {
  112. for model in self.canFoldModel() {
  113. if model.isFold() == false {
  114. return false
  115. }
  116. }
  117. return true
  118. }
  119. }