Skip to content

Commit

Permalink
feat: support dtk_lib
Browse files Browse the repository at this point in the history
Change-Id: I5605891eec17f31d4afb4cdcc5dca2a57b921a18
  • Loading branch information
Iceyer committed Apr 12, 2018
1 parent 390f51b commit 0732643
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
14 changes: 1 addition & 13 deletions dtkwidget.pro
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
TEMPLATE = subdirs
load(dtk_lib)

CONFIG += ordered

SUBDIRS += \
src \
tools \
examples

win* {
!system(python $$PWD/tools/translate_generation.py $$PWD): error("Failed to generate translation")
} else {
!system($$PWD/tools/translate_generation.sh): error("Failed to generate translation")
}
4 changes: 3 additions & 1 deletion examples/dwidget-examples/collections/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ int main(int argc, char *argv[])
DApplication::loadDXcbPlugin();

DApplication a(argc, argv);
Dtk::Core::DLogManager::registerConsoleAppender();

a.loadTranslator();
a.setAttribute(Qt::AA_EnableHighDpiScaling, true);
a.setTheme("light");
Dtk::Core::DLogManager::registerConsoleAppender();

if (!a.setSingleInstance("deepin-tool-kit-examples")) {
qDebug() << "another instance is running!!";
Expand Down
16 changes: 12 additions & 4 deletions src/dtkwidget_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
#define DWIDGET_END_NAMESPACE }}
#define DWIDGET_USE_NAMESPACE using namespace DTK_WIDGET_NAMESPACE;

void inline dtk_windget_init_resource()
{
Q_INIT_RESOURCE(icons);
Q_INIT_RESOURCE(dui_theme_dark);
Q_INIT_RESOURCE(dui_theme_light);
// TODO: use marco create by dtk_build
Q_INIT_RESOURCE(dtkwidget_translations);
}

namespace Dtk
{
namespace Widget
Expand All @@ -37,9 +46,8 @@ namespace Widget
#if defined(DTK_STATIC_LIB)
#define DWIDGET_INIT_RESOURCE() \
do { \
Q_INIT_RESOURCE(icons); \
Q_INIT_RESOURCE(dui_theme_dark); \
Q_INIT_RESOURCE(dui_theme_light); } while (0)
dtk_windget_init_resource(); \
} while (0)
#endif

}
Expand All @@ -60,7 +68,7 @@ namespace Widget
#define D_THEME_INIT_WIDGET(className, ...) do{\
DThemeManager * manager = DThemeManager::instance(); \
{const QString &sheet = this->styleSheet() + manager->getQssForWidget(#className, this); \
if (!sheet.isEmpty()) this->setStyleSheet(sheet); \
if (!sheet.isEmpty()) this->setStyleSheet(sheet); \
} \
connect(manager, &DThemeManager::themeChanged, this, [this, manager] (QString) { \
const QString &sheet = manager->getQssForWidget(#className, this); \
Expand Down
10 changes: 0 additions & 10 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@ win32* {
includes.files += $$PWD/platforms/windows/*.h
}

# add translations
TRANSLATIONS += $$PWD/../translations/$${TARGET}2.ts \
$$PWD/../translations/$${TARGET}2_zh_CN.ts

translations.path = $$PREFIX/share/$${TARGET}/translations
translations.files = $$PWD/../translations/*.qm

INSTALLS += translations

# create DtkWidgets file
defineTest(containIncludeFiles) {
header = $$absolute_path($$ARGS)
Expand Down Expand Up @@ -126,5 +117,4 @@ INSTALLS += includes target

load(dtk_cmake)

QMAKE_PKGCONFIG_REQUIRES += dtkcore
load(dtk_module)
14 changes: 12 additions & 2 deletions src/widgets/dapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,19 @@ bool DApplicationPrivate::setSingleInstanceBySemaphore(const QString &key)

while (ss.acquire() && singleInstance)
{
if (!that)
if (!that) {
return;
}

if (that->startingUp() || that->closingDown()) {
break;
}

ss.release(1);

if (that)
if (that) {
Q_EMIT that->newInstanceStarted();
}
}
});

Expand Down Expand Up @@ -230,6 +232,10 @@ bool DApplicationPrivate::loadDtkTranslator(QList<QLocale> localeFallback)
DPathBuf currentDir(QDir::currentPath());
translateDirs << currentDir.join("translations");

#ifdef DTK_STATIC_TRANSLATION
translateDirs << DPathBuf(":/dtk/translations");
#endif

return loadTranslator(translateDirs, dtkwidgetName, localeFallback);
}

Expand Down Expand Up @@ -395,6 +401,10 @@ bool DApplication::loadTranslator(QList<QLocale> localeFallback)
DPathBuf currentDir(QDir::currentPath());
translateDirs << currentDir.join("translations");

#ifdef DTK_STATIC_TRANSLATION
translateDirs << DPathBuf(":/dtk/translations");
#endif

return d->loadTranslator(translateDirs, appName, localeFallback);
}

Expand Down
1 change: 0 additions & 1 deletion src/widgets/widgets.pri
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ HEADERS += $$PWD/dslider.h\
$$PWD/dpageindicator.h \
$$PWD/dclipeffectwidget.h \
$$PWD/dgraphicsclipeffect.h \
$$PWD/dvideowidget.h \
$$PWD/dforeignwindow.h \
$$PWD/dpushbutton.h \
$$PWD/dtickeffect.h \
Expand Down

0 comments on commit 0732643

Please sign in to comment.