⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gradients.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    }    set_shade_points(pts_red, m_red_shade);    set_shade_points(pts_green, m_green_shade);    set_shade_points(pts_blue, m_blue_shade);    set_shade_points(pts_alpha, m_alpha_shade);}GradientWidget::GradientWidget(QWidget *parent)    : QWidget(parent){    setWindowTitle("Gradients");    m_renderer = new GradientRenderer(this);    QGroupBox *mainGroup = new QGroupBox(this);    mainGroup->setTitle("Gradients");    QGroupBox *editorGroup = new QGroupBox(mainGroup);    editorGroup->setAttribute(Qt::WA_ContentsPropagated);    editorGroup->setTitle("Color Editor");    m_editor = new GradientEditor(editorGroup);    QGroupBox *typeGroup = new QGroupBox(mainGroup);    typeGroup->setAttribute(Qt::WA_ContentsPropagated);    typeGroup->setTitle("Gradient Type");    m_linearButton = new QRadioButton("Linear Gradient", typeGroup);    m_radialButton = new QRadioButton("Radial Gradient", typeGroup);    m_conicalButton = new QRadioButton("Conical Gradient", typeGroup);    QGroupBox *spreadGroup = new QGroupBox(mainGroup);    spreadGroup->setAttribute(Qt::WA_ContentsPropagated);    spreadGroup->setTitle("Spread Method");    m_padSpreadButton = new QRadioButton("Pad Spread", spreadGroup);    m_reflectSpreadButton = new QRadioButton("Reflect Spread", spreadGroup);    m_repeatSpreadButton = new QRadioButton("Repeat Spread", spreadGroup);    QGroupBox *defaultsGroup = new QGroupBox(mainGroup);    defaultsGroup->setAttribute(Qt::WA_ContentsPropagated);    defaultsGroup->setTitle("Defaults");    QPushButton *default1Button = new QPushButton("1", defaultsGroup);    QPushButton *default2Button = new QPushButton("2", defaultsGroup);    QPushButton *default3Button = new QPushButton("3", defaultsGroup);    QPushButton *default4Button = new QPushButton("Reset", editorGroup);    QPushButton *showSourceButton = new QPushButton(mainGroup);    showSourceButton->setText("Show Source");#ifdef QT_OPENGL_SUPPORT    QPushButton *enableOpenGLButton = new QPushButton(mainGroup);    enableOpenGLButton->setText("Use OpenGL");    enableOpenGLButton->setCheckable(true);    enableOpenGLButton->setChecked(m_renderer->usesOpenGL());    if (!QGLFormat::hasOpenGL())        enableOpenGLButton->hide();#endif    QPushButton *whatsThisButton = new QPushButton(mainGroup);    whatsThisButton->setText("What's This?");    whatsThisButton->setCheckable(true);    // Layouts    QHBoxLayout *mainLayout = new QHBoxLayout(this);    mainLayout->addWidget(m_renderer);    mainLayout->addWidget(mainGroup);    mainGroup->setFixedWidth(180);    QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);    mainGroupLayout->addWidget(editorGroup);    mainGroupLayout->addWidget(typeGroup);    mainGroupLayout->addWidget(spreadGroup);    mainGroupLayout->addWidget(defaultsGroup);    mainGroupLayout->addStretch(1);    mainGroupLayout->addWidget(showSourceButton);#ifdef QT_OPENGL_SUPPORT    mainGroupLayout->addWidget(enableOpenGLButton);#endif    mainGroupLayout->addWidget(whatsThisButton);    QVBoxLayout *editorGroupLayout = new QVBoxLayout(editorGroup);    editorGroupLayout->addWidget(m_editor);    QVBoxLayout *typeGroupLayout = new QVBoxLayout(typeGroup);    typeGroupLayout->addWidget(m_linearButton);    typeGroupLayout->addWidget(m_radialButton);    typeGroupLayout->addWidget(m_conicalButton);    QVBoxLayout *spreadGroupLayout = new QVBoxLayout(spreadGroup);    spreadGroupLayout->addWidget(m_padSpreadButton);    spreadGroupLayout->addWidget(m_repeatSpreadButton);    spreadGroupLayout->addWidget(m_reflectSpreadButton);    QHBoxLayout *defaultsGroupLayout = new QHBoxLayout(defaultsGroup);    defaultsGroupLayout->addWidget(default1Button);    defaultsGroupLayout->addWidget(default2Button);    defaultsGroupLayout->addWidget(default3Button);    editorGroupLayout->addWidget(default4Button);    connect(m_editor, SIGNAL(gradientStopsChanged(const QGradientStops &)),            m_renderer, SLOT(setGradientStops(const QGradientStops &)));    connect(m_linearButton, SIGNAL(clicked()), m_renderer, SLOT(setLinearGradient()));    connect(m_radialButton, SIGNAL(clicked()), m_renderer, SLOT(setRadialGradient()));    connect(m_conicalButton, SIGNAL(clicked()), m_renderer, SLOT(setConicalGradient()));    connect(m_padSpreadButton, SIGNAL(clicked()), m_renderer, SLOT(setPadSpread()));    connect(m_reflectSpreadButton, SIGNAL(clicked()), m_renderer, SLOT(setReflectSpread()));    connect(m_repeatSpreadButton, SIGNAL(clicked()), m_renderer, SLOT(setRepeatSpread()));    connect(default1Button, SIGNAL(clicked()), this, SLOT(setDefault1()));    connect(default2Button, SIGNAL(clicked()), this, SLOT(setDefault2()));    connect(default3Button, SIGNAL(clicked()), this, SLOT(setDefault3()));    connect(default4Button, SIGNAL(clicked()), this, SLOT(setDefault4()));    connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource()));#ifdef QT_OPENGL_SUPPORT    connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));#endif    connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool)));    connect(whatsThisButton, SIGNAL(clicked(bool)),            m_renderer->hoverPoints(), SLOT(setDisabled(bool)));    connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),            whatsThisButton, SLOT(setChecked(bool)));    connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),            m_renderer->hoverPoints(), SLOT(setDisabled(bool)));    m_renderer->loadSourceFile(":res/gradients.cpp");    m_renderer->loadDescription(":res/gradients.html");    QTimer::singleShot(50, this, SLOT(setDefault1()));}void GradientWidget::setDefault(int config){    QGradientStops stops;    QPolygonF points;    switch (config) {    case 1:        stops << QGradientStop(0.00, QColor::fromRgba(0));        stops << QGradientStop(0.04, QColor::fromRgba(0xff131360));        stops << QGradientStop(0.08, QColor::fromRgba(0xff202ccc));        stops << QGradientStop(0.42, QColor::fromRgba(0xff93d3f9));        stops << QGradientStop(0.51, QColor::fromRgba(0xffb3e6ff));        stops << QGradientStop(0.73, QColor::fromRgba(0xffffffec));        stops << QGradientStop(0.92, QColor::fromRgba(0xff5353d9));        stops << QGradientStop(0.96, QColor::fromRgba(0xff262666));        stops << QGradientStop(1.00, QColor::fromRgba(0));        m_linearButton->animateClick();        m_repeatSpreadButton->animateClick();        break;    case 2:        stops << QGradientStop(0.00, QColor::fromRgba(0xffffffff));        stops << QGradientStop(0.11, QColor::fromRgba(0xfff9ffa0));        stops << QGradientStop(0.13, QColor::fromRgba(0xfff9ff99));        stops << QGradientStop(0.14, QColor::fromRgba(0xfff3ff86));        stops << QGradientStop(0.49, QColor::fromRgba(0xff93b353));        stops << QGradientStop(0.87, QColor::fromRgba(0xff264619));        stops << QGradientStop(0.96, QColor::fromRgba(0xff0c1306));        stops << QGradientStop(1.00, QColor::fromRgba(0));        m_radialButton->animateClick();        m_padSpreadButton->animateClick();        break;    case 3:        stops << QGradientStop(0.00, QColor::fromRgba(0));        stops << QGradientStop(0.10, QColor::fromRgba(0xffe0cc73));        stops << QGradientStop(0.17, QColor::fromRgba(0xffc6a006));        stops << QGradientStop(0.46, QColor::fromRgba(0xff600659));        stops << QGradientStop(0.72, QColor::fromRgba(0xff0680ac));        stops << QGradientStop(0.92, QColor::fromRgba(0xffb9d9e6));        stops << QGradientStop(1.00, QColor::fromRgba(0));        m_conicalButton->animateClick();        m_padSpreadButton->animateClick();        break;    case 4:        stops << QGradientStop(0.00, QColor::fromRgba(0xff000000));        stops << QGradientStop(1.00, QColor::fromRgba(0xffffffff));        break;    default:        qWarning("bad default: %d\n", config);        break;    }    QPolygonF pts;    int h_off = m_renderer->width() / 10;    int v_off = m_renderer->height() / 8;    pts << QPointF(m_renderer->width() / 2, m_renderer->height() / 2)        << QPointF(m_renderer->width() / 2 - h_off, m_renderer->height() / 2 - v_off);    m_editor->setGradientStops(stops);    m_renderer->hoverPoints()->setPoints(pts);    m_renderer->setGradientStops(stops);}GradientRenderer::GradientRenderer(QWidget *parent)    : ArthurFrame(parent){    m_hoverPoints = new HoverPoints(this, HoverPoints::CircleShape);    m_hoverPoints->setPointSize(QSize(20, 20));    m_hoverPoints->setConnectionType(HoverPoints::NoConnection);    m_hoverPoints->setEditable(false);    QVector<QPointF> points;    points << QPointF(100, 100) << QPointF(200, 200);    m_hoverPoints->setPoints(points);    m_spread = QGradient::PadSpread;    m_gradientType = Qt::LinearGradientPattern;}void GradientRenderer::setGradientStops(const QGradientStops &stops){    m_stops = stops;    update();}void GradientRenderer::mousePressEvent(QMouseEvent *){    setDescriptionEnabled(false);}void GradientRenderer::paint(QPainter *p){    QPolygonF pts = m_hoverPoints->points();    QGradient g;    if (m_gradientType == Qt::LinearGradientPattern) {        g = QLinearGradient(pts.at(0), pts.at(1));    } else if (m_gradientType == Qt::RadialGradientPattern) {        QLineF line(pts.at(0), pts.at(1));        if (line.length() > 132)            line.setLength(132);        g = QRadialGradient(line.p1(), qMin(width(), height()) / 3.0, line.p2());    } else {        QLineF l(pts.at(0), pts.at(1));        double angle = l.angle(QLineF(0, 0, 1, 0));        if (l.dy() > 0)            angle = 360 - angle;        g = QConicalGradient(pts.at(0), angle);    }    for (int i=0; i<m_stops.size(); ++i)        g.setColorAt(m_stops.at(i).first, m_stops.at(i).second);    g.setSpread(m_spread);    p->setBrush(g);    p->setPen(Qt::NoPen);    p->drawRect(rect());}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -