1 #include "imageviewer.h"
3 #include <QDesktopWidget>
8 ImageViewer::ImageViewer(QWidget *parent)
15 p.fillRect(0, 0, 32, 32, Qt::white);
16 p.fillRect(0, 0, 16, 16, QColor(193, 193, 193));
17 p.fillRect(16, 16, 16, 16, QColor(193, 193, 193));
19 QPalette pal = scrollAreaWidgetContents->palette();
20 pal.setBrush(QPalette::Background,
22 pal.setBrush(QPalette::Base,
24 scrollAreaWidgetContents->setPalette(pal);
27 void ImageViewer::setImage(const QImage &image)
30 QPixmap px = QPixmap::fromImage(image);
31 imageLabel->setPixmap(px);
35 QSize ImageViewer::sizeHint() const
39 int vScrollWidth = scrollArea->verticalScrollBar() ?
40 scrollArea->verticalScrollBar()->width() : 0;
41 int hScrollHeight = scrollArea->horizontalScrollBar() ?
42 scrollArea->horizontalScrollBar()->height() : 0;
43 QSize optimalWindowSize(m_image.width() + vScrollWidth,
44 m_image.height() + hScrollHeight);
46 QRect screenRect = QApplication::desktop()->availableGeometry();
47 const float maxPercentOfDesktopSpace = 0.8;
48 QSize maxAvailableSize(maxPercentOfDesktopSpace * screenRect.width(),
49 maxPercentOfDesktopSpace * screenRect.height());
51 return QSize(qMin(optimalWindowSize.width(), maxAvailableSize.width()),
52 qMin(optimalWindowSize.height(), maxAvailableSize.height()));
55 #include "imageviewer.moc"