diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,8 +42,7 @@ settings.cpp settings_versionsync.cpp softwareimporters.cpp - systemtray.cpp - tag.cpp + tag.cpp tagsedit.cpp transparentwidget.cpp tools.cpp diff --git a/src/basketscene.cpp b/src/basketscene.cpp --- a/src/basketscene.cpp +++ b/src/basketscene.cpp @@ -1416,10 +1416,6 @@ if (zone == Note::GroupExpander) { clicked->toggleFolded(); - if (/*m_animationTimeLine == 0 && */ Settings::playAnimations()) { - qWarning() << "Folding animation to be done"; - } - relayoutNotes(); m_noActionOnMouseRelease = true; @@ -1873,17 +1869,14 @@ m_editor->lineEdit()->paste(); } else { if (!isLoaded()) { - Global::bnpView->showPassiveLoading(this); load(); } closeEditor(); unselectAll(); Note *note = NoteFactory::dropNote(event->mimeData(), this, true, event->dropAction(), dynamic_cast(event->source())); if (note) { insertCreatedNote(note); // unselectAllBut(note); - if (Settings::usePassivePopup()) - Global::bnpView->showPassiveDropped(i18n("Dropped to basket %1", m_basketName)); } } save(); @@ -1898,17 +1891,14 @@ m_editor->lineEdit()->paste(); } else { if (!isLoaded()) { - Global::bnpView->showPassiveLoading(this); load(); } closeEditor(); unselectAll(); Note *note = NoteFactory::dropNote(mimeData, this, true, dropAction, dynamic_cast(source)); if (note) { insertCreatedNote(note); // unselectAllBut(note); - if (Settings::usePassivePopup()) - Global::bnpView->showPassiveDropped(i18n("Dropped to basket %1", m_basketName)); } } save(); @@ -1976,7 +1966,6 @@ m_editor->lineEdit()->paste(); } else { if (!isLoaded()) { - Global::bnpView->showPassiveLoading(this); load(); } closeEditor(); diff --git a/src/bnpview.h b/src/bnpview.h --- a/src/bnpview.h +++ b/src/bnpview.h @@ -47,6 +47,7 @@ class State; class Note; class KMainWindow; +class KMessageWidget; class BASKET_EXPORT BNPView : public QSplitter { @@ -144,12 +145,6 @@ void addNoteCrossReference(); void addNoteColor(); /** Passive Popups for Global Actions */ - void showPassiveDropped(const QString &title); - void showPassiveDroppedDelayed(); // Do showPassiveDropped(), but delayed - void showPassiveContent(bool forceShow = false); - void showPassiveContentForced(); - void showPassiveImpossible(const QString &message); - void showPassiveLoading(BasketScene *basket); // For GUI : void setFiltering(bool filtering); /** Edit */ @@ -183,11 +178,8 @@ void delayedOpenArchive(); void delayedOpenBasket(); void lockBasket(); - void hideOnEscape(); void changedSelectedNotes(); - void timeoutTryHide(); - void timeoutHide(); void loadCrossReference(QString link); QString folderFromBasketNameLink(QStringList pages, QTreeWidgetItem *parent = nullptr); @@ -223,7 +215,6 @@ QAction *actNewBasket; QAction *actNewSubBasket; QAction *actNewSiblingBasket; - QAction *m_actHideWindow; QAction *m_actExportToHtml; QAction *m_actPropBasket; QAction *m_actSortChildrenAsc; @@ -338,10 +329,7 @@ void basketChanged(); void setWindowCaption(const QString &s); void showPart(); - -protected: - void enterEvent(QEvent *) override; - void leaveEvent(QEvent *) override; + void showErrorMessage(const QString &message); protected: void hideMainWindow(); @@ -362,8 +350,6 @@ KActionCollection *m_actionCollection; KXMLGUIClient *m_guiClient; BasketStatusBar *m_statusbar; - QTimer *m_tryHideTimer; - QTimer *m_hideTimer; QUndoStack *m_history; KMainWindow *m_HiddenMainWindow; diff --git a/src/bnpview.cpp b/src/bnpview.cpp --- a/src/bnpview.cpp +++ b/src/bnpview.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #ifndef BASKET_USE_DRKONQI #include @@ -99,8 +100,6 @@ , m_actionCollection(actionCollection) , m_guiClient(aGUIClient) , m_statusbar(bar) - , m_tryHideTimer(nullptr) - , m_hideTimer(nullptr) { // new BNPViewAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); @@ -135,8 +134,6 @@ Global::bnpView = nullptr; - delete Global::systemTray; - Global::systemTray = nullptr; delete m_statusbar; delete m_history; m_history = nullptr; @@ -146,30 +143,10 @@ void BNPView::lateInit() { - /* - InlineEditors* instance = InlineEditors::instance(); - - if(instance) - { - KToolBar* toolbar = instance->richTextToolBar(); - - if(toolbar) - toolbar->hide(); - } - */ - // If the main window is hidden when session is saved, Container::queryClose() // isn't called and the last value would be kept - Settings::setStartDocked(true); Settings::saveConfig(); - /* System tray icon */ - Global::systemTray = new SystemTray(Global::activeMainWindow()); - Global::systemTray->setIconByName(":/images/22-apps-basket"); - connect(Global::systemTray, SIGNAL(showPart()), this, SIGNAL(showPart())); - /*if (Settings::useSystray()) - Global::systemTray->show();*/ - // Load baskets DEBUG_WIN << "Baskets are loaded from " + Global::basketsFolder(); @@ -199,22 +176,6 @@ Settings::setWelcomeBasketsAdded(true); Settings::saveConfig(); } - - m_tryHideTimer = new QTimer(this); - m_hideTimer = new QTimer(this); - connect(m_tryHideTimer, SIGNAL(timeout()), this, SLOT(timeoutTryHide())); - connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(timeoutHide())); - - // Preload every baskets for instant filtering: - /*StopWatch::start(100); - QListViewItemIterator it(m_tree); - while (it.current()) { - BasketListViewItem *item = ((BasketListViewItem*)it.current()); - item->basket()->load(); - qApp->processEvents(); - ++it; - } - StopWatch::check(100);*/ } void BNPView::addWelcomeBaskets() @@ -268,28 +229,13 @@ int modifier = Qt::CTRL + Qt::ALT + Qt::SHIFT; - if (basketMainWindow) { - a = ac->addAction("global_show_hide_main_window", Global::systemTray, SLOT(toggleActive())); - a->setText(i18n("Show/hide main window")); - a->setStatusTip( - i18n("Allows you to show main Window if it is hidden, and to hide " - "it if it is shown.")); - KGlobalAccel::self()->setGlobalShortcut(a, (QKeySequence(modifier + Qt::Key_W))); - } - a = ac->addAction("global_paste", Global::bnpView, SLOT(globalPasteInCurrentBasket())); a->setText(i18n("Paste clipboard contents in current basket")); a->setStatusTip( i18n("Allows you to paste clipboard contents in the current basket " "without having to open the main window.")); KGlobalAccel::self()->setGlobalShortcut(a, QKeySequence(modifier + Qt::Key_V)); - a = ac->addAction("global_show_current_basket", Global::bnpView, SLOT(showPassiveContentForced())); - a->setText(i18n("Show current basket name")); - a->setStatusTip( - i18n("Allows you to know basket is current without opening " - "the main window.")); - a = ac->addAction("global_paste_selection", Global::bnpView, SLOT(pasteSelInCurrentBasket())); a->setText(i18n("Paste selection in current basket")); a->setStatusTip( @@ -439,13 +385,6 @@ a->setShortcut(0); m_actOpenArchive = a; - a = ac->addAction("window_hide", this, SLOT(hideOnEscape())); - a->setText(i18n("&Hide Window")); - m_actionCollection->setDefaultShortcut(a, KStandardShortcut::Close); - m_actHideWindow = a; - - m_actHideWindow->setEnabled(Settings::useSystray()); // Init here ! - a = ac->addAction("basket_export_html", this, SLOT(exportToHTML())); a->setText(i18n("&HTML Web Page...")); a->setIcon(QIcon::fromTheme("text-html")); @@ -969,6 +908,7 @@ BasketScene *basket = decoBasket->basket(); m_stack->addWidget(decoBasket); + connect(this, &BNPView::showErrorMessage, decoBasket, &DecoratedBasket::showErrorMessage); connect(basket, SIGNAL(countsChanged(BasketScene *)), this, SLOT(countsChanged(BasketScene *))); // Important: Create listViewItem and connect signal BEFORE loadProperties(), so we get the listViewItem updated without extra work: connect(basket, SIGNAL(propertiesChanged(BasketScene *)), this, SLOT(updateBasketListViewItem(BasketScene *))); @@ -1257,8 +1197,6 @@ setWindowTitle(item->basket()->basketName()); countsChanged(basket); updateStatusBarHint(); - if (Global::systemTray) - Global::systemTray->updateDisplay(); m_tree->scrollToItem(m_tree->currentItem()); item->basket()->setFocus(); } @@ -1372,8 +1310,6 @@ if (basket == currentBasket()) { setWindowTitle(basket->basketName()); - if (Global::systemTray) - Global::systemTray->updateDisplay(); } // Don't save if we are loading! @@ -1740,14 +1676,9 @@ void BNPView::colorPicked(const QColor &color) { if (!currentBasket()->isLoaded()) { - showPassiveLoading(currentBasket()); currentBasket()->load(); } currentBasket()->insertColor(color); - - if (Settings::usePassivePopup()) { - showPassiveDropped(i18n("Picked color to basket %1")); - } } void BNPView::slotConvertTexts() @@ -1788,7 +1719,6 @@ QMenu *menu = nullptr; if (m_guiClient) { - qDebug() << "m_guiClient"; KXMLGUIFactory *factory = m_guiClient->factory(); if (factory) { menu = (QMenu *)factory->container(menuName, m_guiClient); @@ -1833,16 +1763,15 @@ void BNPView::insertEmpty(int type) { if (currentBasket()->isLocked()) { - showPassiveImpossible(i18n("Cannot add note.")); return; } currentBasket()->insertEmptyNote(type); } void BNPView::insertWizard(int type) { if (currentBasket()->isLocked()) { - showPassiveImpossible(i18n("Cannot add note.")); + Q_EMIT showErrorMessage(i18n("Cannot add note.")); return; } currentBasket()->insertWizard(type); @@ -1903,16 +1832,13 @@ } if (!currentBasket()->isLoaded()) { - showPassiveLoading(currentBasket()); currentBasket()->load(); } currentBasket()->insertImage(pixmap); if (m_colorPickWasShown) showMainWindow(); - if (Settings::usePassivePopup()) - showPassiveDropped(i18n("Grabbed screen zone to basket %1")); } BasketScene *BNPView::basketForFolderName(const QString &folderName) @@ -2205,146 +2131,11 @@ void BNPView::pasteInCurrentBasket() { currentBasket()->pasteNote(); - - if (Settings::usePassivePopup()) - showPassiveDropped(i18n("Clipboard content pasted to basket %1")); } void BNPView::pasteSelInCurrentBasket() { currentBasket()->pasteNote(QClipboard::Selection); - - if (Settings::usePassivePopup()) - showPassiveDropped(i18n("Selection pasted to basket %1")); -} - -void BNPView::showPassiveDropped(const QString &title) -{ - if (!currentBasket()->isLocked()) { - // TODO: Keep basket, so that we show the message only if something was added to a NOT visible basket - m_passiveDroppedTitle = title; - m_passiveDroppedSelection = currentBasket()->selectedNotes(); - QTimer::singleShot(c_delayTooltipTime, this, SLOT(showPassiveDroppedDelayed())); - // DELAY IT BELOW: - } else - showPassiveImpossible(i18n("No note was added.")); -} - -void BNPView::showPassiveDroppedDelayed() -{ - if (isMainWindowActive() || m_passiveDroppedSelection == nullptr) - return; - - QString title = m_passiveDroppedTitle; - - QImage contentsImage = NoteDrag::feedbackPixmap(m_passiveDroppedSelection).toImage(); - QResource::registerResource(contentsImage.bits(), QStringLiteral(":/images/passivepopup_image")); - - if (Settings::useSystray()) { - /*Uncomment after switching to QSystemTrayIcon or port to KStatusNotifierItem - See also other occurrences of Global::systemTray below*/ - /*KPassivePopup::message(KPassivePopup::Boxed, - title.arg(Tools::textToHTMLWithoutP(currentBasket()->basketName())), - (contentsImage.isNull() ? QString() : QStringLiteral("")), - KIconLoader::global()->loadIcon( - currentBasket()->icon(), KIconLoader::NoGroup, 16, - KIconLoader::DefaultState, QStringList(), 0L, true - ), - Global::systemTray);*/ - } else { - KPassivePopup::message(KPassivePopup::Boxed, - title.arg(Tools::textToHTMLWithoutP(currentBasket()->basketName())), - (contentsImage.isNull() ? QString() : QStringLiteral("")), - KIconLoader::global()->loadIcon(currentBasket()->icon(), KIconLoader::NoGroup, 16, KIconLoader::DefaultState, QStringList(), nullptr, true), - (QWidget *)this); - } -} - -void BNPView::showPassiveImpossible(const QString &message) -{ - if (Settings::useSystray()) { - /*KPassivePopup::message(KPassivePopup::Boxed, - QString("%1") - .arg(i18n("Basket %1 is locked")) - .arg(Tools::textToHTMLWithoutP(currentBasket()->basketName())), - message, - KIconLoader::global()->loadIcon( - currentBasket()->icon(), KIconLoader::NoGroup, 16, - KIconLoader::DefaultState, QStringList(), 0L, true - ), - Global::systemTray);*/ - } else { - /*KPassivePopup::message(KPassivePopup::Boxed, - QString("%1") - .arg(i18n("Basket %1 is locked")) - .arg(Tools::textToHTMLWithoutP(currentBasket()->basketName())), - message, - KIconLoader::global()->loadIcon( - currentBasket()->icon(), KIconLoader::NoGroup, 16, - KIconLoader::DefaultState, QStringList(), 0L, true - ), - (QWidget*)this);*/ - } -} - -void BNPView::showPassiveContentForced() -{ - showPassiveContent(/*forceShow=*/true); -} - -void BNPView::showPassiveContent(bool forceShow /* = false*/) -{ - if (!forceShow && isMainWindowActive()) - return; - - // FIXME: Duplicate code (2 times) - QString message; - - if (Settings::useSystray()) { - /*KPassivePopup::message(KPassivePopup::Boxed, - "" + Tools::makeStandardCaption( - currentBasket()->isLocked() ? QString("%1 %2") - .arg(Tools::textToHTMLWithoutP(currentBasket()->basketName()), i18n("(Locked)")) - : Tools::textToHTMLWithoutP(currentBasket()->basketName()) - ), - message, - KIconLoader::global()->loadIcon( - currentBasket()->icon(), KIconLoader::NoGroup, 16, - KIconLoader::DefaultState, QStringList(), 0L, true - ), - Global::systemTray);*/ - } else { - KPassivePopup::message(KPassivePopup::Boxed, - "" + - Tools::makeStandardCaption(currentBasket()->isLocked() ? QString("%1 %2").arg(Tools::textToHTMLWithoutP(currentBasket()->basketName()), i18n("(Locked)")) - : Tools::textToHTMLWithoutP(currentBasket()->basketName())), - message, - KIconLoader::global()->loadIcon(currentBasket()->icon(), KIconLoader::NoGroup, 16, KIconLoader::DefaultState, QStringList(), nullptr, true), - (QWidget *)this); - } -} - -void BNPView::showPassiveLoading(BasketScene *basket) -{ - if (isMainWindowActive()) - return; - - if (Settings::useSystray()) { - /*KPassivePopup::message(KPassivePopup::Boxed, - Tools::textToHTMLWithoutP(basket->basketName()), - i18n("Loading..."), - KIconLoader::global()->loadIcon( - basket->icon(), KIconLoader::NoGroup, 16, KIconLoader::DefaultState, - QStringList(), 0L, true - ), - Global::systemTray);*/ - } else { - KPassivePopup::message(KPassivePopup::Boxed, - Tools::textToHTMLWithoutP(basket->basketName()), - i18n("Loading..."), - KIconLoader::global()->loadIcon(basket->icon(), KIconLoader::NoGroup, 16, KIconLoader::DefaultState, QStringList(), nullptr, true), - (QWidget *)this); - } } void BNPView::addNoteText() @@ -2437,13 +2228,6 @@ if (active == isMainWindowActive()) return; // qApp->updateUserTimestamp(); // If "activate on mouse hovering systray", or "on drag through systray" - Global::systemTray->activate(); -} - -void BNPView::hideOnEscape() -{ - if (Settings::useSystray()) - setActive(false); } bool BNPView::isMainWindowActive() @@ -2541,67 +2325,6 @@ basketForFolderName(folderName)->reload(); } -/** Scenario of "Hide main window to system tray icon when mouse move out of the window" : - * - At enterEvent() we stop m_tryHideTimer - * - After that and before next, we are SURE cursor is hovering window - * - At leaveEvent() we restart m_tryHideTimer - * - Every 'x' ms, timeoutTryHide() seek if cursor hover a widget of the application or not - * - If yes, we musn't hide the window - * - But if not, we start m_hideTimer to hide main window after a configured elapsed time - * - timeoutTryHide() continue to be called and if cursor move again to one widget of the app, m_hideTimer is stopped - * - If after the configured time cursor hasn't go back to a widget of the application, timeoutHide() is called - * - It then hide the main window to systray icon - * - When the user will show it, enterEvent() will be called the first time he enter mouse to it - * - ... - */ - -/** Why do as this ? Problems with the use of only enterEvent() and leaveEvent() : - * - Resize window or hover titlebar isn't possible : leave/enterEvent - * are - * > Use the grip or Alt+rightDND to resize window - * > Use Alt+DND to move window - * - Each menu trigger the leavEvent - */ - -void BNPView::enterEvent(QEvent *) -{ - if (m_tryHideTimer) - m_tryHideTimer->stop(); - if (m_hideTimer) - m_hideTimer->stop(); -} - -void BNPView::leaveEvent(QEvent *) -{ - if (Settings::useSystray() && Settings::hideOnMouseOut() && m_tryHideTimer) - m_tryHideTimer->start(50); -} - -void BNPView::timeoutTryHide() -{ - // If a menu is displayed, do nothing for the moment - if (qApp->activePopupWidget() != nullptr) - return; - - if (qApp->widgetAt(QCursor::pos()) != nullptr) - m_hideTimer->stop(); - else if (!m_hideTimer->isActive()) { // Start only one time - m_hideTimer->setSingleShot(true); - m_hideTimer->start(Settings::timeToHideOnMouseOut() * 100); - } - - // If a subdialog is opened, we mustn't hide the main window: - if (qApp->activeWindow() != nullptr && qApp->activeWindow() != Global::activeMainWindow()) - m_hideTimer->stop(); -} - -void BNPView::timeoutHide() -{ - // We check that because the setting can have been set to off - if (Settings::useSystray() && Settings::hideOnMouseOut()) - setActive(false); - m_tryHideTimer->stop(); -} void BNPView::changedSelectedNotes() { diff --git a/src/decoratedbasket.h b/src/decoratedbasket.h --- a/src/decoratedbasket.h +++ b/src/decoratedbasket.h @@ -15,15 +15,17 @@ #include "filter.h" +class KMessageWidget; + /** This class handle Basket and add a FilterWidget on top of it. * @author Sébastien Laoût */ class DecoratedBasket : public QWidget { Q_OBJECT public: DecoratedBasket(QWidget *parent, const QString &folderName, Qt::WindowFlags fl = nullptr); - ~DecoratedBasket() override; + ~DecoratedBasket() override = default; void setFilterBarPosition(bool onTop); void resetFilter(); void setFilterBarVisible(bool show, bool switchFocus = true); @@ -46,9 +48,14 @@ void resizeEvent(QResizeEvent *event) override; +public Q_SLOTS: + void showErrorMessage(const QString &errorMessage); + private: QVBoxLayout *m_layout; FilterBar *m_filter; + + KMessageWidget *m_messageWidget = nullptr; BasketScene *m_basket; }; #endif // DECORATEDBASKET_H diff --git a/src/decoratedbasket.cpp b/src/decoratedbasket.cpp --- a/src/decoratedbasket.cpp +++ b/src/decoratedbasket.cpp @@ -1,12 +1,14 @@ /** * SPDX-FileCopyrightText: (C) 2003 by Sébastien Laoût + * * SPDX-License-Identifier: GPL-2.0-or-later */ #include "decoratedbasket.h" #include #include +#include #include "basketscene.h" #include "filter.h" @@ -19,23 +21,25 @@ { m_layout = new QVBoxLayout(this); m_filter = new FilterBar(this); + m_filter->hide(); + m_basket = new BasketScene(this, folderName); m_basket->graphicsView()->setParent(this); m_layout->addWidget(m_basket->graphicsView()); - setFilterBarPosition(Settings::filterOnTop()); - - m_filter->hide(); m_basket->setFocus(); // To avoid the filter bar have focus on load - connect(m_filter, SIGNAL(newFilter(const FilterData &)), m_basket, SLOT(newFilter(const FilterData &))); + m_messageWidget = new KMessageWidget(this); + m_messageWidget->setCloseButtonVisible(true); + m_messageWidget->setMessageType(KMessageWidget::MessageType::Error); + m_messageWidget->hide(); + m_layout->addWidget(m_messageWidget); - connect(m_basket, SIGNAL(postMessage(const QString &)), Global::bnpView, SLOT(postStatusbarMessage(const QString &))); - connect(m_basket, SIGNAL(setStatusBarText(const QString &)), Global::bnpView, SLOT(setStatusBarHint(const QString &))); - connect(m_basket, SIGNAL(resetStatusBarText()), Global::bnpView, SLOT(updateStatusBarHint())); -} + setFilterBarPosition(Settings::filterOnTop()); -DecoratedBasket::~DecoratedBasket() -{ + connect(m_filter, SIGNAL(newFilter(const FilterData &)), m_basket, SLOT(newFilter(const FilterData &))); + connect(m_basket, &BasketScene::postMessage, Global::bnpView, &BNPView::postStatusbarMessage); + connect(m_basket, &BasketScene::setStatusBarText, Global::bnpView, &BNPView::setStatusBarHint); + connect(m_basket, &BasketScene::resetStatusBarText, Global::bnpView, &BNPView::updateStatusBarHint); } void DecoratedBasket::setFilterBarPosition(bool onTop) @@ -45,12 +49,14 @@ m_layout->insertWidget(0, m_filter); setTabOrder(this /*(QWidget*)parent()*/, m_filter); setTabOrder(m_filter, m_basket->graphicsView()); - setTabOrder(m_basket->graphicsView(), (QWidget *)parent()); + setTabOrder(m_basket->graphicsView(), m_messageWidget); + setTabOrder(m_messageWidget, (QWidget *)parent()); } else { m_layout->addWidget(m_filter); setTabOrder(this /*(QWidget*)parent()*/, m_basket->graphicsView()); setTabOrder(m_basket->graphicsView(), m_filter); - setTabOrder(m_filter, (QWidget *)parent()); + setTabOrder(m_filter, m_messageWidget); + setTabOrder(m_messageWidget, (QWidget *)parent()); } } @@ -80,3 +86,9 @@ QWidget::resizeEvent(event); m_basket->relayoutNotes(); } + +void DecoratedBasket::showErrorMessage(const QString &errorMessage) +{ + m_messageWidget->setText(errorMessage); + m_messageWidget->show(); +} diff --git a/src/global.h b/src/global.h --- a/src/global.h +++ b/src/global.h @@ -38,7 +38,6 @@ // Global Variables: static DebugWindow *debugWindow; static BackgroundManager *backgroundManager; - static SystemTray *systemTray; static BNPView *bnpView; static KSharedConfig::Ptr basketConfig; static QCommandLineParser *commandLineOpts; diff --git a/src/global.cpp b/src/global.cpp --- a/src/global.cpp +++ b/src/global.cpp @@ -23,7 +23,6 @@ QString Global::s_customSavesFolder; DebugWindow *Global::debugWindow = nullptr; BackgroundManager *Global::backgroundManager = nullptr; -SystemTray *Global::systemTray = nullptr; BNPView *Global::bnpView = nullptr; KSharedConfig::Ptr Global::basketConfig; QCommandLineParser *Global::commandLineOpts = nullptr; diff --git a/src/main.cpp b/src/main.cpp --- a/src/main.cpp +++ b/src/main.cpp @@ -49,21 +49,7 @@ Global::bnpView->handleCommandLine(); app.setActiveWindow(win); - if (Settings::useSystray()) { - // The user wanted to not show the window (but it is already hidden by default, so we do nothing): - if (opts->isSet(QCommandLineOption("start-hidden"))) - ; - // When the application is restored by the desktop session, restore its state: - else if (app.isSessionRestored()) { - if (!Settings::startDocked()) - win->show(); - } - // Else, the application has been launched explicitly by the user (QMenu, keyboard shortcut...), so he need it, we show it: - else - win->show(); - } else - // No system tray icon: always show: - win->show(); + win->show(); // Self-test of the presence of basketui.rc (the only required file after basket executable) if (Global::bnpView->popupMenu("basket") == nullptr) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -235,26 +235,16 @@ return true;*/ if (qApp->isSavingSession()) { - Settings::setStartDocked(false); // If queryClose() is called it's because the window is shown Settings::saveConfig(); return true; } - if (Settings::useSystray() && !m_quit - /*&& Global::systemTray->parentWidgetTrayClose()*/) { - hide(); - return false; - } else - return askForQuit(); + return askForQuit(); } bool MainWindow::askForQuit() { QString message = i18n("

Do you really want to quit %1?

", QGuiApplication::applicationDisplayName()); - if (Settings::useSystray()) - message += i18n( - "

Notice that you do not have to quit the application before ending your desktop session. " - "If you end your session while the application is still running, the application will be reloaded the next time you log in.

"); int really = KMessageBox::warningContinueCancel(this, message, i18n("Quit Confirm"), KStandardGuiItem::quit(), KStandardGuiItem::cancel(), "confirmQuitAsking"); diff --git a/src/settings.h b/src/settings.h --- a/src/settings.h +++ b/src/settings.h @@ -15,7 +15,6 @@ #include "basket_export.h" #include "bnpview.h" -#include "systemtray.h" class KComboBox; @@ -47,16 +46,6 @@ // General KComboBox *m_treeOnLeft; KComboBox *m_filterOnTop; - QCheckBox *m_usePassivePopup; - - // System Tray Icon - QCheckBox *m_useSystray; - QWidget *m_systray; - QCheckBox *m_showIconInSystray; - QCheckBox *m_hideOnMouseOut; - QSpinBox *m_timeToHideOnMouseOut; - QCheckBox *m_showOnMouseIn; - QSpinBox *m_timeToShowOnMouseIn; }; class BASKET_EXPORT BasketsPage : public KCModule @@ -168,15 +157,13 @@ /** Main window */ static bool s_treeOnLeft; static bool s_filterOnTop; - static bool s_playAnimations; static bool s_showNotesToolTip; static bool s_confirmNoteDeletion; static bool s_bigNotes; static bool s_autoBullet; static bool s_pasteAsPlainText; static bool s_exportTextTags; static bool s_useGnuPGAgent; - static bool s_usePassivePopup; static int s_middleAction; // O:Nothing ; 1:Paste ; 2:Text ; 3:Html ; 4:Image ; 5:Link ; 6:Launcher ; 7:Color static bool s_groupOnInsertionLine; static bool s_spellCheckTextNotes; @@ -196,14 +183,6 @@ static int s_viewHtmlFileContent; static int s_viewImageFileContent; static int s_viewSoundFileContent; - /** System tray Icon */ - static bool s_useSystray; - static bool s_showIconInSystray; - static bool s_startDocked; - static bool s_hideOnMouseOut; - static int s_timeToHideOnMouseOut; - static bool s_showOnMouseIn; - static int s_timeToShowOnMouseIn; /** Programs */ static bool s_htmlUseProg; static bool s_imageUseProg; @@ -230,10 +209,6 @@ { return s_filterOnTop; } - static inline bool playAnimations() - { - return s_playAnimations; - } static inline bool showNotesToolTip() { return s_showNotesToolTip; @@ -274,18 +249,6 @@ { return s_reLockTimeoutMinutes; } - static inline bool useSystray() - { - return s_useSystray; - } - static inline bool showIconInSystray() - { - return s_showIconInSystray; - } - static inline bool startDocked() - { - return s_startDocked; - } static inline int middleAction() { return s_middleAction; @@ -298,34 +261,14 @@ { return s_spellCheckTextNotes; } - static inline bool hideOnMouseOut() - { - return s_hideOnMouseOut; - } - static inline int timeToHideOnMouseOut() - { - return s_timeToHideOnMouseOut; - } - static inline bool showOnMouseIn() - { - return s_showOnMouseIn; - } - static inline int timeToShowOnMouseIn() - { - return s_timeToShowOnMouseIn; - } static inline int basketTreeWidth() { return s_basketTreeWidth; } static inline int dropTimeToShow() { return 7; } // TODO: 700 ; TODO: There is certainly a KGlobalConfig ??? - static inline bool usePassivePopup() - { - return s_usePassivePopup; - } static inline bool welcomeBasketsAdded() { return s_welcomeBasketsAdded; @@ -442,28 +385,6 @@ { s_showNotesToolTip = show; } - static void setUseSystray(bool useSystray) - { - if (s_useSystray != useSystray) { - s_useSystray = useSystray; - if (Global::systemTray != nullptr) { - if (Settings::useSystray()) - Global::systemTray->setStatus(KStatusNotifierItem::Active); - else { - Global::systemTray->setStatus(KStatusNotifierItem::Passive); - if (Global::activeMainWindow()) - Global::activeMainWindow()->show(); - } - } - if (Global::bnpView) - Global::bnpView->m_actHideWindow->setEnabled(useSystray); - } - } - static void setShowIconInSystray(bool show) - { - if (s_showIconInSystray != show) - s_showIconInSystray = show; - } static inline void setConfirmNoteDeletion(bool confirm) { s_confirmNoteDeletion = confirm; @@ -482,10 +403,6 @@ { s_useGnuPGAgent = yes; } - static inline void setPlayAnimations(bool play) - { - s_playAnimations = play; - } static inline void setBlinkedFilter(bool blinked) { s_blinkedFilter = blinked; @@ -498,10 +415,6 @@ { s_reLockTimeoutMinutes = minutes; } - static inline void setStartDocked(bool docked) - { - s_startDocked = docked; - } static inline void setMiddleAction(int action) { s_middleAction = action; @@ -514,30 +427,10 @@ { s_spellCheckTextNotes = yes; } - static inline void setHideOnMouseOut(bool hide) - { - s_hideOnMouseOut = hide; - } - static inline void setTimeToHideOnMouseOut(int time) - { - s_timeToHideOnMouseOut = time; - } - static inline void setShowOnMouseIn(bool show) - { - s_showOnMouseIn = show; - } - static inline void setTimeToShowOnMouseIn(int time) - { - s_timeToShowOnMouseIn = time; - } static inline void setBasketTreeWidth(int width) { s_basketTreeWidth = width; } - static inline void setUsePassivePopup(bool enable) - { - s_usePassivePopup = enable; - } static inline void setWelcomeBasketsAdded(bool added) { s_welcomeBasketsAdded = added; diff --git a/src/settings.cpp b/src/settings.cpp --- a/src/settings.cpp +++ b/src/settings.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -37,9 +38,6 @@ /** Settings */ // General: // TODO: Use this grouping everywhere! -bool Settings::s_useSystray = true; -bool Settings::s_usePassivePopup = true; -bool Settings::s_playAnimations = true; bool Settings::s_showNotesToolTip = true; // TODO: RENAME: useBasketTooltips bool Settings::s_confirmNoteDeletion = true; bool Settings::s_bigNotes = false; @@ -70,15 +68,9 @@ // Addictive Features: bool Settings::s_groupOnInsertionLine = false; int Settings::s_middleAction = 0; -bool Settings::s_showIconInSystray = false; // TODO: RENAME: basketIconInSystray -bool Settings::s_hideOnMouseOut = false; -int Settings::s_timeToHideOnMouseOut = 0; -bool Settings::s_showOnMouseIn = false; -int Settings::s_timeToShowOnMouseIn = 1; // Rememberings: int Settings::s_defIconSize = 32; // TODO: RENAME: importIconSize bool Settings::s_blinkedFilter = false; -bool Settings::s_startDocked = false; int Settings::s_basketTreeWidth = -1; bool Settings::s_welcomeBasketsAdded = false; QString Settings::s_dataFolder = QString(); @@ -116,7 +108,6 @@ KConfigGroup config = Global::config()->group("Main window"); // TODO: Split with a "System tray icon" group ! setTreeOnLeft(config.readEntry("treeOnLeft", true)); setFilterOnTop(config.readEntry("filterOnTop", false)); - setPlayAnimations(config.readEntry("playAnimations", true)); setShowNotesToolTip(config.readEntry("showNotesToolTip", true)); setBigNotes(config.readEntry("bigNotes", false)); setConfirmNoteDeletion(config.readEntry("confirmNoteDeletion", true)); @@ -127,18 +118,10 @@ setBlinkedFilter(config.readEntry("blinkedFilter", false)); setEnableReLockTimeout(config.readEntry("enableReLockTimeout", true)); setReLockTimeoutMinutes(config.readEntry("reLockTimeoutMinutes", 0)); - setUseSystray(config.readEntry("useSystray", true)); - setShowIconInSystray(config.readEntry("showIconInSystray", false)); - setStartDocked(config.readEntry("startDocked", false)); setMiddleAction(config.readEntry("middleAction", 0)); setGroupOnInsertionLine(config.readEntry("groupOnInsertionLine", false)); setSpellCheckTextNotes(config.readEntry("spellCheckTextNotes", true)); - setHideOnMouseOut(config.readEntry("hideOnMouseOut", false)); - setTimeToHideOnMouseOut(config.readEntry("timeToHideOnMouseOut", 0)); - setShowOnMouseIn(config.readEntry("showOnMouseIn", false)); - setTimeToShowOnMouseIn(config.readEntry("timeToShowOnMouseIn", 1)); setBasketTreeWidth(config.readEntry("basketTreeWidth", -1)); - setUsePassivePopup(config.readEntry("usePassivePopup", true)); setWelcomeBasketsAdded(config.readEntry("welcomeBasketsAdded", false)); setDataFolder(config.readEntry("dataFolder", QString())); setLastBackup(config.readEntry("lastBackup", QDate())); @@ -204,7 +187,6 @@ KConfigGroup config = Global::config()->group("Main window"); config.writeEntry("treeOnLeft", treeOnLeft()); config.writeEntry("filterOnTop", filterOnTop()); - config.writeEntry("playAnimations", playAnimations()); config.writeEntry("showNotesToolTip", showNotesToolTip()); config.writeEntry("confirmNoteDeletion", confirmNoteDeletion()); config.writeEntry("pasteAsPlainText", pasteAsPlainText()); @@ -218,18 +200,10 @@ config.writeEntry("blinkedFilter", blinkedFilter()); config.writeEntry("enableReLockTimeout", enableReLockTimeout()); config.writeEntry("reLockTimeoutMinutes", reLockTimeoutMinutes()); - config.writeEntry("useSystray", useSystray()); - config.writeEntry("showIconInSystray", showIconInSystray()); - config.writeEntry("startDocked", startDocked()); config.writeEntry("middleAction", middleAction()); config.writeEntry("groupOnInsertionLine", groupOnInsertionLine()); config.writeEntry("spellCheckTextNotes", spellCheckTextNotes()); - config.writeEntry("hideOnMouseOut", hideOnMouseOut()); - config.writeEntry("timeToHideOnMouseOut", timeToHideOnMouseOut()); - config.writeEntry("showOnMouseIn", showOnMouseIn()); - config.writeEntry("timeToShowOnMouseIn", timeToShowOnMouseIn()); config.writeEntry("basketTreeWidth", basketTreeWidth()); - config.writeEntry("usePassivePopup", usePassivePopup()); config.writeEntry("welcomeBasketsAdded", welcomeBasketsAdded()); config.writePathEntry("dataFolder", dataFolder()); config.writeEntry("lastBackup", QDate(lastBackup())); @@ -362,145 +336,38 @@ about->setComponentName(name); setAboutData(about); - QVBoxLayout *layout = new QVBoxLayout(this); - QHBoxLayout *hLay; - QLabel *label; - HelpLabel *hLabel; - - QGridLayout *gl = new QGridLayout; - layout->addLayout(gl); - gl->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding), 0, 2); + QFormLayout *layout = new QFormLayout(this); // Basket Tree Position: m_treeOnLeft = new KComboBox(this); m_treeOnLeft->addItem(i18n("On left")); m_treeOnLeft->addItem(i18n("On right")); - label = new QLabel(this); - label->setText(i18n("&Basket tree position:")); - label->setBuddy(m_treeOnLeft); - - gl->addWidget(label, 0, 0); - gl->addWidget(m_treeOnLeft, 0, 1); + layout->addRow(i18n("&Basket tree position:"), m_treeOnLeft); connect(m_treeOnLeft, SIGNAL(activated(int)), this, SLOT(changed())); // Filter Bar Position: m_filterOnTop = new KComboBox(this); m_filterOnTop->addItem(i18n("On top")); m_filterOnTop->addItem(i18n("On bottom")); - label = new QLabel(this); - label->setText(i18n("&Filter bar position:")); - label->setBuddy(m_filterOnTop); - - gl->addWidget(label, 1, 0); - gl->addWidget(m_filterOnTop, 1, 1); + layout->addRow(i18n("&Filter bar position:"), m_filterOnTop); connect(m_filterOnTop, SIGNAL(activated(int)), this, SLOT(changed())); - // Use balloons to Report Results of Global Actions: - hLay = new QHBoxLayout(nullptr); - m_usePassivePopup = new QCheckBox(i18n("&Use balloons to report results of global actions"), this); - connect(m_usePassivePopup, SIGNAL(stateChanged(int)), this, SLOT(changed())); - hLabel = new HelpLabel(i18n("What are global actions?"), - ("

" + - i18n("You can configure global shortcuts to do some actions without having to show the main window. For instance, you can paste the clipboard content, take a color from " - "a point of the screen, etc. You can also use the mouse scroll wheel over the system tray icon to change the current basket. Or use the middle mouse button " - "on that icon to paste the current selection.") + - "

" + "

" + i18n("When doing so, %1 pops up a little balloon message to inform you the action has been successfully done. You can disable that balloon.", QGuiApplication::applicationDisplayName()) + "

" + - "

" + i18n("Note that those messages are smart enough to not appear if the main window is visible. This is because you already see the result of your actions in the main window.") + "

"), - this); - hLay->addWidget(m_usePassivePopup); - hLay->addWidget(hLabel); - hLay->addStretch(); - layout->addLayout(hLay); - - // System Tray Icon: - QGroupBox *gbSys = new QGroupBox(i18n("System Tray Icon"), this); - layout->addWidget(gbSys); - QVBoxLayout *sysLay = new QVBoxLayout(gbSys); - - // Dock in System Tray: - m_useSystray = new QCheckBox(i18n("&Dock in system tray"), gbSys); - sysLay->addWidget(m_useSystray); - connect(m_useSystray, SIGNAL(stateChanged(int)), this, SLOT(changed())); - - m_systray = new QWidget(gbSys); - QVBoxLayout *subSysLay = new QVBoxLayout(m_systray); - sysLay->addWidget(m_systray); - - // Show Current Basket Icon in System Tray Icon: - m_showIconInSystray = new QCheckBox(i18n("&Show current basket icon in system tray icon"), m_systray); - subSysLay->addWidget(m_showIconInSystray); - connect(m_showIconInSystray, SIGNAL(stateChanged(int)), this, SLOT(changed())); - - QGridLayout *gs = new QGridLayout; - subSysLay->addLayout(gs); - gs->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding), 0, 2); - - // Hide Main Window when Mouse Goes out of it for Some Time: - m_timeToHideOnMouseOut = new QSpinBox(); - m_hideOnMouseOut = new QCheckBox(i18n("&Hide main window when mouse leaves it for"), m_systray); - m_timeToHideOnMouseOut->setRange(0, 600); - m_timeToHideOnMouseOut->setSuffix(i18n(" tenths of seconds")); - gs->addWidget(m_hideOnMouseOut, 0, 0); - gs->addWidget(m_timeToHideOnMouseOut, 0, 1); - connect(m_hideOnMouseOut, SIGNAL(stateChanged(int)), this, SLOT(changed())); - connect(m_timeToHideOnMouseOut, SIGNAL(valueChanged(int)), this, SLOT(changed())); - // subSysLay->addWidget( - - // Show Main Window when Mouse Hovers over the System Tray Icon for Some Time: - m_timeToShowOnMouseIn = new QSpinBox(); - m_showOnMouseIn = new QCheckBox(i18n("Show &main window when mouse hovers over the system tray icon for"), m_systray); - m_timeToShowOnMouseIn->setRange(0, 600); - m_timeToShowOnMouseIn->setSuffix(i18n(" tenths of seconds")); - gs->addWidget(m_showOnMouseIn, 1, 0); - gs->addWidget(m_timeToShowOnMouseIn, 1, 1); - connect(m_showOnMouseIn, SIGNAL(stateChanged(int)), this, SLOT(changed())); - connect(m_timeToShowOnMouseIn, SIGNAL(valueChanged(int)), this, SLOT(changed())); - - connect(m_hideOnMouseOut, SIGNAL(toggled(bool)), m_timeToHideOnMouseOut, SLOT(setEnabled(bool))); - connect(m_showOnMouseIn, SIGNAL(toggled(bool)), m_timeToShowOnMouseIn, SLOT(setEnabled(bool))); - - connect(m_useSystray, SIGNAL(toggled(bool)), m_systray, SLOT(setEnabled(bool))); - - layout->insertStretch(-1); load(); } void GeneralPage::load() { m_treeOnLeft->setCurrentIndex((int)!Settings::treeOnLeft()); m_filterOnTop->setCurrentIndex((int)!Settings::filterOnTop()); - m_usePassivePopup->setChecked(Settings::usePassivePopup()); - - m_useSystray->setChecked(Settings::useSystray()); - m_systray->setEnabled(Settings::useSystray()); - - m_showIconInSystray->setChecked(Settings::showIconInSystray()); - - m_hideOnMouseOut->setChecked(Settings::hideOnMouseOut()); - m_timeToHideOnMouseOut->setValue(Settings::timeToHideOnMouseOut()); - m_timeToHideOnMouseOut->setEnabled(Settings::hideOnMouseOut()); - - m_showOnMouseIn->setChecked(Settings::showOnMouseIn()); - m_timeToShowOnMouseIn->setValue(Settings::timeToShowOnMouseIn()); - m_timeToShowOnMouseIn->setEnabled(Settings::showOnMouseIn()); } void GeneralPage::save() { Settings::setTreeOnLeft(!m_treeOnLeft->currentIndex()); Settings::setFilterOnTop(!m_filterOnTop->currentIndex()); - - Settings::setUsePassivePopup(m_usePassivePopup->isChecked()); - - Settings::setUseSystray(m_useSystray->isChecked()); - Settings::setShowIconInSystray(m_showIconInSystray->isChecked()); - Settings::setShowOnMouseIn(m_showOnMouseIn->isChecked()); - Settings::setTimeToShowOnMouseIn(m_timeToShowOnMouseIn->value()); - Settings::setHideOnMouseOut(m_hideOnMouseOut->isChecked()); - Settings::setTimeToHideOnMouseOut(m_timeToHideOnMouseOut->value()); } void GeneralPage::defaults() @@ -528,10 +395,6 @@ appearanceBox->setLayout(appearanceLayout); layout->addWidget(appearanceBox); - m_playAnimations = new QCheckBox(i18n("Ani&mate changes in baskets"), appearanceBox); - appearanceLayout->addWidget(m_playAnimations); - connect(m_playAnimations, SIGNAL(stateChanged(int)), this, SLOT(changed())); - m_showNotesToolTip = new QCheckBox(i18n("&Show tooltips in baskets"), appearanceBox); appearanceLayout->addWidget(m_showNotesToolTip); connect(m_showNotesToolTip, SIGNAL(stateChanged(int)), this, SLOT(changed())); @@ -658,7 +521,6 @@ void BasketsPage::load() { - m_playAnimations->setChecked(Settings::playAnimations()); m_showNotesToolTip->setChecked(Settings::showNotesToolTip()); m_bigNotes->setChecked(Settings::bigNotes()); @@ -688,7 +550,6 @@ void BasketsPage::save() { - Settings::setPlayAnimations(m_playAnimations->isChecked()); Settings::setShowNotesToolTip(m_showNotesToolTip->isChecked()); Settings::setBigNotes(m_bigNotes->isChecked()); diff --git a/src/systemtray.h b/src/systemtray.h deleted file mode 100644 --- a/src/systemtray.h +++ /dev/null @@ -1,66 +0,0 @@ -/** - * SPDX-FileCopyrightText: (C) 2003 Sébastien Laoût - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#ifndef SYSTEMTRAY_H -#define SYSTEMTRAY_H - -#include -#include -#include - -/** A thin wrapper around KSystemTrayIcon until the old SystemTray is ported. - * As things are ported, items should - * @author Kelvie Wong - */ -class SystemTray : public KStatusNotifierItem -{ - Q_OBJECT - Q_DISABLE_COPY(SystemTray); - -public: - explicit SystemTray(QWidget *parent = nullptr); - ~SystemTray() override; - -public slots: - void updateDisplay(); - -signals: - void showPart(); -}; - -#ifdef USE_OLD_SYSTRAY - -/** This class provide a personalized system tray icon. - * @author Sébastien Laoût - */ -class SystemTray2 : public SystemTray -{ - Q_OBJECT -public: - explicit SystemTray2(QWidget *parent = nullptr, const char *name = nullptr); - ~SystemTray2(); - -protected: - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - virtual void dragEnterEvent(QDragEnterEvent *event); - virtual void dragMoveEvent(QDragMoveEvent *event); - virtual void dragLeaveEvent(QDragLeaveEvent *); - virtual void dropEvent(QDropEvent *event); - void wheelEvent(QWheelEvent *event); - void enterEvent(QEvent *); - void leaveEvent(QEvent *); - -private: - QTimer *m_showTimer; - QTimer *m_autoShowTimer; - bool m_canDrag; - QPoint m_pressPos; -}; -#endif // USE_OLD_SYSTRAY - -#endif // SYSTEMTRAY_H diff --git a/src/systemtray.cpp b/src/systemtray.cpp deleted file mode 100644 --- a/src/systemtray.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/** - * SPDX-FileCopyrightText: (C) 2003 Sébastien Laoût - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -/** SystemTray */ -#include "systemtray.h" - -// Qt -#include -#include -#include -#include - -// Frameworks -#include //Port to Blitz/Quasar? -#include - -// Local -#include "basketscene.h" -#include "global.h" -#include "icon_names.h" -#include "settings.h" -#include "tools.h" - -/* This function comes directly from JuK: */ - -/* - * This function copies the entirety of src into dest, starting in - * dest at x and y. This function exists because I was unable to find - * a function like it in either QImage or kdefx - */ -static bool copyImage(QImage &dest, QImage &src, int x, int y) -{ - if (dest.depth() != src.depth()) - return false; - if ((x + src.width()) >= dest.width()) - return false; - if ((y + src.height()) >= dest.height()) - return false; - - // We want to use KIconEffect::overlay to do this, since it handles - // alpha, but the images need to be the same size. We can handle that. - - QImage large_src(dest); - - // It would perhaps be better to create large_src based on a size, but - // this is the easiest way to make a new image with the same depth, size, - // etc. - - large_src.detach(); - - // However, we do have to specifically ensure that setAlphaBuffer is set - // to false - - // large_src.setAlphaBuffer(false); - large_src.fill(0); // All transparent pixels - // large_src.setAlphaBuffer(true); - - int w = src.width(); - int h = src.height(); - for (int dx = 0; dx < w; dx++) - for (int dy = 0; dy < h; dy++) - large_src.setPixel(dx + x, dy + y, src.pixel(dx, dy)); - - // Apply effect to image - - KIconEffect::overlay(dest, large_src); - - return true; -} - -/** Constructor */ -SystemTray::SystemTray(QWidget *parent) - : KStatusNotifierItem(parent) -{ - updateDisplay(); -} - -/** Destructor */ -SystemTray::~SystemTray() -{ - // pass -} - -/** Updates the icon and tooltip in the system tray */ -void SystemTray::updateDisplay() -{ - BasketScene *basket = Global::bnpView->currentBasket(); - if (!basket) - return; - - // Update the icon - if (basket->icon().isEmpty() || basket->icon() == "basket" || !Settings::showIconInSystray()) - setIconByName("basket"); - else { - // What pixmap size to use? For example, see how overlay icon is applied: - // https://api.kde.org/frameworks-api/frameworks5-apidocs/knotifications/html/kstatusnotifieritem_8cpp_source.html - - // Code that comes from JuK: - QPixmap bgPix = QIcon::fromTheme("basket").pixmap(22); - QPixmap fgPix = QIcon::fromTheme(basket->icon()).pixmap(16); - - QImage bgImage = bgPix.toImage(); // Probably 22x22 - QImage fgImage = fgPix.toImage(); // Should be 16x16 - - KIconEffect::semiTransparent(bgImage); - copyImage(bgImage, fgImage, (bgImage.width() - fgImage.width()) / 2, (bgImage.height() - fgImage.height()) / 2); - - setIconByPixmap(QPixmap::fromImage(bgImage)); - } - setOverlayIconByName(basket->isLocked() ? IconNames::LOCKED : QString()); - - // update the tooltip - QString tip = "

"; - QString basketName = "%1"; - if (basket->isLocked()) - basketName += i18n(" (Locked)"); - tip += Tools::makeStandardCaption(basketName); - tip = tip.arg(Tools::textToHTMLWithoutP(basket->basketName())); - setToolTipTitle(tip); -} - -#ifdef USE_OLD_SYSTRAY -#define QT3_SUPPORT // No need to port that old stuff -SystemTray::SystemTray(QWidget *parent, const char *name) - : KSystemTray2(parent, name != 0 ? name : "SystemTray") - , m_showTimer(0) - , m_autoShowTimer(0) -{ - setAcceptDrops(true); - - m_showTimer = new QTimer(this); - connect(m_showTimer, SIGNAL(timeout()), Global::bnpView, SLOT(setActive())); - - m_autoShowTimer = new QTimer(this); - connect(m_autoShowTimer, SIGNAL(timeout()), Global::bnpView, SLOT(setActive())); - - // Create pixmaps for the icon: - m_iconPixmap = loadIcon("basket"); - // FIXME: When main window is shown at start, the icon is loaded 1 pixel too high - // and then reloaded instantly after at the right position. - // setPixmap(m_iconPixmap); // Load it the sooner as possible to avoid flicker - QImage lockedIconImage = m_iconPixmap.convertToImage(); - QPixmap lockOverlayPixmap = loadIcon("object-locked"); - QImage lockOverlayImage = lockOverlayPixmap.convertToImage(); - KIconEffect::overlay(lockedIconImage, lockOverlayImage); - m_lockedIconPixmap.convertFromImage(lockedIconImage); - - updateToolTip(); // Set toolTip AND icon -} - -SystemTray::~SystemTray() -{ -} - -void SystemTray::mousePressEvent(QMouseEvent *event) -{ - if (event->button() & Qt::LeftButton) { // Prepare drag - m_pressPos = event->globalPos(); - m_canDrag = true; - event->accept(); - } else if (event->button() & Qt::MidButton) { // Paste - Global::bnpView->currentBasket()->setInsertPopupMenu(); - Global::bnpView->currentBasket()->pasteNote(QClipboard::Selection); - Global::bnpView->currentBasket()->cancelInsertPopupMenu(); - if (Settings::usePassivePopup()) - Global::bnpView->showPassiveDropped(i18n("Pasted selection to basket %1")); - event->accept(); - } else if (event->button() & Qt::RightButton) { // Popup menu - QMenu menu(this); - menu.addSection(SmallIcon("basket"), QGuiApplication::applicationDisplayName()); - - Global::bnpView->actNewBasket->plug(&menu); - Global::bnpView->actNewSubBasket->plug(&menu); - Global::bnpView->actNewSiblingBasket->plug(&menu); - menu.insertSeparator(); - Global::bnpView->m_actPaste->plug(&menu); - Global::bnpView->m_actGrabScreenshot->plug(&menu); - Global::bnpView->m_actColorPicker->plug(&menu); - - if (!Global::bnpView->isPart()) { - QAction *action; - - menu.insertSeparator(); - - action = Global::bnpView->actionCollection()->action("options_configure_global_keybinding"); - if (action) - action->plug(&menu); - - action = Global::bnpView->actionCollection()->action("options_configure"); - if (action) - action->plug(&menu); - - menu.insertSeparator(); - - // Minimize / restore : since we manage the popup menu by ourself, we should do that work : - action = Global::bnpView->actionCollection()->action("minimizeRestore"); - if (action) { - if (Global::mainWindow()->isVisible()) - action->setText(i18n("&Minimize")); - else - action->setText(i18n("&Restore")); - action->plug(&menu); - } - - action = Global::bnpView->actionCollection()->action("file_quit"); - if (action) - action->plug(&menu); - } - - Global::bnpView->currentBasket()->setInsertPopupMenu(); - connect(&menu, SIGNAL(aboutToHide()), Global::bnpView->currentBasket(), SLOT(delayedCancelInsertPopupMenu())); - menu.exec(event->globalPos()); - event->accept(); - } else - event->ignore(); -} - -void SystemTray::mouseMoveEvent(QMouseEvent *event) -{ - event->ignore(); -} - -void SystemTray::mouseReleaseEvent(QMouseEvent *event) -{ - m_canDrag = false; - if (event->button() == Qt::LeftButton) // Show / hide main window - if (rect().contains(event->pos())) { // Accept only if released in systemTray - toggleActive(); - emit showPart(); - event->accept(); - } else - event->ignore(); -} - -void SystemTray::dragEnterEvent(QDragEnterEvent *event) -{ - m_showTimer->start(Settings::dropTimeToShow() * 100, true); - Global::bnpView->currentBasket()->showFrameInsertTo(); - /// m_parentContainer->setStatusBarDrag(); // FIXME: move this line in BasketScene::showFrameInsertTo() ? - BasketScene::acceptDropEvent(event); -} - -void SystemTray::dragMoveEvent(QDragMoveEvent *event) -{ - BasketScene::acceptDropEvent(event); -} - -void SystemTray::dragLeaveEvent(QDragLeaveEvent *) -{ - m_showTimer->stop(); - m_canDrag = false; - Global::bnpView->currentBasket()->resetInsertTo(); - Global::bnpView->updateStatusBarHint(); -} - -#include - -void SystemTray::dropEvent(QDropEvent *event) -{ - m_showTimer->stop(); - - Global::bnpView->currentBasket()->blindDrop(event); - - /* BasketScene *basket = Global::bnpView->currentBasket(); - if (!basket->isLoaded()) { - Global::bnpView->showPassiveLoading(basket); - basket->load(); - } - basket->contentsDropEvent(event); - qDebug() << (long) basket->selectedNotes(); - - if (Settings::usePassivePopup()) - Global::bnpView->showPassiveDropped(i18n("Dropped to basket %1", m_basketName));*/ -} - -void SystemTray::updateToolTip() -{ - // return; ///////////////////////////////////////////////////// - - BasketScene *basket = Global::bnpView->currentBasket(); - if (!basket) - return; - - if (basket->icon().isEmpty() || basket->icon() == "basket" || !Settings::showIconInSystray()) - setPixmap(basket->isLocked() ? m_lockedIconPixmap : m_iconPixmap); - else { - // Code that comes from JuK: - QPixmap bgPix = loadIcon("basket"); - QPixmap fgPix = SmallIcon(basket->icon()); - - QImage bgImage = bgPix.convertToImage(); // Probably 22x22 - QImage fgImage = fgPix.convertToImage(); // Should be 16x16 - QImage lockOverlayImage = loadIcon("object-locked").convertToImage(); - - KIconEffect::semiTransparent(bgImage); - copyImage(bgImage, fgImage, (bgImage.width() - fgImage.width()) / 2, (bgImage.height() - fgImage.height()) / 2); - if (basket->isLocked()) - KIconEffect::overlay(bgImage, lockOverlayImage); - - bgPix.convertFromImage(bgImage); - setPixmap(bgPix); - } - - // QTimer::singleShot( Container::c_delayTooltipTime, this, SLOT(updateToolTipDelayed()) ); - // No need to delay: it's be called when notes are changed: - updateToolTipDelayed(); -} - -void SystemTray::updateToolTipDelayed() -{ - BasketScene *basket = Global::bnpView->currentBasket(); - - QString tip = "

" + (basket->isLocked() ? Tools::makeStandardCaption(i18n("%1 (Locked)")) : Tools::makeStandardCaption("%1")).arg(Tools::textToHTMLWithoutP(basket->basketName())); - - QToolTip::add(this, tip); -} - -void SystemTray::wheelEvent(QWheelEvent *event) -{ - if (event->delta() > 0) - Global::bnpView->goToPreviousBasket(); - else - Global::bnpView->goToNextBasket(); - - if (Settings::usePassivePopup()) - Global::bnpView->showPassiveContent(); -} - -void SystemTray::enterEvent(QEvent *) -{ - if (Settings::showOnMouseIn()) - m_autoShowTimer->start(Settings::timeToShowOnMouseIn() * 100, true); -} - -void SystemTray::leaveEvent(QEvent *) -{ - m_autoShowTimer->stop(); -} - -#undef QT3_SUPPORT -#endif // USE_OLD_SYSTRAY