// // KMAnnotationModel.swift // PDF Reader Pro // // Created by tangchao on 2024/4/3. // import Cocoa class KMAnnotationModel: NSObject { weak var anno: CPDFAnnotation? } class KMBotaAnnotationBaseModel: KMAnnotationModel { var isExpand = false var animated = false var isSelected = false } class KMBotaAnnotationModel: KMBotaAnnotationBaseModel { var showPage = true var showTime = true var showAuthor = true var foldType: KMFoldType = .none var foldH: CGFloat = 30 weak var sectionModel: KMBotaAnnotationSectionModel? weak var footerModel: KMBotaAnnotationFooterModel? var replyAnnos: [KMBotaAnnotationReplyModel] = [] func isFold() -> Bool { if self.foldType == .unfold { return false } return true } func canFold() -> Bool { guard let data = self.anno else { return false } if data is CPDFMarkupAnnotation { return true } if data is CPDFTextAnnotation { return true } return false } } class KMBotaAnnotationFooterModel: KMBotaAnnotationBaseModel { weak var annoModel: KMBotaAnnotationModel? weak var replyModel: KMBotaAnnotationReplyModel? var inputContent: String? var isFirstResp = false } class KMBotaAnnotationReplyModel: KMBotaAnnotationBaseModel { // weak var replyAnno: CPDFAnnotation? weak var annoModel: KMBotaAnnotationModel? } class KMBotaAnnotationSectionModel: NSObject { var items: [KMBotaAnnotationBaseModel] = [] var itemCount: Int { get { return self.items.count } } var isExpand = true } class KMAnnotationListModel: NSObject { var datas: [KMBotaAnnotationSectionModel] = [] // 默认全部折叠 var foldType: KMFoldType { set { for model in self.canFoldModel() { if newValue != .none { model.foldType = newValue } } } get { let canFolds = self.canFoldModel() if canFolds.isEmpty { return .none } // 是否全部折叠 var isAll = true for model in canFolds { if model.isFold() == false { isAll = false break } } if isAll { return .fold } // 是否全部展开 for model in canFolds { if model.isFold() { isAll = false break } } return isAll ? .unfold : .none } } func canFoldModel() -> [KMBotaAnnotationModel] { var models: [KMBotaAnnotationModel] = [] for model in self.datas { for itemM in model.items { if let data = itemM as? KMBotaAnnotationModel { if data.canFold() { models.append(data) } } } } return models } func isAllFold() -> Bool { for model in self.canFoldModel() { if model.isFold() == false { return false } } return true } }