├── .clang-tidy ├── .gitignore ├── .travis.yml ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── README.md ├── demo ├── CMakeLists.txt ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h └── mainwindow.ui ├── doc ├── main_page.dox └── qAccordionDoxyfile ├── icons ├── accordion_cc_grey.svg ├── caret-bottom.png ├── caret-right.png ├── noun_111558_cc.svg └── qaccordionicons.qrc ├── include └── qaccordion │ ├── CMakeLists.txt │ ├── clickableframe.hpp │ ├── config.h.in │ ├── contentpane.hpp │ └── qaccordion.hpp └── src ├── CMakeLists.txt ├── clickableframe.cpp ├── contentpane.cpp └── qaccordion.cpp /.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,performance-*,modernize-*,-modernize-use-trailing-return-type,bugprone-*,clang-analyzer-*,misc-*,readability-*,-readability-static-accessed-through-instance,-readability-convert-member-functions-to-static' 3 | WarningsAsErrors: '' 4 | HeaderFilterRegex: '' 5 | AnalyzeTemporaryDtors: false 6 | FormatStyle: none 7 | User: saedelaere 8 | CheckOptions: 9 | - key: bugprone-argument-comment.CommentBoolLiterals 10 | value: '0' 11 | - key: bugprone-argument-comment.CommentCharacterLiterals 12 | value: '0' 13 | - key: bugprone-argument-comment.CommentFloatLiterals 14 | value: '0' 15 | - key: bugprone-argument-comment.CommentIntegerLiterals 16 | value: '0' 17 | - key: bugprone-argument-comment.CommentNullPtrs 18 | value: '0' 19 | - key: bugprone-argument-comment.CommentStringLiterals 20 | value: '0' 21 | - key: bugprone-argument-comment.CommentUserDefinedLiterals 22 | value: '0' 23 | - key: bugprone-argument-comment.IgnoreSingleArgument 24 | value: '0' 25 | - key: bugprone-argument-comment.StrictMode 26 | value: '0' 27 | - key: bugprone-assert-side-effect.AssertMacros 28 | value: assert 29 | - key: bugprone-assert-side-effect.CheckFunctionCalls 30 | value: '0' 31 | - key: bugprone-dangling-handle.HandleClasses 32 | value: 'std::basic_string_view;std::experimental::basic_string_view' 33 | - key: bugprone-dynamic-static-initializers.HeaderFileExtensions 34 | value: ',h,hh,hpp,hxx' 35 | - key: bugprone-exception-escape.FunctionsThatShouldNotThrow 36 | value: '' 37 | - key: bugprone-exception-escape.IgnoredExceptions 38 | value: '' 39 | - key: bugprone-misplaced-widening-cast.CheckImplicitCasts 40 | value: '0' 41 | - key: bugprone-not-null-terminated-result.WantToUseSafeFunctions 42 | value: '1' 43 | - key: bugprone-signed-char-misuse.CharTypdefsToIgnore 44 | value: '' 45 | - key: bugprone-sizeof-expression.WarnOnSizeOfCompareToConstant 46 | value: '1' 47 | - key: bugprone-sizeof-expression.WarnOnSizeOfConstant 48 | value: '1' 49 | - key: bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression 50 | value: '0' 51 | - key: bugprone-sizeof-expression.WarnOnSizeOfThis 52 | value: '1' 53 | - key: bugprone-string-constructor.LargeLengthThreshold 54 | value: '8388608' 55 | - key: bugprone-string-constructor.WarnOnLargeLength 56 | value: '1' 57 | - key: bugprone-suspicious-enum-usage.StrictMode 58 | value: '0' 59 | - key: bugprone-suspicious-missing-comma.MaxConcatenatedTokens 60 | value: '5' 61 | - key: bugprone-suspicious-missing-comma.RatioThreshold 62 | value: '0.200000' 63 | - key: bugprone-suspicious-missing-comma.SizeThreshold 64 | value: '5' 65 | - key: bugprone-suspicious-string-compare.StringCompareLikeFunctions 66 | value: '' 67 | - key: bugprone-suspicious-string-compare.WarnOnImplicitComparison 68 | value: '1' 69 | - key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison 70 | value: '0' 71 | - key: bugprone-too-small-loop-variable.MagnitudeBitsUpperLimit 72 | value: '16' 73 | - key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField 74 | value: '1' 75 | - key: bugprone-unused-return-value.CheckedFunctions 76 | value: '::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique;::std::unique_ptr::release;::std::basic_string::empty;::std::vector::empty' 77 | - key: cert-dcl16-c.NewSuffixes 78 | value: 'L;LL;LU;LLU' 79 | - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField 80 | value: '0' 81 | - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors 82 | value: '1' 83 | - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic 84 | value: '1' 85 | - key: google-readability-braces-around-statements.ShortStatementLines 86 | value: '1' 87 | - key: google-readability-function-size.StatementThreshold 88 | value: '800' 89 | - key: google-readability-namespace-comments.ShortNamespaceLines 90 | value: '10' 91 | - key: google-readability-namespace-comments.SpacesBeforeComments 92 | value: '2' 93 | - key: misc-definitions-in-headers.HeaderFileExtensions 94 | value: ',h,hh,hpp,hxx' 95 | - key: misc-definitions-in-headers.UseHeaderFileExtension 96 | value: '1' 97 | - key: misc-throw-by-value-catch-by-reference.CheckThrowTemporaries 98 | value: '1' 99 | - key: misc-unused-parameters.StrictMode 100 | value: '0' 101 | - key: modernize-loop-convert.MaxCopySize 102 | value: '16' 103 | - key: modernize-loop-convert.MinConfidence 104 | value: reasonable 105 | - key: modernize-loop-convert.NamingStyle 106 | value: CamelCase 107 | - key: modernize-make-shared.IgnoreMacros 108 | value: '1' 109 | - key: modernize-make-shared.IncludeStyle 110 | value: '0' 111 | - key: modernize-make-shared.MakeSmartPtrFunction 112 | value: 'std::make_shared' 113 | - key: modernize-make-shared.MakeSmartPtrFunctionHeader 114 | value: memory 115 | - key: modernize-make-unique.IgnoreMacros 116 | value: '1' 117 | - key: modernize-make-unique.IncludeStyle 118 | value: '0' 119 | - key: modernize-make-unique.MakeSmartPtrFunction 120 | value: 'std::make_unique' 121 | - key: modernize-make-unique.MakeSmartPtrFunctionHeader 122 | value: memory 123 | - key: modernize-pass-by-value.IncludeStyle 124 | value: llvm 125 | - key: modernize-pass-by-value.ValuesOnly 126 | value: '0' 127 | - key: modernize-raw-string-literal.ReplaceShorterLiterals 128 | value: '0' 129 | - key: modernize-replace-auto-ptr.IncludeStyle 130 | value: llvm 131 | - key: modernize-replace-random-shuffle.IncludeStyle 132 | value: llvm 133 | - key: modernize-use-auto.MinTypeNameLength 134 | value: '5' 135 | - key: modernize-use-auto.RemoveStars 136 | value: '0' 137 | - key: modernize-use-default-member-init.IgnoreMacros 138 | value: '1' 139 | - key: modernize-use-default-member-init.UseAssignment 140 | value: '0' 141 | - key: modernize-use-emplace.ContainersWithPushBack 142 | value: '::std::vector;::std::list;::std::deque' 143 | - key: modernize-use-emplace.SmartPointers 144 | value: '::std::shared_ptr;::std::unique_ptr;::std::auto_ptr;::std::weak_ptr' 145 | - key: modernize-use-emplace.TupleMakeFunctions 146 | value: '::std::make_pair;::std::make_tuple' 147 | - key: modernize-use-emplace.TupleTypes 148 | value: '::std::pair;::std::tuple' 149 | - key: modernize-use-equals-default.IgnoreMacros 150 | value: '1' 151 | - key: modernize-use-equals-delete.IgnoreMacros 152 | value: '1' 153 | - key: modernize-use-nodiscard.ReplacementString 154 | value: '[[nodiscard]]' 155 | - key: modernize-use-noexcept.ReplacementString 156 | value: '' 157 | - key: modernize-use-noexcept.UseNoexceptFalse 158 | value: '1' 159 | - key: modernize-use-nullptr.NullMacros 160 | value: 'NULL' 161 | - key: modernize-use-override.AllowOverrideAndFinal 162 | value: '0' 163 | - key: modernize-use-override.FinalSpelling 164 | value: final 165 | - key: modernize-use-override.IgnoreDestructors 166 | value: '0' 167 | - key: modernize-use-override.OverrideSpelling 168 | value: override 169 | - key: modernize-use-transparent-functors.SafeMode 170 | value: '0' 171 | - key: modernize-use-using.IgnoreMacros 172 | value: '1' 173 | - key: performance-faster-string-find.StringLikeClasses 174 | value: 'std::basic_string' 175 | - key: performance-for-range-copy.AllowedTypes 176 | value: '' 177 | - key: performance-for-range-copy.WarnOnAllAutoCopies 178 | value: '0' 179 | - key: performance-inefficient-string-concatenation.StrictMode 180 | value: '0' 181 | - key: performance-inefficient-vector-operation.EnableProto 182 | value: '0' 183 | - key: performance-inefficient-vector-operation.VectorLikeClasses 184 | value: '::std::vector' 185 | - key: performance-move-const-arg.CheckTriviallyCopyableMove 186 | value: '1' 187 | - key: performance-move-constructor-init.IncludeStyle 188 | value: llvm 189 | - key: performance-no-automatic-move.AllowedTypes 190 | value: '' 191 | - key: performance-type-promotion-in-math-fn.IncludeStyle 192 | value: llvm 193 | - key: performance-unnecessary-copy-initialization.AllowedTypes 194 | value: '' 195 | - key: performance-unnecessary-value-param.AllowedTypes 196 | value: '' 197 | - key: performance-unnecessary-value-param.IncludeStyle 198 | value: llvm 199 | - key: readability-braces-around-statements.ShortStatementLines 200 | value: '0' 201 | - key: readability-else-after-return.WarnOnUnfixable 202 | value: '1' 203 | - key: readability-function-size.BranchThreshold 204 | value: '4294967295' 205 | - key: readability-function-size.LineThreshold 206 | value: '4294967295' 207 | - key: readability-function-size.NestingThreshold 208 | value: '4294967295' 209 | - key: readability-function-size.ParameterThreshold 210 | value: '4294967295' 211 | - key: readability-function-size.StatementThreshold 212 | value: '800' 213 | - key: readability-function-size.VariableThreshold 214 | value: '4294967295' 215 | - key: readability-identifier-naming.IgnoreFailedSplit 216 | value: '0' 217 | - key: readability-implicit-bool-conversion.AllowIntegerConditions 218 | value: '0' 219 | - key: readability-implicit-bool-conversion.AllowPointerConditions 220 | value: '0' 221 | - key: readability-inconsistent-declaration-parameter-name.IgnoreMacros 222 | value: '1' 223 | - key: readability-inconsistent-declaration-parameter-name.Strict 224 | value: '0' 225 | - key: readability-magic-numbers.IgnoredFloatingPointValues 226 | value: '1.0;100.0;' 227 | - key: readability-magic-numbers.IgnoredIntegerValues 228 | value: '1;2;3;4;' 229 | - key: readability-redundant-member-init.IgnoreBaseInCopyConstructors 230 | value: '0' 231 | - key: readability-redundant-smartptr-get.IgnoreMacros 232 | value: '1' 233 | - key: readability-redundant-string-init.StringNames 234 | value: '::std::basic_string' 235 | - key: readability-simplify-boolean-expr.ChainedConditionalAssignment 236 | value: '0' 237 | - key: readability-simplify-boolean-expr.ChainedConditionalReturn 238 | value: '0' 239 | - key: readability-simplify-subscript-expr.Types 240 | value: '::std::basic_string;::std::basic_string_view;::std::vector;::std::array' 241 | - key: readability-uppercase-literal-suffix.IgnoreMacros 242 | value: '1' 243 | - key: readability-uppercase-literal-suffix.NewSuffixes 244 | value: '' 245 | ... 246 | 247 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/c++,qt,vim,cmake 2 | 3 | ### C++ ### 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | 22 | # Compiled Static libraries 23 | *.lai 24 | *.la 25 | *.a 26 | *.lib 27 | 28 | # Executables 29 | *.exe 30 | *.out 31 | *.app 32 | 33 | 34 | ### Qt ### 35 | # C++ objects and libs 36 | 37 | *.slo 38 | *.lo 39 | *.o 40 | *.a 41 | *.la 42 | *.lai 43 | *.so 44 | *.dll 45 | *.dylib 46 | 47 | # Qt-es 48 | 49 | /.qmake.cache 50 | /.qmake.stash 51 | *.pro.user 52 | *.pro.user.* 53 | *.qbs.user 54 | *.qbs.user.* 55 | *.moc 56 | moc_*.cpp 57 | qrc_*.cpp 58 | ui_*.h 59 | Makefile* 60 | *-build-* 61 | 62 | # QtCreator 63 | 64 | *.autosave 65 | 66 | #QtCtreator Qml 67 | *.qmlproject.user 68 | *.qmlproject.user.* 69 | 70 | 71 | ### Vim ### 72 | [._]*.s[a-w][a-z] 73 | [._]s[a-w][a-z] 74 | *.un~ 75 | Session.vim 76 | .netrwhist 77 | *~ 78 | 79 | 80 | ### CMake ### 81 | CMakeCache.txt 82 | CMakeFiles 83 | CMakeScripts 84 | Makefile 85 | cmake_install.cmake 86 | install_manifest.txt 87 | 88 | ### Custom ### 89 | 90 | build 91 | CMakeLists.txt.user 92 | doc/html 93 | package 94 | .ycm_extra_conf.py 95 | .lvimrc 96 | .agignore 97 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | matrix: 4 | include: 5 | - os: linux 6 | compiler: gcc 7 | env: COMPILER=g++ 8 | - os: linux 9 | compiler: clang 10 | env: COMPILER=clang++ 11 | #- os: osx 12 | #compiler: clang 13 | #osx_image: xcode6.4 14 | #- os: osx 15 | #compiler: clang 16 | #osx_image: xcode7.3 17 | 18 | #before_install: 19 | # - sudo apt-get update -qq 20 | # - sudo apt-get install -y sfml 21 | 22 | before_install: 23 | # - | 24 | # if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then 25 | # sudo apt-get install mesa-common-dev qtbase5-dev qtconnectivity5-dev -y 26 | # else 27 | # brew update 28 | # brew uninstall --force cmake 29 | # brew install cmake 30 | # brew install qt5 31 | # export PRE_PATH=$(brew --prefix qt5) 32 | # fi 33 | - sudo apt-get install mesa-common-dev qtbase5-dev qtconnectivity5-dev -y 34 | 35 | 36 | script: 37 | - | 38 | cd ${TRAVIS_BUILD_DIR} && pwd 39 | mkdir build 40 | cd build && pwd 41 | cmake -DQACCORDION_BUILD_DEMO=ON -DCMAKE_CXX_COMPILER=$COMPILER ../ 42 | - make 43 | 44 | # blacklist 45 | branches: 46 | except: 47 | - develop 48 | - gh-pages 49 | 50 | #notifications: 51 | # webhooks: 52 | # urls: https://webhooks.gitter.im/e/ 53 | # on_success: change 54 | # 55 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | Christian Rapp - <0x2a@posteo.org> 3 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6 FATAL_ERROR) 2 | project(qAccordion VERSION 0.3) 3 | 4 | option(QACCORDION_BUILD_DEMO OFF) 5 | option(QACCORDION_EXTERNAL OFF) 6 | 7 | # let cmake handle all the export business on windows 8 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) 9 | 10 | add_subdirectory(demo) 11 | add_subdirectory(include/qaccordion) 12 | add_subdirectory(src) 13 | 14 | # use ext_include in parent projects with include directrories. makes sure the 15 | # generated headers are found 16 | if(QACCORDION_EXTERNAL) 17 | set(EXT_INCLUDE ${EXTERNAL_INCLUDE} PARENT_SCOPE) 18 | endif() 19 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # qAccordion 2 | 3 | [![Build Status](https://travis-ci.org/crapp/qaccordion.svg?branch=master)](https://travis-ci.org/crapp/qaccordion) 4 | [![qAccordion license GPL](https://img.shields.io/github/license/crapp/qaccordion.svg)](#license) 5 | [![Latest release](https://img.shields.io/github/release/crapp/qaccordion.svg)](https://github.com/crapp/qaccordion/releases/latest) 6 | 7 | qAccordion provides an accordion widget for Qt 5. The widget is heavily inspired by the [jQuery UI accordion control](https://jqueryui.com/accordion/). 8 | 9 | Watch a screencast made with the [Demo Application](#demo-application) to see what qAccordion is. 10 | 11 | [![qAccordion Demo Screencast](http://i.imgur.com/vLz2dYk.png)](https://www.youtube.com/watch?v=czhRcNdSHw4 "qAccordion Demo Screencast") 12 | 13 | 14 | 15 | 16 | - [Setting up qAccordion](#setting-up-qaccordion) 17 | - [Installation](#installation) 18 | - [Usage](#usage) 19 | - [Bugs and Feature requests](#bugs-and-feature-requests) 20 | - [ToDo](#todo) 21 | - [Development](#development) 22 | - [FAQ](#faq) 23 | - [License](#license) 24 | 25 | 26 | 27 | ## Setting up qAccordion 28 | 29 | qAccordion is based on Qt5 and c++14. Make sure your development environment 30 | meets these requirements: 31 | 32 | * cmake >= 3.6 33 | * gcc >= 5 34 | * clang >= 3.4 35 | * MSVC >= 14 (Visual Studio 2015) 36 | * Qt 5.2 (Qt5Widgets, Qt5Gui, Qt5Core [Qt5Network]) 37 | 38 | To make use of this Qt Widget in your Project you have two choices. 39 | 40 | 1. Use the included CMake project files to compile a shared library which you link 41 | to your application. 42 | 2. Add the source code of the library to your project and compile it. Make sure 43 | to include the icons qrc file 44 | 45 | ## Installation 46 | 47 | Obtain the source code from our [github repository](https://github.com/crapp/qaccordion). 48 | Either download the latest release or use git to check out the master branch. 49 | 50 | ### Linux 51 | Run the following commands to compile a shared library on Linux after you 52 | obtained the source code. 53 | 54 | ```shell 55 | # create a build directory 56 | mkdir build 57 | cd build 58 | # run cmake to create make files. use -DQACCORDION_EXTERNAL=ON if you make use of 59 | # git submodules 60 | cmake -DCMAKE_BUILD_TYPE=RELEASE ../ 61 | # now compile the source code and create the shared library. you can speed up 62 | # compilation with the j option. 63 | make 64 | # optional install the library 65 | sudo make install 66 | ``` 67 | There are ready to use packages for the following Linux distributions: 68 | 69 | * [Archlinux (AUR)](https://aur.archlinux.org/packages/qaccordion/) 70 | 71 | ### Windows 72 | 73 | Compiling the library on Windows is possible with the Microsoft Visual C++ compiler (MinGW is currently __not__ supported). 74 | Generate a Visual Studio Solution with the appropriate cmake generator. After that you can compile the library with the Microsoft IDE. 75 | 76 | ```shell 77 | #create build directory 78 | mkdir build 79 | cd build 80 | # assuming you are using Visual Studio 2013 on a 64bit windows installation and Qt installed to C:\\Qt 81 | # Please change these options so they suit your build evironment. 82 | cmake -G"Visual Studio 12 2013 Win64" -DCMAKE_PREFIX_PATH="C:\\Qt\\5.5\\msvc2013_64" ../ 83 | ``` 84 | Open the solution file and compile the library. 85 | 86 | Another possibility is to use the cmake NMake generator. 87 | 88 | ```shell 89 | #create build directory 90 | mkdir build 91 | cd build 92 | # check the prefix path so it matches your Qt installation 93 | cmake -G"NMake Makefiles" -DCMAKE_PREFIX_PATH="C:\\Qt\\5.5\\msvc2013_64" ../ 94 | # build the library 95 | nmake 96 | ``` 97 | ## Usage 98 | 99 | Using this widget is quite easy. You can add this to your application either programmatically or by using Qt Designer. The widget does __not__ support configuration via the Designer. 100 | 101 | ### A minimum code example 102 | 103 | ```c++ 104 | auto *myAccordion = new QAccordion(); 105 | // add the Accordion to your layout 106 | this->layout()->addWidget(myAccordion); 107 | // add a content pane with a header 108 | int firstPaneIndex = myAccordion->addContentPane("My first content pane"); 109 | // make sure our content pane was added 110 | if (firstPaneIndex != -1) { 111 | // get a QFrame* from the Content Pane. This is where we place our content 112 | auto *contentFrame = myAccordion->getContentPane(firstPaneIndex)->getContentFrame(); 113 | // give the QFrame a QLayout 114 | contentFrame->setLayout(new QVBoxLayout()); 115 | // add a simpel QLabel to the frame 116 | contentFrame->layout()->addWidget(new QLabel("Hello Cute World!!!")); 117 | } 118 | ``` 119 | This would display a Content Pane with the Header _My first content pane_. When you click it, it will expand and you can see the message _Hello Cute World!!!_ 120 | 121 | ### Memory management 122 | 123 | qAccordion makes use of Qt memory management. This means all objects will be freed by Qt when the program is finished. Be aware when you use QAccordion::removeContentPane() you can tell qAccordion to remove the ContentPane object from the layout (and the internal vector) but not to free the allocated memory. This might be useful if you want to add the same ContentPane again at a later time or to another QAccordion widget. If you don't do so, it is up to you to delete the object. 124 | 125 | ### API Documentation 126 | 127 | The library is documented using doxygen style comments. A static HTML version of the API documentation can be found on [github](https://crapp.github.io/qaccordion/). This is the documentation of the latest release. 128 | 129 | The doxygen project file to generate the HTML documents is located in the `doc` folder. Run the following command in a shell to generate your own local HTML documentation so you may read it offline or have an updated documentation for features that are still under development (needs doxygen >= 1.8.6). 130 | 131 | ```shell 132 | doxygen qAccordionDoxyfile 133 | ``` 134 | 135 | ### Demo Application 136 | 137 | In the `demo` folder you can find a demo application that you can build with the library. 138 | You must use the CMake option `QACCORDION_BUILD_DEMO` so it gets compiled. 139 | 140 | Linux example 141 | 142 | ```shell 143 | cd build 144 | cmake -DQACCORDION_BUILD_DEMO=ON ../ 145 | make 146 | ``` 147 | Have a look at the source code of the demo application if you are searching for a more advanced example on how to use this Qt Widget. I have recorded a short video that shows how qAccordion works. 148 | 149 | ## Bugs and Feature requests 150 | 151 | If you find a Bug or have a feature request head over to github and open a new 152 | [issue](https://github.com/crapp/qaccordion/issues). 153 | 154 | ## ToDo ## 155 | * Drag and Drop support. The API already supports moving Content Panes but only programmatically. 156 | * User defined Icons and Icon position. 157 | * Definable animation type. 158 | * Trigger open / close not only on single mouse click (e.g. double click, mouse over). 159 | 160 | ## Development 161 | 162 | Brief overview over the development process of qAccordion. 163 | 164 | ### Repositories 165 | The github repository of qAccordion has several different branches. 166 | 167 | * master: Main development branch. Everything in here is guaranteed to compile and is tested (at least a little bit :)). This is the place for new features and bugfixes. Pull requests welcome. 168 | * develop: Test branch. Code should compile on the developers build environment. Nothing more nothing less. 169 | * release-x.x: Branch for a release. Only bugfixes are allowed here. Pull requests welcome. 170 | * gh-pages: Special branch for the static HTML documentation that will be hosted by github.io. Content is generated by doxygen. 171 | 172 | ### Coding standards 173 | 174 | The source code is formatted with clang-format using the following configuration 175 | 176 | ``` 177 | Language: Cpp, 178 | BasedOnStyle: LLVM, 179 | AccessModifierOffset: -4, 180 | AllowShortIfStatementsOnASingleLine: false, 181 | AlwaysBreakTemplateDeclarations: true, 182 | ColumnLimit: 81, 183 | IndentCaseLabels: false, 184 | Standard: Cpp11, 185 | IndentWidth: 4, 186 | TabWidth: 4, 187 | BreakBeforeBraces: Linux, 188 | CommentPragmas: '(^ IWYU pragma: )|(^.*\[.*\]\(.*\).*$)|(^.*@brief|@param|@return|@throw.*$)|(/\*\*<.*\*/)' 189 | ``` 190 | 191 | ### Static code analysis 192 | 193 | Static code analysis is important for diagnosing and fixing typical programming 194 | errors, like style violations, interface misuse, or bugs that can be deduced via 195 | static analysis. I am using `clang-tidy` to check the source code. This is done 196 | by `cmake` during compilation. 197 | 198 | This is the configuration that is used during qAccordion development 199 | `clang-tidy --checks="-*,performance-*,modernize-*,-modernize-use-trailing-return-type,bugprone-*,clang-analyzer-*,misc-*,readability-*,-readability-static-accessed-through-instance,-readability-convert-member-functions-to-static" --dump-config > .clang-tidy` 200 | 201 | cmake >= 3.6 offers the option `CMAKE_CXX_CLANG_TIDY`. With this option one can 202 | configure clang-tidy and enable specific checks. 203 | 204 | `CMAKE_CXX_CLANG_TIDY:STRING="clang-tidy"` 205 | 206 | ### Versioning 207 | 208 | Somehow every developer faces the problem of version numbers. I decided to use [semantic versioning](http://semver.org/) and stick to their rules. 209 | 210 | > Given a version number MAJOR.MINOR.PATCH, increment the: 211 | > 212 | > 1. MAJOR version when you make incompatible API changes, 213 | > 214 | > 2. MINOR version when you add functionality in a backwards-compatible manner, and 215 | > 216 | > 3. PATCH version when you make backwards-compatible bug fixes. 217 | 218 | We are currently at this stage 219 | 220 | > Major version zero (0.y.z) is for initial development. Anything may change at 221 | > any time. The public API should not be considered stable. 222 | 223 | ## FAQ ## 224 | 225 | **Why does it not have feature X?** 226 | 227 | Feel free to fork the project and do a pull request! 228 | 229 | ## License 230 | ``` 231 | Copyright (C) 2015, 2017, 2020 Christian Rapp 232 | 233 | This program is free software: you can redistribute it and/or modify 234 | it under the terms of the GNU General Public License as published by 235 | the Free Software Foundation, either version 3 of the License, or 236 | (at your option) any later version. 237 | 238 | This program is distributed in the hope that it will be useful, 239 | but WITHOUT ANY WARRANTY; without even the implied warranty of 240 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 241 | GNU General Public License for more details. 242 | 243 | You should have received a copy of the GNU General Public License 244 | along with this program. If not, see . 245 | ``` 246 | -------------------------------------------------------------------------------- /demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(DEMO_UI 2 | ${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.ui 3 | PARENT_SCOPE 4 | ) 5 | 6 | set(DEMO_HEADER 7 | ${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.h 8 | PARENT_SCOPE 9 | ) 10 | set(DEMO_SOURCE 11 | ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp 12 | ${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.cpp 13 | PARENT_SCOPE 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /demo/main.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of qAccordion. An Accordion widget for Qt 2 | // Copyright © 2015, 2017, 2020 Christian Rapp <0x2a at posteo dot org> 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #include 18 | #include 19 | 20 | #include "mainwindow.h" 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | QApplication qAccordionDemo(argc, argv); 25 | QCoreApplication::setOrganizationName("crappbytes"); 26 | QCoreApplication::setOrganizationDomain("crappbytes.org"); 27 | QCoreApplication::setApplicationName("qAccordion Demo"); 28 | 29 | MainWindow mw; 30 | mw.show(); 31 | 32 | return qAccordionDemo.exec(); 33 | } 34 | -------------------------------------------------------------------------------- /demo/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of qAccordion. An Accordion widget for Qt 2 | // Copyright © 2015, 2017, 2020 Christian Rapp <0x2a at posteo dot org> 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #include "mainwindow.h" 18 | #include "ui_mainwindow.h" 19 | 20 | MainWindow::MainWindow(QWidget *parent) 21 | : QMainWindow(parent), ui(new Ui::MainWindow) 22 | { 23 | ui->setupUi(this); 24 | 25 | // create a network access manager object to get some lorem ipsum :) 26 | this->networkManager = std::make_unique(); 27 | QObject::connect(this->networkManager.get(), 28 | &QNetworkAccessManager::finished, this, 29 | &MainWindow::networkRequestFinished); 30 | 31 | // the demo qaccordion. The Accordion will be added programmatically 32 | auto *groupboxDemo = new QGroupBox(); 33 | groupboxDemo->setTitle("Demo Accordion"); 34 | groupboxDemo->setLayout(new QVBoxLayout()); 35 | ui->verticalLayout->insertWidget(0, groupboxDemo); 36 | auto *scrollAreaTop = new QScrollArea(); 37 | groupboxDemo->layout()->addWidget(scrollAreaTop); 38 | auto *topAccordion = new QAccordion(); 39 | scrollAreaTop->setWidget(topAccordion); 40 | // if you are using a QScrollArea you have to tell it that the qaccrdion 41 | // widget is resizable 42 | scrollAreaTop->setWidgetResizable(true); 43 | 44 | // the control accordion. The Accordion was added with the Qt Designer 45 | // Add 4 Content Panes for Add / Insert / Remove / move operations 46 | this->contentPaneAdd(topAccordion); 47 | this->contentPaneInsert(topAccordion); 48 | this->contentPaneRemove(topAccordion); 49 | this->contentPaneMove(topAccordion); 50 | } 51 | 52 | MainWindow::~MainWindow() { delete ui; } 53 | 54 | void MainWindow::networkRequestFinished(QNetworkReply *reply) 55 | { 56 | QLabel *ipsumLabel = this->labelIpsumQueue.front(); 57 | this->labelIpsumQueue.pop(); 58 | ipsumLabel->setTextFormat(Qt::TextFormat::RichText); 59 | ipsumLabel->setWordWrap(true); 60 | // use local ipsum if networkrequest failed 61 | if (reply->error() == QNetworkReply::NetworkError::NoError) { 62 | QByteArray data = reply->readAll(); 63 | ipsumLabel->setText(QString(data)); 64 | } else { 65 | qDebug() << Q_FUNC_INFO << "Network error: " << reply->error() << "\n" 66 | << reply->errorString(); 67 | ipsumLabel->setText(this->offlineIpsum); 68 | } 69 | reply->deleteLater(); 70 | } 71 | 72 | void MainWindow::contentPaneAdd(QAccordion *topAccordion) 73 | { 74 | ui->widgetControlAccordion->setCollapsible(false); 75 | // good pratice is to check the return value of addContentPane. see the API 76 | // Reference for more details 77 | int indexAddPane = ui->widgetControlAccordion->addContentPane("Add Pane"); 78 | 79 | // Get the content frame 80 | this->addCF = ui->widgetControlAccordion->getContentPane(indexAddPane) 81 | ->getContentFrame(); 82 | // Add controls 83 | this->addCF->setLayout(new QVBoxLayout()); 84 | this->addCF->layout()->addWidget( 85 | new QLabel("Add a new Content Pane with the provided Header")); 86 | auto *headerName = new QLineEdit(); 87 | headerName->setPlaceholderText("Header name"); 88 | this->addCF->layout()->addWidget(headerName); 89 | auto *addPaneButton = new QPushButton("Add Content Pane"); 90 | // use a lambda as slot 91 | QObject::connect(addPaneButton, &QPushButton::clicked, [this, topAccordion, 92 | headerName]() { 93 | if (headerName->text() != "") { 94 | // create a QFrame that acts as content frame for a new content pane 95 | auto *frame = new QFrame(); 96 | // add a new content pane with the provided header and the content 97 | // frame 98 | int idx = topAccordion->addContentPane(headerName->text(), frame); 99 | if (idx != -1) { 100 | this->createIpsumLabel(frame); 101 | } else { 102 | this->statusBar()->showMessage( 103 | "Content Pane \"" + headerName->text() + "\" already exists", 104 | 3000); 105 | // if a pane with chosen header already exists we need to delete 106 | // the QFrame 107 | delete frame; 108 | } 109 | } 110 | }); 111 | this->addCF->layout()->addWidget(addPaneButton); 112 | } 113 | 114 | void MainWindow::contentPaneInsert(QAccordion *topAccordion) 115 | { 116 | int indexInsertPane = 117 | ui->widgetControlAccordion->addContentPane("Insert Pane"); 118 | 119 | // insert content pane 120 | this->insertCF = ui->widgetControlAccordion->getContentPane(indexInsertPane) 121 | ->getContentFrame(); 122 | this->insertCF->setLayout(new QVBoxLayout()); 123 | this->insertCF->layout()->addWidget(new QLabel( 124 | "Insert a new content pane by providing a Header and a Position")); 125 | 126 | auto *headerPosition = new QHBoxLayout(); 127 | dynamic_cast(this->insertCF->layout()) 128 | ->addLayout(headerPosition); 129 | auto *headerName = new QLineEdit(); 130 | headerName->setPlaceholderText("Header name"); 131 | headerPosition->addWidget(headerName); 132 | auto *position = new QComboBox(); 133 | // inserting at 0 is always possible. 134 | position->addItem("Position 0", QVariant(0)); 135 | QObject::connect(topAccordion, &QAccordion::numberOfContentPanesChanged, 136 | [position](int number) { 137 | position->clear(); 138 | for (int i = 0; i <= number; i++) { 139 | position->addItem("Position " + QString::number(i), 140 | QVariant(i)); 141 | } 142 | }); 143 | headerPosition->layout()->addWidget(position); 144 | 145 | auto *insertPaneButton = new QPushButton("Insert Content Pane"); 146 | this->insertCF->layout()->addWidget(insertPaneButton); 147 | QObject::connect( 148 | insertPaneButton, &QPushButton::clicked, 149 | [headerName, position, topAccordion, this]() { 150 | if (headerName->text() != "") { 151 | // create a QFrame that acts as content frame for a 152 | // new content pane 153 | auto *frame = new QFrame(); 154 | // add a new content pane with the provided header 155 | // and the content frame 156 | bool status = topAccordion->insertContentPane( 157 | position->currentData().toUInt(), headerName->text(), frame); 158 | if (status) { 159 | this->createIpsumLabel(frame); 160 | } else { 161 | this->statusBar()->showMessage("Content Pane \"" + 162 | headerName->text() + 163 | "\" already exists", 164 | 3000); 165 | // if a pane with chosen header already exists we need to 166 | // delete the QFrame 167 | delete frame; 168 | } 169 | } 170 | }); 171 | } 172 | 173 | void MainWindow::contentPaneRemove(QAccordion *topAccordion) 174 | { 175 | int indexRemovePane = 176 | ui->widgetControlAccordion->addContentPane("Remove Pane"); 177 | 178 | this->removeCF = ui->widgetControlAccordion->getContentPane(indexRemovePane) 179 | ->getContentFrame(); 180 | this->removeCF->setLayout(new QVBoxLayout()); 181 | this->removeCF->layout()->addWidget( 182 | new QLabel("Remove a content pane by providing the Header")); 183 | auto *headerName = new QLineEdit(); 184 | headerName->setPlaceholderText("Header name"); 185 | this->removeCF->layout()->addWidget(headerName); 186 | auto *removePaneButton = new QPushButton("Remove Content Pane"); 187 | this->removeCF->layout()->addWidget(removePaneButton); 188 | QObject::connect(removePaneButton, &QPushButton::clicked, [headerName, 189 | topAccordion, 190 | this]() { 191 | if (headerName->text() != "") { 192 | bool status = 193 | topAccordion->removeContentPane(true, headerName->text()); 194 | if (status) { 195 | this->statusBar()->showMessage( 196 | "Content Pane \"" + headerName->text() + "\" removed", 3000); 197 | } else { 198 | this->statusBar()->showMessage( 199 | "Content Pane \"" + headerName->text() + "\" does not exist", 200 | 3000); 201 | } 202 | } 203 | }); 204 | } 205 | 206 | void MainWindow::contentPaneMove(QAccordion *topAccordion) 207 | { 208 | int indexMoveContentP = 209 | ui->widgetControlAccordion->addContentPane("Move Pane"); 210 | 211 | this->moveCF = ui->widgetControlAccordion->getContentPane(indexMoveContentP) 212 | ->getContentFrame(); 213 | this->moveCF->setLayout(new QVBoxLayout()); 214 | this->moveCF->layout()->addWidget( 215 | new QLabel("Move a content pane to another position")); 216 | auto *fromToCombos = new QHBoxLayout(); 217 | dynamic_cast(this->moveCF->layout())->addLayout(fromToCombos); 218 | auto *fromBox = new QComboBox(); 219 | auto *toBox = new QComboBox(); 220 | fromToCombos->addWidget(fromBox); 221 | fromToCombos->addWidget(toBox); 222 | 223 | auto *movePaneButton = new QPushButton("Move Content Pane"); 224 | movePaneButton->setDisabled(true); 225 | this->moveCF->layout()->addWidget(movePaneButton); 226 | 227 | QObject::connect(topAccordion, &QAccordion::numberOfContentPanesChanged, 228 | [fromBox, toBox, movePaneButton](int number) { 229 | fromBox->clear(); 230 | toBox->clear(); 231 | if (number <= 1) { 232 | movePaneButton->setDisabled(true); 233 | return; 234 | } 235 | for (int i = 0; i < number; i++) { 236 | QString label = "Position " + QString::number(i); 237 | fromBox->addItem(label, QVariant(i)); 238 | toBox->addItem(label, QVariant(i)); 239 | } 240 | movePaneButton->setDisabled(false); 241 | }); 242 | 243 | QObject::connect(movePaneButton, &QPushButton::clicked, [topAccordion, 244 | fromBox, toBox, 245 | this]() { 246 | if (fromBox->currentData().toInt() != toBox->currentData().toInt()) { 247 | bool status = topAccordion->moveContentPane( 248 | fromBox->currentData().toUInt(), toBox->currentData().toUInt()); 249 | if (status) { 250 | this->statusBar()->showMessage( 251 | "Content Pane moved from index " + 252 | fromBox->currentData().toString() + " to " + 253 | toBox->currentData().toString(), 254 | 3000); 255 | } else { 256 | this->statusBar()->showMessage( 257 | "Can not move Content Pane from index " + 258 | fromBox->currentData().toString() + " to " + 259 | toBox->currentData().toString(), 260 | 3000); 261 | } 262 | } 263 | }); 264 | } 265 | 266 | void MainWindow::createIpsumLabel(QFrame *frame) 267 | { 268 | // add some basic stuff to our QFrame 269 | frame->setLayout(new QVBoxLayout()); 270 | auto *ipsumLabel = new QLabel(); 271 | frame->layout()->addWidget(ipsumLabel); 272 | this->labelIpsumQueue.push(ipsumLabel); 273 | dynamic_cast(frame->layout())->addStretch(); 274 | // make the network request 275 | QNetworkRequest rquest; 276 | rquest.setUrl(QUrl(this->ipsumApi)); 277 | rquest.setRawHeader("Accept", "text/html"); 278 | rquest.setRawHeader("Connection", "Keep-Alive"); 279 | this->networkManager->get(rquest); 280 | } 281 | -------------------------------------------------------------------------------- /demo/mainwindow.h: -------------------------------------------------------------------------------- 1 | // This file is part of qAccordion. An Accordion widget for Qt 2 | // Copyright © 2015, 2017, 2020 Christian Rapp <0x2a at posteo dot org> 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #ifndef MAINWINDOW_H 18 | #define MAINWINDOW_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include "qaccordion/qaccordion.hpp" 34 | 35 | namespace Ui 36 | { 37 | class MainWindow; 38 | } 39 | 40 | class MainWindow : public QMainWindow 41 | { 42 | Q_OBJECT 43 | 44 | public: 45 | explicit MainWindow(QWidget *parent = nullptr); 46 | ~MainWindow() override; 47 | 48 | private: 49 | // lorem ipsum api url 50 | const char *const ipsumApi = "https://loripsum.net/api/1/short/code"; 51 | // a random offline ipsum in case there is no network connection 52 | const char *const offlineIpsum = 53 | "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed plane " 54 | "dicit quod intellegit. Aufert enim sensus actionemque tollit omnem. " 55 | "Itaque ab his ordiamur. Restatis igitur vos;

" 56 | "
"
57 |         "Quod enim vituperabile est per se ipsum, id eo ipso vitium"
58 |         "nominatum puto, vel etiam a vitio dictum vituperari."
59 |         "Qui autem esse poteris, nisi te amor ipse ceperit?"
60 |         "
"; 61 | 62 | Ui::MainWindow *ui; 63 | // Keep pointers to our contetn frames 64 | QFrame *addCF; 65 | QFrame *insertCF; 66 | QFrame *removeCF; 67 | QFrame *moveCF; 68 | 69 | std::unique_ptr networkManager; /**< Network manager 70 | for ipsum api 71 | requests.*/ 72 | std::queue labelIpsumQueue; 73 | 74 | void networkRequestFinished(QNetworkReply *reply); 75 | 76 | void contentPaneAdd(QAccordion *topAccordion); 77 | void contentPaneInsert(QAccordion *topAccordion); 78 | void contentPaneRemove(QAccordion *topAccordion); 79 | void contentPaneMove(QAccordion *topAccordion); 80 | 81 | void createIpsumLabel(QFrame *frame); 82 | }; 83 | 84 | #endif // MAINWINDOW_H 85 | -------------------------------------------------------------------------------- /demo/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 900 10 | 635 11 | 12 | 13 | 14 | qAccordion Demo 15 | 16 | 17 | 18 | :/qAccordionIcons/accordion_cc_grey.svg:/qAccordionIcons/accordion_cc_grey.svg 19 | 20 | 21 | 22 | 23 | 24 | true 25 | 26 | 27 | 28 | 29 | 30 | 31 | Control Accordion 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 46 | 0 47 | 900 48 | 23 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | QAccordion 57 | QWidget 58 |
qaccordion/qaccordion.hpp
59 | 1 60 |
61 |
62 | 63 | 64 | 65 | 66 |
67 | -------------------------------------------------------------------------------- /doc/main_page.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @mainpage qAccordion - Cute Accordion redefined 3 | * 4 | * qAccordion provides an accordion widget for Qt 5. The widget is heavily 5 | * inspired by the [jQuery UI accordion control](https://jqueryui.com/accordion/). 6 | * 7 | * ## Dependencies 8 | * 9 | * This widget is for Qt 5 only. I highly recommend cmake for building it. 10 | * 11 | * ## Setting up qAccordion 12 | * 13 | * Using qAccordion in your project is possible in two ways. 14 | * 1. Add the source code to your project and use it directly. 15 | * 2. Compile a shared library using cmake and link your application with it. 16 | * 17 | * ## Usage 18 | * 19 | * You can add this widget to a GUI via the Qt Designer or programmatically but 20 | * you can not use the Designer to configure the widget. 21 | * 22 | * A simple usage example can be found in the README. A more detailed approach is 23 | * used in the demo application located in the test folder. 24 | * 25 | * ## License 26 | * 27 | * Copyright (C) 2015, 2017, 2020 Christian Rapp 28 | * 29 | * This program is free software: you can redistribute it and/or modify 30 | * it under the terms of the GNU General Public License as published by 31 | * the Free Software Foundation, either version 3 of the License, or 32 | * (at your option) any later version. 33 | * 34 | * This program is distributed in the hope that it will be useful, 35 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | * GNU General Public License for more details. 38 | * 39 | * You should have received a copy of the GNU General Public License 40 | * along with this program. If not, see . 41 | * 42 | */ 43 | -------------------------------------------------------------------------------- /icons/accordion_cc_grey.svg: -------------------------------------------------------------------------------- 1 | 2 | image/svg+xml -------------------------------------------------------------------------------- /icons/caret-bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crapp/qaccordion/9fcafc27a8ade4b4c7cf6358f38bf2ce9fea98fe/icons/caret-bottom.png -------------------------------------------------------------------------------- /icons/caret-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crapp/qaccordion/9fcafc27a8ade4b4c7cf6358f38bf2ce9fea98fe/icons/caret-right.png -------------------------------------------------------------------------------- /icons/noun_111558_cc.svg: -------------------------------------------------------------------------------- 1 | Created by Creative Stallfrom the Noun Project -------------------------------------------------------------------------------- /icons/qaccordionicons.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | caret-bottom.png 4 | caret-right.png 5 | accordion_cc_grey.svg 6 | 7 | 8 | -------------------------------------------------------------------------------- /include/qaccordion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (QACCORDION_HEADER 2 | "${CMAKE_CURRENT_SOURCE_DIR}/clickableframe.hpp" 3 | "${CMAKE_CURRENT_SOURCE_DIR}/contentpane.hpp" 4 | "${CMAKE_CURRENT_SOURCE_DIR}/qaccordion.hpp" 5 | PARENT_SCOPE 6 | ) 7 | -------------------------------------------------------------------------------- /include/qaccordion/clickableframe.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of qAccordion. An Accordion widget for Qt 2 | // Copyright © 2015, 2017, 2020 Christian Rapp <0x2a at posteo dot org> 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #ifndef CLICKABLEFRAME_HPP 18 | #define CLICKABLEFRAME_HPP 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "qaccordion_config.hpp" 29 | 30 | /** 31 | * @brief The ClickableFrame class 32 | * 33 | * This class represents a clickable QFrame. It is used by a ContentPane. The 34 | * class is used internally. 35 | */ 36 | class ClickableFrame : public QFrame 37 | { 38 | Q_OBJECT 39 | public: 40 | enum class ICON_POSITION { LEFT, RIGHT }; 41 | enum class TRIGGER { NONE, SINGLECLICK, DOUBLECLICK, MOUSEOVER }; 42 | 43 | const char *const CARRET_ICON_CLOSED = 44 | ":/qAccordionIcons/caret-right.png"; /**< Qt qrc "path" for the closed icon */ 45 | const char *const CARRET_ICON_OPENED = 46 | ":/qAccordionIcons/caret-bottom.png"; /**< Qt qrc "path" for the opened icon */ 47 | 48 | /** 49 | * @brief ClickableFrame constructor 50 | * @param header Header of the frame 51 | * @param parent Parent widget or 0 52 | * @param f Qt::WindowFlags 53 | */ 54 | explicit ClickableFrame(QString header, QWidget *parent = nullptr, 55 | Qt::WindowFlags f = Qt::Widget); 56 | 57 | // TODO: Expose this function to the ContentPane api 58 | /** 59 | * @brief Change header trigger 60 | * @param tr 61 | * 62 | * @details 63 | * Set the trigger for the header. You may choose between single or double 64 | * mouseclick and mouse enter event. Or ClickableFrame::TRIGGER::NONE if you 65 | * want no interaction at all (you may still trigger the header 66 | * programmatically though). 67 | */ 68 | void setTrigger(TRIGGER tr); 69 | /** 70 | * @brief Get the the trigger of the header 71 | * @return ClickableFrame::TRIGGER 72 | */ 73 | TRIGGER getTrigger(); 74 | 75 | /** 76 | * @brief Set the header string 77 | * @param header 78 | */ 79 | void setHeader(QString header); 80 | /** 81 | * @brief Get the header string 82 | * @return QString 83 | */ 84 | QString getHeader(); 85 | /** 86 | * @brief Set the default stylesheet 87 | * @param stylesheet 88 | */ 89 | void setNormalStylesheet(QString stylesheet); 90 | /** 91 | * @brief Get the default stylesheet 92 | * @return QString 93 | */ 94 | QString getNormalStylesheet(); 95 | /** 96 | * @brief Set mouseover stylesheet 97 | * @param stylesheet 98 | */ 99 | void setHoverStylesheet(QString stylesheet); 100 | /** 101 | * @brief Get mouseover stylesheet 102 | * @return 103 | */ 104 | QString getHoverStylesheet(); 105 | 106 | signals: 107 | /** 108 | * @brief Signal that is emitted when the header is triggered 109 | * @param pos Currently unused 110 | */ 111 | void triggered(QPoint pos); 112 | 113 | public slots: 114 | 115 | /** 116 | * @brief Set the header icon 117 | * @param icon 118 | * 119 | * @details 120 | * ContentPane will set an icon depending on its state (active or not). 121 | */ 122 | void setIcon(const QPixmap &icon); 123 | 124 | /** 125 | * @brief Set icon position 126 | * @param pos 127 | */ 128 | //void setIconPosition(ClickableFrame::ICON_POSITION pos); 129 | 130 | private: 131 | QLabel *iconLabel; 132 | QLabel *nameLabel; 133 | 134 | QString hoverStylesheet; 135 | QString normalStylesheet; 136 | 137 | QString header; 138 | QString tooltip; 139 | 140 | TRIGGER headerTrigger; 141 | 142 | void initFrame(); 143 | 144 | protected: 145 | /** 146 | * @brief Reimplemented function to QMouseEvents 147 | * @param event 148 | */ 149 | void mousePressEvent(QMouseEvent *event) override; 150 | void mouseDoubleClickEvent(QMouseEvent *event) override; 151 | 152 | /** 153 | * @brief Enter event for mouse over effects. 154 | * @param event 155 | */ 156 | void enterEvent(QEvent *event) override; 157 | /** 158 | * @brief Leave effect for mouse over effects. 159 | * @param event 160 | */ 161 | void leaveEvent(QEvent *event) override; 162 | }; 163 | 164 | #endif // CLICKABLEFRAME_HPP 165 | -------------------------------------------------------------------------------- /include/qaccordion/config.h.in: -------------------------------------------------------------------------------- 1 | // This file is part of qAccordion. An Accordion widget for Qt 2 | // Copyright © 2015, 2017, 2020 Christian Rapp <0x2a at posteo dot org> 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #ifndef QACCORDION_CONFIG_H_IN 18 | #define QACCORDION_CONFIG_H_IN 19 | 20 | #define VERSION_MAJOR "@qAccordion_VERSION_MAJOR@" 21 | #define VERSION_MINOR "@qAccordion_VERSION_MINOR@" 22 | #define VERSION_PATCH "@qAccordion_VERSION_PATCH@" 23 | 24 | #ifdef __GNUC__ 25 | #define ATTR_UNUSED __attribute__((unused)) 26 | #else 27 | #define ATTR_UNUSED 28 | #endif 29 | 30 | #endif // QACCORDION_CONFIG_H_IN 31 | -------------------------------------------------------------------------------- /include/qaccordion/contentpane.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of qAccordion. An Accordion widget for Qt 2 | // Copyright © 2015, 2017, 2020 Christian Rapp <0x2a at posteo dot org> 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #ifndef CONTENTPANE_HPP 18 | #define CONTENTPANE_HPP 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include "qaccordion_config.hpp" 32 | 33 | #include "clickableframe.hpp" 34 | // #include "qaccordion.hpp" 35 | 36 | /** 37 | * @brief Content Pane class 38 | * 39 | * @details 40 | * Content Panes are part of a QAccordion object. They represent a clickable 41 | * Header and can be expanded or retracted. 42 | * 43 | * When a ContentPane is created you have to provide a Header (ContentPane(QString, QWidget*)) 44 | * and, if you want, a QFrame* (ContentPane(QString, QFrame*, QWidget*)) with the 45 | * content that should be displayed when the ContentPane is expanded. 46 | * 47 | * Managing the content is pretty straight forward use getContentFrame() and setContentFrame() 48 | * to manage the content. You are absolutely free to do anything what you like with 49 | * this QFrame. Just keep in mind there is a maximumHeight for the container in which 50 | * the content frame is placed (currently 150). If your content exceeds this height 51 | * you have to either increase it with setMaximumHeight() or add a [QScrollArea](http://doc.qt.io/qt-5/qscrollarea.html) 52 | * to the content frame. You may use setContainerFrameStyle() to change the frame 53 | * style of the container. 54 | * 55 | * The Header can be changed after the creation of the ContentPane with setHeader(). 56 | * Additionally you can set a tooltip, a standard stylesheet and a mouseover 57 | * stylesheet, the frame style and the icons. 58 | * @sa 59 | * setHeaderTooltip(), setHeaderStylesheet(), setHeaderHoverStylesheet(), 60 | * setHeaderFrameStyle(), setHeaderIconActive(), setHeaderIconInActive() 61 | * 62 | * @details 63 | * The animation speed is influenceable setAnimationDuration(). 64 | */ 65 | class ContentPane : public QWidget 66 | { 67 | Q_OBJECT 68 | public: 69 | /** 70 | * @brief ContentPane constructor 71 | * @param header The Header of the content pane 72 | * @param parent Parent widget or 0 73 | */ 74 | explicit ContentPane(QString header, QWidget *parent = nullptr); 75 | /** 76 | * @brief ContentPane constructor 77 | * @param header The Header of the content pane 78 | * @param content Content to display when expanded 79 | * @param parent Parent widget or 0 80 | */ 81 | explicit ContentPane(QString header, QFrame *content, QWidget *parent = nullptr); 82 | 83 | /** 84 | * @brief Check if this Content pane is active 85 | * @return boolean True if active 86 | */ 87 | bool getActive() const; 88 | 89 | /** 90 | * @brief Get the content frame of the content pane 91 | * @return QFrame* 92 | * 93 | * @details 94 | * Use this method to get a pointer to a QFrame where you can place 95 | * your content. The widget lifetime is managed by qAccordion. 96 | */ 97 | QFrame *getContentFrame(); 98 | /** 99 | * @brief Set the content frame 100 | * @param content QFrame* with your content 101 | * 102 | * Set / change the content frame of this content pane with \p content. The 103 | * lifecycle 104 | */ 105 | void setContentFrame(QFrame *content); 106 | 107 | /** 108 | * @brief Get the maximum height of the content pane container frame 109 | * @return int 110 | */ 111 | int getMaximumHeight(); 112 | /** 113 | * @brief Set the maximum height of the content pane container. 114 | * @param maxHeight 115 | * 116 | * @details 117 | * Every content pane has a container frame that defines the visible maximum 118 | * height. With this function you can change this setting. 119 | * 120 | @note 121 | * This setting does not set the maximum height of the content frame. It is 122 | * the users responsibilty to make sure everything in the content frame is 123 | * visible. This can be influenced by either changing the maximum height of the 124 | * container or for example by adding a [QScrollArea](http://doc.qt.io/qt-5.5/qscrollarea.html). 125 | */ 126 | void setMaximumHeight(int maxHeight); 127 | 128 | void setTrigger(ClickableFrame::TRIGGER tr); 129 | ClickableFrame::TRIGGER getTrigger(); 130 | 131 | /** 132 | * @brief Set the header of the content pane 133 | * @param header 134 | */ 135 | void setHeader(QString header); 136 | /** 137 | * @brief Return the header of the content pane 138 | * @return QString 139 | */ 140 | QString getHeader(); 141 | /** 142 | * @brief Set the header icon that will be displayed when the content pane is active 143 | * @param icon Path to image 144 | * 145 | * @details 146 | * Set the header icon for active content pane state. Provide a path to a 147 | * supported image file. If the file does not exist or has an unsupported 148 | * format the icon will not be changed. 149 | * @sa 150 | * Supported [image formats](http://doc.qt.io/qt-5/qimagereader.html#supportedImageFormats) by QImageReader. 151 | */ 152 | void setHeaderIconActive(const QString &icon); 153 | /** 154 | * @brief Set the header icon that will be displayed when the content pane is active 155 | * @param icon QPixmap that should be used 156 | * 157 | * @details 158 | * This is an overloaded method of setHeaderIconActive(QString), which allows 159 | * you directly pass a QPixmap object. 160 | */ 161 | void setHeaderIconActive(const QPixmap &icon); 162 | /** 163 | * @brief Get the header icon for active state 164 | * @return QPixmap 165 | */ 166 | QPixmap getHeaderIconActive(); 167 | /** 168 | * @brief et the header icon that will be displayed when the content pane is inactive 169 | * @param icon Path to image 170 | * 171 | * @details 172 | * Set the header icon for inactive content pane state. Provide a path to a 173 | * supported image file. If the file does not exist or has an unsupported 174 | * format the icon will not be changed. 175 | * @sa 176 | * Supported [image formats](http://doc.qt.io/qt-5/qimagereader.html#supportedImageFormats) by QImageReader. 177 | */ 178 | void setHeaderIconInActive(const QString &icon); 179 | /** 180 | * @brief setHeaderIconInActive 181 | * @param icon 182 | * @sa setHeaderIconInActive(QString) 183 | */ 184 | void setHeaderIconInActive(const QPixmap &icon); 185 | /** 186 | * @brief Get the header for inactive state 187 | * @return QPixmap 188 | */ 189 | QPixmap getHeaderIconInActive(); 190 | /** 191 | * @brief Set header tooltip 192 | * @param tooltip String to show as tooltip 193 | * 194 | * @details 195 | * Set a string as header tooltip that will be shown when the mouse hovers 196 | * over the header area. 197 | */ 198 | void setHeaderTooltip(const QString &tooltip); 199 | /** 200 | * @brief Get the header tooltip 201 | * @return Tooltip as QString 202 | * 203 | * @details 204 | * Get the header tooltip as QString. 205 | */ 206 | QString getHeaderTooltip(); 207 | /** 208 | * @brief Set a stylesheet for the header frame 209 | * @param stylesheet CSS Style Sheet as string 210 | * 211 | * @details 212 | * You can use [Cascading Style Sheets](http://doc.qt.io/qt-5/stylesheet.html) as supported by Qt to 213 | * style the header. This is the standard style sheet. You may also set a 214 | * style for mouse over with setHeaderHoverStylesheet(). 215 | */ 216 | void setHeaderStylesheet(QString stylesheet); 217 | /** 218 | * @brief Get the current header style sheet 219 | * @return CSS string 220 | * 221 | * @details 222 | * Get the css of the content pane header as QString. 223 | */ 224 | QString getHeaderStylesheet(); 225 | /** 226 | * @brief Set a stylesheet for the header frame when the mouse hovers over it 227 | * @param stylesheet CSS Style Sheet as string 228 | * 229 | * @details 230 | * Set a \p stylesheet for the header for a special effect when the mouse 231 | * hovers over it. 232 | * @sa 233 | * setHeaderStylesheet() for additional details. 234 | */ 235 | void setHeaderHoverStylesheet(QString stylesheet); 236 | /** 237 | * @brief Get the mouse over header style sheet 238 | * @return CSS Style Sheet as string 239 | * 240 | * @details 241 | * Returns the mouse over header style sheet. 242 | */ 243 | QString getHeaderHoverStylesheet(); 244 | /** 245 | * @brief Set the header frame style 246 | * @param style 247 | * 248 | * @details 249 | * The style is the bitwise OR between a frame shape and a frame shadow style. 250 | * See the [Qt Documentation](http://doc.qt.io/qt-5/qframe.html#setFrameStyle) for additional details. 251 | */ 252 | void setHeaderFrameStyle(int style); 253 | /** 254 | * @brief Get the header frame style 255 | * @return int 256 | * 257 | * @sa 258 | * setHeaderFrameStyle() for additional information. 259 | */ 260 | int getHeaderFrameStyle(); 261 | /** 262 | * @brief Set the container frame style 263 | * @param style 264 | * 265 | * @sa 266 | * setHeaderFrameStyle() for additional information 267 | */ 268 | void setContainerFrameStyle(int style); 269 | /** 270 | * @brief Get the container frame style 271 | * @return int 272 | * 273 | * @sa 274 | * setHeaderFrameStyle() for additional information 275 | */ 276 | int getContainerFrameStyle(); 277 | /** 278 | * @brief Set the duration for the open and close animation 279 | * @param duration Duration in milliseconds 280 | * 281 | * @details 282 | * Set the duration of the QPropertyAnimation in milliseconds. 283 | */ 284 | void setAnimationDuration(uint duration); 285 | /** 286 | * @brief Get the duration of the open, close animation. 287 | * @return Duration in milliseconds 288 | */ 289 | uint getAnimationDuration(); 290 | 291 | signals: 292 | 293 | /** 294 | * @brief Clicked signal is emitted when the header is clicked 295 | */ 296 | void clicked(); 297 | /** 298 | * @brief Signal will be emitted after the open animation finished 299 | */ 300 | void isActive(); 301 | /** 302 | * @brief Signal will be emitted after the close animation finished 303 | */ 304 | void isInactive(); 305 | 306 | public slots: 307 | 308 | /** 309 | * @brief Slot that is called when the header has been triggered 310 | * @param pos Currently unused 311 | * 312 | * @details 313 | * This slot is used to notify the ContentPane widget that the header 314 | * has been triggered. You can use this slot yourself to open or close the 315 | * ContentPane. Check the state of the pane before with getActive() as this 316 | * slot might not do what you intended to do (for example you want to close 317 | * the ContentPane. If it is already inactive and you call this slot without 318 | * checking the state it will be opened). 319 | */ 320 | void headerTriggered(QPoint pos); 321 | 322 | private: 323 | // yeah we are friends. this is important to keep openContentPane and 324 | // closeContentPane private 325 | friend class QAccordion; 326 | 327 | ClickableFrame *header; 328 | QFrame *container; 329 | QFrame *content; 330 | 331 | QPixmap headerIconActive; 332 | QPixmap headerIconInActive; 333 | 334 | int headerFrameStyle; 335 | int contentPaneFrameStyle; 336 | int containerAnimationMaxHeight; 337 | 338 | bool active; 339 | 340 | std::unique_ptr openAnimation; 341 | std::unique_ptr closeAnimation; 342 | 343 | void initDefaults(QString header); 344 | void initHeaderFrame(QString header); 345 | void initContainerContentFrame(); 346 | void initAnimations(); 347 | 348 | private slots: 349 | 350 | /** 351 | * @brief Open the content pane 352 | * 353 | * @details 354 | * This will open the content pane if it is currently closed. 355 | * @warning 356 | * Currently there is no inbuild mechanism to close an already open 357 | * Content Pane when you open another one programmatically. Meaning you have 358 | * to take care of this yourself. 359 | */ 360 | void openContentPane(); 361 | /** 362 | * @brief Close the content pane 363 | * 364 | * @details 365 | * This will close the content pane if it is currently open. 366 | */ 367 | void closeContentPane(); 368 | 369 | protected: 370 | /** 371 | * @brief paintEvent Reimplement paintEvent to use stylesheets in derived Widgets 372 | * @param event 373 | */ 374 | void paintEvent(ATTR_UNUSED QPaintEvent *event) override; 375 | }; 376 | 377 | #endif // CONTENTPANE_HPP 378 | -------------------------------------------------------------------------------- /include/qaccordion/qaccordion.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of qAccordion. An Accordion widget for Qt 2 | // Copyright © 2015, 2017, 2020 Christian Rapp <0x2a at posteo dot org> 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #ifndef QACCORDION_HPP 18 | #define QACCORDION_HPP 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "qaccordion_config.hpp" 36 | 37 | #include "contentpane.hpp" 38 | 39 | class ContentPane; 40 | 41 | /** 42 | * @brief QAccordion base class 43 | * 44 | * @details 45 | * This class is the basis of the qAccordion widget. If you want to add a 46 | * accordion widget to your gui then you have to create an object of this class. 47 | * 48 | * Managing content panes is simpel: 49 | * * You can either add (addContentPane()) or insert (insertContentPane()) new ContentPanes. 50 | * * Use removeContentPane() to remove existing ContentPanes. 51 | * * moveContentPane() allows you to change the order of the ContentPanes. 52 | * * To change a ContentPane in place use swapContentPane() 53 | * 54 | * @note 55 | * Many of the mentioned functions are overloaded, provided for convenience. 56 | * 57 | * @details 58 | * The signal numberOfContentPanesChanged() is emitted whenever the number of 59 | * content panes changed. 60 | * 61 | * In case of an error you may get a more detailed error description with 62 | * getError(). 63 | * 64 | * @warning 65 | * Currently Headers have to be unique 66 | * 67 | */ 68 | class QAccordion : public QWidget 69 | { 70 | Q_OBJECT 71 | public: 72 | /** 73 | * @brief QAccordion constructor 74 | * @param parent Optionally provide a parent widget 75 | */ 76 | explicit QAccordion(QWidget *parent = nullptr); 77 | 78 | /** 79 | * @brief Returns the number of content panes 80 | * @return int 81 | */ 82 | int numberOfContentPanes() const; 83 | 84 | /** 85 | * @brief Add a new content Pane 86 | * @param header Header of the content pane 87 | * @return Content pane index 88 | * 89 | * @details 90 | * Use this method to add a new content pane with the Header header. 91 | * The method will return the index of the new content pane, or -1 if 92 | * the pane was not added because \p header already exists. 93 | */ 94 | int addContentPane(QString header); 95 | /** 96 | * @brief Add a new content Pane 97 | * @param header Header of the content pane 98 | * @param contentFrame The content of the pane 99 | * @return Content pane index 100 | * 101 | * @details 102 | * This is an overloaded method of addContentPane(QString), that 103 | * allows you to provide your own content frame. 104 | * @warning 105 | * Headers have to be unique 106 | */ 107 | int addContentPane(QString header, QFrame *contentFrame); 108 | /** 109 | * @brief Add content pane 110 | * @param cpane New content pane to add 111 | * @return Content pane index 112 | * 113 | * @details 114 | * This is an overloaded method of addContentPane(QString), that 115 | * allows you to provide your own content pane. 116 | */ 117 | int addContentPane(ContentPane *cpane); 118 | /** 119 | * @brief Insert content pane 120 | * @param index Index of the content pane 121 | * @param header Header of the content pane 122 | * @return bool True if insert was successfull 123 | * 124 | * @details 125 | * You can use this method to insert a new content pane at given index with 126 | * \p header defining the Header. An empty content pane will be created that 127 | * you can get with getContentPane(). 128 | * 129 | * Returns true if the insert was successfull. 130 | */ 131 | bool insertContentPane(uint index, QString header); 132 | /** 133 | * @brief Insert content pane 134 | * @param index Index of the content pane 135 | * @param header Header of the content pane 136 | * @param contentFrame Content frame of the content pane 137 | * @return bool True if insert was successfull 138 | * 139 | * @details 140 | * This is an overloaded method of insertContentPane(uint, QString). 141 | * Use this method when you already created a content frame that you want to 142 | * insert. 143 | * @warning 144 | * Headers have to be unique 145 | */ 146 | bool insertContentPane(uint index, QString header, QFrame *contentFrame); 147 | /** 148 | * @brief Insert content pane 149 | * @param index Index of the content pane 150 | * @param cpane Content Pane to insert 151 | * @return bool True if insert was successfull 152 | * 153 | * @details 154 | * This is an overloaded method of insertContentPane(uint, QString). 155 | * Use this method when you already created a content pane that you want to 156 | * insert. 157 | */ 158 | bool insertContentPane(uint index, ContentPane *cpane); 159 | 160 | /** 161 | * @brief Swap the content pane 162 | * @param index Index of the content pane to swap 163 | * @param cpane New content pane 164 | * @return bool True if swap was successfull 165 | * 166 | * @details 167 | * With this method you can replace an existing content pane at \p index with 168 | * a new one \p cpane. 169 | * 170 | * Returns true if the swap was successfull. 171 | * 172 | * The old content pane will be __deleted__. 173 | */ 174 | bool swapContentPane(uint index, ContentPane *cpane); 175 | 176 | /** 177 | * @brief Remove a content pane 178 | * @param deleteObject Delete the object and free memory 179 | * @param index Index of the content pane 180 | * @return bool 181 | * 182 | * @details 183 | * Remove a content pane at \p index. If \p deleteObject is \p true the 184 | * object will be deleted. Otherwise it is up to the user to 185 | * free the allocated memory. 186 | * 187 | * Returns true if the pane was removed and false otherwise. 188 | */ 189 | bool removeContentPane(bool deleteObject, uint index); 190 | /** 191 | * @brief Remove a content pane 192 | * @param deleteObject Delete the object and free memory 193 | * @param header Header of the content pane 194 | * @return bool 195 | * 196 | * @details 197 | * This is an overloaded method of removeContentPane(bool, uint). 198 | */ 199 | bool removeContentPane(bool deleteObject, QString header); 200 | /** 201 | * @brief Remove a content pane 202 | * @param deleteObject Delete the object and free memory 203 | * @param contentframe Content frame of the content pane 204 | * @return bool 205 | * 206 | * @details 207 | * This is an overloaded method of removeContentPane(bool, uint). 208 | */ 209 | bool removeContentPane(bool deleteObject, QFrame *contentframe); 210 | /** 211 | * @brief Remove a content pane 212 | * @param deleteObject Delete the object and free memory 213 | * @param contentPane The content pane to remove 214 | * @return bool 215 | * 216 | * @details 217 | * This is an overloaded method of removeContentPane(bool, uint). 218 | */ 219 | bool removeContentPane(bool deleteObject, ContentPane *contentPane); 220 | 221 | /** 222 | * @brief Move content pane 223 | * @param currentIndex The current index of the content pane. 224 | * @param newIndex The new index of the current pane 225 | * @return bool 226 | * 227 | * @details 228 | * Moves a content from \p currentIndex to \p newIndex. Returns true if the 229 | * content pane was moved, false otherwise. 230 | */ 231 | bool moveContentPane(uint currentIndex, uint newIndex); 232 | 233 | /** 234 | * @brief Get content pane 235 | * @param index Index of the content pane 236 | * @return QFrame* or nullptr 237 | * 238 | * @details 239 | * Get a content pane (QFrame*) with \p index. This method will return a 240 | * __nullptr__ if the content pane does not exist. 241 | */ 242 | ContentPane *getContentPane(uint index); 243 | 244 | /** 245 | * @brief Get the index of a content pane 246 | * @param header Header of the Content Pane 247 | * @return Index of the content pane 248 | * 249 | * @details 250 | * Get the index of a ContentPane with \p header. This method will return 251 | * -1 if a ContentPane with this header does not exist. 252 | */ 253 | int getContentPaneIndex(QString header) const; 254 | /** 255 | * @brief Get the index of a content pane 256 | * @param contentFrame Content Frame 257 | * @return Index of the content pane 258 | * 259 | * @details 260 | * This is an overloaded function of getContentPaneIndex(QString) 261 | */ 262 | int getContentPaneIndex(QFrame *contentFrame) const; 263 | /** 264 | * @brief Get the index of a content pane 265 | * @param contentPane ContentPane* 266 | * @return Index of the content pane 267 | * 268 | * @details 269 | * This is an overloaded function of getContentPaneIndex(QString) 270 | */ 271 | int getContentPaneIndex(ContentPane *contentPane) const; 272 | 273 | /** 274 | * @brief Get the index of the active ContentPane 275 | * @return Vector with indexes of all active ContentPanes 276 | * 277 | * @details 278 | * This method will fill a vector with the index of all active ContentPanes. 279 | * The vector will be empty if no ContentPane is active 280 | */ 281 | void getActiveContentPaneIndex(std::vector &indexVector) const; 282 | 283 | /** 284 | * @brief Get the number of content panes 285 | * @return Number of content panes 286 | */ 287 | int getNumberOfContentPanes() const; 288 | 289 | /** 290 | * @brief Allow multiple ContentPane to be open 291 | * @param status 292 | * 293 | * @details 294 | * This option allows you to open several ContentPane at the same time. 295 | * @note 296 | * Default value for this option is \p false. 297 | */ 298 | void setMultiActive(bool status); 299 | /** 300 | * @brief Check status of multiActive 301 | * @return bool 302 | * 303 | * @sa 304 | * setMultiActive() 305 | */ 306 | bool getMultiActive() const; 307 | 308 | /** 309 | * @brief If collapsible is true you can close all ContentPanes 310 | * @param status 311 | * 312 | * @details 313 | * With the collapsible option you can control if one content pane has to be 314 | * open and can't be closed. 315 | */ 316 | void setCollapsible(bool status); 317 | /** 318 | * @brief Get collapsible status 319 | * @return bool 320 | * @sa 321 | * setCollapsible() 322 | */ 323 | bool getCollapsible() const; 324 | 325 | /** 326 | * @brief Get error string 327 | * @return Error string 328 | * 329 | * @details 330 | * Call this method after a function call failed for a detailed error 331 | * description. 332 | */ 333 | QString getError(); 334 | 335 | signals: 336 | /** 337 | * @brief Signals the new number of content panes 338 | * @param number Number of content panes 339 | * 340 | * @details 341 | * Signal will be emitted if the number of content panes changes 342 | */ 343 | void numberOfContentPanesChanged(int number); 344 | 345 | public slots: 346 | 347 | private: 348 | std::vector contentPanes; 349 | 350 | QSpacerItem *spacer; 351 | 352 | QString errorString; 353 | 354 | bool multiActive; 355 | bool collapsible; 356 | 357 | int internalAddContentPane(QString header, QFrame *cframe = nullptr, 358 | ContentPane *cpane = nullptr); 359 | bool internalInsertContentPane(uint index, QString header, 360 | QFrame *contentFrame = nullptr, 361 | ContentPane *cpane = nullptr); 362 | bool internalRemoveContentPane(bool deleteOject, int index = -1, 363 | QString name = "", 364 | QFrame *contentFrame = nullptr, 365 | ContentPane *cpane = nullptr); 366 | int findContentPaneIndex(QString name = "", QFrame *cframe = nullptr, 367 | ContentPane *cpane = nullptr) const; 368 | 369 | bool checkIndexError(uint index, bool sizeIndexAllowed, 370 | const QString &errMessage); 371 | void handleClickedSignal(ContentPane *cpane); 372 | 373 | private slots: 374 | void numberOfPanesChanged(int number); 375 | 376 | protected: 377 | /** 378 | * @brief paintEvent Reimplement paintEvent to use stylesheets in derived Widgets 379 | * @param event 380 | */ 381 | void paintEvent(ATTR_UNUSED QPaintEvent *event) override; 382 | }; 383 | 384 | #endif // QACCORDION_HPP 385 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Find includes in corresponding build directories 2 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 3 | # Instruct CMake to run moc automatically when needed. 4 | set(CMAKE_AUTOMOC ON) 5 | 6 | # Find the QtWidgets library. This has dependencies on QtGui and QtCore! 7 | find_package(Qt5Widgets 5.2 REQUIRED) 8 | message(STATUS "Found Qt version ${Qt5Widgets_VERSION_STRING}") 9 | 10 | if(QACCORDION_EXTERNAL) 11 | set(base_path ${CMAKE_SOURCE_DIR}/external/qaccordion/) 12 | message(STATUS 13 | "Using qAccordion external config with base path: ${base_path}") 14 | # provide the current build path to parent scope. add this to include 15 | # directories in parent projects 16 | set(EXTERNAL_INCLUDE 17 | "${CMAKE_CURRENT_BINARY_DIR}" 18 | PARENT_SCOPE 19 | ) 20 | else() 21 | set(base_path ${CMAKE_SOURCE_DIR}) 22 | endif() 23 | 24 | # configure a header file to pass some of the CMake settings 25 | # to the source code 26 | configure_file( 27 | ${base_path}/include/qaccordion/config.h.in 28 | ${CMAKE_CURRENT_BINARY_DIR}/qaccordion_config.hpp 29 | ) 30 | 31 | set(QACCORDION_SOURCE 32 | ${CMAKE_CURRENT_SOURCE_DIR}/clickableframe.cpp 33 | ${CMAKE_CURRENT_SOURCE_DIR}/contentpane.cpp 34 | ${CMAKE_CURRENT_SOURCE_DIR}/qaccordion.cpp 35 | ) 36 | 37 | set(QACCORDION_ICON_RESOURCE "${base_path}/icons/qaccordionicons.qrc") 38 | # add resource files so they can be compiled into the binary 39 | qt5_add_resources(ICON_RESOURCE_ADDED ${QACCORDION_ICON_RESOURCE}) 40 | 41 | # we are building a shared library 42 | add_library(qaccordion SHARED 43 | ${QACCORDION_HEADER} 44 | ${QACCORDION_SOURCE} 45 | ${ICON_RESOURCE_ADDED}) 46 | 47 | target_link_libraries(qaccordion Qt5::Widgets) 48 | 49 | set_property(TARGET qaccordion PROPERTY CXX_STANDARD_REQUIRED ON) 50 | set_property(TARGET qaccordion PROPERTY CXX_STANDARD 14) 51 | 52 | target_include_directories(qaccordion 53 | PUBLIC ${CMAKE_CURRENT_BINARY_DIR} 54 | PUBLIC ${base_path}/include 55 | ) 56 | 57 | if(QACCORDION_BUILD_DEMO) 58 | # generate ui_*.h files 59 | qt5_wrap_ui(accordion_demo_FORMS ${DEMO_UI}) 60 | find_package(Qt5Network REQUIRED) 61 | add_executable(accordion_demo 62 | ${DEMO_HEADER} ${DEMO_SOURCE} ${accordion_demo_FORMS}) 63 | target_link_libraries(accordion_demo qaccordion Qt5::Widgets Qt5::Network) 64 | set_property(TARGET accordion_demo PROPERTY CXX_STANDARD_REQUIRED ON) 65 | set_property(TARGET accordion_demo PROPERTY CXX_STANDARD 14) 66 | endif() 67 | 68 | install(TARGETS qaccordion DESTINATION lib) 69 | install(FILES ${base_path}/include/qaccordion/clickableframe.hpp 70 | DESTINATION include/qaccordion) 71 | install(FILES ${base_path}/include/qaccordion/contentpane.hpp 72 | DESTINATION include/qaccordion) 73 | install(FILES ${base_path}/include/qaccordion/qaccordion.hpp 74 | DESTINATION include/qaccordion) 75 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qaccordion_config.hpp 76 | DESTINATION include/qaccordion) 77 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qaccordion_export.hpp 78 | DESTINATION include/qaccordion) 79 | 80 | -------------------------------------------------------------------------------- /src/clickableframe.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of qAccordion. An Accordion widget for Qt 2 | // Copyright © 2015, 2017, 2020 Christian Rapp <0x2a at posteo dot org> 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #include "qaccordion/clickableframe.hpp" 18 | 19 | ClickableFrame::ClickableFrame(QString header, QWidget *parent, 20 | Qt::WindowFlags f) 21 | : iconLabel(nullptr), 22 | nameLabel(nullptr), 23 | header(std::move(header)), 24 | QFrame(parent, f) 25 | { 26 | this->setAttribute(Qt::WA_Hover, true); 27 | this->headerTrigger = TRIGGER::SINGLECLICK; 28 | this->setCursor(Qt::PointingHandCursor); 29 | QColor background = this->palette().color(QPalette::ColorRole::Background); 30 | QColor lighter = background.lighter(110); 31 | this->normalStylesheet = ""; 32 | this->hoverStylesheet = "background-color: " + lighter.name() + ";"; 33 | this->initFrame(); 34 | } 35 | 36 | void ClickableFrame::setTrigger(ClickableFrame::TRIGGER tr) 37 | { 38 | this->headerTrigger = tr; 39 | if (tr != TRIGGER::NONE) { 40 | this->setCursor(Qt::PointingHandCursor); 41 | } else { 42 | this->setCursor(Qt::ForbiddenCursor); 43 | } 44 | } 45 | 46 | ClickableFrame::TRIGGER ClickableFrame::getTrigger() 47 | { 48 | return this->headerTrigger; 49 | } 50 | 51 | void ClickableFrame::setHeader(QString header) 52 | { 53 | this->header = std::move(header); 54 | this->nameLabel->setText(this->header); 55 | } 56 | 57 | QString ClickableFrame::getHeader() { return this->header; } 58 | 59 | void ClickableFrame::setIcon(const QPixmap &icon) 60 | { 61 | this->iconLabel->setPixmap(icon); 62 | } 63 | 64 | //void ClickableFrame::setIconPosition(ClickableFrame::ICON_POSITION pos) {} 65 | 66 | void ClickableFrame::setNormalStylesheet(QString stylesheet) 67 | { 68 | this->normalStylesheet = std::move(stylesheet); 69 | this->setStyleSheet(this->normalStylesheet); 70 | } 71 | 72 | QString ClickableFrame::getNormalStylesheet() { return this->normalStylesheet; } 73 | 74 | void ClickableFrame::setHoverStylesheet(QString stylesheet) 75 | { 76 | this->hoverStylesheet = std::move(stylesheet); 77 | } 78 | 79 | QString ClickableFrame::getHoverStylesheet() { return this->hoverStylesheet; } 80 | 81 | void ClickableFrame::initFrame() 82 | { 83 | this->setSizePolicy(QSizePolicy::Policy::Preferred, 84 | QSizePolicy::Policy::Fixed); 85 | this->setLayout(new QHBoxLayout()); 86 | 87 | this->iconLabel = new QLabel(); 88 | this->iconLabel->setPixmap(QPixmap(this->CARRET_ICON_CLOSED)); 89 | this->layout()->addWidget(this->iconLabel); 90 | 91 | this->nameLabel = new QLabel(); 92 | nameLabel->setText(this->header); 93 | this->layout()->addWidget(nameLabel); 94 | 95 | dynamic_cast(this->layout())->addStretch(); 96 | 97 | this->setStyleSheet(this->normalStylesheet); 98 | } 99 | 100 | void ClickableFrame::mousePressEvent(QMouseEvent *event) 101 | { 102 | if (this->headerTrigger == TRIGGER::SINGLECLICK) { 103 | emit this->triggered(event->pos()); 104 | event->accept(); 105 | } else { 106 | event->ignore(); 107 | } 108 | } 109 | 110 | void ClickableFrame::mouseDoubleClickEvent(QMouseEvent *event) 111 | { 112 | if (this->headerTrigger == TRIGGER::DOUBLECLICK) { 113 | emit this->triggered(event->pos()); 114 | event->accept(); 115 | } else { 116 | event->ignore(); 117 | } 118 | } 119 | 120 | // TODO: No Stylesheet change when TRIGGER::NONE? 121 | void ClickableFrame::enterEvent(ATTR_UNUSED QEvent *event) 122 | { 123 | if (this->headerTrigger != TRIGGER::NONE) { 124 | this->setStyleSheet(this->hoverStylesheet); 125 | } 126 | } 127 | 128 | void ClickableFrame::leaveEvent(ATTR_UNUSED QEvent *event) 129 | { 130 | if (this->headerTrigger != TRIGGER::NONE) { 131 | this->setStyleSheet(this->normalStylesheet); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/contentpane.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of qAccordion. An Accordion widget for Qt 2 | // Copyright © 2015, 2017, 2020 Christian Rapp <0x2a at posteo dot org> 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #include "qaccordion/contentpane.hpp" 18 | 19 | ContentPane::ContentPane(QString header, QWidget *parent) : QWidget(parent) 20 | { 21 | this->content = nullptr; 22 | 23 | this->initDefaults(std::move(header)); 24 | } 25 | 26 | ContentPane::ContentPane(QString header, QFrame *content, QWidget *parent) 27 | : content(content), QWidget(parent) 28 | { 29 | this->initDefaults(std::move(header)); 30 | } 31 | 32 | bool ContentPane::getActive() const { return this->active; } 33 | 34 | QFrame *ContentPane::getContentFrame() { return this->content; } 35 | 36 | void ContentPane::setContentFrame(QFrame *content) 37 | { 38 | this->container->layout()->removeWidget(this->content); 39 | if (this->content != nullptr) { 40 | delete (this->content); 41 | } 42 | this->content = content; 43 | dynamic_cast(this->container->layout()) 44 | ->insertWidget(0, this->content); 45 | } 46 | 47 | int ContentPane::getMaximumHeight() { return this->container->maximumHeight(); } 48 | 49 | void ContentPane::setMaximumHeight(int maxHeight) 50 | { 51 | this->containerAnimationMaxHeight = maxHeight; 52 | 53 | if (this->getActive()) { 54 | this->container->setMaximumHeight(this->containerAnimationMaxHeight); 55 | } 56 | this->openAnimation->setEndValue(this->containerAnimationMaxHeight); 57 | this->closeAnimation->setStartValue(this->containerAnimationMaxHeight); 58 | } 59 | 60 | void ContentPane::setTrigger(ClickableFrame::TRIGGER tr) 61 | { 62 | this->header->setTrigger(tr); 63 | } 64 | 65 | ClickableFrame::TRIGGER ContentPane::getTrigger() 66 | { 67 | return this->header->getTrigger(); 68 | } 69 | 70 | void ContentPane::setHeader(QString header) 71 | { 72 | this->header->setHeader(std::move(header)); 73 | } 74 | 75 | QString ContentPane::getHeader() { return this->header->getHeader(); } 76 | 77 | void ContentPane::setHeaderIconActive(const QString &icon) 78 | { 79 | QPixmap pic(icon); 80 | if (!pic.isNull()) { 81 | this->headerIconActive = pic; 82 | if (this->getActive()) { 83 | this->header->setIcon(this->headerIconActive); 84 | } 85 | } 86 | } 87 | 88 | void ContentPane::setHeaderIconActive(const QPixmap &icon) 89 | { 90 | if (!icon.isNull()) { 91 | this->headerIconActive = icon; 92 | if (this->getActive()) { 93 | this->header->setIcon(this->headerIconActive); 94 | } 95 | } 96 | } 97 | 98 | QPixmap ContentPane::getHeaderIconActive() { return this->headerIconActive; } 99 | 100 | void ContentPane::setHeaderIconInActive(const QString &icon) 101 | { 102 | QPixmap pic(icon); 103 | if (!pic.isNull()) { 104 | this->headerIconInActive = pic; 105 | if (!this->getActive()) { 106 | this->header->setIcon(this->headerIconInActive); 107 | } 108 | } 109 | } 110 | 111 | void ContentPane::setHeaderIconInActive(const QPixmap &icon) 112 | { 113 | if (!icon.isNull()) { 114 | this->headerIconInActive = icon; 115 | if (!this->getActive()) { 116 | this->header->setIcon(this->headerIconInActive); 117 | } 118 | } 119 | } 120 | 121 | QPixmap ContentPane::getHeaderIconInActive() { return this->headerIconInActive; } 122 | 123 | void ContentPane::setHeaderTooltip(const QString &tooltip) 124 | { 125 | this->header->setToolTip(tooltip); 126 | } 127 | 128 | QString ContentPane::getHeaderTooltip() { return this->header->toolTip(); } 129 | 130 | void ContentPane::setHeaderStylesheet(QString stylesheet) 131 | { 132 | this->header->setNormalStylesheet(std::move(stylesheet)); 133 | } 134 | 135 | QString ContentPane::getHeaderStylesheet() 136 | { 137 | return this->header->getNormalStylesheet(); 138 | } 139 | 140 | void ContentPane::setHeaderHoverStylesheet(QString stylesheet) 141 | { 142 | this->header->setHoverStylesheet(std::move(stylesheet)); 143 | } 144 | 145 | QString ContentPane::getHeaderHoverStylesheet() 146 | { 147 | return this->header->getHoverStylesheet(); 148 | } 149 | 150 | void ContentPane::setHeaderFrameStyle(int style) 151 | { 152 | this->header->setFrameStyle(style); 153 | } 154 | 155 | int ContentPane::getHeaderFrameStyle() { return this->header->frameStyle(); } 156 | 157 | void ContentPane::setContainerFrameStyle(int style) 158 | { 159 | this->container->setFrameStyle(style); 160 | } 161 | 162 | int ContentPane::getContainerFrameStyle() 163 | { 164 | return this->container->frameStyle(); 165 | } 166 | 167 | void ContentPane::openContentPane() 168 | { 169 | if (this->getActive()) { 170 | return; 171 | } 172 | this->openAnimation->start(); 173 | this->header->setIcon(this->headerIconActive); 174 | this->active = true; 175 | } 176 | 177 | void ContentPane::closeContentPane() 178 | { 179 | if (!this->getActive()) { 180 | return; 181 | } 182 | this->closeAnimation->start(); 183 | this->header->setIcon(this->headerIconInActive); 184 | this->active = false; 185 | } 186 | 187 | void ContentPane::initDefaults(QString header) 188 | { 189 | this->active = false; 190 | 191 | this->headerFrameStyle = QFrame::Shape::StyledPanel | QFrame::Shadow::Raised; 192 | this->contentPaneFrameStyle = 193 | QFrame::Shape::StyledPanel | QFrame::Shadow::Plain; 194 | this->containerAnimationMaxHeight = 150; 195 | // TODO: Why do I need to set the vertial policy to Maximum? from the api 196 | // documentation Minimum would make more sens :/ 197 | this->setSizePolicy(QSizePolicy::Policy::Preferred, 198 | QSizePolicy::Policy::Maximum); 199 | 200 | this->setLayout(new QVBoxLayout()); 201 | this->layout()->setSpacing(1); 202 | this->layout()->setContentsMargins(QMargins()); 203 | 204 | this->initHeaderFrame(std::move(header)); 205 | this->initContainerContentFrame(); 206 | this->initAnimations(); 207 | } 208 | 209 | void ContentPane::initHeaderFrame(QString header) 210 | { 211 | this->header = new ClickableFrame(std::move(header)); 212 | this->header->setFrameStyle(this->headerFrameStyle); 213 | // init the icons 214 | this->setHeaderIconActive(this->header->CARRET_ICON_OPENED); 215 | this->setHeaderIconInActive(this->header->CARRET_ICON_CLOSED); 216 | this->layout()->addWidget(this->header); 217 | 218 | QObject::connect(this->header, &ClickableFrame::triggered, this, 219 | &ContentPane::headerTriggered); 220 | } 221 | 222 | void ContentPane::initContainerContentFrame() 223 | { 224 | this->container = new QFrame(); 225 | this->container->setLayout(new QVBoxLayout()); 226 | this->container->setFrameStyle(this->contentPaneFrameStyle); 227 | this->container->setMaximumHeight(0); 228 | this->container->setSizePolicy(QSizePolicy::Policy::Preferred, 229 | QSizePolicy::Policy::Preferred); 230 | this->layout()->addWidget(this->container); 231 | 232 | if (this->content == nullptr) { 233 | this->content = new QFrame(); 234 | } 235 | 236 | this->container->layout()->addWidget(this->content); 237 | this->container->layout()->setSpacing(0); 238 | this->container->layout()->setContentsMargins(QMargins()); 239 | } 240 | 241 | void ContentPane::initAnimations() 242 | { 243 | this->openAnimation = std::make_unique(); 244 | this->closeAnimation = std::make_unique(); 245 | // TODO: Currently these animations only animate maximumHeight. This leads to 246 | // different behaviour depending on whether the Accordion Widget is placed 247 | // inside a QScollWidget or not. Maybe we also need to animate minimumHeight 248 | // as well to get the same effect. 249 | // TODO: Lots of boilerplate code here 250 | this->openAnimation->setTargetObject(this->container); 251 | this->openAnimation->setPropertyName("maximumHeight"); 252 | this->closeAnimation->setTargetObject(this->container); 253 | this->closeAnimation->setPropertyName("maximumHeight"); 254 | 255 | this->openAnimation->setDuration(300); 256 | this->closeAnimation->setDuration(300); 257 | this->openAnimation->setStartValue(0); 258 | this->closeAnimation->setStartValue(this->containerAnimationMaxHeight); 259 | this->openAnimation->setEndValue(this->containerAnimationMaxHeight); 260 | this->closeAnimation->setEndValue(0); 261 | this->openAnimation->setEasingCurve( 262 | QEasingCurve(QEasingCurve::Type::Linear)); 263 | this->closeAnimation->setEasingCurve( 264 | QEasingCurve(QEasingCurve::Type::Linear)); 265 | } 266 | 267 | void ContentPane::headerTriggered(ATTR_UNUSED QPoint pos) 268 | { 269 | emit this->clicked(); 270 | } 271 | 272 | void ContentPane::paintEvent(ATTR_UNUSED QPaintEvent *event) 273 | { 274 | QStyleOption o; 275 | o.initFrom(this); 276 | QPainter p(this); 277 | style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this); 278 | } 279 | -------------------------------------------------------------------------------- /src/qaccordion.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of qAccordion. An Accordion widget for Qt 2 | // Copyright © 2015, 2017, 2020 Christian Rapp <0x2a at posteo dot org> 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #include "qaccordion/qaccordion.hpp" 18 | 19 | QAccordion::QAccordion(QWidget *parent) : QWidget(parent) 20 | { 21 | // make sure our resource file gets initialized 22 | Q_INIT_RESOURCE(qaccordionicons); 23 | 24 | this->multiActive = false; 25 | this->collapsible = true; 26 | 27 | // set our basic layout 28 | this->setLayout(new QVBoxLayout()); 29 | 30 | // add a stretch to the end so all content panes are at the top 31 | dynamic_cast(this->layout())->addStretch(); 32 | this->layout()->setSpacing(1); 33 | this->layout()->setContentsMargins(QMargins()); 34 | // TODO: Do we need to keep a pointer to the spacer? 35 | this->spacer = dynamic_cast(this->layout()->itemAt(0)); 36 | 37 | // seome things we want to do if the number of panes change 38 | QObject::connect(this, &QAccordion::numberOfContentPanesChanged, this, 39 | &QAccordion::numberOfPanesChanged); 40 | } 41 | 42 | int QAccordion::numberOfContentPanes() const { return this->contentPanes.size(); } 43 | 44 | int QAccordion::addContentPane(QString header) 45 | { 46 | return this->internalAddContentPane(std::move(header)); 47 | } 48 | 49 | int QAccordion::addContentPane(QString header, QFrame *contentFrame) 50 | { 51 | return this->internalAddContentPane(std::move(header), contentFrame); 52 | } 53 | 54 | int QAccordion::addContentPane(ContentPane *cpane) 55 | { 56 | return this->internalAddContentPane("", nullptr, cpane); 57 | } 58 | 59 | bool QAccordion::insertContentPane(uint index, QString header) 60 | { 61 | return this->internalInsertContentPane(index, std::move(header)); 62 | } 63 | 64 | bool QAccordion::insertContentPane(uint index, QString header, 65 | QFrame *contentFrame) 66 | { 67 | return this->internalInsertContentPane(index, std::move(header), 68 | contentFrame); 69 | } 70 | 71 | bool QAccordion::insertContentPane(uint index, ContentPane *cpane) 72 | { 73 | return this->internalInsertContentPane(index, "", nullptr, cpane); 74 | } 75 | 76 | bool QAccordion::swapContentPane(uint index, ContentPane *cpane) 77 | { 78 | if (this->checkIndexError(index, false, 79 | "Can not swap content pane at index " + 80 | QString::number(index) + 81 | ". Index out of range.")) { 82 | return false; 83 | } 84 | 85 | if (this->findContentPaneIndex("", nullptr, cpane) != -1) { 86 | this->errorString = 87 | "Can not swap content pane as new pane is already " 88 | "managed by accordion widget"; 89 | return false; 90 | } 91 | 92 | // remove the old content pane from the accordion layout 93 | dynamic_cast(this->layout()) 94 | ->removeWidget(this->contentPanes.at(index)); 95 | delete this->contentPanes.at(index); 96 | 97 | // add the new content pane to the appropriate vector 98 | this->contentPanes.at(index) = cpane; 99 | 100 | // add the new content pane to the layout 101 | dynamic_cast(this->layout()) 102 | ->insertWidget(index, this->contentPanes.at(index)); 103 | 104 | return true; 105 | } 106 | 107 | bool QAccordion::removeContentPane(bool deleteObject, uint index) 108 | { 109 | return this->internalRemoveContentPane(deleteObject, index); 110 | } 111 | 112 | bool QAccordion::removeContentPane(bool deleteObject, QString header) 113 | { 114 | return this->internalRemoveContentPane(deleteObject, -1, std::move(header)); 115 | } 116 | 117 | bool QAccordion::removeContentPane(bool deleteObject, QFrame *contentframe) 118 | { 119 | return this->internalRemoveContentPane(deleteObject, -1, "", contentframe); 120 | } 121 | 122 | bool QAccordion::removeContentPane(bool deleteObject, ContentPane *contentPane) 123 | { 124 | return this->internalRemoveContentPane(deleteObject, -1, "", nullptr, 125 | contentPane); 126 | } 127 | 128 | bool QAccordion::moveContentPane(uint currentIndex, uint newIndex) 129 | { 130 | if (this->checkIndexError(currentIndex, false, 131 | "Can not move from " + 132 | QString::number(currentIndex) + 133 | ". Index out of range.") || 134 | this->checkIndexError(newIndex, false, 135 | "Can not move to " + QString::number(newIndex) + 136 | ". Index out of range.")) { 137 | return false; 138 | } 139 | 140 | auto *layout = dynamic_cast(this->layout()); 141 | // get the pane we want to move 142 | ContentPane *movePane = this->contentPanes.at(currentIndex); 143 | 144 | // remove the widget from the layout and insert it at the new position 145 | layout->removeWidget(movePane); 146 | layout->insertWidget(newIndex, movePane); 147 | 148 | // keep our vector synchronized 149 | this->contentPanes.erase(this->contentPanes.begin() + currentIndex); 150 | this->contentPanes.insert(this->contentPanes.begin() + newIndex, movePane); 151 | 152 | return true; 153 | } 154 | 155 | ContentPane *QAccordion::getContentPane(uint index) 156 | { 157 | try { 158 | return this->contentPanes.at(index); 159 | } catch (const std::out_of_range &ex) { 160 | qDebug() << Q_FUNC_INFO << "Can not return Content Pane: " << ex.what(); 161 | this->errorString = "Can not return Content Pane: " + QString(ex.what()); 162 | return nullptr; 163 | } 164 | } 165 | 166 | int QAccordion::getContentPaneIndex(QString header) const 167 | { 168 | return this->findContentPaneIndex(std::move(header)); 169 | } 170 | 171 | int QAccordion::getContentPaneIndex(QFrame *contentFrame) const 172 | { 173 | return this->findContentPaneIndex("", contentFrame); 174 | } 175 | 176 | int QAccordion::getContentPaneIndex(ContentPane *contentPane) const 177 | { 178 | return this->findContentPaneIndex("", nullptr, contentPane); 179 | } 180 | 181 | void QAccordion::getActiveContentPaneIndex(std::vector &indexVector) const 182 | { 183 | // first of all make sure it is empty 184 | indexVector.clear(); 185 | std::for_each(this->contentPanes.begin(), this->contentPanes.end(), 186 | [&indexVector, this](ContentPane *pane) { 187 | if (pane->getActive()) { 188 | indexVector.push_back( 189 | this->findContentPaneIndex("", nullptr, pane)); 190 | } 191 | }); 192 | } 193 | 194 | int QAccordion::getNumberOfContentPanes() const { return this->contentPanes.size(); } 195 | 196 | void QAccordion::setMultiActive(bool status) { this->multiActive = status; } 197 | 198 | bool QAccordion::getMultiActive() const { return this->multiActive; } 199 | 200 | void QAccordion::setCollapsible(bool status) { this->collapsible = status; } 201 | 202 | bool QAccordion::getCollapsible() const { return this->collapsible; } 203 | 204 | QString QAccordion::getError() { return this->errorString; } 205 | 206 | int QAccordion::internalAddContentPane(QString header, QFrame *cframe, 207 | ContentPane *cpane) 208 | { 209 | if (this->findContentPaneIndex(header, cframe, cpane) != -1) { 210 | this->errorString = "Can not add content pane as it already exists"; 211 | return -1; 212 | } 213 | 214 | if (cpane == nullptr) { 215 | if (cframe != nullptr) { 216 | cpane = new ContentPane(std::move(header), cframe); 217 | } else { 218 | cpane = new ContentPane(std::move(header)); 219 | } 220 | } 221 | dynamic_cast(this->layout()) 222 | ->insertWidget(this->layout()->count() - 1, cpane); 223 | this->contentPanes.push_back(cpane); 224 | 225 | // manage the clicked signal in a lambda expression 226 | QObject::connect(cpane, &ContentPane::clicked, 227 | [this, cpane]() { this->handleClickedSignal(cpane); }); 228 | 229 | emit numberOfContentPanesChanged(this->contentPanes.size()); 230 | 231 | return static_cast(this->contentPanes.size() - 1); 232 | } 233 | 234 | bool QAccordion::internalInsertContentPane(uint index, QString header, 235 | QFrame *contentFrame, 236 | ContentPane *cpane) 237 | { 238 | if (this->checkIndexError(index, true, 239 | "Can not insert Content Pane at index " + 240 | QString::number(index) + 241 | ". Index out of range")) { 242 | return false; 243 | } 244 | 245 | if (this->findContentPaneIndex(header, contentFrame, cpane) != -1) { 246 | return false; 247 | } 248 | 249 | if (cpane == nullptr) { 250 | if (contentFrame != nullptr) { 251 | cpane = new ContentPane(std::move(header), contentFrame); 252 | } else { 253 | cpane = new ContentPane(std::move(header)); 254 | } 255 | } 256 | 257 | dynamic_cast(this->layout())->insertWidget(index, cpane); 258 | 259 | this->contentPanes.insert(this->contentPanes.begin() + index, cpane); 260 | 261 | // manage the clicked signal in a lambda expression 262 | QObject::connect(cpane, &ContentPane::clicked, 263 | [this, cpane]() { this->handleClickedSignal(cpane); }); 264 | 265 | emit numberOfContentPanesChanged(this->contentPanes.size()); 266 | 267 | return true; 268 | } 269 | 270 | bool QAccordion::internalRemoveContentPane(bool deleteOject, int index, 271 | QString name, QFrame *contentFrame, 272 | ContentPane *cpane) 273 | { 274 | if (index != -1 && 275 | this->checkIndexError(index, false, 276 | "Can not remove content pane at index " + 277 | QString::number(index) + 278 | ". Index out of range")) { 279 | return false; 280 | } 281 | 282 | if (index == -1) { 283 | index = this->findContentPaneIndex(std::move(name), contentFrame, cpane); 284 | if (index == -1) { 285 | this->errorString = 286 | "Can not remove content pane as it is not part " 287 | "of the accordion widget"; 288 | return false; 289 | } 290 | } 291 | 292 | dynamic_cast(this->layout()) 293 | ->removeWidget(this->contentPanes.at(index)); 294 | 295 | // only delete the object if user wants to. 296 | if (deleteOject) { 297 | delete this->contentPanes.at(index); 298 | this->contentPanes.at(index) = nullptr; 299 | } 300 | 301 | this->contentPanes.erase(this->contentPanes.begin() + index); 302 | 303 | emit numberOfContentPanesChanged(this->contentPanes.size()); 304 | 305 | return true; 306 | } 307 | 308 | int QAccordion::findContentPaneIndex(QString name, QFrame *cframe, 309 | ContentPane *cpane) const 310 | { 311 | // simple method that finds the index of a content by Header, content frame 312 | // or content pane. 313 | int index = -1; 314 | if (name != "") { 315 | auto result = std::find_if( 316 | this->contentPanes.begin(), this->contentPanes.end(), 317 | [&name](ContentPane *pane) { return pane->getHeader() == name; }); 318 | if (result != std::end(this->contentPanes)) { 319 | // get the index by subtracting begin iterator from result 320 | // iterator 321 | // TODO: Is this cast really necessary? 322 | index = static_cast(result - this->contentPanes.begin()); 323 | } 324 | } 325 | if (cframe != nullptr) { 326 | auto result = 327 | std::find_if(this->contentPanes.begin(), this->contentPanes.end(), 328 | [cframe](ContentPane *cpane) { 329 | return cpane->getContentFrame() == cframe; 330 | }); 331 | if (result != std::end(this->contentPanes)) { 332 | index = static_cast(result - this->contentPanes.begin()); 333 | } 334 | } 335 | if (cpane != nullptr) { 336 | auto result = std::find(this->contentPanes.begin(), 337 | this->contentPanes.end(), cpane); 338 | if (result != std::end(this->contentPanes)) { 339 | index = static_cast(result - this->contentPanes.begin()); 340 | } 341 | } 342 | return index; 343 | } 344 | 345 | bool QAccordion::checkIndexError(uint index, bool sizeIndexAllowed, 346 | const QString &errMessage) 347 | { 348 | // sizeIndexAllowed is only used by inserting. If there is one pane you will 349 | // be able to insert a new one before and after. 350 | // FIXME: Actually there seem to be some bugs hidden here. User may now for 351 | // example delete index 0 even if there isn't any content pane. I think we 352 | // excluded checking 0 because of inserting. 353 | // Update, I removed the 0 exclusion in the second if statement. Really a 354 | // fix?? 355 | if (sizeIndexAllowed) { 356 | if (index != 0 && index > this->contentPanes.size()) { 357 | qDebug() << Q_FUNC_INFO << errMessage; 358 | this->errorString = errMessage; 359 | return true; 360 | } 361 | } else { 362 | if (index >= this->contentPanes.size()) { 363 | qDebug() << Q_FUNC_INFO << errMessage; 364 | this->errorString = errMessage; 365 | return true; 366 | } 367 | } 368 | return false; 369 | } 370 | 371 | void QAccordion::handleClickedSignal(ContentPane *cpane) 372 | { 373 | // if the clicked content pane is open we simply close it and return 374 | if (cpane->getActive()) { 375 | // if collapsible and multiActive are false we are not allowed to close 376 | // this pane 377 | if (!this->collapsible && !this->multiActive) { 378 | return; 379 | } 380 | // when multiActive is true we have to check if there is any other open 381 | // cpane. if so we can close this one 382 | std::vector activePanes; 383 | if (!this->collapsible) { 384 | this->getActiveContentPaneIndex(activePanes); 385 | if (activePanes.size() == 1) { 386 | return; // only one active --> good bye :) 387 | } 388 | } 389 | cpane->closeContentPane(); 390 | return; 391 | } 392 | // if it is not open we will open it and search our vector for other 393 | // panes that are already open. 394 | // TODO: Is it really necessary to search for more than one open cpane? 395 | if (!cpane->getActive()) { 396 | // check if multiActive is allowed 397 | if (!this->getMultiActive()) { 398 | std::for_each(this->contentPanes.begin(), this->contentPanes.end(), 399 | [](ContentPane *pane) { 400 | if (pane->getActive()) { 401 | pane->closeContentPane(); 402 | } 403 | }); 404 | } 405 | cpane->openContentPane(); 406 | } 407 | } 408 | 409 | void QAccordion::numberOfPanesChanged(int number) 410 | { 411 | // automatically open contentpane if we have only one and collapsible is 412 | // false 413 | if (number == 1 && !this->collapsible) { 414 | this->contentPanes.at(0)->openContentPane(); 415 | } 416 | } 417 | 418 | void QAccordion::paintEvent(ATTR_UNUSED QPaintEvent *event) 419 | { 420 | QStyleOption o; 421 | o.initFrom(this); 422 | QPainter p(this); 423 | style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this); 424 | } 425 | --------------------------------------------------------------------------------