Make definitions for gui support project specific

This commit is contained in:
Martchus 2017-04-27 22:03:37 +02:00
parent 1d49f41582
commit 61a544d42f
10 changed files with 35 additions and 30 deletions

View File

@ -8,8 +8,8 @@ set(META_APP_AUTHOR "Martchus")
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models") set(META_APP_DESCRIPTION "Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models")
set(META_VERSION_MAJOR 5) set(META_VERSION_MAJOR 5)
set(META_VERSION_MINOR 6) set(META_VERSION_MINOR 7)
set(META_VERSION_PATCH 1) set(META_VERSION_PATCH 0)
set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}) set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH})
# add project files # add project files
@ -138,13 +138,13 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" "${CMAKE_MODUL
# configure platform specific capslock detection # configure platform specific capslock detection
if(WIN32) if(WIN32)
# WinAPI provides functions required for capslock detection # WinAPI provides functions required for capslock detection
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS QT_UTILITIES_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION) list(APPEND META_PRIVATE_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION)
else() else()
# X11 can provide functions required for capslock detection under non-Windows environments # X11 can provide functions required for capslock detection under non-Windows environments
find_package(X11) find_package(X11)
if(X11_FOUND) if(X11_FOUND)
list(APPEND LIBRARIES ${X11_LIBRARIES}) list(APPEND LIBRARIES ${X11_LIBRARIES})
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS QT_UTILITIES_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION) list(APPEND META_PRIVATE_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION)
endif() endif()
endif() endif()
@ -172,13 +172,15 @@ else()
endif() endif()
# find c++utilities # find c++utilities
find_package(c++utilities 4.6.0 REQUIRED) find_package(c++utilities 4.7.0 REQUIRED)
use_cpp_utilities() use_cpp_utilities()
# include modules to apply configuration # include modules to apply configuration
include(BasicConfig) include(BasicConfig)
include(QtGuiConfig) include(QtGuiConfig)
# apply Qt utilities specific configuration
set(META_PUBLIC_QT_MODULES Core ${ADDITIONAL_QT_MODULES}) set(META_PUBLIC_QT_MODULES Core ${ADDITIONAL_QT_MODULES})
# include further modules to apply configuration
include(QtConfig) include(QtConfig)
include(WindowsResources) include(WindowsResources)
include(LibraryTarget) include(LibraryTarget)

View File

@ -12,7 +12,8 @@ endif()
# enable Qt Widgets GUI # enable Qt Widgets GUI
if(WIDGETS_GUI) if(WIDGETS_GUI)
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS GUI_QTWIDGETS MODEL_UNDO_SUPPORT) list(APPEND META_PRIVATE_COMPILE_DEFINITIONS GUI_QTWIDGETS)
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_GUI_QTWIDGETS)
list(APPEND WIDGETS_FILES ${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES} ${WIDGETS_RES_FILES} ${WIDGETS_UI_FILES}) list(APPEND WIDGETS_FILES ${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES} ${WIDGETS_RES_FILES} ${WIDGETS_UI_FILES})
list(APPEND ADDITIONAL_HEADER_FILES ${WIDGETS_HEADER_FILES}) list(APPEND ADDITIONAL_HEADER_FILES ${WIDGETS_HEADER_FILES})
if(WIDGETS_FILES) if(WIDGETS_FILES)
@ -28,6 +29,7 @@ endif()
# enable Qt Quick GUI # enable Qt Quick GUI
if(QUICK_GUI) if(QUICK_GUI)
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS GUI_QTQUICK) list(APPEND META_PRIVATE_COMPILE_DEFINITIONS GUI_QTQUICK)
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_GUI_QTQUICK)
list(APPEND QML_FILES ${QML_HEADER_FILES} ${QML_SRC_FILES} ${QML_RES_FILES}) list(APPEND QML_FILES ${QML_HEADER_FILES} ${QML_SRC_FILES} ${QML_RES_FILES})
list(APPEND ADDITIONAL_HEADER_FILES ${QML_HEADER_FILES}) list(APPEND ADDITIONAL_HEADER_FILES ${QML_HEADER_FILES})
if(QML_FILES) if(QML_FILES)

View File

@ -301,11 +301,11 @@ void EnterPasswordDialog::confirm()
* \brief Returns an indication whether the capslock key is pressed using platform specific functions. * \brief Returns an indication whether the capslock key is pressed using platform specific functions.
* *
* \remarks - Returns always false for unsupported platforms. * \remarks - Returns always false for unsupported platforms.
* - This method always returns false when not built with * - This method always returns false when the detection is not supported. It is supported under X11
* QT_UTILITIES_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION defined. * and Windows.
* - This static function will be used internally to detect whether the capslock key is pressed
* when initializing the dialog if available.
* - The function requires the application to be linked against X11 on Linux/Unix. * - The function requires the application to be linked against X11 on Linux/Unix.
* - This static function will be used internally to detect whether the capslock key is pressed
* when initializing the dialog.
*/ */
bool EnterPasswordDialog::isCapslockPressed() bool EnterPasswordDialog::isCapslockPressed()
{ {
@ -325,6 +325,7 @@ bool EnterPasswordDialog::isCapslockPressed()
# else # else
return false; return false;
# endif # endif
#else
return false; return false;
#endif #endif
} }

