123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- //
- // 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
- }
- }
|