Skip to content

Commit

Permalink
chore: gui to qt6
Browse files Browse the repository at this point in the history
Log:
  • Loading branch information
Decodetalkers committed Jan 2, 2024
1 parent 4e15f2f commit c22e7f9
Show file tree
Hide file tree
Showing 22 changed files with 163 additions and 165 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ macro(install_symlink filepath wantsdir)
endmacro(install_symlink)

## qm files
file(GLOB QM_FILES "translations/*.qm")
find_package(Qt6LinguistTools REQUIRED)

file(GLOB TS_FILES "translations/*.ts")

qt6_add_translation(QM_FILES ${TS_FILES})

install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/${BIN_NAME}/translations)

configure_file(
Expand Down
19 changes: 14 additions & 5 deletions dbus/types/dockrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "dockrect.h"

#include <QDebug>

DockRect::DockRect()
Expand All @@ -11,15 +12,11 @@ DockRect::DockRect()
, w(0)
, h(0)
{

}

QDebug operator<<(QDebug debug, const DockRect &rect)
{
debug << QString("DockRect(%1, %2, %3, %4)").arg(rect.x)
.arg(rect.y)
.arg(rect.w)
.arg(rect.h);
debug << QString("DockRect(%1, %2, %3, %4)").arg(rect.x).arg(rect.y).arg(rect.w).arg(rect.h);

return debug;
}
Expand Down Expand Up @@ -52,3 +49,15 @@ void registerDockRectMetaType()
qRegisterMetaType<DockRect>("DockRect");
qDBusRegisterMetaType<DockRect>();
}

bool operator==(const DockRect &infoa, const DockRect &rect)
{
bool re = infoa.x == rect.x && infoa.y == rect.y && infoa.h == rect.h && infoa.w == rect.w;
return re;
}

bool operator!=(const DockRect &infoa, const DockRect &rect)
{
bool re = infoa.x == rect.x && infoa.y == rect.y && infoa.h == rect.h && infoa.w == rect.w;
return !re;
}
2 changes: 2 additions & 0 deletions dbus/types/dockrect.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct DockRect
friend QDebug operator<<(QDebug debug, const DockRect &rect);
friend const QDBusArgument &operator>>(const QDBusArgument &arg, DockRect &rect);
friend QDBusArgument &operator<<(QDBusArgument &arg, const DockRect &rect);
friend bool operator==(const DockRect &a, const DockRect &b);
friend bool operator!=(const DockRect &a, const DockRect &b);

private:
int x;
Expand Down
26 changes: 17 additions & 9 deletions dbus/types/screenrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@
#include "screenrect.h"

ScreenRect::ScreenRect()
: x(0),
y(0),
w(0),
h(0)
: x(0)
, y(0)
, w(0)
, h(0)
{

}

QDebug operator<<(QDebug debug, const ScreenRect &rect)
{
debug << QString("ScreenRect(%1, %2, %3, %4)").arg(rect.x)
.arg(rect.y)
.arg(rect.w)
.arg(rect.h);
debug << QString("ScreenRect(%1, %2, %3, %4)").arg(rect.x).arg(rect.y).arg(rect.w).arg(rect.h);

return debug;
}
Expand All @@ -38,6 +34,18 @@ QDBusArgument &operator<<(QDBusArgument &arg, const ScreenRect &rect)
return arg;
}

bool operator==(const ScreenRect &infoa, const ScreenRect &rect)
{
bool re = infoa.x == rect.x && infoa.y == rect.y && infoa.h == rect.h && infoa.w == rect.w;
return re;
}

bool operator!=(const ScreenRect &infoa, const ScreenRect &rect)
{
bool re = infoa.x == rect.x && infoa.y == rect.y && infoa.h == rect.h && infoa.w == rect.w;
return !re;
}

