Improve voice creation window a bit.
[maemo-rb.git] / rbutil / rbutilqt / preview.cpp
blob5a304933af51707483221caeff3ff6f2ba24a9fa
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 <QtGui>
21 #include "preview.h"
23 PreviewDlg::PreviewDlg(QWidget *parent) : QDialog(parent)
25 ui.setupUi(this);
26 this->setModal(true);
27 this->setMouseTracking(true);
28 this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
32 void PreviewDlg::setText(QString text)
34 ui.themePreview->setText(text);
37 void PreviewDlg::setPixmap(QPixmap p)
39 ui.themePreview->setFixedSize(p.size());
40 this->resize(QSize(10,10));
41 ui.themePreview->setPixmap(p);
44 void PreviewDlg::mouseMoveEvent(QMouseEvent * event)
46 (void) event;
47 this->close();
50 void PreviewDlg::leaveEvent(QEvent * event)
52 (void) event;
53 this->close();
57 void PreviewDlg::changeEvent(QEvent *e)
59 if(e->type() == QEvent::LanguageChange) {
60 ui.retranslateUi(this);
61 } else {
62 QWidget::changeEvent(e);
66 PreviewLabel::PreviewLabel(QWidget * parent, Qt::WindowFlags f)
67 :QLabel(parent,f)
69 this->setMouseTracking(true);
71 preview = new PreviewDlg(parent);
73 hovertimer.setInterval(1500); // wait for 1.5 seconds before showing the Fullsize Preview
74 hovertimer.setSingleShot(true);
75 connect(&hovertimer,SIGNAL(timeout ()),this,SLOT(timeout()));
78 void PreviewLabel::mouseMoveEvent(QMouseEvent * event)
80 hovertimer.start();
81 mousex = event->globalX();
82 mousey = event->globalY();
84 void PreviewLabel::enterEvent(QEvent * event)
86 (void) event;
87 hovertimer.start();
89 void PreviewLabel::leaveEvent(QEvent * event)
91 (void) event;
92 hovertimer.stop();
95 void PreviewLabel::timeout()
97 preview->move(mousex-(preview->width()/2) ,mousey-(preview->height()/2));
98 preview->setVisible(true);
101 void PreviewLabel::setPixmap(QPixmap p)
103 // set the image for the Fullsize Preview
104 preview->setPixmap(p);
106 //scale the image for use in the label
107 QSize img;
108 img.setHeight(this->height());
109 img.setWidth(this->width());
110 QPixmap q;
111 q = p.scaled(img, Qt::KeepAspectRatio, Qt::SmoothTransformation);
112 this->setScaledContents(false);
113 QLabel::setPixmap(q);
116 void PreviewLabel::setText(QString text)
118 QLabel::setText(text);
119 preview->setText(text);