summaryrefslogtreecommitdiffstats
path: root/kwin/popupinfo.cpp
blob: d07e7262ccf31f753246307bc4b7400b53afe969 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*****************************************************************
 KWin - the KDE window manager
 This file is part of the KDE project.

Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 2002 Alexander Kellett <lypanov@kde.org>
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>

You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/

//#define QT_CLEAN_NAMESPACE
#include "popupinfo.h"
#include "workspace.h"
#include "client.h"
#include <tqpainter.h>
#include <tqlabel.h>
#include <tqdrawutil.h>
#include <tqstyle.h>
#include <kglobal.h>
#include <fixx11h.h>
#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>
#include <tqapplication.h>
#include <tqdesktopwidget.h>
#include <kstringhandler.h>
#include <kglobalsettings.h>

// specify externals before namespace

namespace KWinInternal
{

PopupInfo::PopupInfo( Workspace* ws, const char *name )
    : TQWidget( 0, name ), workspace( ws )
    {
    m_infoString = "";
    m_shown = false;
    reset();
    reconfigure();
    connect(&m_delayedHideTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(hide()));

    TQFont f = font();
    f.setBold( TRUE );
    f.setPointSize( 14 );
    setFont( f );

    }

PopupInfo::~PopupInfo()
    {
    }


/*!
  Resets the popup info
 */
void PopupInfo::reset()
    {
    TQRect r = workspace->screenGeometry( workspace->activeScreen());

    int w = fontMetrics().width( m_infoString ) + 30;

    setGeometry( 
       (r.width()-w)/2 + r.x(), r.height()/2-fontMetrics().height()-10 + r.y(),
                 w,                       fontMetrics().height() + 20 );
    }


/*!
  Paints the popup info
 */
void PopupInfo::paintEvent( TQPaintEvent* )
    {
    TQPainter p( this );
    style().drawPrimitive( TQStyle::PE_Panel, &p, TQRect( 0, 0, width(), height() ),
          tqcolorGroup(), TQStyle::Style_Default );
    paintContents();
    }


/*!
  Paints the contents of the tab popup info box. 
  Used in paintEvent() and whenever the contents changes.
 */
void PopupInfo::paintContents()
    {
    TQPainter p( this );
    TQRect r( 6, 6, width()-12, height()-12 );

    p.fillRect( r, tqcolorGroup().brush( TQColorGroup::Background ) );

    /*
    p.setPen(Qt::white);
    p.drawText( r, AlignCenter, m_infoString );
    p.setPen(Qt::black);
    r.moveBy( -1, -1 );
    p.drawText( r, AlignCenter, m_infoString );
    r.moveBy( -1, 0 );
    */
    p.drawText( r, AlignCenter, m_infoString );
    }

void PopupInfo::hide()
    {
    m_delayedHideTimer.stop();
    TQWidget::hide();
    TQApplication::syncX();
    XEvent otherEvent;
    while (XCheckTypedEvent (qt_xdisplay(), EnterNotify, &otherEvent ) )
        ;
    m_shown = false;
    }

void PopupInfo::reconfigure() 
    {
    KConfig * c(KGlobal::config());
    c->setGroup("PopupInfo");
    m_show = c->readBoolEntry("ShowPopup", false );
    m_delayTime = c->readNumEntry("PopupHideDelay", 350 );
    }

void PopupInfo::showInfo(TQString infoString)
    {
    if (m_show) 
        {
        m_infoString = infoString;
        reset();
        if (m_shown) 
            {
            paintContents();
            }
        else 
            {
            show();
            raise();
            m_shown = true;
            }
        m_delayedHideTimer.start(m_delayTime, true);
        }
    }

} // namespace

#include "popupinfo.moc"