fix start/stop/pause
[Sak.git] / pixmapviewer.cpp
blobc30d86eb1552a928522b5e0ab334b36dcb768988
1 #include "pixmapviewer.h"
4 void PixmapViewer::paintEvent(QPaintEvent* )
6 QPainter p(this);
7 QSize s = size();
8 if (m_p.isNull()) {
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);
16 p.drawRect(r);
17 } else {
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);
26 p.drawPixmap(r, m_p);
31 void PixmapViewer::mousePressEvent(QMouseEvent* e)
33 if (e->buttons()) {
34 if (e->buttons() & Qt::RightButton) {
35 if ( QMessageBox::warning(0, "Unset image?", QString("Unset image?")) ) {
36 setPixmap(QPixmap());
37 emit changed();
39 } else {
40 QString file = QFileDialog::getOpenFileName(0, "Select an image");
41 QPixmap tmp;
42 if (!file.isEmpty()) {
43 if (tmp.load ( file ) ) {
44 setPixmap(tmp);
45 QMessageBox::warning(0, "Failure loading image", QString("Failed load image file %1").arg(file));
46 emit changed();