-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagewidget.cpp
33 lines (30 loc) · 1019 Bytes
/
imagewidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "imagewidget.h"
ImageWidget::ImageWidget(QPixmap p, int width, int height) {
originalPixmap = p;
if (width > 0 && height > 0)
pixmap = originalPixmap.scaled(width, height, Qt::KeepAspectRatio);
else if (width > 0)
pixmap = originalPixmap.scaledToWidth(width);
setPixmap(pixmap);
height = pixmap.height();
initialWidth = width;
initialHeight = height;
setAlignment(Qt::AlignCenter);
//setFixedSize(width, height);
//setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
void ImageWidget::resizeEvent(QResizeEvent* event)
{
pixmap = originalPixmap.scaled(event->size().width(),
event->size().height(),
Qt::KeepAspectRatio);
setPixmap(pixmap);
}
void ImageWidget::scale(float s)
{
totalScale*=s;
int w = initialWidth*totalScale;
int h = initialHeight*totalScale;
//pixmap = originalPixmap.scaled(w, h, Qt::KeepAspectRatio);
setFixedSize(w,h);
}