annotate src/imagelabel.cpp @ 38:26e1521b9afd

Add the possibility to detach the picture label on doubleclick
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 06 May 2015 18:09:34 +0200
parents 6b9b5efcd7f4
children
rev   line source
24
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
1 /* Copyright (C) 2015 by ETH Zürich
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
2 * Software engineering by Intevation GmbH
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
3 *
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
6 * See LICENSE.txt for details.
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
7 */
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
8
3
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 #include "imagelabel.h"
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11 ImageLabel::ImageLabel(QWidget *parent) :
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 QWidget(parent) {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13 label = new QLabel(this);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 label->setScaledContents(true);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 label->setFixedSize(0,0);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 void ImageLabel::resizeEvent(QResizeEvent *event) {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19 QWidget::resizeEvent(event);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
20 resizeImage();
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23 const QPixmap* ImageLabel::pixmap() const {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 return label->pixmap();
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 void ImageLabel::setPixmap (const QPixmap &pixmap){
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 label->setPixmap(pixmap);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 resizeImage();
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32 void ImageLabel::resizeImage() {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 QSize pixSize = label->pixmap()->size();
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 pixSize.scale(size(), Qt::KeepAspectRatio);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 label->setFixedSize(pixSize);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 }
38
26e1521b9afd Add the possibility to detach the picture label on doubleclick
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
37
26e1521b9afd Add the possibility to detach the picture label on doubleclick
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
38 void ImageLabel::mouseDoubleClickEvent(QMouseEvent * e) {
26e1521b9afd Add the possibility to detach the picture label on doubleclick
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
39 QWidget::mouseDoubleClickEvent(e);
26e1521b9afd Add the possibility to detach the picture label on doubleclick
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
40 emit doubleClicked();
26e1521b9afd Add the possibility to detach the picture label on doubleclick
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
41 }
26e1521b9afd Add the possibility to detach the picture label on doubleclick
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
42
26e1521b9afd Add the possibility to detach the picture label on doubleclick
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
43 void ImageLabel::closeEvent(QCloseEvent *e) {
26e1521b9afd Add the possibility to detach the picture label on doubleclick
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
44 Q_UNUSED(e);
26e1521b9afd Add the possibility to detach the picture label on doubleclick
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
45 emit closeRequested();
26e1521b9afd Add the possibility to detach the picture label on doubleclick
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
46 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)