From 1525c2cb363ba6c963ca6d43b0ba3dc6e80ff4b0 Mon Sep 17 00:00:00 2001 From: Iceyer Date: Mon, 12 Feb 2018 11:41:56 +0800 Subject: [PATCH] feat: support qt module Change-Id: Iffa23b1971e6e2f49b9a43a34804e3eb0139070e --- .gitignore | 1 + debian/libdtkwidget-dev.install | 1 + .../collections/collections.pro | 15 +-- .../dwidget-examples/collections/main.cpp | 3 +- .../collections/multilistview.h | 8 +- src/config.pri | 32 ------- src/dtkwidget_global.h | 4 +- src/src.pro | 62 ++++++------ src/util/dregionmonitor.cpp | 10 +- src/widgets/dcrumbedit.cpp | 2 +- src/widgets/dimagebutton.cpp | 2 +- src/widgets/dsimplelistview.h | 96 +++++++++---------- tools/svgc/svgc.pro | 31 +++--- 13 files changed, 115 insertions(+), 152 deletions(-) diff --git a/.gitignore b/.gitignore index 0fb8961be..c09ac91ec 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ build*/ src/DtkWidgets src/dtkwidget_config.h cmake/DtkWidget/DtkWidgetConfig.cmake +src/qt_lib_dtk*.pri diff --git a/debian/libdtkwidget-dev.install b/debian/libdtkwidget-dev.install index c59eced9c..f1f7613e7 100644 --- a/debian/libdtkwidget-dev.install +++ b/debian/libdtkwidget-dev.install @@ -2,3 +2,4 @@ usr/lib/*/lib*.so usr/include usr/lib/*/pkgconfig/*.pc usr/lib/*/cmake/*/*.cmake +usr/lib/*/qt5/* diff --git a/examples/dwidget-examples/collections/collections.pro b/examples/dwidget-examples/collections/collections.pro index a07b5f2af..e508c2bfe 100644 --- a/examples/dwidget-examples/collections/collections.pro +++ b/examples/dwidget-examples/collections/collections.pro @@ -1,6 +1,6 @@ QT += core gui multimedia multimediawidgets svg - greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +QT += dtkcore TARGET = collections TEMPLATE = app @@ -10,8 +10,10 @@ DEFINES += QT_MESSAGELOGCONTEXT unix { QT += dbus - CONFIG += link_pkgconfig - PKGCONFIG += dtkcore +} + +!isEmpty(DTK_STATIC_LIB){ + DEFINES += DTK_STATIC_LIB } SOURCES += main.cpp\ @@ -60,15 +62,8 @@ RESOURCES += \ FORMS += \ cameraform.ui -include($$PWD/../../../src/config.pri) - win32* { CONFIG += no_lflags_merge - DEFINES += STATIC_LIB - - #DEPENDS dtkcore - INCLUDEPATH += $$INCLUDE_INSTALL_DIR\libdtk-$$VERSION\DCore - LIBS += -L$$LIB_INSTALL_DIR -ldtkcore } win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../src/release -ldtkwidget diff --git a/examples/dwidget-examples/collections/main.cpp b/examples/dwidget-examples/collections/main.cpp index 135e852cf..0379b4eae 100644 --- a/examples/dwidget-examples/collections/main.cpp +++ b/examples/dwidget-examples/collections/main.cpp @@ -29,8 +29,7 @@ DWIDGET_USE_NAMESPACE int main(int argc, char *argv[]) { - -#if defined(STATIC_LIB) +#if defined(DTK_STATIC_LIB) DWIDGET_INIT_RESOURCE(); #endif diff --git a/examples/dwidget-examples/collections/multilistview.h b/examples/dwidget-examples/collections/multilistview.h index 9d3a58f0e..9bfe0b88d 100644 --- a/examples/dwidget-examples/collections/multilistview.h +++ b/examples/dwidget-examples/collections/multilistview.h @@ -25,12 +25,12 @@ DWIDGET_USE_NAMESPACE class MultiListView : public DSimpleListView { Q_OBJECT - + public: MultiListView(DSimpleListView *parent=0); - -public slots: + +public Q_SLOTS: void popupMenu(QPoint pos, QList items); -}; +}; #endif diff --git a/src/config.pri b/src/config.pri index 1a015befb..6fbf5bb6b 100644 --- a/src/config.pri +++ b/src/config.pri @@ -1,14 +1,3 @@ -CONFIG += c++11 -DEFINES += QT_MESSAGELOGCONTEXT - -isEmpty(PREFIX){ - PREFIX = /usr -} - -win32* { - DEFINES += STATIC_LIB -} - isEmpty(VERSION) { PKG_CONFIG_EXE = $$first($$list($$pkgConfigExecutable())) isEmpty(LIB_INSTALL_DIR) { @@ -24,24 +13,3 @@ isEmpty(VERSION) { isEmpty(VERSION): error(VERSION is empty) } - -ver_list = $$split(VERSION, .) - -isEmpty(VER_MAJ) { - VER_MAJ = $$first(ver_list) -} - -isEmpty(VER_MIN) { - VER_MIN = $$member(ver_list, 1, 1) - isEmpty(VER_MIN):VER_MIN = 0 -} - -isEmpty(VER_PAT) { - VER_PAT = $$member(ver_list, 2, 2) - isEmpty(VER_PAT):VER_PAT = 0 -} - -isEmpty(VER_BUI) { - VER_BUI = $$member(ver_list, 3, 3) - isEmpty(VER_BUI):VER_BUI = 0 -} diff --git a/src/dtkwidget_global.h b/src/dtkwidget_global.h index cf1876b0b..14213a29e 100644 --- a/src/dtkwidget_global.h +++ b/src/dtkwidget_global.h @@ -34,7 +34,7 @@ namespace Dtk namespace Widget { -#if defined(STATIC_LIB) +#if defined(DTK_STATIC_LIB) #define DWIDGET_INIT_RESOURCE() \ do { \ Q_INIT_RESOURCE(icons); \ @@ -45,7 +45,7 @@ namespace Widget } } -#if defined(STATIC_LIB) +#if defined(DTK_STATIC_LIB) # define LIBDTKWIDGETSHARED_EXPORT #else #if defined(LIBDTKWIDGET_LIBRARY) diff --git a/src/src.pro b/src/src.pro index 2080573ca..6e6ec8f3f 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,10 +1,6 @@ -include($$PWD/lib.pri) - -TEMPLATE = lib -CONFIG += qt -TARGET = dtkwidget - -DEFINES += LIBDTKWIDGET_LIBRARY +include($$PWD/config.pri) +# TODO: replace config.pri with dtk_build +load(dtk_build) QT += multimedia multimediawidgets concurrent greaterThan(QT_MAJOR_VERSION, 4) { @@ -13,26 +9,29 @@ greaterThan(QT_MAJOR_VERSION, 4) { greaterThan(QT_MAJOR_VERSION, 5)|greaterThan(QT_MINOR_VERSION, 7): QT += gui-private else: QT += platformsupport-private } + +QT += dtkcore + linux* { QT += x11extras dbus - CONFIG += link_pkgconfig - PKGCONFIG += x11 xext dtkcore } mac* { QT += svg DEFINES += DTK_TITLE_DRAG_WINDOW - CONFIG += link_pkgconfig - PKGCONFIG += dtkcore } win* { QT += svg DEFINES += DTK_TITLE_DRAG_WINDOW +} - #DEPENDS dtkcore - INCLUDEPATH += $$INCLUDE_INSTALL_DIR\libdtk-$$VERSION\DCore - LIBS += -L$$LIB_INSTALL_DIR -ldtkcore +TEMPLATE = lib +TARGET = dtkwidget + +!isEmpty(DTK_STATIC_LIB){ + DEFINES += DTK_STATIC_LIB + CONFIG += staticlib } HEADERS += dtkwidget_global.h @@ -53,20 +52,6 @@ win32* { includes.files += $$PWD/platforms/windows/*.h } -QMAKE_PKGCONFIG_NAME = DTK_WIDGET -QMAKE_PKGCONFIG_DESCRIPTION = Deepin Tool Kit Widget Module -QMAKE_PKGCONFIG_INCDIR = $$includes.path -QMAKE_PKGCONFIG_REQUIRES += dtkcore - -# CMake configure -INC_DIR = $$replace(includes.path, "/", "\/") -CMD = sed -E \'s/DTKWIDGET_INCLUDE_DIR \".*\"\\)$/DTKWIDGET_INCLUDE_DIR \"$${INC_DIR}\"\\)/\' ../cmake/DtkWidget/DtkWidgetConfig.cmake.in > ../cmake/DtkWidget/DtkWidgetConfig.cmake -message($$CMD) -system($$CMD) - -cmake_config.path = $$LIB_INSTALL_DIR -cmake_config.files = $$PWD/../cmake - # add translations TRANSLATIONS += $$PWD/../translations/$${TARGET}2.ts \ $$PWD/../translations/$${TARGET}2_zh_CN.ts @@ -74,7 +59,7 @@ TRANSLATIONS += $$PWD/../translations/$${TARGET}2.ts \ translations.path = $$PREFIX/share/$${TARGET}/translations translations.files = $$PWD/../translations/*.qm -INSTALLS += translations cmake_config +INSTALLS += translations # create DtkWidgets file defineTest(containIncludeFiles) { @@ -126,3 +111,22 @@ defineTest(updateDtkWidgetConfigFile) { } !updateDtkWidgetConfigFile():warning(Cannot create "dtkwidget_config.h" header file) + +INSTALLS += includes target + +# CMake configure +INC_DIR = $$replace(includes.path, "/", "\/") +CMD = sed -E \'s/DTKWIDGET_INCLUDE_DIR \".*\"\\)$/DTKWIDGET_INCLUDE_DIR \"$${INC_DIR}\"\\)/\' ../cmake/DtkWidget/DtkWidgetConfig.cmake.in > ../cmake/DtkWidget/DtkWidgetConfig.cmake +message($$CMD) +system($$CMD) + +cmake_config.path = $$LIB_INSTALL_DIR +cmake_config.files = $$PWD/../cmake +INSTALLS += cmake_config + +#TODO: use dtkcmake +#CMAKE_MODULE=DtkWidget +#load(dtk_cmake) + +QMAKE_PKGCONFIG_REQUIRES += dtkcore +load(dtk_module) diff --git a/src/util/dregionmonitor.cpp b/src/util/dregionmonitor.cpp index 94985fc14..b63bdc3d2 100644 --- a/src/util/dregionmonitor.cpp +++ b/src/util/dregionmonitor.cpp @@ -126,7 +126,7 @@ void DRegionMonitorPrivate::_q_ButtonPress(const int flag, const int x, const in D_Q(DRegionMonitor); - emit q->buttonPress(deviceScaledCoordinate(QPoint(x, y), qApp->devicePixelRatio()), flag); + Q_EMIT q->buttonPress(deviceScaledCoordinate(QPoint(x, y), qApp->devicePixelRatio()), flag); } void DRegionMonitorPrivate::_q_ButtonRelease(const int flag, const int x, const int y, const QString &key) @@ -136,7 +136,7 @@ void DRegionMonitorPrivate::_q_ButtonRelease(const int flag, const int x, const D_Q(DRegionMonitor); - emit q->buttonRelease(deviceScaledCoordinate(QPoint(x, y), qApp->devicePixelRatio()), flag); + Q_EMIT q->buttonRelease(deviceScaledCoordinate(QPoint(x, y), qApp->devicePixelRatio()), flag); } void DRegionMonitorPrivate::_q_CursorMove(const int x, const int y, const QString &key) @@ -146,7 +146,7 @@ void DRegionMonitorPrivate::_q_CursorMove(const int x, const int y, const QStrin D_Q(DRegionMonitor); - emit q->cursorMove(deviceScaledCoordinate(QPoint(x, y), qApp->devicePixelRatio())); + Q_EMIT q->cursorMove(deviceScaledCoordinate(QPoint(x, y), qApp->devicePixelRatio())); } void DRegionMonitorPrivate::_q_KeyPress(const QString &keyname, const int x, const int y, const QString &key) @@ -159,7 +159,7 @@ void DRegionMonitorPrivate::_q_KeyPress(const QString &keyname, const int x, con D_Q(DRegionMonitor); - emit q->keyPress(keyname); + Q_EMIT q->keyPress(keyname); } void DRegionMonitorPrivate::_q_KeyRelease(const QString &keyname, const int x, const int y, const QString &key) @@ -172,7 +172,7 @@ void DRegionMonitorPrivate::_q_KeyRelease(const QString &keyname, const int x, c D_Q(DRegionMonitor); - emit q->keyRelease(keyname); + Q_EMIT q->keyRelease(keyname); } const QPoint DRegionMonitorPrivate::deviceScaledCoordinate(const QPoint &p, const double ratio) const diff --git a/src/widgets/dcrumbedit.cpp b/src/widgets/dcrumbedit.cpp index 6566cb2e5..b550166bb 100644 --- a/src/widgets/dcrumbedit.cpp +++ b/src/widgets/dcrumbedit.cpp @@ -343,7 +343,7 @@ class DCrumbEditPrivate : public DCORE_NAMESPACE::DObjectPrivate } } - foreach (const DCrumbTextFormat &f, formats) { + Q_FOREACH(const DCrumbTextFormat &f, formats) { if (!crumbList.contains(f.text())) { formats.remove(f.text()); formatsChanged = true; diff --git a/src/widgets/dimagebutton.cpp b/src/widgets/dimagebutton.cpp index 535ce737c..84d1e339e 100644 --- a/src/widgets/dimagebutton.cpp +++ b/src/widgets/dimagebutton.cpp @@ -245,7 +245,7 @@ void DImageButton::setChecked(bool flag) d->setState(Normal); } - emit checkedChanged(d->m_isChecked); + Q_EMIT checkedChanged(d->m_isChecked); } /*! diff --git a/src/widgets/dsimplelistview.h b/src/widgets/dsimplelistview.h index 56978cdb5..4efb07192 100644 --- a/src/widgets/dsimplelistview.h +++ b/src/widgets/dsimplelistview.h @@ -19,7 +19,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - */ + */ #ifndef DSIMPLELISTVIEW_H #define DSIMPLELISTVIEW_H @@ -40,16 +40,16 @@ class DSimpleListViewPrivate; class LIBDTKWIDGETSHARED_EXPORT DSimpleListView : public QWidget, public DTK_CORE_NAMESPACE::DObject { Q_OBJECT - + public: explicit DSimpleListView(QWidget *parent = 0); ~DSimpleListView(); // DSimpleListView interfaces. - - /* + + /* * Set row height of DSimpleListView. - * + * * @height the height of row */ void setRowHeight(int height); @@ -58,13 +58,13 @@ class LIBDTKWIDGETSHARED_EXPORT DSimpleListView : public QWidget, public DTK_COR * Set column titles, widths and height. * If you want some column use expand space, please set width with -1 * Only allowed one -1 to set in width list. - * + * * @titles a list to contains titles * @widths the width of column, list length same as titles list * @height height of titlebar, don't display titlebar if set height with 0 */ void setColumnTitleInfo(QList titles, QList widths, int height); - + /* * Set column hide flags. * At least have false in hide flags list, and hide flags count must same as titles list. @@ -73,107 +73,107 @@ class LIBDTKWIDGETSHARED_EXPORT DSimpleListView : public QWidget, public DTK_COR * @alwaysVisibleColumn the column index that column is always visible, default is -1, mean no column can always visible. */ void setColumnHideFlags(QList toggleHideFlags, int alwaysVisibleColumn=-1); - + /* * Set column sorting algorithms. * Note SortAlgorithm function type must be 'static', otherwise function pointer can't match type. - * + * * @algorithms a list of SortAlgorithm, SortAlgorithm is function pointer, it's type is: 'bool (*) (const DSimpleListItem *item1, const DSimpleListItem *item2, bool descendingSort)' * @sortColumn default sort column, -1 mean don't sort any column default * @descendingSort whether sort column descending, default is false */ void setColumnSortingAlgorithms(QList *algorithms, int sortColumn=-1, bool descendingSort=false); - + /* * Set search algorithm to filter match items. - * + * * @algorithm the search algorithm, it's type is: 'bool (*) (const DSimpleListItem *item, QString searchContent)' */ void setSearchAlgorithm(SearchAlgorithm algorithm); - + /* * Set radius to clip listview. - * + * * @radius the radius of clip area, default is 0 pixel. */ void setClipRadius(int radius); - + /* * Set frame details. - * + * * @enableFrame draw frame if enableFrame is true, default is false * @color the frame color, default is black * @opacity the frame opacity, default is 0.1 */ void setFrame(bool enableFrame, QColor color=QColor("#000000"), double opacity=0.1); - - /* + + /* * Add DSimpleListItem list to ListView. - * If user has click title to sort, sort items after add items to list. - * + * If user has click title to sort, sort items after add items to list. + * * @items List of LiteItem* */ void addItems(QList items); - - /* + + /* * Clear items from DSimpleListView. */ void clearItems(); - + /* * Add DSimpleListItem list to mark selected effect in ListView. - * + * * @items List of DSimpleListItem* to mark selected * @recordLastSelection record last selection item to make selected operation continuously, default is true */ void addSelections(QList items, bool recordLastSelection=true); - + /* * Clear selection items from DSimpleListView. - * + * * @clearLastSelection clear last selection item if option is true, default is true */ void clearSelections(bool clearLastSelection=true); - + /* * Refresh all items in DSimpleListView. * This function is different that addItems is: it will clear items first before add new items. * This function will keep selection status and scroll offset when add items. - * + * * @items List of DSimpleListItem* to add */ void refreshItems(QList items); - + /* * Search */ void search(QString searchContent); - + // DSimpleListView operations. void selectAllItems(); void selectFirstItem(); void selectLastItem(); void selectNextItem(); void selectPrevItem(); - + void shiftSelectPageDown(); void shiftSelectPageUp(); void shiftSelectToEnd(); void shiftSelectToHome(); void shiftSelectToNext(); void shiftSelectToPrev(); - + void scrollPageDown(); void scrollPageUp(); - + void ctrlScrollPageDown(); void ctrlScrollPageUp(); void ctrlScrollToEnd(); void ctrlScrollToHome(); - + protected: virtual void leaveEvent(QEvent * event); - + QPixmap arrowDownDarkHoverImage; QPixmap arrowDownDarkNormalImage; QPixmap arrowDownDarkPressImage; @@ -209,14 +209,14 @@ class LIBDTKWIDGETSHARED_EXPORT DSimpleListView : public QWidget, public DTK_COR qreal scrollbarHoverOpacity = 0.7; qreal scrollbarNormalOpacity = 0.5; qreal scrollbarPressOpacity = 0.8; - -signals: + +Q_SIGNALS: void rightClickItems(QPoint pos, QList items); void changeColumnVisible(int index, bool visible, QList columnVisibles); void changeSortingStatus(int index, bool sortingOrder); void changeHoverItem(QPoint pos, DSimpleListItem* item, int columnIndex); - -protected: + +protected: bool eventFilter(QObject *, QEvent *event); void keyPressEvent(QKeyEvent *keyEvent); void mouseMoveEvent(QMouseEvent *mouseEvent); @@ -224,34 +224,34 @@ class LIBDTKWIDGETSHARED_EXPORT DSimpleListView : public QWidget, public DTK_COR void mouseReleaseEvent(QMouseEvent *mouseEvent); void paintEvent(QPaintEvent *); void wheelEvent(QWheelEvent *event); - + void paintScrollbar(QPainter *painter); - + void selectPrevItemWithOffset(int scrollOffset); void selectNextItemWithOffset(int scrollOffset); void shiftSelectNextItemWithOffset(int scrollOffset); void shiftSelectPrevItemWithOffset(int scrollOffset); - + int getBottomRenderOffset(); int getScrollbarY(); int getScrollAreaHeight(); int getScrollbarHeight(); - + QList getRenderWidths(); void shiftSelectItemsWithBound(int selectionStartIndex, int selectionEndIndex); int adjustRenderOffset(int offset); - + void startScrollbarHideTimer(); - + bool isMouseAtScrollArea(int x); bool isMouseAtTitleArea(int y); - + QList columnVisibles; - -private slots: + +private Q_SLOTS: void hideScrollbar(); - + private: D_DECLARE_PRIVATE(DSimpleListView) }; diff --git a/tools/svgc/svgc.pro b/tools/svgc/svgc.pro index 12e2e11f6..9cb6ff095 100644 --- a/tools/svgc/svgc.pro +++ b/tools/svgc/svgc.pro @@ -1,9 +1,8 @@ -include($$PWD/../../src/config.pri) - QT += gui svg +QT += dtkcore TARGET = dtk-svgc -CONFIG += c++11 console +CONFIG += c++11 CONFIG -= app_bundle # The following define makes your compiler emit warnings if you use @@ -17,27 +16,23 @@ DEFINES += QT_DEPRECATED_WARNINGS # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp - -unix { - CONFIG+=link_pkgconfig - PKGCONFIG += dtkcore -} - -win32* { - #DEPENDS dtkcore - INCLUDEPATH += $$INCLUDE_INSTALL_DIR\libdtk-$$VERSION\DCore - LIBS += -L$$LIB_INSTALL_DIR -ldtkcore -} +DEFINES += QT_MESSAGELOGCONTEXT isEmpty(PREFIX){ PREFIX = /usr } +isEmpty(BIN_INSTALL_DIR) { + BIN_INSTALL_DIR=$${PREFIX}/lib/dtk2 +} +!isEmpty(DTK_STATIC_LIB){ + DEFINES += DTK_STATIC_LIB +} + +SOURCES += main.cpp -binary.files += $${OUT_PWD}/$${TARGET} -binary.path = $${PREFIX}/lib/dtk2 +target.path = $${BIN_INSTALL_DIR} -INSTALLS += binary +INSTALLS += target win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../src/release/ -ldtkwidget else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../src/debug/ -ldtkwidget