Skip to content

Commit

Permalink
Adresses Clément's comments (1st part)
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-guyot-infomaniak committed Mar 20, 2024
1 parent 0e4371e commit fa94f50
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 90 deletions.
42 changes: 0 additions & 42 deletions src/gui/guiutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QHelpEvent *>(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
27 changes: 0 additions & 27 deletions src/gui/guiutility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/gui/parameterswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/gui/parameterswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/gui/preferencesblocwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "preferencesblocwidget.h"
#include "guiutility.h"
#include "widgetwithcustomtooltip.h"

#include <QFrame>
#include <QGraphicsDropShadowEffect>
Expand All @@ -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()),
Expand Down
4 changes: 2 additions & 2 deletions src/gui/preferencesblocwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#pragma once

#include "clickablewidget.h"
#include "guiutility.h"
#include "widgetwithcustomtooltip.h"

#include <QBoxLayout>
#include <QColor>
Expand All @@ -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)
Expand Down
66 changes: 66 additions & 0 deletions src/gui/widgetwithcustomtooltip.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#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<QHelpEvent *>(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
59 changes: 59 additions & 0 deletions src/gui/widgetwithcustomtooltip.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/


#pragma once

#include <QPoint>
#include <QString>
#include <QWidget>

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
2 changes: 2 additions & 0 deletions src/libcommon/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 7 additions & 14 deletions src/server/appserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,8 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray &para
break;
}
case REQUEST_NUM_DRIVE_DEFAULTCOLOR: {
static const QColor color(0x9F9F9F);

resultStream << ExitCodeOk;
resultStream << color;
resultStream << driveDefaultColor;
break;
}
case REQUEST_NUM_DRIVE_UPDATE: {
Expand Down Expand Up @@ -3742,24 +3740,19 @@ void AppServer::sendSyncRemoved(int syncDbId) {
}

void AppServer::sendSyncDeletionFailed(int syncDbId) {
int id;

QByteArray params;
QDataStream paramsStream(&params, 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(&params, 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);
}


Expand Down

0 comments on commit fa94f50

Please sign in to comment.