Key Shortcuts for Zooming. Refactored some event propogation.

Review URL: https://codereview.appspot.com/6452052

git-svn-id: http://skia.googlecode.com/svn/trunk@4794 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
chudy@google.com 2012-07-26 20:26:44 +00:00
parent 7eed139383
commit a1226319b7
5 changed files with 43 additions and 11 deletions

View File

@ -110,15 +110,15 @@ void SkCanvasWidget::updateWidgetTransform(TransformType type) {
}
}
void SkCanvasWidget::wheelEvent(QWheelEvent* event) {
fScaleFactor += event->delta()/120;
void SkCanvasWidget::zoom(float zoomIncrement) {
fScaleFactor += zoomIncrement;
/* The range of the fScaleFactor crosses over the range -1,0,1 frequently.
* Based on the code below, -1 and 1 both scale the image to it's original
* size we do the following to never have a registered wheel scroll
* not effect the fScaleFactor. */
* Based on the code below, -1 and 1 both scale the image to it's original
* size we do the following to never have a registered wheel scroll
* not effect the fScaleFactor. */
if (fScaleFactor == 0) {
fScaleFactor += (event->delta()/120) * 2;
fScaleFactor = 2 * zoomIncrement;
}
emit scaleFactorChanged(fScaleFactor);
updateWidgetTransform(kScale);

View File

@ -100,13 +100,18 @@ public:
return &fRasterWidget;
}
void zoom(float zoomIncrement);
signals:
void scaleFactorChanged(float newScaleFactor);
void commandChanged(int newCommand);
void hitChanged(int hit);
private slots:
void keyZoom(int zoomIncrement) {
zoom(zoomIncrement);
}
private:
QHBoxLayout fHorizontalLayout;
SkRasterWidget fRasterWidget;
@ -132,7 +137,9 @@ private:
void mouseDoubleClickEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
void wheelEvent(QWheelEvent* event) {
zoom(event->delta()/120);
}
};

View File

@ -28,6 +28,9 @@ SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
, fActionShowDeletes(this)
, fActionStepBack(this)
, fActionStepForward(this)
, fActionZoomIn(this)
, fActionZoomOut(this)
, fMapper(this)
, fCentralWidget(this)
, fFilter(&fCentralWidget)
, fContainerLayout(&fCentralWidget)
@ -76,6 +79,13 @@ SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
fMapper.setMapping(&fActionZoomIn, 1);
fMapper.setMapping(&fActionZoomOut, -1);
connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(keyZoom(int)));
fInspectorWidget.setDisabled(true);
fMenuEdit.setDisabled(true);
fMenuNavigate.setDisabled(true);
@ -413,6 +423,11 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
fActionStepForward.setIcon(stepForward);
fActionStepForward.setText("Step Forward");
fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
fActionZoomIn.setText("Zoom In");
fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
fActionZoomOut.setText("Zoom Out");
fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
fListWidget.setObjectName(QString::fromUtf8("listWidget"));
fListWidget.setMaximumWidth(250);
@ -501,6 +516,8 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
fMenuView.setTitle("View");
fMenuView.addAction(&fActionBreakpoint);
fMenuView.addAction(&fActionShowDeletes);
fMenuView.addAction(&fActionZoomIn);
fMenuView.addAction(&fActionZoomOut);
fMenuWindows.setTitle("Window");
fMenuWindows.addAction(&fActionInspector);

View File

@ -202,6 +202,9 @@ private:
QAction fActionShowDeletes;
QAction fActionStepBack;
QAction fActionStepForward;
QAction fActionZoomIn;
QAction fActionZoomOut;
QSignalMapper fMapper;
QWidget fCentralWidget;
QComboBox fFilter;

View File

@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'SkCanvasWidget.h'
**
** Created: Wed Jul 11 15:15:07 2012
** Created: Thu Jul 26 15:56:26 2012
** by: The Qt Meta Object Compiler version 62 (Qt 4.6.2)
**
** WARNING! All changes made in this file will be lost!
@ -23,7 +23,7 @@ static const uint qt_meta_data_SkCanvasWidget[] = {
4, // revision
0, // classname
0, 0, // classinfo
3, 14, // methods
4, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
@ -35,6 +35,9 @@ static const uint qt_meta_data_SkCanvasWidget[] = {
68, 57, 15, 15, 0x05,
92, 88, 15, 15, 0x05,
// slots: signature, parameters, type, tag, flags
122, 108, 15, 15, 0x08,
0 // eod
};
@ -42,6 +45,7 @@ static const char qt_meta_stringdata_SkCanvasWidget[] = {
"SkCanvasWidget\0\0newScaleFactor\0"
"scaleFactorChanged(float)\0newCommand\0"
"commandChanged(int)\0hit\0hitChanged(int)\0"
"zoomIncrement\0keyZoom(int)\0"
};
const QMetaObject SkCanvasWidget::staticMetaObject = {
@ -76,9 +80,10 @@ int SkCanvasWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
case 0: scaleFactorChanged((*reinterpret_cast< float(*)>(_a[1]))); break;
case 1: commandChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
case 2: hitChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
case 3: keyZoom((*reinterpret_cast< int(*)>(_a[1]))); break;
default: ;
}
_id -= 3;
_id -= 4;
}
return _id;
}