1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://sam.zoy.org/wtfpl/COPYING for more details.
17 #include <QVBoxLayout>
27 class K8PopupLayout
: public QVBoxLayout
{
31 K8PopupLayout (int aWidth
, QWidget
*parent
=0) : QVBoxLayout(parent
) { mWidth
= aWidth
; }
34 QSize
sizeHint () const;
43 K8PopupType (const QString
&aName
, const QString
&aStyle
=QString()) : name(aName
), style(aStyle
) {}
51 ///////////////////////////////////////////////////////////////////////////////
53 class K8PopupFader
: public QWidget
{
57 K8PopupFader (QWidget
*parent
, bool aIn
);
59 inline QColor
fadeColor () const { return mStartColor
; }
60 inline void setFadeColor (const QColor
&newColor
) { mStartColor
= newColor
; }
62 inline int fadeDuration() const { return mDuration
; }
63 inline void setFadeDuration (int milliseconds
) { mDuration
= milliseconds
; }
68 void paintEvent (QPaintEvent
*event
);
81 ///////////////////////////////////////////////////////////////////////////////
82 class K8PopupWin
: public QWidget
{
84 friend class K8PopupManager
;
91 bool eventFilter (QObject
*obj
, QEvent
*event
);
92 void enterEvent (QEvent
*event
);
93 void leaveEvent (QEvent
*event
);
96 K8PopupWin (K8PopupManager
*aMan
, int aWidth
, int aHeight
, K8PopupType
*aType
,
97 const QString
&aId
, const QString
&msg
, QWidget
*parent
=0);
99 void initUI (int width
, int height
);
100 void setData (const QString
&msg
);
104 void buildAndSetMask (QWidget
*w
);
109 void onFaderInDies (QObject
*obj
);
110 void onFaderOutDies (QObject
*obj
);
114 K8PopupManager
*mMan
;
123 QVBoxLayout
*mLayout
;
124 QLabel
*mContentLabel
;
127 K8PopupFader
*mFaderIn
;
128 K8PopupFader
*mFaderOut
;
136 ///////////////////////////////////////////////////////////////////////////////
137 class K8PopupManager
: public QObject
{
139 friend class K8PopupWin
;
143 LeftTop
=0, TopLeft
=0,
144 RightTop
=1, TopRight
=1,
145 LeftBottom
=2, BottomLeft
=2,
146 RightBottom
=3, BottomRight
=3
150 K8PopupManager (int width
, int height
, uint timeout
, Position pos
);
153 /* WARNING: DO NOT CALL THIS WHEN POPUPS ACTIVE! */
154 void addType (const QString
&aName
, const QString
&aStyle
=QString());
155 void delType (const QString
&aName
);
156 bool hasType (const QString
&aName
);
158 void showMessage (const QString
&type
, const QString
&id
, const QString
&msg
);
159 void updateMessage (const QString
&type
, const QString
&id
, const QString
&msg
);
161 inline Position
position () const { return mPos
; }
162 inline void setPosition (Position pos
) { if (mPos
!= pos
) { mPos
= pos
; remove(0); } }
164 inline int width () const { return mWidth
; }
165 inline int height () const { return mHeight
; }
166 inline int timeout () const { return mTimeout
; }
168 inline bool floatHeight () const { return mFloatHeight
; }
169 inline void setFloatHeight (bool fh
) { if (mFloatHeight
!= fh
) { mFloatHeight
= fh
; rearrange(); } }
171 void setTimeout (int timeout
);
173 void removeById (const QString
&type
, const QString
&id
);
177 void click (const QString
&type
, const QString
&id
, Qt::MouseButton button
);
183 void emitClick (K8PopupWin
*w
, Qt::MouseButton button
);
185 void allocSlot (K8PopupWin
*wnd
);
187 void remove (K8PopupWin
*wnd
);
196 QVector
<K8PopupWin
*>mList
;
198 QHash
<QString
, K8PopupType
*> mTypes
;
205 * escape '<' and '&' chars
207 QString
escapeStr (const QString
&str
);