diff --git a/plugins/ColorCode_plugin/COPYING b/plugins/ColorCode_plugin/COPYING new file mode 100644 index 000000000..94a9ed024 --- /dev/null +++ b/plugins/ColorCode_plugin/COPYING @@ -0,0 +1,674 @@ + 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 +. diff --git a/plugins/ColorCode_plugin/ColorCode.pro b/plugins/ColorCode_plugin/ColorCode.pro index fd1b784c5..dc030f9e8 100644 --- a/plugins/ColorCode_plugin/ColorCode.pro +++ b/plugins/ColorCode_plugin/ColorCode.pro @@ -25,26 +25,34 @@ SOURCES += ColorCodePlugin.cpp #=============================================================================== - -SOURCES += main.cpp \ - mainwindow.cpp \ - colorpeg.cpp \ - rowhint.cpp \ - pegrow.cpp \ - msg.cpp \ - about.cpp -HEADERS += mainwindow.h \ +# Input +HEADERS += about.h \ + colorcode.h \ colorpeg.h \ - rowhint.h \ - pegrow.h \ msg.h \ - about.h -RESOURCES += resource.qrc + pegrow.h \ + rowhint.h \ + ccsolver.h \ + background.h \ + solrow.h FORMS += about.ui -OTHER_FILES += docs/GPL.html \ +SOURCES += about.cpp \ + colorcode.cpp \ + colorpeg.cpp \ + main.cpp \ + msg.cpp \ + pegrow.cpp \ + rowhint.cpp \ + ccsolver.cpp \ + background.cpp \ + solrow.cpp +RESOURCES += resource.qrc +OTHER_FILES += docs/GPL.html +win32 { + RC_FILE = ColorCode.rc +} +TRANSLATIONS += trans_de.ts \ trans_en.ts \ - trans_de.ts -TRANSLATIONS = trans_en.ts \ - trans_de.ts + trans_cs.ts CODECFORTR = UTF-8 CODECFORSRC = UTF-8 diff --git a/plugins/ColorCode_plugin/ColorCodePlugin.cpp b/plugins/ColorCode_plugin/ColorCodePlugin.cpp index 8a4a6356a..456ef3ccb 100644 --- a/plugins/ColorCode_plugin/ColorCodePlugin.cpp +++ b/plugins/ColorCode_plugin/ColorCodePlugin.cpp @@ -24,7 +24,7 @@ //#include #include "ColorCodePlugin.h" -#include "mainwindow.h" +#include "colorcode.h" QString ColorCodePlugin::pluginDescription() const @@ -44,7 +44,7 @@ ColorCodePlugin::pluginName() const QWidget* ColorCodePlugin::pluginWidget(QWidget * parent ) { - MainWindow* window = new MainWindow(); + ColorCode* window = new ColorCode(); return window; } diff --git a/plugins/ColorCode_plugin/INSTALL b/plugins/ColorCode_plugin/INSTALL index 944d72672..d4a9d2d3b 100644 --- a/plugins/ColorCode_plugin/INSTALL +++ b/plugins/ColorCode_plugin/INSTALL @@ -1,8 +1,11 @@ -ColorCode 0.1 +# simply run: -simply run: - -qmake-qt4 -project qmake-qt4 make +# to install: +cp ColorCode /usr/bin/ + +# to uninstall: +rm /usr/bin/ColorCode + diff --git a/plugins/ColorCode_plugin/about.cpp b/plugins/ColorCode_plugin/about.cpp index 72c1cf9cf..a85455568 100644 --- a/plugins/ColorCode_plugin/about.cpp +++ b/plugins/ColorCode_plugin/about.cpp @@ -1,3 +1,21 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #include "about.h" About::About(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) @@ -9,7 +27,8 @@ About::About(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) mAuthorText->setText("" + tr("ColorCode") + "
" + tr("A needful game to train your brain ;-)") + - "

Version: 0.2
Author: Dirk Laebisch"); + tr("

Free MasterMind clone including a built in,
rather intelligent solver.") + + "

