PageRenderTime 49ms CodeModel.GetById 11ms app.highlight 34ms RepoModel.GetById 1ms app.codeStats 0ms

/vp_plugins/tEditor/view.cpp

http://cupsfilter.googlecode.com/
C++ | 135 lines | 95 code | 31 blank | 9 comment | 0 complexity | e145bf149b598149b467ab2c08720201 MD5 | raw file
  1#define _USE_MATH_DEFINES
  2#include "view.h"
  3#include <QtGui>
  4#include <qmath.h>
  5#include <QUndoStack>
  6
  7
  8View::View( QWidget *parent)
  9    : QFrame(parent)
 10    , tabNumber(-1)
 11{
 12
 13    setFrameStyle(Sunken | StyledPanel);
 14    graphicsView = new myGraphicsView;
 15    graphicsView->setRenderHint(QPainter::Antialiasing, false);
 16    graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
 17    graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
 18    graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
 19    curAngle = 0;
 20
 21    int size = style()->pixelMetric(QStyle::PM_ToolBarIconSize);
 22    QSize iconSize(size, size);
 23
 24    QToolButton *zoomInIcon = new QToolButton;
 25    zoomInIcon->setAutoRepeat(true);
 26    zoomInIcon->setAutoRepeatInterval(33);
 27    zoomInIcon->setAutoRepeatDelay(0);
 28    zoomInIcon->setIcon(QPixmap(":/zoomin.png"));
 29    zoomInIcon->setIconSize(iconSize);
 30    QToolButton *zoomOutIcon = new QToolButton;
 31    zoomOutIcon->setAutoRepeat(true);
 32    zoomOutIcon->setAutoRepeatInterval(33);
 33    zoomOutIcon->setAutoRepeatDelay(0);
 34    zoomOutIcon->setIcon(QPixmap(":/zoomout.png"));
 35    zoomOutIcon->setIconSize(iconSize);
 36    zoomSlider = new QSlider;
 37    zoomSlider->setMinimum(0);
 38    zoomSlider->setMaximum(500);
 39    zoomSlider->setValue(250);
 40    zoomSlider->setTickPosition(QSlider::TicksRight);
 41
 42    // Zoom slider layout
 43    QVBoxLayout *zoomSliderLayout = new QVBoxLayout;
 44    zoomSliderLayout->addWidget(zoomInIcon);
 45    zoomSliderLayout->addWidget(zoomSlider);
 46    zoomSliderLayout->addWidget(zoomOutIcon);
 47
 48
 49    QGridLayout *topLayout = new QGridLayout;
 50
 51    topLayout->addWidget(graphicsView, 1, 0);
 52    topLayout->addLayout(zoomSliderLayout, 1, 1);
 53    setLayout(topLayout);
 54
 55    connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
 56    connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
 57    connect(graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
 58
 59    connect(zoomInIcon, SIGNAL(clicked()), this, SLOT(zoomIn()));
 60    connect(zoomOutIcon, SIGNAL(clicked()), this, SLOT(zoomOut()));
 61
 62
 63    setupMatrix();
 64}
 65
 66void View::setAngle(qreal angle)
 67{
 68    curAngle = angle;
 69    setupMatrix();
 70
 71}
 72
 73QGraphicsView *View::gr_view() const
 74{
 75    return graphicsView;
 76}
 77
 78void View::resetView()
 79{
 80    zoomSlider->setValue(250);
 81
 82    setupMatrix();
 83    graphicsView->ensureVisible(QRectF(0, 0, 0, 0));
 84
 85    //resetButton->setEnabled(false);
 86}
 87
 88void View::setResetButtonEnabled()
 89{
 90    //resetButton->setEnabled(true);
 91}
 92
 93void View::setupMatrix()
 94{
 95    qreal scale = qPow(qreal(2), (zoomSlider->value() - 250) / qreal(50));
 96
 97    QMatrix matrix;
 98
 99    //matrix = graphicsView->matrix();
100    //matrix.scale(1., 1.);
101    matrix.scale(scale, scale);
102    matrix.rotate(curAngle);
103    graphicsView->setMatrix(matrix);
104
105}
106
107
108void View::setGridSize(int g_size)
109{
110    graphicsView->setInterval(g_size);
111}
112
113void View::setShowGrid(bool grid_show)
114{
115    graphicsView->setShowGrid(grid_show);
116}
117
118void View::toggleAntialiasing()
119{
120    /*
121    graphicsView->setRenderHint(QPainter::Antialiasing,
122                                antialiasButton->isChecked());
123                                */
124}
125
126
127void View::zoomIn()
128{
129    zoomSlider->setValue(zoomSlider->value() + 1);
130}
131
132void View::zoomOut()
133{
134    zoomSlider->setValue(zoomSlider->value() - 1);
135}