minor tweaks, fix typo, add new bug
This commit is contained in:
parent
e0d5c9db3d
commit
ad879f8f8b
|
@ -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)
|
||||
|
|
|
@ -17,6 +17,7 @@ signals:
|
|||
void zoomInBtnClicked();
|
||||
void zoomOutBtnClicked();
|
||||
void toggleCheckerboardBtnClicked();
|
||||
void rotateRightBtnClicked();
|
||||
};
|
||||
|
||||
#endif // BOTTOMBUTTONGROUP_H
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<file>icons/zoom-out.svg</file>
|
||||
<file>icons/view-fullscreen.svg</file>
|
||||
<file>icons/zoom-original.svg</file>
|
||||
<file>icons/object-rorate-right.svg</file>
|
||||
<file>icons/object-rotate-right.svg</file>
|
||||
<file>icons/view-background-checkerboard.svg</file>
|
||||
<file>icons/app-icon.svg</file>
|
||||
</qresource>
|
||||
|
|
Loading…
Reference in New Issue
Block a user