pax_global_header00006660000000000000000000000064124473436440014525gustar00rootroot0000000000000052 comment=bcd04a342830e6aa7bc8d3424bb8908fce544c75 yasw_0.6/000077500000000000000000000000001244734364400124375ustar00rootroot00000000000000yasw_0.6/README000066400000000000000000000016011244734364400133150ustar00rootroot00000000000000YASW ---- YASW (Yet Another Scan Wizard) is an application used to correct images taken with a camera while scanning a book. See http://http://www.diybookscanner.org/ for full information on how to scan with digital cameras. LICENSE ------- YASW is licenced under GPLv3. => See documentation/gpl.txt for details. yasw uses icons fron the Tango Theme, which are in the public domain. => See src/icons/tango-icon-theme/copyright.txt for details: The icons in this folder are taken from the Tango Icon Theme Version 0.8.90. It can be downloaded from http://tango.freedesktop.org/releases The icons in the Tango Icon Theme are released under the Public Domain, as stated by the COPYING file in the original tarball: "The icons in this repository are herefore released into the Public Domain." DOWNLOAD -------- You can download YASW from https://sourceforge.net/projects/yascanw/ yasw_0.6/changelog.txt000066400000000000000000000046531244734364400151370ustar00rootroot0000000000000020141218; YASW 0.6 - Progress dialogs for long operations - Performance optimisation (calculate only when seen on screen or exporting) & bug fixes - Removed doxygen documentation as it is not complete. I will comment in the source as much as possible, but without the doxygen format. - XML Project Files (.yasw) Closes #22 and #25 as a side effect (Loading Project messes up file order) - Scaling filter splitted in two - Fixes #19 - Checkbox "Enable Filter" works now - Fixes #27 - Changes are now only propagated when a user selects the according button, to avoid unwanted propagations. Fixes #24 - Migration to Qt5 - Progress bar when adding multiple images (Fixes #29) 20130629; YASW 0.5 - Key shortcuts - Redesign of the Scaling Filter Widget - New policies for propagating changes. I'm not 100% happy as this is quite complicated. But I have no other Idea for now... Closes #14 - Move am image between left and right column. Closes #13 - Move image selection with arrow keys. Closes #12 - Segfault when changing settings of a non existent image - Fixes #15 - QPixmap::scaled: Pixmap is a null pixmap while loading - Fixes #17 - Fixed #18 Inserted item is selected but does not apear in the filter select - Fixed #10 Margins + Positioning 20130601; YASW 0.4 - Fixed Ticket #2 (Image order not retained when project is reloaded.) - Fixed Ticket #1 (Display FileName instead of BaseName in the image list) - Fixed Ticket #3 (Propagate settings to all images for one side) - Added a background color (configurable) for the filter widgets. - Fixed Ticket #11 (Do not interleave pages in PDF Export) - Scaling filter - Improve PDF Export (a lot!) 20130525; YASW 0.3 - About dialog - open -> recent projects - change selection color for dekeystoning and cropping - move all corners (dekeystonig, cropping) when pressing "control" while draging one of the corners 20121118; YASW 0.2 - export to pdf - a lot of small fixes in handling to pages types (even/odd) - cleaning old code away (only one page type handling) - menu for adding/removing images - key "delete" deletes an image - key "pgup/pgdown" to move image - windows port (build on linux with mxe.cc) - remove add left/right in favor of one "add", wich defaults to left. 20121006; YASW 0.1 - First release - handling two page types (left/right) - Saving / Loading project Settings - Exporting project to images - Propaging page/image settings to other pages/images yasw_0.6/developpers.txt000066400000000000000000000016461244734364400155370ustar00rootroot00000000000000Implement your own filter ------------------------- In order develop your own filter, you have to create a class that inherits from BaseFilter and reimplement at least: public: (QObject * parent = 0); QString getIdentifier(); QString getName(); QMap getSettings(); void setSettings(QMap settings); protected: void compute(); This class should provide a Widget that implements the AbstractFilterWidget. The inherited methods (getWidget) from the BaseFilter don't need to be reimplemented in most cases. Each Filter should be placed somewhere appropiate under the filter folder. The name of the classes and files should beginn with the filer name as in getIdentifier(). If you create a new folder, don't forget to modifiy the INCLUDEPATH in yasw.pro. Have a look at the BaseFilter and the Rotation class (folder filter/rotation) for simple filter example. yasw_0.6/gpl.txt000066400000000000000000001045131244734364400137660ustar00rootroot00000000000000 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 . yasw_0.6/install.txt000066400000000000000000000042041244734364400146460ustar00rootroot00000000000000How to Install YASW ------------------- Currently, YASW has no install procedure. You can test YASW by compiling it and running it directly from the compilation directory. YASW is developped under Debian GNU/Linux. It is cross-compiled for windows using http://mxe.cc (see How to release for details) YASW ought to run on other Qt-Platforms. If you want to contribute to / port / compile YASW on other platforms, your help is welcome! Complile YASW ------------- Prerequisite to build YASW is the Qt5-Plateform. $ cd src $ qmake $ make Alternative: install QT Creator, open yasw.pro and click "run". Run YASW -------- After compiling YASW, just go into src and run "yasw", on linux: ./yasw How to Release -------------- ####################### # Prepare Release ####################### - edit changelog - update version in constants.h - make distclean working repository, rebuild in release, extensive test - cross-compile to windows, small test - insert images - export to pdf ####################### # Build source tarball ####################### # Tag the git repository VERSION=0.6 git tag -a yasw_${VERSION} -m "YASW version ${VERSION}" # build the tarball (note: it contains files like .gitignore...) git archive --prefix=yasw_${VERSION}/ yasw_${VERSION} | gzip > ../yasw_${VERSION}.tgz # test archive (tar xvzf, qmake, make, ./yasw, play around) # publish the tag on github: git push --tags ####################### # Build windows version (cross compile under linux) ####################### # Preparation: follow steps 1; 3; 4; 5c on http://mxe.cc/#tutorial : git clone -b stable https://github.com/mxe/mxe.git cd mxe make qtsvg export PATH=/where MXE is installed/usr/bin:$PATH # Cross-compile YASW: cd mkdir windows-build cd windows-build /where MXE is installed/usr/i686-pc-mingw32/qt5/bin/qmake ../src/yasw.pro CONFIG+=static make # build archive VERSION=0.6 mkdir yasw_${VERSION}_Windows cp release/yasw.exe yasw_${VERSION}_Windows/ cp ../README yasw_${VERSION}_Windows/ cp ../changelog.txt yasw_${VERSION}_Windows/ cp ../documentation/gpl.txt yasw_${VERSION}_Windows/ zip -r yasw_${VERSION}_Windows.zip yasw_${VERSION}_Windows/ yasw_0.6/src/000077500000000000000000000000001244734364400132265ustar00rootroot00000000000000yasw_0.6/src/.gitignore000066400000000000000000000000641244734364400152160ustar00rootroot00000000000000/yasw.pro.user /Makefile *.o moc_* qrc_* ui_* /yasw yasw_0.6/src/constants.cpp000066400000000000000000000035251244734364400157530ustar00rootroot00000000000000/* * Copyright (C) 2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "constants.h" QStringList Constants::displayUnits = QStringList() << "pixel" << "milimeter" << "inch"; QStringList Constants::dpiList = QStringList() << "150" << "300" << "600"; qreal const Constants::milimeterPerInch = 25.4; // 1 inch = 25,4 mm QStringList Constants::horizontalAlignment = QStringList() << "Left" << "Center" << "Right"; QStringList Constants::verticalAlignment = QStringList() << "Top" << "Center" << "Bottom"; QRegExp Constants::trailZero = QRegExp("0+$"); QRegExp Constants::trailDot = QRegExp("\\.$"); QString Constants::float2String(qreal n, int precision) { QString str = QString::number(n, 'f', precision); str.remove(trailZero); str.remove(trailDot); return str; } yasw_0.6/src/constants.h000066400000000000000000000032531244734364400154160ustar00rootroot00000000000000/* * Copyright (C) 2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef CONSTANTS_H #define CONSTANTS_H #include // QDebug included centraly, so that it can be commented out. #include static const char VERSION[] = "0.6"; class Constants { public: static QStringList displayUnits; static QStringList dpiList; static qreal const milimeterPerInch ; //= 25.4; static int const MIN_DPI = 10; static int const DEFAULT_DPI = 300; // Constants for Layout Filter & Widget enum horizintalAlignmentEnum {LeftHAlignment, CenterHAlignment, RightHAlignment}; enum verticalAlignmentEnum {TopVAlignment, CenterVAlignment, BottomVAlignment}; static QStringList horizontalAlignment; static QStringList verticalAlignment; static QString float2String(qreal n, int precision = 2); private: // Code optimisation: define these QRegExp once and loading a project is much faster. static QRegExp trailZero; static QRegExp trailDot; }; #endif // CONSTANTS_H yasw_0.6/src/filter/000077500000000000000000000000001244734364400145135ustar00rootroot00000000000000yasw_0.6/src/filter/abstractfilterwidget.cpp000066400000000000000000000015571244734364400214440ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "abstractfilterwidget.h" AbstractFilterWidget::AbstractFilterWidget(QWidget *parent) : QWidget(parent) { } yasw_0.6/src/filter/abstractfilterwidget.h000066400000000000000000000035421244734364400211050ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef ABSTRACTFILTERWIDGET_H #define ABSTRACTFILTERWIDGET_H #include /* An abstract class for all Filter Widgets. This abstract class describes the members a Filter Widget must have. It has to be inherited by all Filter Widgets. A Filter Widget must provide a way to setPixmap - set the input image (for displaying it) setPreview - set the output image (for previewing the result) preview - inform if the preview is active parameterChanged - inform if parameter have been changed in the widget */ class AbstractFilterWidget : public QWidget { Q_OBJECT public: AbstractFilterWidget(QWidget *parent = 0); // Sets the input pixmap virtual void setPixmap(QPixmap pixmap) = 0; // Sets the output pixmap for preview virtual void setPreview(QPixmap pixmap) = 0; // true if preview is active virtual bool preview() = 0; virtual void enableFilter(bool enable) = 0; protected: QPixmap inputPixmap; QPixmap previewPixmap; signals: void parameterChanged(); void enableFilterToggled(bool checked); void previewChecked(); }; #endif // ABSTRACTFILTERWIDGET_H yasw_0.6/src/filter/basefilter.cpp000066400000000000000000000126541244734364400173470ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "constants.h" #include "basefilter.h" /*! \class BaseFilter \brief The BaseFilter class is the model for all Filter applied on pages. It should be inherited by every Filter. The PageFilter class is functional but does nothing, and returns the pixmap unmodified. Some functions are definied as virtual in order to allow the calling class use a unique interface (all Filter can be stored as a "BaseFilter" Class). */ /*! \brief Constructs a Filter */ BaseFilter::BaseFilter(QObject * parent) : QObject(parent) { widget = new BaseFilterWidget(); filterWidget = widget; } BaseFilter::~BaseFilter() { delete widget; } /*! \brief Set input Page This function is called by the calling class to set the Pixmap to be "filtered". */ void BaseFilter::setImage(QPixmap pixmap) { inputPixmap = pixmap; emit parameterChanged(); filterWidget->setPixmap(pixmap); mustRecalculate = true; } /*! \brief Returns the transformed image @returns The transformed page, or a null Pixmap if no page is available */ QPixmap BaseFilter::getOutputImage() { refresh(); return outputPixmap; } /*! \brief Gets the widget to display the filter The returned widget must not be freed, it is handled by the class destructor. @returns The Widget for this Filter. */ AbstractFilterWidget* BaseFilter::getWidget() { return filterWidget; } /** \brief Returns a universal name for this filter. This identifier is unique for the filter. It can be used to identify the filter used (for example in configuration files) */ QString BaseFilter::getIdentifier() { return QString("BaseFilter"); } /*! \brief Retruns the name of the filter */ QString BaseFilter::getName() { return tr("Base Filer"); } void BaseFilter::inputImageChanged() { reloadInputImage = true; // This implies mustRecalculate = true in refresh(); // Tell folowing filter that my parameter changed. emit parameterChanged(); } void BaseFilter::widgetParameterChanged() { emit parameterChanged(); mustRecalculate = true; // Only refresh the output image if preview is active if (filterWidget->preview()) { refresh(); } } void BaseFilter::enableFilterToggled(bool checked) { filterEnabled = checked; emit parameterChanged(); // Only refresh the output image if preview is active mustRecalculate = true; if (filterWidget->preview()) { refresh(); } } void BaseFilter::previewChecked() { refresh(); filterWidget->setPreview(outputPixmap); } /*! \brief virtual function to get the Filter settings @returns A QMap of keys (QString) to settings (QVariant). */ QMap BaseFilter::getSettings() { /* As BaseFilter does nothing, there is nothing to save */ return QMap(); } /** \brief virtual function do set the Filter settings. If a needed setting is not available in settings, a default has to be set. */ void BaseFilter::setSettings(QMap /* settings */) { // loadingSettings = true; /* Ignore settings, as there is nothing to set */ // loadingSettings = false; } // Dummy function that create a node for filter that do not implement this virtual function void BaseFilter::settings2Dom(QDomDocument &doc, QDomElement &imageElement, QMap /* settings */) { QDomElement filterElement = doc.createElement(getIdentifier()); QDomComment commentElement = doc.createComment("Created by BaseFilter"); imageElement.appendChild(filterElement); filterElement.appendChild(commentElement); return; } QMap BaseFilter::dom2Settings(QDomElement & /* filterElement */) { /* As BaseFilter does nothing, there are no settings to transform */ return QMap(); } void BaseFilter::setPreviousFilter(BaseFilter *filter) { previousFilter = filter; /* Change of previous Filter = change of external Parameter*/ inputImageChanged(); } void BaseFilter::enableFilter(bool enable) { filterEnabled = enable; filterWidget->enableFilter(enable); } void BaseFilter::refresh() { if (loadingSettings) return; if (reloadInputImage && previousFilter) { setImage(previousFilter->getOutputImage()); reloadInputImage = false; mustRecalculate = true; } if (mustRecalculate) { outputPixmap = QPixmap::fromImage(filter(inputPixmap.toImage())); mustRecalculate = false; filterWidget->setPreview(outputPixmap); } } // Do compute the outputPixmap with the help of all available parameters. void BaseFilter::compute() { outputPixmap = QPixmap::fromImage(filter(inputPixmap.toImage())); } QImage BaseFilter::filter(QImage inputImage) { return inputImage; } yasw_0.6/src/filter/basefilter.h000066400000000000000000000056611244734364400170140ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef BASEFILTER_H #define BASEFILTER_H #include #include #include #include #include #include #include #include "basefilterwidget.h" #include class BaseFilter : public QObject { Q_OBJECT public: BaseFilter(QObject * parent = 0); ~BaseFilter(); void setImage(const QPixmap pixmap); virtual QPixmap getOutputImage(); AbstractFilterWidget* getWidget(); virtual QString getIdentifier(); virtual QString getName(); virtual QMap getSettings(); virtual void setSettings(QMap settings); virtual void settings2Dom(QDomDocument &doc, QDomElement &imageElement, QMap settings); virtual QMap dom2Settings(QDomElement &filterElement); void setPreviousFilter(BaseFilter *filter); void enableFilter(bool enable); void refresh(); public slots: /* get the information from external classes that an external parameter changed. * Next time getFilteredImage() is called, must reload the inputPixmap. */ void inputImageChanged(); /* Parameter for the Filter changed through user intercaction */ void widgetParameterChanged(); void enableFilterToggled(bool checked); void previewChecked(); signals: /* Yell that my parameter (this includes input image) changed and that one need to reload my FilteredImage */ void parameterChanged(); protected: QPixmap inputPixmap; QPixmap outputPixmap; AbstractFilterWidget *filterWidget = NULL; /* Store the information that the input image has to be reloaded before producing the output image */ bool reloadInputImage = false; /* Only recalculate when mustRecalculate == true */ bool mustRecalculate = false; /* Link to previous Filter which can delivery a new inputImage */ BaseFilter *previousFilter = NULL; // when true, do not recalculate (this is not an user interaction) bool loadingSettings = false; virtual void compute(); virtual QImage filter(QImage inputImage); bool filterEnabled = true; // default on all widgets private: BaseFilterWidget* widget; }; #endif // BASEFILTER_H yasw_0.6/src/filter/basefiltergraphicsview.cpp000066400000000000000000000042251244734364400217560ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "basefiltergraphicsview.h" #include #include #include BaseFilterGraphicsView::BaseFilterGraphicsView(QWidget *parent) : QGraphicsView(parent) { scene = new QGraphicsScene(); setScene(scene); pixmapItem = new QGraphicsPixmapItem(); scene->addItem(pixmapItem); } BaseFilterGraphicsView::~BaseFilterGraphicsView() { delete scene; // this includes all items in the scene so pixmapItem must not be explicitly deleted. } //TODO: add another possibility to zoom (buttons, ctrl+-..). void BaseFilterGraphicsView::wheelEvent(QWheelEvent *event) { if (event->modifiers().testFlag(Qt::ControlModifier)) { int numDegrees = event->delta() / 8; int numSteps = numDegrees / 15; double factor = pow(1.125, numSteps); scale(factor, factor); } // If one would want to scroll horizintaly with Shift instead of Alt (Qt Default), // else if (event->modifiers().testFlag(Qt::ShiftModifier)) // We should create a new Event with a changed modifier Qt::AltModifier // But this is Qt Default, so we stay by Qt Default (Alt+Scroll) for now. else { QGraphicsView::wheelEvent(event); } } void BaseFilterGraphicsView::setPixmap(const QPixmap pixmap) { scene->setSceneRect(pixmap.rect()); pixmapItem->setPixmap(pixmap); /* Zoom the QGraphicsView to fit the new Pixmap */ fitInView(pixmapItem, Qt::KeepAspectRatio); } yasw_0.6/src/filter/basefiltergraphicsview.h000066400000000000000000000023311244734364400214170ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef BASEFILTERGRAPHICSVIEW_H #define BASEFILTERGRAPHICSVIEW_H #include #include class BaseFilterGraphicsView : public QGraphicsView { Q_OBJECT public: BaseFilterGraphicsView(QWidget *parent); ~BaseFilterGraphicsView(); void setPixmap(const QPixmap pixmap); protected: void wheelEvent(QWheelEvent *event); QGraphicsScene *scene = NULL; QGraphicsPixmapItem *pixmapItem = NULL; }; #endif // BASEFILTERGRAPHICSVIEW_H yasw_0.6/src/filter/basefilterwidget.cpp000066400000000000000000000032211244734364400205410ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "basefilterwidget.h" #include "ui_basefilterwidget.h" BaseFilterWidget::BaseFilterWidget(QWidget *parent) : AbstractFilterWidget(parent), ui(new Ui::BaseFilterWidget) { ui->setupUi(this); } BaseFilterWidget::~BaseFilterWidget() { delete ui; } void BaseFilterWidget::changeEvent(QEvent *e) { QWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } } void BaseFilterWidget::setPixmap(QPixmap pixmap) { ui->view->setPixmap(pixmap); } void BaseFilterWidget::setPreview(QPixmap pixmap) { previewPixmap = pixmap; } bool BaseFilterWidget::preview() { return ui->preview->isChecked(); } void BaseFilterWidget::enableFilter(bool enable) { ui->enable->setChecked(enable); } void BaseFilterWidget::on_enable_toggled(bool checked) { emit enableFilterToggled(checked); } yasw_0.6/src/filter/basefilterwidget.h000066400000000000000000000025611244734364400202140ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef BASEFILTERWIDGET_H #define BASEFILTERWIDGET_H #include #include "abstractfilterwidget.h" namespace Ui { class BaseFilterWidget; } class BaseFilterWidget : public AbstractFilterWidget { Q_OBJECT public: BaseFilterWidget(QWidget *parent = 0); ~BaseFilterWidget(); void setPixmap(QPixmap pixmap); void setPreview(QPixmap pixmap); // true if preview is active bool preview(); void enableFilter(bool enable); protected: void changeEvent(QEvent *e); private slots: void on_enable_toggled(bool checked); private: Ui::BaseFilterWidget *ui; }; #endif // BASEFILTERWIDGET_H yasw_0.6/src/filter/basefilterwidget.ui000066400000000000000000000056571244734364400204130ustar00rootroot00000000000000 Copyright (C) 2012 Robert Chéramy (robert@cheramy.net) This file is part of YASW (Yet Another Scan Wizard). YASW 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. YASW 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 YASW. If not, see http://www.gnu.org/licenses/. BaseFilterWidget 0 0 400 300 Form Enable Filter true Preview Qt::Horizontal 193 20 BaseFilterGraphicsView QGraphicsView
basefiltergraphicsview.h
enable toggled(bool) view setEnabled(bool) 62 18 68 91 enable toggled(bool) preview setEnabled(bool) 86 17 161 22
yasw_0.6/src/filter/colorcorrection.cpp000066400000000000000000000142401244734364400204260ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "colorcorrection.h" #include #include ColorCorrection::ColorCorrection(QObject *parent) : BaseFilter(parent) { widget = new ColorCorrectionWidget(); filterWidget = widget; connect(widget, SIGNAL(parameterChanged()), this, SLOT(widgetParameterChanged())); if (parent) { /* Connect slots to the filtercontainer */ connect(parent, SIGNAL(backgroundColorChanged(QColor)), widget, SLOT(setBackgroundColor(QColor))); } // Connect seems only to work when applied to the inherited classes // I would have love to connect one for all in Basefilter... connect(widget, SIGNAL(enableFilterToggled(bool)), this, SLOT(enableFilterToggled(bool))); connect(widget, SIGNAL(previewChecked()), this, SLOT(previewChecked())); } QString ColorCorrection::getIdentifier() { return QString("colorcorrection"); } QString ColorCorrection::getName() { return tr("Color Correction"); } QMap ColorCorrection::getSettings() { QMap settings; QColor color; color = widget->whitePoint(); settings["whitepoint"] = color.name(); color = widget->blackPoint(); settings["blackpoint"] = color.name(); settings["enabled"] = filterEnabled; return settings; } void ColorCorrection::setSettings(QMap settings) { loadingSettings = true; QColor color; if (settings.contains("whitepoint")) color.setNamedColor(settings["whitepoint"].toString()); else color = Qt::white; widget->setWhitePoint(color); if (settings.contains("blackpoint")) color.setNamedColor(settings["blackpoint"].toString()); else color = Qt::black; widget->setBlackPoint(color); if (settings.contains("enabled")) enableFilter(settings["enabled"].toBool()); else enableFilter("true"); mustRecalculate = true; loadingSettings = false; } void ColorCorrection::settings2Dom(QDomDocument &doc, QDomElement &parent, QMap settings) { QDomElement filter = doc.createElement(getIdentifier()); parent.appendChild(filter); if (settings.contains("whitepoint")) filter.setAttribute("whitepoint", settings["whitepoint"].toString()); else filter.setAttribute("whitepoint", "#FFFFFF"); if (settings.contains("blackpoint")) filter.setAttribute("blackpoint", settings["blackpoint"].toString()); else filter.setAttribute("blackpoint", "#000000"); if (settings.contains("enabled")) filter.setAttribute("enabled", settings["enabled"].toBool()); else filter.setAttribute("enabled", true); } QMap ColorCorrection::dom2Settings(QDomElement &filterElement) { QMap settings; settings["whitepoint"] = filterElement.attribute("whitepoint", "#FFFFFF"); settings["blackpoint"] = filterElement.attribute("blackpoint", "#000000"); return settings; } /* Scales every pixel value of the image so that it matches the choosen White and Black points. * For every color (here red) whe have: * - an intensity "red" * - the red component of the white point "redWhite" * - the red component of the white point "redBlack" * - the new intensity "redNew" * So we just need to scale the range redBlack..redWhite to 0..255, points under redBlack are set to 0, points over redWhite to 255: * redNew = red * 255 / (redWhite - redBlack) - redBlack) (plus min and max) * NOTE: to optimise, we use redDelta = (redWhite - redBlack); dividing by 255 may be contra-productive * as it needs the use of real values. * * NOTE: performance improvements might be possible (use of scanline() or preview a scaled image) * NOTE: move this code to an ImageManipulation class? */ QImage ColorCorrection::filter(QImage inputImage) { if (!filterEnabled) return inputImage; QImage outputImage(inputImage.width(), inputImage.height(), QImage::Format_ARGB32_Premultiplied); int x, y; // coordinates in the image for the for() loops QRgb pixelColor; int redNew, redWhite, redBlack, redDelta; int greenNew, greenWhite, greenBlack, greenDelta; int blueNew, blueWhite, blueBlack, blueDelta; QColor whitePoint = widget->whitePoint(); QColor blackPoint = widget->blackPoint(); // Optimisation: Storing everything static in seperate values to avoid needless calls while computing. redWhite = whitePoint.red(); greenWhite = whitePoint.green(); blueWhite = whitePoint.blue(); redBlack = blackPoint.red(); greenBlack = blackPoint.green(); blueBlack = blackPoint.blue(); // as we divide through xxxDelta, it must at least be 1. redDelta = qMax(1, redWhite - redBlack); greenDelta = qMax(1, greenWhite - greenBlack); blueDelta = qMax(1, blueWhite - blueBlack); int imageWidth = inputImage.width(); int imageHeight = inputImage.height(); for (x = 0; x < imageWidth; x++) { for (y = 0; y < imageHeight; y++) { pixelColor = inputImage.pixel(x,y); redNew = qMax(0, qMin(255, qRed(pixelColor) * 255 / redDelta - redBlack)); greenNew = qMax(0, qMin(255, qGreen(pixelColor) * 255 / greenDelta - greenBlack)); blueNew = qMax(0, qMin(255, qBlue(pixelColor) * 255 / blueDelta - blueBlack)); outputImage.setPixel(x, y, qRgb(redNew, greenNew, blueNew)); } } return outputImage; } yasw_0.6/src/filter/colorcorrection.h000066400000000000000000000026121244734364400200730ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef COLORCORRECTION_H #define COLORCORRECTION_H #include "basefilter.h" #include "colorcorrectionwidget.h" class ColorCorrection : public BaseFilter { public: ColorCorrection(QObject * parent = 0); QString getIdentifier(); QString getName(); QMap getSettings(); void setSettings(QMap settings); void settings2Dom(QDomDocument &doc, QDomElement &parent, QMap settings); QMap dom2Settings(QDomElement &filterElement); protected: virtual QImage filter(QImage inputImage); private: ColorCorrectionWidget *widget; }; #endif // COLORCORRECTION_H yasw_0.6/src/filter/colorcorrectiongraphicsscene.cpp000066400000000000000000000027251244734364400231720ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "colorcorrectiongraphicsscene.h" #include ColorCorrectionGraphicsScene::ColorCorrectionGraphicsScene(QObject *parent) : QGraphicsScene(parent) { privPixmapItem = new QGraphicsPixmapItem(); } ColorCorrectionGraphicsScene::~ColorCorrectionGraphicsScene() { delete privPixmapItem; } QGraphicsPixmapItem *ColorCorrectionGraphicsScene::pixmapItem() { return privPixmapItem; } void ColorCorrectionGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { QPoint position = event->scenePos().toPoint(); QImage image = privPixmapItem->pixmap().toImage(); if (image.valid(position)) { // The click was isued on the image emit pixmapClicked(QColor(image.pixel(position))); } } yasw_0.6/src/filter/colorcorrectiongraphicsscene.h000066400000000000000000000025471244734364400226410ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef COLORCORRECTIONGRAPHICSSCENE_H #define COLORCORRECTIONGRAPHICSSCENE_H #include #include #include #include class ColorCorrectionGraphicsScene : public QGraphicsScene { Q_OBJECT public: ColorCorrectionGraphicsScene(QObject *parent = 0); ~ColorCorrectionGraphicsScene(); QGraphicsPixmapItem *pixmapItem(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); signals: void pixmapClicked(QColor color); private: QGraphicsPixmapItem *privPixmapItem = NULL; }; #endif // COLORCORRECTIONGRAPHICSSCENE_H yasw_0.6/src/filter/colorcorrectiongraphicsview.cpp000066400000000000000000000041521244734364400230430ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "colorcorrectiongraphicsview.h" #include #include #include ColorCorrectionGraphicsView::ColorCorrectionGraphicsView(QWidget *parent) : QGraphicsView(parent) { scene = new ColorCorrectionGraphicsScene(); setScene(scene); pixmapItem = scene->pixmapItem(); scene->addItem(pixmapItem); // forward the signal connect (scene, SIGNAL(pixmapClicked(QColor)), this, SLOT(colorFromScene(QColor))); } ColorCorrectionGraphicsView::~ColorCorrectionGraphicsView() { delete scene; } // FIXME: I would have prefered to inheritate this method from BaseFilterGraphicsView... void ColorCorrectionGraphicsView::wheelEvent(QWheelEvent *event) { if (event->modifiers().testFlag(Qt::ControlModifier)) { int numDegrees = event->delta() / 8; int numSteps = numDegrees / 15; double factor = pow(1.125, numSteps); scale(factor, factor); } else { QGraphicsView::wheelEvent(event); } } // Must reimplement as scene is another Class. void ColorCorrectionGraphicsView::setPixmap(const QPixmap pixmap) { scene->setSceneRect(pixmap.rect()); pixmapItem->setPixmap(pixmap); /* Zoom the QGraphicsView to fit the new Pixmap */ fitInView(pixmapItem, Qt::KeepAspectRatio); } void ColorCorrectionGraphicsView::colorFromScene(QColor color) { emit pixmapClicked(color); } yasw_0.6/src/filter/colorcorrectiongraphicsview.h000066400000000000000000000027221244734364400225110ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef COLORCORRECTIONGRAPHICSVIEW_H #define COLORCORRECTIONGRAPHICSVIEW_H #include "colorcorrectiongraphicsscene.h" #include #include #include class ColorCorrectionGraphicsView : public QGraphicsView { Q_OBJECT public: ColorCorrectionGraphicsView(QWidget *parent = 0); ~ColorCorrectionGraphicsView(); void setPixmap(const QPixmap pixmap); public slots: void colorFromScene(QColor color); signals: void pixmapClicked(QColor color); protected: void wheelEvent(QWheelEvent *event); // QGraphicsScene *scene = NULL; ColorCorrectionGraphicsScene *scene = NULL; QGraphicsPixmapItem *pixmapItem = NULL; }; #endif // COLORCORRECTIONGRAPHICSVIEW_H yasw_0.6/src/filter/colorcorrectionwidget.cpp000066400000000000000000000111711244734364400216320ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "colorcorrectionwidget.h" #include "ui_colorcorrectionwidget.h" #include #include ColorCorrectionWidget::ColorCorrectionWidget(QWidget *parent) : AbstractFilterWidget(parent), ui(new Ui::ColorCorrectionWidget) { ui->setupUi(this); connect(ui->view, SIGNAL(pixmapClicked(QColor)), this, SLOT(imageClicked(QColor))); } ColorCorrectionWidget::~ColorCorrectionWidget() { delete ui; delete intValidator; } void ColorCorrectionWidget::setPixmap(QPixmap pixmap) { inputPixmap = pixmap; if (!preview()) { ui->view->setPixmap(pixmap); } } void ColorCorrectionWidget::setPreview(QPixmap pixmap) { previewPixmap = pixmap; if (preview()) ui->view->setPixmap(pixmap); } bool ColorCorrectionWidget::preview() { return ui->preview->isChecked(); } QColor ColorCorrectionWidget::whitePoint() { return whitepoint; } QColor ColorCorrectionWidget::blackPoint() { return blackpoint; } void ColorCorrectionWidget::on_whiteReset_clicked() { setWhitePoint(QColor("white")); } void ColorCorrectionWidget::on_blackReset_clicked() { setBlackPoint(QColor("black")); } void ColorCorrectionWidget::setWhitePoint(QColor white) { whitepoint = white; QString whiteName = whitepoint.name(); ui->whitepoint->setText(whiteName); ui->whitepoint->setStyleSheet("background-color: " + whiteName + ";"); emit parameterChanged(); } void ColorCorrectionWidget::setBlackPoint(QColor black) { blackpoint = black; QString blackName = blackpoint.name(); ui->blackpoint->setText(blackName); ui->blackpoint->setStyleSheet("background-color: " + blackName + "; color: rgb(255, 255, 255);"); emit parameterChanged(); } void ColorCorrectionWidget::enableFilter(bool enable) { ui->enable->setChecked(enable); } void ColorCorrectionWidget::on_preview_toggled(bool checked) { if (checked) { // This does recalculate the output image if necessary and sets the preview Image. emit previewChecked(); } else { ui->view->setPixmap(inputPixmap); } } void ColorCorrectionWidget::imageClicked(QColor color) { if (setWhitePointClicked) { setWhitePoint(color); } if (setBlackPointClicked) { setBlackPoint(color); } } void ColorCorrectionWidget::setBackgroundColor(QColor color) { ui->view->setBackgroundBrush(QBrush(color)); } //// While Setting a point, the text of the button changes. //void ColorCorrectionWidget::on_whiteSetPoint_clicked() //{ // if (setWhitePointClicked) { // ui->whiteSetPoint->setText(tr("Set")); // setWhitePointClicked = false; // } else { // ui->whiteSetPoint->setText(tr("Done")); // setWhitePointClicked = true; // } // // deaktivate setting black point if necessery // if (setBlackPointClicked) { // ui->blackSetPoint->setText(tr("Set")); // setBlackPointClicked = false; // } //} //void ColorCorrectionWidget::on_blackSetPoint_clicked() //{ // if (setBlackPointClicked) { // ui->blackSetPoint->setText(tr("Set")); // setBlackPointClicked = false; // } else { // ui->blackSetPoint->setText(tr("Done")); // setBlackPointClicked = true; // } // // deaktivate setting black point if necessery // if (setWhitePointClicked) { // ui->whiteSetPoint->setText(tr("Set")); // setWhitePointClicked = false; // } //} void ColorCorrectionWidget::on_enable_toggled(bool checked) { emit enableFilterToggled(checked); } void ColorCorrectionWidget::on_whitepoint_clicked() { QColor color = QColorDialog::getColor(whitepoint, this, tr("Choose whitepoint")); if (color.isValid()) { setWhitePoint(color); } } void ColorCorrectionWidget::on_blackpoint_clicked() { QColor color = QColorDialog::getColor(blackpoint, this, tr("Choose blackpoint")); if (color.isValid()) { setBlackPoint(color); } } yasw_0.6/src/filter/colorcorrectionwidget.h000066400000000000000000000040071244734364400212770ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef COLORCORRECTIONWIDGET_H #define COLORCORRECTIONWIDGET_H #include #include #include #include "abstractfilterwidget.h" namespace Ui { class ColorCorrectionWidget; } class ColorCorrectionWidget : public AbstractFilterWidget { Q_OBJECT public: explicit ColorCorrectionWidget(QWidget *parent = 0); ~ColorCorrectionWidget(); void setPixmap(QPixmap pixmap); void setPreview(QPixmap pixmap); bool preview(); QColor whitePoint(); QColor blackPoint(); void setWhitePoint(QColor white); void setBlackPoint(QColor black); void enableFilter(bool enable); public slots: void on_whiteReset_clicked(); void on_blackReset_clicked(); void on_preview_toggled(bool checked); void imageClicked(QColor color); void setBackgroundColor(QColor color); private slots: // void on_whiteSetPoint_clicked(); // void on_blackSetPoint_clicked(); void on_enable_toggled(bool checked); void on_whitepoint_clicked(); void on_blackpoint_clicked(); private: Ui::ColorCorrectionWidget *ui; QIntValidator *intValidator = NULL; bool setWhitePointClicked = false; bool setBlackPointClicked = false; QColor whitepoint; QColor blackpoint; }; #endif // COLORCORRECTIONWIDGET_H yasw_0.6/src/filter/colorcorrectionwidget.ui000066400000000000000000000137711244734364400214750ustar00rootroot00000000000000 Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) This file is part of YASW (Yet Another Scan Wizard). YASW 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. YASW 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 YASW. If not, see http://www.gnu.org/licenses/. ColorCorrectionWidget 0 0 569 450 Form Enable Filter true Preview false Qt::Horizontal 330 20 1 0 1 0 0 0 White balance 100 0 100 16777215 White point background-color: rgb(255, 255, 255); #FFFFFF Pick 100 0 100 16777215 Black point background-color: rgb(0, 0, 0); color: rgb(255, 255, 255); #000000 Pick Qt::Vertical 20 302 ColorCorrectionGraphicsView QGraphicsView
colorcorrectiongraphicsview.h
BaseFilterGraphicsView QGraphicsView
basefiltergraphicsview.h
yasw_0.6/src/filter/cropping/000077500000000000000000000000001244734364400163345ustar00rootroot00000000000000yasw_0.6/src/filter/cropping/cropping.cpp000066400000000000000000000110041244734364400206550ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "cropping.h" Cropping::Cropping(QObject *parent) { widget = new CroppingWidget(); filterWidget = widget; connect(widget, SIGNAL(parameterChanged()), this, SLOT(widgetParameterChanged())); if (parent) { /* Connect slots to the filtercontainer */ connect(parent, SIGNAL(selectionColorChanged(QColor)), widget, SLOT(setSelectionColor(QColor))); connect(parent, SIGNAL(backgroundColorChanged(QColor)), widget, SLOT(setBackgroundColor(QColor))); } // Connect seems only to work when applied to the inherited classes // I would have love to connect one for all in Basefilter... connect(widget, SIGNAL(enableFilterToggled(bool)), this, SLOT(enableFilterToggled(bool))); connect(widget, SIGNAL(previewChecked()), this, SLOT(previewChecked())); } QImage Cropping::filter(QImage inputImage) { if (filterEnabled) { QRect rectangle = widget->rectangle(); return inputImage.copy(rectangle); } else { return inputImage; } } /** \brief Returns a universal name for this filter. This identifier is unique for the filter. It can be used to identify the filter used (for example in configuration files) */ QString Cropping::getIdentifier() { return QString("Cropping"); } /** \brief Returns the localised name of this Filter */ QString Cropping::getName() { return tr("Cropping"); } /** \brief Gets the settings from this filter */ QMap Cropping::getSettings() { QMap settings = widget->getSettings(); settings["enabled"] = filterEnabled; return settings; } /** \brief set this filter's settings **/ void Cropping::setSettings(QMap settings) { loadingSettings = true; widget->setSettings(settings); if (settings.contains("enabled")) enableFilter(settings["enabled"].toBool()); else enableFilter("true"); mustRecalculate = true; loadingSettings = false; emit parameterChanged(); } void Cropping::settings2Dom(QDomDocument &doc, QDomElement &imageElement, QMap settings) { QDomElement filter = doc.createElement(getIdentifier()); imageElement.appendChild(filter); QDomElement pointElement; QPointF point; QString corner; QStringList cornerNames; int i; // Iterate through cornerNames to save all Positions cornerNames << "bottomRightCorner" << "topLeftCorner"; for (i = 0; i < cornerNames.size(); i++) { corner = cornerNames.at(i); if (settings.contains(corner)) { pointElement = doc.createElement(corner); point = settings[corner].toPoint(); pointElement.setAttribute("x", point.x()); pointElement.setAttribute("y", point.y()); filter.appendChild(pointElement); } } if (settings.contains("enabled")) filter.setAttribute("enabled", settings["enabled"].toBool()); else filter.setAttribute("enabled", true); } QMap Cropping::dom2Settings(QDomElement &filterElement) { QMap settings; QStringList cornerNames; QString corner; int i; QDomElement cornerElement; // Iterate through cornerNames to save all Positions cornerNames << "bottomRightCorner" << "topLeftCorner"; for (i = 0; i < cornerNames.size(); i++) { corner = cornerNames.at(i); cornerElement = filterElement.firstChildElement(corner); if (!cornerElement.isNull()) { settings[corner] = QPointF(cornerElement.attribute("x").toDouble(), cornerElement.attribute("y").toDouble()); } } settings["enabled"] = filterElement.attribute("enabled", "1").toInt(); return settings; } yasw_0.6/src/filter/cropping/cropping.h000066400000000000000000000025531244734364400203330ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef CROPPING_H #define CROPPING_H #include "basefilter.h" #include "croppingwidget.h" class Cropping : public BaseFilter { Q_OBJECT public: Cropping(QObject * parent = 0); QString getIdentifier(); QString getName(); QMap getSettings(); void setSettings(QMap settings); void settings2Dom(QDomDocument &doc, QDomElement &imageElement, QMap settings); QMap dom2Settings(QDomElement &filterElement); protected: virtual QImage filter(QImage inputImage); private: CroppingWidget *widget; }; #endif // CROPPING_H yasw_0.6/src/filter/cropping/croppingcorner.cpp000066400000000000000000000052521244734364400220760ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "croppingcorner.h" #include /*! \class CroppingCorner \brief corner of the cropping rectangle A cropping rectangle is defined by its top left and bottom right corner. When they move, the Rectangle coordinates and size have to be changed. */ /*! \brief Creates a Corner for the rectangle The corner is a circle (diameter 8 pixel) that can be moved to modify the rectangle. It ignores Transformation of the GraphicsView so that it has allways the same size while zooming. */ CroppingCorner::CroppingCorner(QPoint position) { setRect(-diameter/2, -diameter/2, diameter, diameter); setPos(position); lastPosition = pos(); setZValue(100); setFlags(ItemIsMovable | ItemIgnoresTransformations | ItemSendsGeometryChanges); } bool CroppingCorner::getCornerMoved() { return cornerMoved; } void CroppingCorner::resetCornerMoved() { cornerMoved = false; } QVariant CroppingCorner::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionHasChanged) { Qt::KeyboardModifiers keyMod = QApplication::keyboardModifiers (); if (keyMod.testFlag(Qt::ControlModifier)) { QPointF positionDelta = pos() - lastPosition; emit moveOtherCorner(positionDelta); } cornerMoved = true; emit signalCornerMoved(); lastPosition = pos(); // tell the filter widget that a parameter changed } return QGraphicsEllipseItem::itemChange(change, value); } void CroppingCorner::moveCorner(QPointF delta) { /* deativate change notifications */ setFlag(ItemSendsGeometryChanges, false); /* move the Corner */ setPos(pos() + delta); /* Update cornerMoved, lastPosition and rectangle */ cornerMoved = true; emit signalCornerMoved(); lastPosition = pos(); /* reactivate change notifications */ setFlag(ItemSendsGeometryChanges, true); } yasw_0.6/src/filter/cropping/croppingcorner.h000066400000000000000000000036311244734364400215420ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef CROPPINGCORNER_H #define CROPPINGCORNER_H #include #include enum CornerType { TopLeftCorner, BottomRightCorner }; /*! Inherits QObject to be able to emit signals */ class CroppingCorner : public QObject, public QGraphicsEllipseItem { Q_OBJECT public: CroppingCorner(QPoint position); bool getCornerMoved(); void resetCornerMoved(); protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value); private: QRect *rectangle; bool cornerMoved; const int diameter = 8; QPointF lastPosition; signals: /** \brief signal emited when a corner was moved. This signal is connected to the parent class CroppingGraphicsView::moveRectangle() */ void signalCornerMoved(); /** \brief signal emited when a corner was moved and other corner have to change their position. This signal is connected to the slot DekeystoningCorner::moveCorner() of the three other coners. The connection is handeld in the constructor of DekeystoningGraphicsView. */ void moveOtherCorner(QPointF delta); public slots: void moveCorner(QPointF delta); }; #endif // CROPPINGCORNER_H yasw_0.6/src/filter/cropping/croppinggraphicsview.cpp000066400000000000000000000100261244734364400232740ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "croppinggraphicsview.h" CroppingGraphicsView::CroppingGraphicsView(QWidget *parent) : BaseFilterGraphicsView(parent) { topLeftCorner = new CroppingCorner(defaultTopLeft); //, TopLeftCorner, &rectangle); scene->addItem(topLeftCorner); bottomRightCorner = new CroppingCorner(defaultBottomRight); //, BottomRightCorner, &rectangle); scene->addItem(bottomRightCorner); rectangle = new QGraphicsRectItem(); scene->addItem(rectangle); connect(topLeftCorner, SIGNAL(signalCornerMoved()), this, SLOT(moveRectangle())); connect(bottomRightCorner, SIGNAL(signalCornerMoved()), this, SLOT(moveRectangle())); moveRectangle(); /* connect the corners together so they can move each other when Control is pressed */ connect(topLeftCorner, SIGNAL(moveOtherCorner(QPointF)), bottomRightCorner, SLOT(moveCorner(QPointF))); connect(bottomRightCorner, SIGNAL(moveOtherCorner(QPointF)), topLeftCorner, SLOT(moveCorner(QPointF))); } CroppingGraphicsView::~CroppingGraphicsView() { delete topLeftCorner; delete bottomRightCorner; delete rectangle; } QRect CroppingGraphicsView::getRectangle() { return QRect(topLeftCorner->scenePos().toPoint(), bottomRightCorner->scenePos().toPoint()); } void CroppingGraphicsView::resetRectangleMoved() { topLeftCorner->resetCornerMoved(); bottomRightCorner->resetCornerMoved(); } bool CroppingGraphicsView::rectangleMoved() { return topLeftCorner->getCornerMoved() || bottomRightCorner->getCornerMoved(); } void CroppingGraphicsView::hideRectangle(bool hide) { bool showRectangle = !hide; topLeftCorner->setVisible(showRectangle); bottomRightCorner->setVisible(showRectangle); rectangle->setVisible(showRectangle); } void CroppingGraphicsView::moveRectangle() { qreal width = bottomRightCorner->x()-topLeftCorner->x(); qreal heigth = bottomRightCorner->y()-topLeftCorner->y(); rectangle->setRect(0, 0, width, heigth); rectangle->setPos(topLeftCorner->scenePos()); // tell the filter widget that a parameter changed emit parameterChanged(); } /** \brief Get the filter settings (gets the polygon coordinates) */ QMap CroppingGraphicsView::getSettings() { QMap settings; settings["bottomRightCorner"] = bottomRightCorner->pos(); settings["topLeftCorner"] = topLeftCorner->pos(); return settings; } /** \brief sets the filter settings (change polygon coordinates) If the settings are not present, sets default values */ void CroppingGraphicsView::setSettings(QMap settings) { if (settings.contains("bottomRightCorner") && settings["bottomRightCorner"].canConvert(QVariant::PointF)) { bottomRightCorner->setPos(settings["bottomRightCorner"].toPointF()); } else { bottomRightCorner->setPos(defaultBottomRight); } if (settings.contains("topLeftCorner") && settings["topLeftCorner"].canConvert(QVariant::PointF)) { topLeftCorner->setPos(settings["topLeftCorner"].toPointF()); } else { topLeftCorner->setPos(defaultTopLeft); } } void CroppingGraphicsView::setSelectionColor(QColor color) { QPen pen = QPen(color); topLeftCorner->setPen(pen); bottomRightCorner->setPen(pen); rectangle->setPen(pen); } yasw_0.6/src/filter/cropping/croppinggraphicsview.h000066400000000000000000000032041244734364400227410ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef CROPPINGGRAPHICSVIEW_H #define CROPPINGGRAPHICSVIEW_H #include #include "basefiltergraphicsview.h" #include "croppingcorner.h" class CroppingGraphicsView : public BaseFilterGraphicsView { Q_OBJECT public: CroppingGraphicsView(QWidget *parent); ~CroppingGraphicsView(); QRect getRectangle(); bool rectangleMoved(); void resetRectangleMoved(); QMap getSettings(); void setSettings(QMap settings); void setSelectionColor(QColor color); public slots: void hideRectangle(bool hide); void moveRectangle(); private: CroppingCorner *topLeftCorner; CroppingCorner *bottomRightCorner; QGraphicsRectItem *rectangle; const QPoint defaultTopLeft = QPoint(100, 100); const QPoint defaultBottomRight = QPoint(500, 500); signals: void parameterChanged(); }; #endif // CROPPINGGRAPHICSVIEW_H yasw_0.6/src/filter/cropping/croppingwidget.cpp000066400000000000000000000044111244734364400220650ustar00rootroot00000000000000#include "croppingwidget.h" #include "ui_croppingwidget.h" CroppingWidget::CroppingWidget(QWidget *parent) : AbstractFilterWidget(parent), ui(new Ui::CroppingWidget) { ui->setupUi(this); connect(ui->view, SIGNAL(parameterChanged()), this, SLOT(gvParameterChanged())); } CroppingWidget::~CroppingWidget() { delete ui; } void CroppingWidget::on_preview_toggled(bool checked) { if (checked) { ui->view->resetRectangleMoved(); // This does recalculate the output image if necessary and sets the preview Image. emit previewChecked(); } else { ui->view->setPixmap(inputPixmap); } } void CroppingWidget::setPixmap(QPixmap pixmap) { inputPixmap = pixmap; if (!preview()) ui->view->setPixmap(pixmap); } void CroppingWidget::setPreview(QPixmap pixmap) { previewPixmap = pixmap; if (preview()) ui->view->setPixmap(pixmap); } bool CroppingWidget::preview() { return ui->preview->isChecked(); } QRect CroppingWidget::rectangle() { return ui->view->getRectangle(); } /** \brief Get the filter settings NOTE: Currently does only save the polygon coordinates; one may want to save activated and preview. */ QMap CroppingWidget::getSettings() { return ui->view->getSettings(); } /** \brief sets the filter settings (change polygon coordinates) If the settings are not present, sets default values NOTE: Currently does only save the polygon coordinates; one may want to load activated and preview settings (if present). */ void CroppingWidget::setSettings(QMap settings) { ui->view->setSettings(settings); } void CroppingWidget::enableFilter(bool enable) { ui->enable->setChecked(enable); } /** \brief Sets new Selection Color This does only forward the information, as this widget ist the only one able to call members functions of ui->view. */ void CroppingWidget::setSelectionColor(QColor color) { ui->view->setSelectionColor(color); } void CroppingWidget::setBackgroundColor(QColor color) { ui->view->setBackgroundBrush(QBrush(color)); } void CroppingWidget::gvParameterChanged() { emit parameterChanged(); } void CroppingWidget::on_enable_toggled(bool checked) { emit enableFilterToggled(checked); } yasw_0.6/src/filter/cropping/croppingwidget.h000066400000000000000000000015721244734364400215370ustar00rootroot00000000000000#ifndef CROPPINGWIDGET_H #define CROPPINGWIDGET_H #include "abstractfilterwidget.h" namespace Ui { class CroppingWidget; } class CroppingWidget : public AbstractFilterWidget { Q_OBJECT public: explicit CroppingWidget(QWidget *parent = 0); ~CroppingWidget(); void setPixmap(QPixmap pixmap); void setPreview(QPixmap pixmap); bool preview(); QRect rectangle(); bool rectangleMoved(); void resetRectangleMoved(); QMap getSettings(); void setSettings(QMap settings); void enableFilter(bool enable); public slots: void setSelectionColor(QColor color); void setBackgroundColor(QColor color); void gvParameterChanged(); private: Ui::CroppingWidget *ui; private slots: void on_preview_toggled(bool checked); void on_enable_toggled(bool checked); }; #endif // CROPPINGWIDGET_H yasw_0.6/src/filter/cropping/croppingwidget.ui000066400000000000000000000052411244734364400217220ustar00rootroot00000000000000 Copyright (C) 2012 Robert Chéramy (robert@cheramy.net>) This file is part of YASW (Yet Another Scan Wizard). YASW 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. YASW 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 YASW. If not, see http://www.gnu.org/licenses/. CroppingWidget 0 0 371 323 Form Enable Filter true Preview Qt::Horizontal 164 20 CroppingGraphicsView QGraphicsView
croppinggraphicsview.h
hideRectangle(bool)
preview toggled(bool) view hideRectangle(bool) 139 23 134 85
yasw_0.6/src/filter/dekeystoning/000077500000000000000000000000001244734364400172165ustar00rootroot00000000000000yasw_0.6/src/filter/dekeystoning/dekeystoning.cpp000066400000000000000000000125371244734364400224350ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "dekeystoning.h" #include #include Dekeystoning::Dekeystoning(QObject *parent) { widget = new DekeystoningWidget(); filterWidget = widget; connect(widget, SIGNAL(parameterChanged()), this, SLOT(widgetParameterChanged())); if (parent) { /* Connect slots to the filtercontainer */ connect(parent, SIGNAL(selectionColorChanged(QColor)), widget, SLOT(setSelectionColor(QColor))); connect(parent, SIGNAL(backgroundColorChanged(QColor)), widget, SLOT(setBackgroundColor(QColor))); } // Connect seems only to work when applied to the inherited classes // I would have love to connect one for all in Basefilter... connect(widget, SIGNAL(enableFilterToggled(bool)), this, SLOT(enableFilterToggled(bool))); connect(widget, SIGNAL(previewChecked()), this, SLOT(previewChecked())); } /** \brief Returns a universal name for this filter. This identifier is unique for the filter. It can be used to identify the filter used (for example in configuration files) */ QString Dekeystoning::getIdentifier() { return QString("Dekeystoning"); } /*! \brief Retruns the localised name of the filter */ QString Dekeystoning::getName() { return tr("Dekeystoning"); } /** \brief Gets the settings from this filter */ QMap Dekeystoning::getSettings() { QMap settings = widget->getSettings(); settings["enabled"] = filterEnabled; return settings; } /** \brief set this filter's settings **/ void Dekeystoning::setSettings(QMap settings) { loadingSettings = true; widget->setSettings(settings); if (settings.contains("enabled")) enableFilter(settings["enabled"].toBool()); else enableFilter("true"); mustRecalculate = true; loadingSettings = false; emit parameterChanged(); } void Dekeystoning::settings2Dom(QDomDocument &doc, QDomElement &imageElement, QMap settings) { QDomElement filter = doc.createElement(getIdentifier()); imageElement.appendChild(filter); QDomElement pointElement; QPointF point; QString corner; QStringList cornerNames; int i; // Iterate through cornerNames to save all 4 Positions cornerNames << "topLeftCorner" << "topRightCorner" << "bottomRightCorner" << "bottomLeftCorner"; for (i = 0; i < cornerNames.size(); i++) { corner = cornerNames.at(i); if (settings.contains(corner)) { pointElement = doc.createElement(corner); point = settings[corner].toPoint(); pointElement.setAttribute("x", point.x()); pointElement.setAttribute("y", point.y()); filter.appendChild(pointElement); } } if (settings.contains("enabled")) filter.setAttribute("enabled", settings["enabled"].toBool()); else filter.setAttribute("enabled", true); } QMap Dekeystoning::dom2Settings(QDomElement &filterElement) { QMap settings; QStringList cornerNames; QString corner; int i; QDomElement cornerElement; // Iterate through cornerNames to save all 4 Positions cornerNames << "topLeftCorner" << "topRightCorner" << "bottomRightCorner" << "bottomLeftCorner"; for (i = 0; i < cornerNames.size(); i++) { corner = cornerNames.at(i); cornerElement = filterElement.firstChildElement(corner); if (!cornerElement.isNull()) { settings[corner] = QPointF(cornerElement.attribute("x").toDouble(), cornerElement.attribute("y").toDouble()); } } settings["enabled"] = filterElement.attribute("enabled", "1").toInt(); return settings; } QImage Dekeystoning::filter(QImage inputImage) { if (!filterEnabled) return inputImage; QPolygonF polygon = widget->polygon(); QTransform transformMatrix; /* it might not be possbible to calculate a treansformation matrix */ if (!QTransform::quadToSquare(polygon, transformMatrix)) { qDebug() << "No transformation exists for this"; return QImage(); } /* As transformMatrix transforms the polygon to a unit square (1px * 1px), we have * to scale it back to the size of our rectangle selection. We use the mean size of * the Rectangle as a reference. */ qreal width = widget->meanWidth(); qreal height = widget->meanHeight(); QTransform scaleMatrix = QTransform::fromScale(width, height); QTransform transformationMatrix = transformMatrix * scaleMatrix; return inputImage.transformed(transformationMatrix); } yasw_0.6/src/filter/dekeystoning/dekeystoning.h000066400000000000000000000026071244734364400220770ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef DEKEYSTONING_H #define DEKEYSTONING_H #include "basefilter.h" #include "dekeystoningwidget.h" class Dekeystoning : public BaseFilter { Q_OBJECT public: Dekeystoning(QObject * parent = 0); QString getIdentifier(); QString getName(); QMap getSettings(); void setSettings(QMap settings); void settings2Dom(QDomDocument &doc, QDomElement &imageElement, QMap settings); QMap dom2Settings(QDomElement &filterElement); protected: virtual QImage filter(QImage inputImage); private: DekeystoningWidget *widget; }; #endif // DEKEYSTONING_H yasw_0.6/src/filter/dekeystoning/dekeystoningcorner.cpp000066400000000000000000000073001244734364400236360ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "dekeystoningcorner.h" #include "dekeystoningline.h" #include #include /*! \class DekeystoningCorner \brief Corner to build a polygon The corner is a circle (diameter 8 pixel) that can be moved to modify the lines connected to it (via Line::trackCorner). All the corner together build a polygon, wich moves with it. Corner is q QGraphicsItem wich is to be used in a QGraphicsScene/View. It ignores Transformation of the GraphicsView so that it has allways the same size while zooming. */ DekeystoningCorner::DekeystoningCorner(QPoint position) { setRect(-diameter/2, -diameter/2, diameter, diameter); setPos(position); lastPosition = pos(); setZValue(100); setFlags(ItemIsMovable | ItemIgnoresTransformations | ItemSendsGeometryChanges); } /** \brief Registers a line ending at this corner. This is called from the DekeystoningLine itself */ void DekeystoningCorner::registerLine(DekeystoningLine *line) { myLines.insert(line); } /*! \brief Handle Corner moves itemChanged ist called because the Flag ItemSendsGeometryChanges is set. When called, it will update the position of the sides of the Polygon (Line) and register that the Corner moved so that the transformation Matrix and the output Pixmap has to be recalculated. */ QVariant DekeystoningCorner::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionHasChanged) { Qt::KeyboardModifiers keyMod = QApplication::keyboardModifiers (); if (keyMod.testFlag(Qt::ControlModifier)) { QPointF positionDelta = pos() - lastPosition; emit moveOtherCorner(positionDelta); } cornerMoved = true; foreach (DekeystoningLine *line, myLines) line->trackCorners(); lastPosition = pos(); // tell the filter widget that a parameter changed emit parameterChanged(); } return QGraphicsEllipseItem::itemChange(change, value); } /* \brief Move the corner withoud activating an itemChange When a corner is moved while pressing the Control key modifier, other three corner have to be moved equaly. This is done by emiting a DekeystoningCorner::signalCornerMoved() signal which is connected to this slot. The connection is handled by the constructor of DekeystoningGraphicsView */ void DekeystoningCorner::moveCorner(QPointF delta) { /* deativate change notifications */ setFlag(ItemSendsGeometryChanges, false); /* move the Corner */ setPos(pos() + delta); /* Update cornerMoved, lastPosition and lines */ cornerMoved = true; foreach (DekeystoningLine *line, myLines) line->trackCorners(); lastPosition = pos(); /* reactivate change notifications */ setFlag(ItemSendsGeometryChanges, true); } void DekeystoningCorner::resetCornerMoved() { cornerMoved = false; } bool DekeystoningCorner::getCornerMoved() { return cornerMoved; } yasw_0.6/src/filter/dekeystoning/dekeystoningcorner.h000066400000000000000000000036511244734364400233100ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef DEKEYSTONINGCORNER_H #define DEKEYSTONINGCORNER_H #include #include #include #include class DekeystoningLine; /*! Inherits QObject to be able to emit and receive signals */ class DekeystoningCorner : public QObject, public QGraphicsEllipseItem { Q_OBJECT public: DekeystoningCorner(QPoint position); void registerLine(DekeystoningLine *line); bool getCornerMoved(); void resetCornerMoved(); protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value); private: QSet myLines; bool cornerMoved; const int diameter = 8; QPointF lastPosition; public slots: void moveCorner(QPointF delta); signals: /** \brief signal emited when a corner was moved and other corner have to change their position. This signal is connected to the slot DekeystoningCorner::moveCorner() of the three other coners. The connection is handeld in the constructor of DekeystoningGraphicsView. */ void moveOtherCorner(QPointF delta); // When a corner is moved, emit a parameterChanged() signal. void parameterChanged(); }; #endif // DEKEYSTONINGCORNER_H yasw_0.6/src/filter/dekeystoning/dekeystoninggraphicsview.cpp000066400000000000000000000207241244734364400250460ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "dekeystoninggraphicsview.h" /*! \class DekeystoningGraphicsView \brief Display a polygon over an image for configuring of deykeystoning. DekeystoningGraphicsView inherits BaseFilterGraphicsView and its features (scene, zooming, setPixmap). The polygon can be hidden (to display the preview of the pixmap. */ /*! Constructs the polygon, formed of 4 corners (c1..4) and 4 lines (l1..4) and adds them to the scene. */ DekeystoningGraphicsView::DekeystoningGraphicsView(QWidget *parent): BaseFilterGraphicsView(parent) { topLeftCorner = new DekeystoningCorner(defaultTopLeft); scene->addItem(topLeftCorner); topRightCorner = new DekeystoningCorner(defaultTopRight); scene->addItem(topRightCorner); bottomRightCorner = new DekeystoningCorner(defaultBottomRight); scene->addItem(bottomRightCorner); bottomLeftCorner = new DekeystoningCorner(defaultBottomLeft); scene->addItem(bottomLeftCorner); l1 = new DekeystoningLine(topLeftCorner, topRightCorner); l2 = new DekeystoningLine(topRightCorner, bottomRightCorner); l3 = new DekeystoningLine(bottomRightCorner, bottomLeftCorner); l4 = new DekeystoningLine(bottomLeftCorner, topLeftCorner); scene->addItem(l1); scene->addItem(l2); scene->addItem(l3); scene->addItem(l4); /* connect the corners together so they can move each other when Control is pressed */ connect(topLeftCorner, SIGNAL(moveOtherCorner(QPointF)), topRightCorner, SLOT(moveCorner(QPointF))); connect(topLeftCorner, SIGNAL(moveOtherCorner(QPointF)), bottomRightCorner, SLOT(moveCorner(QPointF))); connect(topLeftCorner, SIGNAL(moveOtherCorner(QPointF)), bottomLeftCorner, SLOT(moveCorner(QPointF))); connect(topRightCorner, SIGNAL(moveOtherCorner(QPointF)), topLeftCorner, SLOT(moveCorner(QPointF))); connect(topRightCorner, SIGNAL(moveOtherCorner(QPointF)), bottomRightCorner, SLOT(moveCorner(QPointF))); connect(topRightCorner, SIGNAL(moveOtherCorner(QPointF)), bottomLeftCorner, SLOT(moveCorner(QPointF))); connect(bottomRightCorner, SIGNAL(moveOtherCorner(QPointF)), topRightCorner, SLOT(moveCorner(QPointF))); connect(bottomRightCorner, SIGNAL(moveOtherCorner(QPointF)), topLeftCorner, SLOT(moveCorner(QPointF))); connect(bottomRightCorner, SIGNAL(moveOtherCorner(QPointF)), bottomLeftCorner, SLOT(moveCorner(QPointF))); connect(bottomLeftCorner, SIGNAL(moveOtherCorner(QPointF)), topLeftCorner, SLOT(moveCorner(QPointF))); connect(bottomLeftCorner, SIGNAL(moveOtherCorner(QPointF)), bottomRightCorner, SLOT(moveCorner(QPointF))); connect(bottomLeftCorner, SIGNAL(moveOtherCorner(QPointF)), topRightCorner, SLOT(moveCorner(QPointF))); connect(topLeftCorner, SIGNAL(parameterChanged()), this, SLOT(cornerMoved())); connect(topRightCorner, SIGNAL(parameterChanged()), this, SLOT(cornerMoved())); connect(bottomRightCorner, SIGNAL(parameterChanged()), this, SLOT(cornerMoved())); connect(bottomLeftCorner, SIGNAL(parameterChanged()), this, SLOT(cornerMoved())); } /*! cleen the allocated memory */ DekeystoningGraphicsView::~DekeystoningGraphicsView() { delete topLeftCorner; delete topRightCorner; delete bottomRightCorner; delete bottomLeftCorner; delete l1; delete l2; delete l3; delete l4; } /** \brief Mean width of the transformation polygon. This is used as the width of the resulting Pixmap. */ qreal DekeystoningGraphicsView::meanWidth() { QLineF line1 = QLineF(topLeftCorner->pos(), topRightCorner->pos()); QLineF line2 = QLineF(bottomRightCorner->pos(), bottomLeftCorner->pos()); qreal width = (line1.length() + line2.length())/2; return width; } /*! \brief Mean height of the transformation polygon. This is used as the height of the resulting Pixmap. */ qreal DekeystoningGraphicsView::meanHeight() { QLineF line1 = QLineF(topRightCorner->pos(), bottomRightCorner->pos()); QLineF line2 = QLineF(topLeftCorner->pos(), bottomLeftCorner->pos()); qreal height = (line1.length() + line2.length())/2; return height; } /*! \return The polygon as drywed in the scene */ QPolygonF DekeystoningGraphicsView::polygon() { QPolygonF polygon; polygon << topLeftCorner->pos() << topRightCorner->pos() << bottomRightCorner->pos() << bottomLeftCorner->pos(); return polygon; } /*! Hides the polygon so that it does not interfere with a previewed Pixmap */ void DekeystoningGraphicsView::hidePolygon(bool hide) { bool showPolygon = !hide; topLeftCorner->setVisible(showPolygon); topRightCorner->setVisible(showPolygon); bottomRightCorner->setVisible(showPolygon); bottomLeftCorner->setVisible(showPolygon); l1->setVisible(showPolygon); l2->setVisible(showPolygon); l3->setVisible(showPolygon); l4->setVisible(showPolygon); } void DekeystoningGraphicsView::cornerMoved() { emit parameterChanged(); } /** \brief Changes the color of the corners and the line. This slot is called when changing the selectionColor preference of yasw */ void DekeystoningGraphicsView::setSelectionColor(QColor color) { QPen pen = QPen(color); topLeftCorner->setPen(pen); topRightCorner->setPen(color); bottomRightCorner->setPen(color); bottomLeftCorner->setPen(color); l1->setPen(color); l2->setPen(color); l3->setPen(color); l4->setPen(color); } /** \brief Check if polygon moved since last resetPolygonMoved() */ bool DekeystoningGraphicsView::polygonMoved() { return topLeftCorner->getCornerMoved() || topRightCorner->getCornerMoved() || bottomRightCorner->getCornerMoved() || bottomLeftCorner->getCornerMoved(); } /** \brief Resets all registered moves for the polygon, so that polygonMoved() returns false */ void DekeystoningGraphicsView::resetPolygonMoved() { topLeftCorner->resetCornerMoved(); topRightCorner->resetCornerMoved(); bottomRightCorner->resetCornerMoved(); bottomLeftCorner->resetCornerMoved(); } /** \brief Get the filter settings (gets the polygon coordinates) */ QMap DekeystoningGraphicsView::getSettings() { QMap settings; settings["topLeftCorner"] = topLeftCorner->pos(); settings["topRightCorner"] = topRightCorner->pos(); settings["bottomRightCorner"] = bottomRightCorner->pos(); settings["bottomLeftCorner"] = bottomLeftCorner->pos(); return settings; } /** \brief sets the filter settings (change polygon coordinates) If the settings are not present, sets default values */ void DekeystoningGraphicsView::setSettings(QMap settings) { if (settings.contains("topLeftCorner") && settings["topLeftCorner"].canConvert(QVariant::PointF)) { topLeftCorner->setPos(settings["topLeftCorner"].toPointF()); } else { topLeftCorner->setPos(defaultTopLeft); } if (settings.contains("topRightCorner") && settings["topRightCorner"].canConvert(QVariant::PointF)) { topRightCorner->setPos(settings["topRightCorner"].toPointF()); } else { topRightCorner->setPos(defaultTopRight); } if (settings.contains("bottomRightCorner") && settings["bottomRightCorner"].canConvert(QVariant::PointF)) { bottomRightCorner->setPos(settings["bottomRightCorner"].toPointF()); } else { bottomRightCorner->setPos(defaultBottomRight); } if (settings.contains("bottomLeftCorner") && settings["bottomLeftCorner"].canConvert(QVariant::PointF)) { bottomLeftCorner->setPos(settings["bottomLeftCorner"].toPointF()); } else { bottomLeftCorner->setPos(defaultBottomLeft); } } yasw_0.6/src/filter/dekeystoning/dekeystoninggraphicsview.h000066400000000000000000000037221244734364400245120ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef DEKEYSTONINGGRAPHICSVIEW_H #define DEKEYSTONINGGRAPHICSVIEW_H #include #include "basefiltergraphicsview.h" #include "dekeystoningcorner.h" #include "dekeystoningline.h" #include class DekeystoningGraphicsView : public BaseFilterGraphicsView { Q_OBJECT public: DekeystoningGraphicsView(QWidget *parent); ~DekeystoningGraphicsView(); qreal meanWidth(); qreal meanHeight(); QPolygonF polygon(); bool polygonMoved(); void resetPolygonMoved(); QMap getSettings(); void setSettings(QMap settings); void setSelectionColor(QColor color); public slots: void hidePolygon(bool hide); void cornerMoved(); private: DekeystoningCorner *topLeftCorner, *topRightCorner, *bottomRightCorner, *bottomLeftCorner; DekeystoningLine *l1, *l2, *l3, *l4; // predefined corner positions for default settings const QPoint defaultTopLeft = QPoint(100, 100); const QPoint defaultTopRight = QPoint(500, 100); const QPoint defaultBottomLeft = QPoint(100, 500); const QPoint defaultBottomRight = QPoint(500, 500); signals: void parameterChanged(); }; #endif // DEKEYSTONINGGRAPHICSVIEW_H yasw_0.6/src/filter/dekeystoning/dekeystoningline.cpp000066400000000000000000000025331244734364400233000ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "dekeystoningline.h" #include "dekeystoningcorner.h" /*! \class DekeystoningLine \brief Line of the quadrilateral used to define how to dekeystone The lines are updated when the corners are moved. The corners call trackCorners. */ DekeystoningLine::DekeystoningLine(DekeystoningCorner *from, DekeystoningCorner *to) { fromCorner = from; fromCorner->registerLine(this); toCorner = to; toCorner->registerLine(this); trackCorners(); } /** \brief redraw the line */ void DekeystoningLine::trackCorners() { setLine(QLineF(fromCorner->scenePos(), toCorner->scenePos())); } yasw_0.6/src/filter/dekeystoning/dekeystoningline.h000066400000000000000000000021451244734364400227440ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef DEKEYSTONINGLINE_H #define DEKEYSTONINGLINE_H #include class DekeystoningCorner; class DekeystoningLine : public QGraphicsLineItem { public: DekeystoningLine(DekeystoningCorner *fromCorner, DekeystoningCorner *toCorner); void trackCorners(); private: DekeystoningCorner *fromCorner, *toCorner; }; #endif // DEKEYSTONINGLINE_H yasw_0.6/src/filter/dekeystoning/dekeystoningwidget.cpp000066400000000000000000000071561244734364400236420ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "dekeystoningwidget.h" #include "ui_dekeystoningwidget.h" DekeystoningWidget::DekeystoningWidget(QWidget *parent) : AbstractFilterWidget(parent), ui(new Ui::DekeystoningWidget) { ui->setupUi(this); connect(ui->view, SIGNAL(parameterChanged()), this, SLOT(gvParameterChanged())); } DekeystoningWidget::~DekeystoningWidget() { delete ui; } void DekeystoningWidget::changeEvent(QEvent *e) { QWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } } void DekeystoningWidget::setPixmap(QPixmap pixmap) { inputPixmap = pixmap; if (!preview()) ui->view->setPixmap(pixmap); } void DekeystoningWidget::setPreview(QPixmap pixmap) { previewPixmap = pixmap; if (preview()) ui->view->setPixmap(pixmap); } qreal DekeystoningWidget::meanWidth() { return ui->view->meanWidth(); } qreal DekeystoningWidget::meanHeight() { return ui->view->meanHeight(); } QPolygonF DekeystoningWidget::polygon() { return ui->view->polygon(); } bool DekeystoningWidget::preview() { return ui->preview->isChecked(); } void DekeystoningWidget::on_preview_toggled(bool checked) { if (checked) { ui->view->resetPolygonMoved(); // This does recalculate the output image if necessary and sets the preview Image. emit previewChecked(); } else { ui->view->setPixmap(inputPixmap); } } bool DekeystoningWidget::polygonMoved() { return ui->view->polygonMoved(); } void DekeystoningWidget::resetPolygonMoved() { return ui->view->resetPolygonMoved(); } /** \brief Get the filter settings NOTE: Currently does only save the polygon coordinates; one may want to save activated and preview. */ QMap DekeystoningWidget::getSettings() { return ui->view->getSettings(); } /** \brief sets the filter settings (change polygon coordinates) If the settings are not present, sets default values NOTE: Currently does only save the polygon coordinates; one may want to load activated and preview settings (if present). */ void DekeystoningWidget::setSettings(QMap settings) { ui->view->setSettings(settings); } void DekeystoningWidget::enableFilter(bool enable) { ui->enable->setChecked(enable); } /** \brief Sets new Selection Color This does only forward the information, as this widget ist the only one able to call members functions of ui->view. */ void DekeystoningWidget::setSelectionColor(QColor color) { ui->view->setSelectionColor(color); } void DekeystoningWidget::setBackgroundColor(QColor color) { ui->view->setBackgroundBrush(QBrush(color)); } void DekeystoningWidget::gvParameterChanged() { emit parameterChanged(); } void DekeystoningWidget::on_enable_toggled(bool checked) { emit enableFilterToggled(checked); } yasw_0.6/src/filter/dekeystoning/dekeystoningwidget.h000066400000000000000000000033611244734364400233010ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef DEKEYSTONINGWIDGET_H #define DEKEYSTONINGWIDGET_H #include #include "abstractfilterwidget.h" namespace Ui { class DekeystoningWidget; } class DekeystoningWidget : public AbstractFilterWidget { Q_OBJECT public: DekeystoningWidget(QWidget *parent = 0); ~DekeystoningWidget(); void setPixmap(QPixmap pixmap); void setPreview(QPixmap pixmap); bool preview(); qreal meanWidth(); qreal meanHeight(); QPolygonF polygon(); bool polygonMoved(); void resetPolygonMoved(); QMap getSettings(); void setSettings(QMap settings); void enableFilter(bool enable); public slots: void setSelectionColor(QColor color); void setBackgroundColor(QColor color); void gvParameterChanged(); protected: void changeEvent(QEvent *e); private: Ui::DekeystoningWidget *ui; private slots: void on_preview_toggled(bool checked); void on_enable_toggled(bool checked); }; #endif // DEKEYSTONINGWIDGET_H yasw_0.6/src/filter/dekeystoning/dekeystoningwidget.ui000066400000000000000000000057651244734364400235010ustar00rootroot00000000000000 Copyright (C) 2012 Robert Chéramy (robert@cheramy.net) This file is part of YASW (Yet Another Scan Wizard). YASW 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. YASW 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 YASW. If not, see http://www.gnu.org/licenses/. DekeystoningWidget 0 0 537 464 Form Enable Filter true Preview Qt::Horizontal 242 20 DekeystoningGraphicsView QGraphicsView
dekeystoninggraphicsview.h
hidePolygon(bool)
enable toggled(bool) view setEnabled(bool) 73 27 113 146 preview toggled(bool) view hidePolygon(bool) 151 13 192 130
yasw_0.6/src/filter/layoutfilter.cpp000066400000000000000000000152541244734364400177510ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "layoutfilter.h" #include "constants.h" #include #include LayoutFilter::LayoutFilter(QObject * parent) : BaseFilter(parent) { widget = new LayoutWidget(); filterWidget = widget; connect(widget, SIGNAL(parameterChanged()), this, SLOT(widgetParameterChanged())); if (parent) { /* Connect slots to the filtercontainer */ connect(parent, SIGNAL(backgroundColorChanged(QColor)), widget, SLOT(setBackgroundColor(QColor))); connect(parent, SIGNAL(displayUnitChanged(QString)), this, SLOT(setDisplayUnit(QString))); connect(parent, SIGNAL(dpiChanged(int)), widget, SLOT(setDPI(int))); } // Connect seems only to work when applied to the inherited classes // I would have love to connect one for all in Basefilter... connect(widget, SIGNAL(enableFilterToggled(bool)), this, SLOT(enableFilterToggled(bool))); connect(widget, SIGNAL(previewChecked()), this, SLOT(previewChecked())); } QString LayoutFilter::getIdentifier() { return QString("LayoutFilter"); } QString LayoutFilter::getName() { return tr("Layout"); } /** \brief Gets the settings of the filter. As all the settings are maintained in the widget, this function just gets the setting from the widget and gives them back. */ QMap LayoutFilter::getSettings() { QMap settings = widget->getSettings(); settings["enabled"] = filterEnabled; return settings; } /** \brief Sets the settings for the filter. Gives the settings to the widget (were they are stored) and recalculate the produced Image. */ void LayoutFilter::setSettings(QMap settings) { loadingSettings = true; widget->setSettings(settings); if (settings.contains("enabled")) enableFilter(settings["enabled"].toBool()); else enableFilter("true"); mustRecalculate = true; loadingSettings = false; emit parameterChanged(); } void LayoutFilter::settings2Dom(QDomDocument &doc, QDomElement &parent, QMap settings) { QDomElement filter = doc.createElement(getIdentifier()); parent.appendChild(filter); QString attribute; QStringList attributeNames; int i; // Iterate through attributeNames to save all double attributeNames << "pxPageWidth" << "pxPageHeight"; for (i = 0; i < attributeNames.size(); i++) { attribute = attributeNames.at(i); if (settings.contains(attribute)) { filter.setAttribute(attribute, Constants::float2String(settings[attribute].toDouble())); } } // Iterate through attributeNames to save all strings attributeNames.clear(); attributeNames << "horizontalAlignement" << "verticalAlignement"; for (i = 0; i < attributeNames.size(); i++) { attribute = attributeNames.at(i); if (settings.contains(attribute)) { filter.setAttribute(attribute, settings[attribute].toString()); } } if (settings.contains("enabled")) filter.setAttribute("enabled", settings["enabled"].toBool()); else filter.setAttribute("enabled", true); } QMap LayoutFilter::dom2Settings(QDomElement &filterElement) { QMap settings; QString attribute; QStringList attributeNames; int i; QDomElement cornerElement; // Iterate through attributeNames to save all double attributeNames << "pxPageWidth" << "pxPageHeight"; for (i = 0; i < attributeNames.size(); i++) { attribute = attributeNames.at(i); if (filterElement.hasAttribute(attribute)) { settings[attribute] = filterElement.attribute(attribute).toDouble(); } } // Iterate through attributeNames to save all strings attributeNames << "horizontalAlignement" << "verticalAlignement"; for (i = 0; i < attributeNames.size(); i++) { attribute = attributeNames.at(i); if (filterElement.hasAttribute(attribute)) { settings[attribute] = filterElement.attribute(attribute); } } settings["enabled"] = filterElement.attribute("enabled", "1").toInt(); return settings; } void LayoutFilter::setDisplayUnit(QString unit) { widget->setDisplayUnit(unit); } QImage LayoutFilter::filter(QImage inputImage) { if (!filterEnabled) return inputImage; qreal pageWidth = widget->pagePixelWidth(); qreal pageHeight = widget->pagePixelHeight(); if (pageWidth == 0 || pageHeight == 0 || inputPixmap.isNull()) { return QImage(); } qreal imageWidth = inputImage.width(); qreal imageHeight = inputImage.height(); qreal leftMargin = 0; qreal topMargin = 0; QString horizontalAlignement = widget->horizontalAlignement(); QString verticalAlignement = widget->verticalAlignement(); // indexOf returns -1 if the alignement is unknown. In this case, margin = 0; switch (Constants::horizontalAlignment.indexOf(horizontalAlignement)) { case Constants::LeftHAlignment: leftMargin = 0; break; case Constants::CenterHAlignment: leftMargin = qMax((pageWidth - imageWidth) / 2, 0.0); break; case Constants::RightHAlignment: leftMargin = qMax(pageWidth - imageWidth, 0.0); break; } switch (Constants::verticalAlignment.indexOf(verticalAlignement)) { case Constants::TopVAlignment: topMargin = 0; break; case Constants::CenterVAlignment: topMargin = qMax((pageHeight - imageHeight) / 2, 0.0); break; case Constants::BottomVAlignment: topMargin = qMax(pageHeight - imageHeight, 0.0); break; } QImage page = QImage(pageWidth, pageHeight, QImage::Format_ARGB32_Premultiplied); //NOTE: fill color could be a parameter. I do wait for user feedback ;-) page.fill(Qt::white); QPainter painter(&page); painter.drawImage(leftMargin, topMargin, inputImage); return page; } yasw_0.6/src/filter/layoutfilter.h000066400000000000000000000026601244734364400174130ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef LAYOUTFILTER_H #define LAYOUTFILTER_H #include "basefilter.h" #include "layoutwidget.h" class LayoutFilter : public BaseFilter { Q_OBJECT public: LayoutFilter(QObject * parent = 0); QString getIdentifier(); QString getName(); QMap getSettings(); void setSettings(QMap settings); void settings2Dom(QDomDocument &doc, QDomElement &imageElement, QMap settings); QMap dom2Settings(QDomElement &filterElement); public slots: void setDisplayUnit(QString unit); protected: virtual QImage filter(QImage inputImage); private: LayoutWidget *widget; }; #endif // LAYOUTFILTER_H yasw_0.6/src/filter/layoutwidget.cpp000066400000000000000000000210721244734364400177420ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "layoutwidget.h" #include "ui_layoutwidget.h" #include "constants.h" #include #include #include LayoutWidget::LayoutWidget(QWidget *parent) : AbstractFilterWidget(parent), ui(new Ui::LayoutWidget) { ui->setupUi(this); // default value displayUnit = "pixel"; doubleValidator = new QDoubleValidator; doubleValidator->setBottom(0.001); doubleValidator->setDecimals(3); doubleValidator->setNotation(QDoubleValidator::StandardNotation); ui->pageHeight->setValidator(doubleValidator); ui->pageWidth->setValidator(doubleValidator); ui->horizontalAlignment->insertItems(0, Constants::horizontalAlignment); ui->horizontalAlignment->setCurrentIndex(Constants::horizontalAlignment.indexOf("Center")); ui->verticalAlignment->insertItems(0, Constants::verticalAlignment); ui->verticalAlignment->setCurrentIndex(Constants::verticalAlignment.indexOf("Center")); setDPI(Constants::DEFAULT_DPI); } LayoutWidget::~LayoutWidget() { delete ui; delete doubleValidator; } void LayoutWidget::setPixmap(QPixmap pixmap) { inputPixmap = pixmap; if (!pixmap.isNull() && pxPageWidth == 0 && pxPageHeight == 0) { pxPageWidth = pixmap.width(); pxPageHeight = pixmap.height(); } updateFormSizes(); if (!preview()) { ui->view->setPixmap(pixmap); } } void LayoutWidget::setPreview(QPixmap pixmap) { previewPixmap = pixmap; if (preview()) ui->view->setPixmap(pixmap); } bool LayoutWidget::preview() { return ui->preview->isChecked(); } double LayoutWidget::pagePixelHeight() { return pxPageHeight; } double LayoutWidget::pagePixelWidth() { return pxPageWidth; } QString LayoutWidget::verticalAlignement() { return ui->verticalAlignment->currentText(); } QString LayoutWidget::horizontalAlignement() { return ui->horizontalAlignment->currentText(); } QMap LayoutWidget::getSettings() { QMap settings; settings["pxPageWidth"] = pxPageWidth; settings["pxPageHeight"] = pxPageHeight; settings["verticalAlignement"] = verticalAlignement(); settings["horizontalAlignement"] = horizontalAlignement(); return settings; } void LayoutWidget::setSettings(QMap settings) { pxPageWidth = settings["pxPageWidth"].toDouble(); pxPageHeight = settings["pxPageHeight"].toDouble(); if (Constants::verticalAlignment.contains(settings["verticalAlignement"].toString())) { ui->verticalAlignment->setCurrentIndex( Constants::verticalAlignment.indexOf(settings["verticalAlignement"].toString())); } else { ui->verticalAlignment->setCurrentIndex( Constants::verticalAlignment.indexOf("Center")); } if (Constants::horizontalAlignment.contains(settings["horizontalAlignement"].toString())) { ui->horizontalAlignment->setCurrentIndex( Constants::horizontalAlignment.indexOf(settings["horizontalAlignement"].toString())); } else { ui->horizontalAlignment->setCurrentIndex( Constants::horizontalAlignment.indexOf("Center")); } // Update the Form updateFormSizes(); } void LayoutWidget::setDisplayUnit(QString unit) { switch (Constants::displayUnits.indexOf(unit)) { case 0: // pixel factorPixeltoDisplayUnit = 1; break; case 1: // millimeter factorPixeltoDisplayUnit = Constants::milimeterPerInch / dpi; break; case 2: // inches factorPixeltoDisplayUnit = 1 / dpi; break; default: // The unit provided is not valid. Do nothing. return; } displayUnit = unit; ui->lbUnitHeight->setText(unit); ui->lbUnitWidth->setText(unit); updateFormSizes(); } void LayoutWidget::enableFilter(bool enable) { ui->enable->setChecked(enable); } void LayoutWidget::setBackgroundColor(QColor color) { ui->view->setBackgroundBrush(QBrush(color)); } void LayoutWidget::on_preview_toggled(bool checked) { if (checked) { // This does recalculate the output image if necessary and sets the preview Image. emit previewChecked(); } else ui->view->setPixmap(inputPixmap); } // When a parameter is changed, the input and resulting Image Sizes are recalculated with this function. void LayoutWidget::updateFormSizes() { QString newPageWidth, newPageHeight; newPageWidth = Constants::float2String(pxPageWidth * factorPixeltoDisplayUnit); newPageHeight = Constants::float2String(pxPageHeight * factorPixeltoDisplayUnit); ui->pageWidth->setText(newPageWidth); ui->pageHeight->setText(newPageHeight); ui->pixelPageWidth->setText(Constants::float2String(pxPageWidth)); ui->pixelPageHeight->setText(Constants::float2String(pxPageHeight)); ui->inchPageWidth->setText(Constants::float2String(pxPageWidth / dpi)); ui->inchPageHeight->setText(Constants::float2String(pxPageHeight / dpi)); ui->millimeterPageWidth->setText( Constants::float2String(pxPageWidth / dpi * Constants::milimeterPerInch)); ui->millimeterPageHeight->setText( Constants::float2String(pxPageHeight / dpi * Constants::milimeterPerInch)); int inputWidth = inputPixmap.width(); int inputHeight = inputPixmap.height(); ui->pixelInputWidth->setText(Constants::float2String(inputWidth)); ui->pixelInputHeight->setText(Constants::float2String(inputHeight)); ui->inchInputWidth->setText(Constants::float2String(inputWidth / dpi)); ui->inchInputHeight->setText(Constants::float2String(inputHeight / dpi)); ui->millimeterInputWidth->setText( Constants::float2String(inputWidth / dpi * Constants::milimeterPerInch)); ui->millimeterInputHeight->setText( Constants::float2String(inputHeight / dpi * Constants::milimeterPerInch)); } void LayoutWidget::setDPI(int newDpi) { if (newDpi < Constants::MIN_DPI) // we only accept positive DPI return; if (dpi == newDpi) // do nothing when nothing changes. return; dpi = newDpi; switch (Constants::displayUnits.indexOf(displayUnit)) { case 0: // pixel factorPixeltoDisplayUnit = 1; break; case 1: // millimeter factorPixeltoDisplayUnit = Constants::milimeterPerInch / dpi; break; case 2: // inches factorPixeltoDisplayUnit = 1 / dpi; break; // default: // Default will not happen, we check the unit before setting displayUnit } updateFormSizes(); emit parameterChanged(); } void LayoutWidget::on_pageWidth_editingFinished() { pxPageWidth = ui->pageWidth->text().toDouble() / factorPixeltoDisplayUnit; updateFormSizes(); emit parameterChanged(); } void LayoutWidget::on_pageHeight_editingFinished() { pxPageHeight = ui->pageHeight->text().toDouble() / factorPixeltoDisplayUnit; updateFormSizes(); emit parameterChanged(); } void LayoutWidget::on_pageWidth_textEdited(const QString &strValue) { qreal width = strValue.toDouble(); if (width <= 0.001) { ui->pageWidth->setStyleSheet("background-color: rgb(255, 0, 0);"); } else { ui->pageWidth->setStyleSheet(""); } } void LayoutWidget::on_pageHeight_textEdited(const QString &strValue) { qreal height = strValue.toDouble(); if (height <= 0.001) { ui->pageHeight->setStyleSheet("background-color: rgb(255, 0, 0);"); } else { ui->pageHeight->setStyleSheet(""); } } void LayoutWidget::on_horizontalAlignment_currentIndexChanged(int /*index*/) { emit parameterChanged(); } void LayoutWidget::on_verticalAlignment_currentIndexChanged(int /*index*/) { emit parameterChanged(); } void LayoutWidget::on_enable_toggled(bool checked) { emit enableFilterToggled(checked); } yasw_0.6/src/filter/layoutwidget.h000066400000000000000000000045151244734364400174120ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef LAYOUTWIDGET_H #define LAYOUTWIDGET_H #include #include "abstractfilterwidget.h" #include namespace Ui { class LayoutWidget; } class LayoutWidget : public AbstractFilterWidget { Q_OBJECT public: explicit LayoutWidget(QWidget *parent = 0); ~LayoutWidget(); void setPixmap(QPixmap pixmap); void setPreview(QPixmap pixmap); bool preview(); double pagePixelHeight(); double pagePixelWidth(); // NOTE: It might be cleaner to use an Enum referencing an array of char*... QString verticalAlignement(); QString horizontalAlignement(); QMap getSettings(); void setSettings(QMap settings); void setDisplayUnit(QString unit); void enableFilter(bool enable); public slots: void setBackgroundColor(QColor color); void setDPI(int newDpi); private slots: void on_preview_toggled(bool checked); void on_pageWidth_editingFinished(); void on_pageHeight_editingFinished(); void on_pageWidth_textEdited(const QString &strValue); void on_pageHeight_textEdited(const QString &strValue); void on_horizontalAlignment_currentIndexChanged(int /*index*/); void on_verticalAlignment_currentIndexChanged(int /*index*/); void on_enable_toggled(bool checked); private: void updateFormSizes(); Ui::LayoutWidget *ui; QDoubleValidator *doubleValidator; int lastUnitIndex = 0; QString displayUnit; qreal factorPixeltoDisplayUnit = 1; qreal pxPageWidth = 0; qreal pxPageHeight = 0; qreal dpi = 1; }; #endif // LAYOUTWIDGET_H yasw_0.6/src/filter/layoutwidget.ui000066400000000000000000000315501244734364400175770ustar00rootroot00000000000000 LayoutWidget 0 0 592 518 0 0 Form Enable Filter true Preview true Qt::Horizontal 216 20 0 0 Page size Width: 0 0 pixel Height: 0 0 pixel Image position Horizintal alignement -1 Vertical alignement -1 Qt::Horizontal Input sizes 0 Qt::AlignCenter Millimeter Qt::AlignCenter Image height Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter 0 Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter Image width Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter Inch Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter Pixel Qt::AlignCenter Resulting sizes Millimeter Qt::AlignCenter 0 Qt::AlignCenter Page height Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter 0 Qt::AlignCenter Pixel Qt::AlignCenter Page width Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter Inch Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter Qt::Vertical 227 68 BaseFilterGraphicsView QGraphicsView
basefiltergraphicsview.h
slotPropertyChanged()
yasw_0.6/src/filter/rotation/000077500000000000000000000000001244734364400163525ustar00rootroot00000000000000yasw_0.6/src/filter/rotation/rotation.cpp000066400000000000000000000074501244734364400207230ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "rotation.h" #include Rotation::Rotation(QObject * parent) : BaseFilter(parent) { widget = new RotationWidget(); filterWidget = widget; connect(widget, SIGNAL(parameterChanged()), this, SLOT(widgetParameterChanged())); if (parent) { /* Connect slots to the filtercontainer */ connect(parent, SIGNAL(backgroundColorChanged(QColor)), widget, SLOT(setBackgroundColor(QColor))); } // TODO: Connect seems only to work when applied to the inherited classes // I would have love to connect one for all in Basefilter... connect(widget, SIGNAL(enableFilterToggled(bool)), this, SLOT(enableFilterToggled(bool))); connect(widget, SIGNAL(previewChecked()), this, SLOT(previewChecked())); } /** \brief Returns a universal name for this filter. This identifier is unique for the filter. It can be used to identify the filter used (for example in configuration files) */ QString Rotation::getIdentifier() { return QString("Rotation"); } /** \brief Returns the localised name of this filter */ QString Rotation::getName() { return tr("Rotation"); } QImage Rotation::filter(QImage inputImage) { if (filterEnabled) { rotationMatrix.reset(); rotationMatrix.rotate(widget->rotation()); return inputImage.transformed(rotationMatrix); } else { return inputImage; } } // Return the settings of the filter: Rotation Angle in Degrees and Enable Checkbox QMap Rotation::getSettings() { QMap settings; settings["rotation"] = widget->rotation(); settings["enabled"] = filterEnabled; return settings; } /** \brief Set filter settings The only relevant Setting for the Filter is its rotation angle. todo: One may want to also save the preview checkbox. */ void Rotation::setSettings(QMap settings) { loadingSettings = true; if (settings.contains("rotation")) widget->setRotation(settings["rotation"].toInt()); else widget->setRotation(0); if (settings.contains("enabled")) enableFilter(settings["enabled"].toBool()); else enableFilter("true"); mustRecalculate = true; loadingSettings = false; emit parameterChanged(); } void Rotation::settings2Dom(QDomDocument &doc, QDomElement &parent, QMap settings) { QDomElement filter = doc.createElement(getIdentifier()); parent.appendChild(filter); if (settings.contains("rotation")) filter.setAttribute("angle", settings["rotation"].toInt()); else filter.setAttribute("angle", 0); if (settings.contains("enabled")) filter.setAttribute("enabled", settings["enabled"].toBool()); else filter.setAttribute("enabled", true); } QMap Rotation::dom2Settings(QDomElement &filterElement) { QMap settings; settings["rotation"] = filterElement.attribute("angle", "0").toInt(); settings["enabled"] = filterElement.attribute("enabled", "1").toInt(); return settings; } yasw_0.6/src/filter/rotation/rotation.h000066400000000000000000000026521244734364400203670ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef ROTATION_H #define ROTATION_H #include #include #include "rotationwidget.h" #include "basefilter.h" class Rotation: public BaseFilter { Q_OBJECT public: Rotation(QObject * parent = 0); QString getIdentifier(); QString getName(); QMap getSettings(); void setSettings(QMap settings); void settings2Dom(QDomDocument &doc, QDomElement &parent, QMap settings); QMap dom2Settings(QDomElement &filterElement); protected: virtual QImage filter(QImage inputImage); private: RotationWidget *widget; QTransform rotationMatrix; }; #endif // ROTATION_H yasw_0.6/src/filter/rotation/rotationwidget.cpp000066400000000000000000000051231244734364400221220ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "rotationwidget.h" #include "ui_rotationwidget.h" #include RotationWidget::RotationWidget(QWidget *parent) : AbstractFilterWidget(parent), ui(new Ui::RotationWidget) { ui->setupUi(this); rotationAngle = 0; } RotationWidget::~RotationWidget() { delete ui; } void RotationWidget::setPixmap(QPixmap pixmap) { inputPixmap = pixmap; if (!preview()) { ui->view->setPixmap(pixmap); } } void RotationWidget::setPreview(QPixmap pixmap) { previewPixmap = pixmap; if (preview()) ui->view->setPixmap(pixmap); } void RotationWidget::on_rotateLeft_clicked() { rotationAngle = (rotationAngle - 90) % 360; emit parameterChanged(); } void RotationWidget::on_rotateRight_clicked() { rotationAngle = (rotationAngle + 90) % 360;; emit parameterChanged(); } void RotationWidget::on_preview_toggled(bool checked) { if (checked) { // This does recalculate the output image if necessary and sets the preview Image. emit previewChecked(); } else { ui->view->setPixmap(inputPixmap); } } bool RotationWidget::preview() { return ui->preview->isChecked(); } int RotationWidget::rotation() { return rotationAngle; } /** \brief Sets the rotation angle in degrees This function is called when changing the Settings of the Rotation Filter */ void RotationWidget::setRotation(int degrees) { /* If the rotation angle is not 0, 90, 180 or 270, someone tempered with the project file and knows what (s)he is dooing, so we don't check */ rotationAngle = degrees; } void RotationWidget::enableFilter(bool enable) { ui->enable->setChecked(enable); } void RotationWidget::setBackgroundColor(QColor color) { ui->view->setBackgroundBrush(QBrush(color)); } void RotationWidget::on_enable_toggled(bool checked) { emit enableFilterToggled(checked); } yasw_0.6/src/filter/rotation/rotationwidget.h000066400000000000000000000030261244734364400215670ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef ROTATIONWIDGET_H #define ROTATIONWIDGET_H #include #include "abstractfilterwidget.h" namespace Ui { class RotationWidget; } class RotationWidget : public AbstractFilterWidget { Q_OBJECT public: explicit RotationWidget(QWidget *parent = 0); ~RotationWidget(); void setPixmap(QPixmap pixmap); void setPreview(QPixmap pixmap); bool preview(); int rotation(); void setRotation(int degrees); void enableFilter(bool enable); public slots: void setBackgroundColor(QColor color); private slots: void on_rotateLeft_clicked(); void on_rotateRight_clicked(); void on_preview_toggled(bool checked); void on_enable_toggled(bool checked); private: Ui::RotationWidget *ui; int rotationAngle; }; #endif // ROTATIONWIDGET_H yasw_0.6/src/filter/rotation/rotationwidget.ui000066400000000000000000000101731244734364400217560ustar00rootroot00000000000000 Copyright (C) 2012 Robert Chéramy (robert@cheramy.net) This file is part of YASW (Yet Another Scan Wizard). YASW 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. YASW 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 YASW. If not, see http://www.gnu.org/licenses/. RotationWidget 0 0 509 422 Form Enable Filter true Preview true Rotate the image counterclockwise rotate counterclockwise :/icons/tango-icon-theme/edit-undo.svg:/icons/tango-icon-theme/edit-undo.svg Rotate the image clockwise rotate clockwise :/icons/tango-icon-theme/edit-redo.svg:/icons/tango-icon-theme/edit-redo.svg Qt::Horizontal 302 20 BaseFilterGraphicsView QGraphicsView
basefiltergraphicsview.h
enable toggled(bool) rotateLeft setEnabled(bool) 29 17 218 33 enable toggled(bool) rotateRight setEnabled(bool) 72 21 252 33 rotateLeft() rotateRight()
yasw_0.6/src/filter/scalefilter.cpp000066400000000000000000000113301244734364400175120ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "scalefilter.h" #include "constants.h" #include ScaleFilter::ScaleFilter(QObject * parent) : BaseFilter(parent) { widget = new ScaleWidget(); filterWidget = widget; connect(widget, SIGNAL(parameterChanged()), this, SLOT(widgetParameterChanged())); if (parent) { /* Connect slots to the filtercontainer */ connect(parent, SIGNAL(backgroundColorChanged(QColor)), widget, SLOT(setBackgroundColor(QColor))); connect(parent, SIGNAL(displayUnitChanged(QString)), this, SLOT(setDisplayUnit(QString))); connect(parent, SIGNAL(dpiChanged(int)), widget, SLOT(setDPI(int))); } // Connect seems only to work when applied to the inherited classes // I would have love to connect one for all in Basefilter... connect(widget, SIGNAL(enableFilterToggled(bool)), this, SLOT(enableFilterToggled(bool))); connect(widget, SIGNAL(previewChecked()), this, SLOT(previewChecked())); } QString ScaleFilter::getIdentifier() { return QString("ScaleFilter"); } QString ScaleFilter::getName() { return tr("Scale"); } /** \brief Gets the settings of the filter. As all the settings are maintained in the widget, this function just gets the setting from the widget and gives them back. */ QMap ScaleFilter::getSettings() { QMap settings = widget->getSettings(); settings["enabled"] = filterEnabled; return settings; } /** \brief Sets the settings for the filter. Gives the settings to the widget (were they are stored) and recalculate the produced Image. */ void ScaleFilter::setSettings(QMap settings) { loadingSettings = true; widget->setSettings(settings); if (settings.contains("enabled")) enableFilter(settings["enabled"].toBool()); else enableFilter("true"); mustRecalculate = true; loadingSettings = false; emit parameterChanged(); } void ScaleFilter::settings2Dom(QDomDocument &doc, QDomElement &parent, QMap settings) { QDomElement filter = doc.createElement(getIdentifier()); parent.appendChild(filter); QString attribute; QStringList attributeNames; int i; // Iterate through attributeNames to save all double attributeNames << "pxImageWidth" << "pxImageHeight"; for (i = 0; i < attributeNames.size(); i++) { attribute = attributeNames.at(i); if (settings.contains(attribute)) { filter.setAttribute(attribute, Constants::float2String(settings[attribute].toDouble())); } } if (settings.contains("enabled")) filter.setAttribute("enabled", settings["enabled"].toBool()); else filter.setAttribute("enabled", true); } QMap ScaleFilter::dom2Settings(QDomElement &filterElement) { QMap settings; QString attribute; QStringList attributeNames; int i; QDomElement cornerElement; // Iterate through attributeNames to save all double attributeNames << "pxImageWidth" << "pxImageHeight"; for (i = 0; i < attributeNames.size(); i++) { attribute = attributeNames.at(i); if (filterElement.hasAttribute(attribute)) { settings[attribute] = filterElement.attribute(attribute).toDouble(); } } settings["enabled"] = filterElement.attribute("enabled", "1").toInt(); return settings; } void ScaleFilter::setDisplayUnit(QString unit) { displayUnit = unit; widget->setDisplayUnit(unit); } QImage ScaleFilter::filter(QImage inputImage) { if (!filterEnabled) return inputImage; qreal imageWidth = widget->imagePixelWidth(); qreal imageHeight = widget->imagePixelHeight(); if (imageWidth == 0 || imageHeight == 0 || inputPixmap.isNull()) { return QImage(); } QSize outputImageSize = QSize(imageWidth, imageHeight); QImage scaledImage = inputImage.scaled(outputImageSize); return scaledImage; } yasw_0.6/src/filter/scalefilter.h000066400000000000000000000027371244734364400171720ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef SCALEFILTER_H #define SCALEFILTER_H #include "basefilter.h" #include "scalewidget.h" class ScaleFilter : public BaseFilter { Q_OBJECT public: ScaleFilter(QObject * parent = 0); QString getIdentifier(); QString getName(); QMap getSettings(); void setSettings(QMap settings); void settings2Dom(QDomDocument &doc, QDomElement &imageElement, QMap settings); QMap dom2Settings(QDomElement &filterElement); public slots: void setDisplayUnit(QString unit); protected: virtual QImage filter(QImage inputImage); private: ScaleWidget *widget; QTransform scaleMatrix; QString displayUnit; }; #endif // SCALEFILTER_H yasw_0.6/src/filter/scalewidget.cpp000066400000000000000000000157411244734364400175220ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "scalewidget.h" #include "ui_scalewidget.h" #include "constants.h" #include #include #include ScaleWidget::ScaleWidget(QWidget *parent) : AbstractFilterWidget(parent), ui(new Ui::ScaleWidget) { ui->setupUi(this); // default value displayUnit = "pixel"; doubleValidator = new QDoubleValidator; doubleValidator->setBottom(0.001); doubleValidator->setDecimals(3); doubleValidator->setNotation(QDoubleValidator::StandardNotation); ui->imageHeight->setValidator(doubleValidator); ui->imageWidth->setValidator(doubleValidator); setDPI(Constants::DEFAULT_DPI); } ScaleWidget::~ScaleWidget() { delete ui; delete doubleValidator; } void ScaleWidget::setPixmap(QPixmap pixmap) { inputPixmap = pixmap; if (!pixmap.isNull() && pxImageWidth == 0 && pxImageHeight == 0) { pxImageWidth = pixmap.width(); pxImageHeight = pixmap.height(); } updateFormSizes(); if (!preview()) { ui->view->setPixmap(pixmap); } } void ScaleWidget::setPreview(QPixmap pixmap) { previewPixmap = pixmap; if (preview()) ui->view->setPixmap(pixmap); } bool ScaleWidget::preview() { return ui->preview->isChecked(); } double ScaleWidget::imagePixelHeight() { return pxImageHeight; } double ScaleWidget::imagePixelWidth() { return pxImageWidth; } QMap ScaleWidget::getSettings() { QMap settings; settings["pxImageWidth"] = pxImageWidth; settings["pxImageHeight"] = pxImageHeight; return settings; } void ScaleWidget::setSettings(QMap settings) { pxImageWidth = settings["pxImageWidth"].toDouble(); pxImageHeight = settings["pxImageHeight"].toDouble(); // Update the form updateFormSizes(); } void ScaleWidget::setDisplayUnit(QString unit) { switch (Constants::displayUnits.indexOf(unit)) { case 0: // pixel factorPixeltoDisplayUnit = 1; break; case 1: // millimeter factorPixeltoDisplayUnit = Constants::milimeterPerInch / dpi; break; case 2: // inches factorPixeltoDisplayUnit = 1 / dpi; break; default: // The unit provided is not valid. Do nothing. return; } displayUnit = unit; ui->lbUnitHeight->setText(unit); ui->lbUnitWidth->setText(unit); updateFormSizes(); } void ScaleWidget::enableFilter(bool enable) { ui->enable->setChecked(enable); } void ScaleWidget::setBackgroundColor(QColor color) { ui->view->setBackgroundBrush(QBrush(color)); } void ScaleWidget::on_preview_toggled(bool checked) { if (checked) { // This does recalculate the output image if necessary and sets the preview Image. emit previewChecked(); } else ui->view->setPixmap(inputPixmap); } // When a parameter is changed, the input and resulting image Sizes are recalculated with this function. void ScaleWidget::updateFormSizes() { QString newImageWidth, newImageHeight; newImageWidth = Constants::float2String(pxImageWidth * factorPixeltoDisplayUnit); newImageHeight = Constants::float2String(pxImageHeight * factorPixeltoDisplayUnit); ui->imageWidth->setText(newImageWidth); ui->imageHeight->setText(newImageHeight); ui->pixelImageWidth->setText(Constants::float2String(pxImageWidth)); ui->pixelImageHeight->setText(Constants::float2String(pxImageHeight)); ui->inchImageWidth->setText(Constants::float2String(pxImageWidth / dpi)); ui->inchImageHeight->setText(Constants::float2String(pxImageHeight / dpi)); ui->millimeterImageWidth->setText( Constants::float2String(pxImageWidth / dpi * Constants::milimeterPerInch)); ui->millimeterImageHeight->setText( Constants::float2String(pxImageHeight / dpi * Constants::milimeterPerInch)); int inputWidth = inputPixmap.width(); int inputHeight = inputPixmap.height(); ui->pixelInputWidth->setText(Constants::float2String(inputWidth)); ui->pixelInputHeight->setText(Constants::float2String(inputHeight)); ui->inchInputWidth->setText(Constants::float2String(inputWidth / dpi)); ui->inchInputHeight->setText(Constants::float2String(inputHeight / dpi)); ui->millimeterInputWidth->setText( Constants::float2String(inputWidth / dpi * Constants::milimeterPerInch)); ui->millimeterInputHeight->setText( Constants::float2String(inputHeight / dpi * Constants::milimeterPerInch)); } void ScaleWidget::setDPI(int newDpi) { if (newDpi < Constants::MIN_DPI) // we only accept positive DPI return; if (dpi == newDpi) // do nothing when nothing changes. return; dpi = newDpi; switch (Constants::displayUnits.indexOf(displayUnit)) { case 0: // pixel factorPixeltoDisplayUnit = 1; break; case 1: // millimeter factorPixeltoDisplayUnit = Constants::milimeterPerInch / dpi; break; case 2: // inches factorPixeltoDisplayUnit = 1 / dpi; break; // default: // Default will not happen, we check the unit before setting displayUnit } updateFormSizes(); emit parameterChanged(); } void ScaleWidget::on_imageWidth_editingFinished() { pxImageWidth = ui->imageWidth->text().toDouble() / factorPixeltoDisplayUnit; updateFormSizes(); emit parameterChanged(); } void ScaleWidget::on_imageHeight_editingFinished() { pxImageHeight = ui->imageHeight->text().toDouble() / factorPixeltoDisplayUnit; updateFormSizes(); emit parameterChanged(); } void ScaleWidget::on_imageWidth_textEdited(const QString &strValue) { qreal width = strValue.toDouble(); if (width <= 0.001) { ui->imageWidth->setStyleSheet("background-color: rgb(255, 0, 0);"); } else { ui->imageWidth->setStyleSheet(""); } } void ScaleWidget::on_imageHeight_textEdited(const QString &strValue) { qreal height = strValue.toDouble(); if (height <= 0.001) { ui->imageHeight->setStyleSheet("background-color: rgb(255, 0, 0);"); } else { ui->imageHeight->setStyleSheet(""); }} void ScaleWidget::on_enable_toggled(bool checked) { emit enableFilterToggled(checked); } yasw_0.6/src/filter/scalewidget.h000066400000000000000000000040601244734364400171570ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef SCALEWIDGET_H #define SCALEWIDGET_H #include "abstractfilterwidget.h" #include #include namespace Ui { class ScaleWidget; } class ScaleWidget : public AbstractFilterWidget { Q_OBJECT public: explicit ScaleWidget(QWidget *parent = 0); ~ScaleWidget(); void setPixmap(QPixmap pixmap); void setPreview(QPixmap pixmap); bool preview(); double imagePixelHeight(); double imagePixelWidth(); QMap getSettings(); void setSettings(QMap settings); void setDisplayUnit(QString unit); void enableFilter(bool enable); public slots: void setBackgroundColor(QColor color); void setDPI(int newDpi); private slots: void on_preview_toggled(bool checked); void on_imageWidth_editingFinished(); void on_imageHeight_editingFinished(); void on_imageWidth_textEdited(const QString &strValue); void on_imageHeight_textEdited(const QString &strValue); void on_enable_toggled(bool checked); private: void updateFormSizes(); Ui::ScaleWidget *ui; QDoubleValidator *doubleValidator; int lastUnitIndex = 0; QString displayUnit; qreal factorPixeltoDisplayUnit = 1; qreal pxImageWidth = 0; qreal pxImageHeight = 0; qreal dpi = 1; }; #endif // SCALEWIDGET_H yasw_0.6/src/filter/scalewidget.ui000066400000000000000000000276461244734364400173640ustar00rootroot00000000000000 ScaleWidget 0 0 640 523 0 0 Form Enable Filter true Preview false Qt::Horizontal 216 20 0 0 Resulting Image Size Width: 0 0 pixel Height: 0 0 pixel Qt::Horizontal Input sizes Millimeter Qt::AlignCenter 0 Qt::AlignCenter Image height Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter 0 Qt::AlignCenter Pixel Qt::AlignCenter Image width Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter Inch Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter Resulting sizes Millimeter Qt::AlignCenter 0 Qt::AlignCenter Image height Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter 0 Qt::AlignCenter Pixel Qt::AlignCenter Image width Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter Inch Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter 0 Qt::AlignCenter Qt::Vertical 20 317 enable preview view groupBox groupBox_4 groupBox_2 BaseFilterGraphicsView QGraphicsView
basefiltergraphicsview.h
slotPropertyChanged()
yasw_0.6/src/filtercontainer.cpp000066400000000000000000000177321244734364400171340ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include "filtercontainer.h" #include "rotation.h" #include "dekeystoning.h" #include "cropping.h" #include "scalefilter.h" #include "colorcorrection.h" #include "layoutfilter.h" #include #include /** \class FilterContainer \brief A customised QTabWidget to display the different filters. FilterContainer initialises each Filter. As QTabWidget::currentWidget only returns a QWidget and we need a FilterWidget and its virtual functions, we keep a Map between tabs indexes and FilterWidgets in tabToWidget. */ FilterContainer::FilterContainer( QWidget * parent) : QTabWidget(parent) { // initialise the filters Rotation *rotationFilter = new Rotation(this); tabToFilter.append(rotationFilter); addTab(rotationFilter->getWidget(), rotationFilter->getName()); Dekeystoning *dekeystoningFilter = new Dekeystoning(this); tabToFilter.append(dekeystoningFilter); addTab(dekeystoningFilter->getWidget(), dekeystoningFilter->getName()); /* connect the filter to previous filter so it gets changes automaticaly */ connect(rotationFilter, SIGNAL(parameterChanged()), dekeystoningFilter, SLOT(inputImageChanged())); dekeystoningFilter->setPreviousFilter(rotationFilter); Cropping *croppingFilter = new Cropping(this); tabToFilter.append(croppingFilter); addTab(croppingFilter->getWidget(), croppingFilter->getName()); /* connect the filter to previous filter so it gets changes automaticaly */ connect(dekeystoningFilter, SIGNAL(parameterChanged()), croppingFilter, SLOT(inputImageChanged())); croppingFilter->setPreviousFilter(dekeystoningFilter); ScaleFilter *scaleFilter = new ScaleFilter(this); tabToFilter.append(scaleFilter); addTab(scaleFilter->getWidget(), scaleFilter->getName()); /* connect the filter to previous filter so it gets changes automaticaly */ scaleFilter->setPreviousFilter(croppingFilter); connect(croppingFilter, SIGNAL(parameterChanged()), scaleFilter, SLOT(inputImageChanged())); LayoutFilter *layoutFilter = new LayoutFilter(this); tabToFilter.append(layoutFilter); addTab(layoutFilter->getWidget(), layoutFilter->getName()); /* connect the filter to previous filter so it gets changes automaticaly */ layoutFilter->setPreviousFilter(scaleFilter); connect(scaleFilter, SIGNAL(parameterChanged()), layoutFilter, SLOT(inputImageChanged())); // Deactivation Color Corection for release 0.6: this ist not good enought for a release. // ColorCorrection *colorCorrection = new ColorCorrection(this); // tabToFilter.append(colorCorrection); // addTab(colorCorrection->getWidget(), colorCorrection->getName()); // /* connect the filter to previous filter so it gets changes automaticaly */ // colorCorrection->setPreviousFilter(layoutFilter); // connect(layoutFilter, SIGNAL(parameterChanged()), // colorCorrection, SLOT(inputImageChanged())); // get informed when a tab changed connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); } FilterContainer::~FilterContainer() { int index; for (index = 0; index < tabToFilter.size(); index++) { delete tabToFilter[index]; } tabToFilter.clear(); } /* Sets the image to be worked on. */ void FilterContainer::setImage(QPixmap pixmap) { // Settings the image on the fist filter results in recalculating the image for all filters, // as the each filter emits a parameterChanged signal, which is recieved by the next filter. tabToFilter[0]->setImage(pixmap); int currentTab = std::min (tabToFilter.size(), currentIndex()); tabToFilter[currentTab]->refresh(); } void FilterContainer::setSelectionColor(QColor color) { emit(selectionColorChanged(color)); } void FilterContainer::setBackgroundColor(QColor color) { emit(backgroundColorChanged(color)); } void FilterContainer::setDisplayUnit(QString unit) { emit(displayUnitChanged(unit)); } void FilterContainer::setDPI(int dpi) { emit(dpiChanged(dpi)); } void FilterContainer::tabChanged(int index) { int currentTab = std::min (tabToFilter.size(), currentIndex()); tabToFilter[currentTab]->refresh(); oldIndex = index; } /*! \brief Get settings from the filters. Each Filter.getSettings will return its settings in a QMap, which will be packed in another QMap (its type is QMap > ). The String Key is the value of Filter.getName(). */ QMap FilterContainer::getSettings() { /* QVariant here is a QMap */ QMap allSettings; BaseFilter *filter; foreach (filter, tabToFilter) { allSettings[filter->getIdentifier()] = filter->getSettings(); } return allSettings; } /*! \brief Set settings to the filters. See also FilterContainer::getSettings */ void FilterContainer::setSettings(QMap settings) { QString filterName; BaseFilter *filter; bool filterSet; foreach (filter, tabToFilter) { filterSet = false; foreach (filterName, settings.keys()) { if (filterName == filter->getIdentifier()) { filter->setSettings(settings[filterName].toMap()); filterSet = true; } } if (filterSet == false) { /* we did not found settings for this filter, reset settings */ filter->setSettings(QMap()); } } int currentTab = std::min (tabToFilter.size(), currentIndex()); tabToFilter[currentTab]->refresh(); } /* Fills the parent with filter DomEmelents and ther parameters We have to provide the parameters as they are stored in the calling Class (ImageTableWidget) This function is called when serializing the settings into an XML file. */ void FilterContainer::settings2Dom(QDomDocument &doc, QDomElement &imageElement, QMap settings) { BaseFilter *filter; foreach (filter, tabToFilter) { if (settings.contains(filter->getIdentifier())) { filter->settings2Dom(doc, imageElement, settings[filter->getIdentifier()].toMap()); } } } // Transforms the subtags from into filter settings QMap. // NOTE: It might be interesting to get ride of the QMap and only use DOM for the whole Settings. QMap FilterContainer::dom2Settings(QDomElement &imageElement) { QDomElement filterElement; BaseFilter *filter; QMap settings; filterElement = imageElement.firstChildElement(); while (!filterElement.isNull()) { foreach (filter, tabToFilter) { if (filterElement.tagName() == filter->getIdentifier()) { settings[filter->getIdentifier()] = filter->dom2Settings(filterElement); } } filterElement = filterElement.nextSiblingElement(); } return settings; } /** \brief Compute and return the resulting image above all filter */ QPixmap FilterContainer::getResultImage() { int maxTab = tabToFilter.size() - 1; return tabToFilter[maxTab]->getOutputImage(); } /** \brief Returns the identifiert of the current filter */ QString FilterContainer::currentFilter() { return tabToFilter[currentIndex()]->getIdentifier(); } yasw_0.6/src/filtercontainer.h000066400000000000000000000040441244734364400165710ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef FILTERCONTAINER_H #define FILTERCONTAINER_H #include #include #include #include #include #include "basefilter.h" #include "abstractfilterwidget.h" #include "scalefilter.h" class FilterContainer : public QTabWidget { Q_OBJECT public: FilterContainer(QWidget * parent = 0); ~FilterContainer(); QMap getSettings(); void setSettings(QMap settings); void settings2Dom(QDomDocument &doc, QDomElement &imageElement, QMap settings); QMap dom2Settings(QDomElement &imageElement); QPixmap getResultImage(); QString currentFilter(); void setImage(QPixmap pixmap); public slots: void tabChanged(int index); void setSelectionColor(QColor color); void setBackgroundColor(QColor color); void setDisplayUnit(QString unit); void setDPI(int dpi); private: QList tabToFilter; int oldIndex = 0; //stores the last selected index, at init = first tab signals: // Propagates changes to global configuration paramters void selectionColorChanged(QColor color); void backgroundColorChanged(QColor color); void displayUnitChanged(QString unit); void dpiChanged(int dpi); }; #endif // FILTERCONTAINER_H yasw_0.6/src/icons/000077500000000000000000000000001244734364400143415ustar00rootroot00000000000000yasw_0.6/src/icons/icons.qrc000066400000000000000000000010201244734364400161540ustar00rootroot00000000000000 tango-icon-theme/edit-redo.svg tango-icon-theme/edit-undo.svg tango-icon-theme/list-remove.svg tango-icon-theme/document-new.svg tango-icon-theme/go-down.svg tango-icon-theme/go-up.svg tango-icon-theme/list-add.svg tango-icon-theme/go-next.svg tango-icon-theme/go-previous.svg yasw_0.6/src/icons/tango-icon-theme/000077500000000000000000000000001244734364400174775ustar00rootroot00000000000000yasw_0.6/src/icons/tango-icon-theme/copyright.txt000066400000000000000000000005311244734364400222470ustar00rootroot00000000000000The icons in this folder are taken from the Tango Icon Theme Version 0.8.90. It can be downloaded from http://tango.freedesktop.org/releases The icons in the Tango Icon Theme are released under the Public Domain, as stated by the COPYING file in the original tarball: "The icons in this repository are herefore released into the Public Domain."yasw_0.6/src/icons/tango-icon-theme/document-new.svg000066400000000000000000000417761244734364400226440ustar00rootroot00000000000000 image/svg+xml New Document Jakub Steiner http://jimmac.musichall.cz yasw_0.6/src/icons/tango-icon-theme/edit-redo.svg000066400000000000000000000221631244734364400221000ustar00rootroot00000000000000 image/svg+xml Jakub Steiner http://jimmac.musichall.cz Edit Redo edit redo again reapply yasw_0.6/src/icons/tango-icon-theme/edit-undo.svg000066400000000000000000000220231244734364400221070ustar00rootroot00000000000000 image/svg+xml Jakub Steiner http://jimmac.musichall.cz Edit Undo edit undo revert yasw_0.6/src/icons/tango-icon-theme/go-down.svg000066400000000000000000000202141244734364400215710ustar00rootroot00000000000000 image/svg+xml Jakub Steiner http://jimmac.musichall.cz Go Down go lower down arrow pointer > Andreas Nilsson yasw_0.6/src/icons/tango-icon-theme/go-next.svg000066400000000000000000000173401244734364400216060ustar00rootroot00000000000000 image/svg+xml Jakub Steiner http://jimmac.musichall.cz Go Next go next right arrow pointer > yasw_0.6/src/icons/tango-icon-theme/go-previous.svg000066400000000000000000000674231244734364400225130ustar00rootroot00000000000000 image/svg+xml Jakub Steiner http://jimmac.musichall.cz Go Previous go previous left arrow pointer < yasw_0.6/src/icons/tango-icon-theme/go-up.svg000066400000000000000000000200321244734364400212440ustar00rootroot00000000000000 image/svg+xml Jakub Steiner http://jimmac.musichall.cz Go Up go higher up arrow pointer > Andreas Nilsson yasw_0.6/src/icons/tango-icon-theme/list-add.svg000066400000000000000000000347301244734364400217300ustar00rootroot00000000000000 image/svg+xml Add 2006-01-04 Andreas Nilsson http://tango-project.org add plus yasw_0.6/src/icons/tango-icon-theme/list-remove.svg000066400000000000000000000327361244734364400225010ustar00rootroot00000000000000 image/svg+xml Remove 2006-01-04 Andreas Nilsson http://tango-project.org remove delete yasw_0.6/src/imagetablewidget.cpp000066400000000000000000000546771244734364400172530ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include #include #include #include #include #include #include "imagetablewidget.h" #include "constants.h" #include "ui_imagetablewidget.h" /* FIXME: I am very unhapy with the design of this ImageTableWidget. This is a dirty hack that has to be rewritten. It is a lot of work that noone sees but has to be rewritten before nice features like drag&drop comme in play. Layout has to be separated from Data, items have to become a dedicated widget (ideas: filename under image, display source image or preview, infos with tooltip...) */ ImageTableWidget::ImageTableWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ImageTableWidget) { ui->setupUi(this); connect(ui->images, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)), this, SLOT(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*))); filterContainer = NULL; itemCount[leftSide] = 0; itemCount[rightSide] = 0; ui->images->setHorizontalHeaderLabels(QStringList() << "Left" << "Right"); } ImageTableWidget::~ImageTableWidget() { delete ui; } void ImageTableWidget::setFilterContainer(FilterContainer *container) { if (filterContainer) { Q_ASSERT (false); // Changing filterContainer. This should never occur ! } filterContainer = container; } void ImageTableWidget::currentItemChanged(QTableWidgetItem *newItem, QTableWidgetItem *previousItem) { if (!filterContainer) { // This should never happen, but if so, do nothing. return; } QMap settings; QMap oldSettings; QString filterID = ""; if (previousItem) { settings = filterContainer->getSettings(); oldSettings = previousItem->data(ImagePreferences).toMap(); // settings changed? Save them! if (settings != oldSettings) { previousItem->setData(ImagePreferences, settings); } } if (newItem) { // NOTE: setting the image an setting the settings results in recaluling twice the image // There might be a performance improvement here. filterContainer->setImage(QPixmap(newItem->data(ImageFileName).toString())); filterContainer->setSettings(newItem->data(ImagePreferences).toMap()); } else { // FIXME: can this happen? qDebug() << "ImageTableWidget::currentItemChanged to an empty item"; filterContainer->setImage(QPixmap()); // Reset Filter Settings as no image is selected filterContainer->setSettings(QMap()); } } /** \brief Slot called from the UI to add an one or many images */ void ImageTableWidget::insertImage() { QFileInfo fi; QString imageFileName; bool moveSelectionDown = false; ImageTableWidget::ImageSide side; int column = ui->images->currentColumn(); if (column == 1) side = ImageTableWidget::rightSide; else // defaults to left side = ImageTableWidget::leftSide; // if there is a selected item, save its settings. QTableWidgetItem *currentImage = ui->images->currentItem(); if (currentImage) { // Save current settings: call the currentItemChanged slot newItem = previusItem = currentItem currentItemChanged(currentImage, currentImage); } if (lastDir.length() == 0) lastDir = QDir::currentPath(); QStringList images = QFileDialog::getOpenFileNames(this, tr("Choose images"), lastDir, // FIXME: scaling down for *.png does not work as good as for jpg // FIXME: export fron png images don not work. Deactiving png for now. // tr("Images (*.jpg *.png);;All files (* *.*)")); tr("Images (*.jpg);;All files (* *.*)")); int progress = 0; int numberImages = images.length(); if (numberImages == 0) // No image to load return; QProgressDialog progressDialog(tr("Loading images..."), "Abort", 0, numberImages); progressDialog.setWindowModality(Qt::WindowModal); foreach (imageFileName, images) { // Update Progress Dialog progressDialog.setValue(progress); progress++; if (progressDialog.wasCanceled()) { // Allready loaded image can't be undone. // Load settings/image for the current item. currentItemChanged(ui->images->currentItem(), NULL); return; } // Insert the image if (moveSelectionDown) { // Append images after the previous insertion. // Insert the first image depending on current selection, so do nothing. ui->images->setCurrentCell(ui->images->currentRow() + 1, ui->images->currentColumn()); } addImage(imageFileName, side); moveSelectionDown = true; } // Load settings/image for the current item. currentItemChanged(ui->images->currentItem(), NULL); // Close progressDialog progressDialog.setValue(numberImages); // Saves path of the last loaded image. if (imageFileName.length() > 0) { fi = QFileInfo(imageFileName); lastDir = fi.absolutePath(); } } /* Inserts an image at the current selection on the given side and selects it. */ void ImageTableWidget::addImage(QString fileName, ImageTableWidget::ImageSide side, QMap settings) { QTableWidgetItem *item; QTableWidgetItem *currentItem; QFileInfo fi(fileName); QPixmap icon; int currentRow; //NOTE: loading all icons at this time implies waiting time for the user. //Alternatives: put some "waiting" dialog or do ICON-loading in the background icon = QPixmap(fileName).scaledToWidth(100); item = new QTableWidgetItem(QIcon(icon), fi.fileName()); item->setData(ImageFileName, fileName); item->setData(ImagePreferences, settings); item->setToolTip(fileName); currentItem = ui->images->currentItem(); if (currentItem && ui->images->currentColumn() == side) { // Insert before current item currentRow = ui->images->currentRow(); } else { // Insert at the End currentRow = itemCount[side]; } insertItem(item, currentRow, side); // Select the inserted item ui->images->setCurrentItem(item); } /** \brief Inserts an item at row and side */ void ImageTableWidget::insertItem(QTableWidgetItem *item, int row, int side) { int i; /* If the position is outside the possible possition, modifiy it to be the best * available value */ if (side < 0) side = 0; if (side > 1) side = 1; if (row < 0) row = 0; if (row >= itemCount[side]) row = itemCount[side]; // Adjust Table size if necessary if (itemCount[side] >= ui->images->rowCount()) { ui->images->setRowCount(itemCount[side] + 1); } // move all items after position one step down for (i = itemCount[side]; i > row; i--) { ui->images->setItem(i, side, ui->images->takeItem(i - 1, side)); } ui->images->setItem(row, side, item); itemCount[side] = itemCount[side] + 1; } /** \brief Appends an image at the end of the Table */ void ImageTableWidget::appendImageToSide(QString fileName, ImageTableWidget::ImageSide side, QMap settings) { QTableWidgetItem *item; QPixmap icon; QFileInfo fi(fileName); icon = QPixmap(fileName).scaledToWidth(100); item = new QTableWidgetItem(QIcon(icon), fi.fileName()); // Adjust Table size if necessary if (itemCount[side] >= ui->images->rowCount()) { ui->images->setRowCount(itemCount[side] + 1); } ui->images->setItem(itemCount[side], side, item); item->setData(ImageFileName, fileName); item->setData(ImagePreferences, settings); item->setToolTip(fileName); itemCount[side] = itemCount[side] + 1; } void ImageTableWidget::insertEmptyImage() { ImageTableWidget::ImageSide side; int column = ui->images->currentColumn(); if (column == 1) side = ImageTableWidget::rightSide; else // defaults to left side = ImageTableWidget::leftSide; addImage("", side); } void ImageTableWidget::imageDown() { int side = ui->images->currentColumn(); if (side < 0 || side > 1) return; int currentRow = ui->images->currentRow(); if (currentRow + 1 > itemCount[side] - 1) { return; } QTableWidgetItem *itemToDown = ui->images->takeItem(currentRow, side); QTableWidgetItem *itemToUp = ui->images->takeItem(currentRow + 1, side); ui->images->setItem(currentRow +1, side, itemToDown); ui->images->setItem(currentRow, side, itemToUp); ui->images->setCurrentItem(itemToDown); } void ImageTableWidget::imageUp() { int side = ui->images->currentColumn(); if (side < 0 || side > 1) return; int currentRow = ui->images->currentRow(); if (currentRow < 1 || currentRow >= itemCount[side]) { return; } QTableWidgetItem *itemToUp = ui->images->takeItem(currentRow, side); QTableWidgetItem *itemToDown = ui->images->takeItem(currentRow -1, side); ui->images->setItem(currentRow - 1, side, itemToUp); ui->images->setItem(currentRow, side, itemToDown); ui->images->setCurrentItem(itemToUp); } void ImageTableWidget::moveImageLeft() { int side = ui->images->currentColumn(); if (side != 1) { // nothing to move return; } int otherSide = 1 - side; int currentRow = ui->images->currentRow(); if (currentRow < 0 || currentRow >= itemCount[side]) { return; } QTableWidgetItem *itemToMove = takeItem(currentRow, side); insertItem(itemToMove, currentRow, otherSide); // Select the moved item ui->images->setCurrentItem(itemToMove); } void ImageTableWidget::moveImageRight() { int side = ui->images->currentColumn(); if (side != 0) { // nothing to move return; } int otherSide = 1 - side; int currentRow = ui->images->currentRow(); if (currentRow < 0 || currentRow >= itemCount[side]) { return; } QTableWidgetItem *itemToMove = takeItem(currentRow, side); insertItem(itemToMove, currentRow, otherSide); // Select the moved item ui->images->setCurrentItem(itemToMove); } void ImageTableWidget::selectPreviousImage() { int side = ui->images->currentColumn(); int row = ui->images->currentRow(); row = row - 1; /* If the position is outside the possible possition, modifiy it to be the best * available value */ if (side < 0) side = 0; if (side > 1) side = 1; if (row < 0) row = 0; if (row >= itemCount[side]) row = itemCount[side] - 1; ui->images->setCurrentCell(row, side); } void ImageTableWidget::selectNextImage() { int side = ui->images->currentColumn(); int row = ui->images->currentRow(); row = row + 1; /* If the position is outside the possible possition, modifiy it to be the best * available value */ if (side < 0) side = 0; if (side > 1) side = 1; if (row < 0) row = 0; if (row >= itemCount[side]) row = itemCount[side] - 1; ui->images->setCurrentCell(row, side);} void ImageTableWidget::selectRightImage() { int side = ui->images->currentColumn(); int row = ui->images->currentRow(); side = 1; /* If the position is outside the possible possition, modifiy it to be the best * available value */ if (row < 0) row = 0; if (row >= itemCount[side]) row = itemCount[side] - 1; ui->images->setCurrentCell(row, side); } void ImageTableWidget::selectLeftImage() { int side = ui->images->currentColumn(); int row = ui->images->currentRow(); side = 0; /* If the position is outside the possible possition, modifiy it to be the best * available value */ if (row < 0) row = 0; if (row >= itemCount[side]) row = itemCount[side] - 1; ui->images->setCurrentCell(row, side); } QTableWidgetItem * ImageTableWidget::takeItem(int row, int side) { int i; QTableWidgetItem *item; if (side < 0 || side > 1) return NULL; //Nothing to delete int otherSide = 1 - side; if (row >=0 && row >= itemCount[side]) { return NULL; //Nothing to delete } item = ui->images->takeItem(row, side); for (i = row; i < itemCount[side] - 1; i++) { ui->images->setItem(i, side, ui->images->takeItem(i + 1, side)); } itemCount[side]--; if (itemCount[side] >= itemCount[otherSide]) { ui->images->setRowCount(itemCount[side]); } // if last column removed, scroll one up if (row == itemCount[side] && row > 0) { ui->images->setCurrentCell(row - 1, side); } // redraw currentItemChanged(ui->images->currentItem(), NULL); return item; } void ImageTableWidget::removeSelected() { int currentRow = ui->images->currentRow(); int currentColumn = ui->images->currentColumn(); delete takeItem(currentRow, currentColumn); } void ImageTableWidget::saveProjectParameters(QDomDocument &doc, QDomElement &parent) { int row; QTableWidgetItem *item; QDomElement imageElement; QMap settings; // Save the settings of current filter before saving settings = filterContainer->getSettings(); item = ui->images->currentItem(); if (item) item->setData(ImagePreferences, settings); settings.clear(); for (row = 0; row < itemCount[leftSide]; row++) { item = ui->images->item(row, leftSide); // Save the image attributes imageElement = doc.createElement("image"); imageElement.setAttribute("side", "left"); imageElement.setAttribute("filename", item->data(ImageFileName).toString()); parent.appendChild(imageElement); // Save the filter settings settings = item->data(ImagePreferences).toMap(); filterContainer->settings2Dom(doc, imageElement, settings); } for (row = 0; row < itemCount[rightSide]; row++) { item = ui->images->item(row, rightSide); // Save the image attributes imageElement = doc.createElement("image"); imageElement.setAttribute("side", "right"); imageElement.setAttribute("filename", item->data(ImageFileName).toString()); parent.appendChild(imageElement); // Save the filter settings settings = item->data(ImagePreferences).toMap(); filterContainer->settings2Dom(doc, imageElement, settings); } } // This function loads the parameter from XML (DOM) int yasw bool ImageTableWidget::loadProjectParameters(QDomElement &rootElement) { QDomElement imageElement; QString sideString; ImageTableWidget::ImageSide side; int progress = 1; QString filename; clear(); // Load all Images int numberImages = rootElement.elementsByTagName("image").size(); QProgressDialog progressDialog("Loading project...", "Abort", 1, numberImages); progressDialog.setWindowModality(Qt::WindowModal); QMap settings; imageElement = rootElement.firstChildElement("image"); while (!imageElement.isNull()) { // update progress dialog progressDialog.setValue(progress); if (progressDialog.wasCanceled()) { return false; } // load image sideString = imageElement.attribute("side"); if (sideString == "left") { side = leftSide; } else if (sideString == "right") { side = rightSide; } else { // Project file is not OK => cancel Loading // FIXME: signal the error to the User? progressDialog.cancel(); return false; } filename = imageElement.attribute("filename"); // FIXME: settings settings = filterContainer->dom2Settings(imageElement); appendImageToSide(filename, side, settings); imageElement = imageElement.nextSiblingElement("image"); progress++; } progressDialog.setValue(numberImages); return true; } // Empty the widget from all images; void ImageTableWidget::clear() { //FIXME: is memory cleared? ui->images->setRowCount(0); itemCount[leftSide] = 0; itemCount[rightSide] = 0; } void ImageTableWidget::exportToFolder(QString folder) { int row; QTableWidgetItem *currentItem = ui->images->currentItem(); QPixmap pixmap; QString filename; int progress = 0; int maxProgress = itemCount[leftSide] + itemCount[rightSide]; QProgressDialog progressDialog(QString("Exporting to folder %2...").arg(folder), "Abort", 0, maxProgress); progressDialog.setWindowModality(Qt::WindowModal); for (row = 0; row < itemCount[leftSide]; row++) { // Update Process Dialog progressDialog.setValue(progress); progress++; if (progressDialog.wasCanceled()) { ui->images->setCurrentItem(currentItem); return; } // Export image ui->images->setCurrentCell(row, leftSide); pixmap = filterContainer->getResultImage(); filename = QString("%1/image_%2_Left.jpg").arg(folder).arg(row+1, 3, 10, QChar('0')); pixmap.save(filename); } for (row = 0; row < itemCount[rightSide]; row++) { // Update Process Dialog progressDialog.setValue(progress); progress++; if (progressDialog.wasCanceled()) { ui->images->setCurrentItem(currentItem); return; } // Export image ui->images->setCurrentCell(row, rightSide); pixmap = filterContainer->getResultImage(); filename = QString("%1/image_%2_Right.jpg").arg(folder).arg(row+1, 3, 10, QChar('0')); pixmap.save(filename); } progressDialog.setValue(maxProgress); ui->images->setCurrentItem(currentItem); } void ImageTableWidget::exportToPdf(QString pdfFile, int DPI) { int row; qreal w = 0; qreal h = 0; bool firstPage = true; QTableWidgetItem *currentItem = ui->images->currentItem(); QPixmap pixmap; QPainter painter; QPrinter printer(QPrinter::HighResolution); printer.setOutputFormat(QPrinter::PdfFormat); printer.setFullPage(true); printer.setOutputFileName(pdfFile); // This seems to have no effect. Setting it doesn't hurt... printer.setResolution(DPI); int progress = 0; int maxProgress = qMax(itemCount[leftSide], itemCount[rightSide]); QProgressDialog progressDialog(QString("Exporting to %2...").arg(pdfFile), "Abort", 0, maxProgress); progressDialog.setWindowModality(Qt::WindowModal); for (row = 0; row < qMax(itemCount[leftSide], itemCount[rightSide]); row++) { // Update Process Dialog progressDialog.setValue(progress); progress++; if (progressDialog.wasCanceled()) { painter.end(); ui->images->setCurrentItem(currentItem); return; } // Export pages // handle both side with one peace of code. side values: 0 = leftSide, 1 = rightSide for (int side = 0; side <= 1; side++) { if (row < itemCount[side]) { // is one item available at this row? ui->images->setCurrentCell(row, side); pixmap = filterContainer->getResultImage(); // as QPrinter does not handle DPI right, we have set the paper size in inches. w = (qreal) pixmap.width() / DPI; h = (qreal) pixmap.height() / DPI; printer.setPaperSize(QSizeF(w, h), QPrinter::Inch); // we don't need a new page for the first page or we would have a blank page if (firstPage == true) { firstPage = false; painter.begin(&printer); } else { printer.newPage(); } painter.drawPixmap(printer.pageRect(), pixmap); } } } painter.end(); progressDialog.setValue(maxProgress); ui->images->setCurrentItem(currentItem); } void ImageTableWidget::on_btnPropagateFollowingSameSide_clicked() { QMap filterSettings; int row = ui->images->currentRow(); int side = ui->images->currentColumn(); QMap settings = filterContainer->getSettings(); QString filterID = filterContainer->currentFilter(); for (int i = row; i < itemCount[side]; i++) { filterSettings = ui->images->item(i, side)->data(ImagePreferences).toMap(); filterSettings[filterID] = settings[filterID]; ui->images->item(i, side)->setData(ImagePreferences, filterSettings); } } void ImageTableWidget::on_btnPropagateAllSameSide_clicked() { QMap filterSettings; int side = ui->images->currentColumn(); QMap settings = filterContainer->getSettings(); QString filterID = filterContainer->currentFilter(); for (int i = 0; i < itemCount[side]; i++) { filterSettings = ui->images->item(i, side)->data(ImagePreferences).toMap(); filterSettings[filterID] = settings[filterID]; ui->images->item(i, side)->setData(ImagePreferences, filterSettings); } } void ImageTableWidget::on_btnPropagateAll_clicked() { QMap filterSettings; for (int side=0; side <= 1; side++) { QMap settings = filterContainer->getSettings(); QString filterID = filterContainer->currentFilter(); for (int i = 0; i < itemCount[side]; i++) { filterSettings = ui->images->item(i, side)->data(ImagePreferences).toMap(); filterSettings[filterID] = settings[filterID]; ui->images->item(i, side)->setData(ImagePreferences, filterSettings); } } } yasw_0.6/src/imagetablewidget.h000066400000000000000000000054401244734364400167000ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef IMAGETABLEWIDGET_H #define IMAGETABLEWIDGET_H #include #include #include #include "filtercontainer.h" namespace Ui { class ImageTableWidget; } class ImageTableWidget : public QWidget { Q_OBJECT public: explicit ImageTableWidget(QWidget *parent = 0); ~ImageTableWidget(); void setFilterContainer(FilterContainer *container); // save YASW into XML void saveProjectParameters(QDomDocument &doc, QDomElement &parent); // load XML int YASW bool loadProjectParameters(QDomElement &rootElement); void clear(); void exportToFolder(QString folder); void exportToPdf(QString pdfFile, int DPI); public slots: void currentItemChanged(QTableWidgetItem *newItem, QTableWidgetItem *previousItem); void insertImage(); void insertEmptyImage(); void imageUp(); void imageDown(); void removeSelected(); void moveImageLeft(); void moveImageRight(); void selectPreviousImage(); void selectNextImage(); void selectRightImage(); void selectLeftImage(); private: Ui::ImageTableWidget *ui; enum ImageSide { leftSide, rightSide }; FilterContainer *filterContainer; QString lastDir = ""; // stores the last row for left and right images int itemCount[2]; void addImage(QString fileName, enum ImageSide side, QMap settings = QMap ()); void appendImageToSide(QString fileName, ImageTableWidget::ImageSide side, QMap settings); enum ImageTableUserRoles { ImagePreferences = Qt::UserRole, ImageFileName }; void addClicked(ImageTableWidget::ImageSide side); QTableWidgetItem * takeItem(int row, int side); void insertItem(QTableWidgetItem * item, int row, int side); private slots: void on_btnPropagateFollowingSameSide_clicked(); void on_btnPropagateAllSameSide_clicked(); void on_btnPropagateAll_clicked(); }; #endif // IMAGETABLEWIDGET_H yasw_0.6/src/imagetablewidget.ui000066400000000000000000000254211244734364400170670ustar00rootroot00000000000000 Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) This file is part of YASW (Yet Another Scan Wizard). YASW 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. YASW 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 YASW. If not, see http://www.gnu.org/licenses/. ImageTableWidget 0 0 238 566 0 0 238 0 238 16777215 Form 0 0 220 0 220 16777215 QAbstractItemView::NoEditTriggers false false QAbstractItemView::NoDragDrop QAbstractItemView::SingleSelection 100 100 true 0 2 100 false false 100 Qt::Horizontal 13 20 Move the selected image up up :/icons/tango-icon-theme/go-up.svg:/icons/tango-icon-theme/go-up.svg Add an empty image to the left :/icons/tango-icon-theme/document-new.svg:/icons/tango-icon-theme/document-new.svg remove selected image remove :/icons/tango-icon-theme/list-remove.svg:/icons/tango-icon-theme/list-remove.svg Move the selected image down down :/icons/tango-icon-theme/go-down.svg:/icons/tango-icon-theme/go-down.svg Insert an image on the left + :/icons/tango-icon-theme/list-add.svg:/icons/tango-icon-theme/list-add.svg Move the selected image up move left :/icons/tango-icon-theme/go-previous.svg:/icons/tango-icon-theme/go-previous.svg Move the selected image up move right :/icons/tango-icon-theme/go-next.svg:/icons/tango-icon-theme/go-next.svg Qt::Horizontal Propagate the settings of the active filter to... true all following images on the side all images on the side all images add clicked() ImageTableWidget insertImage() 35 427 118 207 remove clicked() ImageTableWidget removeSelected() 35 458 169 250 up clicked() ImageTableWidget imageUp() 99 427 168 391 down clicked() ImageTableWidget imageDown() 99 458 148 430 addEmpty clicked() ImageTableWidget insertEmptyImage() 59 427 104 167 moveLeft clicked() ImageTableWidget moveImageLeft() 118 415 118 282 moveRight clicked() ImageTableWidget moveImageRight() 150 415 153 335 removeSelected() imageUp() imageDown() insertImage() insertEmptyImage() moveImageLeft() moveImageRight() yasw_0.6/src/main.cpp000066400000000000000000000016361244734364400146640ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } yasw_0.6/src/mainwindow.cpp000066400000000000000000000250041244734364400161070ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include #include #include #include #include #include #include #include #include "mainwindow.h" #include "ui_mainwindow.h" #include "constants.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->imageList->setFilterContainer(ui->filterContainer); showMaximized(); settings = new QSettings("yasw", "yasw"); /* update recent projects menu */ addRecentProject(""); preferencesDialog = new PreferencesDialog(); // Transmit global preferences changes to the filter container. // The filter container will retransmit the changes to the filter who subscribed to its signal connect(preferencesDialog, SIGNAL(selectionColorChanged(QColor)), ui->filterContainer, SLOT(setSelectionColor(QColor))); connect(preferencesDialog, SIGNAL(backgroundColorChanged(QColor)), ui->filterContainer, SLOT(setBackgroundColor(QColor))); connect(preferencesDialog, SIGNAL(displayUnitChanged(QString)), ui->filterContainer, SLOT(setDisplayUnit(QString))); connect(preferencesDialog, SIGNAL(dpiChanged(int)), ui->filterContainer, SLOT(setDPI(int))); preferencesDialog->setSettings(settings); } MainWindow::~MainWindow() { delete ui; delete settings; delete preferencesDialog; } void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } } /** \brief Save the current project */ void MainWindow::on_action_Save_triggered() { if (projectFileName.length() != 0) { saveProjectSettings(projectFileName); } else { on_action_SaveAs_triggered(); } } /** \brief Save the current project in a new file */ void MainWindow::on_action_SaveAs_triggered() { QString fileName; fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::currentPath() + "/project.yasw", tr("yasw projects (*.yasw);;All files (* *.*")); if (fileName.length() == 0) return; //If saving to file was successfull, store the project filename in a global variable if (saveProjectSettings(fileName)) setProjectFileName(fileName); } /** Save project settings to an XML File returns true if successful; false on failure This private member is used to avoid dupplicate code betwenn save and save as. */ bool MainWindow::saveProjectSettings(QString fileName) { QFile file(fileName); if (!file.open(QFile::WriteOnly | QFile::Text)) { // Failure QMessageBox::critical(this, tr("Could not save Project"), tr("A problem occured while saving file \"%1\". The project could not be saved") .arg(fileName) ); return false; } QDomDocument doc; QDomElement yasw = doc.createElement("yasw"); doc.appendChild(yasw); yasw.setAttribute("version", VERSION); preferencesDialog->saveProjectParameters(doc, yasw); ui->imageList->saveProjectParameters(doc, yasw); QTextStream out(&file); doc.save(out, 4); file.close(); return true; } /* \Brief Sets the current project name in the title bar and inserts it to the recent projects. It also saves the current project file name in the property projectFileName for other usages. */ void MainWindow::setProjectFileName(QString fileName) { QFileInfo fi(fileName); this->projectFileName = fileName; if (fileName.length() > 0) { setWindowTitle(tr("yasw - %1").arg(fi.fileName())); addRecentProject(fileName); } else setWindowTitle(tr("yasw - new project")); } void MainWindow::addRecentProject(QString fileName) { QStringList recentProjects; recentProjects = settings->value("recent_projects").toStringList(); // If we have a "valid" filename, update the list; else just update the menu //NOTE: perhaps the menu update thing should be done in a separate function if (fileName.size() > 0) { /* remove the file from the list to avoid duplicates */ recentProjects.removeAll(fileName); recentProjects.prepend(fileName); } /* reduce size of list to MAX_RECENT_PROJECTS */ while (recentProjects.size() > MAX_RECENT_PROJECTS) recentProjects.removeLast(); settings->setValue("recent_projects", recentProjects); ui->recentProjects->clear(); if (recentProjects.size() == 0) { ui->recentProjects->setEnabled(false); } else { ui->recentProjects->setEnabled(true); QAction *action; QString project; foreach (project, recentProjects) { action = ui->recentProjects->addAction(project); connect(action, SIGNAL(triggered()), this, SLOT(openRecentProject())); } } } void MainWindow::loadProject(QString fileName) { QMap settings; bool loadingOK = true; QFile file(fileName); if (!file.open(QFile::ReadOnly | QFile::Text)) { // Failure QMessageBox::critical(this, tr("Could not load Project"), tr("A problem occured while loading file \"%1\"") .arg(fileName) ); return; } QDomDocument doc; QString errMsg; int errLine, errColumn; if (!doc.setContent(&file, false, &errMsg, &errLine, &errColumn)) { QMessageBox::critical(this, tr("Could not load Project"), tr("A problem occured while parsing file \"%1\" :\n" "Line %2, Column %3: %4") .arg(fileName, QString::number(errLine), QString::number(errColumn), errMsg)); return; } QDomElement rootElement = doc.documentElement(); if (rootElement.tagName() != "yasw") { QMessageBox::critical(this, tr("Could not load Project"), tr("\"%1\" is not a valid YASW project file") .arg(fileName) ); return; } // if loadingError is true, the function after || will not be called. loadingOK = loadingOK && preferencesDialog->loadProjectParameters(rootElement); loadingOK = loadingOK && ui->imageList->loadProjectParameters(rootElement); if (loadingOK) { setProjectFileName(fileName); } else { // Something went wrong -> clear the project. on_action_Close_triggered(); } } /** \brief Open a project from file // FIXME: Load and Check QStream version and yasw Version */ void MainWindow::on_action_Open_triggered() { QString fileName = QFileDialog::getOpenFileName(this, tr("Choose project"), QDir::currentPath(), // FIXME: save last path tr("yasw projects (*.yasw);;All files (* *.*")); if (fileName.length() == 0) // Cancel pressed return; loadProject(fileName); } void MainWindow::exportToJpeg() { QString exportFolder = QFileDialog::getExistingDirectory(this, tr("Choose folder for export"), QDir::currentPath() // FIXME: save last path ); if (exportFolder.length() == 0) return; ui->imageList->exportToFolder(exportFolder); } void MainWindow::exportToPdf() { QString pdfFilename = QDir::currentPath() + "/file.pdf"; if (projectFileName.length() > 0) { QFileInfo fi(projectFileName); pdfFilename = fi.path() + "/" + fi.baseName() + ".pdf"; } QString exportFile = QFileDialog::getSaveFileName(this, tr("Export to PDF"), pdfFilename, tr("PDF Files (*.pdf);;All files (* *.*")); if (exportFile.length() == 0) return; ui->imageList->exportToPdf(exportFile, preferencesDialog->DPI()); } /** \brief Close curent project, reset settings to default values */ void MainWindow::on_action_Close_triggered() { ui->imageList->clear(); setProjectFileName(""); } void MainWindow::on_action_About_triggered() { QMessageBox::about(this, tr("Yet Another Scan Wizard Version: %1").arg(VERSION), tr("Yet Another Scan Wizard (YASW) is an application used to correct images taken " "with a camera while scanning a book.\n\n" "YASW is written by Robert Cheramy \n\n" "YASW 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.\n" "YASW 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.\n" "You should have received a copy of the GNU General Public License " "along with YASW. If not, see .\n\n" "YASW uses icons from the Tango Theme, which is in the public domain.")); } void MainWindow::openRecentProject() { QAction *action = qobject_cast(sender()); if (action) loadProject(action->text()); } void MainWindow::on_action_Preferences_triggered() { preferencesDialog->exec(); } yasw_0.6/src/mainwindow.h000066400000000000000000000035231244734364400155560ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include #include #include #include #include #include "preferencesdialog.h" namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); protected: void changeEvent(QEvent *e); private slots: void on_action_Save_triggered(); void on_action_Open_triggered(); void on_action_SaveAs_triggered(); void on_action_Close_triggered(); void exportToJpeg(); void exportToPdf(); void on_action_About_triggered(); void openRecentProject(); void on_action_Preferences_triggered(); private: bool saveProjectSettings(QString fileName); void loadProject(QString fileName); void setProjectFileName(QString fileName); void addRecentProject(QString fileName); Ui::MainWindow *ui; QString projectFileName; QSettings *settings = NULL; const int MAX_RECENT_PROJECTS = 5; PreferencesDialog *preferencesDialog; }; #endif // MAINWINDOW_H yasw_0.6/src/mainwindow.ui000066400000000000000000000344471244734364400157550ustar00rootroot00000000000000 Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) This file is part of YASW (Yet Another Scan Wizard). YASW 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. YASW 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 YASW. If not, see http://www.gnu.org/licenses/. MainWindow 0 0 1010 582 0 0 yasw - new project 0 0 0 0 238 0 238 16777215 -1 0 0 1010 24 &Project true &Recent projects E&xport to &Image &Help & &Edit &Quit Alt+F4 &Open Ctrl+O &Save Ctrl+S Save&As &Close Ctrl+W &JPEG &PDF &Add Image Insert an image at current position (when no selection, defaults to left) + &Remove selected image Del Move image &up Move image up Ctrl+Up Move image &down Move image down Ctrl+Down Add &empty image Adds an empty image at selection. If there is default selection, inserts left &About &Preferences Move image &left Ctrl+Left Move image right Ctrl+Right Select previous image Select previous image Up Select next image Down Select left image Left Select right image Right FilterContainer QTabWidget
filtercontainer.h
1
ImageTableWidget QWidget
imagetablewidget.h
1 removeSelected() imageUp() imageDown() insertImage() insertEmptyImage() moveImageLeft() moveImageRight() selectPreviousImage() selectNextImage() selectLeftImage() selectRightImage()
action_Quit triggered() MainWindow close() -1 -1 534 347 actionTo_Jpeg triggered() MainWindow exportToJpeg() -1 -1 504 290 actionTo_PDF triggered() MainWindow exportToPdf() -1 -1 504 290 actionAddImage triggered() imageList insertImage() -1 -1 127 293 actionRemove_selected triggered() imageList removeSelected() -1 -1 127 293 actionMoveImageUp triggered() imageList imageUp() -1 -1 127 293 actionMoveImageDown triggered() imageList imageDown() -1 -1 127 293 actionAdd_empty_image triggered() imageList insertEmptyImage() -1 -1 127 293 actionMove_image_left triggered() imageList moveImageLeft() -1 -1 127 293 actionMove_image_right triggered() imageList moveImageRight() -1 -1 127 293 actionSelectPreviousImage triggered() imageList selectPreviousImage() -1 -1 127 293 actionSelect_next_image triggered() imageList selectNextImage() -1 -1 127 293 actionSelect_left_image triggered() imageList selectLeftImage() -1 -1 127 293 actionSelect_right_image triggered() imageList selectRightImage() -1 -1 127 293 ImageSelected(QModelIndex) slotTransform() exportToJpeg() exportToPdf()
yasw_0.6/src/preferencesdialog.cpp000066400000000000000000000140151244734364400174140ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #include #include #include #include #include #include "preferencesdialog.h" #include "ui_preferencesdialog.h" #include "constants.h" PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent), ui(new Ui::PreferencesDialog) { ui->setupUi(this); setSelectionColor(Qt::red); setBackgroundColor(Qt::lightGray); ui->unit->insertItems(0, Constants::displayUnits); setDisplayUnit("pixel"); QIntValidator *dpiValidator = new QIntValidator(); dpiValidator->setBottom(Constants::MIN_DPI); ui->dpi->setValidator(dpiValidator); connect(ui->dpi->lineEdit(), SIGNAL(editingFinished()), this, SLOT(dpiFormChanged())); ui->dpi->insertItems(0, Constants::dpiList); setDPI(Constants::DEFAULT_DPI); } PreferencesDialog::~PreferencesDialog() { delete ui; } void PreferencesDialog::setSettings(QSettings *newSettings) { QColor color; settings = newSettings; color = QColor(settings->value("selectionColor").toString()); if (!color.isValid()) { color = selectionColor; } setSelectionColor(color); color = QColor(settings->value("backgroundColor").toString()); if (!color.isValid()) { color = backgroundColor; } setBackgroundColor(color); QString unit = settings->value("displayUnit").toString(); setDisplayUnit(unit); } QString PreferencesDialog::displayUnit() { return ui->unit->currentText(); } void PreferencesDialog::setDPI(int newDpi) { if (newDpi <= Constants::MIN_DPI) // we only accept positive DPI return; dpi = newDpi; QString dpiString = QString::number(dpi, 'f', 0); if (Constants::dpiList.contains(dpiString)) { ui->dpi->setCurrentIndex(Constants::dpiList.indexOf(dpiString)); } else { ui->dpi->setEditText(dpiString); } emit(dpiChanged(dpi)); } int PreferencesDialog::DPI() { return dpi; } void PreferencesDialog::saveProjectParameters(QDomDocument &doc, QDomElement &rootElement) { QDomElement parameter = doc.createElement("global"); parameter.setAttribute("DPI", dpi); rootElement.appendChild(parameter); } bool PreferencesDialog::loadProjectParameters(QDomElement &rootElement) { QDomElement parameter = rootElement.firstChildElement("global"); if (parameter.isNull()) return false; setDPI(parameter.attribute("DPI", QString::number(Constants::DEFAULT_DPI, 'f', 0)).toInt()); return true; } // We don't want the dialog to close when pressing enter or the user might not see that his DPI // has not been taken into account void PreferencesDialog::keyPressEvent(QKeyEvent *evt) { if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) return; QDialog::keyPressEvent(evt); } void PreferencesDialog::on_selectionColorButton_clicked() { QColor color; color = QColorDialog::getColor(selectionColor, this, tr("Choose a color for visual selection")); setSelectionColor(color); } /** \brief Sets the Color for grafical selection feedback (example deykeystoning quadrilateral) This function emits a selectionColorChanged signal, so that the filtercontainer can transmit the information to the plugings, who should change the color used. */ void PreferencesDialog::setSelectionColor(QColor color) { QPalette palette; if (!color.isValid()) { return; } selectionColor = color; palette.setColor(QPalette::Button, color); ui->selectionColorButton->setPalette(palette); if (settings) { settings->setValue("selectionColor", color.name()); } emit(selectionColorChanged(color)); } void PreferencesDialog::setBackgroundColor(QColor color) { QPalette palette; if (!color.isValid()) { return; } backgroundColor = color; palette.setColor(QPalette::Button, color); ui->backgroundColorButton->setPalette(palette); if (settings) { settings->setValue("backgroundColor", color.name()); } emit(backgroundColorChanged(color)); } void PreferencesDialog::setDisplayUnit(QString unit) { if (!Constants::displayUnits.contains(unit)) // unit unknown? Do nothing. return; ui->unit->setCurrentIndex(Constants::displayUnits.indexOf(unit)); if (settings) { settings->setValue("displayUnit", unit); } } void PreferencesDialog::on_backgroundColorButton_clicked() { QColor color; color = QColorDialog::getColor(backgroundColor, this, tr("Choose a background color")); setBackgroundColor(color); } void PreferencesDialog::on_unit_currentIndexChanged(const QString &unit) { if (settings) { settings->setValue("displayUnit", unit); } emit(displayUnitChanged(unit)); } void PreferencesDialog::on_dpi_editTextChanged(const QString &stringDPI) { qreal dpi = stringDPI.toDouble(); if (dpi < Constants::MIN_DPI) { ui->dpi->setStyleSheet("background-color: rgb(255, 0, 0);"); } else { ui->dpi->setStyleSheet(""); } } void PreferencesDialog::dpiFormChanged() { int newDPI = ui->dpi->currentText().toInt(); if (dpi == newDPI) // do nothing when nothing changes. return; if (newDPI < Constants::MIN_DPI) { // We don't accept small DPI, but this should never happen (Validator on Form) return; } dpi = newDPI; emit dpiChanged(dpi); } yasw_0.6/src/preferencesdialog.h000066400000000000000000000042621244734364400170640ustar00rootroot00000000000000/* * Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) * * This file is part of YASW (Yet Another Scan Wizard). * * YASW 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. * * YASW 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 YASW. If not, see . */ #ifndef PREFERENCESDIALOG_H #define PREFERENCESDIALOG_H #include #include #include #include #include #include namespace Ui { class PreferencesDialog; } class PreferencesDialog : public QDialog { Q_OBJECT public: explicit PreferencesDialog(QWidget *parent = 0); ~PreferencesDialog(); void setSettings(QSettings *newSettings); QString displayUnit(); void setDPI(int newDpi); int DPI(); // save YASW into XML void saveProjectParameters(QDomDocument &doc, QDomElement &rootElement); // load XML int YASW bool loadProjectParameters(QDomElement &rootElement); void keyPressEvent(QKeyEvent *evt); public slots: void dpiFormChanged(); private slots: void on_selectionColorButton_clicked(); void on_backgroundColorButton_clicked(); void on_unit_currentIndexChanged(const QString &unit); void on_dpi_editTextChanged(const QString &stringDPI); private: void setSelectionColor(QColor color); void setBackgroundColor(QColor color); void setDisplayUnit(QString unit); Ui::PreferencesDialog *ui; QColor selectionColor; QSettings *settings = NULL; QColor backgroundColor; int dpi = 0; signals: void selectionColorChanged(QColor color); void backgroundColorChanged(QColor color); void displayUnitChanged(QString unit); void dpiChanged(int dpi); }; #endif // PREFERENCESDIALOG_H yasw_0.6/src/preferencesdialog.ui000066400000000000000000000135431244734364400172540ustar00rootroot00000000000000 Copyright (C) 2012-2014 Robert Chéramy (robert@cheramy.net) This file is part of YASW (Yet Another Scan Wizard). YASW 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. YASW 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 YASW. If not, see http://www.gnu.org/licenses/. PreferencesDialog 0 0 409 351 YASW Preferences Global settings Selection Color 255 0 0 255 0 0 255 0 0 Background Color Display Unit Project settings Dots per Inch (DPI) true Qt::Vertical 20 161 Qt::Horizontal 114 20 Qt::Horizontal QDialogButtonBox::Ok buttonBox accepted() PreferencesDialog accept() 425 247 157 274 buttonBox rejected() PreferencesDialog reject() 425 247 286 274 yasw_0.6/src/yasw.pro000066400000000000000000000075351244734364400147450ustar00rootroot00000000000000# Copyright (C) 2012 Robert Chéramy (robert@cheramy.net) # # This file is part of YASW (Yet Another Scan Wizard). # # YASW 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. # # YASW 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 YASW. If not, see . # Disable warning about non-static data member initializers. # No idea if this works on other platforms, old platforms will probably do not support it. QMAKE_CXXFLAGS += -std=c++11 TARGET = yasw TEMPLATE = app QT += xml QT += widgets QT += printsupport SOURCES += main.cpp \ mainwindow.cpp \ filter/basefilter.cpp \ filter/basefiltergraphicsview.cpp \ filter/basefilterwidget.cpp \ filtercontainer.cpp \ filter/dekeystoning/dekeystoningwidget.cpp \ filter/dekeystoning/dekeystoning.cpp \ filter/rotation/rotationwidget.cpp \ filter/rotation/rotation.cpp \ filter/abstractfilterwidget.cpp \ filter/cropping/cropping.cpp \ filter/cropping/croppingwidget.cpp \ filter/cropping/croppinggraphicsview.cpp \ filter/cropping/croppingcorner.cpp \ filter/dekeystoning/dekeystoningline.cpp \ filter/dekeystoning/dekeystoningcorner.cpp \ imagetablewidget.cpp \ filter/scalewidget.cpp \ preferencesdialog.cpp \ filter/colorcorrectionwidget.cpp \ filter/colorcorrection.cpp \ filter/dekeystoning/dekeystoninggraphicsview.cpp \ filter/colorcorrectiongraphicsview.cpp \ filter/colorcorrectiongraphicsscene.cpp \ constants.cpp \ filter/layoutfilter.cpp \ filter/layoutwidget.cpp \ filter/scalefilter.cpp HEADERS += mainwindow.h \ filter/basefilter.h \ filter/basefiltergraphicsview.h \ filter/basefilterwidget.h \ filtercontainer.h \ filter/dekeystoning/dekeystoningwidget.h \ filter/dekeystoning/dekeystoninggraphicsview.h \ filter/dekeystoning/dekeystoning.h \ filter/rotation/rotationwidget.h \ filter/rotation/rotation.h \ filter/abstractfilterwidget.h \ filter/cropping/cropping.h \ filter/cropping/croppingwidget.h \ filter/cropping/croppinggraphicsview.h \ filter/cropping/croppingcorner.h \ filter/dekeystoning/dekeystoningline.h \ filter/dekeystoning/dekeystoningcorner.h \ imagetablewidget.h \ filter/scalewidget.h \ filter/layoutfilter.h \ filter/layoutwidget.h \ preferencesdialog.h \ filter/colorcorrectionwidget.h \ filter/colorcorrection.h \ filter/colorcorrectiongraphicsview.h \ filter/colorcorrectiongraphicsscene.h \ constants.h \ filter/scalefilter.h FORMS += mainwindow.ui \ filter/basefilterwidget.ui \ filter/dekeystoning/dekeystoningwidget.ui \ filter/rotation/rotationwidget.ui \ filter/cropping/croppingwidget.ui \ imagetablewidget.ui \ preferencesdialog.ui \ filter/scalewidget.ui \ filter/layoutwidget.ui \ filter/colorcorrectionwidget.ui INCLUDEPATH += filter \ filter/dekeystoning \ filter/rotation \ filter/cropping RESOURCES += icons/icons.qrc OTHER_FILES += \ ../changelog.txt \ ../install.txt \ ../gpl.txt \ ../developpers.txt \ ../README static { ## Everything below takes effect when calling qmake with CONFIG += static ## thanks to Charles N. Burns, http://www.formortals.com/how-to-statically-link-qt-4/ for the help ## Update Qt5: Q_IMPORT_PLUGIN(qsvg) in main.c is not needed anymore; QT += svg neither QTPLUGIN += qsvg DEFINES += STATIC message ("This is a static build") }