" + tr("Version") + ": 0.5.5
" + tr("Author") + ": Dirk Laebisch"); QString license_file = ":/docs/GPL.html"; if (QFile::exists(license_file)) @@ -44,5 +63,5 @@ About::~About() QSize About::sizeHint () const { - return QSize(320, 240); + return QSize(360, 270); } diff --git a/plugins/ColorCode_plugin/about.h b/plugins/ColorCode_plugin/about.h index 74d94c664..97c221aca 100644 --- a/plugins/ColorCode_plugin/about.h +++ b/plugins/ColorCode_plugin/about.h @@ -1,3 +1,21 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #ifndef ABOUT_H #define ABOUT_H diff --git a/plugins/ColorCode_plugin/about.ui b/plugins/ColorCode_plugin/about.ui index 3a65f1f6d..21de7f803 100644 --- a/plugins/ColorCode_plugin/about.ui +++ b/plugins/ColorCode_plugin/about.ui @@ -9,8 +9,8 @@ 0 0 - 320 - 240 + 360 + 270 diff --git a/plugins/ColorCode_plugin/background.cpp b/plugins/ColorCode_plugin/background.cpp new file mode 100644 index 000000000..0139511a3 --- /dev/null +++ b/plugins/ColorCode_plugin/background.cpp @@ -0,0 +1,140 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ +#include + +#include "background.h" + +using namespace std; + +BackGround::BackGround(QObject*) +{ + setCacheMode(QGraphicsItem::DeviceCoordinateCache); + + QLinearGradient topgrad(0, 16, 0, 129); + topgrad.setColorAt(0.0, QColor(0xf8, 0xf8, 0xf8)); + topgrad.setColorAt(0.6, QColor(0xb8, 0xb9, 0xbb)); + topgrad.setColorAt(1, QColor(0xd4, 0xd5, 0xd7)); + mTopGrad = QBrush(topgrad); + + QLinearGradient botgrad(0, 530, 0, 557); + botgrad.setColorAt(0.0, QColor("#d4d5d7")); + botgrad.setColorAt(0.3, QColor("#cecfd1")); + botgrad.setColorAt(1.0, QColor("#b0b1b3")); + mBotGrad = QBrush(botgrad); + + QLinearGradient lgrad(0, 190, 320, 370); + lgrad.setColorAt(0.0, QColor(0xff, 0xff, 0xff, 0xa0)); + lgrad.setColorAt(0.49, QColor(0xff, 0xff, 0xff, 0xa0)); + lgrad.setColorAt(0.50, QColor(0, 0, 0, 0x80)); + lgrad.setColorAt(1.0, QColor(0, 0, 0, 0x80)); + mFramePen = QPen(QBrush(lgrad), 1); + + mPend = QColor("#646568"); + mPenl = QColor("#ecedef"); + mGrad0 = QColor("#cccdcf"); + mGrad1 = QColor("#fcfdff"); + + mPend.setAlpha(0x32); + mPenl.setAlpha(0x50); + mGrad0.setAlpha(0x32); + mGrad1.setAlpha(0x32); +} + +BackGround::~BackGround() +{ + scene()->removeItem(this); +} + +QRectF BackGround::boundingRect() const +{ + const int margin = 1; + return outlineRect().adjusted(-margin, -margin, +margin, +margin); +} + +QRectF BackGround::outlineRect() const +{ + return QRectF(0.0, 0.0, 320.0, 560.0); +} + +void BackGround::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /* widget */) +{ + int i; + + painter->setPen(Qt::NoPen); + + QRectF cr = QRectF(3, 3, 314, 554); + QPainterPath cpath; + cpath.addRoundedRect(cr, 10.1, 10.1); + painter->setClipPath(cpath); + painter->setClipping(true); + + painter->setBrush(mTopGrad); + painter->drawRect(QRect(4, 4, 312, 125)); + painter->setBrush(QBrush(QColor("#707173"))); + painter->drawRect(QRect(1, 129, 318, 1)); + + painter->setPen(Qt::NoPen); + for (i = 0; i < 10; ++i) + { + painter->setBrush(QBrush(QColor("#9e9fa0"))); + painter->drawRect(QRect(1, i * 40 + 130, 318, 1)); + QLinearGradient rowgrad(0, i * 40 + 131, 0, i * 40 + 169); + rowgrad.setColorAt(0.0, QColor("#9a9b9d")); + rowgrad.setColorAt(1.0, QColor("#949597")); + painter->setBrush(QBrush(rowgrad)); + painter->drawRect(QRect(1, i * 40 + 131, 318, 38)); + painter->setBrush(QBrush(QColor("#88898b"))); + painter->drawRect(QRect(1, i * 40 + 169, 318, 1)); + + painter->setBrush(QBrush(mPenl)); + painter->drawRect(QRectF(277, i * 40 + 130, 39, 1)); + painter->drawRect(QRectF(277, i * 40 + 130, 1, 39)); + painter->setBrush(QBrush(mPend)); + painter->drawRect(QRectF(277, i * 40 + 130 + 39, 40, 1)); + painter->drawRect(QRectF(277 + 39, i * 40 + 130, 1, 40)); + + QRadialGradient grad(QPointF(277 + 10, i * 40 + 130 + 10), 100); + grad.setColorAt(0, mGrad0); + grad.setColorAt(1, mGrad1); + painter->setBrush(QBrush(grad)); + painter->drawRect(QRectF(277 + 1, i * 40 + 131, 38.0, 38.0)); + + painter->setBrush(Qt::NoBrush); + QPointF x0 = QPointF(279, i * 40 + 130 + 2); + QLinearGradient lgrad(x0, QPointF(x0.x() + 36, x0.y() + 36)); + lgrad.setColorAt(0.0, QColor(0, 0, 0, 0x80)); + lgrad.setColorAt(1.0, QColor(0xff, 0xff, 0xff, 0xa0)); + painter->setPen(QPen(QBrush(lgrad), 0.5)); + painter->drawEllipse(QRectF(x0.x(), x0.y(), 36, 36)); + painter->setPen(Qt::NoPen); + } + + painter->setBrush(mBotGrad); + painter->drawRect(QRect(1, 531, 318, 27)); + painter->setBrush(QBrush(QColor("#eff0f2"))); + painter->drawRect(QRect(1, 530, 318, 1)); + + painter->setClipping(false); + + QRectF r = QRectF(3.5, 3.5, 313, 553); + painter->setBrush(Qt::NoBrush); + painter->setPen(mFramePen); + painter->drawRoundedRect(r, 9.8, 9.8); +} + + diff --git a/plugins/ColorCode_plugin/background.h b/plugins/ColorCode_plugin/background.h new file mode 100644 index 000000000..b9515246f --- /dev/null +++ b/plugins/ColorCode_plugin/background.h @@ -0,0 +1,55 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + +#ifndef BACKGROUND_H +#define BACKGROUND_H + +#include +#include +#include +#include +#include +#include "colorcode.h" + +class BackGround : public QObject, public QGraphicsItem +{ + Q_OBJECT + + public: + BackGround(QObject* parent = 0); + ~BackGround(); + + QRectF boundingRect() const; + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); + + private: + QRectF outlineRect() const; + + QBrush mTopGrad; + QBrush mBotGrad; + + QPen mFramePen; + + QColor mPend; + QColor mPenl; + QColor mGrad0; + QColor mGrad1; + +}; + +#endif // BACKGROUND_H diff --git a/plugins/ColorCode_plugin/ccsolver.cpp b/plugins/ColorCode_plugin/ccsolver.cpp new file mode 100644 index 000000000..be5c2aa41 --- /dev/null +++ b/plugins/ColorCode_plugin/ccsolver.cpp @@ -0,0 +1,674 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + +#include "ccsolver.h" + +using namespace std; + +const int CCSolver::mFGCnts[4][9][4] = { +{ + {2, 0, 0, 0}, + {2, 0, 0, 0}, + {1, 1, 0, 0}, + {1, 1, 0, 0}, + {1, 1, 0, 0}, + {1, 1, 0, 0}, + {1, 1, 0, 0}, + {1, 1, 0, 0}, + {1, 1, 0, 0} +}, +{ + {3, 0, 0, 0}, + {2, 1, 0, 0}, + {1, 1, 1, 0}, + {1, 1, 1, 0}, + {1, 1, 1, 0}, + {1, 1, 1, 0}, + {1, 1, 1, 0}, + {1, 1, 1, 0}, + {1, 1, 1, 0} +}, +{ + {3, 1, 0, 0}, + {3, 1, 0, 0}, + {2, 1, 1, 0}, + {2, 2, 0, 0}, + {2, 2, 0, 0}, + {1, 1, 1, 1}, + {1, 1, 1, 1}, + {1, 1, 1, 1}, + {1, 1, 1, 1} +}, +{ + {4, 1, 0, 0}, + {3, 2, 0, 0}, + {3, 1, 1, 0}, + {2, 2, 1, 0}, + {2, 1, 1, 1}, + {2, 2, 1, 0}, + {2, 1, 1, 1}, + {2, 1, 1, 1}, + {2, 1, 1, 1} +} +}; + +CCSolver::CCSolver(ColorCode* cc) +{ + mCc = cc; + + mColorCnt = 0; + mPegCnt = 0; + mDoubles = -1; + mLevel = -1; + mMaxGuessCnt = 0; + + mAllCnt = 0; + mPosCnt = 0; + mHistCnt = 0; + mGuessCnt = 0; + mMaxRes = 0; + mResCnt = 0; + + mRestartCnt = 0; + + mResTable = NULL; + mCascade = NULL; + mPossible = NULL; + mAllTable = NULL; + mHist = NULL; + + mS = NULL; + mP = NULL; + + mBusy = false; +} + +CCSolver::~CCSolver() +{ + FreeTables(); +} + +void CCSolver::NewGame(const int ccnt, const int pcnt, const int doubles, const int level, const int gcnt) +{ + FreeTables(); + + mColorCnt = ccnt; + mPegCnt = pcnt; + mDoubles = doubles; + mLevel = level; + mMaxGuessCnt = gcnt; + + mAllCnt = 0; + mPosCnt = 0; + mHistCnt = 0; + mGuessCnt = 0; + mMaxRes = 0; + mResCnt = 0; + + mRestartCnt = 0; + mLastPosCnt = 0; + + InitTables(); +} + +void CCSolver::RestartGame() +{ + if (mGuessCnt > 0) + { + ++mRestartCnt; + } + + for (int i = 0 ; i < mMaxGuessCnt ; ++i) + { + mHist[i] = NULL; + } + + mGuessCnt = 0; +} + +void CCSolver::GuessIn(string str) +{ + int ix = Row2Ix(str); + mHist[mGuessCnt] = new int[2]; + mHist[mGuessCnt][0] = ix; +} + +void CCSolver::GuessIn(const vector* rowsol) +{ + int ix = Row2Ix(rowsol); + mHist[mGuessCnt] = new int[2]; + mHist[mGuessCnt][0] = ix; +} + +int* CCSolver::GuessOut() +{ + if (mPosCnt == mLastPosCnt && (mGuessCnt > 0 || mRestartCnt > 0)) + { + return mAllTable[mLastGuess]; + } + + int g = Guess(); + if (g < 0 || g >= mAllCnt) + { + return NULL; + } + + mLastPosCnt = mPosCnt; + mLastGuess = g; + return mAllTable[g]; +} + +int CCSolver::ResIn(const vector* res) +{ + int r = 0; + int len = res->size(); + int i; + for (i = 0; i < len; ++i) + { + if (res->at(i) == 2) + { + r += 10; + } + else if (res->at(i) == 1) + { + r += 1; + } + } + + mHist[mGuessCnt][1] = r; + UpdPos(mHist[mGuessCnt][0], r); + ++mGuessCnt; + + return r; +} + +void CCSolver::FreeTables() +{ + int i; + + delete [] mCascade; + mCascade = NULL; + + delete [] mPossible; + mPossible = NULL; + + for (i = 0 ; i < mAllCnt ; ++i) + { + delete [] mAllTable[i] ; + } + delete [] mAllTable; + mAllTable = NULL; + + for (i = 0 ; i < mMaxGuessCnt ; ++i) + { + delete [] mHist[i] ; + } + + delete [] mHist; + mHist = NULL; + + delete [] mResTable; + mResTable = NULL; + + delete [] mS; + mS = NULL; + + delete [] mP; + mP = NULL; +} + +void CCSolver::InitTables() +{ + int i, j, k; + + if (mDoubles != 1 && mColorCnt < mPegCnt) + { + return; + } + + mCascade = new int [mPegCnt]; + + for (i = 0; i < mPegCnt; ++i) + { + mCascade[i] = IntPow(mColorCnt, mPegCnt - i - 1); + } + + mAllCnt = 1; + for (i = 0; i < mPegCnt; ++i) + { + mAllCnt *= mColorCnt; + } + + mAllTable = new int* [mAllCnt]; + + for (i = 0; i < mAllCnt; ++i) + { + mAllTable[i] = new int [mPegCnt]; + } + + + mPossible = new int [mAllCnt]; + + for (i = 0; i < mAllCnt; ++i) + { + FillTable(i); + } + + mHist = new int* [mMaxGuessCnt]; + for (i = 0 ; i < mMaxGuessCnt ; ++i) + { + mHist[i] = NULL; + } + + mS = new int [mColorCnt]; + mP = new int [mColorCnt]; + + mMaxRes = mPegCnt * 10; + + mResCnt = (IntFac(mPegCnt + 2)) / (IntFac(mPegCnt) * 2) - 1; + + mResTable = new int[mResCnt]; + + k = 0; + for (i = 0; i <= mPegCnt; ++i) + { + for (j = 0; j <= mPegCnt - i; ++j, ++k) + { + if (i == mPegCnt - 1 && j == 1) + { + --k; + continue; + } + mResTable[k] = i * 10 + j; + } + } +} + +void CCSolver::FillTable(const int ix) +{ + int i; + int v = ix; + int pos = 1; + int j; + + for (i = 0; i < mPegCnt; ++i) + { + mAllTable[ix][i] = 0; + } + + for (i = 0; i < mPegCnt; ++i) + { + while (v >= mCascade[i]) + { + ++mAllTable[ix][i]; + v -= mCascade[i]; + } + if (mDoubles != 1 && pos == 1) + { + for (j = 0; j < i; j++) + { + if (mAllTable[ix][j] == mAllTable[ix][i]) + { + pos = 0; + break; + } + } + } + } + + mPosCnt += pos; + mPossible[ix] = pos; +} + +int CCSolver::RowCmp(const int* sol, const int* pat) +{ + int bl = 0; + int wh = 0; + int i; + + for (i = 0; i < mColorCnt; ++i) + { + mS[i] = mP[i] = 0; + } + + for (i = 0; i < mPegCnt; ++i) + { + if (sol[i] == pat[i]) + { + ++bl; + } + else + { + if (mP[sol[i]] > 0) + { + ++wh; + --mP[sol[i]]; + } + else + { + ++mS[sol[i]]; + } + + if (mS[pat[i]] > 0) + { + ++wh; + --mS[pat[i]]; + } + else + { + ++mP[pat[i]]; + } + } + } + + return (10 * bl + wh); +} + +void CCSolver::UpdPos(const int ix, const int res) +{ + int i; + for (i = 0; i < mAllCnt; ++i) + { + if (!mPossible[i]) + { + continue; + } + + if (RowCmp(mAllTable[i], mAllTable[ix]) != res) + { + mPossible[i] = 0; + --mPosCnt; + } + } +} + +string CCSolver::FirstGuess() +{ + int i, j, r; + int pegcnt = 0; + int diffcnt = 0; + + const int* fg = mFGCnts[mPegCnt-2][mColorCnt-2]; + char s[mPegCnt]; + int t[mColorCnt]; + + for (i = 0; i < mColorCnt; ++i) + { + t[i] = 0; + } + + if (mDoubles == 1) + { + for (i = 0; i < 4; ++i) + { + if (fg[i] == 0) + { + break; + } + + do + { + r = rand() % mColorCnt; + } + while (t[r] > 0); + ++t[r]; + ++diffcnt; + for (j = 0; j < fg[i]; ++j) + { + s[pegcnt++] = 'A' + r; + } + if (pegcnt == mPegCnt) + { + break; + } + } + + if (pegcnt != mPegCnt) + { + ; + } + + if (mPegCnt > 2 && diffcnt > 1) + { + for (int i = 0; i < (mPegCnt - 1); ++i) + { + r = i + (rand() % (mPegCnt - i)); + if (i != r) + { + char tmp = s[i]; + s[i] = s[r]; + s[r] = tmp; + } + } + } + } + else + { + for (i = 0; i < mPegCnt; ++i) + { + do + { + r = rand() % mColorCnt; + } + while (t[r] > 0); + ++t[r]; + s[i] = 'A' + r; + } + } + + return string(s, mPegCnt); +} + +int CCSolver::Guess() +{ + clock_t start, finish; + start = clock(); + + if (mGuessCnt == 0 && mRestartCnt == 0) + { + return Row2Ix(FirstGuess()); + } + + mBusy = true; + + int level = mLevel; + if (level == 2 && mPosCnt > 10000) + { + level = 1; + } + + int i, j; + + if (level == 0) + { + for (i = 0; i < mAllCnt; ++i) + { + if (mPossible[i]) + { + break; + } + } + } + else if (level == 1) + { + int m = mPosCnt >> 1; + for (i = 0; i < mAllCnt; ++i) + { + if (mPossible[i]) + { + if (--m <= 0) + { + break; + } + } + } + } + else + { + // Donald E. Knuth. The Computer as Master Mind. J. Recreational Mathematics, 9 (1976-77), 1-6. + // Kenji Koyama, Tony W. Lai. An optimal Mastermind Strategy. J. Recreational Mathematics, 1994. + // we'll only take the still possible ones into account, but ... + + int solix = -1; + int shortest = 1000000; + int longest; + int res2pos[mMaxRes]; + + for (j = 0; j <= mMaxRes; ++j) + { + res2pos[j] = 0; + } + + for (i = 0; i < mAllCnt; ++i) + { + if (!mPossible[i]) + { + continue; + } + + for (j = 0; j < mAllCnt; ++j) + { + if (!mPossible[j]) + { + continue; + } + ++res2pos[RowCmp(mAllTable[j], mAllTable[i])]; + } + + longest = 0; + for (j = 0; j < mResCnt; ++j) + { + if (res2pos[mResTable[j]] > longest) + { + longest = res2pos[mResTable[j]]; + } + res2pos[mResTable[j]] = 0; + } + + if (longest < shortest) + { + shortest = longest; + solix = i; + } + } + + i = solix; + } + + finish = clock(); + mBusy = false; + + return i; +} + +string CCSolver::RowOut(const int* r) +{ + char s[mPegCnt]; + + int i; + for (i = 0; i < mPegCnt; ++i) + { + s[i] = 'A' + r[i]; + } + + return string(s, mPegCnt); +} + +int CCSolver::Row2Ix(const vector* v) +{ + int i; + int ix = 0; + int len = v->size(); + + if (len != mPegCnt) + { + return -1; + } + + int j; + for (i = 0; i < mPegCnt; ++i) + { + j = v->at(i); + if (j >= mColorCnt) + { + ix = -1; + break; + } + ix += j * mCascade[i]; + } + + if (ix >= 0 && ix < mAllCnt) + { + return ix; + } + + return -1; +} + +int CCSolver::Row2Ix(const string str) +{ + int i; + int ix = 0; + int len = int(str.size()); + + if (len != mPegCnt) + { + return -1; + } + + int j; + for (i = 0; i < mPegCnt; ++i) + { + j = toupper(int(str[i])) - 'A'; + if (j >= mColorCnt) + { + ix = -1; + break; + } + ix += j * mCascade[i]; + } + + if (ix >= 0 && ix < mAllCnt) + { + return ix; + } + + return -1; +} + +int CCSolver::IntPow(const int b, const int e) +{ + int i; + int ret = 1; + for (i = 0; i < e; ++i) + { + ret *= b; + } + return ret; +} + +int CCSolver::IntFac(const int n) +{ + int fac = 1; + int i; + for (i = n; i > 1; --i) + { + fac *= i; + } + return fac; +} diff --git a/plugins/ColorCode_plugin/ccsolver.h b/plugins/ColorCode_plugin/ccsolver.h new file mode 100644 index 000000000..662aa2d65 --- /dev/null +++ b/plugins/ColorCode_plugin/ccsolver.h @@ -0,0 +1,90 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + +#ifndef CCSOLVER_H +#define CCSOLVER_H + +#include +#include "colorcode.h" + +using namespace std; + +class CCSolver +{ +public: + CCSolver(ColorCode* cc); + ~CCSolver(); + + void NewGame(const int ccnt, const int pcnt = 4, const int doubles = 1, const int level = 2, const int gcnt = 10); + void RestartGame(); + string FirstGuess(); + void GuessIn(string str); + void GuessIn(const vector* rowsol); + int ResIn(const vector* res); + int* GuessOut(); + + volatile bool mBusy; + +private: + static const int mFGCnts[4][9][4]; + + ColorCode* mCc; + + int mMaxGuessCnt; + int mColorCnt; + int mPegCnt; + int mDoubles; + int mLevel; + + int mLastGuess; + int mLastPosCnt; + + int mAllCnt; + int mPosCnt; + int mHistCnt; + int mGuessCnt; + int mMaxRes; + int mResCnt; + + int mRestartCnt; + + int* mResTable; + int* mCascade; + int* mPossible; + int** mAllTable; + int** mHist; + + int* mS; + int* mP; + + void FreeTables(); + void InitTables(); + void FillTable(const int ix); + int RowCmp(const int* sol, const int* pat); + void UpdPos(const int ix, const int res); + int Guess(); + + string RowOut(const int* r); + int Row2Ix(const string str); + int Row2Ix(const vector* v); + + int IntPow(const int b, const int e); + int IntFac(const int n); +}; + +#endif // CCSOLVER_H diff --git a/plugins/ColorCode_plugin/changelog b/plugins/ColorCode_plugin/changelog new file mode 100644 index 000000000..cd09a90d5 --- /dev/null +++ b/plugins/ColorCode_plugin/changelog @@ -0,0 +1,84 @@ +* 0.5.5 released, October 31, 2009 + * Summary + - Accessibility and usability improvements + * Settings options + - For the color sensitive of us ;-) the posibility to change the color order by drag and drop + has been added. + - Press CTRL while dragging to flip two colors or CTRL+SHIFT to cyclic shift the color order. + You can do this even while a game is running - the whole existing display will change. + - New 'Reset Color Order' option in the settings menu to revert your changes. + - Also - and more important - for the more text aimed a settings option has been added, + to toggle the display of letter indicators for the different peg colors. + - Make the documentations page accessible from the game's help menu. + * Layout/Design + - Some minor changes. + + +* 0.5 released, October 21, 2009 + * Summary + - The number of columns in the game is now customizable. The column count can be any number + from 2 untill 5. + - Updated translation files + * Solver + - Changed how the solver determines the first guess. Also - for the following really calculated + guesses - if the number of possibilities is very high (mostly at the early phase of a 10 colors/ + 5 columns game) the solver will automatically fallback to a weaker algorithm until the number + of possibilities has been narrowed, to reduce calculating time + * Layout/Design + - Some minor changes to handle the variable number of columns. Added toolbar controls to enable + the change of all level related settings here. The statusbar now permanently shows the current + game's settings. + + +* 0.4 released, October 7, 2009 + * Summary + - The GUI has been changed completely and the Usability was improved by adding some keyboard + shortcuts for often needed interactions. + - Added czech translation. Thanks to Pavel Fric. + * Fixes + - To avoid those 'QGraphicsItem::ungrabMouse: not a mouse grabber' warnings emit the mouse event + only if the hint button hasn't been disabled just before ... + * License + - The License had been changed from the GPL v2 to GPL v3. + * Layout/Design + - Complete Change, so all paint methods had to be changed and optimized. The background is now + drawn by its own class, no more brushed metall background image anymore. + + +* 0.3 released, September 26, 2009 + * Summary + - Introduced a rather perfect MasterMind solver. It will watch any move you take and any hints + you have gotten, so you can at any time in a running game let your computer guess for you. + Of course you can change or discard it's suggestion :-) . + * Solver + - The solver has 3 built in levels of stregth. For the suggestions, currently only the most + powerfull is used. For the first guess it will use a reasonable random guess based on pre- + calculated combinations to reduce computation time. + * Layout/Design + - Make the solver's guess action accessible at the toolbar. + + +* 0.2 released, September 10, 2009 + * Summary + - Added 3 levels of difficulty (Easy, Medium, Hard) based on the possibility to change the + available number of colors for a game. You can play games with 6, 8 or 10 colors. + * Layout/Design + - Added a combo-box (select) control to the toolbar, to easily access the level (color count) + settings. + - Enable hiding the menubar, toolbar and statusbar. + - Changed to a centered layout (message display and game board). + + +* 0.1 released, September 6, 2009 + * Summary + - This is the initial release of ColorCode, a free MasterMind clone. Try to guess a combination + of 8 colors within at most 10 guesses. + - You may allow or not pegs of the same color. You can fill the rows by random or duplicate + a previous one. + * GUI + - English and German translations are available. + + + + + diff --git a/plugins/ColorCode_plugin/colorcode.cpp b/plugins/ColorCode_plugin/colorcode.cpp new file mode 100644 index 000000000..695127e97 --- /dev/null +++ b/plugins/ColorCode_plugin/colorcode.cpp @@ -0,0 +1,1588 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + + +#include + +#include "ccsolver.h" +#include "colorcode.h" +#include "colorpeg.h" +#include "pegrow.h" +#include "rowhint.h" +#include "msg.h" +#include "background.h" +#include "about.h" +#include "solrow.h" + +using namespace std; + +const int IdRole = Qt::UserRole; + +int ColorCode::mColorCnt = 0; +int ColorCode::mPegCnt = 0; +int ColorCode::mDoubles = 1; +int ColorCode::mXOffs = 0; +int ColorCode::mMaxZ = 0; +int ColorCode::mLevel = -1; + +volatile bool ColorCode::mNoAct = false; + +const int ColorCode::STATE_RUNNING = 0; +const int ColorCode::STATE_WON = 1; +const int ColorCode::STATE_LOST = 2; +const int ColorCode::STATE_GAVE_UP = 3; + +const int ColorCode::MAX_COLOR_CNT = 10; + +const int ColorCode::mLevelSettings[5][3] = { + { 2, 2, 1}, + { 4, 3, 0}, + { 6, 4, 1}, + { 8, 4, 1}, + {10, 5, 1} + }; + +ColorCode::ColorCode() +{ + QTime midnight(0, 0, 0); + qsrand(midnight.secsTo(QTime::currentTime())); + + ROW_CNT = 10; + ROW_Y0 = 130; + + mOrigSize = NULL; + + setWindowTitle(tr("ColorCode")); + setWindowIcon(QIcon(QPixmap(":/img/cc16.png"))); + setIconSize(QSize(16, 16)); + + mMenuBar = menuBar(); + mBg = new BackGround(); + mMsg = new Msg; + + // as long as menuBar's size is invalid populated initially ... +#ifdef Q_WS_X11 + scene = new QGraphicsScene(0, 0, 320, 580); +#else + scene = new QGraphicsScene(0, 0, 320, 560); +#endif + + scene->setBackgroundBrush(QBrush(QColor("#b0b1b3"))); + view = new QGraphicsView; + view->setScene(scene); + view->setGeometry(0, 0, 320, 560); + view->setDragMode(QGraphicsView::NoDrag); + view->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); + view->setContextMenuPolicy(Qt::NoContextMenu); + view->setAlignment(Qt::AlignCenter); + view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setCentralWidget(view); + scene->addItem(mBg); + mBg->setPos(0, 0); + scene->addItem(mMsg); + mMsg->setPos(20, 10); + + mSolver = new CCSolver(this); + + mCurRow = NULL; + mColorCnt = MAX_COLOR_CNT; + mGameId = 0; + mGuessCnt = 0; + + InitTypesMap(); + InitActions(); + InitMenus(); + InitToolBars(); + + statusBar()->setStyleSheet("QStatusBar::item { border: 0px solid black }; "); + mStatusLabel = new QLabel(); + statusBar()->addPermanentWidget(mStatusLabel, 0); + + InitSolution(); + InitRows(); + InitPegBtns(); + + NewGame(); + + mMsg->setZValue(++ColorCode::mMaxZ); +} + +ColorCode::~ColorCode() +{ + int i; + if (mPegCnt > 0) + { + for (i = 0; i < mPegCnt; ++i) + { + if (mSolPegs[i] != NULL) + { + RemovePeg(mSolPegs[i]); + mSolPegs[i] = NULL; + } + } + + delete [] mSolPegs; + mSolPegs = NULL; + } +} + +void ColorCode::InitSolution() +{ + mSolRow = new SolRow(); + mSolRow->setPos(50, 70); + scene->addItem(mSolRow); +} + +void ColorCode::InitRows() +{ + PegRow* row; + RowHint* hint; + + int xpos = 60; + int ypos = ROW_Y0; + int i; + + for (i = 0; i < ROW_CNT; ++i) + { + row = new PegRow(); + row->SetIx(i); + row->setPos(QPoint(xpos, ypos + (ROW_CNT - (i + 1)) * 40)); + row->setZValue(++ColorCode::mMaxZ); + row->SetActive(false); + scene->addItem(row); + mPegRows[i] = row; + connect(row, SIGNAL(RemovePegSignal(ColorPeg*)), this, SLOT(RemovePegSlot(ColorPeg*))); + connect(row, SIGNAL(RowSolutionSignal(int)), this, SLOT(RowSolutionSlot(int))); + + hint = new RowHint; + hint->SetIx(i); + hint->setPos(QPoint(4, ypos + (ROW_CNT - (i + 1)) * 40)); + hint->setZValue(++ColorCode::mMaxZ); + hint->SetActive(false); + scene->addItem(hint); + mHintBtns[i] = hint; + connect(hint, SIGNAL(HintPressedSignal(int)), this, SLOT(HintPressedSlot(int))); + } +} + +void ColorCode::InitPegBtns() +{ + for (int i = 0; i < MAX_COLOR_CNT; ++i) + { + mPegBtns[i] = NULL; + } +} + +void ColorCode::InitTypesMap() +{ + int ix; + + QRadialGradient grad = QRadialGradient(20, 20, 40, 5, 5); + QRadialGradient grad2 = QRadialGradient(18, 18, 18, 12, 12); + + ix = 0; + mTypesMap[ix] = new PegType; + grad.setColorAt(0.0, QColor("#FFFF80")); + grad.setColorAt(1.0, QColor("#C05800")); + mGradMap[ix] = grad; + mTypesMap[ix]->grad = &mGradMap[ix]; + mTypesMap[ix]->ix = ix; + mTypesMap[ix]->pencolor = Qt::green; + + ix = 1; + mTypesMap[ix] = new PegType; + grad.setColorAt(0.0, QColor("#FF3300")); + grad.setColorAt(1.0, QColor("#400040")); + mGradMap[ix] = grad; + mTypesMap[ix]->grad = &mGradMap[ix]; + mTypesMap[ix]->ix = ix; + mTypesMap[ix]->pencolor = Qt::green; + + ix = 2; + mTypesMap[ix] = new PegType; + grad.setColorAt(0.0, QColor("#33CCFF")); + grad.setColorAt(1.0, QColor("#000080")); + mGradMap[ix] = grad; + mTypesMap[ix]->grad = &mGradMap[ix]; + mTypesMap[ix]->ix = ix; + mTypesMap[ix]->pencolor = Qt::red; + + ix = 3; + mTypesMap[ix] = new PegType; + grad2.setColorAt(0.0, Qt::white); + grad2.setColorAt(0.5, QColor("#f8f8f0")); + grad2.setColorAt(0.7, QColor("#f0f0f0")); + grad2.setColorAt(1.0, QColor("#d0d0d0")); + mGradMap[ix] = grad2; + mTypesMap[ix]->grad = &mGradMap[ix]; + mTypesMap[ix]->ix = ix; + mTypesMap[ix]->pencolor = Qt::green; + + ix = 4; + mTypesMap[ix] = new PegType; + grad.setColorAt(0.0, QColor("#808080")); + grad.setColorAt(1.0, Qt::black); + mGradMap[ix] = grad; + mTypesMap[ix]->grad = &mGradMap[ix]; + mTypesMap[ix]->ix = ix; + mTypesMap[ix]->pencolor = Qt::red; + + ix = 5; + mTypesMap[ix] = new PegType; + grad.setColorAt(0.0, QColor("#66FF33")); + grad.setColorAt(1.0, QColor("#385009")); + mGradMap[ix] = grad; + mTypesMap[ix]->grad = &mGradMap[ix]; + mTypesMap[ix]->ix = ix; + mTypesMap[ix]->pencolor = Qt::red; + + ix = 6; + mTypesMap[ix] = new PegType; + grad.setColorAt(0.0, QColor("#FF9900")); + grad.setColorAt(1.0, QColor("#A82A00")); + mGradMap[ix] = grad; + mTypesMap[ix]->grad = &mGradMap[ix]; + mTypesMap[ix]->ix = ix; + mTypesMap[ix]->pencolor = Qt::red; + + ix = 7; + mTypesMap[ix] = new PegType; + grad.setColorAt(0.0, QColor("#BA88FF")); + grad.setColorAt(1.0, QColor("#38005D")); + mGradMap[ix] = grad; + mTypesMap[ix]->grad = &mGradMap[ix]; + mTypesMap[ix]->ix = ix; + mTypesMap[ix]->pencolor = Qt::green; + + ix = 8; + mTypesMap[ix] = new PegType; + grad.setColorAt(0.0, QColor("#00FFFF")); + grad.setColorAt(1.0, QColor("#004040")); + mGradMap[ix] = grad; + mTypesMap[ix]->grad = &mGradMap[ix]; + mTypesMap[ix]->ix = ix; + mTypesMap[ix]->pencolor = Qt::green; + + ix = 9; + mTypesMap[ix] = new PegType; + grad.setColorAt(0.0, QColor("#FFC0FF")); + grad.setColorAt(1.0, QColor("#800080")); + mGradMap[ix] = grad; + mTypesMap[ix]->grad = &mGradMap[ix]; + mTypesMap[ix]->ix = ix; + mTypesMap[ix]->pencolor = Qt::green; + + for (ix = 0; ix < MAX_COLOR_CNT; ++ix) + { + mTypesMap[ix]->let = 'A' + ix; + mGradBuff[ix] = mGradMap[ix]; + } +} + +void ColorCode::InitActions() +{ + NewGameAction = new QAction(tr("&New Game"), this); + NewGameAction->setIcon(QIcon(":/img/document-new.png")); + NewGameAction->setShortcut(tr("Ctrl+N")); + connect(NewGameAction, SIGNAL(triggered()), this, SLOT(NewGameSlot())); + + RestartGameAction = new QAction(tr("&Restart Game"), this); + RestartGameAction->setIcon(QIcon(":/img/view-refresh.png")); + RestartGameAction->setShortcut(tr("Ctrl+Shift+R")); + connect(RestartGameAction, SIGNAL(triggered()), this, SLOT(RestartGameSlot())); + + GiveInAction = new QAction(tr("&Throw In The Towel"), this); + GiveInAction->setIcon(QIcon(":/img/face-sad.png")); + GiveInAction->setShortcut(tr("Ctrl+G")); + connect(GiveInAction, SIGNAL(triggered()), this, SLOT(GiveInSlot())); + + ExitAction = new QAction(tr("E&xit"), this); + ExitAction->setIcon(QIcon(":/img/application-exit.png")); + ExitAction->setShortcut(tr("Ctrl+Q")); + connect(ExitAction, SIGNAL(triggered()), this, SLOT(close())); + + ShowToolbarAction = new QAction(tr("Show Toolbar"), this); + ShowToolbarAction->setCheckable(true); + ShowToolbarAction->setChecked(true); + ShowToolbarAction->setShortcut(tr("Ctrl+T")); + connect(ShowToolbarAction, SIGNAL(triggered()), this, SLOT(ShowToolbarSlot())); + + ShowMenubarAction = new QAction(tr("Show Menubar"), this); + ShowMenubarAction->setCheckable(true); + ShowMenubarAction->setChecked(true); + ShowMenubarAction->setShortcut(tr("Ctrl+M")); + connect(ShowMenubarAction, SIGNAL(triggered()), this, SLOT(ShowMenubarSlot())); + + ShowStatusbarAction = new QAction(tr("Show Statusbar"), this); + ShowStatusbarAction->setCheckable(true); + ShowStatusbarAction->setChecked(true); + ShowStatusbarAction->setShortcut(tr("Ctrl+S")); + connect(ShowStatusbarAction, SIGNAL(triggered()), this, SLOT(ShowStatusbarSlot())); + + mActResetColorsOrder = new QAction(tr("Reset Color Order"), this); + mActResetColorsOrder->setShortcut(tr("Ctrl+Shift+R")); + connect(mActResetColorsOrder, SIGNAL(triggered()), this, SLOT(ResetColorsOrderSlot())); + + mActShowLetter = new QAction(tr("Show Letter Indicators"), this); + mActShowLetter->setCheckable(true); + mActShowLetter->setChecked(false); + mActShowLetter->setShortcut(tr("Ctrl+Shift+L")); + connect(mActShowLetter, SIGNAL(triggered()), this, SLOT(ShowLetterSlot())); + + SameColorAction = new QAction(tr("Allow Pegs of the Same Color"), this); + SameColorAction->setCheckable(true); + SameColorAction->setChecked(true); + SameColorAction->setShortcut(tr("Ctrl+Shift+C")); + connect(SameColorAction, SIGNAL(triggered(bool)), this, SLOT(SameColorSlot(bool))); + + mActSameColorIcon = new QAction(tr("Allow Pegs of the Same Color"), this); + mActSameColorIcon->setCheckable(true); + mActSameColorIcon->setChecked(true); + mActSameColorIcon->setToolTip(tr("Disallow Pegs of the Same Color")); + mActSameColorIcon->setIcon(QIcon(":/img/same_color_1.png")); + connect(mActSameColorIcon, SIGNAL(triggered(bool)), this, SLOT(SameColorSlot(bool))); + + AutoCloseAction = new QAction(tr("Close Rows when the last Peg is placed"), this); + AutoCloseAction->setCheckable(true); + AutoCloseAction->setChecked(false); + AutoCloseAction->setShortcut(tr("Ctrl+L")); + connect(AutoCloseAction, SIGNAL(triggered()), this, SLOT(AutoCloseSlot())); + + mLaunchHelpAction = new QAction(tr("Online &Help"), this); + mLaunchHelpAction->setIcon(QIcon(":/img/help.png")); + mLaunchHelpAction->setShortcut(tr("F1")); + connect(mLaunchHelpAction, SIGNAL(triggered()), this, SLOT(OnlineHelpSlot())); + + AboutAction = new QAction(tr("About &ColorCode"), this); + AboutAction->setIcon(QIcon(":/img/help-about.png")); + AboutAction->setShortcut(tr("Ctrl+A")); + connect(AboutAction, SIGNAL(triggered()), this, SLOT(AboutSlot())); + + AboutQtAction = new QAction(tr("About &Qt"), this); + AboutQtAction->setIcon(QIcon(":/img/qt.png")); + AboutQtAction->setShortcut(tr("Ctrl+I")); + connect(AboutQtAction, SIGNAL(triggered()), this, SLOT(AboutQtSlot())); + + RandRowAction = new QAction(tr("Fill Row by Random"), this); + RandRowAction->setIcon(QIcon(":/img/system-switch-user.png")); + RandRowAction->setShortcut(tr("Ctrl+R")); + connect(RandRowAction, SIGNAL(triggered()), this, SLOT(RandRowSlot())); + + PrevRowAction = new QAction(tr("Duplicate Previous Row"), this); + PrevRowAction->setIcon(QIcon(":/img/edit-copy.png")); + PrevRowAction->setShortcut(tr("Ctrl+D")); + connect(PrevRowAction, SIGNAL(triggered()), this, SLOT(PrevRowSlot())); + + ClearRowAction = new QAction(tr("Clear Row"), this); + ClearRowAction->setIcon(QIcon(":/img/edit-clear.png")); + ClearRowAction->setShortcut(tr("Ctrl+C")); + connect(ClearRowAction, SIGNAL(triggered()), this, SLOT(ClearRowSlot())); + + mActLevelEasy = new QAction(tr("Beginner (2 Colors, 2 Slots, Doubles)"), this); + mActLevelEasy->setData(0); + mActLevelEasy->setCheckable(true); + mActLevelEasy->setChecked(false); + connect(mActLevelEasy, SIGNAL(triggered()), this, SLOT(ForceLevelSlot())); + + mActLevelClassic = new QAction(tr("Easy (4 Colors, 3 Slots, No Doubles)"), this); + mActLevelClassic->setData(1); + mActLevelClassic->setCheckable(true); + mActLevelClassic->setChecked(false); + connect(mActLevelClassic, SIGNAL(triggered()), this, SLOT(ForceLevelSlot())); + + mActLevelMedium = new QAction(tr("Classic (6 Colors, 4 Slots, Doubles)"), this); + mActLevelMedium->setData(2); + mActLevelMedium->setCheckable(true); + mActLevelMedium->setChecked(true); + connect(mActLevelMedium, SIGNAL(triggered()), this, SLOT(ForceLevelSlot())); + + mActLevelChallenging = new QAction(tr("Challenging (8 Colors, 4 Slots, Doubles)"), this); + mActLevelChallenging->setData(3); + mActLevelChallenging->setCheckable(true); + mActLevelChallenging->setChecked(false); + connect(mActLevelChallenging, SIGNAL(triggered()), this, SLOT(ForceLevelSlot())); + + mActLevelHard = new QAction(tr("Hard (10 Colors, 5 Slots, Doubles)"), this); + mActLevelHard->setData(4); + mActLevelHard->setCheckable(true); + mActLevelHard->setChecked(false); + connect(mActLevelHard, SIGNAL(triggered()), this, SLOT(ForceLevelSlot())); + + + mActGetGuess = new QAction(tr("Computer's Guess"), this); + mActGetGuess->setIcon(QIcon(":/img/business_user.png")); + mActGetGuess->setShortcut(tr("Ctrl+H")); + connect(mActGetGuess, SIGNAL(triggered()), this, SLOT(GetGuessSlot())); +} + +void ColorCode::InitMenus() +{ + GameMenu = mMenuBar->addMenu(tr("&Game")); + GameMenu->addAction(NewGameAction); + GameMenu->addAction(RestartGameAction); + GameMenu->addAction(GiveInAction); + GameMenu->addSeparator(); + GameMenu->addAction(ExitAction); + + RowMenu = mMenuBar->addMenu(tr("&Row")); + RowMenu->addAction(RandRowAction); + RowMenu->addAction(PrevRowAction); + RowMenu->addAction(ClearRowAction); + RowMenu->addSeparator(); + RowMenu->addAction(mActGetGuess); + connect(RowMenu, SIGNAL(aboutToShow()), this, SLOT(UpdateRowMenuSlot())); + + SettingsMenu = mMenuBar->addMenu(tr("&Settings")); + SettingsMenu->addAction(ShowMenubarAction); + SettingsMenu->addAction(ShowToolbarAction); + SettingsMenu->addAction(ShowStatusbarAction); + SettingsMenu->addSeparator(); + SettingsMenu->addAction(mActResetColorsOrder); + SettingsMenu->addAction(mActShowLetter); + SettingsMenu->addSeparator(); + + LevelMenu = SettingsMenu->addMenu(tr("Level Presets")); + mLevelActions = new QActionGroup(LevelMenu); + mLevelActions->addAction(mActLevelEasy); + mLevelActions->addAction(mActLevelClassic); + mLevelActions->addAction(mActLevelMedium); + mLevelActions->addAction(mActLevelChallenging); + mLevelActions->addAction(mActLevelHard); + QList levelacts = mLevelActions->actions(); + LevelMenu->addActions(levelacts); + SettingsMenu->addSeparator(); + + SettingsMenu->addAction(SameColorAction); + SettingsMenu->addAction(AutoCloseAction); + + HelpMenu = mMenuBar->addMenu(tr("&Help")); + HelpMenu->addAction(mLaunchHelpAction); + HelpMenu->addSeparator(); + HelpMenu->addAction(AboutAction); + HelpMenu->addAction(AboutQtAction); + + RowContextMenu = new QMenu(); + RowContextMenu->addAction(RandRowAction); + RowContextMenu->addAction(PrevRowAction); + RowContextMenu->addAction(ClearRowAction); + RowContextMenu->addSeparator(); + RowContextMenu->addAction(mActGetGuess); + RowContextMenu->addSeparator(); + RowContextMenu->addAction(NewGameAction); + RowContextMenu->addAction(RestartGameAction); + RowContextMenu->addAction(GiveInAction); + RowContextMenu->addSeparator(); + RowContextMenu->addAction(ExitAction); + + addActions(mMenuBar->actions()); +} + +void ColorCode::InitToolBars() +{ + mGameToolbar = addToolBar(tr("Game")); + mGameToolbar->setAllowedAreas(Qt::NoToolBarArea); + mGameToolbar->setFloatable(false); + mGameToolbar->setIconSize(QSize(16, 16)); + mGameToolbar->setMovable(false); + mGameToolbar->addAction(NewGameAction); + mGameToolbar->addAction(RestartGameAction); + mGameToolbar->addAction(GiveInAction); + mGameToolbar->addSeparator(); + mGameToolbar->addAction(mActGetGuess); + + mColorCntCmb = new QComboBox(); + mColorCntCmb->setLayoutDirection(Qt::LeftToRight); + mColorCntCmb->setFixedWidth(84); + mColorCntCmb->addItem("2 " + tr("Colors"), 2); + mColorCntCmb->addItem("3 " + tr("Colors"), 3); + mColorCntCmb->addItem("4 " + tr("Colors"), 4); + mColorCntCmb->addItem("5 " + tr("Colors"), 5); + mColorCntCmb->addItem("6 " + tr("Colors"), 6); + mColorCntCmb->addItem("7 " + tr("Colors"), 7); + mColorCntCmb->addItem("8 " + tr("Colors"), 8); + mColorCntCmb->addItem("9 " + tr("Colors"), 9); + mColorCntCmb->addItem("10 " + tr("Colors"), 10); + mColorCntCmb->setCurrentIndex(6); + connect(mColorCntCmb, SIGNAL(currentIndexChanged(int)), this, SLOT(mColorCntChangedSlot())); + + mPegCntCmb = new QComboBox(); + mPegCntCmb->setLayoutDirection(Qt::LeftToRight); + mPegCntCmb->setFixedWidth(76); + mPegCntCmb->addItem("2 " + tr("Slots"), 2); + mPegCntCmb->addItem("3 " + tr("Slots"), 3); + mPegCntCmb->addItem("4 " + tr("Slots"), 4); + mPegCntCmb->addItem("5 " + tr("Slots"), 5); + mPegCntCmb->setCurrentIndex(2); + connect(mPegCntCmb, SIGNAL(currentIndexChanged(int)), this, SLOT(PegCntChangedSlot())); + + mLevelToolbar = addToolBar(tr("Level")); + mLevelToolbar->setAllowedAreas(Qt::NoToolBarArea); + mLevelToolbar->setFloatable(false); + mLevelToolbar->setIconSize(QSize(16, 16)); + mLevelToolbar->setMovable(false); + mLevelToolbar->setLayoutDirection(Qt::RightToLeft); + mLevelToolbar->addWidget(mColorCntCmb); + QWidget* spacer = new QWidget(); + spacer->setMinimumWidth(4); + mLevelToolbar->addWidget(spacer); + mLevelToolbar->addWidget(mPegCntCmb); + QWidget* spacer2 = new QWidget(); + spacer2->setMinimumWidth(4); + mLevelToolbar->addWidget(spacer2); + mLevelToolbar->addAction(mActSameColorIcon); +} + +void ColorCode::contextMenuEvent(QContextMenuEvent* e) +{ + + QList list = view->items(view->mapFromGlobal(e->globalPos())); + int i = 0; + bool isrow = false; + if (mGameState == STATE_RUNNING && mCurRow != NULL) + { + for (i = 0; i < list.size(); ++i) + { + if (list.at(i) == mCurRow || list.at(i) == mHintBtns[mCurRow->GetIx()]) + { + isrow = true; + break; + } + } + } + + if (isrow) + { + UpdateRowMenuSlot(); + RowContextMenu->exec(e->globalPos()); + } + else + { + GameMenu->exec(e->globalPos()); + } +} + +void ColorCode::resizeEvent (QResizeEvent* e) +{ + Q_UNUSED(e); + Scale(); +} + +void ColorCode::keyPressEvent(QKeyEvent *e) +{ + switch (e->key()) + { + case Qt::Key_Return: + case Qt::Key_Enter: + if (mCurRow != NULL && mGameState == STATE_RUNNING) + { + int ix = mCurRow->GetIx(); + if (mHintBtns[ix]->mActive) + { + std::vector s = mCurRow->GetSolution(); + if (s.size() == (unsigned) mPegCnt) + { + mHintBtns[ix]->SetActive(false); + HintPressedSlot(ix); + } + } + } + break; + } +} + +void ColorCode::UpdateRowMenuSlot() +{ + if (mGameState != STATE_RUNNING || mCurRow == NULL) + { + RandRowAction->setEnabled(false); + PrevRowAction->setEnabled(false); + ClearRowAction->setEnabled(false); + mActGetGuess->setEnabled(false); + return; + } + else + { + RandRowAction->setEnabled(true); + mActGetGuess->setEnabled(true); + } + + if (mCurRow->GetIx() < 1) + { + PrevRowAction->setEnabled(false); + } + else + { + PrevRowAction->setEnabled(true); + } + + if (mCurRow->GetPegCnt() == 0) + { + ClearRowAction->setEnabled(false); + } + else + { + ClearRowAction->setEnabled(true); + } +} + +void ColorCode::RestartGameSlot() +{ + ResetRows(); + SetState(STATE_RUNNING); + + mCurRow = NULL; + mSolver->RestartGame(); + NextRow(); +} + +void ColorCode::NewGameSlot() +{ + if (mGameState == STATE_RUNNING && mCurRow != NULL) + { + int r = QMessageBox::warning( this, + tr("New Game"), + tr("Do you want to give in\nand start a new Game?"), + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); + if (r == QMessageBox::Yes) + { + NewGame(); + } + } + else + { + NewGame(); + } +} + +void ColorCode::GiveInSlot() +{ + int r = QMessageBox::Yes; + if (mGameState == STATE_RUNNING && mCurRow != NULL) + { + r = QMessageBox::warning( this, + tr("Give In"), + tr("Do you really want to give in?"), + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); + } + + if (r == QMessageBox::Yes) + { + SetState(STATE_GAVE_UP); + + if (mCurRow != NULL) + { + mCurRow->CloseRow(); + mHintBtns[mCurRow->GetIx()]->SetActive(false); + } + + ResolveGame(); + } +} + +void ColorCode::OnlineHelpSlot() +{ + QDesktopServices::openUrl(QUrl("http://colorcode.laebisch.com/documentation", QUrl::TolerantMode)); +} + +void ColorCode::AboutSlot() +{ + About ab(this); + ab.exec(); +} + +void ColorCode::AboutQtSlot() +{ + QMessageBox::aboutQt( this, + tr("About Qt")); +} + +void ColorCode::ShowToolbarSlot() +{ + if (!ShowToolbarAction->isChecked()) + { + mGameToolbar->hide(); + mLevelToolbar->hide(); + } + else + { + mGameToolbar->show(); + mLevelToolbar->show(); + } + Scale(); +} + +void ColorCode::ShowMenubarSlot() +{ + if (!ShowMenubarAction->isChecked()) + { + mMenuBar->hide(); + } + else + { + mMenuBar->show(); + } + Scale(); +} + +void ColorCode::ShowStatusbarSlot() +{ + if (!ShowStatusbarAction->isChecked()) + { + statusBar()->hide(); + } + else + { + statusBar()->show(); + } + Scale(); +} + +void ColorCode::ResetColorsOrderSlot() +{ + int ix; + for (ix = 0; ix < MAX_COLOR_CNT; ++ix) + { + mGradMap[ix] = mGradBuff[ix]; + } + scene->update(scene->sceneRect()); +} + +void ColorCode::ShowLetterSlot() +{ + bool checked = mActShowLetter->isChecked(); + vector::iterator it; + for (it = mAllPegs.begin(); it < mAllPegs.end(); it++) + { + (*it)->ShowLetter(checked); + } +} + +void ColorCode::SameColorSlot(bool checked) +{ + if (mNoAct) + { + return; + } + + SetSameColor(checked); + + int r = QMessageBox::Yes; + if (mGameState == STATE_RUNNING && mGuessCnt > 1) + { + r = QMessageBox::question( this, + tr("Message"), + tr("The changed settings will only apply to new games!\nDo you want to give in the current and start a new Game?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes); + } + + if (r == QMessageBox::Yes) + { + NewGame(); + } +} + +void ColorCode::AutoCloseSlot() +{ + +} + +void ColorCode::mColorCntChangedSlot() +{ + if (mNoAct) + { + return; + } + + int r = QMessageBox::Yes; + if (mGameState == STATE_RUNNING && mGuessCnt > 1) + { + r = QMessageBox::question( this, + tr("Message"), + tr("The changed settings will only apply to new games!\nDo you want to give in the current and start a new Game?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes); + } + + if (r == QMessageBox::Yes) + { + NewGame(); + } +} + +void ColorCode::PegCntChangedSlot() +{ + if (mNoAct) + { + return; + } + + int pcnt = mPegCntCmb->itemData(mPegCntCmb->currentIndex(), IdRole).toInt(); + if (pcnt == mPegCnt) + { + return; + } + + int r = QMessageBox::Yes; + if (mGameState == STATE_RUNNING && mGuessCnt > 1) + { + r = QMessageBox::question( this, + tr("Message"), + tr("The changed settings will only apply to new games!\nDo you want to give in the current and start a new Game?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes); + } + + if (r == QMessageBox::Yes) + { + NewGame(); + } +} + +void ColorCode::ForceLevelSlot() +{ + mNoAct = true; + int ix = mLevelActions->checkedAction()->data().toInt(); + + if (ix < 0 || ix > 4) + { + return; + } + + int i; + i = mColorCntCmb->findData(mLevelSettings[ix][0]); + if (i != -1 && mColorCntCmb->currentIndex() != i) + { + mColorCntCmb->setCurrentIndex(i); + } + i = mPegCntCmb->findData(mLevelSettings[ix][1]); + if (i != -1 && mPegCntCmb->currentIndex() != i) + { + mPegCntCmb->setCurrentIndex(i); + } + + SetSameColor((mLevelSettings[ix][2] == 1)); + + int r = QMessageBox::Yes; + if (mGameState == STATE_RUNNING && mGuessCnt > 1) + { + r = QMessageBox::question( this, + tr("Message"), + tr("The changed settings will only apply to new games!\nDo you want to give in the current and start a new Game?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes); + } + + mNoAct = false; + + if (r == QMessageBox::Yes) + { + NewGame(); + } +} + +void ColorCode::RemovePegSlot(ColorPeg* cp) +{ + RemovePeg(cp); +} + +void ColorCode::ShowMsgSlot(QString msg) +{ + mMsg->ShowMsg(msg); +} + +void ColorCode::PegPressSlot(ColorPeg* cp) +{ + if (cp == NULL) { return; } + cp->setZValue(++ColorCode::mMaxZ); + + if (cp->IsBtn()) + { + cp->SetBtn(false); + mPegBtns[cp->GetPegType()->ix] = CreatePeg(cp->GetPegType()->ix); + mPegBtns[cp->GetPegType()->ix]->SetEnabled(false); + } +} + +void ColorCode::PegSortSlot(ColorPeg* cp) +{ + if (cp == NULL) { return; } + cp->setZValue(++ColorCode::mMaxZ); + + if (cp->IsBtn()) + { + cp->SetBtn(false); + mPegBtns[cp->GetPegType()->ix] = CreatePeg(cp->GetPegType()->ix); + mPegBtns[cp->GetPegType()->ix]->SetEnabled(false); + } +} + +void ColorCode::PegReleasedSlot(ColorPeg* cp) +{ + if (cp == NULL || !cp) { return; } + + scene->clearSelection(); + scene->clearFocus(); + + int i; + if (cp->GetSort() == 0) + { + bool snapped = false; + QList list = scene->items(QPointF(cp->pos().x() + 18, cp->pos().y() + 18)); + + for (i = 0; i < list.size(); ++i) + { + if (mCurRow != NULL && list.at(i) == mCurRow) + { + snapped = mCurRow->SnapCP(cp); + break; + } + } + + if (!snapped) + { + RemovePeg(cp); + } + } + else + { + int ystart = ROW_Y0 + (MAX_COLOR_CNT - mColorCnt) * 40; + int ix1 = qRound((qRound(cp->pos().y()) - ystart + 18) / 40); + ix1 = min(mColorCnt - 1, max(0, ix1)); + + int ix0 = cp->GetPegType()->ix; + if (ix0 != ix1) + { + QRadialGradient tmp = mGradMap[ix0]; + + if (cp->GetSort() == 1) + { + mGradMap[ix0] = mGradMap[ix1]; + } + else + { + int step = (ix1 > ix0) ? 1 : -1; + + + + for (i = ix0;; i += step) + { + mGradMap[i] = mGradMap[i + step]; + if (i == ix1 - step) + { + break; + } + } + } + + mGradMap[ix1] = tmp; + } + RemovePeg(cp); + } + + if (!mPegBtns[cp->GetPegType()->ix]->isEnabled()) + { + mPegBtns[cp->GetPegType()->ix]->SetEnabled(true); + } +} + +void ColorCode::RowSolutionSlot(int ix) +{ + std::vector s = mPegRows[ix]->GetSolution(); + if (s.size() == (unsigned) mPegCnt) + { + if (AutoCloseAction->isChecked()) + { + HintPressedSlot(ix); + } + else + { + mHintBtns[ix]->SetActive(true); + ShowMsgSlot(tr("Press the Hint Field or Key Enter if You're done.")); + } + } + else + { + mHintBtns[ix]->SetActive(false); + ShowMsgSlot(tr("Place Your pegs ...")); + } + +} + +void ColorCode::HintPressedSlot(int) +{ + mCurRow->CloseRow(); + ResolveRow(); + NextRow(); + ResolveGame(); +} + +void ColorCode::RandRowSlot() +{ + if (mCurRow == NULL || mGameState != STATE_RUNNING) + { + return; + } + + mCurRow->ClearRow(); + + int i, rndm; + int check[mColorCnt]; + ColorPeg* peg; + for (i = 0; i < mColorCnt; ++i) + { + check[i] = 0; + } + + for (i = 0; i < mPegCnt; ++i) + { + rndm = qrand() % mColorCnt; + if (mDoubles == 0 && check[rndm] != 0) + { + --i; + continue; + } + + check[rndm] = 1; + + peg = CreatePeg(rndm); + mCurRow->ForceSnap(peg, i); + } +} + +void ColorCode::GetGuessSlot() +{ + if (mCurRow == NULL || mGameState != STATE_RUNNING || mSolver->mBusy) + { + return; + } + + mCurRow->ClearRow(); + mActGetGuess->setEnabled(false); + int* row = mSolver->GuessOut(); + mActGetGuess->setEnabled(true); + if (row == NULL) + { + return; + } + + ColorPeg* peg; + int i; + for (i = 0; i < mPegCnt; ++i) + { + if (row[i] < 0 || row[i] >= MAX_COLOR_CNT) + { + ; + } + peg = CreatePeg(row[i]); + mCurRow->ForceSnap(peg, i); + } +} + +void ColorCode::PrevRowSlot() +{ + if (mCurRow == NULL || mGameState != STATE_RUNNING) + { + return; + } + + if (mCurRow->GetIx() < 1) + { + return; + } + + mCurRow->ClearRow(); + + ColorPeg* peg; + std::vector prev = mPegRows[mCurRow->GetIx() - 1]->GetSolution(); + int i; + for (i = 0; i < mPegCnt; ++i) + { + peg = CreatePeg(prev.at(i)); + mCurRow->ForceSnap(peg, i); + } +} + +void ColorCode::ClearRowSlot() +{ + if (mCurRow == NULL || mGameState != STATE_RUNNING) + { + return; + } + + mCurRow->ClearRow(); +} + +void ColorCode::TestSlot() +{ + ; +} + +void ColorCode::CheckSameColorsSetting() +{ + if (mColorCnt < mPegCnt) + { + if (SameColorAction->isEnabled()) + { + SameColorAction->setEnabled(false); + } + if (mActSameColorIcon->isEnabled()) + { + mActSameColorIcon->setEnabled(false); + } + if (!SameColorAction->isChecked()) + { + SameColorAction->setChecked(true); + } + if (!mActSameColorIcon->isChecked()) + { + mActSameColorIcon->setChecked(true); + } + } + else + { + if (!SameColorAction->isEnabled()) + { + SameColorAction->setEnabled(true); + } + if (!mActSameColorIcon->isEnabled()) + { + mActSameColorIcon->setEnabled(true); + } + } + + if (mActSameColorIcon->isChecked()) + { + mActSameColorIcon->setIcon(QIcon(":/img/same_color_1.png")); + mActSameColorIcon->setToolTip(tr("Disallow Pegs of the Same Color")); + } + else + { + mActSameColorIcon->setIcon(QIcon(":/img/same_color_0.png")); + mActSameColorIcon->setToolTip(tr("Allow Pegs of the Same Color")); + } +} + +void ColorCode::SetSameColor(bool checked) +{ + SameColorAction->setChecked(checked); + mActSameColorIcon->setChecked(checked); + + if (checked) + { + mActSameColorIcon->setIcon(QIcon(":/img/same_color_1.png")); + mActSameColorIcon->setToolTip(tr("Disallow Pegs of the Same Color")); + } + else + { + mActSameColorIcon->setIcon(QIcon(":/img/same_color_0.png")); + mActSameColorIcon->setToolTip(tr("Allow Pegs of the Same Color")); + } +} + +void ColorCode::CheckLevel() +{ + int ix = -1; + for (int i = 0; i < 5; ++i) + { + if ( mLevelSettings[i][0] == mColorCnt + && mLevelSettings[i][1] == mPegCnt + && mLevelSettings[i][2] == mDoubles ) + { + ix = i; + break; + } + } + + if (ix > -1) + { + QList levelacts = mLevelActions->actions(); + levelacts.at(ix)->setChecked(true); + } + else + { + QAction* act = mLevelActions->checkedAction(); + if (act != NULL) + { + act->setChecked(false); + } + } +} + +void ColorCode::ResetGame() +{ + int i; + + if (mPegCnt > 0) + { + for (i = 0; i < mPegCnt; ++i) + { + if (mSolPegs[i] != NULL) + { + RemovePeg(mSolPegs[i]); + mSolPegs[i] = NULL; + } + } + + delete [] mSolPegs; + mSolPegs = NULL; + } + + SetPegCnt(); + + mSolPegs = new ColorPeg* [mPegCnt]; + for (int i = 0; i < mPegCnt; ++i) + { + mSolPegs[i] = NULL; + } + + mSolRow->SetState(mPegCnt, false); + + ResetRows(); + + mGameId = qrand(); + mGuessCnt = 0; + + SetColorCnt(); + + CheckSameColorsSetting(); + + mDoubles = (int) SameColorAction->isChecked(); + CheckLevel(); +} + +void ColorCode::ResetRows() +{ + for (int i = 0; i < ROW_CNT; ++i) + { + mPegRows[i]->Reset(mPegCnt); + mHintBtns[i]->Reset(mPegCnt); + } +} + +void ColorCode::NewGame() +{ + ResetGame(); + QString doubles = (mDoubles == 1) ? tr("Yes") : tr("No"); + QString colors = QString::number(mColorCnt, 10); + QString pegs = QString::number(mPegCnt, 10); + mStatusLabel->setText(tr("Pegs of Same Color") + ": " + doubles + " :: " + tr("Slots") + ": " + pegs + " :: " + tr("Colors") + ": " + colors + " "); + SetState(STATE_RUNNING); + + mCurRow = NULL; + SetSolution(); + mSolver->NewGame(mColorCnt, mPegCnt, mDoubles, 2, ROW_CNT); + NextRow(); +} + +void ColorCode::NextRow() +{ + if (mGameState != STATE_RUNNING) + { + return; + } + + if (mCurRow == NULL) + { + mCurRow = mPegRows[0]; + } + else if (mCurRow->GetIx() < ROW_CNT - 1) + { + mCurRow = mPegRows[mCurRow->GetIx() + 1]; + } + else + { + mCurRow = NULL; + SetState(STATE_LOST); + } + + if (mCurRow != NULL) + { + ++mGuessCnt; + mCurRow->SetActive(true); + ShowMsgSlot(tr("Place Your pegs ...")); + } +} + +void ColorCode::ResolveRow() +{ + std::vector res; + std::vector left1; + std::vector left0; + std::vector rowsol = mCurRow->GetSolution(); + mSolver->GuessIn(&rowsol); + + int i, p0, p1; + for (i = 0; i < mPegCnt; ++i) + { + p0 = rowsol.at(i); + p1 = mSolution.at(i); + if (p0 == p1) + { + res.push_back(2); + } + else + { + left0.push_back(p0); + left1.push_back(p1); + } + } + + if (res.size() == (unsigned) mPegCnt) + { + SetState(STATE_WON); + } + else + { + int len0 = left0.size(); + for (i = 0; i < len0; ++i) + { + p0 = left0.at(i); + for (unsigned j = 0; j < left1.size(); ++j) + { + p1 = left1.at(j); + if (p0 == p1) + { + res.push_back(1); + left1.erase(left1.begin() + j); + break; + } + } + } + } + mSolver->ResIn(&res); + mHintBtns[mCurRow->GetIx()]->DrawHints(res); +} + +void ColorCode::ResolveGame() +{ + switch (mGameState) + { + case STATE_WON: + ShowMsgSlot(tr("Congratulation! You have won!")); + break; + case STATE_LOST: + ShowMsgSlot(tr("Sorry! You lost!")); + break; + case STATE_GAVE_UP: + ShowMsgSlot(tr("Sure, You're too weak for me!")); + break; + case STATE_RUNNING: + default: + return; + break; + } + + ShowSolution(); +} + +void ColorCode::SetPegCnt() +{ + int pegcnt = mPegCntCmb->itemData(mPegCntCmb->currentIndex(), IdRole).toInt(); + pegcnt = max(2, min(5, pegcnt)); + mPegCnt = pegcnt; + mXOffs = 160 - mPegCnt * 20; +} + +void ColorCode::SetColorCnt() +{ + int ccnt = mColorCntCmb->itemData(mColorCntCmb->currentIndex(), IdRole).toInt(); + ccnt = max(2, min(10, ccnt)); + + if (mColorCnt == ccnt) + { + return; + } + + mColorCnt = ccnt; + + int xpos = 279; + int ystart = ROW_Y0 + (MAX_COLOR_CNT - mColorCnt) * 40; + int ypos; + int i; + + for (i = 0; i < MAX_COLOR_CNT; ++i) + { + ypos = ystart + i * 40 + 2; + mBtnPos[i] = QPoint(xpos, ypos); + + if (i < mColorCnt) + { + if (mPegBtns[i] == NULL) + { + mPegBtns[i] = CreatePeg(i); + } + mPegBtns[i]->setPos(mBtnPos[i]); + mPegBtns[i]->setVisible(true); + } + else if (mPegBtns[i] != NULL) + { + mPegBtns[i]->setVisible(false); + } + } +} + +void ColorCode::SetSolution() +{ + mSolution.clear(); + int i, rndm; + int check[mColorCnt]; + for (i = 0; i < mColorCnt; ++i) + { + check[i] = 0; + } + + for (i = 0; i < mPegCnt; ++i) + { + rndm = qrand() % mColorCnt; + if (mDoubles == 0 && check[rndm] != 0) + { + --i; + continue; + } + mSolution.push_back(rndm); + check[rndm] = 1; + } +} + +void ColorCode::ShowSolution() +{ + ColorPeg* peg; + for (int i = 0; i < mPegCnt; ++i) + { + peg = CreatePeg(mSolution.at(i)); + peg->setPos(mXOffs + i * 40 + 2, 72); + peg->SetBtn(false); + peg->SetEnabled(false); + mSolPegs[i] = peg; + } +} + +void ColorCode::SetState(const int s) +{ + if (mGameState == s) + { + return; + } + + mGameState = s; + + bool running = mGameState == STATE_RUNNING; + + RestartGameAction->setEnabled(running); + GiveInAction->setEnabled(running); + mActGetGuess->setEnabled(running); +} + +void ColorCode::Scale() +{ + qreal w = geometry().width() - 4; + qreal h = geometry().height() - 4; + + if (ShowStatusbarAction->isChecked()) + { + h -= statusBar()->height(); + } + if (ShowMenubarAction->isChecked()) + { + h -= mMenuBar->height(); + } + if (ShowToolbarAction->isChecked()) + { + h -= mGameToolbar->height(); + } + + if (w < 50 || h < 50) + { + return; + } + + if (mOrigSize == NULL) + { + mOrigSize = new QSize(320, 560); + scene->setSceneRect(QRectF(0, 0, 320, 560)); + } + else + { + qreal sc = min(w / mOrigSize->width(), h / mOrigSize->height()); + view->resetTransform(); + view->scale(sc, sc); + } +} + +ColorPeg* ColorCode::CreatePeg(int ix) +{ + if (ix < 0 || ix >= mColorCnt) + { + ix = ColorCode::mMaxZ % mColorCnt; + } + + PegType *pt = mTypesMap[ix]; + ColorPeg *peg; + + if (mPegBuff.empty()) + { + peg = new ColorPeg; + peg->SetPegType(pt); + peg->SetBtn(true); + peg->ShowLetter(mActShowLetter->isChecked()); + peg->SetId(ColorCode::mMaxZ); + scene->addItem(peg); + peg->setPos(mBtnPos[ix]); + peg->setZValue(24); + mAllPegs.push_back(peg); + scene->clearSelection(); + scene->update(mBtnPos[ix].x(), mBtnPos[ix].y(), 38, 38); + peg->setSelected(true); + + connect(peg, SIGNAL(PegPressSignal(ColorPeg *)), this, SLOT(PegPressSlot(ColorPeg *))); + connect(peg, SIGNAL(PegSortSignal(ColorPeg *)), this, SLOT(PegSortSlot(ColorPeg *))); + connect(peg, SIGNAL(PegReleasedSignal(ColorPeg *)), this, SLOT(PegReleasedSlot(ColorPeg *))); + } + else + { + unsigned int sz = mPegBuff.size(); + peg = mPegBuff.at(sz - 1); + mPegBuff.resize(sz - 1); + + peg->setVisible(true); + + peg->SetPegType(pt); + peg->SetBtn(true); + peg->SetEnabled(true); + peg->setPos(mBtnPos[ix]); + scene->clearSelection(); + scene->update(mBtnPos[ix].x(), mBtnPos[ix].y(), 38, 38); + peg->setSelected(true); + } + + ++ColorCode::mMaxZ; + + return peg; +} + +void ColorCode::RemovePeg(ColorPeg* cp) +{ + if (cp != NULL) + { + cp->Reset(); + cp->setVisible(false); + mPegBuff.push_back(cp); + } +} diff --git a/plugins/ColorCode_plugin/mainwindow.h b/plugins/ColorCode_plugin/colorcode.h similarity index 56% rename from plugins/ColorCode_plugin/mainwindow.h rename to plugins/ColorCode_plugin/colorcode.h index f1adad133..b1e68293b 100644 --- a/plugins/ColorCode_plugin/mainwindow.h +++ b/plugins/ColorCode_plugin/colorcode.h @@ -1,5 +1,23 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + +#ifndef COLORCODE_H +#define COLORCODE_H #include #include @@ -7,30 +25,34 @@ struct PegType { int ix; - QRadialGradient grad; + char let; + QRadialGradient* grad; QColor pencolor; }; -//typedef std::vector TypesMap; - class QAction; class QActionGroup; class QComboBox; +class QLabel; class QGraphicsItem; class QGraphicsTextItem; class QGraphicsScene; class QGraphicsView; +class CCSolver; class ColorPeg; class PegRow; class RowHint; class Msg; +class BackGround; +class SolRow; -class MainWindow : public QMainWindow +class ColorCode : public QMainWindow { Q_OBJECT public: - MainWindow(); + ColorCode(); + ~ColorCode(); static const int STATE_RUNNING; static const int STATE_WON; @@ -38,13 +60,13 @@ class MainWindow : public QMainWindow static const int STATE_GAVE_UP; static const int MAX_COLOR_CNT; - static const int LEVEL_COLOR_CNTS[3]; int ROW_CNT; - int POS_CNT; + int ROW_Y0; public slots: void PegPressSlot(ColorPeg *cp); + void PegSortSlot(ColorPeg* cp); void PegReleasedSlot(ColorPeg *cp); void RowSolutionSlot(int ix); void HintPressedSlot(int ix); @@ -54,6 +76,7 @@ class MainWindow : public QMainWindow protected : void resizeEvent(QResizeEvent* e); void contextMenuEvent(QContextMenuEvent* e); + void keyPressEvent(QKeyEvent *e); private slots: void InitRows(); @@ -62,12 +85,16 @@ class MainWindow : public QMainWindow void RestartGameSlot(); void GiveInSlot(); void ResetRows(); + void OnlineHelpSlot(); void AboutSlot(); void AboutQtSlot(); void ShowToolbarSlot(); void ShowMenubarSlot(); void ShowStatusbarSlot(); - void SameColorSlot(); + void ResetColorsOrderSlot(); + void ShowLetterSlot(); + void SameColorSlot(bool checked); + void SetSameColor(bool checked); void AutoCloseSlot(); void ForceLevelSlot(); @@ -75,22 +102,30 @@ class MainWindow : public QMainWindow void PrevRowSlot(); void ClearRowSlot(); - void LevelChangedSlot(); + void mColorCntChangedSlot(); + void PegCntChangedSlot(); void UpdateRowMenuSlot(); + void GetGuessSlot(); + void TestSlot(); private: - enum Level { LEVEL_EASY, - LEVEL_MEDIUM, - LEVEL_HARD }; + static const int mLevelSettings[5][3]; - static Level mLevel; + static int mLevel; static int mColorCnt; + static int mPegCnt; + static int mDoubles; static int mMaxZ; + static int mXOffs; + + volatile static bool mNoAct; int mGameState; + int mGameId; + int mGuessCnt; std::vector mSolution; @@ -98,29 +133,37 @@ class MainWindow : public QMainWindow QGraphicsView* view; QSize* mOrigSize; + CCSolver* mSolver; Msg* mMsg; + BackGround* mBg; PegRow* mCurRow; + std::vector mAllPegs; std::vector mPegBuff; - PegRow* mSolRow; + SolRow* mSolRow; PegRow* mPegRows[10]; RowHint* mHintBtns[10]; PegType* mTypesMap[10]; + QRadialGradient mGradMap[10]; + QRadialGradient mGradBuff[10]; ColorPeg* mPegBtns[10]; - ColorPeg* mSolPegs[4]; + ColorPeg** mSolPegs; QPoint mBtnPos[10]; - void FillTypesMap(); - + void InitTypesMap(); void InitSolution(); void InitActions(); void InitMenus(); void InitToolBars(); - void SetLevel(); + void SetPegCnt(); + void SetColorCnt(); + void CheckLevel(); + void CheckSameColorsSetting(); void SetState(const int s); + void ResetGame(); void NewGame(); void SetSolution(); void ShowSolution(); @@ -138,10 +181,13 @@ class MainWindow : public QMainWindow QMenu* LevelMenu; QMenu* HelpMenu; QMenu* RowContextMenu; + QMenuBar* mMenuBar; QToolBar* mGameToolbar; QToolBar* mLevelToolbar; - QComboBox* mLevelCmb; + QComboBox* mColorCntCmb; + QComboBox* mPegCntCmb; + QLabel* mStatusLabel; QActionGroup* mLevelActions; QAction* NewGameAction; @@ -151,19 +197,28 @@ class MainWindow : public QMainWindow QAction* ShowMenubarAction; QAction* ShowStatusbarAction; QAction* SameColorAction; + QAction* mActResetColorsOrder; + QAction* mActShowLetter; + QAction* mActSameColorIcon; QAction* AutoCloseAction; QAction* AboutAction; QAction* AboutQtAction; QAction* ExitAction; + QAction* mActSetPegCnt; + QAction* mActLevelEasy; + QAction* mActLevelClassic; QAction* mActLevelMedium; + QAction* mActLevelChallenging; QAction* mActLevelHard; + QAction* mLaunchHelpAction; QAction* RandRowAction; QAction* PrevRowAction; QAction* ClearRowAction; + QAction* mActGetGuess; }; -#endif // MAINWINDOW_H +#endif // COLORCODE_H diff --git a/plugins/ColorCode_plugin/colorpeg.cpp b/plugins/ColorCode_plugin/colorpeg.cpp index 96a34125a..5f7c3cbb7 100644 --- a/plugins/ColorCode_plugin/colorpeg.cpp +++ b/plugins/ColorCode_plugin/colorpeg.cpp @@ -1,12 +1,39 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #include #include "colorpeg.h" using namespace std; - +const QFont ColorPeg::mFont = ColorPeg::GetLetterFont(); const QBrush ColorPeg::mShadowBrush = ColorPeg::GetShadowBrush(); -const QPen ColorPeg::mPen = ColorPeg::GetOutlinePen(); +const QBrush ColorPeg::mOutlineBrush = ColorPeg::GetOutlineBrush(); +const QBrush ColorPeg::mGlossyBrush = ColorPeg::GetGlossyBrush(); + +QFont ColorPeg::GetLetterFont() +{ + QFont lf("Arial", 12, QFont::Bold, false); + lf.setStyleHint(QFont::SansSerif); + + return lf; +} QBrush ColorPeg::GetShadowBrush() { @@ -17,12 +44,20 @@ QBrush ColorPeg::GetShadowBrush() return QBrush(rgrad); } -QPen ColorPeg::GetOutlinePen() +QBrush ColorPeg::GetOutlineBrush() { - QRadialGradient rgrad(20, 20, 32, 0, 0); - rgrad.setColorAt(0.0, Qt::black); - rgrad.setColorAt(1.0, Qt::white); - return QPen(QBrush(rgrad), 2); + QLinearGradient lgrad(0, 0, 38, 38); + lgrad.setColorAt(0.0, QColor(0, 0, 0, 0xa0)); + lgrad.setColorAt(1.0, QColor(0xff, 0xff, 0xff, 0xa0)); + return QBrush(lgrad); +} + +QBrush ColorPeg::GetGlossyBrush() +{ + QLinearGradient lgrad(20, 4, 20, 20); + lgrad.setColorAt(0.0, QColor(0xff, 0xff, 0xff, 0x80)); + lgrad.setColorAt(1.0, QColor(0xff, 0xff, 0xff, 0x00)); + return QBrush(lgrad); } @@ -33,6 +68,8 @@ ColorPeg::ColorPeg(QObject*) mPegRow = NULL; SetBtn(true); mIsDragged = false; + mShowLetter = false; + mSort = 0; mId = -1; } @@ -66,6 +103,11 @@ bool ColorPeg::IsBtn() const return mIsBtn; } +int ColorPeg::GetSort() const +{ + return mSort; +} + void ColorPeg::SetBtn(bool b) { mIsBtn = b; @@ -105,23 +147,43 @@ void ColorPeg::SetIsDragged(bool b) void ColorPeg::SetEnabled(const bool b) { setEnabled(b); - //setFlags(QGraphicsItem::GraphicsItemFlags(0)); SetCursorShape(); } +void ColorPeg::ShowLetter(const bool b) +{ + if (mShowLetter != b) + { + mShowLetter = b; + update(boundingRect()); + } +} + void ColorPeg::SetCursorShape(Qt::CursorShape shape, const bool force) { if (!force) { if (mIsDragged) { - shape = Qt::ClosedHandCursor; + if (mSort == 0) + { + shape = Qt::ClosedHandCursor; + } + else if (mSort == 1) + { + shape = Qt::SizeVerCursor; + } + else + { + shape = Qt::SplitVCursor; + } } else if (isEnabled()) { shape = Qt::OpenHandCursor; } } + if (cursor().shape() != shape) { setCursor(QCursor(shape)); @@ -130,16 +192,7 @@ void ColorPeg::SetCursorShape(Qt::CursorShape shape, const bool force) QVariant ColorPeg::itemChange(GraphicsItemChange change, const QVariant &value) { - if (change == ItemPositionHasChanged) - { - } - else if (change == ItemPositionChange) - { - } - else if (change == ItemFlagsChange) - { - } - else if (change == ItemSelectedHasChanged) + if (change == ItemSelectedHasChanged) { scene()->update(scene()->sceneRect()); } @@ -148,21 +201,38 @@ QVariant ColorPeg::itemChange(GraphicsItemChange change, const QVariant &value) void ColorPeg::mousePressEvent(QGraphicsSceneMouseEvent *e) { + QGraphicsItem::mousePressEvent(e); if (mPegType != NULL) { if (e->button() == Qt::LeftButton) { Reset(); SetIsDragged(true); + if (IsBtn() && (e->modifiers() & Qt::ControlModifier) != 0) + { + if ((e->modifiers() & Qt::ShiftModifier) == 0) + { + mSort = 1; + } + else + { + mSort = 2; + } + } + else + { + mSort = 0; + + } emit PegPressSignal(this); SetCursorShape(); } } - QGraphicsItem::mousePressEvent(e); } void ColorPeg::mouseReleaseEvent (QGraphicsSceneMouseEvent *e) { + QGraphicsItem::mouseReleaseEvent(e); if (mPegType != NULL) { if (e->button() == Qt::LeftButton) @@ -172,7 +242,6 @@ void ColorPeg::mouseReleaseEvent (QGraphicsSceneMouseEvent *e) SetCursorShape(); } } - QGraphicsItem::mouseReleaseEvent(e); } QPainterPath ColorPeg::shape() const @@ -202,31 +271,39 @@ QRectF ColorPeg::outlineRect() const return rect; } +QRectF ColorPeg::GetColorRect() const +{ + QRectF rect(1.0, 1.0, 34.0, 34.0); + return rect; +} + void ColorPeg::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget* /* widget */) { - /* - QPen pen(Qt::red); - pen.setWidth(2); - if (option->state & QStyle::State_Selected) + painter->setPen(Qt::NoPen); + + if (!mIsDragged) { - pen.setStyle(Qt::DotLine); + painter->setBrush(ColorPeg::mOutlineBrush); + painter->drawEllipse(outlineRect()); } - */ - - - if (mIsDragged) + else { - painter->setPen(Qt::NoPen); painter->translate(QPointF(-2, -2)); painter->setBrush(ColorPeg::mShadowBrush); painter->drawEllipse(QRectF(0, 0, 44, 44)); painter->translate(QPointF(2, 2)); } - else - { - painter->setPen(ColorPeg::mPen); - } - painter->setBrush(QBrush(mPegType->grad)); - painter->drawEllipse(outlineRect()); + painter->setBrush(QBrush(*mPegType->grad)); + painter->drawEllipse(GetColorRect()); + painter->setBrush(mGlossyBrush); + painter->drawEllipse(QRectF(5, 3, 24, 20)); + + if (mShowLetter) + { + painter->setPen(QPen(QColor("#303133"))); + painter->setRenderHint(QPainter::TextAntialiasing, true); + painter->setFont(mFont); + painter->drawText(QRectF(1.5, 2.0, 32.0, 32.0), Qt::AlignCenter, QString(mPegType->let)); + } } diff --git a/plugins/ColorCode_plugin/colorpeg.h b/plugins/ColorCode_plugin/colorpeg.h index f85b587a0..9adb1f654 100644 --- a/plugins/ColorCode_plugin/colorpeg.h +++ b/plugins/ColorCode_plugin/colorpeg.h @@ -1,3 +1,21 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #ifndef COLORPEG_H #define COLORPEG_H @@ -7,7 +25,7 @@ #include #include #include -#include "mainwindow.h" +#include "colorcode.h" #include "pegrow.h" #include "rowhint.h" @@ -15,7 +33,6 @@ class ColorPeg : public QObject, public QGraphicsItem { Q_OBJECT - //Q_DECLARE_TR_FUNCTIONS(ColorPeg) public: ColorPeg(QObject* parent = 0); @@ -33,6 +50,7 @@ public: void SetType(const int t); void SetEnabled(const bool b); + void ShowLetter(const bool b); void SetCursorShape( Qt::CursorShape shape = Qt::ArrowCursor, const bool force = false); PegType* GetPegType(); int GetType() const; @@ -40,12 +58,14 @@ public: QColor GetBrushColor() const; bool IsBtn() const; + int GetSort() const; void SetBtn(bool b); void Reset(); signals: void PegReleasedSignal(ColorPeg* cp); void PegPressSignal(ColorPeg* cp); + void PegSortSignal(ColorPeg* cp); protected: PegType* mPegType; @@ -55,11 +75,16 @@ protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent* e); private: + static const QFont mFont; + static QFont GetLetterFont(); static const QBrush mShadowBrush; static QBrush GetShadowBrush(); - static const QPen mPen; - static QPen GetOutlinePen(); + static const QBrush mOutlineBrush; + static QBrush GetOutlineBrush(); + static const QBrush mGlossyBrush; + static QBrush GetGlossyBrush(); + QRectF GetColorRect() const; QRectF outlineRect() const; void SetIsDragged(bool b); @@ -68,8 +93,10 @@ private: const QBrush mBrush; int mType; + int mSort; bool mIsBtn; - bool mIsDragged; + bool mIsDragged; + bool mShowLetter; }; diff --git a/plugins/ColorCode_plugin/docs/GPL.html b/plugins/ColorCode_plugin/docs/GPL.html index 24d8b7b9b..77894b212 100644 --- a/plugins/ColorCode_plugin/docs/GPL.html +++ b/plugins/ColorCode_plugin/docs/GPL.html @@ -1,492 +1,694 @@ - - - - - - - - - -GNU General Public License v2.0 - GNU Project - Free Software Foundation (FSF) - - - -

