Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkwidget
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#631
  • Loading branch information
deepin-ci-robot committed Jan 14, 2025
1 parent 63dc5d4 commit 2b49ca5
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ License: LGPL-3.0-or-later
Files: tests/data/*
Copyright: None
License: CC0-1.0


Files: toolGenerate/**/*
Copyright: None
License: CC0-1.0
Binary file added docs/images/dwatermarkhelper_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions docs/widgets/dwatermarkhelper.zh_CN.dox
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,51 @@
@param[in] parent
@sa DWaterMaskHelper::instance

@details
### 实例代码
#### main.cpp

```cpp
#include <DApplication>
#include <DWaterMarkHelper>
#include <QMainWindow>

using namespace Dtk::Widget;


int main(int argc,char* argv[])
{
QApplication a(argc,argv);

QMainWindow w;
w.show();

auto ins = DWaterMarkHelper::instance();

WaterMarkData data = ins->data();
data.setText("dtk example");
data.setType(WaterMarkData::WaterMarkType::Text);
data.setLayout(WaterMarkData::WaterMarkLayout::Tiled) ;
data.setRotation(30);
data.setScaleFactor(0.5);
data.setColor(Qt::red);
QFont font;
font.setPointSize(30);
data.setFont(font);
data.setSpacing(65);
data.setLineSpacing(-1);
data.setOpacity(0.3);
data.setGrayScale(true);

ins->setData(data);

ins->registerWidget(&w);
return a.exec();
}
```
### 实例图片
@image html dwatermarkhelper_example.png

@fn DWaterMarkHelper::instance
@brief DWaterMarkHelper 的单例对象,使用 Q_GLOBAL_STATIC 定义,在第一次调用时实例化。

Expand Down
214 changes: 214 additions & 0 deletions toolGenerate/dconfig2cpp/org_deepin_dtkwidget_feature-display.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/**
* This file is generated by dconfig2cpp.
* Command line arguments: ./dconfig2cpp -p ./dtkwidget/toolGenerate/dconfig2cpp ./dtkwidget/src/org.deepin.dtkwidget.feature-display.json
* Generation time: 2025-01-14T10:54:57
* JSON file version: 1.0
*
* WARNING: DO NOT MODIFY THIS FILE MANUALLY.
* If you need to change the content, please modify the dconfig2cpp tool.
*/

#ifndef ORG_DEEPIN_DTKWIDGET_FEATURE-DISPLAY_H
#define ORG_DEEPIN_DTKWIDGET_FEATURE-DISPLAY_H

#include <QThread>
#include <QVariant>
#include <QDebug>
#include <QAtomicPointer>
#include <QAtomicInteger>
#include <DConfig>

