Skip to content

Commit

Permalink
#38 - zoom in and out not smooth and can be better
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaza-Is committed Feb 19, 2016
1 parent 3b80f64 commit 58e7e11
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,18 @@ void Canvas::drawBackground(QPainter *painter, const QRectF &rect)
}
}

void Canvas::Zoom(int val)
{
qreal sf = 0.0;
if(val<6){
sf = 1.0 / val;
}
else{
sf = val - 5;
}
d->view->matrix().reset();
d->view->scale(sf,sf);
}

} // namespace Logicsim

3 changes: 3 additions & 0 deletions src/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Canvas : public QGraphicsScene

void drawBackground(QPainter *painter, const QRectF &rect);

public Q_SLOTS:
void Zoom(int val);

private:
class Private;
Private* const d;
Expand Down
8 changes: 8 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ MainWindow::MainWindow(QWidget *parent)
ui->frameGridLayout->addWidget(d->tabWidget);
d->tabWidget->setTabsClosable(true);

ui->horizontalSlider->setRange(1,11);
//ui->horizontalSlider->setSingleStep(1);
ui->horizontalSlider->setFocusPolicy(Qt::StrongFocus);
ui->horizontalSlider->setTickPosition(QSlider::TicksBothSides);

// Connection
connect(ui->actionNew, SIGNAL(triggered(bool)),
this, SLOT(newFile()));
Expand Down Expand Up @@ -132,6 +137,7 @@ Canvas* MainWindow::newFile()

connect(this, SIGNAL(notLastTabClosed(int)),
d->workspaceTab, SLOT(updateComponents()));

}
d->tabsCount++;
int tabIndex = d->tabWidget->addTab(c->view(), "New Circuit");
Expand Down Expand Up @@ -184,6 +190,8 @@ void MainWindow::changeManager(int index)
void MainWindow::tabChanged(int index)
{
d->activeTabIndex = index;
connect(ui->horizontalSlider,SIGNAL(valueChanged(int)),
d->canvases[d->activeTabIndex],SLOT(Zoom(int)));
}

void MainWindow::tabAboutToBeClosed(int index)
Expand Down
9 changes: 8 additions & 1 deletion src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Zoom</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider">
<property name="orientation">
Expand All @@ -103,7 +110,7 @@
<x>0</x>
<y>0</y>
<width>1280</width>
<height>28</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down

0 comments on commit 58e7e11

Please sign in to comment.