view.cpp Example File
Find this file on Gitorious.
- /****************************************************************************
- **
- ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
- ** All rights reserved.
- ** Contact: Nokia Corporation (qt-info@nokia.com)
- **
- ** This file is part of the demonstration applications of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** GNU Lesser General Public License Usage
- ** This file may be used under the terms of the GNU Lesser General Public
- ** License version 2.1 as published by the Free Software Foundation and
- ** appearing in the file LICENSE.LGPL included in the packaging of this
- ** file. Please review the following information to ensure the GNU Lesser
- ** General Public License version 2.1 requirements will be met:
- ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
- **
- ** In addition, as a special exception, Nokia gives you certain additional
- ** rights. These rights are described in the Nokia Qt LGPL Exception
- ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU General
- ** Public License version 3.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 the GNU General
- ** Public License version 3.0 requirements will be met:
- ** http://www.gnu.org/copyleft/gpl.html.
- **
- ** Other Usage
- ** Alternatively, this file may be used in accordance with the terms and
- ** conditions contained in a signed written agreement between you and Nokia.
- **
- **
- **
- **
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
- #include "view.h"
- #include <QtGui>
- #ifndef QT_NO_OPENGL
- #include <QtOpenGL>
- #endif
- #include <qmath.h>
- {
- setFrameStyle(Sunken | StyledPanel);
- graphicsView = new QGraphicsView;
- zoomInIcon->setAutoRepeat(true);
- zoomInIcon->setAutoRepeatInterval(33);
- zoomInIcon->setAutoRepeatDelay(0);
- zoomInIcon->setIconSize(iconSize);
- zoomOutIcon->setAutoRepeat(true);
- zoomOutIcon->setAutoRepeatInterval(33);
- zoomOutIcon->setAutoRepeatDelay(0);
- zoomOutIcon->setIconSize(iconSize);
- zoomSlider = new QSlider;
- zoomSlider->setMinimum(0);
- zoomSlider->setMaximum(500);
- zoomSlider->setValue(250);
- // Zoom slider layout
- zoomSliderLayout->addWidget(zoomInIcon);
- zoomSliderLayout->addWidget(zoomSlider);
- zoomSliderLayout->addWidget(zoomOutIcon);
- rotateLeftIcon->setIconSize(iconSize);
- rotateRightIcon->setIconSize(iconSize);
- rotateSlider = new QSlider;
- rotateSlider->setMinimum(-360);
- rotateSlider->setMaximum(360);
- rotateSlider->setValue(0);
- // Rotate slider layout
- rotateSliderLayout->addWidget(rotateLeftIcon);
- rotateSliderLayout->addWidget(rotateSlider);
- rotateSliderLayout->addWidget(rotateRightIcon);
- resetButton = new QToolButton;
- resetButton->setText(tr("0"));
- resetButton->setEnabled(false);
- // Label layout
- antialiasButton = new QToolButton;
- antialiasButton->setText(tr("Antialiasing"));
- antialiasButton->setCheckable(true);
- antialiasButton->setChecked(false);
- openGlButton = new QToolButton;
- openGlButton->setText(tr("OpenGL"));
- openGlButton->setCheckable(true);
- #ifndef QT_NO_OPENGL
- #else
- openGlButton->setEnabled(false);
- #endif
- printButton = new QToolButton;
- labelLayout->addWidget(label);
- labelLayout->addStretch();
- labelLayout->addWidget(antialiasButton);
- labelLayout->addWidget(openGlButton);
- labelLayout->addWidget(printButton);
- topLayout->addLayout(labelLayout, 0, 0);
- topLayout->addWidget(graphicsView, 1, 0);
- topLayout->addLayout(zoomSliderLayout, 1, 1);
- topLayout->addLayout(rotateSliderLayout, 2, 0);
- topLayout->addWidget(resetButton, 2, 1);
- setLayout(topLayout);
- connect(resetButton, SIGNAL(clicked()), this, SLOT(resetView()));
- connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
- connect(rotateSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
- connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
- connect(graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
- connect(antialiasButton, SIGNAL(toggled(bool)), this, SLOT(toggleAntialiasing()));
- connect(openGlButton, SIGNAL(toggled(bool)), this, SLOT(toggleOpenGL()));
- connect(rotateLeftIcon, SIGNAL(clicked()), this, SLOT(rotateLeft()));
- connect(rotateRightIcon, SIGNAL(clicked()), this, SLOT(rotateRight()));
- connect(zoomInIcon, SIGNAL(clicked()), this, SLOT(zoomIn()));
- connect(zoomOutIcon, SIGNAL(clicked()), this, SLOT(zoomOut()));
- connect(printButton, SIGNAL(clicked()), this, SLOT(print()));
- setupMatrix();
- }
- {
- return graphicsView;
- }
- void View::resetView()
- {
- zoomSlider->setValue(250);
- rotateSlider->setValue(0);
- setupMatrix();
- resetButton->setEnabled(false);
- }
- void View::setResetButtonEnabled()
- {
- resetButton->setEnabled(true);
- }
- void View::setupMatrix()
- {
- qreal scale = qPow(qreal(2), (zoomSlider->value() - 250) / qreal(50));
- QMatrix matrix;
- matrix.scale(scale, scale);
- matrix.rotate(rotateSlider->value());
- graphicsView->setMatrix(matrix);
- setResetButtonEnabled();
- }
- void View::toggleOpenGL()
- {
- #ifndef QT_NO_OPENGL
- #endif
- }
- void View::toggleAntialiasing()
- {
- }
- void View::print()
- {
- #ifndef QT_NO_PRINTER
- QPrinter printer;
- graphicsView->render(&painter);
- }
- #endif
- }
- void View::zoomIn()
- {
- zoomSlider->setValue(zoomSlider->value() + 1);
- }
- void View::zoomOut()
- {
- zoomSlider->setValue(zoomSlider->value() - 1);
- }
- void View::rotateLeft()
- {
- rotateSlider->setValue(rotateSlider->value() - 10);
- }
- void View::rotateRight()
- {
- rotateSlider->setValue(rotateSlider->value() + 10);
- }


No notes