1 #ifndef _NOTIFIERWINDOW_H_
2 #define _NOTIFIERWINDOW_H_
3 //=============================================================================
4 //
5 //   File : NotifierWindow.h
6 //   Creation date : Tue Jul 6 2004 20:25:12 CEST by Szymon Stefanek
7 //
8 //   This file is part of the KVIrc IRC client distribution
9 //   Copyright (C) 2004 Szymon Stefanek (pragma at kvirc dot net)
10 //   Copyright (C) 2005-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it >
11 //
12 //   This program is FREE software. You can redistribute it and/or
13 //   modify it under the terms of the GNU General Public License
14 //   as published by the Free Software Foundation; either version 2
15 //   of the License, or (at your option) any later version.
16 //
17 //   This program is distributed in the HOPE that it will be USEFUL,
18 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 //   See the GNU General Public License for more details.
21 //
22 //   You should have received a copy of the GNU General Public License
23 //   along with this program. If not, write to the Free Software Foundation,
24 //   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 //
26 //=============================================================================
27 
28 #include "NotifierSettings.h"
29 
30 #include "kvi_settings.h"
31 #include "KviQString.h"
32 #include "KviPointerList.h"
33 #include "KviTimeUtils.h"
34 
35 #include <QBitmap>
36 #include <QColor>
37 #include <QCursor>
38 #include <QDateTime>
39 #include <QImage>
40 #include <QPixmap>
41 #include <QRect>
42 #include <QTimer>
43 #include <QWidget>
44 #include <QTabWidget>
45 #include <QProgressBar>
46 #include <QMenu>
47 
48 class QPainter;
49 class KviWindow;
50 class NotifierMessage;
51 class NotifierWindowBorder;
52 class KviNotifierWindowTabs;
53 class KviThemedLineEdit;
54 
55 extern kvi_time_t g_tNotifierDisabledUntil;
56 
57 class NotifierWindow : public QWidget
58 {
59 	Q_OBJECT
60 public:
61 	NotifierWindow();
62 	~NotifierWindow();
63 
64 protected:
65 	QTimer * m_pShowHideTimer = nullptr;
66 	QTimer * m_pBlinkTimer = nullptr;
67 	QTimer * m_pAutoHideTimer = nullptr;
68 	State m_eState = Hidden;
69 	bool m_bBlinkOn = false;
70 	double m_dOpacity = 0.0;
71 
72 	bool m_bCloseDown = false;
73 	bool m_bPrevDown = false;
74 	bool m_bNextDown = false;
75 	bool m_bWriteDown = false;
76 	bool m_bCrashShowWorkAround;
77 
78 	QRect m_wndRect;
79 
80 	NotifierMessage * m_pCurrentMessage = nullptr;
81 	KviThemedLineEdit * m_pLineEdit = nullptr;
82 
83 	bool m_bDragging = false;
84 	bool m_bLeftButtonIsPressed = false;
85 	bool m_bDiagonalResizing = false;
86 	bool m_bResizing = false;
87 
88 	int m_whereResizing;
89 
90 	QPoint m_pntDrag;
91 	QPoint m_pntPos;
92 	QPoint m_pntClick;
93 	int m_iBlinkCount;
94 	QMenu * m_pContextPopup = nullptr;
95 	QMenu * m_pDisablePopup = nullptr;
96 	KviWindow * m_pWindowToRaise = nullptr;
97 	kvi_time_t m_tAutoHideAt = 0;
98 	kvi_time_t m_tStartedAt = 0;
99 	QTime m_qtStartedAt;
100 	bool m_bDisableHideOnMainWindowGotAttention = false;
101 
102 	QCursor m_cursor;
103 
104 	QTabWidget * m_pWndTabs = nullptr;
105 	QProgressBar * m_pProgressBar = nullptr;
106 	NotifierWindowBorder * m_pWndBorder = nullptr;
107 
108 public:
109 	void doShow(bool bDoAnimate);
110 	void doHide(bool bDoAnimate);
111 	int textWidth();
112 	void addMessage(KviWindow * pWnd, const QString & szImageId, const QString & szText, unsigned int uMessageTime);
setDisableHideOnMainWindowGotAttention(bool b)113 	void setDisableHideOnMainWindowGotAttention(bool b) { m_bDisableHideOnMainWindowGotAttention = b; };
114 	void showLineEdit(bool bShow);
countTabs()115 	int countTabs() const
116 	{
117 		if(m_pWndTabs)
118 			return m_pWndTabs->count();
119 		return 0;
120 	}
state()121 	State state() const { return m_eState; }
122 protected:
123 	void showEvent(QShowEvent * e) override;
124 	void hideEvent(QHideEvent * e) override;
125 	void paintEvent(QPaintEvent * e) override;
126 	void mousePressEvent(QMouseEvent * e) override;
127 	void mouseReleaseEvent(QMouseEvent * e) override;
128 	void mouseMoveEvent(QMouseEvent * e) override;
129 	void leaveEvent(QEvent * e) override;
130 	void enterEvent(QEvent * e) override;
131 	bool eventFilter(QObject * pEdit, QEvent * e) override;
132 	void keyPressEvent(QKeyEvent * e) override;
133 public slots:
134 	void hideNow();
135 	void toggleLineEdit();
136 	void slotTabCloseRequested(int index);
137 protected slots:
138 	void blink();
139 	void heartbeat();
140 	void returnPressed();
141 	void updateGui();
142 	void fillContextPopup();
143 	void disableFor1Minute();
144 	void disableFor5Minutes();
145 	void disableFor15Minutes();
146 	void disableFor30Minutes();
147 	void disableFor60Minutes();
148 	void disableUntilKVIrcRestarted();
149 	void disablePermanently();
150 	void progressUpdate();
151 
152 private:
153 	void contextPopup(const QPoint & pos);
154 	void startBlinking();
155 	// 	void computeRect();
156 	void stopShowHideTimer();
157 	void stopBlinkTimer();
158 	void stopAutoHideTimer();
159 	void startAutoHideTimer();
160 	bool shouldHideIfMainWindowGotAttention();
161 	void setCursor(int);
162 	void resize(QPoint p, bool = true);
163 	void redrawText();
164 	bool checkResizing(QPoint);
165 };
166 
167 #endif //_NOTIFIERWINDOW_H_
168