2018-12-24 09:32:05 -05:00
|
|
|
#include "editorstyle.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOption>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
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<const QStyleOptionMenuItem*>(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));
|
2018-12-24 10:04:00 -05:00
|
|
|
else
|
|
|
|
painter->fillRect(option->rect, QColor(50, 50, 55));
|
2018-12-24 09:32:05 -05:00
|
|
|
|
|
|
|
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<const QStyleOptionMenuItem*>(option);
|
|
|
|
|
|
|
|
if(menuopt->menuItemType == QStyleOptionMenuItem::Separator) {
|
|
|
|
painter->setPen(QColor(75, 75, 80));
|
2018-12-24 10:04:00 -05:00
|
|
|
painter->drawLine(x + 5, y + 2, x + width - 5, y + 2);
|
2018-12-24 09:32:05 -05:00
|
|
|
} 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;
|
|
|
|
|
|
|
|
if(enabled && (selected || hovered))
|
|
|
|
painter->fillRect(rect, option->palette.brush(QPalette::Highlight));
|
|
|
|
|
2018-12-24 10:04:00 -05:00
|
|
|
rect.adjust(0, 4, 0, 0);
|
|
|
|
|
2018-12-24 09:32:05 -05:00
|
|
|
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) {
|
2018-12-24 10:04:00 -05:00
|
|
|
if(enabled && (selected || hovered))
|
|
|
|
painter->setPen(Qt::white);
|
|
|
|
else
|
|
|
|
painter->setPen(QColor(150, 150, 150));
|
|
|
|
|
2018-12-24 09:32:05 -05:00
|
|
|
drawItemText(painter, rect.adjusted(0, 0, -10, 0), Qt::AlignRight | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine, menuopt->palette, true, shortcut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2018-12-24 10:04:00 -05:00
|
|
|
case CE_TabBarTab:
|
|
|
|
{
|
|
|
|
const QStyleOptionTab* menuopt = qstyleoption_cast<const QStyleOptionTab*>(option);
|
|
|
|
|
|
|
|
painter->setPen(QColor(75, 75, 80));
|
|
|
|
painter->setBrush(QColor(50, 50, 55));
|
|
|
|
|
|
|
|
painter->drawRect(option->rect);
|
|
|
|
|
|
|
|
QRect rect = option->rect;
|
|
|
|
rect.adjust(10, 5, 0, 0);
|
|
|
|
|
|
|
|
QPixmap pix = menuopt->icon.pixmap(16, 16, (menuopt->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
|
|
|
|
|
|
|
|
if(!pix.isNull()) {
|
|
|
|
const QRect iconRect = option->rect.adjusted(5, 6, 0, 0);
|
|
|
|
|
|
|
|
drawItemPixmap(painter, iconRect, 0, pix);
|
|
|
|
|
|
|
|
rect.adjust(16, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
drawItemText(painter, rect, Qt::AlignLeft | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine, menuopt->palette, true, menuopt->text, QPalette::ButtonText);
|
|
|
|
}
|
|
|
|
break;
|
2018-12-24 09:32:05 -05:00
|
|
|
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<const QStyleOptionMenuItem *>(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) {
|
2018-12-24 10:04:00 -05:00
|
|
|
palette.setBrush(QPalette::Window, QColor(45, 45, 45));
|
|
|
|
palette.setBrush(QPalette::Button, QColor(50, 50, 55));
|
2018-12-24 09:32:05 -05:00
|
|
|
}
|
|
|
|
|