def layoutRow(self, rect, scale, row): # [TODO] if len(row) == 0: return rect if rect.width() > rect.height(): dir = 'Horizontal' else: dir = 'Vertical' primary = max(rect.width(), rect.height()) sum = row.sumTotalSizes() secondary = int(sum * (1.0 * scale) / primary) if sum == 0: # Prevent division by zero. return rect if secondary < self._parentView.minTileSize( ): # We don't want tiles that small. return rect offset = 0 remaining = primary for fileInfo in row: childSize = int((1.0 * fileInfo.totalSize()) / (1.0 * sum) * primary + 0.5) if childSize > remaining: # Prevent overflow because of accumulated rounding errors childSize = remaining remaining -= childSize if childSize >= self._parentView.minTileSize(): if dir == 'Horizontal': childRect = Rect(Point(rect.x() + offset, rect.y()), Size(childSize, secondary)) else: childRect = Rect(Point(rect.x(), rect.y() + offset), Size(secondary, childSize)) tile = TreemapTile(self._parentView, self, fileInfo, childRect, orientation='Auto') # What should I do with the tile ? offset += childSize if (dir == 'Horizontal'): newRect = Rect(Point(rect.x(), rect.y() + secondary), Size(rect.width(), rect.height() - secondary)) else: newRect = Rect(Point(rect.x() + secondary, rect.y()), Size(rect.width() - secondary, rect.height())) return newRect
def rebuildTreemap( self, newRoot=None, newSize=None ): needtoclean_savedRootUrl = False if not newRoot : (newRoot,newSize) = self._getparam_rebuildTreemap() needtoclean_savedRootUrl = True if not newSize : newSize = self.visibleSize() self._selectedTile = None; self._selectionRect = None; self._rootTile = None; self.canvas().resize( newSize.width(), newSize.height() ) if newSize.width() >= UpdateMinSize and newSize.height() >= UpdateMinSize : if newRoot : self._rootTile = TreemapTile( self, # parentView None, # parentTile newRoot, # orig Rect( point=Point(0, 0), size=newSize ), 'Auto' ) # if self._tree.selection() : # self.selectTile( self._tree.selection() ) if needtoclean_savedRootUrl : self._savedRootUrl = ""
def createChildrenSimple(self, rect, orientation): dir = orientation childDir = orientation if dir == 'Auto': if rect.width() > rect.height(): dir = 'Horizontal' else: dir = 'Vertical' if orientation == 'Horizontal': childDir = 'Vertical' if orientation == 'Vertical': childDir = 'Horizontal' offset = 0 size = {'Horizontal': rect.width(), 'Vertical': rect.height()}[dir] # count = 0 scale = (1.0 * size) / (1.0 * self._orig.totalSize()) fileInfoList = FileInfoList(self._orig, minSize=self._parentView.minTileSize() / scale, bySize=True, param='AsSubDir') # KFileInfoSortedBySizeIterator it( _orig, # (KFileSize) ( _parentView->minTileSize() / scale ), # KDotEntryAsSubDir ); for fileInfo in fileInfoList: childSize = fileInfo.totalSize() if childSize >= self._parentView.minTileSize(): if dir == 'Horizontal': childRect = Rect(point=Point(rect.x() + offset, rect.y()), size=Size(childSize, rect.height())) else: childRect = Rect(point=Point(rect.x(), rect.y() + offset), size=Size(rect.width(), childSize)) tile = TreemapTile(self._parentView, self, fileInfo, childRect, childDir) offset += childSize
def rebuildTreemap(self, newRoot, newSize=None): """Build/Rebuild the tree.""" if not newSize: newSize = self.visibleSize() self._selectedTile = None self._selectionRect = None self._rootTile = None self.canvas().resize(newSize.width(), newSize.height()) if newSize.width() >= UpdateMinSize and newSize.height( ) >= UpdateMinSize: if newRoot: self._rootTile = TreemapTile( self, # parentView None, # parentTile newRoot, # fileinfo Rect(point=Point(0, 0), size=newSize), 'Auto')