View File

@ -1,13 +1,13 @@
#include "./dialogutils.h" #include "./dialogutils.h"
#ifdef GUI_NONE #if !defined(QT_UTILITIES_GUI_QTWIDGETS) && !defined(QT_UTILITIES_GUI_QTQUICK)
# include <QCoreApplication> # include <QCoreApplication>
#else #else
# include <QGuiApplication> # include <QGuiApplication>
# include <QPalette> # include <QPalette>
# include <QWidget> # include <QWidget>
# include <QStyle> # include <QStyle>
# ifdef GUI_QTWIDGETS # ifdef QT_UTILITIES_GUI_QTWIDGETS
# include <QApplication> # include <QApplication>
# include <QDesktopWidget> # include <QDesktopWidget>
# include <QCursor> # include <QCursor>
@ -46,7 +46,7 @@ QString generateWindowTitle(DocumentStatus documentStatus, const QString &docume
} }
} }
#ifndef GUI_NONE #if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
# ifdef Q_OS_WIN32 # ifdef Q_OS_WIN32
@ -87,7 +87,7 @@ const QString &dialogStyle()
return style; return style;
} }
# ifdef GUI_QTWIDGETS # ifdef QT_UTILITIES_GUI_QTWIDGETS
/*! /*!
* \brief Moves the specified \a widget in the middle of the (available) screen area. If there are multiple * \brief Moves the specified \a widget in the middle of the (available) screen area. If there are multiple

View File

@ -22,13 +22,13 @@ enum class DocumentStatus {
QString QT_UTILITIES_EXPORT generateWindowTitle(DocumentStatus documentStatus, const QString &documentPath); QString QT_UTILITIES_EXPORT generateWindowTitle(DocumentStatus documentStatus, const QString &documentPath);
#ifndef GUI_NONE #if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined (QT_UTILITIES_GUI_QTQUICK)
# ifdef Q_OS_WIN32 # ifdef Q_OS_WIN32
QColor QT_UTILITIES_EXPORT windowFrameColor(); QColor QT_UTILITIES_EXPORT windowFrameColor();
QColor QT_UTILITIES_EXPORT instructionTextColor(); QColor QT_UTILITIES_EXPORT instructionTextColor();
# endif # endif
const QString QT_UTILITIES_EXPORT &dialogStyle(); const QString QT_UTILITIES_EXPORT &dialogStyle();
# ifdef GUI_QTWIDGETS # ifdef QT_UTILITIES_GUI_QTWIDGETS
void QT_UTILITIES_EXPORT centerWidget(QWidget *widget); void QT_UTILITIES_EXPORT centerWidget(QWidget *widget);
void QT_UTILITIES_EXPORT cornerWidget(QWidget *widget); void QT_UTILITIES_EXPORT cornerWidget(QWidget *widget);
void QT_UTILITIES_EXPORT makeHeading(QWidget *widget); void QT_UTILITIES_EXPORT makeHeading(QWidget *widget);

View File

@ -4,7 +4,7 @@
#include "resources/config.h" #include "resources/config.h"
#ifdef QT_STATIC #ifdef QT_STATIC
# if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK) # if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
# include <QtPlugin> # include <QtPlugin>
# ifdef Q_OS_WIN32 # ifdef Q_OS_WIN32
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)

View File

@ -6,7 +6,7 @@
#include <QLocale> #include <QLocale>
#include <QFont> #include <QFont>
#include <QIcon> #include <QIcon>
#ifdef GUI_QTWIDGETS #ifdef QT_UTILITIES_GUI_QTWIDGETS
# include <QApplication> # include <QApplication>
# include <QStyleFactory> # include <QStyleFactory>
#else #else
@ -65,9 +65,9 @@ QtConfigArguments::QtConfigArguments() :
m_qtQuickGuiArg.setSubArguments({&m_lngArg, &m_qmlDebuggerArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg}); m_qtQuickGuiArg.setSubArguments({&m_lngArg, &m_qmlDebuggerArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg});
m_qtWidgetsGuiArg.setDenotesOperation(true); m_qtWidgetsGuiArg.setDenotesOperation(true);
m_qtQuickGuiArg.setDenotesOperation(true); m_qtQuickGuiArg.setDenotesOperation(true);
#if defined GUI_QTWIDGETS #if defined QT_UTILITIES_GUI_QTWIDGETS
m_qtWidgetsGuiArg.setImplicit(true); m_qtWidgetsGuiArg.setImplicit(true);
#elif defined GUI_QTQUICK #elif defined QT_UTILITIES_GUI_QTQUICK
m_qtQuickGuiArg.setImplicit(true); m_qtQuickGuiArg.setImplicit(true);
#endif #endif
} }
@ -83,14 +83,14 @@ void QtConfigArguments::applySettings(bool preventApplyingDefaultFont) const
QLocale::setDefault(QLocale(QString::fromLocal8Bit(m_lngArg.values().front()))); QLocale::setDefault(QLocale(QString::fromLocal8Bit(m_lngArg.values().front())));
} }
if(m_styleArg.isPresent()) { if(m_styleArg.isPresent()) {
#ifdef GUI_QTWIDGETS #ifdef QT_UTILITIES_GUI_QTWIDGETS
if(QStyle *style = QStyleFactory::create(QString::fromLocal8Bit(m_styleArg.values().front()))) { if(QStyle *style = QStyleFactory::create(QString::fromLocal8Bit(m_styleArg.values().front()))) {
QApplication::setStyle(style); QApplication::setStyle(style);
} else { } else {
cerr << "Warning: Can not find the specified style." << endl; cerr << "Warning: Can not find the specified style." << endl;
} }
#else #else
# ifdef GUI_QTQUICK # ifdef QT_UTILITIES_GUI_QTQUICK
cerr << "Warning: Can not set a style for the Qt Quick GUI." << endl; cerr << "Warning: Can not set a style for the Qt Quick GUI." << endl;
# endif # endif
#endif #endif

View File

@ -10,12 +10,12 @@
#include <QDir> #include <QDir>
#include <QStringBuilder> #include <QStringBuilder>
#include <QSettings> #include <QSettings>
#if defined(GUI_QTWIDGETS) #if defined(QT_UTILITIES_GUI_QTWIDGETS)
# include <QApplication> # include <QApplication>
# include <QIcon> # include <QIcon>
# include <QFont> # include <QFont>
# include <QStyleFactory> # include <QStyleFactory>
#elif defined(GUI_QTQUICK) #elif defined(QT_UTILITIES_GUI_QTQUICK)
# include <QGuiApplication> # include <QGuiApplication>
# include <QIcon> # include <QIcon>
# include <QFont> # include <QFont>
@ -214,7 +214,7 @@ void loadApplicationTranslationFile(const std::initializer_list<QString> &applic
*/ */
namespace ApplicationInstances { namespace ApplicationInstances {
#if defined(GUI_QTWIDGETS) #if defined(QT_UTILITIES_GUI_QTWIDGETS)
/*! /*!
* \brief Returns whether a QApplication has been instantiated yet. * \brief Returns whether a QApplication has been instantiated yet.
*/ */
@ -224,7 +224,7 @@ bool hasWidgetsApp()
} }
#endif #endif
#if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK) #if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
/*! /*!
* \brief Returns whether a QGuiApplication has been instantiated yet. * \brief Returns whether a QGuiApplication has been instantiated yet.
*/ */

