]> git.cworth.org Git - apitrace/blob - gui/imageviewer.cpp
Removed unused copy of thumbnails.
[apitrace] / gui / imageviewer.cpp
1 #include "imageviewer.h"
2
3 #include <QDesktopWidget>
4 #include <QPainter>
5 #include <QPixmap>
6 #include <QScrollBar>
7
8 ImageViewer::ImageViewer(QWidget *parent)
9     : QDialog(parent)
10 {
11     setupUi(this);
12
13     QPixmap px(32, 32);
14     QPainter p(&px);
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));
18     p.end();
19     QPalette pal = scrollAreaWidgetContents->palette();
20     pal.setBrush(QPalette::Background,
21                  QBrush(px));
22     pal.setBrush(QPalette::Base,
23                  QBrush(px));
24     scrollAreaWidgetContents->setPalette(pal);
25 }
26
27 void ImageViewer::setImage(const QImage &image)
28 {
29     m_image = image;
30     QPixmap px = QPixmap::fromImage(image);
31     imageLabel->setPixmap(px);
32     updateGeometry();
33 }
34
35 QSize ImageViewer::sizeHint() const
36 {
37     QSize size;
38
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);
45
46     QRect screenRect = QApplication::desktop()->availableGeometry();
47     const float maxPercentOfDesktopSpace = 0.8;
48     QSize maxAvailableSize(maxPercentOfDesktopSpace * screenRect.width(),
49                            maxPercentOfDesktopSpace * screenRect.height());
50
51     return QSize(qMin(optimalWindowSize.width(), maxAvailableSize.width()),
52                  qMin(optimalWindowSize.height(), maxAvailableSize.height()));
53 }
54
55 #include "imageviewer.moc"