mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-23 10:22:52 +00:00
generic: drop kvkbd, krfb, krdc, kget, kcalc and qmlwallpapers
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
70e02f5b00
commit
cf2654a6de
530 changed files with 1 additions and 80123 deletions
|
@ -18,14 +18,9 @@ kde4_optional_add_subdirectory(about-distro)
|
||||||
kde4_optional_add_subdirectory(ark)
|
kde4_optional_add_subdirectory(ark)
|
||||||
kde4_optional_add_subdirectory(filelight)
|
kde4_optional_add_subdirectory(filelight)
|
||||||
kde4_optional_add_subdirectory(gwenview)
|
kde4_optional_add_subdirectory(gwenview)
|
||||||
kde4_optional_add_subdirectory(kcalc)
|
|
||||||
kde4_optional_add_subdirectory(kdeplasma-addons)
|
kde4_optional_add_subdirectory(kdeplasma-addons)
|
||||||
kde4_optional_add_subdirectory(kemu)
|
kde4_optional_add_subdirectory(kemu)
|
||||||
kde4_optional_add_subdirectory(kget)
|
|
||||||
kde4_optional_add_subdirectory(krdc)
|
|
||||||
kde4_optional_add_subdirectory(krfb)
|
|
||||||
kde4_optional_add_subdirectory(ksnapshot)
|
kde4_optional_add_subdirectory(ksnapshot)
|
||||||
kde4_optional_add_subdirectory(kvkbd)
|
|
||||||
kde4_optional_add_subdirectory(okular)
|
kde4_optional_add_subdirectory(okular)
|
||||||
kde4_optional_add_subdirectory(partitionmanager)
|
kde4_optional_add_subdirectory(partitionmanager)
|
||||||
kde4_optional_add_subdirectory(thumbnailers)
|
kde4_optional_add_subdirectory(thumbnailers)
|
||||||
|
|
|
@ -154,6 +154,5 @@ Type=Application
|
||||||
Terminal=false
|
Terminal=false
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
X-KDE-HasTempFileOption=true
|
X-KDE-HasTempFileOption=true
|
||||||
X-KDE-HasTrayOption=true
|
|
||||||
Categories=Qt;KDE;Utility;Archiving;Compression;X-KDE-Utilities-File;
|
Categories=Qt;KDE;Utility;Archiving;Compression;X-KDE-Utilities-File;
|
||||||
InitialPreference=3
|
InitialPreference=3
|
||||||
|
|
|
@ -159,4 +159,3 @@ MimeType=inode/directory;
|
||||||
X-DocPath=filelight/index.html
|
X-DocPath=filelight/index.html
|
||||||
Categories=Qt;KDE;Utility;
|
Categories=Qt;KDE;Utility;
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
X-KDE-HasTrayOption=true
|
|
||||||
|
|
|
@ -182,4 +182,3 @@ X-DocPath=gwenview/index.html
|
||||||
# primary applications for folders.
|
# primary applications for folders.
|
||||||
InitialPreference=8
|
InitialPreference=8
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
X-KDE-HasTrayOption=true
|
|
||||||
|
|
|
@ -1,104 +0,0 @@
|
||||||
project(kcalc)
|
|
||||||
|
|
||||||
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
|
||||||
include(FeatureSummary)
|
|
||||||
|
|
||||||
find_package(KDELibs4 4.23.0 REQUIRED)
|
|
||||||
|
|
||||||
include_directories(${KDE4_INCLUDES})
|
|
||||||
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}")
|
|
||||||
|
|
||||||
find_package(GMP)
|
|
||||||
set_package_properties(GMP PROPERTIES
|
|
||||||
DESCRIPTION "The GNU Multiple Precision Arithmetic Library"
|
|
||||||
URL "http://gmplib.org/"
|
|
||||||
PURPOSE "Required for building KCalc"
|
|
||||||
TYPE REQUIRED
|
|
||||||
)
|
|
||||||
|
|
||||||
include(CheckTypeSize)
|
|
||||||
|
|
||||||
check_type_size("signed long" SIZEOF_SIGNED_LONG)
|
|
||||||
check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
|
|
||||||
|
|
||||||
configure_file(
|
|
||||||
config-kcalc.h.cmake
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/config-kcalc.h
|
|
||||||
)
|
|
||||||
|
|
||||||
include_directories(
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/knumber
|
|
||||||
${GMP_INCLUDE_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
########### next target ###############
|
|
||||||
|
|
||||||
# Needs absolute paths due to the test program for knumber
|
|
||||||
set(libknumber_la_SRCS
|
|
||||||
${kcalc_SOURCE_DIR}/knumber/knumber.cpp
|
|
||||||
${kcalc_SOURCE_DIR}/knumber/knumber_error.cpp
|
|
||||||
${kcalc_SOURCE_DIR}/knumber/knumber_float.cpp
|
|
||||||
${kcalc_SOURCE_DIR}/knumber/knumber_fraction.cpp
|
|
||||||
${kcalc_SOURCE_DIR}/knumber/knumber_integer.cpp
|
|
||||||
${kcalc_SOURCE_DIR}/knumber/knumber_operators.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_subdirectory( knumber )
|
|
||||||
# add_subdirectory( tests )
|
|
||||||
|
|
||||||
set(kcalc_SRCS ${libknumber_la_SRCS}
|
|
||||||
kcalc.cpp
|
|
||||||
bitbutton.cpp
|
|
||||||
kcalc_bitset.cpp
|
|
||||||
kcalc_button.cpp
|
|
||||||
kcalc_const_button.cpp
|
|
||||||
kcalc_const_menu.cpp
|
|
||||||
kcalc_core.cpp
|
|
||||||
kcalcdisplay.cpp
|
|
||||||
stats.cpp
|
|
||||||
kcalc.ui
|
|
||||||
constants.ui
|
|
||||||
colors.ui
|
|
||||||
fonts.ui
|
|
||||||
general.ui
|
|
||||||
)
|
|
||||||
|
|
||||||
kde4_add_kcfg_files(kcalc_SRCS kcalc_settings.kcfgc)
|
|
||||||
|
|
||||||
add_executable(kcalc ${kcalc_SRCS})
|
|
||||||
|
|
||||||
target_link_libraries(kcalc
|
|
||||||
KDE4::kdeui
|
|
||||||
${QT_QTXML_LIBRARY}
|
|
||||||
${GMP_LIBRARIES}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
TARGETS kcalc
|
|
||||||
DESTINATION ${KDE4_BIN_INSTALL_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
########### install files ###############
|
|
||||||
|
|
||||||
install(
|
|
||||||
PROGRAMS kcalc.desktop
|
|
||||||
DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
FILES kcalcui.rc
|
|
||||||
DESTINATION ${KDE4_DATA_INSTALL_DIR}/kcalc
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
FILES scienceconstants.xml
|
|
||||||
DESTINATION ${KDE4_DATA_INSTALL_DIR}/kcalc
|
|
||||||
)
|
|
||||||
|
|
||||||
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
|
||||||
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
|
||||||
endif()
|
|
346
kcalc/COPYING
346
kcalc/COPYING
|
@ -1,346 +0,0 @@
|
||||||
NOTE! The GPL below is copyrighted by the Free Software Foundation, but
|
|
||||||
the instance of code that it refers to (the kde programs) are copyrighted
|
|
||||||
by the authors who actually wrote it.
|
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 2, June 1991
|
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
License is intended to guarantee your freedom to share and change free
|
|
||||||
software--to make sure the software is free for all its users. This
|
|
||||||
General Public License applies to most of the Free Software
|
|
||||||
Foundation's software and to any other program whose authors commit to
|
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
|
||||||
the GNU Library General Public License instead.) You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
this service if you wish), that you receive source code or can get it
|
|
||||||
if you want it, that you can change the software or use pieces of it
|
|
||||||
in new free programs; and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
anyone to deny you these rights or to ask you to surrender the rights.
|
|
||||||
These restrictions translate to certain responsibilities for you if you
|
|
||||||
distribute copies of the software, or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must give the recipients all the rights that
|
|
||||||
you have. You must make sure that they, too, receive or can get the
|
|
||||||
source code. And you must show them these terms so they know their
|
|
||||||
rights.
|
|
||||||
|
|
||||||
We protect your rights with two steps: (1) copyright the software, and
|
|
||||||
(2) offer you this license which gives you legal permission to copy,
|
|
||||||
distribute and/or modify the software.
|
|
||||||
|
|
||||||
Also, for each author's protection and ours, we want to make certain
|
|
||||||
that everyone understands that there is no warranty for this free
|
|
||||||
software. If the software is modified by someone else and passed on, we
|
|
||||||
want its recipients to know that what they have is not the original, so
|
|
||||||
that any problems introduced by others will not reflect on the original
|
|
||||||
authors' reputations.
|
|
||||||
|
|
||||||
Finally, any free program is threatened constantly by software
|
|
||||||
patents. We wish to avoid the danger that redistributors of a free
|
|
||||||
program will individually obtain patent licenses, in effect making the
|
|
||||||
program proprietary. To prevent this, we have made it clear that any
|
|
||||||
patent must be licensed for everyone's free use or not licensed at all.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License applies to any program or other work which contains
|
|
||||||
a notice placed by the copyright holder saying it may be distributed
|
|
||||||
under the terms of this General Public License. The "Program", below,
|
|
||||||
refers to any such program or work, and a "work based on the Program"
|
|
||||||
means either the Program or any derivative work under copyright law:
|
|
||||||
that is to say, a work containing the Program or a portion of it,
|
|
||||||
either verbatim or with modifications and/or translated into another
|
|
||||||
language. (Hereinafter, translation is included without limitation in
|
|
||||||
the term "modification".) Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running the Program is not restricted, and the output from the Program
|
|
||||||
is covered only if its contents constitute a work based on the
|
|
||||||
Program (independent of having been made by running the Program).
|
|
||||||
Whether that is true depends on what the Program does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Program's
|
|
||||||
source code as you receive it, in any medium, provided that you
|
|
||||||
conspicuously and appropriately publish on each copy an appropriate
|
|
||||||
copyright notice and disclaimer of warranty; keep intact all the
|
|
||||||
notices that refer to this License and to the absence of any warranty;
|
|
||||||
and give any other recipients of the Program a copy of this License
|
|
||||||
along with the Program.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy, and
|
|
||||||
you may at your option offer warranty protection in exchange for a fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Program or any portion
|
|
||||||
of it, thus forming a work based on the Program, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) You must cause the modified files to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
b) You must cause any work that you distribute or publish, that in
|
|
||||||
whole or in part contains or is derived from the Program or any
|
|
||||||
part thereof, to be licensed as a whole at no charge to all third
|
|
||||||
parties under the terms of this License.
|
|
||||||
|
|
||||||
c) If the modified program normally reads commands interactively
|
|
||||||
when run, you must cause it, when started running for such
|
|
||||||
interactive use in the most ordinary way, to print or display an
|
|
||||||
announcement including an appropriate copyright notice and a
|
|
||||||
notice that there is no warranty (or else, saying that you provide
|
|
||||||
a warranty) and that users may redistribute the program under
|
|
||||||
these conditions, and telling the user how to view a copy of this
|
|
||||||
License. (Exception: if the Program itself is interactive but
|
|
||||||
does not normally print such an announcement, your work based on
|
|
||||||
the Program is not required to print an announcement.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Program,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Program, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Program.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Program
|
|
||||||
with the Program (or with a work based on the Program) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may copy and distribute the Program (or a work based on it,
|
|
||||||
under Section 2) in object code or executable form under the terms of
|
|
||||||
Sections 1 and 2 above provided that you also do one of the following:
|
|
||||||
|
|
||||||
a) Accompany it with the complete corresponding machine-readable
|
|
||||||
source code, which must be distributed under the terms of Sections
|
|
||||||
1 and 2 above on a medium customarily used for software interchange; or,
|
|
||||||
|
|
||||||
b) Accompany it with a written offer, valid for at least three
|
|
||||||
years, to give any third party, for a charge no more than your
|
|
||||||
cost of physically performing source distribution, a complete
|
|
||||||
machine-readable copy of the corresponding source code, to be
|
|
||||||
distributed under the terms of Sections 1 and 2 above on a medium
|
|
||||||
customarily used for software interchange; or,
|
|
||||||
|
|
||||||
c) Accompany it with the information you received as to the offer
|
|
||||||
to distribute corresponding source code. (This alternative is
|
|
||||||
allowed only for noncommercial distribution and only if you
|
|
||||||
received the program in object code or executable form with such
|
|
||||||
an offer, in accord with Subsection b above.)
|
|
||||||
|
|
||||||
The source code for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For an executable work, complete source
|
|
||||||
code means all the source code for all modules it contains, plus any
|
|
||||||
associated interface definition files, plus the scripts used to
|
|
||||||
control compilation and installation of the executable. However, as a
|
|
||||||
special exception, the source code distributed need not include
|
|
||||||
anything that is normally distributed (in either source or binary
|
|
||||||
form) with the major components (compiler, kernel, and so on) of the
|
|
||||||
operating system on which the executable runs, unless that component
|
|
||||||
itself accompanies the executable.
|
|
||||||
|
|
||||||
If distribution of executable or object code is made by offering
|
|
||||||
access to copy from a designated place, then offering equivalent
|
|
||||||
access to copy the source code from the same place counts as
|
|
||||||
distribution of the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
4. You may not copy, modify, sublicense, or distribute the Program
|
|
||||||
except as expressly provided under this License. Any attempt
|
|
||||||
otherwise to copy, modify, sublicense or distribute the Program is
|
|
||||||
void, and will automatically terminate your rights under this License.
|
|
||||||
However, parties who have received copies, or rights, from you under
|
|
||||||
this License will not have their licenses terminated so long as such
|
|
||||||
parties remain in full compliance.
|
|
||||||
|
|
||||||
5. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Program or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Program (or any work based on the
|
|
||||||
Program), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Program or works based on it.
|
|
||||||
|
|
||||||
6. Each time you redistribute the Program (or any work based on the
|
|
||||||
Program), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute or modify the Program subject to
|
|
||||||
these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties to
|
|
||||||
this License.
|
|
||||||
|
|
||||||
7. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Program at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Program by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Program.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under
|
|
||||||
any particular circumstance, the balance of the section is intended to
|
|
||||||
apply and the section as a whole is intended to apply in other
|
|
||||||
circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system, which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
8. If the distribution and/or use of the Program is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Program under this License
|
|
||||||
may add an explicit geographical distribution limitation excluding
|
|
||||||
those countries, so that distribution is permitted only in or among
|
|
||||||
countries not thus excluded. In such case, this License incorporates
|
|
||||||
the limitation as if written in the body of this License.
|
|
||||||
|
|
||||||
9. The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program
|
|
||||||
specifies a version number of this License which applies to it and "any
|
|
||||||
later version", you have the option of following the terms and conditions
|
|
||||||
either of that version or of any later version published by the Free
|
|
||||||
Software Foundation. If the Program does not specify a version number of
|
|
||||||
this License, you may choose any version ever published by the Free Software
|
|
||||||
Foundation.
|
|
||||||
|
|
||||||
10. If you wish to incorporate parts of the Program into other free
|
|
||||||
programs whose distribution conditions are different, write to the author
|
|
||||||
to ask for permission. For software which is copyrighted by the Free
|
|
||||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
|
||||||
make exceptions for this. Our decision will be guided by the two goals
|
|
||||||
of preserving the free status of all derivatives of our free software and
|
|
||||||
of promoting the sharing and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
|
||||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
|
||||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
|
||||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
|
||||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
|
||||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
|
||||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
|
||||||
REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
|
||||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
|
||||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
|
||||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
|
||||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
||||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) 19yy <name of author>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program is interactive, make it output a short notice like this
|
|
||||||
when it starts in an interactive mode:
|
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, the commands you use may
|
|
||||||
be called something other than `show w' and `show c'; they could even be
|
|
||||||
mouse-clicks or menu items--whatever suits your program.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
|
||||||
necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
|
||||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1989
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
This General Public License does not permit incorporating your program into
|
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
|
||||||
consider it more useful to permit linking proprietary applications with the
|
|
||||||
library. If this is what you want to do, use the GNU Library General
|
|
||||||
Public License instead of this License.
|
|
|
@ -1,510 +0,0 @@
|
||||||
|
|
||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
Version 2.1, February 1999
|
|
||||||
|
|
||||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
|
||||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
[This is the first released version of the Lesser GPL. It also counts
|
|
||||||
as the successor of the GNU Library Public License, version 2, hence
|
|
||||||
the version number 2.1.]
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
Licenses are intended to guarantee your freedom to share and change
|
|
||||||
free software--to make sure the software is free for all its users.
|
|
||||||
|
|
||||||
This license, the Lesser General Public License, applies to some
|
|
||||||
specially designated software packages--typically libraries--of the
|
|
||||||
Free Software Foundation and other authors who decide to use it. You
|
|
||||||
can use it too, but we suggest you first think carefully about whether
|
|
||||||
this license or the ordinary General Public License is the better
|
|
||||||
strategy to use in any particular case, based on the explanations
|
|
||||||
below.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom of use,
|
|
||||||
not price. Our General Public Licenses are designed to make sure that
|
|
||||||
you have the freedom to distribute copies of free software (and charge
|
|
||||||
for this service if you wish); that you receive source code or can get
|
|
||||||
it if you want it; that you can change the software and use pieces of
|
|
||||||
it in new free programs; and that you are informed that you can do
|
|
||||||
these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
distributors to deny you these rights or to ask you to surrender these
|
|
||||||
rights. These restrictions translate to certain responsibilities for
|
|
||||||
you if you distribute copies of the library or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of the library, whether gratis
|
|
||||||
or for a fee, you must give the recipients all the rights that we gave
|
|
||||||
you. You must make sure that they, too, receive or can get the source
|
|
||||||
code. If you link other code with the library, you must provide
|
|
||||||
complete object files to the recipients, so that they can relink them
|
|
||||||
with the library after making changes to the library and recompiling
|
|
||||||
it. And you must show them these terms so they know their rights.
|
|
||||||
|
|
||||||
We protect your rights with a two-step method: (1) we copyright the
|
|
||||||
library, and (2) we offer you this license, which gives you legal
|
|
||||||
permission to copy, distribute and/or modify the library.
|
|
||||||
|
|
||||||
To protect each distributor, we want to make it very clear that
|
|
||||||
there is no warranty for the free library. Also, if the library is
|
|
||||||
modified by someone else and passed on, the recipients should know
|
|
||||||
that what they have is not the original version, so that the original
|
|
||||||
author's reputation will not be affected by problems that might be
|
|
||||||
introduced by others.
|
|
||||||
|
|
||||||
Finally, software patents pose a constant threat to the existence of
|
|
||||||
any free program. We wish to make sure that a company cannot
|
|
||||||
effectively restrict the users of a free program by obtaining a
|
|
||||||
restrictive license from a patent holder. Therefore, we insist that
|
|
||||||
any patent license obtained for a version of the library must be
|
|
||||||
consistent with the full freedom of use specified in this license.
|
|
||||||
|
|
||||||
Most GNU software, including some libraries, is covered by the
|
|
||||||
ordinary GNU General Public License. This license, the GNU Lesser
|
|
||||||
General Public License, applies to certain designated libraries, and
|
|
||||||
is quite different from the ordinary General Public License. We use
|
|
||||||
this license for certain libraries in order to permit linking those
|
|
||||||
libraries into non-free programs.
|
|
||||||
|
|
||||||
When a program is linked with a library, whether statically or using
|
|
||||||
a shared library, the combination of the two is legally speaking a
|
|
||||||
combined work, a derivative of the original library. The ordinary
|
|
||||||
General Public License therefore permits such linking only if the
|
|
||||||
entire combination fits its criteria of freedom. The Lesser General
|
|
||||||
Public License permits more lax criteria for linking other code with
|
|
||||||
the library.
|
|
||||||
|
|
||||||
We call this license the "Lesser" General Public License because it
|
|
||||||
does Less to protect the user's freedom than the ordinary General
|
|
||||||
Public License. It also provides other free software developers Less
|
|
||||||
of an advantage over competing non-free programs. These disadvantages
|
|
||||||
are the reason we use the ordinary General Public License for many
|
|
||||||
libraries. However, the Lesser license provides advantages in certain
|
|
||||||
special circumstances.
|
|
||||||
|
|
||||||
For example, on rare occasions, there may be a special need to
|
|
||||||
encourage the widest possible use of a certain library, so that it
|
|
||||||
becomes a de-facto standard. To achieve this, non-free programs must
|
|
||||||
be allowed to use the library. A more frequent case is that a free
|
|
||||||
library does the same job as widely used non-free libraries. In this
|
|
||||||
case, there is little to gain by limiting the free library to free
|
|
||||||
software only, so we use the Lesser General Public License.
|
|
||||||
|
|
||||||
In other cases, permission to use a particular library in non-free
|
|
||||||
programs enables a greater number of people to use a large body of
|
|
||||||
free software. For example, permission to use the GNU C Library in
|
|
||||||
non-free programs enables many more people to use the whole GNU
|
|
||||||
operating system, as well as its variant, the GNU/Linux operating
|
|
||||||
system.
|
|
||||||
|
|
||||||
Although the Lesser General Public License is Less protective of the
|
|
||||||
users' freedom, it does ensure that the user of a program that is
|
|
||||||
linked with the Library has the freedom and the wherewithal to run
|
|
||||||
that program using a modified version of the Library.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow. Pay close attention to the difference between a
|
|
||||||
"work based on the library" and a "work that uses the library". The
|
|
||||||
former contains code derived from the library, whereas the latter must
|
|
||||||
be combined with the library in order to run.
|
|
||||||
|
|
||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License Agreement applies to any software library or other
|
|
||||||
program which contains a notice placed by the copyright holder or
|
|
||||||
other authorized party saying it may be distributed under the terms of
|
|
||||||
this Lesser General Public License (also called "this License").
|
|
||||||
Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
A "library" means a collection of software functions and/or data
|
|
||||||
prepared so as to be conveniently linked with application programs
|
|
||||||
(which use some of those functions and data) to form executables.
|
|
||||||
|
|
||||||
The "Library", below, refers to any such software library or work
|
|
||||||
which has been distributed under these terms. A "work based on the
|
|
||||||
Library" means either the Library or any derivative work under
|
|
||||||
copyright law: that is to say, a work containing the Library or a
|
|
||||||
portion of it, either verbatim or with modifications and/or translated
|
|
||||||
straightforwardly into another language. (Hereinafter, translation is
|
|
||||||
included without limitation in the term "modification".)
|
|
||||||
|
|
||||||
"Source code" for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For a library, complete source code means
|
|
||||||
all the source code for all modules it contains, plus any associated
|
|
||||||
interface definition files, plus the scripts used to control
|
|
||||||
compilation and installation of the library.
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running a program using the Library is not restricted, and output from
|
|
||||||
such a program is covered only if its contents constitute a work based
|
|
||||||
on the Library (independent of the use of the Library in a tool for
|
|
||||||
writing it). Whether that is true depends on what the Library does
|
|
||||||
and what the program that uses the Library does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Library's
|
|
||||||
complete source code as you receive it, in any medium, provided that
|
|
||||||
you conspicuously and appropriately publish on each copy an
|
|
||||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
|
||||||
all the notices that refer to this License and to the absence of any
|
|
||||||
warranty; and distribute a copy of this License along with the
|
|
||||||
Library.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy,
|
|
||||||
and you may at your option offer warranty protection in exchange for a
|
|
||||||
fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Library or any portion
|
|
||||||
of it, thus forming a work based on the Library, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The modified work must itself be a software library.
|
|
||||||
|
|
||||||
b) You must cause the files modified to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
c) You must cause the whole of the work to be licensed at no
|
|
||||||
charge to all third parties under the terms of this License.
|
|
||||||
|
|
||||||
d) If a facility in the modified Library refers to a function or a
|
|
||||||
table of data to be supplied by an application program that uses
|
|
||||||
the facility, other than as an argument passed when the facility
|
|
||||||
is invoked, then you must make a good faith effort to ensure that,
|
|
||||||
in the event an application does not supply such function or
|
|
||||||
table, the facility still operates, and performs whatever part of
|
|
||||||
its purpose remains meaningful.
|
|
||||||
|
|
||||||
(For example, a function in a library to compute square roots has
|
|
||||||
a purpose that is entirely well-defined independent of the
|
|
||||||
application. Therefore, Subsection 2d requires that any
|
|
||||||
application-supplied function or table used by this function must
|
|
||||||
be optional: if the application does not supply it, the square
|
|
||||||
root function must still compute square roots.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Library,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Library, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote
|
|
||||||
it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Library.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Library
|
|
||||||
with the Library (or with a work based on the Library) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
|
||||||
License instead of this License to a given copy of the Library. To do
|
|
||||||
this, you must alter all the notices that refer to this License, so
|
|
||||||
that they refer to the ordinary GNU General Public License, version 2,
|
|
||||||
instead of to this License. (If a newer version than version 2 of the
|
|
||||||
ordinary GNU General Public License has appeared, then you can specify
|
|
||||||
that version instead if you wish.) Do not make any other change in
|
|
||||||
these notices.
|
|
||||||
|
|
||||||
Once this change is made in a given copy, it is irreversible for
|
|
||||||
that copy, so the ordinary GNU General Public License applies to all
|
|
||||||
subsequent copies and derivative works made from that copy.
|
|
||||||
|
|
||||||
This option is useful when you wish to copy part of the code of
|
|
||||||
the Library into a program that is not a library.
|
|
||||||
|
|
||||||
4. You may copy and distribute the Library (or a portion or
|
|
||||||
derivative of it, under Section 2) in object code or executable form
|
|
||||||
under the terms of Sections 1 and 2 above provided that you accompany
|
|
||||||
it with the complete corresponding machine-readable source code, which
|
|
||||||
must be distributed under the terms of Sections 1 and 2 above on a
|
|
||||||
medium customarily used for software interchange.
|
|
||||||
|
|
||||||
If distribution of object code is made by offering access to copy
|
|
||||||
from a designated place, then offering equivalent access to copy the
|
|
||||||
source code from the same place satisfies the requirement to
|
|
||||||
distribute the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
5. A program that contains no derivative of any portion of the
|
|
||||||
Library, but is designed to work with the Library by being compiled or
|
|
||||||
linked with it, is called a "work that uses the Library". Such a
|
|
||||||
work, in isolation, is not a derivative work of the Library, and
|
|
||||||
therefore falls outside the scope of this License.
|
|
||||||
|
|
||||||
However, linking a "work that uses the Library" with the Library
|
|
||||||
creates an executable that is a derivative of the Library (because it
|
|
||||||
contains portions of the Library), rather than a "work that uses the
|
|
||||||
library". The executable is therefore covered by this License.
|
|
||||||
Section 6 states terms for distribution of such executables.
|
|
||||||
|
|
||||||
When a "work that uses the Library" uses material from a header file
|
|
||||||
that is part of the Library, the object code for the work may be a
|
|
||||||
derivative work of the Library even though the source code is not.
|
|
||||||
Whether this is true is especially significant if the work can be
|
|
||||||
linked without the Library, or if the work is itself a library. The
|
|
||||||
threshold for this to be true is not precisely defined by law.
|
|
||||||
|
|
||||||
If such an object file uses only numerical parameters, data
|
|
||||||
structure layouts and accessors, and small macros and small inline
|
|
||||||
functions (ten lines or less in length), then the use of the object
|
|
||||||
file is unrestricted, regardless of whether it is legally a derivative
|
|
||||||
work. (Executables containing this object code plus portions of the
|
|
||||||
Library will still fall under Section 6.)
|
|
||||||
|
|
||||||
Otherwise, if the work is a derivative of the Library, you may
|
|
||||||
distribute the object code for the work under the terms of Section 6.
|
|
||||||
Any executables containing that work also fall under Section 6,
|
|
||||||
whether or not they are linked directly with the Library itself.
|
|
||||||
|
|
||||||
6. As an exception to the Sections above, you may also combine or
|
|
||||||
link a "work that uses the Library" with the Library to produce a
|
|
||||||
work containing portions of the Library, and distribute that work
|
|
||||||
under terms of your choice, provided that the terms permit
|
|
||||||
modification of the work for the customer's own use and reverse
|
|
||||||
engineering for debugging such modifications.
|
|
||||||
|
|
||||||
You must give prominent notice with each copy of the work that the
|
|
||||||
Library is used in it and that the Library and its use are covered by
|
|
||||||
this License. You must supply a copy of this License. If the work
|
|
||||||
during execution displays copyright notices, you must include the
|
|
||||||
copyright notice for the Library among them, as well as a reference
|
|
||||||
directing the user to the copy of this License. Also, you must do one
|
|
||||||
of these things:
|
|
||||||
|
|
||||||
a) Accompany the work with the complete corresponding
|
|
||||||
machine-readable source code for the Library including whatever
|
|
||||||
changes were used in the work (which must be distributed under
|
|
||||||
Sections 1 and 2 above); and, if the work is an executable linked
|
|
||||||
with the Library, with the complete machine-readable "work that
|
|
||||||
uses the Library", as object code and/or source code, so that the
|
|
||||||
user can modify the Library and then relink to produce a modified
|
|
||||||
executable containing the modified Library. (It is understood
|
|
||||||
that the user who changes the contents of definitions files in the
|
|
||||||
Library will not necessarily be able to recompile the application
|
|
||||||
to use the modified definitions.)
|
|
||||||
|
|
||||||
b) Use a suitable shared library mechanism for linking with the
|
|
||||||
Library. A suitable mechanism is one that (1) uses at run time a
|
|
||||||
copy of the library already present on the user's computer system,
|
|
||||||
rather than copying library functions into the executable, and (2)
|
|
||||||
will operate properly with a modified version of the library, if
|
|
||||||
the user installs one, as long as the modified version is
|
|
||||||
interface-compatible with the version that the work was made with.
|
|
||||||
|
|
||||||
c) Accompany the work with a written offer, valid for at least
|
|
||||||
three years, to give the same user the materials specified in
|
|
||||||
Subsection 6a, above, for a charge no more than the cost of
|
|
||||||
performing this distribution.
|
|
||||||
|
|
||||||
d) If distribution of the work is made by offering access to copy
|
|
||||||
from a designated place, offer equivalent access to copy the above
|
|
||||||
specified materials from the same place.
|
|
||||||
|
|
||||||
e) Verify that the user has already received a copy of these
|
|
||||||
materials or that you have already sent this user a copy.
|
|
||||||
|
|
||||||
For an executable, the required form of the "work that uses the
|
|
||||||
Library" must include any data and utility programs needed for
|
|
||||||
reproducing the executable from it. However, as a special exception,
|
|
||||||
the materials to be distributed need not include anything that is
|
|
||||||
normally distributed (in either source or binary form) with the major
|
|
||||||
components (compiler, kernel, and so on) of the operating system on
|
|
||||||
which the executable runs, unless that component itself accompanies
|
|
||||||
the executable.
|
|
||||||
|
|
||||||
It may happen that this requirement contradicts the license
|
|
||||||
restrictions of other proprietary libraries that do not normally
|
|
||||||
accompany the operating system. Such a contradiction means you cannot
|
|
||||||
use both them and the Library together in an executable that you
|
|
||||||
distribute.
|
|
||||||
|
|
||||||
7. You may place library facilities that are a work based on the
|
|
||||||
Library side-by-side in a single library together with other library
|
|
||||||
facilities not covered by this License, and distribute such a combined
|
|
||||||
library, provided that the separate distribution of the work based on
|
|
||||||
the Library and of the other library facilities is otherwise
|
|
||||||
permitted, and provided that you do these two things:
|
|
||||||
|
|
||||||
a) Accompany the combined library with a copy of the same work
|
|
||||||
based on the Library, uncombined with any other library
|
|
||||||
facilities. This must be distributed under the terms of the
|
|
||||||
Sections above.
|
|
||||||
|
|
||||||
b) Give prominent notice with the combined library of the fact
|
|
||||||
that part of it is a work based on the Library, and explaining
|
|
||||||
where to find the accompanying uncombined form of the same work.
|
|
||||||
|
|
||||||
8. You may not copy, modify, sublicense, link with, or distribute
|
|
||||||
the Library except as expressly provided under this License. Any
|
|
||||||
attempt otherwise to copy, modify, sublicense, link with, or
|
|
||||||
distribute the Library is void, and will automatically terminate your
|
|
||||||
rights under this License. However, parties who have received copies,
|
|
||||||
or rights, from you under this License will not have their licenses
|
|
||||||
terminated so long as such parties remain in full compliance.
|
|
||||||
|
|
||||||
9. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Library or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Library (or any work based on the
|
|
||||||
Library), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Library or works based on it.
|
|
||||||
|
|
||||||
10. Each time you redistribute the Library (or any work based on the
|
|
||||||
Library), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute, link with or modify the Library
|
|
||||||
subject to these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties with
|
|
||||||
this License.
|
|
||||||
|
|
||||||
11. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Library at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Library by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Library.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under
|
|
||||||
any particular circumstance, the balance of the section is intended to
|
|
||||||
apply, and the section as a whole is intended to apply in other
|
|
||||||
circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
12. If the distribution and/or use of the Library is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Library under this License
|
|
||||||
may add an explicit geographical distribution limitation excluding those
|
|
||||||
countries, so that distribution is permitted only in or among
|
|
||||||
countries not thus excluded. In such case, this License incorporates
|
|
||||||
the limitation as if written in the body of this License.
|
|
||||||
|
|
||||||
13. The Free Software Foundation may publish revised and/or new
|
|
||||||
versions of the Lesser 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 Library
|
|
||||||
specifies a version number of this License which applies to it and
|
|
||||||
"any later version", you have the option of following the terms and
|
|
||||||
conditions either of that version or of any later version published by
|
|
||||||
the Free Software Foundation. If the Library does not specify a
|
|
||||||
license version number, you may choose any version ever published by
|
|
||||||
the Free Software Foundation.
|
|
||||||
|
|
||||||
14. If you wish to incorporate parts of the Library into other free
|
|
||||||
programs whose distribution conditions are incompatible with these,
|
|
||||||
write to the author to ask for permission. For software which is
|
|
||||||
copyrighted by the Free Software Foundation, write to the Free
|
|
||||||
Software Foundation; we sometimes make exceptions for this. Our
|
|
||||||
decision will be guided by the two goals of preserving the free status
|
|
||||||
of all derivatives of our free software and of promoting the sharing
|
|
||||||
and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
|
||||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
|
||||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
|
||||||
OTHER PARTIES PROVIDE THE LIBRARY "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
|
|
||||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
|
||||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
|
||||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
|
||||||
AND/OR REDISTRIBUTE THE LIBRARY 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
|
|
||||||
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
|
||||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
||||||
DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Libraries
|
|
||||||
|
|
||||||
If you develop a new library, and you want it to be of the greatest
|
|
||||||
possible use to the public, we recommend making it free software that
|
|
||||||
everyone can redistribute and change. You can do so by permitting
|
|
||||||
redistribution under these terms (or, alternatively, under the terms
|
|
||||||
of the ordinary General Public License).
|
|
||||||
|
|
||||||
To apply these terms, attach the following notices to the library.
|
|
||||||
It is safest to attach them to the start of each source file to most
|
|
||||||
effectively convey the exclusion of warranty; and each file should
|
|
||||||
have at least the "copyright" line and a pointer to where the full
|
|
||||||
notice is found.
|
|
||||||
|
|
||||||
|
|
||||||
<one line to give the library's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or
|
|
||||||
your school, if any, to sign a "copyright disclaimer" for the library,
|
|
||||||
if necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
|
||||||
library `Frob' (a library for tweaking knobs) written by James
|
|
||||||
Random Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1990
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
That's all there is to it!
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
#! /bin/sh
|
|
||||||
$EXTRACTRC *.rc *.ui *.kcfg >> rc.cpp
|
|
||||||
$EXTRACTATTR --attr=constant,name scienceconstants.xml >>rc.cpp ||exit 11
|
|
||||||
$XGETTEXT *.cpp -o $podir/kcalc.pot
|
|
||||||
rm -f rc.cpp
|
|
|
@ -1,8 +0,0 @@
|
||||||
KCalc
|
|
||||||
=====
|
|
||||||
KCalc is currently covered under the GPL version 2. A copy of this
|
|
||||||
license can be found in a file named COPYING, in the toplevel directory.
|
|
||||||
|
|
||||||
Have fun with kcalc!
|
|
||||||
|
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2012 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 2006 Michel Marti
|
|
||||||
mma@objectxp.com
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bitbutton.h"
|
|
||||||
#include <QApplication>
|
|
||||||
|
|
||||||
#include "moc_bitbutton.cpp"
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: BitButton
|
|
||||||
// Desc: constructor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
BitButton::BitButton(QWidget *parent) : QAbstractButton(parent), on_(false) {
|
|
||||||
|
|
||||||
// too many bits for tab focus
|
|
||||||
setFocusPolicy(Qt::ClickFocus);
|
|
||||||
|
|
||||||
// size button by font
|
|
||||||
QSize size = fontMetrics().size(0, QLatin1String("M"));
|
|
||||||
|
|
||||||
if (size.width() < size.height()) {
|
|
||||||
size.setHeight(size.width());
|
|
||||||
} else {
|
|
||||||
size.setWidth(size.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
setFixedSize(size.expandedTo(QApplication::globalStrut()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: isOn
|
|
||||||
// Desc: returns true if this bit-button is "on"
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool BitButton::isOn() const {
|
|
||||||
|
|
||||||
return on_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setOn
|
|
||||||
// Desc: changes the "on" value for the bitset
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BitButton::setOn(bool value) {
|
|
||||||
|
|
||||||
on_ = value;
|
|
||||||
update();
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2012 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 2006 Michel Marti
|
|
||||||
mma@objectxp.com
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BITBUTTON_H_20120104_
|
|
||||||
#define BITBUTTON_H_20120104_
|
|
||||||
|
|
||||||
#include <QAbstractButton>
|
|
||||||
|
|
||||||
class BitButton : public QAbstractButton {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit BitButton(QWidget *parent = 0);
|
|
||||||
bool isOn() const;
|
|
||||||
void setOn(bool value);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void paintEvent(QPaintEvent *event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool on_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
275
kcalc/colors.ui
275
kcalc/colors.ui
|
@ -1,275 +0,0 @@
|
||||||
<ui version="4.0" >
|
|
||||||
<class>Colors</class>
|
|
||||||
<widget class="QWidget" name="Colors" >
|
|
||||||
<property name="geometry" >
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>240</width>
|
|
||||||
<height>344</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" >
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="displayColorsBox" >
|
|
||||||
<property name="title" >
|
|
||||||
<string>Display Colors</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QHBoxLayout" >
|
|
||||||
<item>
|
|
||||||
<layout class="QGridLayout" >
|
|
||||||
<item row="0" column="0" >
|
|
||||||
<widget class="QLabel" name="textLabel1" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Foreground:</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap" >
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>kcfg_ForeColor</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" >
|
|
||||||
<widget class="KColorButton" name="kcfg_ForeColor" >
|
|
||||||
<property name="text" >
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="color" >
|
|
||||||
<color>
|
|
||||||
<red>0</red>
|
|
||||||
<green>0</green>
|
|
||||||
<blue>0</blue>
|
|
||||||
</color>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0" >
|
|
||||||
<widget class="QLabel" name="textLabel2" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Background:</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap" >
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>kcfg_BackColor</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1" >
|
|
||||||
<widget class="KColorButton" name="kcfg_BackColor" >
|
|
||||||
<property name="text" >
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="color" >
|
|
||||||
<color>
|
|
||||||
<red>189</red>
|
|
||||||
<green>255</green>
|
|
||||||
<blue>180</blue>
|
|
||||||
</color>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" >
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="buttonColorsBox" >
|
|
||||||
<property name="title" >
|
|
||||||
<string>Button Colors</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QHBoxLayout" >
|
|
||||||
<item>
|
|
||||||
<layout class="QGridLayout" >
|
|
||||||
<item row="0" column="0" >
|
|
||||||
<widget class="QLabel" name="textLabel3" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Functions:</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap" >
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>kcfg_FunctionButtonsColor</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" >
|
|
||||||
<widget class="KColorButton" name="kcfg_FunctionButtonsColor" >
|
|
||||||
<property name="text" >
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0" >
|
|
||||||
<widget class="QLabel" name="textLabel4" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>St&atistic functions:</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap" >
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>kcfg_StatButtonsColor</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1" >
|
|
||||||
<widget class="KColorButton" name="kcfg_StatButtonsColor" >
|
|
||||||
<property name="text" >
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0" >
|
|
||||||
<widget class="QLabel" name="textLabel5" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>He&xadecimals:</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap" >
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>kcfg_HexButtonsColor</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1" >
|
|
||||||
<widget class="KColorButton" name="kcfg_HexButtonsColor" >
|
|
||||||
<property name="text" >
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0" >
|
|
||||||
<widget class="QLabel" name="textLabel6" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Numbers:</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap" >
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>kcfg_NumberButtonsColor</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1" >
|
|
||||||
<widget class="KColorButton" name="kcfg_NumberButtonsColor" >
|
|
||||||
<property name="text" >
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0" >
|
|
||||||
<widget class="QLabel" name="textLabel7" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Memory:</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap" >
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>kcfg_MemoryButtonsColor</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1" >
|
|
||||||
<widget class="KColorButton" name="kcfg_MemoryButtonsColor" >
|
|
||||||
<property name="text" >
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0" >
|
|
||||||
<widget class="QLabel" name="textLabel8" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>O&perations:</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap" >
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>kcfg_OperationButtonsColor</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="1" >
|
|
||||||
<widget class="KColorButton" name="kcfg_OperationButtonsColor" >
|
|
||||||
<property name="text" >
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" >
|
|
||||||
<size>
|
|
||||||
<width>31</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType" >
|
|
||||||
<enum>QSizePolicy::Expanding</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" >
|
|
||||||
<size>
|
|
||||||
<width>151</width>
|
|
||||||
<height>70</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>KColorButton</class>
|
|
||||||
<extends>QPushButton</extends>
|
|
||||||
<header>kcolorbutton.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<tabstops>
|
|
||||||
<tabstop>kcfg_ForeColor</tabstop>
|
|
||||||
<tabstop>kcfg_BackColor</tabstop>
|
|
||||||
<tabstop>kcfg_FunctionButtonsColor</tabstop>
|
|
||||||
<tabstop>kcfg_StatButtonsColor</tabstop>
|
|
||||||
<tabstop>kcfg_HexButtonsColor</tabstop>
|
|
||||||
<tabstop>kcfg_NumberButtonsColor</tabstop>
|
|
||||||
<tabstop>kcfg_MemoryButtonsColor</tabstop>
|
|
||||||
<tabstop>kcfg_OperationButtonsColor</tabstop>
|
|
||||||
</tabstops>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -1,5 +0,0 @@
|
||||||
/* The size of a `signed long', as computed by sizeof. */
|
|
||||||
#define SIZEOF_SIGNED_LONG ${SIZEOF_SIGNED_LONG}
|
|
||||||
|
|
||||||
/* The size of a `unsigned long', as computed by sizeof. */
|
|
||||||
#define SIZEOF_UNSIGNED_LONG ${SIZEOF_UNSIGNED_LONG}
|
|
|
@ -1,173 +0,0 @@
|
||||||
<ui version="4.0" >
|
|
||||||
<class>Constants</class>
|
|
||||||
<widget class="QWidget" name="Constants" >
|
|
||||||
<property name="geometry" >
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>185</width>
|
|
||||||
<height>273</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle" >
|
|
||||||
<string>Constants</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" >
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="constantsBox" >
|
|
||||||
<property name="title" >
|
|
||||||
<string>Constants</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" >
|
|
||||||
<item row="0" column="0" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_nameConstant0" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_valueConstant0" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>40</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="2" >
|
|
||||||
<widget class="QPushButton" name="pushButton0" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Predefined</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_nameConstant1" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_valueConstant1" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>40</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="2" >
|
|
||||||
<widget class="QPushButton" name="pushButton1" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Predefined</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_nameConstant2" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_valueConstant2" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>40</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="2" >
|
|
||||||
<widget class="QPushButton" name="pushButton2" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Predefined</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_nameConstant3" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_valueConstant3" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>40</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="2" >
|
|
||||||
<widget class="QPushButton" name="pushButton3" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Predefined</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_nameConstant4" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_valueConstant4" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>40</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="2" >
|
|
||||||
<widget class="QPushButton" name="pushButton4" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Predefined</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_nameConstant5" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="1" >
|
|
||||||
<widget class="QLineEdit" name="kcfg_valueConstant5" >
|
|
||||||
<property name="maxLength" >
|
|
||||||
<number>40</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="2" >
|
|
||||||
<widget class="QPushButton" name="pushButton5" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Predefined</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType" >
|
|
||||||
<enum>QSizePolicy::Expanding</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" >
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<includes>
|
|
||||||
<include location="local" >kpushbutton.h</include>
|
|
||||||
</includes>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -1,83 +0,0 @@
|
||||||
<ui version="4.0" >
|
|
||||||
<class>Fonts</class>
|
|
||||||
<widget class="QWidget" name="Fonts" >
|
|
||||||
<property name="geometry" >
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>288</width>
|
|
||||||
<height>74</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" >
|
|
||||||
<item>
|
|
||||||
<layout class="QFormLayout" name="formLayout" >
|
|
||||||
<property name="fieldGrowthPolicy" >
|
|
||||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0" >
|
|
||||||
<widget class="QLabel" name="buttonlabel" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Button font:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>kcfg_ButtonFont</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" >
|
|
||||||
<widget class="KFontRequester" name="kcfg_ButtonFont" >
|
|
||||||
<property name="focusPolicy" >
|
|
||||||
<enum>Qt::WheelFocus</enum>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip" >
|
|
||||||
<string>The font to use for the buttons</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0" >
|
|
||||||
<widget class="QLabel" name="displaylabel" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Display font:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>kcfg_DisplayFont</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1" >
|
|
||||||
<widget class="KFontRequester" name="kcfg_DisplayFont" >
|
|
||||||
<property name="focusPolicy" >
|
|
||||||
<enum>Qt::WheelFocus</enum>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip" >
|
|
||||||
<string>The font to use in the display</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer" >
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0" >
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>KFontRequester</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>kfontrequester.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
239
kcalc/general.ui
239
kcalc/general.ui
|
@ -1,239 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>General</class>
|
|
||||||
<widget class="QWidget" name="General">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>293</width>
|
|
||||||
<height>319</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>General</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="precisionGroupBox">
|
|
||||||
<property name="title">
|
|
||||||
<string>Precision</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QHBoxLayout">
|
|
||||||
<item>
|
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="textLabel1">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Maximum number of digits:</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>kcfg_Precision</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_Precision">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Maximum number of digits displayed</string>
|
|
||||||
</property>
|
|
||||||
<property name="whatsThis">
|
|
||||||
<string>KCalc can compute with many more digits than the number that fits on the display. This setting gives the maximum number of digits displayed, before KCalc starts using scientific notation, i.e. notation of the type 2.34e12.</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QCheckBox" name="kcfg_Fixed">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Whether to use fixed decimal places</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Set &decimal precision</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_FixedPrecision">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Number of fixed decimal digits</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="groupBox">
|
|
||||||
<property name="title">
|
|
||||||
<string>Grouping</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="_2">
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="kcfg_GroupDigits">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Whether to group digits</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Group digits</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="grouping_binary_lb">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Binary</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="grouping_octal_lb">
|
|
||||||
<property name="text">
|
|
||||||
<string>Octal</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="grouping_hexadecimal_lb">
|
|
||||||
<property name="text">
|
|
||||||
<string>Hexadecimal</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_BinaryGrouping"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_OctalGrouping"/>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_HexadecimalGrouping"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="miscGroupBox">
|
|
||||||
<property name="title">
|
|
||||||
<string>Misc</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout">
|
|
||||||
<item>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="kcfg_Beep">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Whether to beep on error</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>&Beep on error</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="kcfg_CaptionResult">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Whether to show the result in the window title</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Show &result in window title</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="kcfg_TwosComplement">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Whether to use Two's Complement for non-decimal numbers</string>
|
|
||||||
</property>
|
|
||||||
<property name="whatsThis">
|
|
||||||
<string>Select to use Two's Complement notation for Binary, Octal and Hexidecimal numbers. This is a common notation to represent negative numbers for non-decimal numbers in computers.</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Two's complement</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<tabstops>
|
|
||||||
<tabstop>kcfg_Precision</tabstop>
|
|
||||||
<tabstop>kcfg_Fixed</tabstop>
|
|
||||||
<tabstop>kcfg_FixedPrecision</tabstop>
|
|
||||||
</tabstops>
|
|
||||||
<connections>
|
|
||||||
<connection>
|
|
||||||
<sender>kcfg_Fixed</sender>
|
|
||||||
<signal>toggled(bool)</signal>
|
|
||||||
<receiver>kcfg_FixedPrecision</receiver>
|
|
||||||
<slot>setEnabled(bool)</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>97</x>
|
|
||||||
<y>76</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>256</x>
|
|
||||||
<y>94</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
</connections>
|
|
||||||
</ui>
|
|
2327
kcalc/kcalc.cpp
2327
kcalc/kcalc.cpp
File diff suppressed because it is too large
Load diff
|
@ -1,155 +0,0 @@
|
||||||
[Desktop Entry]
|
|
||||||
Name=KCalc
|
|
||||||
Name[af]=Kcalc
|
|
||||||
Name[ar]=حاسبة ك
|
|
||||||
Name[ast]=KCalc
|
|
||||||
Name[bg]=KCalc
|
|
||||||
Name[br]=KCalc
|
|
||||||
Name[bs]=KCalc
|
|
||||||
Name[ca]=KCalc
|
|
||||||
Name[ca@valencia]=KCalc
|
|
||||||
Name[cs]=KCalc
|
|
||||||
Name[cy]=KCalc
|
|
||||||
Name[da]=KCalc
|
|
||||||
Name[de]=KCalc
|
|
||||||
Name[el]=KCalc
|
|
||||||
Name[en_GB]=KCalc
|
|
||||||
Name[eo]=KCalc
|
|
||||||
Name[es]=KCalc
|
|
||||||
Name[et]=KCalc
|
|
||||||
Name[eu]=KCalc
|
|
||||||
Name[fi]=KCalc
|
|
||||||
Name[fr]=KCalc
|
|
||||||
Name[ga]=KCalc
|
|
||||||
Name[gl]=KCalc
|
|
||||||
Name[he]=KCalc
|
|
||||||
Name[hne]=के-केल्क
|
|
||||||
Name[hr]=KCalc
|
|
||||||
Name[hu]=KCalc
|
|
||||||
Name[ia]=KCalc
|
|
||||||
Name[id]=KCalc
|
|
||||||
Name[is]=KCalc
|
|
||||||
Name[it]=KCalc
|
|
||||||
Name[ja]=KCalc
|
|
||||||
Name[kk]=KCalc
|
|
||||||
Name[km]=KCalc
|
|
||||||
Name[ko]=KCalc
|
|
||||||
Name[lt]=KCalc
|
|
||||||
Name[lv]=KCalc
|
|
||||||
Name[mk]=KCalc
|
|
||||||
Name[mr]=के-कॅल्क
|
|
||||||
Name[ms]=KCalc
|
|
||||||
Name[nb]=KCalc
|
|
||||||
Name[nds]=KCalc
|
|
||||||
Name[ne]=केडीई क्याल्क
|
|
||||||
Name[nl]=KCalc
|
|
||||||
Name[nn]=KCalc
|
|
||||||
Name[pa]=ਕੇ-ਕੈਲਕ
|
|
||||||
Name[pl]=Kalkulator
|
|
||||||
Name[pt]=KCalc
|
|
||||||
Name[pt_BR]=KCalc
|
|
||||||
Name[ro]=KCalc
|
|
||||||
Name[ru]=KCalc
|
|
||||||
Name[sk]=KCalc
|
|
||||||
Name[sl]=KCalc
|
|
||||||
Name[sq]=KCalc
|
|
||||||
Name[sr]=К‑калк
|
|
||||||
Name[sr@ijekavian]=К‑калк
|
|
||||||
Name[sr@ijekavianlatin]=KCalc
|
|
||||||
Name[sr@latin]=KCalc
|
|
||||||
Name[sv]=Kcalc
|
|
||||||
Name[ta]=கேகணிப்பான்
|
|
||||||
Name[tg]=KМошинаи ҳисобкунак
|
|
||||||
Name[th]=เครื่องคิดเลข-K
|
|
||||||
Name[tr]=KCalc
|
|
||||||
Name[ug]=KCalc
|
|
||||||
Name[uk]=KCalc
|
|
||||||
Name[uz]=Kalkulyator
|
|
||||||
Name[uz@cyrillic]=Калкулятор
|
|
||||||
Name[vi]=KCalc
|
|
||||||
Name[wa]=KCalc
|
|
||||||
Name[x-test]=xxKCalcxx
|
|
||||||
Name[zh_CN]=KCalc
|
|
||||||
Name[zh_TW]=KDE 計算機
|
|
||||||
Exec=kcalc --icon '%i' --caption '%c'
|
|
||||||
Icon=accessories-calculator
|
|
||||||
X-DocPath=kcalc/index.html
|
|
||||||
GenericName=Scientific Calculator
|
|
||||||
GenericName[af]=Wetenskaplike Sakrekenaar
|
|
||||||
GenericName[ar]=آلة حاسبة علمية
|
|
||||||
GenericName[ast]=Calculadora Científica
|
|
||||||
GenericName[bg]=Калкулатор
|
|
||||||
GenericName[br]=Ur jederez skiantel
|
|
||||||
GenericName[bs]=Naučni kalkulator
|
|
||||||
GenericName[ca]=Calculadora científica
|
|
||||||
GenericName[ca@valencia]=Calculadora científica
|
|
||||||
GenericName[cs]=Vědecká kalkulačka
|
|
||||||
GenericName[cy]=Cyfrifydd Gwyddonol
|
|
||||||
GenericName[da]=Videnskabelig regnemaskine
|
|
||||||
GenericName[de]=Wissenschaftlicher Taschenrechner
|
|
||||||
GenericName[el]=Επιστημονικό κομπιουτεράκι
|
|
||||||
GenericName[en_GB]=Scientific Calculator
|
|
||||||
GenericName[eo]=Scienca kalkulilo
|
|
||||||
GenericName[es]=Calculadora científica
|
|
||||||
GenericName[et]=Teaduslik kalkulaator
|
|
||||||
GenericName[eu]=Kalkulagailu zientifikoa
|
|
||||||
GenericName[fa]=ماشین حساب علمی
|
|
||||||
GenericName[fi]=Tieteellinen laskin
|
|
||||||
GenericName[fr]=Calculatrice scientifique
|
|
||||||
GenericName[ga]=Áireamhán Eolaíochta
|
|
||||||
GenericName[gl]=Unha calculadora científica
|
|
||||||
GenericName[he]=מחשבון מדעי
|
|
||||||
GenericName[hne]=वैग्यानिक केल्कुलेटर
|
|
||||||
GenericName[hr]=Znanstveni kalkulator
|
|
||||||
GenericName[hu]=Tudományos számológép
|
|
||||||
GenericName[ia]=Calculator scientific
|
|
||||||
GenericName[id]=Kalkulator Ilmiah
|
|
||||||
GenericName[is]=Öflug reiknivél
|
|
||||||
GenericName[it]=Calcolatrice scientifica
|
|
||||||
GenericName[ja]=科学電卓
|
|
||||||
GenericName[kk]=Ғылыми калькулятор
|
|
||||||
GenericName[km]=ម៉ាស៊ីនគិតលេខវិទ្យាសាស្ត្រ
|
|
||||||
GenericName[ko]=공학용 계산기
|
|
||||||
GenericName[lt]=Mokslinis skaičiuotuvas
|
|
||||||
GenericName[lv]=Zinātniskais kalkulators
|
|
||||||
GenericName[mk]=Научен калкулатор
|
|
||||||
GenericName[mr]=शास्त्रीय गणकयंत्र
|
|
||||||
GenericName[ms]=Scientific Calculator
|
|
||||||
GenericName[nb]=Vitenskapelig kalkulator
|
|
||||||
GenericName[nds]=Wetenschaplich Taschenreekner
|
|
||||||
GenericName[ne]=वैज्ञानिक गणकयन्त्र
|
|
||||||
GenericName[nl]=Wetenschappelijke rekenmachine
|
|
||||||
GenericName[nn]=Vitskapleg kalkulator
|
|
||||||
GenericName[pa]=ਵਿਗਿਆਨਿਕ ਕੈਲਕੂਲੇਟਰ
|
|
||||||
GenericName[pl]=Kalkulator naukowy
|
|
||||||
GenericName[pt]=Calculadora Cientifica
|
|
||||||
GenericName[pt_BR]=Calculadora científica
|
|
||||||
GenericName[ro]=Calculator științific
|
|
||||||
GenericName[ru]=Калькулятор
|
|
||||||
GenericName[sk]=Vedecká kalkulačka
|
|
||||||
GenericName[sl]=Znanstveno računalo
|
|
||||||
GenericName[sq]=Makinë Llogaritëse Shkencore
|
|
||||||
GenericName[sr]=Научни калкулатор
|
|
||||||
GenericName[sr@ijekavian]=Научни калкулатор
|
|
||||||
GenericName[sr@ijekavianlatin]=Naučni kalkulator
|
|
||||||
GenericName[sr@latin]=Naučni kalkulator
|
|
||||||
GenericName[sv]=Vetenskaplig miniräknare
|
|
||||||
GenericName[ta]= அறிவியல் சார்ந்த கணிப்பான்
|
|
||||||
GenericName[tg]=Мошинаи ҳисобкунаки Илмӣ
|
|
||||||
GenericName[th]=เครื่องคิดเลขทางวิทยาศาสตร์
|
|
||||||
GenericName[tr]=Bilimsel Hesap Makinesi
|
|
||||||
GenericName[ug]=ئىلمىي ھېسابلىغۇچ
|
|
||||||
GenericName[uk]=Калькулятор для науковців
|
|
||||||
GenericName[uz]=Ilmiy kalkulyator
|
|
||||||
GenericName[uz@cyrillic]=Илмий калкулятор
|
|
||||||
GenericName[vi]=Máy Tính Khoa Học
|
|
||||||
GenericName[wa]=Carculete syintifike
|
|
||||||
GenericName[xh]=Umatshini Wokubala Ezenzululwazi
|
|
||||||
GenericName[x-test]=xxScientific Calculatorxx
|
|
||||||
GenericName[zh_CN]=科学计算器
|
|
||||||
GenericName[zh_TW]=科學計算機
|
|
||||||
Terminal=false
|
|
||||||
Type=Application
|
|
||||||
StartupNotify=true
|
|
||||||
X-KDE-HasTrayOption=true
|
|
||||||
Categories=Qt;KDE;Utility;X-KDE-Utilities-Desktop;
|
|
281
kcalc/kcalc.h
281
kcalc/kcalc.h
|
@ -1,281 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 1996 - 2000 Bernd Johannes Wuebben
|
|
||||||
wuebben@kde.org
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KCALC_H_
|
|
||||||
#define KCALC_H_
|
|
||||||
|
|
||||||
class Constants;
|
|
||||||
#include <QButtonGroup>
|
|
||||||
class KToggleAction;
|
|
||||||
class KCalcConstMenu;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Kcalc basically consist of a class for the GUI (here), a class for
|
|
||||||
the display (dlabel.h), and one for the mathematics core
|
|
||||||
(kcalc_core.h).
|
|
||||||
|
|
||||||
When for example '+' is pressed, one sends the contents of the
|
|
||||||
Display and the '+' to the core via "core.Plus(DISPLAY_AMOUNT)".
|
|
||||||
This only updates the core. To bring the changes to the display,
|
|
||||||
use afterwards "UpdateDisplay(true)".
|
|
||||||
|
|
||||||
"UpdateDisplay(true)" means that the amount to be displayed should
|
|
||||||
be taken from the core (get the result of some operation that was
|
|
||||||
performed), "UpdateDisplay(false)" has already the information, what
|
|
||||||
to be display (e.g. user is typing in a number). Note that in the
|
|
||||||
last case the core does not know the number typed in until some
|
|
||||||
operation button is pressed, e.g. "core.Plus(display_number)".
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "kcalc_core.h"
|
|
||||||
#include "kcalc_button.h"
|
|
||||||
#include "kcalc_const_button.h"
|
|
||||||
|
|
||||||
#include "ui_kcalc.h"
|
|
||||||
#include "ui_general.h"
|
|
||||||
#include "ui_fonts.h"
|
|
||||||
#include "ui_constants.h"
|
|
||||||
#include "ui_colors.h"
|
|
||||||
|
|
||||||
#include <QtCore/qglobal.h>
|
|
||||||
|
|
||||||
#include <kxmlguiwindow.h>
|
|
||||||
|
|
||||||
class General: public QWidget, public Ui::General
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit General(QWidget *parent) : QWidget(parent) {
|
|
||||||
setupUi(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Fonts: public QWidget, public Ui::Fonts
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit Fonts(QWidget *parent) : QWidget(parent) {
|
|
||||||
setupUi(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Constants : public QWidget, public Ui::Constants
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit Constants(QWidget *parent) : QWidget(parent) {
|
|
||||||
setupUi(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Colors : public QWidget, public Ui::Colors
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit Colors(QWidget *parent) : QWidget(parent) {
|
|
||||||
setupUi(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class KCalculator : public KXmlGuiWindow, private Ui::KCalculator
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit KCalculator(QWidget *parent = 0);
|
|
||||||
~KCalculator();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void switchShift(bool);
|
|
||||||
void switchMode(ButtonModeFlags, bool);
|
|
||||||
void switchShowAccels(bool);
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum UpdateFlag {
|
|
||||||
UPDATE_FROM_CORE = 1,
|
|
||||||
UPDATE_STORE_RESULT = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag)
|
|
||||||
|
|
||||||
private:
|
|
||||||
virtual bool eventFilter(QObject *o, QEvent *e);
|
|
||||||
void updateGeometry();
|
|
||||||
void setupMainActions();
|
|
||||||
void setupStatusbar();
|
|
||||||
void setupKeys();
|
|
||||||
void setupNumberKeys();
|
|
||||||
void setupRightKeypad();
|
|
||||||
void setupNumericKeypad();
|
|
||||||
void setupLogicKeys();
|
|
||||||
void setupScientificKeys();
|
|
||||||
void setupStatisticKeys();
|
|
||||||
void setupConstantsKeys();
|
|
||||||
void setupMiscKeys();
|
|
||||||
void keyPressEvent(QKeyEvent *e);
|
|
||||||
void keyReleaseEvent(QKeyEvent *e);
|
|
||||||
void setPrecision();
|
|
||||||
void setAngle();
|
|
||||||
void setBase();
|
|
||||||
|
|
||||||
void updateDisplay(UpdateFlags flags);
|
|
||||||
|
|
||||||
// button sets
|
|
||||||
void showMemButtons(bool toggled);
|
|
||||||
void showStatButtons(bool toggled);
|
|
||||||
void showScienceButtons(bool toggled);
|
|
||||||
void showLogicButtons(bool toggled);
|
|
||||||
|
|
||||||
KCalcConstMenu *createConstantsMenu();
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void changeButtonNames();
|
|
||||||
void updateSettings();
|
|
||||||
void setColors();
|
|
||||||
void setFonts();
|
|
||||||
void EnterEqual();
|
|
||||||
void showSettings();
|
|
||||||
|
|
||||||
// Mode
|
|
||||||
void slotSetSimpleMode();
|
|
||||||
void slotSetScienceMode();
|
|
||||||
void slotSetStatisticMode();
|
|
||||||
void slotSetNumeralMode();
|
|
||||||
|
|
||||||
void slotConstantsShow(bool toggled);
|
|
||||||
void slotBitsetshow(bool toggled);
|
|
||||||
void slotAngleSelected(int mode);
|
|
||||||
void slotBaseSelected(int base);
|
|
||||||
void slotNumberclicked(int number_clicked);
|
|
||||||
void slotEEclicked();
|
|
||||||
void slotShifttoggled(bool myboolean);
|
|
||||||
void slotMemRecallclicked();
|
|
||||||
void slotMemStoreclicked();
|
|
||||||
void slotSinclicked();
|
|
||||||
void slotPlusMinusclicked();
|
|
||||||
void slotMemPlusMinusclicked();
|
|
||||||
void slotCosclicked();
|
|
||||||
void slotReciclicked();
|
|
||||||
void slotTanclicked();
|
|
||||||
void slotFactorialclicked();
|
|
||||||
void slotLogclicked();
|
|
||||||
void slotSquareclicked();
|
|
||||||
void slotCubeclicked();
|
|
||||||
void slotLnclicked();
|
|
||||||
void slotPowerclicked();
|
|
||||||
void slotMemClearclicked();
|
|
||||||
void slotClearclicked();
|
|
||||||
void slotAllClearclicked();
|
|
||||||
void slotParenOpenclicked();
|
|
||||||
void slotParenCloseclicked();
|
|
||||||
void slotANDclicked();
|
|
||||||
void slotMultiplicationclicked();
|
|
||||||
void slotDivisionclicked();
|
|
||||||
void slotORclicked();
|
|
||||||
void slotXORclicked();
|
|
||||||
void slotPlusclicked();
|
|
||||||
void slotMinusclicked();
|
|
||||||
void slotLeftShiftclicked();
|
|
||||||
void slotRightShiftclicked();
|
|
||||||
void slotPeriodclicked();
|
|
||||||
void slotEqualclicked();
|
|
||||||
void slotPercentclicked();
|
|
||||||
void slotNegateclicked();
|
|
||||||
void slotModclicked();
|
|
||||||
void slotStatNumclicked();
|
|
||||||
void slotStatMeanclicked();
|
|
||||||
void slotStatStdDevclicked();
|
|
||||||
void slotStatMedianclicked();
|
|
||||||
void slotStatDataInputclicked();
|
|
||||||
void slotStatClearDataclicked();
|
|
||||||
void slotHyptoggled(bool flag);
|
|
||||||
void slotConstclicked(int);
|
|
||||||
void slotBackspaceclicked();
|
|
||||||
|
|
||||||
void slotConstantToDisplay(const science_constant &const_chosen);
|
|
||||||
void slotChooseScientificConst0(const science_constant &);
|
|
||||||
void slotChooseScientificConst1(const science_constant &);
|
|
||||||
void slotChooseScientificConst2(const science_constant &);
|
|
||||||
void slotChooseScientificConst3(const science_constant &);
|
|
||||||
void slotChooseScientificConst4(const science_constant &);
|
|
||||||
void slotChooseScientificConst5(const science_constant &);
|
|
||||||
|
|
||||||
void slotBitsetChanged(quint64);
|
|
||||||
void slotUpdateBitset(const KNumber &);
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum StatusField {
|
|
||||||
ShiftField = 0,
|
|
||||||
BaseField,
|
|
||||||
AngleField,
|
|
||||||
MemField
|
|
||||||
};
|
|
||||||
|
|
||||||
enum AngleMode {
|
|
||||||
DegMode = 0,
|
|
||||||
RadMode,
|
|
||||||
GradMode
|
|
||||||
};
|
|
||||||
|
|
||||||
enum BaseMode {
|
|
||||||
BinMode = 2,
|
|
||||||
OctMode = 8,
|
|
||||||
DecMode = 10,
|
|
||||||
HexMode = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool shift_mode_;
|
|
||||||
bool hyp_mode_;
|
|
||||||
KNumber memory_num_;
|
|
||||||
|
|
||||||
int angle_mode_; // angle modes for trigonometric values
|
|
||||||
|
|
||||||
KCalcConstMenu* constants_menu_;
|
|
||||||
|
|
||||||
Constants* constants_; // this is the dialog for configuring const buttons
|
|
||||||
|
|
||||||
QButtonGroup* angle_choose_group_;
|
|
||||||
QButtonGroup* base_choose_group_;
|
|
||||||
// num_button_group_: 0-9 = digits, 0xA-0xF = hex-keys
|
|
||||||
QButtonGroup* num_button_group_;
|
|
||||||
|
|
||||||
QList<QAbstractButton*> logic_buttons_;
|
|
||||||
QList<QAbstractButton*> scientific_buttons_;
|
|
||||||
QList<QAbstractButton*> stat_buttons_;
|
|
||||||
QList<QAbstractButton*> const_buttons_;
|
|
||||||
|
|
||||||
KToggleAction *action_bitset_show_;
|
|
||||||
KToggleAction *action_constants_show_;
|
|
||||||
|
|
||||||
KToggleAction *action_mode_simple_;
|
|
||||||
KToggleAction *action_mode_science_;
|
|
||||||
KToggleAction *action_mode_statistic_;
|
|
||||||
KToggleAction *action_mode_numeral_;
|
|
||||||
|
|
||||||
QList<QAbstractButton*> function_button_list_;
|
|
||||||
QList<QAbstractButton*> stat_button_list_;
|
|
||||||
QList<QAbstractButton*> mem_button_list_;
|
|
||||||
QList<QAbstractButton*> operation_button_list_;
|
|
||||||
|
|
||||||
CalcEngine core;
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(KCalculator::UpdateFlags)
|
|
||||||
|
|
||||||
#endif
|
|
201
kcalc/kcalc.kcfg
201
kcalc/kcalc.kcfg
|
@ -1,201 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
|
|
||||||
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
|
|
||||||
<include>KApplication</include>
|
|
||||||
<include>KGlobalSettings</include>
|
|
||||||
<include>KColorScheme</include>
|
|
||||||
<include>KLocale</include>
|
|
||||||
<kcfgfile name="kcalcrc"/>
|
|
||||||
<group name="Colors">
|
|
||||||
<entry name="ForeColor" type="Color">
|
|
||||||
<label>The foreground color of the display.</label>
|
|
||||||
<code>KColorScheme schemeView(QPalette::Active, KColorScheme::View);
|
|
||||||
QColor defaultColor = schemeView.foreground().color();</code>
|
|
||||||
<default code="true">defaultColor</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="BackColor" type="Color">
|
|
||||||
<label>The background color of the display.</label>
|
|
||||||
<code>defaultColor = schemeView.background().color();</code>
|
|
||||||
<default code="true">defaultColor</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="NumberButtonsColor" type="Color">
|
|
||||||
<label>The color of number buttons.</label>
|
|
||||||
<code>KColorScheme schemeButtons(QPalette::Active, KColorScheme::Button);
|
|
||||||
QColor defaultButtonColor = schemeButtons.background().color();</code>
|
|
||||||
<default code="true">defaultButtonColor</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="FunctionButtonsColor" type="Color">
|
|
||||||
<label>The color of function buttons.</label>
|
|
||||||
<default code="true">defaultButtonColor</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="StatButtonsColor" type="Color">
|
|
||||||
<label>The color of statistical buttons.</label>
|
|
||||||
<default code="true">defaultButtonColor</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="HexButtonsColor" type="Color">
|
|
||||||
<label>The color of hex buttons.</label>
|
|
||||||
<default code="true">defaultButtonColor</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="MemoryButtonsColor" type="Color">
|
|
||||||
<label>The color of memory buttons.</label>
|
|
||||||
<default code="true">defaultButtonColor</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="OperationButtonsColor" type="Color">
|
|
||||||
<label>The color of operation buttons.</label>
|
|
||||||
<default code="true">defaultButtonColor</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
<group name="Font">
|
|
||||||
<entry name="ButtonFont" type="Font">
|
|
||||||
<label>The font to use for the buttons.</label>
|
|
||||||
<default code="true">KGlobalSettings::generalFont()</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="DisplayFont" type="Font">
|
|
||||||
<label>The font to use in the display.</label>
|
|
||||||
<default code="true">QFont(KGlobalSettings::generalFont().family(), 14, QFont::Bold)</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
<group name="Precision">
|
|
||||||
<entry name="Precision" type="UInt" key="precision">
|
|
||||||
<label>Maximum number of digits displayed.</label>
|
|
||||||
<whatsthis>
|
|
||||||
KCalc can compute with many more digits than the number that
|
|
||||||
fits on the display. This setting gives the maximum number of
|
|
||||||
digits displayed, before KCalc starts using scientific notation,
|
|
||||||
i.e. notation of the type 2.34e12.
|
|
||||||
</whatsthis>
|
|
||||||
<default>12</default>
|
|
||||||
<min>8</min>
|
|
||||||
<max>200</max>
|
|
||||||
</entry>
|
|
||||||
<entry name="FixedPrecision" type="UInt" key="fixedprecision">
|
|
||||||
<label>Number of fixed decimal digits.</label>
|
|
||||||
<default>2</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="Fixed" type="Bool" key="fixed">
|
|
||||||
<label>Whether to use fixed decimal places.</label>
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
<group name="General">
|
|
||||||
<entry name="Beep" type="Bool" key="beep">
|
|
||||||
<label>Whether to beep on error.</label>
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="CaptionResult" type="Bool" key="captionresult">
|
|
||||||
<label>Whether to show the result in the window title.</label>
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="GroupDigits" type="Bool" key="groupdigits">
|
|
||||||
<label>Whether to group digits.</label>
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="TwosComplement" type="Bool" key="twoscomplement">
|
|
||||||
<label>Whether to use Two's Complement for non-decimal numbers.</label>
|
|
||||||
<whatsthis>
|
|
||||||
Select to use Two's Complement notation for Binary, Octal
|
|
||||||
and Hexidecimal numbers. This is a common notation to represent
|
|
||||||
negative numbers in computers.
|
|
||||||
</whatsthis>
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="CalculatorMode" type="Enum">
|
|
||||||
<choices>
|
|
||||||
<choice name="simple">
|
|
||||||
<label>Easy Calculator Mode</label>
|
|
||||||
<whatsthis>A very simple mode where only the basic calculator buttons are shown</whatsthis>
|
|
||||||
</choice>
|
|
||||||
<choice name="science">
|
|
||||||
<label>Science Calculator Mode</label>
|
|
||||||
<whatsthis>Mode with science buttons and optional constants buttons</whatsthis>
|
|
||||||
</choice>
|
|
||||||
<choice name="statistics">
|
|
||||||
<label>Statistic Calculator Mode</label>
|
|
||||||
<whatsthis>Mode with additional statistics buttons and optional constants buttons</whatsthis>
|
|
||||||
</choice>
|
|
||||||
<choice name="numeral">
|
|
||||||
<label>Numeral System Mode</label>
|
|
||||||
<whatsthis>Mode with logic buttons and selectable base. Optional bit edit available.</whatsthis>
|
|
||||||
</choice>
|
|
||||||
</choices>
|
|
||||||
</entry>
|
|
||||||
<entry name="ShowBitset" type="Bool">
|
|
||||||
<label>Whether to show the bit edit widget.</label>
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="ShowConstants" type="Bool">
|
|
||||||
<label>Whether to show constant buttons.</label>
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="AngleMode" type="UInt">
|
|
||||||
<label>Degrees, radians or grads</label>
|
|
||||||
<default>0</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="BaseMode" type="UInt">
|
|
||||||
<label>Numeric base</label>
|
|
||||||
<default>10</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
<group name="Grouping">
|
|
||||||
<entry name="BinaryGrouping" type="UInt" key="binaryGrouping">
|
|
||||||
<label>Binary figures will be separated by a whitespace after every Xth digit.</label>
|
|
||||||
<whatsthis>
|
|
||||||
For easier readability it's possible to visible group the individual digits into pairs
|
|
||||||
for example instead of 10111001 you can display 1011 1001, by setting the setting to
|
|
||||||
4, thus inserting a whitespace after every 4th digit.
|
|
||||||
</whatsthis>
|
|
||||||
<default>4</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="OctalGrouping" type="UInt" key="octalGrouping">
|
|
||||||
<label>Octal figures will be separated by a whitespace after every Xth digit.</label>
|
|
||||||
<whatsthis>
|
|
||||||
For easier readability it's possible to visible group the individual digits into pairs
|
|
||||||
for example instead of 42140213 you can display 4214 0213, by setting the setting to
|
|
||||||
4, thus inserting a whitespace after every 4th digit.
|
|
||||||
</whatsthis>
|
|
||||||
<default>4</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="HexadecimalGrouping" type="UInt" key="hexadecimalGrouping">
|
|
||||||
<label>Hexadecimal figures will be separated by a whitespace after every Xth digit.</label>
|
|
||||||
<whatsthis>
|
|
||||||
For easier readability it's possible to visible group the individual digits into pairs
|
|
||||||
for example instead of AF1C42 you can display AF 1C 42, by setting the setting to
|
|
||||||
2, thus inserting a whitespace after every 2nd digit.
|
|
||||||
</whatsthis>
|
|
||||||
<default>2</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
<group name="UserConstants">
|
|
||||||
<entry name="nameConstant$(ConstIndex)" type="String" key="nameConstant$(ConstIndex)">
|
|
||||||
<label>Name of the user programmable constants.</label>
|
|
||||||
<parameter name="ConstIndex" type="Int" max="5"/>
|
|
||||||
<code>
|
|
||||||
QString nameConstant0 = i18nc("Name of the user programmable constant", "C1");
|
|
||||||
QString nameConstant1 = i18nc("Name of the user programmable constant", "C2");
|
|
||||||
QString nameConstant2 = i18nc("Name of the user programmable constant", "C3");
|
|
||||||
QString nameConstant3 = i18nc("Name of the user programmable constant", "C4");
|
|
||||||
QString nameConstant4 = i18nc("Name of the user programmable constant", "C5");
|
|
||||||
QString nameConstant5 = i18nc("Name of the user programmable constant", "C6");
|
|
||||||
</code>
|
|
||||||
<default param="0" code="true">nameConstant0</default>
|
|
||||||
<default param="1" code="true">nameConstant1</default>
|
|
||||||
<default param="2" code="true">nameConstant2</default>
|
|
||||||
<default param="3" code="true">nameConstant3</default>
|
|
||||||
<default param="4" code="true">nameConstant4</default>
|
|
||||||
<default param="5" code="true">nameConstant5</default>
|
|
||||||
</entry>
|
|
||||||
|
|
||||||
<entry name="valueConstant$(ConstIndex)" type="String" key="valueConstant$(ConstIndex)">
|
|
||||||
<label>List of user programmable constants</label>
|
|
||||||
<parameter name="ConstIndex" type="Int" max="5"/>
|
|
||||||
<default param="0">0</default>
|
|
||||||
<default param="1">0</default>
|
|
||||||
<default param="2">0</default>
|
|
||||||
<default param="3">0</default>
|
|
||||||
<default param="4">0</default>
|
|
||||||
<default param="5">0</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
</kcfg>
|
|
1093
kcalc/kcalc.ui
1093
kcalc/kcalc.ui
File diff suppressed because it is too large
Load diff
|
@ -1,146 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2012 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 2006 Michel Marti
|
|
||||||
mma@objectxp.com
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "kcalc_bitset.h"
|
|
||||||
#include "bitbutton.h"
|
|
||||||
|
|
||||||
#include <QButtonGroup>
|
|
||||||
#include <QGridLayout>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QPen>
|
|
||||||
|
|
||||||
#include "moc_kcalc_bitset.cpp"
|
|
||||||
|
|
||||||
// TODO: I think it would actually be appropriate to use a std::bitset<64>
|
|
||||||
// for the internal representation of this class perhaps
|
|
||||||
// the only real caveat is the conversion to/from quint64
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: paintEvent
|
|
||||||
// Desc: draws the button
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BitButton::paintEvent(QPaintEvent *) {
|
|
||||||
|
|
||||||
QPainter painter(this);
|
|
||||||
QPen pen(palette().text(), 2);
|
|
||||||
pen.setJoinStyle(Qt::MiterJoin);
|
|
||||||
painter.setPen(pen);
|
|
||||||
|
|
||||||
if (on_) {
|
|
||||||
painter.setBrush(palette().text());
|
|
||||||
} else {
|
|
||||||
painter.setBrush(palette().base());
|
|
||||||
}
|
|
||||||
|
|
||||||
painter.drawRect(rect().adjusted(1, 1, -1, -1));
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KCalcBitset
|
|
||||||
// Desc: constructor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KCalcBitset::KCalcBitset(QWidget *parent) : QFrame(parent), value_(0) {
|
|
||||||
|
|
||||||
setFrameStyle(QFrame::Panel | QFrame::Sunken);
|
|
||||||
|
|
||||||
bit_button_group_ = new QButtonGroup(this);
|
|
||||||
connect(bit_button_group_, SIGNAL(buttonClicked(int)), SLOT(slotToggleBit(int)));
|
|
||||||
|
|
||||||
// smaller label font
|
|
||||||
QFont fnt = font();
|
|
||||||
if (fnt.pointSize() > 6) {
|
|
||||||
fnt.setPointSize(fnt.pointSize() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// main layout
|
|
||||||
QGridLayout *layout = new QGridLayout(this);
|
|
||||||
layout->setMargin(2);
|
|
||||||
layout->setSpacing(0);
|
|
||||||
|
|
||||||
// create bits
|
|
||||||
int bitCounter = 63;
|
|
||||||
for (int rows = 0; rows < 2; rows++) {
|
|
||||||
for (int cols = 0; cols < 4; cols++) {
|
|
||||||
// two rows of four words
|
|
||||||
QHBoxLayout *const wordlayout = new QHBoxLayout();
|
|
||||||
wordlayout->setMargin(2);
|
|
||||||
wordlayout->setSpacing(2);
|
|
||||||
layout->addLayout(wordlayout, rows, cols);
|
|
||||||
|
|
||||||
for (int bit = 0; bit < 8; bit++) {
|
|
||||||
BitButton *const tmpBitButton = new BitButton(this);
|
|
||||||
wordlayout->addWidget(tmpBitButton);
|
|
||||||
bit_button_group_->addButton(tmpBitButton, bitCounter);
|
|
||||||
bitCounter--;
|
|
||||||
}
|
|
||||||
|
|
||||||
// label word
|
|
||||||
QLabel *label = new QLabel(this);
|
|
||||||
label->setText(QString::number(bitCounter + 1));
|
|
||||||
label->setFont(fnt);
|
|
||||||
wordlayout->addWidget(label);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setValue
|
|
||||||
// Desc: set the value of the bitset based on an unsigned 64-bit number
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcBitset::setValue(quint64 value) {
|
|
||||||
|
|
||||||
if (value_ == value) {
|
|
||||||
// don't waste time if there was no change..
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_ = value;
|
|
||||||
|
|
||||||
// set each bit button
|
|
||||||
for (int i = 0; i < 64; i++) {
|
|
||||||
if(BitButton *bb = qobject_cast<BitButton*>(bit_button_group_->button(i))) {
|
|
||||||
bb->setOn(value & 1);
|
|
||||||
}
|
|
||||||
value >>= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: getValue
|
|
||||||
// Desc: returns the bitset value as an unsigned 64-bit number
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
quint64 KCalcBitset::getValue() const {
|
|
||||||
return value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotToggleBit
|
|
||||||
// Desc: inverts the value of a single bit
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcBitset::slotToggleBit(int bit) {
|
|
||||||
|
|
||||||
const quint64 nv = getValue() ^(1LL << bit);
|
|
||||||
setValue(nv);
|
|
||||||
emit valueChanged(value_);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2012 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 2006 Michel Marti
|
|
||||||
mma@objectxp.com
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KCALC_BITSET_H_
|
|
||||||
#define KCALC_BITSET_H_
|
|
||||||
|
|
||||||
#include <QFrame>
|
|
||||||
|
|
||||||
#include <QButtonGroup>
|
|
||||||
|
|
||||||
class KCalcBitset : public QFrame {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit KCalcBitset(QWidget *parent = 0);
|
|
||||||
quint64 getValue() const;
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void setValue(quint64 value);
|
|
||||||
void slotToggleBit(int bit);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void valueChanged(quint64 value);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QButtonGroup *bit_button_group_;
|
|
||||||
quint64 value_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,249 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 1996 - 2000 Bernd Johannes Wuebben
|
|
||||||
wuebben@kde.org
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "kcalc_button.h"
|
|
||||||
|
|
||||||
#include <QAbstractTextDocumentLayout>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QtGui/qstyleoption.h>
|
|
||||||
#include <QStylePainter>
|
|
||||||
#include <QTextDocument>
|
|
||||||
|
|
||||||
#include "moc_kcalc_button.cpp"
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KCalcButton
|
|
||||||
// Desc: constructor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KCalcButton::KCalcButton(QWidget *parent) : KPushButton(parent), show_shortcut_mode_(false), mode_flags_(ModeNormal), size_() {
|
|
||||||
|
|
||||||
setAcceptDrops(true); // allow color drops
|
|
||||||
setFocusPolicy(Qt::TabFocus);
|
|
||||||
setAutoDefault(false);
|
|
||||||
|
|
||||||
// use preferred size policy for vertical
|
|
||||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KCalcButton
|
|
||||||
// Desc: constructor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KCalcButton::KCalcButton(const QString &label, QWidget *parent, const QString &tooltip) : KPushButton(label, parent), show_shortcut_mode_(false), mode_flags_(ModeNormal), size_() {
|
|
||||||
|
|
||||||
setAutoDefault(false);
|
|
||||||
addMode(ModeNormal, label, tooltip);
|
|
||||||
|
|
||||||
// use preferred size policy for vertical
|
|
||||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: addMode
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcButton::addMode(ButtonModeFlags mode, const QString &label, const QString &tooltip) {
|
|
||||||
|
|
||||||
if (mode_.contains(mode)) {
|
|
||||||
mode_.remove(mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
mode_[mode] = ButtonMode(label, tooltip);
|
|
||||||
calcSizeHint();
|
|
||||||
|
|
||||||
// Need to put each button into default mode first
|
|
||||||
if (mode == ModeNormal) {
|
|
||||||
slotSetMode(ModeNormal, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotSetMode
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcButton::slotSetMode(ButtonModeFlags mode, bool flag) {
|
|
||||||
|
|
||||||
ButtonModeFlags new_mode;
|
|
||||||
|
|
||||||
if (flag) { // if the specified mode is to be set (i.e. flag = true)
|
|
||||||
new_mode = ButtonModeFlags(mode_flags_ | mode);
|
|
||||||
} else if (mode_flags_ && mode) { // if the specified mode is to be cleared (i.e. flag = false)
|
|
||||||
new_mode = ButtonModeFlags(mode_flags_ - mode);
|
|
||||||
} else {
|
|
||||||
return; // nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode_.contains(new_mode)) {
|
|
||||||
// save shortcut, because setting label erases it
|
|
||||||
QKeySequence current_shortcut = shortcut();
|
|
||||||
|
|
||||||
setText(mode_[new_mode].label);
|
|
||||||
this->setToolTip(mode_[new_mode].tooltip);
|
|
||||||
mode_flags_ = new_mode;
|
|
||||||
|
|
||||||
// restore shortcut
|
|
||||||
setShortcut(current_shortcut);
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is necessary for people pressing CTRL and changing mode at
|
|
||||||
// the same time...
|
|
||||||
if (show_shortcut_mode_) {
|
|
||||||
slotSetAccelDisplayMode(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotSetAccelDisplayMode
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcButton::slotSetAccelDisplayMode(bool flag) {
|
|
||||||
|
|
||||||
show_shortcut_mode_ = flag;
|
|
||||||
|
|
||||||
// save shortcut, because setting label erases it
|
|
||||||
QKeySequence current_shortcut = shortcut();
|
|
||||||
|
|
||||||
if (flag) {
|
|
||||||
setText(shortcut().toString());
|
|
||||||
} else {
|
|
||||||
setText(mode_[mode_flags_].label);
|
|
||||||
}
|
|
||||||
|
|
||||||
// restore shortcut
|
|
||||||
setShortcut(current_shortcut);
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: paintEvent
|
|
||||||
// Desc: draws the button
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcButton::paintEvent(QPaintEvent *) {
|
|
||||||
|
|
||||||
QPainter p(this);
|
|
||||||
QStyleOptionButton option;
|
|
||||||
initStyleOption(&option);
|
|
||||||
const bool is_down = isDown() || isChecked();
|
|
||||||
const int x_offset = is_down ? style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal, &option, this) : 0;
|
|
||||||
const int y_offset = is_down ? style()->pixelMetric(QStyle::PM_ButtonShiftVertical, &option, this) : 0;
|
|
||||||
|
|
||||||
// draw bevel
|
|
||||||
style()->drawControl(QStyle::CE_PushButtonBevel, &option, &p, this);
|
|
||||||
|
|
||||||
// draw label...
|
|
||||||
p.save();
|
|
||||||
|
|
||||||
// rant: Qt4 needs QSimpleRichText, dammit!
|
|
||||||
QTextDocument doc;
|
|
||||||
QAbstractTextDocumentLayout::PaintContext context;
|
|
||||||
doc.setHtml(QLatin1String("<center>") + text() + QLatin1String("</center>"));
|
|
||||||
doc.setDefaultFont(font());
|
|
||||||
context.palette = palette();
|
|
||||||
context.palette.setColor(QPalette::Text, context.palette.buttonText().color());
|
|
||||||
|
|
||||||
p.translate((width() / 2 - doc.size().width() / 2) + x_offset, (height() / 2 - doc.size().height() / 2) + y_offset);
|
|
||||||
doc.documentLayout()->draw(&p, context);
|
|
||||||
p.restore();
|
|
||||||
|
|
||||||
// draw focus
|
|
||||||
if (hasFocus()) {
|
|
||||||
QStyleOptionFocusRect fropt;
|
|
||||||
fropt.QStyleOption::operator=(option);
|
|
||||||
fropt.rect = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &option, this);
|
|
||||||
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &fropt, &p, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sizeHint
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QSize KCalcButton::sizeHint() const {
|
|
||||||
// reimplemented to provide a smaller button
|
|
||||||
return size_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: calcSizeHint
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcButton::calcSizeHint() {
|
|
||||||
|
|
||||||
int margin = style()->pixelMetric(QStyle::PM_ButtonMargin, 0, this);
|
|
||||||
|
|
||||||
// want narrow margin than normal
|
|
||||||
margin = qMax(margin / 2, 3);
|
|
||||||
|
|
||||||
// approximation because metrics doesn't account for richtext
|
|
||||||
size_ = fontMetrics().size(0, mode_[ModeNormal].label);
|
|
||||||
if (mode_.contains(ModeShift)) {
|
|
||||||
size_ = size_.expandedTo(fontMetrics().size(0, mode_[ModeShift].label));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode_.contains(ModeHyperbolic)) {
|
|
||||||
size_ = size_.expandedTo(fontMetrics().size(0, mode_[ModeHyperbolic].label));
|
|
||||||
}
|
|
||||||
|
|
||||||
size_ += QSize(margin * 2, margin * 2);
|
|
||||||
size_ = size_.expandedTo(QApplication::globalStrut());
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setFont
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcButton::setFont(const QFont &fnt) {
|
|
||||||
|
|
||||||
KPushButton::setFont(fnt);
|
|
||||||
calcSizeHint();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setText
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcButton::setText(const QString &text) {
|
|
||||||
|
|
||||||
KPushButton::setText(text);
|
|
||||||
|
|
||||||
// normal mode may not have been explicitly set
|
|
||||||
if (mode_[ModeNormal].label.isEmpty()) {
|
|
||||||
mode_[ModeNormal].label = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
calcSizeHint();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setToolTip
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcButton::setToolTip(const QString &tip) {
|
|
||||||
|
|
||||||
KPushButton::setToolTip(tip);
|
|
||||||
|
|
||||||
// normal mode may not have been explicitly set
|
|
||||||
if (mode_[ModeNormal].tooltip.isEmpty()) {
|
|
||||||
mode_[ModeNormal].tooltip = tip;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,92 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 2003 - 2005 Klaus Niederkrueger
|
|
||||||
kniederk@math.uni-koeln.de
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KCALC_BUTTON_H_
|
|
||||||
#define KCALC_BUTTON_H_
|
|
||||||
|
|
||||||
#include <QMap>
|
|
||||||
#include <kpushbutton.h>
|
|
||||||
|
|
||||||
// The class KCalcButton is an overridden KPushButton. It offers extra
|
|
||||||
// functionality e.g. text can be richtext, and the button can be
|
|
||||||
// told to display its shortcuts in the label, but the most important
|
|
||||||
// thing is that the button may have several modes with corresponding
|
|
||||||
// labels and tooltips. When one switches modes, the corresponding
|
|
||||||
// label is displayed.
|
|
||||||
|
|
||||||
|
|
||||||
enum ButtonModeFlags {
|
|
||||||
ModeNormal = 0,
|
|
||||||
ModeShift = 1,
|
|
||||||
ModeHyperbolic = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Each kcalc button can be in one of several modes.
|
|
||||||
// The following class describes label, tooltip etc. for each mode...
|
|
||||||
class ButtonMode {
|
|
||||||
public:
|
|
||||||
ButtonMode() {
|
|
||||||
}
|
|
||||||
|
|
||||||
ButtonMode(const QString &label, const QString &tooltip) : label(label), tooltip(tooltip) {
|
|
||||||
}
|
|
||||||
|
|
||||||
QString label;
|
|
||||||
QString tooltip;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class KCalcButton : public KPushButton {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit KCalcButton(QWidget *parent);
|
|
||||||
KCalcButton(const QString &label, QWidget *parent,
|
|
||||||
const QString &tooltip = QString());
|
|
||||||
|
|
||||||
void addMode(ButtonModeFlags mode, const QString &label,
|
|
||||||
const QString &tooltip);
|
|
||||||
|
|
||||||
virtual QSize sizeHint() const; // reimp
|
|
||||||
|
|
||||||
void setFont(const QFont &fnt);
|
|
||||||
void setText(const QString &text); // reimp
|
|
||||||
void setToolTip(const QString &tip); // reimp
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void slotSetMode(ButtonModeFlags mode, bool flag);
|
|
||||||
void slotSetAccelDisplayMode(bool flag);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void paintEvent(QPaintEvent *e);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void calcSizeHint();
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool show_shortcut_mode_;
|
|
||||||
ButtonModeFlags mode_flags_;
|
|
||||||
QMap<ButtonModeFlags, ButtonMode> mode_;
|
|
||||||
QSize size_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,139 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 2003 - 2005 Klaus Niederkrueger
|
|
||||||
kniederk@math.uni-koeln.de
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "kcalc_const_button.h"
|
|
||||||
#include "kcalc_const_menu.h"
|
|
||||||
#include "kcalc_settings.h"
|
|
||||||
|
|
||||||
#include <kinputdialog.h>
|
|
||||||
#include <kmenu.h>
|
|
||||||
|
|
||||||
#include "moc_kcalc_const_button.cpp"
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KCalcConstButton
|
|
||||||
// Desc: constructor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KCalcConstButton::KCalcConstButton(QWidget *parent) : KCalcButton(parent), button_num_(-1) {
|
|
||||||
|
|
||||||
addMode(ModeShift, i18nc("Write display data into memory", "Store"), i18n("Write display data into memory"));
|
|
||||||
initPopupMenu();
|
|
||||||
connect(this, SIGNAL(clicked()), SLOT(slotClicked()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KCalcConstButton
|
|
||||||
// Desc: constructor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KCalcConstButton::KCalcConstButton(const QString &label, QWidget *parent, const QString &tooltip) : KCalcButton(label, parent, tooltip), button_num_(-1) {
|
|
||||||
|
|
||||||
addMode(ModeShift, i18nc("Write display data into memory", "Store"), i18n("Write display data into memory"));
|
|
||||||
initPopupMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: constant
|
|
||||||
// Desc: get the value of the const as a QString
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString KCalcConstButton::constant() const {
|
|
||||||
|
|
||||||
return KCalcSettings::valueConstant(button_num_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setButtonNumber
|
|
||||||
// Desc: remembers the "index" of the const button
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcConstButton::setButtonNumber(int num) {
|
|
||||||
|
|
||||||
button_num_ = num;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setLabelAndTooltip
|
|
||||||
// Desc: sets both the label and the tooltip for the const button
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcConstButton::setLabelAndTooltip() {
|
|
||||||
|
|
||||||
QString new_label = QLatin1String("C") + QString::number(button_num_ + 1);
|
|
||||||
QString new_tooltip;
|
|
||||||
|
|
||||||
new_label = (KCalcSettings::nameConstant(button_num_).isNull() ? new_label : KCalcSettings::nameConstant(button_num_));
|
|
||||||
|
|
||||||
new_tooltip = new_label + QLatin1Char('=') + KCalcSettings::valueConstant(button_num_);
|
|
||||||
|
|
||||||
addMode(ModeNormal, new_label, new_tooltip);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: initPopupMenu
|
|
||||||
// Desc: initializes the const button popup
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcConstButton::initPopupMenu() {
|
|
||||||
|
|
||||||
QAction *const a = new QAction(this);
|
|
||||||
a->setText(i18n("Set Name"));
|
|
||||||
connect(a, SIGNAL(triggered()), this, SLOT(slotConfigureButton()));
|
|
||||||
addAction(a);
|
|
||||||
|
|
||||||
KCalcConstMenu *const tmp_menu = new KCalcConstMenu(this);
|
|
||||||
tmp_menu->menuAction()->setText(i18n("Choose From List"));
|
|
||||||
addAction(tmp_menu->menuAction());
|
|
||||||
setContextMenuPolicy(Qt::ActionsContextMenu);
|
|
||||||
|
|
||||||
connect(tmp_menu, SIGNAL(triggeredConstant(science_constant)), SLOT(slotChooseScientificConst(science_constant)));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotConfigureButton
|
|
||||||
// Desc: lets the user set the name for a constant
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcConstButton::slotConfigureButton() {
|
|
||||||
|
|
||||||
bool yes_no;
|
|
||||||
const QString input = KInputDialog::getText(i18n("New Name for Constant"), i18n("New name:"), text(), &yes_no, this); // "nameUserConstants-Dialog"
|
|
||||||
if (yes_no) {
|
|
||||||
KCalcSettings::setNameConstant(button_num_, input);
|
|
||||||
setLabelAndTooltip();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotChooseScientificConst
|
|
||||||
// Desc: set the buttons's scientific constant
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcConstButton::slotChooseScientificConst(const science_constant &const_chosen) {
|
|
||||||
|
|
||||||
KCalcSettings::setValueConstant(button_num_, const_chosen.value);
|
|
||||||
KCalcSettings::setNameConstant(button_num_, const_chosen.label);
|
|
||||||
setLabelAndTooltip();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotClicked
|
|
||||||
// Desc: constant button was clicked
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcConstButton::slotClicked() {
|
|
||||||
|
|
||||||
emit clicked(button_num_);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 1996 - 2000 Bernd Johannes Wuebben
|
|
||||||
wuebben@kde.org
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KCALC_CONST_BUTTON_H_
|
|
||||||
#define KCALC_CONST_BUTTON_H_
|
|
||||||
|
|
||||||
#include "kcalc_button.h"
|
|
||||||
|
|
||||||
struct science_constant;
|
|
||||||
|
|
||||||
|
|
||||||
class KCalcConstButton : public KCalcButton {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
explicit KCalcConstButton(QWidget *parent);
|
|
||||||
|
|
||||||
KCalcConstButton(const QString &label, QWidget *parent,
|
|
||||||
const QString &tooltip = QString());
|
|
||||||
|
|
||||||
QString constant() const;
|
|
||||||
|
|
||||||
void setButtonNumber(int num);
|
|
||||||
|
|
||||||
void setLabelAndTooltip();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void clicked(int num);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void slotConfigureButton();
|
|
||||||
void slotChooseScientificConst(const science_constant &const_chosen);
|
|
||||||
void slotClicked();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void initPopupMenu();
|
|
||||||
|
|
||||||
private:
|
|
||||||
int button_num_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,146 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 2003 - 2005 Klaus Niederkrueger
|
|
||||||
kniederk@math.uni-koeln.de
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "kcalc_const_menu.h"
|
|
||||||
|
|
||||||
#include <QtXml/qdom.h>
|
|
||||||
#include <QFile>
|
|
||||||
#include <kdebug.h>
|
|
||||||
#include <klocale.h>
|
|
||||||
#include <kstandarddirs.h>
|
|
||||||
|
|
||||||
ConstantCategory stringToCategory(const QString &s) {
|
|
||||||
if (s == QLatin1String("mathematics")) {
|
|
||||||
return Mathematics;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s == QLatin1String("electromagnetism")) {
|
|
||||||
return Electromagnetic;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s == QLatin1String("nuclear")) {
|
|
||||||
return Nuclear;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s == QLatin1String("thermodynamics")) {
|
|
||||||
return Thermodynamics;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s == QLatin1String("gravitation")) {
|
|
||||||
return Gravitation;
|
|
||||||
}
|
|
||||||
|
|
||||||
kDebug() << "Invalid Category For Constant: " << s;
|
|
||||||
return Mathematics;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<science_constant> KCalcConstMenu::constants_;
|
|
||||||
|
|
||||||
void KCalcConstMenu::init_consts() {
|
|
||||||
QDomDocument doc(QLatin1String("list_of_constants"));
|
|
||||||
QFile file(KGlobal::dirs()->findResource("appdata", QLatin1String("scienceconstants.xml")));
|
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
|
||||||
kDebug() << "Did not find file \"scienceconstants.xml\". No constants will be available.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!doc.setContent(&file)) {
|
|
||||||
file.close();
|
|
||||||
kDebug() << "The file \"scienceconstants.xml\" does not seem to be a valid description file. No constants will be available.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
// print out the element names of all elements that are direct children
|
|
||||||
// of the outermost element.
|
|
||||||
QDomElement docElem = doc.documentElement();
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
QDomNode n = docElem.firstChild();
|
|
||||||
while (!n.isNull()) {
|
|
||||||
QDomElement e = n.toElement(); // try to convert the node to an element.
|
|
||||||
if (!e.isNull() && e.tagName() == QLatin1String("constant")) {
|
|
||||||
science_constant tmp_const;
|
|
||||||
|
|
||||||
tmp_const.name = I18N_NOOP(e.attributeNode(QLatin1String("name")).value());
|
|
||||||
tmp_const.label = e.attributeNode(QLatin1String("symbol")).value();
|
|
||||||
tmp_const.value = e.attributeNode(QLatin1String("value")).value();
|
|
||||||
|
|
||||||
QString tmp_str_category = e.attributeNode(QLatin1String("category")).value();
|
|
||||||
|
|
||||||
tmp_const.category = stringToCategory(tmp_str_category);
|
|
||||||
tmp_const.whatsthis = e.firstChildElement(QLatin1String("description")).text();
|
|
||||||
|
|
||||||
constants_.append(tmp_const);
|
|
||||||
}
|
|
||||||
n = n.nextSibling();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KCalcConstMenu::init_all()
|
|
||||||
{
|
|
||||||
QMenu *math_menu = addMenu(i18n("Mathematics"));
|
|
||||||
QMenu *em_menu = addMenu(i18n("Electromagnetism"));
|
|
||||||
QMenu *nuclear_menu = addMenu(i18n("Atomic && Nuclear"));
|
|
||||||
QMenu *thermo_menu = addMenu(i18n("Thermodynamics"));
|
|
||||||
QMenu *gravitation_menu = addMenu(i18n("Gravitation"));
|
|
||||||
|
|
||||||
connect(this, SIGNAL(triggered(QAction*)), SLOT(slotPassSignalThrough(QAction*)));
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < constants_.size(); i++) {
|
|
||||||
QAction *tmp_action = new QAction(i18n(constants_.at(i).name.toAscii().data()), this);
|
|
||||||
tmp_action->setData(QVariant(i));
|
|
||||||
if (constants_.at(i).category & Mathematics)
|
|
||||||
math_menu->addAction(tmp_action);
|
|
||||||
if (constants_.at(i).category & Electromagnetic)
|
|
||||||
em_menu->addAction(tmp_action);
|
|
||||||
if (constants_.at(i).category & Nuclear)
|
|
||||||
nuclear_menu->addAction(tmp_action);
|
|
||||||
if (constants_.at(i).category & Thermodynamics)
|
|
||||||
thermo_menu->addAction(tmp_action);
|
|
||||||
if (constants_.at(i).category & Gravitation)
|
|
||||||
gravitation_menu->addAction(tmp_action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KCalcConstMenu::slotPassSignalThrough(QAction *chosen_const)
|
|
||||||
{
|
|
||||||
bool tmp_bool;
|
|
||||||
int chosen_const_idx = (chosen_const->data()).toInt(& tmp_bool);
|
|
||||||
emit triggeredConstant(constants_.at(chosen_const_idx));
|
|
||||||
}
|
|
||||||
|
|
||||||
KCalcConstMenu::KCalcConstMenu(const QString &title, QWidget * parent)
|
|
||||||
: QMenu(title, parent)
|
|
||||||
{
|
|
||||||
init_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
KCalcConstMenu::KCalcConstMenu(QWidget * parent)
|
|
||||||
: QMenu(parent)
|
|
||||||
{
|
|
||||||
init_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#include "moc_kcalc_const_menu.cpp"
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 2003 - 2005 Klaus Niederkrueger
|
|
||||||
kniederk@math.uni-koeln.de
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KCALC_CONST_MENU_H_
|
|
||||||
#define KCALC_CONST_MENU_H_
|
|
||||||
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
enum ConstantCategory {
|
|
||||||
Mathematics = 1,
|
|
||||||
Electromagnetic = 2,
|
|
||||||
Nuclear = 4,
|
|
||||||
Thermodynamics = 8,
|
|
||||||
Gravitation = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
struct science_constant {
|
|
||||||
QString label;
|
|
||||||
QString name;
|
|
||||||
QString whatsthis;
|
|
||||||
QString value;
|
|
||||||
ConstantCategory category;
|
|
||||||
};
|
|
||||||
|
|
||||||
class KCalcConstMenu : public QMenu {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit KCalcConstMenu(QWidget * parent = 0);
|
|
||||||
explicit KCalcConstMenu(const QString &title, QWidget * parent = 0);
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void init_consts();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void triggeredConstant(const science_constant &);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void init_all();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void slotPassSignalThrough(QAction *chosen_const);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static QList<science_constant> constants_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,886 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 2003 - 2005 Klaus Niederkrueger
|
|
||||||
kniederk@math.uni-koeln.de
|
|
||||||
|
|
||||||
Copyright (C) 1996 - 2000 Bernd Johannes Wuebben
|
|
||||||
wuebben@kde.org
|
|
||||||
|
|
||||||
Copyright (C) 1995 Martin Bartlett
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "kcalc_core.h"
|
|
||||||
#include <kdebug.h>
|
|
||||||
#include <klocale.h>
|
|
||||||
#include <kmessagebox.h>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
KNumber Deg2Rad(const KNumber &x) {
|
|
||||||
return x * (KNumber::Pi() / KNumber(180));
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber Gra2Rad(const KNumber &x) {
|
|
||||||
return x * (KNumber::Pi() / KNumber(200));
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber Rad2Deg(const KNumber &x) {
|
|
||||||
return x * (KNumber(180) / KNumber::Pi());
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber Rad2Gra(const KNumber &x) {
|
|
||||||
return x * (KNumber(200) / KNumber::Pi());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool error_;
|
|
||||||
|
|
||||||
KNumber ExecOr(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op | right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecXor(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op ^ right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecAnd(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op & right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecLsh(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op << right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecRsh(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op >> right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecAdd(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op + right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecSubtract(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op - right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecMultiply(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op * right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecDivide(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op / right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecMod(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op % right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecIntDiv(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return (left_op / right_op).integerPart();
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecBinom(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op.bin(right_op);
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecPower(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op.pow(right_op);
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecPwrRoot(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op.pow(KNumber::One / right_op);
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecAddP(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op * (KNumber::One + right_op / KNumber(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecSubP(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op * (KNumber::One - right_op / KNumber(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecMultiplyP(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op * right_op / KNumber(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber ExecDivideP(const KNumber &left_op, const KNumber &right_op) {
|
|
||||||
return left_op * KNumber(100) / right_op;
|
|
||||||
}
|
|
||||||
|
|
||||||
// move a number into the interval [0,360) by adding multiples of 360
|
|
||||||
KNumber moveIntoDegInterval(const KNumber &num) {
|
|
||||||
KNumber tmp_num = num - (num / KNumber(360)).integerPart() * KNumber(360);
|
|
||||||
if (tmp_num < KNumber::Zero)
|
|
||||||
return tmp_num + KNumber(360);
|
|
||||||
return tmp_num;
|
|
||||||
}
|
|
||||||
|
|
||||||
// move a number into the interval [0,400) by adding multiples of 400
|
|
||||||
KNumber moveIntoGradInterval(const KNumber &num) {
|
|
||||||
KNumber tmp_num = num - (num / KNumber(400)).integerPart() * KNumber(400);
|
|
||||||
if (tmp_num < KNumber::Zero)
|
|
||||||
return tmp_num + KNumber(400);
|
|
||||||
return tmp_num;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef KNumber(*Arith)(const KNumber &, const KNumber &);
|
|
||||||
typedef KNumber(*Prcnt)(const KNumber &, const KNumber &);
|
|
||||||
|
|
||||||
struct operator_data {
|
|
||||||
int precedence; // priority of operators in " enum Operation"
|
|
||||||
Arith arith_ptr;
|
|
||||||
Prcnt prcnt_ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
// build precedence list
|
|
||||||
const struct operator_data Operator[] = {
|
|
||||||
{ 0, NULL, NULL}, // FUNC_EQUAL
|
|
||||||
{ 0, NULL, NULL}, // FUNC_PERCENT
|
|
||||||
{ 0, NULL, NULL}, // FUNC_BRACKET
|
|
||||||
{ 1, ExecOr, NULL}, // FUNC_OR
|
|
||||||
{ 2, ExecXor, NULL}, // FUNC_XOR
|
|
||||||
{ 3, ExecAnd, NULL}, // FUNC_AND
|
|
||||||
{ 4, ExecLsh, NULL}, // FUNC_LSH
|
|
||||||
{ 4, ExecRsh, NULL}, // FUNC_RSH
|
|
||||||
{ 5, ExecAdd, ExecAddP}, // FUNC_ADD
|
|
||||||
{ 5, ExecSubtract, ExecSubP}, // FUNC_SUBTRACT
|
|
||||||
{ 6, ExecMultiply, ExecMultiplyP}, // FUNC_MULTIPLY
|
|
||||||
{ 6, ExecDivide, ExecDivideP}, // FUNC_DIVIDE
|
|
||||||
{ 6, ExecMod, NULL}, // FUNC_MOD
|
|
||||||
{ 6, ExecIntDiv, NULL}, // FUNC_INTDIV
|
|
||||||
{ 7, ExecBinom, NULL}, // FUNC_BINOM
|
|
||||||
{ 7, ExecPower, NULL}, // FUNC_POWER
|
|
||||||
{ 7, ExecPwrRoot, NULL} // FUNC_PWR_ROOT
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CalcEngine::CalcEngine() : percent_mode_(false) {
|
|
||||||
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
error_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber CalcEngine::lastOutput(bool &error) const {
|
|
||||||
error = error_;
|
|
||||||
return last_number_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ArcCosDeg(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR || input < -KNumber::One || input > KNumber::One) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
if (input == KNumber::One) {
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == - KNumber::One) {
|
|
||||||
last_number_ = KNumber(180);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == KNumber::Zero) {
|
|
||||||
last_number_ = KNumber(90);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
last_number_ = Rad2Deg(input.acos());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ArcCosRad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR || input < -KNumber::One || input > KNumber::One) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
last_number_ = input.acos();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ArcCosGrad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR || input < -KNumber::One || input > KNumber::One) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
if (input == KNumber::One) {
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == - KNumber::One) {
|
|
||||||
last_number_ = KNumber(200);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == KNumber::Zero) {
|
|
||||||
last_number_ = KNumber(100);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
last_number_ = Rad2Gra(input.acos());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ArcSinDeg(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR ||
|
|
||||||
input < -KNumber::One || input > KNumber::One) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
if (input == KNumber::One) {
|
|
||||||
last_number_ = KNumber(90);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == - KNumber::One) {
|
|
||||||
last_number_ = KNumber(-90);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == KNumber::Zero) {
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
last_number_ = Rad2Deg(input.asin());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ArcSinRad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR ||
|
|
||||||
input < -KNumber::One || input > KNumber::One) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
last_number_ = input.asin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ArcSinGrad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR ||
|
|
||||||
input < -KNumber::One || input > KNumber::One) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
if (input == KNumber::One) {
|
|
||||||
last_number_ = KNumber(100);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == - KNumber::One) {
|
|
||||||
last_number_ = KNumber(-100);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == KNumber::Zero) {
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
last_number_ = Rad2Gra(input.asin());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ArcTangensDeg(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
if (input == KNumber::NaN) last_number_ = KNumber::NaN;
|
|
||||||
if (input == KNumber::PosInfinity) last_number_ = KNumber(90);
|
|
||||||
if (input == KNumber::NegInfinity) last_number_ = KNumber(-90);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = Rad2Deg(input.atan());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ArcTangensRad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
if (input == KNumber::NaN) last_number_ = KNumber::NaN;
|
|
||||||
if (input == KNumber::PosInfinity)
|
|
||||||
last_number_ = KNumber::Pi() / KNumber(2);
|
|
||||||
if (input == KNumber::NegInfinity)
|
|
||||||
last_number_ = -KNumber::Pi() / KNumber(2);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = input.atan();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ArcTangensGrad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
if (input == KNumber::NaN) last_number_ = KNumber::NaN;
|
|
||||||
if (input == KNumber::PosInfinity) last_number_ = KNumber(100);
|
|
||||||
if (input == KNumber::NegInfinity) last_number_ = KNumber(-100);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = Rad2Gra(input.atan());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::AreaCosHyp(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
if (input == KNumber::NaN) last_number_ = KNumber::NaN;
|
|
||||||
if (input == KNumber::PosInfinity) last_number_ = KNumber::PosInfinity;
|
|
||||||
if (input == KNumber::NegInfinity) last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input < KNumber::One) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == KNumber::One) {
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
last_number_ = input.acosh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::AreaSinHyp(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
if (input == KNumber::NaN) last_number_ = KNumber::NaN;
|
|
||||||
if (input == KNumber::PosInfinity) last_number_ = KNumber::PosInfinity;
|
|
||||||
if (input == KNumber::NegInfinity) last_number_ = KNumber::NegInfinity;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input == KNumber::Zero) {
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
last_number_ = input.asinh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::AreaTangensHyp(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input < -KNumber::One || input > KNumber::One) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == KNumber::One) {
|
|
||||||
last_number_ = KNumber::PosInfinity;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (input == - KNumber::One) {
|
|
||||||
last_number_ = KNumber::NegInfinity;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
last_number_ = input.atanh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::Complement(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() != KNumber::TYPE_INTEGER) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = ~input;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::CosDeg(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber trunc_input = moveIntoDegInterval(input);
|
|
||||||
|
|
||||||
if (trunc_input.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
KNumber mult = trunc_input / KNumber(90);
|
|
||||||
if (mult.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
if (mult == KNumber::Zero)
|
|
||||||
last_number_ = KNumber::One;
|
|
||||||
else if (mult == KNumber::One)
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
else if (mult == KNumber(2))
|
|
||||||
last_number_ = KNumber::NegOne;
|
|
||||||
else if (mult == KNumber(3))
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
else kDebug() << "Something wrong in CalcEngine::CosDeg";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trunc_input = Deg2Rad(trunc_input);
|
|
||||||
last_number_ = trunc_input.cos();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::CosRad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = input.cos();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::CosGrad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
KNumber trunc_input = moveIntoGradInterval(input);
|
|
||||||
if (trunc_input.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
KNumber mult = trunc_input / KNumber(100);
|
|
||||||
if (mult.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
if (mult == KNumber::Zero)
|
|
||||||
last_number_ = KNumber::One;
|
|
||||||
else if (mult == KNumber::One)
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
else if (mult == KNumber(2))
|
|
||||||
last_number_ = KNumber::NegOne;
|
|
||||||
else if (mult == KNumber(3))
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
else kDebug() << "Something wrong in CalcEngine::CosGrad";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trunc_input = Gra2Rad(trunc_input);
|
|
||||||
|
|
||||||
last_number_ = trunc_input.cos();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::CosHyp(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
if (input == KNumber::NaN) last_number_ = KNumber::NaN;
|
|
||||||
if (input == KNumber::PosInfinity) last_number_ = KNumber::PosInfinity;
|
|
||||||
// YES, this should be *positive* infinity. We mimic the behavior of
|
|
||||||
// libc which says the following for cosh
|
|
||||||
//
|
|
||||||
// "If x is positive infinity or negative infinity, positive infinity is returned."
|
|
||||||
if (input == KNumber::NegInfinity) last_number_ = KNumber::PosInfinity;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = input.cosh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::Cube(const KNumber &input)
|
|
||||||
{
|
|
||||||
last_number_ = input * input * input;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::CubeRoot(const KNumber &input)
|
|
||||||
{
|
|
||||||
last_number_ = input.cbrt();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::Exp(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
if (input == KNumber::NaN) last_number_ = KNumber::NaN;
|
|
||||||
if (input == KNumber::PosInfinity) last_number_ = KNumber::PosInfinity;
|
|
||||||
if (input == KNumber::NegInfinity) last_number_ = KNumber::Zero;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
last_number_ = KNumber::Euler().pow(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::Exp10(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
if (input == KNumber::NaN) last_number_ = KNumber::NaN;
|
|
||||||
if (input == KNumber::PosInfinity) last_number_ = KNumber::PosInfinity;
|
|
||||||
if (input == KNumber::NegInfinity) last_number_ = KNumber::Zero;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
last_number_ = KNumber(10).pow(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CalcEngine::Factorial(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input == KNumber::PosInfinity) return;
|
|
||||||
if (input < KNumber::Zero || input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
error_ = true;
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = input.integerPart().factorial();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::Gamma(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input == KNumber::PosInfinity) return;
|
|
||||||
if (input < KNumber::Zero || input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
error_ = true;
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = input.tgamma();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::InvertSign(const KNumber &input)
|
|
||||||
{
|
|
||||||
last_number_ = -input;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::Ln(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input < KNumber::Zero)
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
else if (input == KNumber::Zero)
|
|
||||||
last_number_ = KNumber::NegInfinity;
|
|
||||||
else if (input == KNumber::One)
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
else {
|
|
||||||
last_number_ = input.ln();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::Log10(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input < KNumber::Zero)
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
else if (input == KNumber::Zero)
|
|
||||||
last_number_ = KNumber::NegInfinity;
|
|
||||||
else if (input == KNumber::One)
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
else {
|
|
||||||
last_number_ = input.log10();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ParenClose(KNumber input)
|
|
||||||
{
|
|
||||||
// evaluate stack until corresponding opening bracket
|
|
||||||
while (!stack_.isEmpty()) {
|
|
||||||
Node tmp_node = stack_.pop();
|
|
||||||
if (tmp_node.operation == FUNC_BRACKET)
|
|
||||||
break;
|
|
||||||
input = evalOperation(tmp_node.number, tmp_node.operation, input);
|
|
||||||
}
|
|
||||||
last_number_ = input;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::ParenOpen(const KNumber &input)
|
|
||||||
{
|
|
||||||
enterOperation(input, FUNC_BRACKET);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::Reciprocal(const KNumber &input)
|
|
||||||
{
|
|
||||||
last_number_ = KNumber::One / input;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CalcEngine::SinDeg(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber trunc_input = moveIntoDegInterval(input);
|
|
||||||
if (trunc_input.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
KNumber mult = trunc_input / KNumber(90);
|
|
||||||
if (mult.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
if (mult == KNumber::Zero)
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
else if (mult == KNumber::One)
|
|
||||||
last_number_ = KNumber::One;
|
|
||||||
else if (mult == KNumber(2))
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
else if (mult == KNumber(3))
|
|
||||||
last_number_ = KNumber::NegOne;
|
|
||||||
else kDebug() << "Something wrong in CalcEngine::SinDeg";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trunc_input = Deg2Rad(trunc_input);
|
|
||||||
|
|
||||||
last_number_ = trunc_input.sin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::SinRad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = input.sin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::SinGrad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber trunc_input = moveIntoGradInterval(input);
|
|
||||||
if (trunc_input.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
KNumber mult = trunc_input / KNumber(100);
|
|
||||||
if (mult.type() == KNumber::TYPE_INTEGER) {
|
|
||||||
if (mult == KNumber::Zero)
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
else if (mult == KNumber::One)
|
|
||||||
last_number_ = KNumber::One;
|
|
||||||
else if (mult == KNumber(2))
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
else if (mult == KNumber(3))
|
|
||||||
last_number_ = KNumber::NegOne;
|
|
||||||
else kDebug() << "Something wrong in CalcEngine::SinGrad";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trunc_input = Gra2Rad(trunc_input);
|
|
||||||
|
|
||||||
last_number_ = trunc_input.sin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::SinHyp(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
if (input == KNumber::NaN) last_number_ = KNumber::NaN;
|
|
||||||
if (input == KNumber::PosInfinity) last_number_ = KNumber::PosInfinity;
|
|
||||||
if (input == KNumber::NegInfinity) last_number_ = KNumber::NegInfinity;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = input.sinh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::Square(const KNumber &input)
|
|
||||||
{
|
|
||||||
last_number_ = input * input;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::SquareRoot(const KNumber &input)
|
|
||||||
{
|
|
||||||
last_number_ = input.sqrt();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::StatClearAll(const KNumber &input)
|
|
||||||
{
|
|
||||||
Q_UNUSED(input);
|
|
||||||
stats.clearAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::StatCount(const KNumber &input)
|
|
||||||
{
|
|
||||||
Q_UNUSED(input);
|
|
||||||
last_number_ = KNumber(stats.count());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::StatDataNew(const KNumber &input)
|
|
||||||
{
|
|
||||||
stats.enterData(input);
|
|
||||||
last_number_ = KNumber(stats.count());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::StatDataDel(const KNumber &input)
|
|
||||||
{
|
|
||||||
Q_UNUSED(input);
|
|
||||||
stats.clearLast();
|
|
||||||
last_number_ = KNumber(stats.count());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::StatMean(const KNumber &input)
|
|
||||||
{
|
|
||||||
Q_UNUSED(input);
|
|
||||||
last_number_ = stats.mean();
|
|
||||||
|
|
||||||
error_ = stats.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::StatMedian(const KNumber &input)
|
|
||||||
{
|
|
||||||
Q_UNUSED(input);
|
|
||||||
last_number_ = stats.median();
|
|
||||||
|
|
||||||
error_ = stats.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::StatStdDeviation(const KNumber &input)
|
|
||||||
{
|
|
||||||
Q_UNUSED(input);
|
|
||||||
last_number_ = stats.std();
|
|
||||||
|
|
||||||
error_ = stats.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::StatStdSample(const KNumber &input)
|
|
||||||
{
|
|
||||||
Q_UNUSED(input);
|
|
||||||
last_number_ = stats.sample_std();
|
|
||||||
|
|
||||||
error_ = stats.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::StatSum(const KNumber &input)
|
|
||||||
{
|
|
||||||
Q_UNUSED(input);
|
|
||||||
last_number_ = stats.sum();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::StatSumSquares(const KNumber &input)
|
|
||||||
{
|
|
||||||
Q_UNUSED(input);
|
|
||||||
last_number_ = stats.sum_of_squares();
|
|
||||||
|
|
||||||
error_ = stats.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::TangensDeg(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SinDeg(input);
|
|
||||||
KNumber arg1 = last_number_;
|
|
||||||
CosDeg(input);
|
|
||||||
KNumber arg2 = last_number_;
|
|
||||||
|
|
||||||
last_number_ = arg1 / arg2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::TangensRad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SinRad(input);
|
|
||||||
KNumber arg1 = last_number_;
|
|
||||||
CosRad(input);
|
|
||||||
KNumber arg2 = last_number_;
|
|
||||||
|
|
||||||
last_number_ = arg1 / arg2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::TangensGrad(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
last_number_ = KNumber::NaN;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SinGrad(input);
|
|
||||||
KNumber arg1 = last_number_;
|
|
||||||
CosGrad(input);
|
|
||||||
KNumber arg2 = last_number_;
|
|
||||||
|
|
||||||
last_number_ = arg1 / arg2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::TangensHyp(const KNumber &input)
|
|
||||||
{
|
|
||||||
if (input.type() == KNumber::TYPE_ERROR) {
|
|
||||||
if (input == KNumber::NaN) last_number_ = KNumber::NaN;
|
|
||||||
if (input == KNumber::PosInfinity) last_number_ = KNumber::One;
|
|
||||||
if (input == KNumber::NegInfinity) last_number_ = KNumber::NegOne;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_number_ = input.tanh();
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber CalcEngine::evalOperation(const KNumber &arg1, Operation operation, const KNumber &arg2)
|
|
||||||
{
|
|
||||||
if (!percent_mode_ || Operator[operation].prcnt_ptr == NULL) {
|
|
||||||
return (Operator[operation].arith_ptr)(arg1, arg2);
|
|
||||||
} else {
|
|
||||||
percent_mode_ = false;
|
|
||||||
return (Operator[operation].prcnt_ptr)(arg1, arg2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::enterOperation(const KNumber &number, Operation func)
|
|
||||||
{
|
|
||||||
Node tmp_node;
|
|
||||||
|
|
||||||
if (func == FUNC_BRACKET) {
|
|
||||||
tmp_node.number = KNumber::Zero;
|
|
||||||
tmp_node.operation = FUNC_BRACKET;
|
|
||||||
|
|
||||||
stack_.push(tmp_node);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (func == FUNC_PERCENT) {
|
|
||||||
percent_mode_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp_node.number = number;
|
|
||||||
tmp_node.operation = func;
|
|
||||||
|
|
||||||
stack_.push(tmp_node);
|
|
||||||
|
|
||||||
evalStack();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CalcEngine::evalStack()
|
|
||||||
{
|
|
||||||
// this should never happen
|
|
||||||
Q_ASSERT(!stack_.isEmpty());
|
|
||||||
|
|
||||||
Node tmp_node = stack_.pop();
|
|
||||||
|
|
||||||
while (! stack_.isEmpty()) {
|
|
||||||
Node tmp_node2 = stack_.pop();
|
|
||||||
if (Operator[tmp_node.operation].precedence <=
|
|
||||||
Operator[tmp_node2.operation].precedence) {
|
|
||||||
if (tmp_node2.operation == FUNC_BRACKET) continue;
|
|
||||||
const KNumber tmp_result = evalOperation(tmp_node2.number, tmp_node2.operation, tmp_node.number);
|
|
||||||
tmp_node.number = tmp_result;
|
|
||||||
} else {
|
|
||||||
stack_.push(tmp_node2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tmp_node.operation != FUNC_EQUAL && tmp_node.operation != FUNC_PERCENT)
|
|
||||||
stack_.push(tmp_node);
|
|
||||||
|
|
||||||
last_number_ = tmp_node.number;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcEngine::Reset()
|
|
||||||
{
|
|
||||||
error_ = false;
|
|
||||||
last_number_ = KNumber::Zero;
|
|
||||||
|
|
||||||
stack_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,149 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 1996 - 2000 Bernd Johannes Wuebben
|
|
||||||
wuebben@kde.org
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KCALC_CORE_H_
|
|
||||||
#define KCALC_CORE_H_
|
|
||||||
|
|
||||||
#include <QStack>
|
|
||||||
#include "stats.h"
|
|
||||||
#include "knumber.h"
|
|
||||||
|
|
||||||
class CalcEngine {
|
|
||||||
public:
|
|
||||||
// operations that can be stored in calculation stack
|
|
||||||
enum Operation {
|
|
||||||
FUNC_EQUAL,
|
|
||||||
FUNC_PERCENT,
|
|
||||||
FUNC_BRACKET,
|
|
||||||
FUNC_OR,
|
|
||||||
FUNC_XOR,
|
|
||||||
FUNC_AND,
|
|
||||||
FUNC_LSH,
|
|
||||||
FUNC_RSH,
|
|
||||||
FUNC_ADD,
|
|
||||||
FUNC_SUBTRACT,
|
|
||||||
FUNC_MULTIPLY,
|
|
||||||
FUNC_DIVIDE,
|
|
||||||
FUNC_MOD,
|
|
||||||
FUNC_INTDIV,
|
|
||||||
FUNC_BINOM,
|
|
||||||
FUNC_POWER,
|
|
||||||
FUNC_PWR_ROOT
|
|
||||||
};
|
|
||||||
|
|
||||||
CalcEngine();
|
|
||||||
|
|
||||||
KNumber lastOutput(bool &error) const;
|
|
||||||
|
|
||||||
void enterOperation(const KNumber &num, Operation func);
|
|
||||||
|
|
||||||
void ArcCosDeg(const KNumber &input);
|
|
||||||
void ArcCosRad(const KNumber &input);
|
|
||||||
void ArcCosGrad(const KNumber &input);
|
|
||||||
void ArcSinDeg(const KNumber &input);
|
|
||||||
void ArcSinRad(const KNumber &input);
|
|
||||||
void ArcSinGrad(const KNumber &input);
|
|
||||||
void ArcTangensDeg(const KNumber &input);
|
|
||||||
void ArcTangensRad(const KNumber &input);
|
|
||||||
void ArcTangensGrad(const KNumber &input);
|
|
||||||
void AreaCosHyp(const KNumber &input);
|
|
||||||
void AreaSinHyp(const KNumber &input);
|
|
||||||
void AreaTangensHyp(const KNumber &input);
|
|
||||||
void Complement(const KNumber &input);
|
|
||||||
void CosDeg(const KNumber &input);
|
|
||||||
void CosRad(const KNumber &input);
|
|
||||||
void CosGrad(const KNumber &input);
|
|
||||||
void CosHyp(const KNumber &input);
|
|
||||||
void Cube(const KNumber &input);
|
|
||||||
void CubeRoot(const KNumber &input);
|
|
||||||
void Exp(const KNumber &input);
|
|
||||||
void Exp10(const KNumber &input);
|
|
||||||
void Factorial(const KNumber &input);
|
|
||||||
void Gamma(const KNumber &input);
|
|
||||||
void InvertSign(const KNumber &input);
|
|
||||||
void Ln(const KNumber &input);
|
|
||||||
void Log10(const KNumber &input);
|
|
||||||
void ParenClose(KNumber input);
|
|
||||||
void ParenOpen(const KNumber &input);
|
|
||||||
void Reciprocal(const KNumber &input);
|
|
||||||
void SinDeg(const KNumber &input);
|
|
||||||
void SinGrad(const KNumber &input);
|
|
||||||
void SinRad(const KNumber &input);
|
|
||||||
void SinHyp(const KNumber &input);
|
|
||||||
void Square(const KNumber &input);
|
|
||||||
void SquareRoot(const KNumber &input);
|
|
||||||
void StatClearAll(const KNumber &input);
|
|
||||||
void StatCount(const KNumber &input);
|
|
||||||
void StatDataNew(const KNumber &input);
|
|
||||||
void StatDataDel(const KNumber &input);
|
|
||||||
void StatMean(const KNumber &input);
|
|
||||||
void StatMedian(const KNumber &input);
|
|
||||||
void StatStdDeviation(const KNumber &input);
|
|
||||||
void StatStdSample(const KNumber &input);
|
|
||||||
void StatSum(const KNumber &input);
|
|
||||||
void StatSumSquares(const KNumber &input);
|
|
||||||
void TangensDeg(const KNumber &input);
|
|
||||||
void TangensRad(const KNumber &input);
|
|
||||||
void TangensGrad(const KNumber &input);
|
|
||||||
void TangensHyp(const KNumber &input);
|
|
||||||
|
|
||||||
void Reset();
|
|
||||||
|
|
||||||
private:
|
|
||||||
KStats stats;
|
|
||||||
|
|
||||||
struct Node {
|
|
||||||
KNumber number;
|
|
||||||
Operation operation;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Stack holds all operations and numbers that have not yet been
|
|
||||||
// processed, e.g. user types "2+3*", the calculation can not be
|
|
||||||
// executed, because "*" has a higher precedence than "+", so we
|
|
||||||
// need to wait for the next number.
|
|
||||||
//
|
|
||||||
// In the stack this would be stored as ((2,+),(3,*),...)
|
|
||||||
//
|
|
||||||
// "enterOperation": If the introduced Operation has lower priority
|
|
||||||
// than the preceding operations in the stack, then we can start to
|
|
||||||
// evaluate the stack (with "evalStack"). Otherwise we append the new
|
|
||||||
// Operation and number to the stack.
|
|
||||||
//
|
|
||||||
// E.g. "2*3+" evaluates to "6+", but "2+3*" can not be evaluated
|
|
||||||
// yet.
|
|
||||||
//
|
|
||||||
// We also take care of brackets, by writing a marker "FUNC_BRACKET"
|
|
||||||
// into the stack, each time the user opens one. When a bracket is
|
|
||||||
// closed, everything in the stack is evaluated until the first
|
|
||||||
// marker "FUNC_BRACKET" found.
|
|
||||||
QStack<Node> stack_;
|
|
||||||
|
|
||||||
KNumber last_number_;
|
|
||||||
|
|
||||||
bool percent_mode_;
|
|
||||||
|
|
||||||
bool evalStack();
|
|
||||||
|
|
||||||
KNumber evalOperation(const KNumber &arg1, Operation operation, const KNumber &arg2);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,6 +0,0 @@
|
||||||
# Code generation options for kconfig_compiler
|
|
||||||
File=kcalc.kcfg
|
|
||||||
ClassName=KCalcSettings
|
|
||||||
Singleton=true
|
|
||||||
Mutators=true
|
|
||||||
UseEnumTypes=true
|
|
|
@ -1,968 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 1996 - 2000 Bernd Johannes Wuebben
|
|
||||||
wuebben@kde.org
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "kcalcdisplay.h"
|
|
||||||
|
|
||||||
#include <QClipboard>
|
|
||||||
#include <QtGui/qevent.h>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QStyle>
|
|
||||||
#include <QStyleOption>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include <kglobal.h>
|
|
||||||
#include <klocale.h>
|
|
||||||
#include <knotification.h>
|
|
||||||
|
|
||||||
#include "kcalc_core.h"
|
|
||||||
#include "kcalc_settings.h"
|
|
||||||
|
|
||||||
#include "moc_kcalcdisplay.cpp"
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KCalcDisplay
|
|
||||||
// Desc: constructor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KCalcDisplay::KCalcDisplay(QWidget *parent) : QFrame(parent), beep_(false),
|
|
||||||
groupdigits_(true), twoscomplement_(true), button_(0), lit_(false),
|
|
||||||
num_base_(NB_DECIMAL), precision_(9), fixed_precision_(-1), display_amount_(0),
|
|
||||||
history_index_(0), selection_timer_(new QTimer(this)) {
|
|
||||||
|
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
|
||||||
|
|
||||||
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
|
|
||||||
|
|
||||||
setBackgroundRole(QPalette::Base);
|
|
||||||
setForegroundRole(QPalette::Text);
|
|
||||||
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); // set in kalc.ui
|
|
||||||
|
|
||||||
KNumber::setDefaultFloatOutput(true);
|
|
||||||
KNumber::setDefaultFractionalInput(true);
|
|
||||||
|
|
||||||
connect(this, SIGNAL(clicked()), this, SLOT(slotDisplaySelected()));
|
|
||||||
connect(selection_timer_, SIGNAL(timeout()), this, SLOT(slotSelectionTimedOut()));
|
|
||||||
|
|
||||||
sendEvent(EventReset);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: ~KCalcDisplay
|
|
||||||
// Desc: destructor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KCalcDisplay::~KCalcDisplay() {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: changeSettings
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::changeSettings() {
|
|
||||||
QPalette pal = palette();
|
|
||||||
|
|
||||||
pal.setColor(QPalette::Text, KCalcSettings::foreColor());
|
|
||||||
pal.setColor(QPalette::Base, KCalcSettings::backColor());
|
|
||||||
|
|
||||||
setPalette(pal);
|
|
||||||
|
|
||||||
setFont(KCalcSettings::displayFont());
|
|
||||||
|
|
||||||
setPrecision(KCalcSettings::precision());
|
|
||||||
|
|
||||||
if (!KCalcSettings::fixed()) {
|
|
||||||
setFixedPrecision(-1);
|
|
||||||
} else {
|
|
||||||
setFixedPrecision(KCalcSettings::fixedPrecision());
|
|
||||||
}
|
|
||||||
|
|
||||||
setBeep(KCalcSettings::beep());
|
|
||||||
setGroupDigits(KCalcSettings::groupDigits());
|
|
||||||
setTwosComplement(KCalcSettings::twosComplement());
|
|
||||||
setBinaryGrouping(KCalcSettings::binaryGrouping());
|
|
||||||
setOctalGrouping(KCalcSettings::octalGrouping());
|
|
||||||
setHexadecimalGrouping(KCalcSettings::hexadecimalGrouping());
|
|
||||||
updateDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::updateFromCore(const CalcEngine &core, bool store_result_in_history) {
|
|
||||||
|
|
||||||
bool tmp_error;
|
|
||||||
const KNumber &output = core.lastOutput(tmp_error);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
// TODO: do we really need explicit error tracking?
|
|
||||||
// isn't the type of the KNumber good enough?
|
|
||||||
// I think it is and that this error tracking is cruft
|
|
||||||
// left over from a LONG time ago...
|
|
||||||
if(output.type() == KNumber::TYPE_ERROR) {
|
|
||||||
#else
|
|
||||||
if (tmp_error) {
|
|
||||||
#endif
|
|
||||||
sendEvent(EventError);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setAmount(output) && store_result_in_history && (output != KNumber::Zero)) {
|
|
||||||
// add this latest value to our history
|
|
||||||
history_list_.insert(history_list_.begin(), output);
|
|
||||||
history_index_ = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: enterDigit
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::enterDigit(int data) {
|
|
||||||
|
|
||||||
switch (data) {
|
|
||||||
case 0: newCharacter(QLatin1Char('0')); break;
|
|
||||||
case 1: newCharacter(QLatin1Char('1')); break;
|
|
||||||
case 2: newCharacter(QLatin1Char('2')); break;
|
|
||||||
case 3: newCharacter(QLatin1Char('3')); break;
|
|
||||||
case 4: newCharacter(QLatin1Char('4')); break;
|
|
||||||
case 5: newCharacter(QLatin1Char('5')); break;
|
|
||||||
case 6: newCharacter(QLatin1Char('6')); break;
|
|
||||||
case 7: newCharacter(QLatin1Char('7')); break;
|
|
||||||
case 8: newCharacter(QLatin1Char('8')); break;
|
|
||||||
case 9: newCharacter(QLatin1Char('9')); break;
|
|
||||||
case 0xa: newCharacter(QLatin1Char('A')); break;
|
|
||||||
case 0xb: newCharacter(QLatin1Char('B')); break;
|
|
||||||
case 0xc: newCharacter(QLatin1Char('C')); break;
|
|
||||||
case 0xd: newCharacter(QLatin1Char('D')); break;
|
|
||||||
case 0xe: newCharacter(QLatin1Char('E')); break;
|
|
||||||
case 0xf: newCharacter(QLatin1Char('F')); break;
|
|
||||||
default:
|
|
||||||
Q_ASSERT(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotHistoryForward
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::slotHistoryForward() {
|
|
||||||
|
|
||||||
if (history_list_.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (history_index_ <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
history_index_--;
|
|
||||||
setAmount(history_list_[history_index_]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotHistoryBack
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::slotHistoryBack() {
|
|
||||||
|
|
||||||
if (history_list_.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (history_index_ >= history_list_.size()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setAmount(history_list_[history_index_]);
|
|
||||||
history_index_++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sendEvent
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool KCalcDisplay::sendEvent(Event event) {
|
|
||||||
|
|
||||||
switch (event) {
|
|
||||||
case EventClear:
|
|
||||||
case EventReset:
|
|
||||||
display_amount_ = KNumber::Zero;
|
|
||||||
str_int_ = QLatin1String("0");
|
|
||||||
str_int_exp_.clear();
|
|
||||||
|
|
||||||
eestate_ = false;
|
|
||||||
period_ = false;
|
|
||||||
neg_sign_ = false;
|
|
||||||
|
|
||||||
updateDisplay();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case EventChangeSign:
|
|
||||||
return changeSign();
|
|
||||||
|
|
||||||
case EventError:
|
|
||||||
updateDisplay();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotCut
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::slotCut() {
|
|
||||||
|
|
||||||
slotCopy();
|
|
||||||
sendEvent(EventReset);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotCopy
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::slotCopy() {
|
|
||||||
|
|
||||||
QString txt = text_;
|
|
||||||
|
|
||||||
switch(num_base_) {
|
|
||||||
case NB_HEX:
|
|
||||||
txt.prepend(QLatin1String("0x"));
|
|
||||||
txt.remove(QLatin1Char(' '));
|
|
||||||
break;
|
|
||||||
case NB_BINARY:
|
|
||||||
txt.prepend(QLatin1String("0b"));
|
|
||||||
txt.remove(QLatin1Char(' '));
|
|
||||||
break;
|
|
||||||
case NB_OCTAL:
|
|
||||||
txt.prepend(QLatin1String("0"));
|
|
||||||
txt.remove(QLatin1Char(' '));
|
|
||||||
break;
|
|
||||||
case NB_DECIMAL:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
(QApplication::clipboard())->setText(txt, QClipboard::Clipboard);
|
|
||||||
(QApplication::clipboard())->setText(txt, QClipboard::Selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotPaste
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::slotPaste(bool bClipboard) {
|
|
||||||
|
|
||||||
QString tmp_str = (QApplication::clipboard())->text(bClipboard ? QClipboard::Clipboard : QClipboard::Selection);
|
|
||||||
|
|
||||||
if (tmp_str.isNull()) {
|
|
||||||
if (beep_) {
|
|
||||||
KNotification::beep();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NumBase tmp_num_base = num_base_;
|
|
||||||
|
|
||||||
// fix up string
|
|
||||||
tmp_str = tmp_str.trimmed();
|
|
||||||
|
|
||||||
if (groupdigits_) {
|
|
||||||
tmp_str.remove(KGlobal::locale()->toLocale().groupSeparator());
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp_str = tmp_str.toLower();
|
|
||||||
|
|
||||||
// determine base
|
|
||||||
if (tmp_str.startsWith(QLatin1String("0x"))) {
|
|
||||||
tmp_num_base = NB_HEX;
|
|
||||||
tmp_str.remove(0, 2);
|
|
||||||
} else if (tmp_str.startsWith(QLatin1String("0b"))) {
|
|
||||||
tmp_num_base = NB_BINARY;
|
|
||||||
tmp_str.remove(0, 2);
|
|
||||||
} else if (tmp_str.startsWith(QLatin1String("0"))) {
|
|
||||||
// we don't want this to trigger on "0.xxxxxx" cases
|
|
||||||
if(tmp_str.length() < 2 || QString(tmp_str[1]) != KNumber::decimalSeparator()) {
|
|
||||||
tmp_num_base = NB_OCTAL;
|
|
||||||
tmp_str.remove(0, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tmp_num_base != NB_DECIMAL) {
|
|
||||||
bool was_ok;
|
|
||||||
const qint64 tmp_result = tmp_str.toULongLong(&was_ok, tmp_num_base);
|
|
||||||
|
|
||||||
if (!was_ok) {
|
|
||||||
setAmount(KNumber::NaN);
|
|
||||||
if (beep_) {
|
|
||||||
KNotification::beep();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setAmount(KNumber(tmp_result));
|
|
||||||
} else {
|
|
||||||
setAmount(KNumber(tmp_str));
|
|
||||||
if (beep_ && display_amount_ == KNumber::NaN) {
|
|
||||||
KNotification::beep();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotDisplaySelected
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::slotDisplaySelected() {
|
|
||||||
|
|
||||||
if (button_ == Qt::LeftButton) {
|
|
||||||
if (lit_) {
|
|
||||||
slotCopy();
|
|
||||||
selection_timer_->start(100);
|
|
||||||
} else {
|
|
||||||
selection_timer_->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
invertColors();
|
|
||||||
} else {
|
|
||||||
slotPaste(false); // Selection
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: slotSelectionTimedOut
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::slotSelectionTimedOut() {
|
|
||||||
|
|
||||||
lit_ = false;
|
|
||||||
invertColors();
|
|
||||||
selection_timer_->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: invertColors
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::invertColors() {
|
|
||||||
|
|
||||||
QPalette tmp_palette = palette();
|
|
||||||
tmp_palette.setColor(QPalette::Base, palette().color(QPalette::Text));
|
|
||||||
tmp_palette.setColor(QPalette::Text, palette().color(QPalette::Base));
|
|
||||||
setPalette(tmp_palette);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: mousePressEvent
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::mousePressEvent(QMouseEvent *e) {
|
|
||||||
|
|
||||||
if (e->button() == Qt::LeftButton) {
|
|
||||||
lit_ = !lit_;
|
|
||||||
button_ = Qt::LeftButton;
|
|
||||||
} else {
|
|
||||||
button_ = Qt::MiddleButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
emit clicked();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setPrecision
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::setPrecision(int precision) {
|
|
||||||
|
|
||||||
precision_ = precision;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setFixedPrecision
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::setFixedPrecision(int precision) {
|
|
||||||
|
|
||||||
if (fixed_precision_ > precision_) {
|
|
||||||
fixed_precision_ = -1;
|
|
||||||
} else {
|
|
||||||
fixed_precision_ = precision;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setBeep
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::setBeep(bool flag) {
|
|
||||||
beep_ = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setGroupDigits
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::setGroupDigits(bool flag) {
|
|
||||||
groupdigits_ = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setTwosComplement
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::setTwosComplement(bool flag) {
|
|
||||||
twoscomplement_ = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setBinaryGrouping
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::setBinaryGrouping(int digits) {
|
|
||||||
binaryGrouping_ = digits;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setOctalGrouping
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::setOctalGrouping(int digits) {
|
|
||||||
octalGrouping_ = digits;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setHexadecimalGrouping
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::setHexadecimalGrouping(int digits) {
|
|
||||||
hexadecimalGrouping_ = digits;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: getAmount
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
const KNumber &KCalcDisplay::getAmount() const {
|
|
||||||
return display_amount_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setAmount
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool KCalcDisplay::setAmount(const KNumber &new_amount) {
|
|
||||||
|
|
||||||
QString display_str;
|
|
||||||
|
|
||||||
str_int_ = QLatin1String("0");
|
|
||||||
str_int_exp_.clear();
|
|
||||||
period_ = false;
|
|
||||||
neg_sign_ = false;
|
|
||||||
eestate_ = false;
|
|
||||||
|
|
||||||
if ((num_base_ != NB_DECIMAL) && (new_amount.type() != KNumber::TYPE_ERROR)) {
|
|
||||||
display_amount_ = new_amount.integerPart();
|
|
||||||
|
|
||||||
if (twoscomplement_) {
|
|
||||||
// treat number as 64-bit unsigned
|
|
||||||
const quint64 tmp_workaround = display_amount_.toUint64();
|
|
||||||
display_str = QString::number(tmp_workaround, num_base_).toUpper();
|
|
||||||
} else {
|
|
||||||
// QString::number treats non-decimal as unsigned
|
|
||||||
qint64 tmp_workaround = display_amount_.toInt64();
|
|
||||||
const bool neg = tmp_workaround < 0;
|
|
||||||
if (neg) {
|
|
||||||
tmp_workaround = qAbs(tmp_workaround);
|
|
||||||
}
|
|
||||||
|
|
||||||
display_str = QString::number(tmp_workaround, num_base_).toUpper();
|
|
||||||
if (neg) {
|
|
||||||
display_str.prepend(KGlobal::locale()->toLocale().negativeSign());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// num_base_ == NB_DECIMAL || new_amount.type() == KNumber::TYPE_ERROR
|
|
||||||
display_amount_ = new_amount;
|
|
||||||
display_str = display_amount_.toQString(KCalcSettings::precision(), fixed_precision_);
|
|
||||||
}
|
|
||||||
|
|
||||||
setText(display_str);
|
|
||||||
emit changedAmount(display_amount_);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setText
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::setText(const QString &string)
|
|
||||||
{
|
|
||||||
// note that "C" locale is being used internally
|
|
||||||
text_ = string;
|
|
||||||
|
|
||||||
// don't mess with special numbers
|
|
||||||
const bool special = (string.contains(QLatin1String("nan")) || string.contains(QLatin1String("inf")));
|
|
||||||
|
|
||||||
// The decimal mode needs special treatment for two reasons, because: a) it uses KGlobal::locale() to get a localized
|
|
||||||
// format and b) it has possible numbers after the decimal place. Neither applies to Binary, Hexadecimal or Octal.
|
|
||||||
|
|
||||||
if (groupdigits_ && !special){
|
|
||||||
switch (num_base_) {
|
|
||||||
case NB_DECIMAL:
|
|
||||||
if (string.endsWith(QLatin1Char('.'))) {
|
|
||||||
text_.chop(1);
|
|
||||||
// Note: rounding happened already above!
|
|
||||||
text_ = KGlobal::locale()->formatNumber(text_, false, 0);
|
|
||||||
text_.append(KGlobal::locale()->toLocale().decimalPoint());
|
|
||||||
} else {
|
|
||||||
// Note: rounding happened already above!
|
|
||||||
text_ = KGlobal::locale()->formatNumber(text_, false, 0);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NB_BINARY:
|
|
||||||
text_ = groupDigits(text_, binaryGrouping_);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NB_OCTAL:
|
|
||||||
text_ = groupDigits(text_, octalGrouping_);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NB_HEX:
|
|
||||||
text_ = groupDigits(text_, hexadecimalGrouping_);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if(special) {
|
|
||||||
#if 0
|
|
||||||
// TODO: enable this code, it replaces the "inf" with an actual infinity
|
|
||||||
// symbol, but what should be put into the clip board when they copy?
|
|
||||||
if(string.contains(QLatin1String("inf"))) {
|
|
||||||
text_.replace("inf", QChar(0x221e));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
update();
|
|
||||||
emit changedText(text_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: groupDigits
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString KCalcDisplay::groupDigits(const QString &displayString, int numDigits) {
|
|
||||||
|
|
||||||
QString tmpDisplayString;
|
|
||||||
const int stringLength = displayString.length();
|
|
||||||
|
|
||||||
for (int i = stringLength; i > 0 ; i--){
|
|
||||||
if(i % numDigits == 0 && i != stringLength) {
|
|
||||||
tmpDisplayString = tmpDisplayString + ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpDisplayString = tmpDisplayString + displayString[stringLength - i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return tmpDisplayString;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: text
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString KCalcDisplay::text() const {
|
|
||||||
return text_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setBase
|
|
||||||
// Desc: change representation of display to new base (i.e. binary, decimal,
|
|
||||||
// octal, hexadecimal). The amount being displayed is changed to this
|
|
||||||
// base, but for now this amount can not be modified anymore (like
|
|
||||||
// being set with "setAmount"). Return value is the new base.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int KCalcDisplay::setBase(NumBase new_base) {
|
|
||||||
|
|
||||||
switch (new_base) {
|
|
||||||
case NB_HEX:
|
|
||||||
num_base_ = NB_HEX;
|
|
||||||
period_ = false;
|
|
||||||
break;
|
|
||||||
case NB_DECIMAL:
|
|
||||||
num_base_ = NB_DECIMAL;
|
|
||||||
break;
|
|
||||||
case NB_OCTAL:
|
|
||||||
num_base_ = NB_OCTAL;
|
|
||||||
period_ = false;
|
|
||||||
break;
|
|
||||||
case NB_BINARY:
|
|
||||||
num_base_ = NB_BINARY;
|
|
||||||
period_ = false;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Q_ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset amount
|
|
||||||
setAmount(display_amount_);
|
|
||||||
return num_base_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setStatusText
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::setStatusText(int i, const QString &text) {
|
|
||||||
|
|
||||||
if (i < NUM_STATUS_TEXT) {
|
|
||||||
str_status_[i] = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: updateDisplay
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::updateDisplay() {
|
|
||||||
|
|
||||||
// Put sign in front.
|
|
||||||
QString tmp_string;
|
|
||||||
if (neg_sign_) {
|
|
||||||
tmp_string = QLatin1Char('-') + str_int_;
|
|
||||||
} else {
|
|
||||||
tmp_string = str_int_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ok;
|
|
||||||
|
|
||||||
switch (num_base_) {
|
|
||||||
case NB_BINARY:
|
|
||||||
Q_ASSERT(!period_ && !eestate_);
|
|
||||||
setText(tmp_string);
|
|
||||||
display_amount_ = KNumber(str_int_.toULongLong(&ok, 2));
|
|
||||||
if (neg_sign_) {
|
|
||||||
display_amount_ = -display_amount_;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NB_OCTAL:
|
|
||||||
Q_ASSERT(!period_ && !eestate_);
|
|
||||||
setText(tmp_string);
|
|
||||||
display_amount_ = KNumber(str_int_.toULongLong(&ok, 8));
|
|
||||||
if (neg_sign_) {
|
|
||||||
display_amount_ = -display_amount_;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NB_HEX:
|
|
||||||
Q_ASSERT(!period_ && !eestate_);
|
|
||||||
setText(tmp_string);
|
|
||||||
display_amount_ = KNumber(str_int_.toULongLong(&ok, 16));
|
|
||||||
if (neg_sign_) {
|
|
||||||
display_amount_ = -display_amount_;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NB_DECIMAL:
|
|
||||||
if (!eestate_) {
|
|
||||||
setText(tmp_string);
|
|
||||||
display_amount_ = KNumber(tmp_string);
|
|
||||||
} else {
|
|
||||||
if (str_int_exp_.isNull()) {
|
|
||||||
// add 'e0' to display but not to conversion
|
|
||||||
display_amount_ = KNumber(tmp_string);
|
|
||||||
setText(tmp_string + QLatin1String("e0"));
|
|
||||||
} else {
|
|
||||||
tmp_string += QLatin1Char('e') + str_int_exp_;
|
|
||||||
setText(tmp_string);
|
|
||||||
display_amount_ = KNumber(tmp_string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Q_ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
emit changedAmount(display_amount_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: newCharacter
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::newCharacter(const QChar new_char) {
|
|
||||||
const QChar decimalPoint = KGlobal::locale()->toLocale().decimalPoint();
|
|
||||||
// test if character is valid
|
|
||||||
switch (new_char.toLatin1()) {
|
|
||||||
case 'e':
|
|
||||||
// EE can be set only once and in decimal mode
|
|
||||||
if (num_base_ != NB_DECIMAL || eestate_) {
|
|
||||||
if (beep_) {
|
|
||||||
KNotification::beep();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
eestate_ = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'F':
|
|
||||||
case 'E':
|
|
||||||
case 'D':
|
|
||||||
case 'C':
|
|
||||||
case 'B':
|
|
||||||
case 'A':
|
|
||||||
if (num_base_ == NB_DECIMAL) {
|
|
||||||
if (beep_) {
|
|
||||||
KNotification::beep();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// no break
|
|
||||||
case '9':
|
|
||||||
case '8':
|
|
||||||
if (num_base_ == NB_OCTAL) {
|
|
||||||
if (beep_) {
|
|
||||||
KNotification::beep();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// no break
|
|
||||||
case '7':
|
|
||||||
case '6':
|
|
||||||
case '5':
|
|
||||||
case '4':
|
|
||||||
case '3':
|
|
||||||
case '2':
|
|
||||||
if (num_base_ == NB_BINARY) {
|
|
||||||
if (beep_) {
|
|
||||||
KNotification::beep();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// no break
|
|
||||||
case '1':
|
|
||||||
case '0':
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if(new_char == decimalPoint) {
|
|
||||||
// Period can be set only once and only in decimal
|
|
||||||
// mode, also not in EE-mode
|
|
||||||
if (num_base_ != NB_DECIMAL || period_ || eestate_) {
|
|
||||||
if (beep_) {
|
|
||||||
KNotification::beep();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
period_ = true;
|
|
||||||
} else {
|
|
||||||
if (beep_) {
|
|
||||||
KNotification::beep();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// change exponent or mantissa
|
|
||||||
if (eestate_) {
|
|
||||||
// ignore '.' before 'e'. turn e.g. '123.e' into '123e'
|
|
||||||
if (new_char == QLatin1Char('e') && str_int_.endsWith(decimalPoint)) {
|
|
||||||
str_int_.chop(1);
|
|
||||||
period_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 'e' only starts ee_mode, leaves strings unchanged
|
|
||||||
// do not add '0' if at start of exp
|
|
||||||
if (new_char != QLatin1Char('e') && !(str_int_exp_.isNull() && new_char == QLatin1Char('0'))) {
|
|
||||||
str_int_exp_.append(new_char);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// handle first character
|
|
||||||
if (str_int_ == QLatin1String("0")) {
|
|
||||||
switch (new_char.toLatin1()) {
|
|
||||||
case 'e':
|
|
||||||
// display "0e" not just "e"
|
|
||||||
// "0e" does not make sense either, but...
|
|
||||||
str_int_.append(new_char);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if(new_char == decimalPoint) {
|
|
||||||
// display "0." not just "."
|
|
||||||
str_int_.append(new_char);
|
|
||||||
} else {
|
|
||||||
// no leading '0's
|
|
||||||
str_int_[0] = new_char;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
str_int_.append(new_char);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: deleteLastDigit
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::deleteLastDigit() {
|
|
||||||
|
|
||||||
// Only partially implemented !!
|
|
||||||
if (eestate_) {
|
|
||||||
if (str_int_exp_.isNull()) {
|
|
||||||
eestate_ = false;
|
|
||||||
} else {
|
|
||||||
const int length = str_int_exp_.length();
|
|
||||||
if (length > 1) {
|
|
||||||
str_int_exp_.chop(1);
|
|
||||||
} else {
|
|
||||||
str_int_exp_ = QLatin1String((const char *)0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const int length = str_int_.length();
|
|
||||||
if (length > 1) {
|
|
||||||
if (str_int_[length-1] == KGlobal::locale()->toLocale().decimalPoint()) {
|
|
||||||
period_ = false;
|
|
||||||
}
|
|
||||||
str_int_.chop(1);
|
|
||||||
} else {
|
|
||||||
Q_ASSERT(!period_);
|
|
||||||
str_int_[0] = QLatin1Char('0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: changeSign
|
|
||||||
// Desc: change Sign of display. Problem: Only possible here, when in input
|
|
||||||
// mode. Otherwise return 'false' so that the kcalc_core can handle
|
|
||||||
// things.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool KCalcDisplay::changeSign() {
|
|
||||||
|
|
||||||
//stupid way, to see if in input_mode or display_mode
|
|
||||||
if (str_int_ == QLatin1String("0")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eestate_) {
|
|
||||||
if (!str_int_exp_.isNull()) {
|
|
||||||
if (str_int_exp_[0] != QLatin1Char('-')) {
|
|
||||||
str_int_exp_.prepend(QLatin1Char('-'));
|
|
||||||
} else {
|
|
||||||
str_int_exp_.remove(QLatin1Char('-'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
neg_sign_ = !neg_sign_;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDisplay();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: initStyleOption
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::initStyleOption(QStyleOptionFrame *option) const {
|
|
||||||
|
|
||||||
if (!option) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
option->initFrom(this);
|
|
||||||
option->state &= ~QStyle::State_HasFocus; // don't draw focus highlight
|
|
||||||
|
|
||||||
if (frameShadow() == QFrame::Sunken) {
|
|
||||||
option->state |= QStyle::State_Sunken;
|
|
||||||
} else if (frameShadow() == QFrame::Raised) {
|
|
||||||
option->state |= QStyle::State_Raised;
|
|
||||||
}
|
|
||||||
|
|
||||||
option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, option, this);
|
|
||||||
option->midLineWidth = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: paintEvent
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KCalcDisplay::paintEvent(QPaintEvent *) {
|
|
||||||
|
|
||||||
QPainter painter(this);
|
|
||||||
|
|
||||||
QStyleOptionFrame option;
|
|
||||||
initStyleOption(&option);
|
|
||||||
|
|
||||||
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &option, &painter, this);
|
|
||||||
|
|
||||||
// draw display text
|
|
||||||
const int margin = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, 0);
|
|
||||||
QRect cr = contentsRect();
|
|
||||||
cr.adjust(margin*2, 0, -margin*2, 0); // provide a margin
|
|
||||||
|
|
||||||
const int align = QStyle::visualAlignment(layoutDirection(), Qt::AlignRight | Qt::AlignVCenter);
|
|
||||||
painter.drawText(cr, align | Qt::TextSingleLine, text_);
|
|
||||||
|
|
||||||
// draw the status texts using half of the normal
|
|
||||||
// font size but not smaller than 7pt
|
|
||||||
QFont fnt(font());
|
|
||||||
fnt.setPointSize(qMax((fnt.pointSize() / 2), 7));
|
|
||||||
painter.setFont(fnt);
|
|
||||||
|
|
||||||
QFontMetrics fm(fnt);
|
|
||||||
const uint w = fm.width(QLatin1String("________"));
|
|
||||||
const uint h = fm.height();
|
|
||||||
|
|
||||||
for (int n = 0; n < NUM_STATUS_TEXT; ++n) {
|
|
||||||
painter.drawText(5 + n * w, h, str_status_[n]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sizeHint
|
|
||||||
// Desc:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QSize KCalcDisplay::sizeHint() const {
|
|
||||||
|
|
||||||
// basic size
|
|
||||||
QSize sz = fontMetrics().size(Qt::TextSingleLine, text_);
|
|
||||||
|
|
||||||
// expanded by half font height to make room for the status texts
|
|
||||||
QFont fnt(font());
|
|
||||||
fnt.setPointSize(qMax((fnt.pointSize() / 2), 7));
|
|
||||||
|
|
||||||
const QFontMetrics fm(fnt);
|
|
||||||
sz.setHeight(sz.height() + fm.height());
|
|
||||||
|
|
||||||
QStyleOptionFrame option;
|
|
||||||
initStyleOption(&option);
|
|
||||||
|
|
||||||
return (style()->sizeFromContents(QStyle::CT_LineEdit, &option, sz.expandedTo(QApplication::globalStrut()), this));
|
|
||||||
}
|
|
|
@ -1,156 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 1996 - 2000 Bernd Johannes Wuebben
|
|
||||||
wuebben@kde.org
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KCALCDISPLAY_H_
|
|
||||||
#define KCALCDISPLAY_H_
|
|
||||||
|
|
||||||
#include <QFrame>
|
|
||||||
#include <QVector>
|
|
||||||
#include "knumber.h"
|
|
||||||
|
|
||||||
class CalcEngine;
|
|
||||||
class KAction;
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QStyleOptionFrame>
|
|
||||||
|
|
||||||
#define NUM_STATUS_TEXT 4
|
|
||||||
|
|
||||||
/*
|
|
||||||
This class provides a pocket calculator display. The display has
|
|
||||||
implicitely two major modes: One is for editing and one is purely
|
|
||||||
for displaying.
|
|
||||||
|
|
||||||
When one uses "setAmount", the given amount is displayed, and the
|
|
||||||
amount which was possibly typed in before is lost. At the same time
|
|
||||||
this new value can not be modified.
|
|
||||||
|
|
||||||
On the other hand, "addNewChar" adds a new digit to the amount that
|
|
||||||
is being typed in. If "setAmount" was used before, the display is
|
|
||||||
cleared and a new input starts.
|
|
||||||
|
|
||||||
TODO: Check overflows, number of digits and such...
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum NumBase {
|
|
||||||
NB_BINARY = 2,
|
|
||||||
NB_OCTAL = 8,
|
|
||||||
NB_DECIMAL = 10,
|
|
||||||
NB_HEX = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class KCalcDisplay : public QFrame {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit KCalcDisplay(QWidget *parent = 0);
|
|
||||||
~KCalcDisplay();
|
|
||||||
|
|
||||||
enum Event {
|
|
||||||
EventReset, // resets display
|
|
||||||
EventClear, // if no error reset display
|
|
||||||
EventError,
|
|
||||||
EventChangeSign
|
|
||||||
};
|
|
||||||
|
|
||||||
bool sendEvent(Event event);
|
|
||||||
void deleteLastDigit();
|
|
||||||
const KNumber &getAmount() const;
|
|
||||||
void newCharacter(const QChar new_char);
|
|
||||||
bool setAmount(const KNumber &new_amount);
|
|
||||||
int setBase(NumBase new_base);
|
|
||||||
void setBeep(bool flag);
|
|
||||||
void setGroupDigits(bool flag);
|
|
||||||
void setTwosComplement(bool flag);
|
|
||||||
void setBinaryGrouping(int digits);
|
|
||||||
void setOctalGrouping(int digits);
|
|
||||||
void setHexadecimalGrouping(int digits);
|
|
||||||
void setFixedPrecision(int precision);
|
|
||||||
void setPrecision(int precision);
|
|
||||||
void setText(const QString &string);
|
|
||||||
QString groupDigits(const QString &displayString, int numDigits);
|
|
||||||
QString text() const;
|
|
||||||
void updateDisplay();
|
|
||||||
void setStatusText(int i, const QString &text);
|
|
||||||
virtual QSize sizeHint() const;
|
|
||||||
|
|
||||||
void changeSettings();
|
|
||||||
void enterDigit(int data);
|
|
||||||
void updateFromCore(const CalcEngine &core,
|
|
||||||
bool store_result_in_history = false);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void slotCut();
|
|
||||||
void slotCopy();
|
|
||||||
void slotPaste(bool bClipboard = true);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void clicked();
|
|
||||||
void changedText(const QString &);
|
|
||||||
void changedAmount(const KNumber &);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void mousePressEvent(QMouseEvent *);
|
|
||||||
virtual void paintEvent(QPaintEvent *p);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool changeSign();
|
|
||||||
void invertColors();
|
|
||||||
void initStyleOption(QStyleOptionFrame *option) const;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void slotSelectionTimedOut();
|
|
||||||
void slotDisplaySelected();
|
|
||||||
void slotHistoryBack();
|
|
||||||
void slotHistoryForward();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString text_;
|
|
||||||
bool beep_;
|
|
||||||
bool groupdigits_;
|
|
||||||
bool twoscomplement_;
|
|
||||||
int binaryGrouping_;
|
|
||||||
int octalGrouping_;
|
|
||||||
int hexadecimalGrouping_;
|
|
||||||
int button_;
|
|
||||||
bool lit_;
|
|
||||||
NumBase num_base_;
|
|
||||||
|
|
||||||
int precision_;
|
|
||||||
int fixed_precision_; // "-1" = no fixed_precision
|
|
||||||
|
|
||||||
KNumber display_amount_;
|
|
||||||
|
|
||||||
QVector<KNumber> history_list_;
|
|
||||||
int history_index_;
|
|
||||||
|
|
||||||
// only used for input of new numbers
|
|
||||||
bool eestate_;
|
|
||||||
bool period_;
|
|
||||||
bool neg_sign_;
|
|
||||||
QString str_int_;
|
|
||||||
QString str_int_exp_;
|
|
||||||
QString str_status_[NUM_STATUS_TEXT];
|
|
||||||
|
|
||||||
QTimer* selection_timer_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,17 +0,0 @@
|
||||||
<!DOCTYPE kpartgui>
|
|
||||||
<kpartgui name="kcalc" version="20">
|
|
||||||
<MenuBar>
|
|
||||||
<Menu name="settings" noMerge="1"><text>&Settings</text>
|
|
||||||
<Action name="mode_simple"/>
|
|
||||||
<Action name="mode_science"/>
|
|
||||||
<Action name="mode_statistics"/>
|
|
||||||
<Action name="mode_numeral"/>
|
|
||||||
<Separator/>
|
|
||||||
<Action name="show_constants"/>
|
|
||||||
<Action name="show_bitset"/>
|
|
||||||
<Separator/>
|
|
||||||
<Action name="options_configure_keybinding"/>
|
|
||||||
<Action name="options_configure"/>
|
|
||||||
</Menu>
|
|
||||||
</MenuBar>
|
|
||||||
</kpartgui>
|
|
|
@ -1,3 +0,0 @@
|
||||||
if(ENABLE_TESTING)
|
|
||||||
add_subdirectory( tests )
|
|
||||||
endif()
|
|
|
@ -1,937 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config-kcalc.h>
|
|
||||||
#include "knumber.h"
|
|
||||||
#include "knumber_base.h"
|
|
||||||
#include "knumber_error.h"
|
|
||||||
#include "knumber_float.h"
|
|
||||||
#include "knumber_fraction.h"
|
|
||||||
#include "knumber_integer.h"
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QRegExp>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
QString KNumber::GroupSeparator = QLatin1String(",");
|
|
||||||
QString KNumber::DecimalSeparator = QLatin1String(".");
|
|
||||||
|
|
||||||
const KNumber KNumber::Zero(QLatin1String("0"));
|
|
||||||
const KNumber KNumber::One(QLatin1String("1"));
|
|
||||||
const KNumber KNumber::NegOne(QLatin1String("-1"));
|
|
||||||
const KNumber KNumber::PosInfinity(QLatin1String("inf"));
|
|
||||||
const KNumber KNumber::NegInfinity(QLatin1String("-inf"));
|
|
||||||
const KNumber KNumber::NaN(QLatin1String("nan"));
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
namespace impl {
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: increment
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void increment(QString &str, int position) {
|
|
||||||
|
|
||||||
for (int i = position; i >= 0; i--) {
|
|
||||||
const char last_char = str[i].toLatin1();
|
|
||||||
switch (last_char) {
|
|
||||||
case '0':
|
|
||||||
str[i] = QLatin1Char('1');
|
|
||||||
break;
|
|
||||||
case '1':
|
|
||||||
str[i] = QLatin1Char('2');
|
|
||||||
break;
|
|
||||||
case '2':
|
|
||||||
str[i] = QLatin1Char('3');
|
|
||||||
break;
|
|
||||||
case '3':
|
|
||||||
str[i] = QLatin1Char('4');
|
|
||||||
break;
|
|
||||||
case '4':
|
|
||||||
str[i] = QLatin1Char('5');
|
|
||||||
break;
|
|
||||||
case '5':
|
|
||||||
str[i] = QLatin1Char('6');
|
|
||||||
break;
|
|
||||||
case '6':
|
|
||||||
str[i] = QLatin1Char('7');
|
|
||||||
break;
|
|
||||||
case '7':
|
|
||||||
str[i] = QLatin1Char('8');
|
|
||||||
break;
|
|
||||||
case '8':
|
|
||||||
str[i] = QLatin1Char('9');
|
|
||||||
break;
|
|
||||||
case '9':
|
|
||||||
str[i] = QLatin1Char('0');
|
|
||||||
if (i == 0) {
|
|
||||||
str.prepend(QLatin1Char('1'));
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
case '.':
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: round
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void round(QString &str, int precision) {
|
|
||||||
|
|
||||||
// Cut off if more digits in fractional part than 'precision'
|
|
||||||
|
|
||||||
int decimalSymbolPos = str.indexOf(QLatin1Char('.'));
|
|
||||||
|
|
||||||
if (decimalSymbolPos == -1) {
|
|
||||||
if (precision == 0) {
|
|
||||||
return;
|
|
||||||
} else if (precision > 0) { // add dot if missing (and needed)
|
|
||||||
str.append(QLatin1Char('.'));
|
|
||||||
decimalSymbolPos = str.length() - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fill up with more than enough zeroes (in case fractional part too short)
|
|
||||||
str.append(QString().fill(QLatin1Char('0'), precision));
|
|
||||||
|
|
||||||
// Now decide whether to round up or down
|
|
||||||
const char last_char = str[decimalSymbolPos + precision + 1].toLatin1();
|
|
||||||
switch (last_char) {
|
|
||||||
case '0':
|
|
||||||
case '1':
|
|
||||||
case '2':
|
|
||||||
case '3':
|
|
||||||
case '4':
|
|
||||||
// nothing to do, rounding down
|
|
||||||
break;
|
|
||||||
case '5':
|
|
||||||
case '6':
|
|
||||||
case '7':
|
|
||||||
case '8':
|
|
||||||
case '9':
|
|
||||||
// rounding up
|
|
||||||
increment(str, decimalSymbolPos + precision);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
decimalSymbolPos = str.indexOf(QLatin1Char('.'));
|
|
||||||
str.truncate(decimalSymbolPos + precision + 1);
|
|
||||||
|
|
||||||
// if precision == 0 delete also '.'
|
|
||||||
if (precision == 0) {
|
|
||||||
str = str.section(QLatin1Char('.'), 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: round
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString round(const QString &s, int precision) {
|
|
||||||
|
|
||||||
QString tmp = s;
|
|
||||||
if (precision < 0 || !QRegExp(QLatin1String("^[+-]?\\d+(\\.\\d+)*(e[+-]?\\d+)?$")).exactMatch(tmp)) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip the sign (for now)
|
|
||||||
const bool neg = (tmp[0] == QLatin1Char('-'));
|
|
||||||
if (neg || tmp[0] == QLatin1Char('+')) {
|
|
||||||
tmp.remove(0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split off exponential part (including 'e'-symbol)
|
|
||||||
QString mantString = tmp.section(QLatin1Char('e'), 0, 0, QString::SectionCaseInsensitiveSeps);
|
|
||||||
QString expString = tmp.section(QLatin1Char('e'), 1, 1, QString::SectionCaseInsensitiveSeps | QString::SectionIncludeLeadingSep);
|
|
||||||
|
|
||||||
if (expString.length() == 1) {
|
|
||||||
expString.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
impl::round(mantString, precision);
|
|
||||||
|
|
||||||
if (neg) {
|
|
||||||
mantString.prepend(QLatin1Char('-'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return mantString + expString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setGroupSeparator
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KNumber::setGroupSeparator(const QString &ch) {
|
|
||||||
GroupSeparator = ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setDecimalSeparator
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KNumber::setDecimalSeparator(const QString &ch) {
|
|
||||||
DecimalSeparator = ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: groupSeparator
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString KNumber::groupSeparator() {
|
|
||||||
return GroupSeparator;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: decimalSeparator
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString KNumber::decimalSeparator() {
|
|
||||||
return DecimalSeparator;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setDefaultFloatPrecision
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KNumber::setDefaultFloatPrecision(int precision) {
|
|
||||||
// Need to transform decimal digits into binary digits
|
|
||||||
const unsigned long int bin_prec = static_cast<unsigned long int>(double(precision) * M_LN10 / M_LN2 + 1);
|
|
||||||
mpf_set_default_prec(bin_prec);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setSplitoffIntegerForFractionOutput
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KNumber::setSplitoffIntegerForFractionOutput(bool x) {
|
|
||||||
detail::knumber_fraction::set_split_off_integer_for_fraction_output(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setDefaultFractionalInput
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KNumber::setDefaultFractionalInput(bool x) {
|
|
||||||
detail::knumber_fraction::set_default_fractional_input(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: setDefaultFloatOutput
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KNumber::setDefaultFloatOutput(bool x) {
|
|
||||||
detail::knumber_fraction::set_default_fractional_output(!x);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: Pi
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::Pi() {
|
|
||||||
|
|
||||||
// TODO: after 4.10 release:
|
|
||||||
// create a new constructor which works just like the normal QString
|
|
||||||
// accepting constructor, but allows us to specify separator
|
|
||||||
// characters, this will allow things to be done slightly more
|
|
||||||
// efficiently
|
|
||||||
QString s(QLatin1String("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068"));
|
|
||||||
s.replace('.', DecimalSeparator);
|
|
||||||
return KNumber(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: Euler
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::Euler() {
|
|
||||||
|
|
||||||
// TODO: after 4.10 release:
|
|
||||||
// create a new constructor which works just like the normal QString
|
|
||||||
// accepting constructor, but allows us to specify separator
|
|
||||||
// characters, this will allow things to be done slightly more
|
|
||||||
// efficiently
|
|
||||||
QString s(QLatin1String("2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274"));
|
|
||||||
s.replace('.', DecimalSeparator);
|
|
||||||
return KNumber(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::KNumber() : value_(new detail::knumber_integer(0)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::KNumber(const QString &s) : value_(0) {
|
|
||||||
|
|
||||||
const QRegExp special_regex(QLatin1String("^(inf|-inf|nan)$"));
|
|
||||||
const QRegExp integer_regex(QLatin1String("^[+-]?\\d+$"));
|
|
||||||
const QRegExp fraction_regex(QLatin1String("^[+-]?\\d+/\\d+$"));
|
|
||||||
const QRegExp float_regex(QString(QLatin1String("^([+-]?\\d*)(%1\\d*)?(e([+-]?\\d+))?$")).arg(QRegExp::escape(DecimalSeparator)));
|
|
||||||
|
|
||||||
if (special_regex.exactMatch(s)) {
|
|
||||||
value_ = new detail::knumber_error(s);
|
|
||||||
} else if (integer_regex.exactMatch(s)) {
|
|
||||||
value_ = new detail::knumber_integer(s);
|
|
||||||
} else if (fraction_regex.exactMatch(s)) {
|
|
||||||
value_ = new detail::knumber_fraction(s);
|
|
||||||
simplify();
|
|
||||||
} else if (float_regex.exactMatch(s)) {
|
|
||||||
|
|
||||||
if(detail::knumber_fraction::default_fractional_input) {
|
|
||||||
|
|
||||||
const QStringList list = float_regex.capturedTexts();
|
|
||||||
if(list.size() == 5) {
|
|
||||||
|
|
||||||
const QString ipart = list[1];
|
|
||||||
const QString fpart = list[2];
|
|
||||||
const QString epart = list[3];
|
|
||||||
const int e_val = list[4].toInt();
|
|
||||||
|
|
||||||
QString num = ipart + fpart.mid(1);
|
|
||||||
QString den = QLatin1String("1") + QString(fpart.size() - 1, QLatin1Char('0'));
|
|
||||||
|
|
||||||
if(e_val < 0) {
|
|
||||||
den = den + QString(::abs(e_val), QLatin1Char('0'));
|
|
||||||
} else if(e_val > 0) {
|
|
||||||
num = num + QString(::abs(e_val), QLatin1Char('0'));
|
|
||||||
}
|
|
||||||
|
|
||||||
value_ = new detail::knumber_fraction(QString(QLatin1String("%1/%2")).arg(num, den));
|
|
||||||
simplify();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// we need to normalize the decimal searator to US style because that's
|
|
||||||
// the only type that the GMP function accept
|
|
||||||
QString new_s = s;
|
|
||||||
new_s.replace(DecimalSeparator, QLatin1String("."));
|
|
||||||
|
|
||||||
value_ = new detail::knumber_float(new_s);
|
|
||||||
simplify();
|
|
||||||
} else {
|
|
||||||
value_ = new detail::knumber_error(detail::knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::KNumber(qint32 value) : value_(new detail::knumber_integer(value)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::KNumber(qint64 value) : value_(new detail::knumber_integer(value)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::KNumber(quint32 value) : value_(new detail::knumber_integer(value)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::KNumber(quint64 value) : value_(new detail::knumber_integer(value)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::KNumber(qint64 num, quint64 den) : value_(new detail::knumber_fraction(num, den)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::KNumber(quint64 num, quint64 den) : value_(new detail::knumber_fraction(num, den)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::KNumber(double value) : value_(new detail::knumber_float(value)) {
|
|
||||||
simplify();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::KNumber(const KNumber &other) : value_(0) {
|
|
||||||
if(&other != this) {
|
|
||||||
value_ = other.value_->clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: ~KNumber
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::~KNumber() {
|
|
||||||
delete value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: type
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber::Type KNumber::type() const {
|
|
||||||
|
|
||||||
if(dynamic_cast<detail::knumber_integer *>(value_)) {
|
|
||||||
return TYPE_INTEGER;
|
|
||||||
} else if(dynamic_cast<detail::knumber_float *>(value_)) {
|
|
||||||
return TYPE_FLOAT;
|
|
||||||
} else if(dynamic_cast<detail::knumber_fraction *>(value_)) {
|
|
||||||
return TYPE_FRACTION;
|
|
||||||
} else if(dynamic_cast<detail::knumber_error *>(value_)) {
|
|
||||||
return TYPE_ERROR;
|
|
||||||
} else {
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return TYPE_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator=
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator=(const KNumber &rhs) {
|
|
||||||
KNumber(rhs).swap(*this);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: swap
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KNumber::swap(KNumber &other) {
|
|
||||||
qSwap(value_, other.value_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: integerPart
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::integerPart() const {
|
|
||||||
|
|
||||||
KNumber x(*this);
|
|
||||||
|
|
||||||
if(detail::knumber_integer *const p = dynamic_cast<detail::knumber_integer *>(value_)) {
|
|
||||||
// NO-OP
|
|
||||||
Q_UNUSED(p);
|
|
||||||
} else if(detail::knumber_float *const p = dynamic_cast<detail::knumber_float *>(value_)) {
|
|
||||||
detail::knumber_base *v = new detail::knumber_integer(p);
|
|
||||||
qSwap(v, x.value_);
|
|
||||||
delete v;
|
|
||||||
} else if(detail::knumber_fraction *const p = dynamic_cast<detail::knumber_fraction *>(value_)) {
|
|
||||||
detail::knumber_base *v = new detail::knumber_integer(p);
|
|
||||||
qSwap(v, x.value_);
|
|
||||||
delete v;
|
|
||||||
} else if(detail::knumber_error *const p = dynamic_cast<detail::knumber_error *>(value_)) {
|
|
||||||
// NO-OP
|
|
||||||
Q_UNUSED(p);
|
|
||||||
} else {
|
|
||||||
Q_ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: simplify
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KNumber::simplify() {
|
|
||||||
|
|
||||||
if(value_->is_integer()) {
|
|
||||||
|
|
||||||
if(detail::knumber_integer *const p = dynamic_cast<detail::knumber_integer *>(value_)) {
|
|
||||||
// NO-OP
|
|
||||||
Q_UNUSED(p);
|
|
||||||
} else if(detail::knumber_float *const p = dynamic_cast<detail::knumber_float *>(value_)) {
|
|
||||||
detail::knumber_base *v = new detail::knumber_integer(p);
|
|
||||||
qSwap(v, value_);
|
|
||||||
delete v;
|
|
||||||
} else if(detail::knumber_fraction *const p = dynamic_cast<detail::knumber_fraction *>(value_)) {
|
|
||||||
detail::knumber_base *v = new detail::knumber_integer(p);
|
|
||||||
qSwap(v, value_);
|
|
||||||
delete v;
|
|
||||||
} else if(detail::knumber_error *const p = dynamic_cast<detail::knumber_error *>(value_)) {
|
|
||||||
// NO-OP
|
|
||||||
Q_UNUSED(p);
|
|
||||||
} else {
|
|
||||||
Q_ASSERT(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator+=
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator+=(const KNumber &rhs) {
|
|
||||||
value_ = value_->add(rhs.value_);
|
|
||||||
simplify();
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator-=
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator-=(const KNumber &rhs) {
|
|
||||||
value_ = value_->sub(rhs.value_);
|
|
||||||
simplify();
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator*=
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator*=(const KNumber &rhs) {
|
|
||||||
value_ = value_->mul(rhs.value_);
|
|
||||||
simplify();
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator/=
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator/=(const KNumber &rhs) {
|
|
||||||
|
|
||||||
// Fix for bug #330577, x /0 is undefined, not infinity
|
|
||||||
// Also indirectly fixes bug #329897, tan(90) is undefined, not infinity
|
|
||||||
if(rhs == Zero) {
|
|
||||||
*this = NaN;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_ = value_->div(rhs.value_);
|
|
||||||
simplify();
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator%=
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator%=(const KNumber &rhs) {
|
|
||||||
value_ = value_->mod(rhs.value_);
|
|
||||||
simplify();
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator&=
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator&=(const KNumber &rhs) {
|
|
||||||
value_ = value_->bitwise_and(rhs.value_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator|=
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator|=(const KNumber &rhs) {
|
|
||||||
value_ = value_->bitwise_or(rhs.value_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator^=
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator^=(const KNumber &rhs) {
|
|
||||||
value_ = value_->bitwise_xor(rhs.value_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator<<
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator<<=(const KNumber &rhs) {
|
|
||||||
value_ = value_->bitwise_shift(rhs.value_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator>>=
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber &KNumber::operator>>=(const KNumber &rhs) {
|
|
||||||
const KNumber rhs_neg(-rhs);
|
|
||||||
value_ = value_->bitwise_shift(rhs_neg.value_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator-
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::operator-() const {
|
|
||||||
KNumber x(*this);
|
|
||||||
x.value_ = x.value_->neg();
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: operator~
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::operator~() const {
|
|
||||||
KNumber x(*this);
|
|
||||||
x.value_ = x.value_->cmp();
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: toQString
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString KNumber::toQString(int width, int precision) const {
|
|
||||||
|
|
||||||
if(value_->is_zero()) {
|
|
||||||
return QLatin1String("0");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString s;
|
|
||||||
|
|
||||||
if(detail::knumber_integer *const p = dynamic_cast<detail::knumber_integer *>(value_)) {
|
|
||||||
if(width > 0) {
|
|
||||||
s = detail::knumber_float(p).toString(width);
|
|
||||||
} else {
|
|
||||||
s = value_->toString(width);
|
|
||||||
}
|
|
||||||
} else if(detail::knumber_float *const p = dynamic_cast<detail::knumber_float *>(value_)) {
|
|
||||||
if(width > 0) {
|
|
||||||
s = value_->toString(width);
|
|
||||||
} else {
|
|
||||||
s = value_->toString(3 * mpf_get_default_prec() / 10);
|
|
||||||
}
|
|
||||||
} else if(detail::knumber_fraction *const p = dynamic_cast<detail::knumber_fraction *>(value_)) {
|
|
||||||
s = value_->toString(width);
|
|
||||||
} else {
|
|
||||||
return value_->toString(width);
|
|
||||||
}
|
|
||||||
|
|
||||||
// now do some rounding to make sure things are displayed reasonably
|
|
||||||
if (precision >= 0) {
|
|
||||||
return round(s, precision);
|
|
||||||
} else {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: toUint64
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
quint64 KNumber::toUint64() const {
|
|
||||||
return value_->toUint64();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: toInt64
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
qint64 KNumber::toInt64() const {
|
|
||||||
return value_->toInt64();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: abs
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::abs() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->abs();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: cbrt
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::cbrt() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->cbrt();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sqrt
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::sqrt() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->sqrt();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: pow
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::pow(const KNumber &x) const {
|
|
||||||
|
|
||||||
// Fix for bug #330711 (pow(0, -x) was causing crashes
|
|
||||||
// Fix for bug #330597 (pow(0,0) was 1 now it is NaN
|
|
||||||
// Thanks to Raushan Kumar for identifying the issue and submitting
|
|
||||||
// patches
|
|
||||||
if(*this == Zero && x <= Zero) {
|
|
||||||
return NaN;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the LHS is a special then we can use this function
|
|
||||||
// no matter what, cause the result is a special too
|
|
||||||
if(!dynamic_cast<detail::knumber_error *>(value_)) {
|
|
||||||
// number much bigger than this tend to crash GMP with
|
|
||||||
// an abort
|
|
||||||
if(x > KNumber(QLatin1String("1000000000"))) {
|
|
||||||
return PosInfinity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->pow(x.value_);
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sin
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::sin() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->sin();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: cos
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::cos() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->cos();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: tan
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::tan() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->tan();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: tgamma
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::tgamma() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
if(z > KNumber(QLatin1String("10000000000"))) {
|
|
||||||
return PosInfinity;
|
|
||||||
}
|
|
||||||
z.value_ = z.value_->tgamma();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: asin
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::asin() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->asin();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: acos
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::acos() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->acos();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: atan
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::atan() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->atan();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sinh
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::sinh() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->sinh();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: cosh
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::cosh() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->cosh();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: tanh
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::tanh() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->tanh();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: asinh
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::asinh() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->asinh();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: acosh
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::acosh() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->acosh();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: atanh
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::atanh() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->atanh();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: factorial
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::factorial() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
|
|
||||||
// number much bigger than this tend to crash GMP with
|
|
||||||
// an abort
|
|
||||||
if(z > KNumber(QLatin1String("10000000000"))) {
|
|
||||||
return PosInfinity;
|
|
||||||
}
|
|
||||||
|
|
||||||
z.value_ = z.value_->factorial();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: log2
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::log2() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->log2();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: log10
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::log10() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->log10();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: ln
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::ln() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->ln();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: floor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::floor() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->floor();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: ceil
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::ceil() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->ceil();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: exp2
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::exp2() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->exp2();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: exp10
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::exp10() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->exp10();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: exp
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::exp() const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->exp();
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: bin
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KNumber::bin(const KNumber &x) const {
|
|
||||||
KNumber z(*this);
|
|
||||||
z.value_ = z.value_->bin(x.value_);
|
|
||||||
z.simplify();
|
|
||||||
return z;
|
|
||||||
}
|
|
|
@ -1,171 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KNUMBER_H_
|
|
||||||
#define KNUMBER_H_
|
|
||||||
|
|
||||||
#include "knumber_operators.h"
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
class knumber_base;
|
|
||||||
}
|
|
||||||
|
|
||||||
class KNumber {
|
|
||||||
private:
|
|
||||||
friend bool operator==(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
friend bool operator!=(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
friend bool operator>=(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
friend bool operator<=(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
friend bool operator>(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
friend bool operator<(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum Type {
|
|
||||||
TYPE_ERROR,
|
|
||||||
TYPE_INTEGER,
|
|
||||||
TYPE_FLOAT,
|
|
||||||
TYPE_FRACTION
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
// useful constants
|
|
||||||
static const KNumber Zero;
|
|
||||||
static const KNumber One;
|
|
||||||
static const KNumber NegOne;
|
|
||||||
static const KNumber PosInfinity;
|
|
||||||
static const KNumber NegInfinity;
|
|
||||||
static const KNumber NaN;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static KNumber Pi();
|
|
||||||
static KNumber Euler();
|
|
||||||
|
|
||||||
public:
|
|
||||||
// construction/destruction
|
|
||||||
KNumber();
|
|
||||||
explicit KNumber(const QString &s);
|
|
||||||
|
|
||||||
explicit KNumber(qint32 value);
|
|
||||||
explicit KNumber(qint64 value);
|
|
||||||
explicit KNumber(quint32 value);
|
|
||||||
explicit KNumber(quint64 value);
|
|
||||||
|
|
||||||
KNumber(qint64 num, quint64 den);
|
|
||||||
KNumber(quint64 num, quint64 den);
|
|
||||||
|
|
||||||
explicit KNumber(double value);
|
|
||||||
|
|
||||||
KNumber(const KNumber &other);
|
|
||||||
~KNumber();
|
|
||||||
|
|
||||||
public:
|
|
||||||
Type type() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// assignment
|
|
||||||
KNumber &operator=(const KNumber &rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
// basic math operators
|
|
||||||
KNumber &operator+=(const KNumber &rhs);
|
|
||||||
KNumber &operator-=(const KNumber &rhs);
|
|
||||||
KNumber &operator*=(const KNumber &rhs);
|
|
||||||
KNumber &operator/=(const KNumber &rhs);
|
|
||||||
KNumber &operator%=(const KNumber &rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
// bitwise operators
|
|
||||||
KNumber &operator&=(const KNumber &rhs);
|
|
||||||
KNumber &operator|=(const KNumber &rhs);
|
|
||||||
KNumber &operator^=(const KNumber &rhs);
|
|
||||||
KNumber &operator<<=(const KNumber &rhs);
|
|
||||||
KNumber &operator>>=(const KNumber &rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
// neg/cmp
|
|
||||||
KNumber operator-() const;
|
|
||||||
KNumber operator~() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
KNumber integerPart() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
QString toQString(int width = -1, int precision = -1) const;
|
|
||||||
quint64 toUint64() const;
|
|
||||||
qint64 toInt64() const;
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
KNumber abs() const;
|
|
||||||
KNumber cbrt() const;
|
|
||||||
KNumber sqrt() const;
|
|
||||||
KNumber pow(const KNumber &x) const;
|
|
||||||
|
|
||||||
KNumber sin() const;
|
|
||||||
KNumber cos() const;
|
|
||||||
KNumber tan() const;
|
|
||||||
KNumber asin() const;
|
|
||||||
KNumber acos() const;
|
|
||||||
KNumber atan() const;
|
|
||||||
KNumber sinh() const;
|
|
||||||
KNumber cosh() const;
|
|
||||||
KNumber tanh() const;
|
|
||||||
KNumber asinh() const;
|
|
||||||
KNumber acosh() const;
|
|
||||||
KNumber atanh() const;
|
|
||||||
KNumber tgamma() const;
|
|
||||||
|
|
||||||
KNumber factorial() const;
|
|
||||||
|
|
||||||
KNumber log2() const;
|
|
||||||
KNumber log10() const;
|
|
||||||
KNumber ln() const;
|
|
||||||
KNumber floor() const;
|
|
||||||
KNumber ceil() const;
|
|
||||||
KNumber exp2() const;
|
|
||||||
KNumber exp10() const;
|
|
||||||
KNumber exp() const;
|
|
||||||
KNumber bin(const KNumber &x) const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void setDefaultFloatPrecision(int precision);
|
|
||||||
static void setSplitoffIntegerForFractionOutput(bool x);
|
|
||||||
static void setDefaultFractionalInput(bool x);
|
|
||||||
static void setDefaultFloatOutput(bool x);
|
|
||||||
static void setGroupSeparator(const QString &ch);
|
|
||||||
static void setDecimalSeparator(const QString &ch);
|
|
||||||
|
|
||||||
static QString groupSeparator();
|
|
||||||
static QString decimalSeparator();
|
|
||||||
|
|
||||||
public:
|
|
||||||
void swap(KNumber &other);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void simplify();
|
|
||||||
|
|
||||||
private:
|
|
||||||
detail::knumber_base *value_;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static QString GroupSeparator;
|
|
||||||
static QString DecimalSeparator;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,120 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KNUMBER_BASE_H_
|
|
||||||
#define KNUMBER_BASE_H_
|
|
||||||
|
|
||||||
#include <gmp.h>
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
#include <mpfr.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#define KNUMBER_BUFFER(buffername, buffersize) \
|
|
||||||
Q_ASSERT_X(buffersize >= 1, Q_FUNC_INFO, "buffer size is negative or zero"); \
|
|
||||||
char buffername[buffersize]; \
|
|
||||||
::memset(buffername, 0, buffersize * sizeof(char));
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
class knumber_error;
|
|
||||||
class knumber_integer;
|
|
||||||
class knumber_fraction;
|
|
||||||
class knumber_float;
|
|
||||||
|
|
||||||
class knumber_base {
|
|
||||||
public:
|
|
||||||
virtual ~knumber_base() { }
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *clone() = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual QString toString(int precision) const = 0;
|
|
||||||
virtual quint64 toUint64() const = 0;
|
|
||||||
virtual qint64 toInt64() const = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual bool is_integer() const = 0;
|
|
||||||
virtual bool is_zero() const = 0;
|
|
||||||
virtual int sign() const = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// basic math
|
|
||||||
virtual knumber_base *add(knumber_base *rhs) = 0;
|
|
||||||
virtual knumber_base *sub(knumber_base *rhs) = 0;
|
|
||||||
virtual knumber_base *mul(knumber_base *rhs) = 0;
|
|
||||||
virtual knumber_base *div(knumber_base *rhs) = 0;
|
|
||||||
virtual knumber_base *mod(knumber_base *rhs) = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// logical operators
|
|
||||||
virtual knumber_base *bitwise_and(knumber_base *rhs) = 0;
|
|
||||||
virtual knumber_base *bitwise_xor(knumber_base *rhs) = 0;
|
|
||||||
virtual knumber_base *bitwise_or(knumber_base *rhs) = 0;
|
|
||||||
virtual knumber_base *bitwise_shift(knumber_base *rhs) = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// algebraic functions
|
|
||||||
virtual knumber_base *pow(knumber_base *rhs) = 0;
|
|
||||||
virtual knumber_base *neg() = 0;
|
|
||||||
virtual knumber_base *cmp() = 0;
|
|
||||||
virtual knumber_base *abs() = 0;
|
|
||||||
virtual knumber_base *sqrt() = 0;
|
|
||||||
virtual knumber_base *cbrt() = 0;
|
|
||||||
virtual knumber_base *factorial() = 0;
|
|
||||||
virtual knumber_base *reciprocal() = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// special functions
|
|
||||||
virtual knumber_base *log2() = 0;
|
|
||||||
virtual knumber_base *log10() = 0;
|
|
||||||
virtual knumber_base *ln() = 0;
|
|
||||||
virtual knumber_base *exp2() = 0;
|
|
||||||
virtual knumber_base *exp10() = 0;
|
|
||||||
virtual knumber_base *floor() = 0;
|
|
||||||
virtual knumber_base *ceil() = 0;
|
|
||||||
virtual knumber_base *exp() = 0;
|
|
||||||
virtual knumber_base *bin(knumber_base *rhs) = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// trig functions
|
|
||||||
virtual knumber_base *sin() = 0;
|
|
||||||
virtual knumber_base *cos() = 0;
|
|
||||||
virtual knumber_base *tan() = 0;
|
|
||||||
virtual knumber_base *asin() = 0;
|
|
||||||
virtual knumber_base *acos() = 0;
|
|
||||||
virtual knumber_base *atan() = 0;
|
|
||||||
virtual knumber_base *sinh() = 0;
|
|
||||||
virtual knumber_base *cosh() = 0;
|
|
||||||
virtual knumber_base *tanh() = 0;
|
|
||||||
virtual knumber_base *asinh() = 0;
|
|
||||||
virtual knumber_base *acosh() = 0;
|
|
||||||
virtual knumber_base *atanh() = 0;
|
|
||||||
virtual knumber_base *tgamma() = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// comparison
|
|
||||||
virtual int compare(knumber_base *rhs) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,714 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config-kcalc.h>
|
|
||||||
#include "knumber_integer.h"
|
|
||||||
#include "knumber_float.h"
|
|
||||||
#include "knumber_fraction.h"
|
|
||||||
#include "knumber_error.h"
|
|
||||||
#include <cmath> // for M_PI
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_error::knumber_error(Error e) : error_(e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_error::knumber_error(const QString &s) {
|
|
||||||
|
|
||||||
if (s == QLatin1String("nan")) error_ = ERROR_UNDEFINED;
|
|
||||||
else if (s == QLatin1String("inf")) error_ = ERROR_POS_INFINITY;
|
|
||||||
else if (s == QLatin1String("-inf")) error_ = ERROR_NEG_INFINITY;
|
|
||||||
else error_ = ERROR_UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_error::knumber_error() : error_(ERROR_UNDEFINED) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_error::~knumber_error() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_error::knumber_error(const knumber_integer *) : error_(ERROR_UNDEFINED) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_error::knumber_error(const knumber_fraction *) : error_(ERROR_UNDEFINED) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_error::knumber_error(const knumber_float *) : error_(ERROR_UNDEFINED) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_error::knumber_error(const knumber_error *value) : error_(value->error_) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString knumber_error::toString(int precision) const {
|
|
||||||
|
|
||||||
Q_UNUSED(precision);
|
|
||||||
|
|
||||||
switch(error_) {
|
|
||||||
case ERROR_POS_INFINITY:
|
|
||||||
return QLatin1String("inf");
|
|
||||||
case ERROR_NEG_INFINITY:
|
|
||||||
return QLatin1String("-inf");
|
|
||||||
case ERROR_UNDEFINED:
|
|
||||||
default:
|
|
||||||
return QLatin1String("nan");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::add(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
if(error_ == ERROR_POS_INFINITY && p->error_ == ERROR_NEG_INFINITY) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
} else if(error_ == ERROR_NEG_INFINITY && p->error_ == ERROR_POS_INFINITY) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
} else if(p->error_ == ERROR_UNDEFINED) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::sub(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
if(error_ == ERROR_POS_INFINITY && p->error_ == ERROR_POS_INFINITY) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
} else if(error_ == ERROR_NEG_INFINITY && p->error_ == ERROR_NEG_INFINITY) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
} else if(p->error_ == ERROR_UNDEFINED) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::mul(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
if(p->is_zero()) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
if(p->is_zero()) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
if(p->is_zero()) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
if(error_ == ERROR_POS_INFINITY && p->error_ == ERROR_NEG_INFINITY) {
|
|
||||||
error_ = ERROR_NEG_INFINITY;
|
|
||||||
} else if(error_ == ERROR_NEG_INFINITY && p->error_ == ERROR_POS_INFINITY) {
|
|
||||||
error_ = ERROR_NEG_INFINITY;
|
|
||||||
} else if(error_ == ERROR_NEG_INFINITY && p->error_ == ERROR_NEG_INFINITY) {
|
|
||||||
error_ = ERROR_POS_INFINITY;
|
|
||||||
} else if(p->error_ == ERROR_UNDEFINED) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::div(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::mod(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::pow(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
|
|
||||||
switch(error_) {
|
|
||||||
case ERROR_POS_INFINITY:
|
|
||||||
if(p->sign() > 0) {
|
|
||||||
return this;
|
|
||||||
} else if(p->sign() < 0) {
|
|
||||||
knumber_integer *n = new knumber_integer(0);
|
|
||||||
delete this;
|
|
||||||
return n;
|
|
||||||
} else {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ERROR_NEG_INFINITY:
|
|
||||||
if(p->sign() > 0) {
|
|
||||||
error_ = ERROR_POS_INFINITY;
|
|
||||||
return this;
|
|
||||||
} else if(p->sign() < 0) {
|
|
||||||
knumber_integer *n = new knumber_integer(0);
|
|
||||||
delete this;
|
|
||||||
return n;
|
|
||||||
} else {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ERROR_UNDEFINED:
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::neg() {
|
|
||||||
|
|
||||||
switch(error_) {
|
|
||||||
case ERROR_POS_INFINITY:
|
|
||||||
error_ = ERROR_NEG_INFINITY;
|
|
||||||
break;
|
|
||||||
case ERROR_NEG_INFINITY:
|
|
||||||
error_ = ERROR_POS_INFINITY;
|
|
||||||
break;
|
|
||||||
case ERROR_UNDEFINED:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::cmp() {
|
|
||||||
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::abs() {
|
|
||||||
|
|
||||||
switch(error_) {
|
|
||||||
case ERROR_NEG_INFINITY:
|
|
||||||
error_ = ERROR_POS_INFINITY;
|
|
||||||
break;
|
|
||||||
case ERROR_POS_INFINITY:
|
|
||||||
case ERROR_UNDEFINED:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::sqrt() {
|
|
||||||
|
|
||||||
switch(error_) {
|
|
||||||
case ERROR_NEG_INFINITY:
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
break;
|
|
||||||
case ERROR_POS_INFINITY:
|
|
||||||
case ERROR_UNDEFINED:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::cbrt() {
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::factorial() {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::sin() {
|
|
||||||
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::cos() {
|
|
||||||
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base* knumber_error::tgamma() {
|
|
||||||
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::tan() {
|
|
||||||
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::asin() {
|
|
||||||
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::acos() {
|
|
||||||
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::atan() {
|
|
||||||
|
|
||||||
switch(error_) {
|
|
||||||
case ERROR_POS_INFINITY:
|
|
||||||
delete this;
|
|
||||||
return new knumber_float(M_PI / 2.0);
|
|
||||||
case ERROR_NEG_INFINITY:
|
|
||||||
delete this;
|
|
||||||
return new knumber_float(-M_PI / 2.0);
|
|
||||||
case ERROR_UNDEFINED:
|
|
||||||
default:
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::sinh() {
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::cosh() {
|
|
||||||
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::tanh() {
|
|
||||||
|
|
||||||
if(sign() > 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(1);
|
|
||||||
} else if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(-1);
|
|
||||||
} else {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::asinh() {
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::acosh() {
|
|
||||||
|
|
||||||
if(sign() < 0) {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::atanh() {
|
|
||||||
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int knumber_error::compare(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
if(sign() > 0) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
if(sign() > 0) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
if(sign() > 0) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
return sign() == p->sign();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::clone() {
|
|
||||||
return new knumber_error(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::bitwise_and(knumber_base *rhs) {
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::bitwise_xor(knumber_base *rhs) {
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::bitwise_or(knumber_base *rhs) {
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::bitwise_shift(knumber_base *rhs) {
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool knumber_error::is_integer() const {
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool knumber_error::is_zero() const {
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int knumber_error::sign() const {
|
|
||||||
|
|
||||||
switch(error_) {
|
|
||||||
case ERROR_POS_INFINITY:
|
|
||||||
return +1;
|
|
||||||
case ERROR_NEG_INFINITY:
|
|
||||||
return -1;
|
|
||||||
case ERROR_UNDEFINED:
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::reciprocal() {
|
|
||||||
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::log2() {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::log10() {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::ln() {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::ceil() {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::floor() {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::exp2() {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::exp10() {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::exp() {
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
quint64 knumber_error::toUint64() const {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
qint64 knumber_error::toInt64() const {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_error::bin(knumber_base *rhs) {
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
error_ = ERROR_UNDEFINED;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,125 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KNUMBER_ERROR_H_
|
|
||||||
#define KNUMBER_ERROR_H_
|
|
||||||
|
|
||||||
#include "knumber_base.h"
|
|
||||||
|
|
||||||
class KNumber;
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
class knumber_error : public knumber_base {
|
|
||||||
friend class ::KNumber;
|
|
||||||
friend class knumber_integer;
|
|
||||||
friend class knumber_fraction;
|
|
||||||
friend class knumber_float;
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum Error {
|
|
||||||
ERROR_UNDEFINED,
|
|
||||||
ERROR_POS_INFINITY,
|
|
||||||
ERROR_NEG_INFINITY
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit knumber_error(const QString &s);
|
|
||||||
explicit knumber_error(Error e);
|
|
||||||
knumber_error();
|
|
||||||
virtual ~knumber_error();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual QString toString(int precision) const;
|
|
||||||
virtual quint64 toUint64() const;
|
|
||||||
virtual qint64 toInt64() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual bool is_integer() const;
|
|
||||||
virtual bool is_zero() const;
|
|
||||||
virtual int sign() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *add(knumber_base *rhs);
|
|
||||||
virtual knumber_base *sub(knumber_base *rhs);
|
|
||||||
virtual knumber_base *mul(knumber_base *rhs);
|
|
||||||
virtual knumber_base *div(knumber_base *rhs);
|
|
||||||
virtual knumber_base *mod(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *bitwise_and(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_xor(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_or(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_shift(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *pow(knumber_base *rhs);
|
|
||||||
virtual knumber_base *neg();
|
|
||||||
virtual knumber_base *cmp();
|
|
||||||
virtual knumber_base *abs();
|
|
||||||
virtual knumber_base *sqrt();
|
|
||||||
virtual knumber_base *cbrt();
|
|
||||||
virtual knumber_base *factorial();
|
|
||||||
virtual knumber_base *reciprocal();
|
|
||||||
virtual knumber_base *tgamma();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *log2();
|
|
||||||
virtual knumber_base *log10();
|
|
||||||
virtual knumber_base *ln();
|
|
||||||
virtual knumber_base *exp2();
|
|
||||||
virtual knumber_base *exp10();
|
|
||||||
virtual knumber_base *floor();
|
|
||||||
virtual knumber_base *ceil();
|
|
||||||
virtual knumber_base *exp();
|
|
||||||
virtual knumber_base *bin(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *sin();
|
|
||||||
virtual knumber_base *cos();
|
|
||||||
virtual knumber_base *tan();
|
|
||||||
virtual knumber_base *asin();
|
|
||||||
virtual knumber_base *acos();
|
|
||||||
virtual knumber_base *atan();
|
|
||||||
virtual knumber_base *sinh();
|
|
||||||
virtual knumber_base *cosh();
|
|
||||||
virtual knumber_base *tanh();
|
|
||||||
virtual knumber_base *asinh();
|
|
||||||
virtual knumber_base *acosh();
|
|
||||||
virtual knumber_base *atanh();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual int compare(knumber_base *rhs);
|
|
||||||
|
|
||||||
private:
|
|
||||||
// conversion constructors
|
|
||||||
explicit knumber_error(const knumber_integer *value);
|
|
||||||
explicit knumber_error(const knumber_fraction *value);
|
|
||||||
explicit knumber_error(const knumber_float *value);
|
|
||||||
explicit knumber_error(const knumber_error *value);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *clone();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Error error_;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,999 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config-kcalc.h>
|
|
||||||
#include "knumber_integer.h"
|
|
||||||
#include "knumber_float.h"
|
|
||||||
#include "knumber_fraction.h"
|
|
||||||
#include "knumber_error.h"
|
|
||||||
#include <QDebug>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
const mpfr_rnd_t knumber_float::rounding_mode = MPFR_RNDN;
|
|
||||||
const mpfr_prec_t knumber_float::precision = 1024;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <double F(double)>
|
|
||||||
knumber_base *knumber_float::execute_libc_func(double x) {
|
|
||||||
const double r = F(x);
|
|
||||||
if(isnan(r)) {
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
} else if(isinf(r)) {
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
} else {
|
|
||||||
mpf_set_d(mpf_, r);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <double F(double, double)>
|
|
||||||
knumber_base *knumber_float::execute_libc_func(double x, double y) {
|
|
||||||
const double r = F(x, y);
|
|
||||||
if(isnan(r)) {
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
} else if(isinf(r)) {
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
} else {
|
|
||||||
mpf_set_d(mpf_, r);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_float::knumber_float(const QString &s) {
|
|
||||||
|
|
||||||
mpf_init(mpf_);
|
|
||||||
mpf_set_str(mpf_, s.toAscii(), 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_float::knumber_float(double value) {
|
|
||||||
|
|
||||||
Q_ASSERT(!isinf(value));
|
|
||||||
Q_ASSERT(!isnan(value));
|
|
||||||
|
|
||||||
mpf_init_set_d(mpf_, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_float::knumber_float(mpf_t mpf) {
|
|
||||||
|
|
||||||
mpf_init(mpf_);
|
|
||||||
mpf_set(mpf_, mpf);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_float::knumber_float(const knumber_float *value) {
|
|
||||||
|
|
||||||
mpf_init_set(mpf_, value->mpf_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_float::knumber_float(const knumber_integer *value) {
|
|
||||||
|
|
||||||
mpf_init(mpf_);
|
|
||||||
mpf_set_z(mpf_, value->mpz_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_float::knumber_float(const knumber_fraction *value) {
|
|
||||||
|
|
||||||
mpf_init(mpf_);
|
|
||||||
mpf_set_q(mpf_, value->mpq_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::clone() {
|
|
||||||
|
|
||||||
return new knumber_float(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_float::~knumber_float() {
|
|
||||||
|
|
||||||
mpf_clear(mpf_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::add(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return add(&f);
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
mpf_add(mpf_, mpf_, p->mpf_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return add(&f);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
knumber_error *e = new knumber_error(p);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::sub(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return sub(&f);
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
mpf_sub(mpf_, mpf_, p->mpf_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return sub(&f);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
knumber_error *e = new knumber_error(p);
|
|
||||||
delete this;
|
|
||||||
return e->neg();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::mul(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return mul(&f);
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
mpf_mul(mpf_, mpf_, p->mpf_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return mul(&f);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
if(is_zero()) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
knumber_error *e = new knumber_error(p);
|
|
||||||
return e->neg();
|
|
||||||
} else {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::div(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(rhs->is_zero()) {
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_NEG_INFINITY);
|
|
||||||
} else {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return div(&f);
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
mpf_div(mpf_, mpf_, p->mpf_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return div(&f);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
if(p->sign() > 0 || p->sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::mod(knumber_base *rhs) {
|
|
||||||
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
|
|
||||||
if(rhs->is_zero()) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::bitwise_and(knumber_base *rhs) {
|
|
||||||
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::bitwise_xor(knumber_base *rhs) {
|
|
||||||
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::bitwise_or(knumber_base *rhs) {
|
|
||||||
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::bitwise_shift(knumber_base *rhs) {
|
|
||||||
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
delete this;
|
|
||||||
// NOTE: we don't support bitwise operations with non-integer operands
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::neg() {
|
|
||||||
|
|
||||||
mpf_neg(mpf_, mpf_);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::cmp() {
|
|
||||||
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::abs() {
|
|
||||||
|
|
||||||
mpf_abs(mpf_, mpf_);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::sqrt() {
|
|
||||||
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_sqrt(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
#else
|
|
||||||
mpf_sqrt(mpf_, mpf_);
|
|
||||||
#endif
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::cbrt() {
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_cbrt(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
#ifdef Q_CC_MSVC
|
|
||||||
return execute_libc_func< ::pow>(x, 1.0 / 3.0);
|
|
||||||
#else
|
|
||||||
return execute_libc_func< ::cbrt>(x);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::factorial() {
|
|
||||||
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
knumber_integer *i = new knumber_integer(this);
|
|
||||||
delete this;
|
|
||||||
return i->factorial();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::sin() {
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_sin(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::sin>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::floor() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_floor(mpfr, mpfr);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::floor>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::ceil() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_ceil(mpfr, mpfr);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::ceil>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::cos() {
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_cos(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::cos>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::tan() {
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_tan(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::tan>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::asin() {
|
|
||||||
if(mpf_cmp_d(mpf_, 1.0) > 0 || mpf_cmp_d(mpf_, -1.0) < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_asin(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::asin>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------s
|
|
||||||
knumber_base *knumber_float::acos() {
|
|
||||||
if(mpf_cmp_d(mpf_, 1.0) > 0 || mpf_cmp_d(mpf_, -1.0) < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_acos(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::acos>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::atan() {
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_atan(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::atan>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::sinh() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_sinh(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
return execute_libc_func< ::sinh>(x);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::cosh() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_cosh(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
return execute_libc_func< ::cosh>(x);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::tanh() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_tanh(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
return execute_libc_func< ::tanh>(x);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::tgamma() {
|
|
||||||
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_gamma(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::tgamma>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::asinh() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_asinh(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
return execute_libc_func< ::asinh>(x);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::acosh() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_acosh(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
return execute_libc_func< ::acosh>(x);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::atanh() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_atanh(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
return execute_libc_func< ::atanh>(x);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::pow(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
mpf_pow_ui(mpf_, mpf_, mpz_get_ui(p->mpz_));
|
|
||||||
|
|
||||||
if(p->sign() < 0) {
|
|
||||||
return reciprocal();
|
|
||||||
} else {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
return execute_libc_func< ::pow>(mpf_get_d(mpf_), mpf_get_d(p->mpf_));
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return execute_libc_func< ::pow>(mpf_get_d(mpf_), mpf_get_d(f.mpf_));
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
if(p->sign() > 0) {
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
} else if(p->sign() < 0) {
|
|
||||||
knumber_integer *n = new knumber_integer(0);
|
|
||||||
delete this;
|
|
||||||
return n;
|
|
||||||
} else {
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int knumber_float::compare(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return compare(&f);
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
return mpf_cmp(mpf_, p->mpf_);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_float f(p);
|
|
||||||
return compare(&f);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
// NOTE: any number compared to NaN/Inf/-Inf always compares less
|
|
||||||
// at the moment
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString knumber_float::toString(int precision) const {
|
|
||||||
|
|
||||||
size_t size;
|
|
||||||
if (precision > 0) {
|
|
||||||
size = gmp_snprintf(NULL, 0, "%.*Fg", precision, mpf_) + 1;
|
|
||||||
} else {
|
|
||||||
size = gmp_snprintf(NULL, 0, "%.Fg", mpf_) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
KNUMBER_BUFFER(buf, size);
|
|
||||||
|
|
||||||
if (precision > 0) {
|
|
||||||
gmp_snprintf(&buf[0], size, "%.*Fg", precision, mpf_);
|
|
||||||
} else {
|
|
||||||
gmp_snprintf(&buf[0], size, "%.Fg", mpf_);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QLatin1String(&buf[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool knumber_float::is_integer() const {
|
|
||||||
|
|
||||||
return mpf_integer_p(mpf_) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool knumber_float::is_zero() const {
|
|
||||||
|
|
||||||
return mpf_sgn(mpf_) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int knumber_float::sign() const {
|
|
||||||
|
|
||||||
return mpf_sgn(mpf_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::reciprocal() {
|
|
||||||
|
|
||||||
mpf_t mpf;
|
|
||||||
mpf_init_set_d(mpf, 1.0);
|
|
||||||
mpf_div(mpf_, mpf, mpf_);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::log2() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_log2(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::log2>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::log10() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_log10(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::log10>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::ln() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_log(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::log>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::exp2() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_exp2(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::exp2>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::exp10() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_exp10(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::pow>(10, x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::exp() {
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
mpfr_t mpfr;
|
|
||||||
mpfr_init_set_f(mpfr, mpf_, rounding_mode);
|
|
||||||
mpfr_exp(mpfr, mpfr, rounding_mode);
|
|
||||||
mpfr_get_f(mpf_, mpfr, rounding_mode);
|
|
||||||
mpfr_clear(mpfr);
|
|
||||||
return this;
|
|
||||||
#else
|
|
||||||
const double x = mpf_get_d(mpf_);
|
|
||||||
if(isinf(x)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
} else {
|
|
||||||
return execute_libc_func< ::exp>(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
quint64 knumber_float::toUint64() const {
|
|
||||||
return knumber_integer(this).toUint64();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
qint64 knumber_float::toInt64() const {
|
|
||||||
return knumber_integer(this).toInt64();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_float::bin(knumber_base *rhs) {
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,132 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KNUMBER_FLOAT_H_
|
|
||||||
#define KNUMBER_FLOAT_H_
|
|
||||||
|
|
||||||
#include "knumber_base.h"
|
|
||||||
|
|
||||||
class KNumber;
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
class knumber_float : public knumber_base {
|
|
||||||
friend class ::KNumber;
|
|
||||||
friend class knumber_error;
|
|
||||||
friend class knumber_integer;
|
|
||||||
friend class knumber_fraction;
|
|
||||||
|
|
||||||
private:
|
|
||||||
#ifdef KNUMBER_USE_MPFR
|
|
||||||
static const mpfr_rnd_t rounding_mode;
|
|
||||||
static const mpfr_prec_t precision;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit knumber_float(const QString &s);
|
|
||||||
explicit knumber_float(double value);
|
|
||||||
|
|
||||||
explicit knumber_float(mpf_t mpf);
|
|
||||||
virtual ~knumber_float();
|
|
||||||
|
|
||||||
private:
|
|
||||||
// conversion constructors
|
|
||||||
explicit knumber_float(const knumber_integer *value);
|
|
||||||
explicit knumber_float(const knumber_fraction *value);
|
|
||||||
explicit knumber_float(const knumber_float *value);
|
|
||||||
explicit knumber_float(const knumber_error *value);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual QString toString(int precision) const;
|
|
||||||
virtual quint64 toUint64() const;
|
|
||||||
virtual qint64 toInt64() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual bool is_integer() const;
|
|
||||||
virtual bool is_zero() const;
|
|
||||||
virtual int sign() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *add(knumber_base *rhs);
|
|
||||||
virtual knumber_base *sub(knumber_base *rhs);
|
|
||||||
virtual knumber_base *mul(knumber_base *rhs);
|
|
||||||
virtual knumber_base *div(knumber_base *rhs);
|
|
||||||
virtual knumber_base *mod(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *pow(knumber_base *rhs);
|
|
||||||
virtual knumber_base *neg();
|
|
||||||
virtual knumber_base *cmp();
|
|
||||||
virtual knumber_base *abs();
|
|
||||||
virtual knumber_base *sqrt();
|
|
||||||
virtual knumber_base *cbrt();
|
|
||||||
virtual knumber_base *factorial();
|
|
||||||
virtual knumber_base *reciprocal();
|
|
||||||
virtual knumber_base *tgamma();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *log2();
|
|
||||||
virtual knumber_base *log10();
|
|
||||||
virtual knumber_base *ln();
|
|
||||||
virtual knumber_base *floor();
|
|
||||||
virtual knumber_base *ceil();
|
|
||||||
virtual knumber_base *exp2();
|
|
||||||
virtual knumber_base *exp10();
|
|
||||||
virtual knumber_base *exp();
|
|
||||||
virtual knumber_base *bin(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *sin();
|
|
||||||
virtual knumber_base *cos();
|
|
||||||
virtual knumber_base *tan();
|
|
||||||
virtual knumber_base *asin();
|
|
||||||
virtual knumber_base *acos();
|
|
||||||
virtual knumber_base *atan();
|
|
||||||
virtual knumber_base *sinh();
|
|
||||||
virtual knumber_base *cosh();
|
|
||||||
virtual knumber_base *tanh();
|
|
||||||
virtual knumber_base *asinh();
|
|
||||||
virtual knumber_base *acosh();
|
|
||||||
virtual knumber_base *atanh();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual int compare(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *bitwise_and(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_xor(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_or(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_shift(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *clone();
|
|
||||||
|
|
||||||
private:
|
|
||||||
template <double F(double)>
|
|
||||||
knumber_base *execute_libc_func(double x);
|
|
||||||
|
|
||||||
template <double F(double, double)>
|
|
||||||
knumber_base *execute_libc_func(double x, double y);
|
|
||||||
|
|
||||||
private:
|
|
||||||
mpf_t mpf_;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,908 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config-kcalc.h>
|
|
||||||
#include "knumber_integer.h"
|
|
||||||
#include "knumber_float.h"
|
|
||||||
#include "knumber_fraction.h"
|
|
||||||
#include "knumber_error.h"
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
bool knumber_fraction::default_fractional_input = false;
|
|
||||||
bool knumber_fraction::default_fractional_output = true;
|
|
||||||
bool knumber_fraction::split_off_integer_for_fraction_output = false;
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void knumber_fraction::set_default_fractional_input(bool value) {
|
|
||||||
default_fractional_input = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void knumber_fraction::set_default_fractional_output(bool value) {
|
|
||||||
default_fractional_output = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void knumber_fraction::set_split_off_integer_for_fraction_output(bool value) {
|
|
||||||
split_off_integer_for_fraction_output = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_fraction::knumber_fraction(const QString &s) {
|
|
||||||
mpq_init(mpq_);
|
|
||||||
mpq_set_str(mpq_, s.toAscii(), 10);
|
|
||||||
mpq_canonicalize(mpq_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_fraction::knumber_fraction(qint64 num, quint64 den) {
|
|
||||||
mpq_init(mpq_);
|
|
||||||
mpq_set_si(mpq_, num, den);
|
|
||||||
mpq_canonicalize(mpq_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_fraction::knumber_fraction(quint64 num, quint64 den) {
|
|
||||||
mpq_init(mpq_);
|
|
||||||
mpq_set_ui(mpq_, num, den);
|
|
||||||
mpq_canonicalize(mpq_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_fraction::knumber_fraction(mpq_t mpq) {
|
|
||||||
mpq_init(mpq_);
|
|
||||||
mpq_set(mpq_, mpq);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_fraction::knumber_fraction(const knumber_fraction *value) {
|
|
||||||
mpq_init(mpq_);
|
|
||||||
mpq_set(mpq_, value->mpq_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_fraction::knumber_fraction(const knumber_integer *value) {
|
|
||||||
mpq_init(mpq_);
|
|
||||||
mpq_set_z(mpq_, value->mpz_);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_fraction::knumber_fraction(const knumber_float *value) {
|
|
||||||
mpq_init(mpq_);
|
|
||||||
mpq_set_f(mpq_, value->mpf_);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::clone() {
|
|
||||||
return new knumber_fraction(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_fraction::~knumber_fraction() {
|
|
||||||
mpq_clear(mpq_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool knumber_fraction::is_integer() const {
|
|
||||||
return (mpz_cmp_ui(mpq_denref(mpq_), 1) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::add(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_fraction q(p);
|
|
||||||
mpq_add(mpq_, mpq_, q.mpq_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->add(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
mpq_add(mpq_, mpq_, p->mpq_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
knumber_error *e = new knumber_error(p);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::sub(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_fraction q(p);
|
|
||||||
mpq_sub(mpq_, mpq_, q.mpq_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->sub(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
mpq_sub(mpq_, mpq_, p->mpq_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
knumber_error *e = new knumber_error(p);
|
|
||||||
delete this;
|
|
||||||
return e->neg();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::mul(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_fraction q(p);
|
|
||||||
mpq_mul(mpq_, mpq_, q.mpq_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *q = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return q->mul(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
mpq_mul(mpq_, mpq_, p->mpq_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
if(is_zero()) {
|
|
||||||
delete this;
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
knumber_error *e = new knumber_error(p);
|
|
||||||
return e->neg();
|
|
||||||
} else {
|
|
||||||
delete this;
|
|
||||||
knumber_error *e = new knumber_error(p);
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::div(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(rhs->is_zero()) {
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_NEG_INFINITY);
|
|
||||||
} else {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_fraction f(p);
|
|
||||||
return div(&f);
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->div(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
mpq_div(mpq_, mpq_, p->mpq_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
|
|
||||||
if(p->sign() > 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(0);
|
|
||||||
} else if(p->sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
knumber_error *e = new knumber_error(p);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::mod(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(rhs->is_zero()) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: we don't support modulus operations with non-integer operands
|
|
||||||
mpq_set_d(mpq_, 0);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::bitwise_and(knumber_base *rhs) {
|
|
||||||
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
delete this;
|
|
||||||
// NOTE: we don't support bitwise operations with non-integer operands
|
|
||||||
return new knumber_integer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::bitwise_xor(knumber_base *rhs) {
|
|
||||||
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
delete this;
|
|
||||||
// NOTE: we don't support bitwise operations with non-integer operands
|
|
||||||
return new knumber_integer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::bitwise_or(knumber_base *rhs) {
|
|
||||||
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
delete this;
|
|
||||||
// NOTE: we don't support bitwise operations with non-integer operands
|
|
||||||
return new knumber_integer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::bitwise_shift(knumber_base *rhs) {
|
|
||||||
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
delete this;
|
|
||||||
// NOTE: we don't support bitwise operations with non-integer operands
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::neg() {
|
|
||||||
mpq_neg(mpq_, mpq_);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::abs() {
|
|
||||||
mpq_abs(mpq_, mpq_);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::cmp() {
|
|
||||||
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::sqrt() {
|
|
||||||
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mpz_perfect_square_p(mpq_numref(mpq_)) && mpz_perfect_square_p(mpq_denref(mpq_))) {
|
|
||||||
mpz_t num;
|
|
||||||
mpz_t den;
|
|
||||||
mpz_init(num);
|
|
||||||
mpz_init(den);
|
|
||||||
mpq_get_num(num, mpq_);
|
|
||||||
mpq_get_den(den, mpq_);
|
|
||||||
mpz_sqrt(num, num);
|
|
||||||
mpz_sqrt(den, den);
|
|
||||||
mpq_set_num(mpq_, num);
|
|
||||||
mpq_set_den(mpq_, den);
|
|
||||||
mpq_canonicalize(mpq_);
|
|
||||||
mpz_clear(num);
|
|
||||||
mpz_clear(den);
|
|
||||||
return this;
|
|
||||||
} else {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->sqrt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::cbrt() {
|
|
||||||
|
|
||||||
// TODO: figure out how to properly use mpq_numref/mpq_denref here
|
|
||||||
mpz_t num;
|
|
||||||
mpz_t den;
|
|
||||||
|
|
||||||
mpz_init(num);
|
|
||||||
mpz_init(den);
|
|
||||||
|
|
||||||
mpq_get_num(num, mpq_);
|
|
||||||
mpq_get_den(den, mpq_);
|
|
||||||
|
|
||||||
if(mpz_root(num, num, 3) && mpz_root(den, den, 3)) {
|
|
||||||
mpq_set_num(mpq_, num);
|
|
||||||
mpq_set_den(mpq_, den);
|
|
||||||
mpq_canonicalize(mpq_);
|
|
||||||
mpz_clear(num);
|
|
||||||
mpz_clear(den);
|
|
||||||
return this;
|
|
||||||
} else {
|
|
||||||
mpz_clear(num);
|
|
||||||
mpz_clear(den);
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->cbrt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::factorial() {
|
|
||||||
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
knumber_integer *i = new knumber_integer(this);
|
|
||||||
delete this;
|
|
||||||
return i->factorial();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::pow(knumber_base *rhs) {
|
|
||||||
|
|
||||||
// TODO: figure out how to properly use mpq_numref/mpq_denref here
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
|
|
||||||
mpz_t num;
|
|
||||||
mpz_t den;
|
|
||||||
|
|
||||||
mpz_init(num);
|
|
||||||
mpz_init(den);
|
|
||||||
|
|
||||||
mpq_get_num(num, mpq_);
|
|
||||||
mpq_get_den(den, mpq_);
|
|
||||||
|
|
||||||
mpz_pow_ui(num, num, mpz_get_ui(p->mpz_));
|
|
||||||
mpz_pow_ui(den, den, mpz_get_ui(p->mpz_));
|
|
||||||
mpq_set_num(mpq_, num);
|
|
||||||
mpq_set_den(mpq_, den);
|
|
||||||
mpq_canonicalize(mpq_);
|
|
||||||
mpz_clear(num);
|
|
||||||
mpz_clear(den);
|
|
||||||
|
|
||||||
if(p->sign() < 0) {
|
|
||||||
return reciprocal();
|
|
||||||
} else {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->pow(rhs);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
|
|
||||||
// ok, so if any part of the number is > 1,000,000, then we risk
|
|
||||||
// the pow function overflowing... so we'll just convert to float to be safe
|
|
||||||
// TODO: at some point, we should figure out exactly what the threashold is
|
|
||||||
// and if there is a better way to determine if the pow function will
|
|
||||||
// overflow.
|
|
||||||
if(mpz_cmpabs_ui(mpq_numref(mpq_), 1000000) > 0 || mpz_cmpabs_ui(mpq_denref(mpq_), 1000000) > 0 || mpz_cmpabs_ui(mpq_numref(p->mpq_), 1000000) > 0 || mpz_cmpabs_ui(mpq_denref(p->mpq_), 1000000) > 0) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->pow(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
mpz_t lhs_num;
|
|
||||||
mpz_t lhs_den;
|
|
||||||
mpz_t rhs_num;
|
|
||||||
mpz_t rhs_den;
|
|
||||||
|
|
||||||
mpz_init(lhs_num);
|
|
||||||
mpz_init(lhs_den);
|
|
||||||
mpz_init(rhs_num);
|
|
||||||
mpz_init(rhs_den);
|
|
||||||
|
|
||||||
mpq_get_num(lhs_num, mpq_);
|
|
||||||
mpq_get_den(lhs_den, mpq_);
|
|
||||||
mpq_get_num(rhs_num, p->mpq_);
|
|
||||||
mpq_get_den(rhs_den, p->mpq_);
|
|
||||||
|
|
||||||
mpz_pow_ui(lhs_num, lhs_num, mpz_get_ui(rhs_num));
|
|
||||||
mpz_pow_ui(lhs_den, lhs_den, mpz_get_ui(rhs_num));
|
|
||||||
|
|
||||||
if(mpz_sgn(lhs_num) < 0 && mpz_even_p(rhs_den)) {
|
|
||||||
mpz_clear(lhs_num);
|
|
||||||
mpz_clear(lhs_den);
|
|
||||||
mpz_clear(rhs_num);
|
|
||||||
mpz_clear(rhs_den);
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mpz_sgn(lhs_den) < 0 && mpz_even_p(rhs_den)) {
|
|
||||||
mpz_clear(lhs_num);
|
|
||||||
mpz_clear(lhs_den);
|
|
||||||
mpz_clear(rhs_num);
|
|
||||||
mpz_clear(rhs_den);
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
const int n1 = mpz_root(lhs_num, lhs_num, mpz_get_ui(rhs_den));
|
|
||||||
const int n2 = mpz_root(lhs_den, lhs_den, mpz_get_ui(rhs_den));
|
|
||||||
|
|
||||||
if(n1 && n2) {
|
|
||||||
|
|
||||||
mpq_set_num(mpq_, lhs_num);
|
|
||||||
mpq_set_den(mpq_, lhs_den);
|
|
||||||
mpq_canonicalize(mpq_);
|
|
||||||
mpz_clear(lhs_num);
|
|
||||||
mpz_clear(lhs_den);
|
|
||||||
mpz_clear(rhs_num);
|
|
||||||
mpz_clear(rhs_den);
|
|
||||||
|
|
||||||
if(p->sign() < 0) {
|
|
||||||
return reciprocal();
|
|
||||||
} else {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mpz_clear(lhs_num);
|
|
||||||
mpz_clear(lhs_den);
|
|
||||||
mpz_clear(rhs_num);
|
|
||||||
mpz_clear(rhs_den);
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
|
|
||||||
return f->pow(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
if(p->sign() > 0) {
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
} else if(p->sign() < 0) {
|
|
||||||
knumber_integer *n = new knumber_integer(0);
|
|
||||||
delete this;
|
|
||||||
return n;
|
|
||||||
} else {
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::sin() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->sin();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::floor() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->floor();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::ceil() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->ceil();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::cos() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->cos();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::tgamma() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->tgamma();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::tan() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->tan();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::asin() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->asin();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::acos() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->acos();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::atan() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->atan();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::sinh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->sinh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::cosh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->cosh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::tanh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->tanh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::asinh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->asinh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::acosh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->acosh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::atanh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->atanh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int knumber_fraction::compare(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_fraction f(p);
|
|
||||||
return mpq_cmp(mpq_, f.mpq_);
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float f(this);
|
|
||||||
return f.compare(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
return mpq_cmp(mpq_, p->mpq_);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
// NOTE: any number compared to NaN/Inf/-Inf always compares less
|
|
||||||
// at the moment
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString knumber_fraction::toString(int precision) const {
|
|
||||||
|
|
||||||
|
|
||||||
if(knumber_fraction::default_fractional_output) {
|
|
||||||
|
|
||||||
// TODO: figure out how to properly use mpq_numref/mpq_denref here
|
|
||||||
|
|
||||||
knumber_integer integer_part(this);
|
|
||||||
if(split_off_integer_for_fraction_output && !integer_part.is_zero()) {
|
|
||||||
|
|
||||||
mpz_t num;
|
|
||||||
mpz_init(num);
|
|
||||||
mpq_get_num(num, mpq_);
|
|
||||||
|
|
||||||
knumber_integer integer_part_1(this);
|
|
||||||
|
|
||||||
mpz_mul(integer_part.mpz_, integer_part.mpz_, mpq_denref(mpq_));
|
|
||||||
mpz_sub(num, num, integer_part.mpz_);
|
|
||||||
|
|
||||||
if(mpz_sgn(num) < 0) {
|
|
||||||
mpz_neg(num, num);
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t size = gmp_snprintf(NULL, 0, "%Zd %Zd/%Zd", integer_part_1.mpz_, num, mpq_denref(mpq_)) + 1;
|
|
||||||
KNUMBER_BUFFER(buf, size);
|
|
||||||
gmp_snprintf(&buf[0], size, "%Zd %Zd/%Zd", integer_part_1.mpz_, num, mpq_denref(mpq_));
|
|
||||||
|
|
||||||
mpz_clear(num);
|
|
||||||
|
|
||||||
return QLatin1String(&buf[0]);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
mpz_t num;
|
|
||||||
mpz_init(num);
|
|
||||||
mpq_get_num(num, mpq_);
|
|
||||||
|
|
||||||
const size_t size = gmp_snprintf(NULL, 0, "%Zd/%Zd", num, mpq_denref(mpq_)) + 1;
|
|
||||||
KNUMBER_BUFFER(buf, size);
|
|
||||||
gmp_snprintf(&buf[0], size, "%Zd/%Zd", num, mpq_denref(mpq_));
|
|
||||||
|
|
||||||
mpz_clear(num);
|
|
||||||
|
|
||||||
return QLatin1String(&buf[0]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return knumber_float(this).toString(precision);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool knumber_fraction::is_zero() const {
|
|
||||||
return mpq_sgn(mpq_) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int knumber_fraction::sign() const {
|
|
||||||
return mpq_sgn(mpq_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::reciprocal() {
|
|
||||||
|
|
||||||
mpq_inv(mpq_, mpq_);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer *knumber_fraction::numerator() const {
|
|
||||||
|
|
||||||
mpz_t num;
|
|
||||||
mpz_init(num);
|
|
||||||
mpq_get_num(num, mpq_);
|
|
||||||
knumber_integer *n = new knumber_integer(num);
|
|
||||||
mpz_clear(num);
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer *knumber_fraction::denominator() const {
|
|
||||||
|
|
||||||
mpz_t den;
|
|
||||||
mpz_init(den);
|
|
||||||
mpq_get_den(den, mpq_);
|
|
||||||
knumber_integer *n = new knumber_integer(den);
|
|
||||||
mpz_clear(den);
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::log2() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->log2();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::log10() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->log10();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::ln() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->ln();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::exp2() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->exp2();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::exp10() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->exp10();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::exp() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->exp();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
quint64 knumber_fraction::toUint64() const {
|
|
||||||
return knumber_integer(this).toUint64();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
qint64 knumber_fraction::toInt64() const {
|
|
||||||
return knumber_integer(this).toInt64();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_fraction::bin(knumber_base *rhs) {
|
|
||||||
Q_UNUSED(rhs);
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,137 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KNUMBER_FRACTION_H_
|
|
||||||
#define KNUMBER_FRACTION_H_
|
|
||||||
|
|
||||||
#include "knumber_base.h"
|
|
||||||
|
|
||||||
class KNumber;
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
class knumber_fraction : public knumber_base {
|
|
||||||
friend class ::KNumber;
|
|
||||||
friend class knumber_error;
|
|
||||||
friend class knumber_integer;
|
|
||||||
friend class knumber_float;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static bool default_fractional_input;
|
|
||||||
static bool default_fractional_output;
|
|
||||||
static bool split_off_integer_for_fraction_output;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void set_default_fractional_input(bool value);
|
|
||||||
static void set_default_fractional_output(bool value);
|
|
||||||
static void set_split_off_integer_for_fraction_output(bool value);
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit knumber_fraction(const QString &s);
|
|
||||||
knumber_fraction(qint64 num, quint64 den);
|
|
||||||
knumber_fraction(quint64 num, quint64 den);
|
|
||||||
explicit knumber_fraction(mpq_t mpq);
|
|
||||||
virtual ~knumber_fraction();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *clone();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual QString toString(int precision) const;
|
|
||||||
virtual quint64 toUint64() const;
|
|
||||||
virtual qint64 toInt64() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual bool is_integer() const;
|
|
||||||
virtual bool is_zero() const;
|
|
||||||
virtual int sign() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *add(knumber_base *rhs);
|
|
||||||
virtual knumber_base *sub(knumber_base *rhs);
|
|
||||||
virtual knumber_base *mul(knumber_base *rhs);
|
|
||||||
virtual knumber_base *div(knumber_base *rhs);
|
|
||||||
virtual knumber_base *mod(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *bitwise_and(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_xor(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_or(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_shift(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *pow(knumber_base *rhs);
|
|
||||||
virtual knumber_base *neg();
|
|
||||||
virtual knumber_base *cmp();
|
|
||||||
virtual knumber_base *abs();
|
|
||||||
virtual knumber_base *sqrt();
|
|
||||||
virtual knumber_base *cbrt();
|
|
||||||
virtual knumber_base *factorial();
|
|
||||||
virtual knumber_base *reciprocal();
|
|
||||||
virtual knumber_base *tgamma();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *log2();
|
|
||||||
virtual knumber_base *log10();
|
|
||||||
virtual knumber_base *ln();
|
|
||||||
virtual knumber_base *exp2();
|
|
||||||
virtual knumber_base *floor();
|
|
||||||
virtual knumber_base *ceil();
|
|
||||||
virtual knumber_base *exp10();
|
|
||||||
virtual knumber_base *exp();
|
|
||||||
virtual knumber_base *bin(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *sin();
|
|
||||||
virtual knumber_base *cos();
|
|
||||||
virtual knumber_base *tan();
|
|
||||||
virtual knumber_base *asin();
|
|
||||||
virtual knumber_base *acos();
|
|
||||||
virtual knumber_base *atan();
|
|
||||||
virtual knumber_base *sinh();
|
|
||||||
virtual knumber_base *cosh();
|
|
||||||
virtual knumber_base *tanh();
|
|
||||||
virtual knumber_base *asinh();
|
|
||||||
virtual knumber_base *acosh();
|
|
||||||
virtual knumber_base *atanh();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual int compare(knumber_base *rhs);
|
|
||||||
|
|
||||||
private:
|
|
||||||
knumber_integer *numerator() const;
|
|
||||||
knumber_integer *denominator() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
// conversion constructors
|
|
||||||
explicit knumber_fraction(const knumber_integer *value);
|
|
||||||
explicit knumber_fraction(const knumber_fraction *value);
|
|
||||||
#if 0
|
|
||||||
// TODO: this is omitted because there is no good way to
|
|
||||||
// implement it
|
|
||||||
knumber_fraction(const knumber_float *value);
|
|
||||||
#endif
|
|
||||||
explicit knumber_fraction(const knumber_error *value);
|
|
||||||
|
|
||||||
private:
|
|
||||||
mpq_t mpq_;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,887 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config-kcalc.h>
|
|
||||||
#include "knumber_integer.h"
|
|
||||||
#include "knumber_float.h"
|
|
||||||
#include "knumber_fraction.h"
|
|
||||||
#include "knumber_error.h"
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: knumber_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer::knumber_integer(const QString &s) {
|
|
||||||
mpz_init(mpz_);
|
|
||||||
mpz_set_str(mpz_, s.toAscii(), 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: knumber_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer::knumber_integer(qint32 value) {
|
|
||||||
mpz_init_set_si(mpz_, static_cast<signed long int>(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: knumber_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer::knumber_integer(qint64 value) {
|
|
||||||
mpz_init(mpz_);
|
|
||||||
#if SIZEOF_SIGNED_LONG == 8
|
|
||||||
mpz_set_si(mpz_, static_cast<signed long int>(value));
|
|
||||||
#elif SIZEOF_SIGNED_LONG == 4
|
|
||||||
mpz_set_si(mpz_, static_cast<signed long int>(value >> 32));
|
|
||||||
mpz_mul_2exp(mpz_, mpz_, 32);
|
|
||||||
mpz_add_ui(mpz_, mpz_, static_cast<signed long int>(value));
|
|
||||||
#else
|
|
||||||
#error "SIZEOF_SIGNED_LONG is a unhandled case"
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: knumber_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer::knumber_integer(quint32 value) {
|
|
||||||
mpz_init_set_ui(mpz_, static_cast<unsigned long int>(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: knumber_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer::knumber_integer(quint64 value) {
|
|
||||||
mpz_init(mpz_);
|
|
||||||
#if SIZEOF_UNSIGNED_LONG == 8
|
|
||||||
mpz_set_ui(mpz_, static_cast<unsigned long int>(value));
|
|
||||||
#elif SIZEOF_UNSIGNED_LONG == 4
|
|
||||||
mpz_set_ui(mpz_, static_cast<unsigned long int>(value >> 32));
|
|
||||||
mpz_mul_2exp(mpz_, mpz_, 32);
|
|
||||||
mpz_add_ui(mpz_, mpz_, static_cast<unsigned long int>(value));
|
|
||||||
#else
|
|
||||||
#error "SIZEOF_UNSIGNED_LONG is a unhandled case"
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: knumber_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer::knumber_integer(mpz_t mpz) {
|
|
||||||
mpz_init_set(mpz_, mpz);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: knumber_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer::knumber_integer(const knumber_integer *value) {
|
|
||||||
mpz_init_set(mpz_, value->mpz_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: knumber_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer::knumber_integer(const knumber_float *value) {
|
|
||||||
mpz_init(mpz_);
|
|
||||||
mpz_set_f(mpz_, value->mpf_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: knumber_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer::knumber_integer(const knumber_fraction *value) {
|
|
||||||
mpz_init(mpz_);
|
|
||||||
mpz_set_q(mpz_, value->mpq_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: clone
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::clone() {
|
|
||||||
return new knumber_integer(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: ~knumber_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_integer::~knumber_integer() {
|
|
||||||
mpz_clear(mpz_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: add
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::add(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
mpz_add(mpz_, mpz_, p->mpz_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *const f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->add(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_fraction *const q = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return q->add(p);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
delete this;
|
|
||||||
return p->clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sub
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::sub(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
mpz_sub(mpz_, mpz_, p->mpz_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->sub(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_fraction *q = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return q->sub(p);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
knumber_base *e = p->clone();
|
|
||||||
delete this;
|
|
||||||
return e->neg();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: mul
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::mul(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
mpz_mul(mpz_, mpz_, p->mpz_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->mul(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_fraction *q = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return q->mul(p);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
|
|
||||||
if(is_zero()) {
|
|
||||||
delete this;
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
return e->neg();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
knumber_base *e = p->clone();
|
|
||||||
return e->neg();
|
|
||||||
} else {
|
|
||||||
delete this;
|
|
||||||
return p->clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: div
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::div(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(rhs->is_zero()) {
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_NEG_INFINITY);
|
|
||||||
} else {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
knumber_fraction *q = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return q->div(p);
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->div(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_fraction *q = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return q->div(p);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
|
|
||||||
if(p->sign() > 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(0);
|
|
||||||
} else if(p->sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_integer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete this;
|
|
||||||
return p->clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: mod
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::mod(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(rhs->is_zero()) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
mpz_mod(mpz_, mpz_, p->mpz_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->mod(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_fraction *q = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return q->mod(p);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
delete this;
|
|
||||||
return p->clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: bitwise_and
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::bitwise_and(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
mpz_and(mpz_, mpz_, p->mpz_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->bitwise_and(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_fraction *f = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return f->bitwise_and(p);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
delete this;
|
|
||||||
return p->clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: bitwise_xor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::bitwise_xor(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
mpz_xor(mpz_, mpz_, p->mpz_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->bitwise_xor(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_fraction *f = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return f->bitwise_xor(p);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
delete this;
|
|
||||||
return p->clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: bitwise_or
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::bitwise_or(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
mpz_ior(mpz_, mpz_, p->mpz_);
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->bitwise_or(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_fraction *f = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return f->bitwise_or(p);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
delete this;
|
|
||||||
return p->clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: bitwise_shift
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::bitwise_shift(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
|
|
||||||
const signed long int bit_count = mpz_get_si(p->mpz_);
|
|
||||||
|
|
||||||
// TODO: left shift with high bit set is broken in
|
|
||||||
// non decimal modes :-/, always displays 0
|
|
||||||
// interestingly, the bit is not "lost"
|
|
||||||
// we simply don't have a mechanism to display
|
|
||||||
// values in HEX/DEC/OCT mode which are greater than
|
|
||||||
// 64-bits
|
|
||||||
|
|
||||||
if(bit_count > 0) {
|
|
||||||
// left shift
|
|
||||||
mpz_mul_2exp(mpz_, mpz_, bit_count);
|
|
||||||
} else if(bit_count < 0) {
|
|
||||||
// right shift
|
|
||||||
if(mpz_sgn(mpz_) < 0) {
|
|
||||||
mpz_fdiv_q_2exp(mpz_, mpz_, -bit_count);
|
|
||||||
} else {
|
|
||||||
mpz_tdiv_q_2exp(mpz_, mpz_, -bit_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
Q_UNUSED(p);
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: neg
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::neg() {
|
|
||||||
|
|
||||||
mpz_neg(mpz_, mpz_);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: cmp
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::cmp() {
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
// unfortunately this breaks things pretty badly
|
|
||||||
// for non-decimal modes :-(
|
|
||||||
mpz_com(mpz_, mpz_);
|
|
||||||
#else
|
|
||||||
mpz_swap(mpz_, knumber_integer(~toUint64()).mpz_);
|
|
||||||
#endif
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: abs
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::abs() {
|
|
||||||
|
|
||||||
mpz_abs(mpz_, mpz_);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sqrt
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::sqrt() {
|
|
||||||
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mpz_perfect_square_p(mpz_)) {
|
|
||||||
mpz_sqrt(mpz_, mpz_);
|
|
||||||
return this;
|
|
||||||
} else {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->sqrt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: cbrt
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::cbrt() {
|
|
||||||
|
|
||||||
mpz_t x;
|
|
||||||
mpz_init_set(x, mpz_);
|
|
||||||
if(mpz_root(x, x, 3)) {
|
|
||||||
mpz_swap(mpz_, x);
|
|
||||||
mpz_clear(x);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
mpz_clear(x);
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->cbrt();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: pow
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::pow(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
|
|
||||||
if(is_zero() && p->is_even() && p->sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
mpz_pow_ui(mpz_, mpz_, mpz_get_ui(p->mpz_));
|
|
||||||
|
|
||||||
if(p->sign() < 0) {
|
|
||||||
return reciprocal();
|
|
||||||
} else {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->pow(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
knumber_fraction *f = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return f->pow(p);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
if(p->sign() > 0) {
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_POS_INFINITY);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
} else if(p->sign() < 0) {
|
|
||||||
mpz_init_set_si(mpz_, 0);
|
|
||||||
return this;
|
|
||||||
} else {
|
|
||||||
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
delete this;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sin
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::sin() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->sin();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: cos
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::cos() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->cos();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: tan
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::tan() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->tan();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: asin
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::asin() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->asin();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: acos
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::acos() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->acos();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: atan
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::atan() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->atan();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: tgamma
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::tgamma() {
|
|
||||||
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->tgamma();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::sinh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->sinh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::cosh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->cosh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::tanh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->tanh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::asinh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->asinh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::acosh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->acosh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::atanh() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->atanh();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: factorial
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::factorial() {
|
|
||||||
|
|
||||||
if(sign() < 0) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
mpz_fac_ui(mpz_, mpz_get_ui(mpz_));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: compare
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int knumber_integer::compare(knumber_base *rhs) {
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
return mpz_cmp(mpz_, p->mpz_);
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
return knumber_float(this).compare(p);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
return knumber_fraction(this).compare(p);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
// NOTE: any number compared to NaN/Inf/-Inf always compares less
|
|
||||||
// at the moment
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: toString
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
QString knumber_integer::toString(int precision) const {
|
|
||||||
|
|
||||||
Q_UNUSED(precision);
|
|
||||||
|
|
||||||
const size_t size = gmp_snprintf(NULL, 0, "%Zd", mpz_) + 1;
|
|
||||||
KNUMBER_BUFFER(buf, size);
|
|
||||||
gmp_snprintf(&buf[0], size, "%Zd", mpz_);
|
|
||||||
return QLatin1String(&buf[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
quint64 knumber_integer::toUint64() const {
|
|
||||||
// libgmp doesn't have unsigned long long conversion
|
|
||||||
// so convert to string and then to unsigned long long
|
|
||||||
const QString tmpstring = toString(-1);
|
|
||||||
|
|
||||||
bool ok;
|
|
||||||
quint64 value;
|
|
||||||
|
|
||||||
if (sign() < 0) {
|
|
||||||
const qint64 signedvalue = tmpstring.toLongLong(&ok, 10);
|
|
||||||
value = static_cast<quint64>(signedvalue);
|
|
||||||
} else {
|
|
||||||
value = tmpstring.toULongLong(&ok, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok) {
|
|
||||||
// TODO: what to do if error?
|
|
||||||
value = 0;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
qint64 knumber_integer::toInt64() const {
|
|
||||||
// libgmp doesn't have long long conversion
|
|
||||||
// so convert to string and then to long long
|
|
||||||
const QString tmpstring = toString(-1);
|
|
||||||
|
|
||||||
bool ok;
|
|
||||||
qint64 value = tmpstring.toLongLong(&ok, 10);
|
|
||||||
|
|
||||||
if (!ok) {
|
|
||||||
// TODO: what to do if error?
|
|
||||||
value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: is_integer
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool knumber_integer::is_integer() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: is_zero
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool knumber_integer::is_zero() const {
|
|
||||||
return mpz_sgn(mpz_) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sign
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int knumber_integer::sign() const {
|
|
||||||
return mpz_sgn(mpz_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: is_even
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool knumber_integer::is_even() const {
|
|
||||||
return mpz_even_p(mpz_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: is_odd
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool knumber_integer::is_odd() const {
|
|
||||||
return mpz_odd_p(mpz_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: reciprocal
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::reciprocal() {
|
|
||||||
knumber_fraction *q = new knumber_fraction(this);
|
|
||||||
delete this;
|
|
||||||
return q->reciprocal();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: log2
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::log2() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->log2();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: floor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::floor() {
|
|
||||||
// should have no effect on the value
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: ceil
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::ceil() {
|
|
||||||
// should have no effect on the value
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: log10
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::log10() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->log10();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: ln
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::ln() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->ln();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: exp2
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::exp2() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->exp2();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: exp10
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::exp10() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->exp10();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: exp
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::exp() {
|
|
||||||
knumber_float *f = new knumber_float(this);
|
|
||||||
delete this;
|
|
||||||
return f->exp();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: bin
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
knumber_base *knumber_integer::bin(knumber_base *rhs) {
|
|
||||||
|
|
||||||
|
|
||||||
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
|
|
||||||
mpz_bin_ui(mpz_, mpz_, mpz_get_ui(p->mpz_));
|
|
||||||
return this;
|
|
||||||
|
|
||||||
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
|
|
||||||
delete this;
|
|
||||||
return new knumber_error(knumber_error::ERROR_UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,123 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KNUMBER_INTEGER_H_
|
|
||||||
#define KNUMBER_INTEGER_H_
|
|
||||||
|
|
||||||
#include "knumber_base.h"
|
|
||||||
|
|
||||||
class KNumber;
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
class knumber_integer : public knumber_base {
|
|
||||||
friend class ::KNumber;
|
|
||||||
friend class knumber_error;
|
|
||||||
friend class knumber_fraction;
|
|
||||||
friend class knumber_float;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit knumber_integer(const QString &s);
|
|
||||||
explicit knumber_integer(qint32 value);
|
|
||||||
explicit knumber_integer(qint64 value);
|
|
||||||
explicit knumber_integer(quint32 value);
|
|
||||||
explicit knumber_integer(quint64 value);
|
|
||||||
explicit knumber_integer(mpz_t mpz);
|
|
||||||
virtual ~knumber_integer();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *clone();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual QString toString(int precision) const;
|
|
||||||
virtual quint64 toUint64() const;
|
|
||||||
virtual qint64 toInt64() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual bool is_even() const;
|
|
||||||
virtual bool is_odd() const;
|
|
||||||
virtual bool is_integer() const;
|
|
||||||
virtual bool is_zero() const;
|
|
||||||
virtual int sign() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *add(knumber_base *rhs);
|
|
||||||
virtual knumber_base *sub(knumber_base *rhs);
|
|
||||||
virtual knumber_base *mul(knumber_base *rhs);
|
|
||||||
virtual knumber_base *div(knumber_base *rhs);
|
|
||||||
virtual knumber_base *mod(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *bitwise_and(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_xor(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_or(knumber_base *rhs);
|
|
||||||
virtual knumber_base *bitwise_shift(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *pow(knumber_base *rhs);
|
|
||||||
virtual knumber_base *neg();
|
|
||||||
virtual knumber_base *cmp();
|
|
||||||
virtual knumber_base *abs();
|
|
||||||
virtual knumber_base *sqrt();
|
|
||||||
virtual knumber_base *cbrt();
|
|
||||||
virtual knumber_base *factorial();
|
|
||||||
virtual knumber_base *reciprocal();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *log2();
|
|
||||||
virtual knumber_base *log10();
|
|
||||||
virtual knumber_base *ln();
|
|
||||||
virtual knumber_base *exp2();
|
|
||||||
virtual knumber_base *floor();
|
|
||||||
virtual knumber_base *ceil();
|
|
||||||
virtual knumber_base *exp10();
|
|
||||||
virtual knumber_base *exp();
|
|
||||||
virtual knumber_base *bin(knumber_base *rhs);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual knumber_base *sin();
|
|
||||||
virtual knumber_base *cos();
|
|
||||||
virtual knumber_base *tan();
|
|
||||||
virtual knumber_base *asin();
|
|
||||||
virtual knumber_base *acos();
|
|
||||||
virtual knumber_base *atan();
|
|
||||||
virtual knumber_base *sinh();
|
|
||||||
virtual knumber_base *cosh();
|
|
||||||
virtual knumber_base *tanh();
|
|
||||||
virtual knumber_base *asinh();
|
|
||||||
virtual knumber_base *acosh();
|
|
||||||
virtual knumber_base *atanh();
|
|
||||||
virtual knumber_base *tgamma();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual int compare(knumber_base *rhs);
|
|
||||||
|
|
||||||
private:
|
|
||||||
// conversion constructors
|
|
||||||
explicit knumber_integer(const knumber_integer *value);
|
|
||||||
explicit knumber_integer(const knumber_fraction *value);
|
|
||||||
explicit knumber_integer(const knumber_float *value);
|
|
||||||
explicit knumber_integer(const knumber_error *value);
|
|
||||||
|
|
||||||
private:
|
|
||||||
mpz_t mpz_;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,296 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config-kcalc.h>
|
|
||||||
#include "knumber_operators.h"
|
|
||||||
#include "knumber.h"
|
|
||||||
#include "knumber_base.h"
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber operator+(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
KNumber x(lhs);
|
|
||||||
x += rhs;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber operator-(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
KNumber x(lhs);
|
|
||||||
x -= rhs;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber operator*(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
KNumber x(lhs);
|
|
||||||
x *= rhs;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber operator/(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
KNumber x(lhs);
|
|
||||||
x /= rhs;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber operator%(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
KNumber x(lhs);
|
|
||||||
x %= rhs;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber operator&(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
KNumber x(lhs);
|
|
||||||
x &= rhs;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber operator|(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
KNumber x(lhs);
|
|
||||||
x |= rhs;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber operator^(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
KNumber x(lhs);
|
|
||||||
x ^= rhs;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber operator>>(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
KNumber x(lhs);
|
|
||||||
x >>= rhs;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber operator<<(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
KNumber x(lhs);
|
|
||||||
x <<= rhs;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber abs(const KNumber &x) {
|
|
||||||
return x.abs();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber cbrt(const KNumber &x) {
|
|
||||||
return x.cbrt();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber sqrt(const KNumber &x) {
|
|
||||||
return x.sqrt();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber sin(const KNumber &x) {
|
|
||||||
return x.sin();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber cos(const KNumber &x) {
|
|
||||||
return x.cos();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber tan(const KNumber &x) {
|
|
||||||
return x.tan();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber asin(const KNumber &x) {
|
|
||||||
return x.asin();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber acos(const KNumber &x) {
|
|
||||||
return x.acos();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber tgamma(const KNumber &x) {
|
|
||||||
return x.tgamma();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber atan(const KNumber &x) {
|
|
||||||
return x.atan();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber pow(const KNumber &x, const KNumber &y) {
|
|
||||||
return x.pow(y);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber factorial(const KNumber &x) {
|
|
||||||
return x.factorial();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber log2(const KNumber &x) {
|
|
||||||
return x.log2();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber floor(const KNumber &x) {
|
|
||||||
return x.floor();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber ceil(const KNumber &x) {
|
|
||||||
return x.ceil();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber log10(const KNumber &x) {
|
|
||||||
return x.log10();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber ln(const KNumber &x) {
|
|
||||||
return x.ln();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber exp2(const KNumber &x) {
|
|
||||||
return x.exp2();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber exp10(const KNumber &x) {
|
|
||||||
return x.exp10();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber exp(const KNumber &x) {
|
|
||||||
return x.exp();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool operator==(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
return lhs.value_->compare(rhs.value_) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool operator!=(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
return lhs.value_->compare(rhs.value_) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool operator>=(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
return lhs.value_->compare(rhs.value_) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool operator<=(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
return lhs.value_->compare(rhs.value_) <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool operator>(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
return lhs.value_->compare(rhs.value_) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool operator<(const KNumber &lhs, const KNumber &rhs) {
|
|
||||||
return lhs.value_->compare(rhs.value_) < 0;
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KNUMBER_OPERATORS_H_
|
|
||||||
#define KNUMBER_OPERATORS_H_
|
|
||||||
|
|
||||||
class KNumber;
|
|
||||||
|
|
||||||
bool operator==(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
bool operator!=(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
bool operator>=(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
bool operator<=(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
bool operator>(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
bool operator<(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
|
|
||||||
KNumber operator+(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
KNumber operator-(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
KNumber operator*(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
KNumber operator/(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
KNumber operator%(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
|
|
||||||
KNumber operator&(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
KNumber operator|(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
KNumber operator^(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
KNumber operator>>(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
KNumber operator<<(const KNumber &lhs, const KNumber &rhs);
|
|
||||||
|
|
||||||
KNumber abs(const KNumber &x);
|
|
||||||
KNumber cbrt(const KNumber &x);
|
|
||||||
KNumber sqrt(const KNumber &x);
|
|
||||||
KNumber pow(const KNumber &x, const KNumber &y);
|
|
||||||
|
|
||||||
KNumber sin(const KNumber &x);
|
|
||||||
KNumber cos(const KNumber &x);
|
|
||||||
KNumber tan(const KNumber &x);
|
|
||||||
KNumber asin(const KNumber &x);
|
|
||||||
KNumber tgamma(const KNumber &x);
|
|
||||||
KNumber acos(const KNumber &x);
|
|
||||||
KNumber atan(const KNumber &x);
|
|
||||||
|
|
||||||
KNumber factorial(const KNumber &x);
|
|
||||||
|
|
||||||
KNumber log2(const KNumber &x);
|
|
||||||
KNumber log10(const KNumber &x);
|
|
||||||
KNumber ceil(const KNumber &x);
|
|
||||||
KNumber floor(const KNumber &x);
|
|
||||||
KNumber ln(const KNumber &x);
|
|
||||||
KNumber exp2(const KNumber &x);
|
|
||||||
KNumber exp10(const KNumber &x);
|
|
||||||
KNumber exp(const KNumber &x);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,7 +0,0 @@
|
||||||
include_directories( ${CMAKE_SOURCE_DIR}/knumber )
|
|
||||||
|
|
||||||
set(knumbertest_SRCS knumbertest.cpp ${libknumber_la_SRCS})
|
|
||||||
|
|
||||||
kde4_add_test(knumber-KNumber ${knumbertest_SRCS})
|
|
||||||
|
|
||||||
target_link_libraries(knumber-KNumber KDE4::kdecore ${GMP_LIBRARIES})
|
|
|
@ -1,851 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 2003 - 2005 Klaus Niederkrueger
|
|
||||||
kniederk@math.uni-koeln.de
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "knumber.h"
|
|
||||||
#include <QString>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <iostream>
|
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
const int precision = 12;
|
|
||||||
|
|
||||||
QString numtypeToString(int arg) {
|
|
||||||
switch (arg) {
|
|
||||||
case 0:
|
|
||||||
return QLatin1String("Special");
|
|
||||||
case 1:
|
|
||||||
return QLatin1String("Integer");
|
|
||||||
case 3:
|
|
||||||
return QLatin1String("Fraction");
|
|
||||||
case 2:
|
|
||||||
return QLatin1String("Float");
|
|
||||||
default:
|
|
||||||
return QLatin1String("Unknown:") + QString::number(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkResult(const QString &string, const KNumber &result, const QString &desired_string, int desired) {
|
|
||||||
|
|
||||||
std::cout
|
|
||||||
<< "Testing result of: "
|
|
||||||
<< qPrintable(string)
|
|
||||||
<< " should give "
|
|
||||||
<< qPrintable(desired_string)
|
|
||||||
<< " and gives "
|
|
||||||
<< qPrintable(result.toQString(precision))
|
|
||||||
<< " ...\n";
|
|
||||||
|
|
||||||
std::cout
|
|
||||||
<< "The type of the result should be "
|
|
||||||
<< qPrintable(numtypeToString(desired))
|
|
||||||
<< " and gives "
|
|
||||||
<< qPrintable(numtypeToString(result.type()))
|
|
||||||
<< " ... ";
|
|
||||||
|
|
||||||
if (result.type() == desired && result.toQString(precision) == desired_string) {
|
|
||||||
std::cout << "OK\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "Failed\n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkTruth(const QString &string, bool computation, bool desired_result) {
|
|
||||||
|
|
||||||
std::cout
|
|
||||||
<< "Testing truth of: "
|
|
||||||
<< qPrintable(string)
|
|
||||||
<< " should be "
|
|
||||||
<< desired_result
|
|
||||||
<< " and is "
|
|
||||||
<< computation
|
|
||||||
<< " ... ";
|
|
||||||
|
|
||||||
if (computation == desired_result) {
|
|
||||||
std::cout << "OK\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "Failed\n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkType(const QString &string, int test_arg, int desired) {
|
|
||||||
|
|
||||||
std::cout
|
|
||||||
<< "Testing type of: "
|
|
||||||
<< qPrintable(string)
|
|
||||||
<< " should give "
|
|
||||||
<< qPrintable(numtypeToString(desired))
|
|
||||||
<< " and gives "
|
|
||||||
<< qPrintable(numtypeToString(test_arg))
|
|
||||||
<< " ...";
|
|
||||||
|
|
||||||
if (test_arg == desired) {
|
|
||||||
std::cout << "OK\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "Failed\n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingCompare() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing Compare:\n";
|
|
||||||
std::cout << "----------------\n";
|
|
||||||
|
|
||||||
checkTruth("KNumber(5) == KNumber(2)", KNumber(5) == KNumber(2), false);
|
|
||||||
checkTruth("KNumber(5) > KNumber(2)", KNumber(5) > KNumber(2), true);
|
|
||||||
checkTruth("KNumber(5) < KNumber(2)", KNumber(5) < KNumber(2), false);
|
|
||||||
checkTruth("KNumber(5) < KNumber(0)", KNumber(5) < KNumber(0), false);
|
|
||||||
checkTruth("KNumber(-5) < KNumber(0)", KNumber(-5) < KNumber(0), true);
|
|
||||||
checkTruth("KNumber(5) >= KNumber(2)", KNumber(5) >= KNumber(2), true);
|
|
||||||
checkTruth("KNumber(5) <= KNumber(2)", KNumber(5) <= KNumber(2), false);
|
|
||||||
checkTruth("KNumber(5) != KNumber(2)", KNumber(5) != KNumber(2), true);
|
|
||||||
|
|
||||||
checkTruth("KNumber(2) == KNumber(2)", KNumber(2) == KNumber(2), true);
|
|
||||||
checkTruth("KNumber(2) > KNumber(2)", KNumber(2) > KNumber(2), false);
|
|
||||||
checkTruth("KNumber(2) < KNumber(2)", KNumber(2) < KNumber(2), false);
|
|
||||||
checkTruth("KNumber(2) >= KNumber(2)", KNumber(2) >= KNumber(2), true);
|
|
||||||
checkTruth("KNumber(2) <= KNumber(2)", KNumber(2) <= KNumber(2), true);
|
|
||||||
checkTruth("KNumber(2) != KNumber(2)", KNumber(2) != KNumber(2), false);
|
|
||||||
|
|
||||||
checkTruth("KNumber(5) == KNumber(\"1/2\")", KNumber(5) == KNumber(QLatin1String("1/2")), false);
|
|
||||||
checkTruth("KNumber(5) > KNumber(\"1/2\")", KNumber(5) > KNumber(QLatin1String("1/2")), true);
|
|
||||||
checkTruth("KNumber(5) < KNumber(\"1/2\")", KNumber(5) < KNumber(QLatin1String("1/2")), false);
|
|
||||||
checkTruth("KNumber(5) >= KNumber(\"1/2\")", KNumber(5) >= KNumber(QLatin1String("1/2")), true);
|
|
||||||
checkTruth("KNumber(5) <= KNumber(\"1/2\")", KNumber(5) <= KNumber(QLatin1String("1/2")), false);
|
|
||||||
checkTruth("KNumber(5) != KNumber(\"1/2\")", KNumber(5) != KNumber(QLatin1String("1/2")), true);
|
|
||||||
|
|
||||||
checkTruth("KNumber(\"1/2\") == KNumber(\"1/2\")", KNumber(QLatin1String("1/2")) == KNumber(QLatin1String("1/2")), true);
|
|
||||||
checkTruth("KNumber(\"1/2\") > KNumber(\"1/2\")", KNumber(QLatin1String("1/2")) > KNumber(QLatin1String("1/2")), false);
|
|
||||||
checkTruth("KNumber(\"1/2\") < KNumber(\"1/2\")", KNumber(QLatin1String("1/2")) < KNumber(QLatin1String("1/2")), false);
|
|
||||||
checkTruth("KNumber(\"1/2\") >= KNumber(\"1/2\")", KNumber(QLatin1String("1/2")) >= KNumber(QLatin1String("1/2")), true);
|
|
||||||
checkTruth("KNumber(\"1/2\") <= KNumber(\"1/2\")", KNumber(QLatin1String("1/2")) <= KNumber(QLatin1String("1/2")), true);
|
|
||||||
checkTruth("KNumber(\"1/2\") != KNumber(\"1/2\")", KNumber(QLatin1String("1/2")) != KNumber(QLatin1String("1/2")), false);
|
|
||||||
|
|
||||||
checkTruth("KNumber(\"3/2\") == KNumber(\"1/2\")", KNumber(QLatin1String("3/2")) == KNumber(QLatin1String("1/2")), false);
|
|
||||||
checkTruth("KNumber(\"3/2\") > KNumber(\"1/2\")", KNumber(QLatin1String("3/2")) > KNumber(QLatin1String("1/2")), true);
|
|
||||||
checkTruth("KNumber(\"3/2\") < KNumber(\"1/2\")", KNumber(QLatin1String("3/2")) < KNumber(QLatin1String("1/2")), false);
|
|
||||||
checkTruth("KNumber(\"3/2\") >= KNumber(\"1/2\")", KNumber(QLatin1String("3/2")) >= KNumber(QLatin1String("1/2")), true);
|
|
||||||
checkTruth("KNumber(\"3/2\") <= KNumber(\"1/2\")", KNumber(QLatin1String("3/2")) <= KNumber(QLatin1String("1/2")), false);
|
|
||||||
checkTruth("KNumber(\"3/2\") != KNumber(\"1/2\")", KNumber(QLatin1String("3/2")) != KNumber(QLatin1String("1/2")), true);
|
|
||||||
|
|
||||||
checkTruth("KNumber(3.2) != KNumber(3)", KNumber(3.2) != KNumber(3), true);
|
|
||||||
checkTruth("KNumber(3.2) > KNumber(3)", KNumber(3.2) > KNumber(3), true);
|
|
||||||
checkTruth("KNumber(3.2) < KNumber(3)", KNumber(3.2) < KNumber(3), false);
|
|
||||||
|
|
||||||
checkTruth("KNumber(3.2) < KNumber(\"3/5\")", KNumber(3.2) < KNumber(QLatin1String("3/5")), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void testingAdditions() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing additions:\n";
|
|
||||||
std::cout << "------------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(5) + KNumber(2)", KNumber(5) + KNumber(2), QLatin1String("7"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5) + KNumber(\"2/3\")", KNumber(5) + KNumber(QLatin1String("2/3")), QLatin1String("17/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(5) + KNumber(\"2.3\")", KNumber(5) + KNumber(QLatin1String("2.3")), QLatin1String("7.3"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("KNumber(\"5/3\") + KNumber(2)", KNumber(QLatin1String("5/3")) + KNumber(2), QLatin1String("11/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"5/3\") + KNumber(\"2/3\")", KNumber(QLatin1String("5/3")) + KNumber(QLatin1String("2/3")), QLatin1String("7/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"5/3\") + KNumber(\"1/3\")", KNumber(QLatin1String("5/3")) + KNumber(QLatin1String("1/3")), QLatin1String("2"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5/3\") + KNumber(\"-26/3\")", KNumber(QLatin1String("5/3")) + KNumber(QLatin1String("-26/3")), QLatin1String("-7"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5/2\") + KNumber(2.3)", KNumber(QLatin1String("5/2")) + KNumber(2.3), QLatin1String("4.8"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("KNumber(5.3) + KNumber(2)", KNumber(5.3) + KNumber(2), QLatin1String("7.3"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.3) + KNumber(\"2/4\")", KNumber(5.3) + KNumber(QLatin1String("2/4")), QLatin1String("5.8"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.3) + KNumber(2.3)", KNumber(5.3) + KNumber(2.3), QLatin1String("7.6"), KNumber::TYPE_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingSubtractions() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing subtractions:\n";
|
|
||||||
std::cout << "---------------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(5) - KNumber(2)", KNumber(5) - KNumber(2), QLatin1String("3"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5) - KNumber(\"2/3\")", KNumber(5) - KNumber(QLatin1String("2/3")), QLatin1String("13/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(5) - KNumber(2.3)", KNumber(5) - KNumber(2.3), QLatin1String("2.7"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("KNumber(\"5/3\") - KNumber(2)", KNumber(QLatin1String("5/3")) - KNumber(2), QLatin1String("-1/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"5/3\") - KNumber(\"1/3\")", KNumber(QLatin1String("5/3")) - KNumber(QLatin1String("1/3")), QLatin1String("4/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"5/3\") - KNumber(\"2/3\")", KNumber(QLatin1String("5/3")) - KNumber(QLatin1String("2/3")), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"-5/3\") - KNumber(\"4/3\")", KNumber(QLatin1String("-5/3")) - KNumber(QLatin1String("4/3")), QLatin1String("-3"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5/4\") - KNumber(2.2)", KNumber(QLatin1String("5/4")) - KNumber(2.2), QLatin1String("-0.95"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("KNumber(5.3) - KNumber(2)", KNumber(5.3) - KNumber(2), QLatin1String("3.3"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.3) - KNumber(\"3/4\")", KNumber(5.3) - KNumber(QLatin1String("3/4")), QLatin1String("4.55"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.3) - KNumber(2.3)", KNumber(5.3) - KNumber(2.3), QLatin1String("3"), KNumber::TYPE_INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingSpecial() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing special functions:\n";
|
|
||||||
std::cout << "--------------------------\n";
|
|
||||||
|
|
||||||
checkResult("log10(KNumber(5))", log10(KNumber(5)), QLatin1String("0.698970004336"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("log10(pow(KNumber(10), KNumber(308)))", log10(pow(KNumber(10), KNumber(308))), QLatin1String("308"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
// TODO: enable this check once MPFR is commonly enabled
|
|
||||||
// checkResult("log10(pow(KNumber(10), KNumber(309)))", log10(pow(KNumber(10), KNumber(309))), QLatin1String("309"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
checkResult("exp(KNumber(4.34))", exp(KNumber(4.34)), QLatin1String("76.7075393383"), KNumber::TYPE_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingTrig() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing trig functions:\n";
|
|
||||||
std::cout << "-----------------------\n";
|
|
||||||
|
|
||||||
checkResult("sin(KNumber(5))", sin(KNumber(5)), QLatin1String("-0.958924274663"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("cos(KNumber(5))", cos(KNumber(5)), QLatin1String("0.283662185463"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("tan(KNumber(5))", tan(KNumber(5)), QLatin1String("-3.38051500625"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("sin(KNumber(-5))", sin(KNumber(-5)), QLatin1String("0.958924274663"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("cos(KNumber(-5))", cos(KNumber(-5)), QLatin1String("0.283662185463"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("tan(KNumber(-5))", tan(KNumber(-5)), QLatin1String("3.38051500625"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("sin(KNumber(\"5/2\"))", sin(KNumber(QLatin1String("5/2"))), QLatin1String("0.598472144104"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("cos(KNumber(\"5/2\"))", cos(KNumber(QLatin1String("5/2"))), QLatin1String("-0.801143615547"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("tan(KNumber(\"5/2\"))", tan(KNumber(QLatin1String("5/2"))), QLatin1String("-0.747022297239"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("sin(KNumber(\"-5/2\"))", sin(KNumber(QLatin1String("-5/2"))), QLatin1String("-0.598472144104"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("cos(KNumber(\"-5/2\"))", cos(KNumber(QLatin1String("-5/2"))), QLatin1String("-0.801143615547"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("tan(KNumber(\"-5/2\"))", tan(KNumber(QLatin1String("-5/2"))), QLatin1String("0.747022297239"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("sin(KNumber(5.3))", sin(KNumber(5.3)), QLatin1String("-0.832267442224"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("cos(KNumber(5.3))", cos(KNumber(5.3)), QLatin1String("0.554374336179"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("tan(KNumber(5.3))", tan(KNumber(5.3)), QLatin1String("-1.50127339581"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("sin(KNumber(-5.3))", sin(KNumber(-5.3)), QLatin1String("0.832267442224"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("cos(KNumber(-5.3))", cos(KNumber(-5.3)), QLatin1String("0.554374336179"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("tan(KNumber(-5.3))", tan(KNumber(-5.3)), QLatin1String("1.50127339581"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("asin(KNumber(5))", asin(KNumber(5)), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("acos(KNumber(5))", acos(KNumber(5)), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("atan(KNumber(5))", atan(KNumber(5)), QLatin1String("1.37340076695"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("asin(KNumber(-5))", asin(KNumber(-5)), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("acos(KNumber(-5))", acos(KNumber(-5)), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("atan(KNumber(-5))", atan(KNumber(-5)), QLatin1String("-1.37340076695"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("asin(KNumber(\"5/2\"))", asin(KNumber(QLatin1String("5/2"))), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("acos(KNumber(\"5/2\"))", acos(KNumber(QLatin1String("5/2"))), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("atan(KNumber(\"5/2\"))", atan(KNumber(QLatin1String("5/2"))), QLatin1String("1.19028994968"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("asin(KNumber(\"-5/2\"))", asin(KNumber(QLatin1String("-5/2"))), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("acos(KNumber(\"-5/2\"))", acos(KNumber(QLatin1String("-5/2"))), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("atan(KNumber(\"-5/2\"))", atan(KNumber(QLatin1String("-5/2"))), QLatin1String("-1.19028994968"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("asin(KNumber(5.3))", asin(KNumber(5.3)), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("acos(KNumber(5.3))", acos(KNumber(5.3)), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("atan(KNumber(5.3))", atan(KNumber(5.3)), QLatin1String("1.38430942513"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("asin(KNumber(-5.3))", asin(KNumber(-5.3)), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("acos(KNumber(-5.3))", acos(KNumber(-5.3)), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("atan(KNumber(-5.3))", atan(KNumber(-5.3)), QLatin1String("-1.38430942513"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
|
|
||||||
checkResult("asin(KNumber(\"2/5\"))", asin(KNumber(QLatin1String("2/5"))), QLatin1String("0.411516846067"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("acos(KNumber(\"2/5\"))", acos(KNumber(QLatin1String("2/5"))), QLatin1String("1.15927948073"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("atan(KNumber(\"2/5\"))", atan(KNumber(QLatin1String("2/5"))), QLatin1String("0.380506377112"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("asin(KNumber(\"-2/5\"))", asin(KNumber(QLatin1String("-2/5"))), QLatin1String("-0.411516846067"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("acos(KNumber(\"-2/5\"))", acos(KNumber(QLatin1String("-2/5"))), QLatin1String("1.98231317286"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("atan(KNumber(\"-2/5\"))", atan(KNumber(QLatin1String("-2/5"))), QLatin1String("-0.380506377112"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("asin(KNumber(0.3))", asin(KNumber(0.3)), QLatin1String("0.304692654015"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("acos(KNumber(0.3))", acos(KNumber(0.3)), QLatin1String("1.26610367278"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("atan(KNumber(0.3))", atan(KNumber(0.3)), QLatin1String("0.291456794478"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("asin(KNumber(-0.3))", asin(KNumber(-0.3)), QLatin1String("-0.304692654015"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("acos(KNumber(-0.3))", acos(KNumber(-0.3)), QLatin1String("1.87548898081"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("atan(KNumber(-0.3))", atan(KNumber(-0.3)), QLatin1String("-0.291456794478"), KNumber::TYPE_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void testingMultiplications() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing multiplications:\n";
|
|
||||||
std::cout << "------------------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(5) * KNumber(2)", KNumber(5) * KNumber(2), QLatin1String("10"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5) * KNumber(\"2/3\")", KNumber(5) * KNumber(QLatin1String("2/3")), QLatin1String("10/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(5) * KNumber(\"2/5\")", KNumber(5) * KNumber(QLatin1String("2/5")), QLatin1String("2"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5) * KNumber(2.3)", KNumber(5) * KNumber(2.3), QLatin1String("11.5"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(0) * KNumber(\"2/5\")", KNumber(0) * KNumber(QLatin1String("2/5")), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(0) * KNumber(2.3)", KNumber(0) * KNumber(2.3), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
checkResult("KNumber(\"5/3\") * KNumber(2)", KNumber(QLatin1String("5/3")) * KNumber(2), QLatin1String("10/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"5/3\") * KNumber(0)", KNumber(QLatin1String("5/3")) * KNumber(0), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5/3\") * KNumber(\"2/3\")", KNumber(QLatin1String("5/3")) * KNumber(QLatin1String("2/3")), QLatin1String("10/9"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"25/6\") * KNumber(\"12/5\")", KNumber(QLatin1String("25/6")) * KNumber(QLatin1String("12/5")), QLatin1String("10"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5/2\") * KNumber(2.3)", KNumber(QLatin1String("5/2")) * KNumber(2.3), QLatin1String("5.75"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("KNumber(5.3) * KNumber(2)", KNumber(5.3) * KNumber(2), QLatin1String("10.6"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.3) * KNumber(0)", KNumber(5.3) * KNumber(0), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5.3) * KNumber(\"1/2\")", KNumber(5.3) * KNumber(QLatin1String("1/2")), QLatin1String("2.65"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.3) * KNumber(2.3)", KNumber(5.3) * KNumber(2.3), QLatin1String("12.19"), KNumber::TYPE_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingDivisions() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing divisions:\n";
|
|
||||||
std::cout << "------------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(5) / KNumber(2)", KNumber(5) / KNumber(2), QLatin1String("5/2"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(122) / KNumber(2)", KNumber(122) / KNumber(2), QLatin1String("61"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(12) / KNumber(0)", KNumber(12) / KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-12) / KNumber(0)", KNumber(-12) / KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(5) / KNumber(\"2/3\")", KNumber(5) / KNumber(QLatin1String("2/3")), QLatin1String("15/2"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(6) / KNumber(\"2/3\")", KNumber(6) / KNumber(QLatin1String("2/3")), QLatin1String("9"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5) / KNumber(2.5)", KNumber(5) / KNumber(2.5), QLatin1String("2"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5) / KNumber(0.0)", KNumber(5) / KNumber(0.0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) / KNumber(0.0)", KNumber(-5) / KNumber(0.0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
checkResult("KNumber(\"5/3\") / KNumber(2)", KNumber(QLatin1String("5/3")) / KNumber(2), QLatin1String("5/6"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"5/3\") / KNumber(0)", KNumber(QLatin1String("5/3")) / KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") / KNumber(0)", KNumber(QLatin1String("-5/3")) / KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"5/3\") / KNumber(\"2/3\")", KNumber(QLatin1String("5/3")) / KNumber(QLatin1String("2/3")), QLatin1String("5/2"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"49/3\") / KNumber(\"7/9\")", KNumber(QLatin1String("49/3")) / KNumber(QLatin1String("7/9")), QLatin1String("21"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5/2\") / KNumber(2.5)", KNumber(QLatin1String("5/2")) / KNumber(2.5), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5/2\") / KNumber(0.0)", KNumber(QLatin1String("5/2")) / KNumber(0.0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/2\") / KNumber(0.0)", KNumber(QLatin1String("-5/2")) / KNumber(0.0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
checkResult("KNumber(5.3) / KNumber(2)", KNumber(5.3) / KNumber(2), QLatin1String("2.65"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.3) / KNumber(0)", KNumber(5.3) / KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.3) / KNumber(0)", KNumber(-5.3) / KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(5.3) / KNumber(\"2/3\")", KNumber(5.3) / KNumber(QLatin1String("2/3")), QLatin1String("7.95"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.5) / KNumber(2.5)", KNumber(5.5) / KNumber(2.5), QLatin1String("2.2"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.5) / KNumber(0.0)", KNumber(5.5) / KNumber(0.0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.5) / KNumber(0.0)", KNumber(-5.5) / KNumber(0.0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingModulus() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing modulus:\n";
|
|
||||||
std::cout << "----------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(23) % KNumber(4)", KNumber(23) % KNumber(4), QLatin1String("3"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(12) % KNumber(-5)", KNumber(12) % KNumber(-5), QLatin1String("2"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(-12) % KNumber(5)", KNumber(-12) % KNumber(5), QLatin1String("3"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(12) % KNumber(0)", KNumber(-12) % KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-12) % KNumber(0)", KNumber(-12) % KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
#warning test for other types
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingAndOr() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing And/Or:\n";
|
|
||||||
std::cout << "---------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(17) & KNumber(9)", KNumber(17) & KNumber(9), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(17) | KNumber(9)", KNumber(17) | KNumber(9), QLatin1String("25"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(1023) & KNumber(255)", KNumber(1023) & KNumber(255), QLatin1String("255"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(1023) | KNumber(255)", KNumber(1023) | KNumber(255), QLatin1String("1023"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
#warning test for other types
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void testingAbs() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing absolute value:\n";
|
|
||||||
std::cout << "-----------------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(5).abs()", KNumber(5).abs(), QLatin1String("5"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"2/3\").abs()", KNumber(QLatin1String("2/3")).abs(), QLatin1String("2/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"2.3\").abs()", KNumber(QLatin1String("2.3")).abs(), QLatin1String("2.3"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("KNumber(-5).abs()", KNumber(-5).abs(), QLatin1String("5"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"-2/3\").abs()", KNumber(QLatin1String("-2/3")).abs(), QLatin1String("2/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"-2.3\").abs()", KNumber(QLatin1String("-2.3")).abs(), QLatin1String("2.3"), KNumber::TYPE_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingTruncateToInteger() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing truncate to an integer:\n";
|
|
||||||
std::cout << "-------------------------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(16).integerPart()", KNumber(16).integerPart(), QLatin1String("16"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"43/9\").integerPart()", KNumber(QLatin1String("43/9")).integerPart(), QLatin1String("4"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"-43/9\").integerPart()", KNumber(QLatin1String("-43/9")).integerPart(), QLatin1String("-4"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5.25\").integerPart()", KNumber(QLatin1String("5.25")).integerPart(), QLatin1String("5"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"-5.25\").integerPart()", KNumber(QLatin1String("-5.25")).integerPart(), QLatin1String("-5"), KNumber::TYPE_INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void testingSqrt() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing square root, cubic root:\n";
|
|
||||||
std::cout << "--------------------------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(16).sqrt()", KNumber(16).sqrt(), QLatin1String("4"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(-16).sqrt()", KNumber(-16).sqrt(), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"16/9\").sqrt()", KNumber(QLatin1String("16/9")).sqrt(), QLatin1String("4/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"-16/9\").sqrt()", KNumber(QLatin1String("-16/9")).sqrt(), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(2).sqrt()", KNumber(2).sqrt(), QLatin1String("1.41421356237"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(\"2/3\").sqrt()", KNumber(QLatin1String("2/3")).sqrt(), QLatin1String("0.816496580928"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(\"0.25\").sqrt()", KNumber(QLatin1String("0.25")).sqrt(), QLatin1String("0.5"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(\"-0.25\").sqrt()", KNumber(QLatin1String("-0.25")).sqrt(), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
checkResult("KNumber(27).cbrt()", KNumber(27).cbrt(), QLatin1String("3"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(-27).cbrt()", KNumber(-27).cbrt(), QLatin1String("-3"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"27/8\").cbrt()", KNumber(QLatin1String("27/8")).cbrt(), QLatin1String("3/2"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"-8/27\").cbrt()", KNumber(QLatin1String("-8/27")).cbrt(), QLatin1String("-2/3"), KNumber::TYPE_FRACTION);
|
|
||||||
#warning need to check non-perfect cube roots
|
|
||||||
checkResult("KNumber(2).cbrt()", KNumber(2).cbrt(), QLatin1String("1.25992104989"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(\"2/3\").cbrt()", KNumber(QLatin1String("2/3")).cbrt(), QLatin1String("0.873580464736"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(\"0.25\").cbrt()", KNumber(QLatin1String("0.25")).cbrt(), QLatin1String("0.629960524947"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(\"-0.25\").cbrt()", KNumber(QLatin1String("-0.25")).cbrt(), QLatin1String("-0.629960524947"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingFactorial() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing factorial:\n";
|
|
||||||
std::cout << "------------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(-1).factorial()", KNumber(-1).factorial(), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-2).factorial()", KNumber(-2).factorial(), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-20).factorial()", KNumber(-20).factorial(), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-1/2).factorial()", KNumber(QLatin1String("-1/2")).factorial(), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-0.5).factorial()", KNumber(QLatin1String("-0.5")).factorial(), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
checkResult("KNumber(0).factorial()", KNumber(0).factorial(), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(1).factorial()", KNumber(1).factorial(), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(2).factorial()", KNumber(2).factorial(), QLatin1String("2"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(3).factorial()", KNumber(3).factorial(), QLatin1String("6"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(4).factorial()", KNumber(4).factorial(), QLatin1String("24"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5).factorial()", KNumber(5).factorial(), QLatin1String("120"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(6).factorial()", KNumber(6).factorial(), QLatin1String("720"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(9).factorial()", KNumber(9).factorial(), QLatin1String("362880"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(12).factorial()", KNumber(12).factorial(), QLatin1String("479001600"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(13).factorial()", KNumber(13).factorial(), QLatin1String("6227020800"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
checkResult("KNumber(1/2).factorial()", KNumber(QLatin1String("1/2")).factorial(), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(2/1).factorial()", KNumber(QLatin1String("2/1")).factorial(), QLatin1String("2"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(3/2).factorial()", KNumber(QLatin1String("3/2")).factorial(), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
checkResult("KNumber(0.1).factorial()", KNumber(0.1).factorial(), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(0.5).factorial()", KNumber(0.5).factorial(), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(1.5).factorial()", KNumber(1.5).factorial(), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(2.5).factorial()", KNumber(2.5).factorial(), QLatin1String("2"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(3.5).factorial()", KNumber(3.5).factorial(), QLatin1String("6"), KNumber::TYPE_INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingComplement() {
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing complement:\n";
|
|
||||||
std::cout << "-------------------\n";
|
|
||||||
|
|
||||||
// at first glance, these look like they should work
|
|
||||||
// but there is an annoyance. If we use the mpz_com function
|
|
||||||
// ~-2 == 1, but the HEX/OCT/BIN views are broken :-(
|
|
||||||
// specifically, if the value is negative, it goes badly pretty quick..
|
|
||||||
#if 0
|
|
||||||
checkResult("~KNumber(0)", ~KNumber(0), QLatin1String("-1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("~KNumber(1)", ~KNumber(1), QLatin1String("-2"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("~KNumber(2)", ~KNumber(2), QLatin1String("-3"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("~KNumber(8)", ~KNumber(8), QLatin1String("-9"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("~KNumber(15)", ~KNumber(15), QLatin1String("-16"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("~KNumber(-1)", ~KNumber(-1), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("~KNumber(-2)", ~KNumber(-2), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("~KNumber(-3)", ~KNumber(-3), QLatin1String("2"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("~KNumber(-9)", ~KNumber(-9), QLatin1String("8"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("~KNumber(-16)", ~KNumber(-16), QLatin1String("15"), KNumber::TYPE_INTEGER);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
checkResult("~KNumber(0.12345)", ~KNumber(0.12345), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("~KNumber(-0.12345)", ~KNumber(-0.12345), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("~KNumber(\"1/2\")", ~KNumber(QLatin1String("1/2")), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("~KNumber(\"-1/2\")", ~KNumber(QLatin1String("-1/2")), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingShifts() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing left/right shift:\n";
|
|
||||||
std::cout << "-------------------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(16) << KNumber(2)", KNumber(16) << KNumber(2), QLatin1String("64"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(16) >> KNumber(2)", KNumber(16) >> KNumber(2), QLatin1String("4"), KNumber::TYPE_INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingPower() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing Power:\n";
|
|
||||||
std::cout << "--------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(0) ^ KNumber(0)", KNumber(0).pow(KNumber(0)), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(0) ^ KNumber(-4)", KNumber(0).pow(KNumber(-4)), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(5) ^ KNumber(4)", KNumber(5).pow(KNumber(4)), QLatin1String("625"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(122) ^ KNumber(0)", KNumber(122).pow(KNumber(0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(-5) ^ KNumber(0)", KNumber(-5).pow(KNumber(0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(-2) ^ KNumber(3)", KNumber(-2).pow(KNumber(3)), QLatin1String("-8"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(-2) ^ KNumber(4)", KNumber(-2).pow(KNumber(4)), QLatin1String("16"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5) ^ KNumber(-2)", KNumber(5).pow(KNumber(-2)), QLatin1String("1/25"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(8) ^ KNumber(\"2/3\")", KNumber(8).pow(KNumber(QLatin1String("2/3"))), QLatin1String("4"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(8) ^ KNumber(\"-2/3\")", KNumber(8).pow(KNumber(QLatin1String("-2/3"))), QLatin1String("1/4"), KNumber::TYPE_FRACTION);
|
|
||||||
|
|
||||||
checkResult("KNumber(-16) ^ KNumber(\"1/4\")", KNumber(-16).pow(KNumber(QLatin1String("1/4"))), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-8) ^ KNumber(\"1/3\")", KNumber(-8).pow(KNumber(QLatin1String("1/3"))), QLatin1String("-2"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5) ^ KNumber(0.0)", KNumber(5).pow(KNumber(0.0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(-5) ^ KNumber(0.0)", KNumber(-5).pow(KNumber(0.0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
checkResult("KNumber(\"5/3\") ^ KNumber(2)", KNumber(QLatin1String("5/3")).pow(KNumber(2)), QLatin1String("25/9"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"5/3\") ^ KNumber(0)", KNumber(QLatin1String("5/3")).pow(KNumber(0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"-5/3\") ^ KNumber(0)", KNumber(QLatin1String("-5/3")).pow(KNumber(0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"8/27\") ^ KNumber(\"2/3\")", KNumber(QLatin1String("8/27")).pow(KNumber(QLatin1String("2/3"))), QLatin1String("4/9"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"49/3\") ^ KNumber(\"7/9\")", KNumber(QLatin1String("49/3")).pow(KNumber(QLatin1String("7/9"))), QLatin1String("8.78016428243"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(\"5/2\") ^ KNumber(2.5)", KNumber(QLatin1String("5/2")).pow(KNumber(2.5)), QLatin1String("9.88211768803"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(\"5/2\") ^ KNumber(0.0)", KNumber(QLatin1String("5/2")).pow(KNumber(0.0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"-5/2\") ^ KNumber(0.0)", KNumber(QLatin1String("-5/2")).pow(KNumber(0.0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
checkResult("KNumber(5.3) ^ KNumber(2)", KNumber(5.3).pow(KNumber(2)), QLatin1String("28.09"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.3) ^ KNumber(0)", KNumber(5.3).pow(KNumber(0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(-5.3) ^ KNumber(0)", KNumber(-5.3).pow(KNumber(0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(5.3) ^ KNumber(\"2/3\")", KNumber(5.3).pow(KNumber(QLatin1String("2/3"))), QLatin1String("3.03983898039"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.5) ^ KNumber(2.5)", KNumber(5.5).pow(KNumber(2.5)), QLatin1String("70.9425383673"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(5.5) ^ KNumber(0.0)", KNumber(5.5).pow(KNumber(0.0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(-5.5) ^ KNumber(0.0)", KNumber(-5.5).pow(KNumber(0.0)), QLatin1String("1"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
checkResult("KNumber::Pi() ^ KNumber::Pi()", KNumber::Pi().pow(KNumber::Pi()), QLatin1String("36.4621596072"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber::Euler() ^ KNumber::Pi()", KNumber::Euler().pow(KNumber::Pi()), QLatin1String("23.1406926328"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
|
|
||||||
checkResult("KNumber(2.0) ^ KNumber(0.5)", KNumber(2.0).pow(KNumber(0.5)), QLatin1String("1.41421356237"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber(2.0) ^ KNumber(-0.5)", KNumber(2.0).pow(KNumber(-0.5)), QLatin1String("0.707106781187"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
|
|
||||||
checkResult("KNumber(-2.0).exp()", KNumber(-2.0).exp(), QLatin1String("0.135335283237"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber::Euler() ^ KNumber(-2.0)", KNumber::Euler().pow(KNumber(-2.0)), QLatin1String("0.135335283237"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
|
|
||||||
checkResult("KNumber(2.0).exp()", KNumber(2.0).exp(), QLatin1String("7.38905609893"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("KNumber::Euler() ^ KNumber(2.0)", KNumber::Euler().pow(KNumber(2.0)), QLatin1String("7.38905609893"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
// TODO: kinda odd that this ends up being an integer
|
|
||||||
// i guess since my euler constant is only 100 digits, we've exceeded the fractional part
|
|
||||||
checkResult("KNumber::Euler() ^ 1000", KNumber::Euler().pow(KNumber(1000)), QLatin1String("1.97007111402e+434"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
// TODO: make this test pass
|
|
||||||
// the problem is that it is using the libc exp function which has limits that GMP does not
|
|
||||||
// we should basically make this equivalent to KNumber::Euler().pow(KNumber(1000))
|
|
||||||
// which does work
|
|
||||||
#if 0
|
|
||||||
checkResult("KNumber(1000).exp()", KNumber(1000).exp(), QLatin1String("23.1406926328"), KNumber::TYPE_FLOAT);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
KNumber::setDefaultFractionalInput(true);
|
|
||||||
checkResult("KNumber(\"3.1415926\") ^ KNumber(\"3.1415926\")", KNumber(QLatin1String("3.1415926")).pow(KNumber(QLatin1String("3.1415926"))), QLatin1String("36.4621554164"), KNumber::TYPE_FLOAT);
|
|
||||||
KNumber::setDefaultFractionalInput(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingInfArithmetic() {
|
|
||||||
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Testing inf/nan-arithmetics:\n";
|
|
||||||
std::cout << "----------------------------\n";
|
|
||||||
|
|
||||||
checkResult("inf + KNumber(2)", KNumber::PosInfinity + KNumber(2), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) + inf", KNumber(-5) + KNumber::PosInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf + KNumber(\"1/2\")", KNumber::PosInfinity + KNumber(QLatin1String("1/2")), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") + inf", KNumber(QLatin1String("-5/3")) + KNumber::PosInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf + KNumber(2.01)", KNumber::PosInfinity + KNumber(2.01), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) + inf", KNumber(-5.4) + KNumber::PosInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf + KNumber(2)", KNumber::NegInfinity + KNumber(2), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) + -inf", KNumber(-5) + KNumber::NegInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf + KNumber(\"1/2\")", KNumber::NegInfinity + KNumber(QLatin1String("1/2")), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") + -inf", KNumber(QLatin1String("-5/3")) + KNumber::NegInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf + KNumber(2.01)", KNumber::NegInfinity + KNumber(2.01), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) + -inf", KNumber(-5.4) + KNumber::NegInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan + KNumber(2)", KNumber::NaN + KNumber(2), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) + nan", KNumber(-5) + KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan + KNumber(\"1/2\")", KNumber::NaN + KNumber(QLatin1String("1/2")), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") + nan", KNumber(QLatin1String("-5/3")) + KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan + KNumber(2.01)", KNumber::NaN + KNumber(2.01), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) + nan", KNumber(-5.4) + KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf + inf", KNumber::PosInfinity + KNumber::PosInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf + -inf", KNumber::PosInfinity + KNumber::NegInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf + inf", KNumber::NegInfinity + KNumber::PosInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf + -inf", KNumber::NegInfinity + KNumber::NegInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf + nan", KNumber::PosInfinity + KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf + nan", KNumber::NegInfinity + KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan + inf", KNumber::NaN + KNumber::PosInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf + nan", KNumber::NegInfinity + KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
checkResult("inf - KNumber(2)", KNumber::PosInfinity - KNumber(2), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) - inf", KNumber(-5) - KNumber::PosInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf - KNumber(\"1/2\")", KNumber::PosInfinity - KNumber(QLatin1String("1/2")), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") - inf", KNumber(QLatin1String("-5/3")) - KNumber::PosInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf - KNumber(2.01)", KNumber::PosInfinity - KNumber(2.01), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) - inf", KNumber(-5.4) - KNumber::PosInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf - KNumber(2)", KNumber::NegInfinity - KNumber(2), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) - -inf", KNumber(-5) - KNumber::NegInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf - KNumber(\"1/2\")", KNumber::NegInfinity - KNumber(QLatin1String("1/2")), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") - -inf", KNumber(QLatin1String("-5/3")) - KNumber::NegInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf - KNumber(2.01)", KNumber::NegInfinity - KNumber(2.01), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) - -inf", KNumber(-5.4) - KNumber::NegInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan - KNumber(2)", KNumber::NaN - KNumber(2), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) - nan", KNumber(-5) - KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan - KNumber(\"1/2\")", KNumber::NaN - KNumber(QLatin1String("1/2")), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") - nan", KNumber(QLatin1String("-5/3")) - KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan - KNumber(2.01)", KNumber::NaN - KNumber(2.01), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) - nan", KNumber(-5.4) - KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf - inf", KNumber::PosInfinity - KNumber::PosInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf - -inf", KNumber::PosInfinity - KNumber::NegInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf - inf", KNumber::NegInfinity - KNumber::PosInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf - -inf", KNumber::NegInfinity - KNumber::NegInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf - nan", KNumber::PosInfinity - KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf - nan", KNumber::NegInfinity - KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan - inf", KNumber::NaN - KNumber::PosInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf - nan", KNumber::NegInfinity - KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
checkResult("inf * KNumber(2)", KNumber::PosInfinity * KNumber(2), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) * inf", KNumber(-5) * KNumber::PosInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf * KNumber(\"1/2\")", KNumber::PosInfinity * KNumber(QLatin1String("1/2")), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") * inf", KNumber(QLatin1String("-5/3")) * KNumber::PosInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf * KNumber(2.01)", KNumber::PosInfinity * KNumber(2.01), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) * inf", KNumber(-5.4) * KNumber::PosInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf * KNumber(2)", KNumber::NegInfinity * KNumber(2), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) * -inf", KNumber(-5) * KNumber::NegInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf * KNumber(\"1/2\")", KNumber::NegInfinity * KNumber(QLatin1String("1/2")), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") * -inf", KNumber(QLatin1String("-5/3")) * KNumber::NegInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf * KNumber(2.01)", KNumber::NegInfinity * KNumber(2.01), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) * -inf", KNumber(-5.4) * KNumber::NegInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan * KNumber(2)", KNumber::NaN * KNumber(2), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) * nan", KNumber(-5) * KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan * KNumber(\"1/2\")", KNumber::NaN * KNumber(QLatin1String("1/2")), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") * nan", KNumber(QLatin1String("-5/3")) * KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan * KNumber(2.01)", KNumber::NaN * KNumber(2.01), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) * nan", KNumber(-5.4) * KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf * inf", KNumber::PosInfinity * KNumber::PosInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf * -inf", KNumber::PosInfinity * KNumber::NegInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf * inf", KNumber::NegInfinity * KNumber::PosInfinity, QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf * -inf", KNumber::NegInfinity * KNumber::NegInfinity, QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf * nan", KNumber::PosInfinity * KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf * nan", KNumber::NegInfinity * KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan * inf", KNumber::NaN * KNumber::PosInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf * nan", KNumber::NegInfinity * KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(0) * inf", KNumber(0) * KNumber::PosInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(0) * -inf", KNumber(0) * KNumber::NegInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf * KNumber(0)", KNumber::PosInfinity * KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf * KNumber(0)", KNumber::NegInfinity * KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(0.0) * inf", KNumber(0.0) * KNumber::PosInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(0.0) * -inf", KNumber(0.0) * KNumber::NegInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf * KNumber(0.0)", KNumber::PosInfinity * KNumber(0.0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf * KNumber(0.0)", KNumber::NegInfinity * KNumber(0.0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
checkResult("inf / KNumber(2)", KNumber::PosInfinity / KNumber(2), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) / inf", KNumber(-5) / KNumber::PosInfinity, QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("inf / KNumber(\"1/2\")", KNumber::PosInfinity / KNumber(QLatin1String("1/2")), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") / inf", KNumber(QLatin1String("-5/3")) / KNumber::PosInfinity, QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("inf / KNumber(2.01)", KNumber::PosInfinity / KNumber(2.01), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) / inf", KNumber(-5.4) / KNumber::PosInfinity, QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("-inf / KNumber(2)", KNumber::NegInfinity / KNumber(2), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) / -inf", KNumber(-5) / KNumber::NegInfinity, QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("-inf / KNumber(\"1/2\")", KNumber::NegInfinity / KNumber(QLatin1String("1/2")), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") / -inf", KNumber(QLatin1String("-5/3")) / KNumber::NegInfinity, QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("-inf / KNumber(2.01)", KNumber::NegInfinity / KNumber(2.01), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) / -inf", KNumber(-5.4) / KNumber::NegInfinity, QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("nan / KNumber(2)", KNumber::NaN / KNumber(2), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) / nan", KNumber(-5) / KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan / KNumber(\"1/2\")", KNumber::NaN / KNumber(QLatin1String("1/2")), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/3\") / nan", KNumber(QLatin1String("-5/3")) / KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan / KNumber(2.01)", KNumber::NaN / KNumber(2.01), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5.4) / nan", KNumber(-5.4) / KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf / inf", KNumber::PosInfinity / KNumber::PosInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf / -inf", KNumber::PosInfinity / KNumber::NegInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf / inf", KNumber::NegInfinity / KNumber::PosInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf / -inf", KNumber::NegInfinity / KNumber::NegInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("inf / nan", KNumber::PosInfinity / KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf / nan", KNumber::NegInfinity / KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("nan / inf", KNumber::NaN / KNumber::PosInfinity, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf / nan", KNumber::NegInfinity / KNumber::NaN, QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(0) / inf", KNumber(0) / KNumber::PosInfinity, QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(0) / -inf", KNumber(0) / KNumber::NegInfinity, QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("inf / KNumber(0)", KNumber::PosInfinity / KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf / KNumber(0)", KNumber::NegInfinity / KNumber(0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(0.0) / inf", KNumber(0.0) / KNumber::PosInfinity, QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(0.0) / -inf", KNumber(0.0) / KNumber::NegInfinity, QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("inf / KNumber(0.0)", KNumber::PosInfinity / KNumber(0.0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("-inf / KNumber(0.0)", KNumber::NegInfinity / KNumber(0.0), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
checkResult("KNumber(5) ^ KNumber(\"inf\")", KNumber(5).pow(KNumber::PosInfinity), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) ^ KNumber(\"inf\")", KNumber(-5).pow(KNumber::PosInfinity), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"5/2\") ^ KNumber(\"inf\")", KNumber(QLatin1String("5/2")).pow(KNumber::PosInfinity), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/2\") ^ KNumber(\"inf\")", KNumber(QLatin1String("-5/2")).pow(KNumber::PosInfinity), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"5.2\") ^ KNumber(\"inf\")", KNumber(QLatin1String("5.2")).pow(KNumber::PosInfinity), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5.2\") ^ KNumber(\"inf\")", KNumber(QLatin1String("-5.2")).pow(KNumber::PosInfinity), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
checkResult("KNumber(5) ^ KNumber(\"-inf\")", KNumber(5).pow(KNumber::NegInfinity), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(-5) ^ KNumber(\"-inf\")", KNumber(-5).pow(KNumber::NegInfinity), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5/2\") ^ KNumber(\"-inf\")", KNumber(QLatin1String("5/2")).pow(KNumber::NegInfinity), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"-5/2\") ^ KNumber(\"-inf\")", KNumber(QLatin1String("-5/2")).pow(KNumber::NegInfinity), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5.2\") ^ KNumber(\"-inf\")", KNumber(QLatin1String("5.2")).pow(KNumber::NegInfinity), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"-5.2\") ^ KNumber(\"-inf\")", KNumber(QLatin1String("-5.2")).pow(KNumber::NegInfinity), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
checkResult("KNumber(5) ^ KNumber(\"nan\")", KNumber(5).pow(KNumber::NaN), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(-5) ^ KNumber(\"nan\")", KNumber(-5).pow(KNumber::NaN), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"5/2\") ^ KNumber(\"nan\")", KNumber(QLatin1String("5/2")).pow(KNumber::NaN), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5/2\") ^ KNumber(\"nan\")", KNumber(QLatin1String("-5/2")).pow(KNumber::NaN), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"5.2\") ^ KNumber(\"nan\")", KNumber(QLatin1String("5.2")).pow(KNumber::NaN), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-5.2\") ^ KNumber(\"nan\")", KNumber(QLatin1String("-5.2")).pow(KNumber::NaN), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
checkResult("KNumber(\"nan\") ^ KNumber(\"nan\")", KNumber::NaN.pow(KNumber::NaN), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"nan\") ^ KNumber(\"inf\")", KNumber::NaN.pow(KNumber::PosInfinity), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"nan\") ^ KNumber(\"-inf\")", KNumber::NaN.pow(KNumber::NegInfinity), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
checkResult("KNumber(\"inf\") ^ KNumber(\"nan\")", KNumber::PosInfinity.pow(KNumber::NaN), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"inf\") ^ KNumber(\"inf\")", KNumber::PosInfinity.pow(KNumber::PosInfinity), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"inf\") ^ KNumber(\"-inf\")", KNumber::PosInfinity.pow(KNumber::NegInfinity), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
checkResult("KNumber(\"-inf\") ^ KNumber(\"nan\")", KNumber::NegInfinity.pow(KNumber::NaN), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-inf\") ^ KNumber(\"inf\")", KNumber::NegInfinity.pow(KNumber::PosInfinity), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-inf\") ^ KNumber(\"-inf\")", KNumber::NegInfinity.pow(KNumber::NegInfinity), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingFloatPrecision() {
|
|
||||||
|
|
||||||
KNumber::setDefaultFloatPrecision(100);
|
|
||||||
checkResult("Precision >= 100: (KNumber(1) + KNumber(\"1e-80\")) - KNumber(1)", (KNumber(1) + KNumber(QLatin1String("1e-80"))) - KNumber(1), QLatin1String("1e-80"), KNumber::TYPE_FLOAT);
|
|
||||||
checkResult("Precision >= 100: (KNumber(1) + KNumber(\"1e-980\")) - KNumber(1)", (KNumber(1) + KNumber(QLatin1String("1e-980"))) - KNumber(1), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
KNumber::setDefaultFloatPrecision(1000);
|
|
||||||
checkResult("Precision >= 1000: (KNumber(1) + KNumber(\"1e-980\")) - KNumber(1)", (KNumber(1) + KNumber(QLatin1String("1e-980"))) - KNumber(1), QLatin1String("1e-980"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
KNumber::setDefaultFloatPrecision(20);
|
|
||||||
checkResult("Precision >= 20: sin(KNumber(30))", sin(KNumber(30) * (KNumber::Pi() / KNumber(180))), QLatin1String("0.5"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingOutput() {
|
|
||||||
|
|
||||||
KNumber::setDefaultFloatOutput(false);
|
|
||||||
checkResult("Fractional output: KNumber(\"1/4\")", KNumber(QLatin1String("1/4")), QLatin1String("1/4"), KNumber::TYPE_FRACTION);
|
|
||||||
|
|
||||||
KNumber::setDefaultFloatOutput(true);
|
|
||||||
checkResult("Float: KNumber(\"1/4\")", KNumber(QLatin1String("1/4")), QLatin1String("0.25"), KNumber::TYPE_FRACTION);
|
|
||||||
|
|
||||||
KNumber::setDefaultFloatOutput(false);
|
|
||||||
KNumber::setSplitoffIntegerForFractionOutput(true);
|
|
||||||
checkResult("Fractional output: KNumber(\"1/4\")", KNumber(QLatin1String("1/4")), QLatin1String("1/4"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("Fractional output: KNumber(\"-1/4\")", KNumber(QLatin1String("-1/4")), QLatin1String("-1/4"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("Fractional output: KNumber(\"21/4\")", KNumber(QLatin1String("21/4")), QLatin1String("5 1/4"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("Fractional output: KNumber(\"-21/4\")", KNumber(QLatin1String("-21/4")), QLatin1String("-5 1/4"), KNumber::TYPE_FRACTION);
|
|
||||||
|
|
||||||
KNumber::setSplitoffIntegerForFractionOutput(false);
|
|
||||||
checkResult("Fractional output: KNumber(\"1/4\")", KNumber(QLatin1String("1/4")), QLatin1String("1/4"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("Fractional output: KNumber(\"-1/4\")", KNumber(QLatin1String("-1/4")), QLatin1String("-1/4"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("Fractional output: KNumber(\"21/4\")", KNumber(QLatin1String("21/4")), QLatin1String("21/4"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("Fractional output: KNumber(\"-21/4\")", KNumber(QLatin1String("-21/4")), QLatin1String("-21/4"), KNumber::TYPE_FRACTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingConstructors() {
|
|
||||||
std::cout << "Testing Constructors:\n";
|
|
||||||
std::cout << "---------------------\n";
|
|
||||||
|
|
||||||
checkResult("KNumber(5)", KNumber(5), QLatin1String("5"), KNumber::TYPE_INTEGER);
|
|
||||||
checkType(QLatin1String("KNumber(5.3)"), KNumber(5.3).type(), KNumber::TYPE_FLOAT);
|
|
||||||
checkType(QLatin1String("KNumber(0.0)"), KNumber(0.0).type(), KNumber::TYPE_INTEGER);
|
|
||||||
|
|
||||||
checkResult("KNumber(\"5\")", KNumber(QLatin1String("5")), QLatin1String("5"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"5/3\")", KNumber(QLatin1String("5/3")), QLatin1String("5/3"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"5/1\")", KNumber(QLatin1String("5/1")), QLatin1String("5"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"0/12\")", KNumber(QLatin1String("0/12")), QLatin1String("0"), KNumber::TYPE_INTEGER);
|
|
||||||
KNumber::setDefaultFractionalInput(true);
|
|
||||||
std::cout << "Read decimals as fractions:\n";
|
|
||||||
checkResult("KNumber(\"5\")", KNumber(QLatin1String("5")), QLatin1String("5"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"1.2\")", KNumber(QLatin1String("1.2")), QLatin1String("6/5"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"-0.02\")", KNumber(QLatin1String("-0.02")), QLatin1String("-1/50"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"5e-2\")", KNumber(QLatin1String("5e-2")), QLatin1String("1/20"), KNumber::TYPE_FRACTION);
|
|
||||||
checkResult("KNumber(\"1.2e3\")", KNumber(QLatin1String("1.2e3")), QLatin1String("1200"), KNumber::TYPE_INTEGER);
|
|
||||||
checkResult("KNumber(\"0.02e+1\")", KNumber(QLatin1String("0.02e+1")), QLatin1String("1/5"), KNumber::TYPE_FRACTION);
|
|
||||||
|
|
||||||
KNumber::setDefaultFractionalInput(false);
|
|
||||||
std::cout << "Read decimals as floats:\n";
|
|
||||||
checkResult("KNumber(\"5.3\")", KNumber(QLatin1String("5.3")), QLatin1String("5.3"), KNumber::TYPE_FLOAT);
|
|
||||||
|
|
||||||
checkResult("KNumber(\"nan\")", KNumber(QLatin1String("nan")), QLatin1String("nan"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"inf\")", KNumber(QLatin1String("inf")), QLatin1String("inf"), KNumber::TYPE_ERROR);
|
|
||||||
checkResult("KNumber(\"-inf\")", KNumber(QLatin1String("-inf")), QLatin1String("-inf"), KNumber::TYPE_ERROR);
|
|
||||||
|
|
||||||
// test accepting of non-US number formatted strings
|
|
||||||
KNumber::setDecimalSeparator(",");
|
|
||||||
checkResult("KNumber(\"5,2\")", KNumber(QLatin1String("5,2")), QLatin1String("5.2"), KNumber::TYPE_FLOAT);
|
|
||||||
KNumber::setDecimalSeparator(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingConstants() {
|
|
||||||
std::cout << "\n\n";
|
|
||||||
std::cout << "Constants:\n";
|
|
||||||
std::cout << "----------\n";
|
|
||||||
|
|
||||||
checkType(QLatin1String("KNumber::Zero"), KNumber::Zero.type(), KNumber::TYPE_INTEGER);
|
|
||||||
checkType(QLatin1String("KNumber::One"), KNumber::One.type(), KNumber::TYPE_INTEGER);
|
|
||||||
checkType(QLatin1String("KNumber::NegOne"), KNumber::NegOne.type(), KNumber::TYPE_INTEGER);
|
|
||||||
checkType(QLatin1String("KNumber::Pi"), KNumber::Pi().type(), KNumber::TYPE_FLOAT);
|
|
||||||
checkType(QLatin1String("KNumber::Euler"), KNumber::Euler().type(), KNumber::TYPE_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
testingConstants();
|
|
||||||
testingConstructors();
|
|
||||||
testingCompare();
|
|
||||||
testingAdditions();
|
|
||||||
testingSubtractions();
|
|
||||||
testingMultiplications();
|
|
||||||
testingDivisions();
|
|
||||||
testingAndOr();
|
|
||||||
testingModulus();
|
|
||||||
testingAbs();
|
|
||||||
testingSqrt();
|
|
||||||
testingFactorial();
|
|
||||||
testingComplement();
|
|
||||||
testingPower();
|
|
||||||
testingTruncateToInteger();
|
|
||||||
testingShifts();
|
|
||||||
testingInfArithmetic();
|
|
||||||
testingFloatPrecision();
|
|
||||||
testingTrig();
|
|
||||||
testingSpecial();
|
|
||||||
testingOutput();
|
|
||||||
std::cout << "SUCCESS" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<list_of_constants version="1">
|
|
||||||
<constant name="Pi" symbol="π" category="mathematics" value="3.14159265358979323846264338327950288419">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Euler Number" symbol="e" category="mathematics" value="2.71828182845904523536028747135266249775">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Golden Ratio" symbol="φ" category="mathematics" value="1.61803398874989484820458683436563811">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Light Speed" symbol="c" category="electromagnetism" value="2.99792458e8">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Planck's Constant" symbol="h" category="nuclear" value="6.6260693e-34">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Gravitational Constant" symbol="G" category="gravitation" value="6.6742e-11">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Earth Acceleration" symbol="g" category="gravitation" value="9.80665">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Elementary Charge" symbol="e" category="nuclear" value="1.60217653e-19">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Elementary Charge" symbol="e" category="electromagnetism" value="1.60217653e-19">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Impedance of Vacuum" symbol="Z₀" category="electromagnetism" value="376.730313461">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Fine-Structure Constant" symbol="α" category="nuclear" value="7.297352568e-3">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Permeability of Vacuum" symbol="μ₀" category="electromagnetism" value="1.2566370614e-6">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Permittivity of Vacuum" symbol="ε₀" category="electromagnetism" value="8.854187817e-12">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Boltzmann Constant" symbol="k" category="thermodynamics" value="1.3806505e-23">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
|
|
||||||
<constant name="Atomic Mass Unit" symbol="1u" category="thermodynamics" value="1.66053886e-27">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Molar Gas Constant" symbol="R" category="thermodynamics" value="8.314472">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Stefan-Boltzmann Constant" symbol="σ" category="thermodynamics" value="5.670400e-8">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
<constant name="Avogadro's Number" symbol="N_A" category="thermodynamics" value="6.0221415e23">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</constant>
|
|
||||||
</list_of_constants>
|
|
||||||
|
|
213
kcalc/stats.cpp
213
kcalc/stats.cpp
|
@ -1,213 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 1996 - 2000 Bernd Johannes Wuebben
|
|
||||||
wuebben@kde.org
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "stats.h"
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: KStats
|
|
||||||
// Desc: constructor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KStats::KStats() : error_flag_(false) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: ~KStats
|
|
||||||
// Desc: destructor
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KStats::~KStats() {
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: clearAll
|
|
||||||
// Desc: empties the data set
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KStats::clearAll() {
|
|
||||||
data_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: enterData
|
|
||||||
// Desc: adds an item to the data set
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KStats::enterData(const KNumber &data) {
|
|
||||||
data_.push_back(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: clearLast
|
|
||||||
// Desc: remoaves the last item from the data set
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void KStats::clearLast() {
|
|
||||||
|
|
||||||
if(!data_.isEmpty()) {
|
|
||||||
data_.pop_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sum
|
|
||||||
// Desc: calculates the SUM of all values in the data set
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KStats::sum() const {
|
|
||||||
|
|
||||||
KNumber result = KNumber::Zero;
|
|
||||||
|
|
||||||
Q_FOREACH(const KNumber &x, data_) {
|
|
||||||
result += x;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: median
|
|
||||||
// Desc: calculates the MEDIAN of all values in the data set
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KStats::median() {
|
|
||||||
|
|
||||||
KNumber result = KNumber::Zero;
|
|
||||||
size_t index;
|
|
||||||
|
|
||||||
unsigned int bound = count();
|
|
||||||
|
|
||||||
if (bound == 0) {
|
|
||||||
error_flag_ = true;
|
|
||||||
return KNumber::Zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bound == 1)
|
|
||||||
return data_.at(0);
|
|
||||||
|
|
||||||
// need to copy data_-list, because sorting afterwards
|
|
||||||
QVector<KNumber> tmp_data(data_);
|
|
||||||
qSort(tmp_data);
|
|
||||||
|
|
||||||
if (bound & 1) { // odd
|
|
||||||
index = (bound - 1) / 2 + 1;
|
|
||||||
result = tmp_data.at(index - 1);
|
|
||||||
} else { // even
|
|
||||||
index = bound / 2;
|
|
||||||
result = ((tmp_data.at(index - 1)) + (tmp_data.at(index))) / KNumber(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: std_kernel
|
|
||||||
// Desc: calculates the STD Kernel of all values in the data set
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KStats::std_kernel() {
|
|
||||||
KNumber result = KNumber::Zero;
|
|
||||||
const KNumber mean_value = mean();
|
|
||||||
|
|
||||||
if(mean_value.type() != KNumber::TYPE_ERROR) {
|
|
||||||
Q_FOREACH(const KNumber &x, data_) {
|
|
||||||
result += (x - mean_value) * (x - mean_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sum_of_squares
|
|
||||||
// Desc: calculates the SUM of all values in the data set (each squared)
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KStats::sum_of_squares() const {
|
|
||||||
|
|
||||||
KNumber result = KNumber::Zero;
|
|
||||||
|
|
||||||
Q_FOREACH(const KNumber &x, data_) {
|
|
||||||
result += (x * x);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: mean
|
|
||||||
// Desc: calculates the MEAN of all values in the data set
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KStats::mean() {
|
|
||||||
|
|
||||||
if (data_.isEmpty()) {
|
|
||||||
error_flag_ = true;
|
|
||||||
return KNumber::Zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (sum() / KNumber(count()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: std
|
|
||||||
// Desc: calculates the STANDARD DEVIATION of all values in the data set
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KStats::std() {
|
|
||||||
|
|
||||||
if (data_.isEmpty()) {
|
|
||||||
error_flag_ = true;
|
|
||||||
return KNumber::Zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (std_kernel() / KNumber(count())).sqrt();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: sample_std
|
|
||||||
// Desc: calculates the SAMPLE STANDARD DEVIATION of all values in the data set
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
KNumber KStats::sample_std() {
|
|
||||||
|
|
||||||
KNumber result = KNumber::Zero;
|
|
||||||
|
|
||||||
if (count() < 2) {
|
|
||||||
error_flag_ = true;
|
|
||||||
return KNumber::Zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = (std_kernel() / KNumber(count() - 1)).sqrt();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: count
|
|
||||||
// Desc: returns the amount of values in the data set
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int KStats::count() const {
|
|
||||||
|
|
||||||
return data_.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Name: error
|
|
||||||
// Desc: returns the error state AND clears it
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool KStats::error() {
|
|
||||||
|
|
||||||
bool value = error_flag_;
|
|
||||||
error_flag_ = false;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
Copyright (C) 1996 - 2000 Bernd Johannes Wuebben
|
|
||||||
wuebben@kde.org
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KSTATS_H_
|
|
||||||
#define KSTATS_H_
|
|
||||||
|
|
||||||
#include <QVector>
|
|
||||||
#include "knumber.h"
|
|
||||||
|
|
||||||
class KStats {
|
|
||||||
public:
|
|
||||||
KStats();
|
|
||||||
~KStats();
|
|
||||||
|
|
||||||
public:
|
|
||||||
void clearAll();
|
|
||||||
void enterData(const KNumber &data);
|
|
||||||
void clearLast();
|
|
||||||
KNumber sum() const;
|
|
||||||
KNumber sum_of_squares() const;
|
|
||||||
KNumber mean();
|
|
||||||
KNumber median();
|
|
||||||
KNumber std_kernel();
|
|
||||||
KNumber std();
|
|
||||||
KNumber sample_std();
|
|
||||||
int count() const;
|
|
||||||
bool error();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QVector<KNumber> data_;
|
|
||||||
bool error_flag_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2001 - 2013 Evan Teran
|
|
||||||
evan.teran@gmail.com
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KCALCVERSION
|
|
||||||
#define KCALCVERSION "2.13"
|
|
||||||
#endif
|
|
|
@ -107,5 +107,4 @@ X-KDE-PluginInfo-Depends=
|
||||||
X-KDE-PluginInfo-License=GPL
|
X-KDE-PluginInfo-License=GPL
|
||||||
X-KDE-PluginInfo-EnabledByDefault=true
|
X-KDE-PluginInfo-EnabledByDefault=true
|
||||||
|
|
||||||
X-Plasma-NotificationArea=true
|
|
||||||
X-Plasma-DefaultSize=200,200
|
X-Plasma-DefaultSize=200,200
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp
|
$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp
|
||||||
$XGETTEXT `find . -name \*.js -o -name \*.qml -o -name \*.cpp` -o $podir/konsoleprofiles.pot
|
$XGETTEXT `find . -o -name \*.cpp` -o $podir/konsoleprofiles.pot
|
||||||
rm -f rc.cpp
|
rm -f rc.cpp
|
||||||
|
|
|
@ -126,5 +126,3 @@ X-KDE-PluginInfo-Category=Utilities
|
||||||
X-KDE-PluginInfo-Depends=
|
X-KDE-PluginInfo-Depends=
|
||||||
X-KDE-PluginInfo-License=GPL
|
X-KDE-PluginInfo-License=GPL
|
||||||
X-KDE-PluginInfo-EnabledByDefault=true
|
X-KDE-PluginInfo-EnabledByDefault=true
|
||||||
|
|
||||||
#X-Plasma-NotificationArea=true
|
|
||||||
|
|
|
@ -128,5 +128,3 @@ X-KDE-PluginInfo-Category=Utilities
|
||||||
X-KDE-PluginInfo-Depends=
|
X-KDE-PluginInfo-Depends=
|
||||||
X-KDE-PluginInfo-License=GPL
|
X-KDE-PluginInfo-License=GPL
|
||||||
X-KDE-PluginInfo-EnabledByDefault=true
|
X-KDE-PluginInfo-EnabledByDefault=true
|
||||||
X-Plasma-NotificationArea=true
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
add_subdirectory(potd)
|
add_subdirectory(potd)
|
||||||
add_subdirectory(virus)
|
add_subdirectory(virus)
|
||||||
add_subdirectory(qmlwallpapers)
|
|
||||||
add_subdirectory(pattern)
|
add_subdirectory(pattern)
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
project(plasma-wallpaper-qml)
|
|
||||||
|
|
||||||
kde4_add_plugin(plasma_wallpaper_qml wallpapersmodel.cpp wallpapersqml.cpp backgrounddelegate.cpp viewconfig.ui)
|
|
||||||
target_link_libraries(plasma_wallpaper_qml
|
|
||||||
${QT_QTDECLARATIVE_LIBRARY}
|
|
||||||
KDE4::plasma KDE4::kdecore kdeclarative
|
|
||||||
)
|
|
||||||
|
|
||||||
install(TARGETS plasma_wallpaper_qml DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
|
|
||||||
install(FILES plasma-wallpaper-qml.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR})
|
|
||||||
|
|
||||||
add_subdirectory(wallpapers)
|
|
|
@ -1,2 +0,0 @@
|
||||||
#! /usr/bin/env bash
|
|
||||||
$XGETTEXT *.cpp -o $podir/plasma_wallpaper_wallpaper-qml.pot
|
|
|
@ -1,162 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
|
|
||||||
Copyright (c) 2010 Dario Andres Rodriguez <andresbajotierra@gmail.com>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "backgrounddelegate.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QTextDocument>
|
|
||||||
#include <QtCore/qdatetime.h>
|
|
||||||
|
|
||||||
#include <KDebug>
|
|
||||||
#include <KGlobalSettings>
|
|
||||||
#include <KLocalizedString>
|
|
||||||
|
|
||||||
#include <Plasma/PaintUtils>
|
|
||||||
|
|
||||||
static const int BLUR_PAD = 6;
|
|
||||||
|
|
||||||
BackgroundDelegate::BackgroundDelegate(QObject *parent)
|
|
||||||
: QAbstractItemDelegate(parent)
|
|
||||||
{
|
|
||||||
m_maxHeight = SCREENSHOT_SIZE/1.6 + BLUR_INCREMENT;
|
|
||||||
m_maxWidth = SCREENSHOT_SIZE + BLUR_INCREMENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BackgroundDelegate::paint(QPainter *painter,
|
|
||||||
const QStyleOptionViewItem &option,
|
|
||||||
const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
const QString title = index.model()->data(index, Qt::DisplayRole).toString();
|
|
||||||
const QString author = index.model()->data(index, AuthorRole).toString();
|
|
||||||
const QString resolution = index.model()->data(index, ResolutionRole).toString();
|
|
||||||
const QPixmap pix = index.model()->data(index, ScreenshotRole).value<QPixmap>();
|
|
||||||
|
|
||||||
// Highlight selected item
|
|
||||||
QStyleOptionViewItemV4 opt(option);
|
|
||||||
opt.showDecorationSelected = true;
|
|
||||||
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
|
|
||||||
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
|
|
||||||
|
|
||||||
// Draw wallpaper thumbnail
|
|
||||||
if (pix.isNull()) {
|
|
||||||
painter->fillRect(option.rect, option.palette.brush(QPalette::Base));
|
|
||||||
} else {
|
|
||||||
// blur calculation
|
|
||||||
QImage blur(pix.size() + QSize(BLUR_INCREMENT + BLUR_PAD, BLUR_INCREMENT + BLUR_PAD), QImage::Format_ARGB32);
|
|
||||||
QRect blurRect = QRect(QPoint((blur.width() - pix.width()) / 2, (blur.height() - pix.height()) / 2), pix.size());
|
|
||||||
blur.fill(Qt::transparent);
|
|
||||||
QPainter p(&blur);
|
|
||||||
|
|
||||||
QColor color = option.palette.color(QPalette::Base);
|
|
||||||
bool darkBaseColor = qGray(color.rgb()) < 192;
|
|
||||||
p.fillRect(blurRect, darkBaseColor ? Qt::white : Qt::black);
|
|
||||||
p.end();
|
|
||||||
|
|
||||||
// apply blur with a radius of 2 as thumbnail shadow
|
|
||||||
Plasma::PaintUtils::shadowBlur(blur, 2, darkBaseColor ? Qt::white : Qt::black);
|
|
||||||
|
|
||||||
// calculate point
|
|
||||||
const int bx = (option.rect.width() - blur.width()) / 2;
|
|
||||||
const int by = MARGIN + qMax(0, m_maxHeight - blur.height());
|
|
||||||
QRect shadowRect = QRect(option.rect.topLeft(), blur.size()).translated(bx, by);
|
|
||||||
// draw the blur
|
|
||||||
painter->drawImage(shadowRect.topLeft(), blur);
|
|
||||||
// draw the actual thumbnail
|
|
||||||
painter->drawPixmap(QRect(shadowRect.topLeft() + QPoint((shadowRect.width() - pix.width()) / 2, (shadowRect.height() - pix.height()) / 2),
|
|
||||||
pix.size()), pix);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Use a QTextDocument to layout the text
|
|
||||||
|
|
||||||
// Borrowed from Dolphin for consistency and beauty.
|
|
||||||
// For the color of the additional info the inactive text color
|
|
||||||
// is not used as this might lead to unreadable text for some color schemes. Instead
|
|
||||||
// the text color is slightly mixed with the background color.
|
|
||||||
const QColor textColor = option.palette.text().color();
|
|
||||||
const QColor baseColor = option.palette.base().color();
|
|
||||||
const int p1 = 70;
|
|
||||||
const int p2 = 100 - p1;
|
|
||||||
const QColor detailsColor = QColor((textColor.red() * p1 + baseColor.red() * p2) / 100,
|
|
||||||
(textColor.green() * p1 + baseColor.green() * p2) / 100,
|
|
||||||
(textColor.blue() * p1 + baseColor.blue() * p2) / 100);
|
|
||||||
QTextDocument document;
|
|
||||||
QString html = title;
|
|
||||||
|
|
||||||
if (!resolution.isEmpty()) {
|
|
||||||
html += QString("<br /><span style=\"color: %1;\">%2</span>")
|
|
||||||
.arg(detailsColor.name())
|
|
||||||
.arg(resolution);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!author.isEmpty()) {
|
|
||||||
html += QString("<br /><span style=\"color: %1;\">%2</span>")
|
|
||||||
.arg(detailsColor.name())
|
|
||||||
.arg(author);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set the text color according to the item state
|
|
||||||
QPalette::ColorGroup cg = QPalette::Active;
|
|
||||||
if (!(option.state & QStyle::State_Enabled)) {
|
|
||||||
cg = QPalette::Disabled;
|
|
||||||
} else if (!(option.state & QStyle::State_Active)) {
|
|
||||||
cg = QPalette::Inactive;
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor color;
|
|
||||||
if (option.state & QStyle::State_Selected) {
|
|
||||||
color = QApplication::palette().brush(cg, QPalette::HighlightedText).color();
|
|
||||||
} else {
|
|
||||||
color = QApplication::palette().brush(cg, QPalette::Text).color();
|
|
||||||
}
|
|
||||||
|
|
||||||
html = QString("<div style=\"color: %1\" align=\"center\">%2</div>").arg(color.name()).arg(html);
|
|
||||||
|
|
||||||
document.setHtml(html);
|
|
||||||
|
|
||||||
//Calculate positioning
|
|
||||||
int x = option.rect.left() + MARGIN;
|
|
||||||
|
|
||||||
//Enable word-wrap
|
|
||||||
document.setTextWidth(m_maxWidth);
|
|
||||||
|
|
||||||
//Center text on the row
|
|
||||||
int y = option.rect.top() + m_maxHeight + MARGIN * 2; //qMax(0 ,(int)((option.rect.height() - document.size().height()) / 2));
|
|
||||||
|
|
||||||
//Draw text
|
|
||||||
painter->save();
|
|
||||||
painter->translate(x, y);
|
|
||||||
document.drawContents(painter, QRect(QPoint(0, 0), option.rect.size() - QSize(0, m_maxHeight + MARGIN * 2)));
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize BackgroundDelegate::sizeHint(const QStyleOptionViewItem &option,
|
|
||||||
const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(option)
|
|
||||||
const QString title = index.model()->data(index, Qt::DisplayRole).toString();
|
|
||||||
const QString author = index.model()->data(index, AuthorRole).toString();
|
|
||||||
|
|
||||||
//Generate a sample complete entry (with the real title) to calculate sizes
|
|
||||||
QTextDocument document;
|
|
||||||
QString html = title + "<br />";
|
|
||||||
if (!author.isEmpty()) {
|
|
||||||
html += author + "<br />";
|
|
||||||
}
|
|
||||||
html += QString("1600x1200");
|
|
||||||
|
|
||||||
document.setHtml(html);
|
|
||||||
document.setTextWidth(m_maxWidth);
|
|
||||||
|
|
||||||
QSize s(m_maxWidth + MARGIN * 2,
|
|
||||||
m_maxHeight + MARGIN * 3 + (int)(document.size().height()));
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BACKGROUNDDELEGATE_H
|
|
||||||
#define BACKGROUNDDELEGATE_H
|
|
||||||
|
|
||||||
#include <QAbstractItemDelegate>
|
|
||||||
|
|
||||||
class BackgroundDelegate : public QAbstractItemDelegate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum {
|
|
||||||
AuthorRole = Qt::UserRole,
|
|
||||||
ScreenshotRole,
|
|
||||||
ResolutionRole
|
|
||||||
};
|
|
||||||
|
|
||||||
BackgroundDelegate(QObject *parent = 0);
|
|
||||||
|
|
||||||
virtual void paint(QPainter *painter,
|
|
||||||
const QStyleOptionViewItem &option,
|
|
||||||
const QModelIndex &index) const;
|
|
||||||
virtual QSize sizeHint(const QStyleOptionViewItem &option,
|
|
||||||
const QModelIndex &index) const;
|
|
||||||
|
|
||||||
static const int SCREENSHOT_SIZE = 128;
|
|
||||||
static const int BLUR_INCREMENT = 9;
|
|
||||||
static const int MARGIN = 6;
|
|
||||||
|
|
||||||
void resetMaxHeight() { m_maxHeight = 0; }
|
|
||||||
int m_maxHeight;
|
|
||||||
private:
|
|
||||||
int m_maxWidth;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // BACKGROUNDDELEGATEL_H
|
|
|
@ -1,92 +0,0 @@
|
||||||
[Desktop Entry]
|
|
||||||
Name=Animations
|
|
||||||
Name[bs]=Animacije
|
|
||||||
Name[ca]=Animacions
|
|
||||||
Name[ca@valencia]=Animacions
|
|
||||||
Name[cs]=Animace
|
|
||||||
Name[da]=Animationer
|
|
||||||
Name[de]=Animationen
|
|
||||||
Name[el]=Κινούμενα
|
|
||||||
Name[en_GB]=Animations
|
|
||||||
Name[es]=Animaciones
|
|
||||||
Name[et]=Animatsioonid
|
|
||||||
Name[fi]=Animaatiot
|
|
||||||
Name[fr]=Animations
|
|
||||||
Name[gl]=Animacións
|
|
||||||
Name[hu]=Animációk
|
|
||||||
Name[it]=Animazioni
|
|
||||||
Name[kk]=Анимациялар
|
|
||||||
Name[ko]=애니메이션
|
|
||||||
Name[nb]=Animasjoner
|
|
||||||
Name[nds]=Animatschonen
|
|
||||||
Name[nl]=Animaties
|
|
||||||
Name[pl]=Animacje
|
|
||||||
Name[pt]=Animações
|
|
||||||
Name[pt_BR]=Animações
|
|
||||||
Name[ro]=Animații
|
|
||||||
Name[ru]=Анимации
|
|
||||||
Name[sk]=Animácie
|
|
||||||
Name[sl]=Animacije
|
|
||||||
Name[sr]=анимације
|
|
||||||
Name[sr@ijekavian]=анимације
|
|
||||||
Name[sr@ijekavianlatin]=animacije
|
|
||||||
Name[sr@latin]=animacije
|
|
||||||
Name[sv]=Animeringar
|
|
||||||
Name[tr]=Animasyonlar
|
|
||||||
Name[ug]=جانلاندۇرۇملار
|
|
||||||
Name[uk]=Анімації
|
|
||||||
Name[x-test]=xxAnimationsxx
|
|
||||||
Name[zh_CN]=动画
|
|
||||||
Name[zh_TW]=動畫
|
|
||||||
Comment=Interactive, animated wallpapers
|
|
||||||
Comment[ar]=خلفيات متحركة غير فعالة
|
|
||||||
Comment[bs]=Interaktivne, animirane pozadinske slike
|
|
||||||
Comment[ca]=Fons d'escriptori interactius, animats
|
|
||||||
Comment[ca@valencia]=Fons d'escriptori interactius, animats
|
|
||||||
Comment[cs]=Interaktivní animované tapety
|
|
||||||
Comment[da]=Interaktive, animerede baggrundsbilleder
|
|
||||||
Comment[de]=Interaktive, animierte Hintergrundbilder
|
|
||||||
Comment[el]=Διαδραστικές, κινούμενες ταπετσαρίες
|
|
||||||
Comment[en_GB]=Interactive, animated wallpapers
|
|
||||||
Comment[es]=Fondos de pantalla interactivos animados
|
|
||||||
Comment[et]=Interaktiivsed animeeritud taustapildid
|
|
||||||
Comment[fi]=Vuorovaikutteiset, animoidut taustat
|
|
||||||
Comment[fr]=Fonds d'écran interactifs et animés
|
|
||||||
Comment[gl]=Fondos de escritorio animados e interactivos.
|
|
||||||
Comment[hu]=Interaktív, animált háttérképek
|
|
||||||
Comment[it]=Sfondi animati, interattivi
|
|
||||||
Comment[kk]=Интерактивті, анимацияланған тұсқағаздар
|
|
||||||
Comment[ko]=인터랙티브 애니메이션 배경 그림
|
|
||||||
Comment[nb]=Interaktive, animerte tapeter
|
|
||||||
Comment[nds]=Brukerstüert, animeert Achtergrundbiller
|
|
||||||
Comment[nl]=Interactieve geanimeerde bureaubladachtergronden
|
|
||||||
Comment[pl]=Interaktywne, animowane tapety
|
|
||||||
Comment[pt]=Papéis de parede animados e interactivos
|
|
||||||
Comment[pt_BR]=Papéis de parede animados e interativos
|
|
||||||
Comment[ro]=Fundaluri animate, interactive
|
|
||||||
Comment[ru]=Интерактивные анимированные фоны
|
|
||||||
Comment[sk]=Interaktívne, animované tapety
|
|
||||||
Comment[sl]=Interaktivne, animirane slike ozadja
|
|
||||||
Comment[sr]=Интерактивни анимирани тапети
|
|
||||||
Comment[sr@ijekavian]=Интерактивни анимирани тапети
|
|
||||||
Comment[sr@ijekavianlatin]=Interaktivni animirani tapeti
|
|
||||||
Comment[sr@latin]=Interaktivni animirani tapeti
|
|
||||||
Comment[sv]=Interaktiva, animerade skrivbordsunderlägg
|
|
||||||
Comment[tr]=Etkileşimli, hareketli Duvar Kağıtları
|
|
||||||
Comment[uk]=Інтерактивні анімовані шпалери
|
|
||||||
Comment[x-test]=xxInteractive, animated wallpapersxx
|
|
||||||
Comment[zh_CN]=交互,动画壁纸
|
|
||||||
Comment[zh_TW]=互動式動畫桌布
|
|
||||||
Type=Service
|
|
||||||
Icon=preferences-desktop-wallpaper
|
|
||||||
ServiceTypes=Plasma/Wallpaper
|
|
||||||
|
|
||||||
X-KDE-Library=plasma_wallpaper_qml
|
|
||||||
X-KDE-PluginInfo-Author=Aleix Pol Gonzalez
|
|
||||||
X-KDE-PluginInfo-Email=aleixpol@kde.org
|
|
||||||
X-KDE-PluginInfo-Name=org.kde.wallpaper-qml
|
|
||||||
X-KDE-PluginInfo-Version=0.1
|
|
||||||
X-KDE-PluginInfo-Website=
|
|
||||||
X-KDE-PluginInfo-License=GPL
|
|
||||||
X-KDE-PluginInfo-EnabledByDefault=true
|
|
||||||
|
|
|
@ -1,115 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>ViewConfig</class>
|
|
||||||
<widget class="QWidget" name="ViewConfig">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>568</width>
|
|
||||||
<height>379</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="m_colorLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Color:</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>m_color</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="KColorButton" name="m_color">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Change wallpaper frame color</string>
|
|
||||||
</property>
|
|
||||||
<property name="whatsThis">
|
|
||||||
<string>Change the color of the frame that it may be visible when the wallpaper is centered or scaled with the same proportions.</string>
|
|
||||||
</property>
|
|
||||||
<property name="color">
|
|
||||||
<color>
|
|
||||||
<red>70</red>
|
|
||||||
<green>90</green>
|
|
||||||
<blue>130</blue>
|
|
||||||
</color>
|
|
||||||
</property>
|
|
||||||
<property name="defaultColor">
|
|
||||||
<color>
|
|
||||||
<red>70</red>
|
|
||||||
<green>90</green>
|
|
||||||
<blue>130</blue>
|
|
||||||
</color>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0" colspan="2">
|
|
||||||
<widget class="QListView" name="m_view">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>300</width>
|
|
||||||
<height>220</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="movement">
|
|
||||||
<enum>QListView::Static</enum>
|
|
||||||
</property>
|
|
||||||
<property name="resizeMode">
|
|
||||||
<enum>QListView::Adjust</enum>
|
|
||||||
</property>
|
|
||||||
<property name="layoutMode">
|
|
||||||
<enum>QListView::Batched</enum>
|
|
||||||
</property>
|
|
||||||
<property name="spacing">
|
|
||||||
<number>2</number>
|
|
||||||
</property>
|
|
||||||
<property name="viewMode">
|
|
||||||
<enum>QListView::IconMode</enum>
|
|
||||||
</property>
|
|
||||||
<property name="uniformItemSizes">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>KColorButton</class>
|
|
||||||
<extends>QPushButton</extends>
|
|
||||||
<header>kcolorbutton.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -1 +0,0 @@
|
||||||
install(DIRECTORY hunyango/ DESTINATION ${KDE4_DATA_INSTALL_DIR}/plasma/wallpapers/org.kde.hunyango)
|
|
|
@ -1,55 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012 Marco Martin <mart@kde.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2 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 Library General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import QtQuick 1.1
|
|
||||||
import org.kde.plasma.core 0.1 as PlasmaCore
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
id: root
|
|
||||||
width: 800
|
|
||||||
height: 480
|
|
||||||
|
|
||||||
function randomColor() {
|
|
||||||
root.color = Qt.hsva(Math.random(), 1,0.5,1)
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: randomColor()
|
|
||||||
MouseArea {
|
|
||||||
anchors.fill: parent
|
|
||||||
onClicked: randomColor()
|
|
||||||
}
|
|
||||||
|
|
||||||
PlasmaCore.SvgItem {
|
|
||||||
anchors.fill: parent
|
|
||||||
smooth: true
|
|
||||||
svg: PlasmaCore.Svg {
|
|
||||||
id: wallpaperSvg
|
|
||||||
//FIXME: Svg doesn't support relative paths
|
|
||||||
imagePath: Qt.resolvedUrl("wallpaper.svgz").substring(7)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
|
||||||
running: true
|
|
||||||
repeat: true
|
|
||||||
interval: 30000
|
|
||||||
onTriggered: randomColor()
|
|
||||||
}
|
|
||||||
Behavior on color { ColorAnimation { duration: 1000; easing.type: Easing.InQuad } }
|
|
||||||
}
|
|
Binary file not shown.
|
@ -1,55 +0,0 @@
|
||||||
[Desktop Entry]
|
|
||||||
Encoding=UTF-8
|
|
||||||
Name=Hunyango
|
|
||||||
Name[bs]=Hunjango
|
|
||||||
Name[ca]=Hunyango
|
|
||||||
Name[ca@valencia]=Hunyango
|
|
||||||
Name[cs]=Hunyango
|
|
||||||
Name[da]=Hunyango
|
|
||||||
Name[de]=Hunyango
|
|
||||||
Name[el]=Hunyango
|
|
||||||
Name[en_GB]=Hunyango
|
|
||||||
Name[es]=Hunyango
|
|
||||||
Name[et]=Hunyango
|
|
||||||
Name[fi]=Hunyango
|
|
||||||
Name[fr]=Hunyango
|
|
||||||
Name[gl]=Hunyango
|
|
||||||
Name[hu]=Hunyango
|
|
||||||
Name[it]=Hunyango
|
|
||||||
Name[kk]=Хаянго
|
|
||||||
Name[ko]=Hunyango
|
|
||||||
Name[mr]=हुन्यान्गो
|
|
||||||
Name[nb]=Hunyango
|
|
||||||
Name[nds]=Hunyango
|
|
||||||
Name[nl]=Hunyango
|
|
||||||
Name[pl]=Hunyango
|
|
||||||
Name[pt]=Hunyango
|
|
||||||
Name[pt_BR]=Hunyango
|
|
||||||
Name[ro]=Hunyango
|
|
||||||
Name[ru]=Hunyango
|
|
||||||
Name[sk]=Hunyango
|
|
||||||
Name[sl]=Hunyango
|
|
||||||
Name[sr]=Хунјанго
|
|
||||||
Name[sr@ijekavian]=Хунјанго
|
|
||||||
Name[sr@ijekavianlatin]=Hunjango
|
|
||||||
Name[sr@latin]=Hunjango
|
|
||||||
Name[sv]=Hunyango
|
|
||||||
Name[tr]=Hunyango
|
|
||||||
Name[uk]=Уньянго
|
|
||||||
Name[wa]=Hunyango
|
|
||||||
Name[x-test]=xxHunyangoxx
|
|
||||||
Name[zh_CN]=变色龙
|
|
||||||
Name[zh_TW]=Hunyango
|
|
||||||
|
|
||||||
|
|
||||||
Type=Service
|
|
||||||
ServiceTypes=Plasma/DeclarativeWallpaper
|
|
||||||
Icon=preferences-desktop-wallpaper
|
|
||||||
X-Plasma-MainScript=ui/main.qml
|
|
||||||
X-KDE-PluginInfo-Author=Marco Martin
|
|
||||||
X-KDE-PluginInfo-Email=mart@kde.org
|
|
||||||
X-KDE-PluginInfo-Name=org.kde.hunyango
|
|
||||||
X-KDE-PluginInfo-Version=1.0
|
|
||||||
X-KDE-PluginInfo-Website=
|
|
||||||
X-KDE-PluginInfo-License=LGPL
|
|
||||||
X-KDE-PluginInfo-EnabledByDefault=true
|
|
|
@ -1,145 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012 by Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, 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 Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "wallpapersmodel.h"
|
|
||||||
#include <QtDeclarative/QDeclarativeEngine>
|
|
||||||
#include <QtDeclarative/qdeclarativeitem.h>
|
|
||||||
#include <QtGui/qpixmap.h>
|
|
||||||
#include <QtGui/QPainter>
|
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <KIcon>
|
|
||||||
#include <KStandardDirs>
|
|
||||||
#include <plasma/package.h>
|
|
||||||
#include <qdir.h>
|
|
||||||
#include <kdeclarative.h>
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Plasma::Package*);
|
|
||||||
|
|
||||||
WallpapersModel::WallpapersModel(QObject* parent)
|
|
||||||
: QAbstractListModel(parent)
|
|
||||||
{
|
|
||||||
m_scene = new QGraphicsScene(this);
|
|
||||||
m_engine = new QDeclarativeEngine(this);
|
|
||||||
KDeclarative kdeclarative;
|
|
||||||
kdeclarative.setDeclarativeEngine(m_engine);
|
|
||||||
kdeclarative.initialize();
|
|
||||||
kdeclarative.setupBindings();
|
|
||||||
}
|
|
||||||
|
|
||||||
WallpapersModel::~WallpapersModel()
|
|
||||||
{
|
|
||||||
clearCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpapersModel::clearCache()
|
|
||||||
{
|
|
||||||
qDeleteAll(m_packagesItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpapersModel::addPackage(const QString& packageRoot, const QString& packageName)
|
|
||||||
{
|
|
||||||
beginInsertRows(QModelIndex(), m_packages.count(), m_packages.count());
|
|
||||||
Plasma::PackageStructure::Ptr str = Plasma::PackageStructure::load("Plasma/Generic");
|
|
||||||
Plasma::Package* p = new Plasma::Package(packageRoot, packageName, str);
|
|
||||||
|
|
||||||
if (p->isValid() && p->metadata().serviceType()=="Plasma/DeclarativeWallpaper") {
|
|
||||||
m_packages += p;
|
|
||||||
QDeclarativeComponent* component = new QDeclarativeComponent(m_engine);
|
|
||||||
component->loadUrl(QUrl(p->filePath("mainscript")));
|
|
||||||
if (component->isReady()) {
|
|
||||||
QDeclarativeItem* item = qobject_cast<QDeclarativeItem *>(component->create());
|
|
||||||
Q_ASSERT(item);
|
|
||||||
m_packagesItems[p] = item;
|
|
||||||
item->setWidth(m_scene->width());
|
|
||||||
item->setHeight(m_scene->height());
|
|
||||||
item->setVisible(false);
|
|
||||||
m_scene->addItem(item);
|
|
||||||
}
|
|
||||||
delete component;
|
|
||||||
} else {
|
|
||||||
delete p;
|
|
||||||
}
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant WallpapersModel::data(const QModelIndex& index, int role) const
|
|
||||||
{
|
|
||||||
Plasma::Package* p = m_packages[index.row()];
|
|
||||||
switch (role) {
|
|
||||||
case PackageNameRole:
|
|
||||||
return p->metadata().pluginName();
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
return p->metadata().name();
|
|
||||||
case Qt::ToolTipRole:
|
|
||||||
return p->metadata().description();
|
|
||||||
case Qt::DecorationRole:
|
|
||||||
return KIcon(p->metadata().icon());
|
|
||||||
case BackgroundDelegate::AuthorRole:
|
|
||||||
return p->metadata().author();
|
|
||||||
case BackgroundDelegate::ScreenshotRole:
|
|
||||||
QDeclarativeItem* it = m_packagesItems.value(p);
|
|
||||||
if(it) {
|
|
||||||
QPixmap pix(m_scene->sceneRect().size().toSize());
|
|
||||||
pix.fill(Qt::transparent);
|
|
||||||
QPainter painter(&pix);
|
|
||||||
it->setVisible(true);
|
|
||||||
m_scene->render(&painter, QRectF(), QRectF(), Qt::KeepAspectRatio);
|
|
||||||
it->setVisible(false);
|
|
||||||
return pix;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
int WallpapersModel::rowCount(const QModelIndex& parent) const
|
|
||||||
{
|
|
||||||
return parent.isValid()? 0 : m_packages.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex WallpapersModel::indexForPackagePath(const QString& path)
|
|
||||||
{
|
|
||||||
for (int i = 0; i<rowCount(); i++) {
|
|
||||||
if (m_packages[i]->path()==path) {
|
|
||||||
return index(i,0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpapersModel::setWallpaperSize(const QSize& size)
|
|
||||||
{
|
|
||||||
float newHeight = ((float)size.height() / (float)size.width()) * BackgroundDelegate::SCREENSHOT_SIZE;
|
|
||||||
|
|
||||||
m_size = QSize(BackgroundDelegate::SCREENSHOT_SIZE, newHeight);
|
|
||||||
|
|
||||||
m_size.scale(BackgroundDelegate::SCREENSHOT_SIZE, BackgroundDelegate::SCREENSHOT_SIZE/1.6, Qt::KeepAspectRatio);
|
|
||||||
|
|
||||||
reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpapersModel::reload(){
|
|
||||||
m_scene->setSceneRect(0,0, m_size.width(), m_size.height());
|
|
||||||
QStringList dirs(KGlobal::dirs()->findDirs("data", "plasma/wallpapers"));
|
|
||||||
foreach (const QString &dir, dirs) {
|
|
||||||
foreach (const QString &package, Plasma::Package::listInstalled(dir)) {
|
|
||||||
addPackage(dir, package);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012 by Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, 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 Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef WALLPAPERSMODEL_H
|
|
||||||
#define WALLPAPERSMODEL_H
|
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
|
||||||
#include <QDeclarativeComponent>
|
|
||||||
#include <QDeclarativeItem>
|
|
||||||
#include <plasma/packagestructure.h>
|
|
||||||
#include "backgrounddelegate.h"
|
|
||||||
|
|
||||||
namespace Plasma { class Package; }
|
|
||||||
|
|
||||||
class WallpapersModel : public QAbstractListModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
enum Roles {
|
|
||||||
PackageNameRole = BackgroundDelegate::ResolutionRole+1
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit WallpapersModel(QObject* parent = 0);
|
|
||||||
~WallpapersModel();
|
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
|
||||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
|
||||||
QModelIndex indexForPackagePath(const QString& path);
|
|
||||||
void clearCache();
|
|
||||||
void reload();
|
|
||||||
void setWallpaperSize(const QSize& size);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void addPackage(const QString& root, const QString& name);
|
|
||||||
|
|
||||||
QList<Plasma::Package*> m_packages;
|
|
||||||
QMap<Plasma::Package*, QDeclarativeItem*> m_packagesItems;
|
|
||||||
QDeclarativeEngine* m_engine;
|
|
||||||
QGraphicsScene* m_scene;
|
|
||||||
QSize m_size;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // WALLPAPERSMODEL_H
|
|
|
@ -1,217 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012 by Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, 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 Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "wallpapersqml.h"
|
|
||||||
#include "wallpapersmodel.h"
|
|
||||||
#include "backgrounddelegate.h"
|
|
||||||
#include <plasma/package.h>
|
|
||||||
#include <KStandardDirs>
|
|
||||||
#include <KDebug>
|
|
||||||
#include <kdeclarative.h>
|
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <QDeclarativeEngine>
|
|
||||||
#include <QDeclarativeItem>
|
|
||||||
#include <QDeclarativeComponent>
|
|
||||||
#include <QtGui/qgraphicssceneevent.h>
|
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QListView>
|
|
||||||
#include <QDir>
|
|
||||||
#include "ui_viewconfig.h"
|
|
||||||
|
|
||||||
K_EXPORT_PLASMA_WALLPAPER(org.kde.wallpaper-qml, WallpaperQml)
|
|
||||||
|
|
||||||
WallpaperQml::WallpaperQml(QObject *parent, const QVariantList &args)
|
|
||||||
: Plasma::Wallpaper(parent, args)
|
|
||||||
, m_scene(new QGraphicsScene(this))
|
|
||||||
, m_item(0)
|
|
||||||
, m_package(0)
|
|
||||||
{
|
|
||||||
m_engine = new QDeclarativeEngine(this);
|
|
||||||
KDeclarative kdeclarative;
|
|
||||||
kdeclarative.setDeclarativeEngine(m_engine);
|
|
||||||
kdeclarative.initialize();
|
|
||||||
kdeclarative.setupBindings();
|
|
||||||
|
|
||||||
m_component = new QDeclarativeComponent(m_engine);
|
|
||||||
connect(
|
|
||||||
m_component, SIGNAL(statusChanged(QDeclarativeComponent::ComponentStatus)),
|
|
||||||
this, SLOT(componentStatusChanged(QDeclarativeComponent::ComponentStatus))
|
|
||||||
);
|
|
||||||
connect(this, SIGNAL(renderHintsChanged()), SLOT(resizeWallpaper()));
|
|
||||||
connect(m_scene, SIGNAL(changed(QList<QRectF>)), SLOT(shouldRepaint(QList<QRectF>)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::setPackageName(const QString& packageName)
|
|
||||||
{
|
|
||||||
delete m_package;
|
|
||||||
|
|
||||||
kDebug() << "loading package..." << packageName;
|
|
||||||
m_structure = Plasma::PackageStructure::load("Plasma/Generic");
|
|
||||||
QStringList dirs(KGlobal::dirs()->findDirs("data", "plasma/wallpapers"));
|
|
||||||
foreach (const QString &dir, dirs) {
|
|
||||||
m_package = new Plasma::Package(dir, packageName, m_structure);
|
|
||||||
if (m_package->isValid() && !m_package->filePath("mainscript").isEmpty()) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
delete m_package;
|
|
||||||
m_package = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(m_package) {
|
|
||||||
QUrl scriptUrl(m_package->filePath("mainscript"));
|
|
||||||
if (scriptUrl.isValid()) {
|
|
||||||
m_component->loadUrl(scriptUrl);
|
|
||||||
m_packageName = packageName;
|
|
||||||
} else {
|
|
||||||
m_component->setData("import QtQuick 1.1\n Text { text: 'wrong wallpaper'}", QDir::tempPath());
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
kWarning() << "couldn't load the package named" << packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::componentStatusChanged(QDeclarativeComponent::ComponentStatus s)
|
|
||||||
{
|
|
||||||
if (s==QDeclarativeComponent::Ready) {
|
|
||||||
if (m_item) {
|
|
||||||
m_scene->removeItem(m_item);
|
|
||||||
delete m_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_item = qobject_cast<QDeclarativeItem *>(m_component->create());
|
|
||||||
m_item->setSize(targetSizeHint());
|
|
||||||
Q_ASSERT(m_item);
|
|
||||||
m_scene->addItem(m_item);
|
|
||||||
|
|
||||||
resizeWallpaper();
|
|
||||||
} else if (s==QDeclarativeComponent::Error) {
|
|
||||||
delete m_component;
|
|
||||||
m_component = new QDeclarativeComponent(m_engine);
|
|
||||||
connect(
|
|
||||||
m_component, SIGNAL(statusChanged(QDeclarativeComponent::ComponentStatus)),
|
|
||||||
this, SLOT(componentStatusChanged(QDeclarativeComponent::ComponentStatus))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!m_component->errors().isEmpty())
|
|
||||||
kDebug() << "wallpaper errors:" << m_component->errors();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::paint(QPainter *painter, const QRectF& exposedRect)
|
|
||||||
{
|
|
||||||
painter->drawPixmap(exposedRect, m_pixmap, exposedRect.translated(-boundingRect().topLeft()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::resizeWallpaper()
|
|
||||||
{
|
|
||||||
m_scene->setSceneRect(QRectF(QPointF(0,0), targetSizeHint()));
|
|
||||||
if (m_item) {
|
|
||||||
m_item->setSize(targetSizeHint());
|
|
||||||
}
|
|
||||||
m_pixmap = QPixmap(targetSizeHint().toSize());
|
|
||||||
m_pixmap.fill(m_scene->backgroundBrush().color());
|
|
||||||
QPainter p(&m_pixmap);
|
|
||||||
m_scene->render(&p, QRectF(), QRectF(), Qt::IgnoreAspectRatio);
|
|
||||||
p.end();
|
|
||||||
emit update(QRectF());
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::shouldRepaint(const QList<QRectF> &rects)
|
|
||||||
{
|
|
||||||
QRectF repaintRect(0,0,0,0);
|
|
||||||
foreach (const QRectF& rect, rects) {
|
|
||||||
repaintRect = repaintRect.united(rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!repaintRect.isEmpty()) {
|
|
||||||
QPainter p(&m_pixmap);
|
|
||||||
m_scene->render(&p, repaintRect, repaintRect, Qt::IgnoreAspectRatio);
|
|
||||||
p.end();
|
|
||||||
emit update(repaintRect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget* WallpaperQml::createConfigurationInterface(QWidget* parent)
|
|
||||||
{
|
|
||||||
QWidget* w = new QWidget;
|
|
||||||
Ui::ViewConfig v;
|
|
||||||
v.setupUi(w);
|
|
||||||
|
|
||||||
WallpapersModel* m = new WallpapersModel(w);
|
|
||||||
m->setWallpaperSize(targetSizeHint().toSize());
|
|
||||||
|
|
||||||
v.m_view->setModel(m);
|
|
||||||
v.m_view->setItemDelegate(new BackgroundDelegate(v.m_view));
|
|
||||||
if (m_package) {
|
|
||||||
v.m_view->setCurrentIndex(m->indexForPackagePath(m_package->path()));
|
|
||||||
m_packageName = m_package->metadata().pluginName();
|
|
||||||
}
|
|
||||||
v.m_color->setColor(m_scene->backgroundBrush().color());
|
|
||||||
|
|
||||||
connect(v.m_view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(changeWallpaper(QModelIndex)));
|
|
||||||
connect(v.m_color, SIGNAL(changed(QColor)), this, SLOT(setBackgroundColor(QColor)));
|
|
||||||
connect(this, SIGNAL(changed(bool)), parent, SLOT(settingsChanged(bool)));
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::changeWallpaper(const QModelIndex& idx)
|
|
||||||
{
|
|
||||||
m_packageName = idx.data(WallpapersModel::PackageNameRole).toString();
|
|
||||||
emit changed(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::init(const KConfigGroup& config)
|
|
||||||
{
|
|
||||||
setPackageName(config.readEntry("packageName", "org.kde.hunyango"));
|
|
||||||
setBackgroundColor(config.readEntry("color", QColor(Qt::transparent)));
|
|
||||||
emit changed(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::save(KConfigGroup& config)
|
|
||||||
{
|
|
||||||
config.writeEntry("packageName", m_packageName);
|
|
||||||
config.writeEntry("color", m_scene->backgroundBrush().color());
|
|
||||||
config.sync();
|
|
||||||
emit changed(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::setBackgroundColor(const QColor& color)
|
|
||||||
{
|
|
||||||
m_scene->setBackgroundBrush(color);
|
|
||||||
emit changed(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
|
|
||||||
{
|
|
||||||
QApplication::sendEvent(m_scene, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
|
||||||
{
|
|
||||||
QApplication::sendEvent(m_scene, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
|
|
||||||
{
|
|
||||||
QApplication::sendEvent(m_scene, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperQml::wheelEvent(QGraphicsSceneWheelEvent* event)
|
|
||||||
{
|
|
||||||
QApplication::sendEvent(m_scene, event);
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012 by Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, 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 Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef WALLPAPERQML_H
|
|
||||||
#define WALLPAPERQML_H
|
|
||||||
|
|
||||||
#include <plasma/wallpaper.h>
|
|
||||||
#include <QtDeclarative/QDeclarativeComponent>
|
|
||||||
|
|
||||||
#include <QModelIndex>
|
|
||||||
#include <QDeclarativeItem>
|
|
||||||
|
|
||||||
class WallpaperQml : public Plasma::Wallpaper
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
WallpaperQml(QObject* parent, const QVariantList& args);
|
|
||||||
|
|
||||||
virtual void paint(QPainter* painter, const QRectF& exposedRect);
|
|
||||||
virtual QWidget* createConfigurationInterface(QWidget* parent);
|
|
||||||
virtual void save(KConfigGroup& config);
|
|
||||||
virtual void init(const KConfigGroup& config);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void resizeWallpaper();
|
|
||||||
void shouldRepaint(const QList< QRectF >& rects);
|
|
||||||
void componentStatusChanged(QDeclarativeComponent::ComponentStatus s);
|
|
||||||
void setPackageName(const QString& name);
|
|
||||||
void changeWallpaper(const QModelIndex& idx);
|
|
||||||
void setBackgroundColor(const QColor& color);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void changed(bool hasChanged=true);
|
|
||||||
|
|
||||||
private:
|
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
|
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
|
|
||||||
virtual void wheelEvent(QGraphicsSceneWheelEvent* event);
|
|
||||||
|
|
||||||
QGraphicsScene* m_scene;
|
|
||||||
QDeclarativeItem* m_item;
|
|
||||||
QDeclarativeComponent* m_component;
|
|
||||||
Plasma::Package* m_package;
|
|
||||||
Plasma::PackageStructure::Ptr m_structure;
|
|
||||||
QPixmap m_pixmap;
|
|
||||||
QDeclarativeEngine* m_engine;
|
|
||||||
QString m_packageName;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -8,4 +8,3 @@ Terminal=false
|
||||||
Type=Application
|
Type=Application
|
||||||
Categories=Qt;KDE;System;
|
Categories=Qt;KDE;System;
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
X-KDE-HasTrayOption=true
|
|
||||||
|
|
|
@ -1,235 +0,0 @@
|
||||||
project(kget)
|
|
||||||
|
|
||||||
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
|
||||||
include(FeatureSummary)
|
|
||||||
|
|
||||||
find_package(KDELibs4 4.23.0 REQUIRED)
|
|
||||||
|
|
||||||
include_directories(${KDE4_INCLUDES})
|
|
||||||
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include(CheckIncludeFile)
|
|
||||||
include(CheckIncludeFiles)
|
|
||||||
include(CheckSymbolExists)
|
|
||||||
include(CheckFunctionExists)
|
|
||||||
include(CheckLibraryExists)
|
|
||||||
include(CheckTypeSize)
|
|
||||||
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
|
|
||||||
|
|
||||||
kde4_optional_find_package(LibTorrent)
|
|
||||||
set_package_properties(LibTorrent PROPERTIES
|
|
||||||
DESCRIPTION "Feature complete C++ bittorrent implementation focusing on efficiency and scalability"
|
|
||||||
URL "https://libtorrent.org/"
|
|
||||||
PURPOSE "Needed to build KGet torrent support"
|
|
||||||
)
|
|
||||||
|
|
||||||
kde4_optional_find_package(KDE4Workspace)
|
|
||||||
set_package_properties(KDE4Workspace PROPERTIES
|
|
||||||
DESCRIPTION "KDE base workspace libraries"
|
|
||||||
URL "https://osdn.net/projects/kde/"
|
|
||||||
PURPOSE "Allows 'shutdown after downloads completed' in KGet"
|
|
||||||
)
|
|
||||||
|
|
||||||
set(kget_adaptor_SRCS
|
|
||||||
dbus/dbuskgetwrapper.cpp
|
|
||||||
)
|
|
||||||
# set(kget_transfer_adaptor_SRCS
|
|
||||||
# core/transferhandler.cpp
|
|
||||||
# core/transfertreemodel.cpp
|
|
||||||
# )
|
|
||||||
|
|
||||||
add_definitions(-DKDE_DEFAULT_DEBUG_AREA=5001)
|
|
||||||
|
|
||||||
# TODO: utterly broken
|
|
||||||
set(KGET_TESTING FALSE)
|
|
||||||
|
|
||||||
set(SUPPORTED_KGET_MIMETYPES "application/x-kgetlist;")
|
|
||||||
|
|
||||||
if(KGET_TESTING)
|
|
||||||
add_definitions(-DDO_KGET_TEST)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory(core)
|
|
||||||
add_subdirectory(ui)
|
|
||||||
add_subdirectory(transfer-plugins)
|
|
||||||
add_subdirectory(extensions)
|
|
||||||
add_subdirectory(desktop)
|
|
||||||
add_subdirectory(plasma)
|
|
||||||
if(KGET_TESTING)
|
|
||||||
add_subdirectory(tests)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(KDE4WORKSPACE_FOUND)
|
|
||||||
add_definitions(-DHAVE_KWORKSPACE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include_directories(
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/core/
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/core/
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
# kgetcore
|
|
||||||
|
|
||||||
set(kgetcore_SRCS
|
|
||||||
core/job.cpp
|
|
||||||
core/jobqueue.cpp
|
|
||||||
core/kget.cpp
|
|
||||||
core/scheduler.cpp
|
|
||||||
core/transfertreemodel.cpp
|
|
||||||
core/transfertreeselectionmodel.cpp
|
|
||||||
core/transfer.cpp
|
|
||||||
core/transfergroup.cpp
|
|
||||||
core/transfergrouphandler.cpp
|
|
||||||
core/transferhandler.cpp
|
|
||||||
core/handler.cpp
|
|
||||||
core/transfergroupscheduler.cpp
|
|
||||||
core/plugin/plugin.cpp
|
|
||||||
core/plugin/transferfactory.cpp
|
|
||||||
core/transferdatasource.cpp
|
|
||||||
core/kgetkjobadapter.cpp
|
|
||||||
core/kuiserverjobs.cpp
|
|
||||||
core/kgetglobaljob.cpp
|
|
||||||
core/download.cpp
|
|
||||||
core/transferhistorystore.cpp
|
|
||||||
core/transferhistorystore_xml.cpp
|
|
||||||
core/transferhistorystore_json.cpp
|
|
||||||
core/linkimporter.cpp
|
|
||||||
dbus/dbustransferwrapper.cpp
|
|
||||||
dbus/dbusverifierwrapper.cpp
|
|
||||||
core/filemodel.cpp
|
|
||||||
core/verifier.cpp
|
|
||||||
core/verificationthread.cpp
|
|
||||||
core/verificationmodel.cpp
|
|
||||||
core/verificationdelegate.cpp
|
|
||||||
core/urlchecker.cpp
|
|
||||||
core/basedialog.cpp
|
|
||||||
core/mostlocalurl.cpp
|
|
||||||
core/filedeleter.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
kde4_add_kcfg_files(kgetcore_SRCS conf/settings.kcfgc)
|
|
||||||
|
|
||||||
qt4_add_dbus_adaptor(kgetcore_SRCS dbus/org.kde.kget.transfer.xml dbus/dbustransferwrapper.h DBusTransferWrapper)
|
|
||||||
qt4_add_dbus_adaptor(kgetcore_SRCS dbus/org.kde.kget.verifier.xml dbus/dbusverifierwrapper.h DBusVerifierWrapper)
|
|
||||||
|
|
||||||
add_library(kgetcore SHARED ${kgetcore_SRCS})
|
|
||||||
|
|
||||||
target_link_libraries(kgetcore
|
|
||||||
KDE4::kio
|
|
||||||
KDE4::knetworkmanager
|
|
||||||
KDE4::solid
|
|
||||||
)
|
|
||||||
|
|
||||||
if (KDE4WORKSPACE_FOUND)
|
|
||||||
target_link_libraries(kgetcore KDE4Workspace::kworkspace)
|
|
||||||
endif (KDE4WORKSPACE_FOUND)
|
|
||||||
|
|
||||||
set_target_properties(kgetcore PROPERTIES
|
|
||||||
VERSION ${GENERIC_LIB_VERSION}
|
|
||||||
SOVERSION ${GENERIC_LIB_SOVERSION}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
TARGETS kgetcore
|
|
||||||
DESTINATION ${KDE4_LIB_INSTALL_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
# kget
|
|
||||||
|
|
||||||
set(kget_SRCS ${kget_adaptor_SRCS} ${kget_transfer_adaptor_SRCS}
|
|
||||||
conf/autopastemodel.cpp
|
|
||||||
conf/integrationpreferences.cpp
|
|
||||||
conf/dlgwebinterface.cpp
|
|
||||||
conf/preferencesdialog.cpp
|
|
||||||
conf/transfersgrouptree.cpp
|
|
||||||
conf/transfersgroupwidget.cpp
|
|
||||||
conf/pluginselector.cpp
|
|
||||||
conf/verificationpreferences.cpp
|
|
||||||
ui/droptarget.cpp
|
|
||||||
ui/transfersview.cpp
|
|
||||||
ui/transfersviewdelegate.cpp
|
|
||||||
ui/transferdetails.cpp
|
|
||||||
ui/viewscontainer.cpp
|
|
||||||
ui/newtransferdialog.cpp
|
|
||||||
ui/groupsettingsdialog.cpp
|
|
||||||
ui/transfersettingsdialog.cpp
|
|
||||||
ui/contextmenu.cpp
|
|
||||||
ui/tray.cpp
|
|
||||||
ui/history/rangetreewidget.cpp
|
|
||||||
ui/history/transferhistory.cpp
|
|
||||||
ui/history/transferhistoryitemdelegate.cpp
|
|
||||||
ui/history/transferhistorycategorizeddelegate.cpp
|
|
||||||
ui/history/transferhistorycategorizedview.cpp
|
|
||||||
ui/linkview/kget_linkview.cpp
|
|
||||||
ui/linkview/kget_sortfilterproxymodel.cpp
|
|
||||||
ui/mirror/mirrorsettings.cpp
|
|
||||||
ui/mirror/mirrormodel.cpp
|
|
||||||
ui/renamefile.cpp
|
|
||||||
ui/verificationdialog.cpp
|
|
||||||
mainwindow.cpp
|
|
||||||
main.cpp
|
|
||||||
|
|
||||||
extensions/webinterface/httpserver.cpp
|
|
||||||
|
|
||||||
conf/dlgadvanced.ui
|
|
||||||
conf/dlgappearance.ui
|
|
||||||
conf/dlggroups.ui
|
|
||||||
conf/dlgintegration.ui
|
|
||||||
conf/dlgwebinterface.ui
|
|
||||||
conf/dlgnetwork.ui
|
|
||||||
conf/verificationpreferences.ui
|
|
||||||
ui/transferdetailsfrm.ui
|
|
||||||
ui/newtransferwidget.ui
|
|
||||||
ui/history/transferhistory.ui
|
|
||||||
ui/groupsettingsdialog.ui
|
|
||||||
ui/transfersettingsdialog.ui
|
|
||||||
ui/linkview/importlinkdialog.ui
|
|
||||||
ui/mirror/mirrorsettings.ui
|
|
||||||
ui/mirror/mirroradddlg.ui
|
|
||||||
ui/renamefile.ui
|
|
||||||
ui/verificationdialog.ui
|
|
||||||
ui/verificationadddlg.ui
|
|
||||||
)
|
|
||||||
|
|
||||||
if(KGET_TESTING)
|
|
||||||
set(kget_SRCS
|
|
||||||
${kget_SRCS}
|
|
||||||
tests/testkget.cpp
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
qt4_add_dbus_adaptor(kget_SRCS dbus/org.kde.kget.main.xml dbus/dbuskgetwrapper.h DBusKGetWrapper)
|
|
||||||
|
|
||||||
add_executable(kget ${kget_SRCS})
|
|
||||||
|
|
||||||
target_link_libraries(kget
|
|
||||||
KDE4::kdeui
|
|
||||||
KDE4::kio
|
|
||||||
KDE4::kcmutils
|
|
||||||
KDE4::kpasswdstore
|
|
||||||
kgetcore
|
|
||||||
)
|
|
||||||
|
|
||||||
if (KGET_TESTING)
|
|
||||||
target_link_libraries(kget
|
|
||||||
${QT_QTTEST_LIBRARY}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(
|
|
||||||
TARGETS kget
|
|
||||||
DESTINATION ${KDE4_BIN_INSTALL_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
FILES kget.notifyrc
|
|
||||||
DESTINATION ${KDE4_CONFIG_INSTALL_DIR}/notifications
|
|
||||||
)
|
|
||||||
|
|
||||||
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
|
||||||
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
|
||||||
endif()
|
|
347
kget/COPYING
347
kget/COPYING
|
@ -1,347 +0,0 @@
|
||||||
NOTE! The GPL below is copyrighted by the Free Software Foundation, but
|
|
||||||
the instance of code that it refers to (the kde programs) are copyrighted
|
|
||||||
by the authors who actually wrote it.
|
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 2, June 1991
|
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
License is intended to guarantee your freedom to share and change free
|
|
||||||
software--to make sure the software is free for all its users. This
|
|
||||||
General Public License applies to most of the Free Software
|
|
||||||
Foundation's software and to any other program whose authors commit to
|
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
|
||||||
the GNU Library General Public License instead.) You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
this service if you wish), that you receive source code or can get it
|
|
||||||
if you want it, that you can change the software or use pieces of it
|
|
||||||
in new free programs; and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
anyone to deny you these rights or to ask you to surrender the rights.
|
|
||||||
These restrictions translate to certain responsibilities for you if you
|
|
||||||
distribute copies of the software, or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must give the recipients all the rights that
|
|
||||||
you have. You must make sure that they, too, receive or can get the
|
|
||||||
source code. And you must show them these terms so they know their
|
|
||||||
rights.
|
|
||||||
|
|
||||||
We protect your rights with two steps: (1) copyright the software, and
|
|
||||||
(2) offer you this license which gives you legal permission to copy,
|
|
||||||
distribute and/or modify the software.
|
|
||||||
|
|
||||||
Also, for each author's protection and ours, we want to make certain
|
|
||||||
that everyone understands that there is no warranty for this free
|
|
||||||
software. If the software is modified by someone else and passed on, we
|
|
||||||
want its recipients to know that what they have is not the original, so
|
|
||||||
that any problems introduced by others will not reflect on the original
|
|
||||||
authors' reputations.
|
|
||||||
|
|
||||||
Finally, any free program is threatened constantly by software
|
|
||||||
patents. We wish to avoid the danger that redistributors of a free
|
|
||||||
program will individually obtain patent licenses, in effect making the
|
|
||||||
program proprietary. To prevent this, we have made it clear that any
|
|
||||||
patent must be licensed for everyone's free use or not licensed at all.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License applies to any program or other work which contains
|
|
||||||
a notice placed by the copyright holder saying it may be distributed
|
|
||||||
under the terms of this General Public License. The "Program", below,
|
|
||||||
refers to any such program or work, and a "work based on the Program"
|
|
||||||
means either the Program or any derivative work under copyright law:
|
|
||||||
that is to say, a work containing the Program or a portion of it,
|
|
||||||
either verbatim or with modifications and/or translated into another
|
|
||||||
language. (Hereinafter, translation is included without limitation in
|
|
||||||
the term "modification".) Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running the Program is not restricted, and the output from the Program
|
|
||||||
is covered only if its contents constitute a work based on the
|
|
||||||
Program (independent of having been made by running the Program).
|
|
||||||
Whether that is true depends on what the Program does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Program's
|
|
||||||
source code as you receive it, in any medium, provided that you
|
|
||||||
conspicuously and appropriately publish on each copy an appropriate
|
|
||||||
copyright notice and disclaimer of warranty; keep intact all the
|
|
||||||
notices that refer to this License and to the absence of any warranty;
|
|
||||||
and give any other recipients of the Program a copy of this License
|
|
||||||
along with the Program.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy, and
|
|
||||||
you may at your option offer warranty protection in exchange for a fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Program or any portion
|
|
||||||
of it, thus forming a work based on the Program, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) You must cause the modified files to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
b) You must cause any work that you distribute or publish, that in
|
|
||||||
whole or in part contains or is derived from the Program or any
|
|
||||||
part thereof, to be licensed as a whole at no charge to all third
|
|
||||||
parties under the terms of this License.
|
|
||||||
|
|
||||||
c) If the modified program normally reads commands interactively
|
|
||||||
when run, you must cause it, when started running for such
|
|
||||||
interactive use in the most ordinary way, to print or display an
|
|
||||||
announcement including an appropriate copyright notice and a
|
|
||||||
notice that there is no warranty (or else, saying that you provide
|
|
||||||
a warranty) and that users may redistribute the program under
|
|
||||||
these conditions, and telling the user how to view a copy of this
|
|
||||||
License. (Exception: if the Program itself is interactive but
|
|
||||||
does not normally print such an announcement, your work based on
|
|
||||||
the Program is not required to print an announcement.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Program,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Program, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Program.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Program
|
|
||||||
with the Program (or with a work based on the Program) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may copy and distribute the Program (or a work based on it,
|
|
||||||
under Section 2) in object code or executable form under the terms of
|
|
||||||
Sections 1 and 2 above provided that you also do one of the following:
|
|
||||||
|
|
||||||
a) Accompany it with the complete corresponding machine-readable
|
|
||||||
source code, which must be distributed under the terms of Sections
|
|
||||||
1 and 2 above on a medium customarily used for software interchange; or,
|
|
||||||
|
|
||||||
b) Accompany it with a written offer, valid for at least three
|
|
||||||
years, to give any third party, for a charge no more than your
|
|
||||||
cost of physically performing source distribution, a complete
|
|
||||||
machine-readable copy of the corresponding source code, to be
|
|
||||||
distributed under the terms of Sections 1 and 2 above on a medium
|
|
||||||
customarily used for software interchange; or,
|
|
||||||
|
|
||||||
c) Accompany it with the information you received as to the offer
|
|
||||||
to distribute corresponding source code. (This alternative is
|
|
||||||
allowed only for noncommercial distribution and only if you
|
|
||||||
received the program in object code or executable form with such
|
|
||||||
an offer, in accord with Subsection b above.)
|
|
||||||
|
|
||||||
The source code for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For an executable work, complete source
|
|
||||||
code means all the source code for all modules it contains, plus any
|
|
||||||
associated interface definition files, plus the scripts used to
|
|
||||||
control compilation and installation of the executable. However, as a
|
|
||||||
special exception, the source code distributed need not include
|
|
||||||
anything that is normally distributed (in either source or binary
|
|
||||||
form) with the major components (compiler, kernel, and so on) of the
|
|
||||||
operating system on which the executable runs, unless that component
|
|
||||||
itself accompanies the executable.
|
|
||||||
|
|
||||||
If distribution of executable or object code is made by offering
|
|
||||||
access to copy from a designated place, then offering equivalent
|
|
||||||
access to copy the source code from the same place counts as
|
|
||||||
distribution of the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
4. You may not copy, modify, sublicense, or distribute the Program
|
|
||||||
except as expressly provided under this License. Any attempt
|
|
||||||
otherwise to copy, modify, sublicense or distribute the Program is
|
|
||||||
void, and will automatically terminate your rights under this License.
|
|
||||||
However, parties who have received copies, or rights, from you under
|
|
||||||
this License will not have their licenses terminated so long as such
|
|
||||||
parties remain in full compliance.
|
|
||||||
|
|
||||||
5. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Program or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Program (or any work based on the
|
|
||||||
Program), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Program or works based on it.
|
|
||||||
|
|
||||||
6. Each time you redistribute the Program (or any work based on the
|
|
||||||
Program), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute or modify the Program subject to
|
|
||||||
these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties to
|
|
||||||
this License.
|
|
||||||
|
|
||||||
7. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Program at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Program by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Program.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under
|
|
||||||
any particular circumstance, the balance of the section is intended to
|
|
||||||
apply and the section as a whole is intended to apply in other
|
|
||||||
circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system, which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
8. If the distribution and/or use of the Program is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Program under this License
|
|
||||||
may add an explicit geographical distribution limitation excluding
|
|
||||||
those countries, so that distribution is permitted only in or among
|
|
||||||
countries not thus excluded. In such case, this License incorporates
|
|
||||||
the limitation as if written in the body of this License.
|
|
||||||
|
|
||||||
9. The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program
|
|
||||||
specifies a version number of this License which applies to it and "any
|
|
||||||
later version", you have the option of following the terms and conditions
|
|
||||||
either of that version or of any later version published by the Free
|
|
||||||
Software Foundation. If the Program does not specify a version number of
|
|
||||||
this License, you may choose any version ever published by the Free Software
|
|
||||||
Foundation.
|
|
||||||
|
|
||||||
10. If you wish to incorporate parts of the Program into other free
|
|
||||||
programs whose distribution conditions are different, write to the author
|
|
||||||
to ask for permission. For software which is copyrighted by the Free
|
|
||||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
|
||||||
make exceptions for this. Our decision will be guided by the two goals
|
|
||||||
of preserving the free status of all derivatives of our free software and
|
|
||||||
of promoting the sharing and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
|
||||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
|
||||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
|
||||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
|
||||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
|
||||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
|
||||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
|
||||||
REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
|
||||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
|
||||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
|
||||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
|
||||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
||||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) 19yy <name of author>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program is interactive, make it output a short notice like this
|
|
||||||
when it starts in an interactive mode:
|
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, the commands you use may
|
|
||||||
be called something other than `show w' and `show c'; they could even be
|
|
||||||
mouse-clicks or menu items--whatever suits your program.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
|
||||||
necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
|
||||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1989
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
This General Public License does not permit incorporating your program into
|
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
|
||||||
consider it more useful to permit linking proprietary applications with the
|
|
||||||
library. If this is what you want to do, use the GNU Library General
|
|
||||||
Public License instead of this License.
|
|
510
kget/COPYING.LIB
510
kget/COPYING.LIB
|
@ -1,510 +0,0 @@
|
||||||
|
|
||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
Version 2.1, February 1999
|
|
||||||
|
|
||||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
|
||||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
[This is the first released version of the Lesser GPL. It also counts
|
|
||||||
as the successor of the GNU Library Public License, version 2, hence
|
|
||||||
the version number 2.1.]
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
Licenses are intended to guarantee your freedom to share and change
|
|
||||||
free software--to make sure the software is free for all its users.
|
|
||||||
|
|
||||||
This license, the Lesser General Public License, applies to some
|
|
||||||
specially designated software packages--typically libraries--of the
|
|
||||||
Free Software Foundation and other authors who decide to use it. You
|
|
||||||
can use it too, but we suggest you first think carefully about whether
|
|
||||||
this license or the ordinary General Public License is the better
|
|
||||||
strategy to use in any particular case, based on the explanations
|
|
||||||
below.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom of use,
|
|
||||||
not price. Our General Public Licenses are designed to make sure that
|
|
||||||
you have the freedom to distribute copies of free software (and charge
|
|
||||||
for this service if you wish); that you receive source code or can get
|
|
||||||
it if you want it; that you can change the software and use pieces of
|
|
||||||
it in new free programs; and that you are informed that you can do
|
|
||||||
these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
distributors to deny you these rights or to ask you to surrender these
|
|
||||||
rights. These restrictions translate to certain responsibilities for
|
|
||||||
you if you distribute copies of the library or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of the library, whether gratis
|
|
||||||
or for a fee, you must give the recipients all the rights that we gave
|
|
||||||
you. You must make sure that they, too, receive or can get the source
|
|
||||||
code. If you link other code with the library, you must provide
|
|
||||||
complete object files to the recipients, so that they can relink them
|
|
||||||
with the library after making changes to the library and recompiling
|
|
||||||
it. And you must show them these terms so they know their rights.
|
|
||||||
|
|
||||||
We protect your rights with a two-step method: (1) we copyright the
|
|
||||||
library, and (2) we offer you this license, which gives you legal
|
|
||||||
permission to copy, distribute and/or modify the library.
|
|
||||||
|
|
||||||
To protect each distributor, we want to make it very clear that
|
|
||||||
there is no warranty for the free library. Also, if the library is
|
|
||||||
modified by someone else and passed on, the recipients should know
|
|
||||||
that what they have is not the original version, so that the original
|
|
||||||
author's reputation will not be affected by problems that might be
|
|
||||||
introduced by others.
|
|
||||||
|
|
||||||
Finally, software patents pose a constant threat to the existence of
|
|
||||||
any free program. We wish to make sure that a company cannot
|
|
||||||
effectively restrict the users of a free program by obtaining a
|
|
||||||
restrictive license from a patent holder. Therefore, we insist that
|
|
||||||
any patent license obtained for a version of the library must be
|
|
||||||
consistent with the full freedom of use specified in this license.
|
|
||||||
|
|
||||||
Most GNU software, including some libraries, is covered by the
|
|
||||||
ordinary GNU General Public License. This license, the GNU Lesser
|
|
||||||
General Public License, applies to certain designated libraries, and
|
|
||||||
is quite different from the ordinary General Public License. We use
|
|
||||||
this license for certain libraries in order to permit linking those
|
|
||||||
libraries into non-free programs.
|
|
||||||
|
|
||||||
When a program is linked with a library, whether statically or using
|
|
||||||
a shared library, the combination of the two is legally speaking a
|
|
||||||
combined work, a derivative of the original library. The ordinary
|
|
||||||
General Public License therefore permits such linking only if the
|
|
||||||
entire combination fits its criteria of freedom. The Lesser General
|
|
||||||
Public License permits more lax criteria for linking other code with
|
|
||||||
the library.
|
|
||||||
|
|
||||||
We call this license the "Lesser" General Public License because it
|
|
||||||
does Less to protect the user's freedom than the ordinary General
|
|
||||||
Public License. It also provides other free software developers Less
|
|
||||||
of an advantage over competing non-free programs. These disadvantages
|
|
||||||
are the reason we use the ordinary General Public License for many
|
|
||||||
libraries. However, the Lesser license provides advantages in certain
|
|
||||||
special circumstances.
|
|
||||||
|
|
||||||
For example, on rare occasions, there may be a special need to
|
|
||||||
encourage the widest possible use of a certain library, so that it
|
|
||||||
becomes a de-facto standard. To achieve this, non-free programs must
|
|
||||||
be allowed to use the library. A more frequent case is that a free
|
|
||||||
library does the same job as widely used non-free libraries. In this
|
|
||||||
case, there is little to gain by limiting the free library to free
|
|
||||||
software only, so we use the Lesser General Public License.
|
|
||||||
|
|
||||||
In other cases, permission to use a particular library in non-free
|
|
||||||
programs enables a greater number of people to use a large body of
|
|
||||||
free software. For example, permission to use the GNU C Library in
|
|
||||||
non-free programs enables many more people to use the whole GNU
|
|
||||||
operating system, as well as its variant, the GNU/Linux operating
|
|
||||||
system.
|
|
||||||
|
|
||||||
Although the Lesser General Public License is Less protective of the
|
|
||||||
users' freedom, it does ensure that the user of a program that is
|
|
||||||
linked with the Library has the freedom and the wherewithal to run
|
|
||||||
that program using a modified version of the Library.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow. Pay close attention to the difference between a
|
|
||||||
"work based on the library" and a "work that uses the library". The
|
|
||||||
former contains code derived from the library, whereas the latter must
|
|
||||||
be combined with the library in order to run.
|
|
||||||
|
|
||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License Agreement applies to any software library or other
|
|
||||||
program which contains a notice placed by the copyright holder or
|
|
||||||
other authorized party saying it may be distributed under the terms of
|
|
||||||
this Lesser General Public License (also called "this License").
|
|
||||||
Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
A "library" means a collection of software functions and/or data
|
|
||||||
prepared so as to be conveniently linked with application programs
|
|
||||||
(which use some of those functions and data) to form executables.
|
|
||||||
|
|
||||||
The "Library", below, refers to any such software library or work
|
|
||||||
which has been distributed under these terms. A "work based on the
|
|
||||||
Library" means either the Library or any derivative work under
|
|
||||||
copyright law: that is to say, a work containing the Library or a
|
|
||||||
portion of it, either verbatim or with modifications and/or translated
|
|
||||||
straightforwardly into another language. (Hereinafter, translation is
|
|
||||||
included without limitation in the term "modification".)
|
|
||||||
|
|
||||||
"Source code" for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For a library, complete source code means
|
|
||||||
all the source code for all modules it contains, plus any associated
|
|
||||||
interface definition files, plus the scripts used to control
|
|
||||||
compilation and installation of the library.
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running a program using the Library is not restricted, and output from
|
|
||||||
such a program is covered only if its contents constitute a work based
|
|
||||||
on the Library (independent of the use of the Library in a tool for
|
|
||||||
writing it). Whether that is true depends on what the Library does
|
|
||||||
and what the program that uses the Library does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Library's
|
|
||||||
complete source code as you receive it, in any medium, provided that
|
|
||||||
you conspicuously and appropriately publish on each copy an
|
|
||||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
|
||||||
all the notices that refer to this License and to the absence of any
|
|
||||||
warranty; and distribute a copy of this License along with the
|
|
||||||
Library.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy,
|
|
||||||
and you may at your option offer warranty protection in exchange for a
|
|
||||||
fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Library or any portion
|
|
||||||
of it, thus forming a work based on the Library, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The modified work must itself be a software library.
|
|
||||||
|
|
||||||
b) You must cause the files modified to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
c) You must cause the whole of the work to be licensed at no
|
|
||||||
charge to all third parties under the terms of this License.
|
|
||||||
|
|
||||||
d) If a facility in the modified Library refers to a function or a
|
|
||||||
table of data to be supplied by an application program that uses
|
|
||||||
the facility, other than as an argument passed when the facility
|
|
||||||
is invoked, then you must make a good faith effort to ensure that,
|
|
||||||
in the event an application does not supply such function or
|
|
||||||
table, the facility still operates, and performs whatever part of
|
|
||||||
its purpose remains meaningful.
|
|
||||||
|
|
||||||
(For example, a function in a library to compute square roots has
|
|
||||||
a purpose that is entirely well-defined independent of the
|
|
||||||
application. Therefore, Subsection 2d requires that any
|
|
||||||
application-supplied function or table used by this function must
|
|
||||||
be optional: if the application does not supply it, the square
|
|
||||||
root function must still compute square roots.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Library,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Library, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote
|
|
||||||
it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Library.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Library
|
|
||||||
with the Library (or with a work based on the Library) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
|
||||||
License instead of this License to a given copy of the Library. To do
|
|
||||||
this, you must alter all the notices that refer to this License, so
|
|
||||||
that they refer to the ordinary GNU General Public License, version 2,
|
|
||||||
instead of to this License. (If a newer version than version 2 of the
|
|
||||||
ordinary GNU General Public License has appeared, then you can specify
|
|
||||||
that version instead if you wish.) Do not make any other change in
|
|
||||||
these notices.
|
|
||||||
|
|
||||||
Once this change is made in a given copy, it is irreversible for
|
|
||||||
that copy, so the ordinary GNU General Public License applies to all
|
|
||||||
subsequent copies and derivative works made from that copy.
|
|
||||||
|
|
||||||
This option is useful when you wish to copy part of the code of
|
|
||||||
the Library into a program that is not a library.
|
|
||||||
|
|
||||||
4. You may copy and distribute the Library (or a portion or
|
|
||||||
derivative of it, under Section 2) in object code or executable form
|
|
||||||
under the terms of Sections 1 and 2 above provided that you accompany
|
|
||||||
it with the complete corresponding machine-readable source code, which
|
|
||||||
must be distributed under the terms of Sections 1 and 2 above on a
|
|
||||||
medium customarily used for software interchange.
|
|
||||||
|
|
||||||
If distribution of object code is made by offering access to copy
|
|
||||||
from a designated place, then offering equivalent access to copy the
|
|
||||||
source code from the same place satisfies the requirement to
|
|
||||||
distribute the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
5. A program that contains no derivative of any portion of the
|
|
||||||
Library, but is designed to work with the Library by being compiled or
|
|
||||||
linked with it, is called a "work that uses the Library". Such a
|
|
||||||
work, in isolation, is not a derivative work of the Library, and
|
|
||||||
therefore falls outside the scope of this License.
|
|
||||||
|
|
||||||
However, linking a "work that uses the Library" with the Library
|
|
||||||
creates an executable that is a derivative of the Library (because it
|
|
||||||
contains portions of the Library), rather than a "work that uses the
|
|
||||||
library". The executable is therefore covered by this License.
|
|
||||||
Section 6 states terms for distribution of such executables.
|
|
||||||
|
|
||||||
When a "work that uses the Library" uses material from a header file
|
|
||||||
that is part of the Library, the object code for the work may be a
|
|
||||||
derivative work of the Library even though the source code is not.
|
|
||||||
Whether this is true is especially significant if the work can be
|
|
||||||
linked without the Library, or if the work is itself a library. The
|
|
||||||
threshold for this to be true is not precisely defined by law.
|
|
||||||
|
|
||||||
If such an object file uses only numerical parameters, data
|
|
||||||
structure layouts and accessors, and small macros and small inline
|
|
||||||
functions (ten lines or less in length), then the use of the object
|
|
||||||
file is unrestricted, regardless of whether it is legally a derivative
|
|
||||||
work. (Executables containing this object code plus portions of the
|
|
||||||
Library will still fall under Section 6.)
|
|
||||||
|
|
||||||
Otherwise, if the work is a derivative of the Library, you may
|
|
||||||
distribute the object code for the work under the terms of Section 6.
|
|
||||||
Any executables containing that work also fall under Section 6,
|
|
||||||
whether or not they are linked directly with the Library itself.
|
|
||||||
|
|
||||||
6. As an exception to the Sections above, you may also combine or
|
|
||||||
link a "work that uses the Library" with the Library to produce a
|
|
||||||
work containing portions of the Library, and distribute that work
|
|
||||||
under terms of your choice, provided that the terms permit
|
|
||||||
modification of the work for the customer's own use and reverse
|
|
||||||
engineering for debugging such modifications.
|
|
||||||
|
|
||||||
You must give prominent notice with each copy of the work that the
|
|
||||||
Library is used in it and that the Library and its use are covered by
|
|
||||||
this License. You must supply a copy of this License. If the work
|
|
||||||
during execution displays copyright notices, you must include the
|
|
||||||
copyright notice for the Library among them, as well as a reference
|
|
||||||
directing the user to the copy of this License. Also, you must do one
|
|
||||||
of these things:
|
|
||||||
|
|
||||||
a) Accompany the work with the complete corresponding
|
|
||||||
machine-readable source code for the Library including whatever
|
|
||||||
changes were used in the work (which must be distributed under
|
|
||||||
Sections 1 and 2 above); and, if the work is an executable linked
|
|
||||||
with the Library, with the complete machine-readable "work that
|
|
||||||
uses the Library", as object code and/or source code, so that the
|
|
||||||
user can modify the Library and then relink to produce a modified
|
|
||||||
executable containing the modified Library. (It is understood
|
|
||||||
that the user who changes the contents of definitions files in the
|
|
||||||
Library will not necessarily be able to recompile the application
|
|
||||||
to use the modified definitions.)
|
|
||||||
|
|
||||||
b) Use a suitable shared library mechanism for linking with the
|
|
||||||
Library. A suitable mechanism is one that (1) uses at run time a
|
|
||||||
copy of the library already present on the user's computer system,
|
|
||||||
rather than copying library functions into the executable, and (2)
|
|
||||||
will operate properly with a modified version of the library, if
|
|
||||||
the user installs one, as long as the modified version is
|
|
||||||
interface-compatible with the version that the work was made with.
|
|
||||||
|
|
||||||
c) Accompany the work with a written offer, valid for at least
|
|
||||||
three years, to give the same user the materials specified in
|
|
||||||
Subsection 6a, above, for a charge no more than the cost of
|
|
||||||
performing this distribution.
|
|
||||||
|
|
||||||
d) If distribution of the work is made by offering access to copy
|
|
||||||
from a designated place, offer equivalent access to copy the above
|
|
||||||
specified materials from the same place.
|
|
||||||
|
|
||||||
e) Verify that the user has already received a copy of these
|
|
||||||
materials or that you have already sent this user a copy.
|
|
||||||
|
|
||||||
For an executable, the required form of the "work that uses the
|
|
||||||
Library" must include any data and utility programs needed for
|
|
||||||
reproducing the executable from it. However, as a special exception,
|
|
||||||
the materials to be distributed need not include anything that is
|
|
||||||
normally distributed (in either source or binary form) with the major
|
|
||||||
components (compiler, kernel, and so on) of the operating system on
|
|
||||||
which the executable runs, unless that component itself accompanies
|
|
||||||
the executable.
|
|
||||||
|
|
||||||
It may happen that this requirement contradicts the license
|
|
||||||
restrictions of other proprietary libraries that do not normally
|
|
||||||
accompany the operating system. Such a contradiction means you cannot
|
|
||||||
use both them and the Library together in an executable that you
|
|
||||||
distribute.
|
|
||||||
|
|
||||||
7. You may place library facilities that are a work based on the
|
|
||||||
Library side-by-side in a single library together with other library
|
|
||||||
facilities not covered by this License, and distribute such a combined
|
|
||||||
library, provided that the separate distribution of the work based on
|
|
||||||
the Library and of the other library facilities is otherwise
|
|
||||||
permitted, and provided that you do these two things:
|
|
||||||
|
|
||||||
a) Accompany the combined library with a copy of the same work
|
|
||||||
based on the Library, uncombined with any other library
|
|
||||||
facilities. This must be distributed under the terms of the
|
|
||||||
Sections above.
|
|
||||||
|
|
||||||
b) Give prominent notice with the combined library of the fact
|
|
||||||
that part of it is a work based on the Library, and explaining
|
|
||||||
where to find the accompanying uncombined form of the same work.
|
|
||||||
|
|
||||||
8. You may not copy, modify, sublicense, link with, or distribute
|
|
||||||
the Library except as expressly provided under this License. Any
|
|
||||||
attempt otherwise to copy, modify, sublicense, link with, or
|
|
||||||
distribute the Library is void, and will automatically terminate your
|
|
||||||
rights under this License. However, parties who have received copies,
|
|
||||||
or rights, from you under this License will not have their licenses
|
|
||||||
terminated so long as such parties remain in full compliance.
|
|
||||||
|
|
||||||
9. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Library or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Library (or any work based on the
|
|
||||||
Library), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Library or works based on it.
|
|
||||||
|
|
||||||
10. Each time you redistribute the Library (or any work based on the
|
|
||||||
Library), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute, link with or modify the Library
|
|
||||||
subject to these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties with
|
|
||||||
this License.
|
|
||||||
|
|
||||||
11. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Library at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Library by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Library.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under
|
|
||||||
any particular circumstance, the balance of the section is intended to
|
|
||||||
apply, and the section as a whole is intended to apply in other
|
|
||||||
circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
12. If the distribution and/or use of the Library is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Library under this License
|
|
||||||
may add an explicit geographical distribution limitation excluding those
|
|
||||||
countries, so that distribution is permitted only in or among
|
|
||||||
countries not thus excluded. In such case, this License incorporates
|
|
||||||
the limitation as if written in the body of this License.
|
|
||||||
|
|
||||||
13. The Free Software Foundation may publish revised and/or new
|
|
||||||
versions of the Lesser 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 Library
|
|
||||||
specifies a version number of this License which applies to it and
|
|
||||||
"any later version", you have the option of following the terms and
|
|
||||||
conditions either of that version or of any later version published by
|
|
||||||
the Free Software Foundation. If the Library does not specify a
|
|
||||||
license version number, you may choose any version ever published by
|
|
||||||
the Free Software Foundation.
|
|
||||||
|
|
||||||
14. If you wish to incorporate parts of the Library into other free
|
|
||||||
programs whose distribution conditions are incompatible with these,
|
|
||||||
write to the author to ask for permission. For software which is
|
|
||||||
copyrighted by the Free Software Foundation, write to the Free
|
|
||||||
Software Foundation; we sometimes make exceptions for this. Our
|
|
||||||
decision will be guided by the two goals of preserving the free status
|
|
||||||
of all derivatives of our free software and of promoting the sharing
|
|
||||||
and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
|
||||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
|
||||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
|
||||||
OTHER PARTIES PROVIDE THE LIBRARY "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
|
|
||||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
|
||||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
|
||||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
|
||||||
AND/OR REDISTRIBUTE THE LIBRARY 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
|
|
||||||
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
|
||||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
||||||
DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Libraries
|
|
||||||
|
|
||||||
If you develop a new library, and you want it to be of the greatest
|
|
||||||
possible use to the public, we recommend making it free software that
|
|
||||||
everyone can redistribute and change. You can do so by permitting
|
|
||||||
redistribution under these terms (or, alternatively, under the terms
|
|
||||||
of the ordinary General Public License).
|
|
||||||
|
|
||||||
To apply these terms, attach the following notices to the library.
|
|
||||||
It is safest to attach them to the start of each source file to most
|
|
||||||
effectively convey the exclusion of warranty; and each file should
|
|
||||||
have at least the "copyright" line and a pointer to where the full
|
|
||||||
notice is found.
|
|
||||||
|
|
||||||
|
|
||||||
<one line to give the library's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or
|
|
||||||
your school, if any, to sign a "copyright disclaimer" for the library,
|
|
||||||
if necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
|
||||||
library `Frob' (a library for tweaking knobs) written by James
|
|
||||||
Random Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1990
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
That's all there is to it!
|
|
||||||
|
|
||||||
|
|
150
kget/HACKING
150
kget/HACKING
|
@ -1,150 +0,0 @@
|
||||||
This file has been copied from the kicker HACKING file from Aaron Seigo.
|
|
||||||
|
|
||||||
While you may notice that there are many discrepencies between
|
|
||||||
the code and this document, all new development should
|
|
||||||
follow the coding style as described below amd one day the codebase will
|
|
||||||
actually be consistent!
|
|
||||||
|
|
||||||
Naming Conventions
|
|
||||||
------------------
|
|
||||||
Class names start with a capital letter, member variables begin with m_.
|
|
||||||
Methods and functions start with a lower case letter.
|
|
||||||
|
|
||||||
|
|
||||||
Indenting
|
|
||||||
---------
|
|
||||||
Tabstop is 4 spaces. No tabs, only spaces.
|
|
||||||
|
|
||||||
Try to keep lines under 80 characters in width. When wrapping a single
|
|
||||||
logical line of code across multiple lines, new lines should be indented
|
|
||||||
at least once and should preferably line up with parentheses, if any, on
|
|
||||||
the line above. e.g.:
|
|
||||||
|
|
||||||
someMethod(parameterOne, parameterTwo,
|
|
||||||
parameterThree, parameterFour);
|
|
||||||
|
|
||||||
If a boolean expression is spread out over several lines, the boolean
|
|
||||||
operator is always the last item on the line, e.g.:
|
|
||||||
|
|
||||||
if ((condition1 || condition2) &&
|
|
||||||
condition3 &&
|
|
||||||
(condition4 || condition5))
|
|
||||||
{
|
|
||||||
|
|
||||||
Switch statements should have the case line indented and the case block
|
|
||||||
itsel further indented, e.g.:
|
|
||||||
|
|
||||||
switch (condition)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
...
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
...
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
...;
|
|
||||||
}
|
|
||||||
|
|
||||||
Spaces
|
|
||||||
------
|
|
||||||
A single space should appear between keywords and parentheses, eg:
|
|
||||||
|
|
||||||
if (
|
|
||||||
while (
|
|
||||||
for (
|
|
||||||
|
|
||||||
No spaces appear between function/method names and parentheses:
|
|
||||||
|
|
||||||
function(
|
|
||||||
someObject->method(
|
|
||||||
|
|
||||||
No spaces appear between opening closing parens and the arguments:
|
|
||||||
|
|
||||||
for (int i = 0; i < count; ++i)
|
|
||||||
|
|
||||||
Spaces appear between operators, e.g.:
|
|
||||||
|
|
||||||
int i = i + 3;
|
|
||||||
someObject.setValue(someObject.currentValue() + 1)
|
|
||||||
|
|
||||||
|
|
||||||
Braces
|
|
||||||
------
|
|
||||||
Braces always appear on a line by themself, indented to align with the
|
|
||||||
above keyword:
|
|
||||||
|
|
||||||
if (foo)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
Unless it uglifies the code, use braces even for one-liner conditionals:
|
|
||||||
|
|
||||||
if (foo)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Always use braces if the conditional expression wraps across multiple
|
|
||||||
physical lines.
|
|
||||||
|
|
||||||
Braces around case blocks in switch statements are optional.
|
|
||||||
|
|
||||||
|
|
||||||
Constructors
|
|
||||||
------------
|
|
||||||
Constructors are written as:
|
|
||||||
|
|
||||||
MyClass::MyClass(...)
|
|
||||||
: SuperClass(...),
|
|
||||||
m_member1(...),
|
|
||||||
m_member2(...),
|
|
||||||
...
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
Class Definitions
|
|
||||||
-----------------
|
|
||||||
Class definitions will follow the following order:
|
|
||||||
|
|
||||||
class <name> : <scope> <superclass>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
<ctors>
|
|
||||||
<dtors>
|
|
||||||
<operators>
|
|
||||||
<other methods>
|
|
||||||
|
|
||||||
<members>
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
<methods>
|
|
||||||
|
|
||||||
signals:
|
|
||||||
<methods>
|
|
||||||
|
|
||||||
protected:
|
|
||||||
<ctors>
|
|
||||||
<dtors>
|
|
||||||
<operators>
|
|
||||||
|
|
||||||
<members>
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
<methods>
|
|
||||||
|
|
||||||
private:
|
|
||||||
<ctors>
|
|
||||||
<dtors>
|
|
||||||
<operators>
|
|
||||||
|
|
||||||
<members>
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
<methods>
|
|
||||||
};
|
|
|
@ -1,7 +0,0 @@
|
||||||
#! /bin/sh
|
|
||||||
kget_subdirs="conf core dbus transfer-plugins ui extensions/webinterface"
|
|
||||||
$EXTRACTRC `find $kget_subdirs -name \*.ui` >> rc.cpp || exit 11
|
|
||||||
$EXTRACTRC `find $kget_subdirs -name \*.rc` >> rc.cpp || exit 12
|
|
||||||
$EXTRACTRC `find $kget_subdirs -name \*.kcfg` >> rc.cpp || exit 13
|
|
||||||
$XGETTEXT `find $kget_subdirs -name \*.cpp -o -name \*.h` *.cpp *.h -o $podir/kget.pot
|
|
||||||
rm -f rc.cpp
|
|
|
@ -1,353 +0,0 @@
|
||||||
/***************************************************************************
|
|
||||||
* Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net> *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the *
|
|
||||||
* Free Software Foundation, Inc., *
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
#include "autopastemodel.h"
|
|
||||||
#include "settings.h"
|
|
||||||
|
|
||||||
#include <KComboBox>
|
|
||||||
#include <KIcon>
|
|
||||||
#include <KLineEdit>
|
|
||||||
#include <KLocale>
|
|
||||||
|
|
||||||
AutoPasteDelegate::AutoPasteDelegate(QAbstractItemModel *types, QAbstractItemModel *syntaxes, QObject *parent)
|
|
||||||
: QStyledItemDelegate(parent),
|
|
||||||
m_types(types),
|
|
||||||
m_syntaxes(syntaxes)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *AutoPasteDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(option)
|
|
||||||
|
|
||||||
if (!index.isValid()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(index.column()) {
|
|
||||||
case AutoPasteModel::Type: {
|
|
||||||
KComboBox *types = new KComboBox(parent);
|
|
||||||
types->setModel(m_types);
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
case AutoPasteModel::Pattern: {
|
|
||||||
KLineEdit *pattern = new KLineEdit(parent);
|
|
||||||
return pattern;
|
|
||||||
}
|
|
||||||
case AutoPasteModel::PatternSyntax: {
|
|
||||||
KComboBox *syntaxes = new KComboBox(parent);
|
|
||||||
syntaxes->setModel(m_syntaxes);
|
|
||||||
return syntaxes;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AutoPasteDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (!index.isValid() || !editor) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (index.column()) {
|
|
||||||
case AutoPasteModel::Type: {
|
|
||||||
KComboBox *type = static_cast<KComboBox*>(editor);
|
|
||||||
const int row = type->findData(index.data(Qt::EditRole));
|
|
||||||
type->setCurrentIndex(row);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AutoPasteModel::Pattern: {
|
|
||||||
KLineEdit *line = static_cast<KLineEdit*>(editor);
|
|
||||||
line->setText(index.data(Qt::EditRole).toString());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AutoPasteModel::PatternSyntax: {
|
|
||||||
KComboBox *syntax = static_cast<KComboBox*>(editor);
|
|
||||||
const int row = syntax->findData(index.data(Qt::EditRole));
|
|
||||||
syntax->setCurrentIndex(row);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AutoPasteDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (!index.isValid() || !editor || !model) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (index.column()) {
|
|
||||||
case AutoPasteModel::Type: {
|
|
||||||
KComboBox *typeBox = static_cast<KComboBox*>(editor);
|
|
||||||
const int type = typeBox->itemData(typeBox->currentIndex()).toInt();
|
|
||||||
model->setData(index, type);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AutoPasteModel::Pattern: {
|
|
||||||
KLineEdit *line = static_cast<KLineEdit*>(editor);
|
|
||||||
const QString text = line->text();
|
|
||||||
if (!text.isEmpty()) {
|
|
||||||
model->setData(index, text);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AutoPasteModel::PatternSyntax: {
|
|
||||||
KComboBox *syntaxBox = static_cast<KComboBox*>(editor);
|
|
||||||
const int syntax = syntaxBox->itemData(syntaxBox->currentIndex()).toInt();
|
|
||||||
model->setData(index, syntax);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AutoPasteDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(index)
|
|
||||||
editor->setGeometry(option.rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize AutoPasteDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
//make the sizeHint a little bit nicer to have more beautiful editors
|
|
||||||
QSize hint;
|
|
||||||
hint.setWidth(QStyledItemDelegate::sizeHint(option, index).width());
|
|
||||||
hint.setHeight(option.fontMetrics.height() + 7);
|
|
||||||
return hint;
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoPasteModel::AutoPasteModel(QObject *parent)
|
|
||||||
: QAbstractTableModel(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoPasteModel::~AutoPasteModel()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int AutoPasteModel::rowCount(const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (!index.isValid()) {
|
|
||||||
return m_data.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int AutoPasteModel::columnCount(const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (!index.isValid()) {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant AutoPasteModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
|
||||||
if (orientation == Qt::Vertical) {
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
|
||||||
if (section == Pattern) {
|
|
||||||
return i18n("Pattern");
|
|
||||||
} else if (section == PatternSyntax) {
|
|
||||||
return i18n("Syntax");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant AutoPasteModel::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
if (!index.isValid()) {
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
const int column = index.column();
|
|
||||||
const int row = index.row();
|
|
||||||
|
|
||||||
switch (column) {
|
|
||||||
case Type: {
|
|
||||||
if (role == Qt::DecorationRole) {
|
|
||||||
return (m_data[row].type == Include ? KIcon("list-add") : KIcon("list-remove"));
|
|
||||||
} else if ((role == Qt::UserRole) || (role == Qt::EditRole)) {
|
|
||||||
return m_data[row].type;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Pattern: {
|
|
||||||
if ((role == Qt::DisplayRole) || (role == Qt::EditRole) || (role == Qt::UserRole)) {
|
|
||||||
return m_data[row].pattern;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PatternSyntax: {
|
|
||||||
if (role == Qt::DisplayRole) {
|
|
||||||
return (m_data[row].syntax == Wildcard ? i18n("Escape sequences") : i18n("Regular expression"));
|
|
||||||
} else if ((role == Qt::UserRole) || (role == Qt::EditRole)) {
|
|
||||||
return m_data[row].syntax;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
Qt::ItemFlags AutoPasteModel::flags(const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(index)
|
|
||||||
|
|
||||||
return (Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AutoPasteModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
||||||
{
|
|
||||||
if (role != Qt::EditRole) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int row = index.row();
|
|
||||||
const int column = index.column();
|
|
||||||
|
|
||||||
switch (column) {
|
|
||||||
case Type: {
|
|
||||||
m_data[row].type = static_cast<TypeData>(value.toInt());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Pattern: {
|
|
||||||
m_data[row].pattern = value.toString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PatternSyntax: {
|
|
||||||
m_data[row].syntax = static_cast<PatternSyntaxData>(value.toInt());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
emit dataChanged(index, index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AutoPasteModel::removeRows(int row, int count, const QModelIndex &parent)
|
|
||||||
{
|
|
||||||
if (parent.isValid() || (row < 0) || (count < 1) || (row + count > rowCount())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
beginRemoveRows(parent, row, row + count - 1);
|
|
||||||
while (count) {
|
|
||||||
m_data.removeAt(row);
|
|
||||||
--count;
|
|
||||||
}
|
|
||||||
endRemoveRows();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AutoPasteModel::addItem(TypeData dataType, PatternSyntaxData patternSyntax, const QString &pattern)
|
|
||||||
{
|
|
||||||
addItems(QList<int>() << dataType, QList<int>() << patternSyntax, QStringList() << pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AutoPasteModel::addItems(const QList<int> &dataTypes, const QList<int> patternSyntaxes, const QStringList &patterns)
|
|
||||||
{
|
|
||||||
const int row = rowCount();
|
|
||||||
const int numItems = patterns.count();
|
|
||||||
beginInsertRows(QModelIndex(), row, row + numItems - 1);
|
|
||||||
|
|
||||||
for (int i = 0; i < numItems; ++i) {
|
|
||||||
Data data;
|
|
||||||
data.type = static_cast<TypeData>(dataTypes[i]);
|
|
||||||
data.pattern = patterns[i];
|
|
||||||
data.syntax = static_cast<PatternSyntaxData>(patternSyntaxes[i]);
|
|
||||||
m_data.append(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AutoPasteModel::moveItem(int sourceRow, int destinationRow)
|
|
||||||
{
|
|
||||||
if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow, QModelIndex(), destinationRow)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//beginMoveRows asks for different data, than QList::move does, see the 4.7 docs
|
|
||||||
if (sourceRow + 2 == destinationRow) {
|
|
||||||
--destinationRow;
|
|
||||||
}
|
|
||||||
m_data.move(sourceRow, destinationRow);
|
|
||||||
endMoveRows();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AutoPasteModel::load()
|
|
||||||
{
|
|
||||||
//remove all old items if there are any
|
|
||||||
if (rowCount()) {
|
|
||||||
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
|
|
||||||
m_data.clear();
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
addItems(Settings::autoPasteTypes(), Settings::autoPastePatternSyntaxes(), Settings::autoPastePatterns());
|
|
||||||
}
|
|
||||||
|
|
||||||
void AutoPasteModel::save()
|
|
||||||
{
|
|
||||||
QList<int> types;
|
|
||||||
QList<int> syntaxes;
|
|
||||||
QStringList patterns;
|
|
||||||
foreach (const Data &data, m_data) {
|
|
||||||
types << data.type;
|
|
||||||
syntaxes << data.syntax;
|
|
||||||
patterns << data.pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
Settings::self()->setAutoPasteTypes(types);
|
|
||||||
Settings::self()->setAutoPastePatternSyntaxes(syntaxes);
|
|
||||||
Settings::self()->setAutoPastePatterns(patterns);
|
|
||||||
Settings::self()->writeConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AutoPasteModel::resetDefaults()
|
|
||||||
{
|
|
||||||
QStringList names = QStringList() << "AutoPastePatterns" << "AutoPasteTypes" << "AutoPastePatternSyntaxes";
|
|
||||||
foreach (const QString &name, names) {
|
|
||||||
KConfigSkeletonItem *item = Settings::self()->findItem(name);
|
|
||||||
if (item) {
|
|
||||||
item->readDefault(Settings::self()->config());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,123 +0,0 @@
|
||||||
/***************************************************************************
|
|
||||||
* Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net> *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the *
|
|
||||||
* Free Software Foundation, Inc., *
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
#ifndef AUTOPASTEMODEL
|
|
||||||
#define AUTOPASTEMODEL
|
|
||||||
|
|
||||||
#include <QtCore/qabstractitemmodel.h>
|
|
||||||
#include <QtGui/QStyledItemDelegate>
|
|
||||||
|
|
||||||
class AutoPasteDelegate : public QStyledItemDelegate
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
AutoPasteDelegate(QAbstractItemModel *types, QAbstractItemModel *syntaxes, QObject *parent = 0);
|
|
||||||
|
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
|
||||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
|
||||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
|
||||||
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QAbstractItemModel *m_types;
|
|
||||||
QAbstractItemModel *m_syntaxes;
|
|
||||||
};
|
|
||||||
|
|
||||||
class AutoPasteModel : public QAbstractTableModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum DataType {
|
|
||||||
Type = 0,
|
|
||||||
Pattern,
|
|
||||||
PatternSyntax
|
|
||||||
};
|
|
||||||
enum TypeData {
|
|
||||||
Include = 0,
|
|
||||||
Exclude
|
|
||||||
};
|
|
||||||
enum PatternSyntaxData {
|
|
||||||
Wildcard = 0,
|
|
||||||
RegExp
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit AutoPasteModel(QObject *parent = 0);
|
|
||||||
~AutoPasteModel();
|
|
||||||
|
|
||||||
int rowCount(const QModelIndex &index = QModelIndex()) const;
|
|
||||||
int columnCount(const QModelIndex &index = QModelIndex()) const;
|
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
||||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an an item
|
|
||||||
* @note do not use this for loading data
|
|
||||||
* @see load()
|
|
||||||
*/
|
|
||||||
void addItem(TypeData dataType, PatternSyntaxData patternSyntax, const QString &pattern);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Moves an item to a new position
|
|
||||||
* @param sourceRow the current row of the selected item
|
|
||||||
* @param destinationRow is the new row before the move,
|
|
||||||
* i.e. if sourceRow was not removed from the model
|
|
||||||
* @see QAbstractItemModel::beginMoveRows()
|
|
||||||
*/
|
|
||||||
bool moveItem(int sourceRow, int destinationRow);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
/**
|
|
||||||
* Loads the stored data
|
|
||||||
* @see save()
|
|
||||||
*/
|
|
||||||
void load();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves the current data
|
|
||||||
* @see load()
|
|
||||||
*/
|
|
||||||
void save();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets the model to the default data
|
|
||||||
*/
|
|
||||||
void resetDefaults();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void addItems(const QList<int> &dataTypes, const QList<int> patternSyntaxes, const QStringList &patterns);
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct Data
|
|
||||||
{
|
|
||||||
TypeData type;
|
|
||||||
QString pattern;
|
|
||||||
PatternSyntaxData syntax;
|
|
||||||
};
|
|
||||||
|
|
||||||
QList<Data> m_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,162 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>DlgAdvanced</class>
|
|
||||||
<widget class="QWidget" name="DlgAdvanced">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>585</width>
|
|
||||||
<height>443</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="kcfg_EnableSystemTray">
|
|
||||||
<property name="text">
|
|
||||||
<string>Enable system tray icon</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QFormLayout" name="formLayout_2">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QCheckBox" name="kcfg_AfterFinishActionEnabled">
|
|
||||||
<property name="text">
|
|
||||||
<string>Execute action after all downloads have been finished:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="KComboBox" name="kcfg_AfterFinishAction">
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Quit KGet</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>At startup:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="KComboBox" name="kcfg_StartupAction">
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Restore Download State</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Start All Downloads</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Stop All Downloads</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="KComboBox" name="kcfg_HistoryBackend"/>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>History backend:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="kcfg_EnableKUIServerIntegration">
|
|
||||||
<property name="title">
|
|
||||||
<string>Enable KDE Global Progress Tracking</string>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QRadioButton" name="kcfg_ExportSingleTransfer">
|
|
||||||
<property name="text">
|
|
||||||
<string>Show every single download </string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QRadioButton" name="kcfg_ExportGlobalJob">
|
|
||||||
<property name="text">
|
|
||||||
<string>Show overall progress</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="groupBox_2">
|
|
||||||
<property name="title">
|
|
||||||
<string>Handle existing Files/Transfers</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
|
||||||
<item>
|
|
||||||
<widget class="QRadioButton" name="kcfg_FilesAlwaysAsk">
|
|
||||||
<property name="text">
|
|
||||||
<string>Always ask</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QRadioButton" name="kcfg_FilesAutomaticRename">
|
|
||||||
<property name="text">
|
|
||||||
<string>Automatic rename</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QRadioButton" name="kcfg_FilesOverwrite">
|
|
||||||
<property name="text">
|
|
||||||
<string>Overwrite</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Expanding</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>200</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>KComboBox</class>
|
|
||||||
<extends>QComboBox</extends>
|
|
||||||
<header>kcombobox.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -1,55 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>DlgAppearance</class>
|
|
||||||
<widget class="QWidget" name="DlgAppearance">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>507</width>
|
|
||||||
<height>381</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout_4">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QGroupBox" name="kcfg_ShowDropTarget">
|
|
||||||
<property name="title">
|
|
||||||
<string>Use Drop Target</string>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QCheckBox" name="kcfg_AnimateDropTarget">
|
|
||||||
<property name="text">
|
|
||||||
<string>Enable animations</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Expanding</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>349</width>
|
|
||||||
<height>70</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -1,94 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>DlgGroups</class>
|
|
||||||
<widget class="QWidget" name="DlgGroups">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>531</width>
|
|
||||||
<height>322</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="kcfg_DirectoriesAsSuggestion">
|
|
||||||
<property name="text">
|
|
||||||
<string>Use default folders for groups as suggestion</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="kcfg_AskForDestination">
|
|
||||||
<property name="text">
|
|
||||||
<string>Ask for destination if there are no default folders</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="TransfersGroupTree" name="treeView">
|
|
||||||
<property name="alternatingRowColors">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="selectionMode">
|
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
|
||||||
</property>
|
|
||||||
<property name="rootIsDecorated">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="itemsExpandable">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="layout">
|
|
||||||
<item>
|
|
||||||
<widget class="KPushButton" name="add"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="KPushButton" name="rename">
|
|
||||||
<property name="text">
|
|
||||||
<string>Rename</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="KPushButton" name="remove"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="KIconButton" name="selectIcon">
|
|
||||||
<property name="text">
|
|
||||||
<string>Select Icon...</string>
|
|
||||||
</property>
|
|
||||||
<property name="iconSize">
|
|
||||||
<number>16</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="KPushButton" name="configure"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>KIconButton</class>
|
|
||||||
<extends>QPushButton</extends>
|
|
||||||
<header>kicondialog.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
|
||||||
<class>KPushButton</class>
|
|
||||||
<extends>QPushButton</extends>
|
|
||||||
<header>kpushbutton.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
|
||||||
<class>TransfersGroupTree</class>
|
|
||||||
<extends>QTreeView</extends>
|
|
||||||
<header>conf/transfersgrouptree.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -1,137 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>DlgIntegration</class>
|
|
||||||
<widget class="QWidget" name="DlgIntegration">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>558</width>
|
|
||||||
<height>293</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="kcfg_AutoPaste">
|
|
||||||
<property name="title">
|
|
||||||
<string>Monitor Clipboard for Files to Download</string>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<layout class="QFormLayout" name="formLayout_2">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="label_5">
|
|
||||||
<property name="text">
|
|
||||||
<string>Case sensitive:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QCheckBox" name="kcfg_AutoPasteCaseSensitive">
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0" colspan="2">
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="KComboBox" name="type"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="KComboBox" name="patternSyntax"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="KLineEdit" name="pattern">
|
|
||||||
<property name="trapEnterKeyEvent" stdset="0">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="showClearButton" stdset="0">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0" colspan="2">
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
|
||||||
<item>
|
|
||||||
<widget class="QTreeView" name="list">
|
|
||||||
<property name="selectionMode">
|
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
|
||||||
</property>
|
|
||||||
<property name="rootIsDecorated">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="uniformRowHeights">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
|
||||||
<item>
|
|
||||||
<widget class="KPushButton" name="add"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="KPushButton" name="remove"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="KPushButton" name="increase">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Increase Priority</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="KPushButton" name="decrease">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Decrease Priority</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>KComboBox</class>
|
|
||||||
<extends>QComboBox</extends>
|
|
||||||
<header>kcombobox.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
|
||||||
<class>KLineEdit</class>
|
|
||||||
<extends>QLineEdit</extends>
|
|
||||||
<header>klineedit.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
|
||||||
<class>KPushButton</class>
|
|
||||||
<extends>QPushButton</extends>
|
|
||||||
<header>kpushbutton.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -1,184 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>DlgNetwork</class>
|
|
||||||
<widget class="QWidget" name="DlgNetwork">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>349</width>
|
|
||||||
<height>437</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<layout class="QFormLayout" name="formLayout_3">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="lbl_maxnum">
|
|
||||||
<property name="text">
|
|
||||||
<string>Maximum downloads per group:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_MaxConnections">
|
|
||||||
<property name="specialValueText">
|
|
||||||
<string comment="no limit for maximum downloads has been set">No limit</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="kcfg_SpeedLimit">
|
|
||||||
<property name="title">
|
|
||||||
<string>Speed Limit</string>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<layout class="QFormLayout" name="formLayout_2">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="dllimitlb">
|
|
||||||
<property name="text">
|
|
||||||
<string>Global &download limit:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>kcfg_GlobalDownloadLimit</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_GlobalDownloadLimit">
|
|
||||||
<property name="suffix">
|
|
||||||
<string> KiB/s</string>
|
|
||||||
</property>
|
|
||||||
<property name="maximum">
|
|
||||||
<number>1000000</number>
|
|
||||||
</property>
|
|
||||||
<property name="singleStep">
|
|
||||||
<number>5</number>
|
|
||||||
</property>
|
|
||||||
<property name="value">
|
|
||||||
<number>10</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>Global &upload limit:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>kcfg_GlobalUploadLimit</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_GlobalUploadLimit">
|
|
||||||
<property name="suffix">
|
|
||||||
<string> KiB/s</string>
|
|
||||||
</property>
|
|
||||||
<property name="maximum">
|
|
||||||
<number>1000000</number>
|
|
||||||
</property>
|
|
||||||
<property name="singleStep">
|
|
||||||
<number>5</number>
|
|
||||||
</property>
|
|
||||||
<property name="value">
|
|
||||||
<number>10</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="lb_per_transfer">
|
|
||||||
<property name="text">
|
|
||||||
<string>Per transfer:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_TransferSpeedLimit">
|
|
||||||
<property name="suffix">
|
|
||||||
<string> KiB/s</string>
|
|
||||||
</property>
|
|
||||||
<property name="maximum">
|
|
||||||
<number>1000000</number>
|
|
||||||
</property>
|
|
||||||
<property name="singleStep">
|
|
||||||
<number>5</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="kcfg_ReconnectOnBroken">
|
|
||||||
<property name="title">
|
|
||||||
<string>Reconnect on Broken Connection</string>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<layout class="QFormLayout" name="formLayout">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="lb_retries_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>Number of retries:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_ReconnectRetries">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="lb_after_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>Retry after:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_ReconnectDelay">
|
|
||||||
<property name="suffix">
|
|
||||||
<string> sec</string>
|
|
||||||
</property>
|
|
||||||
<property name="minimum">
|
|
||||||
<number>10</number>
|
|
||||||
</property>
|
|
||||||
<property name="maximum">
|
|
||||||
<number>86400</number>
|
|
||||||
</property>
|
|
||||||
<property name="singleStep">
|
|
||||||
<number>5</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Expanding</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>200</width>
|
|
||||||
<height>16</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -1,78 +0,0 @@
|
||||||
/* This file is part of the KDE project
|
|
||||||
|
|
||||||
Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "dlgwebinterface.h"
|
|
||||||
|
|
||||||
#include "core/kget.h"
|
|
||||||
#include "mainwindow.h"
|
|
||||||
#include "extensions/webinterface/httpserver.h"
|
|
||||||
#include "settings.h"
|
|
||||||
|
|
||||||
#include <KMessageBox>
|
|
||||||
#include <KLocale>
|
|
||||||
|
|
||||||
DlgWebinterface::DlgWebinterface(KDialog *parent)
|
|
||||||
: QWidget(parent),
|
|
||||||
m_passwdstore(nullptr)
|
|
||||||
{
|
|
||||||
setupUi(this);
|
|
||||||
|
|
||||||
readConfig();
|
|
||||||
|
|
||||||
connect(parent, SIGNAL(accepted()), SLOT(saveSettings()));
|
|
||||||
connect(webinterfacePwd, SIGNAL(textChanged(QString)), SIGNAL(changed()));
|
|
||||||
}
|
|
||||||
|
|
||||||
DlgWebinterface::~DlgWebinterface()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void DlgWebinterface::readConfig()
|
|
||||||
{
|
|
||||||
if (Settings::webinterfaceEnabled()) {
|
|
||||||
if (!m_passwdstore) {
|
|
||||||
m_passwdstore = new KPasswdStore(this);
|
|
||||||
m_passwdstore->setStoreID("KGet");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_passwdstore->openStore(winId())) {
|
|
||||||
webinterfacePwd->setText(m_passwdstore->getPasswd("Webinterface", winId()));
|
|
||||||
} else {
|
|
||||||
KMessageBox::error(nullptr, i18n("Could not open KPasswdStore"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString webaddress;
|
|
||||||
if (KGet::m_mainWindow && KGet::m_mainWindow->m_webinterface) {
|
|
||||||
webaddress = KGet::m_mainWindow->m_webinterface->address();
|
|
||||||
}
|
|
||||||
if (!webaddress.isEmpty()) {
|
|
||||||
serverLabel->setText(i18n("<html>The server can be accessed at <a href=\"%1\">%1</a>.</html>", webaddress));
|
|
||||||
} else {
|
|
||||||
serverLabel->setText(QString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DlgWebinterface::saveSettings()
|
|
||||||
{
|
|
||||||
if (kcfg_WebinterfaceEnabled->isChecked()) {
|
|
||||||
if (!m_passwdstore) {
|
|
||||||
m_passwdstore = new KPasswdStore(this);
|
|
||||||
m_passwdstore->setStoreID("KGet");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_passwdstore->openStore(winId())) {
|
|
||||||
m_passwdstore->storePasswd("Webinterface", webinterfacePwd->text(), winId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emit saved();
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "moc_dlgwebinterface.cpp"
|
|
|
@ -1,40 +0,0 @@
|
||||||
/* This file is part of the KDE project
|
|
||||||
|
|
||||||
Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DLGWEBINTERFACE_H
|
|
||||||
#define DLGWEBINTERFACE_H
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <KDialog>
|
|
||||||
#include <kpasswdstore.h>
|
|
||||||
|
|
||||||
#include "ui_dlgwebinterface.h"
|
|
||||||
|
|
||||||
class DlgWebinterface : public QWidget, public Ui::DlgWebinterface
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
DlgWebinterface(KDialog *parent = 0);
|
|
||||||
~DlgWebinterface();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void changed();
|
|
||||||
void saved();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void readConfig();
|
|
||||||
void saveSettings();
|
|
||||||
|
|
||||||
private:
|
|
||||||
KPasswdStore *m_passwdstore;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,113 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>DlgWebinterface</class>
|
|
||||||
<widget class="QWidget" name="DlgWebinterface">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>400</width>
|
|
||||||
<height>389</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<property name="margin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="kcfg_WebinterfaceEnabled">
|
|
||||||
<property name="title">
|
|
||||||
<string>Enable Web Interface</string>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<layout class="QFormLayout" name="formLayout">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="portLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Port:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QSpinBox" name="kcfg_WebinterfacePort">
|
|
||||||
<property name="maximum">
|
|
||||||
<number>100000</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="userLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>User:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="KLineEdit" name="kcfg_WebinterfaceUser">
|
|
||||||
<property name="showClearButton" stdset="0">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="passwordLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Password:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="KLineEdit" name="webinterfacePwd">
|
|
||||||
<property name="showClearButton" stdset="0">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="passwordMode">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="serverLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string></string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignHCenter|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
<property name="openExternalLinks">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>KLineEdit</class>
|
|
||||||
<extends>QLineEdit</extends>
|
|
||||||
<header>klineedit.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -1,131 +0,0 @@
|
||||||
/***************************************************************************
|
|
||||||
* Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net> *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the *
|
|
||||||
* Free Software Foundation, Inc., *
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
#include "integrationpreferences.h"
|
|
||||||
#include "autopastemodel.h"
|
|
||||||
#include "settings.h"
|
|
||||||
|
|
||||||
#include <KConfigDialog>
|
|
||||||
#include <KLocale>
|
|
||||||
|
|
||||||
IntegrationPreferences::IntegrationPreferences(KConfigDialog *parent, Qt::WindowFlags f)
|
|
||||||
: QWidget(parent, f)
|
|
||||||
{
|
|
||||||
ui.setupUi(this);
|
|
||||||
|
|
||||||
//AutoPaste stuff
|
|
||||||
ui.type->addItem(KIcon("list-add"), i18n("Include"), AutoPasteModel::Include);
|
|
||||||
ui.type->addItem(KIcon("list-remove"), i18n("Exclude"), AutoPasteModel::Exclude);
|
|
||||||
|
|
||||||
ui.patternSyntax->addItem(i18n("Escape sequences"), AutoPasteModel::Wildcard);
|
|
||||||
ui.patternSyntax->addItem(i18n("Regular expression"), AutoPasteModel::RegExp);
|
|
||||||
|
|
||||||
ui.add->setGuiItem(KStandardGuiItem::add());
|
|
||||||
ui.remove->setGuiItem(KStandardGuiItem::remove());
|
|
||||||
ui.increase->setIcon(KIcon("arrow-up"));
|
|
||||||
ui.decrease->setIcon(KIcon("arrow-down"));
|
|
||||||
|
|
||||||
m_model = new AutoPasteModel(this);
|
|
||||||
m_model->load();
|
|
||||||
ui.list->setModel(m_model);
|
|
||||||
AutoPasteDelegate *delegate = new AutoPasteDelegate(ui.type->model(), ui.patternSyntax->model(), this);
|
|
||||||
ui.list->setItemDelegate(delegate);
|
|
||||||
|
|
||||||
QByteArray loadedState = QByteArray::fromBase64(Settings::autoPasteHeaderState().toAscii());
|
|
||||||
if (Settings::autoPasteHeaderState().isEmpty()) {
|
|
||||||
ui.list->resizeColumnToContents(AutoPasteModel::Type);
|
|
||||||
} else if (!loadedState.isNull()) {
|
|
||||||
ui.list->header()->restoreState(loadedState);
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
|
|
||||||
connect(ui.list->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotUpdateButtons()));
|
|
||||||
connect(ui.pattern, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateButtons()));
|
|
||||||
connect(ui.pattern, SIGNAL(returnPressed(QString)), this, SLOT(slotAddItem()));
|
|
||||||
connect(ui.add, SIGNAL(clicked()), this, SLOT(slotAddItem()));
|
|
||||||
connect(ui.remove, SIGNAL(clicked()), this, SLOT(slotRemoveItem()));
|
|
||||||
connect(ui.increase, SIGNAL(clicked()), this, SLOT(slotIncreasePriority()));
|
|
||||||
connect(ui.decrease, SIGNAL(clicked()), this, SLOT(slotDecreasePriority()));
|
|
||||||
connect(parent, SIGNAL(rejected()), m_model, SLOT(load()));
|
|
||||||
connect(parent, SIGNAL(applyClicked()), m_model, SLOT(save()));
|
|
||||||
connect(parent, SIGNAL(okClicked()), m_model, SLOT(save()));
|
|
||||||
connect(parent, SIGNAL(defaultClicked()), m_model, SLOT(resetDefaults()));
|
|
||||||
|
|
||||||
slotUpdateButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
IntegrationPreferences::~IntegrationPreferences()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPreferences::slotUpdateButtons()
|
|
||||||
{
|
|
||||||
ui.add->setEnabled(!ui.pattern->text().isEmpty());
|
|
||||||
ui.remove->setEnabled(ui.list->selectionModel()->hasSelection());
|
|
||||||
|
|
||||||
const QModelIndex index = ui.list->currentIndex();
|
|
||||||
const bool indexValid = index.isValid() && (ui.list->selectionModel()->selectedRows().count() == 1);
|
|
||||||
ui.increase->setEnabled(indexValid && (index.row() > 0));
|
|
||||||
ui.decrease->setEnabled(indexValid && (m_model->rowCount() > (index.row() + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPreferences::slotAddItem()
|
|
||||||
{
|
|
||||||
const QString pattern = ui.pattern->text();
|
|
||||||
if (pattern.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoPasteModel::TypeData type = static_cast<AutoPasteModel::TypeData>(ui.type->itemData(ui.type->currentIndex()).toInt());
|
|
||||||
AutoPasteModel::PatternSyntaxData syntax = static_cast<AutoPasteModel::PatternSyntaxData>(ui.patternSyntax->itemData(ui.patternSyntax->currentIndex()).toInt());
|
|
||||||
m_model->addItem(type, syntax, pattern);
|
|
||||||
|
|
||||||
ui.pattern->clear();
|
|
||||||
ui.pattern->setFocus();
|
|
||||||
emit changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPreferences::slotRemoveItem()
|
|
||||||
{
|
|
||||||
QItemSelectionModel *selection = ui.list->selectionModel();
|
|
||||||
if (selection->hasSelection()) {
|
|
||||||
while (selection->selectedRows().count()) {
|
|
||||||
const QModelIndex index = selection->selectedRows().first();
|
|
||||||
m_model->removeRow(index.row());
|
|
||||||
}
|
|
||||||
emit changed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPreferences::slotIncreasePriority()
|
|
||||||
{
|
|
||||||
const int row = ui.list->currentIndex().row();
|
|
||||||
m_model->moveItem(row, row - 1);
|
|
||||||
slotUpdateButtons();
|
|
||||||
emit changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPreferences::slotDecreasePriority()
|
|
||||||
{
|
|
||||||
const int row = ui.list->currentIndex().row();
|
|
||||||
m_model->moveItem(row, row + 2);
|
|
||||||
slotUpdateButtons();
|
|
||||||
emit changed();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
/***************************************************************************
|
|
||||||
* Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net> *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the *
|
|
||||||
* Free Software Foundation, Inc., *
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
#ifndef INTEGRATIONPREFERENCES
|
|
||||||
#define INTEGRATIONPREFERENCES
|
|
||||||
|
|
||||||
#include <QtGui/QWidget>
|
|
||||||
|
|
||||||
#include "ui_dlgintegration.h"
|
|
||||||
|
|
||||||
class AutoPasteModel;
|
|
||||||
class KConfigDialog;
|
|
||||||
|
|
||||||
class IntegrationPreferences : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit IntegrationPreferences(KConfigDialog *parent, Qt::WindowFlags f = 0);
|
|
||||||
~IntegrationPreferences();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void slotUpdateButtons();
|
|
||||||
void slotAddItem();
|
|
||||||
void slotRemoveItem();
|
|
||||||
void slotIncreasePriority();
|
|
||||||
void slotDecreasePriority();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
/**
|
|
||||||
* Emitted whenever something changes
|
|
||||||
*/
|
|
||||||
void changed();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::DlgIntegration ui;
|
|
||||||
AutoPasteModel *m_model;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,185 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
|
|
||||||
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
|
|
||||||
|
|
||||||
<include>kdemacros.h</include>
|
|
||||||
<include>KGlobalSettings</include>
|
|
||||||
|
|
||||||
<kcfgfile name="kgetrc"/>
|
|
||||||
|
|
||||||
<group name="Appearance">
|
|
||||||
<entry name="HeaderState" type="String">
|
|
||||||
</entry>
|
|
||||||
<entry name="TransferSettingsHeaderState" type="String">
|
|
||||||
</entry>
|
|
||||||
<entry name="VerificationHeaderState" type="String">
|
|
||||||
</entry>
|
|
||||||
<entry name="AutoPasteHeaderState" type="String">
|
|
||||||
</entry>
|
|
||||||
<entry name="ShowMain" type="Bool">
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="ShowIndividual" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="DockifyIndividual" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="ShowDropTarget" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="AnimateDropTarget" type="Bool">
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group name="Advanced">
|
|
||||||
<entry name="AutoPaste" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="AutoPasteCaseSensitive" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="AutoPastePatterns" type="StringList">
|
|
||||||
<default>*</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="AutoPasteTypes" type="IntList">
|
|
||||||
<default>0</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="AutoPastePatternSyntaxes" type="IntList">
|
|
||||||
<default>0</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="TimedDownload" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="TimedDownloadDateTime" type="DateTime">
|
|
||||||
<default code="true">QDateTime::currentDateTime()</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="TimedDisconnect" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="TimedDisconnectDateTime" type="DateTime">
|
|
||||||
<default code="true">QDateTime::currentDateTime()</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="EnableSystemTray" type="Bool">
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="AfterFinishActionEnabled" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="AfterFinishAction" type="Int">
|
|
||||||
<default>0</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="EnableKUIServerIntegration" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="ExportSingleTransfer" type="Bool">
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="ExportGlobalJob" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="HistoryBackend" type="Int">
|
|
||||||
<default>1</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="StartupAction" type="Int">
|
|
||||||
<default>0</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="FilesAlwaysAsk" type="Bool">
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="FilesAutomaticRename" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="FilesOverwrite" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group name="Network">
|
|
||||||
<entry name="MaxConnections" type="Int">
|
|
||||||
<default>2</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="SpeedLimit" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="TransferSpeedLimit" type="Int">
|
|
||||||
<default>20</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="GlobalDownloadLimit" type="Int">
|
|
||||||
<default>0</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="GlobalUploadLimit" type="Int">
|
|
||||||
<default>0</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="ReconnectOnBroken" type="Bool">
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="ReconnectRetries" type="Int">
|
|
||||||
<default>5</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="ReconnectDelay" type="Int">
|
|
||||||
<default>60</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group name="Webinterface">
|
|
||||||
<entry name="WebinterfaceEnabled" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="WebinterfacePort" type="Int">
|
|
||||||
<default>8080</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="WebinterfaceUser" type="String">
|
|
||||||
<default>admin</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group name="Groups">
|
|
||||||
<entry name="DirectoriesAsSuggestion" type="Bool">
|
|
||||||
<default>false</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="AskForDestination" type="Bool">
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group name="Internal">
|
|
||||||
<!-- NOT CONFIGURABLE -->
|
|
||||||
<entry name="DropPosition" type="Point">
|
|
||||||
<default code="true">QPoint(-1, -1)</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="DropSticky" type="Bool">
|
|
||||||
<default>0</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="FirstRun" type="Bool">
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="LastDirectory" type="Path">
|
|
||||||
<default code="true">KGlobalSettings::downloadPath()</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="LastGroup" type="String">
|
|
||||||
</entry>
|
|
||||||
<entry name="LinkViewFilterPatternSyntax" type="Int">
|
|
||||||
<default>0</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group name="Geometry">
|
|
||||||
<entry name="HistoryColumnWidths" type="IntList">
|
|
||||||
<label>The width of the columns in the history view</label>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group name="Verification">
|
|
||||||
<entry name="ChecksumAutomaticVerification" type="Bool">
|
|
||||||
<default>1</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="ChecksumStrength" type="Int">
|
|
||||||
<default>1</default>
|
|
||||||
</entry>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
</kcfg>
|
|
|
@ -1,49 +0,0 @@
|
||||||
/* This file is part of the KDE project
|
|
||||||
|
|
||||||
Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
#include "pluginselector.h"
|
|
||||||
|
|
||||||
#include "core/kget.h"
|
|
||||||
|
|
||||||
#include <KServiceTypeTrader>
|
|
||||||
#include <KService>
|
|
||||||
#include <KLocale>
|
|
||||||
#include <KPluginInfo>
|
|
||||||
#include <KSharedConfig>
|
|
||||||
#include <KDialog>
|
|
||||||
|
|
||||||
PluginSelector::PluginSelector(KDialog * parent)
|
|
||||||
: KPluginSelector(parent)
|
|
||||||
{
|
|
||||||
KService::List offers = KServiceTypeTrader::self()->query("KGet/Plugin");
|
|
||||||
|
|
||||||
addPlugins(KPluginInfo::fromServices(offers), KPluginSelector::ReadConfigFile, i18n("Plugins"), "Service", KGlobal::config());
|
|
||||||
|
|
||||||
load();
|
|
||||||
|
|
||||||
connect(parent, SIGNAL(accepted()), SLOT(saveState()));
|
|
||||||
connect(parent, SIGNAL(rejected()), SLOT(loadDefaults()));
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginSelector::~PluginSelector()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void PluginSelector::saveState()
|
|
||||||
{
|
|
||||||
save();
|
|
||||||
KGet::loadPlugins();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PluginSelector::loadDefaults()
|
|
||||||
{
|
|
||||||
defaults();
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "moc_pluginselector.cpp"
|
|
|
@ -1,29 +0,0 @@
|
||||||
/* This file is part of the KDE project
|
|
||||||
|
|
||||||
Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
#ifndef PLUGINSELECTOR_H
|
|
||||||
#define PLUGINSELECTOR_H
|
|
||||||
|
|
||||||
#include <KPluginSelector>
|
|
||||||
|
|
||||||
class KDialog;
|
|
||||||
|
|
||||||
class PluginSelector : public KPluginSelector
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
PluginSelector(KDialog * parent);
|
|
||||||
~PluginSelector();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void saveState();
|
|
||||||
void loadDefaults();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,95 +0,0 @@
|
||||||
/* This file is part of the KDE project
|
|
||||||
Copyright (C) 2004 - 2007 KGet Developers <kget@kde.org>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "preferencesdialog.h"
|
|
||||||
#include "core/kget.h"
|
|
||||||
#include "core/transferhistorystore.h"
|
|
||||||
|
|
||||||
#include "ui_dlgappearance.h"
|
|
||||||
#include "ui_dlgnetwork.h"
|
|
||||||
#include "dlgwebinterface.h"
|
|
||||||
|
|
||||||
#include "integrationpreferences.h"
|
|
||||||
#include "transfersgroupwidget.h"
|
|
||||||
#include "pluginselector.h"
|
|
||||||
#include "verificationpreferences.h"
|
|
||||||
|
|
||||||
#include <klocale.h>
|
|
||||||
#include <ktabwidget.h>
|
|
||||||
|
|
||||||
PreferencesDialog::PreferencesDialog(QWidget * parent, KConfigSkeleton * skeleton)
|
|
||||||
: KConfigDialog(parent, "preferences", skeleton)
|
|
||||||
{
|
|
||||||
QWidget *appearance = new QWidget(this);
|
|
||||||
TransfersGroupWidget *groups = new TransfersGroupWidget(this);
|
|
||||||
DlgWebinterface *webinterface = new DlgWebinterface(this);
|
|
||||||
connect(webinterface, SIGNAL(changed()), SLOT(enableApplyButton()));
|
|
||||||
connect(webinterface, SIGNAL(saved()), SLOT(settingsChangedSlot()));
|
|
||||||
QWidget *network = new QWidget(this);
|
|
||||||
QWidget *advanced = new QWidget(this);
|
|
||||||
IntegrationPreferences *integration = new IntegrationPreferences(this);
|
|
||||||
connect(integration, SIGNAL(changed()), SLOT(enableApplyButton()));
|
|
||||||
VerificationPreferences *verification = new VerificationPreferences(this);
|
|
||||||
connect(verification, SIGNAL(changed()), SLOT(enableApplyButton()));
|
|
||||||
PluginSelector * pluginSelector = new PluginSelector(this);
|
|
||||||
connect(pluginSelector, SIGNAL(changed(bool)), SLOT(enableApplyButton()));
|
|
||||||
|
|
||||||
Ui::DlgAppearance dlgApp;
|
|
||||||
Ui::DlgNetwork dlgNet;
|
|
||||||
|
|
||||||
dlgApp.setupUi(appearance);
|
|
||||||
dlgNet.setupUi(network);
|
|
||||||
dlgAdv.setupUi(advanced);
|
|
||||||
|
|
||||||
// history backend entries
|
|
||||||
dlgAdv.kcfg_HistoryBackend->addItem(i18n("Json"), QVariant(TransferHistoryStore::Json));
|
|
||||||
dlgAdv.kcfg_HistoryBackend->addItem(i18n("Xml"), QVariant(TransferHistoryStore::Xml));
|
|
||||||
|
|
||||||
#ifdef HAVE_KWORKSPACE
|
|
||||||
dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Turn Off Computer"), QVariant(KGet::Shutdown));
|
|
||||||
dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Hibernate Computer"), QVariant(KGet::Hibernate));
|
|
||||||
dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Suspend Computer"), QVariant(KGet::Suspend));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// enable or disable the AfterFinishAction depends on the AfterFinishActionEnabled checkbox state
|
|
||||||
dlgAdv.kcfg_AfterFinishAction->setEnabled(dlgAdv.kcfg_AfterFinishActionEnabled->checkState () == Qt::Checked);
|
|
||||||
connect(dlgAdv.kcfg_AfterFinishActionEnabled, SIGNAL(stateChanged(int)),
|
|
||||||
SLOT(slotToggleAfterFinishAction(int)));
|
|
||||||
|
|
||||||
// TODO: remove the following lines as soon as these features are ready
|
|
||||||
dlgNet.lb_per_transfer->setVisible(false);
|
|
||||||
dlgNet.kcfg_TransferSpeedLimit->setVisible(false);
|
|
||||||
|
|
||||||
addPage(appearance, i18n("Appearance"), "preferences-desktop-theme", i18n("Change appearance settings"));
|
|
||||||
addPage(groups, i18n("Groups"), "bookmarks", i18n("Manage the groups"));
|
|
||||||
addPage(network, i18n("Network"), "network-workgroup", i18n("Network and Downloads"));
|
|
||||||
addPage(webinterface, i18n("Web Interface"), "network-workgroup", i18n("Control KGet over a Network or the Internet"));
|
|
||||||
addPage(verification, i18n("Verification"), "document-encrypt", i18n("Verification"));
|
|
||||||
addPage(integration, i18n("Integration"), "applications-other", i18n("Integration of KGet with other applications"));
|
|
||||||
addPage(advanced, i18n("Advanced Options"), "preferences-other", i18n("Advanced Options"));
|
|
||||||
addPage(pluginSelector, i18n("Plugins"), "preferences-plugin", i18n("Transfer Plugins"));
|
|
||||||
|
|
||||||
connect(this, SIGNAL(accepted()), SLOT(disableApplyButton()));
|
|
||||||
connect(this, SIGNAL(rejected()), SLOT(disableApplyButton()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void PreferencesDialog::disableApplyButton()
|
|
||||||
{
|
|
||||||
enableButtonApply(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PreferencesDialog::enableApplyButton()
|
|
||||||
{
|
|
||||||
enableButtonApply(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PreferencesDialog::slotToggleAfterFinishAction(int state)
|
|
||||||
{
|
|
||||||
dlgAdv.kcfg_AfterFinishAction->setEnabled(state == Qt::Checked);
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
/* This file is part of the KDE project
|
|
||||||
Copyright (C) 2004 - 2007 KGet Developers <kget@kde.org>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PREFERENCESDIALOG_H
|
|
||||||
#define PREFERENCESDIALOG_H
|
|
||||||
|
|
||||||
#include "ui_dlgadvanced.h"
|
|
||||||
|
|
||||||
#include <kconfigdialog.h>
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
class KConfigSkeleton;
|
|
||||||
class KTabWidget;
|
|
||||||
|
|
||||||
class PreferencesDialog : public KConfigDialog
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
PreferencesDialog( QWidget * parent, KConfigSkeleton * config );
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void slotToggleAfterFinishAction(int state);
|
|
||||||
void disableApplyButton();
|
|
||||||
void enableApplyButton();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::DlgAdvanced dlgAdv;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,5 +0,0 @@
|
||||||
ClassName=Settings
|
|
||||||
File=kget.kcfg
|
|
||||||
Mutators=true
|
|
||||||
Singleton=true
|
|
||||||
Visibility=KDE_EXPORT
|
|
|
@ -1,150 +0,0 @@
|
||||||
/* This file is part of the KDE project
|
|
||||||
|
|
||||||
Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
|
|
||||||
Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
|
|
||||||
Copyright (C) 2007 Javier Goday <jgoday @ gmail.com>
|
|
||||||
Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
|
|
||||||
Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "transfersgrouptree.h"
|
|
||||||
|
|
||||||
#include "core/kget.h"
|
|
||||||
#include "core/transfertreemodel.h"
|
|
||||||
#include "core/transfertreeselectionmodel.h"
|
|
||||||
|
|
||||||
#include <QtGui/QHeaderView>
|
|
||||||
|
|
||||||
#include <KLineEdit>
|
|
||||||
|
|
||||||
TransfersGroupDelegate::TransfersGroupDelegate(QAbstractItemView *parent)
|
|
||||||
: BasicTransfersViewDelegate(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *TransfersGroupDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (index.column() == TransferTreeModel::Name) {
|
|
||||||
return new KLineEdit(parent);
|
|
||||||
} else {
|
|
||||||
return BasicTransfersViewDelegate::createEditor(parent, option, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransfersGroupDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (index.column() == TransferTreeModel::Name) {
|
|
||||||
KLineEdit *groupEditor = static_cast<KLineEdit*>(editor);
|
|
||||||
groupEditor->setText(index.data().toString());
|
|
||||||
} else {
|
|
||||||
BasicTransfersViewDelegate::setEditorData(editor, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransfersGroupDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (index.column() == TransferTreeModel::Name) {
|
|
||||||
KLineEdit *groupEditor = static_cast<KLineEdit*>(editor);
|
|
||||||
const QString newName = groupEditor->text();
|
|
||||||
const QString oldName = index.data().toString();
|
|
||||||
|
|
||||||
if (!newName.isEmpty()) {
|
|
||||||
foreach (const QString &groupName, KGet::transferGroupNames()) {
|
|
||||||
if (groupName == newName && groupName != oldName) {
|
|
||||||
groupEditor->setText(oldName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
KGet::renameGroup(oldName, newName);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
BasicTransfersViewDelegate::setModelData(editor, model, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TransfersGroupTree::TransfersGroupTree(QWidget *parent)
|
|
||||||
: QTreeView(parent)
|
|
||||||
{
|
|
||||||
setItemDelegate(new TransfersGroupDelegate(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransfersGroupTree::setModel(QAbstractItemModel *model)
|
|
||||||
{
|
|
||||||
QTreeView::setModel(model);
|
|
||||||
|
|
||||||
int nGroups = model->rowCount(QModelIndex());
|
|
||||||
for (int i = 0; i < nGroups; i++) {
|
|
||||||
kDebug() << "openEditor for row " << i;
|
|
||||||
openPersistentEditor(model->index(i, TransferTreeModel::Status, QModelIndex()));
|
|
||||||
}
|
|
||||||
|
|
||||||
setColumnWidth(0 , 250);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransfersGroupTree::rowsInserted(const QModelIndex &parent, int start, int end)
|
|
||||||
{
|
|
||||||
if (!parent.isValid()) {
|
|
||||||
for (int i = start; i <= end; ++i) {
|
|
||||||
kDebug() << "openEditor for row " << i;
|
|
||||||
openPersistentEditor(model()->index(i, TransferTreeModel::Status, parent));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QTreeView::rowsInserted(parent, start, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransfersGroupTree::editCurrent()
|
|
||||||
{
|
|
||||||
QTreeView::edit(currentIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransfersGroupTree::addGroup()
|
|
||||||
{
|
|
||||||
QString groupName(i18n("New Group"));
|
|
||||||
int i=0;
|
|
||||||
|
|
||||||
while(KGet::transferGroupNames().contains(groupName))
|
|
||||||
{
|
|
||||||
groupName = i18n("New Group") + QString::number(++i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (KGet::addGroup(groupName)) {
|
|
||||||
QModelIndex index = model()->index(model()->rowCount() - 1, 0);
|
|
||||||
setCurrentIndex(index);
|
|
||||||
editCurrent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransfersGroupTree::deleteSelectedGroup()
|
|
||||||
{
|
|
||||||
KGet::delGroups(KGet::selectedTransferGroups());
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransfersGroupTree::renameSelectedGroup()
|
|
||||||
{
|
|
||||||
if(currentIndex().isValid())
|
|
||||||
editCurrent();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransfersGroupTree::changeIcon(const QString &icon)
|
|
||||||
{
|
|
||||||
TransferTreeSelectionModel *selModel = KGet::selectionModel();
|
|
||||||
|
|
||||||
QModelIndexList indexList = selModel->selectedRows();
|
|
||||||
|
|
||||||
if (!icon.isEmpty())
|
|
||||||
{
|
|
||||||
foreach (TransferGroupHandler *group, KGet::selectedTransferGroups())
|
|
||||||
{
|
|
||||||
group->setIconName(icon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emit dataChanged(indexList.first(),indexList.last());
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
/* This file is part of the KDE project
|
|
||||||
|
|
||||||
Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
|
|
||||||
Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
|
|
||||||
Copyright (C) 2007 Javier Goday <jgoday @ gmail.com>
|
|
||||||
Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TRANSFERSGROUPTREE_H
|
|
||||||
#define TRANSFERSGROUPTREE_H
|
|
||||||
|
|
||||||
#include "ui/transfersviewdelegate.h"
|
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
|
||||||
#include <QTreeView>
|
|
||||||
|
|
||||||
class GroupStatusEditor;
|
|
||||||
|
|
||||||
class TransfersGroupDelegate : public BasicTransfersViewDelegate
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
TransfersGroupDelegate(QAbstractItemView *parent);
|
|
||||||
|
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
|
||||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
|
||||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TransfersGroupTree : public QTreeView
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
TransfersGroupTree(QWidget *parent=0);
|
|
||||||
void setModel(QAbstractItemModel *model);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void editCurrent();
|
|
||||||
void addGroup();
|
|
||||||
void deleteSelectedGroup();
|
|
||||||
void renameSelectedGroup();
|
|
||||||
void changeIcon(const QString &icon);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void rowsInserted(const QModelIndex &index, int start, int end);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue