diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..01f6ee801 --- /dev/null +++ b/.clang-format @@ -0,0 +1,196 @@ +--- +# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto +Language: Cpp +# BasedOnStyle: LLVM +# 访问说明符(public、private等)的偏移 +AccessModifierOffset: -4 +# 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行) +AlignAfterOpenBracket: Align +# 连续赋值时,对齐所有等号 +AlignConsecutiveAssignments: false +# 连续声明时,对齐所有声明的变量名 +AlignConsecutiveDeclarations: false + +AlignEscapedNewlines: Right + +# 左对齐逃脱换行(使用反斜杠换行)的反斜杠 +#AlignEscapedNewlinesLeft: true +# 水平对齐二元和三元表达式的操作数 +AlignOperands: true +# 对齐连续的尾随的注释 +AlignTrailingComments: true + +# 允许函数声明的所有参数在放在下一行 +AllowAllParametersOfDeclarationOnNextLine: true +# 允许短的块放在同一行 +AllowShortBlocksOnASingleLine: false +# 允许短的case标签放在同一行 +AllowShortCaseLabelsOnASingleLine: false +# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All +AllowShortFunctionsOnASingleLine: Inline +# 允许短的if语句保持在同一行 +AllowShortIfStatementsOnASingleLine: false +# 允许短的循环保持在同一行 +AllowShortLoopsOnASingleLine: false + +# 总是在定义返回类型后换行(deprecated) +AlwaysBreakAfterDefinitionReturnType: None +# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数), +# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义) +AlwaysBreakAfterReturnType: None +# 总是在多行string字面量前换行 +AlwaysBreakBeforeMultilineStrings: false +# 总是在template声明后换行 +AlwaysBreakTemplateDeclarations: false +# false表示函数实参要么都在同一行,要么都各自一行 +BinPackArguments: false +# false表示所有形参要么都在同一行,要么都各自一行 +BinPackParameters: false +# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效 +BraceWrapping: + # class定义后面 + AfterClass: true + # 控制语句后面 + AfterControlStatement: false + # enum定义后面 + AfterEnum: false + # 函数定义后面 + AfterFunction: true + # 命名空间定义后面 + AfterNamespace: false + # ObjC定义后面 + AfterObjCDeclaration: false + # struct定义后面 + AfterStruct: true + # union定义后面 + AfterUnion: true + + AfterExternBlock: false + # catch之前 + BeforeCatch: false + # else之前 + BeforeElse: false + # 缩进大括号 + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true + +# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行) +BreakBeforeBinaryOperators: None +# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似), +# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似), +# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom +# 注:这里认为语句块也属于函数 +BreakBeforeBraces: Custom +# 在三元运算符前换行 +BreakBeforeTernaryOperators: false + +# 在构造函数的初始化列表的逗号前换行 +BreakConstructorInitializersBeforeComma: true +BreakConstructorInitializers: BeforeColon +# 每行字符的限制,0表示没有限制 +ColumnLimit: 130 +# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +# 构造函数的初始化列表要么都在同一行,要么都各自一行 +ConstructorInitializerAllOnOneLineOrOnePerLine: false +# 构造函数的初始化列表的缩进宽度 +ConstructorInitializerIndentWidth: 4 +# 延续的行的缩进宽度 +ContinuationIndentWidth: 4 +# 去除C++11的列表初始化的大括号{后和}前的空格 +Cpp11BracedListStyle: true +# 继承最常用的指针和引用的对齐方式 +DerivePointerAlignment: false +# 关闭格式化 +DisableFormat: false +# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental) +ExperimentalAutoDetectBinPacking: false +# 需要被解读为foreach循环而不是函数调用的宏 +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +# 对#include进行排序,匹配了某正则表达式的#include拥有对应的优先级,匹配不到的则默认优先级为INT_MAX(优先级越小排序越靠前), +# 可以定义负数优先级从而保证某些#include永远在最前面 +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +# 缩进case标签 +IndentCaseLabels: true + +IndentPPDirectives: AfterHash +# 缩进宽度 +IndentWidth: 4 +# 函数返回类型换行时,缩进函数声明或函数定义的函数名 +IndentWrappedFunctionNames: false +# 保留在块开始处的空行 +KeepEmptyLinesAtTheStartOfBlocks: false +# 开始一个块的宏的正则表达式 +MacroBlockBegin: '' +# 结束一个块的宏的正则表达式 +MacroBlockEnd: '' +# 连续空行的最大数量 +MaxEmptyLinesToKeep: 1 +# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All +NamespaceIndentation: Inner +# 使用ObjC块时缩进宽度 +ObjCBlockIndentWidth: 4 +# 在ObjC的@property后添加一个空格 +ObjCSpaceAfterProperty: false +# 在ObjC的protocol列表前添加一个空格 +ObjCSpaceBeforeProtocolList: true + + +# 在call(后对函数调用换行的penalty +PenaltyBreakBeforeFirstCallParameter: 19 +# 在一个注释中引入换行的penalty +PenaltyBreakComment: 300 +# 第一次在<<前换行的penalty +PenaltyBreakFirstLessLess: 120 +# 在一个字符串字面量中引入换行的penalty +PenaltyBreakString: 1000 +# 对于每个在行字符数限制之外的字符的penalty +PenaltyExcessCharacter: 1000000 +# 将函数的返回类型放到它自己的行的penalty +PenaltyReturnTypeOnItsOwnLine: 60 + +# 指针和引用的对齐: Left, Right, Middle +PointerAlignment: Right +# 允许重新排版注释 +ReflowComments: true +# 允许排序#include +SortIncludes: true + +# 在C风格类型转换后添加空格 +SpaceAfterCStyleCast: false + +SpaceAfterTemplateKeyword: true + +# 在赋值运算符之前添加空格 +SpaceBeforeAssignmentOperators: true +# 开圆括号之前添加一个空格: Never, ControlStatements, Always +SpaceBeforeParens: ControlStatements +# 在空的圆括号中添加空格 +SpaceInEmptyParentheses: false +# 在尾随的评论前添加的空格数(只适用于//) +SpacesBeforeTrailingComments: 2 +# 在尖括号的<后和>前添加空格 +SpacesInAngles: false +# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格 +SpacesInContainerLiterals: false +# 在C风格类型转换的括号中添加空格 +SpacesInCStyleCastParentheses: false +# 在圆括号的(后和)前添加空格 +SpacesInParentheses: false +# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响 +SpacesInSquareBrackets: false +# 标准: Cpp03, Cpp11, Auto +Standard: Auto +# tab宽度 +TabWidth: 4 +# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always +UseTab: Never \ No newline at end of file diff --git a/.gitignore b/.gitignore index 75c107bcc..b4da253be 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *.pro.user +build +.cache diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..2f2f7caf8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +project(qt-material-widgets) +cmake_minimum_required(VERSION 3.22) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +add_subdirectory(examples) +add_subdirectory(components) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 000000000..44bb9529c --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,322 @@ + + + + + + EnvironmentId + {d2b00d11-c185-4f43-9d72-0d9e9d9ad5bb} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + Desktop + {2ebfeb06-0a8a-455d-9f68-fc633ebb7f9a} + 0 + 0 + 0 + + Debug + -DCMAKE_GENERATOR:STRING=Unix Makefiles +-DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + /home/cht/git/build-qt-material-widgets-Desktop-Debug + + + + all + + true + Build + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + Build + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + Release + -DCMAKE_GENERATOR:STRING=Unix Makefiles +-DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + /home/cht/git/build-qt-material-widgets-Desktop-Release + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + -DCMAKE_GENERATOR:STRING=Unix Makefiles +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + /home/cht/git/build-qt-material-widgets-Desktop-RelWithDebInfo + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + MinSizeRel + -DCMAKE_GENERATOR:STRING=Unix Makefiles +-DCMAKE_BUILD_TYPE:STRING=MinSizeRel +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + /home/cht/git/build-qt-material-widgets-Desktop-MinSizeRel + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + examples + CMakeProjectManager.CMakeRunConfiguration.examples + examples + false + true + true + false + true + /home/cht/git/build-qt-material-widgets-Desktop-Debug/examples + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/README.md b/README.md index c73eed0dd..501441016 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ YouTube video preview [available here](http://www.youtube.com/watch?v=21UMeNVBPU4). + diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt new file mode 100644 index 000000000..8f2fc18f0 --- /dev/null +++ b/components/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.5) + +project( + components + VERSION 0.1 + LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Qt5 REQUIRED COMPONENTS Core) +find_package(Qt5 REQUIRED COMPONENTS Widgets) + +file(GLOB THELIB "materiallib/*") +file(GLOB COMPONENTSHEADER "*.h") +file(GLOB COMPONENTSSOURCE "*.cpp") +file(GLOB HEADER "../include/qmetarial/*") +file(GLOB HEADER2 "../include/qmetarial/lib/*") + +set(RCC_FILES resources.qrc) +add_library( + ${PROJECT_NAME} STATIC ${THELIB} ${COMPONENTSHEADER} ${COMPONENTSSOURCE} + ${RCC_FILES} ${HEADER} ${HEADER2}) +target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Widgets) +target_include_directories(${PROJECT_NAME} PUBLIC ../include/qmetarial/) +target_link_directories(${PROJECT_NAME} PUBLIC .) diff --git a/components/components.pro b/components/components.pro deleted file mode 100644 index d6080d5db..000000000 --- a/components/components.pro +++ /dev/null @@ -1,130 +0,0 @@ -TEMPLATE = lib -CONFIG += staticlib -SOURCES = \ - qtmaterialavatar.cpp \ - lib/qtmaterialstyle.cpp \ - lib/qtmaterialtheme.cpp \ - qtmaterialbadge.cpp \ - lib/qtmaterialoverlaywidget.cpp \ - qtmaterialcheckbox.cpp \ - lib/qtmaterialcheckable_internal.cpp \ - lib/qtmaterialcheckable.cpp \ - lib/qtmaterialripple.cpp \ - lib/qtmaterialrippleoverlay.cpp \ - qtmaterialfab.cpp \ - qtmaterialraisedbutton.cpp \ - qtmaterialflatbutton_internal.cpp \ - qtmaterialflatbutton.cpp \ - lib/qtmaterialstatetransition.cpp \ - qtmaterialiconbutton.cpp \ - qtmaterialprogress_internal.cpp \ - qtmaterialprogress.cpp \ - qtmaterialcircularprogress_internal.cpp \ - qtmaterialcircularprogress.cpp \ - qtmaterialslider_internal.cpp \ - qtmaterialslider.cpp \ - qtmaterialsnackbar_internal.cpp \ - qtmaterialsnackbar.cpp \ - qtmaterialradiobutton.cpp \ - qtmaterialtoggle_internal.cpp \ - qtmaterialtoggle.cpp \ - qtmaterialtextfield_internal.cpp \ - qtmaterialtextfield.cpp \ - qtmaterialtabs_internal.cpp \ - qtmaterialtabs.cpp \ - qtmaterialscrollbar_internal.cpp \ - qtmaterialscrollbar.cpp \ - qtmaterialdialog_internal.cpp \ - qtmaterialdialog.cpp \ - qtmaterialdrawer_internal.cpp \ - qtmaterialdrawer.cpp \ - qtmaterialappbar.cpp \ - qtmaterialautocomplete.cpp \ - qtmaterialpaper.cpp \ - qtmaterialtable.cpp \ - layouts/qtmaterialsnackbarlayout.cpp \ - qtmaterialautocomplete_internal.cpp \ - qtmaterialmenu.cpp \ - qtmaterialmenu_internal.cpp \ - qtmateriallist.cpp \ - qtmateriallistitem.cpp -HEADERS = \ - qtmaterialavatar_p.h \ - qtmaterialavatar.h \ - lib/qtmaterialstyle_p.h \ - lib/qtmaterialstyle.h \ - lib/qtmaterialtheme_p.h \ - lib/qtmaterialtheme.h \ - qtmaterialbadge_p.h \ - qtmaterialbadge.h \ - lib/qtmaterialoverlaywidget.h \ - qtmaterialcheckbox_p.h \ - qtmaterialcheckbox.h \ - lib/qtmaterialcheckable_internal.h \ - lib/qtmaterialcheckable_p.h \ - lib/qtmaterialripple.h \ - lib/qtmaterialrippleoverlay.h \ - lib/qtmaterialcheckable.h \ - qtmaterialfab_p.h \ - qtmaterialfab.h \ - qtmaterialraisedbutton_p.h \ - qtmaterialraisedbutton.h \ - qtmaterialflatbutton_internal.h \ - qtmaterialflatbutton_p.h \ - qtmaterialflatbutton.h \ - lib/qtmaterialstatetransition.h \ - lib/qtmaterialstatetransitionevent.h \ - qtmaterialiconbutton_p.h \ - qtmaterialiconbutton.h \ - qtmaterialprogress_internal.h \ - qtmaterialprogress_p.h \ - qtmaterialprogress.h \ - qtmaterialcircularprogress_internal.h \ - qtmaterialcircularprogress_p.h \ - qtmaterialcircularprogress.h \ - qtmaterialslider_internal.h \ - qtmaterialslider_p.h \ - qtmaterialslider.h \ - qtmaterialsnackbar_internal.h \ - qtmaterialsnackbar_p.h \ - qtmaterialsnackbar.h \ - qtmaterialradiobutton_p.h \ - qtmaterialradiobutton.h \ - qtmaterialtoggle_internal.h \ - qtmaterialtoggle_p.h \ - qtmaterialtoggle.h \ - qtmaterialtextfield_internal.h \ - qtmaterialtextfield_p.h \ - qtmaterialtextfield.h \ - qtmaterialtabs_internal.h \ - qtmaterialtabs_p.h \ - qtmaterialtabs.h \ - qtmaterialscrollbar_internal.h \ - qtmaterialscrollbar_p.h \ - qtmaterialscrollbar.h \ - qtmaterialdialog_internal.h \ - qtmaterialdialog_p.h \ - qtmaterialdialog.h \ - qtmaterialdrawer_internal.h \ - qtmaterialdrawer_p.h \ - qtmaterialdrawer.h \ - qtmaterialappbar.h \ - qtmaterialappbar_p.h \ - qtmaterialautocomplete.h \ - qtmaterialautocomplete_p.h \ - qtmaterialpaper.h \ - qtmaterialpaper_p.h \ - qtmaterialtable.h \ - qtmaterialtable_p.h \ - layouts/qtmaterialsnackbarlayout.h \ - layouts/qtmaterialsnackbarlayout_p.h \ - qtmaterialautocomplete_internal.h \ - qtmaterialmenu.h \ - qtmaterialmenu_p.h \ - qtmaterialmenu_internal.h \ - qtmateriallist.h \ - qtmateriallist_p.h \ - qtmateriallistitem.h \ - qtmateriallistitem_p.h -RESOURCES += \ - resources.qrc diff --git a/components/layouts/qtmaterialsnackbarlayout.cpp b/components/layouts/qtmaterialsnackbarlayout.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/components/layouts/qtmaterialsnackbarlayout.h b/components/layouts/qtmaterialsnackbarlayout.h deleted file mode 100644 index c194fec81..000000000 --- a/components/layouts/qtmaterialsnackbarlayout.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef QTMATERIALSNACKBARLAYOUT_H -#define QTMATERIALSNACKBARLAYOUT_H - -#endif // QTMATERIALSNACKBARLAYOUT_H diff --git a/components/layouts/qtmaterialsnackbarlayout_p.h b/components/layouts/qtmaterialsnackbarlayout_p.h deleted file mode 100644 index 6c2dd5dcf..000000000 --- a/components/layouts/qtmaterialsnackbarlayout_p.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef QTMATERIALSNACKBARLAYOUT_P_H -#define QTMATERIALSNACKBARLAYOUT_P_H - -#endif // QTMATERIALSNACKBARLAYOUT_P_H diff --git a/components/lib/qtmaterialcheckable_p.h b/components/lib/qtmaterialcheckable_p.h deleted file mode 100644 index e678df70f..000000000 --- a/components/lib/qtmaterialcheckable_p.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef QTMATERIALCHECKABLE_P_H -#define QTMATERIALCHECKABLE_P_H - -#include -#include "lib/qtmaterialcheckable.h" - -class QStateMachine; -class QState; -class QSignalTransition; -class QtMaterialRippleOverlay; -class QtMaterialCheckableIcon; - -class QtMaterialCheckablePrivate -{ - Q_DISABLE_COPY(QtMaterialCheckablePrivate) - Q_DECLARE_PUBLIC(QtMaterialCheckable) - -public: - QtMaterialCheckablePrivate(QtMaterialCheckable *q); - virtual ~QtMaterialCheckablePrivate(); - - void init(); - - QtMaterialCheckable *const q_ptr; - QtMaterialRippleOverlay *rippleOverlay; - QtMaterialCheckableIcon *checkedIcon; - QtMaterialCheckableIcon *uncheckedIcon; - QStateMachine *stateMachine; - QState *uncheckedState; - QState *checkedState; - QState *disabledUncheckedState; - QState *disabledCheckedState; - QSignalTransition *uncheckedTransition; - QSignalTransition *checkedTransition; - QtMaterialCheckable::LabelPosition labelPosition; - QColor checkedColor; - QColor uncheckedColor; - QColor textColor; - QColor disabledColor; - bool useThemeColors; -}; - -#endif // QTMATERIALCHECKABLE_P_H diff --git a/components/lib/qtmaterialoverlaywidget.cpp b/components/lib/qtmaterialoverlaywidget.cpp deleted file mode 100644 index ec0e7fedb..000000000 --- a/components/lib/qtmaterialoverlaywidget.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "lib/qtmaterialoverlaywidget.h" -#include - -/*! - * \class QtMaterialOverlayWidget - * \internal - */ - -QtMaterialOverlayWidget::QtMaterialOverlayWidget(QWidget *parent) - : QWidget(parent) -{ - if (parent) { - parent->installEventFilter(this); - } -} - -QtMaterialOverlayWidget::~QtMaterialOverlayWidget() -{ -} - -/*! - * \reimp - */ -bool QtMaterialOverlayWidget::event(QEvent *event) -{ - if (!parent()) { - return QWidget::event(event); - } - switch (event->type()) - { - case QEvent::ParentChange: - { - parent()->installEventFilter(this); - setGeometry(overlayGeometry()); - break; - } - case QEvent::ParentAboutToChange: - { - parent()->removeEventFilter(this); - break; - } - default: - break; - } - return QWidget::event(event); -} - -/*! - * \reimp - */ -bool QtMaterialOverlayWidget::eventFilter(QObject *obj, QEvent *event) -{ - switch (event->type()) - { - case QEvent::Move: - case QEvent::Resize: - setGeometry(overlayGeometry()); - break; - default: - break; - } - return QWidget::eventFilter(obj, event); -} - -QRect QtMaterialOverlayWidget::overlayGeometry() const -{ - QWidget *widget = parentWidget(); - if (!widget) { - return QRect(); - } - return widget->rect(); -} diff --git a/components/lib/qtmaterialtheme.cpp b/components/lib/qtmaterialtheme.cpp deleted file mode 100644 index 725c95480..000000000 --- a/components/lib/qtmaterialtheme.cpp +++ /dev/null @@ -1,159 +0,0 @@ -#include "lib/qtmaterialtheme.h" -#include "lib/qtmaterialtheme_p.h" -#include -#include -#include - -/*!material - * \class QtMaterialThemePrivate - * \internal - */ - -QtMaterialThemePrivate::QtMaterialThemePrivate(QtMaterialTheme *q) - : q_ptr(q) -{ -} - -QtMaterialThemePrivate::~QtMaterialThemePrivate() -{ -} - -QColor QtMaterialThemePrivate::rgba(int r, int g, int b, qreal a) const -{ - QColor color(r, g, b); - color.setAlphaF(a); - return color; -} - -/*! - * \class QtMaterialTheme - */ - -QtMaterialTheme::QtMaterialTheme(QObject *parent) - : QObject(parent), - d_ptr(new QtMaterialThemePrivate(this)) -{ - setColor("primary1", Material::cyan500); - setColor("primary2", Material::cyan700); - setColor("primary3", Material::lightBlack); - setColor("accent1", Material::pinkA200); - setColor("accent2", Material::grey100); - setColor("accent3", Material::grey500); - setColor("text", Material::darkBlack); - setColor("alternateText", Material::white); - setColor("canvas", Material::white); - setColor("border", Material::grey300); - setColor("disabled", Material::minBlack); - setColor("disabled2", Material::faintBlack); - setColor("disabled3", Material::grey300); -} - -QtMaterialTheme::~QtMaterialTheme() -{ -} - -QColor QtMaterialTheme::getColor(const QString &key) const -{ - Q_D(const QtMaterialTheme); - - if (!d->colors.contains(key)) { - qWarning() << "A theme color matching the key '" << key << "' could not be found."; - return QColor(); - } - return d->colors.value(key); -} - -void QtMaterialTheme::setColor(const QString &key, const QColor &color) -{ - Q_D(QtMaterialTheme); - - d->colors.insert(key, color); -} - -void QtMaterialTheme::setColor(const QString &key, Material::Color color) -{ - Q_D(QtMaterialTheme); - - static const QColor palette[] = { - QColor("#ffebee"), QColor("#ffcdd2"), QColor("#ef9a9a"), QColor("#e57373"), - QColor("#ef5350"), QColor("#f44336"), QColor("#e53935"), QColor("#d32f2f"), - QColor("#c62828"), QColor("#b71c1c"), QColor("#ff8a80"), QColor("#ff5252"), - QColor("#ff1744"), QColor("#d50000"), QColor("#fce4ec"), QColor("#f8bbd0"), - QColor("#f48fb1"), QColor("#f06292"), QColor("#ec407a"), QColor("#e91e63"), - QColor("#d81b60"), QColor("#c2185b"), QColor("#ad1457"), QColor("#880e4f"), - QColor("#ff80ab"), QColor("#ff4081"), QColor("#f50057"), QColor("#c51162"), - QColor("#f3e5f5"), QColor("#e1bee7"), QColor("#ce93d8"), QColor("#ba68c8"), - QColor("#ab47bc"), QColor("#9c27b0"), QColor("#8e24aa"), QColor("#7b1fa2"), - QColor("#6a1b9a"), QColor("#4a148c"), QColor("#ea80fc"), QColor("#e040fb"), - QColor("#d500f9"), QColor("#aa00ff"), QColor("#ede7f6"), QColor("#d1c4e9"), - QColor("#b39ddb"), QColor("#9575cd"), QColor("#7e57c2"), QColor("#673ab7"), - QColor("#5e35b1"), QColor("#512da8"), QColor("#4527a0"), QColor("#311b92"), - QColor("#b388ff"), QColor("#7c4dff"), QColor("#651fff"), QColor("#6200ea"), - QColor("#e8eaf6"), QColor("#c5cae9"), QColor("#9fa8da"), QColor("#7986cb"), - QColor("#5c6bc0"), QColor("#3f51b5"), QColor("#3949ab"), QColor("#303f9f"), - QColor("#283593"), QColor("#1a237e"), QColor("#8c9eff"), QColor("#536dfe"), - QColor("#3d5afe"), QColor("#304ffe"), QColor("#e3f2fd"), QColor("#bbdefb"), - QColor("#90caf9"), QColor("#64b5f6"), QColor("#42a5f5"), QColor("#2196f3"), - QColor("#1e88e5"), QColor("#1976d2"), QColor("#1565c0"), QColor("#0d47a1"), - QColor("#82b1ff"), QColor("#448aff"), QColor("#2979ff"), QColor("#2962ff"), - QColor("#e1f5fe"), QColor("#b3e5fc"), QColor("#81d4fa"), QColor("#4fc3f7"), - QColor("#29b6f6"), QColor("#03a9f4"), QColor("#039be5"), QColor("#0288d1"), - QColor("#0277bd"), QColor("#01579b"), QColor("#80d8ff"), QColor("#40c4ff"), - QColor("#00b0ff"), QColor("#0091ea"), QColor("#e0f7fa"), QColor("#b2ebf2"), - QColor("#80deea"), QColor("#4dd0e1"), QColor("#26c6da"), QColor("#00bcd4"), - QColor("#00acc1"), QColor("#0097a7"), QColor("#00838f"), QColor("#006064"), - QColor("#84ffff"), QColor("#18ffff"), QColor("#00e5ff"), QColor("#00b8d4"), - QColor("#e0f2f1"), QColor("#b2dfdb"), QColor("#80cbc4"), QColor("#4db6ac"), - QColor("#26a69a"), QColor("#009688"), QColor("#00897b"), QColor("#00796b"), - QColor("#00695c"), QColor("#004d40"), QColor("#a7ffeb"), QColor("#64ffda"), - QColor("#1de9b6"), QColor("#00bfa5"), QColor("#e8f5e9"), QColor("#c8e6c9"), - QColor("#a5d6a7"), QColor("#81c784"), QColor("#66bb6a"), QColor("#4caf50"), - QColor("#43a047"), QColor("#388e3c"), QColor("#2e7d32"), QColor("#1b5e20"), - QColor("#b9f6ca"), QColor("#69f0ae"), QColor("#00e676"), QColor("#00c853"), - QColor("#f1f8e9"), QColor("#dcedc8"), QColor("#c5e1a5"), QColor("#aed581"), - QColor("#9ccc65"), QColor("#8bc34a"), QColor("#7cb342"), QColor("#689f38"), - QColor("#558b2f"), QColor("#33691e"), QColor("#ccff90"), QColor("#b2ff59"), - QColor("#76ff03"), QColor("#64dd17"), QColor("#f9fbe7"), QColor("#f0f4c3"), - QColor("#e6ee9c"), QColor("#dce775"), QColor("#d4e157"), QColor("#cddc39"), - QColor("#c0ca33"), QColor("#afb42b"), QColor("#9e9d24"), QColor("#827717"), - QColor("#f4ff81"), QColor("#eeff41"), QColor("#c6ff00"), QColor("#aeea00"), - QColor("#fffde7"), QColor("#fff9c4"), QColor("#fff59d"), QColor("#fff176"), - QColor("#ffee58"), QColor("#ffeb3b"), QColor("#fdd835"), QColor("#fbc02d"), - QColor("#f9a825"), QColor("#f57f17"), QColor("#ffff8d"), QColor("#ffff00"), - QColor("#ffea00"), QColor("#ffd600"), QColor("#fff8e1"), QColor("#ffecb3"), - QColor("#ffe082"), QColor("#ffd54f"), QColor("#ffca28"), QColor("#ffc107"), - QColor("#ffb300"), QColor("#ffa000"), QColor("#ff8f00"), QColor("#ff6f00"), - QColor("#ffe57f"), QColor("#ffd740"), QColor("#ffc400"), QColor("#ffab00"), - QColor("#fff3e0"), QColor("#ffe0b2"), QColor("#ffcc80"), QColor("#ffb74d"), - QColor("#ffa726"), QColor("#ff9800"), QColor("#fb8c00"), QColor("#f57c00"), - QColor("#ef6c00"), QColor("#e65100"), QColor("#ffd180"), QColor("#ffab40"), - QColor("#ff9100"), QColor("#ff6d00"), QColor("#fbe9e7"), QColor("#ffccbc"), - QColor("#ffab91"), QColor("#ff8a65"), QColor("#ff7043"), QColor("#ff5722"), - QColor("#f4511e"), QColor("#e64a19"), QColor("#d84315"), QColor("#bf360c"), - QColor("#ff9e80"), QColor("#ff6e40"), QColor("#ff3d00"), QColor("#dd2c00"), - QColor("#efebe9"), QColor("#d7ccc8"), QColor("#bcaaa4"), QColor("#a1887f"), - QColor("#8d6e63"), QColor("#795548"), QColor("#6d4c41"), QColor("#5d4037"), - QColor("#4e342e"), QColor("#3e2723"), QColor("#eceff1"), QColor("#cfd8dc"), - QColor("#b0bec5"), QColor("#90a4ae"), QColor("#78909c"), QColor("#607d8b"), - QColor("#546e7a"), QColor("#455a64"), QColor("#37474f"), QColor("#263238"), - QColor("#fafafa"), QColor("#f5f5f5"), QColor("#eeeeee"), QColor("#e0e0e0"), - QColor("#bdbdbd"), QColor("#9e9e9e"), QColor("#757575"), QColor("#616161"), - QColor("#424242"), QColor("#212121"), QColor("#000000"), QColor("#ffffff"), - d->rgba(0, 0, 0, 0), - d->rgba(0, 0, 0, 1), - d->rgba(0, 0, 0, 0.87), - d->rgba(0, 0, 0, 0.54), - d->rgba(0, 0, 0, 0.26), - d->rgba(0, 0, 0, 0.12), - d->rgba(255, 255, 255, 1), - d->rgba(255, 255, 255, 0.87), - d->rgba(255, 255, 255, 0.54) - }; - - d->colors.insert(key, palette[color]); -} - -QIcon QtMaterialTheme::icon(QString category, QString icon) -{ - return QIcon(":/icons/icons/" % category % "/svg/production/ic_" % icon % "_24px.svg"); -} diff --git a/components/lib/qtmaterialtheme.h b/components/lib/qtmaterialtheme.h deleted file mode 100644 index fe4a11c82..000000000 --- a/components/lib/qtmaterialtheme.h +++ /dev/null @@ -1,344 +0,0 @@ -#ifndef QTMATERIALTHEME_H -#define QTMATERIALTHEME_H - -#include -#include -#include -#include - -namespace Material -{ - enum ButtonPreset { - FlatPreset, - CheckablePreset - }; - - enum RippleStyle { - CenteredRipple, - PositionedRipple, - NoRipple - }; - - enum OverlayStyle { - NoOverlay, - TintedOverlay, - GrayOverlay - }; - - enum Role { - Default, - Primary, - Secondary - }; - - enum ButtonIconPlacement { - LeftIcon, - RightIcon - }; - - enum ProgressType { - DeterminateProgress, - IndeterminateProgress - }; - - enum AvatarType { - ImageAvatar, - IconAvatar, - LetterAvatar - }; - - enum Color { - red50, - red100, - red200, - red300, - red400, - red500, - red600, - red700, - red800, - red900, - redA100, - redA200, - redA400, - redA700, - pink50, - pink100, - pink200, - pink300, - pink400, - pink500, - pink600, - pink700, - pink800, - pink900, - pinkA100, - pinkA200, - pinkA400, - pinkA700, - purple50, - purple100, - purple200, - purple300, - purple400, - purple500, - purple600, - purple700, - purple800, - purple900, - purpleA100, - purpleA200, - purpleA400, - purpleA700, - deepPurple50, - deepPurple100, - deepPurple200, - deepPurple300, - deepPurple400, - deepPurple500, - deepPurple600, - deepPurple700, - deepPurple800, - deepPurple900, - deepPurpleA100, - deepPurpleA200, - deepPurpleA400, - deepPurpleA700, - indigo50, - indigo100, - indigo200, - indigo300, - indigo400, - indigo500, - indigo600, - indigo700, - indigo800, - indigo900, - indigoA100, - indigoA200, - indigoA400, - indigoA700, - blue50, - blue100, - blue200, - blue300, - blue400, - blue500, - blue600, - blue700, - blue800, - blue900, - blueA100, - blueA200, - blueA400, - blueA700, - lightBlue50, - lightBlue100, - lightBlue200, - lightBlue300, - lightBlue400, - lightBlue500, - lightBlue600, - lightBlue700, - lightBlue800, - lightBlue900, - lightBlueA100, - lightBlueA200, - lightBlueA400, - lightBlueA700, - cyan50, - cyan100, - cyan200, - cyan300, - cyan400, - cyan500, - cyan600, - cyan700, - cyan800, - cyan900, - cyanA100, - cyanA200, - cyanA400, - cyanA700, - teal50, - teal100, - teal200, - teal300, - teal400, - teal500, - teal600, - teal700, - teal800, - teal900, - tealA100, - tealA200, - tealA400, - tealA700, - green50, - green100, - green200, - green300, - green400, - green500, - green600, - green700, - green800, - green900, - greenA100, - greenA200, - greenA400, - greenA700, - lightGreen50, - lightGreen100, - lightGreen200, - lightGreen300, - lightGreen400, - lightGreen500, - lightGreen600, - lightGreen700, - lightGreen800, - lightGreen900, - lightGreenA100, - lightGreenA200, - lightGreenA400, - lightGreenA700, - lime50, - lime100, - lime200, - lime300, - lime400, - lime500, - lime600, - lime700, - lime800, - lime900, - limeA100, - limeA200, - limeA400, - limeA700, - yellow50, - yellow100, - yellow200, - yellow300, - yellow400, - yellow500, - yellow600, - yellow700, - yellow800, - yellow900, - yellowA100, - yellowA200, - yellowA400, - yellowA700, - amber50, - amber100, - amber200, - amber300, - amber400, - amber500, - amber600, - amber700, - amber800, - amber900, - amberA100, - amberA200, - amberA400, - amberA700, - orange50, - orange100, - orange200, - orange300, - orange400, - orange500, - orange600, - orange700, - orange800, - orange900, - orangeA100, - orangeA200, - orangeA400, - orangeA700, - deepOrange50, - deepOrange100, - deepOrange200, - deepOrange300, - deepOrange400, - deepOrange500, - deepOrange600, - deepOrange700, - deepOrange800, - deepOrange900, - deepOrangeA100, - deepOrangeA200, - deepOrangeA400, - deepOrangeA700, - brown50, - brown100, - brown200, - brown300, - brown400, - brown500, - brown600, - brown700, - brown800, - brown900, - blueGrey50, - blueGrey100, - blueGrey200, - blueGrey300, - blueGrey400, - blueGrey500, - blueGrey600, - blueGrey700, - blueGrey800, - blueGrey900, - grey50, - grey100, - grey200, - grey300, - grey400, - grey500, - grey600, - grey700, - grey800, - grey900, - black, - white, - transparent, - fullBlack, - darkBlack, - lightBlack, - minBlack, - faintBlack, - fullWhite, - darkWhite, - lightWhite - }; -} - -class QtMaterialThemePrivate; - -class QtMaterialTheme : public QObject -{ - Q_OBJECT - -public: - explicit QtMaterialTheme(QObject *parent = 0); - ~QtMaterialTheme(); - - QColor getColor(const QString &key) const; - - void setColor(const QString &key, const QColor &color); - void setColor(const QString &key, Material::Color color); - - static QIcon icon(QString category, QString icon); - -protected: - const QScopedPointer d_ptr; - -private: - Q_DISABLE_COPY(QtMaterialTheme) - Q_DECLARE_PRIVATE(QtMaterialTheme) -}; - -#endif // QTMATERIALTHEME_H diff --git a/components/lib/qtmaterialcheckable.cpp b/components/materiallib/qtmaterialcheckable.cpp similarity index 81% rename from components/lib/qtmaterialcheckable.cpp rename to components/materiallib/qtmaterialcheckable.cpp index ee4e0bd88..c50230b80 100644 --- a/components/lib/qtmaterialcheckable.cpp +++ b/components/materiallib/qtmaterialcheckable.cpp @@ -1,20 +1,22 @@ -#include "lib/qtmaterialcheckable.h" -#include "lib/qtmaterialcheckable_p.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include + +#include "qtmaterialcheckable_p.h" + #include #include -#include "lib/qtmaterialrippleoverlay.h" -#include "lib/qtmaterialripple.h" -#include "lib/qtmaterialstyle.h" -#include "lib/qtmaterialcheckable_internal.h" +#include +#include +#include +#include +#include /*! - * \class QtMaterialCheckablePrivate - * \internal + * @class QtMaterialCheckablePrivate + * @internal */ QtMaterialCheckablePrivate::QtMaterialCheckablePrivate(QtMaterialCheckable *q) @@ -22,26 +24,25 @@ QtMaterialCheckablePrivate::QtMaterialCheckablePrivate(QtMaterialCheckable *q) { } -QtMaterialCheckablePrivate::~QtMaterialCheckablePrivate() -{ -} +QtMaterialCheckablePrivate::~QtMaterialCheckablePrivate() {} void QtMaterialCheckablePrivate::init() { Q_Q(QtMaterialCheckable); - rippleOverlay = new QtMaterialRippleOverlay; - checkedIcon = new QtMaterialCheckableIcon(QIcon(":/icons/icons/toggle/svg/production/ic_check_box_24px.svg"), q); - uncheckedIcon = new QtMaterialCheckableIcon(QIcon(":/icons/icons/toggle/svg/production/ic_check_box_outline_blank_24px.svg"), q); - stateMachine = new QStateMachine(q); - uncheckedState = new QState; - checkedState = new QState; + rippleOverlay = new QtMaterialRippleOverlay; + checkedIcon = new QtMaterialCheckableIcon(QIcon(":/icons/icons/toggle/svg/production/ic_check_box_24px.svg"), q); + uncheckedIcon = + new QtMaterialCheckableIcon(QIcon(":/icons/icons/toggle/svg/production/ic_check_box_outline_blank_24px.svg"), q); + stateMachine = new QStateMachine(q); + uncheckedState = new QState; + checkedState = new QState; disabledUncheckedState = new QState; - disabledCheckedState = new QState; - uncheckedTransition = new QSignalTransition(q, SIGNAL(toggled(bool))); - checkedTransition = new QSignalTransition(q, SIGNAL(toggled(bool))); - labelPosition = QtMaterialCheckable::LabelPositionRight; - useThemeColors = true; + disabledCheckedState = new QState; + uncheckedTransition = new QSignalTransition(q, SIGNAL(toggled(bool))); + checkedTransition = new QSignalTransition(q, SIGNAL(toggled(bool))); + labelPosition = QtMaterialCheckable::LabelPositionRight; + useThemeColors = true; rippleOverlay->setParent(q->parentWidget()); rippleOverlay->installEventFilter(q); @@ -122,19 +123,17 @@ void QtMaterialCheckablePrivate::init() } /*! - * \class QtMaterialCheckable + * @class QtMaterialCheckable */ QtMaterialCheckable::QtMaterialCheckable(QWidget *parent) - : QAbstractButton(parent), - d_ptr(new QtMaterialCheckablePrivate(this)) + : QAbstractButton(parent) + , d_ptr(new QtMaterialCheckablePrivate(this)) { d_func()->init(); } -QtMaterialCheckable::~QtMaterialCheckable() -{ -} +QtMaterialCheckable::~QtMaterialCheckable() {} void QtMaterialCheckable::setLabelPosition(LabelPosition placement) { @@ -285,57 +284,55 @@ QIcon QtMaterialCheckable::uncheckedIcon() const } /*! - * \reimp + * @reimp */ QSize QtMaterialCheckable::sizeHint() const { if (text().isEmpty()) { return QSize(40, 40); } - return QSize(fontMetrics().size(Qt::TextShowMnemonic, text()).width()+52, 40); + return QSize(fontMetrics().size(Qt::TextShowMnemonic, text()).width() + 52, 40); } QtMaterialCheckable::QtMaterialCheckable(QtMaterialCheckablePrivate &d, QWidget *parent) - : QAbstractButton(parent), - d_ptr(&d) + : QAbstractButton(parent) + , d_ptr(&d) { d_func()->init(); } /*! - * \reimp + * @reimp */ bool QtMaterialCheckable::event(QEvent *event) { Q_D(QtMaterialCheckable); - switch (event->type()) - { - case QEvent::Resize: - case QEvent::Move: - d->checkedIcon->setGeometry(rect()); - d->uncheckedIcon->setGeometry(rect()); - d->rippleOverlay->setGeometry(geometry().adjusted(-8, -8, 8, 8)); - break; - case QEvent::ParentChange: - QWidget *widget; - if ((widget = parentWidget())) { - d->rippleOverlay->setParent(widget); - } - break; - default: - break; + switch (event->type()) { + case QEvent::Resize: + case QEvent::Move: + d->checkedIcon->setGeometry(rect()); + d->uncheckedIcon->setGeometry(rect()); + d->rippleOverlay->setGeometry(geometry().adjusted(-8, -8, 8, 8)); + break; + case QEvent::ParentChange: + QWidget *widget; + if ((widget = parentWidget())) { + d->rippleOverlay->setParent(widget); + } + break; + default: + break; } return QAbstractButton::event(event); } /*! - * \reimp + * @reimp */ bool QtMaterialCheckable::eventFilter(QObject *obj, QEvent *event) { - if (QEvent::Resize == event->type()) - { + if (QEvent::Resize == event->type()) { Q_D(QtMaterialCheckable); d->rippleOverlay->setGeometry(geometry().adjusted(-8, -8, 8, 8)); @@ -344,7 +341,7 @@ bool QtMaterialCheckable::eventFilter(QObject *obj, QEvent *event) } /*! - * \reimp + * @reimp */ void QtMaterialCheckable::mousePressEvent(QMouseEvent *event) { @@ -358,9 +355,9 @@ void QtMaterialCheckable::mousePressEvent(QMouseEvent *event) QtMaterialRipple *ripple; if (QtMaterialCheckable::LabelPositionLeft == d->labelPosition) { - ripple = new QtMaterialRipple(QPoint(width()-14, 28)); + ripple = new QtMaterialRipple(QPoint(width() - 14, 28)); } else { - ripple = new QtMaterialRipple(QPoint(28, 28)); + ripple = new QtMaterialRipple(QPoint(28, 28)); } ripple->setRadiusEndValue(22); ripple->setColor(isChecked() ? checkedColor() : uncheckedColor()); @@ -373,7 +370,7 @@ void QtMaterialCheckable::mousePressEvent(QMouseEvent *event) } /*! - * \reimp + * @reimp */ void QtMaterialCheckable::paintEvent(QPaintEvent *event) { diff --git a/components/lib/qtmaterialcheckable_internal.cpp b/components/materiallib/qtmaterialcheckable_internal.cpp similarity index 66% rename from components/lib/qtmaterialcheckable_internal.cpp rename to components/materiallib/qtmaterialcheckable_internal.cpp index 4a7eb9a72..a36f6ad18 100644 --- a/components/lib/qtmaterialcheckable_internal.cpp +++ b/components/materiallib/qtmaterialcheckable_internal.cpp @@ -1,30 +1,29 @@ -#include "lib/qtmaterialcheckable_internal.h" -#include +#include "materiallib/qtmaterialcheckable_internal.h" +#include + #include +#include #include -#include "lib/qtmaterialcheckable.h" /*! - * \class QtMaterialCheckableIcon - * \internal + * @class QtMaterialCheckableIcon + * @internal */ QtMaterialCheckableIcon::QtMaterialCheckableIcon(const QIcon &icon, QtMaterialCheckable *parent) - : QWidget(parent), - m_checkable(parent), - m_color(Qt::black), - m_icon(icon), - m_iconSize(24), - m_opacity(1.0) + : QWidget(parent) + , m_checkable(parent) + , m_color(Qt::black) + , m_icon(icon) + , m_iconSize(24) + , m_opacity(1.0) { Q_ASSERT(parent); setAttribute(Qt::WA_TransparentForMouseEvents); } -QtMaterialCheckableIcon::~QtMaterialCheckableIcon() -{ -} +QtMaterialCheckableIcon::~QtMaterialCheckableIcon() {} QSize QtMaterialCheckableIcon::sizeHint() const { @@ -41,14 +40,13 @@ void QtMaterialCheckableIcon::paintEvent(QPaintEvent *event) QPixmap pixmap = icon().pixmap(24, 24); - if (!pixmap.isNull()) - { - const qreal p = static_cast((height())-m_iconSize)/2; - const qreal z = m_iconSize/24; + if (!pixmap.isNull()) { + const qreal p = static_cast((height()) - m_iconSize) / 2; + const qreal z = m_iconSize / 24; QTransform t; if (QtMaterialCheckable::LabelPositionLeft == m_checkable->labelPosition()) { - t.translate(p+width()-42, p); + t.translate(p + width() - 42, p); } else { t.translate(p, p); } diff --git a/components/lib/qtmaterialcheckable_internal.h b/components/materiallib/qtmaterialcheckable_internal.h similarity index 89% rename from components/lib/qtmaterialcheckable_internal.h rename to components/materiallib/qtmaterialcheckable_internal.h index 3fb3d947d..be107f532 100644 --- a/components/lib/qtmaterialcheckable_internal.h +++ b/components/materiallib/qtmaterialcheckable_internal.h @@ -1,9 +1,9 @@ #ifndef QTMATERIALCHECKABLE_INTERNAL_H #define QTMATERIALCHECKABLE_INTERNAL_H -#include #include #include +#include class QtMaterialCheckable; @@ -40,10 +40,10 @@ class QtMaterialCheckableIcon : public QWidget Q_DISABLE_COPY(QtMaterialCheckableIcon) QtMaterialCheckable *const m_checkable; - QColor m_color; - QIcon m_icon; - qreal m_iconSize; - qreal m_opacity; + QColor m_color; + QIcon m_icon; + qreal m_iconSize; + qreal m_opacity; }; inline void QtMaterialCheckableIcon::setIcon(const QIcon &icon) @@ -90,4 +90,4 @@ inline qreal QtMaterialCheckableIcon::opacity() const return m_opacity; } -#endif // QTMATERIALCHECKABLE_INTERNAL_H +#endif // QTMATERIALCHECKABLE_INTERNAL_H diff --git a/components/materiallib/qtmaterialcheckable_p.h b/components/materiallib/qtmaterialcheckable_p.h new file mode 100644 index 000000000..50fba2cc6 --- /dev/null +++ b/components/materiallib/qtmaterialcheckable_p.h @@ -0,0 +1,43 @@ +#ifndef QTMATERIALCHECKABLE_P_H +#define QTMATERIALCHECKABLE_P_H + +#include +#include + +class QStateMachine; +class QState; +class QSignalTransition; +class QtMaterialRippleOverlay; +class QtMaterialCheckableIcon; + +class QtMaterialCheckablePrivate +{ + Q_DISABLE_COPY(QtMaterialCheckablePrivate) + Q_DECLARE_PUBLIC(QtMaterialCheckable) + +public: + QtMaterialCheckablePrivate(QtMaterialCheckable *q); + virtual ~QtMaterialCheckablePrivate(); + + void init(); + + QtMaterialCheckable *const q_ptr; + QtMaterialRippleOverlay *rippleOverlay; + QtMaterialCheckableIcon *checkedIcon; + QtMaterialCheckableIcon *uncheckedIcon; + QStateMachine *stateMachine; + QState *uncheckedState; + QState *checkedState; + QState *disabledUncheckedState; + QState *disabledCheckedState; + QSignalTransition *uncheckedTransition; + QSignalTransition *checkedTransition; + QtMaterialCheckable::LabelPosition labelPosition; + QColor checkedColor; + QColor uncheckedColor; + QColor textColor; + QColor disabledColor; + bool useThemeColors; +}; + +#endif // QTMATERIALCHECKABLE_P_H diff --git a/components/materiallib/qtmaterialoverlaywidget.cpp b/components/materiallib/qtmaterialoverlaywidget.cpp new file mode 100644 index 000000000..9ef3647e8 --- /dev/null +++ b/components/materiallib/qtmaterialoverlaywidget.cpp @@ -0,0 +1,66 @@ +#include +#include + +/*! + * @class QtMaterialOverlayWidget + * @internal + */ + +QtMaterialOverlayWidget::QtMaterialOverlayWidget(QWidget *parent) + : QWidget(parent) +{ + if (parent) { + parent->installEventFilter(this); + } +} + +QtMaterialOverlayWidget::~QtMaterialOverlayWidget() {} + +/*! + * @reimp + */ +bool QtMaterialOverlayWidget::event(QEvent *event) +{ + if (!parent()) { + return QWidget::event(event); + } + switch (event->type()) { + case QEvent::ParentChange: { + parent()->installEventFilter(this); + setGeometry(overlayGeometry()); + break; + } + case QEvent::ParentAboutToChange: { + parent()->removeEventFilter(this); + break; + } + default: + break; + } + return QWidget::event(event); +} + +/*! + * @reimp + */ +bool QtMaterialOverlayWidget::eventFilter(QObject *obj, QEvent *event) +{ + switch (event->type()) { + case QEvent::Move: + case QEvent::Resize: + setGeometry(overlayGeometry()); + break; + default: + break; + } + return QWidget::eventFilter(obj, event); +} + +QRect QtMaterialOverlayWidget::overlayGeometry() const +{ + QWidget *widget = parentWidget(); + if (!widget) { + return QRect(); + } + return widget->rect(); +} diff --git a/components/lib/qtmaterialripple.cpp b/components/materiallib/qtmaterialripple.cpp similarity index 63% rename from components/lib/qtmaterialripple.cpp rename to components/materiallib/qtmaterialripple.cpp index 82125cbf8..cab5b2a9a 100644 --- a/components/lib/qtmaterialripple.cpp +++ b/components/materiallib/qtmaterialripple.cpp @@ -1,40 +1,36 @@ -#include "qtmaterialripple.h" -#include "lib/qtmaterialrippleoverlay.h" +#include +#include /*! - * \class QtMaterialRipple - * \internal + * @class QtMaterialRipple + * @internal */ QtMaterialRipple::QtMaterialRipple(const QPoint ¢er, QObject *parent) - : QParallelAnimationGroup(parent), - m_overlay(0), - m_radiusAnimation(animate("radius")), - m_opacityAnimation(animate("opacity")), - m_radius(0), - m_opacity(0), - m_center(center) + : QParallelAnimationGroup(parent) + , m_overlay(0) + , m_radiusAnimation(animate("radius")) + , m_opacityAnimation(animate("opacity")) + , m_radius(0) + , m_opacity(0) + , m_center(center) { init(); } -QtMaterialRipple::QtMaterialRipple(const QPoint ¢er, - QtMaterialRippleOverlay *overlay, - QObject *parent) - : QParallelAnimationGroup(parent), - m_overlay(overlay), - m_radiusAnimation(animate("radius")), - m_opacityAnimation(animate("opacity")), - m_radius(0), - m_opacity(0), - m_center(center) +QtMaterialRipple::QtMaterialRipple(const QPoint ¢er, QtMaterialRippleOverlay *overlay, QObject *parent) + : QParallelAnimationGroup(parent) + , m_overlay(overlay) + , m_radiusAnimation(animate("radius")) + , m_opacityAnimation(animate("opacity")) + , m_radius(0) + , m_opacity(0) + , m_center(center) { init(); } -QtMaterialRipple::~QtMaterialRipple() -{ -} +QtMaterialRipple::~QtMaterialRipple() {} void QtMaterialRipple::setRadius(qreal radius) { @@ -89,9 +85,7 @@ void QtMaterialRipple::destroy() /*! * \internal */ -QPropertyAnimation *QtMaterialRipple::animate(const QByteArray &property, - const QEasingCurve &easing, - int duration) +QPropertyAnimation *QtMaterialRipple::animate(const QByteArray &property, const QEasingCurve &easing, int duration) { QPropertyAnimation *animation = new QPropertyAnimation; animation->setTargetObject(this); diff --git a/components/lib/qtmaterialrippleoverlay.cpp b/components/materiallib/qtmaterialrippleoverlay.cpp similarity index 78% rename from components/lib/qtmaterialrippleoverlay.cpp rename to components/materiallib/qtmaterialrippleoverlay.cpp index 062d215bc..e887b37f8 100644 --- a/components/lib/qtmaterialrippleoverlay.cpp +++ b/components/materiallib/qtmaterialrippleoverlay.cpp @@ -1,23 +1,21 @@ -#include "lib/qtmaterialrippleoverlay.h" +#include +#include #include -#include "lib/qtmaterialripple.h" /*! - * \class QtMaterialRippleOverlay - * \internal + * @class QtMaterialRippleOverlay + * @internal */ QtMaterialRippleOverlay::QtMaterialRippleOverlay(QWidget *parent) - : QtMaterialOverlayWidget(parent), - m_useClip(false) + : QtMaterialOverlayWidget(parent) + , m_useClip(false) { setAttribute(Qt::WA_TransparentForMouseEvents); setAttribute(Qt::WA_NoSystemBackground); } -QtMaterialRippleOverlay::~QtMaterialRippleOverlay() -{ -} +QtMaterialRippleOverlay::~QtMaterialRippleOverlay() {} void QtMaterialRippleOverlay::addRipple(QtMaterialRipple *ripple) { @@ -25,8 +23,8 @@ void QtMaterialRippleOverlay::addRipple(QtMaterialRipple *ripple) m_ripples.push_back(ripple); ripple->start(); - connect(this, SIGNAL(destroyed(QObject*)), ripple, SLOT(stop())); - connect(this, SIGNAL(destroyed(QObject*)), ripple, SLOT(deleteLater())); + connect(this, SIGNAL(destroyed(QObject *)), ripple, SLOT(stop())); + connect(this, SIGNAL(destroyed(QObject *)), ripple, SLOT(deleteLater())); } void QtMaterialRippleOverlay::addRipple(const QPoint &position, qreal radius) @@ -45,7 +43,7 @@ void QtMaterialRippleOverlay::removeRipple(QtMaterialRipple *ripple) } /*! - * \reimp + * @reimp */ void QtMaterialRippleOverlay::paintEvent(QPaintEvent *event) { diff --git a/components/lib/qtmaterialstatetransition.cpp b/components/materiallib/qtmaterialstatetransition.cpp similarity index 79% rename from components/lib/qtmaterialstatetransition.cpp rename to components/materiallib/qtmaterialstatetransition.cpp index 75f1faf06..99cf2467c 100644 --- a/components/lib/qtmaterialstatetransition.cpp +++ b/components/materiallib/qtmaterialstatetransition.cpp @@ -1,4 +1,4 @@ -#include "lib/qtmaterialstatetransition.h" +#include QtMaterialStateTransition::QtMaterialStateTransition(QtMaterialStateTransitionType type) : m_type(type) @@ -14,6 +14,4 @@ bool QtMaterialStateTransition::eventTest(QEvent *event) return (m_type == transition->type); } -void QtMaterialStateTransition::onTransition(QEvent *) -{ -} +void QtMaterialStateTransition::onTransition(QEvent *) {} diff --git a/components/lib/qtmaterialstyle.cpp b/components/materiallib/qtmaterialstyle.cpp similarity index 73% rename from components/lib/qtmaterialstyle.cpp rename to components/materiallib/qtmaterialstyle.cpp index 83bbab8ae..4461b9bf7 100644 --- a/components/lib/qtmaterialstyle.cpp +++ b/components/materiallib/qtmaterialstyle.cpp @@ -1,10 +1,10 @@ -#include "lib/qtmaterialstyle.h" #include -#include "lib/qtmaterialtheme.h" +#include +#include /*! - * \class QtMaterialStylePrivate - * \internal + * @class QtMaterialStylePrivate + * @internal */ QtMaterialStylePrivate::QtMaterialStylePrivate(QtMaterialStyle *q) @@ -12,9 +12,7 @@ QtMaterialStylePrivate::QtMaterialStylePrivate(QtMaterialStyle *q) { } -QtMaterialStylePrivate::~QtMaterialStylePrivate() -{ -} +QtMaterialStylePrivate::~QtMaterialStylePrivate() {} void QtMaterialStylePrivate::init() { @@ -28,8 +26,8 @@ void QtMaterialStylePrivate::init() } /*! - * \class QtMaterialStyle - * \internal + * @class QtMaterialStyle + * @internal */ void QtMaterialStyle::setTheme(QtMaterialTheme *theme) @@ -50,8 +48,8 @@ QColor QtMaterialStyle::themeColor(const QString &key) const } QtMaterialStyle::QtMaterialStyle() - : QCommonStyle(), - d_ptr(new QtMaterialStylePrivate(this)) + : QCommonStyle() + , d_ptr(new QtMaterialStylePrivate(this)) { d_func()->init(); } diff --git a/components/lib/qtmaterialstyle_p.h b/components/materiallib/qtmaterialstyle_p.h similarity index 92% rename from components/lib/qtmaterialstyle_p.h rename to components/materiallib/qtmaterialstyle_p.h index d59ca4198..e96e1cd5e 100644 --- a/components/lib/qtmaterialstyle_p.h +++ b/components/materiallib/qtmaterialstyle_p.h @@ -21,4 +21,4 @@ class QtMaterialStylePrivate QtMaterialTheme *theme; }; -#endif // QTMATERIALSTYLE_P_H +#endif // QTMATERIALSTYLE_P_H diff --git a/components/materiallib/qtmaterialtheme.cpp b/components/materiallib/qtmaterialtheme.cpp new file mode 100644 index 000000000..980e41f4b --- /dev/null +++ b/components/materiallib/qtmaterialtheme.cpp @@ -0,0 +1,150 @@ +#include + +#include "qtmaterialtheme_p.h" + +#include +#include +#include + +/*!material + * @class QtMaterialThemePrivate + * @internal + */ + +QtMaterialThemePrivate::QtMaterialThemePrivate(QtMaterialTheme *q) + : q_ptr(q) +{ +} + +QtMaterialThemePrivate::~QtMaterialThemePrivate() {} + +QColor QtMaterialThemePrivate::rgba(int r, int g, int b, qreal a) const +{ + QColor color(r, g, b); + color.setAlphaF(a); + return color; +} + +/*! + * @class QtMaterialTheme + */ + +QtMaterialTheme::QtMaterialTheme(QObject *parent) + : QObject(parent) + , d_ptr(new QtMaterialThemePrivate(this)) +{ + setColor("primary1", Material::cyan500); + setColor("primary2", Material::cyan700); + setColor("primary3", Material::lightBlack); + setColor("accent1", Material::pinkA200); + setColor("accent2", Material::grey100); + setColor("accent3", Material::grey500); + setColor("text", Material::darkBlack); + setColor("alternateText", Material::white); + setColor("canvas", Material::white); + setColor("border", Material::grey300); + setColor("disabled", Material::minBlack); + setColor("disabled2", Material::faintBlack); + setColor("disabled3", Material::grey300); +} + +QtMaterialTheme::~QtMaterialTheme() {} + +QColor QtMaterialTheme::getColor(const QString &key) const +{ + Q_D(const QtMaterialTheme); + + if (!d->colors.contains(key)) { + qWarning() << "A theme color matching the key '" << key << "' could not be found."; + return QColor(); + } + return d->colors.value(key); +} + +void QtMaterialTheme::setColor(const QString &key, const QColor &color) +{ + Q_D(QtMaterialTheme); + + d->colors.insert(key, color); +} + +void QtMaterialTheme::setColor(const QString &key, Material::Color color) +{ + Q_D(QtMaterialTheme); + + static const QColor palette[] = { + QColor("#ffebee"), QColor("#ffcdd2"), QColor("#ef9a9a"), QColor("#e57373"), + QColor("#ef5350"), QColor("#f44336"), QColor("#e53935"), QColor("#d32f2f"), + QColor("#c62828"), QColor("#b71c1c"), QColor("#ff8a80"), QColor("#ff5252"), + QColor("#ff1744"), QColor("#d50000"), QColor("#fce4ec"), QColor("#f8bbd0"), + QColor("#f48fb1"), QColor("#f06292"), QColor("#ec407a"), QColor("#e91e63"), + QColor("#d81b60"), QColor("#c2185b"), QColor("#ad1457"), QColor("#880e4f"), + QColor("#ff80ab"), QColor("#ff4081"), QColor("#f50057"), QColor("#c51162"), + QColor("#f3e5f5"), QColor("#e1bee7"), QColor("#ce93d8"), QColor("#ba68c8"), + QColor("#ab47bc"), QColor("#9c27b0"), QColor("#8e24aa"), QColor("#7b1fa2"), + QColor("#6a1b9a"), QColor("#4a148c"), QColor("#ea80fc"), QColor("#e040fb"), + QColor("#d500f9"), QColor("#aa00ff"), QColor("#ede7f6"), QColor("#d1c4e9"), + QColor("#b39ddb"), QColor("#9575cd"), QColor("#7e57c2"), QColor("#673ab7"), + QColor("#5e35b1"), QColor("#512da8"), QColor("#4527a0"), QColor("#311b92"), + QColor("#b388ff"), QColor("#7c4dff"), QColor("#651fff"), QColor("#6200ea"), + QColor("#e8eaf6"), QColor("#c5cae9"), QColor("#9fa8da"), QColor("#7986cb"), + QColor("#5c6bc0"), QColor("#3f51b5"), QColor("#3949ab"), QColor("#303f9f"), + QColor("#283593"), QColor("#1a237e"), QColor("#8c9eff"), QColor("#536dfe"), + QColor("#3d5afe"), QColor("#304ffe"), QColor("#e3f2fd"), QColor("#bbdefb"), + QColor("#90caf9"), QColor("#64b5f6"), QColor("#42a5f5"), QColor("#2196f3"), + QColor("#1e88e5"), QColor("#1976d2"), QColor("#1565c0"), QColor("#0d47a1"), + QColor("#82b1ff"), QColor("#448aff"), QColor("#2979ff"), QColor("#2962ff"), + QColor("#e1f5fe"), QColor("#b3e5fc"), QColor("#81d4fa"), QColor("#4fc3f7"), + QColor("#29b6f6"), QColor("#03a9f4"), QColor("#039be5"), QColor("#0288d1"), + QColor("#0277bd"), QColor("#01579b"), QColor("#80d8ff"), QColor("#40c4ff"), + QColor("#00b0ff"), QColor("#0091ea"), QColor("#e0f7fa"), QColor("#b2ebf2"), + QColor("#80deea"), QColor("#4dd0e1"), QColor("#26c6da"), QColor("#00bcd4"), + QColor("#00acc1"), QColor("#0097a7"), QColor("#00838f"), QColor("#006064"), + QColor("#84ffff"), QColor("#18ffff"), QColor("#00e5ff"), QColor("#00b8d4"), + QColor("#e0f2f1"), QColor("#b2dfdb"), QColor("#80cbc4"), QColor("#4db6ac"), + QColor("#26a69a"), QColor("#009688"), QColor("#00897b"), QColor("#00796b"), + QColor("#00695c"), QColor("#004d40"), QColor("#a7ffeb"), QColor("#64ffda"), + QColor("#1de9b6"), QColor("#00bfa5"), QColor("#e8f5e9"), QColor("#c8e6c9"), + QColor("#a5d6a7"), QColor("#81c784"), QColor("#66bb6a"), QColor("#4caf50"), + QColor("#43a047"), QColor("#388e3c"), QColor("#2e7d32"), QColor("#1b5e20"), + QColor("#b9f6ca"), QColor("#69f0ae"), QColor("#00e676"), QColor("#00c853"), + QColor("#f1f8e9"), QColor("#dcedc8"), QColor("#c5e1a5"), QColor("#aed581"), + QColor("#9ccc65"), QColor("#8bc34a"), QColor("#7cb342"), QColor("#689f38"), + QColor("#558b2f"), QColor("#33691e"), QColor("#ccff90"), QColor("#b2ff59"), + QColor("#76ff03"), QColor("#64dd17"), QColor("#f9fbe7"), QColor("#f0f4c3"), + QColor("#e6ee9c"), QColor("#dce775"), QColor("#d4e157"), QColor("#cddc39"), + QColor("#c0ca33"), QColor("#afb42b"), QColor("#9e9d24"), QColor("#827717"), + QColor("#f4ff81"), QColor("#eeff41"), QColor("#c6ff00"), QColor("#aeea00"), + QColor("#fffde7"), QColor("#fff9c4"), QColor("#fff59d"), QColor("#fff176"), + QColor("#ffee58"), QColor("#ffeb3b"), QColor("#fdd835"), QColor("#fbc02d"), + QColor("#f9a825"), QColor("#f57f17"), QColor("#ffff8d"), QColor("#ffff00"), + QColor("#ffea00"), QColor("#ffd600"), QColor("#fff8e1"), QColor("#ffecb3"), + QColor("#ffe082"), QColor("#ffd54f"), QColor("#ffca28"), QColor("#ffc107"), + QColor("#ffb300"), QColor("#ffa000"), QColor("#ff8f00"), QColor("#ff6f00"), + QColor("#ffe57f"), QColor("#ffd740"), QColor("#ffc400"), QColor("#ffab00"), + QColor("#fff3e0"), QColor("#ffe0b2"), QColor("#ffcc80"), QColor("#ffb74d"), + QColor("#ffa726"), QColor("#ff9800"), QColor("#fb8c00"), QColor("#f57c00"), + QColor("#ef6c00"), QColor("#e65100"), QColor("#ffd180"), QColor("#ffab40"), + QColor("#ff9100"), QColor("#ff6d00"), QColor("#fbe9e7"), QColor("#ffccbc"), + QColor("#ffab91"), QColor("#ff8a65"), QColor("#ff7043"), QColor("#ff5722"), + QColor("#f4511e"), QColor("#e64a19"), QColor("#d84315"), QColor("#bf360c"), + QColor("#ff9e80"), QColor("#ff6e40"), QColor("#ff3d00"), QColor("#dd2c00"), + QColor("#efebe9"), QColor("#d7ccc8"), QColor("#bcaaa4"), QColor("#a1887f"), + QColor("#8d6e63"), QColor("#795548"), QColor("#6d4c41"), QColor("#5d4037"), + QColor("#4e342e"), QColor("#3e2723"), QColor("#eceff1"), QColor("#cfd8dc"), + QColor("#b0bec5"), QColor("#90a4ae"), QColor("#78909c"), QColor("#607d8b"), + QColor("#546e7a"), QColor("#455a64"), QColor("#37474f"), QColor("#263238"), + QColor("#fafafa"), QColor("#f5f5f5"), QColor("#eeeeee"), QColor("#e0e0e0"), + QColor("#bdbdbd"), QColor("#9e9e9e"), QColor("#757575"), QColor("#616161"), + QColor("#424242"), QColor("#212121"), QColor("#000000"), QColor("#ffffff"), + d->rgba(0, 0, 0, 0), d->rgba(0, 0, 0, 1), d->rgba(0, 0, 0, 0.87), d->rgba(0, 0, 0, 0.54), + d->rgba(0, 0, 0, 0.26), d->rgba(0, 0, 0, 0.12), d->rgba(255, 255, 255, 1), d->rgba(255, 255, 255, 0.87), + d->rgba(255, 255, 255, 0.54)}; + + d->colors.insert(key, palette[color]); +} + +QIcon QtMaterialTheme::icon(QString category, QString icon) +{ + return QIcon(":/icons/icons/" % category % "/svg/production/ic_" % icon % "_24px.svg"); +} diff --git a/components/lib/qtmaterialtheme_p.h b/components/materiallib/qtmaterialtheme_p.h similarity index 93% rename from components/lib/qtmaterialtheme_p.h rename to components/materiallib/qtmaterialtheme_p.h index d0ef17839..85b619b7c 100644 --- a/components/lib/qtmaterialtheme_p.h +++ b/components/materiallib/qtmaterialtheme_p.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALTHEME_P_H #define QTMATERIALTHEME_P_H -#include #include +#include class QtMaterialTheme; @@ -21,4 +21,4 @@ class QtMaterialThemePrivate QHash colors; }; -#endif // QTMATERIALTHEME_P_H +#endif // QTMATERIALTHEME_P_H diff --git a/components/qtmaterialappbar.cpp b/components/qtmaterialappbar.cpp index 2170ca496..62e307baa 100644 --- a/components/qtmaterialappbar.cpp +++ b/components/qtmaterialappbar.cpp @@ -1,16 +1,16 @@ #include "qtmaterialappbar.h" +#include "lib/qtmaterialstyle.h" #include "qtmaterialappbar_p.h" -#include #include -#include "lib/qtmaterialstyle.h" +#include /*! - * \class QtMaterialAppBarPrivate - * \internal + * @class QtMaterialAppBarPrivate + * @internal */ /*! - * \internal + * @internal */ QtMaterialAppBarPrivate::QtMaterialAppBarPrivate(QtMaterialAppBar *q) : q_ptr(q) @@ -18,14 +18,12 @@ QtMaterialAppBarPrivate::QtMaterialAppBarPrivate(QtMaterialAppBar *q) } /*! - * \internal + * @internal */ -QtMaterialAppBarPrivate::~QtMaterialAppBarPrivate() -{ -} +QtMaterialAppBarPrivate::~QtMaterialAppBarPrivate() {} /*! - * \internal + * @internal */ void QtMaterialAppBarPrivate::init() { @@ -45,19 +43,17 @@ void QtMaterialAppBarPrivate::init() } /*! - * \class QtMaterialAppBar + * @class QtMaterialAppBar */ QtMaterialAppBar::QtMaterialAppBar(QWidget *parent) - : QWidget(parent), - d_ptr(new QtMaterialAppBarPrivate(this)) + : QWidget(parent) + , d_ptr(new QtMaterialAppBarPrivate(this)) { d_func()->init(); } -QtMaterialAppBar::~QtMaterialAppBar() -{ -} +QtMaterialAppBar::~QtMaterialAppBar() {} QSize QtMaterialAppBar::sizeHint() const { diff --git a/components/qtmaterialappbar_p.h b/components/qtmaterialappbar_p.h index 0586556b4..c4895a6bf 100644 --- a/components/qtmaterialappbar_p.h +++ b/components/qtmaterialappbar_p.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALAPPBAR_P_H #define QTMATERIALAPPBAR_P_H -#include #include +#include class QtMaterialAppBar; @@ -18,9 +18,9 @@ class QtMaterialAppBarPrivate void init(); QtMaterialAppBar *const q_ptr; - bool useThemeColors; - QColor foregroundColor; - QColor backgroundColor; + bool useThemeColors; + QColor foregroundColor; + QColor backgroundColor; }; -#endif // QTMATERIALAPPBAR_P_H +#endif // QTMATERIALAPPBAR_P_H diff --git a/components/qtmaterialautocomplete.cpp b/components/qtmaterialautocomplete.cpp index df006a68a..bf58f1392 100644 --- a/components/qtmaterialautocomplete.cpp +++ b/components/qtmaterialautocomplete.cpp @@ -1,46 +1,45 @@ #include "qtmaterialautocomplete.h" +#include "qtmaterialautocomplete_internal.h" #include "qtmaterialautocomplete_p.h" -#include -#include +#include "qtmaterialflatbutton.h" +#include #include -#include #include -#include -#include "qtmaterialautocomplete_internal.h" -#include "qtmaterialflatbutton.h" +#include +#include +#include /*! - * \class QtMaterialAutoCompletePrivate - * \internal + * @class QtMaterialAutoCompletePrivate + * @internal */ /*! - * \internal + * @internal */ QtMaterialAutoCompletePrivate::QtMaterialAutoCompletePrivate(QtMaterialAutoComplete *q) : QtMaterialTextFieldPrivate(q) + , q_ptr(q) { } /*! - * \internal + * @internal */ -QtMaterialAutoCompletePrivate::~QtMaterialAutoCompletePrivate() -{ -} +QtMaterialAutoCompletePrivate::~QtMaterialAutoCompletePrivate() {} /*! - * \internal + * @internal */ void QtMaterialAutoCompletePrivate::init() { Q_Q(QtMaterialAutoComplete); - menu = new QWidget; - frame = new QWidget; + menu = new QWidget; + frame = new QWidget; stateMachine = new QtMaterialAutoCompleteStateMachine(menu); - menuLayout = new QVBoxLayout; - maxWidth = 0; + menuLayout = new QVBoxLayout; + maxWidth = 0; menu->setParent(q->parentWidget()); frame->setParent(q->parentWidget()); @@ -68,7 +67,7 @@ void QtMaterialAutoCompletePrivate::init() } /*! - * \class QtMaterialAutoComplete + * @class QtMaterialAutoComplete */ QtMaterialAutoComplete::QtMaterialAutoComplete(QWidget *parent) @@ -77,9 +76,7 @@ QtMaterialAutoComplete::QtMaterialAutoComplete(QWidget *parent) d_func()->init(); } -QtMaterialAutoComplete::~QtMaterialAutoComplete() -{ -} +QtMaterialAutoComplete::~QtMaterialAutoComplete() {} void QtMaterialAutoComplete::setDataSource(const QStringList &data) { @@ -151,7 +148,7 @@ void QtMaterialAutoComplete::updateResults(QString text) emit d->stateMachine->shouldOpen(); } - d->menu->setFixedHeight(results.length()*50); + d->menu->setFixedHeight(results.length() * 50); d->menu->setFixedWidth(qMax(d->maxWidth + 24, width())); d->menu->update(); } @@ -160,23 +157,22 @@ bool QtMaterialAutoComplete::QtMaterialAutoComplete::event(QEvent *event) { Q_D(QtMaterialAutoComplete); - switch (event->type()) - { - case QEvent::Move: - case QEvent::Resize: { - d->menu->move(pos() + QPoint(0, height() + 6)); - break; - } - case QEvent::ParentChange: { - QWidget *widget = static_cast(parent()); - if (widget) { - d->menu->setParent(widget); - d->frame->setParent(widget); + switch (event->type()) { + case QEvent::Move: + case QEvent::Resize: { + d->menu->move(pos() + QPoint(0, height() + 6)); + break; } - break; - } - default: - break; + case QEvent::ParentChange: { + QWidget *widget = static_cast(parent()); + if (widget) { + d->menu->setParent(widget); + d->frame->setParent(widget); + } + break; + } + default: + break; } return QtMaterialTextField::event(event); } @@ -185,57 +181,49 @@ bool QtMaterialAutoComplete::eventFilter(QObject *watched, QEvent *event) { Q_D(QtMaterialAutoComplete); - if (d->frame == watched) - { - switch (event->type()) - { - case QEvent::Paint: { - QPainter painter(d->frame); - painter.fillRect(d->frame->rect(), Qt::white); - break; - } - default: - break; - } - } - else if (d->menu == watched) - { - switch (event->type()) - { - case QEvent::Resize: - case QEvent::Move: { - d->frame->setGeometry(d->menu->geometry()); - break; - } - case QEvent::Show: { - d->frame->show(); - d->menu->raise(); - break; - } - case QEvent::Hide: { - d->frame->hide(); - break; - } - default: - break; + if (d->frame == watched) { + switch (event->type()) { + case QEvent::Paint: { + QPainter painter(d->frame); + painter.fillRect(d->frame->rect(), Qt::white); + break; + } + default: + break; } - } - else - { - switch (event->type()) - { - case QEvent::MouseButtonPress: { - emit d->stateMachine->shouldFade(); - QtMaterialFlatButton *widget; - if ((widget = static_cast(watched))) { - QString text(widget->text()); - setText(text); - emit itemSelected(text); + } else if (d->menu == watched) { + switch (event->type()) { + case QEvent::Resize: + case QEvent::Move: { + d->frame->setGeometry(d->menu->geometry()); + break; } - break; + case QEvent::Show: { + d->frame->show(); + d->menu->raise(); + break; + } + case QEvent::Hide: { + d->frame->hide(); + break; + } + default: + break; } - default: - break; + } else { + switch (event->type()) { + case QEvent::MouseButtonPress: { + emit d->stateMachine->shouldFade(); + QtMaterialFlatButton *widget; + if ((widget = static_cast(watched))) { + QString text(widget->text()); + setText(text); + emit itemSelected(text); + } + break; + } + default: + break; } } return QtMaterialTextField::eventFilter(watched, event); diff --git a/components/qtmaterialautocomplete_internal.cpp b/components/qtmaterialautocomplete_internal.cpp index e01848d8c..c342b6540 100644 --- a/components/qtmaterialautocomplete_internal.cpp +++ b/components/qtmaterialautocomplete_internal.cpp @@ -1,23 +1,23 @@ #include "qtmaterialautocomplete_internal.h" -#include +#include #include +#include #include -#include /*! - * \class QtMaterialAutoCompleteStateMachine - * \internal + * @class QtMaterialAutoCompleteStateMachine + * @internal */ /*! - * \internal + * @internal */ QtMaterialAutoCompleteStateMachine::QtMaterialAutoCompleteStateMachine(QWidget *menu) - : QStateMachine(menu), - m_menu(menu), - m_closedState(new QState), - m_openState(new QState), - m_closingState(new QState) + : QStateMachine(menu) + , m_menu(menu) + , m_closedState(new QState) + , m_openState(new QState) + , m_closingState(new QState) { Q_ASSERT(menu); @@ -62,8 +62,6 @@ QtMaterialAutoCompleteStateMachine::QtMaterialAutoCompleteStateMachine(QWidget * } /*! - * \internal + * @internal */ -QtMaterialAutoCompleteStateMachine::~QtMaterialAutoCompleteStateMachine() -{ -} +QtMaterialAutoCompleteStateMachine::~QtMaterialAutoCompleteStateMachine() {} diff --git a/components/qtmaterialautocomplete_internal.h b/components/qtmaterialautocomplete_internal.h index 7e76bd520..382c6cd3c 100644 --- a/components/qtmaterialautocomplete_internal.h +++ b/components/qtmaterialautocomplete_internal.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALAUTOCOMPLETESTATEMACHINE_H #define QTMATERIALAUTOCOMPLETESTATEMACHINE_H -#include #include "qtmaterialautocomplete.h" +#include class QtMaterialAutoCompleteStateMachine : public QStateMachine { @@ -21,9 +21,9 @@ class QtMaterialAutoCompleteStateMachine : public QStateMachine Q_DISABLE_COPY(QtMaterialAutoCompleteStateMachine) QWidget *const m_menu; - QState *const m_closedState; - QState *const m_openState; - QState *const m_closingState; + QState *const m_closedState; + QState *const m_openState; + QState *const m_closingState; }; -#endif // QTMATERIALAUTOCOMPLETESTATEMACHINE_H +#endif // QTMATERIALAUTOCOMPLETESTATEMACHINE_H diff --git a/components/qtmaterialautocomplete_p.h b/components/qtmaterialautocomplete_p.h index 4fd405be7..4e99d7c02 100644 --- a/components/qtmaterialautocomplete_p.h +++ b/components/qtmaterialautocomplete_p.h @@ -7,7 +7,7 @@ class QWidget; class QVBoxLayout; class QtMaterialAutoCompleteOverlay; class QtMaterialAutoCompleteStateMachine; - +class QtMaterialAutoComplete; class QtMaterialAutoCompletePrivate : public QtMaterialTextFieldPrivate { Q_DISABLE_COPY(QtMaterialAutoCompletePrivate) @@ -19,12 +19,13 @@ class QtMaterialAutoCompletePrivate : public QtMaterialTextFieldPrivate void init(); - QWidget *menu; - QWidget *frame; + QtMaterialAutoComplete *const q_ptr; + QWidget *menu; + QWidget *frame; QtMaterialAutoCompleteStateMachine *stateMachine; - QVBoxLayout *menuLayout; - QStringList dataSource; - int maxWidth; + QVBoxLayout *menuLayout; + QStringList dataSource; + int maxWidth; }; -#endif // QTMATERIALAUTOCOMPLETE_P_H +#endif // QTMATERIALAUTOCOMPLETE_P_H diff --git a/components/qtmaterialavatar.cpp b/components/qtmaterialavatar.cpp index e769f8f56..399716aba 100644 --- a/components/qtmaterialavatar.cpp +++ b/components/qtmaterialavatar.cpp @@ -1,16 +1,16 @@ #include "qtmaterialavatar.h" +#include "lib/qtmaterialstyle.h" #include "qtmaterialavatar_p.h" #include #include -#include "lib/qtmaterialstyle.h" /*! - * \class QtMaterialAvatarPrivate - * \internal + * @class QtMaterialAvatarPrivate + * @internal */ /*! - * \internal + * @internal */ QtMaterialAvatarPrivate::QtMaterialAvatarPrivate(QtMaterialAvatar *q) : q_ptr(q) @@ -18,46 +18,43 @@ QtMaterialAvatarPrivate::QtMaterialAvatarPrivate(QtMaterialAvatar *q) } /*! - * \internal + * @internal */ -QtMaterialAvatarPrivate::~QtMaterialAvatarPrivate() -{ -} +QtMaterialAvatarPrivate::~QtMaterialAvatarPrivate() {} /*! - * \internal + * @internal */ void QtMaterialAvatarPrivate::init() { Q_Q(QtMaterialAvatar); - size = 40; - type = Material::LetterAvatar; + size = 40; + type = Material::LetterAvatar; useThemeColors = true; QFont font(q->font()); font.setPointSizeF(16); q->setFont(font); - QSizePolicy policy(QSizePolicy::MinimumExpanding, - QSizePolicy::MinimumExpanding); + QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); q->setSizePolicy(policy); } /*! - * \class QtMaterialAvatar + * @class QtMaterialAvatar */ QtMaterialAvatar::QtMaterialAvatar(QWidget *parent) - : QWidget(parent), - d_ptr(new QtMaterialAvatarPrivate(this)) + : QWidget(parent) + , d_ptr(new QtMaterialAvatarPrivate(this)) { d_func()->init(); } QtMaterialAvatar::QtMaterialAvatar(const QIcon &icon, QWidget *parent) - : QWidget(parent), - d_ptr(new QtMaterialAvatarPrivate(this)) + : QWidget(parent) + , d_ptr(new QtMaterialAvatarPrivate(this)) { d_func()->init(); @@ -65,8 +62,8 @@ QtMaterialAvatar::QtMaterialAvatar(const QIcon &icon, QWidget *parent) } QtMaterialAvatar::QtMaterialAvatar(const QChar &letter, QWidget *parent) - : QWidget(parent), - d_ptr(new QtMaterialAvatarPrivate(this)) + : QWidget(parent) + , d_ptr(new QtMaterialAvatarPrivate(this)) { d_func()->init(); @@ -74,17 +71,15 @@ QtMaterialAvatar::QtMaterialAvatar(const QChar &letter, QWidget *parent) } QtMaterialAvatar::QtMaterialAvatar(const QImage &image, QWidget *parent) - : QWidget(parent), - d_ptr(new QtMaterialAvatarPrivate(this)) + : QWidget(parent) + , d_ptr(new QtMaterialAvatarPrivate(this)) { d_func()->init(); setImage(image); } -QtMaterialAvatar::~QtMaterialAvatar() -{ -} +QtMaterialAvatar::~QtMaterialAvatar() {} void QtMaterialAvatar::setUseThemeColors(bool value) { @@ -131,7 +126,7 @@ void QtMaterialAvatar::setBackgroundColor(const QColor &color) Q_D(QtMaterialAvatar); d->backgroundColor = color; - + MATERIAL_DISABLE_THEME_COLORS update(); } @@ -148,13 +143,13 @@ QColor QtMaterialAvatar::backgroundColor() const } /*! - * \reimp + * @reimp */ QSize QtMaterialAvatar::sizeHint() const { Q_D(const QtMaterialAvatar); - return QSize(d->size+2, d->size+2); + return QSize(d->size + 2, d->size + 2); } void QtMaterialAvatar::setSize(int size) @@ -164,13 +159,11 @@ void QtMaterialAvatar::setSize(int size) d->size = size; if (!d->image.isNull()) { - d->pixmap = QPixmap::fromImage(d->image.scaled(d->size, d->size, - Qt::IgnoreAspectRatio, - Qt::SmoothTransformation)); + d->pixmap = QPixmap::fromImage(d->image.scaled(d->size, d->size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } QFont f(font()); - f.setPointSizeF(size*16/40); + f.setPointSizeF(size * 16.0 / 40.0); setFont(f); update(); @@ -199,9 +192,7 @@ void QtMaterialAvatar::setImage(const QImage &image) d->image = image; d->type = Material::ImageAvatar; - d->pixmap = QPixmap::fromImage(image.scaled(d->size, d->size, - Qt::IgnoreAspectRatio, - Qt::SmoothTransformation)); + d->pixmap = QPixmap::fromImage(image.scaled(d->size, d->size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); update(); } @@ -222,7 +213,7 @@ Material::AvatarType QtMaterialAvatar::type() const } /*! - * \reimp + * @reimp */ void QtMaterialAvatar::paintEvent(QPaintEvent *event) { @@ -234,61 +225,52 @@ void QtMaterialAvatar::paintEvent(QPaintEvent *event) painter.setRenderHint(QPainter::Antialiasing); QRect r = rect(); - const qreal hs = d->size/2; + const qreal hs = d->size / 2.0; - if (!isEnabled()) - { + if (!isEnabled()) { QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(QtMaterialStyle::instance().themeColor("disabled")); painter.setPen(Qt::NoPen); painter.setBrush(brush); - painter.drawEllipse(QRectF((width()-d->size)/2, (height()-d->size)/2, - d->size, d->size)); + painter.drawEllipse(QRectF((width() - d->size) / 2.0, (height() - d->size) / 2.0, d->size, d->size)); return; } - if (Material::ImageAvatar != d->type) - { + if (Material::ImageAvatar != d->type) { QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(backgroundColor()); painter.setPen(Qt::NoPen); painter.setBrush(brush); - painter.drawEllipse(QRectF((width()-d->size)/2, (height()-d->size)/2, - d->size, d->size)); + painter.drawEllipse(QRectF((width() - d->size) / 2.0, (height() - d->size) / 2.0, d->size, d->size)); } - switch (d->type) - { - case Material::ImageAvatar: - { - QPainterPath path; - path.addEllipse(width()/2-hs, height()/2-hs, d->size, d->size); - painter.setClipPath(path); - - painter.drawPixmap(QRect(width()/2-hs, height()/2-hs, d->size, d->size), - d->pixmap); - break; - } - case Material::IconAvatar: - { - QRect iconGeometry((width()-hs)/2, (height()-hs)/2, hs, hs); - QPixmap pixmap = d->icon.pixmap(hs, hs); - QPainter icon(&pixmap); - icon.setCompositionMode(QPainter::CompositionMode_SourceIn); - icon.fillRect(pixmap.rect(), textColor()); - painter.drawPixmap(iconGeometry, pixmap); - break; - } - case Material::LetterAvatar: - { - painter.setPen(textColor()); - painter.setBrush(Qt::NoBrush); - painter.drawText(r, Qt::AlignCenter, QString(d->letter)); - break; - } - default: - break; + switch (d->type) { + case Material::ImageAvatar: { + QPainterPath path; + path.addEllipse(width() / 2.0 - hs, height() / 2.0 - hs, d->size, d->size); + painter.setClipPath(path); + + painter.drawPixmap(QRect(width() / 2.0 - hs, height() / 2.0 - hs, d->size, d->size), d->pixmap); + break; + } + case Material::IconAvatar: { + QRect iconGeometry((width() - hs) / 2, (height() - hs) / 2, hs, hs); + QPixmap pixmap = d->icon.pixmap(hs, hs); + QPainter icon(&pixmap); + icon.setCompositionMode(QPainter::CompositionMode_SourceIn); + icon.fillRect(pixmap.rect(), textColor()); + painter.drawPixmap(iconGeometry, pixmap); + break; + } + case Material::LetterAvatar: { + painter.setPen(textColor()); + painter.setBrush(Qt::NoBrush); + painter.drawText(r, Qt::AlignCenter, QString(d->letter)); + break; + } + default: + break; } } diff --git a/components/qtmaterialavatar_p.h b/components/qtmaterialavatar_p.h index 44b378e10..bc3ce671b 100644 --- a/components/qtmaterialavatar_p.h +++ b/components/qtmaterialavatar_p.h @@ -1,13 +1,13 @@ #ifndef QTMATERIALAVATAR_P_H #define QTMATERIALAVATAR_P_H -#include +#include "lib/qtmaterialtheme.h" #include -#include +#include #include +#include #include -#include -#include "lib/qtmaterialtheme.h" +#include class QtMaterialAvatar; @@ -23,15 +23,15 @@ class QtMaterialAvatarPrivate void init(); QtMaterialAvatar *const q_ptr; - int size; - Material::AvatarType type; - QChar letter; - QImage image; - QIcon icon; - QPixmap pixmap; - bool useThemeColors; - QColor textColor; - QColor backgroundColor; + int size; + Material::AvatarType type; + QChar letter; + QImage image; + QIcon icon; + QPixmap pixmap; + bool useThemeColors; + QColor textColor; + QColor backgroundColor; }; -#endif // QTMATERIALAVATAR_P_H +#endif // QTMATERIALAVATAR_P_H diff --git a/components/qtmaterialbadge.cpp b/components/qtmaterialbadge.cpp index b30aa95ba..75e590207 100644 --- a/components/qtmaterialbadge.cpp +++ b/components/qtmaterialbadge.cpp @@ -1,15 +1,15 @@ #include "qtmaterialbadge.h" +#include "lib/qtmaterialstyle.h" #include "qtmaterialbadge_p.h" #include -#include "lib/qtmaterialstyle.h" /*! - * \class QtMaterialBadgePrivate - * \internal + * @class QtMaterialBadgePrivate + * @internal */ /*! - * \internal + * @internal */ QtMaterialBadgePrivate::QtMaterialBadgePrivate(QtMaterialBadge *q) : q_ptr(q) @@ -17,22 +17,20 @@ QtMaterialBadgePrivate::QtMaterialBadgePrivate(QtMaterialBadge *q) } /*! - * \internal + * @internal */ -QtMaterialBadgePrivate::~QtMaterialBadgePrivate() -{ -} +QtMaterialBadgePrivate::~QtMaterialBadgePrivate() {} /*! - * \internal + * @internal */ void QtMaterialBadgePrivate::init() { Q_Q(QtMaterialBadge); - x = 0; - y = 0; - padding = 10; + x = 0; + y = 0; + padding = 10; useThemeColors = true; q->setAttribute(Qt::WA_TransparentForMouseEvents); @@ -50,15 +48,15 @@ void QtMaterialBadgePrivate::init() */ QtMaterialBadge::QtMaterialBadge(QWidget *parent) - : QtMaterialOverlayWidget(parent), - d_ptr(new QtMaterialBadgePrivate(this)) + : QtMaterialOverlayWidget(parent) + , d_ptr(new QtMaterialBadgePrivate(this)) { d_func()->init(); } QtMaterialBadge::QtMaterialBadge(const QIcon &icon, QWidget *parent) - : QtMaterialOverlayWidget(parent), - d_ptr(new QtMaterialBadgePrivate(this)) + : QtMaterialOverlayWidget(parent) + , d_ptr(new QtMaterialBadgePrivate(this)) { d_func()->init(); @@ -66,17 +64,15 @@ QtMaterialBadge::QtMaterialBadge(const QIcon &icon, QWidget *parent) } QtMaterialBadge::QtMaterialBadge(const QString &text, QWidget *parent) - : QtMaterialOverlayWidget(parent), - d_ptr(new QtMaterialBadgePrivate(this)) + : QtMaterialOverlayWidget(parent) + , d_ptr(new QtMaterialBadgePrivate(this)) { d_func()->init(); setText(text); } -QtMaterialBadge::~QtMaterialBadge() -{ -} +QtMaterialBadge::~QtMaterialBadge() {} void QtMaterialBadge::setUseThemeColors(bool value) { @@ -196,7 +192,7 @@ qreal QtMaterialBadge::relativeYPosition() const QSize QtMaterialBadge::sizeHint() const { const int s = getDiameter(); - return QSize(s+4, s+4); + return QSize(s + 4, s + 4); } void QtMaterialBadge::setIcon(const QIcon &icon) @@ -252,25 +248,21 @@ void QtMaterialBadge::paintEvent(QPaintEvent *event) QBrush brush; brush.setStyle(Qt::SolidPattern); - brush.setColor(isEnabled() ? backgroundColor() - : QtMaterialStyle::instance().themeColor("disabled")); + brush.setColor(isEnabled() ? backgroundColor() : QtMaterialStyle::instance().themeColor("disabled")); painter.setBrush(brush); painter.setPen(Qt::NoPen); const int s = getDiameter(); QRectF r(0, 0, s, s); - r.translate(QPointF((width()-s), (height()-s))/2); + r.translate(QPointF((width() - s), (height() - s)) / 2); - if (d->icon.isNull()) - { + if (d->icon.isNull()) { painter.drawEllipse(r); painter.setPen(textColor()); painter.setBrush(Qt::NoBrush); painter.drawText(r.translated(0, -0.5), Qt::AlignCenter, d->text); - } - else - { + } else { painter.drawEllipse(r); QRectF q(0, 0, 16, 16); q.moveCenter(r.center()); diff --git a/components/qtmaterialbadge_p.h b/components/qtmaterialbadge_p.h index 19757e7bb..16b6b8d21 100644 --- a/components/qtmaterialbadge_p.h +++ b/components/qtmaterialbadge_p.h @@ -1,10 +1,10 @@ #ifndef QTMATERIALBADGE_P_H #define QTMATERIALBADGE_P_H -#include -#include -#include #include +#include +#include +#include class QtMaterialBadge; @@ -20,15 +20,15 @@ class QtMaterialBadgePrivate void init(); QtMaterialBadge *const q_ptr; - QString text; - QColor textColor; - QColor backgroundColor; - QSize size; - QIcon icon; - qreal x; - qreal y; - int padding; - bool useThemeColors; + QString text; + QColor textColor; + QColor backgroundColor; + QSize size; + QIcon icon; + qreal x; + qreal y; + int padding; + bool useThemeColors; }; -#endif // QTMATERIALBADGE_P_H +#endif // QTMATERIALBADGE_P_H diff --git a/components/qtmaterialcheckbox.cpp b/components/qtmaterialcheckbox.cpp index b693a90d9..aed12ef97 100644 --- a/components/qtmaterialcheckbox.cpp +++ b/components/qtmaterialcheckbox.cpp @@ -1,32 +1,31 @@ #include "qtmaterialcheckbox.h" +#include "materiallib/qtmaterialcheckable_internal.h" #include "qtmaterialcheckbox_p.h" #include #include #include -#include "lib/qtmaterialcheckable_internal.h" /*! - * \class QtMaterialCheckBoxPrivate - * \internal + * @class QtMaterialCheckBoxPrivate + * @internal */ /*! - * \internal + * @internal */ QtMaterialCheckBoxPrivate::QtMaterialCheckBoxPrivate(QtMaterialCheckBox *q) : QtMaterialCheckablePrivate(q) + , q_ptr(q) { } /*! - * \internal + * @internal */ -QtMaterialCheckBoxPrivate::~QtMaterialCheckBoxPrivate() -{ -} +QtMaterialCheckBoxPrivate::~QtMaterialCheckBoxPrivate() {} /*! - * \internal + * @internal */ void QtMaterialCheckBoxPrivate::init() { @@ -71,7 +70,7 @@ void QtMaterialCheckBoxPrivate::init() } /*! - * \class QtMaterialCheckBox + * @class QtMaterialCheckBox */ QtMaterialCheckBox::QtMaterialCheckBox(QWidget *parent) @@ -80,6 +79,4 @@ QtMaterialCheckBox::QtMaterialCheckBox(QWidget *parent) d_func()->init(); } -QtMaterialCheckBox::~QtMaterialCheckBox() -{ -} +QtMaterialCheckBox::~QtMaterialCheckBox() {} diff --git a/components/qtmaterialcheckbox_p.h b/components/qtmaterialcheckbox_p.h index daa62d796..40781c6e1 100644 --- a/components/qtmaterialcheckbox_p.h +++ b/components/qtmaterialcheckbox_p.h @@ -1,7 +1,7 @@ #ifndef QTMATERIALCHECKBOX_P_H #define QTMATERIALCHECKBOX_P_H -#include "lib/qtmaterialcheckable_p.h" +#include "materiallib/qtmaterialcheckable_p.h" class QtMaterialCheckBox; @@ -14,7 +14,9 @@ class QtMaterialCheckBoxPrivate : public QtMaterialCheckablePrivate QtMaterialCheckBoxPrivate(QtMaterialCheckBox *q); ~QtMaterialCheckBoxPrivate(); + QtMaterialCheckBox *const q_ptr; + void init(); }; -#endif // QTMATERIALCHECKBOX_P_H +#endif // QTMATERIALCHECKBOX_P_H diff --git a/components/qtmaterialcircularprogress.cpp b/components/qtmaterialcircularprogress.cpp index f38ef0167..5ea7ffa61 100644 --- a/components/qtmaterialcircularprogress.cpp +++ b/components/qtmaterialcircularprogress.cpp @@ -1,15 +1,15 @@ #include "qtmaterialcircularprogress.h" +#include "lib/qtmaterialstyle.h" +#include "qtmaterialcircularprogress_internal.h" #include "qtmaterialcircularprogress_p.h" -#include -#include #include #include -#include "qtmaterialcircularprogress_internal.h" -#include "lib/qtmaterialstyle.h" +#include +#include /*! - * \class QtMaterialCircularProgressPrivate - * \internal + * @class QtMaterialCircularProgressPrivate + * @internal */ QtMaterialCircularProgressPrivate::QtMaterialCircularProgressPrivate(QtMaterialCircularProgress *q) @@ -17,22 +17,19 @@ QtMaterialCircularProgressPrivate::QtMaterialCircularProgressPrivate(QtMaterialC { } -QtMaterialCircularProgressPrivate::~QtMaterialCircularProgressPrivate() -{ -} +QtMaterialCircularProgressPrivate::~QtMaterialCircularProgressPrivate() {} void QtMaterialCircularProgressPrivate::init() { Q_Q(QtMaterialCircularProgress); - delegate = new QtMaterialCircularProgressDelegate(q); - progressType = Material::IndeterminateProgress; - penWidth = 6.25; - size = 64; + delegate = new QtMaterialCircularProgressDelegate(q); + progressType = Material::IndeterminateProgress; + penWidth = 6.25; + size = 64; useThemeColors = true; - q->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, - QSizePolicy::MinimumExpanding)); + q->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); QParallelAnimationGroup *group = new QParallelAnimationGroup(q); group->setLoopCount(-1); @@ -78,19 +75,17 @@ void QtMaterialCircularProgressPrivate::init() } /*! - * \class QtMaterialCircularProgress + * @class QtMaterialCircularProgress */ QtMaterialCircularProgress::QtMaterialCircularProgress(QWidget *parent) - : QProgressBar(parent), - d_ptr(new QtMaterialCircularProgressPrivate(this)) + : QProgressBar(parent) + , d_ptr(new QtMaterialCircularProgressPrivate(this)) { d_func()->init(); } -QtMaterialCircularProgress::~QtMaterialCircularProgress() -{ -} +QtMaterialCircularProgress::~QtMaterialCircularProgress() {} void QtMaterialCircularProgress::setProgressType(Material::ProgressType type) { @@ -180,18 +175,18 @@ QColor QtMaterialCircularProgress::color() const } /*! - * \reimp + * @reimp */ QSize QtMaterialCircularProgress::sizeHint() const { Q_D(const QtMaterialCircularProgress); - const qreal s = d->size+d->penWidth+8; + const qreal s = d->size + d->penWidth + 8; return QSize(s, s); } /*! - * \reimp + * @reimp */ void QtMaterialCircularProgress::paintEvent(QPaintEvent *event) { @@ -202,21 +197,19 @@ void QtMaterialCircularProgress::paintEvent(QPaintEvent *event) QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); - if (!isEnabled()) - { + if (!isEnabled()) { QPen pen; pen.setCapStyle(Qt::RoundCap); pen.setWidthF(d->penWidth); pen.setColor(QtMaterialStyle::instance().themeColor("border")); painter.setPen(pen); - painter.drawLine(rect().center()-QPointF(20, 20), rect().center()+QPointF(20, 20)); - painter.drawLine(rect().center()+QPointF(20, -20), rect().center()-QPointF(20, -20)); + painter.drawLine(rect().center() - QPointF(20, 20), rect().center() + QPointF(20, 20)); + painter.drawLine(rect().center() + QPointF(20, -20), rect().center() - QPointF(20, -20)); return; } - if (Material::IndeterminateProgress == d->progressType) - { - painter.translate(width()/2, height()/2); + if (Material::IndeterminateProgress == d->progressType) { + painter.translate(width() / 2.0, height() / 2.0); painter.rotate(d->delegate->angle()); } @@ -225,26 +218,23 @@ void QtMaterialCircularProgress::paintEvent(QPaintEvent *event) pen.setWidthF(d->penWidth); pen.setColor(color()); - if (Material::IndeterminateProgress == d->progressType) - { + if (Material::IndeterminateProgress == d->progressType) { QVector pattern; - pattern << d->delegate->dashLength()*d->size/50 << 30*d->size/50; + pattern << d->delegate->dashLength() * d->size / 50 << 30.0 * d->size / 50; - pen.setDashOffset(d->delegate->dashOffset()*d->size/50); + pen.setDashOffset(d->delegate->dashOffset() * d->size / 50); pen.setDashPattern(pattern); painter.setPen(pen); - painter.drawEllipse(QPoint(0, 0), d->size/2, d->size/2); - } - else - { + painter.drawEllipse(QPoint(0, 0), d->size / 2, d->size / 2); + } else { painter.setPen(pen); - const qreal x = (width()-d->size)/2; - const qreal y = (height()-d->size)/2; + const qreal x = (width() - d->size) / 2.0; + const qreal y = (height() - d->size) / 2.0; - const qreal a = 360*(value()-minimum())/(maximum()-minimum()); + const qreal a = 360.0 * (value() - minimum()) / (maximum() - minimum()); QPainterPath path; path.arcMoveTo(x, y, d->size, d->size, 0); diff --git a/components/qtmaterialcircularprogress_internal.cpp b/components/qtmaterialcircularprogress_internal.cpp index b11a25f1d..c40c1c4bb 100644 --- a/components/qtmaterialcircularprogress_internal.cpp +++ b/components/qtmaterialcircularprogress_internal.cpp @@ -1,20 +1,18 @@ #include "qtmaterialcircularprogress_internal.h" /*! - * \class QtMaterialCircularProgressDelegate - * \internal + * @class QtMaterialCircularProgressDelegate + * @internal */ QtMaterialCircularProgressDelegate::QtMaterialCircularProgressDelegate(QtMaterialCircularProgress *parent) - : QObject(parent), - m_progress(parent), - m_dashOffset(0), - m_dashLength(89), - m_angle(0) + : QObject(parent) + , m_progress(parent) + , m_dashOffset(0) + , m_dashLength(89) + , m_angle(0) { Q_ASSERT(parent); } -QtMaterialCircularProgressDelegate::~QtMaterialCircularProgressDelegate() -{ -} +QtMaterialCircularProgressDelegate::~QtMaterialCircularProgressDelegate() {} diff --git a/components/qtmaterialcircularprogress_internal.h b/components/qtmaterialcircularprogress_internal.h index a05bd6371..8178aa200 100644 --- a/components/qtmaterialcircularprogress_internal.h +++ b/components/qtmaterialcircularprogress_internal.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALCIRCULARPROGRESS_INTERNAL_H #define QTMATERIALCIRCULARPROGRESS_INTERNAL_H -#include #include "qtmaterialcircularprogress.h" +#include class QtMaterialCircularProgressDelegate : public QObject { @@ -29,9 +29,9 @@ class QtMaterialCircularProgressDelegate : public QObject Q_DISABLE_COPY(QtMaterialCircularProgressDelegate) QtMaterialCircularProgress *const m_progress; - qreal m_dashOffset; - qreal m_dashLength; - int m_angle; + qreal m_dashOffset; + qreal m_dashLength; + int m_angle; }; inline void QtMaterialCircularProgressDelegate::setDashOffset(qreal offset) @@ -67,4 +67,4 @@ inline int QtMaterialCircularProgressDelegate::angle() const return m_angle; } -#endif // QTMATERIALCIRCULARPROGRESS_INTERNAL_H +#endif // QTMATERIALCIRCULARPROGRESS_INTERNAL_H diff --git a/components/qtmaterialcircularprogress_p.h b/components/qtmaterialcircularprogress_p.h index 451bc9c4b..70492eef5 100644 --- a/components/qtmaterialcircularprogress_p.h +++ b/components/qtmaterialcircularprogress_p.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALCIRCULARPROGRESS_P_H #define QTMATERIALCIRCULARPROGRESS_P_H -#include #include "lib/qtmaterialtheme.h" +#include class QtMaterialCircularProgress; class QtMaterialCircularProgressDelegate; @@ -18,13 +18,13 @@ class QtMaterialCircularProgressPrivate void init(); - QtMaterialCircularProgress *const q_ptr; + QtMaterialCircularProgress *const q_ptr; QtMaterialCircularProgressDelegate *delegate; - Material::ProgressType progressType; - QColor color; - qreal penWidth; - int size; - bool useThemeColors; + Material::ProgressType progressType; + QColor color; + qreal penWidth; + int size; + bool useThemeColors; }; -#endif // QTMATERIALCIRCULARPROGRESS_P_H +#endif // QTMATERIALCIRCULARPROGRESS_P_H diff --git a/components/qtmaterialdialog.cpp b/components/qtmaterialdialog.cpp index 82afc898f..7243abf60 100644 --- a/components/qtmaterialdialog.cpp +++ b/components/qtmaterialdialog.cpp @@ -1,18 +1,18 @@ #include "qtmaterialdialog.h" +#include "lib/qtmaterialstatetransition.h" +#include "qtmaterialdialog_internal.h" #include "qtmaterialdialog_p.h" -#include -#include -#include +#include +#include #include +#include #include -#include -#include -#include "qtmaterialdialog_internal.h" -#include "lib/qtmaterialstatetransition.h" +#include +#include /*! - * \class QtMaterialDialogPrivate - * \internal + * @class QtMaterialDialogPrivate + * @internal */ QtMaterialDialogPrivate::QtMaterialDialogPrivate(QtMaterialDialog *q) @@ -20,19 +20,20 @@ QtMaterialDialogPrivate::QtMaterialDialogPrivate(QtMaterialDialog *q) { } -QtMaterialDialogPrivate::~QtMaterialDialogPrivate() -{ -} +QtMaterialDialogPrivate::~QtMaterialDialogPrivate() {} +// main void QtMaterialDialogPrivate::init() { + // get public class Q_Q(QtMaterialDialog); dialogWindow = new QtMaterialDialogWindow(q); - proxyStack = new QStackedLayout; + proxyStack = new QStackedLayout; stateMachine = new QStateMachine(q); - proxy = new QtMaterialDialogProxy(dialogWindow, proxyStack, q); + proxy = new QtMaterialDialogProxy(dialogWindow, proxyStack, q); + // qvbox QVBoxLayout *layout = new QVBoxLayout; q->setLayout(layout); @@ -40,6 +41,7 @@ void QtMaterialDialogPrivate::init() widget->setLayout(proxyStack); widget->setMinimumWidth(400); + // shadoweffect QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; effect->setColor(QColor(0, 0, 0, 200)); effect->setBlurRadius(64); @@ -94,29 +96,25 @@ void QtMaterialDialogPrivate::init() animation->setEasingCurve(QEasingCurve::OutCirc); stateMachine->addDefaultAnimation(animation); - QObject::connect(visibleState, SIGNAL(propertiesAssigned()), - proxy, SLOT(makeOpaque())); - QObject::connect(hiddenState, SIGNAL(propertiesAssigned()), - proxy, SLOT(makeTransparent())); + QObject::connect(visibleState, SIGNAL(propertiesAssigned()), proxy, SLOT(makeOpaque())); + QObject::connect(hiddenState, SIGNAL(propertiesAssigned()), proxy, SLOT(makeTransparent())); stateMachine->start(); QCoreApplication::processEvents(); } /*! - * \class QtMaterialDialog + * @class QtMaterialDialog */ QtMaterialDialog::QtMaterialDialog(QWidget *parent) - : QtMaterialOverlayWidget(parent), - d_ptr(new QtMaterialDialogPrivate(this)) + : QtMaterialOverlayWidget(parent) + , d_ptr(new QtMaterialDialogPrivate(this)) { d_func()->init(); } -QtMaterialDialog::~QtMaterialDialog() -{ -} +QtMaterialDialog::~QtMaterialDialog() {} QLayout *QtMaterialDialog::windowLayout() const { @@ -149,6 +147,7 @@ void QtMaterialDialog::hideDialog() d->proxyStack->setCurrentIndex(1); } +// just paint shadow void QtMaterialDialog::paintEvent(QPaintEvent *event) { Q_UNUSED(event) @@ -162,6 +161,6 @@ void QtMaterialDialog::paintEvent(QPaintEvent *event) brush.setColor(Qt::black); painter.setBrush(brush); painter.setPen(Qt::NoPen); - painter.setOpacity(d->proxy->opacity()/2.4); + painter.setOpacity(d->proxy->opacity() / 2.4); painter.drawRect(rect()); } diff --git a/components/qtmaterialdialog_internal.cpp b/components/qtmaterialdialog_internal.cpp index 6cac9b8c9..00733c8fb 100644 --- a/components/qtmaterialdialog_internal.cpp +++ b/components/qtmaterialdialog_internal.cpp @@ -1,32 +1,29 @@ #include "qtmaterialdialog_internal.h" +#include "qtmaterialdialog.h" +#include #include #include -#include #include -#include "qtmaterialdialog.h" /*! - * \class QtMaterialDialogProxy - * \internal + * @class QtMaterialDialogProxy + * @internal */ -QtMaterialDialogProxy::QtMaterialDialogProxy( - QtMaterialDialogWindow *source, - QStackedLayout *layout, - QtMaterialDialog *dialog, - QWidget *parent) - : QWidget(parent), - m_source(source), - m_layout(layout), - m_dialog(dialog), - m_opacity(0), - m_mode(Transparent) +QtMaterialDialogProxy::QtMaterialDialogProxy(QtMaterialDialogWindow *source, + QStackedLayout *layout, + QtMaterialDialog *dialog, + QWidget *parent) + : QWidget(parent) + , m_source(source) + , m_layout(layout) + , m_dialog(dialog) + , m_opacity(0) + , m_mode(Transparent) { } -QtMaterialDialogProxy::~QtMaterialDialogProxy() -{ -} +QtMaterialDialogProxy::~QtMaterialDialogProxy() {} void QtMaterialDialogProxy::setOpacity(qreal opacity) { @@ -36,7 +33,6 @@ void QtMaterialDialogProxy::setOpacity(qreal opacity) m_dialog->update(); } - void QtMaterialDialogProxy::makeOpaque() { m_dialog->setAttribute(Qt::WA_TransparentForMouseEvents, false); @@ -84,21 +80,17 @@ void QtMaterialDialogProxy::paintEvent(QPaintEvent *event) } /*! - * \class QtMaterialDialogWindow - * \internal + * @class QtMaterialDialogWindow + * @internal */ -QtMaterialDialogWindow::QtMaterialDialogWindow( - QtMaterialDialog *dialog, - QWidget *parent) - : QWidget(parent), - m_dialog(dialog) +QtMaterialDialogWindow::QtMaterialDialogWindow(QtMaterialDialog *dialog, QWidget *parent) + : QWidget(parent) + , m_dialog(dialog) { } -QtMaterialDialogWindow::~QtMaterialDialogWindow() -{ -} +QtMaterialDialogWindow::~QtMaterialDialogWindow() {} void QtMaterialDialogWindow::setOffset(int offset) { diff --git a/components/qtmaterialdialog_internal.h b/components/qtmaterialdialog_internal.h index 52f5a0557..c3e38c19e 100644 --- a/components/qtmaterialdialog_internal.h +++ b/components/qtmaterialdialog_internal.h @@ -20,10 +20,7 @@ class QtMaterialDialogProxy : public QWidget }; public: - QtMaterialDialogProxy(QtMaterialDialogWindow *source, - QStackedLayout *layout, - QtMaterialDialog *dialog, - QWidget *parent = 0); + QtMaterialDialogProxy(QtMaterialDialogWindow *source, QStackedLayout *layout, QtMaterialDialog *dialog, QWidget *parent = 0); ~QtMaterialDialogProxy(); void setOpacity(qreal opacity); @@ -43,10 +40,10 @@ protected slots: Q_DISABLE_COPY(QtMaterialDialogProxy) QtMaterialDialogWindow *const m_source; - QStackedLayout *const m_layout; - QtMaterialDialog *const m_dialog; - qreal m_opacity; - TransparencyMode m_mode; + QStackedLayout *const m_layout; + QtMaterialDialog *const m_dialog; + qreal m_opacity; + TransparencyMode m_mode; }; inline qreal QtMaterialDialogProxy::opacity() const @@ -76,4 +73,4 @@ class QtMaterialDialogWindow : public QWidget QtMaterialDialog *const m_dialog; }; -#endif // QTMATERIALDIALOG_INTERNAL_H +#endif // QTMATERIALDIALOG_INTERNAL_H diff --git a/components/qtmaterialdialog_p.h b/components/qtmaterialdialog_p.h index b10088ee1..238edb813 100644 --- a/components/qtmaterialdialog_p.h +++ b/components/qtmaterialdialog_p.h @@ -20,11 +20,11 @@ class QtMaterialDialogPrivate void init(); - QtMaterialDialog *const q_ptr; + QtMaterialDialog *const q_ptr; QtMaterialDialogWindow *dialogWindow; - QStackedLayout *proxyStack; - QStateMachine *stateMachine; - QtMaterialDialogProxy *proxy; + QStackedLayout *proxyStack; + QStateMachine *stateMachine; + QtMaterialDialogProxy *proxy; }; -#endif // QTMATERIALDIALOG_P_H +#endif // QTMATERIALDIALOG_P_H diff --git a/components/qtmaterialdrawer.cpp b/components/qtmaterialdrawer.cpp index 1bddd4729..93f23bdeb 100644 --- a/components/qtmaterialdrawer.cpp +++ b/components/qtmaterialdrawer.cpp @@ -1,22 +1,22 @@ #include "qtmaterialdrawer.h" +#include "qtmaterialdrawer_internal.h" #include "qtmaterialdrawer_p.h" -#include -#include #include +#include +#include #include +#include #include #include -#include #include -#include "qtmaterialdrawer_internal.h" /*! - * \class QtMaterialDrawerPrivate - * \internal + * @class QtMaterialDrawerPrivate + * @internal */ /*! - * \internal + * @internal */ QtMaterialDrawerPrivate::QtMaterialDrawerPrivate(QtMaterialDrawer *q) : q_ptr(q) @@ -24,33 +24,31 @@ QtMaterialDrawerPrivate::QtMaterialDrawerPrivate(QtMaterialDrawer *q) } /*! - * \internal + * @internal */ -QtMaterialDrawerPrivate::~QtMaterialDrawerPrivate() -{ -} +QtMaterialDrawerPrivate::~QtMaterialDrawerPrivate() {} /*! - * \internal + * @internal */ void QtMaterialDrawerPrivate::init() { Q_Q(QtMaterialDrawer); - widget = new QtMaterialDrawerWidget; + widget = new QtMaterialDrawerWidget; stateMachine = new QtMaterialDrawerStateMachine(widget, q); - window = new QWidget; - width = 250; + window = new QWidget; + width = 250; clickToClose = false; - autoRaise = true; - closed = true; - overlay = false; + autoRaise = true; + closed = true; + overlay = false; QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(window); widget->setLayout(layout); - widget->setFixedWidth(width+16); + widget->setFixedWidth(width + 16); widget->setParent(q); @@ -59,19 +57,17 @@ void QtMaterialDrawerPrivate::init() } /*! - * \class QtMaterialDrawer + * @class QtMaterialDrawer */ QtMaterialDrawer::QtMaterialDrawer(QWidget *parent) - : QtMaterialOverlayWidget(parent), - d_ptr(new QtMaterialDrawerPrivate(this)) + : QtMaterialOverlayWidget(parent) + , d_ptr(new QtMaterialDrawerPrivate(this)) { d_func()->init(); } -QtMaterialDrawer::~QtMaterialDrawer() -{ -} +QtMaterialDrawer::~QtMaterialDrawer() {} void QtMaterialDrawer::setDrawerWidth(int width) { @@ -79,7 +75,7 @@ void QtMaterialDrawer::setDrawerWidth(int width) d->width = width; d->stateMachine->updatePropertyAssignments(); - d->widget->setFixedWidth(width+16); + d->widget->setFixedWidth(width + 16); } int QtMaterialDrawer::drawerWidth() const @@ -162,9 +158,10 @@ void QtMaterialDrawer::openDrawer() void QtMaterialDrawer::closeDrawer() { Q_D(QtMaterialDrawer); - + // emit signal to close emit d->stateMachine->signalClose(); + // reset the attribute if (d->overlay) { setAttribute(Qt::WA_TransparentForMouseEvents); setAttribute(Qt::WA_NoSystemBackground); @@ -175,46 +172,47 @@ bool QtMaterialDrawer::event(QEvent *event) { Q_D(QtMaterialDrawer); - switch (event->type()) - { - case QEvent::Move: - case QEvent::Resize: - if (!d->overlay) { - setMask(QRegion(d->widget->rect())); - } - break; - default: - break; + switch (event->type()) { + case QEvent::Move: + case QEvent::Resize: + if (!d->overlay) { + setMask(QRegion(d->widget->rect())); + } + break; + default: + break; } return QtMaterialOverlayWidget::event(event); } +// size bool QtMaterialDrawer::eventFilter(QObject *obj, QEvent *event) { Q_D(QtMaterialDrawer); - switch (event->type()) - { - case QEvent::MouseButtonPress: { - QMouseEvent *mouseEvent; - if ((mouseEvent = static_cast(event))) { - const bool canClose = d->clickToClose || d->overlay; - if (!d->widget->geometry().contains(mouseEvent->pos()) && canClose) { - closeDrawer(); + switch (event->type()) { + case QEvent::MouseButtonPress: { + QMouseEvent *mouseEvent; + if ((mouseEvent = static_cast(event))) { + // check canClose + const bool canClose = d->clickToClose || d->overlay; + // auto close location + if (!d->widget->geometry().contains(mouseEvent->pos()) && canClose) { + closeDrawer(); + } } + break; } - break; - } - case QEvent::Move: - case QEvent::Resize: { - QLayout *lw = d->widget->layout(); - if (lw && 16 != lw->contentsMargins().right()) { - lw->setContentsMargins(0, 0, 16, 0); + case QEvent::Move: + case QEvent::Resize: { + QLayout *lw = d->widget->layout(); + if (lw && 16 != lw->contentsMargins().right()) { + lw->setContentsMargins(0, 0, 16, 0); + } + break; } - break; - } - default: - break; + default: + break; } return QtMaterialOverlayWidget::eventFilter(obj, event); } @@ -228,6 +226,7 @@ void QtMaterialDrawer::paintEvent(QPaintEvent *event) if (!d->overlay || d->stateMachine->isInClosedState()) { return; } + // shadow QPainter painter(this); painter.setOpacity(d->stateMachine->opacity()); painter.fillRect(rect(), Qt::SolidPattern); diff --git a/components/qtmaterialdrawer_internal.cpp b/components/qtmaterialdrawer_internal.cpp index 7f327005d..15782de1f 100644 --- a/components/qtmaterialdrawer_internal.cpp +++ b/components/qtmaterialdrawer_internal.cpp @@ -1,25 +1,25 @@ #include "qtmaterialdrawer_internal.h" -#include +#include "qtmaterialdrawer.h" #include -#include -#include #include -#include "qtmaterialdrawer.h" +#include +#include +#include /*! - * \class QtMaterialDrawerStateMachine - * \internal + * @class QtMaterialDrawerStateMachine + * @internal */ QtMaterialDrawerStateMachine::QtMaterialDrawerStateMachine(QtMaterialDrawerWidget *drawer, QtMaterialDrawer *parent) - : QStateMachine(parent), - m_drawer(drawer), - m_main(parent), - m_openingState(new QState), - m_openedState(new QState), - m_closingState(new QState), - m_closedState(new QState), - m_opacity(0) + : QStateMachine(parent) + , m_drawer(drawer) + , m_main(parent) + , m_openingState(new QState) + , m_openedState(new QState) + , m_closingState(new QState) + , m_closedState(new QState) + , m_opacity(0) { addState(m_openingState); addState(m_openedState); @@ -85,9 +85,7 @@ QtMaterialDrawerStateMachine::QtMaterialDrawerStateMachine(QtMaterialDrawerWidge updatePropertyAssignments(); } -QtMaterialDrawerStateMachine::~QtMaterialDrawerStateMachine() -{ -} +QtMaterialDrawerStateMachine::~QtMaterialDrawerStateMachine() {} void QtMaterialDrawerStateMachine::setOpacity(qreal opacity) { @@ -102,7 +100,7 @@ bool QtMaterialDrawerStateMachine::isInClosedState() const void QtMaterialDrawerStateMachine::updatePropertyAssignments() { - const qreal closedOffset = -(m_drawer->width()+32); + const qreal closedOffset = -(m_drawer->width() + 32); m_closingState->assignProperty(m_drawer, "offset", closedOffset); m_closedState->assignProperty(m_drawer, "offset", closedOffset); @@ -115,19 +113,17 @@ void QtMaterialDrawerStateMachine::updatePropertyAssignments() } /*! - * \class QtMaterialDrawerWidget - * \internal + * @class QtMaterialDrawerWidget + * @internal */ QtMaterialDrawerWidget::QtMaterialDrawerWidget(QWidget *parent) - : QtMaterialOverlayWidget(parent), - m_offset(0) + : QtMaterialOverlayWidget(parent) + , m_offset(0) { } -QtMaterialDrawerWidget::~QtMaterialDrawerWidget() -{ -} +QtMaterialDrawerWidget::~QtMaterialDrawerWidget() {} void QtMaterialDrawerWidget::setOffset(int offset) { @@ -154,13 +150,13 @@ void QtMaterialDrawerWidget::paintEvent(QPaintEvent *event) painter.drawRect(rect().adjusted(0, 0, -16, 0)); - QLinearGradient gradient(QPointF(width()-16, 0), QPointF(width(), 0)); + QLinearGradient gradient(QPointF(width() - 16, 0), QPointF(width(), 0)); gradient.setColorAt(0, QColor(0, 0, 0, 80)); gradient.setColorAt(0.5, QColor(0, 0, 0, 20)); gradient.setColorAt(1, QColor(0, 0, 0, 0)); painter.setBrush(QBrush(gradient)); - painter.drawRect(width()-16, 0, 16, height()); + painter.drawRect(width() - 16, 0, 16, height()); } QRect QtMaterialDrawerWidget::overlayGeometry() const diff --git a/components/qtmaterialdrawer_internal.h b/components/qtmaterialdrawer_internal.h index 76d219db2..2fb13b2be 100644 --- a/components/qtmaterialdrawer_internal.h +++ b/components/qtmaterialdrawer_internal.h @@ -1,8 +1,8 @@ #ifndef DRAWER_INTERNAL_H #define DRAWER_INTERNAL_H -#include #include "lib/qtmaterialoverlaywidget.h" +#include class QtMaterialDrawer; class QtMaterialDrawerWidget; @@ -14,8 +14,7 @@ class QtMaterialDrawerStateMachine : public QStateMachine Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity) public: - explicit QtMaterialDrawerStateMachine(QtMaterialDrawerWidget *drawer, - QtMaterialDrawer *parent); + explicit QtMaterialDrawerStateMachine(QtMaterialDrawerWidget *drawer, QtMaterialDrawer *parent); ~QtMaterialDrawerStateMachine(); void setOpacity(qreal opacity); @@ -33,12 +32,12 @@ class QtMaterialDrawerStateMachine : public QStateMachine Q_DISABLE_COPY(QtMaterialDrawerStateMachine) QtMaterialDrawerWidget *const m_drawer; - QtMaterialDrawer *const m_main; - QState *const m_openingState; - QState *const m_openedState; - QState *const m_closingState; - QState *const m_closedState; - qreal m_opacity; + QtMaterialDrawer *const m_main; + QState *const m_openingState; + QState *const m_openedState; + QState *const m_closingState; + QState *const m_closedState; + qreal m_opacity; }; inline qreal QtMaterialDrawerStateMachine::opacity() const @@ -65,7 +64,7 @@ class QtMaterialDrawerWidget : public QtMaterialOverlayWidget QRect overlayGeometry() const Q_DECL_OVERRIDE; private: - int m_offset; + int m_offset; }; inline int QtMaterialDrawerWidget::offset() const @@ -73,4 +72,4 @@ inline int QtMaterialDrawerWidget::offset() const return m_offset; } -#endif // DRAWER_INTERNAL_H +#endif // DRAWER_INTERNAL_H diff --git a/components/qtmaterialdrawer_p.h b/components/qtmaterialdrawer_p.h index cdd064d12..f9b772401 100644 --- a/components/qtmaterialdrawer_p.h +++ b/components/qtmaterialdrawer_p.h @@ -19,15 +19,15 @@ class QtMaterialDrawerPrivate void init(); void setClosed(bool value = true); - QtMaterialDrawer *const q_ptr; - QtMaterialDrawerWidget *widget; + QtMaterialDrawer *const q_ptr; + QtMaterialDrawerWidget *widget; QtMaterialDrawerStateMachine *stateMachine; - QWidget *window; - int width; - bool clickToClose; - bool autoRaise; - bool closed; - bool overlay; + QWidget *window; + int width; + bool clickToClose; + bool autoRaise; + bool closed; + bool overlay; }; -#endif // DRAWER_P_H +#endif // DRAWER_P_H diff --git a/components/qtmaterialfab.cpp b/components/qtmaterialfab.cpp index 3c3de8a1f..140122f7f 100644 --- a/components/qtmaterialfab.cpp +++ b/components/qtmaterialfab.cpp @@ -1,42 +1,41 @@ #include "qtmaterialfab.h" +#include "lib/qtmaterialrippleoverlay.h" #include "qtmaterialfab_p.h" -#include -#include #include #include -#include "lib/qtmaterialrippleoverlay.h" +#include +#include /*! - * \class QtMaterialFloatingActionButtonPrivate - * \internal + * @class QtMaterialFloatingActionButtonPrivate + * @internal */ /*! - * \internal + * @internal */ QtMaterialFloatingActionButtonPrivate::QtMaterialFloatingActionButtonPrivate(QtMaterialFloatingActionButton *q) : QtMaterialRaisedButtonPrivate(q) + , q_ptr(q) { } /*! - * \internal + * @internal */ -QtMaterialFloatingActionButtonPrivate::~QtMaterialFloatingActionButtonPrivate() -{ -} +QtMaterialFloatingActionButtonPrivate::~QtMaterialFloatingActionButtonPrivate() {} /*! - * \internal + * @internal */ void QtMaterialFloatingActionButtonPrivate::init() { Q_Q(QtMaterialFloatingActionButton); corner = Qt::BottomRightCorner; - mini = false; - offsX = 34; - offsY = 36; + mini = false; + offsX = 34; + offsY = 36; q->setRole(Material::Primary); q->setFixedSize(DefaultDiameter, DefaultDiameter); @@ -52,7 +51,7 @@ void QtMaterialFloatingActionButtonPrivate::init() } /*! - * \internal + * @internal */ QRect QtMaterialFloatingActionButtonPrivate::fabGeometry() const { @@ -65,23 +64,22 @@ QRect QtMaterialFloatingActionButtonPrivate::fabGeometry() const const int s = mini ? MiniDiameter : DefaultDiameter; - switch (corner) - { - case Qt::TopLeftCorner: - return QRect(offsX, offsY, s, s); - case Qt::TopRightCorner: - return QRect(parent->width()-(offsX+s), offsY, s, s); - case Qt::BottomLeftCorner: - return QRect(offsX, parent->height()-(offsY+s), s, s); - case Qt::BottomRightCorner: - default: - break; + switch (corner) { + case Qt::TopLeftCorner: + return QRect(offsX, offsY, s, s); + case Qt::TopRightCorner: + return QRect(parent->width() - (offsX + s), offsY, s, s); + case Qt::BottomLeftCorner: + return QRect(offsX, parent->height() - (offsY + s), s, s); + case Qt::BottomRightCorner: + default: + break; } - return QRect(parent->width()-(offsX+s), parent->height()-(offsY+s), s, s); + return QRect(parent->width() - (offsX + s), parent->height() - (offsY + s), s, s); } /*! - * \internal + * @internal */ void QtMaterialFloatingActionButtonPrivate::setupProperties() { @@ -101,7 +99,7 @@ void QtMaterialFloatingActionButtonPrivate::setupProperties() } /*! - * \class QtMaterialFloatingActionButton + * @class QtMaterialFloatingActionButton */ QtMaterialFloatingActionButton::QtMaterialFloatingActionButton(const QIcon &icon, QWidget *parent) @@ -112,20 +110,17 @@ QtMaterialFloatingActionButton::QtMaterialFloatingActionButton(const QIcon &icon setIcon(icon); } -QtMaterialFloatingActionButton::~QtMaterialFloatingActionButton() -{ -} +QtMaterialFloatingActionButton::~QtMaterialFloatingActionButton() {} /*! - * \reimp + * @reimp */ QSize QtMaterialFloatingActionButton::sizeHint() const { Q_D(const QtMaterialFloatingActionButton); if (d->mini) { - return QSize(QtMaterialFloatingActionButtonPrivate::MiniDiameter, - QtMaterialFloatingActionButtonPrivate::MiniDiameter); + return QSize(QtMaterialFloatingActionButtonPrivate::MiniDiameter, QtMaterialFloatingActionButtonPrivate::MiniDiameter); } else { return QSize(QtMaterialFloatingActionButtonPrivate::DefaultDiameter, QtMaterialFloatingActionButtonPrivate::DefaultDiameter); @@ -228,7 +223,7 @@ int QtMaterialFloatingActionButton::yOffset() const } /*! - * \reimp + * @reimp */ bool QtMaterialFloatingActionButton::event(QEvent *event) { @@ -237,34 +232,30 @@ bool QtMaterialFloatingActionButton::event(QEvent *event) if (!parent()) { return QtMaterialRaisedButton::event(event); } - switch (event->type()) - { - case QEvent::ParentChange: - { - parent()->installEventFilter(this); - setGeometry(d->fabGeometry()); - break; - } - case QEvent::ParentAboutToChange: - { - parent()->removeEventFilter(this); - break; - } - default: - break; + switch (event->type()) { + case QEvent::ParentChange: { + parent()->installEventFilter(this); + setGeometry(d->fabGeometry()); + break; + } + case QEvent::ParentAboutToChange: { + parent()->removeEventFilter(this); + break; + } + default: + break; } return QtMaterialRaisedButton::event(event); } /*! - * \reimp + * @reimp */ bool QtMaterialFloatingActionButton::eventFilter(QObject *obj, QEvent *event) { const QEvent::Type type = event->type(); - if (QEvent::Move == type || QEvent::Resize == type) - { + if (QEvent::Move == type || QEvent::Resize == type) { Q_D(QtMaterialFloatingActionButton); setGeometry(d->fabGeometry()); } @@ -273,7 +264,7 @@ bool QtMaterialFloatingActionButton::eventFilter(QObject *obj, QEvent *event) } /*! - * \reimp + * @reimp */ void QtMaterialFloatingActionButton::paintEvent(QPaintEvent *event) { @@ -306,8 +297,7 @@ void QtMaterialFloatingActionButton::paintEvent(QPaintEvent *event) QPixmap pixmap = icon().pixmap(QSize(d->iconSize(), d->iconSize())); QPainter icon(&pixmap); icon.setCompositionMode(QPainter::CompositionMode_SourceIn); - icon.fillRect(pixmap.rect(), isEnabled() ? foregroundColor() - : disabledForegroundColor()); + icon.fillRect(pixmap.rect(), isEnabled() ? foregroundColor() : disabledForegroundColor()); painter.drawPixmap(iconGeometry, pixmap); } diff --git a/components/qtmaterialfab_p.h b/components/qtmaterialfab_p.h index fae2d3ae8..e1671fe27 100644 --- a/components/qtmaterialfab_p.h +++ b/components/qtmaterialfab_p.h @@ -11,20 +11,16 @@ class QtMaterialFloatingActionButtonPrivate : public QtMaterialRaisedButtonPriva Q_DECLARE_PUBLIC(QtMaterialFloatingActionButton) public: - enum { - DefaultDiameter = 56, - MiniDiameter = 40 - }; + enum { DefaultDiameter = 56, MiniDiameter = 40 }; - enum { - DefaultIconSize = 24, - MiniIconSize = 18 - }; + enum { DefaultIconSize = 24, MiniIconSize = 18 }; QtMaterialFloatingActionButtonPrivate(QtMaterialFloatingActionButton *q); ~QtMaterialFloatingActionButtonPrivate(); void init(); + + QtMaterialFloatingActionButton *const q_ptr; QRect fabGeometry() const; void setupProperties(); @@ -32,9 +28,9 @@ class QtMaterialFloatingActionButtonPrivate : public QtMaterialRaisedButtonPriva inline int iconSize() const; Qt::Corner corner; - bool mini; - int offsX; - int offsY; + bool mini; + int offsX; + int offsY; }; inline int QtMaterialFloatingActionButtonPrivate::diameter() const @@ -47,4 +43,4 @@ inline int QtMaterialFloatingActionButtonPrivate::iconSize() const return mini ? MiniIconSize : DefaultIconSize; } -#endif // QTMATERIALFAB_P_H +#endif // QTMATERIALFAB_P_H diff --git a/components/qtmaterialflatbutton.cpp b/components/qtmaterialflatbutton.cpp index b9d84d7e2..e5a3687e4 100644 --- a/components/qtmaterialflatbutton.cpp +++ b/components/qtmaterialflatbutton.cpp @@ -1,23 +1,23 @@ #include "qtmaterialflatbutton.h" -#include "qtmaterialflatbutton_p.h" -#include -#include -#include -#include -#include -#include -#include "lib/qtmaterialrippleoverlay.h" #include "lib/qtmaterialripple.h" +#include "lib/qtmaterialrippleoverlay.h" #include "lib/qtmaterialstyle.h" #include "qtmaterialflatbutton_internal.h" +#include "qtmaterialflatbutton_p.h" +#include +#include +#include +#include +#include +#include /*! - * \class QtMaterialFlatButtonPrivate - * \internal + * @class QtMaterialFlatButtonPrivate + * @internal */ /*! - * \internal + * @internal */ QtMaterialFlatButtonPrivate::QtMaterialFlatButtonPrivate(QtMaterialFlatButton *q) : q_ptr(q) @@ -25,34 +25,32 @@ QtMaterialFlatButtonPrivate::QtMaterialFlatButtonPrivate(QtMaterialFlatButton *q } /*! - * \internal + * @internal */ -QtMaterialFlatButtonPrivate::~QtMaterialFlatButtonPrivate() -{ -} +QtMaterialFlatButtonPrivate::~QtMaterialFlatButtonPrivate() {} /*! - * \internal + * @internal */ void QtMaterialFlatButtonPrivate::init() { Q_Q(QtMaterialFlatButton); - rippleOverlay = new QtMaterialRippleOverlay(q); - stateMachine = new QtMaterialFlatButtonStateMachine(q); - role = Material::Default; - rippleStyle = Material::PositionedRipple; - iconPlacement = Material::LeftIcon; - overlayStyle = Material::GrayOverlay; - bgMode = Qt::TransparentMode; - textAlignment = Qt::AlignHCenter; - fixedRippleRadius = 64; - cornerRadius = 3; - baseOpacity = 0.13; - fontSize = 10; // 10.5; - useThemeColors = true; + rippleOverlay = new QtMaterialRippleOverlay(q); + stateMachine = new QtMaterialFlatButtonStateMachine(q); + role = Material::Default; + rippleStyle = Material::PositionedRipple; + iconPlacement = Material::LeftIcon; + overlayStyle = Material::GrayOverlay; + bgMode = Qt::TransparentMode; + textAlignment = Qt::AlignHCenter; + fixedRippleRadius = 64; + cornerRadius = 3; + baseOpacity = 0.13; + fontSize = 10; // 10.5; + useThemeColors = true; useFixedRippleRadius = false; - haloVisible = true; + haloVisible = true; q->setStyle(&QtMaterialStyle::instance()); q->setAttribute(Qt::WA_Hover); @@ -72,12 +70,12 @@ void QtMaterialFlatButtonPrivate::init() } /*! - * \class QtMaterialFlatButton + * @class QtMaterialFlatButton */ QtMaterialFlatButton::QtMaterialFlatButton(QWidget *parent, Material::ButtonPreset preset) - : QPushButton(parent), - d_ptr(new QtMaterialFlatButtonPrivate(this)) + : QPushButton(parent) + , d_ptr(new QtMaterialFlatButtonPrivate(this)) { d_func()->init(); @@ -85,17 +83,20 @@ QtMaterialFlatButton::QtMaterialFlatButton(QWidget *parent, Material::ButtonPres } QtMaterialFlatButton::QtMaterialFlatButton(const QString &text, QWidget *parent, Material::ButtonPreset preset) - : QPushButton(text, parent), - d_ptr(new QtMaterialFlatButtonPrivate(this)) + : QPushButton(text, parent) + , d_ptr(new QtMaterialFlatButtonPrivate(this)) { d_func()->init(); applyPreset(preset); } -QtMaterialFlatButton::QtMaterialFlatButton(const QString &text, Material::Role role, QWidget *parent, Material::ButtonPreset preset) - : QPushButton(text, parent), - d_ptr(new QtMaterialFlatButtonPrivate(this)) +QtMaterialFlatButton::QtMaterialFlatButton(const QString &text, + Material::Role role, + QWidget *parent, + Material::ButtonPreset preset) + : QPushButton(text, parent) + , d_ptr(new QtMaterialFlatButtonPrivate(this)) { d_func()->init(); @@ -103,24 +104,21 @@ QtMaterialFlatButton::QtMaterialFlatButton(const QString &text, Material::Role r setRole(role); } -QtMaterialFlatButton::~QtMaterialFlatButton() -{ -} +QtMaterialFlatButton::~QtMaterialFlatButton() {} void QtMaterialFlatButton::applyPreset(Material::ButtonPreset preset) { - switch (preset) - { - case Material::FlatPreset: - setOverlayStyle(Material::NoOverlay); - break; - case Material::CheckablePreset: - setOverlayStyle(Material::NoOverlay); - setCheckable(true); - setHaloVisible(false); - break; - default: - break; + switch (preset) { + case Material::FlatPreset: + setOverlayStyle(Material::NoOverlay); + break; + case Material::CheckablePreset: + setOverlayStyle(Material::NoOverlay); + setCheckable(true); + setHaloVisible(false); + break; + default: + break; } } @@ -172,20 +170,18 @@ QColor QtMaterialFlatButton::foregroundColor() const { Q_D(const QtMaterialFlatButton); - if (d->useThemeColors || !d->foregroundColor.isValid()) - { + if (d->useThemeColors || !d->foregroundColor.isValid()) { if (Qt::OpaqueMode == d->bgMode) { return QtMaterialStyle::instance().themeColor("canvas"); } - switch (d->role) - { - case Material::Primary: - return QtMaterialStyle::instance().themeColor("primary1"); - case Material::Secondary: - return QtMaterialStyle::instance().themeColor("accent1"); - case Material::Default: - default: - return QtMaterialStyle::instance().themeColor("text"); + switch (d->role) { + case Material::Primary: + return QtMaterialStyle::instance().themeColor("primary1"); + case Material::Secondary: + return QtMaterialStyle::instance().themeColor("accent1"); + case Material::Default: + default: + return QtMaterialStyle::instance().themeColor("text"); } } return d->foregroundColor; @@ -205,17 +201,15 @@ QColor QtMaterialFlatButton::backgroundColor() const { Q_D(const QtMaterialFlatButton); - if (d->useThemeColors || !d->backgroundColor.isValid()) - { - switch (d->role) - { - case Material::Primary: - return QtMaterialStyle::instance().themeColor("primary1"); - case Material::Secondary: - return QtMaterialStyle::instance().themeColor("accent1"); - case Material::Default: - default: - return QtMaterialStyle::instance().themeColor("text"); + if (d->useThemeColors || !d->backgroundColor.isValid()) { + switch (d->role) { + case Material::Primary: + return QtMaterialStyle::instance().themeColor("primary1"); + case Material::Secondary: + return QtMaterialStyle::instance().themeColor("accent1"); + case Material::Default: + default: + return QtMaterialStyle::instance().themeColor("text"); } } return d->backgroundColor; @@ -456,7 +450,7 @@ Qt::Alignment QtMaterialFlatButton::textAlignment() const } /*! - * \reimp + * @reimp */ QSize QtMaterialFlatButton::sizeHint() const { @@ -473,9 +467,9 @@ QSize QtMaterialFlatButton::sizeHint() const return QSize(w, 20 + h); } -QtMaterialFlatButton::QtMaterialFlatButton(QtMaterialFlatButtonPrivate &d,QWidget *parent, Material::ButtonPreset preset) - : QPushButton(parent), - d_ptr(&d) +QtMaterialFlatButton::QtMaterialFlatButton(QtMaterialFlatButtonPrivate &d, QWidget *parent, Material::ButtonPreset preset) + : QPushButton(parent) + , d_ptr(&d) { d_func()->init(); @@ -483,7 +477,7 @@ QtMaterialFlatButton::QtMaterialFlatButton(QtMaterialFlatButtonPrivate &d,QWidge } /*! - * \reimp + * @reimp */ void QtMaterialFlatButton::checkStateSet() { @@ -495,14 +489,13 @@ void QtMaterialFlatButton::checkStateSet() } /*! - * \reimp + * @reimp */ void QtMaterialFlatButton::mousePressEvent(QMouseEvent *event) { Q_D(QtMaterialFlatButton); - if (Material::NoRipple != d->rippleStyle) - { + if (Material::NoRipple != d->rippleStyle) { QPoint pos; qreal radiusEndValue; @@ -515,7 +508,7 @@ void QtMaterialFlatButton::mousePressEvent(QMouseEvent *event) if (d->useFixedRippleRadius) { radiusEndValue = d->fixedRippleRadius; } else { - radiusEndValue = static_cast(width())/2; + radiusEndValue = static_cast(width()) / 2; } QtMaterialRipple *ripple = new QtMaterialRipple(pos); @@ -533,7 +526,7 @@ void QtMaterialFlatButton::mousePressEvent(QMouseEvent *event) } /*! - * \reimp + * @reimp */ void QtMaterialFlatButton::mouseReleaseEvent(QMouseEvent *event) { @@ -552,7 +545,7 @@ void QtMaterialFlatButton::resizeEvent(QResizeEvent *event) } /*! - * \reimp + * @reimp */ void QtMaterialFlatButton::paintEvent(QPaintEvent *event) { @@ -565,8 +558,7 @@ void QtMaterialFlatButton::paintEvent(QPaintEvent *event) const qreal cr = d->cornerRadius; - if (cr > 0) - { + if (cr > 0) { QPainterPath path; path.addRoundedRect(rect(), cr, cr); @@ -584,7 +576,7 @@ void QtMaterialFlatButton::paintEvent(QPaintEvent *event) } /*! - * \internal + * @internal */ void QtMaterialFlatButton::paintBackground(QPainter *painter) { @@ -629,16 +621,16 @@ void QtMaterialFlatButton::paintBackground(QPainter *painter) if (isCheckable() && checkedProgress > 0) { const qreal q = Qt::TransparentMode == d->bgMode ? 0.45 : 0.7; brush.setColor(foregroundColor()); - painter->setOpacity(q*checkedProgress); + painter->setOpacity(q * checkedProgress); painter->setBrush(brush); QRect r(rect()); - r.setHeight(static_cast(r.height())*checkedProgress); + r.setHeight(static_cast(r.height()) * checkedProgress); painter->drawRect(r); } } /*! - * \internal + * @internal */ void QtMaterialFlatButton::paintHalo(QPainter *painter) { @@ -649,8 +641,8 @@ void QtMaterialFlatButton::paintHalo(QPainter *painter) } const qreal opacity = d->stateMachine->haloOpacity(); - const qreal s = d->stateMachine->haloScaleFactor()*d->stateMachine->haloSize(); - const qreal radius = static_cast(width())*s; + const qreal s = d->stateMachine->haloScaleFactor() * d->stateMachine->haloSize(); + const qreal radius = static_cast(width()) * s; if (isEnabled() && opacity > 0) { QBrush brush; @@ -664,10 +656,10 @@ void QtMaterialFlatButton::paintHalo(QPainter *painter) } } -#define COLOR_INTERPOLATE(CH) (1-progress)*source.CH() + progress*dest.CH() +#define COLOR_INTERPOLATE(CH) (1 - progress) * source.CH() + progress *dest.CH() /*! - * \internal + * @internal */ void QtMaterialFlatButton::paintForeground(QPainter *painter) { @@ -678,22 +670,19 @@ void QtMaterialFlatButton::paintForeground(QPainter *painter) const qreal progress = d->stateMachine->checkedOverlayProgress(); if (isCheckable() && progress > 0) { QColor source = foregroundColor(); - QColor dest = Qt::TransparentMode == d->bgMode ? Qt::white - : backgroundColor(); + QColor dest = Qt::TransparentMode == d->bgMode ? Qt::white : backgroundColor(); if (qFuzzyCompare(1, progress)) { painter->setPen(dest); } else { - painter->setPen(QColor(COLOR_INTERPOLATE(red), - COLOR_INTERPOLATE(green), - COLOR_INTERPOLATE(blue), - COLOR_INTERPOLATE(alpha))); + painter->setPen( + QColor(COLOR_INTERPOLATE(red), COLOR_INTERPOLATE(green), COLOR_INTERPOLATE(blue), COLOR_INTERPOLATE(alpha))); } } } else { painter->setPen(disabledForegroundColor()); } - if (icon().isNull()) { + if (icon().isNull()) { if (Qt::AlignLeft == d->textAlignment) { painter->drawText(rect().adjusted(12, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, text()); } else { @@ -703,13 +692,13 @@ void QtMaterialFlatButton::paintForeground(QPainter *painter) } QSize textSize(fontMetrics().size(Qt::TextSingleLine, text())); - QSize base(size()-textSize); + QSize base(size() - textSize); const int iw = iconSize().width() + IconPadding; - QPoint pos(Qt::AlignLeft == d->textAlignment ? 12 : (base.width()-iw)/2, 0); + QPoint pos(Qt::AlignLeft == d->textAlignment ? 12 : (base.width() - iw) / 2, 0); - QRect textGeometry(pos + QPoint(0, base.height()/2), textSize); - QRect iconGeometry(pos + QPoint(0, (height()-iconSize().height())/2), iconSize()); + QRect textGeometry(pos + QPoint(0, base.height() / 2), textSize); + QRect iconGeometry(pos + QPoint(0, (height() - iconSize().height()) / 2), iconSize()); if (Material::LeftIcon == d->iconPlacement) { textGeometry.translate(iw, 0); @@ -727,7 +716,7 @@ void QtMaterialFlatButton::paintForeground(QPainter *painter) } /*! - * \internal + * @internal */ void QtMaterialFlatButton::updateClipPath() { diff --git a/components/qtmaterialflatbutton_internal.cpp b/components/qtmaterialflatbutton_internal.cpp index 0709a45f5..4b90f09b3 100644 --- a/components/qtmaterialflatbutton_internal.cpp +++ b/components/qtmaterialflatbutton_internal.cpp @@ -1,36 +1,36 @@ #include "qtmaterialflatbutton_internal.h" +#include "lib/qtmaterialstatetransition.h" +#include "qtmaterialflatbutton.h" #include -#include #include +#include #include -#include "qtmaterialflatbutton.h" -#include "lib/qtmaterialstatetransition.h" /*! - * \class QtMaterialFlatButtonStateMachine - * \internal + * @class QtMaterialFlatButtonStateMachine + * @internal */ QtMaterialFlatButtonStateMachine::QtMaterialFlatButtonStateMachine(QtMaterialFlatButton *parent) - : QStateMachine(parent), - m_button(parent), - m_topLevelState(new QState(QState::ParallelStates)), - m_configState(new QState(m_topLevelState)), - m_checkableState(new QState(m_topLevelState)), - m_checkedState(new QState(m_checkableState)), - m_uncheckedState(new QState(m_checkableState)), - m_neutralState(new QState(m_configState)), - m_neutralFocusedState(new QState(m_configState)), - m_hoveredState(new QState(m_configState)), - m_hoveredFocusedState(new QState(m_configState)), - m_pressedState(new QState(m_configState)), - m_haloAnimation(new QSequentialAnimationGroup(this)), - m_overlayOpacity(0), - m_checkedOverlayProgress(parent->isChecked() ? 1 : 0), - m_haloOpacity(0), - m_haloSize(0.8), - m_haloScaleFactor(1), - m_wasChecked(false) + : QStateMachine(parent) + , m_button(parent) + , m_topLevelState(new QState(QState::ParallelStates)) + , m_configState(new QState(m_topLevelState)) + , m_checkableState(new QState(m_topLevelState)) + , m_checkedState(new QState(m_checkableState)) + , m_uncheckedState(new QState(m_checkableState)) + , m_neutralState(new QState(m_configState)) + , m_neutralFocusedState(new QState(m_configState)) + , m_hoveredState(new QState(m_configState)) + , m_hoveredFocusedState(new QState(m_configState)) + , m_pressedState(new QState(m_configState)) + , m_haloAnimation(new QSequentialAnimationGroup(this)) + , m_overlayOpacity(0) + , m_checkedOverlayProgress(parent->isChecked() ? 1 : 0) + , m_haloOpacity(0) + , m_haloSize(0.8) + , m_haloScaleFactor(1) + , m_wasChecked(false) { Q_ASSERT(parent); @@ -40,8 +40,7 @@ QtMaterialFlatButtonStateMachine::QtMaterialFlatButtonStateMachine(QtMaterialFla addState(m_topLevelState); setInitialState(m_topLevelState); - m_checkableState->setInitialState(parent->isChecked() ? m_checkedState - : m_uncheckedState); + m_checkableState->setInitialState(parent->isChecked() ? m_checkedState : m_uncheckedState); QtMaterialStateTransition *transition; QPropertyAnimation *animation; @@ -105,9 +104,7 @@ QtMaterialFlatButtonStateMachine::QtMaterialFlatButtonStateMachine(QtMaterialFla m_haloAnimation->setLoopCount(-1); } -QtMaterialFlatButtonStateMachine::~QtMaterialFlatButtonStateMachine() -{ -} +QtMaterialFlatButtonStateMachine::~QtMaterialFlatButtonStateMachine() {} void QtMaterialFlatButtonStateMachine::setOverlayOpacity(qreal opacity) { @@ -186,8 +183,7 @@ void QtMaterialFlatButtonStateMachine::updateCheckedStatus() } } -bool QtMaterialFlatButtonStateMachine::eventFilter(QObject *watched, - QEvent *event) +bool QtMaterialFlatButtonStateMachine::eventFilter(QObject *watched, QEvent *event) { if (QEvent::FocusIn == event->type()) { QFocusEvent *focusEvent = static_cast(event); @@ -199,17 +195,12 @@ bool QtMaterialFlatButtonStateMachine::eventFilter(QObject *watched, return QStateMachine::eventFilter(watched, event); } -void QtMaterialFlatButtonStateMachine::addTransition(QObject *object, - QEvent::Type eventType, - QState *fromState, - QState *toState) +void QtMaterialFlatButtonStateMachine::addTransition(QObject *object, QEvent::Type eventType, QState *fromState, QState *toState) { addTransition(new QEventTransition(object, eventType), fromState, toState); } -void QtMaterialFlatButtonStateMachine::addTransition(QAbstractTransition *transition, - QState *fromState, - QState *toState) +void QtMaterialFlatButtonStateMachine::addTransition(QAbstractTransition *transition, QState *fromState, QState *toState) { transition->setTargetState(toState); diff --git a/components/qtmaterialflatbutton_internal.h b/components/qtmaterialflatbutton_internal.h index ff93972b9..9c5130305 100644 --- a/components/qtmaterialflatbutton_internal.h +++ b/components/qtmaterialflatbutton_internal.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALFLATBUTTON_INTERNAL_H #define QTMATERIALFLATBUTTON_INTERNAL_H -#include #include +#include class QtMaterialFlatButton; class QSequentialAnimationGroup; @@ -55,24 +55,23 @@ class QtMaterialFlatButtonStateMachine : public QStateMachine void addTransition(QAbstractTransition *transition, QState *fromState, QState *toState); QtMaterialFlatButton *const m_button; - QState *const m_topLevelState; - QState *const m_configState; - QState *const m_checkableState; - QState *const m_checkedState; - QState *const m_uncheckedState; - QState *const m_neutralState; - QState *const m_neutralFocusedState; - QState *const m_hoveredState; - QState *const m_hoveredFocusedState; - QState *const m_pressedState; - QSequentialAnimationGroup - *const m_haloAnimation; - qreal m_overlayOpacity; - qreal m_checkedOverlayProgress; - qreal m_haloOpacity; - qreal m_haloSize; - qreal m_haloScaleFactor; - bool m_wasChecked; + QState *const m_topLevelState; + QState *const m_configState; + QState *const m_checkableState; + QState *const m_checkedState; + QState *const m_uncheckedState; + QState *const m_neutralState; + QState *const m_neutralFocusedState; + QState *const m_hoveredState; + QState *const m_hoveredFocusedState; + QState *const m_pressedState; + QSequentialAnimationGroup *const m_haloAnimation; + qreal m_overlayOpacity; + qreal m_checkedOverlayProgress; + qreal m_haloOpacity; + qreal m_haloSize; + qreal m_haloScaleFactor; + bool m_wasChecked; }; inline qreal QtMaterialFlatButtonStateMachine::overlayOpacity() const @@ -100,4 +99,4 @@ inline qreal QtMaterialFlatButtonStateMachine::haloScaleFactor() const return m_haloScaleFactor; } -#endif // QTMATERIALFLATBUTTON_INTERNAL_H +#endif // QTMATERIALFLATBUTTON_INTERNAL_H diff --git a/components/qtmaterialflatbutton_p.h b/components/qtmaterialflatbutton_p.h index 1ab3d226f..5d6a339a8 100644 --- a/components/qtmaterialflatbutton_p.h +++ b/components/qtmaterialflatbutton_p.h @@ -1,9 +1,9 @@ #ifndef QTMATERIALFLATBUTTON_P_H #define QTMATERIALFLATBUTTON_P_H -#include -#include #include "lib/qtmaterialtheme.h" +#include +#include class QtMaterialFlatButton; class QtMaterialRippleOverlay; @@ -20,27 +20,27 @@ class QtMaterialFlatButtonPrivate void init(); - QtMaterialFlatButton *const q_ptr; - QtMaterialRippleOverlay *rippleOverlay; + QtMaterialFlatButton *const q_ptr; + QtMaterialRippleOverlay *rippleOverlay; QtMaterialFlatButtonStateMachine *stateMachine; - Material::Role role; - Material::RippleStyle rippleStyle; - Material::ButtonIconPlacement iconPlacement; - Material::OverlayStyle overlayStyle; - Qt::BGMode bgMode; - Qt::Alignment textAlignment; - QColor backgroundColor; - QColor foregroundColor; - QColor overlayColor; - QColor disabledColor; - QColor disabledBackgroundColor; - qreal fixedRippleRadius; - qreal cornerRadius; - qreal baseOpacity; - qreal fontSize; - bool useThemeColors; - bool useFixedRippleRadius; - bool haloVisible; + Material::Role role; + Material::RippleStyle rippleStyle; + Material::ButtonIconPlacement iconPlacement; + Material::OverlayStyle overlayStyle; + Qt::BGMode bgMode; + Qt::Alignment textAlignment; + QColor backgroundColor; + QColor foregroundColor; + QColor overlayColor; + QColor disabledColor; + QColor disabledBackgroundColor; + qreal fixedRippleRadius; + qreal cornerRadius; + qreal baseOpacity; + qreal fontSize; + bool useThemeColors; + bool useFixedRippleRadius; + bool haloVisible; }; -#endif // QTMATERIALFLATBUTTON_P_H +#endif // QTMATERIALFLATBUTTON_P_H diff --git a/components/qtmaterialiconbutton.cpp b/components/qtmaterialiconbutton.cpp index 525d6b206..ffac96d35 100644 --- a/components/qtmaterialiconbutton.cpp +++ b/components/qtmaterialiconbutton.cpp @@ -1,13 +1,13 @@ #include "qtmaterialiconbutton.h" +#include "lib/qtmaterialrippleoverlay.h" +#include "lib/qtmaterialstyle.h" #include "qtmaterialiconbutton_p.h" -#include #include -#include "lib/qtmaterialstyle.h" -#include "lib/qtmaterialrippleoverlay.h" +#include /*! - * \class QtMaterialIconButtonPrivate - * \internal + * @class QtMaterialIconButtonPrivate + * @internal */ QtMaterialIconButtonPrivate::QtMaterialIconButtonPrivate(QtMaterialIconButton *q) @@ -15,15 +15,13 @@ QtMaterialIconButtonPrivate::QtMaterialIconButtonPrivate(QtMaterialIconButton *q { } -QtMaterialIconButtonPrivate::~QtMaterialIconButtonPrivate() -{ -} +QtMaterialIconButtonPrivate::~QtMaterialIconButtonPrivate() {} void QtMaterialIconButtonPrivate::init() { Q_Q(QtMaterialIconButton); - rippleOverlay = new QtMaterialRippleOverlay(q->parentWidget()); + rippleOverlay = new QtMaterialRippleOverlay(q->parentWidget()); useThemeColors = true; rippleOverlay->installEventFilter(q); @@ -40,30 +38,28 @@ void QtMaterialIconButtonPrivate::updateRipple() Q_Q(QtMaterialIconButton); QRect r(q->rect()); - r.setSize(QSize(q->width()*2, q->height()*2)); + r.setSize(QSize(q->width() * 2, q->height() * 2)); r.moveCenter(q->geometry().center()); rippleOverlay->setGeometry(r); } /*! - * \class QtMaterialIconButton + * @class QtMaterialIconButton */ QtMaterialIconButton::QtMaterialIconButton(const QIcon &icon, QWidget *parent) - : QAbstractButton(parent), - d_ptr(new QtMaterialIconButtonPrivate(this)) + : QAbstractButton(parent) + , d_ptr(new QtMaterialIconButtonPrivate(this)) { d_func()->init(); setIcon(icon); } -QtMaterialIconButton::~QtMaterialIconButton() -{ -} +QtMaterialIconButton::~QtMaterialIconButton() {} /*! - * \reimp + * @reimp */ QSize QtMaterialIconButton::sizeHint() const { @@ -130,45 +126,43 @@ QColor QtMaterialIconButton::disabledColor() const } QtMaterialIconButton::QtMaterialIconButton(QtMaterialIconButtonPrivate &d, QWidget *parent) - : QAbstractButton(parent), - d_ptr(&d) + : QAbstractButton(parent) + , d_ptr(&d) { d_func()->init(); } /*! - * \reimp + * @reimp */ bool QtMaterialIconButton::event(QEvent *event) { Q_D(QtMaterialIconButton); - switch (event->type()) - { - case QEvent::Move: - case QEvent::Resize: - d->updateRipple(); - break; - case QEvent::ParentChange: { - QWidget *widget; - if ((widget = parentWidget())) { - d->rippleOverlay->setParent(widget); + switch (event->type()) { + case QEvent::Move: + case QEvent::Resize: + d->updateRipple(); + break; + case QEvent::ParentChange: { + QWidget *widget; + if ((widget = parentWidget())) { + d->rippleOverlay->setParent(widget); + } + break; } - break; - } - default: - break; + default: + break; } return QAbstractButton::event(event); } /*! - * \reimp + * @reimp */ bool QtMaterialIconButton::eventFilter(QObject *obj, QEvent *event) { - if (QEvent::Resize == event->type()) - { + if (QEvent::Resize == event->type()) { Q_D(QtMaterialIconButton); d->updateRipple(); @@ -177,22 +171,20 @@ bool QtMaterialIconButton::eventFilter(QObject *obj, QEvent *event) } /*! - * \reimp + * @reimp */ void QtMaterialIconButton::mousePressEvent(QMouseEvent *event) { Q_D(QtMaterialIconButton); - d->rippleOverlay->addRipple(QPoint(d->rippleOverlay->width(), - d->rippleOverlay->height())/2, - iconSize().width()); + d->rippleOverlay->addRipple(QPoint(d->rippleOverlay->width(), d->rippleOverlay->height()) / 2, iconSize().width()); emit clicked(); QAbstractButton::mousePressEvent(event); } /*! - * \reimp + * @reimp */ void QtMaterialIconButton::paintEvent(QPaintEvent *event) { @@ -208,5 +200,5 @@ void QtMaterialIconButton::paintEvent(QPaintEvent *event) QRect r(rect()); const qreal w = pixmap.width(); const qreal h = pixmap.height(); - painter.drawPixmap(QRect((r.width()-w)/2, (r.height()-h)/2, w, h), pixmap); + painter.drawPixmap(QRect((r.width() - w) / 2, (r.height() - h) / 2, w, h), pixmap); } diff --git a/components/qtmaterialiconbutton_p.h b/components/qtmaterialiconbutton_p.h index a532abca6..4e1e34c88 100644 --- a/components/qtmaterialiconbutton_p.h +++ b/components/qtmaterialiconbutton_p.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALICONBUTTON_P_H #define QTMATERIALICONBUTTON_P_H +#include #include - class QtMaterialIconButton; class QtMaterialRippleOverlay; class QColor; @@ -19,11 +19,11 @@ class QtMaterialIconButtonPrivate void init(); void updateRipple(); - QtMaterialIconButton *const q_ptr; + QtMaterialIconButton *const q_ptr; QtMaterialRippleOverlay *rippleOverlay; - QColor color; - QColor disabledColor; - bool useThemeColors; + QColor color; + QColor disabledColor; + bool useThemeColors; }; -#endif // QTMATERIALICONBUTTON_P_H +#endif // QTMATERIALICONBUTTON_P_H diff --git a/components/qtmateriallist_p.h b/components/qtmateriallist_p.h index c92b2d641..5844730b9 100644 --- a/components/qtmateriallist_p.h +++ b/components/qtmateriallist_p.h @@ -1,4 +1,4 @@ #ifndef QTMATERIALLIST_P_H #define QTMATERIALLIST_P_H -#endif // QTMATERIALLIST_P_H +#endif // QTMATERIALLIST_P_H diff --git a/components/qtmaterialmenu.cpp b/components/qtmaterialmenu.cpp index 5808a99e0..407ccf019 100644 --- a/components/qtmaterialmenu.cpp +++ b/components/qtmaterialmenu.cpp @@ -1,5 +1,4 @@ #include "qtmaterialmenu.h" -#include "qtmaterialmenu_p.h" QtMaterialMenu::QtMaterialMenu(QWidget *parent) : QWidget(parent) diff --git a/components/qtmaterialmenu_internal.cpp b/components/qtmaterialmenu_internal.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/components/qtmaterialmenu_internal.h b/components/qtmaterialmenu_internal.h deleted file mode 100644 index fb792356d..000000000 --- a/components/qtmaterialmenu_internal.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef QTMATERIALMENU_INTERNAL_H -#define QTMATERIALMENU_INTERNAL_H - -#endif // QTMATERIALMENU_INTERNAL_H diff --git a/components/qtmaterialmenu_p.h b/components/qtmaterialmenu_p.h deleted file mode 100644 index 1328bdca1..000000000 --- a/components/qtmaterialmenu_p.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef QTMATERIALMENU_P_H -#define QTMATERIALMENU_P_H - -#endif // QTMATERIALMENU_P_H diff --git a/components/qtmaterialpaper_p.h b/components/qtmaterialpaper_p.h index 65972a653..be77dbfa6 100644 --- a/components/qtmaterialpaper_p.h +++ b/components/qtmaterialpaper_p.h @@ -1,4 +1,4 @@ #ifndef QTMATERIALPAPER_P_H #define QTMATERIALPAPER_P_H -#endif // QTMATERIALPAPER_P_H +#endif // QTMATERIALPAPER_P_H diff --git a/components/qtmaterialprogress.cpp b/components/qtmaterialprogress.cpp index 03b15b2f0..b2c477077 100644 --- a/components/qtmaterialprogress.cpp +++ b/components/qtmaterialprogress.cpp @@ -1,14 +1,14 @@ #include "qtmaterialprogress.h" +#include "lib/qtmaterialstyle.h" +#include "qtmaterialprogress_internal.h" #include "qtmaterialprogress_p.h" -#include #include #include -#include "qtmaterialprogress_internal.h" -#include "lib/qtmaterialstyle.h" +#include /*! - * \class QtMaterialProgressPrivate - * \internal + * @class QtMaterialProgressPrivate + * @internal */ QtMaterialProgressPrivate::QtMaterialProgressPrivate(QtMaterialProgress *q) @@ -16,16 +16,14 @@ QtMaterialProgressPrivate::QtMaterialProgressPrivate(QtMaterialProgress *q) { } -QtMaterialProgressPrivate::~QtMaterialProgressPrivate() -{ -} +QtMaterialProgressPrivate::~QtMaterialProgressPrivate() {} void QtMaterialProgressPrivate::init() { Q_Q(QtMaterialProgress); - delegate = new QtMaterialProgressDelegate(q); - progressType = Material::IndeterminateProgress; + delegate = new QtMaterialProgressDelegate(q); + progressType = Material::IndeterminateProgress; useThemeColors = true; QPropertyAnimation *animation; @@ -43,19 +41,17 @@ void QtMaterialProgressPrivate::init() } /*! - * \class QtMaterialProgress + * @class QtMaterialProgress */ QtMaterialProgress::QtMaterialProgress(QWidget *parent) - : QProgressBar(parent), - d_ptr(new QtMaterialProgressPrivate(this)) + : QProgressBar(parent) + , d_ptr(new QtMaterialProgressPrivate(this)) { d_func()->init(); } -QtMaterialProgress::~QtMaterialProgress() -{ -} +QtMaterialProgress::~QtMaterialProgress() {} void QtMaterialProgress::setProgressType(Material::ProgressType type) { @@ -134,7 +130,7 @@ QColor QtMaterialProgress::backgroundColor() const } /*! - * \reimp + * @reimp */ void QtMaterialProgress::paintEvent(QPaintEvent *event) { @@ -147,26 +143,24 @@ void QtMaterialProgress::paintEvent(QPaintEvent *event) QBrush brush; brush.setStyle(Qt::SolidPattern); - brush.setColor(isEnabled() ? backgroundColor() - : QtMaterialStyle::instance().themeColor("disabled")); + brush.setColor(isEnabled() ? backgroundColor() : QtMaterialStyle::instance().themeColor("disabled")); painter.setBrush(brush); painter.setPen(Qt::NoPen); QPainterPath path; - path.addRoundedRect(0, height()/2-3, width(), 6, 3, 3); + path.addRoundedRect(0, height() / 2.0 - 3, width(), 6, 3, 3); painter.setClipPath(path); painter.drawRect(0, 0, width(), height()); - if (isEnabled()) - { + if (isEnabled()) { brush.setColor(progressColor()); painter.setBrush(brush); if (Material::IndeterminateProgress == d->progressType) { - painter.drawRect(d->delegate->offset()*width()*2-width(), 0, width(), height()); + painter.drawRect(d->delegate->offset() * width() * 2 - width(), 0, width(), height()); } else { - qreal p = static_cast(width())*(value()-minimum())/(maximum()-minimum()); + qreal p = static_cast(width()) * (value() - minimum()) / (maximum() - minimum()); painter.drawRect(0, 0, p, height()); } } diff --git a/components/qtmaterialprogress_internal.cpp b/components/qtmaterialprogress_internal.cpp index 0544baeba..db22e2862 100644 --- a/components/qtmaterialprogress_internal.cpp +++ b/components/qtmaterialprogress_internal.cpp @@ -1,8 +1,8 @@ #include "qtmaterialprogress_internal.h" /*! - * \class QtMaterialProgressDelegate - * \internal + * @class QtMaterialProgressDelegate + * @internal */ QtMaterialProgressDelegate::QtMaterialProgressDelegate(QtMaterialProgress *parent) diff --git a/components/qtmaterialprogress_internal.h b/components/qtmaterialprogress_internal.h index 811e3d6de..31401eeea 100644 --- a/components/qtmaterialprogress_internal.h +++ b/components/qtmaterialprogress_internal.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALPROGRESS_INTERNAL_H #define QTMATERIALPROGRESS_INTERNAL_H -#include #include "qtmaterialprogress.h" +#include class QtMaterialProgressDelegate : public QObject { @@ -21,7 +21,7 @@ class QtMaterialProgressDelegate : public QObject Q_DISABLE_COPY(QtMaterialProgressDelegate) QtMaterialProgress *const m_progress; - qreal m_offset; + qreal m_offset; }; inline void QtMaterialProgressDelegate::setOffset(qreal offset) @@ -35,4 +35,4 @@ inline qreal QtMaterialProgressDelegate::offset() const return m_offset; } -#endif // QTMATERIALPROGRESS_INTERNAL_H +#endif // QTMATERIALPROGRESS_INTERNAL_H diff --git a/components/qtmaterialprogress_p.h b/components/qtmaterialprogress_p.h index b55fb021c..33192c42a 100644 --- a/components/qtmaterialprogress_p.h +++ b/components/qtmaterialprogress_p.h @@ -1,9 +1,9 @@ #ifndef QTMATERIALPROGRESS_P_H #define QTMATERIALPROGRESS_P_H -#include -#include #include "lib/qtmaterialtheme.h" +#include +#include class QtMaterialProgress; class QtMaterialProgressDelegate; @@ -19,12 +19,12 @@ class QtMaterialProgressPrivate void init(); - QtMaterialProgress *const q_ptr; + QtMaterialProgress *const q_ptr; QtMaterialProgressDelegate *delegate; - Material::ProgressType progressType; - QColor progressColor; - QColor backgroundColor; - bool useThemeColors; + Material::ProgressType progressType; + QColor progressColor; + QColor backgroundColor; + bool useThemeColors; }; -#endif // QTMATERIALPROGRESS_P_H +#endif // QTMATERIALPROGRESS_P_H diff --git a/components/qtmaterialradiobutton.cpp b/components/qtmaterialradiobutton.cpp index 86427c787..d3ba492d4 100644 --- a/components/qtmaterialradiobutton.cpp +++ b/components/qtmaterialradiobutton.cpp @@ -1,27 +1,29 @@ #include "qtmaterialradiobutton.h" +#include "materiallib/qtmaterialcheckable_internal.h" #include "qtmaterialradiobutton_p.h" -#include -#include -#include #include -#include "lib/qtmaterialcheckable_internal.h" +#include +#include +#include /*! * \class QtMaterialRadioButtonPrivate - * \internal + * @parma state private class + * @internal + * */ QtMaterialRadioButtonPrivate::QtMaterialRadioButtonPrivate(QtMaterialRadioButton *q) : QtMaterialCheckablePrivate(q) + , q_ptr(q) { } -QtMaterialRadioButtonPrivate::~QtMaterialRadioButtonPrivate() -{ -} +QtMaterialRadioButtonPrivate::~QtMaterialRadioButtonPrivate() {} void QtMaterialRadioButtonPrivate::init() { + // get the public button Q_Q(QtMaterialRadioButton); q->setAutoExclusive(true); @@ -84,9 +86,7 @@ QtMaterialRadioButton::QtMaterialRadioButton(QWidget *parent) d_func()->init(); } -QtMaterialRadioButton::~QtMaterialRadioButton() -{ -} +QtMaterialRadioButton::~QtMaterialRadioButton() {} void QtMaterialRadioButton::setupProperties() { diff --git a/components/qtmaterialradiobutton_p.h b/components/qtmaterialradiobutton_p.h index 6bb954aa1..dd117ec3a 100644 --- a/components/qtmaterialradiobutton_p.h +++ b/components/qtmaterialradiobutton_p.h @@ -1,7 +1,7 @@ #ifndef QTMATERIALRADIOBUTTON_P_H #define QTMATERIALRADIOBUTTON_P_H -#include "lib/qtmaterialcheckable_p.h" +#include "materiallib/qtmaterialcheckable_p.h" class QtMaterialRadioButton; @@ -13,8 +13,8 @@ class QtMaterialRadioButtonPrivate : public QtMaterialCheckablePrivate public: QtMaterialRadioButtonPrivate(QtMaterialRadioButton *q); ~QtMaterialRadioButtonPrivate(); - + QtMaterialRadioButton *const q_ptr; void init(); }; -#endif // QTMATERIALRADIOBUTTON_P_H +#endif // QTMATERIALRADIOBUTTON_P_H diff --git a/components/qtmaterialraisedbutton.cpp b/components/qtmaterialraisedbutton.cpp index 1607c7072..23d1495dd 100644 --- a/components/qtmaterialraisedbutton.cpp +++ b/components/qtmaterialraisedbutton.cpp @@ -1,41 +1,40 @@ #include "qtmaterialraisedbutton.h" #include "qtmaterialraisedbutton_p.h" +#include +#include #include #include -#include -#include /*! - * \class QtMaterialRaisedButtonPrivate - * \internal + * @class QtMaterialRaisedButtonPrivate + * @internal */ /*! - * \internal + * @internal */ QtMaterialRaisedButtonPrivate::QtMaterialRaisedButtonPrivate(QtMaterialRaisedButton *q) : QtMaterialFlatButtonPrivate(q) + , q_ptr(q) { } /*! - * \internal + * @internal */ -QtMaterialRaisedButtonPrivate::~QtMaterialRaisedButtonPrivate() -{ -} +QtMaterialRaisedButtonPrivate::~QtMaterialRaisedButtonPrivate() {} /*! - * \internal + * @internal */ void QtMaterialRaisedButtonPrivate::init() { Q_Q(QtMaterialRaisedButton); shadowStateMachine = new QStateMachine(q); - normalState = new QState; - pressedState = new QState; - effect = new QGraphicsDropShadowEffect; + normalState = new QState; + pressedState = new QState; + effect = new QGraphicsDropShadowEffect; effect->setBlurRadius(7); effect->setOffset(QPointF(0, 2)); @@ -84,7 +83,7 @@ void QtMaterialRaisedButtonPrivate::init() } /*! - * \class QtMaterialRaisedButton + * @class QtMaterialRaisedButton */ QtMaterialRaisedButton::QtMaterialRaisedButton(QWidget *parent) @@ -101,9 +100,7 @@ QtMaterialRaisedButton::QtMaterialRaisedButton(const QString &text, QWidget *par setText(text); } -QtMaterialRaisedButton::~QtMaterialRaisedButton() -{ -} +QtMaterialRaisedButton::~QtMaterialRaisedButton() {} QtMaterialRaisedButton::QtMaterialRaisedButton(QtMaterialRaisedButtonPrivate &d, QWidget *parent) : QtMaterialFlatButton(d, parent) diff --git a/components/qtmaterialraisedbutton_p.h b/components/qtmaterialraisedbutton_p.h index 12df43c82..319e83aed 100644 --- a/components/qtmaterialraisedbutton_p.h +++ b/components/qtmaterialraisedbutton_p.h @@ -18,11 +18,12 @@ class QtMaterialRaisedButtonPrivate : public QtMaterialFlatButtonPrivate ~QtMaterialRaisedButtonPrivate(); void init(); - - QStateMachine *shadowStateMachine; - QState *normalState; - QState *pressedState; + + QtMaterialRaisedButton *const q_ptr; + QStateMachine *shadowStateMachine; + QState *normalState; + QState *pressedState; QGraphicsDropShadowEffect *effect; }; -#endif // QTMATERIALRAISEDBUTTON_P_H +#endif // QTMATERIALRAISEDBUTTON_P_H diff --git a/components/qtmaterialscrollbar_internal.h b/components/qtmaterialscrollbar_internal.h index 7b1cc92ac..020ded795 100644 --- a/components/qtmaterialscrollbar_internal.h +++ b/components/qtmaterialscrollbar_internal.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALSCROLLBAR_INTERNAL_H #define QTMATERIALSCROLLBAR_INTERNAL_H -#include #include "qtmaterialscrollbar.h" +#include class QtMaterialScrollBarStateMachine : public QStateMachine { @@ -21,9 +21,9 @@ class QtMaterialScrollBarStateMachine : public QStateMachine Q_DISABLE_COPY(QtMaterialScrollBarStateMachine) QtMaterialScrollBar *const m_scrollBar; - QState *const m_focusState; - QState *const m_blurState; - qreal m_opacity; + QState *const m_focusState; + QState *const m_blurState; + qreal m_opacity; }; inline void QtMaterialScrollBarStateMachine::setOpacity(qreal opacity) @@ -37,4 +37,4 @@ inline qreal QtMaterialScrollBarStateMachine::opacity() const return m_opacity; } -#endif // QTMATERIALSCROLLBAR_INTERNAL_H +#endif // QTMATERIALSCROLLBAR_INTERNAL_H diff --git a/components/qtmaterialscrollbar_p.h b/components/qtmaterialscrollbar_p.h index 1d22cc06b..3eeaf0930 100644 --- a/components/qtmaterialscrollbar_p.h +++ b/components/qtmaterialscrollbar_p.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALSCROLLBAR_P_H #define QTMATERIALSCROLLBAR_P_H -#include #include +#include class QtMaterialScrollBar; class QtMaterialScrollBarStateMachine; @@ -18,13 +18,13 @@ class QtMaterialScrollBarPrivate void init(); - QtMaterialScrollBar *const q_ptr; + QtMaterialScrollBar *const q_ptr; QtMaterialScrollBarStateMachine *stateMachine; - QColor backgroundColor; - QColor sliderColor; - QColor canvasColor; - bool hideOnMouseOut; - bool useThemeColors; + QColor backgroundColor; + QColor sliderColor; + QColor canvasColor; + bool hideOnMouseOut; + bool useThemeColors; }; -#endif // QTMATERIALSCROLLBAR_P_H +#endif // QTMATERIALSCROLLBAR_P_H diff --git a/components/qtmaterialslider.cpp b/components/qtmaterialslider.cpp index a0d17dc12..8b1b1aaa8 100644 --- a/components/qtmaterialslider.cpp +++ b/components/qtmaterialslider.cpp @@ -1,10 +1,10 @@ #include "qtmaterialslider.h" +#include "lib/qtmaterialstatetransitionevent.h" +#include "lib/qtmaterialstyle.h" +#include "qtmaterialslider_internal.h" #include "qtmaterialslider_p.h" -#include #include -#include "qtmaterialslider_internal.h" -#include "lib/qtmaterialstyle.h" -#include "lib/qtmaterialstatetransitionevent.h" +#include /*! * \class QtMaterialSliderPrivate @@ -16,33 +16,30 @@ QtMaterialSliderPrivate::QtMaterialSliderPrivate(QtMaterialSlider *q) { } -QtMaterialSliderPrivate::~QtMaterialSliderPrivate() -{ -} +QtMaterialSliderPrivate::~QtMaterialSliderPrivate() {} void QtMaterialSliderPrivate::init() { Q_Q(QtMaterialSlider); - thumb = new QtMaterialSliderThumb(q); - track = new QtMaterialSliderTrack(thumb, q); - stateMachine = new QtMaterialSliderStateMachine(q, thumb, track); - stepTo = 0; - oldValue = q->value(); - trackWidth = 2; - hoverTrack = false; - hoverThumb = false; - hover = false; - step = false; - pageStepMode = true; + thumb = new QtMaterialSliderThumb(q); + track = new QtMaterialSliderTrack(thumb, q); + stateMachine = new QtMaterialSliderStateMachine(q, thumb, track); + stepTo = 0; + oldValue = q->value(); + trackWidth = 2; + hoverTrack = false; + hoverThumb = false; + hover = false; + step = false; + pageStepMode = true; useThemeColors = true; q->setMouseTracking(true); q->setFocusPolicy(Qt::StrongFocus); q->setPageStep(1); - QSizePolicy sp(QSizePolicy::Expanding, - QSizePolicy::Fixed); + QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed); if (q->orientation() == Qt::Vertical) { sp.transpose(); @@ -59,24 +56,25 @@ QRectF QtMaterialSliderPrivate::trackBoundingRect() const { Q_Q(const QtMaterialSlider); - qreal hw = static_cast(trackWidth)/2; + qreal hw = static_cast(trackWidth) / 2; - return Qt::Horizontal == q->orientation() - ? QRectF(QT_MATERIAL_SLIDER_MARGIN, q->height()/2 - hw, - q->width() - QT_MATERIAL_SLIDER_MARGIN*2, hw*2) - : QRectF(q->width()/2 - hw, QT_MATERIAL_SLIDER_MARGIN, hw*2, - q->height() - QT_MATERIAL_SLIDER_MARGIN*2); + return Qt::Horizontal == q->orientation() ? + QRectF(QT_MATERIAL_SLIDER_MARGIN, q->height() / 2.0 - hw, q->width() - QT_MATERIAL_SLIDER_MARGIN * 2, hw * 2) : + QRectF(q->width() / 2.0 - hw, QT_MATERIAL_SLIDER_MARGIN, hw * 2, q->height() - QT_MATERIAL_SLIDER_MARGIN * 2); } QRectF QtMaterialSliderPrivate::thumbBoundingRect() const { Q_Q(const QtMaterialSlider); - return Qt::Horizontal == q->orientation() - ? QRectF(thumb->offset(), q->height()/2 - QT_MATERIAL_SLIDER_MARGIN, - QT_MATERIAL_SLIDER_MARGIN*2, QT_MATERIAL_SLIDER_MARGIN*2) - : QRectF(q->width()/2 - QT_MATERIAL_SLIDER_MARGIN, thumb->offset(), - QT_MATERIAL_SLIDER_MARGIN*2, QT_MATERIAL_SLIDER_MARGIN*2); + return Qt::Horizontal == q->orientation() ? QRectF(thumb->offset(), + q->height() / 2.0 - QT_MATERIAL_SLIDER_MARGIN, + QT_MATERIAL_SLIDER_MARGIN * 2, + QT_MATERIAL_SLIDER_MARGIN * 2) : + QRectF(q->width() / 2.0 - QT_MATERIAL_SLIDER_MARGIN, + thumb->offset(), + QT_MATERIAL_SLIDER_MARGIN * 2, + QT_MATERIAL_SLIDER_MARGIN * 2); } int QtMaterialSliderPrivate::valueFromPosition(const QPoint &pos) const @@ -85,16 +83,11 @@ int QtMaterialSliderPrivate::valueFromPosition(const QPoint &pos) const const int position = Qt::Horizontal == q->orientation() ? pos.x() : pos.y(); - const int span = Qt::Horizontal == q->orientation() - ? q->width() - QT_MATERIAL_SLIDER_MARGIN*2 - : q->height() - QT_MATERIAL_SLIDER_MARGIN*2; + const int span = Qt::Horizontal == q->orientation() ? q->width() - QT_MATERIAL_SLIDER_MARGIN * 2 : + q->height() - QT_MATERIAL_SLIDER_MARGIN * 2; return QtMaterialStyle::sliderValueFromPosition( - q->minimum(), - q->maximum(), - position - QT_MATERIAL_SLIDER_MARGIN, - span, - q->invertedAppearance()); + q->minimum(), q->maximum(), position - QT_MATERIAL_SLIDER_MARGIN, span, q->invertedAppearance()); } void QtMaterialSliderPrivate::setHovered(bool status) @@ -123,15 +116,13 @@ void QtMaterialSliderPrivate::setHovered(bool status) */ QtMaterialSlider::QtMaterialSlider(QWidget *parent) - : QAbstractSlider(parent), - d_ptr(new QtMaterialSliderPrivate(this)) + : QAbstractSlider(parent) + , d_ptr(new QtMaterialSliderPrivate(this)) { d_func()->init(); } -QtMaterialSlider::~QtMaterialSlider() -{ -} +QtMaterialSlider::~QtMaterialSlider() {} void QtMaterialSlider::setUseThemeColors(bool value) { @@ -237,9 +228,7 @@ bool QtMaterialSlider::pageStepMode() const */ QSize QtMaterialSlider::minimumSizeHint() const { - return Qt::Horizontal == orientation() - ? QSize(130, 34) - : QSize(34, 130); + return Qt::Horizontal == orientation() ? QSize(130, 34) : QSize(34, 130); } void QtMaterialSlider::setInvertedAppearance(bool value) @@ -256,16 +245,13 @@ void QtMaterialSlider::sliderChange(SliderChange change) { Q_D(QtMaterialSlider); - if (SliderOrientationChange == change) - { + if (SliderOrientationChange == change) { QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed); if (orientation() == Qt::Vertical) { sp.transpose(); } setSizePolicy(sp); - } - else if (SliderValueChange == change) - { + } else if (SliderValueChange == change) { if (minimum() == value()) { triggerAction(SliderToMinimum); d->stateMachine->postEvent(new QtMaterialStateTransitionEvent(SliderChangedToMinimum)); @@ -290,12 +276,9 @@ void QtMaterialSlider::mouseMoveEvent(QMouseEvent *event) { Q_D(QtMaterialSlider); - if (isSliderDown()) - { + if (isSliderDown()) { setSliderPosition(d->valueFromPosition(event->pos())); - } - else - { + } else { QRectF track(d->trackBoundingRect().adjusted(-2, -2, 2, 2)); if (track.contains(event->pos()) != d->hoverTrack) { @@ -344,9 +327,7 @@ void QtMaterialSlider::mousePressEvent(QMouseEvent *event) d->step = true; d->stepTo = d->valueFromPosition(pos); - SliderAction action = d->stepTo > sliderPosition() - ? SliderPageStepAdd - : SliderPageStepSub; + SliderAction action = d->stepTo > sliderPosition() ? SliderPageStepAdd : SliderPageStepSub; triggerAction(action); setRepeatAction(action, 400, 8); @@ -398,9 +379,7 @@ void QtMaterialSlider::updateThumbOffset() minimum(), maximum(), sliderPosition(), - Qt::Horizontal == orientation() - ? width() - QT_MATERIAL_SLIDER_MARGIN*2 - : height() - QT_MATERIAL_SLIDER_MARGIN*2, + Qt::Horizontal == orientation() ? width() - QT_MATERIAL_SLIDER_MARGIN * 2 : height() - QT_MATERIAL_SLIDER_MARGIN * 2, invertedAppearance()); d->thumb->setOffset(offset); diff --git a/components/qtmaterialslider_internal.cpp b/components/qtmaterialslider_internal.cpp index fd2d50bf8..de21627e9 100644 --- a/components/qtmaterialslider_internal.cpp +++ b/components/qtmaterialslider_internal.cpp @@ -1,37 +1,36 @@ #include "qtmaterialslider_internal.h" -#include +#include "lib/qtmaterialstatetransition.h" +#include "lib/qtmaterialstyle.h" +#include "qtmaterialslider.h" #include -#include #include -#include #include -#include "qtmaterialslider.h" -#include "lib/qtmaterialstyle.h" -#include "lib/qtmaterialstatetransition.h" +#include +#include +#include /*! * \class QtMaterialSliderStateMachine * \internal */ -QtMaterialSliderStateMachine::QtMaterialSliderStateMachine( - QtMaterialSlider *slider, - QtMaterialSliderThumb *thumb, - QtMaterialSliderTrack *track) - : QStateMachine(slider), - m_slider(slider), - m_thumb(thumb), - m_track(track), - m_topState(new QState(QState::ParallelStates)), - m_fstState(new QState(m_topState)), - m_sndState(new QState(m_topState)), - m_inactiveState(new QState(m_fstState)), - m_focusState(new QState(m_fstState)), - m_slidingState(new QState(m_fstState)), - m_pulseOutState(new QState(m_focusState)), - m_pulseInState(new QState(m_focusState)), - m_minState(new QState(m_sndState)), - m_normalState(new QState(m_sndState)) +QtMaterialSliderStateMachine::QtMaterialSliderStateMachine(QtMaterialSlider *slider, + QtMaterialSliderThumb *thumb, + QtMaterialSliderTrack *track) + : QStateMachine(slider) + , m_slider(slider) + , m_thumb(thumb) + , m_track(track) + , m_topState(new QState(QState::ParallelStates)) + , m_fstState(new QState(m_topState)) + , m_sndState(new QState(m_topState)) + , m_inactiveState(new QState(m_fstState)) + , m_focusState(new QState(m_fstState)) + , m_slidingState(new QState(m_fstState)) + , m_pulseOutState(new QState(m_focusState)) + , m_pulseInState(new QState(m_focusState)) + , m_minState(new QState(m_sndState)) + , m_normalState(new QState(m_sndState)) { addState(m_topState); setInitialState(m_topState); @@ -197,9 +196,7 @@ QtMaterialSliderStateMachine::QtMaterialSliderStateMachine( setupProperties(); } -QtMaterialSliderStateMachine::~QtMaterialSliderStateMachine() -{ -} +QtMaterialSliderStateMachine::~QtMaterialSliderStateMachine() {} void QtMaterialSliderStateMachine::setupProperties() { @@ -234,21 +231,19 @@ void QtMaterialSliderStateMachine::setupProperties() */ QtMaterialSliderThumb::QtMaterialSliderThumb(QtMaterialSlider *slider) - : QtMaterialOverlayWidget(slider->parentWidget()), - m_slider(slider), - m_diameter(11), - m_borderWidth(2), - m_haloSize(0), - m_offset(0) + : QtMaterialOverlayWidget(slider->parentWidget()) + , m_slider(slider) + , m_diameter(11) + , m_borderWidth(2) + , m_haloSize(0) + , m_offset(0) { slider->installEventFilter(this); setAttribute(Qt::WA_TransparentForMouseEvents, true); } -QtMaterialSliderThumb::~QtMaterialSliderThumb() -{ -} +QtMaterialSliderThumb::~QtMaterialSliderThumb() {} bool QtMaterialSliderThumb::eventFilter(QObject *obj, QEvent *event) { @@ -274,12 +269,11 @@ void QtMaterialSliderThumb::paintEvent(QPaintEvent *event) painter.setBrush(brush); painter.setPen(Qt::NoPen); - QPointF disp = Qt::Horizontal == m_slider->orientation() - ? QPointF(QT_MATERIAL_SLIDER_MARGIN + m_offset, m_slider->height()/2) - : QPointF(m_slider->width()/2, QT_MATERIAL_SLIDER_MARGIN + m_offset); + QPointF disp = Qt::Horizontal == m_slider->orientation() ? + QPointF(QT_MATERIAL_SLIDER_MARGIN + m_offset, m_slider->height() / 2.0) : + QPointF(m_slider->width() / 2.0, QT_MATERIAL_SLIDER_MARGIN + m_offset); - QRectF halo((m_slider->pos() - QPointF(m_haloSize, m_haloSize)/2) + disp, - QSizeF(m_haloSize, m_haloSize)); + QRectF halo((m_slider->pos() - QPointF(m_haloSize, m_haloSize) / 2) + disp, QSizeF(m_haloSize, m_haloSize)); painter.setOpacity(0.15); painter.drawEllipse(halo); @@ -288,12 +282,8 @@ void QtMaterialSliderThumb::paintEvent(QPaintEvent *event) const bool isMin = m_slider->value() == m_slider->minimum(); - brush.setColor(m_slider->isEnabled() - ? m_fillColor - : m_slider->disabledColor()); - painter.setBrush(!m_slider->isEnabled() && isMin - ? Qt::NoBrush - : brush); + brush.setColor(m_slider->isEnabled() ? m_fillColor : m_slider->disabledColor()); + painter.setBrush(!m_slider->isEnabled() && isMin ? Qt::NoBrush : brush); if (m_slider->isEnabled() || isMin) { QPen pen; @@ -304,11 +294,16 @@ void QtMaterialSliderThumb::paintEvent(QPaintEvent *event) painter.setPen(Qt::NoPen); } - QRectF geometry = Qt::Horizontal == m_slider->orientation() - ? QRectF(m_offset, m_slider->height()/2 - QT_MATERIAL_SLIDER_MARGIN, - QT_MATERIAL_SLIDER_MARGIN*2, QT_MATERIAL_SLIDER_MARGIN*2).translated(m_slider->pos()) - : QRectF(m_slider->width()/2 - QT_MATERIAL_SLIDER_MARGIN, m_offset, - QT_MATERIAL_SLIDER_MARGIN*2, QT_MATERIAL_SLIDER_MARGIN*2).translated(m_slider->pos()); + QRectF geometry = Qt::Horizontal == m_slider->orientation() ? QRectF(m_offset, + m_slider->height() / 2.0 - QT_MATERIAL_SLIDER_MARGIN, + QT_MATERIAL_SLIDER_MARGIN * 2, + QT_MATERIAL_SLIDER_MARGIN * 2) + .translated(m_slider->pos()) : + QRectF(m_slider->width() / 2.0 - QT_MATERIAL_SLIDER_MARGIN, + m_offset, + QT_MATERIAL_SLIDER_MARGIN * 2, + QT_MATERIAL_SLIDER_MARGIN * 2) + .translated(m_slider->pos()); qreal s = m_slider->isEnabled() ? m_diameter : 7; @@ -326,10 +321,10 @@ void QtMaterialSliderThumb::paintEvent(QPaintEvent *event) */ QtMaterialSliderTrack::QtMaterialSliderTrack(QtMaterialSliderThumb *thumb, QtMaterialSlider *slider) - : QtMaterialOverlayWidget(slider->parentWidget()), - m_slider(slider), - m_thumb(thumb), - m_trackWidth(2) + : QtMaterialOverlayWidget(slider->parentWidget()) + , m_slider(slider) + , m_thumb(thumb) + , m_trackWidth(2) { slider->installEventFilter(this); @@ -338,9 +333,7 @@ QtMaterialSliderTrack::QtMaterialSliderTrack(QtMaterialSliderThumb *thumb, QtMat connect(slider, SIGNAL(sliderMoved(int)), this, SLOT(update())); } -QtMaterialSliderTrack::~QtMaterialSliderTrack() -{ -} +QtMaterialSliderTrack::~QtMaterialSliderTrack() {} bool QtMaterialSliderTrack::eventFilter(QObject *obj, QEvent *event) { @@ -360,28 +353,24 @@ void QtMaterialSliderTrack::paintEvent(QPaintEvent *event) QBrush fg; fg.setStyle(Qt::SolidPattern); - fg.setColor(m_slider->isEnabled() ? m_slider->thumbColor() - : m_slider->disabledColor()); + fg.setColor(m_slider->isEnabled() ? m_slider->thumbColor() : m_slider->disabledColor()); QBrush bg; bg.setStyle(Qt::SolidPattern); - bg.setColor(m_slider->isEnabled() ? m_fillColor - : m_slider->disabledColor()); + bg.setColor(m_slider->isEnabled() ? m_fillColor : m_slider->disabledColor()); qreal offset = m_thumb->offset(); if (Qt::Horizontal == m_slider->orientation()) { painter.translate(m_slider->x() + QT_MATERIAL_SLIDER_MARGIN, - m_slider->y() + m_slider->height()/2 - - static_cast(m_trackWidth)/2); + m_slider->y() + m_slider->height() / 2.0 - static_cast(m_trackWidth) / 2.0); } else { - painter.translate(m_slider->x() + m_slider->width()/2 - - static_cast(m_trackWidth)/2, + painter.translate(m_slider->x() + m_slider->width() / 2.0 - static_cast(m_trackWidth) / 2.0, m_slider->y() + QT_MATERIAL_SLIDER_MARGIN); } - QRectF geometry = Qt::Horizontal == m_slider->orientation() - ? QRectF(0, 0, m_slider->width() - QT_MATERIAL_SLIDER_MARGIN*2, m_trackWidth) - : QRectF(0, 0, m_trackWidth, m_slider->height() - QT_MATERIAL_SLIDER_MARGIN*2); + QRectF geometry = Qt::Horizontal == m_slider->orientation() ? + QRectF(0, 0, m_slider->width() - QT_MATERIAL_SLIDER_MARGIN * 2, m_trackWidth) : + QRectF(0, 0, m_trackWidth, m_slider->height() - QT_MATERIAL_SLIDER_MARGIN * 2); QRectF bgRect; QRectF fgRect; diff --git a/components/qtmaterialslider_p.h b/components/qtmaterialslider_p.h index ff6b7ca2b..baaf745f3 100644 --- a/components/qtmaterialslider_p.h +++ b/components/qtmaterialslider_p.h @@ -1,9 +1,9 @@ #ifndef QTMATERIALSLIDER_P_H #define QTMATERIALSLIDER_P_H -#include #include #include +#include class QtMaterialSlider; class QtMaterialSliderThumb; @@ -28,22 +28,22 @@ class QtMaterialSliderPrivate void setHovered(bool status); - QtMaterialSlider *const q_ptr; - QtMaterialSliderThumb *thumb; - QtMaterialSliderTrack *track; + QtMaterialSlider *const q_ptr; + QtMaterialSliderThumb *thumb; + QtMaterialSliderTrack *track; QtMaterialSliderStateMachine *stateMachine; - QColor thumbColor; - QColor trackColor; - QColor disabledColor; - int stepTo; - int oldValue; - int trackWidth; - bool hoverTrack; - bool hoverThumb; - bool hover; - bool step; - bool pageStepMode; - bool useThemeColors; + QColor thumbColor; + QColor trackColor; + QColor disabledColor; + int stepTo; + int oldValue; + int trackWidth; + bool hoverTrack; + bool hoverThumb; + bool hover; + bool step; + bool pageStepMode; + bool useThemeColors; }; -#endif // QTMATERIALSLIDER_P_H +#endif // QTMATERIALSLIDER_P_H diff --git a/components/qtmaterialsnackbar.cpp b/components/qtmaterialsnackbar.cpp index 323ff20fe..e19492098 100644 --- a/components/qtmaterialsnackbar.cpp +++ b/components/qtmaterialsnackbar.cpp @@ -1,11 +1,11 @@ #include "qtmaterialsnackbar.h" -#include "qtmaterialsnackbar_p.h" -#include -#include -#include "qtmaterialsnackbar_internal.h" -#include "lib/qtmaterialstyle.h" #include "lib/qtmaterialstatetransition.h" +#include "lib/qtmaterialstyle.h" +#include "qtmaterialsnackbar_internal.h" +#include "qtmaterialsnackbar_p.h" #include +#include +#include /*! * \class QtMaterialSnackbarPrivate @@ -17,19 +17,17 @@ QtMaterialSnackbarPrivate::QtMaterialSnackbarPrivate(QtMaterialSnackbar *q) { } -QtMaterialSnackbarPrivate::~QtMaterialSnackbarPrivate() -{ -} +QtMaterialSnackbarPrivate::~QtMaterialSnackbarPrivate() {} void QtMaterialSnackbarPrivate::init() { Q_Q(QtMaterialSnackbar); - stateMachine = new QtMaterialSnackbarStateMachine(q); - bgOpacity = 0.9; - duration = 3000; - boxWidth = 300; - clickDismiss = false; + stateMachine = new QtMaterialSnackbarStateMachine(q); + bgOpacity = 0.9; + duration = 3000; + boxWidth = 300; + clickDismiss = false; useThemeColors = true; q->setAttribute(Qt::WA_TransparentForMouseEvents); @@ -47,15 +45,13 @@ void QtMaterialSnackbarPrivate::init() */ QtMaterialSnackbar::QtMaterialSnackbar(QWidget *parent) - : QtMaterialOverlayWidget(parent), - d_ptr(new QtMaterialSnackbarPrivate(this)) + : QtMaterialOverlayWidget(parent) + , d_ptr(new QtMaterialSnackbarPrivate(this)) { d_func()->init(); } -QtMaterialSnackbar::~QtMaterialSnackbar() -{ -} +QtMaterialSnackbar::~QtMaterialSnackbar() {} void QtMaterialSnackbar::setAutoHideDuration(int duration) { @@ -258,10 +254,9 @@ void QtMaterialSnackbar::paintEvent(QPaintEvent *event) painter.setPen(Qt::NoPen); r = br.united(r).adjusted(-10, -10, 10, 20); - const qreal s = 1-d->stateMachine->offset(); + const qreal s = 1 - d->stateMachine->offset(); - painter.translate((width()-(r.width()-20))/2, - height()+10-s*(r.height())); + painter.translate((width() - (r.width() - 20)) / 2.0, height() + 10 - s * (r.height())); br.moveCenter(r.center()); painter.drawRoundedRect(r.adjusted(0, 0, 0, 3), 3, 3); diff --git a/components/qtmaterialsnackbar_internal.cpp b/components/qtmaterialsnackbar_internal.cpp index 9e6167d76..600e9bb31 100644 --- a/components/qtmaterialsnackbar_internal.cpp +++ b/components/qtmaterialsnackbar_internal.cpp @@ -1,12 +1,12 @@ #include "qtmaterialsnackbar_internal.h" -#include -#include "qtmaterialsnackbar.h" #include "lib/qtmaterialstatetransition.h" +#include "qtmaterialsnackbar.h" #include +#include QtMaterialSnackbarStateMachine::QtMaterialSnackbarStateMachine(QtMaterialSnackbar *parent) - : QStateMachine(parent), - m_snackbar(parent) + : QStateMachine(parent) + , m_snackbar(parent) { m_timer.setSingleShot(true); @@ -42,10 +42,8 @@ QtMaterialSnackbarStateMachine::QtMaterialSnackbarStateMachine(QtMaterialSnackba transition->setTargetState(visibleState); finalState->addTransition(transition); - connect(visibleState, SIGNAL(propertiesAssigned()), - this, SLOT(snackbarShown())); - connect(finalState, SIGNAL(propertiesAssigned()), - m_snackbar, SLOT(dequeue())); + connect(visibleState, SIGNAL(propertiesAssigned()), this, SLOT(snackbarShown())); + connect(finalState, SIGNAL(propertiesAssigned()), m_snackbar, SLOT(dequeue())); QPropertyAnimation *animation; @@ -63,9 +61,7 @@ QtMaterialSnackbarStateMachine::QtMaterialSnackbarStateMachine(QtMaterialSnackba m_snackbar->installEventFilter(this); } -QtMaterialSnackbarStateMachine::~QtMaterialSnackbarStateMachine() -{ -} +QtMaterialSnackbarStateMachine::~QtMaterialSnackbarStateMachine() {} bool QtMaterialSnackbarStateMachine::eventFilter(QObject *watched, QEvent *event) { diff --git a/components/qtmaterialsnackbar_internal.h b/components/qtmaterialsnackbar_internal.h index 117a8e557..fd448a89a 100644 --- a/components/qtmaterialsnackbar_internal.h +++ b/components/qtmaterialsnackbar_internal.h @@ -32,8 +32,8 @@ protected slots: Q_DISABLE_COPY(QtMaterialSnackbarStateMachine) QtMaterialSnackbar *const m_snackbar; - QTimer m_timer; - qreal m_offset; + QTimer m_timer; + qreal m_offset; }; inline qreal QtMaterialSnackbarStateMachine::offset() const @@ -41,4 +41,4 @@ inline qreal QtMaterialSnackbarStateMachine::offset() const return m_offset; } -#endif // QTMATERIALSNACKBAR_INTERNAL_H +#endif // QTMATERIALSNACKBAR_INTERNAL_H diff --git a/components/qtmaterialsnackbar_p.h b/components/qtmaterialsnackbar_p.h index 39501fd25..ad5212a8b 100644 --- a/components/qtmaterialsnackbar_p.h +++ b/components/qtmaterialsnackbar_p.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALSNACKBAR_P_H #define QTMATERIALSNACKBAR_P_H -#include #include +#include class QtMaterialSnackbar; class QtMaterialSnackbarStateMachine; @@ -18,16 +18,16 @@ class QtMaterialSnackbarPrivate void init(); - QtMaterialSnackbar *const q_ptr; + QtMaterialSnackbar *const q_ptr; QtMaterialSnackbarStateMachine *stateMachine; - QColor backgroundColor; - QColor textColor; - qreal bgOpacity; - QList messages; - int duration; - int boxWidth; - bool clickDismiss; - bool useThemeColors; + QColor backgroundColor; + QColor textColor; + qreal bgOpacity; + QList messages; + int duration; + int boxWidth; + bool clickDismiss; + bool useThemeColors; }; -#endif // QTMATERIALSNACKBAR_P_H +#endif // QTMATERIALSNACKBAR_P_H diff --git a/components/qtmaterialtabs.cpp b/components/qtmaterialtabs.cpp index dbc55bdbd..3c531c4dd 100644 --- a/components/qtmaterialtabs.cpp +++ b/components/qtmaterialtabs.cpp @@ -1,8 +1,8 @@ #include "qtmaterialtabs.h" +#include "lib/qtmaterialstyle.h" +#include "qtmaterialtabs_internal.h" #include "qtmaterialtabs_p.h" #include -#include "qtmaterialtabs_internal.h" -#include "lib/qtmaterialstyle.h" /*! * \QtMaterialTabsPrivate @@ -14,19 +14,17 @@ QtMaterialTabsPrivate::QtMaterialTabsPrivate(QtMaterialTabs *q) { } -QtMaterialTabsPrivate::~QtMaterialTabsPrivate() -{ -} +QtMaterialTabsPrivate::~QtMaterialTabsPrivate() {} void QtMaterialTabsPrivate::QtMaterialTabsPrivate::init() { Q_Q(QtMaterialTabs); - inkBar = new QtMaterialTabsInkBar(q); - tabLayout = new QHBoxLayout; - rippleStyle = Material::CenteredRipple; - tab = -1; - showHalo = true; + inkBar = new QtMaterialTabsInkBar(q); + tabLayout = new QHBoxLayout; + rippleStyle = Material::CenteredRipple; + tab = -1; + showHalo = true; useThemeColors = true; q->setLayout(tabLayout); @@ -41,15 +39,13 @@ void QtMaterialTabsPrivate::QtMaterialTabsPrivate::init() */ QtMaterialTabs::QtMaterialTabs(QWidget *parent) - : QWidget(parent), - d_ptr(new QtMaterialTabsPrivate(this)) + : QWidget(parent) + , d_ptr(new QtMaterialTabsPrivate(this)) { d_func()->init(); } -QtMaterialTabs::~QtMaterialTabs() -{ -} +QtMaterialTabs::~QtMaterialTabs() {} void QtMaterialTabs::setUseThemeColors(bool value) { diff --git a/components/qtmaterialtabs_internal.cpp b/components/qtmaterialtabs_internal.cpp index e952c0254..ac8d7af45 100644 --- a/components/qtmaterialtabs_internal.cpp +++ b/components/qtmaterialtabs_internal.cpp @@ -1,22 +1,22 @@ #include "qtmaterialtabs_internal.h" +#include "qtmaterialtabs.h" +#include +#include #include #include #include #include -#include -#include "qtmaterialtabs.h" -#include /*! - * \class QtMaterialTabsInkBar - * \internal + * @class QtMaterialTabsInkBar + * @internal */ QtMaterialTabsInkBar::QtMaterialTabsInkBar(QtMaterialTabs *parent) - : QtMaterialOverlayWidget(parent), - m_tabs(parent), - m_animation(new QPropertyAnimation(parent)), - m_tween(0) + : QtMaterialOverlayWidget(parent) + , m_tabs(parent) + , m_animation(new QPropertyAnimation(parent)) + , m_tween(0) { Q_ASSERT(parent); @@ -31,25 +31,22 @@ QtMaterialTabsInkBar::QtMaterialTabsInkBar(QtMaterialTabs *parent) setAttribute(Qt::WA_NoSystemBackground); } -QtMaterialTabsInkBar::~QtMaterialTabsInkBar() -{ -} +QtMaterialTabsInkBar::~QtMaterialTabsInkBar() {} void QtMaterialTabsInkBar::refreshGeometry() { QLayoutItem *item = m_tabs->layout()->itemAt(m_tabs->currentIndex()); - if (item) - { + if (item) { const QRect r(item->geometry()); - const qreal s = 1-m_tween; + const qreal s = 1 - m_tween; if (QAbstractAnimation::Running != m_animation->state()) { - m_geometry = QRect(r.left(), r.bottom()-1, r.width(), 2); + m_geometry = QRect(r.left(), r.bottom() - 1, r.width(), 2); } else { - const qreal left = m_previousGeometry.left()*s + r.left()*m_tween; - const qreal width = m_previousGeometry.width()*s + r.width()*m_tween; - m_geometry = QRect(left, r.bottom()-1, width, 2); + const qreal left = m_previousGeometry.left() * s + r.left() * m_tween; + const qreal width = m_previousGeometry.width() * s + r.width() * m_tween; + m_geometry = QRect(left, r.bottom() - 1, width, 2); } m_tabs->update(); } @@ -69,16 +66,14 @@ void QtMaterialTabsInkBar::animate() bool QtMaterialTabsInkBar::eventFilter(QObject *obj, QEvent *event) { - switch (event->type()) - { - case QEvent::Move: - case QEvent::Resize: - { - refreshGeometry(); - break; - } - default: - break; + switch (event->type()) { + case QEvent::Move: + case QEvent::Resize: { + refreshGeometry(); + break; + } + default: + break; } return QtMaterialOverlayWidget::eventFilter(obj, event); } @@ -94,14 +89,14 @@ void QtMaterialTabsInkBar::paintEvent(QPaintEvent *event) } /*! - * \class QtMaterialTab - * \internal + * @class QtMaterialTab + * @internal */ QtMaterialTab::QtMaterialTab(QtMaterialTabs *parent) - : QtMaterialFlatButton(parent), - m_tabs(parent), - m_active(false) + : QtMaterialFlatButton(parent) + , m_tabs(parent) + , m_active(false) { Q_ASSERT(parent); @@ -119,16 +114,14 @@ QtMaterialTab::QtMaterialTab(QtMaterialTabs *parent) connect(this, SIGNAL(clicked(bool)), this, SLOT(activateTab())); } -QtMaterialTab::~QtMaterialTab() -{ -} +QtMaterialTab::~QtMaterialTab() {} QSize QtMaterialTab::sizeHint() const { if (icon().isNull()) { return QtMaterialFlatButton::sizeHint(); } else { - return QSize(40, iconSize().height()+46); + return QSize(40, iconSize().height() + 46); } } @@ -146,16 +139,15 @@ void QtMaterialTab::paintForeground(QPainter *painter) } QSize textSize(fontMetrics().size(Qt::TextSingleLine, text())); - QSize base(size()-textSize); + QSize base(size() - textSize); - QRect textGeometry(QPoint(base.width(), base.height())/2, textSize); + QRect textGeometry(QPoint(base.width(), base.height()) / 2, textSize); painter->drawText(textGeometry, Qt::AlignCenter, text()); - if (!icon().isNull()) - { + if (!icon().isNull()) { const QSize &size = iconSize(); - QRect iconRect(QPoint((width()-size.width())/2, 0), size); + QRect iconRect(QPoint((width() - size.width()) / 2, 0), size); QPixmap pixmap = icon().pixmap(iconSize()); QPainter icon(&pixmap); @@ -164,8 +156,7 @@ void QtMaterialTab::paintForeground(QPainter *painter) painter->drawPixmap(iconRect, pixmap); } - if (!m_active) - { + if (!m_active) { if (!icon().isNull()) { painter->translate(0, -12); } diff --git a/components/qtmaterialtabs_internal.h b/components/qtmaterialtabs_internal.h index 75dc03478..cb31eaec2 100644 --- a/components/qtmaterialtabs_internal.h +++ b/components/qtmaterialtabs_internal.h @@ -24,17 +24,17 @@ class QtMaterialTabsInkBar : public QtMaterialOverlayWidget void animate(); protected: - bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; + bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(QtMaterialTabsInkBar) - QtMaterialTabs *const m_tabs; + QtMaterialTabs *const m_tabs; QPropertyAnimation *const m_animation; - QRect m_geometry; - QRect m_previousGeometry; - qreal m_tween; + QRect m_geometry; + QRect m_previousGeometry; + qreal m_tween; }; inline void QtMaterialTabsInkBar::setTweenValue(qreal value) @@ -71,7 +71,7 @@ protected slots: Q_DISABLE_COPY(QtMaterialTab) QtMaterialTabs *const m_tabs; - bool m_active; + bool m_active; }; inline void QtMaterialTab::setActive(bool state) @@ -85,4 +85,4 @@ inline bool QtMaterialTab::isActive() const return m_active; } -#endif // QTMATERIALTABS_INTERNAL_H +#endif // QTMATERIALTABS_INTERNAL_H diff --git a/components/qtmaterialtabs_p.h b/components/qtmaterialtabs_p.h index 1f32b04ed..aa9c5c78c 100644 --- a/components/qtmaterialtabs_p.h +++ b/components/qtmaterialtabs_p.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALTABS_P_H #define QTMATERIALTABS_P_H -#include #include "lib/qtmaterialtheme.h" +#include class QHBoxLayout; class QtMaterialTabs; @@ -19,16 +19,16 @@ class QtMaterialTabsPrivate void init(); - QtMaterialTabs *const q_ptr; + QtMaterialTabs *const q_ptr; QtMaterialTabsInkBar *inkBar; - QHBoxLayout *tabLayout; + QHBoxLayout *tabLayout; Material::RippleStyle rippleStyle; - QColor inkColor; - QColor backgroundColor; - QColor textColor; - int tab; - bool showHalo; - bool useThemeColors; + QColor inkColor; + QColor backgroundColor; + QColor textColor; + int tab; + bool showHalo; + bool useThemeColors; }; -#endif // QTMATERIALTABS_P_H +#endif // QTMATERIALTABS_P_H diff --git a/components/qtmaterialtextfield.cpp b/components/qtmaterialtextfield.cpp index 080da8291..b97ab24b1 100644 --- a/components/qtmaterialtextfield.cpp +++ b/components/qtmaterialtextfield.cpp @@ -1,14 +1,14 @@ #include "qtmaterialtextfield.h" -#include "qtmaterialtextfield_p.h" -#include -#include -#include "qtmaterialtextfield_internal.h" #include "lib/qtmaterialstyle.h" +#include "qtmaterialtextfield_internal.h" +#include "qtmaterialtextfield_p.h" #include +#include +#include /*! - * \class QtMaterialTextFieldPrivate - * \internal + * @class QtMaterialTextFieldPrivate + * @internal */ QtMaterialTextFieldPrivate::QtMaterialTextFieldPrivate(QtMaterialTextField *q) @@ -16,19 +16,17 @@ QtMaterialTextFieldPrivate::QtMaterialTextFieldPrivate(QtMaterialTextField *q) { } -QtMaterialTextFieldPrivate::~QtMaterialTextFieldPrivate() -{ -} +QtMaterialTextFieldPrivate::~QtMaterialTextFieldPrivate() {} void QtMaterialTextFieldPrivate::init() { Q_Q(QtMaterialTextField); - stateMachine = new QtMaterialTextFieldStateMachine(q); - label = 0; - labelFontSize = 9.5; - showLabel = false; - showInputLine = true; + stateMachine = new QtMaterialTextFieldStateMachine(q); + label = 0; + labelFontSize = 9.5; + showLabel = false; + showInputLine = true; useThemeColors = true; q->setFrame(false); @@ -44,19 +42,17 @@ void QtMaterialTextFieldPrivate::init() } /*! - * \class QtMaterialTextField + * @class QtMaterialTextField */ QtMaterialTextField::QtMaterialTextField(QWidget *parent) - : QLineEdit(parent), - d_ptr(new QtMaterialTextFieldPrivate(this)) + : QLineEdit(parent) + , d_ptr(new QtMaterialTextFieldPrivate(this)) { d_func()->init(); } -QtMaterialTextField::~QtMaterialTextField() -{ -} +QtMaterialTextField::~QtMaterialTextField() {} void QtMaterialTextField::setUseThemeColors(bool value) { @@ -112,8 +108,7 @@ void QtMaterialTextField::setLabelFontSize(qreal size) d->labelFontSize = size; - if (d->label) - { + if (d->label) { QFont font(d->label->font()); font.setPointSizeF(size); d->label->setFont(font); @@ -249,29 +244,28 @@ bool QtMaterialTextField::hasInputLine() const } QtMaterialTextField::QtMaterialTextField(QtMaterialTextFieldPrivate &d, QWidget *parent) - : QLineEdit(parent), - d_ptr(&d) + : QLineEdit(parent) + , d_ptr(&d) { d_func()->init(); } /*! - * \reimp + * @reimp */ bool QtMaterialTextField::event(QEvent *event) { Q_D(QtMaterialTextField); - switch (event->type()) - { - case QEvent::Resize: - case QEvent::Move: { - if (d->label) { - d->label->setGeometry(rect()); + switch (event->type()) { + case QEvent::Resize: + case QEvent::Move: { + if (d->label) { + d->label->setGeometry(rect()); + } } - } - default: - break; + default: + break; } return QLineEdit::event(event); } @@ -289,22 +283,20 @@ void QtMaterialTextField::paintEvent(QPaintEvent *event) const qreal progress = d->stateMachine->progress(); - if (text().isEmpty() && progress < 1) - { - painter.setOpacity(1-progress); + if (text().isEmpty() && progress < 1) { + painter.setOpacity(1 - progress); painter.fillRect(rect(), parentWidget()->palette().color(backgroundRole())); } - const int y = height()-1; - const int wd = width()-5; + const int y = height() - 1; + const int wd = width() - 5; - if (d->showInputLine) - { + if (d->showInputLine) { QPen pen; pen.setWidth(1); pen.setColor(inputLineColor()); - if (!isEnabled()) + if (!isEnabled()) pen.setStyle(Qt::DashLine); painter.setPen(pen); @@ -315,12 +307,11 @@ void QtMaterialTextField::paintEvent(QPaintEvent *event) brush.setStyle(Qt::SolidPattern); brush.setColor(inkColor()); - if (progress > 0) - { + if (progress > 0) { painter.setPen(Qt::NoPen); painter.setBrush(brush); - const int w = (1-progress)*static_cast(wd/2); - painter.drawRect(w+2.5, height()-2, wd-w*2, 2); + const int w = (1 - progress) * static_cast(wd / 2.0); + painter.drawRect(w + 2.5, height() - 2, wd - w * 2, 2); } } } diff --git a/components/qtmaterialtextfield_internal.cpp b/components/qtmaterialtextfield_internal.cpp index b8b4ce7ff..e9a2b9743 100644 --- a/components/qtmaterialtextfield_internal.cpp +++ b/components/qtmaterialtextfield_internal.cpp @@ -1,23 +1,23 @@ #include "qtmaterialtextfield_internal.h" -#include +#include "qtmaterialtextfield.h" #include #include -#include "qtmaterialtextfield.h" +#include /*! - * \class QtMaterialTextFieldStateMachine - * \internal + * @class QtMaterialTextFieldStateMachine + * @internal */ QtMaterialTextFieldStateMachine::QtMaterialTextFieldStateMachine(QtMaterialTextField *parent) - : QStateMachine(parent), - m_textField(parent), - m_normalState(new QState), - m_focusedState(new QState), - m_label(0), - m_offsetAnimation(0), - m_colorAnimation(0), - m_progress(0.0) + : QStateMachine(parent) + , m_textField(parent) + , m_normalState(new QState) + , m_focusedState(new QState) + , m_label(0) + , m_offsetAnimation(0) + , m_colorAnimation(0) + , m_progress(0.0) { Q_ASSERT(parent); @@ -55,9 +55,7 @@ QtMaterialTextFieldStateMachine::QtMaterialTextFieldStateMachine(QtMaterialTextF connect(m_textField, SIGNAL(textChanged(QString)), this, SLOT(setupProperties())); } -QtMaterialTextFieldStateMachine::~QtMaterialTextFieldStateMachine() -{ -} +QtMaterialTextFieldStateMachine::~QtMaterialTextFieldStateMachine() {} void QtMaterialTextFieldStateMachine::setLabel(QtMaterialTextFieldLabel *label) { @@ -77,8 +75,7 @@ void QtMaterialTextFieldStateMachine::setLabel(QtMaterialTextFieldLabel *label) m_label = label; - if (m_label) - { + if (m_label) { m_offsetAnimation = new QPropertyAnimation(m_label, "offset", this); m_offsetAnimation->setDuration(210); m_offsetAnimation->setEasingCurve(QEasingCurve::OutCubic); @@ -94,22 +91,21 @@ void QtMaterialTextFieldStateMachine::setLabel(QtMaterialTextFieldLabel *label) void QtMaterialTextFieldStateMachine::setupProperties() { - if (m_label) - { + if (m_label) { const int m = m_textField->textMargins().top(); if (m_textField->text().isEmpty()) { m_normalState->assignProperty(m_label, "offset", QPointF(0, 26)); } else { - m_normalState->assignProperty(m_label, "offset", QPointF(0, 0-m)); + m_normalState->assignProperty(m_label, "offset", QPointF(0, 0 - m)); } - m_focusedState->assignProperty(m_label, "offset", QPointF(0, 0-m)); + m_focusedState->assignProperty(m_label, "offset", QPointF(0, 0 - m)); m_focusedState->assignProperty(m_label, "color", m_textField->inkColor()); m_normalState->assignProperty(m_label, "color", m_textField->labelColor()); if (0 != m_label->offset().y() && !m_textField->text().isEmpty()) { - m_label->setOffset(QPointF(0, 0-m)); + m_label->setOffset(QPointF(0, 0 - m)); } else if (!m_textField->hasFocus() && m_label->offset().y() <= 0 && m_textField->text().isEmpty()) { m_label->setOffset(QPointF(0, 26)); } @@ -119,17 +115,17 @@ void QtMaterialTextFieldStateMachine::setupProperties() } /*! - * \class QtMaterialTextFieldLabel - * \internal + * @class QtMaterialTextFieldLabel + * @internal */ QtMaterialTextFieldLabel::QtMaterialTextFieldLabel(QtMaterialTextField *parent) - : QWidget(parent), - m_textField(parent), - m_scale(1), - m_posX(0), - m_posY(26), - m_color(parent->labelColor()) + : QWidget(parent) + , m_textField(parent) + , m_scale(1) + , m_posX(0) + , m_posY(26) + , m_color(parent->labelColor()) { Q_ASSERT(parent); @@ -138,12 +134,10 @@ QtMaterialTextFieldLabel::QtMaterialTextFieldLabel(QtMaterialTextField *parent) setFont(font); } -QtMaterialTextFieldLabel::~QtMaterialTextFieldLabel() -{ -} +QtMaterialTextFieldLabel::~QtMaterialTextFieldLabel() {} /*! - * \reimp + * @reimp */ void QtMaterialTextFieldLabel::paintEvent(QPaintEvent *event) { @@ -159,6 +153,6 @@ void QtMaterialTextFieldLabel::paintEvent(QPaintEvent *event) painter.setPen(m_color); painter.setOpacity(1); - QPointF pos(2+m_posX, height()-36+m_posY); + QPointF pos(2 + m_posX, height() - 36 + m_posY); painter.drawText(pos.x(), pos.y(), m_textField->label()); } diff --git a/components/qtmaterialtextfield_internal.h b/components/qtmaterialtextfield_internal.h index e510287a1..615d659c4 100644 --- a/components/qtmaterialtextfield_internal.h +++ b/components/qtmaterialtextfield_internal.h @@ -1,9 +1,9 @@ #ifndef QTMATERIALTEXTFIELD_INTERNAL_H #define QTMATERIALTEXTFIELD_INTERNAL_H +#include "qtmaterialtextfield.h" #include #include -#include "qtmaterialtextfield.h" class QPropertyAnimation; class QtMaterialTextFieldLabel; @@ -30,12 +30,12 @@ public slots: Q_DISABLE_COPY(QtMaterialTextFieldStateMachine) QtMaterialTextField *const m_textField; - QState *const m_normalState; - QState *const m_focusedState; - QtMaterialTextFieldLabel *m_label; - QPropertyAnimation *m_offsetAnimation; - QPropertyAnimation *m_colorAnimation; - qreal m_progress; + QState *const m_normalState; + QState *const m_focusedState; + QtMaterialTextFieldLabel *m_label; + QPropertyAnimation *m_offsetAnimation; + QPropertyAnimation *m_colorAnimation; + qreal m_progress; }; inline void QtMaterialTextFieldStateMachine::setProgress(qreal progress) @@ -77,10 +77,10 @@ class QtMaterialTextFieldLabel : public QWidget Q_DISABLE_COPY(QtMaterialTextFieldLabel) QtMaterialTextField *const m_textField; - qreal m_scale; - qreal m_posX; - qreal m_posY; - QColor m_color; + qreal m_scale; + qreal m_posX; + qreal m_posY; + QColor m_color; }; inline void QtMaterialTextFieldLabel::setScale(qreal scale) @@ -117,4 +117,4 @@ inline QColor QtMaterialTextFieldLabel::color() const return m_color; } -#endif // QTMATERIALTEXTFIELD_INTERNAL_H +#endif // QTMATERIALTEXTFIELD_INTERNAL_H diff --git a/components/qtmaterialtextfield_p.h b/components/qtmaterialtextfield_p.h index 9e8c83540..7b35575fe 100644 --- a/components/qtmaterialtextfield_p.h +++ b/components/qtmaterialtextfield_p.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALTEXTFIELD_P_H #define QTMATERIALTEXTFIELD_P_H -#include #include +#include class QtMaterialTextField; class QtMaterialTextFieldStateMachine; @@ -19,18 +19,18 @@ class QtMaterialTextFieldPrivate void init(); - QtMaterialTextField *const q_ptr; + QtMaterialTextField *const q_ptr; QtMaterialTextFieldStateMachine *stateMachine; - QtMaterialTextFieldLabel *label; - QColor textColor; - QColor labelColor; - QColor inkColor; - QColor inputLineColor; - QString labelString; - qreal labelFontSize; - bool showLabel; - bool showInputLine; - bool useThemeColors; + QtMaterialTextFieldLabel *label; + QColor textColor; + QColor labelColor; + QColor inkColor; + QColor inputLineColor; + QString labelString; + qreal labelFontSize; + bool showLabel; + bool showInputLine; + bool useThemeColors; }; -#endif // QTMATERIALTEXTFIELD_P_H +#endif // QTMATERIALTEXTFIELD_P_H diff --git a/components/qtmaterialtoggle.cpp b/components/qtmaterialtoggle.cpp index 6d11fc986..bd8c77be3 100644 --- a/components/qtmaterialtoggle.cpp +++ b/components/qtmaterialtoggle.cpp @@ -1,11 +1,11 @@ #include "qtmaterialtoggle.h" +#include "lib/qtmaterialstyle.h" +#include "qtmaterialtoggle_internal.h" #include "qtmaterialtoggle_p.h" -#include -#include -#include #include -#include "qtmaterialtoggle_internal.h" -#include "lib/qtmaterialstyle.h" +#include +#include +#include /*! * \class QtMaterialTogglePrivate @@ -17,21 +17,19 @@ QtMaterialTogglePrivate::QtMaterialTogglePrivate(QtMaterialToggle *q) { } -QtMaterialTogglePrivate::~QtMaterialTogglePrivate() -{ -} +QtMaterialTogglePrivate::~QtMaterialTogglePrivate() {} void QtMaterialTogglePrivate::init() { Q_Q(QtMaterialToggle); - track = new QtMaterialToggleTrack(q); - thumb = new QtMaterialToggleThumb(q); - rippleOverlay = new QtMaterialToggleRippleOverlay(thumb, track, q); - stateMachine = new QStateMachine(q); - offState = new QState; - onState = new QState; - orientation = Qt::Horizontal; + track = new QtMaterialToggleTrack(q); + thumb = new QtMaterialToggleThumb(q); + rippleOverlay = new QtMaterialToggleRippleOverlay(thumb, track, q); + stateMachine = new QStateMachine(q); + offState = new QState; + onState = new QState; + orientation = Qt::Horizontal; useThemeColors = true; q->setCheckable(true); @@ -115,7 +113,7 @@ void QtMaterialTogglePrivate::setupProperties() if (qFuzzyCompare(shift, 1)) { thumb->setThumbColor(q->activeColor()); track->setTrackColor(q->activeColor().lighter(110)); - } else if (qFuzzyCompare(1+shift, 1)) { + } else if (qFuzzyCompare(1 + shift, 1)) { thumb->setThumbColor(q->inactiveColor()); track->setTrackColor(q->trackColor()); } @@ -135,15 +133,13 @@ void QtMaterialTogglePrivate::setupProperties() */ QtMaterialToggle::QtMaterialToggle(QWidget *parent) - : QAbstractButton(parent), - d_ptr(new QtMaterialTogglePrivate(this)) + : QAbstractButton(parent) + , d_ptr(new QtMaterialTogglePrivate(this)) { d_func()->init(); } -QtMaterialToggle::~QtMaterialToggle() -{ -} +QtMaterialToggle::~QtMaterialToggle() {} void QtMaterialToggle::setUseThemeColors(bool value) { @@ -267,27 +263,23 @@ QSize QtMaterialToggle::sizeHint() const { Q_D(const QtMaterialToggle); - return Qt::Horizontal == d->orientation - ? QSize(64, 48) - : QSize(48, 64); + return Qt::Horizontal == d->orientation ? QSize(64, 48) : QSize(48, 64); } bool QtMaterialToggle::event(QEvent *event) { Q_D(QtMaterialToggle); - switch (event->type()) - { - case QEvent::ParentChange: - { - QWidget *widget; - if ((widget = parentWidget())) { - d->rippleOverlay->setParent(widget); + switch (event->type()) { + case QEvent::ParentChange: { + QWidget *widget; + if ((widget = parentWidget())) { + d->rippleOverlay->setParent(widget); + } + break; } - break; - } - default: - break; + default: + break; } return QAbstractButton::event(event); } diff --git a/components/qtmaterialtoggle_internal.cpp b/components/qtmaterialtoggle_internal.cpp index 9bcf82325..038c3e7b4 100644 --- a/components/qtmaterialtoggle_internal.cpp +++ b/components/qtmaterialtoggle_internal.cpp @@ -1,32 +1,29 @@ #include "qtmaterialtoggle_internal.h" -#include +#include "lib/qtmaterialripple.h" +#include "qtmaterialtoggle.h" #include +#include #include -#include "qtmaterialtoggle.h" -#include "lib/qtmaterialripple.h" /*! * \class QtMaterialToggleRippleOverlay * \internal */ -QtMaterialToggleRippleOverlay::QtMaterialToggleRippleOverlay( - QtMaterialToggleThumb *thumb, - QtMaterialToggleTrack *track, - QtMaterialToggle *parent) - : QtMaterialRippleOverlay(parent->parentWidget()), - m_toggle(parent), - m_thumb(thumb), - m_track(track) +QtMaterialToggleRippleOverlay::QtMaterialToggleRippleOverlay(QtMaterialToggleThumb *thumb, + QtMaterialToggleTrack *track, + QtMaterialToggle *parent) + : QtMaterialRippleOverlay(parent->parentWidget()) + , m_toggle(parent) + , m_thumb(thumb) + , m_track(track) { connect(parent, SIGNAL(toggled(bool)), this, SLOT(addToggleRipple())); thumb->installEventFilter(this); } -QtMaterialToggleRippleOverlay::~QtMaterialToggleRippleOverlay() -{ -} +QtMaterialToggleRippleOverlay::~QtMaterialToggleRippleOverlay() {} void QtMaterialToggleRippleOverlay::addToggleRipple() { @@ -37,14 +34,14 @@ void QtMaterialToggleRippleOverlay::addToggleRipple() int t, w; if (Qt::Horizontal == m_toggle->orientation()) { - t = m_toggle->height()/2; - w = m_thumb->height()/2+10; + t = m_toggle->height() / 2; + w = m_thumb->height() / 2 + 10; } else { - t = m_toggle->width()/2; - w = m_thumb->width()/2+10; + t = m_toggle->width() / 2; + w = m_thumb->width() / 2 + 10; } - QtMaterialRipple *ripple = new QtMaterialRipple(QPoint(10+t, 20+t)); + QtMaterialRipple *ripple = new QtMaterialRipple(QPoint(10 + t, 20 + t)); ripple->setColor(m_track->trackColor()); ripple->setRadiusEndValue(w); ripple->setOpacityStartValue(0.8); @@ -70,9 +67,9 @@ QRect QtMaterialToggleRippleOverlay::overlayGeometry() const { const qreal offset = m_thumb->offset(); if (Qt::Horizontal == m_toggle->orientation()) { - return m_toggle->geometry().adjusted(-10+offset, -20, 10+offset, 20); + return m_toggle->geometry().adjusted(-10 + offset, -20, 10 + offset, 20); } else { - return m_toggle->geometry().adjusted(-10, -20+offset, 10, 20+offset); + return m_toggle->geometry().adjusted(-10, -20 + offset, 10, 20 + offset); } } @@ -82,10 +79,10 @@ QRect QtMaterialToggleRippleOverlay::overlayGeometry() const */ QtMaterialToggleThumb::QtMaterialToggleThumb(QtMaterialToggle *parent) - : QWidget(parent), - m_toggle(parent), - m_shift(0), - m_offset(0) + : QWidget(parent) + , m_toggle(parent) + , m_shift(0) + , m_offset(0) { Q_ASSERT(parent); @@ -98,9 +95,7 @@ QtMaterialToggleThumb::QtMaterialToggleThumb(QtMaterialToggle *parent) parent->installEventFilter(this); } -QtMaterialToggleThumb::~QtMaterialToggleThumb() -{ -} +QtMaterialToggleThumb::~QtMaterialToggleThumb() {} void QtMaterialToggleThumb::setShift(qreal shift) { @@ -116,8 +111,7 @@ bool QtMaterialToggleThumb::eventFilter(QObject *obj, QEvent *event) { const QEvent::Type type = event->type(); - if (QEvent::Resize == type || QEvent::Move == type) - { + if (QEvent::Resize == type || QEvent::Move == type) { setGeometry(m_toggle->rect().adjusted(8, 8, -8, -8)); updateOffset(); } @@ -142,11 +136,11 @@ void QtMaterialToggleThumb::paintEvent(QPaintEvent *event) QRectF r; if (Qt::Horizontal == m_toggle->orientation()) { - s = height()-10; - r = QRectF(5+m_offset, 5, s, s); + s = height() - 10; + r = QRectF(5 + m_offset, 5, s, s); } else { - s = width()-10; - r = QRectF(5, 5+m_offset, s, s); + s = width() - 10; + r = QRectF(5, 5 + m_offset, s, s); } painter.drawEllipse(r); @@ -160,9 +154,8 @@ void QtMaterialToggleThumb::paintEvent(QPaintEvent *event) void QtMaterialToggleThumb::updateOffset() { - const QSize s(Qt::Horizontal == m_toggle->orientation() - ? size() : size().transposed()); - m_offset = m_shift*static_cast(s.width()-s.height()); + const QSize s(Qt::Horizontal == m_toggle->orientation() ? size() : size().transposed()); + m_offset = m_shift * static_cast(s.width() - s.height()); update(); } @@ -172,17 +165,15 @@ void QtMaterialToggleThumb::updateOffset() */ QtMaterialToggleTrack::QtMaterialToggleTrack(QtMaterialToggle *parent) - : QWidget(parent), - m_toggle(parent) + : QWidget(parent) + , m_toggle(parent) { Q_ASSERT(parent); parent->installEventFilter(this); } -QtMaterialToggleTrack::~QtMaterialToggleTrack() -{ -} +QtMaterialToggleTrack::~QtMaterialToggleTrack() {} void QtMaterialToggleTrack::setTrackColor(const QColor &color) { @@ -220,12 +211,12 @@ void QtMaterialToggleTrack::paintEvent(QPaintEvent *event) painter.setPen(Qt::NoPen); if (Qt::Horizontal == m_toggle->orientation()) { - const int h = height()/2; - const QRect r(0, h/2, width(), h); - painter.drawRoundedRect(r.adjusted(14, 4, -14, -4), h/2-4, h/2-4); + const int h = height() / 2; + const QRect r(0, h / 2, width(), h); + painter.drawRoundedRect(r.adjusted(14, 4, -14, -4), h / 2.0 - 4, h / 2.0 - 4); } else { - const int w = width()/2; - const QRect r(w/2, 0, w, height()); - painter.drawRoundedRect(r.adjusted(4, 14, -4, -14), w/2-4, w/2-4); + const int w = width() / 2; + const QRect r(w / 2, 0, w, height()); + painter.drawRoundedRect(r.adjusted(4, 14, -4, -14), w / 2.0 - 4, w / 2.0 - 4); } } diff --git a/components/qtmaterialtoggle_internal.h b/components/qtmaterialtoggle_internal.h index 079e36990..fb8799fa3 100644 --- a/components/qtmaterialtoggle_internal.h +++ b/components/qtmaterialtoggle_internal.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALTOGGLE_INTERNAL_H #define QTMATERIALTOGGLE_INTERNAL_H -#include #include "lib/qtmaterialrippleoverlay.h" +#include class QtMaterialToggle; class QtMaterialToggleThumb; @@ -13,9 +13,7 @@ class QtMaterialToggleRippleOverlay : public QtMaterialRippleOverlay Q_OBJECT public: - QtMaterialToggleRippleOverlay(QtMaterialToggleThumb *thumb, - QtMaterialToggleTrack *track, - QtMaterialToggle *parent); + QtMaterialToggleRippleOverlay(QtMaterialToggleThumb *thumb, QtMaterialToggleTrack *track, QtMaterialToggle *parent); ~QtMaterialToggleRippleOverlay(); protected slots: @@ -28,7 +26,7 @@ protected slots: private: Q_DISABLE_COPY(QtMaterialToggleRippleOverlay) - QtMaterialToggle *const m_toggle; + QtMaterialToggle *const m_toggle; QtMaterialToggleThumb *const m_thumb; QtMaterialToggleTrack *const m_track; }; @@ -62,9 +60,9 @@ class QtMaterialToggleThumb : public QWidget void updateOffset(); QtMaterialToggle *const m_toggle; - QColor m_thumbColor; - qreal m_shift; - qreal m_offset; + QColor m_thumbColor; + qreal m_shift; + qreal m_offset; }; inline qreal QtMaterialToggleThumb::shift() const @@ -109,7 +107,7 @@ class QtMaterialToggleTrack : public QWidget Q_DISABLE_COPY(QtMaterialToggleTrack) QtMaterialToggle *const m_toggle; - QColor m_trackColor; + QColor m_trackColor; }; inline QColor QtMaterialToggleTrack::trackColor() const @@ -117,4 +115,4 @@ inline QColor QtMaterialToggleTrack::trackColor() const return m_trackColor; } -#endif // QTMATERIALTOGGLE_INTERNAL_H +#endif // QTMATERIALTOGGLE_INTERNAL_H diff --git a/components/qtmaterialtoggle_p.h b/components/qtmaterialtoggle_p.h index f50d5b35b..bfc4be45f 100644 --- a/components/qtmaterialtoggle_p.h +++ b/components/qtmaterialtoggle_p.h @@ -2,7 +2,7 @@ #define QTMATERIALTOGGLE_P_H #include - +#include class QStateMachine; class QState; class QColor; @@ -23,19 +23,19 @@ class QtMaterialTogglePrivate void init(); void setupProperties(); - QtMaterialToggle *const q_ptr; - QtMaterialToggleTrack *track; - QtMaterialToggleThumb *thumb; + QtMaterialToggle *const q_ptr; + QtMaterialToggleTrack *track; + QtMaterialToggleThumb *thumb; QtMaterialToggleRippleOverlay *rippleOverlay; - QStateMachine *stateMachine; - QState *offState; - QState *onState; - Qt::Orientation orientation; - QColor disabledColor; - QColor activeColor; - QColor inactiveColor; - QColor trackColor; - bool useThemeColors; + QStateMachine *stateMachine; + QState *offState; + QState *onState; + Qt::Orientation orientation; + QColor disabledColor; + QColor activeColor; + QColor inactiveColor; + QColor trackColor; + bool useThemeColors; }; -#endif // QTMATERIALTOGGLE_P_H +#endif // QTMATERIALTOGGLE_P_H diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 000000000..3b27535b8 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.5) + +project( + examples + VERSION 0.1 + LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_CXX_STANDARD 17) + +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) + +file(GLOB HEADER "*.h") +file(GLOB RSOURCE "*.cpp") +file(GLOB UI "*.ui") + +set(RCC_FILES examples.qrc) + +add_executable(${PROJECT_NAME} ${HEADER} ${RSOURCE} ${UI} ${RCC_FILES}) +target_include_directories(${PROJECT_NAME} PUBLIC ../include/qmetarial/) + +target_link_libraries( + ${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Core components) + +set_target_properties( + ${PROJECT_NAME} + PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING + ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE) diff --git a/examples/appbarsettingseditor.cpp b/examples/appbarsettingseditor.cpp index 5f2ce00af..97b78a499 100644 --- a/examples/appbarsettingseditor.cpp +++ b/examples/appbarsettingseditor.cpp @@ -12,7 +12,7 @@ AppBarSettingsEditor::AppBarSettingsEditor(QWidget *parent) { QLabel *label = new QLabel("Inbox"); label->setAttribute(Qt::WA_TranslucentBackground); - label->setForegroundRole(QPalette::Foreground); + label->setForegroundRole(QPalette::WindowText); label->setContentsMargins(6, 0, 0, 0); QPalette palette = label->palette(); diff --git a/examples/dialogsettingseditor.cpp b/examples/dialogsettingseditor.cpp index f4e4916ae..2bcaa6150 100644 --- a/examples/dialogsettingseditor.cpp +++ b/examples/dialogsettingseditor.cpp @@ -1,13 +1,13 @@ #include "dialogsettingseditor.h" -#include #include +#include #include #include DialogSettingsEditor::DialogSettingsEditor(QWidget *parent) - : QWidget(parent), - ui(new Ui::DialogSettingsForm), - m_dialog(new QtMaterialDialog) + : QWidget(parent) + , ui(new Ui::DialogSettingsForm) + , m_dialog(new QtMaterialDialog) { QVBoxLayout *layout = new QVBoxLayout; setLayout(layout); @@ -26,6 +26,7 @@ DialogSettingsEditor::DialogSettingsEditor(QWidget *parent) canvas->setLayout(layout); canvas->setMaximumHeight(300); + // set parent m_dialog->setParent(this); QWidget *dialogWidget = new QWidget; @@ -56,10 +57,6 @@ DialogSettingsEditor::~DialogSettingsEditor() delete ui; } -void DialogSettingsEditor::setupForm() -{ -} +void DialogSettingsEditor::setupForm() {} -void DialogSettingsEditor::updateWidget() -{ -} +void DialogSettingsEditor::updateWidget() {} diff --git a/examples/dialogsettingseditor.h b/examples/dialogsettingseditor.h index f92204621..18caa64e0 100644 --- a/examples/dialogsettingseditor.h +++ b/examples/dialogsettingseditor.h @@ -1,8 +1,8 @@ #ifndef DIALOGSETTINGSEDITOR_H #define DIALOGSETTINGSEDITOR_H -#include #include "ui_dialogsettingsform.h" +#include class QtMaterialDialog; @@ -20,7 +20,7 @@ protected slots: private: Ui::DialogSettingsForm *const ui; - QtMaterialDialog *const m_dialog; + QtMaterialDialog *const m_dialog; }; -#endif // DIALOGSETTINGSEDITOR_H +#endif // DIALOGSETTINGSEDITOR_H diff --git a/examples/drawersettingseditor.h b/examples/drawersettingseditor.h index 45f21af1f..f992843ec 100644 --- a/examples/drawersettingseditor.h +++ b/examples/drawersettingseditor.h @@ -1,8 +1,8 @@ #ifndef DRAWERSETTINGSEDITOR_H #define DRAWERSETTINGSEDITOR_H -#include #include "ui_drawersettingsform.h" +#include class QtMaterialDrawer; @@ -20,7 +20,7 @@ protected slots: private: Ui::DrawerSettingsForm *const ui; - QtMaterialDrawer *const m_drawer; + QtMaterialDrawer *const m_drawer; }; -#endif // DRAWERSETTINGSEDITOR_H +#endif // DRAWERSETTINGSEDITOR_H diff --git a/examples/examples.pro b/examples/examples.pro deleted file mode 100644 index 35d2438ca..000000000 --- a/examples/examples.pro +++ /dev/null @@ -1,75 +0,0 @@ -QT += core gui widgets -TEMPLATE = app -CONFIG += c++11 -SOURCES = mainwindow.cpp \ - main.cpp \ - avatarsettingseditor.cpp \ - badgesettingseditor.cpp \ - checkboxsettingseditor.cpp \ - fabsettingseditor.cpp \ - raisedbuttonsettingseditor.cpp \ - flatbuttonsettingseditor.cpp \ - iconbuttonsettingseditor.cpp \ - progresssettingseditor.cpp \ - circularprogresssettingseditor.cpp \ - slidersettingseditor.cpp \ - radiobuttonsettingseditor.cpp \ - togglesettingseditor.cpp \ - textfieldsettingseditor.cpp \ - tabssettingseditor.cpp \ - snackbarsettingseditor.cpp \ - dialogsettingseditor.cpp \ - drawersettingseditor.cpp \ - scrollbarsettingseditor.cpp \ - appbarsettingseditor.cpp \ - autocompletesettingseditor.cpp \ - menusettingseditor.cpp -HEADERS = mainwindow.h \ - avatarsettingseditor.h \ - badgesettingseditor.h \ - checkboxsettingseditor.h \ - fabsettingseditor.h \ - raisedbuttonsettingseditor.h \ - flatbuttonsettingseditor.h \ - iconbuttonsettingseditor.h \ - progresssettingseditor.h \ - circularprogresssettingseditor.h \ - slidersettingseditor.h \ - radiobuttonsettingseditor.h \ - togglesettingseditor.h \ - textfieldsettingseditor.h \ - tabssettingseditor.h \ - snackbarsettingseditor.h \ - dialogsettingseditor.h \ - drawersettingseditor.h \ - scrollbarsettingseditor.h \ - appbarsettingseditor.h \ - autocompletesettingseditor.h \ - menusettingseditor.h -LIBS += $$top_builddir/components/$(OBJECTS_DIR)/libcomponents.a -INCLUDEPATH += $$top_srcdir/components/ -TARGET = examples-exe -PRE_TARGETDEPS += $$top_builddir/components/$(OBJECTS_DIR)/libcomponents.a - -RESOURCES += \ - examples.qrc - -FORMS += \ - avatarsettingsform.ui \ - badgesettingsform.ui \ - checkboxsettingsform.ui \ - fabsettingsform.ui \ - flatbuttonsettingsform.ui \ - iconbuttonsettingsform.ui \ - progresssettingsform.ui \ - circularprogresssettingsform.ui \ - slidersettingsform.ui \ - snackbarsettingsform.ui \ - radiobuttonsettingsform.ui \ - togglesettingsform.ui \ - textfieldsettingsform.ui \ - tabssettingsform.ui \ - dialogsettingsform.ui \ - drawersettingsform.ui \ - scrollbarsettingsform.ui \ - appbarsettingsform.ui diff --git a/examples/iconbuttonsettingseditor.cpp b/examples/iconbuttonsettingseditor.cpp index 4dbc51861..1bd48fc9d 100644 --- a/examples/iconbuttonsettingseditor.cpp +++ b/examples/iconbuttonsettingseditor.cpp @@ -1,12 +1,12 @@ #include "iconbuttonsettingseditor.h" #include -#include #include +#include IconButtonSettingsEditor::IconButtonSettingsEditor(QWidget *parent) - : QWidget(parent), - ui(new Ui::IconButtonSettingsForm), - m_button(new QtMaterialIconButton(QtMaterialTheme::icon("toggle", "star"))) + : QWidget(parent) + , ui(new Ui::IconButtonSettingsForm) + , m_button(new QtMaterialIconButton(QtMaterialTheme::icon("toggle", "star"))) { init(); } @@ -17,9 +17,9 @@ IconButtonSettingsEditor::~IconButtonSettingsEditor() } IconButtonSettingsEditor::IconButtonSettingsEditor(QtMaterialIconButton *button, QWidget *parent) - : QWidget(parent), - ui(new Ui::IconButtonSettingsForm), - m_button(button) + : QWidget(parent) + , ui(new Ui::IconButtonSettingsForm) + , m_button(button) { init(); } diff --git a/examples/radiobuttonsettingseditor.h b/examples/radiobuttonsettingseditor.h index 76ad852b4..fa7ac8274 100644 --- a/examples/radiobuttonsettingseditor.h +++ b/examples/radiobuttonsettingseditor.h @@ -1,8 +1,8 @@ #ifndef RADIOBUTTONSETTINGSEDITOR_H #define RADIOBUTTONSETTINGSEDITOR_H -#include #include "ui_radiobuttonsettingsform.h" +#include class QtMaterialRadioButton; class RadioButton; @@ -22,9 +22,9 @@ protected slots: private: Ui::RadioButtonSettingsForm *const ui; - QtMaterialRadioButton *const m_radioButton1; - QtMaterialRadioButton *const m_radioButton2; - QtMaterialRadioButton *const m_radioButton3; + QtMaterialRadioButton *const m_radioButton1; + QtMaterialRadioButton *const m_radioButton2; + QtMaterialRadioButton *const m_radioButton3; }; -#endif // RADIOBUTTONSETTINGSEDITOR_H +#endif // RADIOBUTTONSETTINGSEDITOR_H diff --git a/examples/togglesettingseditor.h b/examples/togglesettingseditor.h index a74553e47..7cf5a5639 100644 --- a/examples/togglesettingseditor.h +++ b/examples/togglesettingseditor.h @@ -1,8 +1,8 @@ #ifndef TOGGLESETTINGSEDITOR_H #define TOGGLESETTINGSEDITOR_H -#include #include "ui_togglesettingsform.h" +#include class QtMaterialToggle; @@ -21,7 +21,7 @@ protected slots: private: Ui::ToggleSettingsForm *const ui; - QtMaterialToggle *const m_toggle; + QtMaterialToggle *const m_toggle; }; -#endif // TOGGLESETTINGSEDITOR_H +#endif // TOGGLESETTINGSEDITOR_H diff --git a/components/lib/qtmaterialcheckable.h b/include/qmetarial/lib/qtmaterialcheckable.h similarity index 97% rename from components/lib/qtmaterialcheckable.h rename to include/qmetarial/lib/qtmaterialcheckable.h index c4cc57469..3307f21b2 100644 --- a/components/lib/qtmaterialcheckable.h +++ b/include/qmetarial/lib/qtmaterialcheckable.h @@ -61,4 +61,4 @@ class QtMaterialCheckable : public QAbstractButton Q_DECLARE_PRIVATE(QtMaterialCheckable) }; -#endif // QTMATERIALCHECKABLE_H +#endif // QTMATERIALCHECKABLE_H diff --git a/components/lib/qtmaterialoverlaywidget.h b/include/qmetarial/lib/qtmaterialoverlaywidget.h similarity index 92% rename from components/lib/qtmaterialoverlaywidget.h rename to include/qmetarial/lib/qtmaterialoverlaywidget.h index 11acba020..96898f687 100644 --- a/components/lib/qtmaterialoverlaywidget.h +++ b/include/qmetarial/lib/qtmaterialoverlaywidget.h @@ -21,4 +21,4 @@ class QtMaterialOverlayWidget : public QWidget Q_DISABLE_COPY(QtMaterialOverlayWidget) }; -#endif // QTMATERIALOVERLAYWIDGET_H +#endif // QTMATERIALOVERLAYWIDGET_H diff --git a/components/lib/qtmaterialripple.h b/include/qmetarial/lib/qtmaterialripple.h similarity index 86% rename from components/lib/qtmaterialripple.h rename to include/qmetarial/lib/qtmaterialripple.h index d263c76fc..365b302d7 100644 --- a/components/lib/qtmaterialripple.h +++ b/include/qmetarial/lib/qtmaterialripple.h @@ -1,11 +1,11 @@ #ifndef QTMATERIALRIPPLE_H #define QTMATERIALRIPPLE_H -#include +#include #include -#include +#include #include -#include +#include class QtMaterialRippleOverlay; @@ -52,19 +52,18 @@ protected slots: private: Q_DISABLE_COPY(QtMaterialRipple) - QPropertyAnimation *animate(const QByteArray &property, - const QEasingCurve &easing = QEasingCurve::OutQuad, - int duration = 800); + QPropertyAnimation * + animate(const QByteArray &property, const QEasingCurve &easing = QEasingCurve::OutQuad, int duration = 800); void init(); - QtMaterialRippleOverlay *m_overlay; + QtMaterialRippleOverlay *m_overlay; QPropertyAnimation *const m_radiusAnimation; QPropertyAnimation *const m_opacityAnimation; - qreal m_radius; - qreal m_opacity; - QPoint m_center; - QBrush m_brush; + qreal m_radius; + qreal m_opacity; + QPoint m_center; + QBrush m_brush; }; inline void QtMaterialRipple::setOverlay(QtMaterialRippleOverlay *overlay) @@ -133,4 +132,4 @@ inline void QtMaterialRipple::setDuration(int msecs) m_opacityAnimation->setDuration(msecs); } -#endif // QTMATERIALRIPPLE_H +#endif // QTMATERIALRIPPLE_H diff --git a/components/lib/qtmaterialrippleoverlay.h b/include/qmetarial/lib/qtmaterialrippleoverlay.h similarity index 91% rename from components/lib/qtmaterialrippleoverlay.h rename to include/qmetarial/lib/qtmaterialrippleoverlay.h index 436c2b932..38c29162f 100644 --- a/components/lib/qtmaterialrippleoverlay.h +++ b/include/qmetarial/lib/qtmaterialrippleoverlay.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALRIPPLEOVERLAY_H #define QTMATERIALRIPPLEOVERLAY_H -#include #include "lib/qtmaterialoverlaywidget.h" +#include class QtMaterialRipple; @@ -35,8 +35,8 @@ class QtMaterialRippleOverlay : public QtMaterialOverlayWidget void paintRipple(QPainter *painter, QtMaterialRipple *ripple); QList m_ripples; - QPainterPath m_clipPath; - bool m_useClip; + QPainterPath m_clipPath; + bool m_useClip; }; inline void QtMaterialRippleOverlay::setClipping(bool enable) @@ -61,4 +61,4 @@ inline QList QtMaterialRippleOverlay::ripples() const return m_ripples; } -#endif // QTMATERIALRIPPLEOVERLAY_H +#endif // QTMATERIALRIPPLEOVERLAY_H diff --git a/components/lib/qtmaterialstatetransition.h b/include/qmetarial/lib/qtmaterialstatetransition.h similarity index 92% rename from components/lib/qtmaterialstatetransition.h rename to include/qmetarial/lib/qtmaterialstatetransition.h index d5013022b..033b4537c 100644 --- a/components/lib/qtmaterialstatetransition.h +++ b/include/qmetarial/lib/qtmaterialstatetransition.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALSTATETRANSITION_H #define QTMATERIALSTATETRANSITION_H -#include #include "lib/qtmaterialstatetransitionevent.h" +#include class QtMaterialStateTransition : public QAbstractTransition { @@ -19,4 +19,4 @@ class QtMaterialStateTransition : public QAbstractTransition QtMaterialStateTransitionType m_type; }; -#endif // QTMATERIALSTATETRANSITION_H +#endif // QTMATERIALSTATETRANSITION_H diff --git a/components/lib/qtmaterialstatetransitionevent.h b/include/qmetarial/lib/qtmaterialstatetransitionevent.h similarity index 88% rename from components/lib/qtmaterialstatetransitionevent.h rename to include/qmetarial/lib/qtmaterialstatetransitionevent.h index 1c64ec623..7e05d00e5 100644 --- a/components/lib/qtmaterialstatetransitionevent.h +++ b/include/qmetarial/lib/qtmaterialstatetransitionevent.h @@ -31,12 +31,12 @@ enum QtMaterialStateTransitionType { struct QtMaterialStateTransitionEvent : public QEvent { QtMaterialStateTransitionEvent(QtMaterialStateTransitionType type) - : QEvent(QEvent::Type(QEvent::User + 1)), - type(type) + : QEvent(QEvent::Type(QEvent::User + 1)) + , type(type) { } QtMaterialStateTransitionType type; }; -#endif // QTMATERIALSTATETRANSITIONEVENT_H +#endif // QTMATERIALSTATETRANSITIONEVENT_H diff --git a/components/lib/qtmaterialstyle.h b/include/qmetarial/lib/qtmaterialstyle.h similarity index 58% rename from components/lib/qtmaterialstyle.h rename to include/qmetarial/lib/qtmaterialstyle.h index e16289b0f..0bb9e99a9 100644 --- a/components/lib/qtmaterialstyle.h +++ b/include/qmetarial/lib/qtmaterialstyle.h @@ -1,11 +1,13 @@ #ifndef QTMATERIALSTYLE_H #define QTMATERIALSTYLE_H +#include "materiallib/qtmaterialstyle_p.h" #include -#include "lib/qtmaterialstyle_p.h" -#define MATERIAL_DISABLE_THEME_COLORS \ - if (d->useThemeColors == true) { d->useThemeColors = false; } +#define MATERIAL_DISABLE_THEME_COLORS \ + if (d->useThemeColors == true) { \ + d->useThemeColors = false; \ + } class QtMaterialTheme; @@ -37,4 +39,4 @@ inline QtMaterialStyle &QtMaterialStyle::instance() return instance; } -#endif // QTMATERIALSTYLE_H +#endif // QTMATERIALSTYLE_H diff --git a/include/qmetarial/lib/qtmaterialtheme.h b/include/qmetarial/lib/qtmaterialtheme.h new file mode 100644 index 000000000..d30f545e2 --- /dev/null +++ b/include/qmetarial/lib/qtmaterialtheme.h @@ -0,0 +1,318 @@ +#ifndef QTMATERIALTHEME_H +#define QTMATERIALTHEME_H + +#include +#include +#include +#include + +namespace Material { +enum ButtonPreset { FlatPreset, CheckablePreset }; + +enum RippleStyle { CenteredRipple, PositionedRipple, NoRipple }; + +enum OverlayStyle { NoOverlay, TintedOverlay, GrayOverlay }; + +enum Role { Default, Primary, Secondary }; + +enum ButtonIconPlacement { LeftIcon, RightIcon }; + +enum ProgressType { DeterminateProgress, IndeterminateProgress }; + +enum AvatarType { ImageAvatar, IconAvatar, LetterAvatar }; + +enum Color { + red50, + red100, + red200, + red300, + red400, + red500, + red600, + red700, + red800, + red900, + redA100, + redA200, + redA400, + redA700, + pink50, + pink100, + pink200, + pink300, + pink400, + pink500, + pink600, + pink700, + pink800, + pink900, + pinkA100, + pinkA200, + pinkA400, + pinkA700, + purple50, + purple100, + purple200, + purple300, + purple400, + purple500, + purple600, + purple700, + purple800, + purple900, + purpleA100, + purpleA200, + purpleA400, + purpleA700, + deepPurple50, + deepPurple100, + deepPurple200, + deepPurple300, + deepPurple400, + deepPurple500, + deepPurple600, + deepPurple700, + deepPurple800, + deepPurple900, + deepPurpleA100, + deepPurpleA200, + deepPurpleA400, + deepPurpleA700, + indigo50, + indigo100, + indigo200, + indigo300, + indigo400, + indigo500, + indigo600, + indigo700, + indigo800, + indigo900, + indigoA100, + indigoA200, + indigoA400, + indigoA700, + blue50, + blue100, + blue200, + blue300, + blue400, + blue500, + blue600, + blue700, + blue800, + blue900, + blueA100, + blueA200, + blueA400, + blueA700, + lightBlue50, + lightBlue100, + lightBlue200, + lightBlue300, + lightBlue400, + lightBlue500, + lightBlue600, + lightBlue700, + lightBlue800, + lightBlue900, + lightBlueA100, + lightBlueA200, + lightBlueA400, + lightBlueA700, + cyan50, + cyan100, + cyan200, + cyan300, + cyan400, + cyan500, + cyan600, + cyan700, + cyan800, + cyan900, + cyanA100, + cyanA200, + cyanA400, + cyanA700, + teal50, + teal100, + teal200, + teal300, + teal400, + teal500, + teal600, + teal700, + teal800, + teal900, + tealA100, + tealA200, + tealA400, + tealA700, + green50, + green100, + green200, + green300, + green400, + green500, + green600, + green700, + green800, + green900, + greenA100, + greenA200, + greenA400, + greenA700, + lightGreen50, + lightGreen100, + lightGreen200, + lightGreen300, + lightGreen400, + lightGreen500, + lightGreen600, + lightGreen700, + lightGreen800, + lightGreen900, + lightGreenA100, + lightGreenA200, + lightGreenA400, + lightGreenA700, + lime50, + lime100, + lime200, + lime300, + lime400, + lime500, + lime600, + lime700, + lime800, + lime900, + limeA100, + limeA200, + limeA400, + limeA700, + yellow50, + yellow100, + yellow200, + yellow300, + yellow400, + yellow500, + yellow600, + yellow700, + yellow800, + yellow900, + yellowA100, + yellowA200, + yellowA400, + yellowA700, + amber50, + amber100, + amber200, + amber300, + amber400, + amber500, + amber600, + amber700, + amber800, + amber900, + amberA100, + amberA200, + amberA400, + amberA700, + orange50, + orange100, + orange200, + orange300, + orange400, + orange500, + orange600, + orange700, + orange800, + orange900, + orangeA100, + orangeA200, + orangeA400, + orangeA700, + deepOrange50, + deepOrange100, + deepOrange200, + deepOrange300, + deepOrange400, + deepOrange500, + deepOrange600, + deepOrange700, + deepOrange800, + deepOrange900, + deepOrangeA100, + deepOrangeA200, + deepOrangeA400, + deepOrangeA700, + brown50, + brown100, + brown200, + brown300, + brown400, + brown500, + brown600, + brown700, + brown800, + brown900, + blueGrey50, + blueGrey100, + blueGrey200, + blueGrey300, + blueGrey400, + blueGrey500, + blueGrey600, + blueGrey700, + blueGrey800, + blueGrey900, + grey50, + grey100, + grey200, + grey300, + grey400, + grey500, + grey600, + grey700, + grey800, + grey900, + black, + white, + transparent, + fullBlack, + darkBlack, + lightBlack, + minBlack, + faintBlack, + fullWhite, + darkWhite, + lightWhite +}; +} // namespace Material + +class QtMaterialThemePrivate; + +class QtMaterialTheme : public QObject +{ + Q_OBJECT + +public: + explicit QtMaterialTheme(QObject *parent = 0); + ~QtMaterialTheme(); + + QColor getColor(const QString &key) const; + + void setColor(const QString &key, const QColor &color); + void setColor(const QString &key, Material::Color color); + + static QIcon icon(QString category, QString icon); + +protected: + const QScopedPointer d_ptr; + +private: + Q_DISABLE_COPY(QtMaterialTheme) + Q_DECLARE_PRIVATE(QtMaterialTheme) +}; + +#endif // QTMATERIALTHEME_H diff --git a/components/qtmaterialappbar.h b/include/qmetarial/qtmaterialappbar.h similarity index 97% rename from components/qtmaterialappbar.h rename to include/qmetarial/qtmaterialappbar.h index 4c60564a3..e95879645 100644 --- a/components/qtmaterialappbar.h +++ b/include/qmetarial/qtmaterialappbar.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALAPPBAR_H #define QTMATERIALAPPBAR_H -#include #include +#include class QtMaterialAppBarPrivate; @@ -45,4 +45,4 @@ inline QHBoxLayout *QtMaterialAppBar::appBarLayout() const return static_cast(layout()); } -#endif // QTMATERIALAPPBAR_H +#endif // QTMATERIALAPPBAR_H diff --git a/components/qtmaterialautocomplete.h b/include/qmetarial/qtmaterialautocomplete.h similarity index 95% rename from components/qtmaterialautocomplete.h rename to include/qmetarial/qtmaterialautocomplete.h index 8b4686129..d34505835 100644 --- a/components/qtmaterialautocomplete.h +++ b/include/qmetarial/qtmaterialautocomplete.h @@ -30,4 +30,4 @@ protected slots: Q_DECLARE_PRIVATE(QtMaterialAutoComplete) }; -#endif // QTMATERIALAUTOCOMPLETE_H +#endif // QTMATERIALAUTOCOMPLETE_H diff --git a/components/qtmaterialavatar.h b/include/qmetarial/qtmaterialavatar.h similarity index 97% rename from components/qtmaterialavatar.h rename to include/qmetarial/qtmaterialavatar.h index 9b99ef22f..cd67677b9 100644 --- a/components/qtmaterialavatar.h +++ b/include/qmetarial/qtmaterialavatar.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALAVATAR_H #define QTMATERIALAVATAR_H -#include #include "lib/qtmaterialtheme.h" +#include class QtMaterialAvatarPrivate; @@ -47,4 +47,4 @@ class QtMaterialAvatar : public QWidget Q_DECLARE_PRIVATE(QtMaterialAvatar) }; -#endif // QTMATERIALAVATAR_H +#endif // QTMATERIALAVATAR_H diff --git a/components/qtmaterialbadge.h b/include/qmetarial/qtmaterialbadge.h similarity index 98% rename from components/qtmaterialbadge.h rename to include/qmetarial/qtmaterialbadge.h index deac3ab4b..d4c99398b 100644 --- a/components/qtmaterialbadge.h +++ b/include/qmetarial/qtmaterialbadge.h @@ -58,4 +58,4 @@ class QtMaterialBadge : public QtMaterialOverlayWidget Q_DECLARE_PRIVATE(QtMaterialBadge) }; -#endif // QTMATERIALBADGE_H +#endif // QTMATERIALBADGE_H diff --git a/components/qtmaterialcheckbox.h b/include/qmetarial/qtmaterialcheckbox.h similarity index 92% rename from components/qtmaterialcheckbox.h rename to include/qmetarial/qtmaterialcheckbox.h index 5aaa8f4dc..e3cf2efe2 100644 --- a/components/qtmaterialcheckbox.h +++ b/include/qmetarial/qtmaterialcheckbox.h @@ -18,4 +18,4 @@ class QtMaterialCheckBox : public QtMaterialCheckable Q_DECLARE_PRIVATE(QtMaterialCheckBox) }; -#endif // QTMATERIALCHECKBOX_H +#endif // QTMATERIALCHECKBOX_H diff --git a/components/qtmaterialcircularprogress.h b/include/qmetarial/qtmaterialcircularprogress.h similarity index 96% rename from components/qtmaterialcircularprogress.h rename to include/qmetarial/qtmaterialcircularprogress.h index dfc306e16..b912d7536 100644 --- a/components/qtmaterialcircularprogress.h +++ b/include/qmetarial/qtmaterialcircularprogress.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALCIRCULARPROGRESS_H #define QTMATERIALCIRCULARPROGRESS_H -#include #include "lib/qtmaterialtheme.h" +#include class QtMaterialCircularProgressPrivate; @@ -45,4 +45,4 @@ class QtMaterialCircularProgress : public QProgressBar Q_DECLARE_PRIVATE(QtMaterialCircularProgress) }; -#endif // QTMATERIALCIRCULARPROGRESS_H +#endif // QTMATERIALCIRCULARPROGRESS_H diff --git a/components/qtmaterialdialog.h b/include/qmetarial/qtmaterialdialog.h similarity index 95% rename from components/qtmaterialdialog.h rename to include/qmetarial/qtmaterialdialog.h index 822a5d9f6..08594c4d7 100644 --- a/components/qtmaterialdialog.h +++ b/include/qmetarial/qtmaterialdialog.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALDIALOG_H #define QTMATERIALDIALOG_H -#include #include "lib/qtmaterialoverlaywidget.h" +#include class QLayout; class QtMaterialDialogPrivate; @@ -32,4 +32,4 @@ public slots: Q_DECLARE_PRIVATE(QtMaterialDialog) }; -#endif // QTMATERIALDIALOG_H +#endif // QTMATERIALDIALOG_H diff --git a/components/qtmaterialdrawer.h b/include/qmetarial/qtmaterialdrawer.h similarity index 97% rename from components/qtmaterialdrawer.h rename to include/qmetarial/qtmaterialdrawer.h index 7bf3219a0..5c737a2b4 100644 --- a/components/qtmaterialdrawer.h +++ b/include/qmetarial/qtmaterialdrawer.h @@ -45,4 +45,4 @@ public slots: Q_DECLARE_PRIVATE(QtMaterialDrawer) }; -#endif // QTMATERIALDRAWER_H +#endif // QTMATERIALDRAWER_H diff --git a/components/qtmaterialfab.h b/include/qmetarial/qtmaterialfab.h similarity index 97% rename from components/qtmaterialfab.h rename to include/qmetarial/qtmaterialfab.h index 78838b12b..956b8804a 100644 --- a/components/qtmaterialfab.h +++ b/include/qmetarial/qtmaterialfab.h @@ -40,7 +40,6 @@ class QtMaterialFloatingActionButton : public QtMaterialRaisedButton private: Q_DISABLE_COPY(QtMaterialFloatingActionButton) Q_DECLARE_PRIVATE(QtMaterialFloatingActionButton) - }; -#endif // QTMATERIALFAB_H +#endif // QTMATERIALFAB_H diff --git a/components/qtmaterialflatbutton.h b/include/qmetarial/qtmaterialflatbutton.h similarity index 87% rename from components/qtmaterialflatbutton.h rename to include/qmetarial/qtmaterialflatbutton.h index a74ab6afb..b0d2787be 100644 --- a/components/qtmaterialflatbutton.h +++ b/include/qmetarial/qtmaterialflatbutton.h @@ -1,9 +1,9 @@ #ifndef QTMATERIALFLATBUTTON_H #define QTMATERIALFLATBUTTON_H -#include -#include #include "lib/qtmaterialtheme.h" +#include +#include class QtMaterialFlatButtonPrivate; @@ -21,7 +21,10 @@ class QtMaterialFlatButton : public QPushButton public: explicit QtMaterialFlatButton(QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset); explicit QtMaterialFlatButton(const QString &text, QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset); - QtMaterialFlatButton(const QString &text, Material::Role role, QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset); + QtMaterialFlatButton(const QString &text, + Material::Role role, + QWidget *parent = 0, + Material::ButtonPreset preset = Material::FlatPreset); ~QtMaterialFlatButton(); void applyPreset(Material::ButtonPreset preset); @@ -84,11 +87,11 @@ class QtMaterialFlatButton : public QPushButton QSize sizeHint() const Q_DECL_OVERRIDE; protected: - enum { - IconPadding = 12 - }; + enum { IconPadding = 12 }; - QtMaterialFlatButton(QtMaterialFlatButtonPrivate &d, QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset); + QtMaterialFlatButton(QtMaterialFlatButtonPrivate &d, + QWidget *parent = 0, + Material::ButtonPreset preset = Material::FlatPreset); void checkStateSet() Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; @@ -109,4 +112,4 @@ class QtMaterialFlatButton : public QPushButton Q_DECLARE_PRIVATE(QtMaterialFlatButton) }; -#endif // QTMATERIALFLATBUTTON_H +#endif // QTMATERIALFLATBUTTON_H diff --git a/components/qtmaterialiconbutton.h b/include/qmetarial/qtmaterialiconbutton.h similarity index 96% rename from components/qtmaterialiconbutton.h rename to include/qmetarial/qtmaterialiconbutton.h index 5c2afc47b..09b5b06e2 100644 --- a/components/qtmaterialiconbutton.h +++ b/include/qmetarial/qtmaterialiconbutton.h @@ -39,4 +39,4 @@ class QtMaterialIconButton : public QAbstractButton Q_DECLARE_PRIVATE(QtMaterialIconButton) }; -#endif // QTMATERIALICONBUTTON_H +#endif // QTMATERIALICONBUTTON_H diff --git a/components/qtmateriallist.h b/include/qmetarial/qtmateriallist.h similarity index 100% rename from components/qtmateriallist.h rename to include/qmetarial/qtmateriallist.h diff --git a/components/qtmateriallistitem.h b/include/qmetarial/qtmateriallistitem.h similarity index 100% rename from components/qtmateriallistitem.h rename to include/qmetarial/qtmateriallistitem.h diff --git a/components/qtmaterialmenu.h b/include/qmetarial/qtmaterialmenu.h similarity index 88% rename from components/qtmaterialmenu.h rename to include/qmetarial/qtmaterialmenu.h index beb01b5b9..d745c9747 100644 --- a/components/qtmaterialmenu.h +++ b/include/qmetarial/qtmaterialmenu.h @@ -12,4 +12,4 @@ class QtMaterialMenu : public QWidget ~QtMaterialMenu(); }; -#endif // QTMATERIALMENU_H +#endif // QTMATERIALMENU_H diff --git a/components/qtmaterialpaper.h b/include/qmetarial/qtmaterialpaper.h similarity index 100% rename from components/qtmaterialpaper.h rename to include/qmetarial/qtmaterialpaper.h diff --git a/components/qtmaterialprogress.h b/include/qmetarial/qtmaterialprogress.h similarity index 100% rename from components/qtmaterialprogress.h rename to include/qmetarial/qtmaterialprogress.h diff --git a/components/qtmaterialradiobutton.h b/include/qmetarial/qtmaterialradiobutton.h similarity index 100% rename from components/qtmaterialradiobutton.h rename to include/qmetarial/qtmaterialradiobutton.h diff --git a/components/qtmaterialraisedbutton.h b/include/qmetarial/qtmaterialraisedbutton.h similarity index 94% rename from components/qtmaterialraisedbutton.h rename to include/qmetarial/qtmaterialraisedbutton.h index d8b4ef91e..6eac901e0 100644 --- a/components/qtmaterialraisedbutton.h +++ b/include/qmetarial/qtmaterialraisedbutton.h @@ -24,4 +24,4 @@ class QtMaterialRaisedButton : public QtMaterialFlatButton Q_DECLARE_PRIVATE(QtMaterialRaisedButton) }; -#endif // QTMATERIALRAISEDBUTTON_H +#endif // QTMATERIALRAISEDBUTTON_H diff --git a/components/qtmaterialscrollbar.h b/include/qmetarial/qtmaterialscrollbar.h similarity index 100% rename from components/qtmaterialscrollbar.h rename to include/qmetarial/qtmaterialscrollbar.h diff --git a/components/qtmaterialslider.h b/include/qmetarial/qtmaterialslider.h similarity index 100% rename from components/qtmaterialslider.h rename to include/qmetarial/qtmaterialslider.h diff --git a/components/qtmaterialsnackbar.h b/include/qmetarial/qtmaterialsnackbar.h similarity index 97% rename from components/qtmaterialsnackbar.h rename to include/qmetarial/qtmaterialsnackbar.h index 6d9474001..130ed2889 100644 --- a/components/qtmaterialsnackbar.h +++ b/include/qmetarial/qtmaterialsnackbar.h @@ -54,4 +54,4 @@ protected slots: Q_DECLARE_PRIVATE(QtMaterialSnackbar) }; -#endif // QTMATERIALSNACKBAR_H +#endif // QTMATERIALSNACKBAR_H diff --git a/components/qtmaterialtable.h b/include/qmetarial/qtmaterialtable.h similarity index 100% rename from components/qtmaterialtable.h rename to include/qmetarial/qtmaterialtable.h diff --git a/components/qtmaterialtabs.h b/include/qmetarial/qtmaterialtabs.h similarity index 97% rename from components/qtmaterialtabs.h rename to include/qmetarial/qtmaterialtabs.h index 11a122ee8..34e53f3f0 100644 --- a/components/qtmaterialtabs.h +++ b/include/qmetarial/qtmaterialtabs.h @@ -1,9 +1,9 @@ #ifndef QTMATERIALTABS_H #define QTMATERIALTABS_H -#include -#include #include "lib/qtmaterialtheme.h" +#include +#include class QtMaterialTabsPrivate; class QtMaterialTab; @@ -55,4 +55,4 @@ class QtMaterialTabs : public QWidget Q_DECLARE_PRIVATE(QtMaterialTabs) }; -#endif // QTMATERIALTABS_H +#endif // QTMATERIALTABS_H diff --git a/components/qtmaterialtextfield.h b/include/qmetarial/qtmaterialtextfield.h similarity index 97% rename from components/qtmaterialtextfield.h rename to include/qmetarial/qtmaterialtextfield.h index dead5cc49..d707c8579 100644 --- a/components/qtmaterialtextfield.h +++ b/include/qmetarial/qtmaterialtextfield.h @@ -1,8 +1,8 @@ #ifndef QTMATERIALTEXTFIELD_H #define QTMATERIALTEXTFIELD_H -#include #include +#include class QtMaterialTextFieldPrivate; @@ -58,4 +58,4 @@ class QtMaterialTextField : public QLineEdit Q_DECLARE_PRIVATE(QtMaterialTextField) }; -#endif // QTMATERIALTEXTFIELD_H +#endif // QTMATERIALTEXTFIELD_H diff --git a/components/qtmaterialtoggle.h b/include/qmetarial/qtmaterialtoggle.h similarity index 97% rename from components/qtmaterialtoggle.h rename to include/qmetarial/qtmaterialtoggle.h index 5d5a55701..61138ec95 100644 --- a/components/qtmaterialtoggle.h +++ b/include/qmetarial/qtmaterialtoggle.h @@ -49,4 +49,4 @@ class QtMaterialToggle : public QAbstractButton Q_DECLARE_PRIVATE(QtMaterialToggle) }; -#endif // QTMATERIALTOGGLE_H +#endif // QTMATERIALTOGGLE_H diff --git a/qt-material-widgets.pro b/qt-material-widgets.pro deleted file mode 100644 index 5654f10a8..000000000 --- a/qt-material-widgets.pro +++ /dev/null @@ -1,17 +0,0 @@ -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = qt-material-widgets -TEMPLATE = subdirs -SUBDIRS = components examples -CONFIG += ordered - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which as been marked as deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# 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