|
@@ -12,6 +12,7 @@ let textBoxSpace = 2
|
|
|
let textLabelHeight = 15
|
|
|
|
|
|
typealias KMPDFThumbnailItemMouseDown = (_ view: KMPDFThumbnailItem, _ event: NSEvent) -> Void
|
|
|
+typealias KMPDFThumbnailItemHover = (_ view: KMPDFThumbnailItem, _ mouseEntered: Bool) -> Void
|
|
|
typealias KMPDFThumbnailItemRightMouseDown = (_ view: KMPDFThumbnailItem, _ event: NSEvent) -> Void
|
|
|
|
|
|
class KMPDFThumbnailItem: NSCollectionViewItem {
|
|
@@ -55,12 +56,18 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
|
|
|
|
|
|
lazy var pageView = KMPDFThumbnialPageView()
|
|
|
|
|
|
- var page : CPDFPage = CPDFPage()
|
|
|
+ var page : CPDFPage = CPDFPage() {
|
|
|
+ didSet {
|
|
|
+ self.pageView.page = page
|
|
|
+ self.updatePageState(page: page)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
var thumbnailView : KMPDFThumbnailView = KMPDFThumbnailView()
|
|
|
|
|
|
var mouseDownAction: KMPDFThumbnailItemMouseDown?
|
|
|
var rightMouseDownAction: KMPDFThumbnailItemRightMouseDown?
|
|
|
+ var hoverCallBack: KMPDFThumbnailItemHover?
|
|
|
|
|
|
var contentBox: KMBox?
|
|
|
|
|
@@ -79,6 +86,12 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var hover: Bool = false {
|
|
|
+ didSet {
|
|
|
+ self.updateItemState()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
|
|
|
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
|
|
}
|
|
@@ -114,30 +127,32 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
|
|
|
}
|
|
|
set {
|
|
|
super.isSelected = newValue
|
|
|
- if (newValue) {
|
|
|
- self.view.layer?.backgroundColor = NSColor(hex: "#CED0D4", alpha: 0.6).cgColor
|
|
|
- self.view.layer?.borderColor = NSColor(hex: "#CED0D4").cgColor
|
|
|
- } else {
|
|
|
- self.view.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
- self.view.layer?.borderColor = NSColor.clear.cgColor
|
|
|
- }
|
|
|
+// if (newValue) {
|
|
|
+// self.view.layer?.backgroundColor = NSColor(hex: "#CED0D4", alpha: 0.6).cgColor
|
|
|
+// self.view.layer?.borderColor = NSColor(hex: "#CED0D4").cgColor
|
|
|
+// } else {
|
|
|
+// self.view.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
+// self.view.layer?.borderColor = NSColor.clear.cgColor
|
|
|
+// }
|
|
|
+ self.updateItemState()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func setPage(page:CPDFPage!) {
|
|
|
- self.page = page
|
|
|
- self.pageView.page = page
|
|
|
- let index = page.document.index(for: page) + 1
|
|
|
- self.pageTextLabel.stringValue = "\(index)"
|
|
|
-
|
|
|
- let bounds = self.page.bounds
|
|
|
- if page.rotation == 90 || page.rotation == 270 {
|
|
|
- self.pageSizeTextLabel.stringValue = "\(Int(bounds.size.height))*\(Int(bounds.size.width)) mm"
|
|
|
- } else {
|
|
|
- self.pageSizeTextLabel.stringValue = "\(Int(bounds.size.width))*\(Int(bounds.size.height)) mm"
|
|
|
+ func updatePageState(page: CPDFPage!) {
|
|
|
+ if page != nil {
|
|
|
+ let index = page.document.index(for: page) + 1
|
|
|
+ self.pageTextLabel.stringValue = "\(index)"
|
|
|
+
|
|
|
+ let bounds = self.page.bounds
|
|
|
+ if page.rotation == 90 || page.rotation == 270 {
|
|
|
+ self.pageSizeTextLabel.stringValue = "\(Int(bounds.size.height))*\(Int(bounds.size.width)) mm"
|
|
|
+ } else {
|
|
|
+ self.pageSizeTextLabel.stringValue = "\(Int(bounds.size.width))*\(Int(bounds.size.height)) mm"
|
|
|
+ }
|
|
|
+
|
|
|
+ self.updateFrame()
|
|
|
+ self.updateItemState()
|
|
|
}
|
|
|
-
|
|
|
- self.updateFrame()
|
|
|
}
|
|
|
|
|
|
class func sizeToFit(size:NSSize,page:CPDFPage,isShow:Bool) -> CGFloat {
|
|
@@ -227,14 +242,23 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
|
|
|
self.pageView.frame = NSMakeRect(pageX, pageY, size.width, size.height)
|
|
|
}
|
|
|
|
|
|
+ func updateItemState() {
|
|
|
+ if isSelected {
|
|
|
+ self.view.layer?.backgroundColor = NSColor(hex: "#CED0D4", alpha: 0.6).cgColor
|
|
|
+ self.view.layer?.borderColor = NSColor(hex: "#CED0D4").cgColor
|
|
|
+ } else if hover {
|
|
|
+ self.view.layer?.backgroundColor = NSColor(hex: "#EDEEF0").cgColor
|
|
|
+ self.view.layer?.borderColor = NSColor.clear.cgColor
|
|
|
+ } else {
|
|
|
+ self.view.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
+ self.view.layer?.borderColor = NSColor.clear.cgColor
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
func addContentBox() {
|
|
|
if self.contentBox == nil {
|
|
|
- var rect = self.view.bounds
|
|
|
-// rect.origin.x = self.bounds.origin.x + 8.0
|
|
|
-// rect.size.width = self.bounds.size.width - 16.0
|
|
|
-
|
|
|
+ let rect = self.view.bounds
|
|
|
self.contentBox?.wantsLayer = true
|
|
|
self.contentBox?.layer?.masksToBounds = true
|
|
|
self.contentBox = KMBox(frame: rect)
|
|
@@ -245,21 +269,7 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
|
|
|
self.view.addSubview(self.contentBox!, positioned: NSWindow.OrderingMode.below, relativeTo: self.view)
|
|
|
self.contentBox?.autoresizingMask = [.width, .height]
|
|
|
self.contentBox?.moveCallback = { [unowned self] (mouseEntered, mouseBox) in
|
|
|
- if mouseEntered {
|
|
|
- if self.isSelected {
|
|
|
-
|
|
|
- } else {
|
|
|
- self.view.layer?.backgroundColor = NSColor(hex: "#EDEEF0").cgColor
|
|
|
- self.view.layer?.borderColor = NSColor.clear.cgColor
|
|
|
- }
|
|
|
- } else {
|
|
|
- if self.isSelected {
|
|
|
-
|
|
|
- } else {
|
|
|
- self.view.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
- self.view.layer?.borderColor = NSColor.clear.cgColor
|
|
|
- }
|
|
|
- }
|
|
|
+ self.hoverCallBack?(self, mouseEntered)
|
|
|
}
|
|
|
|
|
|
self.contentBox?.rightDownCallback = { [unowned self] (downEntered, mouseBox, event) in
|
|
@@ -268,30 +278,8 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// override func mouseExited(with event: NSEvent) {
|
|
|
-// super.mouseExited(with: event)
|
|
|
-// if self.isSelected {
|
|
|
-//
|
|
|
-// } else {
|
|
|
-// self.view.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
-// self.view.layer?.borderColor = NSColor.clear.cgColor
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// override func mouseEntered(with event: NSEvent) {
|
|
|
-// super.mouseEntered(with: event)
|
|
|
-// print("mouseEntered")
|
|
|
-// if self.isSelected {
|
|
|
-//
|
|
|
-// } else {
|
|
|
-// self.view.layer?.backgroundColor = NSColor(hex: "#EDEEF0").cgColor
|
|
|
-// self.view.layer?.borderColor = NSColor.clear.cgColor
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
override func mouseMoved(with event: NSEvent) {
|
|
|
super.mouseMoved(with: event)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
override func mouseDown(with event: NSEvent) {
|