From c601b5a27f74b16158adafe429faefbe573e64a2 Mon Sep 17 00:00:00 2001 From: Szymon Tomasz Stefanek Date: Sat, 1 Jan 2011 20:19:56 +0000 Subject: The big rename for modules. Still some details remaining. git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5284 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/notifier/CMakeLists.txt | 12 +- src/modules/notifier/NotifierMessage.cpp | 99 +++ src/modules/notifier/NotifierMessage.h | 87 ++ src/modules/notifier/NotifierSettings.h | 66 ++ src/modules/notifier/NotifierWindow.cpp | 1153 +++++++++++++++++++++++++ src/modules/notifier/NotifierWindow.h | 159 ++++ src/modules/notifier/NotifierWindowBorder.cpp | 205 +++++ src/modules/notifier/NotifierWindowBorder.h | 130 +++ src/modules/notifier/NotifierWindowTab.cpp | 230 +++++ src/modules/notifier/NotifierWindowTab.h | 120 +++ src/modules/notifier/libkvinotifier.cpp | 10 +- src/modules/notifier/notifiermessage.cpp | 99 --- src/modules/notifier/notifiermessage.h | 87 -- src/modules/notifier/notifiersettings.h | 66 -- src/modules/notifier/notifierwindow.cpp | 1153 ------------------------- src/modules/notifier/notifierwindow.h | 159 ---- src/modules/notifier/notifierwindowborder.cpp | 205 ----- src/modules/notifier/notifierwindowborder.h | 130 --- src/modules/notifier/notifierwindowtab.cpp | 230 ----- src/modules/notifier/notifierwindowtab.h | 120 --- 20 files changed, 2260 insertions(+), 2260 deletions(-) create mode 100644 src/modules/notifier/NotifierMessage.cpp create mode 100644 src/modules/notifier/NotifierMessage.h create mode 100644 src/modules/notifier/NotifierSettings.h create mode 100644 src/modules/notifier/NotifierWindow.cpp create mode 100644 src/modules/notifier/NotifierWindow.h create mode 100644 src/modules/notifier/NotifierWindowBorder.cpp create mode 100644 src/modules/notifier/NotifierWindowBorder.h create mode 100644 src/modules/notifier/NotifierWindowTab.cpp create mode 100644 src/modules/notifier/NotifierWindowTab.h delete mode 100644 src/modules/notifier/notifiermessage.cpp delete mode 100644 src/modules/notifier/notifiermessage.h delete mode 100644 src/modules/notifier/notifiersettings.h delete mode 100644 src/modules/notifier/notifierwindow.cpp delete mode 100644 src/modules/notifier/notifierwindow.h delete mode 100644 src/modules/notifier/notifierwindowborder.cpp delete mode 100644 src/modules/notifier/notifierwindowborder.h delete mode 100644 src/modules/notifier/notifierwindowtab.cpp delete mode 100644 src/modules/notifier/notifierwindowtab.h (limited to 'src/modules/notifier') diff --git a/src/modules/notifier/CMakeLists.txt b/src/modules/notifier/CMakeLists.txt index 2453bfdb1..78a1d0b5c 100644 --- a/src/modules/notifier/CMakeLists.txt +++ b/src/modules/notifier/CMakeLists.txt @@ -1,16 +1,16 @@ # CMakeLists for src/modules/notifier SET(kvinotifier_MOC_HDRS - notifierwindow.h - notifierwindowtab.h + NotifierWindow.h + NotifierWindowTab.h ) SET(kvinotifier_SRCS libkvinotifier.cpp - notifierwindow.cpp - notifiermessage.cpp - notifierwindowtab.cpp - notifierwindowborder.cpp + NotifierWindow.cpp + NotifierMessage.cpp + NotifierWindowTab.cpp + NotifierWindowBorder.cpp ) # After this call, files will be moc'ed to moc_kvi_*.cpp diff --git a/src/modules/notifier/NotifierMessage.cpp b/src/modules/notifier/NotifierMessage.cpp new file mode 100644 index 000000000..6dc7977d7 --- /dev/null +++ b/src/modules/notifier/NotifierMessage.cpp @@ -0,0 +1,99 @@ +//============================================================================= +// +// File : NotifierMessage.cpp +// Creation date : Mar 02 Nov 2004 02:41:18 by Iacopo Palazzi +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2004-2008 Iacopo +// Copyright (C) 2009 Fabio Bas < ctrlaltca at gmail dot com > +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "NotifierMessage.h" +#include "NotifierSettings.h" + +#include "KviHtmlGenerator.h" +#include "KviOptions.h" + +#include +#include + +NotifierMessage::NotifierMessage(QPixmap * pPixmap, const QString & szText) +{ + m_pLabel0 = 0; + m_pLabel1 = 0; + + m_szText=szText; + m_pPixmap=pPixmap; + + //QByteArray utf8 = szText.toUtf8(); + //if(utf8.data()) + // qDebug("NOTIFIER TEXT MESSAGE: \n%s\n",utf8.data()); + + m_pHBox = new QHBoxLayout(this); + m_pHBox->setSpacing(SPACING); + m_pHBox->setMargin(SPACING); + + updateGui(); +} + +NotifierMessage::~NotifierMessage() +{ + if(m_pLabel0) + m_pLabel0->deleteLater(); + if(m_pLabel1) + m_pLabel1->deleteLater(); + if(m_pHBox) + m_pHBox->deleteLater(); +} + +void NotifierMessage::updateGui() +{ + bool bShowImages = KVI_OPTION_BOOL(KviOption_boolIrcViewShowImages); + + if(m_pLabel0) + delete m_pLabel0; + + if(m_pLabel1) + delete m_pLabel1; + + if(bShowImages) + { + m_pLabel0 = new QLabel(this); + m_pLabel0->setFixedSize(16,16); + if(m_pPixmap) + m_pLabel0->setPixmap(*m_pPixmap); + } else { + m_pLabel0 = 0; + } + + m_pLabel1 = new QLabel(this); + m_pLabel1->setTextFormat(Qt::RichText); + m_pLabel1->setText(KviHtmlGenerator::convertToHtml(m_szText)); + m_pLabel1->setWordWrap(true); + m_pLabel1->setFont(KVI_OPTION_FONT(KviOption_fontNotifier)); + QPalette pal = m_pLabel1->palette(); + pal.setColor(QPalette::WindowText, KVI_OPTION_COLOR(KviOption_colorNotifierForeground)); + m_pLabel1->setPalette(pal); + + if(bShowImages) + { + m_pHBox->setStretch(1,99); + m_pHBox->addWidget(m_pLabel0); + } + m_pHBox->addWidget(m_pLabel1); +} diff --git a/src/modules/notifier/NotifierMessage.h b/src/modules/notifier/NotifierMessage.h new file mode 100644 index 000000000..025e5a11d --- /dev/null +++ b/src/modules/notifier/NotifierMessage.h @@ -0,0 +1,87 @@ +#ifndef _NOTIFIERMESSAGE_H_ +#define _NOTIFIERMESSAGE_H_ +//============================================================================= +// +// File : NotifierMessage.h +// Creation date : Mar 02 Nov 2004 02:41:18 by Iacopo Palazzi +// +// This file is part of the KVIrc distribution +// Copyright (C) 2004 Szymon Stefanek (pragma at kvirc dot net) +// Copyright (C) 2004-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it > +// Copyright (C) 2009 Fabio Bas < ctrlaltca at gmail dot com > +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include +#include +#include +#include +#include + +/** +* \class NotifierMessage +* \brief A single message in a notifier window +* +* This is basically a single message that can appear in a notifier window +* It's made up of an icon and a rich text content +* This class is basically a QLabel with a method that translates a raw irc message to html code. +*/ +class NotifierMessage : public QWidget +{ + friend class NotifierWindow; +public: + /** + * \brief Constructs the NotifierMessage object + * \param pPixmap pointer to a message icon, can be null + * \param szText const reference to message text in irc format + * \return NotifierMessage + */ + NotifierMessage(QPixmap * pPixmap, const QString &szText); + /** + * \brief Destroys the NotifierMessage object + */ + ~NotifierMessage(); +private: + /// The message text + QString m_szText; + /// The message icon (can be null) + QPixmap * m_pPixmap; + /// Layout for the labels + QHBoxLayout * m_pHBox; + /// Label for the message icon + QLabel * m_pLabel0; + /// Label for the message text + QLabel * m_pLabel1; +public: + /** + * \brief Returns the original irc message + * \return QString + */ + inline QString text() const { return m_szText; }; + /** + * \brief Returns the message icon + * \return QPixmap * + */ + inline QPixmap * pixmap() const { return m_pPixmap; }; + /** + * \brief Updates the aspect of this message + * \return void + */ + void updateGui(); +}; + +#endif //!_NOTIFIERMESSAGE_H_ diff --git a/src/modules/notifier/NotifierSettings.h b/src/modules/notifier/NotifierSettings.h new file mode 100644 index 000000000..28e53ef3b --- /dev/null +++ b/src/modules/notifier/NotifierSettings.h @@ -0,0 +1,66 @@ +#ifndef _NOTIFIER_SETTINGS_H_ +#define _NOTIFIER_SETTINGS_H_ +//============================================================================= +// +// File : NotifierSettings.h +// Creation date : Thu 30 Dev 2004 21:21:33 by Iacopo Palazzi +// +// This file is part of the Notifier - KVIrc Distribution distribution +// Copyright (C) 2004-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it > +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +// Global settings for KviNotifier + + + +#define WDG_MIN_WIDTH 370 +#define WDG_MIN_HEIGHT 160 +#define WDG_BORDER_THICKNESS 5 +#define SPACING 2 + +#define WDG_ICON_OUT 0 +#define WDG_ICON_OVER 1 +#define WDG_ICON_CLICKED 2 +#define WDG_ICON_ON 3 +#define WDG_ICON_OFF 4 + +#define NTF_TABS_FONT_BASELINE 8 + +#define MAX_MESSAGES_IN_WINDOW 20 +// keep hidden messages for 600 seconds : 10 min +#define MAX_MESSAGE_LIFETIME 600 + +#define OPACITY_STEP 0.07 + +#define NUM_OLD_COLORS 6 + +#define WDG_UPSX 1 +#define WDG_UP 2 +#define WDG_UPDX 3 +#define WDG_DWNSX 4 +#define WDG_DWN 5 +#define WDG_DWNDX 6 +#define WDG_SX 7 +#define WDG_DX 8 + +#define m_mac_bkgColor QColor(236,233,216) // Light-brown color of notifier background widget + +enum State { Hidden, Showing, Visible, Hiding, FocusingOff, FocusingOn }; +enum TabState { Normal, Highlighted, Changed }; + +#endif //_NOTIFIER_SETTINGS_H_ diff --git a/src/modules/notifier/NotifierWindow.cpp b/src/modules/notifier/NotifierWindow.cpp new file mode 100644 index 000000000..07b3f86bb --- /dev/null +++ b/src/modules/notifier/NotifierWindow.cpp @@ -0,0 +1,1153 @@ +//============================================================================= +// +// File : NotifierWindow.cpp +// Creation date : Tue Jul 6 2004 20:25:12 CEST by Szymon Stefanek +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2004-2008 Iacopo Palazzi < iakko(at)siena.linux.it > +// +// This program is FREE software. You can redistribute it and/or +// modify it under the linkss of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= +#include "kvi_settings.h" + +#include "NotifierMessage.h" +#include "NotifierWindow.h" +#include "NotifierWindowBorder.h" +#include "NotifierWindowTab.h" + +#include "KviIconManager.h" +#include "KviConfigurationFile.h" +#include "KviWindow.h" +#include "KviLocale.h" +#include "KviMainWindow.h" +#include "KviMircCntrl.h" +#include "KviOptions.h" +#include "KviUserInput.h" +#include "KviThemedLineEdit.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern NotifierWindow * g_pNotifierWindow; + +NotifierWindow::NotifierWindow() +: QWidget(0, +#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) + Qt::FramelessWindowHint | + Qt::Tool | + Qt::WindowStaysOnTopHint) +#else + Qt::FramelessWindowHint | +#ifndef COMPILE_ON_MAC + Qt::Tool | + Qt::X11BypassWindowManagerHint | +#endif + Qt::WindowStaysOnTopHint) +#endif +{ + setObjectName("kvirc_notifier_window"); + + g_pNotifierWindow = this; + + m_eState = Hidden; + m_dOpacity = 0.0; + m_pShowHideTimer = 0; + m_pBlinkTimer = 0; + m_tAutoHideAt = 0; + m_tStartedAt=0; + m_pAutoHideTimer = 0; + + m_pWndBorder = new NotifierWindowBorder(); + + setFocusPolicy(Qt::NoFocus); + setMouseTracking(true); + setAutoFillBackground(true); + + hide(); + + m_bBlinkOn = false; + + m_bCloseDown = false; + m_bPrevDown = false; + m_bNextDown = false; + m_bWriteDown = false; + + m_bLeftButtonIsPressed = false; + m_bDiagonalResizing = false; + m_bResizing = false; + + m_pContextPopup = 0; + m_pDisablePopup = 0; + + m_bDragging = false; + + m_bDisableHideOnMainWindowGotAttention = false; + + // Positioning the notifier bottom-right + QDesktopWidget * pDesktop = QApplication::desktop(); + QRect r = pDesktop->availableGeometry(pDesktop->primaryScreen()); + + m_wndRect.setRect( + r.x() + r.width() - (WDG_MIN_WIDTH + SPACING), + r.y() + r.height() - (WDG_MIN_HEIGHT + SPACING), + WDG_MIN_WIDTH, + WDG_MIN_HEIGHT); + + m_pWndTabs = new QTabWidget(this); + m_pWndTabs->setUsesScrollButtons(true); + m_pWndTabs->setTabsClosable(true); + connect(m_pWndTabs,SIGNAL(tabCloseRequested(int)),this,SLOT(slotTabCloseRequested(int))); + + m_pProgressBar = new QProgressBar(this); + m_pProgressBar->setOrientation(Qt::Vertical); + m_pProgressBar->setRange(0, 100); + m_pProgressBar->setTextVisible(false); + m_pProgressBar->setMaximumWidth(8); + m_pProgressBar->installEventFilter(this); + + m_pLineEdit = new KviThemedLineEdit(this, 0, "notifier_lineedit"); + QPalette palette=m_pLineEdit->palette(); + palette.setColor(m_pLineEdit->backgroundRole(), Qt::transparent); + m_pLineEdit->setPalette(palette); + m_pLineEdit->installEventFilter(this); + connect(m_pLineEdit,SIGNAL(returnPressed()),this,SLOT(returnPressed())); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(m_pProgressBar, 0,0,2,1); + layout->addWidget(m_pWndTabs,0,1,1,1); + layout->addWidget(m_pLineEdit,1,1,1,1); + layout->setSpacing(SPACING); + + layout->setGeometry(m_pWndBorder->bodyRect()); + layout->setContentsMargins(5,25,5,5); + setLayout(layout); + + connect(g_pApp,SIGNAL(updateNotifier()),this,SLOT(updateGui())); + QTimer::singleShot(0,this,SLOT(updateGui())); +} + +NotifierWindow::~NotifierWindow() +{ + stopShowHideTimer(); + stopBlinkTimer(); + stopAutoHideTimer(); + delete m_pWndBorder; + m_pWndTabs->deleteLater(); +} + +void NotifierWindow::updateGui() +{ + setFont(KVI_OPTION_FONT(KviOption_fontNotifier)); + QPalette palette=m_pLineEdit->palette(); + palette.setColor(m_pLineEdit->foregroundRole(), KVI_OPTION_COLOR(KviOption_colorNotifierForeground)); + m_pLineEdit->setPalette(palette); + m_pLineEdit->setFont(KVI_OPTION_FONT(KviOption_fontNotifier)); + + for(int i=0; icount();++i) + { + ((NotifierWindowTab*)m_pWndTabs->widget(i))->updateGui(); + } + +} + +void NotifierWindow::addMessage(KviWindow * pWnd, const QString & szImageId, const QString & szText, unsigned int uMessageTime) +{ + QPixmap * pIcon; + QString szMessage = szText; + szMessage.replace( QRegExp("\r([^\r])*\r([^\r])+\r"), "\\2" ); + if(szImageId.isEmpty()) + pIcon = 0; + else + pIcon = g_pIconManager->getImage(szImageId); + + NotifierMessage * pMessage = new NotifierMessage(pIcon ? new QPixmap(*pIcon) : 0,szMessage); + + //search for an existing tab + NotifierWindowTab * pTab = 0, * pTmp = 0; + for(int i=0; i < m_pWndTabs->count();++i) + { + pTmp = (NotifierWindowTab*)m_pWndTabs->widget(i); + if(pTmp->wnd() == pWnd) + { + pTab = pTmp; + break; + } + } + + if(!pTab) + { + pTab = new NotifierWindowTab(pWnd, m_pWndTabs); + } + + //if the notifier is already visible, don't steal the focus from the current tab! + //the user could be writing a message on it (bug #678) + if(!isVisible()) + m_pWndTabs->setCurrentWidget(pTab); + + pTab->appendMessage(pMessage); + + if(!isActiveWindow()) + startBlinking(); + + if(uMessageTime > 0) + { + kvi_time_t tAutoHide = kvi_unixTime() + uMessageTime; + if(m_tAutoHideAt < tAutoHide) + { + m_tAutoHideAt = tAutoHide; + if(m_eState == Visible) + startAutoHideTimer(); + } + } else { + // never hide + stopAutoHideTimer(); + m_tAutoHideAt = 0; + } + + if(pWnd) + { + if(pWnd->hasAttention()) + m_bDisableHideOnMainWindowGotAttention = true; + } + + if(isVisible()) + update(); +} + +void NotifierWindow::stopShowHideTimer() +{ + if(!m_pShowHideTimer) + return; + delete m_pShowHideTimer; + m_pShowHideTimer = 0; +} + +void NotifierWindow::stopBlinkTimer() +{ + if(!m_pBlinkTimer) + return; + delete m_pBlinkTimer; + m_pBlinkTimer = 0; +} + +void NotifierWindow::stopAutoHideTimer() +{ + if(!m_pAutoHideTimer) + return; + delete m_pAutoHideTimer; + m_pAutoHideTimer = 0; + m_pProgressBar->setValue(0); +} + +// FIXME: The code for detecting fullscreen window does NOT take into account multi-screen setups. +// We also lack the code for MacOSX and Qt-only-X11 compilation. + +#if COMPILE_KDE_SUPPORT + #include + + static bool active_window_is_full_screen() + { + WId activeId = KWindowSystem::activeWindow(); + KWindowInfo wi = KWindowSystem::windowInfo(activeId, NET::WMState); + return (wi.valid() && wi.hasState(NET::FullScreen)); + } +#else // COMPILE_KDE_SUPPORT + #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) + + #include + + static bool active_window_is_full_screen() + { + HWND hForeground = ::GetForegroundWindow(); + if(!hForeground) + return false; + + HWND hDesktop = ::GetDesktopWindow(); + if(hForeground == hDesktop) + return false; + + HWND hShell = ::GetShellWindow(); + if(hForeground == hShell) + return false; + + RECT rct; + ::GetWindowRect(hForeground,&rct); + + if((rct.right - rct.left) < GetSystemMetrics(SM_CXSCREEN)) + return false; + + if((rct.bottom - rct.top) < GetSystemMetrics(SM_CYSCREEN)) + return false; + + return true; + } + + #endif //COMPILE_ON_WINDOWS || COMPILE_ON_MINGW +#endif // COMPILE_KDE_SUPPORT + +void NotifierWindow::doShow(bool bDoAnimate) +{ + if(!KVI_OPTION_BOOL(KviOption_boolEnableNotifier)) + return; + + kvi_time_t tNow = kvi_unixTime(); + if(g_tNotifierDisabledUntil > tNow) + return; + g_tNotifierDisabledUntil = 0; + +#if defined(COMPILE_KDE_SUPPORT) || defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) + if(KVI_OPTION_BOOL(KviOption_boolDontShowNotifierIfActiveWindowIsFullScreen)) + { + // check if the active window is full screen + if(active_window_is_full_screen()) + return; + } +#endif //COMPILE_KDE_SUPPORT || COMPILE_ON_WINDOWS || COMPILE_ON_MINGW + + switch(m_eState) + { + case Showing: + // already showing up + return; + break; + case Visible: + // already visible + return; + break; + case Hiding: + // ops.. hiding! + m_eState = Showing; + break; + case Hidden: + stopShowHideTimer(); + stopBlinkTimer(); + + m_bDragging = false; + m_bCloseDown = false; + m_bPrevDown = false; + m_bNextDown = false; + m_bWriteDown = false; + m_bBlinkOn = false; + if(bDoAnimate) + { + m_pShowHideTimer = new QTimer(); + connect(m_pShowHideTimer,SIGNAL(timeout()),this,SLOT(heartbeat())); + m_dOpacity = OPACITY_STEP; + m_eState = Showing; + m_bCrashShowWorkAround = true; + setWindowOpacity(m_dOpacity); + show(); + m_pShowHideTimer->start(40); + m_bCrashShowWorkAround = false; + } else { + m_dOpacity = 1.0; + m_eState = Visible; + show(); + startBlinking(); + startAutoHideTimer(); + } + break; + default: + break; + } +} + +bool NotifierWindow::shouldHideIfMainWindowGotAttention() +{ + if(m_bDisableHideOnMainWindowGotAttention) + return false; + NotifierWindowTab * pTab = (NotifierWindowTab *) m_pWndTabs->currentWidget(); + if(!pTab) + return false; + if(!pTab->wnd()) + return false; + return pTab->wnd()->hasAttention(); +} + +void NotifierWindow::heartbeat() +{ + bool bIncreasing; + double targetOpacity = 0; + switch(m_eState) + { + case Hidden: + hideNow(); + break; + case Visible: + stopShowHideTimer(); + m_dOpacity = 1.0; + if(!isVisible()) + show(); + else + update(); + break; + case Showing: + // if the main window got attention while + // showing up then just hide now + if(shouldHideIfMainWindowGotAttention()) + { + m_eState = Hiding; + } else { + m_dOpacity += OPACITY_STEP; + targetOpacity = isActiveWindow() ? KVI_OPTION_UINT(KviOption_uintNotifierActiveTransparency) : KVI_OPTION_UINT(KviOption_uintNotifierInactiveTransparency); + + targetOpacity/=100; + if(m_dOpacity >= targetOpacity) + { + m_dOpacity = targetOpacity; + m_eState = Visible; + stopShowHideTimer(); + startBlinking(); + startAutoHideTimer(); + } + + if(!isVisible()) + show(); + setWindowOpacity(m_dOpacity); + update(); + + } + break; + case FocusingOn: + targetOpacity = KVI_OPTION_UINT(KviOption_uintNotifierActiveTransparency); + targetOpacity /= 100; + bIncreasing = targetOpacity > m_dOpacity; + m_dOpacity += bIncreasing? + OPACITY_STEP : -(OPACITY_STEP); + if((bIncreasing && (m_dOpacity >= targetOpacity)) || + (!bIncreasing && (m_dOpacity <= targetOpacity)) + ) + { + m_dOpacity = targetOpacity; + m_eState = Visible; + stopShowHideTimer(); + } + + setWindowOpacity(m_dOpacity); + break; + case FocusingOff: + targetOpacity = KVI_OPTION_UINT(KviOption_uintNotifierInactiveTransparency); + targetOpacity /= 100; + bIncreasing = targetOpacity > m_dOpacity; + m_dOpacity += bIncreasing ? OPACITY_STEP : -(OPACITY_STEP); + //qDebug("%f %f %i %i",m_dOpacity,targetOpacity,bIncreasing,(m_dOpacity >= targetOpacity)); + if((bIncreasing && (m_dOpacity >= targetOpacity)) || + (!bIncreasing && (m_dOpacity <= targetOpacity)) + ) + { + m_dOpacity = targetOpacity; + m_eState = Visible; + stopShowHideTimer(); + } + + setWindowOpacity(m_dOpacity); + break; + case Hiding: + m_dOpacity -= OPACITY_STEP; + setWindowOpacity(m_dOpacity); + if(m_dOpacity <= 0.0) + hideNow(); + else + update(); + break; + } +} + +void NotifierWindow::hideNow() +{ + stopBlinkTimer(); + stopShowHideTimer(); + stopAutoHideTimer(); + m_eState = Hidden; + m_dOpacity = 0.0; + m_tAutoHideAt = 0; + hide(); +} + +void NotifierWindow::doHide(bool bDoAnimate) +{ + stopAutoHideTimer(); + switch(m_eState) + { + case Hiding: + // already hiding up + if(!bDoAnimate) + hideNow(); + return; + break; + case Hidden: + // already hidden + if(isVisible()) + hideNow(); + return; + break; + case Showing: + // ops.. hiding! + if(!bDoAnimate) + hideNow(); + else { + // continue animating, but hide + m_eState = Hiding; + } + break; + case Visible: + stopBlinkTimer(); + stopShowHideTimer(); + if((!bDoAnimate) || (x() != m_pWndBorder->x()) || (y() != m_pWndBorder->y())) + { + + //qDebug("just hide quickly with notifier x() %d and notifier y() % - WBorderx() %d and WBordery() %d and bDoanimate %d",x(),y(),m_pWndBorder->x(),m_pWndBorder->y(),bDoAnimate); + // the user asked to not animate or + // the window has been moved and the animation would suck anyway + // just hide quickly + hideNow(); + } else { + //qDebug("starting hide animation notifier x() %d and notifier y() % - WBorderx() %d and WBordery() %d and bDoanimate %d",x(),y(),m_pWndBorder->x(),m_pWndBorder->y(),bDoAnimate); + m_pShowHideTimer = new QTimer(); + connect(m_pShowHideTimer,SIGNAL(timeout()),this,SLOT(heartbeat())); + m_dOpacity = 1.0 - OPACITY_STEP; + m_eState = Hiding; + setWindowOpacity(m_dOpacity); + update(); + m_pShowHideTimer->start(40); + } + break; + default: + break; + } +} + +void NotifierWindow::showEvent(QShowEvent *) +{ + setGeometry(m_wndRect); +} + +void NotifierWindow::hideEvent(QHideEvent *) +{ + if(m_bCrashShowWorkAround) + return; + stopBlinkTimer(); + stopShowHideTimer(); + stopAutoHideTimer(); + m_eState = Hidden; // make sure it's true + m_tAutoHideAt = 0; // make sure it's true + m_bDisableHideOnMainWindowGotAttention = false; +} + +void NotifierWindow::startBlinking() +{ + stopBlinkTimer(); + m_bBlinkOn = false; + + if(KVI_OPTION_BOOL(KviOption_boolNotifierFlashing)) + { + m_pBlinkTimer = new QTimer(); + connect(m_pBlinkTimer,SIGNAL(timeout()),this,SLOT(blink())); + m_iBlinkCount = 0; + m_pBlinkTimer->start(1000); + } +} + +void NotifierWindow::startAutoHideTimer() +{ + stopAutoHideTimer(); + m_tStartedAt = kvi_unixTime(); + if(m_tAutoHideAt <= m_tStartedAt) + return; + + int iSecs = m_tAutoHideAt - m_tStartedAt; + if(iSecs < 5) + iSecs = 5; + m_pAutoHideTimer = new QTimer(); + + connect(m_pAutoHideTimer,SIGNAL(timeout()),this,SLOT(progressUpdate())); + m_pAutoHideTimer->start(100); +} + +void NotifierWindow::blink() +{ + m_iBlinkCount++; + m_bBlinkOn = !m_bBlinkOn; + + if(m_iBlinkCount > 100) + { + // stop blinking at a certain point and remain highlighted + m_bBlinkOn = true; + stopBlinkTimer(); + } else { + // if the main window got attention while + // showing up then just hide now + if(shouldHideIfMainWindowGotAttention()) + { + doHide(false); // don't animate: the background has almost surely changed + return; + } + } + update(); +} + +void NotifierWindow::paintEvent(QPaintEvent * e) +{ + QPainter * pPaint = new QPainter(this); + + if(m_wndRect.width() != m_pWndBorder->width() || m_wndRect.height() != m_pWndBorder->height()) + m_pWndBorder->resize(m_wndRect.size()); + + if(m_bBlinkOn) + { + m_pWndBorder->draw(pPaint,true); + } else { + m_pWndBorder->draw(pPaint); + } + + pPaint->setPen(KVI_OPTION_COLOR(KviOption_colorNotifierTitleForeground)); + pPaint->setFont(KVI_OPTION_FONT(KviOption_fontNotifierTitle)); + + QString szTitle = "KVIrc - "; + NotifierWindowTab * pTab = (NotifierWindowTab *)m_pWndTabs->currentWidget(); + if(pTab) + { + if(pTab->wnd()) + { + szTitle += pTab->wnd()->plainTextCaption(); + } else { + szTitle += "notifier"; + } + } else { + szTitle += "notifier"; + } + pPaint->drawText(m_pWndBorder->titleRect(),Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine,szTitle); + + delete pPaint; + e->ignore(); +} + +void NotifierWindow::mouseMoveEvent(QMouseEvent * e) +{ + if(!m_bLeftButtonIsPressed) + { + if(checkResizing(e->pos())) + goto sartelo; + + if(m_pWndBorder->captionRect().contains(e->pos())) + { + if(m_pWndBorder->closeRect().contains(e->pos())) + m_pWndBorder->setCloseIcon(WDG_ICON_OVER); + else + m_pWndBorder->setCloseIcon(WDG_ICON_OUT); + goto sartelo; + } + +sartelo: + update(); + } + + if(m_bDragging) + { + setCursor(Qt::SizeAllCursor); + + int iW = m_wndRect.width(); + int iH = m_wndRect.height(); + + m_wndRect.setX(m_pntPos.x() + cursor().pos().x() - m_pntDrag.x()); + m_wndRect.setY(m_pntPos.y() + cursor().pos().y() - m_pntDrag.y()); + + m_wndRect.setWidth(iW); + m_wndRect.setHeight(iH); + + setGeometry(m_wndRect); + } else if(m_bResizing) + { + resize(e->pos()); + } +} + +void NotifierWindow::mousePressEvent(QMouseEvent * e) +{ + // stop blinking first of all :) + bool bWasBlinkOn = m_bBlinkOn; + m_bBlinkOn = false; + stopBlinkTimer(); + m_tAutoHideAt = 0; + stopAutoHideTimer(); + + activateWindow(); + setFocus(); + + m_pntClick = e->pos(); + + if(e->button() == Qt::RightButton) + { + contextPopup(mapToGlobal(e->pos())); + return; + } else if(e->button() == Qt::LeftButton) + { + m_bLeftButtonIsPressed = true; + } + + if(checkResizing(m_pntClick)) + { + update(); + return; + } + + if(m_pWndBorder->captionRect().contains(e->pos())) + { + if(m_pWndBorder->closeRect().contains(e->pos())) + { + m_bCloseDown = true; + m_pWndBorder->setCloseIcon(WDG_ICON_CLICKED); + update(); + return; + } + + if(!m_bResizing) + { + m_bDragging = true; + m_pntDrag = cursor().pos(); + m_pntPos = pos(); + update(); + return; + } + } + + if(m_pWndBorder->rect().contains(e->pos()) || bWasBlinkOn) + update(); +} + +void NotifierWindow::mouseReleaseEvent(QMouseEvent * e) +{ + m_bWriteDown = false; + m_bNextDown = false; + m_bPrevDown = false; + m_bCloseDown = false; + m_bLeftButtonIsPressed = false; + m_bResizing = false; + + if(m_bDragging) + { + m_bDragging = false; + if(QApplication::overrideCursor()) + QApplication::restoreOverrideCursor(); + return; + } + + if(m_pWndBorder->captionRect().contains(e->pos())) + { + if(m_pWndBorder->closeRect().contains(e->pos())) + hideNow(); + else + update(); + } + + setCursor(-1); +} + +void NotifierWindow::keyPressEvent(QKeyEvent * e) +{ + if(e->key() == Qt::Key_Escape) + { + hideNow(); + return; + } +} + +bool NotifierWindow::checkResizing(QPoint e) +{ + if(e.y() < WDG_BORDER_THICKNESS) + { + if(e.x() < WDG_BORDER_THICKNESS) + { + //// UP LEFT CORNER //// + setCursor(Qt::SizeFDiagCursor); + if (m_bLeftButtonIsPressed) + { + m_bResizing = true; + m_whereResizing = WDG_UPSX; + } + } else if(e.x() > (size().width()-WDG_BORDER_THICKNESS)) + { + //// UP RIGHT CORNER //// + setCursor(Qt::SizeBDiagCursor); + if (m_bLeftButtonIsPressed) + { + m_bResizing = true; + m_whereResizing = WDG_UPDX; + } + } else { + //// UP SIDE //// + setCursor(Qt::SizeVerCursor); + if (m_bLeftButtonIsPressed) + { + m_bResizing = true; + m_whereResizing = WDG_UP; + } + } + } else if(e.y() > (size().height()-WDG_BORDER_THICKNESS)) + { + if(e.x() < WDG_BORDER_THICKNESS) + { + //// DOWN LEFT CORNER //// + setCursor(Qt::SizeBDiagCursor); + if(m_bLeftButtonIsPressed) + { + m_bResizing = true; + m_whereResizing = WDG_DWNSX; + } + } else if(e.x() > (size().width()-WDG_BORDER_THICKNESS)) + { + //// DOWN RIGHT CORNER //// + setCursor(Qt::SizeFDiagCursor); + if(m_bLeftButtonIsPressed) + { + m_bResizing = true; + m_whereResizing = WDG_DWNDX; + } + } else { + //// DOWN SIDE //// + setCursor(Qt::SizeVerCursor); + if(m_bLeftButtonIsPressed) + { + m_bResizing = true; + m_whereResizing = WDG_DWN; + } + } + } else { + if(e.x() < WDG_BORDER_THICKNESS) + { + //// LEFT SIZE //// + setCursor(Qt::SizeHorCursor); + if(m_bLeftButtonIsPressed) + { + m_bResizing = true; + m_whereResizing = WDG_SX; + } + } else if(e.x() > (size().width()-WDG_BORDER_THICKNESS)) + { + //// RIGHT SIZE //// + setCursor(Qt::SizeHorCursor); + if(m_bLeftButtonIsPressed) + { + m_bResizing = true; + m_whereResizing = WDG_DX; + } + } else { + //// ELSEWHERE //// + m_whereResizing = 0; + m_bResizing = false; + setCursor(-1); + } + } + return m_bResizing; +} + +void NotifierWindow::resize(QPoint, bool) +{ + if(m_whereResizing == WDG_UPSX || m_whereResizing == WDG_SX || m_whereResizing == WDG_DWNSX) + { + if((x() + width() - cursor().pos().x()) < WDG_MIN_WIDTH) + m_wndRect.setLeft(x() + width() - WDG_MIN_WIDTH); + else + m_wndRect.setLeft(cursor().pos().x()); + } + + if(m_whereResizing == WDG_UPSX || m_whereResizing == WDG_UP || m_whereResizing == WDG_UPDX) + { + if(y()+height()-cursor().pos().y() < WDG_MIN_HEIGHT) + m_wndRect.setTop(y() + height() - WDG_MIN_HEIGHT); + else + m_wndRect.setTop(cursor().pos().y()); + } + + if(m_whereResizing == WDG_DX || m_whereResizing == WDG_UPDX || m_whereResizing == WDG_DWNDX) + { + if((cursor().pos().x() - x()) > WDG_MIN_WIDTH) + m_wndRect.setRight(cursor().pos().x()); + else + m_wndRect.setRight(x() + WDG_MIN_WIDTH); + } + + if(m_whereResizing == WDG_DWN || m_whereResizing == WDG_DWNDX || m_whereResizing == WDG_DWNSX) + { + if((cursor().pos().y() - y()) > WDG_MIN_HEIGHT) + m_wndRect.setBottom(cursor().pos().y()); + else + m_wndRect.setBottom(y() + WDG_MIN_HEIGHT); + } + + showLineEdit(m_pLineEdit->isVisible()); + setGeometry(m_wndRect); +} + +inline void NotifierWindow::setCursor(int iCur) +{ + if(m_cursor.shape() != iCur) + { + if(QApplication::overrideCursor()) + QApplication::restoreOverrideCursor(); + m_cursor.setShape((Qt::CursorShape)iCur); + QApplication::setOverrideCursor(m_cursor); + } else if(iCur == -1) + { + if(QApplication::overrideCursor()) + QApplication::restoreOverrideCursor(); + } +} + +void NotifierWindow::enterEvent(QEvent *) +{ + if(!m_pShowHideTimer) + { + m_pShowHideTimer = new QTimer(); + connect(m_pShowHideTimer,SIGNAL(timeout()),this,SLOT(heartbeat())); + } + m_eState = FocusingOn; + m_pShowHideTimer->start(40); +} + +void NotifierWindow::leaveEvent(QEvent *) +{ + // Leaving the widget area, restore default cursor + m_pWndBorder->resetIcons(); + if(!m_bResizing) + setCursor(-1); + + if(!m_pShowHideTimer) + { + m_pShowHideTimer = new QTimer(); + connect(m_pShowHideTimer,SIGNAL(timeout()),this,SLOT(heartbeat())); + } + + if(m_eState!=Hidden) + { + m_eState = FocusingOff; + m_pShowHideTimer->start(40); + } +} + +void NotifierWindow::contextPopup(const QPoint & pos) +{ + if(!m_pContextPopup) + { + m_pContextPopup = new KviTalPopupMenu(this); + connect(m_pContextPopup,SIGNAL(aboutToShow()),this,SLOT(fillContextPopup())); + m_pDisablePopup = new KviTalPopupMenu(this); + } + + m_pContextPopup->popup(pos); +} + +void NotifierWindow::fillContextPopup() +{ + m_pContextPopup->clear(); + m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_EDITOR)),__tr2qs_ctx("Show/Hide input line","notifier"),this,SLOT(toggleLineEdit())); + m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CLOSE)),__tr2qs_ctx("Hide","notifier"),this,SLOT(hideNow())); + m_pContextPopup->insertSeparator(); + m_pDisablePopup->clear(); + m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)),__tr2qs_ctx("1 Minute","notifier"),this,SLOT(disableFor1Minute())); + m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)),__tr2qs_ctx("5 Minutes","notifier"),this,SLOT(disableFor5Minutes())); + m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)),__tr2qs_ctx("15 Minutes","notifier"),this,SLOT(disableFor15Minutes())); + m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)),__tr2qs_ctx("30 Minutes","notifier"),this,SLOT(disableFor30Minutes())); + m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)),__tr2qs_ctx("1 Hour","notifier"),this,SLOT(disableFor60Minutes())); + m_pDisablePopup->insertSeparator(); + m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_QUIT)),__tr2qs_ctx("Until KVIrc is Restarted","notifier"),this,SLOT(disableUntilKVIrcRestarted())); + m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_QUIT)),__tr2qs_ctx("Permanently (Until Explicitly Enabled)","notifier"),this,SLOT(disablePermanently())); + + m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_QUIT)),__tr2qs_ctx("Disable","notifier"),m_pDisablePopup); +} + +void NotifierWindow::disableFor15Minutes() +{ + kvi_time_t tNow = kvi_unixTime(); + g_tNotifierDisabledUntil = tNow + (60 * 15); + + hideNow(); +} + +void NotifierWindow::disableFor5Minutes() +{ + kvi_time_t tNow = kvi_unixTime(); + g_tNotifierDisabledUntil = tNow + (60 * 5); + + hideNow(); +} + + +void NotifierWindow::disableFor1Minute() +{ + kvi_time_t tNow = kvi_unixTime(); + g_tNotifierDisabledUntil = tNow + 60; + + hideNow(); +} + +void NotifierWindow::disableFor30Minutes() +{ + kvi_time_t tNow = kvi_unixTime(); + g_tNotifierDisabledUntil = tNow + (60 * 30); + + hideNow(); +} + +void NotifierWindow::disableFor60Minutes() +{ + kvi_time_t tNow = kvi_unixTime(); + g_tNotifierDisabledUntil = tNow + (60 * 60); + + hideNow(); +} + +void NotifierWindow::disableUntilKVIrcRestarted() +{ + kvi_time_t tNow = kvi_unixTime(); + // in fact we just disable for one year + g_tNotifierDisabledUntil = tNow + (3600 * 24 * 360); // one year :D + // this will NOT work if the module is forcibly unloaded with /notifier.unload + // but the user should never do it :D + hideNow(); +} + +void NotifierWindow::disablePermanently() +{ + KVI_OPTION_BOOL(KviOption_boolEnableNotifier) = false; + hideNow(); +} + +void NotifierWindow::toggleLineEdit() +{ + showLineEdit(!m_pLineEdit->isVisible()); +} + +void NotifierWindow::showLineEdit(bool bShow) +{ + if(bShow) + { + if(m_pLineEdit->isVisible()) + return; + if(!((NotifierWindowTab *)m_pWndTabs->currentWidget())->wnd()) + return; + m_pLineEdit->setToolTip(""); + + QString szTip = __tr2qs_ctx("Write text or commands to window","notifier"); + szTip += " \""; + szTip += ((NotifierWindowTab *)m_pWndTabs->currentWidget())->wnd()->plainTextCaption(); + szTip += "\""; + m_pLineEdit->setToolTip(szTip); + m_pLineEdit->show(); + m_pLineEdit->setFocus(); + activateWindow(); + } else { + if(!m_pLineEdit->isVisible()) + return; + m_pLineEdit->hide(); + setFocus(); + update(); + } +} + +bool NotifierWindow::eventFilter(QObject * pEdit, QEvent * e) +{ + if(pEdit != (QObject *)m_pLineEdit) + return false; // huh ? + if(!m_pLineEdit->isVisible()) + return false; + if(e->type() == QEvent::MouseButtonPress) + { + bool bWasBlinkOn = m_bBlinkOn; + m_bBlinkOn = false; + m_tAutoHideAt = 0; + stopAutoHideTimer(); + stopBlinkTimer(); + activateWindow(); + m_pLineEdit->setFocus(); + if(bWasBlinkOn) + update(); + return true; + } + if(e->type() == QEvent::KeyPress) + { + if(((QKeyEvent *)e)->key() == Qt::Key_Escape) + { + hideNow(); + return true; + } + } + return false; +} + +void NotifierWindow::returnPressed() +{ + if(!m_pLineEdit->isVisible()) + return; + + NotifierWindowTab * pTab = (NotifierWindowTab *) m_pWndTabs->currentWidget(); + if(!pTab) + return; + if(!pTab->wnd()) + return; + + QString szTxt = m_pLineEdit->text(); + if(szTxt.isEmpty()) + return; + QString szHtml = szTxt; + szHtml.replace("<","<"); + szHtml.replace(">",">"); + KviCString szTmp(KviCString::Format,"%d",KVI_SMALLICON_OWNPRIVMSG); + + addMessage(pTab->wnd(),szTmp.ptr(),szHtml,0); + m_pLineEdit->setText(""); + KviUserInput::parse(szTxt,pTab->wnd(),QString(),1); +} + +void NotifierWindow::progressUpdate() +{ + kvi_time_t now = kvi_unixTime(); + int iProgress = (int)(100/(m_tAutoHideAt - m_tStartedAt)*(now - m_tStartedAt)); + m_pProgressBar->setValue(iProgress); + if(now >= m_tAutoHideAt) + { + m_tAutoHideAt = 0; + stopAutoHideTimer(); + doHide(true); + } +} + +void NotifierWindow::slotTabCloseRequested(int iIndex) +{ + if(m_pWndTabs) + { + NotifierWindowTab * pTab = (NotifierWindowTab *) m_pWndTabs->widget(iIndex); + m_pWndTabs->removeTab(iIndex); + if(pTab) + pTab->deleteLater(); + + if(m_pWndTabs->count()==0) + hideNow(); + } +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_NotifierWindow.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/notifier/NotifierWindow.h b/src/modules/notifier/NotifierWindow.h new file mode 100644 index 000000000..d58cde2ae --- /dev/null +++ b/src/modules/notifier/NotifierWindow.h @@ -0,0 +1,159 @@ +#ifndef _NOTIFIERWINDOW_H_ +#define _NOTIFIERWINDOW_H_ +//============================================================================= +// +// File : NotifierWindow.h +// Creation date : Tue Jul 6 2004 20:25:12 CEST by Szymon Stefanek +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2004 Szymon Stefanek (pragma at kvirc dot net) +// Copyright (C) 2005-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it > +// +// This program is FREE software. You can redistribute it and/or +// modify it under the linkss of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "NotifierSettings.h" + +#include "kvi_settings.h" +#include "KviQString.h" +#include "KviPointerList.h" +#include "KviTalPopupMenu.h" +#include "KviTimeUtils.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class QPainter; +class KviWindow; +class NotifierMessage; +class NotifierWindowBorder; +class KviNotifierWindowTabs; +class KviThemedLineEdit; + +extern kvi_time_t g_tNotifierDisabledUntil; + +class NotifierWindow : public QWidget +{ + Q_OBJECT +public: + NotifierWindow(); + ~NotifierWindow(); +protected: + QTimer * m_pShowHideTimer; + QTimer * m_pBlinkTimer; + QTimer * m_pAutoHideTimer; + State m_eState; + bool m_bBlinkOn; + double m_dOpacity; + + bool m_bCloseDown; + bool m_bPrevDown; + bool m_bNextDown; + bool m_bWriteDown; + bool m_bCrashShowWorkAround; + + QRect m_wndRect; + + NotifierMessage * m_pCurrentMessage; + KviThemedLineEdit * m_pLineEdit; + + bool m_bDragging; + bool m_bLeftButtonIsPressed; + bool m_bDiagonalResizing; + bool m_bResizing; + + int m_whereResizing; + + QPoint m_pntDrag; + QPoint m_pntPos; + QPoint m_pntClick; + int m_iBlinkCount; + KviTalPopupMenu * m_pContextPopup; + KviTalPopupMenu * m_pDisablePopup; + KviWindow * m_pWindowToRaise; + kvi_time_t m_tAutoHideAt; + kvi_time_t m_tStartedAt; + QTime m_qtStartedAt; + bool m_bDisableHideOnMainWindowGotAttention; + + QCursor m_cursor; + + QTabWidget * m_pWndTabs; + QProgressBar * m_pProgressBar; + NotifierWindowBorder * m_pWndBorder; +public: + void doShow(bool bDoAnimate); + void doHide(bool bDoAnimate); + int textWidth(); + void addMessage(KviWindow * pWnd,const QString &szImageId,const QString &szText,unsigned int uMessageTime); + void setDisableHideOnMainWindowGotAttention(bool b){ m_bDisableHideOnMainWindowGotAttention = b; }; + void showLineEdit(bool bShow); + inline int countTabs() const { if(m_pWndTabs)return m_pWndTabs->count(); return 0; }; + inline State state() const { return m_eState; }; +protected: + virtual void showEvent(QShowEvent *e); + virtual void hideEvent(QHideEvent * e); + virtual void paintEvent(QPaintEvent * e); + virtual void mousePressEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void leaveEvent(QEvent * e); + virtual void enterEvent(QEvent * e); + virtual bool eventFilter(QObject * pEdit,QEvent * e); + virtual void keyPressEvent ( QKeyEvent * e ); +public slots: + void hideNow(); + void toggleLineEdit(); + void slotTabCloseRequested(int index); +protected slots: + void blink(); + void heartbeat(); + void returnPressed(); + void updateGui(); + void fillContextPopup(); + void disableFor1Minute(); + void disableFor5Minutes(); + void disableFor15Minutes(); + void disableFor30Minutes(); + void disableFor60Minutes(); + void disableUntilKVIrcRestarted(); + void disablePermanently(); + void progressUpdate(); +private: + void contextPopup(const QPoint &pos); + void startBlinking(); +// void computeRect(); + void stopShowHideTimer(); + void stopBlinkTimer(); + void stopAutoHideTimer(); + void startAutoHideTimer(); + bool shouldHideIfMainWindowGotAttention(); + void setCursor(int); + void resize(QPoint p, bool = true); + void redrawText(); + bool checkResizing(QPoint); +}; + +#endif //_NOTIFIERWINDOW_H_ diff --git a/src/modules/notifier/NotifierWindowBorder.cpp b/src/modules/notifier/NotifierWindowBorder.cpp new file mode 100644 index 000000000..a47d3a64c --- /dev/null +++ b/src/modules/notifier/NotifierWindowBorder.cpp @@ -0,0 +1,205 @@ +//============================================================================= +// +// File : NotifierWindowBorder.cpp +// Creation date : Mon 03 Jan 2005 02:27:22 by Iacopo Palazzi +// +// This file is part of the KVIrc distribution +// Copyright (C) 2005-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it > +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "NotifierWindowBorder.h" +#include "NotifierWindowTab.h" + +#include "KviIconManager.h" + +#include + +NotifierWindowBorder::NotifierWindowBorder(QSize s) +{ + loadImages(); + resize(s); +} + +NotifierWindowBorder::~NotifierWindowBorder() +{ +} + +void NotifierWindowBorder::loadImages() +{ + // Normal Border + + QPixmap * p; + + if((p = g_pIconManager->getPixmap("notifier_pix_wnd_sx.png"))) + m_pixSX_N = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dx.png"))) + m_pixDX_N = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwn.png"))) + m_pixDWN_N = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwndx.png"))) + m_pixDWNDX_N = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwnsx.png"))) + m_pixDWNSX_N = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_caption_sx.png"))) + m_pixCaptionSX_N = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_caption_dx.png"))) + m_pixCaptionDX_N = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_caption_bkg.png"))) + m_pixCaptionBKG_N = *p; + + if((p = g_pIconManager->getPixmap("notifier_icon_close_out.png"))) + m_pixIconClose_out_N = *p; + if((p = g_pIconManager->getPixmap("notifier_icon_close_over.png"))) + m_pixIconClose_over_N = *p; + if((p = g_pIconManager->getPixmap("notifier_icon_close_clicked.png"))) + m_pixIconClose_clicked_N = *p; + + // Highlighted Border + + if((p = g_pIconManager->getPixmap("notifier_pix_wnd_sx_hl.png"))) + m_pixSX_HL = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dx_hl.png"))) + m_pixDX_HL = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwn_hl.png"))) + m_pixDWN_HL = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwndx_hl.png"))) + m_pixDWNDX_HL = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwnsx_hl.png"))) + m_pixDWNSX_HL = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_caption_sx_hl.png"))) + m_pixCaptionSX_HL = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_caption_dx_hl.png"))) + m_pixCaptionDX_HL = *p; + if((p = g_pIconManager->getPixmap("notifier_pix_caption_bkg_hl.png"))) + m_pixCaptionBKG_HL = *p; + + if((p = g_pIconManager->getPixmap("notifier_icon_close_out_hl.png"))) + m_pixIconClose_out_HL = *p; + if((p = g_pIconManager->getPixmap("notifier_icon_close_over_hl.png"))) + m_pixIconClose_over_HL = *p; + if((p = g_pIconManager->getPixmap("notifier_icon_close_clicked_hl.png"))) + m_pixIconClose_clicked_HL = *p; + + setPics(); + setCloseIcon(WDG_ICON_OUT); + + if ( m_pixCaptionDX->height()==m_pixCaptionSX->height() && m_pixCaptionDX->height()==m_pixCaptionBKG->height()) // just to be sure that the height is fitting + m_captionRect.setHeight(m_pixCaptionDX->height()); + +} + +void NotifierWindowBorder::setPics(bool b) +{ + if (b) { + m_pixSX = &m_pixSX_HL; + m_pixDX = &m_pixDX_HL; + m_pixDWN = &m_pixDWN_HL; + m_pixDWNSX = &m_pixDWNSX_HL; + m_pixDWNDX = &m_pixDWNDX_HL; + m_pixCaptionSX = &m_pixCaptionSX_HL; + m_pixCaptionDX = &m_pixCaptionDX_HL; + m_pixCaptionBKG = &m_pixCaptionBKG_HL; + m_pixIconClose_out = &m_pixIconClose_out_HL; + m_pixIconClose_over = &m_pixIconClose_over_HL; + m_pixIconClose_clicked = &m_pixIconClose_clicked_HL; + } else { + m_pixSX = &m_pixSX_N; + m_pixDX = &m_pixDX_N; + m_pixDWN = &m_pixDWN_N; + m_pixDWNSX = &m_pixDWNSX_N; + m_pixDWNDX = &m_pixDWNDX_N; + m_pixCaptionSX = &m_pixCaptionSX_N; + m_pixCaptionDX = &m_pixCaptionDX_N; + m_pixCaptionBKG = &m_pixCaptionBKG_N; + m_pixIconClose_out = &m_pixIconClose_out_N; + m_pixIconClose_over = &m_pixIconClose_over_N; + m_pixIconClose_clicked = &m_pixIconClose_clicked_N; + } +} + +void NotifierWindowBorder::setWidth(int w) +{ + m_iRctWidth = w; + recalculatePositions(); +} + +void NotifierWindowBorder::setHeight(int h) +{ + m_iRctHeight = h; + recalculatePositions(); +} + +void NotifierWindowBorder::recalculatePositions() +{ + m_rct.setHeight(m_iRctHeight); + m_rct.setWidth(m_iRctWidth); + m_rct.setTopLeft(QPoint(0,0)); + + m_closeIconRect.setX(m_rct.width()-m_pixCaptionDX->width()-m_pixIconClose->width()); + m_closeIconRect.setY(2); + m_closeIconRect.setWidth(m_pixIconClose->width()); + m_closeIconRect.setHeight(m_pixIconClose->height()); + + m_captionRect.setTopLeft( m_rct.topLeft() ); + m_captionRect.setSize( QSize(m_rct.width(),m_pixCaptionDX->height()) ); + + m_bodyRect.setTopLeft( QPoint(m_pixCaptionDX->width(),m_captionRect.height()) ); + m_bodyRect.setSize( QSize(m_captionRect.width()-(2*m_pixCaptionDX->width()),m_rct.height()-m_captionRect.height()-m_pixDWN->height()) ); + + m_titleRect.setTopLeft( QPoint(m_pixCaptionSX->width(),0) ); + m_titleRect.setSize( QSize(m_rct.width()-m_pixCaptionSX->width()-m_pixCaptionDX->width()-m_pixIconClose->width(),m_captionRect.height())); + +} + +void NotifierWindowBorder::setCloseIcon(int state) +{ + m_eIconState = state; + switch (m_eIconState) { + case WDG_ICON_OUT: m_pixIconClose = m_pixIconClose_out; break; + case WDG_ICON_OVER: m_pixIconClose = m_pixIconClose_over; break; + case WDG_ICON_CLICKED: m_pixIconClose = m_pixIconClose_clicked; break; + }; +} + +void NotifierWindowBorder::resetIcons() +{ + setCloseIcon(WDG_ICON_OUT); +} + +void NotifierWindowBorder::draw(QPainter * p, bool b) +{ + setPics(b); + setCloseIcon(m_eIconState); + + // Draw the caption + p->drawPixmap(m_captionRect.x(), m_captionRect.y(), *m_pixCaptionSX); + p->drawTiledPixmap(m_pixCaptionSX->width(), 0, m_captionRect.width() - (m_pixCaptionSX->width() + m_pixCaptionDX->width()), m_captionRect.height(), *m_pixCaptionBKG); + p->drawPixmap(m_captionRect.width() - m_pixCaptionDX->width(), 0, *m_pixCaptionDX); + + // Draw the tiled borders + p->drawTiledPixmap(0, m_captionRect.height(), m_pixSX->width(), m_bodyRect.height(), *m_pixSX); + p->drawTiledPixmap(m_bodyRect.width() + m_bodyRect.x(), m_captionRect.height(), m_pixDX->width(), m_bodyRect.height(), *m_pixDX); + p->drawTiledPixmap(m_pixDWNSX->width(), m_captionRect.height() + m_bodyRect.height(), m_bodyRect.width() + 1, m_pixDWN->height(), *m_pixDWN); + + // Draw down corners + p->drawPixmap(0, m_captionRect.height() + m_bodyRect.height(), *m_pixDWNSX); + p->drawPixmap(m_bodyRect.width() + m_bodyRect.x(), m_captionRect.height() + m_bodyRect.height(), *m_pixDWNDX); + + //Drawing icons + p->drawPixmap(m_closeIconRect.x(), m_closeIconRect.y(), *m_pixIconClose); +} diff --git a/src/modules/notifier/NotifierWindowBorder.h b/src/modules/notifier/NotifierWindowBorder.h new file mode 100644 index 000000000..b59d90b74 --- /dev/null +++ b/src/modules/notifier/NotifierWindowBorder.h @@ -0,0 +1,130 @@ +#ifndef _KVINOTIFIERWINDOWBORDER_H_ +#define _KVINOTIFIERWINDOWBORDER_H_ +//============================================================================= +// +// File : NotifierWindowBorder.h +// Creation date : Mon 03 Jan 2005 02:27:22 by Iacopo Palazzi +// +// This file is part of the KVIrc distribution +// Copyright (C) 2005-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it > +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "NotifierSettings.h" + +#include +#include +#include + +class QPainter; + +class NotifierWindowBorder +{ +public: + NotifierWindowBorder(QSize = QSize(WDG_MIN_WIDTH,WDG_MIN_HEIGHT)); + ~NotifierWindowBorder(); + +// ================================ +// Put members declaration below... +// ================================ +private: + QRect m_rct; + QPoint m_pnt; + + QRect m_closeIconRect; + + QRect m_captionRect; + QRect m_bodyRect; + QRect m_titleRect; + + // Pictures + QPixmap * m_pixSX; + QPixmap * m_pixDX; + QPixmap * m_pixDWN; + QPixmap * m_pixDWNSX; + QPixmap * m_pixDWNDX; + QPixmap * m_pixCaptionSX; + QPixmap * m_pixCaptionDX; + QPixmap * m_pixCaptionBKG; + QPixmap * m_pixIconClose_out; + QPixmap * m_pixIconClose_over; + QPixmap * m_pixIconClose_clicked; + QPixmap * m_pixIconClose; + + QPixmap m_pixSX_N; + QPixmap m_pixDX_N; + QPixmap m_pixDWN_N; + QPixmap m_pixDWNSX_N; + QPixmap m_pixDWNDX_N; + QPixmap m_pixCaptionSX_N; + QPixmap m_pixCaptionDX_N; + QPixmap m_pixCaptionBKG_N; + QPixmap m_pixIconClose_out_N; + QPixmap m_pixIconClose_over_N; + QPixmap m_pixIconClose_clicked_N; + + QPixmap m_pixSX_HL; + QPixmap m_pixDX_HL; + QPixmap m_pixDWN_HL; + QPixmap m_pixDWNSX_HL; + QPixmap m_pixDWNDX_HL; + QPixmap m_pixCaptionSX_HL; + QPixmap m_pixCaptionDX_HL; + QPixmap m_pixCaptionBKG_HL; + QPixmap m_pixIconClose_out_HL; + QPixmap m_pixIconClose_over_HL; + QPixmap m_pixIconClose_clicked_HL; + + int m_eIconState; + int m_iRctWidth; + int m_iRctHeight; +private: + void loadImages(); + void recalculatePositions(); + +public: + // reading methods... + void setWidth(int w); + void setHeight(int h); + void resize(int w, int h) { setWidth(w); setHeight(h); }; + void resize(QSize r) { setWidth(r.width()); setHeight(r.height()); }; + void setGeometry(QRect r) { r.topLeft(); r.size(); /*qDebug("x,y: %d,%d", r.x(), r.y()); qDebug("w,h: %d,%d", r.width(), r.height());*/ }; + void setGeometry(QPoint p, QSize s) { setPoint (p.x(), p.y()); setWidth (s.width()); setHeight (s.height()); }; + + void setPoint(int x, int y) { m_pnt.setX(x); m_pnt.setY(y); m_rct.setX(x); m_rct.setY(y); }; + + void setCloseIcon(int state); + void resetIcons(); + + // writing methods... + inline int x() const { return m_pnt.x(); }; + inline int y() const { return m_pnt.y(); }; + inline int width() const { return m_rct.width(); }; + inline int height() const { return m_rct.height(); }; + inline int baseLine() const { return (y()+height()); }; + + inline QRect bodyRect() const { return m_bodyRect; }; + inline QRect captionRect() const { return m_captionRect; }; + inline QRect rect() const { return m_rct; }; + inline QRect closeRect() const { return m_closeIconRect; }; + inline QRect titleRect() const { return m_titleRect; }; + + void draw(QPainter *, bool b = false); + void setPics(bool b = false); +}; + +#endif //!_KVINOTIFIERWINDOWBORDER_H_ diff --git a/src/modules/notifier/NotifierWindowTab.cpp b/src/modules/notifier/NotifierWindowTab.cpp new file mode 100644 index 000000000..dc47a3535 --- /dev/null +++ b/src/modules/notifier/NotifierWindowTab.cpp @@ -0,0 +1,230 @@ +//============================================================================= +// +// File : NotifierWindowTab.cpp +// File : NotifierWindowTab.h +// Creation date : Tue 07 Jul 2009 10:28 by Fabio Bas +// +// This file is part of the KVIrc distribution +// Copyright (C) 2009 Fabio Bas < ctrlaltca at gmail dot com > +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "NotifierMessage.h" +#include "NotifierWindowTab.h" +#include "NotifierWindow.h" +#include "NotifierSettings.h" + +#include "KviApplication.h" +#include "KviConfigurationFile.h" +#include "KviLocale.h" +#include "KviMainWindow.h" +#include "KviOptions.h" +#include "KviPixmapUtils.h" +#include "KviWindow.h" + +#include +#include +#include +#include +#include +#include + +#ifdef COMPILE_PSEUDO_TRANSPARENCY + #include + extern KVIRC_API QPixmap * g_pShadedChildGlobalDesktopBackground; +#endif + +extern NotifierWindow * g_pNotifierWindow; + +NotifierWindowTab::NotifierWindowTab(KviWindow * pWnd, QTabWidget * pParent) +: QScrollArea(pParent) +{ + m_pWnd = pWnd; + if(m_pWnd) + { + m_szLabel = m_pWnd->windowName(); + connect(pWnd,SIGNAL(windowNameChanged()),this,SLOT(labelChanged())); + connect(pWnd,SIGNAL(destroyed()),this,SLOT(closeMe())); + } else { + m_szLabel = "----"; + } + + if(pParent) + { + m_pParent = pParent; + m_pParent->addTab(this, m_szLabel); + } + + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + + if(verticalScrollBar()) + connect(verticalScrollBar(),SIGNAL(rangeChanged(int, int)),this, SLOT(scrollRangeChanged(int, int))); + + QPalette pal = palette(); + pal.setColor(backgroundRole(), Qt::transparent); + setPalette(pal); + + m_pVWidget = new QWidget(viewport()); + m_pVBox = new QVBoxLayout(m_pVWidget); + m_pVBox->setSizeConstraint(QLayout::SetFixedSize); + m_pVBox->setSpacing(SPACING); + m_pVBox->setMargin(SPACING); + + setWidget(m_pVWidget); +} + +NotifierWindowTab::~NotifierWindowTab() +{ + if(m_pVBox) + m_pVBox->deleteLater(); + if(m_pVWidget) + m_pVWidget->deleteLater(); +} + +void NotifierWindowTab::appendMessage(NotifierMessage * pMessage) +{ + m_pVBox->addWidget(pMessage); + pMessage->setFixedWidth(viewport()->width()); + + while(m_pVBox->count() > MAX_MESSAGES_IN_WINDOW) + { + QLayoutItem * pTmp = m_pVBox->takeAt(0); + NotifierMessage * pTmp2 = (NotifierMessage*)pTmp->widget(); + if(pTmp2) + pTmp2->deleteLater(); + } +} + +void NotifierWindowTab::updateGui() +{ + for(int i=0; icount(); ++i) + { + QLayoutItem * pTmp = m_pVBox->itemAt(i); + NotifierMessage * pTmp2 = (NotifierMessage*)pTmp->widget(); + if(pTmp2) + pTmp2->updateGui(); + } +} + +void NotifierWindowTab::scrollRangeChanged(int, int) +{ + //this is the autoscroll + if(verticalScrollBar()) + verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum); +} + +void NotifierWindowTab::labelChanged() +{ + if(!m_pWnd || !m_pParent) + return; + + int iIdx = m_pParent->indexOf(this); + m_szLabel = m_pWnd->windowName(); + if(iIdx > -1) + m_pParent->setTabText(iIdx, m_szLabel); +} + +void NotifierWindowTab::mouseDoubleClickEvent(QMouseEvent *) +{ + if(!m_pWnd || !g_pNotifierWindow) + return; + if(!g_pApp->windowExists(m_pWnd)) + return; + + g_pNotifierWindow->hideNow(); + + if(m_pWnd->mdiParent()) + { + m_pWnd->frame()->raise(); + m_pWnd->frame()->setFocus(); + m_pWnd->frame()->setWindowState((m_pWnd->frame()->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); + if(!m_pWnd->frame()->isVisible()) + m_pWnd->frame()->show(); + } + + m_pWnd->frame()->setActiveWindow(m_pWnd); +} + +void NotifierWindowTab::closeMe() +{ + //our window has been closed + if(m_pParent && g_pNotifierWindow) + { + int iIdx = m_pParent->indexOf(this); + if(iIdx != -1) + { + g_pNotifierWindow->slotTabCloseRequested(iIdx); + } + } +} + +void NotifierWindowTab::resizeEvent(QResizeEvent *) +{ + if(m_pVBox) + { + int iWidth = viewport()->width(); + NotifierMessage * pMessage; + for(int i=0; i < m_pVBox->count(); i++) + { + pMessage = (NotifierMessage *)m_pVBox->itemAt(i)->widget(); + if(pMessage) + pMessage->setFixedWidth(iWidth); + } + } +} + +void NotifierWindowTab::paintEvent(QPaintEvent * e) +{ + QPainter * pPainter = new QPainter(viewport()); + + //make sure you clean your widget with a transparent + // color before doing any rendering + // note the usage of a composition mode Source + // it's important! + + #ifdef COMPILE_PSEUDO_TRANSPARENCY + if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing()) + { + pPainter->save(); + pPainter->setCompositionMode(QPainter::CompositionMode_Source); + QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade); + col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100)); + pPainter->fillRect(e->rect(), col); + pPainter->restore(); + } else if(g_pShadedChildGlobalDesktopBackground) + { + QPoint pnt = mapToGlobal(e->rect().topLeft()); + pPainter->drawTiledPixmap(e->rect(),*(g_pShadedChildGlobalDesktopBackground), pnt); + } else { + #endif + QPixmap * pPix = KVI_OPTION_PIXMAP(KviOption_pixmapNotifierBackground).pixmap(); + + if(pPix) + KviPixmapUtils::drawPixmapWithPainter(pPainter,pPix,KVI_OPTION_UINT(KviOption_uintNotifierPixmapAlign),e->rect(),e->rect().width(),e->rect().height()); + else pPainter->fillRect(e->rect(),KVI_OPTION_COLOR(KviOption_colorNotifierBackground)); + #ifdef COMPILE_PSEUDO_TRANSPARENCY + } + #endif + + delete pPainter; + e->ignore(); +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_NotifierWindowTab.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/notifier/NotifierWindowTab.h b/src/modules/notifier/NotifierWindowTab.h new file mode 100644 index 000000000..5a07f387d --- /dev/null +++ b/src/modules/notifier/NotifierWindowTab.h @@ -0,0 +1,120 @@ +#ifndef _KVINOTIFIERWINDOWTAB_H_ +#define _KVINOTIFIERWINDOWTAB_H_ +//============================================================================= +// +// File : NotifierWindowTab.h +// Creation date : Tue 07 Jul 2009 10:28 by Fabio Bas +// +// This file is part of the KVIrc distribution +// Copyright (C) 2009 Fabio Bas < ctrlaltca at gmail dot com > +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +/** +* \file NotifierWindowTab.h +* \author Fabio Bas +* \brief Defines the tab page for the notifier object +*/ + +#include "NotifierMessage.h" + +#include "kvi_settings.h" + +#include + +class QVBoxLayout; +class QWidget; +class QTabWidget; +class QPainter; +class KviWindow; + +/** +* \class NotifierWindowTab +* \brief Defines an object for every single tab about the tabs area +*/ +class NotifierWindowTab : public QScrollArea +{ + Q_OBJECT +public: + /** + * \brief Creates the tab object + * \param pWnd The name of the window represented by the tab + * \param pParent The parent area container + * \return NotifierWindowTab + */ + NotifierWindowTab(KviWindow * pWnd, QTabWidget * pParent); + + /** + * \brief Destroys the tab object + */ + ~NotifierWindowTab(); +private: + QString m_szLabel; + KviWindow * m_pWnd; + QTabWidget * m_pParent; + QVBoxLayout * m_pVBox; + QWidget * m_pVWidget; +public: + /** + * \brief Appends the given message to the window + * \param pMessage The message received to append + * \return void + */ + void appendMessage(NotifierMessage * pMessage); + + /** + * \brief Updates the GUI + * \return void + */ + void updateGui(); + + /** + * \brief Returns the name of the current window + * \return QString + */ + inline QString label() const { return m_szLabel; }; + + /** + * \brief Returns the pointer of the current window + * \return KviWindow * + */ + inline KviWindow * wnd() const { return m_pWnd; }; +protected: + virtual void mouseDoubleClickEvent(QMouseEvent * e); + virtual void resizeEvent(QResizeEvent * e); + virtual void paintEvent(QPaintEvent * e); +private slots: + /** + * \brief Emitted when the scrollbar range is changed + * \return void + */ + void scrollRangeChanged(int, int); + + /** + * \brief Emitted when the window changes its name + * \return void + */ + void labelChanged(); + + /** + * \brief Emitted when the window is being destroyed + * \return void + */ + void closeMe(); +}; + +#endif //!_KVINOTIFIERWINDOWTAB_H_ diff --git a/src/modules/notifier/libkvinotifier.cpp b/src/modules/notifier/libkvinotifier.cpp index 0b71a6450..1943faffc 100644 --- a/src/modules/notifier/libkvinotifier.cpp +++ b/src/modules/notifier/libkvinotifier.cpp @@ -23,8 +23,8 @@ // //============================================================================= -#include "notifierwindow.h" -#include "notifiermessage.h" +#include "NotifierWindow.h" +#include "NotifierMessage.h" #include "KviModule.h" #include "KviKvsVariant.h" @@ -38,7 +38,7 @@ #include -KviNotifierWindow * g_pNotifierWindow = 0; +NotifierWindow * g_pNotifierWindow = 0; kvi_time_t g_tNotifierDisabledUntil = 0; /* @@ -119,7 +119,7 @@ static bool notifier_kvs_cmd_message(KviKvsModuleCommandCall * c) KVSM_PARAMETERS_END(c) if(!g_pNotifierWindow) - g_pNotifierWindow = new KviNotifierWindow(); + g_pNotifierWindow = new NotifierWindow(); QString szIco=""; QString szWnd=""; @@ -293,7 +293,7 @@ static bool notifier_module_ctrl(KviModule *, const char * pcOperation, void * p return false; if(!g_pNotifierWindow) - g_pNotifierWindow = new KviNotifierWindow(); + g_pNotifierWindow = new NotifierWindow(); g_pNotifierWindow->addMessage(p->pWindow,p->szIcon,p->szMessage,p->uMessageLifetime); g_pNotifierWindow->doShow(KVI_OPTION_BOOL(KviOption_boolNotifierFading) ? true : false); diff --git a/src/modules/notifier/notifiermessage.cpp b/src/modules/notifier/notifiermessage.cpp deleted file mode 100644 index 67c43a244..000000000 --- a/src/modules/notifier/notifiermessage.cpp +++ /dev/null @@ -1,99 +0,0 @@ -//============================================================================= -// -// File : notifiermessage.cpp -// Creation date : Mar 02 Nov 2004 02:41:18 by Iacopo Palazzi -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2004-2008 Iacopo -// Copyright (C) 2009 Fabio Bas < ctrlaltca at gmail dot com > -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -#include "notifiermessage.h" -#include "notifiersettings.h" - -#include "KviHtmlGenerator.h" -#include "KviOptions.h" - -#include -#include - -KviNotifierMessage::KviNotifierMessage(QPixmap * pPixmap, const QString & szText) -{ - m_pLabel0 = 0; - m_pLabel1 = 0; - - m_szText=szText; - m_pPixmap=pPixmap; - - //QByteArray utf8 = szText.toUtf8(); - //if(utf8.data()) - // qDebug("NOTIFIER TEXT MESSAGE: \n%s\n",utf8.data()); - - m_pHBox = new QHBoxLayout(this); - m_pHBox->setSpacing(SPACING); - m_pHBox->setMargin(SPACING); - - updateGui(); -} - -KviNotifierMessage::~KviNotifierMessage() -{ - if(m_pLabel0) - m_pLabel0->deleteLater(); - if(m_pLabel1) - m_pLabel1->deleteLater(); - if(m_pHBox) - m_pHBox->deleteLater(); -} - -void KviNotifierMessage::updateGui() -{ - bool bShowImages = KVI_OPTION_BOOL(KviOption_boolIrcViewShowImages); - - if(m_pLabel0) - delete m_pLabel0; - - if(m_pLabel1) - delete m_pLabel1; - - if(bShowImages) - { - m_pLabel0 = new QLabel(this); - m_pLabel0->setFixedSize(16,16); - if(m_pPixmap) - m_pLabel0->setPixmap(*m_pPixmap); - } else { - m_pLabel0 = 0; - } - - m_pLabel1 = new QLabel(this); - m_pLabel1->setTextFormat(Qt::RichText); - m_pLabel1->setText(KviHtmlGenerator::convertToHtml(m_szText)); - m_pLabel1->setWordWrap(true); - m_pLabel1->setFont(KVI_OPTION_FONT(KviOption_fontNotifier)); - QPalette pal = m_pLabel1->palette(); - pal.setColor(QPalette::WindowText, KVI_OPTION_COLOR(KviOption_colorNotifierForeground)); - m_pLabel1->setPalette(pal); - - if(bShowImages) - { - m_pHBox->setStretch(1,99); - m_pHBox->addWidget(m_pLabel0); - } - m_pHBox->addWidget(m_pLabel1); -} diff --git a/src/modules/notifier/notifiermessage.h b/src/modules/notifier/notifiermessage.h deleted file mode 100644 index 518a15098..000000000 --- a/src/modules/notifier/notifiermessage.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef _NOTIFIERMESSAGE_H_ -#define _NOTIFIERMESSAGE_H_ -//============================================================================= -// -// File : notifiermessage.h -// Creation date : Mar 02 Nov 2004 02:41:18 by Iacopo Palazzi -// -// This file is part of the KVIrc distribution -// Copyright (C) 2004 Szymon Stefanek (pragma at kvirc dot net) -// Copyright (C) 2004-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it > -// Copyright (C) 2009 Fabio Bas < ctrlaltca at gmail dot com > -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -#include -#include -#include -#include -#include - -/** -* \class KviNotifierMessage -* \brief A single message in a notifier window -* -* This is basically a single message that can appear in a notifier window -* It's made up of an icon and a rich text content -* This class is basically a QLabel with a method that translates a raw irc message to html code. -*/ -class KviNotifierMessage : public QWidget -{ - friend class KviNotifierWindow; -public: - /** - * \brief Constructs the KviNotifierMessage object - * \param pPixmap pointer to a message icon, can be null - * \param szText const reference to message text in irc format - * \return KviNotifierMessage - */ - KviNotifierMessage(QPixmap * pPixmap, const QString &szText); - /** - * \brief Destroys the KviNotifierMessage object - */ - ~KviNotifierMessage(); -private: - /// The message text - QString m_szText; - /// The message icon (can be null) - QPixmap * m_pPixmap; - /// Layout for the labels - QHBoxLayout * m_pHBox; - /// Label for the message icon - QLabel * m_pLabel0; - /// Label for the message text - QLabel * m_pLabel1; -public: - /** - * \brief Returns the original irc message - * \return QString - */ - inline QString text() const { return m_szText; }; - /** - * \brief Returns the message icon - * \return QPixmap * - */ - inline QPixmap * pixmap() const { return m_pPixmap; }; - /** - * \brief Updates the aspect of this message - * \return void - */ - void updateGui(); -}; - -#endif //!_NOTIFIERMESSAGE_H_ diff --git a/src/modules/notifier/notifiersettings.h b/src/modules/notifier/notifiersettings.h deleted file mode 100644 index 1a0a29e42..000000000 --- a/src/modules/notifier/notifiersettings.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef _NOTIFIER_SETTINGS_H_ -#define _NOTIFIER_SETTINGS_H_ -//============================================================================= -// -// File : notifiersettings.h -// Creation date : Thu 30 Dev 2004 21:21:33 by Iacopo Palazzi -// -// This file is part of the Notifier - KVIrc Distribution distribution -// Copyright (C) 2004-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it > -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -// Global settings for KviNotifier - - - -#define WDG_MIN_WIDTH 370 -#define WDG_MIN_HEIGHT 160 -#define WDG_BORDER_THICKNESS 5 -#define SPACING 2 - -#define WDG_ICON_OUT 0 -#define WDG_ICON_OVER 1 -#define WDG_ICON_CLICKED 2 -#define WDG_ICON_ON 3 -#define WDG_ICON_OFF 4 - -#define NTF_TABS_FONT_BASELINE 8 - -#define MAX_MESSAGES_IN_WINDOW 20 -// keep hidden messages for 600 seconds : 10 min -#define MAX_MESSAGE_LIFETIME 600 - -#define OPACITY_STEP 0.07 - -#define NUM_OLD_COLORS 6 - -#define WDG_UPSX 1 -#define WDG_UP 2 -#define WDG_UPDX 3 -#define WDG_DWNSX 4 -#define WDG_DWN 5 -#define WDG_DWNDX 6 -#define WDG_SX 7 -#define WDG_DX 8 - -#define m_mac_bkgColor QColor(236,233,216) // Light-brown color of notifier background widget - -enum State { Hidden, Showing, Visible, Hiding, FocusingOff, FocusingOn }; -enum TabState { Normal, Highlighted, Changed }; - -#endif //_NOTIFIER_SETTINGS_H_ diff --git a/src/modules/notifier/notifierwindow.cpp b/src/modules/notifier/notifierwindow.cpp deleted file mode 100644 index f46b87c2d..000000000 --- a/src/modules/notifier/notifierwindow.cpp +++ /dev/null @@ -1,1153 +0,0 @@ -//============================================================================= -// -// File : notifierwindow.cpp -// Creation date : Tue Jul 6 2004 20:25:12 CEST by Szymon Stefanek -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2004-2008 Iacopo Palazzi < iakko(at)siena.linux.it > -// -// This program is FREE software. You can redistribute it and/or -// modify it under the linkss of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= -#include "kvi_settings.h" - -#include "notifiermessage.h" -#include "notifierwindow.h" -#include "notifierwindowborder.h" -#include "notifierwindowtab.h" - -#include "KviIconManager.h" -#include "KviConfigurationFile.h" -#include "KviWindow.h" -#include "KviLocale.h" -#include "KviMainWindow.h" -#include "KviMircCntrl.h" -#include "KviOptions.h" -#include "KviUserInput.h" -#include "KviThemedLineEdit.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern KviNotifierWindow * g_pNotifierWindow; - -KviNotifierWindow::KviNotifierWindow() -: QWidget(0, -#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) - Qt::FramelessWindowHint | - Qt::Tool | - Qt::WindowStaysOnTopHint) -#else - Qt::FramelessWindowHint | -#ifndef COMPILE_ON_MAC - Qt::Tool | - Qt::X11BypassWindowManagerHint | -#endif - Qt::WindowStaysOnTopHint) -#endif -{ - setObjectName("kvirc_notifier_window"); - - g_pNotifierWindow = this; - - m_eState = Hidden; - m_dOpacity = 0.0; - m_pShowHideTimer = 0; - m_pBlinkTimer = 0; - m_tAutoHideAt = 0; - m_tStartedAt=0; - m_pAutoHideTimer = 0; - - m_pWndBorder = new KviNotifierWindowBorder(); - - setFocusPolicy(Qt::NoFocus); - setMouseTracking(true); - setAutoFillBackground(true); - - hide(); - - m_bBlinkOn = false; - - m_bCloseDown = false; - m_bPrevDown = false; - m_bNextDown = false; - m_bWriteDown = false; - - m_bLeftButtonIsPressed = false; - m_bDiagonalResizing = false; - m_bResizing = false; - - m_pContextPopup = 0; - m_pDisablePopup = 0; - - m_bDragging = false; - - m_bDisableHideOnMainWindowGotAttention = false; - - // Positioning the notifier bottom-right - QDesktopWidget * pDesktop = QApplication::desktop(); - QRect r = pDesktop->availableGeometry(pDesktop->primaryScreen()); - - m_wndRect.setRect( - r.x() + r.width() - (WDG_MIN_WIDTH + SPACING), - r.y() + r.height() - (WDG_MIN_HEIGHT + SPACING), - WDG_MIN_WIDTH, - WDG_MIN_HEIGHT); - - m_pWndTabs = new QTabWidget(this); - m_pWndTabs->setUsesScrollButtons(true); - m_pWndTabs->setTabsClosable(true); - connect(m_pWndTabs,SIGNAL(tabCloseRequested(int)),this,SLOT(slotTabCloseRequested(int))); - - m_pProgressBar = new QProgressBar(this); - m_pProgressBar->setOrientation(Qt::Vertical); - m_pProgressBar->setRange(0, 100); - m_pProgressBar->setTextVisible(false); - m_pProgressBar->setMaximumWidth(8); - m_pProgressBar->installEventFilter(this); - - m_pLineEdit = new KviThemedLineEdit(this, 0, "notifier_lineedit"); - QPalette palette=m_pLineEdit->palette(); - palette.setColor(m_pLineEdit->backgroundRole(), Qt::transparent); - m_pLineEdit->setPalette(palette); - m_pLineEdit->installEventFilter(this); - connect(m_pLineEdit,SIGNAL(returnPressed()),this,SLOT(returnPressed())); - - QGridLayout *layout = new QGridLayout; - layout->addWidget(m_pProgressBar, 0,0,2,1); - layout->addWidget(m_pWndTabs,0,1,1,1); - layout->addWidget(m_pLineEdit,1,1,1,1); - layout->setSpacing(SPACING); - - layout->setGeometry(m_pWndBorder->bodyRect()); - layout->setContentsMargins(5,25,5,5); - setLayout(layout); - - connect(g_pApp,SIGNAL(updateNotifier()),this,SLOT(updateGui())); - QTimer::singleShot(0,this,SLOT(updateGui())); -} - -KviNotifierWindow::~KviNotifierWindow() -{ - stopShowHideTimer(); - stopBlinkTimer(); - stopAutoHideTimer(); - delete m_pWndBorder; - m_pWndTabs->deleteLater(); -} - -void KviNotifierWindow::updateGui() -{ - setFont(KVI_OPTION_FONT(KviOption_fontNotifier)); - QPalette palette=m_pLineEdit->palette(); - palette.setColor(m_pLineEdit->foregroundRole(), KVI_OPTION_COLOR(KviOption_colorNotifierForeground)); - m_pLineEdit->setPalette(palette); - m_pLineEdit->setFont(KVI_OPTION_FONT(KviOption_fontNotifier)); - - for(int i=0; icount();++i) - { - ((KviNotifierWindowTab*)m_pWndTabs->widget(i))->updateGui(); - } - -} - -void KviNotifierWindow::addMessage(KviWindow * pWnd, const QString & szImageId, const QString & szText, unsigned int uMessageTime) -{ - QPixmap * pIcon; - QString szMessage = szText; - szMessage.replace( QRegExp("\r([^\r])*\r([^\r])+\r"), "\\2" ); - if(szImageId.isEmpty()) - pIcon = 0; - else - pIcon = g_pIconManager->getImage(szImageId); - - KviNotifierMessage * pMessage = new KviNotifierMessage(pIcon ? new QPixmap(*pIcon) : 0,szMessage); - - //search for an existing tab - KviNotifierWindowTab * pTab = 0, * pTmp = 0; - for(int i=0; i < m_pWndTabs->count();++i) - { - pTmp = (KviNotifierWindowTab*)m_pWndTabs->widget(i); - if(pTmp->wnd() == pWnd) - { - pTab = pTmp; - break; - } - } - - if(!pTab) - { - pTab = new KviNotifierWindowTab(pWnd, m_pWndTabs); - } - - //if the notifier is already visible, don't steal the focus from the current tab! - //the user could be writing a message on it (bug #678) - if(!isVisible()) - m_pWndTabs->setCurrentWidget(pTab); - - pTab->appendMessage(pMessage); - - if(!isActiveWindow()) - startBlinking(); - - if(uMessageTime > 0) - { - kvi_time_t tAutoHide = kvi_unixTime() + uMessageTime; - if(m_tAutoHideAt < tAutoHide) - { - m_tAutoHideAt = tAutoHide; - if(m_eState == Visible) - startAutoHideTimer(); - } - } else { - // never hide - stopAutoHideTimer(); - m_tAutoHideAt = 0; - } - - if(pWnd) - { - if(pWnd->hasAttention()) - m_bDisableHideOnMainWindowGotAttention = true; - } - - if(isVisible()) - update(); -} - -void KviNotifierWindow::stopShowHideTimer() -{ - if(!m_pShowHideTimer) - return; - delete m_pShowHideTimer; - m_pShowHideTimer = 0; -} - -void KviNotifierWindow::stopBlinkTimer() -{ - if(!m_pBlinkTimer) - return; - delete m_pBlinkTimer; - m_pBlinkTimer = 0; -} - -void KviNotifierWindow::stopAutoHideTimer() -{ - if(!m_pAutoHideTimer) - return; - delete m_pAutoHideTimer; - m_pAutoHideTimer = 0; - m_pProgressBar->setValue(0); -} - -// FIXME: The code for detecting fullscreen window does NOT take into account multi-screen setups. -// We also lack the code for MacOSX and Qt-only-X11 compilation. - -#if COMPILE_KDE_SUPPORT - #include - - static bool active_window_is_full_screen() - { - WId activeId = KWindowSystem::activeWindow(); - KWindowInfo wi = KWindowSystem::windowInfo(activeId, NET::WMState); - return (wi.valid() && wi.hasState(NET::FullScreen)); - } -#else // COMPILE_KDE_SUPPORT - #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) - - #include - - static bool active_window_is_full_screen() - { - HWND hForeground = ::GetForegroundWindow(); - if(!hForeground) - return false; - - HWND hDesktop = ::GetDesktopWindow(); - if(hForeground == hDesktop) - return false; - - HWND hShell = ::GetShellWindow(); - if(hForeground == hShell) - return false; - - RECT rct; - ::GetWindowRect(hForeground,&rct); - - if((rct.right - rct.left) < GetSystemMetrics(SM_CXSCREEN)) - return false; - - if((rct.bottom - rct.top) < GetSystemMetrics(SM_CYSCREEN)) - return false; - - return true; - } - - #endif //COMPILE_ON_WINDOWS || COMPILE_ON_MINGW -#endif // COMPILE_KDE_SUPPORT - -void KviNotifierWindow::doShow(bool bDoAnimate) -{ - if(!KVI_OPTION_BOOL(KviOption_boolEnableNotifier)) - return; - - kvi_time_t tNow = kvi_unixTime(); - if(g_tNotifierDisabledUntil > tNow) - return; - g_tNotifierDisabledUntil = 0; - -#if defined(COMPILE_KDE_SUPPORT) || defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) - if(KVI_OPTION_BOOL(KviOption_boolDontShowNotifierIfActiveWindowIsFullScreen)) - { - // check if the active window is full screen - if(active_window_is_full_screen()) - return; - } -#endif //COMPILE_KDE_SUPPORT || COMPILE_ON_WINDOWS || COMPILE_ON_MINGW - - switch(m_eState) - { - case Showing: - // already showing up - return; - break; - case Visible: - // already visible - return; - break; - case Hiding: - // ops.. hiding! - m_eState = Showing; - break; - case Hidden: - stopShowHideTimer(); - stopBlinkTimer(); - - m_bDragging = false; - m_bCloseDown = false; - m_bPrevDown = false; - m_bNextDown = false; - m_bWriteDown = false; - m_bBlinkOn = false; - if(bDoAnimate) - { - m_pShowHideTimer = new QTimer(); - connect(m_pShowHideTimer,SIGNAL(timeout()),this,SLOT(heartbeat())); - m_dOpacity = OPACITY_STEP; - m_eState = Showing; - m_bCrashShowWorkAround = true; - setWindowOpacity(m_dOpacity); - show(); - m_pShowHideTimer->start(40); - m_bCrashShowWorkAround = false; - } else { - m_dOpacity = 1.0; - m_eState = Visible; - show(); - startBlinking(); - startAutoHideTimer(); - } - break; - default: - break; - } -} - -bool KviNotifierWindow::shouldHideIfMainWindowGotAttention() -{ - if(m_bDisableHideOnMainWindowGotAttention) - return false; - KviNotifierWindowTab * pTab = (KviNotifierWindowTab *) m_pWndTabs->currentWidget(); - if(!pTab) - return false; - if(!pTab->wnd()) - return false; - return pTab->wnd()->hasAttention(); -} - -void KviNotifierWindow::heartbeat() -{ - bool bIncreasing; - double targetOpacity = 0; - switch(m_eState) - { - case Hidden: - hideNow(); - break; - case Visible: - stopShowHideTimer(); - m_dOpacity = 1.0; - if(!isVisible()) - show(); - else - update(); - break; - case Showing: - // if the main window got attention while - // showing up then just hide now - if(shouldHideIfMainWindowGotAttention()) - { - m_eState = Hiding; - } else { - m_dOpacity += OPACITY_STEP; - targetOpacity = isActiveWindow() ? KVI_OPTION_UINT(KviOption_uintNotifierActiveTransparency) : KVI_OPTION_UINT(KviOption_uintNotifierInactiveTransparency); - - targetOpacity/=100; - if(m_dOpacity >= targetOpacity) - { - m_dOpacity = targetOpacity; - m_eState = Visible; - stopShowHideTimer(); - startBlinking(); - startAutoHideTimer(); - } - - if(!isVisible()) - show(); - setWindowOpacity(m_dOpacity); - update(); - - } - break; - case FocusingOn: - targetOpacity = KVI_OPTION_UINT(KviOption_uintNotifierActiveTransparency); - targetOpacity /= 100; - bIncreasing = targetOpacity > m_dOpacity; - m_dOpacity += bIncreasing? - OPACITY_STEP : -(OPACITY_STEP); - if((bIncreasing && (m_dOpacity >= targetOpacity)) || - (!bIncreasing && (m_dOpacity <= targetOpacity)) - ) - { - m_dOpacity = targetOpacity; - m_eState = Visible; - stopShowHideTimer(); - } - - setWindowOpacity(m_dOpacity); - break; - case FocusingOff: - targetOpacity = KVI_OPTION_UINT(KviOption_uintNotifierInactiveTransparency); - targetOpacity /= 100; - bIncreasing = targetOpacity > m_dOpacity; - m_dOpacity += bIncreasing ? OPACITY_STEP : -(OPACITY_STEP); - //qDebug("%f %f %i %i",m_dOpacity,targetOpacity,bIncreasing,(m_dOpacity >= targetOpacity)); - if((bIncreasing && (m_dOpacity >= targetOpacity)) || - (!bIncreasing && (m_dOpacity <= targetOpacity)) - ) - { - m_dOpacity = targetOpacity; - m_eState = Visible; - stopShowHideTimer(); - } - - setWindowOpacity(m_dOpacity); - break; - case Hiding: - m_dOpacity -= OPACITY_STEP; - setWindowOpacity(m_dOpacity); - if(m_dOpacity <= 0.0) - hideNow(); - else - update(); - break; - } -} - -void KviNotifierWindow::hideNow() -{ - stopBlinkTimer(); - stopShowHideTimer(); - stopAutoHideTimer(); - m_eState = Hidden; - m_dOpacity = 0.0; - m_tAutoHideAt = 0; - hide(); -} - -void KviNotifierWindow::doHide(bool bDoAnimate) -{ - stopAutoHideTimer(); - switch(m_eState) - { - case Hiding: - // already hiding up - if(!bDoAnimate) - hideNow(); - return; - break; - case Hidden: - // already hidden - if(isVisible()) - hideNow(); - return; - break; - case Showing: - // ops.. hiding! - if(!bDoAnimate) - hideNow(); - else { - // continue animating, but hide - m_eState = Hiding; - } - break; - case Visible: - stopBlinkTimer(); - stopShowHideTimer(); - if((!bDoAnimate) || (x() != m_pWndBorder->x()) || (y() != m_pWndBorder->y())) - { - - //qDebug("just hide quickly with notifier x() %d and notifier y() % - WBorderx() %d and WBordery() %d and bDoanimate %d",x(),y(),m_pWndBorder->x(),m_pWndBorder->y(),bDoAnimate); - // the user asked to not animate or - // the window has been moved and the animation would suck anyway - // just hide quickly - hideNow(); - } else { - //qDebug("starting hide animation notifier x() %d and notifier y() % - WBorderx() %d and WBordery() %d and bDoanimate %d",x(),y(),m_pWndBorder->x(),m_pWndBorder->y(),bDoAnimate); - m_pShowHideTimer = new QTimer(); - connect(m_pShowHideTimer,SIGNAL(timeout()),this,SLOT(heartbeat())); - m_dOpacity = 1.0 - OPACITY_STEP; - m_eState = Hiding; - setWindowOpacity(m_dOpacity); - update(); - m_pShowHideTimer->start(40); - } - break; - default: - break; - } -} - -void KviNotifierWindow::showEvent(QShowEvent *) -{ - setGeometry(m_wndRect); -} - -void KviNotifierWindow::hideEvent(QHideEvent *) -{ - if(m_bCrashShowWorkAround) - return; - stopBlinkTimer(); - stopShowHideTimer(); - stopAutoHideTimer(); - m_eState = Hidden; // make sure it's true - m_tAutoHideAt = 0; // make sure it's true - m_bDisableHideOnMainWindowGotAttention = false; -} - -void KviNotifierWindow::startBlinking() -{ - stopBlinkTimer(); - m_bBlinkOn = false; - - if(KVI_OPTION_BOOL(KviOption_boolNotifierFlashing)) - { - m_pBlinkTimer = new QTimer(); - connect(m_pBlinkTimer,SIGNAL(timeout()),this,SLOT(blink())); - m_iBlinkCount = 0; - m_pBlinkTimer->start(1000); - } -} - -void KviNotifierWindow::startAutoHideTimer() -{ - stopAutoHideTimer(); - m_tStartedAt = kvi_unixTime(); - if(m_tAutoHideAt <= m_tStartedAt) - return; - - int iSecs = m_tAutoHideAt - m_tStartedAt; - if(iSecs < 5) - iSecs = 5; - m_pAutoHideTimer = new QTimer(); - - connect(m_pAutoHideTimer,SIGNAL(timeout()),this,SLOT(progressUpdate())); - m_pAutoHideTimer->start(100); -} - -void KviNotifierWindow::blink() -{ - m_iBlinkCount++; - m_bBlinkOn = !m_bBlinkOn; - - if(m_iBlinkCount > 100) - { - // stop blinking at a certain point and remain highlighted - m_bBlinkOn = true; - stopBlinkTimer(); - } else { - // if the main window got attention while - // showing up then just hide now - if(shouldHideIfMainWindowGotAttention()) - { - doHide(false); // don't animate: the background has almost surely changed - return; - } - } - update(); -} - -void KviNotifierWindow::paintEvent(QPaintEvent * e) -{ - QPainter * pPaint = new QPainter(this); - - if(m_wndRect.width() != m_pWndBorder->width() || m_wndRect.height() != m_pWndBorder->height()) - m_pWndBorder->resize(m_wndRect.size()); - - if(m_bBlinkOn) - { - m_pWndBorder->draw(pPaint,true); - } else { - m_pWndBorder->draw(pPaint); - } - - pPaint->setPen(KVI_OPTION_COLOR(KviOption_colorNotifierTitleForeground)); - pPaint->setFont(KVI_OPTION_FONT(KviOption_fontNotifierTitle)); - - QString szTitle = "KVIrc - "; - KviNotifierWindowTab * pTab = (KviNotifierWindowTab *)m_pWndTabs->currentWidget(); - if(pTab) - { - if(pTab->wnd()) - { - szTitle += pTab->wnd()->plainTextCaption(); - } else { - szTitle += "notifier"; - } - } else { - szTitle += "notifier"; - } - pPaint->drawText(m_pWndBorder->titleRect(),Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine,szTitle); - - delete pPaint; - e->ignore(); -} - -void KviNotifierWindow::mouseMoveEvent(QMouseEvent * e) -{ - if(!m_bLeftButtonIsPressed) - { - if(checkResizing(e->pos())) - goto sartelo; - - if(m_pWndBorder->captionRect().contains(e->pos())) - { - if(m_pWndBorder->closeRect().contains(e->pos())) - m_pWndBorder->setCloseIcon(WDG_ICON_OVER); - else - m_pWndBorder->setCloseIcon(WDG_ICON_OUT); - goto sartelo; - } - -sartelo: - update(); - } - - if(m_bDragging) - { - setCursor(Qt::SizeAllCursor); - - int iW = m_wndRect.width(); - int iH = m_wndRect.height(); - - m_wndRect.setX(m_pntPos.x() + cursor().pos().x() - m_pntDrag.x()); - m_wndRect.setY(m_pntPos.y() + cursor().pos().y() - m_pntDrag.y()); - - m_wndRect.setWidth(iW); - m_wndRect.setHeight(iH); - - setGeometry(m_wndRect); - } else if(m_bResizing) - { - resize(e->pos()); - } -} - -void KviNotifierWindow::mousePressEvent(QMouseEvent * e) -{ - // stop blinking first of all :) - bool bWasBlinkOn = m_bBlinkOn; - m_bBlinkOn = false; - stopBlinkTimer(); - m_tAutoHideAt = 0; - stopAutoHideTimer(); - - activateWindow(); - setFocus(); - - m_pntClick = e->pos(); - - if(e->button() == Qt::RightButton) - { - contextPopup(mapToGlobal(e->pos())); - return; - } else if(e->button() == Qt::LeftButton) - { - m_bLeftButtonIsPressed = true; - } - - if(checkResizing(m_pntClick)) - { - update(); - return; - } - - if(m_pWndBorder->captionRect().contains(e->pos())) - { - if(m_pWndBorder->closeRect().contains(e->pos())) - { - m_bCloseDown = true; - m_pWndBorder->setCloseIcon(WDG_ICON_CLICKED); - update(); - return; - } - - if(!m_bResizing) - { - m_bDragging = true; - m_pntDrag = cursor().pos(); - m_pntPos = pos(); - update(); - return; - } - } - - if(m_pWndBorder->rect().contains(e->pos()) || bWasBlinkOn) - update(); -} - -void KviNotifierWindow::mouseReleaseEvent(QMouseEvent * e) -{ - m_bWriteDown = false; - m_bNextDown = false; - m_bPrevDown = false; - m_bCloseDown = false; - m_bLeftButtonIsPressed = false; - m_bResizing = false; - - if(m_bDragging) - { - m_bDragging = false; - if(QApplication::overrideCursor()) - QApplication::restoreOverrideCursor(); - return; - } - - if(m_pWndBorder->captionRect().contains(e->pos())) - { - if(m_pWndBorder->closeRect().contains(e->pos())) - hideNow(); - else - update(); - } - - setCursor(-1); -} - -void KviNotifierWindow::keyPressEvent(QKeyEvent * e) -{ - if(e->key() == Qt::Key_Escape) - { - hideNow(); - return; - } -} - -bool KviNotifierWindow::checkResizing(QPoint e) -{ - if(e.y() < WDG_BORDER_THICKNESS) - { - if(e.x() < WDG_BORDER_THICKNESS) - { - //// UP LEFT CORNER //// - setCursor(Qt::SizeFDiagCursor); - if (m_bLeftButtonIsPressed) - { - m_bResizing = true; - m_whereResizing = WDG_UPSX; - } - } else if(e.x() > (size().width()-WDG_BORDER_THICKNESS)) - { - //// UP RIGHT CORNER //// - setCursor(Qt::SizeBDiagCursor); - if (m_bLeftButtonIsPressed) - { - m_bResizing = true; - m_whereResizing = WDG_UPDX; - } - } else { - //// UP SIDE //// - setCursor(Qt::SizeVerCursor); - if (m_bLeftButtonIsPressed) - { - m_bResizing = true; - m_whereResizing = WDG_UP; - } - } - } else if(e.y() > (size().height()-WDG_BORDER_THICKNESS)) - { - if(e.x() < WDG_BORDER_THICKNESS) - { - //// DOWN LEFT CORNER //// - setCursor(Qt::SizeBDiagCursor); - if(m_bLeftButtonIsPressed) - { - m_bResizing = true; - m_whereResizing = WDG_DWNSX; - } - } else if(e.x() > (size().width()-WDG_BORDER_THICKNESS)) - { - //// DOWN RIGHT CORNER //// - setCursor(Qt::SizeFDiagCursor); - if(m_bLeftButtonIsPressed) - { - m_bResizing = true; - m_whereResizing = WDG_DWNDX; - } - } else { - //// DOWN SIDE //// - setCursor(Qt::SizeVerCursor); - if(m_bLeftButtonIsPressed) - { - m_bResizing = true; - m_whereResizing = WDG_DWN; - } - } - } else { - if(e.x() < WDG_BORDER_THICKNESS) - { - //// LEFT SIZE //// - setCursor(Qt::SizeHorCursor); - if(m_bLeftButtonIsPressed) - { - m_bResizing = true; - m_whereResizing = WDG_SX; - } - } else if(e.x() > (size().width()-WDG_BORDER_THICKNESS)) - { - //// RIGHT SIZE //// - setCursor(Qt::SizeHorCursor); - if(m_bLeftButtonIsPressed) - { - m_bResizing = true; - m_whereResizing = WDG_DX; - } - } else { - //// ELSEWHERE //// - m_whereResizing = 0; - m_bResizing = false; - setCursor(-1); - } - } - return m_bResizing; -} - -void KviNotifierWindow::resize(QPoint, bool) -{ - if(m_whereResizing == WDG_UPSX || m_whereResizing == WDG_SX || m_whereResizing == WDG_DWNSX) - { - if((x() + width() - cursor().pos().x()) < WDG_MIN_WIDTH) - m_wndRect.setLeft(x() + width() - WDG_MIN_WIDTH); - else - m_wndRect.setLeft(cursor().pos().x()); - } - - if(m_whereResizing == WDG_UPSX || m_whereResizing == WDG_UP || m_whereResizing == WDG_UPDX) - { - if(y()+height()-cursor().pos().y() < WDG_MIN_HEIGHT) - m_wndRect.setTop(y() + height() - WDG_MIN_HEIGHT); - else - m_wndRect.setTop(cursor().pos().y()); - } - - if(m_whereResizing == WDG_DX || m_whereResizing == WDG_UPDX || m_whereResizing == WDG_DWNDX) - { - if((cursor().pos().x() - x()) > WDG_MIN_WIDTH) - m_wndRect.setRight(cursor().pos().x()); - else - m_wndRect.setRight(x() + WDG_MIN_WIDTH); - } - - if(m_whereResizing == WDG_DWN || m_whereResizing == WDG_DWNDX || m_whereResizing == WDG_DWNSX) - { - if((cursor().pos().y() - y()) > WDG_MIN_HEIGHT) - m_wndRect.setBottom(cursor().pos().y()); - else - m_wndRect.setBottom(y() + WDG_MIN_HEIGHT); - } - - showLineEdit(m_pLineEdit->isVisible()); - setGeometry(m_wndRect); -} - -inline void KviNotifierWindow::setCursor(int iCur) -{ - if(m_cursor.shape() != iCur) - { - if(QApplication::overrideCursor()) - QApplication::restoreOverrideCursor(); - m_cursor.setShape((Qt::CursorShape)iCur); - QApplication::setOverrideCursor(m_cursor); - } else if(iCur == -1) - { - if(QApplication::overrideCursor()) - QApplication::restoreOverrideCursor(); - } -} - -void KviNotifierWindow::enterEvent(QEvent *) -{ - if(!m_pShowHideTimer) - { - m_pShowHideTimer = new QTimer(); - connect(m_pShowHideTimer,SIGNAL(timeout()),this,SLOT(heartbeat())); - } - m_eState = FocusingOn; - m_pShowHideTimer->start(40); -} - -void KviNotifierWindow::leaveEvent(QEvent *) -{ - // Leaving the widget area, restore default cursor - m_pWndBorder->resetIcons(); - if(!m_bResizing) - setCursor(-1); - - if(!m_pShowHideTimer) - { - m_pShowHideTimer = new QTimer(); - connect(m_pShowHideTimer,SIGNAL(timeout()),this,SLOT(heartbeat())); - } - - if(m_eState!=Hidden) - { - m_eState = FocusingOff; - m_pShowHideTimer->start(40); - } -} - -void KviNotifierWindow::contextPopup(const QPoint & pos) -{ - if(!m_pContextPopup) - { - m_pContextPopup = new KviTalPopupMenu(this); - connect(m_pContextPopup,SIGNAL(aboutToShow()),this,SLOT(fillContextPopup())); - m_pDisablePopup = new KviTalPopupMenu(this); - } - - m_pContextPopup->popup(pos); -} - -void KviNotifierWindow::fillContextPopup() -{ - m_pContextPopup->clear(); - m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_EDITOR)),__tr2qs_ctx("Show/Hide input line","notifier"),this,SLOT(toggleLineEdit())); - m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CLOSE)),__tr2qs_ctx("Hide","notifier"),this,SLOT(hideNow())); - m_pContextPopup->insertSeparator(); - m_pDisablePopup->clear(); - m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)),__tr2qs_ctx("1 Minute","notifier"),this,SLOT(disableFor1Minute())); - m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)),__tr2qs_ctx("5 Minutes","notifier"),this,SLOT(disableFor5Minutes())); - m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)),__tr2qs_ctx("15 Minutes","notifier"),this,SLOT(disableFor15Minutes())); - m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)),__tr2qs_ctx("30 Minutes","notifier"),this,SLOT(disableFor30Minutes())); - m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)),__tr2qs_ctx("1 Hour","notifier"),this,SLOT(disableFor60Minutes())); - m_pDisablePopup->insertSeparator(); - m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_QUIT)),__tr2qs_ctx("Until KVIrc is Restarted","notifier"),this,SLOT(disableUntilKVIrcRestarted())); - m_pDisablePopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_QUIT)),__tr2qs_ctx("Permanently (Until Explicitly Enabled)","notifier"),this,SLOT(disablePermanently())); - - m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_QUIT)),__tr2qs_ctx("Disable","notifier"),m_pDisablePopup); -} - -void KviNotifierWindow::disableFor15Minutes() -{ - kvi_time_t tNow = kvi_unixTime(); - g_tNotifierDisabledUntil = tNow + (60 * 15); - - hideNow(); -} - -void KviNotifierWindow::disableFor5Minutes() -{ - kvi_time_t tNow = kvi_unixTime(); - g_tNotifierDisabledUntil = tNow + (60 * 5); - - hideNow(); -} - - -void KviNotifierWindow::disableFor1Minute() -{ - kvi_time_t tNow = kvi_unixTime(); - g_tNotifierDisabledUntil = tNow + 60; - - hideNow(); -} - -void KviNotifierWindow::disableFor30Minutes() -{ - kvi_time_t tNow = kvi_unixTime(); - g_tNotifierDisabledUntil = tNow + (60 * 30); - - hideNow(); -} - -void KviNotifierWindow::disableFor60Minutes() -{ - kvi_time_t tNow = kvi_unixTime(); - g_tNotifierDisabledUntil = tNow + (60 * 60); - - hideNow(); -} - -void KviNotifierWindow::disableUntilKVIrcRestarted() -{ - kvi_time_t tNow = kvi_unixTime(); - // in fact we just disable for one year - g_tNotifierDisabledUntil = tNow + (3600 * 24 * 360); // one year :D - // this will NOT work if the module is forcibly unloaded with /notifier.unload - // but the user should never do it :D - hideNow(); -} - -void KviNotifierWindow::disablePermanently() -{ - KVI_OPTION_BOOL(KviOption_boolEnableNotifier) = false; - hideNow(); -} - -void KviNotifierWindow::toggleLineEdit() -{ - showLineEdit(!m_pLineEdit->isVisible()); -} - -void KviNotifierWindow::showLineEdit(bool bShow) -{ - if(bShow) - { - if(m_pLineEdit->isVisible()) - return; - if(!((KviNotifierWindowTab *)m_pWndTabs->currentWidget())->wnd()) - return; - m_pLineEdit->setToolTip(""); - - QString szTip = __tr2qs_ctx("Write text or commands to window","notifier"); - szTip += " \""; - szTip += ((KviNotifierWindowTab *)m_pWndTabs->currentWidget())->wnd()->plainTextCaption(); - szTip += "\""; - m_pLineEdit->setToolTip(szTip); - m_pLineEdit->show(); - m_pLineEdit->setFocus(); - activateWindow(); - } else { - if(!m_pLineEdit->isVisible()) - return; - m_pLineEdit->hide(); - setFocus(); - update(); - } -} - -bool KviNotifierWindow::eventFilter(QObject * pEdit, QEvent * e) -{ - if(pEdit != (QObject *)m_pLineEdit) - return false; // huh ? - if(!m_pLineEdit->isVisible()) - return false; - if(e->type() == QEvent::MouseButtonPress) - { - bool bWasBlinkOn = m_bBlinkOn; - m_bBlinkOn = false; - m_tAutoHideAt = 0; - stopAutoHideTimer(); - stopBlinkTimer(); - activateWindow(); - m_pLineEdit->setFocus(); - if(bWasBlinkOn) - update(); - return true; - } - if(e->type() == QEvent::KeyPress) - { - if(((QKeyEvent *)e)->key() == Qt::Key_Escape) - { - hideNow(); - return true; - } - } - return false; -} - -void KviNotifierWindow::returnPressed() -{ - if(!m_pLineEdit->isVisible()) - return; - - KviNotifierWindowTab * pTab = (KviNotifierWindowTab *) m_pWndTabs->currentWidget(); - if(!pTab) - return; - if(!pTab->wnd()) - return; - - QString szTxt = m_pLineEdit->text(); - if(szTxt.isEmpty()) - return; - QString szHtml = szTxt; - szHtml.replace("<","<"); - szHtml.replace(">",">"); - KviCString szTmp(KviCString::Format,"%d",KVI_SMALLICON_OWNPRIVMSG); - - addMessage(pTab->wnd(),szTmp.ptr(),szHtml,0); - m_pLineEdit->setText(""); - KviUserInput::parse(szTxt,pTab->wnd(),QString(),1); -} - -void KviNotifierWindow::progressUpdate() -{ - kvi_time_t now = kvi_unixTime(); - int iProgress = (int)(100/(m_tAutoHideAt - m_tStartedAt)*(now - m_tStartedAt)); - m_pProgressBar->setValue(iProgress); - if(now >= m_tAutoHideAt) - { - m_tAutoHideAt = 0; - stopAutoHideTimer(); - doHide(true); - } -} - -void KviNotifierWindow::slotTabCloseRequested(int iIndex) -{ - if(m_pWndTabs) - { - KviNotifierWindowTab * pTab = (KviNotifierWindowTab *) m_pWndTabs->widget(iIndex); - m_pWndTabs->removeTab(iIndex); - if(pTab) - pTab->deleteLater(); - - if(m_pWndTabs->count()==0) - hideNow(); - } -} - -#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES -#include "m_notifierwindow.moc" -#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/notifier/notifierwindow.h b/src/modules/notifier/notifierwindow.h deleted file mode 100644 index 10e1b8c6a..000000000 --- a/src/modules/notifier/notifierwindow.h +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef _NOTIFIERWINDOW_H_ -#define _NOTIFIERWINDOW_H_ -//============================================================================= -// -// File : notifierwindow.h -// Creation date : Tue Jul 6 2004 20:25:12 CEST by Szymon Stefanek -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2004 Szymon Stefanek (pragma at kvirc dot net) -// Copyright (C) 2005-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it > -// -// This program is FREE software. You can redistribute it and/or -// modify it under the linkss of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -#include "notifiersettings.h" - -#include "kvi_settings.h" -#include "KviQString.h" -#include "KviPointerList.h" -#include "KviTalPopupMenu.h" -#include "KviTimeUtils.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class QPainter; -class KviWindow; -class KviNotifierMessage; -class KviNotifierWindowBorder; -class KviNotifierWindowTabs; -class KviThemedLineEdit; - -extern kvi_time_t g_tNotifierDisabledUntil; - -class KviNotifierWindow : public QWidget -{ - Q_OBJECT -public: - KviNotifierWindow(); - ~KviNotifierWindow(); -protected: - QTimer * m_pShowHideTimer; - QTimer * m_pBlinkTimer; - QTimer * m_pAutoHideTimer; - State m_eState; - bool m_bBlinkOn; - double m_dOpacity; - - bool m_bCloseDown; - bool m_bPrevDown; - bool m_bNextDown; - bool m_bWriteDown; - bool m_bCrashShowWorkAround; - - QRect m_wndRect; - - KviNotifierMessage * m_pCurrentMessage; - KviThemedLineEdit * m_pLineEdit; - - bool m_bDragging; - bool m_bLeftButtonIsPressed; - bool m_bDiagonalResizing; - bool m_bResizing; - - int m_whereResizing; - - QPoint m_pntDrag; - QPoint m_pntPos; - QPoint m_pntClick; - int m_iBlinkCount; - KviTalPopupMenu * m_pContextPopup; - KviTalPopupMenu * m_pDisablePopup; - KviWindow * m_pWindowToRaise; - kvi_time_t m_tAutoHideAt; - kvi_time_t m_tStartedAt; - QTime m_qtStartedAt; - bool m_bDisableHideOnMainWindowGotAttention; - - QCursor m_cursor; - - QTabWidget * m_pWndTabs; - QProgressBar * m_pProgressBar; - KviNotifierWindowBorder * m_pWndBorder; -public: - void doShow(bool bDoAnimate); - void doHide(bool bDoAnimate); - int textWidth(); - void addMessage(KviWindow * pWnd,const QString &szImageId,const QString &szText,unsigned int uMessageTime); - void setDisableHideOnMainWindowGotAttention(bool b){ m_bDisableHideOnMainWindowGotAttention = b; }; - void showLineEdit(bool bShow); - inline int countTabs() const { if(m_pWndTabs)return m_pWndTabs->count(); return 0; }; - inline State state() const { return m_eState; }; -protected: - virtual void showEvent(QShowEvent *e); - virtual void hideEvent(QHideEvent * e); - virtual void paintEvent(QPaintEvent * e); - virtual void mousePressEvent(QMouseEvent * e); - virtual void mouseReleaseEvent(QMouseEvent * e); - virtual void mouseMoveEvent(QMouseEvent * e); - virtual void leaveEvent(QEvent * e); - virtual void enterEvent(QEvent * e); - virtual bool eventFilter(QObject * pEdit,QEvent * e); - virtual void keyPressEvent ( QKeyEvent * e ); -public slots: - void hideNow(); - void toggleLineEdit(); - void slotTabCloseRequested(int index); -protected slots: - void blink(); - void heartbeat(); - void returnPressed(); - void updateGui(); - void fillContextPopup(); - void disableFor1Minute(); - void disableFor5Minutes(); - void disableFor15Minutes(); - void disableFor30Minutes(); - void disableFor60Minutes(); - void disableUntilKVIrcRestarted(); - void disablePermanently(); - void progressUpdate(); -private: - void contextPopup(const QPoint &pos); - void startBlinking(); -// void computeRect(); - void stopShowHideTimer(); - void stopBlinkTimer(); - void stopAutoHideTimer(); - void startAutoHideTimer(); - bool shouldHideIfMainWindowGotAttention(); - void setCursor(int); - void resize(QPoint p, bool = true); - void redrawText(); - bool checkResizing(QPoint); -}; - -#endif //_NOTIFIERWINDOW_H_ diff --git a/src/modules/notifier/notifierwindowborder.cpp b/src/modules/notifier/notifierwindowborder.cpp deleted file mode 100644 index c8c94c3f5..000000000 --- a/src/modules/notifier/notifierwindowborder.cpp +++ /dev/null @@ -1,205 +0,0 @@ -//============================================================================= -// -// File : notifierwindowborder.cpp -// Creation date : Mon 03 Jan 2005 02:27:22 by Iacopo Palazzi -// -// This file is part of the KVIrc distribution -// Copyright (C) 2005-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it > -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -#include "notifierwindowborder.h" -#include "notifierwindowtab.h" - -#include "KviIconManager.h" - -#include - -KviNotifierWindowBorder::KviNotifierWindowBorder(QSize s) -{ - loadImages(); - resize(s); -} - -KviNotifierWindowBorder::~KviNotifierWindowBorder() -{ -} - -void KviNotifierWindowBorder::loadImages() -{ - // Normal Border - - QPixmap * p; - - if((p = g_pIconManager->getPixmap("notifier_pix_wnd_sx.png"))) - m_pixSX_N = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dx.png"))) - m_pixDX_N = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwn.png"))) - m_pixDWN_N = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwndx.png"))) - m_pixDWNDX_N = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwnsx.png"))) - m_pixDWNSX_N = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_caption_sx.png"))) - m_pixCaptionSX_N = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_caption_dx.png"))) - m_pixCaptionDX_N = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_caption_bkg.png"))) - m_pixCaptionBKG_N = *p; - - if((p = g_pIconManager->getPixmap("notifier_icon_close_out.png"))) - m_pixIconClose_out_N = *p; - if((p = g_pIconManager->getPixmap("notifier_icon_close_over.png"))) - m_pixIconClose_over_N = *p; - if((p = g_pIconManager->getPixmap("notifier_icon_close_clicked.png"))) - m_pixIconClose_clicked_N = *p; - - // Highlighted Border - - if((p = g_pIconManager->getPixmap("notifier_pix_wnd_sx_hl.png"))) - m_pixSX_HL = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dx_hl.png"))) - m_pixDX_HL = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwn_hl.png"))) - m_pixDWN_HL = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwndx_hl.png"))) - m_pixDWNDX_HL = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_wnd_dwnsx_hl.png"))) - m_pixDWNSX_HL = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_caption_sx_hl.png"))) - m_pixCaptionSX_HL = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_caption_dx_hl.png"))) - m_pixCaptionDX_HL = *p; - if((p = g_pIconManager->getPixmap("notifier_pix_caption_bkg_hl.png"))) - m_pixCaptionBKG_HL = *p; - - if((p = g_pIconManager->getPixmap("notifier_icon_close_out_hl.png"))) - m_pixIconClose_out_HL = *p; - if((p = g_pIconManager->getPixmap("notifier_icon_close_over_hl.png"))) - m_pixIconClose_over_HL = *p; - if((p = g_pIconManager->getPixmap("notifier_icon_close_clicked_hl.png"))) - m_pixIconClose_clicked_HL = *p; - - setPics(); - setCloseIcon(WDG_ICON_OUT); - - if ( m_pixCaptionDX->height()==m_pixCaptionSX->height() && m_pixCaptionDX->height()==m_pixCaptionBKG->height()) // just to be sure that the height is fitting - m_captionRect.setHeight(m_pixCaptionDX->height()); - -} - -void KviNotifierWindowBorder::setPics(bool b) -{ - if (b) { - m_pixSX = &m_pixSX_HL; - m_pixDX = &m_pixDX_HL; - m_pixDWN = &m_pixDWN_HL; - m_pixDWNSX = &m_pixDWNSX_HL; - m_pixDWNDX = &m_pixDWNDX_HL; - m_pixCaptionSX = &m_pixCaptionSX_HL; - m_pixCaptionDX = &m_pixCaptionDX_HL; - m_pixCaptionBKG = &m_pixCaptionBKG_HL; - m_pixIconClose_out = &m_pixIconClose_out_HL; - m_pixIconClose_over = &m_pixIconClose_over_HL; - m_pixIconClose_clicked = &m_pixIconClose_clicked_HL; - } else { - m_pixSX = &m_pixSX_N; - m_pixDX = &m_pixDX_N; - m_pixDWN = &m_pixDWN_N; - m_pixDWNSX = &m_pixDWNSX_N; - m_pixDWNDX = &m_pixDWNDX_N; - m_pixCaptionSX = &m_pixCaptionSX_N; - m_pixCaptionDX = &m_pixCaptionDX_N; - m_pixCaptionBKG = &m_pixCaptionBKG_N; - m_pixIconClose_out = &m_pixIconClose_out_N; - m_pixIconClose_over = &m_pixIconClose_over_N; - m_pixIconClose_clicked = &m_pixIconClose_clicked_N; - } -} - -void KviNotifierWindowBorder::setWidth(int w) -{ - m_iRctWidth = w; - recalculatePositions(); -} - -void KviNotifierWindowBorder::setHeight(int h) -{ - m_iRctHeight = h; - recalculatePositions(); -} - -void KviNotifierWindowBorder::recalculatePositions() -{ - m_rct.setHeight(m_iRctHeight); - m_rct.setWidth(m_iRctWidth); - m_rct.setTopLeft(QPoint(0,0)); - - m_closeIconRect.setX(m_rct.width()-m_pixCaptionDX->width()-m_pixIconClose->width()); - m_closeIconRect.setY(2); - m_closeIconRect.setWidth(m_pixIconClose->width()); - m_closeIconRect.setHeight(m_pixIconClose->height()); - - m_captionRect.setTopLeft( m_rct.topLeft() ); - m_captionRect.setSize( QSize(m_rct.width(),m_pixCaptionDX->height()) ); - - m_bodyRect.setTopLeft( QPoint(m_pixCaptionDX->width(),m_captionRect.height()) ); - m_bodyRect.setSize( QSize(m_captionRect.width()-(2*m_pixCaptionDX->width()),m_rct.height()-m_captionRect.height()-m_pixDWN->height()) ); - - m_titleRect.setTopLeft( QPoint(m_pixCaptionSX->width(),0) ); - m_titleRect.setSize( QSize(m_rct.width()-m_pixCaptionSX->width()-m_pixCaptionDX->width()-m_pixIconClose->width(),m_captionRect.height())); - -} - -void KviNotifierWindowBorder::setCloseIcon(int state) -{ - m_eIconState = state; - switch (m_eIconState) { - case WDG_ICON_OUT: m_pixIconClose = m_pixIconClose_out; break; - case WDG_ICON_OVER: m_pixIconClose = m_pixIconClose_over; break; - case WDG_ICON_CLICKED: m_pixIconClose = m_pixIconClose_clicked; break; - }; -} - -void KviNotifierWindowBorder::resetIcons() -{ - setCloseIcon(WDG_ICON_OUT); -} - -void KviNotifierWindowBorder::draw(QPainter * p, bool b) -{ - setPics(b); - setCloseIcon(m_eIconState); - - // Draw the caption - p->drawPixmap(m_captionRect.x(), m_captionRect.y(), *m_pixCaptionSX); - p->drawTiledPixmap(m_pixCaptionSX->width(), 0, m_captionRect.width() - (m_pixCaptionSX->width() + m_pixCaptionDX->width()), m_captionRect.height(), *m_pixCaptionBKG); - p->drawPixmap(m_captionRect.width() - m_pixCaptionDX->width(), 0, *m_pixCaptionDX); - - // Draw the tiled borders - p->drawTiledPixmap(0, m_captionRect.height(), m_pixSX->width(), m_bodyRect.height(), *m_pixSX); - p->drawTiledPixmap(m_bodyRect.width() + m_bodyRect.x(), m_captionRect.height(), m_pixDX->width(), m_bodyRect.height(), *m_pixDX); - p->drawTiledPixmap(m_pixDWNSX->width(), m_captionRect.height() + m_bodyRect.height(), m_bodyRect.width() + 1, m_pixDWN->height(), *m_pixDWN); - - // Draw down corners - p->drawPixmap(0, m_captionRect.height() + m_bodyRect.height(), *m_pixDWNSX); - p->drawPixmap(m_bodyRect.width() + m_bodyRect.x(), m_captionRect.height() + m_bodyRect.height(), *m_pixDWNDX); - - //Drawing icons - p->drawPixmap(m_closeIconRect.x(), m_closeIconRect.y(), *m_pixIconClose); -} diff --git a/src/modules/notifier/notifierwindowborder.h b/src/modules/notifier/notifierwindowborder.h deleted file mode 100644 index d5a6bbcb0..000000000 --- a/src/modules/notifier/notifierwindowborder.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef _KVINOTIFIERWINDOWBORDER_H_ -#define _KVINOTIFIERWINDOWBORDER_H_ -//============================================================================= -// -// File : notifierwindowborder.h -// Creation date : Mon 03 Jan 2005 02:27:22 by Iacopo Palazzi -// -// This file is part of the KVIrc distribution -// Copyright (C) 2005-2008 Iacopo Palazzi < iakko(at)siena(dot)linux(dot)it > -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -#include "notifiersettings.h" - -#include -#include -#include - -class QPainter; - -class KviNotifierWindowBorder -{ -public: - KviNotifierWindowBorder(QSize = QSize(WDG_MIN_WIDTH,WDG_MIN_HEIGHT)); - ~KviNotifierWindowBorder(); - -// ================================ -// Put members declaration below... -// ================================ -private: - QRect m_rct; - QPoint m_pnt; - - QRect m_closeIconRect; - - QRect m_captionRect; - QRect m_bodyRect; - QRect m_titleRect; - - // Pictures - QPixmap * m_pixSX; - QPixmap * m_pixDX; - QPixmap * m_pixDWN; - QPixmap * m_pixDWNSX; - QPixmap * m_pixDWNDX; - QPixmap * m_pixCaptionSX; - QPixmap * m_pixCaptionDX; - QPixmap * m_pixCaptionBKG; - QPixmap * m_pixIconClose_out; - QPixmap * m_pixIconClose_over; - QPixmap * m_pixIconClose_clicked; - QPixmap * m_pixIconClose; - - QPixmap m_pixSX_N; - QPixmap m_pixDX_N; - QPixmap m_pixDWN_N; - QPixmap m_pixDWNSX_N; - QPixmap m_pixDWNDX_N; - QPixmap m_pixCaptionSX_N; - QPixmap m_pixCaptionDX_N; - QPixmap m_pixCaptionBKG_N; - QPixmap m_pixIconClose_out_N; - QPixmap m_pixIconClose_over_N; - QPixmap m_pixIconClose_clicked_N; - - QPixmap m_pixSX_HL; - QPixmap m_pixDX_HL; - QPixmap m_pixDWN_HL; - QPixmap m_pixDWNSX_HL; - QPixmap m_pixDWNDX_HL; - QPixmap m_pixCaptionSX_HL; - QPixmap m_pixCaptionDX_HL; - QPixmap m_pixCaptionBKG_HL; - QPixmap m_pixIconClose_out_HL; - QPixmap m_pixIconClose_over_HL; - QPixmap m_pixIconClose_clicked_HL; - - int m_eIconState; - int m_iRctWidth; - int m_iRctHeight; -private: - void loadImages(); - void recalculatePositions(); - -public: - // reading methods... - void setWidth(int w); - void setHeight(int h); - void resize(int w, int h) { setWidth(w); setHeight(h); }; - void resize(QSize r) { setWidth(r.width()); setHeight(r.height()); }; - void setGeometry(QRect r) { r.topLeft(); r.size(); /*qDebug("x,y: %d,%d", r.x(), r.y()); qDebug("w,h: %d,%d", r.width(), r.height());*/ }; - void setGeometry(QPoint p, QSize s) { setPoint (p.x(), p.y()); setWidth (s.width()); setHeight (s.height()); }; - - void setPoint(int x, int y) { m_pnt.setX(x); m_pnt.setY(y); m_rct.setX(x); m_rct.setY(y); }; - - void setCloseIcon(int state); - void resetIcons(); - - // writing methods... - inline int x() const { return m_pnt.x(); }; - inline int y() const { return m_pnt.y(); }; - inline int width() const { return m_rct.width(); }; - inline int height() const { return m_rct.height(); }; - inline int baseLine() const { return (y()+height()); }; - - inline QRect bodyRect() const { return m_bodyRect; }; - inline QRect captionRect() const { return m_captionRect; }; - inline QRect rect() const { return m_rct; }; - inline QRect closeRect() const { return m_closeIconRect; }; - inline QRect titleRect() const { return m_titleRect; }; - - void draw(QPainter *, bool b = false); - void setPics(bool b = false); -}; - -#endif //!_KVINOTIFIERWINDOWBORDER_H_ diff --git a/src/modules/notifier/notifierwindowtab.cpp b/src/modules/notifier/notifierwindowtab.cpp deleted file mode 100644 index 7f48d15f6..000000000 --- a/src/modules/notifier/notifierwindowtab.cpp +++ /dev/null @@ -1,230 +0,0 @@ -//============================================================================= -// -// File : notifierwindowtab.cpp -// File : notifierwindowtab.h -// Creation date : Tue 07 Jul 2009 10:28 by Fabio Bas -// -// This file is part of the KVIrc distribution -// Copyright (C) 2009 Fabio Bas < ctrlaltca at gmail dot com > -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -#include "notifiermessage.h" -#include "notifierwindowtab.h" -#include "notifierwindow.h" -#include "notifiersettings.h" - -#include "KviApplication.h" -#include "KviConfigurationFile.h" -#include "KviLocale.h" -#include "KviMainWindow.h" -#include "KviOptions.h" -#include "KviPixmapUtils.h" -#include "KviWindow.h" - -#include -#include -#include -#include -#include -#include - -#ifdef COMPILE_PSEUDO_TRANSPARENCY - #include - extern KVIRC_API QPixmap * g_pShadedChildGlobalDesktopBackground; -#endif - -extern KviNotifierWindow * g_pNotifierWindow; - -KviNotifierWindowTab::KviNotifierWindowTab(KviWindow * pWnd, QTabWidget * pParent) -: QScrollArea(pParent) -{ - m_pWnd = pWnd; - if(m_pWnd) - { - m_szLabel = m_pWnd->windowName(); - connect(pWnd,SIGNAL(windowNameChanged()),this,SLOT(labelChanged())); - connect(pWnd,SIGNAL(destroyed()),this,SLOT(closeMe())); - } else { - m_szLabel = "----"; - } - - if(pParent) - { - m_pParent = pParent; - m_pParent->addTab(this, m_szLabel); - } - - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - - if(verticalScrollBar()) - connect(verticalScrollBar(),SIGNAL(rangeChanged(int, int)),this, SLOT(scrollRangeChanged(int, int))); - - QPalette pal = palette(); - pal.setColor(backgroundRole(), Qt::transparent); - setPalette(pal); - - m_pVWidget = new QWidget(viewport()); - m_pVBox = new QVBoxLayout(m_pVWidget); - m_pVBox->setSizeConstraint(QLayout::SetFixedSize); - m_pVBox->setSpacing(SPACING); - m_pVBox->setMargin(SPACING); - - setWidget(m_pVWidget); -} - -KviNotifierWindowTab::~KviNotifierWindowTab() -{ - if(m_pVBox) - m_pVBox->deleteLater(); - if(m_pVWidget) - m_pVWidget->deleteLater(); -} - -void KviNotifierWindowTab::appendMessage(KviNotifierMessage * pMessage) -{ - m_pVBox->addWidget(pMessage); - pMessage->setFixedWidth(viewport()->width()); - - while(m_pVBox->count() > MAX_MESSAGES_IN_WINDOW) - { - QLayoutItem * pTmp = m_pVBox->takeAt(0); - KviNotifierMessage * pTmp2 = (KviNotifierMessage*)pTmp->widget(); - if(pTmp2) - pTmp2->deleteLater(); - } -} - -void KviNotifierWindowTab::updateGui() -{ - for(int i=0; icount(); ++i) - { - QLayoutItem * pTmp = m_pVBox->itemAt(i); - KviNotifierMessage * pTmp2 = (KviNotifierMessage*)pTmp->widget(); - if(pTmp2) - pTmp2->updateGui(); - } -} - -void KviNotifierWindowTab::scrollRangeChanged(int, int) -{ - //this is the autoscroll - if(verticalScrollBar()) - verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum); -} - -void KviNotifierWindowTab::labelChanged() -{ - if(!m_pWnd || !m_pParent) - return; - - int iIdx = m_pParent->indexOf(this); - m_szLabel = m_pWnd->windowName(); - if(iIdx > -1) - m_pParent->setTabText(iIdx, m_szLabel); -} - -void KviNotifierWindowTab::mouseDoubleClickEvent(QMouseEvent *) -{ - if(!m_pWnd || !g_pNotifierWindow) - return; - if(!g_pApp->windowExists(m_pWnd)) - return; - - g_pNotifierWindow->hideNow(); - - if(m_pWnd->mdiParent()) - { - m_pWnd->frame()->raise(); - m_pWnd->frame()->setFocus(); - m_pWnd->frame()->setWindowState((m_pWnd->frame()->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); - if(!m_pWnd->frame()->isVisible()) - m_pWnd->frame()->show(); - } - - m_pWnd->frame()->setActiveWindow(m_pWnd); -} - -void KviNotifierWindowTab::closeMe() -{ - //our window has been closed - if(m_pParent && g_pNotifierWindow) - { - int iIdx = m_pParent->indexOf(this); - if(iIdx != -1) - { - g_pNotifierWindow->slotTabCloseRequested(iIdx); - } - } -} - -void KviNotifierWindowTab::resizeEvent(QResizeEvent *) -{ - if(m_pVBox) - { - int iWidth = viewport()->width(); - KviNotifierMessage * pMessage; - for(int i=0; i < m_pVBox->count(); i++) - { - pMessage = (KviNotifierMessage *)m_pVBox->itemAt(i)->widget(); - if(pMessage) - pMessage->setFixedWidth(iWidth); - } - } -} - -void KviNotifierWindowTab::paintEvent(QPaintEvent * e) -{ - QPainter * pPainter = new QPainter(viewport()); - - //make sure you clean your widget with a transparent - // color before doing any rendering - // note the usage of a composition mode Source - // it's important! - - #ifdef COMPILE_PSEUDO_TRANSPARENCY - if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing()) - { - pPainter->save(); - pPainter->setCompositionMode(QPainter::CompositionMode_Source); - QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade); - col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100)); - pPainter->fillRect(e->rect(), col); - pPainter->restore(); - } else if(g_pShadedChildGlobalDesktopBackground) - { - QPoint pnt = mapToGlobal(e->rect().topLeft()); - pPainter->drawTiledPixmap(e->rect(),*(g_pShadedChildGlobalDesktopBackground), pnt); - } else { - #endif - QPixmap * pPix = KVI_OPTION_PIXMAP(KviOption_pixmapNotifierBackground).pixmap(); - - if(pPix) - KviPixmapUtils::drawPixmapWithPainter(pPainter,pPix,KVI_OPTION_UINT(KviOption_uintNotifierPixmapAlign),e->rect(),e->rect().width(),e->rect().height()); - else pPainter->fillRect(e->rect(),KVI_OPTION_COLOR(KviOption_colorNotifierBackground)); - #ifdef COMPILE_PSEUDO_TRANSPARENCY - } - #endif - - delete pPainter; - e->ignore(); -} - -#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES -#include "m_notifierwindowtab.moc" -#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/notifier/notifierwindowtab.h b/src/modules/notifier/notifierwindowtab.h deleted file mode 100644 index 0e6edcdbe..000000000 --- a/src/modules/notifier/notifierwindowtab.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef _KVINOTIFIERWINDOWTAB_H_ -#define _KVINOTIFIERWINDOWTAB_H_ -//============================================================================= -// -// File : notifierwindowtab.h -// Creation date : Tue 07 Jul 2009 10:28 by Fabio Bas -// -// This file is part of the KVIrc distribution -// Copyright (C) 2009 Fabio Bas < ctrlaltca at gmail dot com > -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -/** -* \file notifierwindowtab.h -* \author Fabio Bas -* \brief Defines the tab page for the notifier object -*/ - -#include "notifiermessage.h" - -#include "kvi_settings.h" - -#include - -class QVBoxLayout; -class QWidget; -class QTabWidget; -class QPainter; -class KviWindow; - -/** -* \class KviNotifierWindowTab -* \brief Defines an object for every single tab about the tabs area -*/ -class KviNotifierWindowTab : public QScrollArea -{ - Q_OBJECT -public: - /** - * \brief Creates the tab object - * \param pWnd The name of the window represented by the tab - * \param pParent The parent area container - * \return KviNotifierWindowTab - */ - KviNotifierWindowTab(KviWindow * pWnd, QTabWidget * pParent); - - /** - * \brief Destroys the tab object - */ - ~KviNotifierWindowTab(); -private: - QString m_szLabel; - KviWindow * m_pWnd; - QTabWidget * m_pParent; - QVBoxLayout * m_pVBox; - QWidget * m_pVWidget; -public: - /** - * \brief Appends the given message to the window - * \param pMessage The message received to append - * \return void - */ - void appendMessage(KviNotifierMessage * pMessage); - - /** - * \brief Updates the GUI - * \return void - */ - void updateGui(); - - /** - * \brief Returns the name of the current window - * \return QString - */ - inline QString label() const { return m_szLabel; }; - - /** - * \brief Returns the pointer of the current window - * \return KviWindow * - */ - inline KviWindow * wnd() const { return m_pWnd; }; -protected: - virtual void mouseDoubleClickEvent(QMouseEvent * e); - virtual void resizeEvent(QResizeEvent * e); - virtual void paintEvent(QPaintEvent * e); -private slots: - /** - * \brief Emitted when the scrollbar range is changed - * \return void - */ - void scrollRangeChanged(int, int); - - /** - * \brief Emitted when the window changes its name - * \return void - */ - void labelChanged(); - - /** - * \brief Emitted when the window is being destroyed - * \return void - */ - void closeMe(); -}; - -#endif //!_KVINOTIFIERWINDOWTAB_H_ -- cgit v1.3.1-10-gc9f91