no more popup fading (got rid of it)
[dyskinesia.git] / src / k8popups / k8popups.h
blob977e8c7f6ad95bda43b4db89aa5b0664519658e7
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.
9 */
10 #ifndef K8POPUPS_H
11 #define K8POPUPS_H
13 #include <QHash>
14 #include <QLabel>
15 #include <QString>
16 #include <QTimer>
17 #include <QVBoxLayout>
18 #include <QVector>
19 #include <QWidget>
22 class K8PopupManager;
23 class K8PopupWin;
24 class K8PopupType;
27 class K8PopupLayout : public QVBoxLayout {
28 Q_OBJECT
30 public:
31 K8PopupLayout (int aWidth, QWidget *parent=0) : QVBoxLayout(parent) { mWidth = aWidth; }
32 ~K8PopupLayout () { }
34 QSize sizeHint () const;
36 private:
37 int mWidth;
41 class K8PopupType {
42 public:
43 K8PopupType (const QString &aName, const QString &aStyle=QString()) : name(aName), style(aStyle) {}
45 public:
46 QString name;
47 QString style;
51 ///////////////////////////////////////////////////////////////////////////////
52 #ifdef FADING
53 class K8PopupFader : public QWidget {
54 Q_OBJECT
56 public:
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; }
65 void start ();
67 protected:
68 void paintEvent (QPaintEvent *event);
70 private:
71 QWidget *mPParent;
72 QTimer *mTimer;
73 QColor mStartColor;
74 int mCurrentAlpha;
75 int mDuration;
76 bool mIn;
78 #endif
81 ///////////////////////////////////////////////////////////////////////////////
82 class K8PopupWin : public QWidget {
83 Q_OBJECT
84 friend class K8PopupManager;
86 public:
87 ~K8PopupWin ();
88 virtual void show ();
90 protected:
91 bool eventFilter (QObject *obj, QEvent *event);
92 void enterEvent (QEvent *event);
93 void leaveEvent (QEvent *event);
95 private:
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);
102 void getOut ();
104 void buildAndSetMask (QWidget *w);
105 void rebuildMask ();
107 #ifdef FADING
108 private slots:
109 void onFaderInDies (QObject *obj);
110 void onFaderOutDies (QObject *obj);
111 #endif
113 private:
114 K8PopupManager *mMan;
115 K8PopupType *mType;
117 bool mShouldClose;
118 bool mMouseInside;
120 uint mShowTime;
121 QString mId;
123 QVBoxLayout *mLayout;
124 QLabel *mContentLabel;
126 #ifdef FADING
127 K8PopupFader *mFaderIn;
128 K8PopupFader *mFaderOut;
129 bool mFadingOut;
130 #endif
132 //bool mMaskSet;
136 ///////////////////////////////////////////////////////////////////////////////
137 class K8PopupManager : public QObject {
138 Q_OBJECT
139 friend class K8PopupWin;
141 public:
142 enum Position {
143 LeftTop=0, TopLeft=0,
144 RightTop=1, TopRight=1,
145 LeftBottom=2, BottomLeft=2,
146 RightBottom=3, BottomRight=3
149 // timeout: seconds
150 K8PopupManager (int width, int height, uint timeout, Position pos);
151 ~K8PopupManager ();
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);
174 void removeAll ();
176 signals:
177 void click (const QString &type, const QString &id, Qt::MouseButton button);
179 private slots:
180 void onTimer ();
182 private:
183 void emitClick (K8PopupWin *w, Qt::MouseButton button);
185 void allocSlot (K8PopupWin *wnd);
186 void rearrange ();
187 void remove (K8PopupWin *wnd);
189 private:
190 Position mPos;
191 int mWidth;
192 int mHeight;
193 uint mTimeout;
194 bool mFloatHeight;
196 QVector<K8PopupWin *>mList;
197 QTimer *mCheckTimer;
198 QHash<QString, K8PopupType *> mTypes;
202 namespace K8Popups {
205 * escape '<' and '&' chars
207 QString escapeStr (const QString &str);
212 #endif