View File

@ -49,10 +49,10 @@ QT_UTILITIES_EXPORT void loadApplicationTranslationFile(const std::initializer_l
namespace ApplicationInstances { namespace ApplicationInstances {
#if defined(GUI_QTWIDGETS) #if defined(QT_UTILITIES_GUI_QTWIDGETS)
QT_UTILITIES_EXPORT bool hasWidgetsApp(); QT_UTILITIES_EXPORT bool hasWidgetsApp();
#endif #endif
#if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK) #if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
QT_UTILITIES_EXPORT bool hasGuiApp(); QT_UTILITIES_EXPORT bool hasGuiApp();
#endif #endif
QT_UTILITIES_EXPORT bool hasCoreApp(); QT_UTILITIES_EXPORT bool hasCoreApp();

View File

@ -1,7 +1,7 @@
#include "./optioncategorymodel.h" #include "./optioncategorymodel.h"
#include "./optioncategory.h" #include "./optioncategory.h"
#ifdef GUI_QTWIDGETS #ifdef QT_UTILITIES_GUI_QTWIDGETS
# include <QApplication> # include <QApplication>
# include <QStyle> # include <QStyle>
#endif #endif
@ -72,7 +72,7 @@ QVariant OptionCategoryModel::data(const QModelIndex &index, int role) const
const QIcon &icon = m_categories.at(index.row())->icon(); const QIcon &icon = m_categories.at(index.row())->icon();
if(!icon.isNull()) { if(!icon.isNull()) {
return icon.pixmap( return icon.pixmap(
#ifdef GUI_QTWIDGETS #ifdef QT_UTILITIES_GUI_QTWIDGETS
QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize) QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize)
#else #else
QSize(32, 32) QSize(32, 32)