chore: 清理cppcheck警告信息

清理cppcheck警告信息

Log:
Task: https://pms.uniontech.com/zentao/task-view-77871.html
Change-Id: I93e77403b3f3b656be4e7d442b81dcbe227c3150
This commit is contained in:
FanPengCheng 2021-05-31 17:37:21 +08:00 committed by fanpengcheng
parent 5784fa3753
commit b891a5565e
51 changed files with 87 additions and 1037 deletions

View File

@ -333,42 +333,6 @@ void DockItemManager::reloadAppItems()
appItemAdded(path, -1);
}
// 不同的模式下,插件顺序不一样
void DockItemManager::sortPluginItems()
{
int firstPluginIndex = -1;
for (int i(0); i != m_itemList.size(); ++i) {
if (m_itemList[i]->itemType() == DockItem::Plugins) {
firstPluginIndex = i;
break;
}
}
if (firstPluginIndex == -1)
return;
std::sort(m_itemList.begin() + firstPluginIndex, m_itemList.end(), [](QPointer<DockItem> a, QPointer<DockItem> b) -> bool {
PluginsItem *pa = static_cast<PluginsItem *>(a.data());
PluginsItem *pb = static_cast<PluginsItem *>(b.data());
const int aKey = pa->itemSortKey();
const int bKey = pb->itemSortKey();
if (bKey == -1)
return true;
if (aKey == -1)
return false;
return aKey < bKey;
});
// reset order
for (int i(firstPluginIndex); i != m_itemList.size(); ++i) {
emit itemRemoved(m_itemList[i]);
emit itemInserted(-1, m_itemList[i]);
}
}
void DockItemManager::manageItem(DockItem *item)
{
connect(item, &DockItem::requestRefreshWindowVisible, this, &DockItemManager::requestRefershWindowVisible, Qt::UniqueConnection);

View File

@ -61,7 +61,6 @@ signals:
public slots:
void refreshItemsIcon();
void sortPluginItems();
void itemMoved(DockItem *const sourceItem, DockItem *const targetItem);
void itemAdded(const QString &appDesktop, int idx);

View File

@ -44,7 +44,7 @@ class DBusDockAdaptors: public QDBusAbstractAdaptor
"")
public:
DBusDockAdaptors(MainWindow *parent);
explicit DBusDockAdaptors(MainWindow *parent);
virtual ~DBusDockAdaptors();
MainWindow *parent() const;

View File

@ -22,7 +22,6 @@
#include "appitem.h"
#include "themeappicon.h"
#include "imagefactory.h"
#include "xcb_misc.h"
#include "appswingeffectbuilder.h"
#include "appspreviewprovider.h"
@ -555,10 +554,11 @@ void AppItem::startDrag()
bool AppItem::hasAttention() const
{
for (const auto &info : m_windowInfos)
if (info.attention)
return true;
return false;
auto it = std::find_if(m_windowInfos.constBegin(), m_windowInfos.constEnd(), [ = ] (const auto &info) {
return info.attention;
});
return (it != m_windowInfos.end());
}
QPoint AppItem::appIconPosition() const

View File

