diff --git a/src/gui/guiutility.cpp b/src/gui/guiutility.cpp index 076b2f899..bb8db4e37 100644 --- a/src/gui/guiutility.cpp +++ b/src/gui/guiutility.cpp @@ -564,46 +564,4 @@ bool GuiUtility::getLinuxDesktopType(QString &type, QString &version) { return true; } #endif - -GuiUtility::WidgetWithCustomToolTip::WidgetWithCustomToolTip(QWidget *parent) : QWidget(parent), _customToolTip{nullptr} {} - -// Place the tooltip at the bottom middle of the widget. -QPoint GuiUtility::WidgetWithCustomToolTip::customToolTipPosition(QHelpEvent *event) { - Q_UNUSED(event); - const QRect widgetRect = geometry(); - - return parentWidget()->mapToGlobal((widgetRect.bottomLeft() + widgetRect.bottomRight()) / 2.0); -} - -bool GuiUtility::WidgetWithCustomToolTip::event(QEvent *event) { - static const int defaultToolTipDuration = 3000; // ms - - if (event->type() == QEvent::ToolTip) { - if (!_customToolTipText.isEmpty()) { - const QPoint position = customToolTipPosition(static_cast(event)); - delete _customToolTip; - _customToolTip = new CustomToolTip(_customToolTipText, position, defaultToolTipDuration, this); - _customToolTip->show(); - event->ignore(); - - return true; - } - } - - return QWidget::event(event); -} - -void GuiUtility::WidgetWithCustomToolTip::leaveEvent(QEvent *event) { - delete _customToolTip; - _customToolTip = nullptr; - - QWidget::leaveEvent(event); -} - -GuiUtility::LargeWidgetWithCustomToolTip::LargeWidgetWithCustomToolTip(QWidget *parent) : WidgetWithCustomToolTip(parent) {} - -// Place the tooltip at mouse pointer position. -QPoint GuiUtility::LargeWidgetWithCustomToolTip::customToolTipPosition(QHelpEvent *event) { - return mapToGlobal(event->pos()); -} } // namespace KDC diff --git a/src/gui/guiutility.h b/src/gui/guiutility.h index 67c1b1714..cfbc1a471 100644 --- a/src/gui/guiutility.h +++ b/src/gui/guiutility.h @@ -113,33 +113,6 @@ void setEnabledRecursively(C *root, bool enabled) { setEnabledRecursively(child, enabled); } } - -class WidgetWithCustomToolTip : public QWidget { - Q_OBJECT - - public: - explicit WidgetWithCustomToolTip(QWidget *parent); - void setCustomToolTipText(const QString &text) { _customToolTipText = text; } - - private: - virtual QPoint customToolTipPosition(QHelpEvent *event); - - protected: - CustomToolTip *_customToolTip; - QString _customToolTipText; - virtual bool event(QEvent *event) override; - virtual void leaveEvent(QEvent *event) override; -}; - -class LargeWidgetWithCustomToolTip : public WidgetWithCustomToolTip { - Q_OBJECT - - public: - explicit LargeWidgetWithCustomToolTip(QWidget *parent); - - private: - virtual QPoint customToolTipPosition(QHelpEvent *event) override; -}; } // namespace GuiUtility } // namespace KDC diff --git a/src/gui/parameterswidget.cpp b/src/gui/parameterswidget.cpp index ae739b7f0..3d43bcc0a 100644 --- a/src/gui/parameterswidget.cpp +++ b/src/gui/parameterswidget.cpp @@ -17,12 +17,11 @@ */ #include "parameterswidget.h" - #include "customdialog.h" namespace KDC { -ParametersWidget::ParametersWidget(QWidget *parent) : GuiUtility::LargeWidgetWithCustomToolTip(parent) {} +ParametersWidget::ParametersWidget(QWidget *parent) : LargeWidgetWithCustomToolTip(parent) {} void ParametersWidget::setEnabled(bool val) { // Disable all parent CustomDialog diff --git a/src/gui/parameterswidget.h b/src/gui/parameterswidget.h index 7b1d04710..c137c709f 100644 --- a/src/gui/parameterswidget.h +++ b/src/gui/parameterswidget.h @@ -18,11 +18,11 @@ #pragma once -#include "guiutility.h" +#include "widgetwithcustomtooltip.h" namespace KDC { -class ParametersWidget : public GuiUtility::LargeWidgetWithCustomToolTip { +class ParametersWidget : public LargeWidgetWithCustomToolTip { Q_OBJECT public: diff --git a/src/gui/preferencesblocwidget.cpp b/src/gui/preferencesblocwidget.cpp index 419075221..bdc7e17b9 100644 --- a/src/gui/preferencesblocwidget.cpp +++ b/src/gui/preferencesblocwidget.cpp @@ -18,6 +18,7 @@ #include "preferencesblocwidget.h" #include "guiutility.h" +#include "widgetwithcustomtooltip.h" #include #include @@ -39,7 +40,7 @@ static const int shadowBlurRadius = 20; Q_LOGGING_CATEGORY(lcPreferencesBlocWidget, "gui.preferencesblocwidget", QtInfoMsg) PreferencesBlocWidget::PreferencesBlocWidget(QWidget *parent) - : GuiUtility::LargeWidgetWithCustomToolTip(parent), + : LargeWidgetWithCustomToolTip(parent), _backgroundColor(QColor()), _actionIconColor(QColor()), _actionIconSize(QSize()), diff --git a/src/gui/preferencesblocwidget.h b/src/gui/preferencesblocwidget.h index d8b9f9d0e..4745dc97e 100644 --- a/src/gui/preferencesblocwidget.h +++ b/src/gui/preferencesblocwidget.h @@ -19,7 +19,7 @@ #pragma once #include "clickablewidget.h" -#include "guiutility.h" +#include "widgetwithcustomtooltip.h" #include #include @@ -32,7 +32,7 @@ namespace KDC { class CustomToolTip; -class PreferencesBlocWidget : public GuiUtility::LargeWidgetWithCustomToolTip { +class PreferencesBlocWidget : public LargeWidgetWithCustomToolTip { Q_OBJECT Q_PROPERTY(QColor background_color READ backgroundColor WRITE setBackgroundColor) diff --git a/src/gui/widgetwithcustomtooltip.cpp b/src/gui/widgetwithcustomtooltip.cpp new file mode 100644 index 000000000..268867a7e --- /dev/null +++ b/src/gui/widgetwithcustomtooltip.cpp @@ -0,0 +1,66 @@ +/* + * Infomaniak kDrive - Desktop + * Copyright (C) 2023-2024 Infomaniak Network SA + * + * 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 3 of the License, or + * (at your option) 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, see . + */ + +#include "customtooltip.h" +#include "widgetwithcustomtooltip.h" + +namespace KDC { + +WidgetWithCustomToolTip::WidgetWithCustomToolTip(QWidget *parent) : QWidget(parent), _customToolTip{nullptr} {} + +// Place the tooltip at the bottom middle of the widget. +QPoint WidgetWithCustomToolTip::customToolTipPosition(QHelpEvent *event) { + Q_UNUSED(event); + const QRect widgetRect = geometry(); + + return parentWidget()->mapToGlobal((widgetRect.bottomLeft() + widgetRect.bottomRight()) / 2.0); +} + +bool WidgetWithCustomToolTip::event(QEvent *event) { + static const int defaultToolTipDuration = 3000; // ms + + if (event->type() == QEvent::ToolTip) { + if (!_customToolTipText.isEmpty()) { + const QPoint position = customToolTipPosition(static_cast(event)); + delete _customToolTip; + _customToolTip = new CustomToolTip(_customToolTipText, position, defaultToolTipDuration, this); + _customToolTip->show(); + event->ignore(); + + return true; + } + } + + return QWidget::event(event); +} + +void WidgetWithCustomToolTip::leaveEvent(QEvent *event) { + delete _customToolTip; + _customToolTip = nullptr; + + QWidget::leaveEvent(event); +} + +LargeWidgetWithCustomToolTip::LargeWidgetWithCustomToolTip(QWidget *parent) : WidgetWithCustomToolTip(parent) {} + +// Place the tooltip at mouse pointer position. +QPoint LargeWidgetWithCustomToolTip::customToolTipPosition(QHelpEvent *event) { + return mapToGlobal(event->pos()); +} + +} // namespace KDC diff --git a/src/gui/widgetwithcustomtooltip.h b/src/gui/widgetwithcustomtooltip.h new file mode 100644 index 000000000..ff967f37a --- /dev/null +++ b/src/gui/widgetwithcustomtooltip.h @@ -0,0 +1,59 @@ +/* + * Infomaniak kDrive - Desktop + * Copyright (C) 2023-2024 Infomaniak Network SA + * + * 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 3 of the License, or + * (at your option) 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, see . + */ + + +#pragma once + +#include +#include +#include + +class QHelpEvent; +class QLayout; + +namespace KDC { + +class CustomToolTip; + +class WidgetWithCustomToolTip : public QWidget { + Q_OBJECT + + public: + explicit WidgetWithCustomToolTip(QWidget *parent); + void setCustomToolTipText(const QString &text) { _customToolTipText = text; } + + private: + virtual QPoint customToolTipPosition(QHelpEvent *event); + + protected: + CustomToolTip *_customToolTip; + QString _customToolTipText; + virtual bool event(QEvent *event) override; + virtual void leaveEvent(QEvent *event) override; +}; + +class LargeWidgetWithCustomToolTip : public WidgetWithCustomToolTip { + Q_OBJECT + + public: + explicit LargeWidgetWithCustomToolTip(QWidget *parent); + + private: + virtual QPoint customToolTipPosition(QHelpEvent *event) override; +}; +} // namespace KDC diff --git a/src/libcommon/comm.h b/src/libcommon/comm.h index e94852ef6..d1cb8e6cc 100644 --- a/src/libcommon/comm.h +++ b/src/libcommon/comm.h @@ -42,6 +42,8 @@ typedef enum { REQUEST = 0, REPLY, SIGNAL } MsgType; +static const QColor driveDefaultColor(0x9F9F9F); + typedef enum { REQUEST_NUM_LOGIN_REQUESTTOKEN = 1, REQUEST_NUM_USER_DBIDLIST, diff --git a/src/server/appserver.cpp b/src/server/appserver.cpp index ceca8f630..c15763dcf 100644 --- a/src/server/appserver.cpp +++ b/src/server/appserver.cpp @@ -718,10 +718,8 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray ¶ break; } case REQUEST_NUM_DRIVE_DEFAULTCOLOR: { - static const QColor color(0x9F9F9F); - resultStream << ExitCodeOk; - resultStream << color; + resultStream << driveDefaultColor; break; } case REQUEST_NUM_DRIVE_UPDATE: { @@ -3742,24 +3740,19 @@ void AppServer::sendSyncRemoved(int syncDbId) { } void AppServer::sendSyncDeletionFailed(int syncDbId) { - int id; - - QByteArray params; - QDataStream paramsStream(¶ms, QIODevice::WriteOnly); - paramsStream << syncDbId; + int id = 0; + const ArgsReader params(syncDbId); CommServer::instance()->sendSignal(SIGNAL_NUM_SYNC_DELETE_FAILED, params, id); } void AppServer::sendDriveDeletionFailed(int driveDbId) { - int id; - - QByteArray params; - QDataStream paramsStream(¶ms, QIODevice::WriteOnly); - paramsStream << driveDbId; + int id = 0; + const ArgsReader params(driveDbId) - CommServer::instance()->sendSignal(SIGNAL_NUM_DRIVE_DELETE_FAILED, params, id); + CommServer::instance() + ->sendSignal(SIGNAL_NUM_DRIVE_DELETE_FAILED, params, id); }