def setAlternateBrush(self, brush): """ Sets the alternating brush used for this widget to the inputed brush. :param brush | <QBrush> || <QColor> """ self._alternateBrush = QBrush(brush)
def setWeekendBrush(self, brush): """ Sets the brush to be used when coloring weekend columns. :param brush | <QBrush> || <QColor> """ self._weekendBrush = QBrush(brush)
def setBrush(self, brush): """ Sets the main background brush used for this widget to the inputed brush. :param brush | <QBrush> || <QColor> """ self._brush = QBrush(brush)
def paintMilestone(self, painter): """ Paints this item as the milestone look. :param painter | <QPainter> """ # generate the rect rect = self.rect() padding = self.padding() gantt = self.scene().ganttWidget() cell_w = gantt.cellWidth() cell_h = gantt.cellHeight() x = rect.width() - cell_w y = self.padding() w = cell_w h = rect.height() - padding - 2 # grab the color options color = self.color() alt_color = self.alternateColor() if (self.isSelected()): color = self.highlightColor() alt_color = self.alternateHighlightColor() # create the background brush gradient = QLinearGradient() gradient.setStart(0, 0) gradient.setFinalStop(0, h) gradient.setColorAt(0, color) gradient.setColorAt(0.8, alt_color) gradient.setColorAt(1, color) painter.setPen(self.borderColor()) painter.setBrush(QBrush(gradient)) pen = painter.pen() pen.setWidthF(0.5) painter.setPen(pen) painter.setRenderHint(painter.Antialiasing) path = QPainterPath() path.moveTo(x - cell_w / 3.0, y + h / 2.0) path.lineTo(x, y) path.lineTo(x + cell_w / 3.0, y + h / 2.0) path.lineTo(x, y + h) path.lineTo(x - cell_w / 3.0, y + h / 2.0) painter.drawPath(path)
def rebuildTiles(self): # create the foreground pixmap gantt = self.ganttWidget() header = gantt.treeWidget().header() width = self.sceneRect().width() height = header.height() # create the main color palette = gantt.palette() color = palette.color(palette.Button) textColor = palette.color(palette.ButtonText) borderColor = color.darker(140) text_align = Qt.AlignBottom | Qt.AlignHCenter # create the gradient gradient = QLinearGradient() gradient.setStart(0, 0) gradient.setFinalStop(0, height) gradient.setColorAt(0, color) gradient.setColorAt(1, color.darker(120)) # generate the tiles tiles = [] painters = [] for rect, label in self._topLabels: tile_rect = QRectF(rect.x(), 0, rect.width(), height) pixmap = QPixmap(rect.width(), height) with XPainter(pixmap) as painter: painter.setBrush(QBrush(gradient)) painter.drawRect(tile_rect) rx = 0 ry = 0 rw = rect.width() rh = rect.height() painter.setPen(borderColor) painter.drawRect(rx, ry, rw, rh) painter.setPen(textColor) painter.drawText(rx, ry, rw, rh - 2, text_align, label) tiles.append((tile_rect, pixmap)) painters.append((tile_rect, pixmap, painter)) # add bottom labels for rect, label in self._labels: for tile_rect, tile, painter in painters: if tile_rect.x() <= rect.x() and \ rect.right() <= tile_rect.right(): rx = rect.x() - tile_rect.x() ry = rect.y() rw = rect.width() rh = rect.height() with painter: painter.setPen(borderColor) painter.drawRect(rx, ry, rw, rh) painter.setPen(textColor) painter.drawText(rx, ry, rw, rh - 2, text_align, label) self._tiles = tiles
def __init__(self, parent=None): super(XGanttWidget, self).__init__(parent) # load the user interface projexui.loadUi(__file__, self) # define custom properties self._backend = None self._dateStart = QDate.currentDate().addMonths(-2) self._dateEnd = QDate.currentDate().addMonths(2) self._timeStart = QTime(0, 0, 0) self._timeEnd = QTime(23, 59, 59) self._alternatingRowColors = False self._cellWidth = 20 self._cellHeight = 20 self._first = True self._dateFormat = 'M/d/yy' self._timescale = XGanttWidget.Timescale.Month self._scrolling = False self._dirty = False # setup the palette colors palette = self.palette() color = palette.color(palette.Base) self._gridPen = QPen(color.darker(115)) self._brush = QBrush(color) self._alternateBrush = QBrush(color.darker(105)) weekendColor = color.darker(108) self._weekendBrush = QBrush(weekendColor) # setup the columns for the tree self.setColumns(['Name', 'Start', 'End', 'Calendar Days', 'Work Days']) header = self.uiGanttTREE.header() header.setFixedHeight(self._cellHeight * 2) headerItem = self.uiGanttTREE.headerItem() headerItem.setSizeHint(0, QSize(80, header.height())) # initialize the tree widget self.uiGanttTREE.setShowGrid(False) self.uiGanttTREE.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.uiGanttTREE.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.uiGanttTREE.setVerticalScrollMode(self.uiGanttTREE.ScrollPerPixel) self.uiGanttTREE.setResizeToContentsInteractive(True) self.uiGanttTREE.setEditable(True) self.uiGanttTREE.resize(500, 20) self.uiGanttTREE.setContextMenuPolicy(Qt.CustomContextMenu) # initialize the view widget self.uiGanttVIEW.setDragMode(self.uiGanttVIEW.RubberBandDrag) self.uiGanttVIEW.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.uiGanttVIEW.setAlignment(Qt.AlignTop | Qt.AlignLeft) self.uiGanttVIEW.setScene(XGanttScene(self)) self.uiGanttVIEW.installEventFilter(self) self.uiGanttVIEW.horizontalScrollBar().setValue(50) self.uiGanttVIEW.setContextMenuPolicy(Qt.CustomContextMenu) # create connections self.uiGanttTREE.itemExpanded.connect(self.syncView) self.uiGanttTREE.itemCollapsed.connect(self.syncView) # connect scrollbars tree_bar = self.uiGanttTREE.verticalScrollBar() view_bar = self.uiGanttVIEW.verticalScrollBar() tree_bar.rangeChanged.connect(self._updateViewRect) tree_bar.valueChanged.connect(self._scrollView) view_bar.valueChanged.connect(self._scrollTree) # connect selection self.uiGanttTREE.itemSelectionChanged.connect(self._selectView) self.uiGanttVIEW.scene().selectionChanged.connect(self._selectTree) self.uiGanttTREE.itemChanged.connect(self.updateItemData) self.uiGanttTREE.customContextMenuRequested.connect( self.requestTreeMenu) self.uiGanttVIEW.customContextMenuRequested.connect( self.requestViewMenu)
def paintNormal(self, painter): """ Paints this item as the normal look. :param painter | <QPainter> """ # generate the rect rect = self.rect() x = 0 y = self.padding() w = rect.width() h = rect.height() - (2 * self.padding()) - 1 radius = self.borderRadius() # grab the color options color = self.color() alt_color = self.alternateColor() if (self.isSelected()): color = self.highlightColor() alt_color = self.alternateHighlightColor() # create the background brush gradient = QLinearGradient() gradient.setStart(0, 0) gradient.setFinalStop(0, h) gradient.setColorAt(0, color) gradient.setColorAt(0.8, alt_color) gradient.setColorAt(1, color) painter.setPen(self.borderColor()) if (radius): painter.setRenderHint(painter.Antialiasing) pen = painter.pen() pen.setWidthF(0.5) painter.setPen(pen) painter.setBrush(QBrush(gradient)) painter.drawRoundedRect(x, y, w, h, radius, radius) # create the progress brush if (self.showProgress()): gradient = QLinearGradient() gradient.setStart(0, 0) gradient.setFinalStop(0, h) gradient.setColorAt(0, self.progressColor()) gradient.setColorAt(0.8, self.alternateProgressColor()) gradient.setColorAt(1, self.progressColor()) prog_w = (w - 4) * (self._percentComplete / 100.0) radius -= 2 painter.setPen(Qt.NoPen) painter.setBrush(QBrush(gradient)) painter.drawRoundedRect(x + 2, y + 2, prog_w, h - 4, radius, radius) # draw the text on this item if (self.text()): painter.setPen(self.textColor()) painter.drawText(x, y, w, h, Qt.AlignCenter, self.text())
def paintGroup(self, painter): """ Paints this item as the group look. :param painter | <QPainter> """ # generate the rect rect = self.rect() padding = self.padding() gantt = self.scene().ganttWidget() cell_w = gantt.cellWidth() cell_h = gantt.cellHeight() x = 0 y = self.padding() w = rect.width() h = rect.height() - (padding + 1) # grab the color options color = self.color() alt_color = self.alternateColor() if (self.isSelected()): color = self.highlightColor() alt_color = self.alternateHighlightColor() # create the background brush gradient = QLinearGradient() gradient.setStart(0, 0) gradient.setFinalStop(0, h) gradient.setColorAt(0, color) gradient.setColorAt(0.8, alt_color) gradient.setColorAt(1, color) painter.setPen(self.borderColor()) painter.setBrush(QBrush(gradient)) pen = painter.pen() pen.setWidthF(0.5) painter.setPen(pen) painter.setRenderHint(painter.Antialiasing) path = QPainterPath() path.moveTo(x - cell_w / 4.0, y) path.lineTo(w + cell_w / 4.0, y) path.lineTo(w + cell_w / 4.0, y + h / 2.0) path.lineTo(w, h) path.lineTo(w - cell_w / 4.0, y + h / 2.0) path.lineTo(x + cell_w / 4.0, y + h / 2.0) path.lineTo(x, h) path.lineTo(x - cell_w / 4.0, y + h / 2.0) path.lineTo(x - cell_w / 4.0, y) painter.drawPath(path) # create the progress brush if (self.showProgress()): gradient = QLinearGradient() gradient.setStart(0, 0) gradient.setFinalStop(0, h) gradient.setColorAt(0, self.progressColor()) gradient.setColorAt(0.8, self.alternateProgressColor()) gradient.setColorAt(1, self.progressColor()) prog_w = (w - 4) * (self._percentComplete / 100.0) painter.setPen(Qt.NoPen) painter.setBrush(QBrush(gradient)) painter.drawRect(x, y, prog_w, y + h / 2.0) # draw the text on this item if (self.text()): painter.setPen(self.textColor()) painter.drawText(x, y, w, h, Qt.AlignCenter, self.text())