diff --git a/docs/images/dwatermarkhelper_example.png b/docs/images/dwatermarkhelper_example.png new file mode 100644 index 000000000..1c0125040 Binary files /dev/null and b/docs/images/dwatermarkhelper_example.png differ diff --git a/docs/widgets/dwatermarkhelper.zh_CN.dox b/docs/widgets/dwatermarkhelper.zh_CN.dox index e1b2d0862..971fd1422 100644 --- a/docs/widgets/dwatermarkhelper.zh_CN.dox +++ b/docs/widgets/dwatermarkhelper.zh_CN.dox @@ -8,6 +8,51 @@ @param[in] parent @sa DWaterMaskHelper::instance +@details +### 实例代码 +#### main.cpp + +```cpp +#include +#include +#include + +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 定义,在第一次调用时实例化。 diff --git a/toolGenerate/dconfig2cpp/org_deepin_dtkwidget_feature-display.hpp b/toolGenerate/dconfig2cpp/org_deepin_dtkwidget_feature-display.hpp new file mode 100644 index 000000000..fe49bda69 --- /dev/null +++ b/toolGenerate/dconfig2cpp/org_deepin_dtkwidget_feature-display.hpp @@ -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-13T16:35:04 + * 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 +#include +#include +#include +#include +#include + +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(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(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 m_config = nullptr; + bool p_autoDisplayFeature { false }; + bool p_featureUpdated { false }; + QAtomicInteger m_propertySetStatus0 = 0; +}; + +#endif // ORG_DEEPIN_DTKWIDGET_FEATURE-DISPLAY_H