const QDBusArgument &operator>>(const QDBusArgument &arg, ScreenRect &rect)
{
arg.beginStructure();
Expand Down
3 changes: 2 additions & 1 deletion dbus/types/screenrect.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ struct ScreenRect
friend QDebug operator<<(QDebug debug, const ScreenRect &rect);
friend const QDBusArgument &operator>>(const QDBusArgument &arg, ScreenRect &rect);
friend QDBusArgument &operator<<(QDBusArgument &arg, const ScreenRect &rect);

friend bool operator ==(const ScreenRect &infoa, const ScreenRect& info);
friend bool operator !=(const ScreenRect &infoa, const ScreenRect& info);
private:
qint16 x;
qint16 y;
Expand Down
5 changes: 5 additions & 0 deletions dbus/types/touchscreeninfolist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ bool TouchscreenInfo::operator==(const TouchscreenInfo &info)
return id == info.id && name == info.name && deviceNode == info.deviceNode && serialNumber == info.serialNumber;
}

bool TouchscreenInfo::operator==(const TouchscreenInfo &info) const
{
return id == info.id && name == info.name && deviceNode == info.deviceNode && serialNumber == info.serialNumber;
}

void registerTouchscreenInfoMetaType()
{
qRegisterMetaType<TouchscreenInfo>("TouchscreenInfo");
Expand Down
1 change: 1 addition & 0 deletions dbus/types/touchscreeninfolist.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct TouchscreenInfo {
QString serialNumber;

bool operator ==(const TouchscreenInfo& info);
bool operator ==(const TouchscreenInfo& info) const;
};

typedef QList<TouchscreenInfo> TouchscreenInfoList;
Expand Down
9 changes: 8 additions & 1 deletion dbus/types/touchscreeninfolist_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ const QDBusArgument &operator>>(const QDBusArgument &arg, TouchscreenInfo_V2 &in

bool TouchscreenInfo_V2::operator==(const TouchscreenInfo_V2 &info)
{
return id == info.id && name == info.name && deviceNode == info.deviceNode && serialNumber == info.serialNumber && UUID == info.UUID;
return id == info.id && name == info.name && deviceNode == info.deviceNode
&& serialNumber == info.serialNumber && UUID == info.UUID;
}

bool TouchscreenInfo_V2::operator==(const TouchscreenInfo_V2 &info) const
{
return id == info.id && name == info.name && deviceNode == info.deviceNode
&& serialNumber == info.serialNumber && UUID == info.UUID;
}

void registerTouchscreenInfoV2MetaType()
Expand Down
1 change: 1 addition & 0 deletions dbus/types/touchscreeninfolist_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct TouchscreenInfo_V2 {
QString UUID;

bool operator ==(const TouchscreenInfo_V2& info);
bool operator ==(const TouchscreenInfo_V2& info) const;
};

typedef QList<TouchscreenInfo_V2> TouchscreenInfoList_V2;
Expand Down
26 changes: 12 additions & 14 deletions dde-clipboard/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
set(BIN_NAME dde-clipboard)

find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core)
find_package(Qt5 COMPONENTS Gui Widgets DBus Test Concurrent REQUIRED)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
find_package(Qt6 COMPONENTS Gui Widgets DBus Test Concurrent REQUIRED)

find_package(Dtk COMPONENTS Widget Core REQUIRED)
find_package(DtkTools)

pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-qt)
find_package(Dtk6 COMPONENTS Widget Core REQUIRED)
find_package(Dtk6Tools)

