1 #include "pixmapviewer.h"
4 void PixmapViewer::paintEvent(QPaintEvent
* )
9 int edge
= qMin(s
.width(), s
.height()) - 4;
10 int offx
= (s
.width() - edge
) / 2;
11 int offy
= (s
.height() - edge
) / 2;
12 QRect
r(offx
, offy
, edge
, edge
);
13 p
.fillRect(r
, Qt::white
);
14 p
.drawLine(edge
+ offx
, offy
, offx
, offy
+edge
);
15 p
.drawLine(offx
, offy
, offx
+edge
, offy
+edge
);
18 double ratiox
= (double)s
.width()/(double)m_p
.width();
19 double ratioy
= (double)s
.height()/(double)m_p
.height();
20 double ratio
= qMin(ratiox
, ratioy
);
21 int w
= (int)(ratio
*m_p
.width());
22 int h
= (int)(ratio
*m_p
.height());
23 int offx
= (s
.width() - w
)/2;
24 int offy
= (s
.height() - h
)/2;
25 QRect
r(offx
, offy
, w
, h
);
30 //void PixmapViewer::keyPressEvent(QKeyEvent * e)
32 // if (e->key() == Qt::Key_Cancel || e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete) {
33 // setPixmap(QPixmap());
38 void PixmapViewer::mousePressEvent(QMouseEvent
* e
)
41 if (e
->buttons() & Qt::RightButton
) {
42 if ( QMessageBox::warning(0, "Unset image?", QString("Unset image?")) ) {
47 QString file
= QFileDialog::getOpenFileName(0, "Select an image");
49 if (!file
.isEmpty()) {
50 if ( tmp
.load ( file
) ) {
54 QMessageBox::warning(0, "Failure loading image", QString("Failed to load image file %1").arg(file
));