def panel_palette(old_palette, light_colored=False): if light_colored: color = theme.get_color('PanelTextColorDark') else: color = theme.get_color('PanelTextColorLight') pal = old_palette pal.setBrush(QPalette.All, QPalette.WindowText, color) pal.setBrush(QPalette.All, QPalette.ButtonText, color) return pal
def __init__(self): super(RunWidget, self).__init__() vbox = QVBoxLayout(self) vbox.setSpacing(0) vbox.setContentsMargins(0, 0, 0, 0) self.output = OutputWidget(self) # Button Widgets self._btn_zoom_in = QToolButton() self._btn_zoom_in.setIcon( ui_tools.colored_icon(':img/plus', theme.get_color('IconBaseColor'))) self._btn_zoom_in.setToolTip('Zoom In') self._btn_zoom_in.clicked.connect(self.output.zoomIn) self._btn_zoom_out = QToolButton() self._btn_zoom_out.setIcon( ui_tools.colored_icon(':img/minus', theme.get_color('IconBaseColor'))) self._btn_zoom_out.setToolTip('Zoom Out') self._btn_zoom_out.clicked.connect(self.output.zoomOut) self._btn_clean = QToolButton() self._btn_clean.setIcon( ui_tools.colored_icon(':img/clean', theme.get_color('IconBaseColor'))) self._btn_clean.setToolTip('Clear Output') self._btn_stop = QToolButton() self._btn_stop.setIcon(ui_tools.colored_icon(':img/stop', '#d74044')) self._btn_stop.setToolTip('Stop Running Program') self._btn_stop.clicked.connect(self.kill_process) hbox = QHBoxLayout() hbox.setContentsMargins(5, 0, 0, 0) self.input = QLineEdit() self.label_input = QLabel(self.tr("Input: ")) self.input.hide() self.label_input.hide() vbox.addWidget(self.output) hbox.addWidget(self.label_input) hbox.addWidget(self.input) vbox.addLayout(hbox) self.set_font(settings.FONT) # Process self._process = RunProcess(self) self._process.processStarted.connect(self._on_process_started) self._process.processFinished.connect(self._on_process_finished) self._process.stdoutAvailable.connect(self._on_stdout_available) self._process.errorAvailable.connect(self._on_error_available) self.input.returnPressed.connect(self.insert_input)
def __init__(self, parent=None): super().__init__(parent) # Button widgets self._btn_clean = QToolButton() self._btn_clean.setIcon( ui_tools.colored_icon( ':img/clean', theme.get_color('IconBaseColor'))) self._btn_clean.clicked.connect(self._clear_results) container = QHBoxLayout(self) container.setContentsMargins(3, 0, 3, 0) self._actions = FindInFilesActions(self) container.addWidget(self._actions) self._tree_results = SearchResultTreeView(self) container.addWidget(self._tree_results) self._main_container = IDE.get_service("main_container") # Search worker self._search_worker = FindInFilesWorker() self._search_thread = QThread() self._search_worker.moveToThread(self._search_thread) self._search_worker.finished.connect(self._on_worker_finished) # self._search_thread.finished.connect(self._search_worker.deleteLater) self._actions.searchRequested.connect(self._on_search_requested) self._tree_results.activated.connect(self._go_to)
def paintEvent(self, event): fm = self.fontMetrics() base_line = (self.height() - fm.height()) / 2 + fm.ascent() number_width = fm.width(self._number) painter = QPainter(self) opt = QStyleOption() opt.initFrom(self) hovered = opt.state & QStyle.State_MouseOver c = theme.get_color('ToolButtonColor') if hovered: c = theme.get_color('ToolButtonHover') elif self.isDown() or self.isChecked(): c = QColor('#66000000') painter.fillRect(self.rect(), c) painter.setPen(theme.get_color('ToolButtonTextColor')) # Draw shortcut number painter.drawText((15 - number_width) / 2, base_line, self._number) # Draw display name of tool button painter.drawText( 18, base_line, fm.elidedText(self._text, Qt.ElideRight, self.width()))
def paintEvent(self, event): painter = QPainter(self) painter.fillRect(event.rect(), theme.get_color('Splitter'))
def __init__(self, main_combo=False): super(ActionBar, self).__init__() # self.setObjectName("actionbar") self.setProperty('gradient', True) hbox = QHBoxLayout(self) hbox.setContentsMargins(0, 0, 0, 0) hbox.setSpacing(0) # self.lbl_checks = QLabel('') # self.lbl_checks.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) # self.lbl_checks.setFixedWidth(48) # self.lbl_checks.setVisible(False) # hbox.addWidget(self.lbl_checks) self.combo_files = ComboFiles() # self.combo_files = QComboBox() self.combo_files.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.combo_files.setProperty("border", True) self.combo_files.setProperty("gradient", True) self.combo_files.setSizeAdjustPolicy( QComboBox.AdjustToMinimumContentsLengthWithIcon) self.combo_files.setMaximumWidth(300) self.combo_files.currentIndexChanged[int].connect(self.current_changed) self.combo_files.setToolTip(translations.TR_COMBO_FILE_TOOLTIP) self.combo_files.setContextMenuPolicy(Qt.CustomContextMenu) self.combo_files.customContextMenuRequested.connect( self._context_menu_requested) hbox.addWidget(self.combo_files) self.symbols_combo = QComboBox() self.symbols_combo.setProperty("border", True) self.symbols_combo.setProperty("gradient", True) self.symbols_combo.setSizeAdjustPolicy( QComboBox.AdjustToMinimumContentsLengthWithIcon) self.symbols_combo.setObjectName("combo_symbols") self.symbols_combo.activated[int].connect(self.current_symbol_changed) hbox.addWidget(self.symbols_combo) # Code Navigator actions self.code_navigator = CodeNavigator() hbox.addWidget(self.code_navigator) # Image Viewer actions self.image_viewer_controls = ImageViewerControls() self.image_viewer_controls.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.image_viewer_controls.setVisible(False) hbox.addWidget(self.image_viewer_controls) self._pos_text = "Line: %d, Col: %d" self.lbl_position = QLabel() self.lbl_position.setProperty("gradient", True) self.lbl_position.setText(self._pos_text % (0, 0)) margin = self.style().pixelMetric( QStyle.PM_LayoutHorizontalSpacing) / 2 self.lbl_position.setContentsMargins(margin, 0, margin, 0) self.lbl_position.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox.addWidget(self.lbl_position) self.btn_close = QToolButton() self.btn_close.setProperty("gradient", True) if main_combo: self.btn_close.setIcon( ui_tools.colored_icon(':img/close', theme.get_color('IconBaseColor'))) self.btn_close.setToolTip(translations.TR_CLOSE_FILE) self.btn_close.clicked.connect(self.about_to_close_file) else: self.btn_close.setIcon( ui_tools.colored_icon(':img/close', "#ff9222")) self.btn_close.setToolTip(translations.TR_CLOSE_SPLIT) self.btn_close.clicked.connect(self.close_split) self.btn_close.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox.addWidget(self.btn_close) # Added for set language self._setter_language = set_language.SetLanguageFile()
def drawControl(self, element, opt, painter, widget): """elif element == QStyle.CE_PushButtonBevel: # States is_down = (opt.state & STATE_SUNKEN) | (opt.state & STATE_ON) hovered = opt.state & STATE_ENABLED and opt.state & STATE_MOUSEOVER has_focus = opt.state & STATE_HASFOCUS rect = opt.rect btn_color = opt.palette.button().color() painter.setPen(btn_color) painter.setRenderHint(QPainter.Antialiasing) path = QPainterPath() path.addRoundedRect(QRectF(rect), 3, 3) if is_down: painter.setBrush(btn_color.darker(115)) elif has_focus: painter.setBrush(btn_color.lighter(130)) elif hovered: grad = QLinearGradient(rect.topLeft(), rect.bottomLeft()) grad.setColorAt(0.6, btn_color) grad.setColorAt(1, btn_color.lighter(120)) painter.setBrush(grad) else: painter.setBrush(btn_color) painter.drawPath(path)""" if element == QStyle.CE_ComboBoxLabel: cb = opt painter.save() edit_rect = self.subControlRect(QStyle.CC_ComboBox, cb, QStyle.SC_ComboBoxEditField, widget) # Draw icon if not cb.currentIcon.isNull(): if cb.state & STATE_ENABLED: mode = QIcon.Normal else: mode = QIcon.Disabled pixmap = cb.currentIcon.pixmap(cb.iconSize, mode) icon_rect = QRect(cb.rect) icon_rect.setWidth(cb.iconSize.width() + 4) # icon_rect = self.alignedRect(opt.direction, # Qt.AlignLeft | Qt.AlignVCenter, # icon_rect.size(), edit_rect) self.drawItemPixmap(painter, icon_rect, Qt.AlignCenter, pixmap) # Space between text if cb.direction == Qt.RightToLeft: edit_rect.translate(-4, -cb.iconSize.width(), 0) else: edit_rect.translate(cb.iconSize.width() + 4, 0) edit_rect.adjusted(0, 0, -13, 0) # Draw text elide_width = edit_rect.width() - opt.fontMetrics.width('**') text = opt.fontMetrics.elidedText(cb.currentText, Qt.ElideRight, elide_width) # FIXME: states painter.setPen(theme.get_color('ComboBoxTextColor')) painter.drawText(edit_rect.adjusted(1, 0, -1, 0), Qt.AlignLeft | Qt.AlignVCenter, text) painter.restore() # TODO: tab with flat style # elif element == QStyle.CE_TabBarTabShape: # pass elif element == QStyle.CE_ToolBar: rect = opt.rect color = theme.get_color('ToolButtonColor') if widget.property('gradient') and not theme.flag("FlatComboBox"): base = QColor(theme.get_color('Window')) color = QLinearGradient(opt.rect.topRight(), opt.rect.bottomRight()) color.setColorAt(0.2, base.lighter(150)) color.setColorAt(0.9, base.darker(135)) # print(widget.property("border"), widget) painter.fillRect(rect, color) if widget.property("border"): # painter.setPen(opt.palette.light().color().lighter(150)) painter.setPen(theme.get_color('Border')) painter.drawLine(rect.topRight(), rect.bottomRight()) # painter.setPen(theme.get_color(Border']) # painter.drawLine(opt.rect.topRight(), opt.rect.bottomRight()) elif element == QStyle.CE_MenuItem: painter.save() enabled = opt.state & STATE_ENABLED item = opt item.rect = opt.rect pal = opt.palette if enabled: color = theme.get_color('MenuItemEnabled') else: color = theme.get_color('MenuItemDisabled') item.palette = pal pal.setBrush(QPalette.Text, color) QProxyStyle.drawControl(self, element, opt, painter, widget) painter.restore() elif element == QStyle.CE_MenuBarEmptyArea: painter.fillRect(opt.rect, theme.get_color('MenuBar')) # Draw border painter.save() # FIXME: color from theme painter.setPen(theme.get_color('MenuBarBorderColor')) painter.drawLine(opt.rect.bottomLeft() + QPointF(.5, .5), opt.rect.bottomRight() + QPointF(.5, .5)) painter.restore() # elif element == QStyle.CE_PushButtonBevel: # painter.setPen(Qt.red) # painter.fillRect(opt.rect, QColor("red")) elif element == QStyle.CE_MenuBarItem: painter.save() act = opt.state & (STATE_SUNKEN | QStyle.State_Selected) dis = not (opt.state & STATE_ENABLED) painter.fillRect(opt.rect, theme.get_color('MenuBar')) pal = opt.palette item = opt item.rect = opt.rect if dis: color = theme.get_color('MenuBarItemDisabled') else: color = theme.get_color('MenuBarItemEnabled') pal.setBrush(QPalette.ButtonText, color) item.palette = pal QCommonStyle.drawControl(self, element, item, painter, widget) if act: pal = opt.palette color = theme.get_color('MenuBarHover') painter.fillRect(opt.rect, color) align = (Qt.AlignCenter | Qt.TextShowMnemonic | Qt.TextDontClip | Qt.TextSingleLine) if not self.styleHint(QStyle.SH_UnderlineShortcut, opt, widget): align |= Qt.TextHideMnemonic # FIXME: if dis: co = theme.get_color('IconDisabledColor') else: co = theme.get_color('MenuBarTextHover') painter.setPen(Qt.NoPen) pal.setBrush(QPalette.Text, co) self.drawItemText(painter, item.rect, align, pal, not dis, opt.text, QPalette.Text) painter.restore() else: QProxyStyle.drawControl(self, element, opt, painter, widget)
def drawPrimitive(self, element, opt, painter, widget): if not self.__panel_widget(widget): return QProxyStyle.drawPrimitive(self, element, opt, painter, widget) if element == QStyle.PE_PanelButtonTool: flat = theme.flag("FlatComboBox") pressed = (opt.state & STATE_SUNKEN or opt.state & STATE_ON) hovered = opt.state & STATE_ENABLED and opt.state & STATE_MOUSEOVER button_color = theme.get_color('ToolButtonColor') if not flat and widget.property("gradient"): base = QColor(theme.get_color('Window')) button_color = QLinearGradient(opt.rect.topRight(), opt.rect.bottomRight()) button_color.setColorAt(0.2, base.lighter(150)) button_color.setColorAt(0.9, base.darker(135)) if pressed: button_color = theme.get_color('ToolButtonSelected') elif hovered: if not flat and widget.property("gradient"): button_color.setColorAt(0.2, base.lighter(160)) button_color.setColorAt(0.9, base.darker(100)) else: button_color = theme.get_color('ToolButtonHover') if widget.property("border_bottom"): painter.setPen(theme.get_color('Border')) painter.drawLine(opt.rect.bottomLeft(), opt.rect.bottomRight()) painter.fillRect(opt.rect.adjusted(1, 1, -1, -1), button_color) # elif not opt.state & STATE_ENABLED: # color = _PALETTE['ButtonDisabled'] # painter.fillRect(opt.rect, color) # TODO: keyboard focus change state # elif element == QStyle.PE_PanelButtonCommand: # Draw a flat push button # is_down = opt.state & STATE_SUNKEN or opt.state & STATE_ON # is_enabled = opt.state & STATE_ENABLED # is_hover = is_enabled and opt.state & STATE_MOUSEOVER # FIXME: has_focus state # FIXME: from theme # color = QColor("#444a58") # if is_down: # color = color.darker(130) # elif is_hover: # color = color.lighter(110) # painter.fillRect(opt.rect, color) elif element == QStyle.PE_PanelLineEdit: painter.save() # Fill background rect = opt.rect enabled = False if opt.state & STATE_ENABLED: enabled = True if not enabled: painter.setOpacity(0.55) painter.fillRect(rect, theme.get_color('LineEditBackground')) has_focus = False if opt.state & QStyle.State_HasFocus: has_focus = True if enabled and (has_focus or opt.state & STATE_MOUSEOVER): # FIXME: color from theme # hover = QColor("#6a6ea9") # if has_focus: # alpha = 200 # else: # alpha = 55 # hover.setAlpha(alpha) # painter.setPen(QPen(hover, 2, Qt.SolidLine, # Qt.SquareCap, Qt.RoundJoin)) # painter.drawRect(rect.adjusted(0, 0, 0, 0)) pass painter.restore() elif element == QStyle.PE_IndicatorToolBarSeparator: rect = opt.rect painter.setPen(theme.get_color('SeparatorColor')) border_rect = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5) if opt.state & QStyle.State_Horizontal: border_rect.setWidth(1) painter.drawLine(border_rect.topRight() + QPointF(0, 3), border_rect.bottomRight() - QPointF(0, 3)) else: border_rect.setHeight(1) painter.drawLine(border_rect.topLeft() + QPointF(3, 0), border_rect.topRight() - QPointF(3, 0)) elif element == QStyle.PE_IndicatorToolBarHandle: # FIXME: draw a fancy handler QProxyStyle.drawPrimitive(self, element, opt, painter, widget) else: QProxyStyle.drawPrimitive(self, element, opt, painter, widget)
def drawComplexControl(self, element, opt, painter, widget): if not self.__panel_widget(widget): QProxyStyle.drawComplexControl(self, element, opt, painter, widget) return if element == QStyle.CC_ComboBox: empty = False if not opt.currentText and opt.currentIcon.isNull(): empty = True tool_btn = opt if empty: tool_btn.state &= ~(STATE_ENABLED | STATE_SUNKEN) self.drawPrimitive(QStyle.PE_PanelButtonTool, tool_btn, painter, widget) # Draw border if widget.property("border"): painter.setPen(theme.get_color("MenuBarBorderColor")) painter.drawLine(opt.rect.topRight() + QPoint(0, 3), opt.rect.bottomRight() - QPoint(0, 3)) if widget.property("border_bottom"): painter.setPen(theme.get_color('Border')) painter.drawLine(opt.rect.bottomLeft(), opt.rect.bottomRight()) arrow_rect = QRect((opt.rect.left() + opt.rect.right()) / 2 + 6, opt.rect.center().y(), 9, 9) arrow_rect.moveRight(opt.rect.width() - 10) # FIXME: arrow_opt = QStyleOptionComboBox() arrow_opt.state = opt.state arrow_opt.rect = arrow_rect if empty: arrow_opt.state &= ~(STATE_ENABLED | STATE_SUNKEN) if self.styleHint(QStyle.SH_ComboBox_Popup, opt, widget): arrow_opt.rect.translate(0, -6) arrow_opt.palette.setColor(QPalette.ButtonText, theme.get_color('IconBaseColor')) QCommonStyle.drawPrimitive(self, QStyle.PE_IndicatorArrowUp, arrow_opt, painter, widget) arrow_opt.rect.translate(0, 6) QCommonStyle.drawPrimitive(self, QStyle.PE_IndicatorArrowDown, arrow_opt, painter, widget) elif element == QStyle.CC_ToolButton: button = self.subControlRect(element, opt, QStyle.SC_ToolButton, widget) flags = opt.state if flags & QStyle.State_AutoRaise: if not flags & STATE_MOUSEOVER: flags &= ~QStyle.State_Raised tool = opt tool.palette = self.panel_palette(opt.palette) if opt.subControls & QStyle.SC_ToolButton: tool.rect = button tool.state = flags self.drawPrimitive(QStyle.PE_PanelButtonTool, tool, painter, widget) label = opt label.palette.setColor(QPalette.ButtonText, label.palette.buttonText().color()) fw = self.pixelMetric(QStyle.PM_DefaultFrameWidth, opt, widget) label.rect = opt.rect.adjusted(fw, fw, -fw, -fw) self.drawControl(QStyle.CE_ToolButtonLabel, label, painter, widget) else: QProxyStyle.drawComplexControl(self, element, opt, painter, widget)