def draw_ticks(self, painter): # needs some performance polishing !!! xmin, xmax = self.proj.get_in_range() ticks = num.arange(xmin, xmax + self.xtick_increment, self.xtick_increment, dtype=num.int) ticks_proj = self.proj(ticks) + 180 line = qc.QLine(self.halfside * 0.9, 0, self.halfside, 0) subline = qc.QLine(self.halfside * 0.95, 0, self.halfside, 0) painter.save() font = painter.font() font.setPointSize(8) painter.setFont(font) text_box_with = 100 for i, degree in enumerate(ticks_proj): painter.save() if i % 5 == 0: rotate_rad = degree * d2r x = self.halfside * 0.8 * num.cos( rotate_rad) - text_box_with / 2 y = self.halfside * 0.8 * num.sin(rotate_rad) rect = qc.QRectF(x, y, text_box_with, text_box_with / 5) painter.drawText(rect, qc.Qt.AlignCenter, str(ticks[i])) painter.rotate(degree) painter.drawLine(line) else: painter.rotate(degree) painter.drawLine(subline) painter.restore() painter.restore()
def _GridLines(self, painter: QtGui.QPainter, rect: QtCore.QRectF): # * grid bounds left = int(math.floor(rect.left())) right = int(math.ceil(rect.right())) top = int(math.floor(rect.top())) bottom = int(math.ceil(rect.bottom())) fLeft = left - (left % self._gridSize) fTop = top - (top % self._gridSize) # * compute lines majorLine = [ QtCore.QLine(x, top, x, bottom) for x in range(fLeft, right, self._gridSize * self._lineSpacing) ] for y in range(fTop, bottom, self._gridSize * self._lineSpacing): majorLine.append(QtCore.QLine(left, y, right, y)) minorLines = [ QtCore.QLine(x, top, x, bottom) for x in range(fLeft, right, self._gridSize) ] for y in range(fTop, bottom, self._gridSize): minorLines.append(QtCore.QLine(left, y, right, y)) # * draw lines painter.setPen(self._penMajorLine) for line in majorLine: painter.drawLine(line) painter.setPen(self._penMinorLine) for line in minorLines: painter.drawLine(line)
def drawBackground(self, painter, rect): super().drawBackground(painter, rect) # here we create our grid left = int(math.floor(rect.left())) right = int(math.ceil(rect.right())) top = int(math.floor(rect.top())) bottom = int(math.ceil(rect.bottom())) first_left = left - (left % self.gridSize) first_top = top - (top % self.gridSize) # compute all lines to be drawn lines_light, lines_dark = [], [] for x in range(first_left, right, self.gridSize): if (x % (self.gridSize * self.gridSquares) != 0): lines_light.append(QtCore.QLine(x, top, x, bottom)) else: lines_dark.append(QtCore.QLine(x, top, x, bottom)) for y in range(first_top, bottom, self.gridSize): if (y % (self.gridSize * self.gridSquares) != 0): lines_light.append(QtCore.QLine(left, y, right, y)) else: lines_dark.append(QtCore.QLine(left, y, right, y)) # draw the lines painter.setPen(self._pen_light) painter.drawLines(*lines_light) painter.setPen(self._pen_dark) painter.drawLines(*lines_dark)
def drawBasicGrid(self, canvas, grid=True): canvas.drawLine(QtCore.QLine(-9999, 0, 9999, 0)) canvas.drawLine(QtCore.QLine(0, -9999, 0, 9999)) fromIter, toIter = -7, 7 gridSize = 20 if grid: for iterIndex in range(fromIter, toIter + 1): canvas.drawLine(QtCore.QLine(-9999, iterIndex * gridSize, 9999, iterIndex * gridSize)) canvas.drawLine(QtCore.QLine(iterIndex * gridSize, -9999, iterIndex * gridSize, 9999))
def paint(self, painter, option, widget): window = MyWindow() painter.save() painter.setPen(QtGui.QPen(QtCore.Qt.gray)) for n_lines in range(1, (window.length_scene // 50) + 1): painter.drawLine( QtCore.QLine(50 * n_lines, 0, 50 * n_lines, window.length_scene)) for n_lines in range(1, (window.width_scene // 50) + 1): painter.drawLine( QtCore.QLine(0, 50 * n_lines, window.length_scene, 50 * n_lines)) painter.restore()
def get_cross_lines(rect): ''' return two diagonals QtCore.QLine from a QtCore.QRect ''' line_1 = QtCore.QLine( QtCore.QPoint(rect.left(), rect.top()), QtCore.QPoint(rect.left() + rect.width(), rect.top() + rect.height())) line_2 = QtCore.QLine( QtCore.QPoint(rect.left(), rect.top() + rect.height()), QtCore.QPoint(rect.left() + rect.width(), rect.top())) return line_1, line_2
def generate_grid(self) -> Dict[str, List[QtCore.QLine]] or dict: """ creates grid lines and returns them :return: dict with "x" and "y" keys, which contain lists with QLine elements or empty dict if core size is None """ if not self.core_size: return {} lines_x = [] lines_y = [] for x in range(self.offset_left, self.core_size[0] + 1, self.step): lines_y.append(QtCore.QLine(x, 0, x, self.core_size[1])) for y in range(self.offset_top, self.core_size[1] + 1, self.step): lines_x.append(QtCore.QLine(0, y, self.core_size[0], y)) return {"x": lines_x, "y": lines_y}
def draw(self, painter: QtGui.QPainter): painter.drawLine( QtCore.QLine( self.center.to_v2().to_QPoint(), (self.point + self.center).to_v2().to_QPoint() ) ) painter.drawText((self.center + self.point).to_v2().to_QPoint() + QPoint(5, 5), self.label)
def gen_lines(self) -> List[QtCore.QLine]: ret = [] for connection in self.conn: a, b = connection A = (self.points[a-1] + v3(self.center)).to_v2().to_QPoint() B = (self.points[b-1] + v3(self.center)).to_v2().to_QPoint() ret.append(QtCore.QLine(A, B)) return ret
def _draw_scale(self, event): painter = QtGui.QPainter(self) brush = QtGui.QBrush() brush.setColor(self._black) brush.setStyle(Qt.SolidPattern) # Draw vertical line line = QtCore.QLine(self._left_padding - 14, self._upper_padding, self._left_padding - 14, self._lower_padding) painter.drawLine(line) # Draw end with label line = QtCore.QLine(self._left_padding - 30, self._upper_padding, self._left_padding - 14, self._upper_padding) painter.drawLine(line) rect = QtCore.QRect(self._left_padding - 70, self._upper_padding - 8, self._left_padding - 35, self._upper_padding + 5) painter.drawText(rect, Qt.AlignRight, "{}".format(self.max_value)) # Draw start with label line = QtCore.QLine(self._left_padding - 30, self._lower_padding, self._left_padding - 14, self._lower_padding) painter.drawLine(line) rect = QtCore.QRect(self._left_padding - 70, self._lower_padding - 8, self._left_padding - 35, self._lower_padding) painter.drawText(rect, Qt.AlignRight, "{}".format(self.min_value)) step_length = int( (self._lower_padding - self._upper_padding) / self.steps) step_length_value = round( ((self.max_value - self.min_value) / self.steps), 1) horizontal_x = self._upper_padding + step_length current_value = self.max_value - step_length_value for i in range(0, self.steps - 1): line = QtCore.QLine(self._left_padding - 30, horizontal_x, self._left_padding - 14, horizontal_x) painter.drawLine(line) rect = QtCore.QRect(self._left_padding - 70, horizontal_x - 8, self._left_padding - 35, self._lower_padding) painter.drawText(rect, Qt.AlignRight, "{}".format(round(current_value, 2))) horizontal_x += step_length current_value -= step_length_value painter.end()
def popolamentoDati(self, istanza): # Reset dei dati self.cancellaDati() # Generazione rettangoli colorati per ogni paziente for indicePaziente, paziente in enumerate(istanza): for esame in paziente: x = indicePaziente * self.scala + self.offsetx y = (5 - esame) * self.altezza + self.offsety self.rettangoli.append([ QtCore.QRect(QtCore.QPoint(x, y), QtCore.QSize(1 * self.scala, self.altezza)), self.colori[esame - 1] ]) # Label self.labels.append([ QtCore.QRect( QtCore.QPoint(x - self.labelx / 2 + self.scala / 2, self.compAssey + self.offsetLabelx), QtCore.QSize(self.labelx, self.labely)), str(indicePaziente + 1) ]) # Creazione assi cartesiani e labels asse y self.linee.append( QtCore.QLine( QtCore.QPoint(self.offsetx, self.compAssey), QtCore.QPoint( len(istanza) * self.scala + self.offsetx, self.compAssey))) self.linee.append( QtCore.QLine(QtCore.QPoint(self.offsetx, self.compAssey), QtCore.QPoint(self.offsetx, self.offsety))) for tipoEsame in range(1, 6): y = (5 - tipoEsame) * self.altezza + self.offsety self.labels.append([ QtCore.QRect( QtCore.QPoint(0 - (self.labelx - 50) / 2, y + ((self.altezza - self.labely) / 2)), QtCore.QSize(self.labelx, self.labely)), "Esame " + str(tipoEsame) ]) # Aggiornamento forzato widget self.update()
def get_flag_line(rect): ''' return a QtCore.QLine representing the woodstick of the MineSweeper Flag ''' point_1 = QtCore.QPoint(rect.left() + rect.width() // 3, rect.top() + (rect.height() // 10)) point_2 = QtCore.QPoint( rect.left() + rect.width() // 3, rect.top() + rect.height() - ((rect.height() // 10))) return QtCore.QLine(point_1, point_2)
def draw_lines(self): """ Draw the lines: iterates the _lines_base, and if COPYING_LINES, the iterate the_lines_new, finally draw the current line Returns: None """ new_pen = qg.QPen(qg.QColor(qc.Qt.red), 3, qc.Qt.SolidLine) adj_pen = qg.QPen(qg.QColor(qc.Qt.red), 3, qc.Qt.DashLine) old_pen = qg.QPen(qg.QColor.fromRgb(0, 230, 255), 3, qc.Qt.SolidLine) painter = qg.QPainter() height = self._background_pixmap.height() * self._current_zoom width = self._background_pixmap.width() * self._current_zoom pix = self._background_pixmap.scaled(width, height) painter.begin(pix) # make copy font = painter.font() font.setPointSize(font.pointSize() * 2) painter.setFont(font) # TODO make self._current_line the source for adjustments if self._display_line is not None: painter.setPen(old_pen) frames = self._display_line.frame_numbers for frame in frames: line_segment = self._display_line[frame] self.draw_single_line(line_segment, painter, str(frame)) if self._storage_state == StorageState.COPYING_LINES: painter.setPen(old_pen) for line in self._lines_base: self.draw_single_line(line, painter) painter.setPen(new_pen) for line in self._lines_new: self.draw_single_line(line, painter, str(self._current_frame)) else: painter.setPen(new_pen) for line in self._lines_base: self.draw_single_line(line, painter, str(self._current_frame)) if self._current_line is not None: painter.setPen(adj_pen) zoomed = self._current_line.scale(self._current_zoom) qt_line = qc.QLine( qc.QPoint(int(zoomed.start.x), int(zoomed.start.y)), qc.QPoint(int(zoomed.end.x), int(zoomed.end.y))) painter.drawLine(qt_line) painter.end() self.setPixmap(pix)
def mouseMoveEvent(self, event): if QtCore.QLineF(QtCore.QLine(event.screenPos(), event.buttonDownScreenPos(Qt.LeftButton))).length() \ > QtWidgets.QApplication.startDragDistance(): drag = QtGui.QDrag(event.widget()) sel = self.scene.selection() drag.setMimeData(selection.MimeData(sel)) if len(sel.wrappers()) == 1: drag.setPixmap(sel.wrappers()[0].element.getCover(100)) drag.setHotSpot(QtCore.QPoint(50, 50)) drag.exec_() self.setCursor(Qt.OpenHandCursor)
def paintEvent(self, _event): w = self.width() h = self.height() x = 8 # offset line y = 6 # offset line painter = QtGui.QPainter() painter.begin(self) painter.fillRect(0, 0, w, h, self.box_bg_color) painter.setPen(self.pen) painter.drawLine(QtCore.QLine(x, h - y, w - x, y)) painter.end()
def paintEvent(self, event): painter = QPainter() painter.begin(self) pixmap = QtGui.QPixmap() pixmap.load(self.map) painter.drawPixmap(0, 0, 1250, 800, pixmap) painter.setPen(QPen(Qt.red, 5, Qt.SolidLine)) for i in range(len(self.points)): painter.drawEllipse(self.points[i][0], self.points[i][1], 8, 8) if len(self.points) > 1: line = QtCore.QLine(QtCore.QPoint(self.points[i - 1][0], self.points[i - 1][1]), QtCore.QPoint(self.points[i][0], self.points[i][1])) painter.drawLine(line) if i > 0: painter.setBrush(QtGui.QBrush(QtGui.QColor(239, 8, 45, 100))) for j in range(self.ways[i]): temp_point = self.findStepLine(self.points[i - 1], self.points[i], j, self.height_poly[i]) painter.drawPolygon( self.createPolygon(4, math.sqrt(self.height_poly[i] ** 2 + self.height_poly[i] ** 2) / 2, # радіус рівний половині діагоналі self.angels[i], temp_point[0], temp_point[1], self.weight_poly[i] - self.height_poly[i])) if self.bool_end: a = self.points[len(self.points) - 2] b = self.points[len(self.points) - 1] c = self.points[0] vector_ba = b - a vector_bc = b - c mod_ba = np.linalg.norm(a - b) mod_bc = np.linalg.norm(c - b) scalar_ba_bc = np.dot(vector_ba, vector_bc) cos_b = scalar_ba_bc / (mod_ba * mod_bc) end_angel = -math.degrees(math.acos(cos_b)) + self.angels[len(self.angels) - 1] painter.setBrush(QtGui.QBrush(QtGui.QColor(239, 8, 45, 100))) for j in range(self.ways[0]): temp_point = self.findStepLine(self.points[len(self.points) - 1], self.points[0], j, self.height_poly[len(self.height_poly) - 1]) painter.drawPolygon( self.createPolygon(4, math.sqrt(self.height_poly[len(self.height_poly) - 1] ** 2 + self.height_poly[len(self.height_poly) - 1] ** 2) / 2, end_angel, temp_point[0], temp_point[1], self.weight_poly[len(self.weight_poly) - 1] - self.height_poly[len(self.height_poly) - 1])) if self.percent_bool_end: self.percentAfterWay(self.points[len(self.points) - 1], self.points[0]) self.percent_point[self.count] -= self.ways[0] * self.percent_per_photo self.percent.setText("Заряд дрона " + str(int(self.percent_point[len(self.percent_point) - 1])) + "%") self.percent_bool_end = False painter.end() self.update()
def paintEvent(self, event): qp = QPainter(self) if self.state == State.DRAW_ROI: self.display_text.setText("Select Region of Interest") # draw the frame qp.drawPixmap(getCorrectRatioRect(getCurrentFrameDims=False), self.currentFramePixmap) # draw the main ROI br = QBrush(QColor(0, 255, 0, 30)) qp.setBrush(br) qp.drawRect(QtCore.QRect(self.begin, self.end)) elif self.state == State.DRAW_CHIMNEY: self.display_text.setText("Select Entrance of Chimney") # draw the frame qp.drawPixmap(getCorrectRatioRect(getCurrentFrameDims=False), self.currentFramePixmap) # draw the main ROI roiBegin = QtCore.QPoint(mainROI[0], mainROI[1]) roiEnd = QtCore.QPoint(mainROI[0] + mainROI[2], mainROI[1] + mainROI[3]) br = QBrush(QColor(0, 255, 0, 30)) qp.setBrush(br) qp.drawRect(QtCore.QRect(roiBegin, roiEnd)) # draw the chimney line pen = QPen(Qt.red, 3) qp.setPen(pen) qp.drawLine(QtCore.QLine(self.begin, self.end)) elif self.state == State.RUNNING: self.display_text.setText("") if self.currentFramePixmap is not None: qp.drawPixmap(getCorrectRatioRect(), self.currentFramePixmap) else: self.display_text.setText( "The video is hidden, but we're still counting!") br = QBrush(QColor(255, 255, 255, 1)) qp.setBrush(br) qp.drawRect(self.rect()) elif self.state == State.VIDEO_ENDED: self.display_text.setText("Video Finished") br = QBrush(QColor(255, 255, 255, 1)) qp.setBrush(br) qp.drawRect(self.rect())
def draw_single_line(self, line, painter, label=None): """ draw a single line segment Args: line (int) the array index of the line painter (QPainter) the painter to be used for the drawing, with pen set label (string) a label for the line, default is None Returns: None """ zoomed = line.scale(self._current_zoom) qt_line = qc.QLine(qc.QPoint(int(zoomed.start.x), int(zoomed.start.y)), qc.QPoint(int(zoomed.end.x), int(zoomed.end.y))) painter.drawLine(qt_line) if self._show_labels and label is not None: self.draw_line_label(painter, zoomed, label)
def drag_magnet_checker(self, obj: TextWidget) -> Tuple[int, int, int, int, bool, bool, Dict[ TextWidget, Tuple[Union[Optional[int], Any], Union[Optional[int], Any]]]]: """ checks whether object has magnetic lines to other objects while moving :param obj: object for check :return: (x, y, width, height) of object, (x, y) was modified and dict with struct widget = (way by x line, way by y line) """ self.manager.magnet_lines = [] obj_x1 = obj.x() obj_y1 = obj.y() obj_x2 = obj_x1 + obj.geometry().width() obj_y2 = obj_y1 + obj.geometry().height() x_mod = y_mod = False # widget: x, y widgets = {} for widget in self.get_all_widgets(): way_x = way_y = None if widget == obj: continue x1, y1 = widget.geometry().x(), widget.geometry().y() x2, y2 = x1 + widget.geometry().width(), y1 + widget.geometry().height() if x1 - OFFSET_MAGNET <= obj_x1 <= x1 + OFFSET_MAGNET: obj_x1 = x1 way_y = (y2 + y1) // 2 x_mod = True self.manager.magnet_lines.append(QtCore.QLine( x1, (y1 + y2) // 2, x1, (obj_y1 + obj_y2) // 2 )) if x1 - OFFSET_MAGNET <= obj_x2 <= x1 + OFFSET_MAGNET: obj_x1 = x1 - obj.geometry().width() way_y = (y2 + y1) // 2 x_mod = True self.manager.magnet_lines.append(QtCore.QLine( x1, (y1 + y2) // 2, x1, (obj_y1 + obj_y2) // 2 )) if x2 - OFFSET_MAGNET <= obj_x1 <= x2 + OFFSET_MAGNET: obj_x1 = x2 way_y = (y2 + y1) // 2 x_mod = True self.manager.magnet_lines.append(QtCore.QLine( x2, (y1 + y2) // 2, obj_x1, (obj_y1 + obj_y2) // 2 )) if x2 - OFFSET_MAGNET <= obj_x2 <= x2 + OFFSET_MAGNET: obj_x1 = x2 - obj.geometry().width() way_y = (y2 + y1) // 2 x_mod = True self.manager.magnet_lines.append(QtCore.QLine( x2, (y1 + y2) // 2, x2, (obj_y1 + obj_y2) // 2 )) if (x1 + x2) // 2 - OFFSET_MAGNET <= (obj_x1 + obj_x2) // 2 \ <= (x1 + x2) // 2 + OFFSET_MAGNET: obj_x1 = (x1 + x2) // 2 - obj.geometry().width() // 2 way_y = (y2 + y1) // 2 x_mod = True self.manager.magnet_lines.append(QtCore.QLine( (x1 + x2) // 2, (y1 + y2) // 2, (x1 + x2) // 2, (obj_y1 + obj_y2) // 2 )) if y1 - OFFSET_MAGNET <= obj_y1 <= y1 + OFFSET_MAGNET: obj_y1 = y1 way_x = (x2 + x1) // 2 y_mod = True self.manager.magnet_lines.append(QtCore.QLine( (x1 + x2) // 2, y1, (obj_x1 + obj_x2) // 2, y1 )) if y1 - OFFSET_MAGNET <= obj_y2 <= y1 + OFFSET_MAGNET: obj_y1 = y1 - obj.geometry().height() way_x = (x2 + x1) // 2 y_mod = True self.manager.magnet_lines.append(QtCore.QLine( (x1 + x2) // 2, y1, (obj_x1 + obj_x2) // 2, y1 )) if y2 - OFFSET_MAGNET <= obj_y1 <= y2 + OFFSET_MAGNET: obj_y1 = y2 way_x = (x2 + x1) // 2 y_mod = True self.manager.magnet_lines.append(QtCore.QLine( (x1 + x2) // 2, y2, (obj_x1 + obj_x2) // 2, y2 )) if y2 - OFFSET_MAGNET <= obj_y2 <= y2 + OFFSET_MAGNET: obj_y1 = y2 - obj.geometry().height() way_x = (x2 + x1) // 2 y_mod = True self.manager.magnet_lines.append(QtCore.QLine( (x1 + x2) // 2, y2, (obj_x1 + obj_x2) // 2, y2 )) if (y1 + y2) // 2 - OFFSET_MAGNET <= (obj_y1 + obj_y2) // 2 \ <= (y1 + y2) // 2 + OFFSET_MAGNET: obj_y1 = (y1 + y2) // 2 - obj.geometry().height() // 2 way_x = (x2 + x1) // 2 y_mod = True self.manager.magnet_lines.append(QtCore.QLine( (x1 + x2) // 2, (y1 + y2) // 2, (obj_x1 + obj_x2) // 2, (y1 + y2) // 2 )) if way_y or way_x: widgets[widget] = way_x, way_y return obj_x1, obj_y1, obj_x2, obj_y2, x_mod, y_mod, widgets
def decay_crv(self): pt_1 = self.attack_pt pt_2 = self.decay_pt return QtCore.QLine(pt_1, pt_2)
def mouseReleaseEvent(self, event): self.end = event.pos() self.update() if self.toolkit.switch == 0 and self.sel_rect \ and event.buttons() == QtCore.Qt.LeftButton: self.scene_sel.setRect(self.begin.x(), self.begin.y(), self.end.x() - self.begin.x(), self.end.y() - self.begin.y()) self.paint_allowed = False elif self.toolkit.switch == 0: self.paint_allowed = False if not self.paint_allowed: return self.paint_allowed = False if self.begin == self.end: return if self.toolkit.switch == 6: self.scene_sel.setRect(self.begin.x(), self.begin.y(), self.end.x() - self.begin.x(), self.end.y() - self.begin.y()) rectwidth, rectheight, rectx, recty = (self.sel_rect.width(), self.sel_rect.height(), self.sel_rect.x(), self.sel_rect.y()) if "-" in str(rectwidth): rectx = rectx + rectwidth rectwidth = abs(rectwidth) if "-" in str(rectheight): recty = recty + rectheight rectheight = abs(rectheight) tmp = self.crop(self.pixmap().toImage()) blurred = QtGui.QImage(tmp.size(), QtGui.QImage.Format_ARGB32_Premultiplied) blurred.fill(QtGui.QColor('transparent')) painter = QPainter(blurred) painter.setRenderHint(QPainter.HighQualityAntialiasing) painter.setRenderHint(QPainter.SmoothPixmapTransform) ctypes_blur(painter, tmp, 45, True, False) painter.end() dest = QtGui.QPixmap().fromImage(blurred) painter = QPainter(self.pixmap()) painter.setRenderHint(QPainter.HighQualityAntialiasing) self.history.sequence += 'b' for _ in range(6): painter.drawPixmap(rectx, recty, rectwidth + 1, rectheight + 1, dest) self.history.blur.append( [rectx, recty, rectwidth, rectheight, dest]) painter.end() self.update() self.begin = QtCore.QPoint() self.end = QtCore.QPoint() self.sel_rect = None self.scene_sel.setRect(0, 0, 0, 0) self.scene_px.setPixmap(self.pixmap()) self.pixel_data = self.pixmap().toImage() return painter = QPainter(self.pixmap()) painter.setRenderHint(QPainter.HighQualityAntialiasing) brush, pen, pen_outline = self.get_drawing_pen() painter.setBrush(brush) painter.setPen(pen) rect = self.build_rect() if self.toolkit.switch == 5: self.build_path() if not self.path: return self.history.sequence += 'f' self.history.free.append((self.path, pen, brush, pen_outline)) if pen_outline: painter.setPen(pen_outline) painter.drawPath(self.path) painter.setPen(pen) painter.drawPath(self.path) self.pen_cords_track_list = [] self.scene_px.setPixmap(self.pixmap()) self.pixel_data = self.pixmap().toImage() self.update() return # draw on pixmap if self.toolkit.switch == 2: self.history.sequence += 'c' self.history.circle.append((rect, pen, brush, pen_outline)) if pen_outline: painter.setPen(pen_outline) painter.drawEllipse(rect) painter.setPen(pen) painter.drawEllipse(rect) elif self.toolkit.switch == 3: self.history.sequence += 'r' self.history.rect.append((rect, pen, brush, pen_outline)) if pen_outline: painter.setPen(pen_outline) painter.drawRect(rect) painter.setPen(pen) painter.drawRect(rect) elif self.toolkit.switch == 4: self.history.sequence += 'l' line = QtCore.QLine(self.begin.x(), self.begin.y(), self.end.x(), self.end.y()) if self.quadratic: line = QtCore.QLineF(self.begin.x(), self.begin.y(), self.end.x(), self.end.y()) angle = self.line_align(line.angle()) line.setAngle(angle) self.history.line.append(((line.x1(), line.y1(), line.x2(), line.y2()), pen, brush, pen_outline)) if pen_outline: painter.setPen(pen_outline) painter.drawLine(line) painter.setPen(pen) painter.drawLine(line) self.begin = QtCore.QPoint() self.end = QtCore.QPoint() self.scene_px.setPixmap(self.pixmap()) self.pixel_data = self.pixmap().toImage() self.update()
def paintEvent(self, event=None): ''' draws the widget - recalled at any point by instance.update() ''' if len(self.dents) == 0: return # blank widget if no dents working self.dragLine = None painter = QtGui.QPainter(self) painter.setBrush(BGCOLOR) currentSlot = 0 self.font.setPointSize(localsettings.appointmentFontSize) fm = QtGui.QFontMetrics(self.font) painter.setFont(self.font) self.timeOffset = fm.width(" 88:88 ") self.headingHeight = fm.height() self.slotHeight = (self.height() - self.headingHeight) / self.slotCount columnCount = len(self.dents) if columnCount == 0: columnCount = 1 # avoid division by zero!! columnWidth = (self.width() - self.timeOffset) / columnCount # put the times down the side while currentSlot < self.slotCount: # offset the first time. if (currentSlot + 2) % self.textDetail == 0: y = 0.8 * self.headingHeight + currentSlot * self.slotHeight trect = QtCore.QRectF(0, y, self.timeOffset, self.textDetail * self.slotHeight) painter.setPen(BLACK_PEN) slot_time = self.startTime + currentSlot * self.slotLength painter.drawText(trect, QtCore.Qt.AlignHCenter, localsettings.humanTime(slot_time)) currentSlot += 1 col = 0 highlighted_rect = None highlighted_rects = [] for dent in self.dents: leftx = self.timeOffset + col * columnWidth rightx = self.timeOffset + (col + 1) * columnWidth # headings painter.setPen(BLACK_PEN) painter.setBrush(APPTCOLORS["HEADER"]) rect = QtCore.QRectF(leftx, 0, columnWidth, self.headingHeight) painter.drawRoundedRect(rect, 5, 5) initials = localsettings.apptix_reverse.get(dent.ix) if dent.memo != "": initials = "*%s*" % initials painter.drawText(rect, QtCore.Qt.AlignHCenter, initials) # dentist start/finish painter.setBrush(BGCOLOR) startcell = ((self.daystart[dent.ix] - self.startTime) / self.slotLength) length = self.dayend[dent.ix] - self.daystart[dent.ix] startY = startcell * self.slotHeight + self.headingHeight endY = (length / self.slotLength) * self.slotHeight rect = QtCore.QRectF(leftx, startY, columnWidth, endY) if self.flagDict[dent.ix]: # don't draw a white canvas if dentist is out of office # a white canvas painter.save() painter.drawRect(rect) # grey lines painter.setPen(GREYLINE_PEN) y = startY while y < startY + endY: painter.drawLine(leftx, y, rightx, y) y += self.slotHeight / 2 painter.restore() painter.setPen(BLACK_PEN) # emergencies for appt in self.eTimes[dent.ix]: painter.save() if (self.daystart[dent.ix] <= appt.mpm < self.dayend[dent.ix]): startcell = (appt.mpm - self.startTime) / self.slotLength rect = QtCore.QRectF( leftx, startcell * self.slotHeight + self.headingHeight, columnWidth, (appt.length / self.slotLength) * self.slotHeight) if self.mode == self.SCHEDULING_MODE: painter.setBrush(APPTCOLORS["BUSY"]) painter.setPen(GREY_PEN) elif appt.isEmergency: painter.setBrush(APPTCOLORS["EMERGENCY"]) elif appt.name.upper() in APPTCOLORS: painter.setBrush(APPTCOLORS[appt.name.upper()]) # elif appt.cset in APPTCOLORS: # painter.setBrush(APPTCOLORS[appt.cset]) else: painter.setBrush(APPTCOLORS["default"]) painter.drawRect(rect) text = appt.name[:5] if len(text) < len(appt.name): text += ".." painter.drawText(rect, QtCore.Qt.AlignLeft, text) painter.restore() painter.save() painter.setBrush(APPTCOLORS["LUNCH"]) for appt in self.lunches[dent.ix]: if (self.daystart[dent.ix] <= appt.mpm < self.dayend[dent.ix]): startcell = \ (appt.mpm - self.startTime) / self.slotLength rect = QtCore.QRectF( leftx, startcell * self.slotHeight + self.headingHeight, columnWidth, (appt.length / self.slotLength) * self.slotHeight) if self.mode == self.SCHEDULING_MODE: painter.setPen(GREY_PEN) else: painter.setPen(BLACK_PEN) painter.drawRect(rect) painter.drawText(rect, _("Lunch"), CENTRE_OPTION) painter.restore() # appts for appt in self.appts[dent.ix]: if (self.diary_widget.pt and appt.serialno == self.diary_widget.pt.serialno): painter.setBrush(APPTCOLORS["current_patient"]) elif self.mode == self.SCHEDULING_MODE: painter.setPen(GREY_PEN) painter.setBrush(APPTCOLORS["BUSY"]) elif appt.name.upper() in APPTCOLORS: painter.setBrush(APPTCOLORS[appt.name.upper()]) elif appt.cset in APPTCOLORS: painter.setBrush(APPTCOLORS[appt.cset]) else: painter.setBrush(APPTCOLORS["BUSY"]) startcell = (appt.mpm - self.startTime) / self.slotLength rect = QtCore.QRectF( leftx, startcell * self.slotHeight + self.headingHeight, columnWidth, (appt.length / self.slotLength) * self.slotHeight) painter.drawRoundedRect(rect, 5, 5) text = appt.trt[:5] if len(text) < len(appt.trt): text += ".." painter.drawText(rect, text, CENTRE_OPTION) h_app = self.diary_widget.highlighted_appointment if h_app: # print h_app, appt if appt.serialno == h_app.serialno: appt.apptix = dent.ix if h_app == appt: highlighted_rect = rect else: highlighted_rects.append(rect) # slots painter.save() for slot in self.freeslots.get(dent.ix, []): slotstart = localsettings.pyTimeToMinutesPastMidnight( slot.date_time.time()) startcell = (slotstart - self.startTime) / self.slotLength rect = QtCore.QRectF( leftx, startcell * self.slotHeight + self.headingHeight, columnWidth, (slot.length / self.slotLength) * self.slotHeight) if slot.is_primary: brush = APPTCOLORS["SLOT"] else: brush = APPTCOLORS["SLOT2"] if slot in self.active_slots: painter.setPen(BIG_RED_PEN) if self.blink_on: painter.setOpacity(1) else: painter.setOpacity(0.3) else: painter.setPen(RED_PEN) painter.setOpacity(0.6) painter.setBrush(brush) painter.drawRoundedRect(rect.adjusted(1, 0, -1, 0), 5, 5) painter.setOpacity(1) painter.drawText(rect, QtCore.Qt.AlignCenter, "%s" % slot.length) painter.restore() # drag drop if (self.is_dragging and self.mouse_drag_rect[0] == dent.ix): painter.save() rect = self.mouse_drag_rect[1] painter.setBrush(APPTCOLORS["ACTIVE_SLOT"]) painter.drawRect(rect) painter.setPen(RED_PEN) height = (self.drag_appt.length / self.slotLength) \ * self.slotHeight rect = QtCore.QRectF(leftx, self.dropPos.y(), columnWidth - 1, height) painter.drawRect(rect) self.dragLine = QtCore.QLine(0, self.dropPos.y(), self.width(), self.dropPos.y()) trect = QtCore.QRectF(0, self.dropPos.y(), self.timeOffset, height) painter.drawRect(trect) painter.drawText(trect, QtCore.Qt.AlignHCenter, localsettings.humanTime(self.drop_time())) painter.restore() if col > 0: painter.save() painter.setPen(BLACK_PEN) painter.drawLine(leftx, 0, leftx, self.height()) painter.restore() col += 1 painter.setBrush(TRANSPARENT) if self.selected_rect is not None: painter.setPen(ORANGE_PEN) painter.drawRoundedRect(self.selected_rect, 5, 5) if highlighted_rect: painter.setPen(BIG_RED_PEN) painter.drawRect(highlighted_rect.adjusted(2, 0, -2, 0)) for h_rect in highlighted_rects: painter.setPen(RED_PEN) painter.drawRect(h_rect) if self.dragLine: painter.setPen(RED_PEN) painter.drawLine(self.dragLine)
def attack_crv(self): pt_1 = self.start_pt pt_2 = self.attack_pt return QtCore.QLine(pt_1, pt_2)
def release_crv(self): pt_1 = self.sustain_pt pt_2 = self.release_pt return QtCore.QLine(pt_1, pt_2)
def popolamentoDati(self, soluzione): # Reset dati self.cancellaDati() # Generazione rettangoli colorati con etichette e valori di riferimento for paziente in soluzione.pazienti.values(): for tipo, start in paziente.esami.items(): x = start.valore * self.scala + self.offsetx y = (2 - paziente.ambulatorio) * self.altezza + self.offsety # Aggiunta rettangolo self.rettangoli.append([ QtCore.QRect( QtCore.QPoint(x, y), QtCore.QSize( getattr(self.config, "durata" + str(tipo)) * self.scala, self.altezza)), self.colori[tipo - 1] ]) # Aggiunta labels if start.valore not in self.valoriUsati: self.labels.append([ QtCore.QRect( QtCore.QPoint(x - 25, self.compAssey + self.offsetLabely), QtCore.QSize(50, 20)), str(start.valore) ]) self.linee.append( QtCore.QLine( QtCore.QPoint(x, self.compAssey), QtCore.QPoint(x, self.compAssey + self.offsetLabely))) self.valoriUsati.append(start.valore) if start.valore + getattr(self.config, "durata" + str(tipo)) not in self.valoriUsati: xFine = (start.valore + getattr(self.config, "durata" + str(tipo))) * self.scala + self.offsetx self.labels.append([ QtCore.QRect( QtCore.QPoint(xFine - 25, self.compAssey + self.offsetLabely), QtCore.QSize(50, 20)), str(start.valore + getattr(self.config, "durata" + str(tipo))) ]) self.linee.append( QtCore.QLine( QtCore.QPoint(xFine, self.compAssey), QtCore.QPoint(xFine, self.compAssey + self.offsetLabely))) self.valoriUsati.append(start.valore + getattr(self.config, "durata" + str(tipo))) # Label raffigurante id paziente e tipo di job self.labels.append([ QtCore.QRect( QtCore.QPoint(x, y), QtCore.QSize( getattr(self.config, "durata" + str(tipo)) * self.scala, self.altezza)), "P" + str(paziente.id) + " - E" + str(tipo) ]) self.linee.append( QtCore.QLine( QtCore.QPoint(self.offsetx, self.compAssey), QtCore.QPoint(soluzione.makeSpan * self.scala + self.offsetx, self.compAssey))) self.linee.append( QtCore.QLine(QtCore.QPoint(self.offsetx, self.compAssey), QtCore.QPoint(self.offsetx, self.offsety))) # Aggiornamento forzato widget self.update()
def to_QLine( self, offset: QtCore.QPoint = QtCore.QPoint(0, 0)) -> QtCore.QLine: return QtCore.QLine(self.A.to_QPoint() + offset, self.B.to_QPoint() + offset)
def drawLine(self, colour, width, x1, y1, x2, y2): painter = QtGui.QPainter(self) painter.setPen(QtGui.QPen(colour, width)) brush = QtGui.QBrush() painter.setBrush(brush) painter.drawLine(QtCore.QLine(x1, y1, x2, y2))
def sustain_crv(self): pt_1 = self.decay_pt pt_2 = self.sustain_pt return QtCore.QLine(pt_1, pt_2)
def extract_midline(screen): return QtCore.QLine( QtCore.QPoint(int(screen.center().x()), 0), QtCore.QPoint(int(screen.center().x()), int(screen.height())))