1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
**/
#include "customstyle.h"
#include <QDebug>
#include <QPainter>
#include <QPainterPath>
#include <QStyleOption>
#include <QLineEdit>
#include <QFileDialog>
#include <QAbstractItemView>
#include <QApplication>
#include <QComboBox>
InternalStyle::InternalStyle(const QString &styleName, QObject *parent) : QProxyStyle(styleName)
{
}
void InternalStyle::drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
switch(element)
{
case CE_ShapedFrame: {
//return proxy()->drawPrimitive(PE_Frame, option, painter, widget);
QStyleOptionFrame frame = *qstyleoption_cast<const QStyleOptionFrame *>(option);
frame.lineWidth = 0;
QFrame::Shape shape = frame.frameShape;
switch (shape) {
case QFrame::Box: {
// Draw four rounded corners
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setBrush(option->palette.color(QPalette::Base));
painter->setPen(Qt::transparent);
QRect rect = widget->rect();
painter->drawRoundedRect(rect.x() + 1, rect.y() + 1, rect.width() - 2, rect.height() - 2, 6, 6);
painter->restore();
return;
}
case QFrame::HLine: {
// Draw rounded corners at the bottom left and bottom right
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
QPainterPath path;
path.addRoundedRect(frame.rect, 6,6);
path.setFillRule(Qt::WindingFill);
path.addRect(frame.rect.width() - 6, 0, 6, 6);
path.addRect(0, 0, 6, 6);
painter->setPen(Qt::transparent);
painter->setBrush(option->palette.color(QPalette::Button));
painter->setClipPath(path);
painter->drawRect(frame.rect);
painter->restore();
return;
}
case QFrame::VLine: {
// Draw rounded corners in the upper left and upper right corners
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
QPainterPath path;
path.addRoundedRect(frame.rect, 6,6);
path.setFillRule(Qt::WindingFill);
path.addRect(0, frame.rect.height() - 6, 6, 6);
path.addRect(frame.rect.width() - 6, frame.rect.height() - 6, 6, 6);
painter->setPen(Qt::transparent);
painter->setBrush(option->palette.color(QPalette::Button));
painter->setClipPath(path);
painter->drawRect(frame.rect);
painter->restore();
return;
}
case QFrame::Panel: {
// Do not draw corner
painter->fillRect(frame.rect, option->palette.color(QPalette::Button));
return;
}
case QFrame::StyledPanel: {
if (widget && qobject_cast<const QComboBox *>(widget->parentWidget())) {
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setPen(QPen(frame.palette.color(frame.state & State_Enabled ? QPalette::Active : QPalette::Disabled, QPalette::Button), 2));
painter->setBrush(frame.palette.base());
painter->drawRoundedRect(frame.rect, 4, 4);
painter->restore();
}
return;
}
default:
return;
}
return;
break;
}
default:
break;
}
return QProxyStyle::drawControl(element, option, painter, widget);
}
void InternalStyle::drawComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
{
switch (control) {
case CC_ComboBox: {
break;
}
default:
break;
}
return QProxyStyle::drawComplexControl(control, option, painter, widget);
}
void InternalStyle::polish(QPalette &pal)
{
QProxyStyle::polish(pal);
}
void InternalStyle::polish(QWidget *widget)
{
QProxyStyle::polish(widget);
if (qobject_cast<QDialog *>(widget) && !qobject_cast<QFileDialog *>(widget)) {
QPalette paltte = widget->palette();
paltte.setColor(QPalette::Window, paltte.base().color());
widget->setPalette(paltte);
}
}
|