123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- //
- // KMPageEditThumbnailView.swift
- // PDF Master
- //
- // Created by tangchao on 2023/1/6.
- //
- import Cocoa
- typealias KMPageEditThumbnailViewSelectionDidChange = (_ selectedIndexs: Set<IndexPath>) -> ()
- class KMPageEditThumbnailView: KMPDFThumbnailView {
- var selectionDidChange: KMPageEditThumbnailViewSelectionDidChange?
-
- private let defaultItemSize = NSMakeSize(208, 294)
- private var defaultThumbnailSzie: NSSize?
-
- override var selectionIndexPaths: Set<IndexPath> {
- get {
- return super.selectionIndexPaths
- }
- set {
- super.selectionIndexPaths = newValue
- // 通知外面
- guard let callback = self.selectionDidChange else {
- return
- }
- callback(self.collectionView.selectionIndexPaths)
- }
- }
-
- override func initDefaultValue() {
- super.initDefaultValue()
-
- self.itemSize = NSMakeSize(208, 294)
- self.defaultThumbnailSzie = self.thumbnailSzie
- self.isShowPageSize = true
-
- self.register(KMPageEditThumbnailItem.self)
- self.collectionView.allowsMultipleSelection = true
- }
-
- func selectPages(at indexpaths: Set<IndexPath>) {
- self.selectionIndexPaths = indexpaths
- }
-
- public func canZoomOut() -> Bool {
- return self.itemSize.width <= self.defaultItemSize.width
- }
-
- public func zoomOut() {
- if (self.canZoomOut() == false) {
- return
- }
- let indexpaths = self.collectionView.selectionIndexPaths
- if (self.itemSize.width < self.defaultItemSize.width) {
- self.itemSize = self.defaultItemSize
- self.thumbnailSzie = self.defaultThumbnailSzie!
- } else if (self.itemSize.width == self.defaultItemSize.width) {
- self.itemSize = NSSize(width: self.defaultItemSize.width*1.5, height: self.defaultItemSize.height*1.5)
- self.thumbnailSzie = NSSize(width: self.defaultThumbnailSzie!.width*1.5, height: self.defaultThumbnailSzie!.height*1.5)
- }
-
- self.reloadData()
- self.collectionView.selectionIndexPaths = indexpaths
- }
-
- public func canZoomIn() -> Bool {
- return self.itemSize.width >= self.defaultItemSize.width
- }
- public func zoomIn() {
- if (self.canZoomIn() == false) {
- return
- }
- let indexpaths = self.collectionView.selectionIndexPaths
- if (self.itemSize.width > self.defaultItemSize.width) {
- self.itemSize = self.defaultItemSize
- self.thumbnailSzie = self.defaultThumbnailSzie!
- } else if (self.itemSize.width == self.defaultItemSize.width) {
- self.itemSize = NSSize(width: self.defaultItemSize.width*0.5, height: self.defaultItemSize.height*0.5)
- self.thumbnailSzie = NSSize(width: self.defaultThumbnailSzie!.width*0.5, height: self.defaultThumbnailSzie!.height*0.5)
- }
-
- self.reloadData()
- self.collectionView.selectionIndexPaths = indexpaths
- }
- }
- extension KMPageEditThumbnailView {
- override func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
- super.collectionView(collectionView, didSelectItemsAt: indexPaths)
-
- DispatchQueue.main.async {
- guard let callback = self.selectionDidChange else {
- return
- }
- callback(collectionView.selectionIndexPaths)
- }
- }
-
- override func collectionView(_ collectionView: NSCollectionView, didDeselectItemsAt indexPaths: Set<IndexPath>) {
- super.collectionView(collectionView, didDeselectItemsAt: indexPaths)
-
- DispatchQueue.main.async {
- guard let callback = self.selectionDidChange else {
- return
- }
- callback(collectionView.selectionIndexPaths)
- }
- }
- }
|