@ -50,6 +50,9 @@ public:
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) override {
Q_UNUSED(option);
Q_UNUSED(widget);
Q_ASSERT(!m_appPixmap.isNull());
painter->drawPixmap(QPoint(0, 0), m_appPixmap);
@ -373,7 +376,6 @@ void AppDragWidget::enterEvent(QEvent *event)
void AppDragWidget::showRemoveTips()
{
bool model = true;
Dock::Position pos = Dock::Position::Bottom;
DockPopupWindow *popup = m_popupWindow;
@ -393,9 +395,9 @@ void AppDragWidget::showRemoveTips()
const QPoint p = popupMarkPoint(pos);
if (!popup->isVisible())
QMetaObject::invokeMethod(popup, "show", Qt::QueuedConnection, Q_ARG(QPoint, p), Q_ARG(bool, model));
QMetaObject::invokeMethod(popup, "show", Qt::QueuedConnection, Q_ARG(QPoint, p), Q_ARG(bool, true));
else
popup->show(p, model);
popup->show(p, true);
m_object->setOpacity(0.5);
m_animOpacity->setStartValue(0.5);

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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
* 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 "hoverhighlighteffect.h"
#include "imagefactory.h"
#include <QPainter>
#include <QDebug>
HoverHighlightEffect::HoverHighlightEffect(QObject *parent)
: QGraphicsEffect(parent)
, m_highlighting(false)
{
}
void HoverHighlightEffect::draw(QPainter *painter)
{
const QPixmap pix = sourcePixmap(Qt::DeviceCoordinates);
if (m_highlighting)
{
painter->drawPixmap(0, 0, ImageFactory::lighterEffect(pix));
} else {
painter->drawPixmap(0, 0, pix);
}
}

View File

@ -1,43 +0,0 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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
* 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/>.
*/
#ifndef HOVERHIGHLIGHTEFFECT_H
#define HOVERHIGHLIGHTEFFECT_H
#include <QGraphicsEffect>
class HoverHighlightEffect : public QGraphicsEffect
{
Q_OBJECT
public:
explicit HoverHighlightEffect(QObject *parent = nullptr);
void setHighlighting(const bool highlighting) { m_highlighting = highlighting; }
protected:
void draw(QPainter *painter);
private:
bool m_highlighting;
};
#endif // HOVERHIGHLIGHTEFFECT_H

View File

@ -20,7 +20,6 @@
*/
#include "dockitem.h"
#include "hoverhighlighteffect.h"
#include "pluginsitem.h"
#include <QMouseEvent>
@ -41,8 +40,6 @@ DockItem::DockItem(QWidget *parent)
, m_popupShown(false)
, m_tapAndHold(false)
, m_draging(false)
//FIXME: 可能是qt的bug概率性导致崩溃待修复
// , m_hoverEffect(new HoverHighlightEffect(this))
, m_popupTipsDelayTimer(new QTimer(this))
, m_popupAdjustDelayTimer(new QTimer(this))

View File

@ -24,7 +24,6 @@
#include "constants.h"
#include "dockpopupwindow.h"
#include "hoverhighlighteffect.h"
#include <QFrame>
#include <QPointer>
@ -114,8 +113,6 @@ protected:
QMenu m_contextMenu;
QPointer<QWidget> m_lastPopupWidget;
//FIXME: 可能是qt的bug概率性导致崩溃待修复
// QPointer<HoverHighlightEffect> m_hoverEffect;
QTimer *m_popupTipsDelayTimer;
QTimer *m_popupAdjustDelayTimer;

View File

@ -21,7 +21,6 @@
#include "launcheritem.h"
#include "themeappicon.h"
#include "imagefactory.h"
#include "utils.h"
#include <QPainter>

View File

@ -22,9 +22,7 @@
#include "constants.h"
#include "pluginsitem.h"
#include "pluginsiteminterface.h"
#include "utils.h"
#include "imagefactory.h"
#include <QPainter>
#include <QBoxLayout>

View File

@ -91,10 +91,10 @@ bool IsSaveMode()
// 创建默认配置文件,记录段时间内的崩溃次数
if (!QFile::exists(g_cfgPath)) {
QFile file(g_cfgPath);
if (!file.open(QIODevice::WriteOnly))
QFile cfgFile(g_cfgPath);
if (!cfgFile.open(QIODevice::WriteOnly))
exit(0);
file.close();
cfgFile.close();
}
QSettings settings(g_cfgPath, QSettings::IniFormat);

View File

@ -28,6 +28,7 @@
#include <QDebug>
#include <QDir>
#include <QMapIterator>
static const QStringList CompatiblePluginApiList {
"1.1.1",
@ -61,8 +62,7 @@ AbstractPluginsController::~AbstractPluginsController()
void AbstractPluginsController::saveValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant &value)
{
// is it necessary?
// refreshPluginSettings();
int fixedPluginCount(0); // FixPlugin Counts
// refreshPluginSettings();
// save to local cache
QJsonObject localObject = m_pluginSettingsObject.value(itemInter->pluginName()).toObject();
@ -74,6 +74,7 @@ void AbstractPluginsController::saveValue(PluginsItemInterface *const itemInter,
remoteObject.insert(itemInter->pluginName(), remoteObjectInter);
if (itemInter->type() == PluginsItemInterface::Fixed && key == "enable" && !value.toBool()) {
int fixedPluginCount = 0;
// 遍历FixPlugin插件个数
for (auto it(m_pluginsMap.begin()); it != m_pluginsMap.end();) {
if (it.key()->type() == PluginsItemInterface::Fixed) {
@ -135,11 +136,11 @@ QObject *AbstractPluginsController::pluginItemAt(PluginsItemInterface *const ite
PluginsItemInterface *AbstractPluginsController::pluginInterAt(const QString &itemKey)
{
for (auto it = m_pluginsMap.constBegin(); it != m_pluginsMap.constEnd(); ++it) {
for (auto key : it.value().keys()) {
if (key == itemKey) {
return it.key();
}
QMapIterator<PluginsItemInterface *, QMap<QString, QObject *>> it(m_pluginsMap);
while (it.hasNext()) {
it.next();
if (it.value().keys().contains(itemKey)) {
return it.key();
}
}
@ -147,12 +148,12 @@ PluginsItemInterface *AbstractPluginsController::pluginInterAt(const QString &it
}
PluginsItemInterface *AbstractPluginsController::pluginInterAt(QObject *destItem)
{
for (auto it = m_pluginsMap.constBegin(); it != m_pluginsMap.constEnd(); ++it) {
for (auto item : it.value().values()) {
if (item == destItem) {
return it.key();
}
{
QMapIterator<PluginsItemInterface *, QMap<QString, QObject *>> it(m_pluginsMap);
while (it.hasNext()) {
it.next();
if (it.value().values().contains(destItem)) {
return it.key();
}
}
@ -163,11 +164,11 @@ void AbstractPluginsController::startLoader(PluginLoader *loader)
{
connect(loader, &PluginLoader::finished, loader, &PluginLoader::deleteLater, Qt::QueuedConnection);
connect(loader, &PluginLoader::pluginFounded, this, [ = ](const QString &pluginFile){
QPair<QString, PluginsItemInterface *> pair;
pair.first = pluginFile;
pair.second = nullptr;
m_pluginLoadMap.insert(pair, false);
});
QPair<QString, PluginsItemInterface *> pair;
pair.first = pluginFile;
pair.second = nullptr;
m_pluginLoadMap.insert(pair, false);
});
connect(loader, &PluginLoader::pluginFounded, this, &AbstractPluginsController::loadPlugin, Qt::QueuedConnection);
int delay = Utils::SettingValue("com.deepin.dde.dock", "/com/deepin/dde/dock/", "delay-plugins-time", 0).toInt();
@ -200,9 +201,9 @@ void AbstractPluginsController::loadPlugin(const QString &pluginFile)
bool pluginIsValid = true;
if (pluginApi.isEmpty() || !CompatiblePluginApiList.contains(pluginApi)) {
qDebug() << objectName()
<< "plugin api version not matched! expect versions:" << CompatiblePluginApiList
<< ", got version:" << pluginApi
<< ", the plugin file is:" << pluginFile;
<< "plugin api version not matched! expect versions:" << CompatiblePluginApiList
<< ", got version:" << pluginApi
<< ", the plugin file is:" << pluginFile;
pluginIsValid = false;
}
@ -240,18 +241,22 @@ void AbstractPluginsController::loadPlugin(const QString &pluginFile)
}
}
for (auto &pair: m_pluginLoadMap.keys()) {
if (pair.first == pluginFile) {
m_pluginLoadMap.remove(pair);
QPair<QString, PluginsItemInterface *> newPair;
newPair.first = pluginFile;
newPair.second = interface;
m_pluginLoadMap.insert(newPair, false);
QMapIterator<QPair<QString, PluginsItemInterface *>, bool> it(m_pluginLoadMap);
while (it.hasNext()) {
it.next();
if (it.key().first == pluginFile) {
break;
}
}
if (it.hasNext()) {
m_pluginLoadMap.remove(it.key());
QPair<QString, PluginsItemInterface *> newPair;
newPair.first = pluginFile;
newPair.second = interface;
m_pluginLoadMap.insert(newPair, false);
}
// 保存 PluginLoader 对象指针
QMap<QString, QObject *> interfaceData;
interfaceData["pluginloader"] = pluginLoader;
@ -260,7 +265,7 @@ void AbstractPluginsController::loadPlugin(const QString &pluginFile)
if (!dbusService.isEmpty() && !m_dbusDaemonInterface->isServiceRegistered(dbusService).value()) {
qDebug() << objectName() << dbusService << "daemon has not started, waiting for signal";
connect(m_dbusDaemonInterface, &QDBusConnectionInterface::serviceOwnerChanged, this,
[ = ](const QString & name, const QString & oldOwner, const QString & newOwner) {
[ = ](const QString & name, const QString & oldOwner, const QString & newOwner) {
Q_UNUSED(oldOwner);
if (name == dbusService && !newOwner.isEmpty()) {
qDebug() << objectName() << dbusService << "daemon started, init plugin and disconnect";
@ -268,7 +273,7 @@ void AbstractPluginsController::loadPlugin(const QString &pluginFile)
disconnect(m_dbusDaemonInterface);
}
}
);
);
return;
}

View File

@ -1,65 +0,0 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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
* 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 "imagefactory.h"
#include <QDebug>
#include <QPainter>
ImageFactory::ImageFactory(QObject *parent)
: QObject(parent)
{
}
QPixmap ImageFactory::lighterEffect(const QPixmap pixmap, const int delta)
{
if (pixmap.isNull()) {
return pixmap;
}
QImage image = pixmap.toImage();
const int width = image.width();
const int height = image.height();
const int bytesPerPixel = image.bytesPerLine() / image.width();
for (int i(0); i != height; ++i)
{
uchar *scanLine = image.scanLine(i);
for (int j(0); j != width; ++j)
{
QRgb &rgba = *(QRgb*)scanLine;
if (qAlpha(rgba) == 0xff) {
rgba = QColor::fromRgba(rgba).light(delta).rgba();
// const QColor hsv = QColor::fromRgba(rgba).toHsv();
// // check brightness first, color with max brightness processed with lighter will
// // become white like color which will ruin the whole image in general cases.
// if (hsv.value() < 255) {
// rgba = QColor::fromRgba(rgba).lighter(delta).rgba();
// }
}
scanLine += bytesPerPixel;
}
}
return QPixmap::fromImage(image);
}

View File

@ -1,39 +0,0 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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
* 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/>.
*/
#ifndef IMAGEFACTORY_H
#define IMAGEFACTORY_H
#include <QObject>
#include <QPixmap>
#include <QImage>
class ImageFactory : public QObject
{
Q_OBJECT
public:
explicit ImageFactory(QObject *parent = 0);
static QPixmap lighterEffect(const QPixmap pixmap, const int delta = 120);
};
#endif // IMAGEFACTORY_H

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
* kirigaya <kirigaya@mkacg.com>
* Hualet <mr.asianwang@gmail.com>
*
* Maintainer: sbw <sbw@sbw.so>
* kirigaya <kirigaya@mkacg.com>
* Hualet <mr.asianwang@gmail.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 3 of the License, or
* 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 "monitor.h"
Monitor::Monitor(QObject *parent)
: QObject(parent)
, m_x(0)
, m_y(0)
, m_w(0)
, m_h(0)
, m_enable(false)
{
}
void Monitor::setX(const int x)
{
if (m_x == x)
return;
m_x = x;
Q_EMIT geometryChanged();
}
void Monitor::setY(const int y)
{
if (m_y == y)
return;
m_y = y;
Q_EMIT geometryChanged();
}
void Monitor::setW(const int w)
{
if (m_w == w)
return;
m_w = w;
Q_EMIT geometryChanged();
}
void Monitor::setH(const int h)
{
if (m_h == h)
return;
m_h = h;
Q_EMIT geometryChanged();
}
void Monitor::setName(const QString &name)
{
qDebug() << "screen name change from :" << m_name << " to: " << name;
m_name = name;
Q_EMIT nameChanged(m_name);
}
void Monitor::setPath(const QString &path)
{
m_path = path;
}
bool compareResolution(const Resolution &first, const Resolution &second)
{
long firstSum = long(first.width()) * first.height();
long secondSum = long(second.width()) * second.height();
if (firstSum > secondSum)
return true;
else if (firstSum == secondSum) {
if (first.rate() - second.rate() > 0.000001)
return true;
else
return false;
} else
return false;
}
void Monitor::setMonitorEnable(bool enable)
{
if (m_enable == enable)
return;
m_enable = enable;
Q_EMIT enableChanged(enable);
}

View File

@ -1,131 +0,0 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
* kirigaya <kirigaya@mkacg.com>
* Hualet <mr.asianwang@gmail.com>
*
* Maintainer: sbw <sbw@sbw.so>
* kirigaya <kirigaya@mkacg.com>
* Hualet <mr.asianwang@gmail.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 3 of the License, or
* 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/>.
*/
#ifndef MONITOR_H
#define MONITOR_H
#include "constants.h"
#include <QObject>
#include <QDebug>
#include <com_deepin_daemon_display_monitor.h>
using MonitorInter = com::deepin::daemon::display::Monitor;
using namespace Dock;
class Monitor : public QObject
{
Q_OBJECT
public:
struct DockPosition {
// 左、上、右、下
bool leftDock = true;
bool topDock = true;
bool rightDock = true;
bool bottomDock = true;
DockPosition(bool l = true, bool t = true, bool r = true, bool b = true)
{
qDebug() << leftDock << topDock << rightDock << bottomDock;
leftDock = l;
topDock = t;
rightDock = r;
bottomDock = b;
}
bool docked(const Position &pos)
{
switch (pos) {
case Position::Top:
return topDock;
case Position::Bottom:
return bottomDock;
case Position::Left:
return leftDock;
case Position::Right:
return rightDock;
}
Q_UNREACHABLE();
}
void reset()
{
leftDock = true;
topDock = true;
rightDock = true;
bottomDock = true;
}
};
public:
explicit Monitor(QObject *parent = nullptr);
inline int x() const { return m_x; }
inline int y() const { return m_y; }
inline int w() const { return m_w; }
inline int h() const { return m_h; }
inline int left() const { return m_x; }
inline int right() const { return m_x + m_w; }
inline int top() const { return m_y; }
inline int bottom() const { return m_y + m_h; }
inline QPoint topLeft() const { return QPoint(m_x, m_y); }
inline QPoint topRight() const { return QPoint(m_x + m_w, m_y); }
inline QPoint bottomLeft() const { return QPoint(m_x, m_y + m_h); }
inline QPoint bottomRight() const { return QPoint(m_x + m_w, m_y + m_h); }
inline const QRect rect() const { return QRect(m_x, m_y, m_w, m_h); }
inline const QString name() const { Q_ASSERT(!m_name.isEmpty()); return m_name; }
inline const QString path() const { return m_path; }
inline bool enable() const { return m_enable; }
inline void setDockPosition(const DockPosition &position) { m_dockPosition = position; }
inline DockPosition &dockPosition() { return m_dockPosition; }
Q_SIGNALS:
void geometryChanged() const;
void enableChanged(bool enable) const;
void nameChanged(const QString &name) const;
public Q_SLOTS:
void setX(const int x);
void setY(const int y);
void setW(const int w);
void setH(const int h);
void setName(const QString &name);
void setPath(const QString &path);
void setMonitorEnable(bool enable);
private:
int m_x;
int m_y;
int m_w;
int m_h;
QString m_name;
QString m_path;
bool m_enable;
DockPosition m_dockPosition;
};
#endif // MONITOR_H

View File

@ -1199,19 +1199,6 @@ void MultiScreenWorker::changeDockPosition(QString fromScreen, QString toScreen,
group->start(QVariantAnimation::DeleteWhenStopped);
}
/**
* @brief updateDockScreenName ,,
* @param screenName
*/
void MultiScreenWorker::updateDockScreenName(const QString &screenName)
{
Q_UNUSED(screenName);
m_ds.updateDockedScreen(screenName);
qInfo() << "update dock screen: " << m_ds.current();
}
/**
* @brief getValidScreen 使
* @return

View File

@ -23,7 +23,6 @@
#define MULTISCREENWORKER_H
#include "constants.h"
#include "monitor.h"
#include "utils.h"
#include "dockitem.h"
#include "xcb_misc.h"
@ -37,6 +36,7 @@
#include <DWindowManagerHelper>
#include <QObject>
#include <QFlag>
#define WINDOWMARGIN ((m_displayMode == Dock::Efficient) ? 0 : 10)
#define ANIMATIONTIME 300
@ -128,7 +128,7 @@ public:
RunState_Mask = 0xffffffff,
};
Q_DECLARE_FLAGS(RunStates, RunState)
typedef QFlags<RunState> RunStates;
MultiScreenWorker(QWidget *parent, DWindowManagerHelper *helper);
~MultiScreenWorker();
@ -223,7 +223,6 @@ private:
void tryToShowDock(int eventX, int eventY);
void changeDockPosition(QString lastScreen, QString deskScreen, const Position &fromPos, const Position &toPos);
void updateDockScreenName(const QString &screenName);
QString getValidScreen(const Position &pos);
void resetDockScreen();

View File

@ -52,7 +52,8 @@ private:
QPoint m_resizePoint;
public:
DragWidget(QWidget *parent = nullptr) : QWidget(parent)
explicit DragWidget(QWidget *parent = nullptr)
: QWidget(parent)
{
setObjectName("DragWidget");
m_dragStatus = false;

View File

@ -72,7 +72,6 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
device->setDeviceType(bluetoothDeviceType);
m_devices[id] = device;
divideDevice(device);
emit deviceAdded(device);
}
@ -83,7 +82,6 @@ void Adapter::removeDevice(const QString &deviceId)
auto device = const_cast<Device *>(constDevice);
if (device) {
m_devices.remove(deviceId);
m_paredDev.remove(deviceId);
emit deviceRemoved(device);
delete device;
}
@ -120,37 +118,6 @@ void Adapter::updateDevice(const QJsonObject &dviceJson)
}
}
//void Adapter::removeAllDevices()
//{
// QMapIterator<QString, const Device *> iterator(m_devices);
// while (iterator.hasNext()) {
// iterator.next();
// auto device = const_cast<Device *>(iterator.value());
// if (device) {
// m_devices.remove(device->id());
// m_paredDev.remove(device->id());
// delete device;
// }
// }
//}
const QMap<QString, const Device *> &Adapter::paredDevices() const
{
return m_paredDev;
}
//int Adapter::paredDevicesCount() const
//{
// return m_paredDev.size();
//}
void Adapter::divideDevice(const Device *device)
{
if (device->paired()) {
m_paredDev[device->id()] = device;
}
}
void Adapter::setPowered(bool powered)
{
if (powered != m_powered) {
@ -186,7 +153,6 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
device->setDeviceType(bluetoothDeviceType);
m_devices[id] = device;
divideDevice(device);
}
}

View File

@ -55,9 +55,6 @@ public:
void addDevice(const QJsonObject &deviceObj);
void removeDevice(const QString &deviceId);
void updateDevice(const QJsonObject &dviceJson);
// void removeAllDevices();
const QMap<QString, const Device *> &paredDevices() const;
// int paredDevicesCount() const;
Q_SIGNALS:
void nameChanged(const QString &name) const;
@ -67,9 +64,6 @@ Q_SIGNALS:
void poweredChanged(const bool powered) const;
void discoveringChanged(const bool discover) const;
private:
void divideDevice(const Device *device);
private:
QString m_id;
QString m_name;
@ -78,7 +72,6 @@ private:
bool m_discover;
QMap<QString, const Device *> m_devices;
QMap<QString, const Device *> m_paredDev;
};
#endif // ADAPTER_H

View File

@ -35,7 +35,6 @@ AdaptersManager::AdaptersManager(QObject *parent)
"/com/deepin/daemon/Bluetooth",
QDBusConnection::sessionBus(),
this))
, m_defaultAdapterState(false)
{
connect(m_bluetoothInter, &DBusBluetooth::AdapterAdded, this, &AdaptersManager::onAddAdapter);
connect(m_bluetoothInter, &DBusBluetooth::AdapterRemoved, this, &AdaptersManager::onRemoveAdapter);
@ -78,7 +77,6 @@ AdaptersManager::AdaptersManager(QObject *parent)
for (int index = 0; index < arr.size(); index++) {
auto *adapter = new Adapter(this);
adapterAdd(adapter, arr[index].toObject());
m_defaultAdapterState |= adapter->powered();
}
}
@ -102,11 +100,11 @@ void AdaptersManager::setAdapterPowered(const Adapter *adapter, const bool &powe
}
});
} else {
QDBusPendingCall call = m_bluetoothInter->ClearUnpairedDevice();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
QDBusPendingCall clearUnpairedCall = m_bluetoothInter->ClearUnpairedDevice();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(clearUnpairedCall, this);
connect(watcher, &QDBusPendingCallWatcher::finished, [ = ] {
if (call.isError())
qWarning() << call.error().message();
if (clearUnpairedCall.isError())
qWarning() << clearUnpairedCall.error().message();
});
}
}
@ -132,11 +130,6 @@ void AdaptersManager::connectDevice(const Device *device, Adapter *adapter)
}
}
bool AdaptersManager::defaultAdapterInitPowerState()
{
return m_defaultAdapterState;
}
int AdaptersManager::adaptersCount()
{
return m_adapters.size();

View File

@ -36,7 +36,6 @@ public:
void setAdapterPowered(const Adapter *adapter, const bool &powered);
void connectDevice(const Device *device, Adapter *adapter);
bool defaultAdapterInitPowerState();
int adaptersCount();
void adapterRefresh(const Adapter *adapter);
void disconnectDevice(Device *device);
@ -62,7 +61,6 @@ private:
private:
DBusBluetooth *m_bluetoothInter;
QMap<QString, const Adapter *> m_adapters;
bool m_defaultAdapterState;
};
#endif // ADAPTERSMANAGER_H

View File

@ -363,7 +363,7 @@ void BluetoothAdapterItem::setUnnamedDevicesVisible(bool isShow)
if (isShow) {
// 计算已连接蓝牙设备数
int connectCount = 0;
for (i = m_deviceItems.begin(); i != m_deviceItems.end(); i++) {
for (i = m_deviceItems.begin(); i != m_deviceItems.end(); ++i) {
BluetoothDeviceItem *deviceItem = i.value();
if (deviceItem && deviceItem->device() && deviceItem->device()->paired()
@ -372,7 +372,7 @@ void BluetoothAdapterItem::setUnnamedDevicesVisible(bool isShow)
}
// 显示所有蓝牙设备
for (i = m_deviceItems.begin(); i != m_deviceItems.end(); i++) {
for (i = m_deviceItems.begin(); i != m_deviceItems.end(); ++i) {
BluetoothDeviceItem *deviceItem = i.value();
if (deviceItem && deviceItem->device() && deviceItem->device()->name().isEmpty()) {
@ -388,7 +388,7 @@ void BluetoothAdapterItem::setUnnamedDevicesVisible(bool isShow)
}
for (i = m_deviceItems.begin(); i != m_deviceItems.end(); i++) {
for (i = m_deviceItems.begin(); i != m_deviceItems.end(); ++i) {
BluetoothDeviceItem *deviceItem = i.value();
// 将名称为空的蓝牙设备过滤,如果蓝牙正在连接或者已连接不过滤

View File

@ -22,6 +22,7 @@
#include "device.h"
#include <DStyleHelper>
#include <QDateTime>
QMap<QString, QString> Device::deviceType2Icon = {
@ -52,18 +53,12 @@ Device::Device(QObject *parent)
, m_state(StateUnavailable)
, m_connectState(false)
{
m_time = static_cast<int>(QDateTime::currentDateTime().toTime_t());
}
Device::~Device()
{
}
void Device::updateDeviceTime()
{
m_time = static_cast<int>(QDateTime::currentDateTime().toTime_t());
}
void Device::setId(const QString &id)
{
m_id = id;
@ -109,22 +104,6 @@ void Device::setConnectState(const bool connectState)
}
}
void Device::setTrusted(bool trusted)
{
if (trusted != m_trusted) {
m_trusted = trusted;
Q_EMIT trustedChanged(trusted);
}
}
void Device::setConnecting(bool connecting)
{
if (connecting != m_connecting) {
m_connecting = connecting;
Q_EMIT connectingChanged(connecting);
}
}
void Device::setRssi(int rssi)
{
if (m_rssi != rssi) {

View File

@ -64,10 +64,8 @@ public:
void setConnectState(const bool connectState);
inline bool trusted() const { return m_trusted; }
void setTrusted(bool trusted);
inline bool connecting() const { return m_connecting; }
void setConnecting(bool connecting);
inline int rssi() const { return m_rssi; }
void setRssi(int rssi);
@ -78,17 +76,12 @@ public:
inline QString deviceType() const { return m_deviceType; }
void setDeviceType(const QString &deviceType);
inline int deviceTime() const { return m_time; }
void updateDeviceTime();
Q_SIGNALS:
void nameChanged(const QString &name) const;
void aliasChanged(const QString &alias) const;
void pairedChanged(const bool paired) const;
void stateChanged(const State state) const;
void connectStateChanged(const bool connectState) const;
void trustedChanged(const bool trusted) const;
void connectingChanged(const bool &connecting) const;
void rssiChanged(const int rssi) const;
private:
@ -103,7 +96,6 @@ private:
bool m_connectState;
QString m_adapterId;
QString m_deviceType;
int m_time;
};
QDebug &operator<<(QDebug &stream, const Device *device);

View File

@ -40,7 +40,7 @@ class DBusAdaptors : public QDBusAbstractAdaptor
// "")
public:
DBusAdaptors(QObject *parent = nullptr);
explicit DBusAdaptors(QObject *parent = nullptr);
~DBusAdaptors();
public:

View File

@ -519,16 +519,16 @@ QString NetworkItem::getStrengthStateString(int strength)
{
if (5 >= strength)
return "0";
else if (5 < strength && 30 >= strength)
else if (30 >= strength)
return "20";
else if (30 < strength && 55 >= strength)
else if (55 >= strength)
return "40";
else if (55 < strength && 65 >= strength)
else if (65 >= strength)
return "60";
else if (65 < strength)
return "80";
else
return "0";
return "80";
Q_UNREACHABLE();
}
void NetworkItem::wiredsEnable(bool enable)

View File

@ -79,7 +79,7 @@ public:
{ return "com.deepin.daemon.Accounts"; }
public:
DBusAccount(QObject *parent = 0);
explicit DBusAccount(QObject *parent = 0);
~DBusAccount();

View File

@ -79,7 +79,7 @@ public:
{ return "com.deepin.daemon.Accounts"; }
public:
DBusAccount(QObject *parent = 0);
explicit DBusAccount(QObject *parent = 0);
~DBusAccount();

View File

@ -34,6 +34,7 @@
#include <QIcon>
#include <QScrollBar>
#include <QPainter>
#include <QListIterator>
#define SEPARATOR_HEIGHT 2
#define WIDTH 260
@ -130,45 +131,8 @@ SoundApplet::SoundApplet(QWidget *parent)
initUi();
}
///**
// * @brief SoundApplet::setControlBackground 设置音频界面控件背景颜色
// */
//void SoundApplet::setControlBackground()
//{
// QPalette soundAppletBackgroud;
// QPalette listViewBackgroud = m_listView->palette();
// if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
// soundAppletBackgroud.setColor(QPalette::Background, QColor(255, 255, 255, 0.03 * 255));
// else
// soundAppletBackgroud.setColor(QPalette::Background, QColor(0, 0, 0, 0.03 * 255));
// this->setAutoFillBackground(true);
// this->setPalette(soundAppletBackgroud);
// listViewBackgroud.setColor(QPalette::Base, Qt::transparent);
// m_listView->setAutoFillBackground(true);
// m_listView->setPalette(listViewBackgroud);
//}
///**
// * @brief SoundApplet::setItemHoverColor 通过代理方式根据当前主题设置音频列表文字颜色和item选中颜色
// */
//void SoundApplet::setItemHoverColor()
//{
// QPalette hoverBackgroud = m_listView->palette();
// if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
// hoverBackgroud.setColor(QPalette::Normal, QPalette::Highlight, QColor(0, 0, 0, 30));
// hoverBackgroud.setColor(QPalette::Normal, QPalette::HighlightedText, QColor(0, 0, 0, 255));
// } else {
// hoverBackgroud.setColor(QPalette::Normal, QPalette::Highlight, QColor(255, 255, 255, 30));
// hoverBackgroud.setColor(QPalette::Normal, QPalette::HighlightedText, QColor(255, 255, 255, 255));
// }
// m_listView->setPalette(hoverBackgroud);
// m_listView->setItemDelegate(m_itemDelegate);
//}
void SoundApplet::initUi()
{
// setControlBackground();
m_listView->setFrameShape(QFrame::NoFrame);
m_listView->setEditTriggers(DListView::NoEditTriggers);
m_listView->setSelectionMode(QAbstractItemView::NoSelection);
@ -260,7 +224,7 @@ void SoundApplet::initUi()
});
connect(qApp, &QGuiApplication::fontChanged, this, &SoundApplet::updateListHeight);
connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SoundApplet::volumeSliderValueChanged);
connect(m_audioInter, &DBusAudio::DefaultSinkChanged, this, static_cast<void (SoundApplet::*)()>(&SoundApplet::defaultSinkChanged));
connect(m_audioInter, &DBusAudio::DefaultSinkChanged, this, &SoundApplet::onDefaultSinkChanged);
connect(m_audioInter, &DBusAudio::IncreaseVolumeChanged, this, &SoundApplet::increaseVolumeChanged);
connect(m_audioInter, &DBusAudio::PortEnabledChanged, [this](uint cardId, QString portId) {
portEnableChange(cardId, portId);
@ -279,7 +243,7 @@ void SoundApplet::initUi()
QDBusConnection::sessionBus().connect("com.deepin.daemon.Audio", "/com/deepin/daemon/Audio", "org.freedesktop.DBus.Properties"
,"PropertiesChanged", "sa{sv}as", this, SLOT(haldleDbusSignal(QDBusMessage)));
QMetaObject::invokeMethod(this, "defaultSinkChanged", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "onDefaultSinkChanged", Qt::QueuedConnection);
refreshIcon();
@ -301,7 +265,7 @@ VolumeSlider *SoundApplet::mainSlider()
return m_volumeSlider;
}
void SoundApplet::defaultSinkChanged()
void SoundApplet::onDefaultSinkChanged()
{
//防止手动切换设备,与后端交互时,获取到多个信号,设备切换多次,造成混乱
QThread::msleep(200);
@ -388,7 +352,7 @@ void SoundApplet::cardsChanged(const QString &cards)
tmpCardIds.insert(cardId, tmpPorts);
}
defaultSinkChanged();//重新获取切换的设备信息
onDefaultSinkChanged();//重新获取切换的设备信息
enableDevice(true);
for (Port *port : m_ports) {
@ -495,10 +459,12 @@ bool SoundApplet::containsPort(const Port *port)
Port *SoundApplet::findPort(const QString &portId, const uint &cardId) const
{
for (Port *port : m_ports) {
if (port->id() == portId && port->cardId() == cardId) {
return port;
}
auto it = std::find_if(m_ports.begin(), m_ports.end(), [ = ] (Port *p) {
return (p->id() == portId && p->cardId() == cardId);
});
if (it != m_ports.end()) {
return *it;
}
return nullptr;

View File

@ -118,7 +118,7 @@ signals:
void defaultSinkChanged(DBusSink *sink) const;
private slots:
void defaultSinkChanged();
void onDefaultSinkChanged();
void onVolumeChanged(double volume);
void volumeSliderValueChanged();
void increaseVolumeChanged();

View File

@ -54,7 +54,7 @@ SoundItem::SoundItem(QWidget *parent)
m_applet->setVisible(false);
connect(m_applet, static_cast<void (SoundApplet::*)(DBusSink *) const>(&SoundApplet::defaultSinkChanged), this, &SoundItem::sinkChanged);
connect(m_applet, &SoundApplet::defaultSinkChanged, this, &SoundItem::sinkChanged);
connect(m_applet, &SoundApplet::volumeChanged, this, &SoundItem::refresh, Qt::QueuedConnection);
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [ = ] {

View File

@ -39,10 +39,8 @@ public:
virtual ~AbstractTrayWidget();
virtual QString itemKeyForConfig() = 0;
virtual void setActive(const bool active) = 0;
virtual void updateIcon() = 0;
virtual void sendClick(uint8_t mouseButton, int x, int y) = 0;
virtual const QImage trayImage() = 0;
virtual inline TrayType trayTyep() const { return TrayType::ApplicationTray; } // default is ApplicationTray
virtual bool isValid() {return true;}

View File

@ -29,7 +29,6 @@ AbstractContainer::AbstractContainer(TrayPlugin *trayPlugin, QWidget *parent)
, m_currentDraggingWrapper(nullptr)
, m_expand(true)
, m_dockPosition(Dock::Position::Bottom)
// , m_wrapperSize(QSize(PLUGIN_BACKGROUND_MAX_SIZE, PLUGIN_BACKGROUND_MAX_SIZE))
{
setAcceptDrops(true);
@ -230,22 +229,12 @@ int AbstractContainer::itemCount()
bool AbstractContainer::containsWrapper(FashionTrayWidgetWrapper *wrapper)
{
for (auto w : m_wrapperList) {
if (w == wrapper) {
return true;
}
}
return false;
return m_wrapperList.contains(wrapper);
}
bool AbstractContainer::containsWrapperByTrayWidget(AbstractTrayWidget *trayWidget)
{
if (wrapperByTrayWidget(trayWidget)) {
return true;
}
return false;
return wrapperByTrayWidget(trayWidget);
}
FashionTrayWidgetWrapper *AbstractContainer::wrapperByTrayWidget(AbstractTrayWidget *trayWidget)

View File

@ -169,8 +169,6 @@ void FashionTrayItem::onExpandChanged(const bool expand)
{
m_trayPlugin->saveValue(FASHION_MODE_ITEM_KEY, ExpandedKey, expand);
// refreshHoldContainerPosition();
m_normalContainer->setExpand(expand);
m_attentionContainer->setExpand(expand);
@ -292,20 +290,6 @@ void FashionTrayItem::requestResize()
resizeTray();
}
void FashionTrayItem::refreshHoldContainerPosition()
{
m_mainBoxLayout->removeWidget(m_holdContainer);
int destIndex = 0;
if (m_controlWidget->expanded()) {
destIndex = m_mainBoxLayout->indexOf(m_controlWidget);
} else {
destIndex = m_mainBoxLayout->indexOf(m_attentionContainer);
}
m_mainBoxLayout->insertWidget(destIndex, m_holdContainer);
}
void FashionTrayItem::onRequireDraggingWrapper()
{
AbstractContainer *container = dynamic_cast<AbstractContainer *>(sender());

View File

@ -77,7 +77,6 @@ private Q_SLOTS:
void attentionWrapperToNormalWrapper();
void normalWrapperToAttentionWrapper(FashionTrayWidgetWrapper *wrapper);
void requestResize();
void refreshHoldContainerPosition();
void onRequireDraggingWrapper();
private:

View File

@ -67,21 +67,11 @@ QString IndicatorTrayWidget::itemKeyForConfig()
return toIndicatorKey(m_indicatorName);
}
void IndicatorTrayWidget::setActive(const bool)
{
}
void IndicatorTrayWidget::updateIcon()
{
}
const QImage IndicatorTrayWidget::trayImage()
{
return m_label->grab().toImage();
}
void IndicatorTrayWidget::sendClick(uint8_t buttonIndex, int x, int y)
{
Q_EMIT clicked(buttonIndex, x, y);
@ -94,11 +84,6 @@ void IndicatorTrayWidget::setPixmapData(const QByteArray &data)
m_label->setPixmap(rawPixmap);
}
void IndicatorTrayWidget::setPixmapPath(const QString &text)
{
m_label->setPixmap(QPixmap(text));
}
void IndicatorTrayWidget::setText(const QString &text)
{
m_label->setText(text);

View File

@ -34,16 +34,13 @@ public:
~IndicatorTrayWidget();
QString itemKeyForConfig() override;
void setActive(const bool active) override;
void updateIcon() override;
const QImage trayImage() override;
void sendClick(uint8_t, int, int) override;
static QString toIndicatorKey(const QString &indicatorName) { return QString("indicator:%1").arg(indicatorName); }
static bool isIndicatorKey(const QString &itemKey) { return itemKey.startsWith("indicator:"); }
public Q_SLOTS:
Q_SCRIPTABLE void setPixmapData(const QByteArray &data);
Q_SCRIPTABLE void setPixmapPath(const QString &text);
Q_SCRIPTABLE void setText(const QString &text);
Q_SIGNALS:

View File

@ -168,10 +168,6 @@ QString SNITrayWidget::itemKeyForConfig()
return QString("sni:%1").arg(key);
}
void SNITrayWidget::setActive(const bool active)
{
}
void SNITrayWidget::updateIcon()
{
m_updateIconTimer->start();
@ -200,11 +196,6 @@ void SNITrayWidget::sendClick(uint8_t mouseButton, int x, int y)
}
}
const QImage SNITrayWidget::trayImage()
{
return m_pixmap.toImage();
}
bool SNITrayWidget::isValid()
{
return m_sniInter->isValid();

View File

@ -56,10 +56,8 @@ public:
SNITrayWidget(const QString &sniServicePath, QWidget *parent = Q_NULLPTR);
QString itemKeyForConfig() override;
void setActive(const bool active) override;
void updateIcon() override;
void sendClick(uint8_t mouseButton, int x, int y) override;
const QImage trayImage() override;
bool isValid() override;
SNITrayWidget::ItemStatus status();

View File

@ -96,21 +96,11 @@ QString SystemTrayItem::itemKeyForConfig()
return m_itemKey;
}
void SystemTrayItem::setActive(const bool active)
{
Q_UNUSED(active);
}
void SystemTrayItem::updateIcon()
{
m_pluginInter->refreshIcon(m_itemKey);
}
const QImage SystemTrayItem::trayImage()
{
return QImage();
}
void SystemTrayItem::sendClick(uint8_t mouseButton, int x, int y)
{
Q_UNUSED(mouseButton);

View File

@ -41,9 +41,7 @@ public:
public:
QString itemKeyForConfig() override;
void setActive(const bool active) override;
void updateIcon() override;
const QImage trayImage() override;
void sendClick(uint8_t mouseButton, int x, int y) override;
inline TrayType trayTyep() const override { return TrayType::SystemTray; }

View File

@ -47,7 +47,7 @@ class TrayPlugin : public QObject, PluginsItemInterface
Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "tray.json")
public:
explicit TrayPlugin(QObject *parent = 0);
explicit TrayPlugin(QObject *parent = nullptr);
const QString pluginName() const override;
void init(PluginProxyInterface *proxyInter) override;

View File

@ -109,11 +109,6 @@ QString XEmbedTrayWidget::itemKeyForConfig()
return QString("window:%1").arg(getAppNameForWindow(m_windowId));
}
const QImage XEmbedTrayWidget::trayImage()
{
return m_image;
}
void XEmbedTrayWidget::showEvent(QShowEvent *e)
{
QWidget::showEvent(e);
@ -387,12 +382,6 @@ bool XEmbedTrayWidget::isXEmbedKey(const QString &itemKey)
return itemKey.startsWith("window:");
}
void XEmbedTrayWidget::setActive(const bool active)
{
m_active = active;
m_updateTimer->start();
}
void XEmbedTrayWidget::refershIconImage()
{
const auto ratio = devicePixelRatioF();

View File

@ -37,8 +37,6 @@ public:
QString itemKeyForConfig() override;
void updateIcon() override;
void setActive(const bool active) override;
const QImage trayImage() override;
void sendClick(uint8_t mouseButton, int x, int y) override;
static QString getWindowProperty(quint32 winId, QString propName);

View File

@ -72,7 +72,6 @@ TEST_F(Test_DockItemManager, get_method_test)
TEST_F(Test_DockItemManager, refreshItemsIcon_test)
{
manager->refreshItemsIcon();
manager->sortPluginItems();
}
TEST_F(Test_DockItemManager, cover_test)

View File

@ -1,60 +0,0 @@
/*
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
*
* Author: fanpengcheng <fanpengcheng@uniontech.com>
*
* Maintainer: fanpengcheng <fanpengcheng@uniontech.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 3 of the License, or
* 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 <QObject>
#include <QThread>
#include <QTest>
#include <QSignalSpy>
#include <QThread>
#include <gtest/gtest.h>
#define private public
#include "hoverhighlighteffect.h"
#undef private
class Test_HoverHighlightEffect : public ::testing::Test
{
public:
virtual void SetUp() override;
virtual void TearDown() override;
public:
HoverHighlightEffect *effect = nullptr;
};
void Test_HoverHighlightEffect::SetUp()
{
effect = new HoverHighlightEffect();
}
void Test_HoverHighlightEffect::TearDown()
{
delete effect;
effect = nullptr;
}
TEST_F(Test_HoverHighlightEffect, test)
{
effect->setHighlighting(true);
ASSERT_EQ(effect->m_highlighting, true) ;
effect->setHighlighting(false);
ASSERT_EQ(effect->m_highlighting, false) ;
}

View File

@ -1,63 +0,0 @@
/*
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
*
* Author: fanpengcheng <fanpengcheng@uniontech.com>
*
* Maintainer: fanpengcheng <fanpengcheng@uniontech.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 3 of the License, or
* 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 <QObject>
#include <QApplication>
#include <QSignalSpy>
#include <QTest>
#include <gtest/gtest.h>
#include "imagefactory.h"
class Test_ImageFactory : public QObject, public ::testing::Test
{
public:
virtual void SetUp() override;
virtual void TearDown() override;
public:
ImageFactory *factory = nullptr;
};
void Test_ImageFactory::SetUp()
{
factory = new ImageFactory();
}
void Test_ImageFactory::TearDown()
{
delete factory;
factory = nullptr;
}
TEST_F(Test_ImageFactory, factory_test)
{
QPixmap pix(":/res/all_settings_on.png");
// 以下是无效值,应该屏蔽才对
factory->lighterEffect(pix, -1);
factory->lighterEffect(pix, 256);
// 传入空的pixmap对象
QPixmap emptyPix;
factory->lighterEffect(emptyPix, 150);
}

View File

@ -1,138 +0,0 @@
/*
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
*
* Author: chenjun <chenjun@uniontech.com>
*
* Maintainer: chenjun <chenjun@uniontech.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 3 of the License, or
* 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 <QObject>
#include <QThread>
#include <QTest>
#include <gtest/gtest.h>
#include "monitor.h"
//因为GTest不能断言自定义结构数据需要重载<<和==操作符
std::ostream & operator<<(std::ostream & os, const Monitor::DockPosition & dockPosition) {
return os << "leftDock = "
<< dockPosition.leftDock
<< " rightDock = "
<< dockPosition.rightDock
<< "topDock = "
<< dockPosition.topDock
<< " bottomDock = "
<< dockPosition.bottomDock;
}
bool operator==(const Monitor::DockPosition & p1, const Monitor::DockPosition & p2) {
return p1.leftDock == p2.leftDock && p1.rightDock == p2.rightDock && p1.topDock == p2.topDock && p1.bottomDock == p2.bottomDock;
}
class Test_Monitor : public ::testing::Test
{
public:
virtual void SetUp() override;
virtual void TearDown() override;
public:
Monitor *monitor = nullptr;
};
void Test_Monitor::SetUp()
{
monitor = new Monitor();
}
void Test_Monitor::TearDown()
{
delete monitor;
monitor = nullptr;
}
TEST_F(Test_Monitor, monitor_test)
{
ASSERT_NE(monitor, nullptr);
int x = 10;
int y = 10;
int w = 100;
int h = 100;
monitor->setX(x);
QCOMPARE(monitor->x(), x);
monitor->setX(x);
monitor->setY(y);
QCOMPARE(monitor->y(), y);
monitor->setY(y);
monitor->setW(w);
QCOMPARE(monitor->w(), w);
monitor->setW(w);
monitor->setH(h);
QCOMPARE(monitor->h(), h);
monitor->setH(h);
QCOMPARE(monitor->left(), x);
QCOMPARE(monitor->right(), x + w);
QCOMPARE(monitor->top(), y);
QCOMPARE(monitor->bottom(), y + h);
QCOMPARE(monitor->topLeft(), QPoint(x, y));
QCOMPARE(monitor->topRight(), QPoint(x + w, y));
QCOMPARE(monitor->bottomLeft(), QPoint(x, y + h));
QCOMPARE(monitor->bottomRight(), QPoint(x + w, y + h));
QCOMPARE(monitor->rect(), QRect(x, y, w, h));
QString name = "MonitorTestName";
monitor->setName(name);
QCOMPARE(monitor->name(), name);
QString path = "testPath";
monitor->setPath(path);
QCOMPARE(monitor->path(), path);
bool monitorEnable = true;
monitor->setMonitorEnable(monitorEnable);
QCOMPARE(monitor->enable(), monitorEnable);
monitor->setMonitorEnable(monitorEnable);
Monitor::DockPosition dockPosition;
dockPosition.leftDock = true;
dockPosition.rightDock = true;
dockPosition.topDock = true;
dockPosition.bottomDock = true;
monitor->setDockPosition(dockPosition);
QCOMPARE(monitor->dockPosition(), dockPosition);
}
TEST_F(Test_Monitor, dockPosition_test)
{
monitor->setDockPosition(Monitor::DockPosition(false, false, false, false));
ASSERT_FALSE(monitor->dockPosition().docked(Position::Top));
ASSERT_FALSE(monitor->dockPosition().docked(Position::Bottom));
ASSERT_FALSE(monitor->dockPosition().docked(Position::Left));
ASSERT_FALSE(monitor->dockPosition().docked(Position::Right));
monitor->dockPosition().reset();
ASSERT_TRUE(monitor->dockPosition().docked(Position::Top));
ASSERT_TRUE(monitor->dockPosition().docked(Position::Bottom));
ASSERT_TRUE(monitor->dockPosition().docked(Position::Left));
ASSERT_TRUE(monitor->dockPosition().docked(Position::Right));
}