file(GLOB_RECURSE Clipboard_SCRS
"*.h"
Expand Down Expand Up @@ -47,14 +45,14 @@ add_executable(dde-clipboard
)

target_link_libraries(dde-clipboard PRIVATE
Dtk::Widget
Dtk::Core
PkgConfig::GIO
Qt5::Core
Qt5::Widgets
Qt5::GuiPrivate
Qt5::Gui
Qt5::DBus
Dtk6::Widget
Dtk6::Core
#PkgConfig::GIO
Qt::Core
Qt::Widgets
Qt::GuiPrivate
Qt::Gui
Qt::DBus
)

install(TARGETS dde-clipboard DESTINATION ${CMAKE_INSTALL_BINDIR})
40 changes: 19 additions & 21 deletions dde-clipboard/clipboardmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
#include "clipboardmodel.h"

#include <QApplication>
#include <QPointer>
#include <QDebug>
#include <QDir>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDBusConnection>
#include <QDebug>
#include <QDir>
#include <QPointer>

ClipboardModel::ClipboardModel(ListView *list, QObject *parent) : QAbstractListModel(parent)
ClipboardModel::ClipboardModel(ListView *list, QObject *parent)
: QAbstractListModel(parent)
, m_list(list)
, m_loaderInter(new ClipboardLoader("org.deepin.dde.ClipboardLoader1",

Check warning on line 18 in dde-clipboard/clipboardmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'ClipboardModel' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).

Check warning on line 18 in dde-clipboard/clipboardmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'ClipboardModel' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).
"/org/deepin/dde/ClipboardLoader1",
QDBusConnection::sessionBus(), this))
QDBusConnection::sessionBus(),
this))
{
checkDbusConnect();
}
Expand Down Expand Up @@ -58,7 +60,8 @@ QVariant ClipboardModel::data(const QModelIndex &index, int role) const
Qt::ItemFlags ClipboardModel::flags(const QModelIndex &index) const
{
if (index.isValid()) {
if (m_list != nullptr) m_list->openPersistentEditor(index);
if (m_list != nullptr)
m_list->openPersistentEditor(index);
return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
}
return QAbstractListModel::flags(index);
Expand All @@ -67,12 +70,14 @@ Qt::ItemFlags ClipboardModel::flags(const QModelIndex &index) const
void ClipboardModel::destroy(ItemData *data)
{
int row = m_data.indexOf(data);
if (row == -1) return;
if (row == -1)
return;

m_list->startAni(row);

QTimer::singleShot(AnimationTime, this, [ = ] {
if (m_data.indexOf(data) == -1) return;
QTimer::singleShot(AnimationTime, this, [=] {
if (m_data.indexOf(data) == -1)
return;
beginRemoveRows(QModelIndex(), row, row);
auto item = m_data.takeAt(m_data.indexOf(data));
endRemoveRows();
Expand All @@ -97,17 +102,11 @@ void ClipboardModel::reborn(ItemData *data)
QByteArray buf;
QDataStream stream(&buf, QIODevice::WriteOnly);
QByteArray iconBuf;

Check warning on line 104 in dde-clipboard/clipboardmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'iconBuf' is not assigned a value.

Check warning on line 104 in dde-clipboard/clipboardmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'iconBuf' is not assigned a value.
stream << data->formatMap()
<< data->type()
<< data->urls()
<< data->imageData().isValid();
stream << data->formatMap() << data->type() << data->urls() << data->imageData().isValid();
if (data->imageData().isValid()) {
stream << data->imageData();
}
stream << data->dataEnabled()
<< data->text()
<< data->time()
<< iconBuf;
stream << data->dataEnabled() << data->text() << data->time() << iconBuf;

m_loaderInter->dataReborned(buf);

Expand All @@ -124,9 +123,8 @@ void ClipboardModel::checkDbusConnect()
QTimer *timer = new QTimer(this);
timer->setInterval(1000);

connect(timer, &QTimer::timeout, this, [ = ] {
if (m_loaderInter->isValid())
{
connect(timer, &QTimer::timeout, this, [=] {
if (m_loaderInter->isValid()) {
connect(m_loaderInter, &ClipboardLoader::dataComing, this, &ClipboardModel::dataComing);
timer->stop();
}
Expand Down
51 changes: 26 additions & 25 deletions dde-clipboard/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H

#include <QSize>
#include <QPixmap>
#include <QBitmap>
#include <QIcon>
#include <QPainter>
#include <QPalette>
#include <QBitmap>
#include <QPixmap>
#include <QSize>
#include <QTimer>
#include <QIcon>

#define MAX(a,b) ((a) > (b) ? (a):(b))
#define MIN(a,b) ((a) < (b) ? (a):(b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

inline constexpr int WindowWidth = 300;
inline constexpr int WindowMargin = 10; //边距
inline constexpr int WindowMargin = 10; // 边距
inline constexpr int WindowTitleHeight = 56;
inline constexpr int ItemTitleHeight = 36; //Item标题栏高度
inline constexpr int ItemStatusBarHeight = 30; //Item状态栏高度
inline constexpr int ItemTitleHeight = 36; // Item标题栏高度
inline constexpr int ItemStatusBarHeight = 30; // Item状态栏高度
inline constexpr int ItemWidth = WindowWidth - 2 * WindowMargin;
inline constexpr int ItemHeight = 200;
inline constexpr int ItemMargin = 10;
inline constexpr int PixmapWidth = 180; //图像最大显示宽度
inline constexpr int PixmapHeight = 100; //图像最大显示高度
inline constexpr int PixmapWidth = 180; // 图像最大显示宽度
inline constexpr int PixmapHeight = 100; // 图像最大显示高度
inline constexpr int FileIconWidth = PixmapWidth;
inline constexpr int FileIconHeight = PixmapHeight;
inline constexpr int PixmapxStep = 15;
inline constexpr int PixmapyStep = 5;
inline constexpr int ContentMargin = 21;
inline constexpr int TextContentTopMargin = 20;
inline constexpr int AnimationTime = 300; //ms
inline constexpr int AnimationTime = 300; // ms

static const QString DBusClipBoardService = "org.deepin.dde.Clipboard1";
static const QString DBusClipBoardPath = "/org/deepin/dde/Clipboard1";
Expand All @@ -43,12 +43,13 @@ static const QString TextPlainLiteral QStringLiteral("text/plain");
static const QString ApplicationXColorLiteral QStringLiteral("application/x-color");
static const QString ApplicationXQtImageLiteral QStringLiteral("application/x-qt-image");

typedef struct {
typedef struct
{
QStringList cornerIconList;
QIcon fileIcon;
} FileIconData;

namespace Globals {
namespace Globals {
/*!
* \~chinese \name GetScale
* \~chinese \brief 获取缩放的比例
Expand Down Expand Up @@ -98,24 +99,24 @@ inline QPixmap GetRoundPixmap(const QPixmap &pix, QColor borderColor)

int radius = 10;
int borderWidth = 10;
// if (pix.width() > pix.height()) {
// radius = int(8 * 1.0 / PixmapWidth * pix.width());
// borderWidth = int(10 * 1.0 / PixmapWidth * pix.width());
// } else {
// radius = int(8 * 1.0 / PixmapHeight * pix.height());
// borderWidth = int(10 * 1.0 / PixmapHeight * pix.height());
// }
// if (pix.width() > pix.height()) {
// radius = int(8 * 1.0 / PixmapWidth * pix.width());
// borderWidth = int(10 * 1.0 / PixmapWidth * pix.width());
// } else {
// radius = int(8 * 1.0 / PixmapHeight * pix.height());
// borderWidth = int(10 * 1.0 / PixmapHeight * pix.height());
// }

QPixmap pixmap = pix;
//绘制边框
// 绘制边框
QPainter pixPainter(&pixmap);
pixPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
borderColor.setAlpha(60);
pixPainter.setPen(QPen(borderColor, borderWidth));
pixPainter.setBrush(Qt::transparent);
pixPainter.drawRoundedRect(pixmap.rect(), radius, radius);

//设置圆角
// 设置圆角
QSize size(pixmap.size());
QBitmap mask(size);
QPainter painter(&mask);
Expand All @@ -124,10 +125,10 @@ inline QPixmap GetRoundPixmap(const QPixmap &pix, QColor borderColor)
painter.setBrush(Qt::color1);
painter.drawRoundedRect(mask.rect(), radius, radius);

//遮罩
// 遮罩
QPixmap image = pixmap;
image.setMask(mask);
return image;
}
} ;
}; // namespace Globals
#endif // CONSTANTS_H
Loading

0 comments on commit c22e7f9

Please sign in to comment.