summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Rusin <zack@kde.org>2011-09-23 20:25:47 -0400
committerZack Rusin <zack@kde.org>2011-09-24 13:44:07 -0400
commit2ffe9f84af4555b6e85c9b47c5c217a975436d9f (patch)
tree9c0833eaf7975b2f564103a5d4d7c1f50497f2b4
parent07bb055d977040d022c05962b45f2349bc0c8c2b (diff)
Cleanup the default size computation for the surface viewer.
-rw-r--r--gui/imageviewer.cpp24
-rw-r--r--gui/imageviewer.h4
-rw-r--r--gui/mainwindow.cpp3
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 <QDesktopWidget>
#include <QPainter>
#include <QPixmap>
+#include <QScrollBar>
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<QImage>();
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();