Prepare new maemo release
[maemo-rb.git] / rbutil / rbutilqt / preview.cpp
blob72af37deeeeaf14abde19133db82ccc5d2d591d1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include <QDialog>
20 #include <QMouseEvent>
22 #include "preview.h"
24 PreviewDlg::PreviewDlg(QWidget *parent) : QDialog(parent)
26 ui.setupUi(this);
27 this->setModal(true);
28 this->setMouseTracking(true);
29 this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
33 void PreviewDlg::setText(QString text)
35 ui.themePreview->setText(text);
38 void PreviewDlg::setPixmap(QPixmap p)
40 ui.themePreview->setFixedSize(p.size());
41 this->resize(QSize(10,10));
42 ui.themePreview->setPixmap(p);
45 void PreviewDlg::mouseMoveEvent(QMouseEvent * event)
47 (void) event;
48 this->close();
51 void PreviewDlg::leaveEvent(QEvent * event)
53 (void) event;
54 this->close();
58 void PreviewDlg::changeEvent(QEvent *e)
60 if(e->type() == QEvent::LanguageChange) {
61 ui.retranslateUi(this);
62 } else {
63 QWidget::changeEvent(e);
67 PreviewLabel::PreviewLabel(QWidget * parent, Qt::WindowFlags f)
68 :QLabel(parent,f)
70 this->setMouseTracking(true);
72 preview = new PreviewDlg(parent);
74 hovertimer.setInterval(1500); // wait for 1.5 seconds before showing the Fullsize Preview
75 hovertimer.setSingleShot(true);
76 connect(&hovertimer,SIGNAL(timeout ()),this,SLOT(timeout()));
79 void PreviewLabel::mouseMoveEvent(QMouseEvent * event)
81 hovertimer.start();
82 mousex = event->globalX();
83 mousey = event->globalY();
85 void PreviewLabel::enterEvent(QEvent * event)
87 (void) event;
88 hovertimer.start();
90 void PreviewLabel::leaveEvent(QEvent * event)
92 (void) event;
93 hovertimer.stop();
96 void PreviewLabel::timeout()
98 preview->move(mousex-(preview->width()/2) ,mousey-(preview->height()/2));
99 preview->setVisible(true);
102 void PreviewLabel::setPixmap(QPixmap p)
104 // set the image for the Fullsize Preview
105 preview->setPixmap(p);
107 //scale the image for use in the label
108 QSize img;
109 img.setHeight(this->height());
110 img.setWidth(this->width());
111 QPixmap q;
112 q = p.scaled(img, Qt::KeepAspectRatio, Qt::SmoothTransformation);
113 this->setScaledContents(false);
114 QLabel::setPixmap(q);
117 void PreviewLabel::setText(QString text)
119 QLabel::setText(text);
120 preview->setText(text);