aboutsummaryrefslogtreecommitdiff
path: root/Flat Bezel/FlatBezelCollectingSearchObjectView.swift
blob: 26586be2f60441ee354dfc4e77db7afcba020e0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class FlatBezelCollectingSearchObjectView: QSCollectingSearchObjectView {
  override static var cellClass : AnyClass? {
      get { return BBObjectCell.self }
      set { super.cellClass = newValue }
  }
  
  override func draw(_ rect: NSRect) {
    var frame = frame
    
    // These properties aren't available to Swift, so they need to be accessed in this way.
    let collection = (value(forKey: "collection") as! NSMutableArray)
    let collecting = (value(forKey: "collecting") as! Bool)
    
    let count = collection.count
    if self.currentEditor() == nil && count != 0 {
      frame.origin = NSZeroPoint
      cell?.draw(withFrame: frame, in: self)
      let iconSize = collectionSpace() != 0 ? collectionSpace() : 16
      let opacity = collecting ? 1.0 : 0.75
      let totalWidth = iconSize + 2
      for i in 0..<count {
        let object = collection.object(at: i) as! QSObject
        var icon = object.icon()
        let size = NSMakeSize(16, 16)
        icon?.size = size
        let inRect = NSMakeRect(
          frame.size.width - totalWidth * CGFloat(count - i),
          frame.origin.y + 2,
          iconSize,
          iconSize
        )
        icon?.draw(in: inRect, from: rectFromSize(size), operation: .sourceOver, fraction: opacity)
      }
    } else {
      super.draw(rect)
    }
  }
}