GNU GENERAL PUBLIC LICENSE

-

-Version 2, June 1991 -

- -
-Copyright (C) 1989, 1991 Free Software Foundation, Inc.  
-51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
-
-Everyone is permitted to copy and distribute verbatim copies
-of this license document, but changing it is not allowed.
-
- -

Preamble

- -

- The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) 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 -this service 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 make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. -

- -

- For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. 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. -

- -

- We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. -

- -

- Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. -

- -

- Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. -

- -

- The precise terms and conditions for copying, distribution and -modification follow. -

- - -

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

- - -

-0. - This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". -

- -

-Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. -

- -

-1. - You may copy and distribute 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 and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. -

- -

-You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. -

- -

-2. - You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: -

- -
-
-
- a) - You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. -
-
-
- b) - You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. -
-
-
- c) - If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) -
-
- -

-These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. -

- -

-Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. -

- -

-In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. -

- -

-3. - You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: -

- - - - -
-
-
- a) - Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, -
-
-
- b) - Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, -
-
-
- c) - Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) -
-
- -

-The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. -

- -

-If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. -

- -

-4. - You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. -

- -

-5. - You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. -

- -

-6. - Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. -

- -

-7. - If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -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 -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. -

- -

-If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. -

- -

-It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. -

- -

-This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. -

- -

-8. - If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. -

