diff --git a/src/modules/trayicon/CMakeLists.txt b/src/modules/trayicon/CMakeLists.txt index 256347bc32..e1e82ef25e 100644 --- a/src/modules/trayicon/CMakeLists.txt +++ b/src/modules/trayicon/CMakeLists.txt @@ -8,18 +8,15 @@ set(imageFiles kvi_dock_normal_16-0.png kvi_dock_normal_16-1.png kvi_dock_normal_16-2.png - kvi_dock_normal_22-0.png - kvi_dock_normal_22-1.png - kvi_dock_normal_22-2.png kvi_dock_normal_48-0.png kvi_dock_normal_48-1.png kvi_dock_normal_48-2.png - kvi_dock_mono_22-0.png - kvi_dock_mono_22-1.png - kvi_dock_mono_22-2.png - kvi_dock_mono_48-0.png - kvi_dock_mono_48-1.png - kvi_dock_mono_48-2.png + kvi_dock_dark_48-0.png + kvi_dock_dark_48-1.png + kvi_dock_dark_48-2.png + kvi_dock_light_48-0.png + kvi_dock_light_48-1.png + kvi_dock_light_48-2.png ) file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.png") diff --git a/src/modules/trayicon/kvi_dock_48.xcf b/src/modules/trayicon/kvi_dock_48.xcf index ce75177de8..c134dc47bd 100644 Binary files a/src/modules/trayicon/kvi_dock_48.xcf and b/src/modules/trayicon/kvi_dock_48.xcf differ diff --git a/src/modules/trayicon/kvi_dock_dark_48-0.png b/src/modules/trayicon/kvi_dock_dark_48-0.png new file mode 100644 index 0000000000..51984cb6c1 Binary files /dev/null and b/src/modules/trayicon/kvi_dock_dark_48-0.png differ diff --git a/src/modules/trayicon/kvi_dock_dark_48-1.png b/src/modules/trayicon/kvi_dock_dark_48-1.png new file mode 100644 index 0000000000..0c7a5cc99e Binary files /dev/null and b/src/modules/trayicon/kvi_dock_dark_48-1.png differ diff --git a/src/modules/trayicon/kvi_dock_dark_48-2.png b/src/modules/trayicon/kvi_dock_dark_48-2.png new file mode 100644 index 0000000000..99ddd62051 Binary files /dev/null and b/src/modules/trayicon/kvi_dock_dark_48-2.png differ diff --git a/src/modules/trayicon/kvi_dock_light_48-0.png b/src/modules/trayicon/kvi_dock_light_48-0.png new file mode 100644 index 0000000000..3e0817f6a8 Binary files /dev/null and b/src/modules/trayicon/kvi_dock_light_48-0.png differ diff --git a/src/modules/trayicon/kvi_dock_light_48-1.png b/src/modules/trayicon/kvi_dock_light_48-1.png new file mode 100644 index 0000000000..6d28cc609c Binary files /dev/null and b/src/modules/trayicon/kvi_dock_light_48-1.png differ diff --git a/src/modules/trayicon/kvi_dock_light_48-2.png b/src/modules/trayicon/kvi_dock_light_48-2.png new file mode 100644 index 0000000000..8f9c345651 Binary files /dev/null and b/src/modules/trayicon/kvi_dock_light_48-2.png differ diff --git a/src/modules/trayicon/kvi_dock_mono_22-0.png b/src/modules/trayicon/kvi_dock_mono_22-0.png deleted file mode 100644 index 1cd0f5efc7..0000000000 Binary files a/src/modules/trayicon/kvi_dock_mono_22-0.png and /dev/null differ diff --git a/src/modules/trayicon/kvi_dock_mono_22-1.png b/src/modules/trayicon/kvi_dock_mono_22-1.png deleted file mode 100644 index 098ce2c9f2..0000000000 Binary files a/src/modules/trayicon/kvi_dock_mono_22-1.png and /dev/null differ diff --git a/src/modules/trayicon/kvi_dock_mono_22-2.png b/src/modules/trayicon/kvi_dock_mono_22-2.png deleted file mode 100644 index bf0908435b..0000000000 Binary files a/src/modules/trayicon/kvi_dock_mono_22-2.png and /dev/null differ diff --git a/src/modules/trayicon/kvi_dock_mono_48-0.png b/src/modules/trayicon/kvi_dock_mono_48-0.png deleted file mode 100644 index b2b4d829b5..0000000000 Binary files a/src/modules/trayicon/kvi_dock_mono_48-0.png and /dev/null differ diff --git a/src/modules/trayicon/kvi_dock_mono_48-1.png b/src/modules/trayicon/kvi_dock_mono_48-1.png deleted file mode 100644 index 75cc65eda0..0000000000 Binary files a/src/modules/trayicon/kvi_dock_mono_48-1.png and /dev/null differ diff --git a/src/modules/trayicon/kvi_dock_mono_48-2.png b/src/modules/trayicon/kvi_dock_mono_48-2.png deleted file mode 100644 index 8b4b48944d..0000000000 Binary files a/src/modules/trayicon/kvi_dock_mono_48-2.png and /dev/null differ diff --git a/src/modules/trayicon/kvi_dock_normal_22-0.png b/src/modules/trayicon/kvi_dock_normal_22-0.png deleted file mode 100644 index 3771834937..0000000000 Binary files a/src/modules/trayicon/kvi_dock_normal_22-0.png and /dev/null differ diff --git a/src/modules/trayicon/kvi_dock_normal_22-1.png b/src/modules/trayicon/kvi_dock_normal_22-1.png deleted file mode 100644 index 46da85f50c..0000000000 Binary files a/src/modules/trayicon/kvi_dock_normal_22-1.png and /dev/null differ diff --git a/src/modules/trayicon/kvi_dock_normal_22-2.png b/src/modules/trayicon/kvi_dock_normal_22-2.png deleted file mode 100644 index 6008ca828e..0000000000 Binary files a/src/modules/trayicon/kvi_dock_normal_22-2.png and /dev/null differ diff --git a/src/modules/trayicon/libkvitrayicon.cpp b/src/modules/trayicon/libkvitrayicon.cpp index c71832ab32..ae3c4a4e65 100644 --- a/src/modules/trayicon/libkvitrayicon.cpp +++ b/src/modules/trayicon/libkvitrayicon.cpp @@ -26,14 +26,12 @@ #include "libkvitrayicon.h" -#include "kvi_settings.h" #include "KviApplication.h" #include "KviModule.h" #include "KviLocale.h" #include "KviMemory.h" #include "KviWindowListBase.h" #include "KviWindow.h" -#include "KviDynamicToolTip.h" #include "KviIconManager.h" #include "KviInternalCommand.h" #include "KviConsoleWindow.h" @@ -45,7 +43,6 @@ #include #include #include -#include #include #include @@ -68,7 +65,12 @@ static QPixmap * g_pDock2 = nullptr; static QPixmap * g_pDock3 = nullptr; KviTrayIconWidget::KviTrayIconWidget() - : QSystemTrayIcon(g_pMainWindow), m_Tip(g_pMainWindow, "dock_tooltip"), m_CurrentPixmap(ICON_SIZE, ICON_SIZE) +#ifdef COMPILE_KDE_SUPPORT + : KStatusNotifierItem(g_pMainWindow), +#else + : QSystemTrayIcon(g_pMainWindow), +#endif + m_CurrentPixmap(ICON_SIZE, ICON_SIZE) { g_pTrayIcon = this; m_pContextPopup = new QMenu(nullptr); @@ -86,7 +88,7 @@ KviTrayIconWidget::KviTrayIconWidget() g_pMainWindow->setTrayIcon(this); -#ifndef COMPILE_ON_MAC +#if !defined(COMPILE_ON_MAC) && !defined(COMPILE_KDE_SUPPORT) m_pTitleLabel = new QLabel(__tr2qs("
KVIrc Tray Options
"), m_pContextPopup); QPalette p; m_pTitleLabel->setStyleSheet("background-color: " + p.color(QPalette::Normal, QPalette::Mid).name()); @@ -117,21 +119,38 @@ KviTrayIconWidget::KviTrayIconWidget() connect(m_pContextPopup, SIGNAL(aboutToShow()), this, SLOT(fillContextPopup())); +#ifdef COMPILE_KDE_SUPPORT + setCategory(KStatusNotifierItem::ApplicationStatus); + setToolTipTitle("KVIrc"); + setIconByPixmap(*g_pDock1); + setStandardActionsEnabled(false); +#else setIcon(*g_pDock1); - connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(activatedSlot(QSystemTrayIcon::ActivationReason))); +#endif } KviTrayIconWidget::~KviTrayIconWidget() { g_pTrayIcon = nullptr; g_pMainWindow->setTrayIcon(nullptr); + +#ifndef COMPILE_KDE_SUPPORT + // KStatusNotifierItem takes ownership of the menu, avoid deleting it if(m_bHidden) m_pContextPopup->deleteLater(); else delete m_pContextPopup; +#endif } +#ifdef COMPILE_KDE_SUPPORT +void KviTrayIconWidget::show() +{ + setStatus(KStatusNotifierItem::Active); +} +#endif + void KviTrayIconWidget::executeInternalCommand(bool) { int iCmd; @@ -186,52 +205,48 @@ static const char * idlemsgs[] = { static const std::size_t NIDLEMSGS = sizeof(idlemsgs) / sizeof(*idlemsgs); -bool KviTrayIconWidget::event(QEvent * e) +const QString KviTrayIconWidget::getToolTipText(bool bHtml) { - if(e->type() == QEvent::ToolTip) - { - QPoint pos = g_pMainWindow->mapFromGlobal(QCursor::pos()); - QString tmp; + QString szTmp; - KviWindowListBase * t = g_pMainWindow->windowListWidget(); + KviWindowListBase * t = g_pMainWindow->windowListWidget(); - QString line; - bool first = true; + QString line; + bool first = true; - for(KviWindowListItem * b = t->firstItem(); b; b = t->nextItem()) - { + for(KviWindowListItem * b = t->firstItem(); b; b = t->nextItem()) + { - if(b->kviWindow()->view()) + if(b->kviWindow()->view()) + { + if(b->kviWindow()->view()->haveUnreadedMessages()) { - if(b->kviWindow()->view()->haveUnreadedMessages()) + line = b->kviWindow()->lastMessageText(); + if(!line.isEmpty()) { - line = b->kviWindow()->lastMessageText(); - if(!line.isEmpty()) - { - if(!first) - tmp += "

\n"; - else - first = false; + if(!first) + szTmp += bHtml ? "

\n" : "\n\n"; + else + first = false; + if(bHtml) { line.replace(QChar('&'), "&"); line.replace(QChar('<'), "<"); line.replace(QChar('>'), ">"); - tmp += ""; - tmp += b->kviWindow()->plainTextCaption(); - tmp += "
"; - tmp += line; + szTmp += ""; } + szTmp += b->kviWindow()->plainTextCaption(); + szTmp += bHtml ? "
" : "\n"; + szTmp += line; } } } + } - if(tmp.isEmpty()) - tmp = __tr2qs_no_xgettext(idlemsgs[std::rand() % NIDLEMSGS]); + if(szTmp.isEmpty()) + szTmp = __tr2qs_no_xgettext(idlemsgs[std::rand() % NIDLEMSGS]); - m_Tip.tip(QRect(pos, QSize(0, 0)), tmp); - return true; - } - return false; + return szTmp; } void KviTrayIconWidget::doAway(bool) @@ -458,8 +473,18 @@ void KviTrayIconWidget::refresh() ICON_SIZE / 2, ICON_SIZE / 2, ICON_SIZE / 2, ICON_SIZE / 2); } updateIcon(); + +#ifdef COMPILE_KDE_SUPPORT + setToolTipSubTitle(getToolTipText(true)); +#else + setToolTip(getToolTipText(false)); +#endif } +#ifndef COMPILE_KDE_SUPPORT +// Under Kde do nothing, KWin will restore/hide our window +// See ctor doc: KStatusNotifierItem::KStatusNotifierItem ( QObject * parent = nullptr ) + void KviTrayIconWidget::activatedSlot(QSystemTrayIcon::ActivationReason reason) { switch(reason) @@ -483,6 +508,7 @@ void KviTrayIconWidget::activatedSlot(QSystemTrayIcon::ActivationReason reason) break; } } +#endif void KviTrayIconWidget::grabActivityInfo() { @@ -605,7 +631,11 @@ void KviTrayIconWidget::grabActivityInfo() void KviTrayIconWidget::updateIcon() { +#ifdef COMPILE_KDE_SUPPORT + setIconByPixmap(QIcon(m_CurrentPixmap)); +#else setIcon(QIcon(m_CurrentPixmap)); +#endif } /* @@ -723,26 +753,31 @@ static bool trayicon_kvs_fnc_isvisible(KviKvsModuleFunctionCall * c) return true; } -#if defined(COMPILE_KDE_SUPPORT) || defined(COMPILE_ON_MAC) -#define ICON_INFIX "mono" -#else -#define ICON_INFIX "normal" -#endif - /////////////////////////////////////////////////////////////////////////////// // init routine /////////////////////////////////////////////////////////////////////////////// static bool trayicon_module_init(KviModule * m) { + QString szIconTheme; +#if defined(COMPILE_KDE_SUPPORT) || defined(COMPILE_ON_MAC) + if (g_pApp->palette().window().color().value() > g_pApp->palette().windowText().color().value()) + { + szIconTheme = "light"; + } else { + szIconTheme = "dark"; + } +#else + szIconTheme = "normal"; +#endif QString buffer; - g_pApp->findImage(buffer, QString("kvi_dock_" ICON_INFIX "_%1-0.png").arg(ICON_SIZE)); + g_pApp->findImage(buffer, QString("kvi_dock_%1_%2-0.png").arg(szIconTheme).arg(ICON_SIZE)); g_pDock1 = new QPixmap(buffer); - g_pApp->findImage(buffer, QString("kvi_dock_" ICON_INFIX "_%1-1.png").arg(ICON_SIZE)); + g_pApp->findImage(buffer, QString("kvi_dock_%1_%2-1.png").arg(szIconTheme).arg(ICON_SIZE)); g_pDock2 = new QPixmap(buffer); - g_pApp->findImage(buffer, QString("kvi_dock_" ICON_INFIX "_%1-2.png").arg(ICON_SIZE)); + g_pApp->findImage(buffer, QString("kvi_dock_%1_%2-2.png").arg(szIconTheme).arg(ICON_SIZE)); g_pDock3 = new QPixmap(buffer); KVSM_REGISTER_SIMPLE_COMMAND(m, "hide", trayicon_kvs_cmd_hide); diff --git a/src/modules/trayicon/libkvitrayicon.h b/src/modules/trayicon/libkvitrayicon.h index 53b5dcdf8d..d90ec44bac 100644 --- a/src/modules/trayicon/libkvitrayicon.h +++ b/src/modules/trayicon/libkvitrayicon.h @@ -27,18 +27,29 @@ //============================================================================= #include "kvi_settings.h" -#include "KviDynamicToolTip.h" #include "KviMainWindow.h" #include "KviTrayIcon.h" -#include +#include #include #include +#include #include +#ifdef COMPILE_KDE_SUPPORT +#include +#else +#include +#endif + class QPixmap; -class KviTrayIconWidget final : public QSystemTrayIcon, public KviTrayIcon +class KviTrayIconWidget final +#ifdef COMPILE_KDE_SUPPORT +: public KStatusNotifierItem, public KviTrayIcon +#else +: public QSystemTrayIcon, public KviTrayIcon +#endif { Q_OBJECT public: @@ -46,7 +57,6 @@ class KviTrayIconWidget final : public QSystemTrayIcon, public KviTrayIcon ~KviTrayIconWidget() override; private: - KviDynamicToolTip m_Tip; QMenu * m_pContextPopup; QMenu m_awayPopup; #ifndef COMPILE_ON_MAC @@ -70,16 +80,21 @@ class KviTrayIconWidget final : public QSystemTrayIcon, public KviTrayIcon public: void refresh() override; void updateIcon(); +#ifdef COMPILE_KDE_SUPPORT + void show(); +#endif private: void grabActivityInfo(); - bool event(QEvent * e) override; + const QString getToolTipText(bool bHtml); private slots: void fillContextPopup(); void toggleParentFrame(); void doAway(bool); void flashingTimerShot(); +#ifndef COMPILE_KDE_SUPPORT void activatedSlot(QSystemTrayIcon::ActivationReason reason); +#endif void executeInternalCommand(bool); void disableTrayIcon(); };