class org_deepin_dtkwidget_feature-display : public QObject {
Q_OBJECT

Q_PROPERTY(bool autoDisplayFeature READ autoDisplayFeature WRITE setAutoDisplayFeature NOTIFY autoDisplayFeatureChanged)
Q_PROPERTY(bool featureUpdated READ featureUpdated WRITE setFeatureUpdated NOTIFY featureUpdatedChanged)
public:
explicit org_deepin_dtkwidget_feature-display(QThread *thread, const QString &appId, const QString &name, const QString &subpath, QObject *parent = nullptr)
: QObject(parent) {

if (!thread->isRunning()) {
qWarning() << QStringLiteral("Warning: The provided thread is not running.");
}
Q_ASSERT(QThread::currentThread() != thread);
auto worker = new QObject();
worker->moveToThread(thread);
QMetaObject::invokeMethod(worker, [=]() {
auto config = DTK_CORE_NAMESPACE::DConfig::create(appId, name, subpath, nullptr);
if (!config) {
qWarning() << QStringLiteral("Failed to create DConfig instance.");
worker->deleteLater();
return;
}
config->moveToThread(QThread::currentThread());
initialize(config);
worker->deleteLater();
});
}
explicit org_deepin_dtkwidget_feature-display(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &appId, const QString &name, const QString &subpath, QObject *parent = nullptr)
: QObject(parent) {

if (!thread->isRunning()) {
qWarning() << QStringLiteral("Warning: The provided thread is not running.");
}
Q_ASSERT(QThread::currentThread() != thread);
auto worker = new QObject();
worker->moveToThread(thread);
QMetaObject::invokeMethod(worker, [=]() {
auto config = DTK_CORE_NAMESPACE::DConfig::create(backend, appId, name, subpath, nullptr);
if (!config) {
qWarning() << QStringLiteral("Failed to create DConfig instance.");
worker->deleteLater();
return;
}
config->moveToThread(QThread::currentThread());
initialize(config);
worker->deleteLater();
});
}
explicit org_deepin_dtkwidget_feature-display(QThread *thread, const QString &name, const QString &subpath, QObject *parent = nullptr)
: QObject(parent) {

if (!thread->isRunning()) {
qWarning() << QStringLiteral("Warning: The provided thread is not running.");
}
Q_ASSERT(QThread::currentThread() != thread);
auto worker = new QObject();
worker->moveToThread(thread);
QMetaObject::invokeMethod(worker, [=]() {
auto config = DTK_CORE_NAMESPACE::DConfig::create(name, subpath, nullptr);
if (!config) {
qWarning() << QStringLiteral("Failed to create DConfig instance.");
worker->deleteLater();
return;
}
config->moveToThread(QThread::currentThread());
initialize(config);
worker->deleteLater();
});
}
explicit org_deepin_dtkwidget_feature-display(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &subpath, QObject *parent = nullptr)
: QObject(parent) {

if (!thread->isRunning()) {
qWarning() << QStringLiteral("Warning: The provided thread is not running.");
}
Q_ASSERT(QThread::currentThread() != thread);
auto worker = new QObject();
worker->moveToThread(thread);
QMetaObject::invokeMethod(worker, [=]() {
auto config = DTK_CORE_NAMESPACE::DConfig::create(backend, name, subpath, nullptr);
if (!config) {
qWarning() << QStringLiteral("Failed to create DConfig instance.");
worker->deleteLater();
return;
}
config->moveToThread(QThread::currentThread());
initialize(config);
worker->deleteLater();
});
}
~org_deepin_dtkwidget_feature-display() {
if (m_config.loadRelaxed()) {
m_config.loadRelaxed()->deleteLater();
}
}

bool autoDisplayFeature() const {
return p_autoDisplayFeature;
}
void setAutoDisplayFeature(const bool &value) {
auto oldValue = p_autoDisplayFeature;
p_autoDisplayFeature = value;
markPropertySet(0);
if (auto config = m_config.loadRelaxed()) {
QMetaObject::invokeMethod(config, [this, value]() {
m_config.loadRelaxed()->setValue(QStringLiteral("autoDisplayFeature"), value);
});
}
if (p_autoDisplayFeature != oldValue) {
Q_EMIT autoDisplayFeatureChanged();
}
}
bool featureUpdated() const {
return p_featureUpdated;
}
void setFeatureUpdated(const bool &value) {
auto oldValue = p_featureUpdated;
p_featureUpdated = value;
markPropertySet(1);
if (auto config = m_config.loadRelaxed()) {
QMetaObject::invokeMethod(config, [this, value]() {
m_config.loadRelaxed()->setValue(QStringLiteral("featureUpdated"), value);
});
}
if (p_featureUpdated != oldValue) {
Q_EMIT featureUpdatedChanged();
}
}
Q_SIGNALS:
void autoDisplayFeatureChanged();
void featureUpdatedChanged();
private:
void initialize(DTK_CORE_NAMESPACE::DConfig *config) {
Q_ASSERT(!m_config.loadRelaxed());
m_config.storeRelaxed(config);
if (testPropertySet(0)) {
config->setValue(QStringLiteral("autoDisplayFeature"), QVariant::fromValue(p_autoDisplayFeature));
} else {
updateValue(QStringLiteral("autoDisplayFeature"), QVariant::fromValue(p_autoDisplayFeature));
}
if (testPropertySet(1)) {
config->setValue(QStringLiteral("featureUpdated"), QVariant::fromValue(p_featureUpdated));
} else {
updateValue(QStringLiteral("featureUpdated"), QVariant::fromValue(p_featureUpdated));
}

connect(config, &DTK_CORE_NAMESPACE::DConfig::valueChanged, this, [this](const QString &key) {
updateValue(key);
}, Qt::DirectConnection);
}
void updateValue(const QString &key, const QVariant &fallback = QVariant()) {
Q_ASSERT(QThread::currentThread() == m_config.loadRelaxed()->thread());
const QVariant &value = m_config.loadRelaxed()->value(key, fallback);
if (key == QStringLiteral("autoDisplayFeature")) {
auto newValue = qvariant_cast<bool>(value);
QMetaObject::invokeMethod(this, [this, newValue]() {
if (p_autoDisplayFeature != newValue) {
p_autoDisplayFeature = newValue;
Q_EMIT autoDisplayFeatureChanged();
}
});
return;
}
if (key == QStringLiteral("featureUpdated")) {
auto newValue = qvariant_cast<bool>(value);
QMetaObject::invokeMethod(this, [this, newValue]() {
if (p_featureUpdated != newValue) {
p_featureUpdated = newValue;
Q_EMIT featureUpdatedChanged();
}
});
return;
}
}
inline void markPropertySet(const int index) {
if (index < 32) {
m_propertySetStatus0.fetchAndOrOrdered(1 << (index - 0));
return;
}
Q_UNREACHABLE();
}
inline bool testPropertySet(const int index) const {
if (index < 32) {
return (m_propertySetStatus0.loadRelaxed() & (1 << (index - 0)));
}
Q_UNREACHABLE();
}
QAtomicPointer<DTK_CORE_NAMESPACE::DConfig> m_config = nullptr;
bool p_autoDisplayFeature { false };
bool p_featureUpdated { false };
QAtomicInteger<quint32> m_propertySetStatus0 = 0;
};

#endif // ORG_DEEPIN_DTKWIDGET_FEATURE-DISPLAY_H

0 comments on commit 2b49ca5

Please sign in to comment.