pax_global_header00006660000000000000000000000064134642165060014521gustar00rootroot0000000000000052 comment=acc42e93bf217115c2d2310e4c421f9090c017fc deepin-menu-3.4.8/000077500000000000000000000000001346421650600137435ustar00rootroot00000000000000deepin-menu-3.4.8/.clog.toml000066400000000000000000000002231346421650600156370ustar00rootroot00000000000000[clog] repository = "https://github.com/linuxdeepin/deepin-menu" from-latest-tag = true changelog = "CHANGELOG.md" [sections] Others = ["chore"] deepin-menu-3.4.8/.gitignore000066400000000000000000000001371346421650600157340ustar00rootroot00000000000000.#* *.pyc *.pyo deepin_menu.egg-info build dist core *.o moc_* qrc_*.cpp deepin-menu.pro.user* deepin-menu-3.4.8/CHANGELOG.md000066400000000000000000000144161346421650600155620ustar00rootroot00000000000000 ### 3.4.6 (2019-04-28) #### Others * set isScaled default value to true ([f2f6de0a](https://github.com/linuxdeepin/deepin-menu/commit/f2f6de0acd5a663183b4df29ff4d337f39723b9b)) ### 3.4.5 (2019-04-28) #### Features * **menu:** Add a description of whether to scale ([aefb41b1](https://github.com/linuxdeepin/deepin-menu/commit/aefb41b1525653b88fee1e116c0b9100c04f2fa6)) ## 3.4.4 (2019-04-25) ### 3.4.3 (2019-04-12) #### Bug Fixes * **pos:** HiDPI screen coordinates ([8d3cae29](https://github.com/linuxdeepin/deepin-menu/commit/8d3cae292312fc56b16e610afb8bb65641fcaefc)) ### 3.4.2 (2019-04-12) #### Bug Fixes * position shift when use kwin ([c86bbfd4](https://github.com/linuxdeepin/deepin-menu/commit/c86bbfd4643ceef903b1469ee4847b1cba770711)) ### 3.4.1 (2018-12-07) #### Features * support touchscreen ([18abfd60](https://github.com/linuxdeepin/deepin-menu/commit/18abfd60a9291c34c200ce3a8aa50ccf0cd99d39)) ## 3.4.0 (2018-09-07) #### Bug Fixes * not hide menu when unregisterMenu ([cba7f135](https://github.com/linuxdeepin/deepin-menu/commit/cba7f135edbdbaa7df903f43dea86a0cfbafb038)) ### 3.3.10 (2018-07-20) #### Bug Fixes * not emit signal ([af266ccf](https://github.com/linuxdeepin/deepin-menu/commit/af266ccf7ecc615f7dc2035969694de3606ef384)) ### 3.3.9 (2018-07-20) #### Bug Fixes * wrong menu style on Qt 5.10.x ([d423e499](https://github.com/linuxdeepin/deepin-menu/commit/d423e499dbb9e4fd1a5c46a5311909776bbd6313)) ### 3.3.8 (2018-06-13) #### Bug Fixes * **subment:** submenu not send invoked singnals ([8fbf86d8](https://github.com/linuxdeepin/deepin-menu/commit/8fbf86d8b34371f10fb8af1f71ee308294633191)) ## 3.3.7 (2018-05-31) #### Bug Fixes * menu dead lock on destructor ([a865d4f9](https://github.com/linuxdeepin/deepin-menu/commit/a865d4f9040e0f0102aaa9ce68d5d8a399349b46)) ## 3.3.6 (2018-05-30) * Minor bug fixes. ## 3.3.5 (2018-05-29) * Fix menu unregister but not notify signals emitted ## 3.3.4 (2018-05-24) #### Features * Add oom score ([aeda7e58](https://github.com/linuxdeepin/deepin-menu/commit/aeda7e58658184c1305b2114fa20fd9248de2d61)) #### Bug Fixes * not click ([82196c3a](https://github.com/linuxdeepin/deepin-menu/commit/82196c3a4a14ff189f06831d02bc1f844b5ba53b)) * use DRegionMonitor replace all grab ([5dc5e63f](https://github.com/linuxdeepin/deepin-menu/commit/5dc5e63f24973d17ec371ef9e10cc0387b738997)) * click outside the menu to hide ([2a4f2f30](https://github.com/linuxdeepin/deepin-menu/commit/2a4f2f3093daadf4b751f705aa3b3583f3238a0d)) ## 3.3.3 (2018-05-04) #### Bug Fixes * desktop menu cannot hide ([80505421](https://github.com/linuxdeepin/deepin-menu/commit/80505421a26d704e9c819829651bc684412c6394)) ### 3.3.2 (2018-03-26) #### Bug Fixes * prevent memory leaks, use QPointer for MenuObject ([7511080e](https://github.com/linuxdeepin/deepin-menu/commit/7511080ec142709b7f5bdefba84627c2ad82f234)) * crash cause menu adapter double free ([41a9b79a](https://github.com/linuxdeepin/deepin-menu/commit/41a9b79a8734cbd04b9194647420f81e52633ff3)) ### 3.3.1 (2018-03-22) #### Bug Fixes * **ddesktopmenu:** remove BypassWindowManagerHint ([92779b8c](https://github.com/linuxdeepin/deepin-menu/commit/92779b8ca7228c8fa5206acc554459aa8da6737d)) ## 3.3.0 (2018-03-08) #### Bug Fixes * deepin-menu isn't counted as DE component ([200f2a77](https://github.com/linuxdeepin/deepin-menu/commit/200f2a77740149c6fa5d7ca0aa513cb194098d58)) * Adapt lintian ([83f836e2](https://github.com/linuxdeepin/deepin-menu/commit/83f836e2a762a80b4fbec20eac39a316c894329a)) * **ddesktopmenu:** remove DReigonMonitor ([a541e01a](https://github.com/linuxdeepin/deepin-menu/commit/a541e01a1b09d60cb6c46defaec5e85096ddc3d3)) * **debian:** remove useless depend ([9e459981](https://github.com/linuxdeepin/deepin-menu/commit/9e45998180cfa55a9c1136772621acbca851474c)) * **desktopmenu:** add accessible name for desktopmenu ([0f220778](https://github.com/linuxdeepin/deepin-menu/commit/0f220778c806f36a66aaa705f91390b4704e26b4)) * **dockmenu:** * set border alpha is 0 ([a1d3388b](https://github.com/linuxdeepin/deepin-menu/commit/a1d3388b97418f717124897ae61b3126f36f93b7)) * remove use DRegionMonitor ([abc53564](https://github.com/linuxdeepin/deepin-menu/commit/abc535647ef8bf00e8ba77eb838cd593e28ae761)) * reduce delay time ([417d90d2](https://github.com/linuxdeepin/deepin-menu/commit/417d90d2af4338abf7e0cf259b3e7dd507e78cc6)) #### Others * remove autostart desktop file ([09e65bd7](https://github.com/linuxdeepin/deepin-menu/commit/09e65bd7bd46c9aa6cdd1b205aa4e4f7be33ef0c)) ## 3.2.0 (2017-11-28) #### Bug Fixes * **dockmenu:** multi screen coordinates are not correct ([e2d60cfe](https://github.com/linuxdeepin/deepin-menu/commit/e2d60cfe9d5591cb48665b8ea584da7f96c1c1d8)) ### 3.1.8 (2017-11-06) #### Features * font size change with system font settings ([642f4c6a](https://github.com/linuxdeepin/deepin-menu/commit/642f4c6ad8a55fb35a8bfaf0bd3fe3efc8060862)) #### Bug Fixes * desktop menu hide immediately after showing ([79faf768](https://github.com/linuxdeepin/deepin-menu/commit/79faf768bf20c34a93adb6c73a4d742c5310aedd)) * **dock menu:** no spacing between items ([fd39cc14](https://github.com/linuxdeepin/deepin-menu/commit/fd39cc144b39f2fe80335fb304ed64762252ed1a)) ### 3.1.7 (2017-10-24) #### Others * setup .clog.toml ([f751c10c](https://github.com/linuxdeepin/deepin-menu/commit/f751c10c3dbed6d920a1af2b297c38809e3e7853)) #### Bug Fixes * support hidpi of ddesktopmenu ([56a8cfc3](https://github.com/linuxdeepin/deepin-menu/commit/56a8cfc365eb5c2d5612f158d8db6716cec41a43)) #### Features * support hiDPI use DRegionMonitor ([bd5c8229](https://github.com/linuxdeepin/deepin-menu/commit/bd5c8229728d4429444ed9061d6b9cfe2f604eba)) * **hidpi:** add basic hidpi support ([77c46c63](https://github.com/linuxdeepin/deepin-menu/commit/77c46c63f55ec8f510bab4db4e0c276c6a94e7a6)) deepin-menu-3.4.8/LICENSE000066400000000000000000001045131346421650600147540ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . deepin-menu-3.4.8/README.md000066400000000000000000000020361346421650600152230ustar00rootroot00000000000000# Deepin Menu Deepin Menu is the unified menu service for Deepin Desktop Environment. ## Dependencies ### Build dependencies * Qt (>= 5.10) * dtkwidget (>= 2.0.6) ### Runtime dependencies * DBus * Qt5 (>= 5.10) * Qt5-Widgets * Qt5-Gui * Qt5-DBus * dtkwidget (>=2.0.6) ## Installation ### Build from source code 1. Make sure you have installed all dependencies. 2. Build: ``` $ cd deepin-menu $ mkdir build $ cd build $ qmake .. $ make ``` 3. Install: ``` $ sudo make install ``` ## Usage Run the binary, the two DBus interfaces com.deepin.Menu.Manager and com.deepin.Menu it provides should be sufficient to explain itself. More details on the data structure it uses needs to be done. ## Getting help You may also find these channels useful if you encounter any other issues: * [Gitter](https://gitter.im/orgs/linuxdeepin/rooms) * [IRC Channel](https://webchat.freenode.net/?channels=deepin) * [Official Forum](https://bbs.deepin.org/) * [Wiki](http://wiki.deepin.org/) ## License Deepin Menu is licensed under [GPLv3](LICENSE). deepin-menu-3.4.8/data/000077500000000000000000000000001346421650600146545ustar00rootroot00000000000000deepin-menu-3.4.8/data/com.deepin.menu.Manager.xml000066400000000000000000000006611346421650600217360ustar00rootroot00000000000000 deepin-menu-3.4.8/data/com.deepin.menu.Menu.xml000066400000000000000000000026251346421650600212720ustar00rootroot00000000000000 deepin-menu-3.4.8/data/com.deepin.menu.service000066400000000000000000000000771346421650600212260ustar00rootroot00000000000000[D-BUS Service] Name=com.deepin.menu Exec=/usr/bin/deepin-menu deepin-menu-3.4.8/debian/000077500000000000000000000000001346421650600151655ustar00rootroot00000000000000deepin-menu-3.4.8/debian/changelog000066400000000000000000000026731346421650600170470ustar00rootroot00000000000000deepin-menu (3.0.4-1) stable; urgency=low * Autobuild Tag 3.0.4 -- TagBuilder Fri, 12 Aug 2016 18:59:32 +0000 deepin-menu (3.0.3-1) stable; urgency=low * Autobuild Tag 3.0.3 -- TagBuilder Wed, 20 Jul 2016 07:20:30 +0000 deepin-menu (3.0.2-1) stable; urgency=low * Autobuild Tag 3.0.2 -- TagBuilder Fri, 22 Jan 2016 19:37:39 +0000 deepin-menu (3.0.1-1) stable; urgency=low * Autobuild Tag 3.0.1 -- TagBuilder Tue, 12 Jan 2016 19:51:31 +0000 deepin-menu (3.0.0-1) stable; urgency=low * Autobuild Tag 3.0.0 -- TagBuilder Mon, 28 Dec 2015 21:06:03 +0000 deepin-menu (2.90.2-1) stable; urgency=low * Autobuild Tag 2.90.2 -- TagBuilder Wed, 09 Dec 2015 22:06:30 +0000 deepin-menu (2.90.1-2) stable; urgency=low * Rebuild Version 2.90.1 -- TagBuilder Fri, 20 Nov 2015 09:50:48 +0000 deepin-menu (2.90.1-1) stable; urgency=low * Autobuild Tag 2.90.1 -- TagBuilder Fri, 20 Nov 2015 09:50:26 +0000 deepin-menu (2.3.0-1) stable; urgency=low * Autobuild Tag 2.3.0-1 -- TagBuilder Wed, 01 Jul 2015 09:32:07 +0000 deepin-menu (0.0.0) unstable; urgency=medium * Unstable release. -- 宋文武 Thu, 13 Nov 2014 16:05:26 +0800 deepin-menu-3.4.8/debian/compat000066400000000000000000000000021346421650600163630ustar00rootroot000000000000009 deepin-menu-3.4.8/debian/control000066400000000000000000000011341346421650600165670ustar00rootroot00000000000000Source: deepin-menu Priority: extra Section: devel Maintainer: Deepin Packages Builder Build-Depends: debhelper (>= 9), pkg-config, qt5-qmake, libdtkwidget-dev, qtbase5-private-dev, libglib2.0-dev, libxrender-dev, libmtdev-dev, libfontconfig1-dev, libfreetype6-dev, libegl1-mesa-dev, libqt5xdgiconloader-dev, libqt5svg5-dev Standards-Version: 3.9.8 Homepage: https://github.com/linuxdeepin/deepin-menu Package: deepin-menu Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: Deepin menu service Deepin menu service for building beautiful menus. deepin-menu-3.4.8/debian/copyright000066400000000000000000000016451346421650600171260ustar00rootroot00000000000000Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: deepin-menu Files: * Copyright: 2017 Deepin Technology Co., Ltd. License: GPL-3+ This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. . This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License along with this program. If not, see . On Debian systems, the complete text of the GNU General Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". deepin-menu-3.4.8/debian/rules000077500000000000000000000007301346421650600162450ustar00rootroot00000000000000#!/usr/bin/make -f # -*- makefile -*- # Sample debian/rules that uses debhelper. # This file was originally written by Joey Hess and Craig Small. # As a special exception, when this file is copied by dh-make into a # dh-make output file, you may use that output file without restriction. # This special exception was added by Craig Small in version 0.37 of dh-make. # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 export QT_SELECT=5 %: dh $@ --parallel deepin-menu-3.4.8/debian/source/000077500000000000000000000000001346421650600164655ustar00rootroot00000000000000deepin-menu-3.4.8/debian/source/format000066400000000000000000000000151346421650600176740ustar00rootroot000000000000003.0 (native) deepin-menu-3.4.8/deepin-menu.desktop000066400000000000000000000002071346421650600175430ustar00rootroot00000000000000[Desktop Entry] Type=Application Name=Deepin Menu Exec=/usr/bin/deepin-menu NoDisplay=true OnlyShowIn=Deepin X-Deepin-DEComponent=true deepin-menu-3.4.8/deepin-menu.pro000066400000000000000000000021771346421650600167020ustar00rootroot00000000000000#------------------------------------------------- # # Project created by QtCreator 2014-08-14T14:55:09 # #------------------------------------------------- QT += core gui dbus greaterThan(QT_MINOR_VERSION, 7): QT += gui-private else: QT += platformsupport-private greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = deepin-menu TEMPLATE = app CONFIG += c++11 link_pkgconfig PKGCONFIG += dtkwidget SOURCES += src/main.cpp \ src/ddesktopmenu.cpp \ src/utils.cpp \ src/dmenucontent.cpp \ src/dbus_manager_adaptor.cpp \ src/dbus_menu_adaptor.cpp \ src/manager_object.cpp \ src/menu_object.cpp \ src/ddockmenu.cpp \ src/dmenuapplication.cpp \ src/dabstractmenu.cpp HEADERS += \ src/ddesktopmenu.h \ src/utils.h \ src/dmenucontent.h \ src/dbus_manager_adaptor.h \ src/dbus_menu_adaptor.h \ src/manager_object.h \ src/menu_object.h \ src/ddockmenu.h \ src/dmenuapplication.h \ src/dabstractmenu.h dbus.path = /usr/share/dbus-1/services dbus.files = data/com.deepin.menu.service RESOURCES += \ images.qrc target.path = /usr/bin INSTALLS += target dbus deepin-menu-3.4.8/deepin_menu/000077500000000000000000000000001346421650600162335ustar00rootroot00000000000000deepin-menu-3.4.8/deepin_menu/DBusInterfaces.py000066400000000000000000000065331346421650600214550ustar00rootroot00000000000000#! /usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2015 Deepin Technology Co., Ltd. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. from PyQt5.QtCore import pyqtSignal from PyQt5.QtDBus import QDBusAbstractInterface, QDBusConnection, QDBusReply class MenuManagerInterface(QDBusAbstractInterface): def __init__(self): super(MenuManagerInterface, self).__init__("com.deepin.menu", "/com/deepin/menu", "com.deepin.menu.Manager", QDBusConnection.sessionBus(), None) def registerMenu(self): return self.call('RegisterMenu') def unregisterMenu(self, objPath): self.call('UnregisterMenu', objPath) class MenuObjectInterface(QDBusAbstractInterface): ItemInvoked = pyqtSignal(str, bool) ItemTextSet = pyqtSignal(str, str) ItemActivitySet = pyqtSignal(str, bool) ItemCheckedSet = pyqtSignal(str, bool) MenuUnregistered = pyqtSignal() def __init__(self, path): super(MenuObjectInterface, self).__init__("com.deepin.menu", path, "com.deepin.menu.Menu", QDBusConnection.sessionBus(), None) def showMenu(self, jsonContent): self.asyncCall('ShowMenu', jsonContent) def setItemText(self, id, value): self.asyncCall('SetItemText', id, value) def setItemActivity(self, id, value): self.asyncCall('SetItemActivity', id, value) def setItemChecked(self, id, value): self.asyncCall('SetItemChecked', id, value) class XMouseAreaInterface(QDBusAbstractInterface): ButtonPress = pyqtSignal(int, int, int, int) KeyPress = pyqtSignal(str, int, int, int) MotionMove = pyqtSignal(int, int, int) def __init__(self): super(XMouseAreaInterface, self).__init__("com.deepin.api.XMouseArea", "/com/deepin/api/XMouseArea", "com.deepin.api.XMouseArea", QDBusConnection.sessionBus(), None) def registerArea(self, x1, x2, y1, y2, flag): msg = self.call("RegisterArea", x1, x2, y1, y2, flag) print msg.errorName(), msg.errorMessage() reply = QDBusReply(msg) return reply.value() def unregisterArea(self, id): self.call("UnregisterArea", id) class DisplayPropertyInterface(QDBusAbstractInterface): def __init__(self): super(DisplayPropertyInterface, self).__init__( "com.deepin.daemon.Display", "/com/deepin/daemon/Display", "org.freedesktop.DBus.Properties", QDBusConnection.sessionBus(), None) def getPrimaryRect(self): msg = self.call("Get", "com.deepin.daemon.Display", "PrimaryRect") reply = QDBusReply(msg) return reply.value() deepin-menu-3.4.8/deepin_menu/__init__.py000066400000000000000000000005331346421650600203450ustar00rootroot00000000000000#! /usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2015 Deepin Technology Co., Ltd. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. deepin-menu-3.4.8/deepin_menu/menu.py000066400000000000000000000232371346421650600175600ustar00rootroot00000000000000#! /usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2015 Deepin Technology Co., Ltd. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. import json from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal from PyQt5.QtDBus import QDBusReply from DBusInterfaces import MenuManagerInterface, MenuObjectInterface def parseMenuItem(menuItem): assert len(menuItem) >= 2 result = MenuItem(menuItem[0], menuItem[1]) if len(menuItem) > 2: result.setIcons(menuItem[2]) if len(menuItem) > 3: result.setSubMenu(parseMenu(Menu(is_root=False), menuItem[3])) if len(menuItem) > 4: result.extra = menuItem[4] return result def parseMenu(obj, menu): result = obj for menuItem in menu: if menuItem == None: result.addMenuItem(MenuSeparator()) elif isinstance(menuItem, MenuItem): result.addMenuItem(menuItem) else: result.addMenuItem(parseMenuItem(menuItem)) return result def validateItemGroupInfo(item, groupId, groupType): info = item.id.split(":") item.id = "%s:%s:%s" % (groupId, groupType, info[-1]) class MenuItem(QObject): def __init__(self, id, text, icons=None, subMenu=None, isActive=True, isCheckable=False, checked=False, showCheckmark=True, extra=""): super(MenuItem, self).__init__() self.id = id self.text = text self.extra = extra self.icons = icons or () self.subMenu = subMenu or Menu(is_root=False) self.isActive = isActive self.isCheckable = isCheckable self.checked = checked self.showCheckmark = self.isCheckable and showCheckmark @property def serializableContent(self): iconNormal = "" iconHover = "" iconInactive = "" if len(self.icons) > 0: iconNormal = self.icons[0] iconHover = self.icons[0] iconInactive = self.icons[0] if len(self.icons) > 1: iconHover = self.icons[1] if len(self.icons) > 2: iconInactive = self.icons[2] return {"itemId": self.id, "itemIcon": iconNormal, "itemIconHover": iconHover, "itemIconInactive": iconInactive, "itemText": self.text, "itemExtra": self.extra, "itemSubMenu": self.subMenu.serializableItemList, "isActive": self.isActive, "isCheckable": self.isCheckable, "checked": self.checked, "showCheckmark": self.showCheckmark} def setSubMenu(self, menu): self.subMenu = menu def setIcons(self, icons): self.icons = icons @property def hasSubMenu(self): return len(self.subMenu.items) != 0 def __str__(self): return json.dumps(self.serializableContent) class CheckableMenuItem(MenuItem): def __init__(self, id, text, checked=False, showCheckmark=True, extra=""): super(CheckableMenuItem, self).__init__(id, text, isCheckable=True, checked=checked, showCheckmark=showCheckmark, extra=extra) class MenuSeparator(MenuItem): def __init__(self): super(MenuSeparator, self).__init__("", "", isActive=False) class Menu(QObject): itemClicked = pyqtSignal(str, bool) menuDismissed = pyqtSignal() def __init__(self, items=None, is_root=True, checkableMenu=False, singleCheck=False): super(Menu, self).__init__() self.items = [] if items: parseMenu(self, items) if is_root: self.managerIface = MenuManagerInterface() self.menuIface = None self.checkableMenu = checkableMenu self.singleCheck = singleCheck @property def serializableItemList(self): items= [] for item in self.items: items.append(item.serializableContent) return {"items": items, "checkableMenu": self.checkableMenu, "singleCheck": self.singleCheck} def addMenuItem(self, item): self.items.append(item) def addMenuItems(self, items): for item in items: self.addMenuItem(item) def getItemById(self, id): for item in self.items: if item.hasSubMenu: if item.subMenu.getItemById(id): return item.subMenu.getItemById(id) if item.id == id: return item return None def setItemActivity(self, id, value): item = self.getItemById(id) if item: item.isActive = value if self.menuIface: self.menuIface.setItemActivity(id, value) def setItemText(self, id, value): item = self.getItemById(id) if item: item.text = value if self.menuIface: self.menuIface.setItemText(id, value) def showRectMenu(self, x, y): msg = self.managerIface.registerMenu() reply = QDBusReply(msg) self.menuIface = MenuObjectInterface(reply.value()) self.menuIface.showMenu(json.dumps({"x": x, "y": y, "isDockMenu": False, "menuJsonContent": str(self)})) self.menuIface.ItemInvoked.connect(self.itemInvokedSlot) self.menuIface.MenuUnregistered.connect(self.menuUnregisteredSlot) def showDockMenu(self, x, y, cornerDirection="down"): msg = self.managerIface.registerMenu() reply = QDBusReply(msg) self.menuIface = MenuObjectInterface(reply.value()) self.menuIface.showMenu(json.dumps({"x": x, "y": y, "isDockMenu": True, "cornerDirection": cornerDirection, "menuJsonContent": str(self)})) self.menuIface.ItemInvoked.connect(self.itemInvokedSlot) self.menuIface.MenuUnregistered.connect(self.menuUnregisteredSlot) @pyqtSlot(str, bool) def itemInvokedSlot(self, itemId, checked): self.itemClicked.emit(itemId, checked) @pyqtSlot() def menuUnregisteredSlot(self): self.menuDismissed.emit() def __str__(self): return json.dumps(self.serializableItemList) class CheckboxMenu(Menu): def __init__(self, groupId, items): self.groupId = groupId super(CheckboxMenu, self).__init__(items, checkableMenu=True, singleCheck=False) def addMenuItem(self, item): validateItemGroupInfo(item, self.groupId, "checkbox") item.isCheckable = True item.showCheckmark = True self.items.append(item) class RadioButtonMenu(Menu): def __init__(self, groupId, items): self.groupId = groupId super(RadioButtonMenu, self).__init__(items, checkableMenu=True, singleCheck=True) def addMenuItem(self, item): validateItemGroupInfo(item, self.groupId, "radio") item.isCheckable = True item.showCheckmark = True self.items.append(item) if __name__ == "__main__": import sys from PyQt5.QtCore import QCoreApplication app = QCoreApplication([]) @pyqtSlot(str, bool) def invoked(s, c): print "id: ", s, ", checked: ", c # menu.setItemText("id_nonactive", "hello") # menu.setItemActivity("id_nonactive", True) @pyqtSlot() def dismissed(): print "dismissed" # 1) # driver = MenuItem("id_driver", "Driver", "/usr/share/icons/Deepin/apps/16/preferences-driver.png") # display = MenuItem("id_display", "Display", "/usr/share/icons/Deepin/apps/16/preferences-display.png") # show = Menu() # show.addMenuItem(MenuItem("id_sub_display", "Display", "/usr/share/icons/Deepin/apps/16/preferences-display.png")) # display.setSubMenu(show) # menu = Menu(is_root=True) # menu.addMenuItems([driver, display]) # menu.showMenu(200, 200) # 2) menu = Menu([("id_driver", "Driver", ("/usr/share/icons/Deepin/apps/16/preferences-display.png",)), None, ("id_display", "_Display", (), [("display_sub1", "Display One"), ("display_sub2", "Display Two"),]), ("id_radio", "RadioButtonMenu"), ("id_checkbox", "_CheckBoxMenu"), ("id_extra", "_ExtraTest", (), [], "Ctrl-X"), MenuSeparator(), CheckableMenuItem("radio_group_2:radio:radio2_sub1", "One"), CheckableMenuItem("radio_group_2:radio:radio2_sub2", "Two"), None, CheckableMenuItem("checkbox_group_2:checkbox:checkbox2_sub1", "One"), CheckableMenuItem("checkbox_group_2:checkbox:checkbox2_sub2", "Two"), None, MenuItem("id_nonactive", "NotActive", isActive=False), CheckableMenuItem("id_check", "CheckMe", True)], is_root=True,) radio_sub = RadioButtonMenu("radio_group_1", [("id_radio1", "Radio One"), ("id_radio2", "Radio Two"),]) checkbox_sub = CheckboxMenu("checkbox_group_1", [("id_checkbox1", "Checkbox One"), ("id_checkbox2", "Checkbox Two")]) menu.getItemById("id_radio").setSubMenu(radio_sub) menu.getItemById("id_checkbox").setSubMenu(checkbox_sub) # menu.getItemById("id_radio2").showCheckmark = False menu.itemClicked.connect(invoked) menu.menuDismissed.connect(dismissed) menu.showRectMenu(300, 300) #menu.showDockMenu(1366, 768) sys.exit(app.exec_()) deepin-menu-3.4.8/images.qrc000066400000000000000000000007751346421650600157300ustar00rootroot00000000000000 images/arrow-light.png images/arrow-light-hover.png images/arrow-light-inactive.png images/check_dark_hover.png images/check_dark_inactive.png images/check_dark_normal.png images/check_light_hover.png images/check_light_inactive.png images/check_light_normal.png deepin-menu-3.4.8/images/000077500000000000000000000000001346421650600152105ustar00rootroot00000000000000deepin-menu-3.4.8/images/arrow-light-hover.png000066400000000000000000000002461346421650600213000ustar00rootroot00000000000000PNG  IHDR /3gAMA a]IDATc`hdw@"C'Q,0파k:@ܥ &?@,ro@\M Y@al 7NKIENDB`deepin-menu-3.4.8/images/arrow-light-inactive.png000066400000000000000000000003321346421650600217530ustar00rootroot00000000000000PNG  IHDR /3gAMA aIDATc`Pf xXccc  FFk, 6ٳgeee?^ZZ0"k755U33&d &&_ ann./w3ϟ@v?\a*Ap@?IfIENDB`deepin-menu-3.4.8/images/arrow-light.png000066400000000000000000000003011346421650600201470ustar00rootroot00000000000000PNG  IHDR /3gAMA axIDATc`P6 n߾ Y%%%JHHs  ȹd%$@0􉑑/c066v344tD ~As*?ia4e.}IENDB`deepin-menu-3.4.8/images/check_dark_hover.png000066400000000000000000000003151346421650600211760ustar00rootroot00000000000000PNG  IHDR  gAMA aIDATc`Ċx@Z3T _@lO2P{ .+rxX&dsE ^ @i@|y@@z1_ኁ@|q1budPBo1#a dC*t/IENDB`deepin-menu-3.4.8/images/check_dark_inactive.png000066400000000000000000000003321346421650600216540ustar00rootroot00000000000000PNG  IHDR  gAMA aIDAT} @w@`!SY "R Z`Xvw3$谖2V[huȲF1)"U!T (()Gx!5StNjѫ4L=mo/:-)=.Hj:+h[55QIENDB`deepin-menu-3.4.8/images/check_dark_normal.png000066400000000000000000000003251346421650600213440ustar00rootroot00000000000000PNG  IHDR  gAMA aIDATc`" %Lxԁ8:>Ob5|D & L @ ـL ȸ&;sA1@$S@\@V1@ m@^iTT M@<Pex@@& .H"xIENDB`deepin-menu-3.4.8/images/check_light_hover.png000066400000000000000000000003151346421650600213640ustar00rootroot00000000000000PNG  IHDR  gAMA aIDATc`Ċx@Z3T _@lO2P{ .+rxX&dsE ^ @i@|y@@z1_ኁ@|q1budPBo1#a dC*t/IENDB`deepin-menu-3.4.8/images/check_light_inactive.png000066400000000000000000000004171346421650600220460ustar00rootroot00000000000000PNG  IHDR  gAMA aIDATc`hnnRˆG)##* &233o={s&l&*rdbb:RRä/7OΝ;w &asOcccVO4 Lf:ׯ_5lIII [ϟ? H3?ʺ*@顋m@Xu~IENDB`deepin-menu-3.4.8/images/check_light_normal.png000066400000000000000000000004101346421650600215250ustar00rootroot00000000000000PNG  IHDR  gAMA aIDATcf}x1022hTgddkhh p*266Vښh<ˑ#Gރw7.\Srl/_;88;H$hF>M 4̙37Q8@2ՁCΟ?Y \EGBjSaIENDB`deepin-menu-3.4.8/src/000077500000000000000000000000001346421650600145325ustar00rootroot00000000000000deepin-menu-3.4.8/src/dabstractmenu.cpp000066400000000000000000000021471346421650600200760ustar00rootroot00000000000000/* * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #include "dabstractmenu.h" #include DAbstractMenu::DAbstractMenu() { } void DAbstractMenu::releaseFocus() { } void DAbstractMenu::setItems(QJsonArray) { } void DAbstractMenu::setItemActivity(const QString &, bool) { } void DAbstractMenu::setItemChecked(const QString &, bool) { } void DAbstractMenu::setItemText(const QString &, const QString &) { } deepin-menu-3.4.8/src/dabstractmenu.h000066400000000000000000000022771346421650600175470ustar00rootroot00000000000000/* * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #ifndef DABSTRACTMENU_H #define DABSTRACTMENU_H #include class DAbstractMenu { public: explicit DAbstractMenu(); public: virtual void releaseFocus(); virtual void setItems(QJsonArray items); virtual void setItemActivity(const QString &itemId, bool isActive); virtual void setItemChecked(const QString &itemId, bool checked); virtual void setItemText(const QString &itemId, const QString &text); }; #endif // DABSTRACTMENU_H deepin-menu-3.4.8/src/dbus_manager_adaptor.cpp000066400000000000000000000040671346421650600214060ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ /* * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -c ManagerAdaptor -a dbus_manager_adaptor.h:dbus_manager_adaptor.cpp com.deepin.menu.Manager.xml * * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). * * This is an auto-generated file. * Do not edit! All changes made to it will be lost. */ #include "dbus_manager_adaptor.h" #include #include #include #include #include #include #include /* * Implementation of adaptor class ManagerAdaptor */ ManagerAdaptor::ManagerAdaptor(QObject *parent) : QDBusAbstractAdaptor(parent) { // constructor setAutoRelaySignals(true); } ManagerAdaptor::~ManagerAdaptor() { // destructor } QDBusObjectPath ManagerAdaptor::RegisterMenu() { // handle method call com.deepin.menu.Manager.RegisterMenu QDBusObjectPath menuObjectPath; QMetaObject::invokeMethod(parent(), "RegisterMenu", Q_RETURN_ARG(QDBusObjectPath, menuObjectPath)); return menuObjectPath; } void ManagerAdaptor::UnregisterMenu(const QString &menuObjectPath) { // handle method call com.deepin.menu.Manager.UnregisterMenu QMetaObject::invokeMethod(parent(), "UnregisterMenu", Q_ARG(QString, menuObjectPath)); } deepin-menu-3.4.8/src/dbus_manager_adaptor.h000066400000000000000000000043671346421650600210560ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ /* * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -c ManagerAdaptor -a dbus_manager_adaptor.h:dbus_manager_adaptor.cpp com.deepin.menu.Manager.xml * * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). * * This is an auto-generated file. * This file may have been hand-edited. Look for HAND-EDIT comments * before re-generating it. */ #ifndef DBUS_MANAGER_ADAPTOR_H_1405666337 #define DBUS_MANAGER_ADAPTOR_H_1405666337 #include #include QT_BEGIN_NAMESPACE class QByteArray; template class QList; template class QMap; class QString; class QStringList; class QVariant; QT_END_NAMESPACE /* * Adaptor class for interface com.deepin.menu.Manager */ class ManagerAdaptor: public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "com.deepin.menu.Manager") Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "") public: ManagerAdaptor(QObject *parent); virtual ~ManagerAdaptor(); public: // PROPERTIES public Q_SLOTS: // METHODS QDBusObjectPath RegisterMenu(); void UnregisterMenu(const QString &menuObjectPath); Q_SIGNALS: // SIGNALS }; #endif deepin-menu-3.4.8/src/dbus_menu_adaptor.cpp000066400000000000000000000047021346421650600207340ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ /* * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -c MenuAdaptor -a dbus_menu_adaptor.h:dbus_menu_adaptor.cpp com.deepin.menu.Menu.xml * * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). * * This is an auto-generated file. * Do not edit! All changes made to it will be lost. */ #include "dbus_menu_adaptor.h" #include #include #include #include #include #include #include /* * Implementation of adaptor class MenuAdaptor */ MenuAdaptor::MenuAdaptor(QObject *parent) : QDBusAbstractAdaptor(parent) { // constructor setAutoRelaySignals(true); } MenuAdaptor::~MenuAdaptor() { // destructor } void MenuAdaptor::SetItemActivity(const QString &itemId, bool isActive) { // handle method call com.deepin.menu.Menu.SetItemActivity QMetaObject::invokeMethod(parent(), "SetItemActivity", Q_ARG(QString, itemId), Q_ARG(bool, isActive)); } void MenuAdaptor::SetItemChecked(const QString &itemId, bool checked) { // handle method call com.deepin.menu.Menu.SetItemChecked QMetaObject::invokeMethod(parent(), "SetItemChecked", Q_ARG(QString, itemId), Q_ARG(bool, checked)); } void MenuAdaptor::SetItemText(const QString &itemId, const QString &text) { // handle method call com.deepin.menu.Menu.SetItemText QMetaObject::invokeMethod(parent(), "SetItemText", Q_ARG(QString, itemId), Q_ARG(QString, text)); } void MenuAdaptor::ShowMenu(const QString &menuJsonContent) { // handle method call com.deepin.menu.Menu.ShowMenu QMetaObject::invokeMethod(parent(), "ShowMenu", Q_ARG(QString, menuJsonContent)); } deepin-menu-3.4.8/src/dbus_menu_adaptor.h000066400000000000000000000060751346421650600204060ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ /* * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -c MenuAdaptor -a dbus_menu_adaptor.h:dbus_menu_adaptor.cpp com.deepin.menu.Menu.xml * * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). * * This is an auto-generated file. * This file may have been hand-edited. Look for HAND-EDIT comments * before re-generating it. */ #ifndef DBUS_MENU_ADAPTOR_H_1405666344 #define DBUS_MENU_ADAPTOR_H_1405666344 #include #include QT_BEGIN_NAMESPACE class QByteArray; template class QList; template class QMap; class QString; class QStringList; class QVariant; QT_END_NAMESPACE /* * Adaptor class for interface com.deepin.menu.Menu */ class MenuAdaptor: public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "com.deepin.menu.Menu") Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "") public: MenuAdaptor(QObject *parent); virtual ~MenuAdaptor(); public: // PROPERTIES public Q_SLOTS: // METHODS void SetItemActivity(const QString &itemId, bool isActive); void SetItemChecked(const QString &itemId, bool checked); void SetItemText(const QString &itemId, const QString &text); void ShowMenu(const QString &menuJsonContent); Q_SIGNALS: // SIGNALS void ItemInvoked(const QString &itemId, bool checked); void MenuUnregistered(); }; #endif deepin-menu-3.4.8/src/ddesktopmenu.cpp000066400000000000000000000126461346421650600177510ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #include "ddesktopmenu.h" #include #include #include #include #include #include #include #include #include DDesktopMenu::DDesktopMenu() : QMenu() , m_monitor(new DRegionMonitor(this)) { setAccessibleName("DesktopMenu"); // NOTE(hualet): don't change those window flags, if you delete below line, deepin-menu // won't even show working with deepin-terminal2 and dde-launcher. setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Tool); connect(m_monitor, &DRegionMonitor::buttonPress, this, [=] (const QPoint &p) { for (auto *menu : m_ownMenus) if (menu->geometry().contains(p)) return; QTimer::singleShot(100, this, &DDesktopMenu::hide); }); } DDesktopMenu::~DDesktopMenu() { m_monitor->unregisterRegion(); releaseKeyboard(); } void DDesktopMenu::setItems(QJsonArray items) { addActionFromJson(this, items); } void DDesktopMenu::setItemActivity(const QString &itemId, bool isActive) { QAction *action = this->action(itemId); if (action) { action->setEnabled(isActive); } } void DDesktopMenu::setItemChecked(const QString &itemId, bool checked) { QAction *action = this->action(itemId); if (action) { action->setChecked(checked); } } void DDesktopMenu::setItemText(const QString &itemId, const QString &text) { QAction *action = this->action(itemId); if (action) { action->setText(text); } } void DDesktopMenu::showMenu(const QPoint pos, bool isScaled) { QPoint handlePos = pos; if (isScaled) { handlePos = pos * devicePixelRatioF(); } // 因为.dde_env已经不包含qt的缩放环境变量,所以收到的都是原始坐标 QList oldList = qApp->screens(); // 得到坐标所在的屏幕 for (auto it = oldList.constBegin(); it != oldList.constEnd(); ++it) { QScreen const * currentScreen = (*it); QRect rect = currentScreen->handle()->geometry(); const QPoint point = rect.topLeft(); if (rect.contains(handlePos)) { // 计算接收坐标距离当前屏幕左边缘的长宽 // 保持原始的topleft和在当前屏幕内坐标的偏移就可以正常显示了 QMenu::popup(QPoint(rect.topLeft() + (handlePos - point) / devicePixelRatioF())); break; } } } void DDesktopMenu::showEvent(QShowEvent *e) { QMenu::showEvent(e); m_monitor->registerRegion(); QTimer::singleShot(100, this, [=] { activateWindow(); grabKeyboard(); }); } void DDesktopMenu::hideEvent(QHideEvent *e) { QMenu::hideEvent(e); m_monitor->unregisterRegion(); releaseKeyboard(); } void DDesktopMenu::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Escape) { hide(); } QMenu::keyPressEvent(event); } QAction *DDesktopMenu::action(const QString &id) { for (QAction *action : actions()) { if (action->property("itemId") == id) { return action; } } return nullptr; } void DDesktopMenu::addActionFromJson(QMenu *menu, const QJsonArray &items) { m_ownMenus << menu; foreach (QJsonValue item, items) { QJsonObject itemObj = item.toObject(); const QString itemText = itemObj["itemText"].toString().replace("_", QString()).replace(QRegExp("\\([^)]+\\)"), QString()); const QString itemIcon = itemObj["itemIcon"].toString(); const QJsonObject subMenuJson = itemObj["itemSubMenu"].toObject(); const QJsonArray subMenuItemsJson = subMenuJson["items"].toArray(); QAction *action = nullptr; if (subMenuItemsJson.count()) { QMenu *subMenu = new QMenu(menu); action = menu->addMenu(subMenu); addActionFromJson(subMenu, subMenuItemsJson); } else if (itemText.isEmpty()) { menu->addSeparator(); continue; } else { action = new QAction(menu); menu->addAction(action); } action->setText(itemText); action->setIcon(QIcon(itemIcon)); action->setEnabled(itemObj["isActive"].toBool()); action->setCheckable(itemObj["isCheckable"].toBool()); action->setChecked(itemObj["checked"].toBool()); action->setProperty("itemId", itemObj["itemId"].toString()); connect(action, &QAction::triggered, menu, [=] (const bool checked) { const QString id = action->property("itemId").toString(); releaseFocus(); releaseMouse(); releaseKeyboard(); emit itemClicked(id, checked); hide(); }); } } deepin-menu-3.4.8/src/ddesktopmenu.h000066400000000000000000000034271346421650600174130ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #ifndef DDESKTOPMENU_H #define DDESKTOPMENU_H #include #include #include "dabstractmenu.h" DWIDGET_USE_NAMESPACE class DDesktopMenu : public QMenu, public DAbstractMenu { Q_OBJECT public: explicit DDesktopMenu(); ~DDesktopMenu(); void setItems(QJsonArray items) Q_DECL_OVERRIDE; void setItemActivity(const QString &itemId, bool isActive) Q_DECL_OVERRIDE; void setItemChecked(const QString &itemId, bool checked) Q_DECL_OVERRIDE; void setItemText(const QString &itemId, const QString &text) Q_DECL_OVERRIDE; void showMenu(const QPoint pos, bool isScaled); signals: void itemClicked(const QString &id, bool checked); protected: void showEvent(QShowEvent *e) Q_DECL_OVERRIDE; void hideEvent(QHideEvent *e) Q_DECL_OVERRIDE; void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; private: QAction *action(const QString &id); void addActionFromJson(QMenu *menu, const QJsonArray &items); DRegionMonitor *m_monitor; QList m_ownMenus; }; #endif // DDESKTOPMENU_H deepin-menu-3.4.8/src/ddockmenu.cpp000066400000000000000000000153211346421650600172110ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #include #include #include #include #include #include #include #include #include #include #include #include "ddockmenu.h" #include "dmenucontent.h" #include "utils.h" DDockMenu::DDockMenu(DDockMenu *parent) : DArrowRectangle(DArrowRectangle::ArrowBottom, parent) , m_menuContent(new DMenuContent(this)) , m_monitor(new DRegionMonitor(this)) { setAttribute(Qt::WA_InputMethodEnabled, false); setMouseTracking(true); m_wmHelper = DWindowManagerHelper::instance(); connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &DDockMenu::onWMCompositeChanged); onWMCompositeChanged(); setAccessibleName("DockMenu"); setBackgroundColor(DBlurEffectWidget::DarkColor); setMargin(0); setArrowWidth(18); setArrowHeight(10); normalStyle = ItemStyle{Qt::transparent, Qt::white, QColor("#646464"), ":/images/check_dark_normal.png", ":/images/arrow-dark.png"}; hoverStyle = ItemStyle{QColor("#2ca7f8"), Qt::white, QColor("#646464"), ":/images/check_dark_hover.png", ":/images/arrow-dark.png"}; inactiveStyle = ItemStyle{Qt::transparent, QColor("#646464"), QColor("#646464"), ":/images/check_dark_inactive.png", ":/images/arrow-dark.png"}; connect(m_monitor, &DRegionMonitor::buttonPress, this, [=] (const QPoint &p) { if (geometry().contains(p)) { // The action performed is not from QAction and needs to be postponed because the menu requires a hover style. QTimer::singleShot(100, this, [=] { m_menuContent->processButtonClick(p); }); } else { qDebug() << "window deactivate, destroy menu"; destroyAll(); } }); } DDockMenu::~DDockMenu() { m_monitor->unregisterRegion(); setVisible(false); releaseFocus(); releaseKeyboard(); } void DDockMenu::setItems(QJsonArray items) { m_menuContent->setCurrentIndex(-1); m_menuContent->clearActions(); foreach (QJsonValue item, items) { QJsonObject itemObj = item.toObject(); QAction *action = new QAction(m_menuContent); QString itemText = itemObj["itemText"].toString().replace("_", QString()).replace(QRegExp("\\([^)]+\\)"), QString()); action->setText(itemText); action->setEnabled(itemObj["isActive"].toBool()); action->setCheckable(itemObj["isCheckable"].toBool() || Utils::menuItemCheckableFromId(itemObj["itemId"].toString())); action->setChecked(itemObj["checked"].toBool()); action->setProperty("itemId", itemObj["itemId"].toString()); action->setProperty("itemIcon", itemObj["itemIcon"].toString()); action->setProperty("itemIconHover", itemObj["itemIconHover"].toString()); action->setProperty("itemIconInactive", itemObj["itemIconInactive"].toString()); action->setProperty("itemSubMenu", itemObj["itemSubMenu"].toObject()); m_menuContent->addAction(action); } // adjust its size according to its content. m_menuContent->setFixedSize(m_menuContent->contentWidth(), m_menuContent->contentHeight()); setContent(m_menuContent); resizeWithContent(); } DDockMenu *DDockMenu::getRootMenu() { return this; } void DDockMenu::showSubMenu(int, int, const QJsonObject &) { } bool DDockMenu::event(QEvent *event) { if (event->type() == QEvent::WindowDeactivate) { // NOTE(sbw): test if we have mouse handle if (rect().contains(mapFromGlobal(QCursor::pos()))) { activateWindow(); } else { qDebug() << "window deactivate, destroy menu"; destroyAll(); } } if (event->type() == QEvent::Move) { qDebug() << pos(); } return DArrowRectangle::event(event); } void DDockMenu::showEvent(QShowEvent *e) { Q_ASSERT(!m_monitor->registered()); m_monitor->registerRegion(); QTimer::singleShot(100, this, [=] { if (!isVisible()) return; if (!isActiveWindow()) activateWindow(); grabKeyboard(); }); DArrowRectangle::showEvent(e); } void DDockMenu::hideEvent(QHideEvent *event) { DArrowRectangle::hideEvent(event); m_monitor->unregisterRegion(); releaseKeyboard(); } void DDockMenu::mouseMoveEvent(QMouseEvent *event) { DArrowRectangle::mouseMoveEvent(event); m_menuContent->processCursorMove(mapToGlobal(event->pos())); } void DDockMenu::keyPressEvent(QKeyEvent *event) { DArrowRectangle::keyPressEvent(event); switch (event->key()) { case Qt::Key_Escape: destroyAll(); break; case Qt::Key_Return: case Qt::Key_Enter: m_menuContent->doCurrentAction(); break; case Qt::Key_Up: m_menuContent->selectPrevious(); break; case Qt::Key_Down: m_menuContent->selectNext(); break; default: break; } } /** * @brief DDockMenu::menuUnderPoint * @param point is a global position. * @return */ DDockMenu *DDockMenu::menuUnderPoint(const QPoint point) { return geometry().contains(point) ? this : nullptr; } void DDockMenu::releaseFocus() { qDebug() << Q_FUNC_INFO << this; releaseMouse(); releaseKeyboard(); } void DDockMenu::destroyAll() { // NOTE(hualet): the events processed by this menu is actually delivered by // xmousearea which is xrecord backed, so if we destroy this window too // early, say immediately after mouse clicks, the actual events will go to // the window behide the menu(desktop for example). QTimer::singleShot(100, this, [this] { qApp->processEvents(); deleteLater(); }); } void DDockMenu::onWMCompositeChanged() { if (m_wmHelper->hasComposite()) setBorderColor(QColor(255, 255, 255, 0)); else setBorderColor(QColor("#2C3238")); } deepin-menu-3.4.8/src/ddockmenu.h000066400000000000000000000042051346421650600166550ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #ifndef DDOCKMENU_H #define DDOCKMENU_H #include "dabstractmenu.h" #include #include #include DWIDGET_USE_NAMESPACE struct ItemStyle { QColor itemBackgroundColor; QColor itemTextColor; QColor itemShortcutColor; QString checkmarkIcon; QString subMenuIndicatorIcon; }; class DMenuContent; class DDockMenu : public DArrowRectangle, public DAbstractMenu { Q_OBJECT public: explicit DDockMenu(DDockMenu *parent = 0); ~DDockMenu(); void setItems(QJsonArray items) Q_DECL_OVERRIDE; void releaseFocus() Q_DECL_OVERRIDE; void destroyAll(); signals: void itemClicked(const QString &id, bool checked); private slots: void onWMCompositeChanged(); private: DDockMenu *getRootMenu(); DDockMenu *menuUnderPoint(const QPoint point); void showSubMenu(int x, int y, const QJsonObject &obj ); protected: bool event(QEvent *event) Q_DECL_OVERRIDE; void showEvent(QShowEvent *e) Q_DECL_OVERRIDE; void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void keyPressEvent(QKeyEvent *event); private: friend class DMenuContent; DMenuContent *m_menuContent; ItemStyle normalStyle; ItemStyle hoverStyle; ItemStyle inactiveStyle; DRegionMonitor *m_monitor; DWindowManagerHelper *m_wmHelper; }; #endif // DDOCKMENU_H deepin-menu-3.4.8/src/dmenuapplication.cpp000066400000000000000000000017231346421650600205750ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #include "dmenuapplication.h" DMenuApplication::DMenuApplication(int &argc, char *argv[]) : DApplication(argc, argv) { setTheme("light"); } void DMenuApplication::quitApplication(const QString &) { this->quit(); } deepin-menu-3.4.8/src/dmenuapplication.h000066400000000000000000000020421346421650600202350ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #ifndef DMENUAPPLICATION_H #define DMENUAPPLICATION_H #include DWIDGET_USE_NAMESPACE class DMenuApplication : public DApplication { Q_OBJECT public: explicit DMenuApplication(int &, char**); public slots: void quitApplication(const QString&); }; #endif // DMENUAPPLICATION_H deepin-menu-3.4.8/src/dmenubase.cpp000066400000000000000000000312721346421650600172060ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "dmenubase.h" #include "dmenucontent.h" #include "utils.h" #define GRAB_FOCUS_TRY_TIMES 100 DMenuBase::DMenuBase(QWidget *parent) : QWidget(parent, Qt::Tool | Qt::BypassWindowManagerHint), _subMenu(NULL), _radius(4), _shadowMargins(QMargins(0, 0, 0, 0)) { this->setAttribute(Qt::WA_TranslucentBackground); queryXIExtension(); _dropShadow = new QGraphicsDropShadowEffect(this); _dropShadow->setColor(QColor::fromRgbF(0, 0, 0, 0.2)); _dropShadow->setXOffset(0); _dropShadow->setYOffset(6); this->setGraphicsEffect(_dropShadow); _grabFocusTimer = new QTimer(this); _grabFocusTimer->setSingleShot(true); } // getters and setters int DMenuBase::radius() { return _radius; } void DMenuBase::setRadius(int radius) { if (_radius != radius) { _radius = radius; emit radiusChanged(radius); } } QMargins DMenuBase::shadowMargins() { return _shadowMargins; } void DMenuBase::setShadowMargins(QMargins shadowMargins) { if (_shadowMargins != shadowMargins) { _shadowMargins = shadowMargins; _dropShadow->setBlurRadius(qMax(qMax(_shadowMargins.left(), _shadowMargins.top()), qMax(_shadowMargins.right(), _shadowMargins.bottom()))); emit shadowMarginsChanged(shadowMargins); } } QMargins DMenuBase::menuContentMargins() { return _menuContentMargins; } void DMenuBase::setMenuContentMargins(QMargins margins) { if(_menuContentMargins != margins) { _menuContentMargins = margins; emit menuContentMarginsChanged(margins); } } int DMenuBase::itemLeftSpacing() { return _itemLeftSpacing; } void DMenuBase::setItemLeftSpacing(int spacing) { if (_itemLeftSpacing != spacing) { _itemLeftSpacing = spacing; emit itemLeftSpacingChanged(spacing); } } int DMenuBase::itemCenterSpacing() { return _itemCenterSpacing; } void DMenuBase::setItemCenterSpacing(int spacing) { if (_itemCenterSpacing != spacing) { _itemCenterSpacing = spacing; emit itemCenterSpacingChanged(spacing); } } int DMenuBase::itemRightSpacing() { return _itemRightSpacing; } void DMenuBase::setItemRightSpacing(int spacing) { if (_itemRightSpacing != spacing) { _itemRightSpacing = spacing; emit itemRightSpacingChanged(spacing); } } QSharedPointer DMenuBase::menuContent() { return _menuContent; } void DMenuBase::setMenuContent(QSharedPointer content) { _menuContent = content; _menuContent->setContentsMargins(_menuContentMargins); QHBoxLayout *layout = new QHBoxLayout(this); layout->setContentsMargins(QMargins(0, _menuContentMargins.top(), 0, _menuContentMargins.bottom())); layout->addWidget(_menuContent.data()); this->setLayout(layout); } DMenuBase* DMenuBase::subMenu() { return _subMenu; } void DMenuBase::setContent(QJsonArray items) { Q_ASSERT(this->menuContent()); this->menuContent()->setCurrentIndex(-1); this->menuContent()->clearActions(); foreach (QJsonValue item, items) { QJsonObject itemObj = item.toObject(); QAction *action = new QAction(this->menuContent().data()); QString itemText = itemObj["itemText"].toString().replace("_", QString()).replace(QRegExp("\\([^)]+\\)"), QString());/*.replace(regexp, navKeyWrapper)*/; action->setText(itemText); action->setEnabled(itemObj["isActive"].toBool()); action->setCheckable(itemObj["isCheckable"].toBool() || Utils::menuItemCheckableFromId(itemObj["itemId"].toString())); action->setChecked(itemObj["checked"].toBool()); action->setProperty("itemId", itemObj["itemId"].toString()); action->setProperty("itemIcon", itemObj["itemIcon"].toString()); action->setProperty("itemIconHover", itemObj["itemIconHover"].toString()); action->setProperty("itemIconInactive", itemObj["itemIconInactive"].toString()); action->setProperty("itemSubMenu", itemObj["itemSubMenu"].toObject()); // action->setProperty("itemNavKey", navKey); _menuContent->addAction(action); } // adjust its size according to its content. this->resize(_menuContent->contentWidth() + _shadowMargins.left() + _shadowMargins.right() + _menuContentMargins.left() + _menuContentMargins.right() + this->contentsMargins().left() - _shadowMargins.left() + this->contentsMargins().right() - _shadowMargins.right(), _menuContent->contentHeight() + _shadowMargins.top() + _shadowMargins.bottom() + _menuContentMargins.top() + _menuContentMargins.bottom() + this->contentsMargins().top() - _shadowMargins.top() + this->contentsMargins().bottom() - _shadowMargins.bottom()); } void DMenuBase::destroyAll() { releaseFocus(); if(this->parent()) { DMenuBase *parent = qobject_cast(this->parent()); Q_ASSERT(parent); parent->destroyAll(); } else { this->deleteLater(); } } void DMenuBase::grabFocus() { if (mouseGrabber() == menuContent().data() && keyboardGrabber() == menuContent().data()) { // the menu already grabs the focus, no need // to do it again. return; } grabFocusSlot(); connect(_grabFocusTimer, SIGNAL(timeout()), this, SLOT(grabFocusSlot())); } void DMenuBase::releaseFocus() { if (mouseGrabber()) mouseGrabber()->releaseMouse(); if (keyboardGrabber()) keyboardGrabber()->releaseKeyboard(); } bool DMenuBase::grabFocusInternal(int tryTimes) { QWindow *window = this->menuContent()->windowHandle(); if (!window) if (const QWidget *nativeParent = this->menuContent()->nativeParentWidget()) window = nativeParent->windowHandle(); // grab pointer int i = 0; while(!window->setMouseGrabEnabled(true) && i < tryTimes) { QThread::msleep(10); i++; } if (i >= tryTimes) { qWarning() << QString("GrabMouse Failed after trying %1 times").arg(i); } else { qDebug() << QString("GrabMouse tries %1").arg(i); } this->menuContent()->grabMouse(); // grab keyboard int j = 0; while(!window->setKeyboardGrabEnabled(true) && j < tryTimes) { QThread::msleep(10); j++; } if (j >= tryTimes) { qWarning() << QString("GrabKeyboard Failed after trying %1 times").arg(j); } else { qDebug() << QString("GrabKeyboard tries %1").arg(j); } this->menuContent()->grabKeyboard(); return (i < tryTimes) && (j < tryTimes); } void DMenuBase::grabFocusSlot() { if (!grabFocusInternal(1)) { _grabFocusTimer->start(); } } DMenuBase *DMenuBase::menuUnderPoint(QPoint point) { if(this->parent()) { DMenuBase *parent = qobject_cast(this->parent()); Q_ASSERT(parent); return parent->menuUnderPoint(point); } else { DMenuBase *result = NULL; DMenuBase *subMenu =this; while (subMenu) { // remove the shadow margin, so clicks on the shadow won't be eaten by us. if (Utils::pointInRect(point, subMenu->geometry().marginsRemoved(subMenu->shadowMargins()))) { // shouldn't return here, otherwise the old menus are able to steal focus from // the younger ones even if they are at the bottom of the stack. result = subMenu; } subMenu = subMenu->subMenu(); } return result; } } void DMenuBase::setItemActivity(const QString &itemId, bool isActive) { QString prop("%1Activity"); this->setProperty(prop.arg(itemId).toLatin1(), isActive); this->updateAll(); } void DMenuBase::setItemChecked(const QString &itemId, bool checked) { QString prop("%1Checked"); this->setProperty(prop.arg(itemId).toLatin1(), checked); this->updateAll(); } void DMenuBase::setItemText(const QString &itemId, const QString &text) { QString prop("%1Text"); this->setProperty(prop.arg(itemId).toLatin1(), text); this->updateAll(); } const DMenuBase::ItemStyle DMenuBase::normalStyle() { return _normalStyle; } const DMenuBase::ItemStyle DMenuBase::hoverStyle() { return _hoverStyle; } const DMenuBase::ItemStyle DMenuBase::inactiveStyle() { return _inactiveStyle; } DMenuBase *DMenuBase::getRootMenu() { QObject *root = this; while (root) { if (root->parent()) { root = root->parent(); } else { break; } } DMenuBase *result = qobject_cast(root); Q_ASSERT(result); return result; } // override methods bool DMenuBase::nativeEvent(const QByteArray &eventType, void *message, long *) { if (eventType=="xcb_generic_event_t") { xcb_generic_event_t *event = static_cast(message); const uint8_t responseType = event->response_type & ~0x80; xXIDeviceEvent *ev = reinterpret_cast(event); // qDebug() << ev->detail << Button1Mask << Button3Mask << Button2Mask; if (ev->detail !=0 && ev->detail != 1 && ev->detail != 2 && ev->detail != 3) { // drop all mouse events with button other than left button // or right button; return false; } if (isXIType(event, xiOpCode, XI_ButtonPress) || isXIType(event, xiOpCode, XI_TouchBegin)) { // qDebug() << "nativeEvent XI_ButtonPress" << fixed1616ToReal(ev->root_x) << // fixed1616ToReal(ev->root_y); if (!this->menuUnderPoint(QPoint(fixed1616ToReal(ev->root_x), fixed1616ToReal(ev->root_y)))) { this->destroyAll(); } } else if (isXIType(event, xiOpCode, XI_ButtonRelease)) { // qDebug() << "nativeEvent XI_ButtonRelease" << fixed1616ToReal(ev->root_x) << // fixed1616ToReal(ev->root_y); if (this->menuUnderPoint(QPoint(fixed1616ToReal(ev->root_x), fixed1616ToReal(ev->root_y))) && _menuContent){ _menuContent->doCurrentAction(); } } else if (isXIType(event, xiOpCode, XI_Motion)) { // qDebug() << "nativeEvent XI_Motion" << fixed1616ToReal(ev->root_x) << // fixed1616ToReal(ev->root_y); DMenuBase *menuUnderPoint = this->menuUnderPoint( QPoint(fixed1616ToReal(ev->root_x), fixed1616ToReal(ev->root_y))); if (menuUnderPoint) { menuUnderPoint->grabFocus(); } } } return false; } void DMenuBase::queryXIExtension() { XQueryExtension((Display *)QX11Info::display(), "XInputExtension", &xiOpCode, &xiEventBase, &xiErrorBase); qDebug() << "xiOpCode: " << xiOpCode; } bool DMenuBase::isXIEvent(xcb_generic_event_t *event, int opCode) { qt_xcb_ge_event_t *e = (qt_xcb_ge_event_t *)event; return e->extension == opCode; } bool DMenuBase::isXIType(xcb_generic_event_t *event, int opCode, uint16_t type) { if (!isXIEvent(event, opCode)) return false; xXIGenericDeviceEvent *xiEvent = reinterpret_cast(event); return xiEvent->evtype == type; } qreal DMenuBase::fixed1616ToReal(FP1616 val) { return (qreal(val >> 16)) + (val & 0xFFFF) / (qreal)0xFFFF; } // private methods void DMenuBase::updateAll() { DMenuBase *subMenu = this; while (subMenu) { subMenu->update(); subMenu = subMenu->subMenu(); } } deepin-menu-3.4.8/src/dmenubase.h000066400000000000000000000116731346421650600166560ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #ifndef DMENUBASE_H #define DMENUBASE_H // this event type was added in libxcb 1.10, // but we support also older version #ifndef XCB_GE_GENERIC #define XCB_GE_GENERIC 35 #endif #include #include #include #include #include // Starting from the xcb version 1.9.3 struct xcb_ge_event_t has changed: // - "pad0" became "extension" // - "pad1" and "pad" became "pad0" // New and old version of this struct share the following fields: typedef struct qt_xcb_ge_event_t { uint8_t response_type; uint8_t extension; uint16_t sequence; uint32_t length; uint16_t event_type; } qt_xcb_ge_event_t; class QColor; class QTimer; class QMargins; class QJsonArray; class QByteArray; class DMenuContent; class DMenuBase : public QWidget { Q_OBJECT public: explicit DMenuBase(QWidget *parent = 0); struct ItemStyle { QColor itemBackgroundColor; QColor itemTextColor; QColor itemShortcutColor; QString checkmarkIcon; QString subMenuIndicatorIcon; }; Q_PROPERTY(int radius READ radius WRITE setRadius NOTIFY radiusChanged) Q_PROPERTY(QMargins shadowMargins READ shadowMargins WRITE setShadowMargins NOTIFY shadowMarginsChanged) Q_PROPERTY(QMargins menuContentMargins READ menuContentMargins WRITE setMenuContentMargins NOTIFY menuContentMarginsChanged) Q_PROPERTY(int itemLeftSpacing READ itemLeftSpacing WRITE setItemLeftSpacing NOTIFY itemLeftSpacingChanged) Q_PROPERTY(int itemCenterSpacing READ itemCenterSpacing WRITE setItemCenterSpacing NOTIFY itemCenterSpacingChanged) Q_PROPERTY(int itemRightSpacing READ itemRightSpacing WRITE setItemRightSpacing NOTIFY itemRightSpacingChanged) int radius(); void setRadius(int); QMargins shadowMargins(); void setShadowMargins(QMargins); QMargins menuContentMargins(); void setMenuContentMargins(QMargins); int itemLeftSpacing(); void setItemLeftSpacing(int); int itemCenterSpacing(); void setItemCenterSpacing(int); int itemRightSpacing(); void setItemRightSpacing(int); QSharedPointer menuContent(); void setMenuContent(QSharedPointer content); DMenuBase *subMenu(); void setContent(QJsonArray items); void destroyAll(); void grabFocus(); void releaseFocus(); DMenuBase *menuUnderPoint(QPoint); DMenuBase *getRootMenu(); void setItemActivity(const QString &itemId, bool isActive); void setItemChecked(const QString &itemId, bool checked); void setItemText(const QString &itemId, const QString &text); const ItemStyle normalStyle(); const ItemStyle hoverStyle(); const ItemStyle inactiveStyle(); virtual void setPosition(int, int) = 0; virtual void showSubMenu(int, int, QJsonObject) = 0; signals: void radiusChanged(int radius); void shadowMarginsChanged(QMargins shadowWidth); void menuContentMarginsChanged(QMargins menuContentMargins); void itemBackgroundColorChanged(QColor itemBackgroundColor); void itemTextColorChanged(QColor itemTextColor); void itemShortcutColorChanged(QColor itemShortcutColor); void itemLeftSpacingChanged(int itemLeftSpacing); void itemCenterSpacingChanged(int itemCenterSpacing); void itemRightSpacingChanged(int itemRightSpacing); void itemClicked(QString id, bool checked); protected: DMenuBase *_subMenu; ItemStyle _normalStyle; ItemStyle _hoverStyle; ItemStyle _inactiveStyle; virtual bool nativeEvent(const QByteArray &, void *, long *); private slots: void grabFocusSlot(); private: int xiErrorBase; int xiEventBase; int xiOpCode; int _radius; QMargins _shadowMargins; QMargins _menuContentMargins; int _itemLeftSpacing; int _itemCenterSpacing; int _itemRightSpacing; QSharedPointer _menuContent; QGraphicsDropShadowEffect *_dropShadow; QTimer *_grabFocusTimer; void queryXIExtension(); bool isXIEvent(xcb_generic_event_t *event, int opCode); bool isXIType(xcb_generic_event_t *event, int opCode, uint16_t type); qreal fixed1616ToReal(FP1616 val); bool grabFocusInternal(int); void updateAll(); }; #endif // DMENUBASE_H deepin-menu-3.4.8/src/dmenucontent.cpp000066400000000000000000000370741346421650600177540ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "utils.h" #include "dmenucontent.h" #include "ddockmenu.h" #define MENU_ITEM_MAX_WIDTH 500 #define SEPARATOR_HEIGHT 6 #define MENU_ITEM_TOP_BOTTOM_PADDING 2 static const int LeftRightPadding = 20; static const int TopBottomPadding = 4; DMenuContent::DMenuContent(DDockMenu *parent) : QWidget(parent), _currentIndex(-1) { this->setMouseTracking(true); } int DMenuContent::currentIndex() { return _currentIndex; } void DMenuContent::setCurrentIndex(int index) { if (index < 0 || _currentIndex == index) return; _currentIndex = index; this->update(); if (index < 0 || index >= this->actions().count()) return; DDockMenu *parent = qobject_cast(this->parent()); Q_ASSERT(parent); QAction *action = this->actions().at(index); QRect actionRect = this->getRectOfActionAtIndex(index); QPoint point = this->mapToGlobal(QPoint(this->width(), actionRect.y())); QString itemId = action->property("itemId").toString(); QString prop("%1Active"); QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1()); bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool(); QJsonObject subMenuJsonObj = active ? this->actions().at(index)->property("itemSubMenu").value() : QJsonObject(); parent->showSubMenu(point.x(), point.y(), subMenuJsonObj); } int DMenuContent::contentWidth() { int result = 0; QFontMetrics metrics(font()); foreach (QAction *action, this->actions()) { result = qMax(result, metrics.width(action->text())); } return qMin(MENU_ITEM_MAX_WIDTH, result + 10 + LeftRightPadding*2); } int DMenuContent::contentHeight() { int result = 0; QFontMetrics fm(font()); foreach (QAction *action, this->actions()) { if (action->text().isEmpty()) { result += SEPARATOR_HEIGHT; } else { result += fm.height() + MENU_ITEM_TOP_BOTTOM_PADDING * 2; } } return (result + TopBottomPadding * 2); } void DMenuContent::doCurrentAction() { if (_currentIndex < 0 || _currentIndex >= this->actions().count()) return; DDockMenu *parent = qobject_cast(this->parent()); Q_ASSERT(parent); QAction *currentAction = this->actions().at(_currentIndex); QString itemId = currentAction->property("itemId").toString(); QString prop("%1Checked"); QVariant checkedCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1()); bool checked = checkedCache.isNull() ? currentAction->isChecked() : checkedCache.toBool(); bool currentActionHasSubMenu = currentAction->property("itemSubMenu").value()["items"].toArray().count() != 0; prop = QString("%1Activity"); QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1()); bool active = activeCache.isNull() ? currentAction->isEnabled() : activeCache.toBool(); if (!active || currentAction->text().isEmpty() || currentActionHasSubMenu) return; if (currentAction->isCheckable()) { if (checked) { this->doUnCheck(_currentIndex); } else { this->doCheck(_currentIndex); } } else { parent->releaseFocus(); this->sendItemClickedSignal(currentAction->property("itemId").toString(), false); } qDebug() << "do action, destroy all"; parent->destroyAll(); } // override methods void DMenuContent::paintEvent(QPaintEvent *) { DDockMenu *parent = qobject_cast(this->parent()); QPainter painter(this); for(int i = 0; i < this->actions().count(); i++) { QAction *action = this->actions().at(i); QRect actionRect = this->getRectOfActionAtIndex(i); QString itemId = action->property("itemId").toString(); QString prop("%1Activity"); QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1()); bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool(); ItemStyle itemStyle = active ? i == _currentIndex ? parent->hoverStyle : parent->normalStyle : parent->inactiveStyle; // indicates that this item is a separator if (action->text().isEmpty()) { int topLineX1 = actionRect.x() + 4; int topLineY1 = actionRect.y() + (actionRect.height() - 2) / 2; int topLineX2 = actionRect.x() + actionRect.width() - 4; int topLineY2 = actionRect.y() + (actionRect.height() - 2) / 2; int bottomLineX1 = topLineX1; int bottomLineY1 = topLineY1 + 1; int bottomLineX2 = topLineX2; int bottomLineY2 = topLineY1 + 1; painter.setPen(QPen(QColor::fromRgbF(0, 0, 0, 0.1))); painter.drawLine(topLineX1, topLineY1, topLineX2, topLineY2); painter.setPen(QPen(QColor::fromRgbF(1, 1, 1, 0.1))); painter.drawLine(bottomLineX1, bottomLineY1, bottomLineX2, bottomLineY2); } else { painter.fillRect(actionRect, QBrush(itemStyle.itemBackgroundColor)); painter.setPen(QPen(itemStyle.itemTextColor)); // draw text QString prop("%1Text"); QVariant textCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1()); QString text = textCache.isNull() ? action->text() : textCache.toString(); QString elidedText = elideText(text, actionRect.width() - LeftRightPadding * 2); QTextOption option; option.setAlignment(Qt::AlignVCenter | Qt::AlignLeft); QRect textRect(actionRect); textRect.adjust(LeftRightPadding, 0, -LeftRightPadding, 0); painter.drawText(textRect, elidedText, option); } } painter.end(); } void DMenuContent::processCursorMove(const QPoint &p) { int index = itemIndexUnderEvent(p); setCurrentIndex(index); } void DMenuContent::processButtonClick(const QPoint &p) { DDockMenu *parent = qobject_cast(this->parent()); if (parent) { DDockMenu *menu = parent->menuUnderPoint(p); qDebug() << "menu geometry is " << parent->geometry(); if (menu) { doCurrentAction(); } else { qDebug() << "no menu under mouse event: " << p.x() << p.y() << ", destroy menus."; parent->destroyAll(); } } } // private methods QRect DMenuContent::getRectOfActionAtIndex(int index) { QFontMetrics fm(font()); auto getItemHeight = [this, &fm](const int i) { QAction *action = this->actions().at(i); if (action->text().isEmpty()) { return SEPARATOR_HEIGHT; } else { return fm.height() + MENU_ITEM_TOP_BOTTOM_PADDING * 2; } }; int previousHeight = TopBottomPadding; int itemHeight = getItemHeight(index); for (int i = 0; i < index; i++) { int height = getItemHeight(i); previousHeight += height; } return QRect(0, previousHeight, this->width(), itemHeight); } void DMenuContent::clearActions() { foreach (QAction *action, this->actions()) { this->removeAction(action); } } int DMenuContent::getNextItemsHasShortcut(int startPos, QString keyText) { if (keyText.isEmpty()) return -1; DDockMenu *parent = qobject_cast(this->parent()); Q_ASSERT(parent); for (int i = qMax(startPos, 0); i < this->actions().count(); i++) { QString itemId(this->actions().at(i)->property("itemId").toString()); QAction *action = this->actions().at(i); QString prop("%1Active"); QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1()); bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool(); // a trick here, using currentIndex as the cursor. if (active && keyText == this->actions().at(i)->property("itemNavKey").toString().toLower()){ return i; } } // we do the check another time to support wrapping. for (int i = 0; i < this->actions().count(); i++) { QString itemId(this->actions().at(i)->property("itemId").toString()); QAction *action = this->actions().at(i); QString prop("%1Active"); QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1()); bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool(); if (active && keyText == this->actions().at(i)->property("itemNavKey").toString().toLower()) { return i; } } return -1; } void DMenuContent::selectPrevious() { DDockMenu *parent = qobject_cast(this->parent()); Q_ASSERT(parent); for (int i = currentIndex() - 1; i >= 0; i--) { QAction * action = actions().at(i); QString itemId(action->property("itemId").toString()); QString prop("%1Active"); QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1()); bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool(); if (active && !action->text().isEmpty()) { setCurrentIndex(i); break; } } } void DMenuContent::selectNext() { DDockMenu *parent = qobject_cast(this->parent()); Q_ASSERT(parent); for (int i = currentIndex() + 1; i < actions().count(); i++) { QAction * action = actions().at(i); QString itemId(action->property("itemId").toString()); QString prop("%1Active"); QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1()); bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool(); if (active && !action->text().isEmpty()) { setCurrentIndex(i); break; } } } void DMenuContent::doCheck(int index) { DDockMenu *parent = qobject_cast(this->parent()); Q_ASSERT(parent); QAction *action = this->actions().at(index); QString itemId = action->property("itemId").toString(); parent->getRootMenu()->setItemChecked(itemId, true); this->sendItemClickedSignal(itemId, true); if (Utils::menuItemCheckableFromId(itemId)) { QStringList components = itemId.split(':'); QString group = components.at(0); foreach (QAction *act, this->actions()) { QString _itemId = act->property("itemId").toString(); if (act != action && Utils::menuItemCheckableFromId(_itemId)) { QStringList _components = _itemId.split(':'); QString _group = _components.at(0); QString _type = _components.at(1); if (_type == "radio" && _group == group) { parent->getRootMenu()->setItemChecked(_itemId, false); } } } } this->update(); } void DMenuContent::doUnCheck(int index) { DDockMenu *parent = qobject_cast(this->parent()); Q_ASSERT(parent); QAction *action = this->actions().at(index); QString itemId = action->property("itemId").toString(); if (Utils::menuItemCheckableFromId(itemId)) { QStringList components = itemId.split(':'); QString group = components.at(0); QString type = components.at(1); if (type == "radio") { bool hasNoCheck = true; foreach (QAction *act, this->actions()) { QString _itemId = act->property("itemId").toString(); if (Utils::menuItemCheckableFromId(_itemId) && _itemId != itemId) { QStringList components = _itemId.split(':'); QString _group = components.at(0); QString _type = components.at(1); if (group == _group && _type == "radio") { QString prop("%1Checked"); QVariant checkedCache = parent->getRootMenu()->property(prop.arg(_itemId).toLatin1()); bool checked = checkedCache.isNull() ? act->isChecked() : checkedCache.toBool(); hasNoCheck = hasNoCheck && !checked; } } } if (!hasNoCheck) { parent->getRootMenu()->setItemChecked(itemId, false); this->sendItemClickedSignal(action->property("itemId").toString(), false); } else { parent->getRootMenu()->setItemChecked(itemId, true); this->sendItemClickedSignal(action->property("itemId").toString(), true); } } else { parent->getRootMenu()->setItemChecked(itemId, false); this->sendItemClickedSignal(action->property("itemId").toString(), false); } } else { parent->getRootMenu()->setItemChecked(itemId, false); this->sendItemClickedSignal(action->property("itemId").toString(), false); } this->update(); } void DMenuContent::sendItemClickedSignal(QString id, bool checked) { DDockMenu *root = qobject_cast(this->parent()); Q_ASSERT(root); while (root) { if (!root->parent()) { qDebug() << Q_FUNC_INFO << "itemClicked"; // NOTE(sbw): ensure mouse/keyboard released before send itemClicked, root->releaseMouse(); root->releaseFocus(); root->releaseKeyboard(); root->itemClicked(id, checked); break; } else { root = qobject_cast(root->parent()); Q_ASSERT(root); } } } int DMenuContent::itemIndexUnderEvent(QPoint point) const { DDockMenu *parent = qobject_cast(this->parent()); Q_ASSERT(parent); const QPoint lPoint = mapFromGlobal(point); DDockMenu *menuUnderCursor = parent->menuUnderPoint(point); if (menuUnderCursor == parent) { int previousHeight = (y() + TopBottomPadding); QFontMetrics fm(font()); for (int i = 0; i < this->actions().count(); i++) { QAction *action = this->actions().at(i); int itemHeight = action->text().isEmpty() ? SEPARATOR_HEIGHT : (fm.height() + MENU_ITEM_TOP_BOTTOM_PADDING * 2); QRect itemRect(x(), previousHeight, width(), itemHeight); if (itemRect.contains(lPoint)) { return i; } else { previousHeight += itemHeight; } } } return -1; } QString DMenuContent::elideText(QString source, int maxWidth) const { QFontMetrics metrics(font()); if (metrics.width(source) < maxWidth) { return source; } else { return metrics.elidedText(source, Qt::ElideRight, maxWidth); } } deepin-menu-3.4.8/src/dmenucontent.h000066400000000000000000000034241346421650600174110ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #ifndef DMENUCONTENT_H #define DMENUCONTENT_H #include #include class QRect; class DDockMenu; class DMenuContent : public QWidget { Q_OBJECT public: explicit DMenuContent(DDockMenu *parent = 0); int contentWidth(); int contentHeight(); int currentIndex(); void setCurrentIndex(int); void clearActions(); void doCurrentAction(); protected: void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; private: friend class DDockMenu; void processCursorMove(const QPoint &p); void processButtonClick(const QPoint &p); private: int _iconWidth; int _shortcutWidth; int _subMenuIndicatorWidth; int _currentIndex; QRect getRectOfActionAtIndex(int); int getNextItemsHasShortcut(int, QString); void selectPrevious(); void selectNext(); void doCheck(int); void doUnCheck(int); void sendItemClickedSignal(QString, bool); int itemIndexUnderEvent(QPoint point) const; QString elideText(QString source, int maxWidth) const; }; #endif // DMENUCONTENT_H deepin-menu-3.4.8/src/main.cpp000066400000000000000000000040621346421650600161640ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #include #include #include #include "dbus_manager_adaptor.h" #include "manager_object.h" #include "dmenuapplication.h" #define MENU_SERVICE_NAME "com.deepin.menu" #define MENU_SERVICE_PATH "/com/deepin/menu" DCORE_USE_NAMESPACE DWIDGET_USE_NAMESPACE int main(int argc, char *argv[]) { DApplication::loadDXcbPlugin(); DMenuApplication app(argc, argv); app.setOrganizationName("deepin"); app.setApplicationName("deepin-menu"); app.setApplicationVersion("2.0"); #if DTK_VERSION >= DTK_VERSION_CHECK(2, 0, 9, 0) app.setOOMScoreAdj(500); #endif DLogManager::registerConsoleAppender(); DLogManager::registerFileAppender(); ManagerObject managerObject; ManagerAdaptor manager(&managerObject); QDBusConnection connection = QDBusConnection::sessionBus(); connection.interface()->registerService(MENU_SERVICE_NAME, QDBusConnectionInterface::ReplaceExistingService, QDBusConnectionInterface::AllowReplacement); connection.registerObject(MENU_SERVICE_PATH, &managerObject); DMenuApplication::connect(connection.interface(), SIGNAL(serviceUnregistered(QString)), &app, SLOT(quitApplication(QString))); return app.exec(); } deepin-menu-3.4.8/src/manager_object.cpp000066400000000000000000000047621346421650600202070ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #include #include #include #include "dbus_menu_adaptor.h" #include "manager_object.h" ManagerObject::ManagerObject(QObject *parent) : QObject(parent) { menuObjectPath = ""; menuObject = nullptr; menuAdaptor = nullptr; } QDBusObjectPath ManagerObject::RegisterMenu() { UnregisterMenu(); if (!menuAdaptor.isNull()) menuAdaptor->deleteLater(); menuRegisterGuard.lock(); QString uuid = QUuid::createUuid().toString(); uuid = uuid.replace("{", ""); uuid = uuid.replace("}", ""); uuid = uuid.replace("-", "_"); menuObjectPath = "/com/deepin/menu/" + uuid; menuObject = new MenuObject; menuAdaptor = new MenuAdaptor(menuObject); connect(menuObject.data(), &MenuObject::destroyed, this, &ManagerObject::menuObjectDestroiedSlot, Qt::QueuedConnection); QDBusConnection connection = QDBusConnection::sessionBus(); connection.registerObject(menuObjectPath, menuObject); QDBusObjectPath result(menuObjectPath); menuRegisterGuard.unlock(); return result; } void ManagerObject::UnregisterMenu() { UnregisterMenu(menuObjectPath); } void ManagerObject::UnregisterMenu(const QString &) { if (menuObject.isNull() && menuObjectPath.isEmpty()) return; menuRegisterGuard.lock(); if (!menuObject.isNull() || !menuObjectPath.isEmpty()) { if (!menuObject.isNull()) delete menuObject; menuObject.clear(); menuObjectPath.clear(); } menuRegisterGuard.unlock(); } // private slots void ManagerObject::menuObjectDestroiedSlot() { if (!menuObject.isNull()) menuObject->deleteLater(); QDBusConnection connection = QDBusConnection::sessionBus(); connection.unregisterObject(menuObjectPath); } deepin-menu-3.4.8/src/manager_object.h000066400000000000000000000026271346421650600176520ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #ifndef MANAGER_OBJECT_H #define MANAGER_OBJECT_H #include #include #include #include #include #include class ManagerObject : public QObject { Q_OBJECT public: explicit ManagerObject(QObject *parent = 0); signals: public slots: QDBusObjectPath RegisterMenu(); void UnregisterMenu(); void UnregisterMenu(const QString &menuObjectPath); private: QMutex menuRegisterGuard; QPointer menuObject; QPointer menuAdaptor; QString menuObjectPath; private slots: void menuObjectDestroiedSlot(); }; #endif // MANAGER_OBJECT_H deepin-menu-3.4.8/src/menu_object.cpp000066400000000000000000000107221346421650600175320ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #include #include #include #include #include #include #include #include #include #include "menu_object.h" #include "ddesktopmenu.h" #include "ddockmenu.h" static DArrowRectangle::ArrowDirection DirectionFromString(QString direction) { if (direction == "top") { return DArrowRectangle::ArrowTop; } else if (direction == "left") { return DArrowRectangle::ArrowLeft; } else if (direction == "right") { return DArrowRectangle::ArrowRight; } return DArrowRectangle::ArrowBottom; } MenuObject::MenuObject(): QObject(), m_dockMenu(nullptr), m_desktopMenu(nullptr) { } MenuObject::~MenuObject() { if (!m_dockMenu.isNull()) { delete m_dockMenu; } if (!m_desktopMenu.isNull()) { delete m_desktopMenu; } } void MenuObject::SetItemActivity(const QString &itemId, bool isActive) { if (!m_dockMenu.isNull()) m_dockMenu->setItemActivity(itemId, isActive); if (!m_desktopMenu.isNull()) m_desktopMenu->setItemActivity(itemId, isActive); } void MenuObject::SetItemChecked(const QString &itemId, bool checked) { if (!m_dockMenu.isNull()) m_dockMenu->setItemChecked(itemId, checked); if (!m_desktopMenu.isNull()) m_desktopMenu->setItemChecked(itemId, checked); } void MenuObject::SetItemText(const QString &itemId, const QString &text) { if (!m_dockMenu.isNull()) m_dockMenu->setItemText(itemId, text); if (!m_desktopMenu.isNull()) m_desktopMenu->setItemText(itemId, text); } void MenuObject::ShowMenu(const QString &menuJsonContent) { QByteArray bytes; bytes.append(menuJsonContent); QJsonDocument menuDocument = QJsonDocument::fromJson(bytes); QJsonObject jsonObj = menuDocument.object(); int x = jsonObj["x"].toDouble(); int y = jsonObj["y"].toDouble(); QString direction = jsonObj["direction"].toString(); if(jsonObj["isDockMenu"].toBool()) { m_dockMenu = new DDockMenu; connect(m_dockMenu, &DDockMenu::destroyed, this, &MenuObject::menuDismissedSlot, Qt::QueuedConnection); connect(m_dockMenu, &DDockMenu::itemClicked, this, &MenuObject::ItemInvoked); } else { m_desktopMenu = new DDesktopMenu; connect(m_desktopMenu, &DDesktopMenu::aboutToHide, this, &MenuObject::menuDismissedSlot, Qt::QueuedConnection); connect(m_desktopMenu, &DDesktopMenu::itemClicked, this, &MenuObject::ItemInvoked); } bytes.clear(); bytes.append(jsonObj["menuJsonContent"].toString()); QJsonDocument menuContent = QJsonDocument::fromJson(bytes); QJsonObject menuContentObj = menuContent.object(); if (!m_dockMenu.isNull()) { m_dockMenu->setArrowDirection(DirectionFromString(direction)); m_dockMenu->setItems(menuContentObj["items"].toArray()); m_dockMenu->show(x, y); } else if (!m_desktopMenu.isNull()) { m_desktopMenu->setItems(menuContentObj["items"].toArray()); // 在Qt 5.10.x上, 菜单 show 之前没有被polish, 导致 dstyle 中无法将菜单设置为"圆角+模糊"样式 if (m_desktopMenu->style() && !m_desktopMenu->testAttribute(Qt::WA_WState_Polished)) { m_desktopMenu->style()->polish(m_desktopMenu); } bool isScaled = true; if (!jsonObj["isScaled"].isNull()) { isScaled = jsonObj["isScaled"].toBool(); } m_desktopMenu->showMenu(QPoint(x, y), isScaled); } } void MenuObject::menuDismissedSlot() { emit MenuUnregistered(); if (!m_dockMenu.isNull()) { m_dockMenu->deleteLater(); m_dockMenu = nullptr; } if (!m_desktopMenu.isNull()) { m_desktopMenu->deleteLater(); m_desktopMenu = nullptr; } deleteLater(); } deepin-menu-3.4.8/src/menu_object.h000066400000000000000000000027161346421650600172030ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #ifndef MENU_OBJECT_H #define MENU_OBJECT_H #include #include class DDockMenu; class DDesktopMenu; class MenuObject : public QObject { Q_OBJECT public: MenuObject(); ~MenuObject(); signals: void ItemInvoked(const QString &itemId, bool checked); void MenuUnregistered(); public slots: void SetItemActivity(const QString &itemId, bool isActive); void SetItemChecked(const QString &itemId, bool checked); void SetItemText(const QString &itemId, const QString &text); void ShowMenu(const QString &menuJsonContent); private slots: void menuDismissedSlot(); private: QPointer m_dockMenu; QPointer m_desktopMenu; }; #endif // MENU_OBJECT_H deepin-menu-3.4.8/src/utils.cpp000066400000000000000000000015551346421650600164040ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #include "utils.h" namespace Utils { bool menuItemCheckableFromId(QString id) { return id.split(':').count() == 3; } } deepin-menu-3.4.8/src/utils.h000066400000000000000000000022701346421650600160440ustar00rootroot00000000000000/* * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd. * * Author: Hualet Wang . */ #ifndef UTILS_H #define UTILS_H #include #include #define DISPLAY_SERVICE "com.deepin.daemon.Display" #define DISPLAY_PATH "/com/deepin/daemon/Display" #define PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties" #define DISPLAY_INTERFACE "com.deepin.daemon.Display" #define MONITOR_INTERFACE "com.deepin.daemon.Display.Monitor" class QString; namespace Utils { bool menuItemCheckableFromId(QString id); } #endif // UTILS_H