- -

-9. - The Free Software Foundation may publish revised and/or new versions -of the 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 a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. -

- -

-10. - If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. -

- -

NO WARRANTY

- -

-11. - BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. -

- -

-12. - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE 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. -

- -

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 -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. -

- -
-one line to give the program's name and an idea of what it does.
-Copyright (C) yyyy  name of author
-
-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 2
-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, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-
- -

-Also add information on how to contact you by electronic and paper mail. -

- -

-If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: -

- -
-Gnomovision version 69, Copyright (C) year name of author
-Gnomovision 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, the -commands you use may be called something other than `show w' and -`show c'; they could even be mouse-clicks or menu items--whatever -suits your program. -

- -

-You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: -

- - -
-Yoyodyne, Inc., hereby disclaims all copyright
-interest in the program `Gnomovision'
-(which makes passes at compilers) written 
-by James Hacker.
-
-signature of Ty Coon, 1 April 1989
-Ty Coon, President of Vice
-
- -

-This 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. -

- - - + + + + + GNU General Public License - GNU Project - Free Software Foundation (FSF) + + + +

GNU GENERAL PUBLIC LICENSE

+

Version 3, 29 June 2007

+ +

Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>

+ 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.

+ +
    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    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 <http://www.gnu.org/licenses/>.
+
+ +

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:

+ +
    <program>  Copyright (C) <year>  <name of author>
+    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 +<http://www.gnu.org/licenses/>.

+ +

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 +<http://www.gnu.org/philosophy/why-not-lgpl.html>.

+ + + diff --git a/plugins/ColorCode_plugin/img/Thumbs.db b/plugins/ColorCode_plugin/img/Thumbs.db index 5d10538b0..4fcb6e19c 100644 Binary files a/plugins/ColorCode_plugin/img/Thumbs.db and b/plugins/ColorCode_plugin/img/Thumbs.db differ diff --git a/plugins/ColorCode_plugin/img/business_user.png b/plugins/ColorCode_plugin/img/business_user.png new file mode 100644 index 000000000..65f5d9a8e Binary files /dev/null and b/plugins/ColorCode_plugin/img/business_user.png differ diff --git a/plugins/ColorCode_plugin/img/gplv3-80x32.png b/plugins/ColorCode_plugin/img/gplv3-80x32.png new file mode 100644 index 000000000..7f6731699 Binary files /dev/null and b/plugins/ColorCode_plugin/img/gplv3-80x32.png differ diff --git a/plugins/ColorCode_plugin/img/help.png b/plugins/ColorCode_plugin/img/help.png new file mode 100644 index 000000000..9f0c92f23 Binary files /dev/null and b/plugins/ColorCode_plugin/img/help.png differ diff --git a/plugins/ColorCode_plugin/img/same_color_0.png b/plugins/ColorCode_plugin/img/same_color_0.png new file mode 100644 index 000000000..0ffbe8b2e Binary files /dev/null and b/plugins/ColorCode_plugin/img/same_color_0.png differ diff --git a/plugins/ColorCode_plugin/img/same_color_1.png b/plugins/ColorCode_plugin/img/same_color_1.png new file mode 100644 index 000000000..35aca3870 Binary files /dev/null and b/plugins/ColorCode_plugin/img/same_color_1.png differ diff --git a/plugins/ColorCode_plugin/main.cpp b/plugins/ColorCode_plugin/main.cpp index 6a1c67b3c..7eb1cd6eb 100644 --- a/plugins/ColorCode_plugin/main.cpp +++ b/plugins/ColorCode_plugin/main.cpp @@ -1,9 +1,27 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #include #include #include #include #include -#include "mainwindow.h" +#include "colorcode.h" int main(int argc, char* argv[]) { @@ -20,13 +38,13 @@ int main(int argc, char* argv[]) { cout << "usage: ColorCode [options]" << endl; cout << " options:" << endl; - cout << " -l cc, --lang=cc use country code cc instead of system locale, accepted values for cc: en|de" << endl; + cout << " -l cc, --lang=cc use country code cc instead of system locale, accepted values for cc: en|de|cs" << endl; cout << " -h, --help prints this message ;-)" << endl; return 0; } else if (str == "-l" && i < argc - 1) { - if (std::string(argv[i + 1]) == "de" || std::string(argv[i + 1]) == "en") + if (std::string(argv[i + 1]) == "de" || std::string(argv[i + 1]) == "en" || std::string(argv[i + 1]) == "cs") { std::string test(argv[i]); lang = argv[i + 1]; @@ -34,7 +52,7 @@ int main(int argc, char* argv[]) } else if ( str.size() == 9 && str.find("--lang=") != string::npos - && (str.substr(7) == "en" || str.substr(7) == "de") ) + && (str.substr(7) == "en" || str.substr(7) == "de" || str.substr(7) == "cs") ) { lang = str.substr(7); } @@ -57,7 +75,7 @@ int main(int argc, char* argv[]) QTranslator appTranslator; if (lang == "") { - appTranslator.load("trans_" + QLocale::system().name()); + appTranslator.load(":/trans_" + QLocale::system().name()); } else { @@ -65,7 +83,7 @@ int main(int argc, char* argv[]) } app.installTranslator(&appTranslator); - MainWindow w; + ColorCode w; w.show(); return app.exec(); } diff --git a/plugins/ColorCode_plugin/mainwindow.cpp b/plugins/ColorCode_plugin/mainwindow.cpp deleted file mode 100644 index c12b23671..000000000 --- a/plugins/ColorCode_plugin/mainwindow.cpp +++ /dev/null @@ -1,1136 +0,0 @@ -#include - -#include "mainwindow.h" -#include "colorpeg.h" -#include "pegrow.h" -#include "rowhint.h" -#include "msg.h" -#include "about.h" - -using namespace std; - -const int IdRole = Qt::UserRole; - -MainWindow::Level MainWindow::mLevel = LEVEL_EASY; -int MainWindow::mColorCnt = 0; -int MainWindow::mMaxZ = 0; - -const int MainWindow::STATE_RUNNING = 0; -const int MainWindow::STATE_WON = 1; -const int MainWindow::STATE_LOST = 2; -const int MainWindow::STATE_GAVE_UP = 3; - -const int MainWindow::MAX_COLOR_CNT = 10; -const int MainWindow::LEVEL_COLOR_CNTS[3] = {6, 8, MainWindow::MAX_COLOR_CNT}; - -MainWindow::MainWindow() -{ - ROW_CNT = 10; - POS_CNT = 4; - - //setMaximumSize(334, 649); - - mOrigSize = NULL; - - setWindowTitle(tr("ColorCode")); - setWindowIcon(QIcon(QPixmap(":/img/cc16.png"))); - setIconSize(QSize(16, 16)); - - mMsg = new Msg; - scene = new QGraphicsScene(0, 0, 320, 560); - - scene->setBackgroundBrush(QImage(":/img/bm03.png")); - //scene->setItemIndexMethod(scene->NoIndex); - - view = new QGraphicsView; - view->setScene(scene); - view->setGeometry(0, 0, 320, 540); - view->setDragMode(QGraphicsView::NoDrag); - view->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); - //view->setContextMenuPolicy(Qt::ActionsContextMenu); - //view->setContextMenuPolicy(Qt::DefaultContextMenu); - view->setContextMenuPolicy(Qt::NoContextMenu); - view->setAlignment(Qt::AlignCenter); - view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setCentralWidget(view); - scene->addItem(mMsg); - mMsg->setPos(20, 0); - - //view->setBackgroundBrush(QImage(":/img/metal5.png")); - //view->setCacheMode(QGraphicsView::CacheBackground); - - mCurRow = NULL; - mColorCnt = MAX_COLOR_CNT; - - FillTypesMap(); - - InitActions(); - InitMenus(); - InitToolBars(); - - statusBar(); - - InitSolution(); - InitRows(); - InitPegBtns(); - - NewGame(); -} - -void MainWindow::Scale() -{ - qreal w = geometry().width() - 4; - qreal h = geometry().height() - 4; - - if (ShowStatusbarAction->isChecked()) - { - h -= statusBar()->height(); - } - if (ShowMenubarAction->isChecked()) - { - h -= menuBar()->height(); - } - if (ShowToolbarAction->isChecked()) - { - h -= mGameToolbar->height(); - } - - if (w < 50 || h < 50) - { - return; - } - - if (mOrigSize == NULL) - { - mOrigSize = new QSize(320, 541); - scene->setSceneRect(QRectF(0, 0, 320, 540)); - } - else - { - qreal sc = min(w / mOrigSize->width(), h / mOrigSize->height()); - view->resetTransform(); - view->scale(sc, sc); - } -} - -void MainWindow::contextMenuEvent(QContextMenuEvent* e) -{ - - QList list = view->items(view->mapFromGlobal(e->globalPos())); - int i = 0; - bool isrow = false; - if (mGameState == STATE_RUNNING && mCurRow != NULL) - { - for (i = 0; i < list.size(); ++i) - { - if (list.at(i) == mCurRow || list.at(i) == mHintBtns[mCurRow->GetIx()]) - { - isrow = true; - break; - } - } - } - - if (isrow) - { - UpdateRowMenuSlot(); - RowContextMenu->exec(e->globalPos()); - } - else - { - GameMenu->exec(e->globalPos()); - } -} - -void MainWindow::UpdateRowMenuSlot() -{ - if (mGameState != STATE_RUNNING || mCurRow == NULL) - { - RandRowAction->setEnabled(false); - PrevRowAction->setEnabled(false); - ClearRowAction->setEnabled(false); - return; - } - else - { - RandRowAction->setEnabled(true); - } - - if (mCurRow->GetIx() < 1) - { - PrevRowAction->setEnabled(false); - } - else - { - PrevRowAction->setEnabled(true); - } - - if (mCurRow->GetPegCnt() == 0) - { - ClearRowAction->setEnabled(false); - } - else - { - ClearRowAction->setEnabled(true); - } -} - -void MainWindow::resizeEvent (QResizeEvent* e) -{ - Q_UNUSED(e); - Scale(); -} - -void MainWindow::NewGame() -{ - SetLevel(); - ResetRows(); - SetState(STATE_RUNNING); - - mCurRow = NULL; - SetSolution(); - NextRow(); -} - -void MainWindow::RestartGameSlot() -{ - for (int i = 0; i < 4; ++i) - { - if (mSolPegs[i] != NULL) - { - RemovePeg(mSolPegs[i]); - mSolPegs[i] = NULL; - } - } - ResetRows(); - SetState(STATE_RUNNING); - - mCurRow = NULL; - NextRow(); -} - -void MainWindow::NewGameSlot() -{ - if (mGameState == STATE_RUNNING && mCurRow != NULL) - { - int r = QMessageBox::warning( this, - tr("New Game"), - tr("Do you want to give in\nand start a new Game?"), - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); - if (r == QMessageBox::Yes) - { - NewGame(); - } - } - else - { - NewGame(); - } -} - -void MainWindow::GiveInSlot() -{ - int r = QMessageBox::Yes; - if (mGameState == STATE_RUNNING && mCurRow != NULL) - { - r = QMessageBox::warning( this, - tr("Give In"), - tr("Do you really want to give in?"), - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); - } - - if (r == QMessageBox::Yes) - { - SetState(STATE_GAVE_UP); - - if (mCurRow != NULL) - { - mCurRow->CloseRow(); - mHintBtns[mCurRow->GetIx()]->SetActive(false); - } - - ResolveGame(); - } -} -/* -void MainWindow::AboutSlot() -{ - QMessageBox::about( this, - tr("About"), - tr("ColorCode
A needful game to train your brain ;-)

Version: 0.0.1
Author: Dirk Laebisch")); -} -*/ -void MainWindow::AboutSlot() -{ - About ab(this); - ab.exec(); -} - -void MainWindow::AboutQtSlot() -{ - QMessageBox::aboutQt( this, - tr("About Qt")); -} - -void MainWindow::SetSolution() -{ - static bool firstrun = true; - - if (firstrun) - { - firstrun = false; - QTime midnight(0, 0, 0); - qsrand(midnight.secsTo(QTime::currentTime())); - } - - mSolution.clear(); - int i, rndm; - int check[mColorCnt]; - for (i = 0; i < mColorCnt; ++i) - { - check[i] = 0; - } - - for (i = 0; i < POS_CNT; ++i) - { - rndm = qrand() % mColorCnt; - if (!SameColorAction->isChecked() && check[rndm] != 0) - { - --i; - continue; - } - mSolution.push_back(rndm); - check[rndm] = 1; - if (mSolPegs[i] != NULL) - { - RemovePeg(mSolPegs[i]); - mSolPegs[i] = NULL; - } - } - mSolRow->update(mSolRow->boundingRect()); -} - -void MainWindow::ShowSolution() -{ - ColorPeg* peg; - for (int i = 0; i < POS_CNT; ++i) - { - peg = CreatePeg(mSolution.at(i)); - peg->setPos(i * 40 + 80, 62); - peg->SetBtn(false); - peg->SetEnabled(false); - mSolPegs[i] = peg; - } -} - -void MainWindow::ResetRows() -{ - for (int i = 0; i < ROW_CNT; ++i) - { - mPegRows[i]->Reset(); - mHintBtns[i]->Reset(); - } -} - -void MainWindow::FillTypesMap() -{ - int ix; - - QRadialGradient grad = QRadialGradient(20, 20, 40, 5, 5); - QRadialGradient grad2 = QRadialGradient(18, 18, 18, 12, 12); - - ix = 0; - mTypesMap[ix] = new PegType; - grad.setColorAt(0.0, QColor("#FFFF80")); - grad.setColorAt(1.0, QColor("#C05800")); - mTypesMap[ix]->grad = grad; - mTypesMap[ix]->ix = ix; - mTypesMap[ix]->pencolor = Qt::green; - - - ix = 1; - mTypesMap[ix] = new PegType; - grad.setColorAt(0.0, QColor("#FF3300")); - grad.setColorAt(1.0, QColor("#400040")); - mTypesMap[ix]->grad = grad; - mTypesMap[ix]->ix = ix; - mTypesMap[ix]->pencolor = Qt::green; - - ix = 2; - mTypesMap[ix] = new PegType; - grad.setColorAt(0.0, QColor("#33CCFF")); - grad.setColorAt(1.0, QColor("#000080")); - mTypesMap[ix]->grad = grad; - mTypesMap[ix]->ix = ix; - mTypesMap[ix]->pencolor = Qt::red; - - ix = 3; - mTypesMap[ix] = new PegType; - grad2.setColorAt(0.0, Qt::white); - grad2.setColorAt(0.5, QColor("#f8f8f0")); - grad2.setColorAt(0.7, QColor("#f0f0f0")); - //grad2.setColorAt(0.85, QColor("#d8dEFF")); - grad2.setColorAt(1.0, QColor("#d0d0d0")); - mTypesMap[ix]->grad = grad2; - mTypesMap[ix]->ix = ix; - mTypesMap[ix]->pencolor = Qt::green; - - ix = 4; - mTypesMap[ix] = new PegType; - grad.setColorAt(0.0, QColor("#808080")); - grad.setColorAt(1.0, Qt::black); - mTypesMap[ix]->grad = grad; - mTypesMap[ix]->ix = ix; - mTypesMap[ix]->pencolor = Qt::red; - - ix = 5; - mTypesMap[ix] = new PegType; - grad.setColorAt(0.0, QColor("#66FF33")); - grad.setColorAt(1.0, QColor("#385009")); - mTypesMap[ix]->grad = grad; - mTypesMap[ix]->ix = ix; - mTypesMap[ix]->pencolor = Qt::red; - - ix = 6; - mTypesMap[ix] = new PegType; - grad.setColorAt(0.0, QColor("#FF9900")); - grad.setColorAt(1.0, QColor("#A82A00")); - mTypesMap[ix]->grad = grad; - mTypesMap[ix]->ix = ix; - mTypesMap[ix]->pencolor = Qt::red; - - ix = 7; - mTypesMap[ix] = new PegType; - grad.setColorAt(0.0, QColor("#BA88FF")); - grad.setColorAt(1.0, QColor("#38005D")); - mTypesMap[ix]->grad = grad; - mTypesMap[ix]->ix = ix; - mTypesMap[ix]->pencolor = Qt::green; - - ix = 8; - mTypesMap[ix] = new PegType; - grad.setColorAt(0.0, QColor("#00FFFF")); - grad.setColorAt(1.0, QColor("#004040")); - mTypesMap[ix]->grad = grad; - mTypesMap[ix]->ix = ix; - mTypesMap[ix]->pencolor = Qt::green; - - ix = 9; - mTypesMap[ix] = new PegType; - grad.setColorAt(0.0, QColor("#FFC0FF")); - grad.setColorAt(1.0, QColor("#800080")); - mTypesMap[ix]->grad = grad; - mTypesMap[ix]->ix = ix; - mTypesMap[ix]->pencolor = Qt::green; -} - -void MainWindow::InitActions() -{ - NewGameAction = new QAction(tr("&New Game"), this); - NewGameAction->setIcon(QIcon(":/img/document-new.png")); - NewGameAction->setShortcut(tr("Ctrl+N")); - connect(NewGameAction, SIGNAL(triggered()), this, SLOT(NewGameSlot())); - - RestartGameAction = new QAction(tr("&Restart Game"), this); - RestartGameAction->setIcon(QIcon(":/img/view-refresh.png")); - RestartGameAction->setShortcut(tr("Ctrl+Shift+R")); - connect(RestartGameAction, SIGNAL(triggered()), this, SLOT(RestartGameSlot())); - - GiveInAction = new QAction(tr("&Throw In The Towel"), this); - GiveInAction->setIcon(QIcon(":/img/face-sad.png")); - GiveInAction->setShortcut(tr("Ctrl+G")); - connect(GiveInAction, SIGNAL(triggered()), this, SLOT(GiveInSlot())); - - ExitAction = new QAction(tr("E&xit"), this); - ExitAction->setIcon(QIcon(":/img/application-exit.png")); - ExitAction->setShortcut(tr("Ctrl+Q")); - //connect(ExitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - connect(ExitAction, SIGNAL(triggered()), this, SLOT(close())); - - ShowToolbarAction = new QAction(tr("Show Toolbar"), this); - ShowToolbarAction->setCheckable(true); - ShowToolbarAction->setChecked(true); - //ShowToolbarAction->setIcon(QIcon(":/img/configure-toolbars.png")); - ShowToolbarAction->setShortcut(tr("Ctrl+T")); - connect(ShowToolbarAction, SIGNAL(triggered()), this, SLOT(ShowToolbarSlot())); - - ShowMenubarAction = new QAction(tr("Show Menubar"), this); - ShowMenubarAction->setCheckable(true); - ShowMenubarAction->setChecked(true); - //ShowToolbarAction->setIcon(QIcon(":/img/configure-toolbars.png")); - ShowMenubarAction->setShortcut(tr("Ctrl+M")); - connect(ShowMenubarAction, SIGNAL(triggered()), this, SLOT(ShowMenubarSlot())); - - ShowStatusbarAction = new QAction(tr("Show Statusbar"), this); - ShowStatusbarAction->setCheckable(true); - ShowStatusbarAction->setChecked(true); - //ShowToolbarAction->setIcon(QIcon(":/img/configure-toolbars.png")); - ShowStatusbarAction->setShortcut(tr("Ctrl+S")); - connect(ShowStatusbarAction, SIGNAL(triggered()), this, SLOT(ShowStatusbarSlot())); - - SameColorAction = new QAction(tr("Allow Pegs of the Same Color"), this); - SameColorAction->setCheckable(true); - SameColorAction->setChecked(true); - //SameColorAction->setIcon(QIcon(":/img/configure-toolbars.png")); - SameColorAction->setShortcut(tr("Ctrl+Shift+C")); - connect(SameColorAction, SIGNAL(triggered()), this, SLOT(SameColorSlot())); - - AutoCloseAction = new QAction(tr("Close Rows when the 4th Peg is placed"), this); - AutoCloseAction->setCheckable(true); - AutoCloseAction->setChecked(false); - //AutoCloseAction->setIcon(QIcon(":/img/configure-toolbars.png")); - AutoCloseAction->setShortcut(tr("Ctrl+4")); - connect(AutoCloseAction, SIGNAL(triggered()), this, SLOT(AutoCloseSlot())); - - AboutAction = new QAction(tr("About &ColorCode"), this); - AboutAction->setIcon(QIcon(":/img/help-about.png")); - AboutAction->setShortcut(tr("Ctrl+A")); - connect(AboutAction, SIGNAL(triggered()), this, SLOT(AboutSlot())); - - AboutQtAction = new QAction(tr("About &Qt"), this); - AboutQtAction->setIcon(QIcon(":/img/qt.png")); - AboutQtAction->setShortcut(tr("Ctrl+I")); - connect(AboutQtAction, SIGNAL(triggered()), this, SLOT(AboutQtSlot())); - - RandRowAction = new QAction(tr("Fill Row by Random"), this); - RandRowAction->setIcon(QIcon(":/img/system-switch-user.png")); - RandRowAction->setShortcut(tr("Ctrl+R")); - connect(RandRowAction, SIGNAL(triggered()), this, SLOT(RandRowSlot())); - - PrevRowAction = new QAction(tr("Duplicate Previous Row"), this); - PrevRowAction->setIcon(QIcon(":/img/edit-copy.png")); - PrevRowAction->setShortcut(tr("Ctrl+D")); - connect(PrevRowAction, SIGNAL(triggered()), this, SLOT(PrevRowSlot())); - - ClearRowAction = new QAction(tr("Clear Row"), this); - ClearRowAction->setIcon(QIcon(":/img/edit-clear.png")); - ClearRowAction->setShortcut(tr("Ctrl+C")); - connect(ClearRowAction, SIGNAL(triggered()), this, SLOT(ClearRowSlot())); - - mActLevelEasy = new QAction(tr("Easy - 6 Colors"), this); - mActLevelEasy->setData(int(LEVEL_EASY)); - mActLevelEasy->setCheckable(true); - mActLevelEasy->setChecked(false); - connect(mActLevelEasy, SIGNAL(triggered()), this, SLOT(ForceLevelSlot())); - - mActLevelMedium = new QAction(tr("Medium - 8 Colors"), this); - mActLevelMedium->setData(int(LEVEL_MEDIUM)); - mActLevelMedium->setCheckable(true); - mActLevelMedium->setChecked(true); - //mActLevelMedium->setEnabled(false); - connect(mActLevelMedium, SIGNAL(triggered()), this, SLOT(ForceLevelSlot())); - - mActLevelHard = new QAction(tr("Hard - 10 Colors"), this); - mActLevelHard->setData(int(LEVEL_HARD)); - mActLevelHard->setCheckable(true); - mActLevelHard->setChecked(false); - connect(mActLevelHard, SIGNAL(triggered()), this, SLOT(ForceLevelSlot())); -} - -void MainWindow::InitMenus() -{ - GameMenu = menuBar()->addMenu(tr("&Game")); - GameMenu->addAction(NewGameAction); - GameMenu->addAction(RestartGameAction); - GameMenu->addAction(GiveInAction); - GameMenu->addSeparator(); - GameMenu->addAction(ExitAction); - - RowMenu = menuBar()->addMenu(tr("&Row")); - RowMenu->addAction(RandRowAction); - RowMenu->addAction(PrevRowAction); - RowMenu->addAction(ClearRowAction); - connect(RowMenu, SIGNAL(aboutToShow()), this, SLOT(UpdateRowMenuSlot())); - - SettingsMenu = menuBar()->addMenu(tr("&Settings")); - SettingsMenu->addAction(ShowMenubarAction); - SettingsMenu->addAction(ShowToolbarAction); - SettingsMenu->addAction(ShowStatusbarAction); - SettingsMenu->addSeparator(); - - LevelMenu = SettingsMenu->addMenu(tr("Level")); - LevelMenu->addAction(mActLevelEasy); - LevelMenu->addAction(mActLevelMedium); - LevelMenu->addAction(mActLevelHard); - mLevelActions = new QActionGroup(LevelMenu); - mActLevelEasy->setActionGroup(mLevelActions); - mActLevelMedium->setActionGroup(mLevelActions); - mActLevelHard->setActionGroup(mLevelActions); - - SettingsMenu->addSeparator(); - SettingsMenu->addAction(SameColorAction); - SettingsMenu->addAction(AutoCloseAction); - - HelpMenu = menuBar()->addMenu(tr("&Help")); - HelpMenu->addAction(AboutAction); - HelpMenu->addAction(AboutQtAction); - - RowContextMenu = new QMenu(); - RowContextMenu->addAction(RandRowAction); - RowContextMenu->addAction(PrevRowAction); - RowContextMenu->addAction(ClearRowAction); - RowContextMenu->addSeparator(); - RowContextMenu->addAction(NewGameAction); - RowContextMenu->addAction(RestartGameAction); - RowContextMenu->addAction(GiveInAction); - RowContextMenu->addSeparator(); - RowContextMenu->addAction(ExitAction); - - addActions(menuBar()->actions()); -} - -void MainWindow::TestSlot() -{ -} - -void MainWindow::InitToolBars() -{ - mGameToolbar = addToolBar(tr("Game")); - mGameToolbar->setAllowedAreas(Qt::NoToolBarArea); - mGameToolbar->setFloatable(false); - mGameToolbar->setIconSize(QSize(16, 16)); - mGameToolbar->addAction(NewGameAction); - mGameToolbar->addAction(RestartGameAction); - mGameToolbar->addAction(GiveInAction); - mGameToolbar->addSeparator(); - mGameToolbar->addAction(AboutAction); - - mLevelCmb = new QComboBox(); - mLevelCmb->setLayoutDirection(Qt::LeftToRight); - mLevelCmb->setFixedWidth(132); - mLevelCmb->addItem(tr("Easy - 6 Colors"), int(LEVEL_EASY)); - mLevelCmb->addItem(tr("Medium - 8 Colors"), int(LEVEL_MEDIUM)); - mLevelCmb->addItem(tr("Hard - 10 Colors"), int(LEVEL_HARD)); - mLevelCmb->setCurrentIndex(1); - connect(mLevelCmb, SIGNAL(currentIndexChanged(int)), this, SLOT(LevelChangedSlot())); - - mLevelToolbar = addToolBar(tr("Level")); - mLevelToolbar->setAllowedAreas(Qt::NoToolBarArea); - mLevelToolbar->setFloatable(false); - mLevelToolbar->setIconSize(QSize(16, 16)); - mLevelToolbar->setLayoutDirection(Qt::RightToLeft); - mLevelToolbar->addWidget(mLevelCmb); -} - -void MainWindow::ShowToolbarSlot() -{ - if (!ShowToolbarAction->isChecked()) - { - mGameToolbar->hide(); - mLevelToolbar->hide(); - } - else - { - mGameToolbar->show(); - mLevelToolbar->show(); - } - Scale(); -} - -void MainWindow::ShowMenubarSlot() -{ - if (!ShowMenubarAction->isChecked()) - { - menuBar()->hide(); - } - else - { - menuBar()->show(); - } - Scale(); -} - -void MainWindow::ShowStatusbarSlot() -{ - if (!ShowStatusbarAction->isChecked()) - { - statusBar()->hide(); - } - else - { - statusBar()->show(); - } - Scale(); -} - -void MainWindow::SameColorSlot() -{ - int r = QMessageBox::Yes; - if (mGameState == STATE_RUNNING && mCurRow != NULL) - { - r = QMessageBox::question( this, - tr("Message"), - tr("The changed settings will only apply to new games!\nDo you want to give in the current and start a new Game?"), - QMessageBox::Yes | QMessageBox::No, - QMessageBox::Yes); - } - - if (r == QMessageBox::Yes) - { - NewGame(); - } -} - -void MainWindow::AutoCloseSlot() -{ - -} - -void MainWindow::LevelChangedSlot() -{ - int ix = mLevelCmb->itemData(mLevelCmb->currentIndex(), IdRole).toInt(); - if (mLevelActions->checkedAction()->data().toInt() != ix) - { - QList list = LevelMenu->actions(); - for (int i = 0; i < list.size(); ++i) - { - if (list.at(i)->data().toInt() == ix) - { - list.at(i)->setChecked(true); - break; - } - } - } - - int r = QMessageBox::Yes; - if (mGameState == STATE_RUNNING && mCurRow != NULL) - { - r = QMessageBox::question( this, - tr("Message"), - tr("The changed settings will only apply to new games!\nDo you want to give in the current and start a new Game?"), - QMessageBox::Yes | QMessageBox::No, - QMessageBox::Yes); - } - - if (r == QMessageBox::Yes) - { - NewGame(); - } -} - -void MainWindow::ForceLevelSlot() -{ - int i = mLevelActions->checkedAction()->data().toInt(); - - int ix = mLevelCmb->findData(i); - - if (ix != -1 && mLevelCmb->currentIndex() != ix) - { - mLevelCmb->setCurrentIndex(ix); - } -} - -void MainWindow::SetLevel() -{ - int ix = mLevelCmb->itemData(mLevelCmb->currentIndex(), IdRole).toInt(); - ix = max(0, min(2, ix)); - Level lv = Level(ix); - - if (mLevel == lv) - { - return; - } - - mLevel = lv; - mColorCnt = LEVEL_COLOR_CNTS[int(mLevel)]; - - int xpos = 260; - int ystart = 120 + (MAX_COLOR_CNT - mColorCnt) * 40; - int ypos; - int i; - - for (i = 0; i < MAX_COLOR_CNT; ++i) - { - ypos = ystart + i * 40; - mBtnPos[i] = QPoint(xpos, ypos); - - if (i < mColorCnt) - { - if (mPegBtns[i] == NULL) - { - mPegBtns[i] = CreatePeg(i); - } - mPegBtns[i]->setPos(mBtnPos[i]); - mPegBtns[i]->setVisible(true); - } - else if (mPegBtns[i] != NULL) - { - mPegBtns[i]->setVisible(false); - } - } -} - -void MainWindow::InitSolution() -{ - mSolRow = new PegRow(); - mSolRow->setPos(78, 60); - mSolRow->SetActive(false); - scene->addItem(mSolRow); - - for (int i = 0; i < POS_CNT; ++i) - { - mSolPegs[i] = NULL; - } -} - -void MainWindow::InitRows() -{ - - PegRow* row; - RowHint* hint; - - int xpos = 78; - int ypos = 120; - int i; - - for (i = 0; i < ROW_CNT; ++i) - { - row = new PegRow(); - row->SetIx(i); - row->setPos(QPoint(xpos, ypos + (ROW_CNT - (i + 1)) * 40)); - row->setZValue(++MainWindow::mMaxZ); - row->SetActive(false); - scene->addItem(row); - mPegRows[i] = row; - connect(row, SIGNAL(RemovePegSignal(ColorPeg*)), this, SLOT(RemovePegSlot(ColorPeg*))); - connect(row, SIGNAL(RowSolutionSignal(int)), this, SLOT(RowSolutionSlot(int))); - - hint = new RowHint; - hint->SetIx(i); - hint->setPos(QPoint(20, ypos + (ROW_CNT - (i + 1)) * 40)); - hint->setZValue(++MainWindow::mMaxZ); - hint->SetActive(false); - scene->addItem(hint); - mHintBtns[i] = hint; - connect(hint, SIGNAL(HintPressedSignal(int)), this, SLOT(HintPressedSlot(int))); - } -} - -void MainWindow::InitPegBtns() -{ - for (int i = 0; i < MAX_COLOR_CNT; ++i) - { - mPegBtns[i] = NULL; - } -} - -ColorPeg* MainWindow::CreatePeg(int ix) -{ - if (ix < 0 || ix >= mColorCnt) - { - ix = MainWindow::mMaxZ % mColorCnt; - } - - PegType *pt = mTypesMap[ix]; - ColorPeg *peg; - - if (mPegBuff.empty()) - { - peg = new ColorPeg; - peg->SetPegType(pt); - peg->SetBtn(true); - peg->SetId(MainWindow::mMaxZ); - scene->addItem(peg); - peg->setPos(mBtnPos[ix]); - peg->setZValue(MainWindow::mMaxZ); - scene->clearSelection(); - scene->update(mBtnPos[ix].x(), mBtnPos[ix].y(), 38, 38); - peg->setSelected(true); - - connect(peg, SIGNAL(PegPressSignal(ColorPeg *)), this, SLOT(PegPressSlot(ColorPeg *))); - connect(peg, SIGNAL(PegReleasedSignal(ColorPeg *)), this, SLOT(PegReleasedSlot(ColorPeg *))); - } - else - { - unsigned int sz = mPegBuff.size(); - peg = mPegBuff.at(sz - 1); - mPegBuff.resize(sz - 1); - - peg->setVisible(true); - - peg->SetPegType(pt); - peg->SetBtn(true); - peg->SetEnabled(true); - //peg->SetId(MainWindow::mMaxZ); - peg->setPos(mBtnPos[ix]); - //peg->setZValue(MainWindow::mMaxZ); - scene->clearSelection(); - scene->update(mBtnPos[ix].x(), mBtnPos[ix].y(), 38, 38); - peg->setSelected(true); - } - - - - ++MainWindow::mMaxZ; - - return peg; -} - -void MainWindow::RemovePeg(ColorPeg* cp) -{ - if (cp != NULL) - { - cp->Reset(); - cp->setVisible(false); - mPegBuff.push_back(cp); - } -} - -void MainWindow::RemovePegSlot(ColorPeg* cp) -{ - RemovePeg(cp); -} - -void MainWindow::ShowMsgSlot(QString msg) -{ - statusBar()->showMessage(msg); - mMsg->ShowMsg(msg); -} - -void MainWindow::PegPressSlot(ColorPeg* cp) -{ - if (cp == NULL) { return; } - if (cp->IsBtn()) - { - cp->SetBtn(false); - mPegBtns[cp->GetPegType()->ix] = CreatePeg(cp->GetPegType()->ix); - } - else - { - } - cp->setZValue(++MainWindow::mMaxZ); -} - -void MainWindow::PegReleasedSlot(ColorPeg* cp) -{ - if (cp == NULL || !cp) { return; } - - bool snapped = false; - QList list = scene->items(QPointF(cp->pos().x() + 18, cp->pos().y() + 18)); - int i = 0; - for (i = 0; i < list.size(); ++i) - { - if (mCurRow != NULL && list.at(i) == mCurRow) - { - snapped = mCurRow->SnapCP(cp); - break; - } - } - - if (!snapped) - { - RemovePeg(cp); - } - -} - -void MainWindow::RowSolutionSlot(int ix) -{ - std::vector s = mPegRows[ix]->GetSolution(); - if (s.size() == 4) - { - if (AutoCloseAction->isChecked()) - { - HintPressedSlot(ix); - } - else - { - mHintBtns[ix]->SetActive(true); - ShowMsgSlot(tr("Press the Hint Field if You're done.")); - } - } - else - { - mHintBtns[ix]->SetActive(false); - ShowMsgSlot(tr("Place Your pegs ...")); - } - -} - -void MainWindow::HintPressedSlot(int) -{ - mCurRow->CloseRow(); - ResolveRow(); - NextRow(); - ResolveGame(); -} - -void MainWindow::RandRowSlot() -{ - if (mCurRow == NULL || mGameState != STATE_RUNNING) - { - return; - } - - mCurRow->ClearRow(); - - int i, rndm; - int check[mColorCnt]; - ColorPeg* peg; - for (i = 0; i < mColorCnt; ++i) - { - check[i] = 0; - } - - for (i = 0; i < POS_CNT; ++i) - { - rndm = qrand() % mColorCnt; - if (!SameColorAction->isChecked() && check[rndm] != 0) - { - --i; - continue; - } - - check[rndm] = 1; - - peg = CreatePeg(rndm); - mCurRow->ForceSnap(peg, i); - } -} - -void MainWindow::PrevRowSlot() -{ - if (mCurRow == NULL || mGameState != STATE_RUNNING) - { - return; - } - - if (mCurRow->GetIx() < 1) - { - return; - } - - mCurRow->ClearRow(); - - ColorPeg* peg; - std::vector prev = mPegRows[mCurRow->GetIx() - 1]->GetSolution(); - int i; - for (i = 0; i < POS_CNT; ++i) - { - peg = CreatePeg(prev.at(i)); - mCurRow->ForceSnap(peg, i); - } -} - -void MainWindow::ClearRowSlot() -{ - if (mCurRow == NULL || mGameState != STATE_RUNNING) - { - return; - } - - mCurRow->ClearRow(); -} - -void MainWindow::ResolveRow() -{ - std::vector res; - std::vector left1; - std::vector left0; - std::vector rowsol = mCurRow->GetSolution(); - int i, p0, p1; - for (i = 0; i < POS_CNT; ++i) - { - p0 = rowsol.at(i); - p1 = mSolution.at(i); - if (p0 == p1) - { - res.push_back(2); - } - else - { - left0.push_back(p0); - left1.push_back(p1); - } - } - - if (res.size() == (unsigned) POS_CNT) - { - SetState(STATE_WON); - } - else - { - int len0 = left0.size(); - for (i = 0; i < len0; ++i) - { - p0 = left0.at(i); - for (unsigned j = 0; j < left1.size(); ++j) - { - p1 = left1.at(j); - if (p0 == p1) - { - res.push_back(1); - left1.erase(left1.begin() + j); - break; - } - } - } - } - mHintBtns[mCurRow->GetIx()]->DrawHints(res); -} - -void MainWindow::NextRow() -{ - if (mGameState != STATE_RUNNING) - { - return; - } - - if (mCurRow == NULL) - { - mCurRow = mPegRows[0]; - } - else if (mCurRow->GetIx() < ROW_CNT - 1) - { - mCurRow = mPegRows[mCurRow->GetIx() + 1]; - } - else - { - mCurRow = NULL; - SetState(STATE_LOST); - } - - if (mCurRow != NULL) - { - mCurRow->SetActive(true); - ShowMsgSlot(tr("Place Your pegs ...")); - } -} - -void MainWindow::ResolveGame() -{ - switch (mGameState) - { - case STATE_WON: - ShowMsgSlot(tr("Congratulation! You have won!")); - break; - case STATE_LOST: - ShowMsgSlot(tr("Sorry! You lost!")); - break; - case STATE_GAVE_UP: - ShowMsgSlot(tr("Sure, You're too weak for me!")); - break; - case STATE_RUNNING: - default: - return; - break; - } - - ShowSolution(); -} - -void MainWindow::SetState(const int s) -{ - if (mGameState == s) - { - return; - } - - mGameState = s; - - bool running = mGameState == STATE_RUNNING; - - RestartGameAction->setEnabled(running); - GiveInAction->setEnabled(running); -} diff --git a/plugins/ColorCode_plugin/msg.cpp b/plugins/ColorCode_plugin/msg.cpp index 82f846845..52007f704 100644 --- a/plugins/ColorCode_plugin/msg.cpp +++ b/plugins/ColorCode_plugin/msg.cpp @@ -1,3 +1,21 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #include #include "msg.h" @@ -6,21 +24,7 @@ using namespace std; Msg::Msg() { - /* - setFont(QFont("Arial", 14, QFont::Bold, false)); - setDefaultTextColor(QColor("#cccccc")); - setTextWidth(300); - - mTd = new QTextDocument(); - mTd->setDefaultFont(QFont("Arial", 14, QFont::Bold, false)); - mTd->setTextWidth(300); - - - //QAbstractTextDocumentLayout* lay = mTd->documentLayout(); - - setDocument(mTd); - */ - mFont = QFont("Arial", 14, QFont::Bold, false); + mFont = QFont("Arial", 12, QFont::Bold, false); mFont.setStyleHint(QFont::SansSerif); mLay = new QTextLayout(); mLay->setFont(mFont); @@ -34,13 +38,10 @@ Msg::~Msg() void Msg::ShowMsg(const QString str) { - //setPlainText(str); - //mTd->clear(); - //mTd->setPlainText(str); mUpdateRect = boundingRect(); mLay->setText(str); - int leading = -3;//fontMetrics.leading(); + int leading = -3; qreal h = 10; qreal maxw = 0; qreal maxh = 0; @@ -62,7 +63,6 @@ void Msg::ShowMsg(const QString str) } mLay->endLayout(); - maxw = qMax(mUpdateRect.width(), mLay->boundingRect().width()); maxh = qMax(mUpdateRect.height(), mLay->boundingRect().height() + 8); mUpdateRect = QRectF(0, 0, maxw, maxh); @@ -77,7 +77,7 @@ QRectF Msg::boundingRect() const void Msg::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /* widget */) { - //painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(QColor("#f0f0f0"))); + painter->setRenderHint(QPainter::TextAntialiasing, true); + painter->setPen(QPen(QColor("#303133"))); mLay->draw(painter, QPoint(0, 0)); } diff --git a/plugins/ColorCode_plugin/msg.h b/plugins/ColorCode_plugin/msg.h index b3271168c..c4d013c87 100644 --- a/plugins/ColorCode_plugin/msg.h +++ b/plugins/ColorCode_plugin/msg.h @@ -1,3 +1,21 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #ifndef MSG_H #define MSG_H @@ -19,10 +37,6 @@ public: void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); private: - /* - QTextDocument* mTd; - QTextBlock mTb; - */ QTextLayout* mLay; QFont mFont; QRectF mUpdateRect; diff --git a/plugins/ColorCode_plugin/pegrow.cpp b/plugins/ColorCode_plugin/pegrow.cpp index d3dc55f34..ab721a3a2 100644 --- a/plugins/ColorCode_plugin/pegrow.cpp +++ b/plugins/ColorCode_plugin/pegrow.cpp @@ -1,3 +1,21 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #include #include "colorpeg.h" @@ -9,32 +27,41 @@ using namespace std; PegRow::PegRow(QObject*) { mIx = -1; + mPegCnt = 0; + mXOffs = 0; + mPend = QColor("#646568"); + mPenl = QColor("#ecedef"); + mGrad0 = QColor("#cccdcf"); + mGrad1 = QColor("#fcfdff"); - //setFlags(QGraphicsItem::GraphicsItemFlags(0)); + mColorPegs = NULL; - mPen = QPen(QColor("#808080")); - - for (int i = 0; i < 4; ++i) - { - mColorPegs[i] = NULL; - } - - Reset(); + Reset(0); } PegRow::~PegRow() { + for (int i = 0; i < mPegCnt; ++i) + { + delete mColorPegs[i]; + } + delete [] mColorPegs; + mColorPegs = NULL; } -void PegRow::Reset() +void PegRow::Reset(const int pegcnt) { ClearRow(); SetActive(false); + mSolved = false; + SetPegCnt(pegcnt); } void PegRow::ClearRow() { - for (int i = 0; i < 4; ++i) + if (mColorPegs == NULL) { return; }; + + for (int i = 0; i < mPegCnt; ++i) { if (mColorPegs[i] != NULL) { @@ -53,11 +80,32 @@ void PegRow::SetIx(const int ix) mIx = ix; } +void PegRow::SetPegCnt(const int pegcnt) +{ + ClearRow(); + for (int i = 0; i < mPegCnt; ++i) + { + delete mColorPegs[i]; + } + delete [] mColorPegs; + mColorPegs = NULL; + + mPegCnt = pegcnt; + mColorPegs = new ColorPeg* [mPegCnt]; + for (int i = 0; i < mPegCnt; ++i) + { + mColorPegs[i] = NULL; + } + mXOffs = 100 - mPegCnt * 20; +} + int PegRow::GetPegCnt() { + if (mColorPegs == NULL) { return 0; }; + int cnt = 0; int i = 0; - for (i = 0; i < 4; ++i) + for (i = 0; i < mPegCnt; ++i) { if (mColorPegs[i] != NULL) { @@ -75,19 +123,15 @@ ColorPeg** PegRow::GetPegs() void PegRow::SetActive(const bool b) { mIsActive = b; - if (b) - { - setOpacity(1.0); - } - else - { - setOpacity(0.5); - } update(boundingRect()); } bool PegRow::SnapCP(ColorPeg *cp) { + if (mColorPegs == NULL) + { + return false; + } bool snapped = false; if (mIsActive) @@ -102,9 +146,9 @@ bool PegRow::SnapCP(ColorPeg *cp) if (p.y() >= 0 && p.y() <= 40) { - for (i = 0; i < 4; ++i) + for (i = 0; i < mPegCnt; ++i) { - if (p.x() >= i * 40 && p.x() < (i + 1) * 40) + if (p.x() >= mXOffs + i * 40 && p.x() < mXOffs + (i + 1) * 40) { if (mColorPegs[i] != NULL) { @@ -114,7 +158,7 @@ bool PegRow::SnapCP(ColorPeg *cp) mColorPegs[i] = cp; cp->SetPegRow(this); ix = i; - cp->setPos(mapToParent(i * 40 + 2, 2)); + cp->setPos(mapToParent(mXOffs + i * 40 + 2, 2)); break; } } @@ -129,6 +173,16 @@ bool PegRow::SnapCP(ColorPeg *cp) void PegRow::ForceSnap(ColorPeg* cp, int posix) { + if (mColorPegs == NULL) + { + return; + } + + if (posix > mPegCnt - 1) + { + return; + } + if (mIsActive) { if (mColorPegs[posix] != NULL) @@ -138,7 +192,7 @@ void PegRow::ForceSnap(ColorPeg* cp, int posix) } mColorPegs[posix] = cp; cp->SetPegRow(this); - cp->setPos(mapToParent(posix * 40 + 2, 2)); + cp->setPos(mapToParent(mXOffs + posix * 40 + 2, 2)); CheckSolution(); } @@ -146,11 +200,19 @@ void PegRow::ForceSnap(ColorPeg* cp, int posix) void PegRow::CloseRow() { - for (int i = 0; i < 4; ++i) + mSolved = true; + if (mColorPegs == NULL) { - if (mColorPegs[i] != NULL) + ; + } + else + { + for (int i = 0; i < mPegCnt; ++i) { - mColorPegs[i]->SetEnabled(false); + if (mColorPegs[i] != NULL) + { + mColorPegs[i]->SetEnabled(false); + } } } SetActive(false); @@ -159,13 +221,15 @@ void PegRow::CloseRow() void PegRow::CheckSolution() { mSolution.clear(); + if (mColorPegs == NULL) + { + ; + } - for (int i = 0; i < 4; ++i) + for (int i = 0; i < mPegCnt; ++i) { if (mColorPegs[i] != NULL) { - //mColorPegs[i]->setEnabled(false); - //mColorPegs[i]->setFlags(QGraphicsItem::GraphicsItemFlags(0)); mSolution.push_back(mColorPegs[i]->GetPegType()->ix); } } @@ -180,7 +244,12 @@ std::vector PegRow::GetSolution() const void PegRow::RemovePeg(ColorPeg *cp) { - for (int i = 0; i < 4; ++i) + if (mColorPegs == NULL) + { + return; + } + + for (int i = 0; i < mPegCnt; ++i) { if (mColorPegs[i] == cp) { @@ -213,26 +282,52 @@ QRectF PegRow::boundingRect() const QRectF PegRow::outlineRect() const { - return QRectF(0.0, 0.0, 160.0, 40.0); + return QRectF(0.0, 0.0, 200.0, 40.0); } -void PegRow::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* /* widget */) +void PegRow::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* /* widget */) { - mPen.setWidth(2); - if (option->state & QStyle::State_Selected) + if (mPegCnt == 0) { - mPen.setStyle(Qt::DotLine); + return; } - painter->setPen(mPen); - - int i; - for (i = 0; i < 4; i++) + if (mIsActive) { - QRadialGradient grad(QPointF(i * 40 + 10, 10), 100); - grad.setColorAt(0, QColor("#cccccc")); - grad.setColorAt(1, QColor("#ffffff")); + mPend.setAlpha(0xff); + mPenl.setAlpha(0xff); + mGrad0.setAlpha(0xff); + mGrad1.setAlpha(0xff); + } + else if (mSolved) + { + mPend.setAlpha(0xa0); + mPenl.setAlpha(0xa0); + mGrad0.setAlpha(0xa0); + mGrad1.setAlpha(0xa0); + } + else + { + mPend.setAlpha(0x32); + mPenl.setAlpha(0x50); + mGrad0.setAlpha(0x32); + mGrad1.setAlpha(0x32); + } + painter->setPen(Qt::NoPen); + int i; + for (i = 0; i < mPegCnt; i++) + { + painter->setBrush(QBrush(mPenl)); + painter->drawRect(QRectF(mXOffs + i * 40, 0.0, 39, 1)); + painter->drawRect(QRectF(mXOffs + i * 40, 0.0, 1, 39)); + painter->setBrush(QBrush(mPend)); + painter->drawRect(QRectF(mXOffs + i * 40, 39.0, 40, 1)); + painter->drawRect(QRectF(mXOffs + i * 40 + 39, 0.0, 1, 40)); + + QRadialGradient grad(QPointF(mXOffs + i * 40 + 10, 10), 100); + grad.setColorAt(0, mGrad0); + grad.setColorAt(1, mGrad1); painter->setBrush(QBrush(grad)); - painter->drawRect(QRectF(i * 40, 0.0, 40.0, 40.0)); + painter->drawRect(QRectF(mXOffs + i * 40 + 1, 1.0, 38.0, 38.0)); } } diff --git a/plugins/ColorCode_plugin/pegrow.h b/plugins/ColorCode_plugin/pegrow.h index 2e2d2e675..7b1227b84 100644 --- a/plugins/ColorCode_plugin/pegrow.h +++ b/plugins/ColorCode_plugin/pegrow.h @@ -1,3 +1,21 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #ifndef PEGROW_H #define PEGROW_H @@ -8,7 +26,7 @@ #include #include #include -#include "mainwindow.h" +#include "colorcode.h" #include "pegrow.h" #include "colorpeg.h" @@ -25,6 +43,7 @@ public: ColorPeg** GetPegs(); std::vector GetSolution() const; void SetIx(const int ix); + void SetPegCnt(const int pegcnt); void SetActive(const bool b); bool SnapCP(ColorPeg* cp); void ForceSnap(ColorPeg* cp, int posix); @@ -32,7 +51,7 @@ public: void CloseRow(); void ClearRow(); - void Reset(); + void Reset(const int pegcnt); void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); QRectF boundingRect() const; @@ -44,27 +63,23 @@ signals: protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value); - //void contextMenuEvent(QGraphicsSceneContextMenuEvent* e); - -private slots: - //void FillRandSlot(); private: std::vector mSolution; - QPen mPen; + + QColor mPend; + QColor mPenl; + QColor mGrad0; + QColor mGrad1; bool mIsActive; + bool mSolved; int mIx; + int mPegCnt; + int mXOffs; void CheckSolution(); - ColorPeg* mColorPegs[4]; + ColorPeg** mColorPegs; QRectF outlineRect() const; - /* - void InitActions(); - void InitMenus(); - QAction* FillRandAct; - QAction* ClearRowAct; - QMenu* ContextMenu; - */ }; #endif // PEGROW_H diff --git a/plugins/ColorCode_plugin/resource.qrc b/plugins/ColorCode_plugin/resource.qrc index 51a4a5e35..ccfb7d0ab 100644 --- a/plugins/ColorCode_plugin/resource.qrc +++ b/plugins/ColorCode_plugin/resource.qrc @@ -21,5 +21,10 @@ img/cc32.png img/cc64.png cc32.ico + img/business_user.png + trans_cs.qm + img/same_color_0.png + img/same_color_1.png + img/help.png diff --git a/plugins/ColorCode_plugin/rowhint.cpp b/plugins/ColorCode_plugin/rowhint.cpp index 72110cba9..ef28ba69b 100644 --- a/plugins/ColorCode_plugin/rowhint.cpp +++ b/plugins/ColorCode_plugin/rowhint.cpp @@ -1,14 +1,62 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #include #include "rowhint.h" using namespace std; +const int RowHint::mPegPos[4][5][3] = { + { + { 6, 14, 12 }, + { 22, 14, 12 }, + { 0, 0, 0 }, + { 0, 0, 0 }, + { 0, 0, 0 }, + }, + { + { 6, 6, 12 }, + { 22, 6, 12 }, + { 14, 22, 12 }, + { 0, 0, 0 }, + { 0, 0, 0 }, + }, + { + { 6, 6, 12 }, + { 22, 6, 12 }, + { 6, 22, 12 }, + { 22, 22, 12 }, + { 0, 0, 0 }, + }, + { + { 4, 4, 12 }, + { 24, 4, 12 }, + { 14, 14, 12 }, + { 4, 24, 12 }, + { 24, 24, 12 } + } + }; + RowHint::RowHint(QObject*) { - //setFlags(QGraphicsItem::GraphicsItemFlags(0)); - mIx = -1; + mPegCnt = 0; mPen = QPen(QColor("#808080")); mPen.setWidth(2); @@ -21,7 +69,7 @@ RowHint::RowHint(QObject*) grad.setColorAt(1, QColor(255, 255, 255, 51)); mBrush0 = QBrush(grad); - Reset(); + Reset(0); } RowHint::~RowHint() @@ -29,11 +77,12 @@ RowHint::~RowHint() scene()->removeItem(this); } -void RowHint::Reset() +void RowHint::Reset(const int pegcnt) { mActive = true; mHints.clear(); mSolved = false; + SetPegCnt(pegcnt); SetActive(false); } @@ -47,6 +96,11 @@ void RowHint::SetIx(const int ix) mIx = ix; } +void RowHint::SetPegCnt(const int pegcnt) +{ + mPegCnt = pegcnt; +} + void RowHint::SetActive(bool b) { if (b == mActive) @@ -60,16 +114,14 @@ void RowHint::SetActive(bool b) if (b) { setCursor(Qt::PointingHandCursor); - //setOpacity(1); setToolTip(tr("Commit Your solution")); } else { setCursor(Qt::ArrowCursor); - //setOpacity(0.2); setToolTip(QString("")); } - //scene()->update(mapRectToScene(boundingRect())); + update(boundingRect()); } @@ -77,23 +129,27 @@ void RowHint::DrawHints(std::vector res) { mHints = res; mSolved = true; - for (unsigned i = 0; i < mHints.size(); ++i) - { - } + update(boundingRect()); } void RowHint::mousePressEvent(QGraphicsSceneMouseEvent *e) { + bool disabled = false; if (mActive && !mSolved) { if (e->button() == Qt::LeftButton) { SetActive(false); emit HintPressedSignal(mIx); + disabled = true; } } - QGraphicsItem::mousePressEvent(e); + + if (!disabled) + { + QGraphicsItem::mousePressEvent(e); + } } QPainterPath RowHint::shape() const @@ -105,8 +161,8 @@ QPainterPath RowHint::shape() const QRectF RowHint::boundingRect() const { - const int Margin = 1; - return outlineRect().adjusted(-Margin, -Margin, +Margin, +Margin); + const int margin = 1; + return outlineRect().adjusted(-margin, -margin, 2 * margin, 2 * margin); } QRectF RowHint::outlineRect() const @@ -116,30 +172,73 @@ QRectF RowHint::outlineRect() const void RowHint::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /* widget */) { - painter->setPen(mPen); + if (mPegCnt == 0) + { + return; + } + + int i; + + QColor pend = QColor("#646568"); + QColor penl = QColor("#ecedef"); + QColor grad0 = QColor("#cccdcf"); + QColor grad1 = QColor("#fcfdff"); if (mActive) { - painter->setBrush(mBrush1); + pend.setAlpha(0xff); + penl.setAlpha(0xff); + grad0.setAlpha(0xff); + grad1.setAlpha(0xff); + } + else if (mSolved) + { + pend.setAlpha(0xa0); + penl.setAlpha(0xa0); + grad0.setAlpha(0xa0); + grad1.setAlpha(0xa0); } else { - painter->setBrush(mBrush0); + pend.setAlpha(0x32); + penl.setAlpha(0x50); + grad0.setAlpha(0x32); + grad1.setAlpha(0x32); } + painter->setPen(Qt::NoPen); - QPainterPath path; - path.addRect(QRectF(0.0, 0.0, 40.0, 40.0)); - for (int i = 0; i < 4; i++) + painter->setBrush(QBrush(penl)); + painter->drawRect(QRectF(0.0, 0.0, 39, 1)); + painter->drawRect(QRectF(0.0, 0.0, 1, 39)); + painter->setBrush(QBrush(pend)); + painter->drawRect(QRectF(0.0, 39.0, 40, 1)); + painter->drawRect(QRectF(39, 0.0, 1, 40)); + + QRadialGradient grad(QPointF(10, 10), 100); + grad.setColorAt(0, grad0); + grad.setColorAt(1, grad1); + painter->setBrush(QBrush(grad)); + painter->drawRect(QRectF(1, 1.0, 38.0, 38.0)); + + painter->setBrush(Qt::NoBrush); + + int posix = mPegCnt - 2; + QPointF x0; + for (i = 0; i < mPegCnt; i++) { - //painter->drawEllipse(QRect((i % 2) * 16 + 6, floor(i / 2) * 16 + 6, 12, 12)); - path.addEllipse(QRectF((i % 2) * 16 + 6, floor(i / 2) * 16 + 6, 12, 12)); + x0 = QPointF(mPegPos[posix][i][0], mPegPos[posix][i][1]); + QLinearGradient lgrad(x0, QPointF(x0.x() + 10, x0.y() + 10)); + lgrad.setColorAt(0.0, QColor(0, 0, 0, 0xa0)); + lgrad.setColorAt(1.0, QColor(0xff, 0xff, 0xff, 0xa0)); + painter->setPen(QPen(QBrush(lgrad), 0.5)); + painter->drawEllipse(QRectF(mPegPos[posix][i][0], mPegPos[posix][i][1], mPegPos[posix][i][2], mPegPos[posix][i][2])); } - //painter->drawRect(QRectF(0.0, 0.0, 40.0, 40.0)); - painter->drawPath(path); if (mSolved) { + painter->setPen(Qt::NoPen); for (unsigned i = 0; i < mHints.size(); i++) { + x0 = QPointF(mPegPos[posix][i][0], mPegPos[posix][i][1]); if (mHints.at(i) == 2) { painter->setBrush(QBrush(Qt::black)); @@ -148,7 +247,7 @@ void RowHint::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option* { painter->setBrush(QBrush(Qt::white)); } - painter->drawEllipse(QRectF((i % 2) * 16 + 6, floor(i / 2) * 16 + 6, 12, 12)); + painter->drawEllipse(QRectF(mPegPos[posix][i][0], mPegPos[posix][i][1], mPegPos[posix][i][2], mPegPos[posix][i][2])); } } } diff --git a/plugins/ColorCode_plugin/rowhint.h b/plugins/ColorCode_plugin/rowhint.h index 7a3dbdc59..d62310b00 100644 --- a/plugins/ColorCode_plugin/rowhint.h +++ b/plugins/ColorCode_plugin/rowhint.h @@ -1,3 +1,21 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + #ifndef ROWHINT_H #define ROWHINT_H @@ -7,7 +25,7 @@ #include #include #include -#include "mainwindow.h" +#include "colorcode.h" class RowHint : public QObject, public QGraphicsItem { @@ -24,9 +42,10 @@ public: int GetIx() const; void SetIx(const int ix); + void SetPegCnt(const int pegcnt); void SetActive(bool b); void DrawHints(std::vector res); - void Reset(); + void Reset(const int pegcnt); void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); QRectF boundingRect() const; @@ -39,6 +58,10 @@ protected: void mousePressEvent(QGraphicsSceneMouseEvent* e); private: + static const int mPegPos[4][5][3]; + + int mPegCnt; + QPen mPen; QBrush mBrush0; QBrush mBrush1; diff --git a/plugins/ColorCode_plugin/solrow.cpp b/plugins/ColorCode_plugin/solrow.cpp new file mode 100644 index 000000000..32c6b7c92 --- /dev/null +++ b/plugins/ColorCode_plugin/solrow.cpp @@ -0,0 +1,97 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + +#include +#include "solrow.h" + +using namespace std; + +SolRow::SolRow() +{ + setCacheMode(QGraphicsItem::DeviceCoordinateCache); + + mPegCnt = 0; + mSolved = false; + + mRect = QRectF(0.5, 0.5, 219, 39); + mRectC = QRectF(2, 2, 216, 36); + + QLinearGradient solgrad(0, 0, 0, 40); + solgrad.setColorAt(0.0, QColor("#9fa0a2")); + solgrad.setColorAt(1.0, QColor("#8c8d8f")); + mBgBrush = QBrush(solgrad); + + QLinearGradient framegrad(0, 0, 0, 40); + framegrad.setColorAt(0.0, QColor("#4e4f51")); + framegrad.setColorAt(1.0, QColor("#ebecee")); + mFramePen = QPen(QBrush(framegrad), 1); + + mFont = QFont("Arial", 22, QFont::Bold, false); + mFont.setStyleHint(QFont::SansSerif); +} + +void SolRow::SetState(const int pegcnt, const bool solved) +{ + mPegCnt = pegcnt; + mSolved = solved; + update(boundingRect()); +} + +QRectF SolRow::boundingRect() const +{ + const double margin = 0.5; + return mRect.adjusted(-margin, -margin, 2 * margin, 2 * margin); +} + +void SolRow::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget* /* widget */) +{ + if (mPegCnt == 0) + { + return; + } + + int i; + painter->setBrush(mBgBrush); + painter->setPen(mFramePen); + painter->drawRoundedRect(mRect, 20, 20); + + QPainterPath cpath; + cpath.addRoundedRect(mRectC, 19, 19); + painter->setClipPath(cpath); + + painter->setRenderHint(QPainter::TextAntialiasing, true); + + int x0 = (220 - mPegCnt * 40) / 2; + int xpos; + for (i = 0; i <= mPegCnt; ++i) + { + xpos = x0 + i * 40; + painter->setPen(Qt::NoPen); + painter->setBrush(QBrush(QColor(0x7d, 0x7e, 0x80, 0x80))); + painter->drawRect(xpos - 1, 1, 1, 38); + painter->setBrush(QBrush(QColor(0xc3, 0xc4, 0xc6, 0x80))); + painter->drawRect(xpos, 1, 1, 38); + + if (i < mPegCnt) + { + painter->setPen(QPen(QColor("#ff9933"))); + painter->setFont(mFont); + painter->drawText(QRectF(xpos + 3.0, 3.0, 34.0, 34.0), Qt::AlignCenter, QString('?')); + } + } +} diff --git a/plugins/ColorCode_plugin/solrow.h b/plugins/ColorCode_plugin/solrow.h new file mode 100644 index 000000000..a87dcf168 --- /dev/null +++ b/plugins/ColorCode_plugin/solrow.h @@ -0,0 +1,45 @@ +/* ColorCode, a free MasterMind clone with built in solver + * Copyright (C) 2009 Dirk Laebisch + * http://www.laebisch.com/ + * + * ColorCode 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. + * + * ColorCode 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 ColorCode. If not, see . +*/ + +#ifndef SOLROW_H +#define SOLROW_H + +#include +#include + +class SolRow : public QGraphicsItem +{ +public: + SolRow(); + + void SetState(const int pegcnt, const bool solved); + QRectF boundingRect() const; + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); + +private: + QRectF mRect; + QRectF mRectC; + QBrush mBgBrush; + QPen mFramePen; + QFont mFont; + + int mPegCnt; + bool mSolved; +}; + +#endif // SOLROW_H diff --git a/plugins/ColorCode_plugin/trans_cs.qm b/plugins/ColorCode_plugin/trans_cs.qm new file mode 100644 index 000000000..d85cf53cc Binary files /dev/null and b/plugins/ColorCode_plugin/trans_cs.qm differ diff --git a/plugins/ColorCode_plugin/trans_cs.ts b/plugins/ColorCode_plugin/trans_cs.ts new file mode 100644 index 000000000..9ad1a73ab --- /dev/null +++ b/plugins/ColorCode_plugin/trans_cs.ts @@ -0,0 +1,343 @@ + + + +UTF-8 + + About + + &Author + &Autor + + + icon + ikona + + + &License + &Licence + + + A needful game to train your brain ;-) + Hra pro udržení bdělosti <br>vašeho mozku ;-) + + + 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 2 of the License, or (at your option) any later version. + Tento program je svobodným. Můžete jej šířit a/nebo upravovat za podmínek GNU General Public License, jak jsou zveřejněny Free Software Foundation, buď podle verze 2 licence nebo (podle své volby) podle jakékoli pozdější verze. + + + ColorCode + ColorCode + + + About ColorCode + O ColorCode + + + <br><br>Free MasterMind clone including a built in,<br>rather intelligent solver. + <br><br>Klon Freie MasterMind s vestavěným<br>celkem schopným řešitelem. + + + Version + Verze + + + Author + Autor + + + + ColorCode + + New Game + Nová hra + + + Do you want to give in +and start a new Game? + Chcete vzdát hru +a začít novou? + + + About Qt + O Qt + + + &New Game + &Nová hra + + + Ctrl+N + + + + &Restart Game + &Začít hru znovu + + + Ctrl+R + + + + E&xit + &Ukončit + + + Ctrl+Q + + + + Ctrl+T + + + + Ctrl+C + + + + Ctrl+A + + + + About &Qt + O &Qt + + + &Game + &Hra + + + &Settings + &Nastavení + + + &Help + &Nápověda + + + Game + Hra + + + Message + Hlášení + + + The changed settings will only apply to new games! +Do you want to give in the current and start a new Game? + Změny v nastavení se projeví teprve po novém spuštění hry! +Chcete vzdát nynější hru a začít novou? + + + Place Your pegs ... + Umístěte své kameny... + + + Congratulation! You have won! + Blahopřejeme! Vyhrál jste! + + + Sorry! You lost! + Promiňte, ale nezvládl jste to! + + + Ctrl+I + + + + Give In + Vzdát + + + Do you really want to give in? + Skutečně chcete hru vzdát? + + + &Throw In The Towel + &Vhodit ručník + + + Ctrl+G + + + + Sure, You're too weak for me! + Je jasné, že jste pro mě příliš slabý! + + + Ctrl+Shift+R + + + + Ctrl+Shift+C + + + + Fill Row by Random + Naplnit řádek náhodně + + + Duplicate Previous Row + Zdvojit předchozí řádek + + + Ctrl+D + + + + Clear Row + Vyprázdnit řádek + + + &Row + &Řádek + + + ColorCode + ColorCode + + + About &ColorCode + O &ColorCode + + + Ctrl+M + + + + Ctrl+S + + + + Easy - 6 Colors + Lehká - 6 barev + + + Medium - 8 Colors + Střední - 8 barev + + + Hard - 10 Colors + Těžká - 10 barev + + + Show Toolbar + Ukázat nástrojovou lištu + + + Show Menubar + Ukázat lištu s hlavní nabídkou + + + Show Statusbar + Ukázat stavový pruh + + + Allow Pegs of the Same Color + Povolit kameny se stejnou barvou + + + Close Rows when the 4th Peg is placed + Vyhodnotit řádky po umístění čtyř kamenů + + + Level + Úroveň + + + Computer's Guess + Nechte svůj počítač hádat + + + Ctrl+H + + + + Press the Hint Field or Key Enter if You're done. + Hotovo? Potom klepněte na pole s radou. + + + Disallow Pegs of the Same Color + Zákázat kameny stejné barvy + + + Close Rows when the last Peg is placed + Vyhodnotit řádky po umístění posledního kamene + + + Ctrl+L + Ctrl+L + + + Beginner (2 Colors, 2 Slots, Doubles) + Začátečník (2 barvy, 2 místa, zdvojení) + + + Easy (4 Colors, 3 Slots, No Doubles) + Lehká (4 barvy, 3 místa, bez zdvojení) + + + Classic (6 Colors, 4 Slots, Doubles) + Klasická (6 barev, 4 místa, zdvojení) + + + Challenging (8 Colors, 4 Slots, Doubles) + Náročná (8 barev, 4 místa, zdvojení) + + + Hard (10 Colors, 5 Slots, Doubles) + Těžká (10 barev, 5 míst, zdvojení) + + + Level Presets + Přednastavení stupně obtížnosti + + + Colors + Barvy + + + Pegs of Same Color + Kameny se stejnou barvou + + + Slots + Místa + + + Yes + Ano + + + No + Ne + + + Reset Color Order + Znovu nastavit pořadí barev + + + Show Letter Indicators + Ukázat ukazatele písmen + + + Ctrl+Shift+L + Ctrl+Shift+L + + + Online &Help + &Nápověda po internetu + + + F1 + F1 + + + + RowHint + + Commit Your solution + Vyzkoušet své řešení + + + +