diff --git a/graphicsview.cpp b/graphicsview.cpp index 08dfc96..5e46df6 100644 --- a/graphicsview.cpp +++ b/graphicsview.cpp @@ -142,12 +142,16 @@ void GraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadio applyTransformationModeByScaleFactor(); } -void GraphicsView::checkAndDoFitInView() +void GraphicsView::checkAndDoFitInView(bool markItOnAnyway) { if (!isThingSmallerThanWindowWith(transform())) { m_enableFitInView = true; fitInView(sceneRect(), Qt::KeepAspectRatio); } + + if (markItOnAnyway) { + m_enableFitInView = true; + } } void GraphicsView::toggleCheckerboard() diff --git a/graphicsview.h b/graphicsview.h index 96a6046..f942562 100644 --- a/graphicsview.h +++ b/graphicsview.h @@ -30,7 +30,7 @@ public: void rotateView(qreal rotateAngel); void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio); - void checkAndDoFitInView(); + void checkAndDoFitInView(bool markItOnAnyway = true); signals: void navigatorViewRequired(bool required, qreal angle); diff --git a/mainwindow.cpp b/mainwindow.cpp index 1ff9275..d883f02 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -29,7 +29,7 @@ MainWindow::MainWindow(QWidget *parent) : { this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); this->setAttribute(Qt::WA_TranslucentBackground, true); - this->setMinimumSize(710, 530); + this->setMinimumSize(350, 350); this->setWindowIcon(QIcon(":/icons/app-icon.svg")); this->setMouseTracking(true); @@ -187,11 +187,11 @@ void MainWindow::adjustWindowSizeBySceneRect() QSize screenSize = qApp->screenAt(QCursor::pos())->availableSize(); if (screenSize.expandedTo(sceneSize) == screenSize) { // we can show the picture by increase the window size. - if (screenSize.expandedTo(sceneSizeWithMargins) == screenSize) { - this->resize(sceneSizeWithMargins); - } else { - this->resize(screenSize); - } + QSize finalSize = (screenSize.expandedTo(sceneSizeWithMargins) == screenSize) ? + sceneSizeWithMargins : screenSize; + // We have a very reasonable sizeHint() value ;P + this->resize(finalSize.expandedTo(this->sizeHint())); + // We're sure the window can display the whole thing with 1:1 scale. // The old window size may cause fitInView call from resize() and the // above resize() call won't reset the scale back to 1:1, so we @@ -559,6 +559,11 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r #endif // _WIN32 } +QSize MainWindow::sizeHint() const +{ + return QSize(710, 530); +} + void MainWindow::centerWindow() { this->setGeometry( diff --git a/mainwindow.h b/mainwindow.h index 6d9d798..0d3c8de 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -50,6 +50,8 @@ protected slots: bool nativeEvent(const QByteArray& eventType, void* message, long* result) override; + QSize sizeHint() const override; + void centerWindow(); void closeWindow(); void updateWidgetsPosition();