Changeset View
Changeset View
Standalone View
Standalone View
src/ui/imagepreviewwidget.cpp
Show All 24 Lines | |||||
25 | #include <core/entryinternal.h> | 25 | #include <core/entryinternal.h> | ||
26 | 26 | | |||
27 | using namespace KNS3; | 27 | using namespace KNS3; | ||
28 | 28 | | |||
29 | ImagePreviewWidget::ImagePreviewWidget(QWidget *parent) : | 29 | ImagePreviewWidget::ImagePreviewWidget(QWidget *parent) : | ||
30 | QWidget(parent) | 30 | QWidget(parent) | ||
31 | { | 31 | { | ||
32 | //installEventFilter(this); | 32 | //installEventFilter(this); | ||
33 | | ||||
34 | const QString framefile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/knewstuff/pics/thumb_frame.png")); | | |||
35 | m_frameImage = QPixmap(framefile); | | |||
36 | } | 33 | } | ||
37 | 34 | | |||
38 | void ImagePreviewWidget::setImage(const QImage &preview) | 35 | void ImagePreviewWidget::setImage(const QImage &preview) | ||
39 | { | 36 | { | ||
40 | m_image = preview; | 37 | m_image = preview; | ||
41 | m_scaledImage = QImage(); | 38 | m_scaledImage = QImage(); | ||
42 | updateGeometry(); | 39 | updateGeometry(); | ||
43 | repaint(); | 40 | repaint(); | ||
Show All 31 Lines | 57 | { | |||
75 | } | 72 | } | ||
76 | 73 | | |||
77 | QPoint point; | 74 | QPoint point; | ||
78 | 75 | | |||
79 | point.setX(contentsRect().left() + ((width - m_scaledImage.width()) / 2)); | 76 | point.setX(contentsRect().left() + ((width - m_scaledImage.width()) / 2)); | ||
80 | point.setY(contentsRect().top() + ((height - m_scaledImage.height()) / 2)); | 77 | point.setY(contentsRect().top() + ((height - m_scaledImage.height()) / 2)); | ||
81 | 78 | | |||
82 | QPoint framePoint(point.x() - 5, point.y() - 5); | 79 | QPoint framePoint(point.x() - 5, point.y() - 5); | ||
83 | painter.drawPixmap(framePoint, m_frameImage.scaled(m_scaledImage.width() + 10, m_scaledImage.height() + 10)); | | |||
84 | painter.drawImage(point, m_scaledImage); | 80 | painter.drawImage(point, m_scaledImage); | ||
85 | } | 81 | } | ||
86 | 82 | | |||
87 | QSize ImagePreviewWidget::sizeHint() const | 83 | QSize ImagePreviewWidget::sizeHint() const | ||
88 | { | 84 | { | ||
89 | if (m_image.isNull()) { | 85 | if (m_image.isNull()) { | ||
90 | return QSize(); | 86 | return QSize(); | ||
91 | } | 87 | } | ||
92 | QSize sh = m_image.size(); | 88 | QSize sh = m_image.size(); | ||
93 | sh.scale(maximumSize(), Qt::KeepAspectRatio); | 89 | sh.scale(maximumSize(), Qt::KeepAspectRatio); | ||
94 | return sh; | 90 | return sh; | ||
95 | } | 91 | } |