123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // KMAnnotationModel.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2024/4/3.
- //
- import Cocoa
- class KMAnnotationModel: NSObject {
- weak var anno: CPDFAnnotation?
- }
- class KMBotaAnnotationModel: KMAnnotationModel {
- var showPage = true
- var showTime = true
- var showAuthor = true
-
- var foldType: KMFoldType = .none
- var foldH: CGFloat = 30
-
- 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 KMAnnotationListModel: NSObject {
- var datas: [KMBotaAnnotationModel] = []
-
- // 默认全部折叠
- 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 {
- if model.canFold() {
- models.append(model)
- }
- }
- return models
- }
-
- func isAllFold() -> Bool {
- for model in self.canFoldModel() {
- if model.isFold() == false {
- return false
- }
- }
- return true
- }
- }
|