merge in my changes from soc-krdc branch
[kdenetwork.git] / krdc / kfullscreenpanel.cpp
bloba4cd2811fc70cab7de90028001244c8c08141968
1 /***************************************************************************
2 kfullscreenpanel.cpp - auto-hideable toolbar
3 -------------------
4 begin : Tue May 13 23:07:42 CET 2002
5 copyright : (C) 2002 by Tim Jansen
6 email : tim@tjansen.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include "kfullscreenpanel.h"
19 #include <kdebug.h>
20 //Added by qt3to4:
21 #include <QVBoxLayout>
22 #include <QEvent>
24 Counter::Counter(float start) :
25 m_currentValue(start) {
26 connect(&m_timer, SIGNAL(timeout()), SLOT(timeout()));
29 void Counter::count(float stop, float stepSize, float frequency) {
30 m_timer.stop();
31 m_stopValue = stop;
32 m_stepSize = stepSize;
33 m_timeoutMs = (int)(1000.0 / frequency);
34 timeout();
37 void Counter::timeout() {
38 if (m_stepSize < 0) {
39 if (m_currentValue <= m_stopValue) {
40 m_currentValue = m_stopValue;
41 emit counted(m_currentValue);
42 emit countingDownFinished();
43 return;
45 } else {
46 if (m_currentValue >= m_stopValue) {
47 m_currentValue = m_stopValue;
48 emit counted(m_currentValue);
49 emit countingUpFinished();
50 return;
53 emit counted(m_currentValue);
55 m_currentValue += m_stepSize;
56 m_timer.setSingleShot(true);
57 m_timer.start(m_timeoutMs);
61 KFullscreenPanel::KFullscreenPanel(QWidget* parent,
62 const char *name,
63 const QSize &resolution) :
64 QWidget(parent),
65 m_child(0),
66 m_layout(0),
67 m_fsResolution(resolution),
68 m_counter(0)
70 setObjectName(name);
71 connect(&m_counter, SIGNAL(countingDownFinished()), SLOT(hide()));
72 connect(&m_counter, SIGNAL(counted(float)), SLOT(movePanel(float)));
75 KFullscreenPanel::~KFullscreenPanel() {
78 void KFullscreenPanel::movePanel(float posY) {
79 move(x(), (int)posY);
80 if (!isVisible())
81 show();
84 void KFullscreenPanel::setChild(QWidget *child) {
86 if (m_layout)
87 delete m_layout;
88 m_child = child;
90 m_layout = new QVBoxLayout(this);
91 m_layout->addWidget(child);
92 doLayout();
95 void KFullscreenPanel::doLayout() {
96 QSize s = sizeHint();
97 setFixedSize(s);
98 setGeometry((m_fsResolution.width() - s.width())/2, 0,
99 s.width(), s.height());
102 void KFullscreenPanel::startShow() {
103 m_counter.count(0, height()/3.0, 24);
106 void KFullscreenPanel::startHide() {
107 m_counter.count(-height(), -height()/12.0, 24);
110 void KFullscreenPanel::enterEvent(QEvent*) {
111 emit mouseEnter();
114 void KFullscreenPanel::leaveEvent(QEvent*) {
115 emit mouseLeave();
119 #include "kfullscreenpanel.moc"