diff --git a/bottombuttongroup.cpp b/bottombuttongroup.cpp
index 573b5d1..49e6584 100644
--- a/bottombuttongroup.cpp
+++ b/bottombuttongroup.cpp
@@ -46,7 +46,9 @@ BottomButtonGroup::BottomButtonGroup(QWidget *parent)
addButton(newBtn("view-background-checkerboard", [this]() {
emit toggleCheckerboardBtnClicked();
}));
- addButton(newBtn("object-rorate-right", [](){qDebug()<< "TODO: object-rorate-right";}));
+ addButton(newBtn("object-rotate-right", [this]() {
+ emit rotateRightBtnClicked();
+ }));
}
void BottomButtonGroup::addButton(QAbstractButton *button)
diff --git a/bottombuttongroup.h b/bottombuttongroup.h
index 85f60ba..e338f5c 100644
--- a/bottombuttongroup.h
+++ b/bottombuttongroup.h
@@ -17,6 +17,7 @@ signals:
void zoomInBtnClicked();
void zoomOutBtnClicked();
void toggleCheckerboardBtnClicked();
+ void rotateRightBtnClicked();
};
#endif // BOTTOMBUTTONGROUP_H
diff --git a/graphicsview.cpp b/graphicsview.cpp
index e061651..9407d21 100644
--- a/graphicsview.cpp
+++ b/graphicsview.cpp
@@ -84,6 +84,14 @@ void GraphicsView::setScene(GraphicsScene *scene)
return QGraphicsView::setScene(scene);
}
+void GraphicsView::checkAndDoFitInView()
+{
+ if (!isThingSmallerThanWindowWith(transform())) {
+ m_enableFitInView = true;
+ fitInView(sceneRect(), Qt::KeepAspectRatio);
+ }
+}
+
void GraphicsView::toggleCheckerboard()
{
setCheckerboardEnabled(!m_checkerboardEnabled);
@@ -189,14 +197,14 @@ void GraphicsView::dropEvent(QDropEvent *event)
}
bool GraphicsView::isThingSmallerThanWindowWith(const QTransform &transform) const
-{
+{qDebug() << sceneRect();
return rect().size().expandedTo(transform.mapRect(sceneRect()).size().toSize())
== rect().size();
}
bool GraphicsView::shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const
{
- if (isThingSmallerThanWindowWith(transform())) {
+ if (event->buttons() == Qt::NoButton) {
return true;
}
@@ -205,15 +213,11 @@ bool GraphicsView::shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) con
return true;
}
- return false;
-}
-
-void GraphicsView::checkAndDoFitInView()
-{
- if (!isThingSmallerThanWindowWith(transform())) {
- m_enableFitInView = true;
- fitInView(sceneRect(), Qt::KeepAspectRatio);
+ if (isThingSmallerThanWindowWith(transform())) {
+ return true;
}
+
+ return false;
}
void GraphicsView::setCheckerboardEnabled(bool enabled)
@@ -222,9 +226,9 @@ void GraphicsView::setCheckerboardEnabled(bool enabled)
if (m_checkerboardEnabled) {
// Prepare background check-board pattern
QPixmap tilePixmap(0x20, 0x20);
- tilePixmap.fill(QColor(30, 30, 30, 100));
+ tilePixmap.fill(QColor(35, 35, 35, 110));
QPainter tilePainter(&tilePixmap);
- QColor color(40, 40, 40, 100);
+ QColor color(40, 40, 40, 110);
tilePainter.fillRect(0, 0, 0x10, 0x10, color);
tilePainter.fillRect(0x10, 0x10, 0x10, 0x10, color);
tilePainter.end();
diff --git a/graphicsview.h b/graphicsview.h
index 6ec8151..d81bef7 100644
--- a/graphicsview.h
+++ b/graphicsview.h
@@ -20,6 +20,8 @@ public:
GraphicsScene * scene() const;
void setScene(GraphicsScene *scene);
+ void checkAndDoFitInView();
+
public slots:
void toggleCheckerboard();
@@ -36,7 +38,6 @@ private:
bool isThingSmallerThanWindowWith(const QTransform &transform) const;
bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const;
- void checkAndDoFitInView();
void setCheckerboardEnabled(bool enabled);
bool m_enableFitInView = false;
diff --git a/icons/object-rorate-right.svg b/icons/object-rotate-right.svg
similarity index 100%
rename from icons/object-rorate-right.svg
rename to icons/object-rotate-right.svg
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 85a9fc1..35de353 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -59,13 +59,18 @@ MainWindow::MainWindow(QWidget *parent) :
m_bottomButtonGroup = new BottomButtonGroup(this);
connect(m_bottomButtonGroup, &BottomButtonGroup::resetToOriginalBtnClicked,
- this, [ = ](){ m_graphicsView->setTransform(QTransform()); });
+ this, [ = ](){ m_graphicsView->resetTransform(); });
connect(m_bottomButtonGroup, &BottomButtonGroup::zoomInBtnClicked,
this, [ = ](){ m_graphicsView->scale(1.25, 1.25); });
connect(m_bottomButtonGroup, &BottomButtonGroup::zoomOutBtnClicked,
this, [ = ](){ m_graphicsView->scale(0.75, 0.75); });
connect(m_bottomButtonGroup, &BottomButtonGroup::toggleCheckerboardBtnClicked,
this, [ = ](){ m_graphicsView->toggleCheckerboard(); });
+ connect(m_bottomButtonGroup, &BottomButtonGroup::rotateRightBtnClicked,
+ this, [ = ](){
+ m_graphicsView->rotate(90);
+ m_graphicsView->checkAndDoFitInView();
+ });
centerWindow();
}
@@ -114,7 +119,8 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
if (event->buttons() & Qt::LeftButton) {
m_clickedOnWindow = true;
m_oldMousePos = event->pos();
- qDebug() << m_oldMousePos;
+ qDebug() << m_oldMousePos << m_graphicsView->transform().m11()
+ << m_graphicsView->transform().m22() << m_graphicsView->matrix().m11();
event->accept();
}
diff --git a/resources.qrc b/resources.qrc
index 608eea7..d4311dc 100644
--- a/resources.qrc
+++ b/resources.qrc
@@ -4,7 +4,7 @@
icons/zoom-out.svg
icons/view-fullscreen.svg
icons/zoom-original.svg
- icons/object-rorate-right.svg
+ icons/object-rotate-right.svg
icons/view-background-checkerboard.svg
icons/app-icon.svg