📄 pathstroke.cpp
字号:
/******************************************************************************** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.**** This file is part of the demonstration applications of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "pathstroke.h"#include "arthurstyle.h"#include "arthurwidgets.h"extern void draw_round_rect(QPainter *p, const QRect &bounds, int radius);PathStrokeWidget::PathStrokeWidget(){ setWindowTitle(tr("Path Stroking")); // Setting up palette. QPalette pal = palette();// pal.setBrush(QPalette::Background, Qt::white);// pal.setBrush(QPalette::Foreground, QColor("aquamarine"));// pal.setBrush(QPalette::Background, QPixmap("background.png")); setPalette(pal); // Widget construction and property setting m_renderer = new PathStrokeRenderer(this); QGroupBox *mainGroup = new QGroupBox(this);// QWidget *mainGroup = new QWidget(this); mainGroup->setFixedWidth(180); mainGroup->setTitle("Path Stroking"); QGroupBox *capGroup = new QGroupBox(mainGroup); capGroup->setAttribute(Qt::WA_ContentsPropagated); QRadioButton *flatCap = new QRadioButton(capGroup); QRadioButton *squareCap = new QRadioButton(capGroup); QRadioButton *roundCap = new QRadioButton(capGroup); capGroup->setTitle("Cap Style"); flatCap->setText("Flat Cap"); squareCap->setText("Square Cap"); roundCap->setText("Round Cap"); QGroupBox *joinGroup = new QGroupBox(mainGroup); joinGroup->setAttribute(Qt::WA_ContentsPropagated); QRadioButton *bevelJoin = new QRadioButton(joinGroup); QRadioButton *miterJoin = new QRadioButton(joinGroup); QRadioButton *roundJoin = new QRadioButton(joinGroup); joinGroup->setTitle("Join Style"); bevelJoin->setText("Bevel Join"); miterJoin->setText("Miter Join"); roundJoin->setText("Round Join"); QGroupBox *styleGroup = new QGroupBox(mainGroup); styleGroup->setAttribute(Qt::WA_ContentsPropagated); QRadioButton *solidLine = new QRadioButton(styleGroup); QRadioButton *dashLine = new QRadioButton(styleGroup); QRadioButton *dotLine = new QRadioButton(styleGroup); QRadioButton *dashDotLine = new QRadioButton(styleGroup); QRadioButton *dashDotDotLine = new QRadioButton(styleGroup); QRadioButton *customDashLine = new QRadioButton(styleGroup); styleGroup->setTitle("Pen Style");#if 0 solidLine->setText("Solid Line"); dashLine->setText("Dash Line"); dotLine->setText("Dot Line"); dashDotLine->setText("Dash Dot Line"); dashDotDotLine->setText("Dash Dot Dot Line");#else QPixmap line_solid(":res/images/line_solid.png"); solidLine->setIcon(line_solid); solidLine->setIconSize(line_solid.size()); QPixmap line_dashed(":res/images/line_dashed.png"); dashLine->setIcon(line_dashed); dashLine->setIconSize(line_dashed.size()); QPixmap line_dotted(":res/images/line_dotted.png"); dotLine->setIcon(line_dotted); dotLine->setIconSize(line_dotted.size()); QPixmap line_dash_dot(":res/images/line_dash_dot.png"); dashDotLine->setIcon(line_dash_dot); dashDotLine->setIconSize(line_dash_dot.size()); QPixmap line_dash_dot_dot(":res/images/line_dash_dot_dot.png"); dashDotDotLine->setIcon(line_dash_dot_dot); dashDotDotLine->setIconSize(line_dash_dot_dot.size()); customDashLine->setText("Custom Style"); int fixedHeight = bevelJoin->sizeHint().height(); solidLine->setFixedHeight(fixedHeight); dashLine->setFixedHeight(fixedHeight); dotLine->setFixedHeight(fixedHeight); dashDotLine->setFixedHeight(fixedHeight); dashDotDotLine->setFixedHeight(fixedHeight);#endif QGroupBox *pathModeGroup = new QGroupBox(mainGroup); pathModeGroup->setAttribute(Qt::WA_ContentsPropagated); QRadioButton *curveMode = new QRadioButton(pathModeGroup); QRadioButton *lineMode = new QRadioButton(pathModeGroup); pathModeGroup->setTitle("Path composed of"); curveMode->setText("Curves"); lineMode->setText("Lines"); QGroupBox *penWidthGroup = new QGroupBox(mainGroup); penWidthGroup->setAttribute(Qt::WA_ContentsPropagated); QSlider *penWidth = new QSlider(Qt::Horizontal, penWidthGroup); penWidth->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); penWidthGroup->setTitle("Pen Width"); penWidth->setRange(0, 500);#if 0 QCheckBox *animated = new QCheckBox(mainGroup); animated->setText("Animated");#else QPushButton *animated = new QPushButton(mainGroup); animated->setText("Animate"); animated->setCheckable(true);#endif 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); // Layouting QHBoxLayout *viewLayout = new QHBoxLayout(this); viewLayout->addWidget(m_renderer); viewLayout->addWidget(mainGroup); QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup); mainGroupLayout->setMargin(3); mainGroupLayout->addWidget(capGroup); mainGroupLayout->addWidget(joinGroup); mainGroupLayout->addWidget(styleGroup); mainGroupLayout->addWidget(penWidthGroup); mainGroupLayout->addWidget(pathModeGroup); mainGroupLayout->addWidget(animated); mainGroupLayout->addStretch(1); mainGroupLayout->addWidget(showSourceButton);#ifdef QT_OPENGL_SUPPORT mainGroupLayout->addWidget(enableOpenGLButton);#endif mainGroupLayout->addWidget(whatsThisButton); QVBoxLayout *capGroupLayout = new QVBoxLayout(capGroup); capGroupLayout->addWidget(flatCap); capGroupLayout->addWidget(squareCap); capGroupLayout->addWidget(roundCap); QVBoxLayout *joinGroupLayout = new QVBoxLayout(joinGroup); joinGroupLayout->addWidget(bevelJoin); joinGroupLayout->addWidget(miterJoin); joinGroupLayout->addWidget(roundJoin); QVBoxLayout *styleGroupLayout = new QVBoxLayout(styleGroup); styleGroupLayout->addWidget(solidLine); styleGroupLayout->addWidget(dashLine); styleGroupLayout->addWidget(dotLine); styleGroupLayout->addWidget(dashDotLine); styleGroupLayout->addWidget(dashDotDotLine); styleGroupLayout->addWidget(customDashLine); QVBoxLayout *pathModeGroupLayout = new QVBoxLayout(pathModeGroup); pathModeGroupLayout->addWidget(curveMode); pathModeGroupLayout->addWidget(lineMode); QVBoxLayout *penWidthLayout = new QVBoxLayout(penWidthGroup); penWidthLayout->addWidget(penWidth); // Set up connections connect(penWidth, SIGNAL(valueChanged(int)), m_renderer, SLOT(setPenWidth(int))); connect(animated, SIGNAL(toggled(bool)), m_renderer, SLOT(setAnimation(bool))); connect(flatCap, SIGNAL(clicked()), m_renderer, SLOT(setFlatCap())); connect(squareCap, SIGNAL(clicked()), m_renderer, SLOT(setSquareCap())); connect(roundCap, SIGNAL(clicked()), m_renderer, SLOT(setRoundCap())); connect(bevelJoin, SIGNAL(clicked()), m_renderer, SLOT(setBevelJoin())); connect(miterJoin, SIGNAL(clicked()), m_renderer, SLOT(setMiterJoin())); connect(roundJoin, SIGNAL(clicked()), m_renderer, SLOT(setRoundJoin())); connect(curveMode, SIGNAL(clicked()), m_renderer, SLOT(setCurveMode())); connect(lineMode, SIGNAL(clicked()), m_renderer, SLOT(setLineMode())); connect(solidLine, SIGNAL(clicked()), m_renderer, SLOT(setSolidLine())); connect(dashLine, SIGNAL(clicked()), m_renderer, SLOT(setDashLine()));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -