#include "editorstyle.h" #include #include #include void EditorStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *widget) const { int x, y, width, height; opt->rect.getRect(&x, &y, &width, &height); switch(pe) { case PE_FrameMenu: { p->fillRect(x, y, width, height, QColor(75, 75, 80)); } break; case PE_PanelMenu: { p->fillRect(x, y, width, height, QColor(50, 50, 55)); } break; case PE_PanelMenuBar: { p->fillRect(x, y, width, height, QColor(75, 75, 80)); } break; default: QProxyStyle::drawPrimitive(pe, opt, p, widget); break; } } void EditorStyle::drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const { int x, y, width, height; option->rect.getRect(&x, &y, &width, &height); switch(element) { case CE_MenuBarEmptyArea: painter->fillRect(option->rect, QColor(50, 50, 55)); break; case CE_MenuBarItem: { const QStyleOptionMenuItem* menuopt = qstyleoption_cast(option); const bool selected = menuopt->state & State_Selected; const bool hovered = menuopt->state & State_MouseOver; const bool enabled = menuopt->state & State_Enabled; if(enabled && (selected || hovered)) painter->fillRect(option->rect, option->palette.brush(QPalette::Highlight)); drawItemText(painter, option->rect, Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine, menuopt->palette, true, menuopt->text, QPalette::ButtonText); } break; case CE_MenuItem: { const QStyleOptionMenuItem* menuopt = qstyleoption_cast(option); if(menuopt->menuItemType == QStyleOptionMenuItem::Separator) { painter->setPen(QColor(75, 75, 80)); painter->drawLine(x + 5, y + 1, x + width - 5, y + 1); } else { const bool selected = menuopt->state & State_Selected; const bool hovered = menuopt->state & State_MouseOver; const bool enabled = menuopt->state & State_Enabled; QPixmap pix = menuopt->icon.pixmap(16, 16, (menuopt->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); QRect rect = option->rect; rect.adjust(0, 4, 0, 0); if(enabled && (selected || hovered)) painter->fillRect(rect, option->palette.brush(QPalette::Highlight)); if(!pix.isNull()) { const QRect iconRect = option->rect.adjusted(5, 5, 0, 0); drawItemPixmap(painter, iconRect, 0, pix); rect.adjust(27, 0, 0, 0); } auto index = menuopt->text.indexOf("CTRL", 0, Qt::CaseInsensitive); QString label = menuopt->text.left(index); QString shortcut; if(index != -1) shortcut = menuopt->text.right(menuopt->text.length() - index + 1); drawItemText(painter, rect, Qt::AlignLeft | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine, menuopt->palette, true, label, QPalette::ButtonText); if(index != -1) { painter->setPen(QColor(150, 150, 150)); drawItemText(painter, rect.adjusted(0, 0, -10, 0), Qt::AlignRight | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine, menuopt->palette, true, shortcut); } } } break; default: QProxyStyle::drawControl(element, option, painter, widget); break; } } void EditorStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const { QProxyStyle::drawComplexControl(control, opt, p, widget); } QSize EditorStyle::sizeFromContents(ContentsType type, const QStyleOption *opt, const QSize &size, const QWidget *widget) const { switch(type) { case QStyle::CT_MenuBarItem: { const QStyleOptionMenuItem* menuopt = qstyleoption_cast(opt); return menuopt->fontMetrics.size(Qt::TextShowMnemonic, menuopt->text) + QSize(15, 5); } break; default: return QProxyStyle::sizeFromContents(type, opt, size, widget); } } int EditorStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const { switch (metric) { case PM_MenuBarPanelWidth: return 1; case PM_MenuPanelWidth: return 1; case PM_MenuBarVMargin: return 2; case PM_MenuBarHMargin: return 2; default: return QProxyStyle::pixelMetric(metric, option, widget); } } void EditorStyle::polish(QPalette& palette) { palette.setBrush(QPalette::Button, QColor(50, 50, 50)); }