From 2ffe9f84af4555b6e85c9b47c5c217a975436d9f Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Fri, 23 Sep 2011 20:25:47 -0400 Subject: Cleanup the default size computation for the surface viewer. --- gui/imageviewer.cpp | 24 ++++++++++++++++++++++++ gui/imageviewer.h | 4 ++++ gui/mainwindow.cpp | 3 --- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/gui/imageviewer.cpp b/gui/imageviewer.cpp index fd5ec5d..4a11da5 100644 --- a/gui/imageviewer.cpp +++ b/gui/imageviewer.cpp @@ -1,7 +1,9 @@ #include "imageviewer.h" +#include #include #include +#include ImageViewer::ImageViewer(QWidget *parent) : QDialog(parent) @@ -24,8 +26,30 @@ ImageViewer::ImageViewer(QWidget *parent) void ImageViewer::setImage(const QImage &image) { + m_image = image; QPixmap px = QPixmap::fromImage(image); imageLabel->setPixmap(px); + updateGeometry(); +} + +QSize ImageViewer::sizeHint() const +{ + QSize size; + + int vScrollWidth = scrollArea->verticalScrollBar() ? + scrollArea->verticalScrollBar()->width() : 0; + int hScrollHeight = scrollArea->horizontalScrollBar() ? + scrollArea->horizontalScrollBar()->height() : 0; + QSize optimalWindowSize(m_image.width() + vScrollWidth, + m_image.height() + hScrollHeight); + + QRect screenRect = QApplication::desktop()->availableGeometry(); + const float maxPercentOfDesktopSpace = 0.8; + QSize maxAvailableSize(maxPercentOfDesktopSpace * screenRect.width(), + maxPercentOfDesktopSpace * screenRect.height()); + + return QSize(qMin(optimalWindowSize.width(), maxAvailableSize.width()), + qMin(optimalWindowSize.height(), maxAvailableSize.height())); } #include "imageviewer.moc" diff --git a/gui/imageviewer.h b/gui/imageviewer.h index 05e8f45..16bc7f2 100644 --- a/gui/imageviewer.h +++ b/gui/imageviewer.h @@ -11,6 +11,10 @@ public: ImageViewer(QWidget *parent = 0); void setImage(const QImage &image); + + QSize sizeHint() const; +private: + QImage m_image; }; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 8d7af8a..3ee8cc2 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -618,9 +618,6 @@ void MainWindow::showSelectedSurface() QImage img = var.value(); viewer->setImage(img); - QRect screenRect = QApplication::desktop()->availableGeometry(); - viewer->resize(qMin(int(0.75 * screenRect.width()), img.width()) + 40, - qMin(int(0.75 * screenRect.height()), img.height()) + 40); viewer->show(); viewer->raise(); viewer->activateWindow(); -- cgit v1.2.3