📄 composition.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 "composition.h"#include <QBoxLayout>#include <QRadioButton>#include <QTimer>#include <QDateTime>#include <QSlider>#include <QMouseEvent>#include <math.h>CompositionWidget::CompositionWidget(QWidget *parent) : QWidget(parent){ CompositionRenderer *view = new CompositionRenderer(this); QGroupBox *mainGroup = new QGroupBox(parent); mainGroup->setAttribute(Qt::WA_ContentsPropagated); mainGroup->setTitle("Composition Modes"); QGroupBox *modesGroup = new QGroupBox(mainGroup); modesGroup->setAttribute(Qt::WA_ContentsPropagated); modesGroup->setTitle("Mode"); rbClear = new QRadioButton("Clear", modesGroup); connect(rbClear, SIGNAL(clicked()), view, SLOT(setClearMode())); rbSource = new QRadioButton("Source", modesGroup); connect(rbSource, SIGNAL(clicked()), view, SLOT(setSourceMode())); rbDest = new QRadioButton("Destination", modesGroup); connect(rbDest, SIGNAL(clicked()), view, SLOT(setDestMode())); rbSourceOver = new QRadioButton("Source Over", modesGroup); connect(rbSourceOver, SIGNAL(clicked()), view, SLOT(setSourceOverMode())); rbDestOver = new QRadioButton("Destination Over", modesGroup); connect(rbDestOver, SIGNAL(clicked()), view, SLOT(setDestOverMode())); rbSourceIn = new QRadioButton("Source In", modesGroup); connect(rbSourceIn, SIGNAL(clicked()), view, SLOT(setSourceInMode())); rbDestIn = new QRadioButton("Dest In", modesGroup); connect(rbDestIn, SIGNAL(clicked()), view, SLOT(setDestInMode())); rbSourceOut = new QRadioButton("Source Out", modesGroup); connect(rbSourceOut, SIGNAL(clicked()), view, SLOT(setSourceOutMode())); rbDestOut = new QRadioButton("Dest Out", modesGroup); connect(rbDestOut, SIGNAL(clicked()), view, SLOT(setDestOutMode())); rbSourceAtop = new QRadioButton("Source Atop", modesGroup); connect(rbSourceAtop, SIGNAL(clicked()), view, SLOT(setSourceAtopMode())); rbDestAtop = new QRadioButton("Dest Atop", modesGroup); connect(rbDestAtop, SIGNAL(clicked()), view, SLOT(setDestAtopMode())); rbXor = new QRadioButton("Xor", modesGroup); connect(rbXor, SIGNAL(clicked()), view, SLOT(setXorMode())); QGroupBox *circleColorGroup = new QGroupBox(mainGroup); circleColorGroup->setAttribute(Qt::WA_ContentsPropagated); circleColorGroup->setTitle("Circle color"); QSlider *circleColorSlider = new QSlider(Qt::Horizontal, circleColorGroup); circleColorSlider->setRange(0, 359); circleColorSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); connect(circleColorSlider, SIGNAL(valueChanged(int)), view, SLOT(setCircleColor(int))); QGroupBox *circleAlphaGroup = new QGroupBox(mainGroup); circleAlphaGroup->setAttribute(Qt::WA_ContentsPropagated); circleAlphaGroup->setTitle("Circle alpha"); QSlider *circleAlphaSlider = new QSlider(Qt::Horizontal, circleAlphaGroup); circleAlphaSlider->setRange(0, 255); circleAlphaSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); connect(circleAlphaSlider, SIGNAL(valueChanged(int)), view, SLOT(setCircleAlpha(int))); 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(view->usesOpenGL()); if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) enableOpenGLButton->hide();#endif QPushButton *whatsThisButton = new QPushButton(mainGroup); whatsThisButton->setText("What's This?"); whatsThisButton->setCheckable(true); QPushButton *animateButton = new QPushButton(mainGroup); animateButton->setText("Animated"); animateButton->setCheckable(true); animateButton->setChecked(true); QHBoxLayout *viewLayout = new QHBoxLayout(this); viewLayout->addWidget(view); viewLayout->addWidget(mainGroup); QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup); mainGroupLayout->addWidget(circleColorGroup); mainGroupLayout->addWidget(circleAlphaGroup); mainGroupLayout->addWidget(modesGroup); mainGroupLayout->addStretch(); mainGroupLayout->addWidget(animateButton); mainGroupLayout->addWidget(whatsThisButton); mainGroupLayout->addWidget(showSourceButton);#ifdef QT_OPENGL_SUPPORT mainGroupLayout->addWidget(enableOpenGLButton);#endif QVBoxLayout *modesLayout = new QVBoxLayout(modesGroup); modesLayout->addWidget(rbClear); modesLayout->addWidget(rbSource); modesLayout->addWidget(rbDest); modesLayout->addWidget(rbSourceOver); modesLayout->addWidget(rbDestOver); modesLayout->addWidget(rbSourceIn); modesLayout->addWidget(rbDestIn); modesLayout->addWidget(rbSourceOut); modesLayout->addWidget(rbDestOut); modesLayout->addWidget(rbSourceAtop); modesLayout->addWidget(rbDestAtop); modesLayout->addWidget(rbXor); QVBoxLayout *circleColorLayout = new QVBoxLayout(circleColorGroup); circleColorLayout->addWidget(circleColorSlider); QVBoxLayout *circleAlphaLayout = new QVBoxLayout(circleAlphaGroup); circleAlphaLayout->addWidget(circleAlphaSlider); view->loadDescription(":res/composition.html"); view->loadSourceFile(":res/composition.cpp"); connect(whatsThisButton, SIGNAL(clicked(bool)), view, SLOT(setDescriptionEnabled(bool))); connect(view, SIGNAL(descriptionEnabledChanged(bool)), whatsThisButton, SLOT(setChecked(bool))); connect(showSourceButton, SIGNAL(clicked()), view, SLOT(showSource()));#ifdef QT_OPENGL_SUPPORT connect(enableOpenGLButton, SIGNAL(clicked(bool)), view, SLOT(enableOpenGL(bool)));#endif connect(animateButton, SIGNAL(toggled(bool)), view, SLOT(setAnimationEnabled(bool))); circleColorSlider->setValue(270); circleAlphaSlider->setValue(200); rbSourceOut->animateClick(); setWindowTitle(tr("Composition Modes"));}void CompositionWidget::nextMode(){ /* if (!m_animation_enabled) return; if (rbClear->isChecked()) rbSource->animateClick(); if (rbSource->isChecked()) rbDest->animateClick(); if (rbDest->isChecked()) rbSourceOver->animateClick(); if (rbSourceOver->isChecked()) rbDestOver->animateClick(); if (rbDestOver->isChecked()) rbSourceIn->animateClick(); if (rbSourceIn->isChecked()) rbDestIn->animateClick(); if (rbDestIn->isChecked()) rbSourceOut->animateClick(); if (rbSourceOut->isChecked()) rbDestOut->animateClick(); if (rbDestOut->isChecked()) rbSourceAtop->animateClick(); if (rbSourceAtop->isChecked()) rbDestAtop->animateClick(); if (rbDestAtop->isChecked()) rbXor->animateClick(); if (rbXor->isChecked()) rbClear->animateClick(); */}CompositionRenderer::CompositionRenderer(QWidget *parent) : ArthurFrame(parent){ m_animation_enabled = true; m_image = QImage(":res/flower_2.png"); m_circle_alpha = 127; m_circle_hue = 255; m_current_object = NoObject; m_composition_mode = QPainter::CompositionMode_SourceOut; m_circle_pos = QPoint(200, 100); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);#ifdef QT_OPENGL_SUPPORT m_pbuffer = 0; m_pbuffer_size = 1024;#endif}QRectF rectangle_around(const QPointF &p, const QSizeF &size = QSize(250, 200)){ QRectF rect(p, size);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -