pax_global_header 0000666 0000000 0000000 00000000064 13251276421 0014515 g ustar 00root root 0000000 0000000 52 comment=e55103c466f62a24ec3507ae8291572057048e56
phototonic-2.1/ 0000775 0000000 0000000 00000000000 13251276421 0013545 5 ustar 00root root 0000000 0000000 phototonic-2.1/.gitignore 0000664 0000000 0000000 00000000137 13251276421 0015536 0 ustar 00root root 0000000 0000000 *.exe
phototonic
moc_*.cpp
*.o
*.obj
.qmake.stash
qrc_phototonic.cpp
*.pro.user
Makefile
mingw
phototonic-2.1/.travis.yml 0000664 0000000 0000000 00000000513 13251276421 0015655 0 ustar 00root root 0000000 0000000 os: linux
dist: trusty
sudo: true
compiler:
- gcc
addons:
apt:
packages:
- libexiv2-dev
before_install:
- sudo add-apt-repository ppa:beineri/opt-qt58-trusty -y
- sudo apt-get update -q
- sudo apt-get install -y qt58-meta-minimal
script:
- source /opt/qt58/bin/qt58-env.sh
- qmake
- make -j2
phototonic-2.1/Bookmarks.cpp 0000664 0000000 0000000 00000005355 13251276421 0016211 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "Bookmarks.h"
BookMarks::BookMarks(QWidget *parent) : QTreeWidget(parent) {
setAcceptDrops(true);
setDragEnabled(false);
setDragDropMode(QAbstractItemView::DropOnly);
connect(this, SIGNAL(expanded(
const QModelIndex &)),
this, SLOT(resizeTreeColumn(
const QModelIndex &)));
connect(this, SIGNAL(collapsed(
const QModelIndex &)),
this, SLOT(resizeTreeColumn(
const QModelIndex &)));
setColumnCount(1);
setHeaderHidden(true);
reloadBookmarks();
}
void BookMarks::reloadBookmarks() {
clear();
QSetIterator it(Settings::bookmarkPaths);
while (it.hasNext()) {
QString itemPath = it.next();
QTreeWidgetItem *item = new QTreeWidgetItem(this);
item->setText(0, QFileInfo(itemPath).fileName());
item->setIcon(0, QIcon(":/images/bookmarks.png"));
item->setToolTip(0, itemPath);
insertTopLevelItem(0, item);
}
}
void BookMarks::resizeTreeColumn(const QModelIndex &) {
resizeColumnToContents(0);
}
void BookMarks::removeBookmark() {
if (selectedItems().size() == 1) {
Settings::bookmarkPaths.remove(selectedItems().at(0)->toolTip(0));
reloadBookmarks();
}
}
void BookMarks::dragEnterEvent(QDragEnterEvent *event) {
QModelIndexList selectedDirs = selectionModel()->selectedRows();
if (selectedDirs.size() > 0) {
dndOrigSelection = selectedDirs[0];
}
event->acceptProposedAction();
}
void BookMarks::dragMoveEvent(QDragMoveEvent *event) {
setCurrentIndex(indexAt(event->pos()));
}
void BookMarks::dropEvent(QDropEvent *event) {
if (event->source()) {
QString fileSystemTreeStr("FileSystemTree");
bool dirOp = (event->source()->metaObject()->className() == fileSystemTreeStr);
emit dropOp(event->keyboardModifiers(), dirOp, event->mimeData()->urls().at(0).toLocalFile());
}
}
phototonic-2.1/Bookmarks.h 0000664 0000000 0000000 00000002562 13251276421 0015653 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef BOOKMARKS_H
#define BOOKMARKS_H
#include
#include "Settings.h"
class BookMarks : public QTreeWidget {
Q_OBJECT
public:
BookMarks(QWidget *parent);
void reloadBookmarks();
public slots:
void removeBookmark();
private:
QModelIndex dndOrigSelection;
private slots:
void resizeTreeColumn(const QModelIndex &);
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
signals:
void dropOp(Qt::KeyboardModifiers keyMods, bool dirOp, QString cpMvDirPath);
};
#endif // BOOKMARKS_H
phototonic-2.1/COPYING 0000664 0000000 0000000 00000104513 13251276421 0014604 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
phototonic-2.1/ColorsDialog.cpp 0000664 0000000 0000000 00000026675 13251276421 0016652 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include
#include
#include
#include
#include
#include "ImageViewer.h"
#include "ColorsDialog.h"
#include "Settings.h"
ColorsDialog::ColorsDialog(QWidget *parent, ImageViewer *imageViewer) : QDialog(parent) {
setWindowTitle(tr("Colors"));
setWindowIcon(QIcon(":/images/colors.png"));
resize(350, 300);
this->imageViewer = imageViewer;
QHBoxLayout *buttonsHbox = new QHBoxLayout;
QPushButton *resetButton = new QPushButton(tr("Reset"));
resetButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(resetButton, SIGNAL(clicked()), this, SLOT(reset()));
buttonsHbox->addWidget(resetButton, 0, Qt::AlignLeft);
QPushButton *okButton = new QPushButton(tr("OK"));
okButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(okButton, SIGNAL(clicked()), this, SLOT(ok()));
buttonsHbox->addWidget(okButton, 0, Qt::AlignRight);
okButton->setDefault(true);
/* hue saturation */
QLabel *hueLab = new QLabel(tr("Hue"));
QLabel *satLab = new QLabel(tr("Saturation"));
QLabel *lightLab = new QLabel(tr("Lightness"));
hueSlider = new QSlider(Qt::Horizontal);
hueSlider->setTickPosition(QSlider::TicksAbove);
hueSlider->setTickInterval(25);
hueSlider->setRange(-100, 100);
hueSlider->setTracking(false);
connect(hueSlider, SIGNAL(valueChanged(int)), this, SLOT(applyColors(int)));
colorizeCheckBox = new QCheckBox(tr("Colorize"), this);
colorizeCheckBox->setCheckState(Settings::colorizeEnabled ? Qt::Checked : Qt::Unchecked);
connect(colorizeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableColorize(int)));
rNegateCheckBox = new QCheckBox(tr("Negative"), this);
rNegateCheckBox->setCheckState(Settings::rNegateEnabled ? Qt::Checked : Qt::Unchecked);
connect(rNegateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(redNegative(int)));
gNegateCheckBox = new QCheckBox(tr("Negative"), this);
gNegateCheckBox->setCheckState(Settings::gNegateEnabled ? Qt::Checked : Qt::Unchecked);
connect(gNegateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(greenNegative(int)));
bNegateCheckBox = new QCheckBox(tr("Negative"), this);
bNegateCheckBox->setCheckState(Settings::bNegateEnabled ? Qt::Checked : Qt::Unchecked);
connect(bNegateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(blueNegative(int)));
saturationSlider = new QSlider(Qt::Horizontal);
saturationSlider->setTickPosition(QSlider::TicksAbove);
saturationSlider->setTickInterval(25);
saturationSlider->setRange(-100, 100);
saturationSlider->setTracking(false);
connect(saturationSlider, SIGNAL(valueChanged(int)), this, SLOT(applyColors(int)));
lightnessSlider = new QSlider(Qt::Horizontal);
lightnessSlider->setTickPosition(QSlider::TicksAbove);
lightnessSlider->setTickInterval(25);
lightnessSlider->setRange(-100, 100);
lightnessSlider->setTracking(false);
connect(lightnessSlider, SIGNAL(valueChanged(int)), this, SLOT(applyColors(int)));
QHBoxLayout *channelsHbox = new QHBoxLayout;
redCheckBox = new QCheckBox(tr("Red"));
redCheckBox->setCheckable(true);
redCheckBox->setChecked(Settings::hueRedChannel);
connect(redCheckBox, SIGNAL(clicked()), this, SLOT(setRedChannel()));
channelsHbox->addWidget(redCheckBox, 0, Qt::AlignLeft);
greenCheckBox = new QCheckBox(tr("Green"));
greenCheckBox->setCheckable(true);
greenCheckBox->setChecked(Settings::hueGreenChannel);
connect(greenCheckBox, SIGNAL(clicked()), this, SLOT(setGreenChannel()));
channelsHbox->addWidget(greenCheckBox, 0, Qt::AlignLeft);
blueCheckBox = new QCheckBox(tr("Blue"));
blueCheckBox->setCheckable(true);
blueCheckBox->setChecked(Settings::hueBlueChannel);
connect(blueCheckBox, SIGNAL(clicked()), this, SLOT(setBlueChannel()));
channelsHbox->addWidget(blueCheckBox, 0, Qt::AlignLeft);
channelsHbox->addStretch(1);
QGridLayout *hueSatLay = new QGridLayout;
hueSatLay->addWidget(hueLab, 1, 0, 1, 1);
hueSatLay->addWidget(hueSlider, 1, 1, 1, 1);
hueSatLay->addWidget(colorizeCheckBox, 2, 1, 1, 1);
hueSatLay->addWidget(satLab, 3, 0, 1, 1);
hueSatLay->addWidget(saturationSlider, 3, 1, 1, 1);
hueSatLay->addWidget(lightLab, 4, 0, 1, 1);
hueSatLay->addWidget(lightnessSlider, 4, 1, 1, 1);
hueSatLay->setColumnMinimumWidth(0, 70);
QGroupBox *hueSatGroup = new QGroupBox(tr("Hue and Saturation"));
hueSatGroup->setLayout(hueSatLay);
QGridLayout *channelsLay = new QGridLayout;
channelsLay->addLayout(channelsHbox, 5, 1, 1, 1);
channelsLay->setColumnMinimumWidth(0, 70);
QGroupBox *channelsGroup = new QGroupBox(tr("Affected Channels"));
channelsGroup->setLayout(channelsLay);
/* brightness contrast */
QLabel *brightLab = new QLabel(tr("Brightness"));
QLabel *contrastLab = new QLabel(tr("Contrast"));
brightSlider = new QSlider(Qt::Horizontal);
brightSlider->setTickPosition(QSlider::TicksAbove);
brightSlider->setTickInterval(25);
brightSlider->setRange(-100, 100);
brightSlider->setTracking(false);
connect(brightSlider, SIGNAL(valueChanged(int)), this, SLOT(applyColors(int)));
contrastSlider = new QSlider(Qt::Horizontal);
contrastSlider->setTickPosition(QSlider::TicksAbove);
contrastSlider->setTickInterval(25);
contrastSlider->setRange(-100, 100);
contrastSlider->setTracking(false);
contrastSlider->setInvertedAppearance(true);
connect(contrastSlider, SIGNAL(valueChanged(int)), this, SLOT(applyColors(int)));
QGridLayout *brightContrastbox = new QGridLayout;
brightContrastbox->addWidget(brightLab, 1, 0, 1, 1);
brightContrastbox->addWidget(brightSlider, 1, 1, 1, 1);
brightContrastbox->addWidget(contrastLab, 2, 0, 1, 1);
brightContrastbox->addWidget(contrastSlider, 2, 1, 1, 1);
brightContrastbox->setColumnMinimumWidth(0, 70);
QGroupBox *brightContrastGroup = new QGroupBox(tr("Brightness and Contrast"));
brightContrastGroup->setLayout(brightContrastbox);
/* Channel mixer */
QLabel *redLab = new QLabel(tr("Red"));
redSlider = new QSlider(Qt::Horizontal);
redSlider->setTickPosition(QSlider::TicksAbove);
redSlider->setTickInterval(25);
redSlider->setRange(-100, 100);
redSlider->setTracking(false);
connect(redSlider, SIGNAL(valueChanged(int)), this, SLOT(applyColors(int)));
QLabel *greenLab = new QLabel(tr("Green"));
greenSlider = new QSlider(Qt::Horizontal);
greenSlider->setTickPosition(QSlider::TicksAbove);
greenSlider->setTickInterval(25);
greenSlider->setRange(-100, 100);
greenSlider->setTracking(false);
connect(greenSlider, SIGNAL(valueChanged(int)), this, SLOT(applyColors(int)));
QLabel *blueLab = new QLabel(tr("Blue"));
blueSlider = new QSlider(Qt::Horizontal);
blueSlider->setTickPosition(QSlider::TicksAbove);
blueSlider->setTickInterval(25);
blueSlider->setRange(-100, 100);
blueSlider->setTracking(false);
connect(blueSlider, SIGNAL(valueChanged(int)), this, SLOT(applyColors(int)));
QGridLayout *channelMixbox = new QGridLayout;
channelMixbox->addWidget(redLab, 1, 0, 1, 1);
channelMixbox->addWidget(redSlider, 1, 1, 1, 1);
channelMixbox->addWidget(rNegateCheckBox, 1, 2, 1, 1);
channelMixbox->addWidget(greenLab, 2, 0, 1, 1);
channelMixbox->addWidget(greenSlider, 2, 1, 1, 1);
channelMixbox->addWidget(gNegateCheckBox, 2, 2, 1, 1);
channelMixbox->addWidget(blueLab, 3, 0, 1, 1);
channelMixbox->addWidget(blueSlider, 3, 1, 1, 1);
channelMixbox->addWidget(bNegateCheckBox, 3, 2, 1, 1);
channelMixbox->setColumnMinimumWidth(0, 70);
QGroupBox *channelMixGroup = new QGroupBox(tr("Color Balance"));
channelMixGroup->setLayout(channelMixbox);
QVBoxLayout *mainVbox = new QVBoxLayout;
mainVbox->addWidget(brightContrastGroup);
mainVbox->addWidget(channelMixGroup);
mainVbox->addWidget(hueSatGroup);
mainVbox->addWidget(channelsGroup);
mainVbox->addStretch(1);
mainVbox->addLayout(buttonsHbox);
setLayout(mainVbox);
applyColors(0);
}
void ColorsDialog::applyColors(int) {
if (brightSlider->value() >= 0) {
Settings::brightVal = (brightSlider->value() * 500 / 100) + 100;
} else {
Settings::brightVal = brightSlider->value() + 100;
}
if (contrastSlider->value() >= 0) {
Settings::contrastVal = (contrastSlider->value() * 79 / 100) + 78;
} else {
Settings::contrastVal = contrastSlider->value() + 79;
}
Settings::hueVal = hueSlider->value() * 127 / 100;
if (saturationSlider->value() >= 0) {
Settings::saturationVal = (saturationSlider->value() * 500 / 100) + 100;
} else {
Settings::saturationVal = saturationSlider->value() + 100;
}
if (lightnessSlider->value() >= 0) {
Settings::lightnessVal = (lightnessSlider->value() * 200 / 100) + 100;
} else {
Settings::lightnessVal = lightnessSlider->value() + 100;
}
Settings::redVal = redSlider->value();
Settings::greenVal = greenSlider->value();
Settings::blueVal = blueSlider->value();
imageViewer->refresh();
}
void ColorsDialog::ok() {
Settings::dialogLastX = pos().x();
Settings::dialogLastY = pos().y();
accept();
}
void ColorsDialog::reset() {
hueSlider->setValue(0);
colorizeCheckBox->setChecked(false);
rNegateCheckBox->setChecked(false);
gNegateCheckBox->setChecked(false);
bNegateCheckBox->setChecked(false);
saturationSlider->setValue(0);
lightnessSlider->setValue(0);
redCheckBox->setChecked(true);
greenCheckBox->setChecked(true);
blueCheckBox->setChecked(true);
Settings::hueRedChannel = true;
Settings::hueGreenChannel = true;
Settings::hueBlueChannel = true;
contrastSlider->setValue(0);
brightSlider->setValue(0);
redSlider->setValue(0);
greenSlider->setValue(0);
blueSlider->setValue(0);
imageViewer->refresh();
}
void ColorsDialog::enableColorize(int state) {
Settings::colorizeEnabled = state;
imageViewer->refresh();
}
void ColorsDialog::redNegative(int state) {
Settings::rNegateEnabled = state;
imageViewer->refresh();
}
void ColorsDialog::greenNegative(int state) {
Settings::gNegateEnabled = state;
imageViewer->refresh();
}
void ColorsDialog::blueNegative(int state) {
Settings::bNegateEnabled = state;
imageViewer->refresh();
}
void ColorsDialog::setRedChannel() {
Settings::hueRedChannel = redCheckBox->isChecked();
imageViewer->refresh();
}
void ColorsDialog::setGreenChannel() {
Settings::hueGreenChannel = greenCheckBox->isChecked();
imageViewer->refresh();
}
void ColorsDialog::setBlueChannel() {
Settings::hueBlueChannel = blueCheckBox->isChecked();
imageViewer->refresh();
}
phototonic-2.1/ColorsDialog.h 0000664 0000000 0000000 00000003411 13251276421 0016276 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef COLORS_DIALOG_H
#define COLORS_DIALOG_H
#include
#include "ImageViewer.h"
class ColorsDialog : public QDialog {
Q_OBJECT
public:
ColorsDialog(QWidget *parent, ImageViewer *imageViewer);
public slots:
void ok();
void reset();
void enableColorize(int state);
void redNegative(int state);
void greenNegative(int state);
void blueNegative(int state);
void setRedChannel();
void setGreenChannel();
void setBlueChannel();
void applyColors(int value);
private:
ImageViewer *imageViewer;
QSlider *hueSlider;
QCheckBox *colorizeCheckBox;
QSlider *saturationSlider;
QSlider *lightnessSlider;
QCheckBox *redCheckBox;
QCheckBox *greenCheckBox;
QCheckBox *blueCheckBox;
QSlider *brightSlider;
QSlider *contrastSlider;
QSlider *redSlider;
QSlider *greenSlider;
QSlider *blueSlider;
QCheckBox *rNegateCheckBox;
QCheckBox *gNegateCheckBox;
QCheckBox *bNegateCheckBox;
};
#endif // COLORS_DIALOG_H phototonic-2.1/CopyMoveDialog.cpp 0000664 0000000 0000000 00000011420 13251276421 0017130 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "CopyMoveDialog.h"
static QString autoRename(QString &destDir, QString &currFile) {
int extSep = currFile.lastIndexOf(".");
QString nameOnly = currFile.left(extSep);
QString extOnly = currFile.right(currFile.size() - extSep - 1);
QString newFile;
int idx = 1;
do {
newFile = QString(nameOnly + "_copy_%1." + extOnly).arg(idx);
++idx;
} while (idx && (QFile::exists(destDir + QDir::separator() + newFile)));
return newFile;
}
int CopyMoveDialog::copyOrMoveFile(bool isCopy, QString &srcFile, QString &srcPath, QString &dstPath, QString &dstDir) {
int res;
if (isCopy) {
res = QFile::copy(srcPath, dstPath);
} else {
res = QFile::rename(srcPath, dstPath);
}
if (!res && QFile::exists(dstPath)) {
QString newName = autoRename(dstDir, srcFile);
QString newDestPath = dstDir + QDir::separator() + newName;
if (isCopy) {
res = QFile::copy(srcPath, newDestPath);
} else {
res = QFile::rename(srcPath, newDestPath);
}
dstPath = newDestPath;
}
return res;
}
CopyMoveDialog::CopyMoveDialog(QWidget *parent) : QDialog(parent) {
abortOp = false;
opLabel = new QLabel("");
cancelButton = new QPushButton(tr("Cancel"));
cancelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(cancelButton, SIGNAL(clicked()), this, SLOT(abort()));
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(opLabel);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
buttonsLayout->addWidget(cancelButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
mainLayout->addLayout(buttonsLayout, Qt::AlignRight);
setLayout(mainLayout);
}
void CopyMoveDialog::exec(ThumbsViewer *thumbView, QString &destDir, bool pasteInCurrDir) {
int res = 0;
QString sourceFile;
QFileInfo fileInfo;
QString currFile;
QString destFile;
int tn;
show();
if (pasteInCurrDir) {
for (tn = 0; tn < Settings::copyCutFileList.size(); ++tn) {
sourceFile = Settings::copyCutFileList[tn];
fileInfo = QFileInfo(sourceFile);
currFile = fileInfo.fileName();
destFile = destDir + QDir::separator() + currFile;
opLabel->setText((Settings::isCopyOperation ? tr("Copying \"%1\" to \"%2\".") : tr("Moving \"%1\" to \"%2\"."))
.arg(sourceFile).arg(destFile));
QApplication::processEvents();
res = CopyMoveDialog::copyOrMoveFile(Settings::isCopyOperation, currFile, sourceFile, destFile, destDir);
if (!res || abortOp) {
break;
} else {
Settings::copyCutFileList[tn] = destFile;
}
}
} else {
QList rowList;
for (tn = Settings::copyCutIndexList.size() - 1; tn >= 0; --tn) {
sourceFile = thumbView->thumbsViewerModel->item(Settings::copyCutIndexList[tn].row())->
data(thumbView->FileNameRole).toString();
fileInfo = QFileInfo(sourceFile);
currFile = fileInfo.fileName();
destFile = destDir + QDir::separator() + currFile;
opLabel->setText((Settings::isCopyOperation ?
tr("Copying %1 to %2.") : tr("Moving %1 to %2.")).arg(sourceFile).arg(destFile));
QApplication::processEvents();
res = copyOrMoveFile(Settings::isCopyOperation, currFile, sourceFile, destFile, destDir);
if (!res || abortOp) {
break;
}
rowList.append(Settings::copyCutIndexList[tn].row());
}
if (!Settings::isCopyOperation) {
qSort(rowList);
for (int t = rowList.size() - 1; t >= 0; --t)
thumbView->thumbsViewerModel->removeRow(rowList.at(t));
}
latestRow = rowList.at(0);
}
nFiles = Settings::copyCutIndexList.size();
close();
}
void CopyMoveDialog::abort() {
abortOp = true;
}
phototonic-2.1/CopyMoveDialog.h 0000664 0000000 0000000 00000002515 13251276421 0016602 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef COPY_MOVE_DIALOG_H
#define COPY_MOVE_DIALOG_H
#include
#include "ThumbsViewer.h"
class CopyMoveDialog : public QDialog {
Q_OBJECT
public slots:
void abort();
public:
CopyMoveDialog(QWidget *parent);
static int copyOrMoveFile(bool isCopy, QString &srcFile, QString &srcPath, QString &dstPath, QString &dstDir);
void exec(ThumbsViewer *thumbView, QString &destDir, bool pasteInCurrDir);
int nFiles;
int latestRow;
private:
QLabel *opLabel;
QPushButton *cancelButton;
bool abortOp;
};
#endif // COPY_MOVE_DIALOG_H phototonic-2.1/CopyMoveToDialog.cpp 0000664 0000000 0000000 00000014323 13251276421 0017440 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov - oferkv@live.com
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "CopyMoveToDialog.h"
#include "Settings.h"
void CopyMoveToDialog::selection(const QItemSelection &, const QItemSelection &) {
if (pathsTable->selectionModel()->selectedRows().size() > 0) {
destinationLabel->setText(tr("Destination:") + " " +
pathsTableModel->item(
pathsTable->selectionModel()->selectedRows().at(0).row())->text());
}
}
void CopyMoveToDialog::pathDoubleClick(const QModelIndex &) {
copyOrMove();
}
void CopyMoveToDialog::savePaths() {
Settings::bookmarkPaths.clear();
for (int i = 0; i < pathsTableModel->rowCount(); ++i) {
Settings::bookmarkPaths.insert
(pathsTableModel->itemFromIndex(pathsTableModel->index(i, 0))->text());
}
}
void CopyMoveToDialog::copyOrMove() {
savePaths();
QModelIndexList indexesList;
if ((indexesList = pathsTable->selectionModel()->selectedIndexes()).size()) {
selectedPath = pathsTableModel->itemFromIndex(indexesList.first())->text();
accept();
} else {
reject();
}
}
void CopyMoveToDialog::justClose() {
savePaths();
reject();
}
void CopyMoveToDialog::add() {
QString dirName = QFileDialog::getExistingDirectory(this, tr("Choose Directory"), currentPath,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dirName.isEmpty()) {
return;
}
QStandardItem *item = new QStandardItem(QIcon(":/images/bookmarks.png"), dirName);
pathsTableModel->insertRow(pathsTableModel->rowCount(), item);
pathsTable->selectionModel()->clearSelection();
pathsTable->selectionModel()->select(pathsTableModel->index(pathsTableModel->rowCount() - 1, 0),
QItemSelectionModel::Select);
}
void CopyMoveToDialog::remove() {
QModelIndexList indexesList;
if ((indexesList = pathsTable->selectionModel()->selectedIndexes()).size()) {
pathsTableModel->removeRow(indexesList.first().row());
}
}
CopyMoveToDialog::CopyMoveToDialog(QWidget *parent, QString thumbsPath, bool move) : QDialog(parent) {
copyOp = !move;
if (move) {
setWindowTitle(tr("Move to..."));
setWindowIcon(QIcon::fromTheme("go-next"));
} else {
setWindowTitle(tr("Copy to..."));
setWindowIcon(QIcon::fromTheme("edit-copy"));
}
resize(350, 250);
currentPath = thumbsPath;
pathsTable = new QTableView(this);
pathsTable->setSelectionBehavior(QAbstractItemView::SelectItems);
pathsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
pathsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
pathsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
pathsTable->setSelectionMode(QAbstractItemView::SingleSelection);
pathsTableModel = new QStandardItemModel(this);
pathsTable->setModel(pathsTableModel);
pathsTable->verticalHeader()->setVisible(false);
pathsTable->horizontalHeader()->setVisible(false);
pathsTable->verticalHeader()->setDefaultSectionSize(pathsTable->verticalHeader()->
minimumSectionSize());
pathsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
pathsTable->setShowGrid(false);
connect(pathsTable->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
this, SLOT(selection(QItemSelection, QItemSelection)));
connect(pathsTable, SIGNAL(doubleClicked(
const QModelIndex &)),
this, SLOT(pathDoubleClick(
const QModelIndex &)));
QHBoxLayout *addRemoveHbox = new QHBoxLayout;
QPushButton *addButton = new QPushButton(tr("Browse..."));
connect(addButton, SIGNAL(clicked()), this, SLOT(add()));
QPushButton *removeButton = new QPushButton(tr("Delete Bookmark"));
connect(removeButton, SIGNAL(clicked()), this, SLOT(remove()));
addRemoveHbox->addWidget(removeButton, 0, Qt::AlignLeft);
addRemoveHbox->addStretch(1);
addRemoveHbox->addWidget(addButton, 0, Qt::AlignRight);
QHBoxLayout *buttonsHbox = new QHBoxLayout;
QPushButton *cancelButton = new QPushButton(tr("Cancel"));
cancelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(cancelButton, SIGNAL(clicked()), this, SLOT(justClose()));
QPushButton *okButton = new QPushButton(tr("OK"));
okButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
okButton->setDefault(true);
connect(okButton, SIGNAL(clicked()), this, SLOT(copyOrMove()));
buttonsHbox->addStretch(1);
buttonsHbox->addWidget(cancelButton, 0, Qt::AlignRight);
buttonsHbox->addWidget(okButton, 0, Qt::AlignRight);
destinationLabel = new QLabel(tr("Destination:"));
QFrame *line = new QFrame(this);
line->setObjectName(QString::fromUtf8("line"));
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
QVBoxLayout *mainVbox = new QVBoxLayout;
mainVbox->addWidget(pathsTable);
mainVbox->addLayout(addRemoveHbox);
mainVbox->addWidget(line);
mainVbox->addWidget(destinationLabel);
mainVbox->addLayout(buttonsHbox);
setLayout(mainVbox);
// Load paths list
QSetIterator it(Settings::bookmarkPaths);
while (it.hasNext()) {
QStandardItem *item = new QStandardItem(QIcon(":/images/bookmarks.png"), it.next());
pathsTableModel->insertRow(pathsTableModel->rowCount(), item);
}
pathsTableModel->sort(0);
}
phototonic-2.1/CopyMoveToDialog.h 0000664 0000000 0000000 00000002740 13251276421 0017105 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov - oferkv@live.com
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef COPY_MOVE_TO_DIALOG_H
#define COPY_MOVE_TO_DIALOG_H
#include
#include
#include
class CopyMoveToDialog : public QDialog {
Q_OBJECT
public:
CopyMoveToDialog(QWidget *parent, QString thumbsPath, bool move);
QString selectedPath;
bool copyOp;
private slots:
void copyOrMove();
void justClose();
void add();
void remove();
void selection(const QItemSelection &, const QItemSelection &);
void pathDoubleClick(const QModelIndex &idx);
private:
QTableView *pathsTable;
QStandardItemModel *pathsTableModel;
QString currentPath;
QLabel *destinationLabel;
void savePaths();
};
#endif // COPY_MOVE_TO_DIALOG_H phototonic-2.1/CropDialog.cpp 0000664 0000000 0000000 00000012410 13251276421 0016272 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "CropDialog.h"
#include "Settings.h"
CropDialog::CropDialog(QWidget *parent, ImageViewer *imageViewer) : QDialog(parent) {
setWindowTitle(tr("Cropping"));
setWindowIcon(QIcon(":/images/crop.png"));
resize(350, 100);
if (Settings::dialogLastX)
move(Settings::dialogLastX, Settings::dialogLastY);
this->imageViewer = imageViewer;
QHBoxLayout *buttonsHbox = new QHBoxLayout;
QPushButton *resetButton = new QPushButton(tr("Reset"));
connect(resetButton, SIGNAL(clicked()), this, SLOT(reset()));
QPushButton *okButton = new QPushButton(tr("OK"));
connect(okButton, SIGNAL(clicked()), this, SLOT(ok()));
okButton->setDefault(true);
buttonsHbox->addWidget(resetButton, 0, Qt::AlignLeft);
buttonsHbox->addWidget(okButton, 0, Qt::AlignRight);
QSlider *topSlide = new QSlider(Qt::Horizontal);
topSlide->setTickPosition(QSlider::TicksAbove);
topSlide->setTickInterval(10);
topSlide->setTracking(false);
QSlider *bottomSlide = new QSlider(Qt::Horizontal);
bottomSlide->setTickPosition(QSlider::TicksAbove);
bottomSlide->setTickInterval(10);
bottomSlide->setTracking(false);
QSlider *leftSlide = new QSlider(Qt::Horizontal);
leftSlide->setTickPosition(QSlider::TicksAbove);
leftSlide->setTickInterval(10);
leftSlide->setTracking(false);
QSlider *rightSlide = new QSlider(Qt::Horizontal);
rightSlide->setTickPosition(QSlider::TicksAbove);
rightSlide->setTickInterval(10);
rightSlide->setTracking(false);
topSpinBox = new QSpinBox;
topSpinBox->setPrefix("% ");
bottomSpinBox = new QSpinBox;
bottomSpinBox->setPrefix("% ");
leftSpinBox = new QSpinBox;
leftSpinBox->setPrefix("% ");
rightSpinBox = new QSpinBox;
rightSpinBox->setPrefix("% ");
QLabel *leftLab = new QLabel(tr("Left"));
QLabel *rightLab = new QLabel(tr("Right"));
QLabel *topLab = new QLabel(tr("Top"));
QLabel *bottomLab = new QLabel(tr("Bottom"));
QGridLayout *mainGbox = new QGridLayout;
mainGbox->addWidget(leftLab, 0, 0, 1, 1);
mainGbox->addWidget(leftSlide, 0, 1, 1, 1);
mainGbox->addWidget(leftSpinBox, 0, 2, 1, 1);
mainGbox->addWidget(rightLab, 1, 0, 1, 1);
mainGbox->addWidget(rightSlide, 1, 1, 1, 1);
mainGbox->addWidget(rightSpinBox, 1, 2, 1, 1);
mainGbox->addWidget(topLab, 2, 0, 1, 1);
mainGbox->addWidget(topSlide, 2, 1, 1, 1);
mainGbox->addWidget(topSpinBox, 2, 2, 1, 1);
mainGbox->addWidget(bottomLab, 3, 0, 1, 1);
mainGbox->addWidget(bottomSlide, 3, 1, 1, 1);
mainGbox->addWidget(bottomSpinBox, 3, 2, 1, 1);
QVBoxLayout *mainVbox = new QVBoxLayout;
mainVbox->addLayout(mainGbox);
mainVbox->addLayout(buttonsHbox);
setLayout(mainVbox);
topSpinBox->setRange(0, 100);
bottomSpinBox->setRange(0, 100);
leftSpinBox->setRange(0, 100);
rightSpinBox->setRange(0, 100);
topSlide->setRange(0, 100);
bottomSlide->setRange(0, 100);
leftSlide->setRange(0, 100);
rightSlide->setRange(0, 100);
connect(topSlide, SIGNAL(valueChanged(int)), topSpinBox, SLOT(setValue(int)));
connect(bottomSlide, SIGNAL(valueChanged(int)), bottomSpinBox, SLOT(setValue(int)));
connect(leftSlide, SIGNAL(valueChanged(int)), leftSpinBox, SLOT(setValue(int)));
connect(rightSlide, SIGNAL(valueChanged(int)), rightSpinBox, SLOT(setValue(int)));
connect(topSpinBox, SIGNAL(valueChanged(int)), topSlide, SLOT(setValue(int)));
connect(bottomSpinBox, SIGNAL(valueChanged(int)), bottomSlide, SLOT(setValue(int)));
connect(leftSpinBox, SIGNAL(valueChanged(int)), leftSlide, SLOT(setValue(int)));
connect(rightSpinBox, SIGNAL(valueChanged(int)), rightSlide, SLOT(setValue(int)));
connect(topSpinBox, SIGNAL(valueChanged(int)), this, SLOT(applyCrop(int)));
connect(bottomSpinBox, SIGNAL(valueChanged(int)), this, SLOT(applyCrop(int)));
connect(leftSpinBox, SIGNAL(valueChanged(int)), this, SLOT(applyCrop(int)));
connect(rightSpinBox, SIGNAL(valueChanged(int)), this, SLOT(applyCrop(int)));
}
void CropDialog::applyCrop(int) {
Settings::cropLeftPercent = leftSpinBox->value();
Settings::cropTopPercent = topSpinBox->value();
Settings::cropWidthPercent = rightSpinBox->value();
Settings::cropHeightPercent = bottomSpinBox->value();
imageViewer->refresh();
}
void CropDialog::ok() {
Settings::dialogLastX = pos().x();
Settings::dialogLastY = pos().y();
accept();
}
void CropDialog::reset() {
leftSpinBox->setValue(0);
rightSpinBox->setValue(0);
topSpinBox->setValue(0);
bottomSpinBox->setValue(0);
} phototonic-2.1/CropDialog.h 0000664 0000000 0000000 00000002324 13251276421 0015742 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef CROP_DIALOG_H
#define CROP_DIALOG_H
#include
#include "ImageViewer.h"
class CropDialog : public QDialog {
Q_OBJECT
public:
CropDialog(QWidget *parent, ImageViewer *imageViewer);
public slots:
void ok();
void reset();
void applyCrop(int);
private:
QSpinBox *topSpinBox;
QSpinBox *bottomSpinBox;
QSpinBox *leftSpinBox;
QSpinBox *rightSpinBox;
ImageViewer *imageViewer;
};
#endif // CROP_DIALOG_H phototonic-2.1/CropRubberband.cpp 0000664 0000000 0000000 00000004311 13251276421 0017142 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov - oferkv@live.com
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "CropRubberband.h"
CropRubberBand::CropRubberBand(QWidget *parent) : QWidget(parent) {
setWindowFlags(Qt::SubWindow);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
QHBoxLayout *topLayout = new QHBoxLayout();
topLayout->setContentsMargins(0, 0, 0, 0);
QHBoxLayout *bottomLayout = new QHBoxLayout();
bottomLayout->setContentsMargins(0, 0, 0, 0);
QSizeGrip *grip1 = new QSizeGrip(this);
QSizeGrip *grip2 = new QSizeGrip(this);
QSizeGrip *grip3 = new QSizeGrip(this);
QSizeGrip *grip4 = new QSizeGrip(this);
grip1->setStyleSheet("background-color: rgba(0, 0, 0, 0%)");
grip2->setStyleSheet("background-color: rgba(0, 0, 0, 0%)");
grip3->setStyleSheet("background-color: rgba(0, 0, 0, 0%)");
grip4->setStyleSheet("background-color: rgba(0, 0, 0, 0%)");
topLayout->addWidget(grip1, 0, Qt::AlignTop | Qt::AlignLeft);
topLayout->addWidget(grip2, 1, Qt::AlignTop | Qt::AlignRight);
bottomLayout->addWidget(grip3, 0, Qt::AlignBottom | Qt::AlignLeft);
bottomLayout->addWidget(grip4, 1, Qt::AlignBottom | Qt::AlignRight);
mainLayout->addLayout(topLayout);
mainLayout->addLayout(bottomLayout);
rubberband = new QRubberBand(QRubberBand::Rectangle, this);
rubberband->setStyleSheet("background-color: rgb(255, 255, 255)");
rubberband->show();
}
void CropRubberBand::resizeEvent(QResizeEvent *) {
rubberband->resize(size());
}
phototonic-2.1/CropRubberband.h 0000664 0000000 0000000 00000002023 13251276421 0016605 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov - oferkv@live.com
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef CROPRUBBERBAND_H
#define CROPRUBBERBAND_H
#include
class CropRubberBand : public QWidget {
public:
CropRubberBand(QWidget *parent = 0);
private:
QRubberBand *rubberband;
void resizeEvent(QResizeEvent *);
};
#endif // CROPRUBBERBAND_H
phototonic-2.1/DirCompleter.cpp 0000664 0000000 0000000 00000002575 13251276421 0016653 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2015 Thomas Lübking
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include
#include "DirCompleter.h"
DirCompleter::DirCompleter(QObject *parent) : QCompleter(parent) {
QDirModel *model = new QDirModel;
model->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
model->setLazyChildCount(true);
setModel(model);
}
QString DirCompleter::pathFromIndex(const QModelIndex &index) const {
return QCompleter::pathFromIndex(index) + "/";
}
QStringList DirCompleter::splitPath(const QString &path) const {
if (path.startsWith("~")) {
return QCompleter::splitPath(QString(path).replace(0, 1, QDir::homePath()));
}
return QCompleter::splitPath(path);
}
phototonic-2.1/DirCompleter.h 0000664 0000000 0000000 00000002123 13251276421 0016305 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2015 Thomas Lübking
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef DIR_COMPLETER_H
#define DIR_COMPLETER_H
#include
class DirCompleter : public QCompleter {
Q_OBJECT
public:
DirCompleter(QObject *parent = 0);
QString pathFromIndex(const QModelIndex &index) const;
public slots:
QStringList splitPath(const QString &path) const;
};
#endif // DIR_COMPLETER_H
phototonic-2.1/ExternalAppsDialog.cpp 0000664 0000000 0000000 00000011755 13251276421 0020010 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include
#include "ExternalAppsDialog.h"
#include "Settings.h"
ExternalAppsDialog::ExternalAppsDialog(QWidget *parent) : QDialog(parent) {
setWindowTitle(tr("Manage External Applications"));
setWindowIcon(QIcon::fromTheme("preferences-other", QIcon(":/images/phototonic.png")));
resize(350, 250);
appsTable = new QTableView(this);
appsTable->setSelectionBehavior(QAbstractItemView::SelectItems);
appsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
appsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
appsTableModel = new QStandardItemModel(this);
appsTable->setModel(appsTableModel);
appsTable->verticalHeader()->setVisible(false);
appsTable->verticalHeader()->setDefaultSectionSize(appsTable->verticalHeader()->minimumSectionSize());
appsTableModel->setHorizontalHeaderItem(0, new QStandardItem(QString(tr("Name"))));
appsTableModel->setHorizontalHeaderItem(1,
new QStandardItem(QString(tr("Application path and arguments"))));
appsTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Interactive);
appsTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
appsTable->setShowGrid(false);
QHBoxLayout *externalAppsLayout = new QHBoxLayout;
QPushButton *addButton = new QPushButton(tr("Choose"));
connect(addButton, SIGNAL(clicked()), this, SLOT(add()));
externalAppsLayout->addWidget(addButton, 0, Qt::AlignRight);
QPushButton *entryButton = new QPushButton(tr("Add manually"));
connect(entryButton, SIGNAL(clicked()), this, SLOT(entry()));
externalAppsLayout->addWidget(entryButton, 0, Qt::AlignRight);
QPushButton *removeButton = new QPushButton(tr("Delete"));
connect(removeButton, SIGNAL(clicked()), this, SLOT(remove()));
externalAppsLayout->addWidget(removeButton, 0, Qt::AlignRight);
externalAppsLayout->addStretch(1);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
QPushButton *okButton = new QPushButton(tr("OK"));
okButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(okButton, SIGNAL(clicked()), this, SLOT(ok()));
buttonsLayout->addWidget(okButton, 0, Qt::AlignRight);
QVBoxLayout *externalAppsMainLayout = new QVBoxLayout;
externalAppsMainLayout->addWidget(appsTable);
externalAppsMainLayout->addLayout(externalAppsLayout);
externalAppsMainLayout->addLayout(buttonsLayout);
setLayout(externalAppsMainLayout);
// Load external apps list
QString key, val;
QMapIterator it(Settings::externalApps);
while (it.hasNext()) {
it.next();
key = it.key();
val = it.value();
addTableModelItem(appsTableModel, key, val);
}
}
void ExternalAppsDialog::ok() {
int row = appsTableModel->rowCount();
Settings::externalApps.clear();
for (int i = 0; i < row; ++i) {
if (!appsTableModel->itemFromIndex(appsTableModel->index(i, 1))->text().isEmpty()) {
Settings::externalApps[appsTableModel->itemFromIndex(appsTableModel->index(i, 0))->text()] =
appsTableModel->itemFromIndex(appsTableModel->index(i, 1))->text();
}
}
accept();
}
void ExternalAppsDialog::add() {
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose Application"), "", "");
if (fileName.isEmpty())
return;
QFileInfo fileInfo = QFileInfo(fileName);
QString appName = fileInfo.fileName();
addTableModelItem(appsTableModel, appName, fileName);
}
void ExternalAppsDialog::entry() {
int atRow = appsTableModel->rowCount();
QStandardItem *itemKey = new QStandardItem(QString(tr("New Application")));
appsTableModel->insertRow(atRow, itemKey);
}
void ExternalAppsDialog::remove() {
QModelIndexList indexesList;
while ((indexesList = appsTable->selectionModel()->selectedIndexes()).size()) {
appsTableModel->removeRow(indexesList.first().row());
}
}
void ExternalAppsDialog::addTableModelItem(QStandardItemModel *model, QString &key, QString &val) {
int atRow = model->rowCount();
QStandardItem *itemKey = new QStandardItem(key);
QStandardItem *itemKey2 = new QStandardItem(val);
model->insertRow(atRow, itemKey);
model->setItem(atRow, 1, itemKey2);
}
phototonic-2.1/ExternalAppsDialog.h 0000664 0000000 0000000 00000002426 13251276421 0017450 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef EXTERNAL_APPS_DIALOG_H
#define EXTERNAL_APPS_DIALOG_H
#include
#include
class ExternalAppsDialog : public QDialog {
Q_OBJECT
public:
ExternalAppsDialog(QWidget *parent);
public slots:
void ok();
private slots:
void add();
void remove();
void entry();
private:
QTableView *appsTable;
QStandardItemModel *appsTableModel;
void addTableModelItem(QStandardItemModel *model, QString &key, QString &val);
};
#endif // EXTERNAL_APPS_DIALOG_H phototonic-2.1/FileListWidget.cpp 0000664 0000000 0000000 00000004154 13251276421 0017134 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "FileListWidget.h"
FileListWidget::FileListWidget(QWidget *parent) : QTreeWidget(parent) {
setAcceptDrops(true);
setDragEnabled(false);
setDragDropMode(QAbstractItemView::DropOnly);
setColumnCount(1);
setHeaderHidden(true);
addFileListEntry();
setMaximumHeight((int) (QFontMetrics(font()).height() * 1.6));
}
void FileListWidget::addFileListEntry() {
QTreeWidgetItem *item = new QTreeWidgetItem(this);
item->setText(0, "File List");
item->setIcon(0, style()->standardIcon(QStyle::SP_FileDialogDetailedView));
insertTopLevelItem(0, item);
}
void FileListWidget::resizeTreeColumn(const QModelIndex &) {
resizeColumnToContents(0);
}
void FileListWidget::dragEnterEvent(QDragEnterEvent *event) {
QModelIndexList selectedDirs = selectionModel()->selectedRows();
if (selectedDirs.size() > 0) {
dndOrigSelection = selectedDirs[0];
}
event->acceptProposedAction();
}
void FileListWidget::dragMoveEvent(QDragMoveEvent *event) {
setCurrentIndex(indexAt(event->pos()));
}
void FileListWidget::dropEvent(QDropEvent *event) {
if (event->source()) {
QString fileSystemTreeStr("FileSystemTree");
bool dirOp = (event->source()->metaObject()->className() == fileSystemTreeStr);
emit dropOp(event->keyboardModifiers(), dirOp, event->mimeData()->urls().at(0).toLocalFile());
}
}
phototonic-2.1/FileListWidget.h 0000664 0000000 0000000 00000002547 13251276421 0016605 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef FILE_LIST_WIDGET_H
#define FILE_LIST_WIDGET_H
#include
#include "Settings.h"
class FileListWidget : public QTreeWidget {
Q_OBJECT
public:
FileListWidget(QWidget *parent);
void addFileListEntry();
private:
QModelIndex dndOrigSelection;
private slots:
void resizeTreeColumn(const QModelIndex &);
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
signals:
void dropOp(Qt::KeyboardModifiers keyMods, bool dirOp, QString cpMvDirPath);
};
#endif // FILE_LIST_WIDGET_H
phototonic-2.1/FileSystemModel.cpp 0000664 0000000 0000000 00000002243 13251276421 0017317 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "FileSystemModel.h"
bool FileSystemModel::hasChildren(const QModelIndex &parent) const {
if (parent.column() > 0) {
return false;
}
if (!parent.isValid()) {
return true;
}
if (parent.flags() & Qt::ItemNeverHasChildren) {
return false;
}
return QDirIterator(filePath(parent), filter() | QDir::NoDotAndDotDot, QDirIterator::NoIteratorFlags).hasNext();
} phototonic-2.1/FileSystemModel.h 0000664 0000000 0000000 00000001773 13251276421 0016773 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef FILE_SYSTEM_MODEL_H
#define FILE_SYSTEM_MODEL_H
#include
class FileSystemModel : public QFileSystemModel {
Q_OBJECT
public:
bool hasChildren(const QModelIndex &parent) const;
};
#endif // FILE_SYSTEM_MODEL_H
phototonic-2.1/FileSystemTree.cpp 0000664 0000000 0000000 00000005265 13251276421 0017165 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "FileSystemTree.h"
FileSystemTree::FileSystemTree(QWidget *parent) : QTreeView(parent) {
setAcceptDrops(true);
setDragEnabled(true);
setDragDropMode(QAbstractItemView::InternalMove);
fileSystemModel = new FileSystemModel();
fileSystemModel->setRootPath("");
setModelFlags();
setModel(fileSystemModel);
for (int i = 1; i <= 3; ++i) {
hideColumn(i);
}
setHeaderHidden(true);
connect(this, SIGNAL(expanded(
const QModelIndex &)),
this, SLOT(resizeTreeColumn(
const QModelIndex &)));
connect(this, SIGNAL(collapsed(
const QModelIndex &)),
this, SLOT(resizeTreeColumn(
const QModelIndex &)));
}
QModelIndex FileSystemTree::getCurrentIndex() {
return selectedIndexes().first();
}
void FileSystemTree::resizeTreeColumn(const QModelIndex &) {
resizeColumnToContents(0);
}
void FileSystemTree::dragEnterEvent(QDragEnterEvent *event) {
QModelIndexList selectedDirs = selectionModel()->selectedRows();
if (selectedDirs.size() > 0) {
dndOrigSelection = selectedDirs[0];
event->acceptProposedAction();
}
}
void FileSystemTree::dragMoveEvent(QDragMoveEvent *event) {
setCurrentIndex(indexAt(event->pos()));
}
void FileSystemTree::dropEvent(QDropEvent *event) {
if (event->source()) {
QString fileSystemTreeStr = "FileSystemTree";
bool dirOp = (event->source()->metaObject()->className() == fileSystemTreeStr);
emit dropOp(event->keyboardModifiers(), dirOp, event->mimeData()->urls().at(0).toLocalFile());
setCurrentIndex(dndOrigSelection);
}
}
void FileSystemTree::setModelFlags() {
fileSystemModel->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
if (Settings::showHiddenFiles) {
fileSystemModel->setFilter(fileSystemModel->filter() | QDir::Hidden);
}
}
phototonic-2.1/FileSystemTree.h 0000664 0000000 0000000 00000002752 13251276421 0016630 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include
#include
#include "Settings.h"
#include "FileSystemModel.h"
#ifndef FILE_SYSTEM_TREE_H
#define FILE_SYSTEM_TREE_H
class FileSystemTree : public QTreeView {
Q_OBJECT
public:
FileSystemTree(QWidget *parent);
FileSystemModel *fileSystemModel;
QModelIndex getCurrentIndex();
void setModelFlags();
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
signals:
void dropOp(Qt::KeyboardModifiers keyMods, bool dirOp, QString cpMvDirPath);
private:
QModelIndex dndOrigSelection;
private slots:
void resizeTreeColumn(const QModelIndex &);
};
#endif // FILE_SYSTEM_TREE_H
phototonic-2.1/HISTORY.md 0000664 0000000 0000000 00000012261 13251276421 0015232 0 ustar 00root root 0000000 0000000 # Phototonic Image Viewer
### History:
##### 4 Jul 2015 - v1.6.6
+ Improved tags usability and performance
+ Bug fixes
##### 6 Jun 2015 - v1.6.2
+ Image tags, tagging images and filtering images by tags
+ Delete confirmation is now configurable
+ Improvements to drag and drop
+ A more sophisticated Dir-completer
+ Many many more fixes and improvements, thanks to the contributors!
##### 6 Feb 2015 - v1.5.54
+ Keyboard Shortcuts are now comfortably edited in a table
+ Enhancements to Find Duplicates feature
+ Many enhancements to translations and translations functionality
+ Fixes to the way key bindings are saved
+ Fixes to invalid behavior when deleting elements
+ Fixed folders expand indicator showing when there are no sub-folders
+ Fixed to the way bookmarks are saved
+ Added Changelog
##### 21 Nov 2014 - v1.5.1
+ New toolbar in viewer mode for image manipulation actions
+ Added Bookmarks feature
+ Fixed sorting order when sorting by time and size
+ Added Find Duplicate Images feature
+ Added shortcuts for changing the focus to the Find and Path text areas
+ Enhancements to Copy to and Move to dialogs
+ Can now set thumbnails background image
+ Enhancements to Colors dialog, added color balance feature
+ Added Crop to Selection feature
+ Added mouse shortcuts for Reset/Original Zoom
+ Added feedback notification for transformation actions in viewer
+ Changed Cropping dialog orientation to percentage cropping for continuous image cropping
+ Image data now showed in sections
+ Many other fixes
##### 19 Sep 2014 - v1.4
+ Viewer is now available in the thumbnails layout as a Dock
+ Thumbnails can now also be rotated according Exif orientation
+ Added Debian packaging scripts
+ Enhances to external application dialog
+ Added Czech translation
+ Added French translation
+ Better feedback when starting external applications
+ Settings dialog controls are now grouped in tabs
+ Added 16px size application icon
+ Improvements to German translation
+ Can now rename an image when in viewer
+ Added busy indicator for some actions in thumbnails layout
+ Changes to version scheme
+ Open image action now toggles closing the image when in viewer
+ Consolidate feedback in viewer to bubbles
+ Tool bars icon size is now custom
+ Confirmation is asked when moving folders around in the tree
+ Fixes to slowness and other bugs when closing image from full screen
+ Fixed folder focus stealing issue when creating a new folder
+ Fixes for some untranslated dialogs
+ Fix dialogs creating shadow over image under KDE
+ Fixes for wrong dock sizes when toggling layouts
+ Fixed slowness when inverting selection
+ Many other fixes
##### 8 Aug 2014 - v1.03
+ Added translations for Polish, German and Russian. Many thanks to the translators!
+ Added Startup Folder options
+ Added Brightness and Contrast controls
+ Added Scale Image feature
+ Added option to show image name in full screen
+ Can now show/hide thumbnail labels in Classic and Compact modes
+ Added menu for docks and toolbars visibility
+ Improved rename dialog
+ Optimizations to thumbnail layouts
+ Fixed zooming with mouse wheel direction
+ Fixes thumbnails sorting case sensitivity
+ Fixes to menu visibility in Ubuntu
+ Fixes to Slide show
+ Many more small bug fixes
##### 14 Jul 2014 - v1.01
+ Fixed image saving failure in some cases
+ Fixed tool bars and docks non persistent visibility state
##### 12 Jul 2014 - v1.00
+ Thumbnails can be loaded and browsed recursively on a folder tree
+ Thumbnails are now loaded dynamically, enabling browsing very large folders
+ Enhancements to thumbnails filtering
+ Added "Copy/Move Images to..." Dialog
+ Can now open image with multiple external programs
+ Added customization for mouse behavior
+ Added Show Hidden Files option
+ Enhancements to crop dialog
+ Image zooming can now be controlled with mouse wheel+ctrl key
+ Enhancements to thumbnails loading UX
+ Fixes to slide show starting offset
+ Fixed file management issues
+ Fixed issues with docks state not being saved
+ Fixed issue with window size when exiting Phototonic while in full screen
+ Fixed invalid image movement when moving with keyboard
##### 17 May 2014 - v0.99
+ Images can+ now be rotated freely to any angle
+ Added file name filtering option
+ Added Exif support (Exiv2 is now a dependency), metadata retained when saving images
+ New Image features: New Image, Copy and Paste image data
+ File system tree and Image Info panes can now be removed or docked anywhere
+ Many other small fixes and enhancements
+
##### 27 Apr 2014 - v0.98
+ New Colors dialog with Hue and Saturation settings
+ Added support for animated GIFs
+ Large images can now be moved around with keyboard as well as the mouse
+ Added notifications while in viewer
##### 11 Apr 2014 - v0.97
+ Moved to Qt5
+ Fixed missing icons when not in a DE
+ Added additional image info in status and title bars
##### 29 Mar 2014 - v0.96
+ Fixed thumbnails navigation usability issues
##### 28 Mar 2014 - v0.95
+ Added Open with external application option and other enhancements
##### 25 Mar 2014 - v0.94
+ Icons now loaded from theme.
+ Added Copy Image option.
##### 22 Mar 2014 - v0.93
+ Added keyboard shortcuts customization
+ Fixed issues related to image formats
+ New web site, under construction
phototonic-2.1/ImagePreview.cpp 0000664 0000000 0000000 00000007066 13251276421 0016646 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "ImagePreview.h"
#include "Settings.h"
#include "ThumbsViewer.h"
ImagePreview::ImagePreview(QWidget *parent) : QWidget(parent) {
imageLabel = new QLabel;
imageLabel->setScaledContents(true);
scrollArea = new QScrollArea;
scrollArea->setContentsMargins(0, 0, 0, 0);
scrollArea->setAlignment(Qt::AlignCenter);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->verticalScrollBar()->blockSignals(true);
scrollArea->horizontalScrollBar()->blockSignals(true);
scrollArea->setFrameStyle(0);
scrollArea->setWidget(imageLabel);
scrollArea->setWidgetResizable(true);
QHBoxLayout *mainLayout = new QHBoxLayout();
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
mainLayout->addWidget(scrollArea);
setBackgroundColor();
setLayout(mainLayout);
}
QPixmap& ImagePreview::loadImage(QString imageFileName) {
QImageReader imageReader(imageFileName);
if (imageReader.size().isValid()) {
QSize resize = imageReader.size();
resize.scale(QSize(imageLabel->width(), imageLabel->height()), Qt::KeepAspectRatio);
QImage previewImage;
imageReader.read(&previewImage);
if (Settings::exifRotationEnabled) {
imageViewer->rotateByExifRotation(previewImage, imageFileName);
}
previewPixmap = QPixmap::fromImage(previewImage);
} else {
previewPixmap = QIcon::fromTheme("image-missing",
QIcon(":/images/error_image.png")).pixmap(BAD_IMAGE_SIZE, BAD_IMAGE_SIZE);
}
imageLabel->setPixmap(previewPixmap);
resizeImagePreview();
return previewPixmap;
}
void ImagePreview::clear() {
imageLabel->clear();
}
void ImagePreview::resizeImagePreview() {
const QPixmap *pixmap = imageLabel->pixmap();
if (!pixmap) {
return;
}
QSize previewSizePixmap = pixmap->size();
if (previewSizePixmap.width() > scrollArea->width() || previewSizePixmap.height() > scrollArea->height()) {
previewSizePixmap.scale(scrollArea->width(), scrollArea->height(), Qt::KeepAspectRatio);
}
imageLabel->setFixedSize(previewSizePixmap);
imageLabel->adjustSize();
}
void ImagePreview::resizeEvent(QResizeEvent *event) {
QWidget::resizeEvent(event);
resizeImagePreview();
}
void ImagePreview::setBackgroundColor() {
QString bgColor = "background: rgb(%1, %2, %3); ";
bgColor = bgColor.arg(Settings::thumbsBackgroundColor.red())
.arg(Settings::thumbsBackgroundColor.green()).arg(Settings::thumbsBackgroundColor.blue());
QString ss = "QWidget { " + bgColor + " }";
scrollArea->setStyleSheet(ss);
}
void ImagePreview::setImageViewer(ImageViewer *imageViewer) {
this->imageViewer = imageViewer;
}
phototonic-2.1/ImagePreview.h 0000664 0000000 0000000 00000002504 13251276421 0016303 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef IMAGE_PREVIEW_H
#define IMAGE_PREVIEW_H
#include
#include "ImageViewer.h"
class ImagePreview : public QWidget {
Q_OBJECT
public:
ImagePreview(QWidget *parent);
QPixmap &loadImage(QString imageFileName);
void resizeImagePreview();
void setBackgroundColor();
void clear();
void setImageViewer(ImageViewer *imageViewer);
QScrollArea *scrollArea;
protected:
void resizeEvent(QResizeEvent *event);
private:
QLabel *imageLabel;
QPixmap previewPixmap;
ImageViewer *imageViewer;
};
#endif // IMAGE_PREVIEW_H
phototonic-2.1/ImageViewer.cpp 0000664 0000000 0000000 00000106153 13251276421 0016463 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov - oferkv@live.com
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "ImageViewer.h"
#include "Phototonic.h"
#include "MessageBox.h"
#define CLIPBOARD_IMAGE_NAME "clipboard.png"
#define ROUND(x) ((int) ((x) + 0.5))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
ImageViewer::ImageViewer(QWidget *parent, MetadataCache *metadataCache) : QWidget(parent) {
this->phototonic = (Phototonic *) parent;
this->metadataCache = metadataCache;
cursorIsHidden = false;
moveImageLocked = false;
mirrorLayout = LayNone;
imageLabel = new QLabel;
imageLabel->setScaledContents(true);
isAnimation = false;
animation = nullptr;
scrollArea = new QScrollArea;
scrollArea->setContentsMargins(0, 0, 0, 0);
scrollArea->setAlignment(Qt::AlignCenter);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->verticalScrollBar()->blockSignals(true);
scrollArea->horizontalScrollBar()->blockSignals(true);
scrollArea->setFrameStyle(0);
scrollArea->setWidget(imageLabel);
scrollArea->setWidgetResizable(true);
setBackgroundColor();
QVBoxLayout *scrollLayout = new QVBoxLayout;
scrollLayout->setContentsMargins(0, 0, 0, 0);
scrollLayout->setSpacing(0);
scrollLayout->addWidget(scrollArea);
this->setLayout(scrollLayout);
imageInfoLabel = new QLabel(this);
imageInfoLabel->setVisible(Settings::showImageName);
imageInfoLabel->setMargin(3);
imageInfoLabel->move(10, 10);
imageInfoLabel->setStyleSheet("QLabel { background-color : black; color : white; border-radius: 3px} ");
feedbackLabel = new QLabel(this);
feedbackLabel->setVisible(false);
feedbackLabel->setMargin(3);
feedbackLabel->setStyleSheet("QLabel { background-color : black; color : white; border-radius: 3px} ");
QGraphicsOpacityEffect *infoEffect = new QGraphicsOpacityEffect;
infoEffect->setOpacity(0.5);
imageInfoLabel->setGraphicsEffect(infoEffect);
QGraphicsOpacityEffect *feedbackEffect = new QGraphicsOpacityEffect;
feedbackEffect->setOpacity(0.5);
feedbackLabel->setGraphicsEffect(feedbackEffect);
mouseMovementTimer = new QTimer(this);
connect(mouseMovementTimer, SIGNAL(timeout()), this, SLOT(monitorCursorState()));
Settings::cropLeft = Settings::cropTop = Settings::cropWidth = Settings::cropHeight = 0;
Settings::cropLeftPercent = Settings::cropTopPercent = Settings::cropWidthPercent = Settings::cropHeightPercent = 0;
Settings::hueVal = 0;
Settings::saturationVal = 100;
Settings::lightnessVal = 100;
Settings::hueRedChannel = true;
Settings::hueGreenChannel = true;
Settings::hueBlueChannel = true;
Settings::contrastVal = 78;
Settings::brightVal = 100;
Settings::dialogLastX = Settings::dialogLastY = 0;
newImage = false;
cropRubberBand = 0;
}
static unsigned int getHeightByWidth(int imgWidth, int imgHeight, int newWidth) {
float aspect;
aspect = (float) imgWidth / (float) newWidth;
return (imgHeight / aspect);
}
static unsigned int getWidthByHeight(int imgHeight, int imgWidth, int newHeight) {
float aspect;
aspect = (float) imgHeight / (float) newHeight;
return (imgWidth / aspect);
}
static inline int calcZoom(int size) {
return size * Settings::imageZoomFactor;
}
void ImageViewer::resizeImage() {
static bool busy = false;
if (busy || (!imageLabel->pixmap() && !animation)) {
return;
}
busy = true;
int imageViewWidth = this->size().width();
int imageViewHeight = this->size().height();
QSize imageSize = isAnimation ? animation->currentPixmap().size() : imageLabel->pixmap()->size();
if (tempDisableResize) {
imageSize.scale(imageSize.width(), imageSize.height(), Qt::KeepAspectRatio);
} else {
switch (Settings::zoomInFlags) {
case Disable:
if (imageSize.width() <= imageViewWidth && imageSize.height() <= imageViewHeight) {
imageSize.scale(calcZoom(imageSize.width()),
calcZoom(imageSize.height()),
Qt::KeepAspectRatio);
}
break;
case WidthAndHeight:
if (imageSize.width() <= imageViewWidth && imageSize.height() <= imageViewHeight) {
imageSize.scale(calcZoom(imageViewWidth),
calcZoom(imageViewHeight),
Qt::KeepAspectRatio);
}
break;
case Width:
if (imageSize.width() <= imageViewWidth) {
imageSize.scale(calcZoom(imageViewWidth),
calcZoom(getHeightByWidth(imageSize.width(),
imageSize.height(),
imageViewWidth)),
Qt::KeepAspectRatio);
}
break;
case Height:
if (imageSize.height() <= imageViewHeight) {
imageSize.scale(calcZoom(getWidthByHeight(imageSize.height(),
imageSize.width(),
imageViewHeight)),
calcZoom(imageViewHeight),
Qt::KeepAspectRatio);
}
break;
case Disprop:
int newWidth = imageSize.width(), newHeight = imageSize.height();
if (newWidth <= imageViewWidth) {
newWidth = imageViewWidth;
}
if (newHeight <= imageViewHeight) {
newHeight = imageViewHeight;
}
imageSize.scale(calcZoom(newWidth), calcZoom(newHeight), Qt::IgnoreAspectRatio);
break;
}
switch (Settings::zoomOutFlags) {
case Disable:
if (imageSize.width() >= imageViewWidth || imageSize.height() >= imageViewHeight) {
imageSize.scale(calcZoom(imageSize.width()),
calcZoom(imageSize.height()),
Qt::KeepAspectRatio);
}
break;
case WidthAndHeight:
if (imageSize.width() >= imageViewWidth || imageSize.height() >= imageViewHeight) {
imageSize.scale(calcZoom(imageViewWidth),
calcZoom(imageViewHeight),
Qt::KeepAspectRatio);
}
break;
case Width:
if (imageSize.width() >= imageViewWidth) {
imageSize.scale(calcZoom(imageViewWidth),
calcZoom(getHeightByWidth(imageSize.width(),
imageSize.height(),
imageViewWidth)),
Qt::KeepAspectRatio);
}
break;
case Height:
if (imageSize.height() >= imageViewHeight) {
imageSize.scale(calcZoom(getWidthByHeight(imageSize.height(),
imageSize.width(),
imageViewHeight)),
calcZoom(imageViewHeight),
Qt::KeepAspectRatio);
}
break;
case Disprop:
int newWidth = imageSize.width(), newHeight = imageSize.height();
if (newWidth >= imageViewWidth) {
newWidth = imageViewWidth;
}
if (newHeight >= imageViewHeight) {
newHeight = imageViewHeight;
}
imageSize.scale(calcZoom(newWidth), calcZoom(newHeight), Qt::IgnoreAspectRatio);
break;
}
}
imageLabel->setFixedSize(imageSize);
imageLabel->adjustSize();
centerImage(imageSize);
busy = false;
}
void ImageViewer::resizeEvent(QResizeEvent *event) {
QWidget::resizeEvent(event);
resizeImage();
}
void ImageViewer::showEvent(QShowEvent *event) {
QWidget::showEvent(event);
resizeImage();
}
void ImageViewer::centerImage(QSize &imgSize) {
int newX = (this->size().width() - imgSize.width()) / 2;
int newY = (this->size().height() - imgSize.height()) / 2;
if (newX != imageLabel->pos().x() || newY != imageLabel->pos().y()) {
imageLabel->move(newX, newY);
}
}
void ImageViewer::rotateByExifRotation(QImage &image, QString &imageFullPath) {
QTransform trans;
long orientation = metadataCache->getImageOrientation(imageFullPath);
switch (orientation) {
case 1:
break;
case 2:
image = image.mirrored(true, false);
break;
case 3:
trans.rotate(180);
image = image.transformed(trans, Qt::SmoothTransformation);
break;
case 4:
image = image.mirrored(false, true);
break;
case 5:
trans.rotate(90);
image = image.transformed(trans, Qt::SmoothTransformation);
image = image.mirrored(true, false);
break;
case 6:
trans.rotate(90);
image = image.transformed(trans, Qt::SmoothTransformation);
break;
case 7:
trans.rotate(90);
image = image.transformed(trans, Qt::SmoothTransformation);
image = image.mirrored(false, true);
break;
case 8:
trans.rotate(270);
image = image.transformed(trans, Qt::SmoothTransformation);
break;
default:
break;
}
}
void ImageViewer::transform() {
if (Settings::exifRotationEnabled) {
rotateByExifRotation(viewerImage, viewerImageFullPath);
}
if (Settings::rotation) {
QTransform trans;
trans.rotate(Settings::rotation);
viewerImage = viewerImage.transformed(trans, Qt::SmoothTransformation);
}
if (Settings::flipH || Settings::flipV) {
viewerImage = viewerImage.mirrored(Settings::flipH, Settings::flipV);
}
int cropLeftPercentPixels = 0, cropTopPercentPixels = 0, cropWidthPercentPixels = 0, cropHeightPercentPixels = 0;
bool croppingOn = false;
if (Settings::cropLeftPercent || Settings::cropTopPercent
|| Settings::cropWidthPercent || Settings::cropHeightPercent) {
croppingOn = true;
cropLeftPercentPixels = (viewerImage.width() * Settings::cropLeftPercent) / 100;
cropTopPercentPixels = (viewerImage.height() * Settings::cropTopPercent) / 100;
cropWidthPercentPixels = (viewerImage.width() * Settings::cropWidthPercent) / 100;
cropHeightPercentPixels = (viewerImage.height() * Settings::cropHeightPercent) / 100;
}
if (Settings::cropLeft || Settings::cropTop || Settings::cropWidth || Settings::cropHeight) {
viewerImage = viewerImage.copy(
Settings::cropLeft + cropLeftPercentPixels,
Settings::cropTop + cropTopPercentPixels,
viewerImage.width() - Settings::cropLeft - Settings::cropWidth - cropLeftPercentPixels -
cropWidthPercentPixels,
viewerImage.height() - Settings::cropTop - Settings::cropHeight - cropTopPercentPixels -
cropHeightPercentPixels);
} else {
if (croppingOn) {
viewerImage = viewerImage.copy(
cropLeftPercentPixels,
cropTopPercentPixels,
viewerImage.width() - cropLeftPercentPixels - cropWidthPercentPixels,
viewerImage.height() - cropTopPercentPixels - cropHeightPercentPixels);
}
}
}
void ImageViewer::mirror() {
switch (mirrorLayout) {
case LayDual: {
mirrorImage = QImage(viewerImage.width() * 2, viewerImage.height(),
QImage::Format_ARGB32);
QPainter painter(&mirrorImage);
painter.drawImage(0, 0, viewerImage);
painter.drawImage(viewerImage.width(), 0, viewerImage.mirrored(true, false));
break;
}
case LayTriple: {
mirrorImage = QImage(viewerImage.width() * 3, viewerImage.height(),
QImage::Format_ARGB32);
QPainter painter(&mirrorImage);
painter.drawImage(0, 0, viewerImage);
painter.drawImage(viewerImage.width(), 0, viewerImage.mirrored(true, false));
painter.drawImage(viewerImage.width() * 2, 0, viewerImage.mirrored(false, false));
break;
}
case LayQuad: {
mirrorImage = QImage(viewerImage.width() * 2, viewerImage.height() * 2,
QImage::Format_ARGB32);
QPainter painter(&mirrorImage);
painter.drawImage(0, 0, viewerImage);
painter.drawImage(viewerImage.width(), 0, viewerImage.mirrored(true, false));
painter.drawImage(0, viewerImage.height(), viewerImage.mirrored(false, true));
painter.drawImage(viewerImage.width(), viewerImage.height(),
viewerImage.mirrored(true, true));
break;
}
case LayVDual: {
mirrorImage = QImage(viewerImage.width(), viewerImage.height() * 2,
QImage::Format_ARGB32);
QPainter painter(&mirrorImage);
painter.drawImage(0, 0, viewerImage);
painter.drawImage(0, viewerImage.height(), viewerImage.mirrored(false, true));
break;
}
}
viewerImage = mirrorImage;
}
static inline int bound0To255(int val) {
return ((val > 255) ? 255 : (val < 0) ? 0 : val);
}
static inline int hslValue(double n1, double n2, double hue) {
double value;
if (hue > 255) {
hue -= 255;
} else if (hue < 0) {
hue += 255;
}
if (hue < 42.5) {
value = n1 + (n2 - n1) * (hue / 42.5);
} else if (hue < 127.5) {
value = n2;
} else if (hue < 170) {
value = n1 + (n2 - n1) * ((170 - hue) / 42.5);
} else {
value = n1;
}
return ROUND(value * 255.0);
}
void rgbToHsl(int r, int g, int b, unsigned char *hue, unsigned char *sat, unsigned char *light) {
double h, s, l;
int min, max;
int delta;
if (r > g) {
max = MAX(r, b);
min = MIN(g, b);
} else {
max = MAX(g, b);
min = MIN(r, b);
}
l = (max + min) / 2.0;
if (max == min) {
s = 0.0;
h = 0.0;
} else {
delta = (max - min);
if (l < 128) {
s = 255 * (double) delta / (double) (max + min);
} else {
s = 255 * (double) delta / (double) (511 - max - min);
}
if (r == max) {
h = (g - b) / (double) delta;
} else if (g == max) {
h = 2 + (b - r) / (double) delta;
} else {
h = 4 + (r - g) / (double) delta;
}
h = h * 42.5;
if (h < 0) {
h += 255;
} else if (h > 255) {
h -= 255;
}
}
*hue = ROUND(h);
*sat = ROUND(s);
*light = ROUND(l);
}
void hslToRgb(double h, double s, double l,
unsigned char *red, unsigned char *green, unsigned char *blue) {
if (s == 0) {
/* achromatic case */
*red = l;
*green = l;
*blue = l;
} else {
double m1, m2;
if (l < 128)
m2 = (l * (255 + s)) / 65025.0;
else
m2 = (l + s - (l * s) / 255.0) / 255.0;
m1 = (l / 127.5) - m2;
/* chromatic case */
*red = hslValue(m1, m2, h + 85);
*green = hslValue(m1, m2, h);
*blue = hslValue(m1, m2, h - 85);
}
}
void ImageViewer::colorize() {
int y, x;
unsigned char hr, hg, hb;
int r, g, b;
QRgb *line;
unsigned char h, s, l;
static unsigned char contrastTransform[256];
static unsigned char brightTransform[256];
bool hasAlpha = viewerImage.hasAlphaChannel();
if (viewerImage.colorCount()) {
viewerImage = viewerImage.convertToFormat(QImage::Format_RGB32);
}
int i;
float contrast = ((float) Settings::contrastVal / 100.0);
float brightness = ((float) Settings::brightVal / 100.0);
for (i = 0; i < 256; ++i) {
if (i < (int) (128.0f + 128.0f * tan(contrast)) && i > (int) (128.0f - 128.0f * tan(contrast))) {
contrastTransform[i] = (i - 128) / tan(contrast) + 128;
} else if (i >= (int) (128.0f + 128.0f * tan(contrast))) {
contrastTransform[i] = 255;
} else {
contrastTransform[i] = 0;
}
}
for (i = 0; i < 256; ++i) {
brightTransform[i] = MIN(255, (int) ((255.0 * pow(i / 255.0, 1.0 / brightness)) + 0.5));
}
for (y = 0; y < viewerImage.height(); ++y) {
line = (QRgb *) viewerImage.scanLine(y);
for (x = 0; x < viewerImage.width(); ++x) {
r = Settings::rNegateEnabled ? bound0To255(255 - qRed(line[x])) : qRed(line[x]);
g = Settings::gNegateEnabled ? bound0To255(255 - qGreen(line[x])) : qGreen(line[x]);
b = Settings::bNegateEnabled ? bound0To255(255 - qBlue(line[x])) : qBlue(line[x]);
r = bound0To255((r * (Settings::redVal + 100)) / 100);
g = bound0To255((g * (Settings::greenVal + 100)) / 100);
b = bound0To255((b * (Settings::blueVal + 100)) / 100);
r = bound0To255(brightTransform[r]);
g = bound0To255(brightTransform[g]);
b = bound0To255(brightTransform[b]);
r = bound0To255(contrastTransform[r]);
g = bound0To255(contrastTransform[g]);
b = bound0To255(contrastTransform[b]);
rgbToHsl(r, g, b, &h, &s, &l);
h = Settings::colorizeEnabled ? Settings::hueVal : h + Settings::hueVal;
s = bound0To255(((s * Settings::saturationVal) / 100));
l = bound0To255(((l * Settings::lightnessVal) / 100));
hslToRgb(h, s, l, &hr, &hg, &hb);
r = Settings::hueRedChannel ? hr : qRed(line[x]);
g = Settings::hueGreenChannel ? hg : qGreen(line[x]);
b = Settings::hueBlueChannel ? hb : qBlue(line[x]);
if (hasAlpha) {
line[x] = qRgba(r, g, b, qAlpha(line[x]));
} else {
line[x] = qRgb(r, g, b);
}
}
}
}
void ImageViewer::refresh() {
if (isAnimation) {
return;
}
if (Settings::scaledWidth) {
viewerImage = origImage.scaled(Settings::scaledWidth, Settings::scaledHeight,
Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
} else {
viewerImage = origImage;
}
transform();
if (Settings::colorsActive || Settings::keepTransform) {
colorize();
}
if (mirrorLayout) {
mirror();
}
viewerPixmap = QPixmap::fromImage(viewerImage);
imageLabel->setPixmap(viewerPixmap);
resizeImage();
}
QImage createImageWithOverlay(const QImage &baseImage, const QImage &overlayImage, int x, int y) {
QImage imageWithOverlay = QImage(overlayImage.size(), QImage::Format_ARGB32_Premultiplied);
QPainter painter(&imageWithOverlay);
QImage scaledImage = baseImage.scaled(overlayImage.width(), overlayImage.height(),
Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(imageWithOverlay.rect(), Qt::transparent);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(x, y, scaledImage);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(0, 0, overlayImage);
painter.end();
return imageWithOverlay;
}
void ImageViewer::reload() {
isAnimation = false;
if (Settings::showImageName) {
if (viewerImageFullPath.left(1) == ":") {
setInfo("No Image");
} else if (viewerImageFullPath.isEmpty()) {
setInfo("Clipboard");
} else {
setInfo(QFileInfo(viewerImageFullPath).fileName());
}
}
if (!Settings::keepTransform) {
Settings::cropLeftPercent = Settings::cropTopPercent = Settings::cropWidthPercent = Settings::cropHeightPercent = 0;
Settings::rotation = 0;
Settings::flipH = Settings::flipV = false;
}
Settings::scaledWidth = Settings::scaledHeight = 0;
Settings::cropLeft = Settings::cropTop = Settings::cropWidth = Settings::cropHeight = 0;
if (newImage || viewerImageFullPath.isEmpty()) {
newImage = true;
viewerImageFullPath = CLIPBOARD_IMAGE_NAME;
origImage.load(":/images/no_image.png");
viewerImage = origImage;
viewerPixmap = QPixmap::fromImage(viewerImage);
imageLabel->setPixmap(viewerPixmap);
pasteImage();
return;
}
QImageReader imageReader(viewerImageFullPath);
if (Settings::enableAnimations && imageReader.supportsAnimation()) {
if (animation) {
delete animation;
}
animation = new QMovie(viewerImageFullPath);
if (animation->frameCount() > 1) {
isAnimation = true;
imageLabel->setMovie(animation);
animation->start();
resizeImage();
return;
}
}
if (imageReader.size().isValid() && imageReader.read(&origImage)) {
viewerImage = origImage;
transform();
if (Settings::colorsActive || Settings::keepTransform) {
colorize();
}
if (mirrorLayout) {
mirror();
}
viewerPixmap = QPixmap::fromImage(viewerImage);
} else {
viewerPixmap = QIcon::fromTheme("image-missing",
QIcon(":/images/error_image.png")).pixmap(BAD_IMAGE_SIZE, BAD_IMAGE_SIZE);
setInfo(imageReader.errorString());
}
imageLabel->setPixmap(viewerPixmap);
resizeImage();
if (Settings::setWindowIcon) {
phototonic->setWindowIcon(viewerPixmap.scaled(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE,
Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
}
void ImageViewer::setInfo(QString infoString) {
imageInfoLabel->setText(infoString);
imageInfoLabel->adjustSize();
}
void ImageViewer::unsetFeedback() {
feedbackLabel->clear();
feedbackLabel->setVisible(false);
}
void ImageViewer::setFeedback(QString feedbackString) {
feedbackLabel->setText(feedbackString);
feedbackLabel->setVisible(true);
int margin = imageInfoLabel->isVisible() ? (imageInfoLabel->height() + 15) : 10;
feedbackLabel->move(10, margin);
feedbackLabel->adjustSize();
QTimer::singleShot(3000, this, SLOT(unsetFeedback()));
}
void ImageViewer::loadImage(QString imageFileName) {
newImage = false;
tempDisableResize = false;
viewerImageFullPath = imageFileName;
if (!Settings::keepZoomFactor) {
Settings::imageZoomFactor = 1.0;
}
QApplication::processEvents();
reload();
}
void ImageViewer::clearImage() {
origImage.load(":/images/no_image.png");
viewerImage = origImage;
viewerPixmap = QPixmap::fromImage(viewerImage);
imageLabel->setPixmap(viewerPixmap);
}
void ImageViewer::monitorCursorState() {
static QPoint lastPos;
if (QCursor::pos() != lastPos) {
lastPos = QCursor::pos();
if (cursorIsHidden) {
QApplication::restoreOverrideCursor();
cursorIsHidden = false;
}
} else {
if (!cursorIsHidden) {
QApplication::setOverrideCursor(Qt::BlankCursor);
cursorIsHidden = true;
}
}
}
void ImageViewer::setCursorHiding(bool hide) {
if (hide) {
mouseMovementTimer->start(500);
} else {
mouseMovementTimer->stop();
if (cursorIsHidden) {
QApplication::restoreOverrideCursor();
cursorIsHidden = false;
}
}
}
void ImageViewer::mouseDoubleClickEvent(QMouseEvent *event) {
QWidget::mouseDoubleClickEvent(event);
while (QApplication::overrideCursor()) {
QApplication::restoreOverrideCursor();
}
}
void ImageViewer::mousePressEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
if (event->modifiers() == Qt::ControlModifier) {
cropOrigin = event->pos();
if (!cropRubberBand) {
cropRubberBand = new CropRubberBand(this);
}
cropRubberBand->show();
cropRubberBand->setGeometry(QRect(cropOrigin, event->pos()).normalized());
} else {
if (cropRubberBand) {
cropRubberBand->hide();
}
}
setMouseMoveData(true, event->x(), event->y());
QApplication::setOverrideCursor(Qt::ClosedHandCursor);
event->accept();
}
QWidget::mousePressEvent(event);
}
void ImageViewer::mouseReleaseEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
setMouseMoveData(false, 0, 0);
while (QApplication::overrideCursor()) {
QApplication::restoreOverrideCursor();
}
if (cropRubberBand && cropRubberBand->isVisible()) {
setFeedback(tr("Selection size: ")
+ QString::number(cropRubberBand->width())
+ "x"
+ QString::number(cropRubberBand->height()));
}
}
QWidget::mouseReleaseEvent(event);
}
void ImageViewer::cropToSelection() {
if (cropRubberBand && cropRubberBand->isVisible()) {
QPoint bandTopLeft = mapToGlobal(cropRubberBand->geometry().topLeft());
QPoint bandBottomRight = mapToGlobal(cropRubberBand->geometry().bottomRight());
bandTopLeft = imageLabel->mapFromGlobal(bandTopLeft);
bandBottomRight = imageLabel->mapFromGlobal(bandBottomRight);
double scaledX = imageLabel->rect().width();
double scaledY = imageLabel->rect().height();
scaledX = viewerPixmap.width() / scaledX;
scaledY = viewerPixmap.height() / scaledY;
bandTopLeft.setX(int(bandTopLeft.x() * scaledX));
bandTopLeft.setY(int(bandTopLeft.y() * scaledY));
bandBottomRight.setX(int(bandBottomRight.x() * scaledX));
bandBottomRight.setY(int(bandBottomRight.y() * scaledY));
int cropLeft = bandTopLeft.x();
int cropTop = bandTopLeft.y();
int cropWidth = viewerPixmap.width() - bandBottomRight.x();
int cropHeight = viewerPixmap.height() - bandBottomRight.y();
if (cropLeft > 0) {
Settings::cropLeft += cropLeft;
}
if (cropTop > 0) {
Settings::cropTop += cropTop;
}
if (cropWidth > 0) {
Settings::cropWidth += cropWidth;
}
if (cropHeight > 0) {
Settings::cropHeight += cropHeight;
}
cropRubberBand->hide();
refresh();
} else {
MessageBox messageBox(this);
messageBox.warning(tr("No selection for cropping"),
tr("To make a selection, hold down the Ctrl key and select a region using the mouse."));
}
}
void ImageViewer::setMouseMoveData(bool lockMove, int lMouseX, int lMouseY) {
moveImageLocked = lockMove;
mouseX = lMouseX;
mouseY = lMouseY;
layoutX = imageLabel->pos().x();
layoutY = imageLabel->pos().y();
}
void ImageViewer::mouseMoveEvent(QMouseEvent *event) {
if (event->modifiers() == Qt::ControlModifier) {
if (cropRubberBand && cropRubberBand->isVisible()) {
cropRubberBand->setGeometry(QRect(cropOrigin, event->pos()).normalized());
}
} else {
if (moveImageLocked) {
int newX = layoutX + (event->pos().x() - mouseX);
int newY = layoutY + (event->pos().y() - mouseY);
bool needToMove = false;
if (imageLabel->size().width() > size().width()) {
if (newX > 0) {
newX = 0;
} else if (newX < (size().width() - imageLabel->size().width())) {
newX = (size().width() - imageLabel->size().width());
}
needToMove = true;
} else {
newX = layoutX;
}
if (imageLabel->size().height() > size().height()) {
if (newY > 0) {
newY = 0;
} else if (newY < (size().height() - imageLabel->size().height())) {
newY = (size().height() - imageLabel->size().height());
}
needToMove = true;
} else {
newY = layoutY;
}
if (needToMove) {
imageLabel->move(newX, newY);
}
}
}
}
void ImageViewer::keyMoveEvent(int direction) {
int newX = layoutX = imageLabel->pos().x();
int newY = layoutY = imageLabel->pos().y();
bool needToMove = false;
switch (direction) {
case MoveLeft:
newX += 50;
break;
case MoveRight:
newX -= 50;
break;
case MoveUp:
newY += 50;
break;
case MoveDown:
newY -= 50;
break;
}
if (imageLabel->size().width() > size().width()) {
if (newX > 0) {
newX = 0;
} else if (newX < (size().width() - imageLabel->size().width())) {
newX = (size().width() - imageLabel->size().width());
}
needToMove = true;
} else {
newX = layoutX;
}
if (imageLabel->size().height() > size().height()) {
if (newY > 0) {
newY = 0;
} else if (newY < (size().height() - imageLabel->size().height())) {
newY = (size().height() - imageLabel->size().height());
}
needToMove = true;
} else {
newY = layoutY;
}
if (needToMove) {
int i;
switch (direction) {
case MoveLeft:
for (i = imageLabel->pos().x(); i <= newX; ++i)
imageLabel->move(newX, newY);
break;
case MoveRight:
for (i = imageLabel->pos().x(); i >= newX; --i)
imageLabel->move(newX, newY);
break;
case MoveUp:
for (i = imageLabel->pos().y(); i <= newY; ++i)
imageLabel->move(newX, newY);
break;
case MoveDown:
for (i = imageLabel->pos().y(); i >= newY; --i)
imageLabel->move(newX, newY);
break;
}
}
}
void ImageViewer::saveImage() {
Exiv2::Image::AutoPtr image;
bool exifError = false;
if (newImage) {
saveImageAs();
return;
}
setFeedback(tr("Saving..."));
try {
image = Exiv2::ImageFactory::open(viewerImageFullPath.toStdString());
image->readMetadata();
}
catch (Exiv2::Error &error) {
exifError = true;
}
QImageReader imageReader(viewerImageFullPath);
if (!viewerPixmap.save(viewerImageFullPath, imageReader.format().toUpper(), Settings::defaultSaveQuality)) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to save image."));
return;
}
if (!exifError) {
try {
image->writeMetadata();
}
catch (Exiv2::Error &error) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to save Exif metadata."));
}
}
reload();
setFeedback(tr("Image saved."));
}
void ImageViewer::saveImageAs() {
Exiv2::Image::AutoPtr exifImage;
Exiv2::Image::AutoPtr newExifImage;
bool exifError = false;
setCursorHiding(false);
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save image as"),
viewerImageFullPath,
tr("Images") +
" (*.jpg *.jpeg *.png *.bmp *.tif *.tiff *.ppm *.pgm *.pbm *.xbm *.xpm *.cur *.ico *.icns *.wbmp *.webp)");
if (!fileName.isEmpty()) {
try {
exifImage = Exiv2::ImageFactory::open(viewerImageFullPath.toStdString());
exifImage->readMetadata();
}
catch (Exiv2::Error &error) {
exifError = true;
}
if (!viewerPixmap.save(fileName, 0, Settings::defaultSaveQuality)) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to save image."));
} else {
if (!exifError) {
try {
newExifImage = Exiv2::ImageFactory::open(fileName.toStdString());
newExifImage->setMetadata(*exifImage);
newExifImage->writeMetadata();
}
catch (Exiv2::Error &error) {
exifError = true;
}
}
setFeedback(tr("Image saved."));
}
}
if (phototonic->isFullScreen()) {
setCursorHiding(true);
}
}
void ImageViewer::contextMenuEvent(QContextMenuEvent *) {
while (QApplication::overrideCursor()) {
QApplication::restoreOverrideCursor();
}
ImagePopUpMenu->exec(QCursor::pos());
}
int ImageViewer::getImageWidthPreCropped() {
return origImage.width();
}
int ImageViewer::getImageHeightPreCropped() {
return origImage.height();
}
bool ImageViewer::isNewImage() {
return newImage;
}
void ImageViewer::copyImage() {
QApplication::clipboard()->setImage(viewerImage);
}
void ImageViewer::pasteImage() {
if (isAnimation) {
return;
}
if (!QApplication::clipboard()->image().isNull()) {
origImage = QApplication::clipboard()->image();
refresh();
}
phototonic->setWindowTitle(tr("Clipboard") + " - Phototonic");
if (Settings::setWindowIcon) {
phototonic->setWindowIcon(phototonic->getDefaultWindowIcon());
}
}
void ImageViewer::setBackgroundColor() {
QString bgColor = "background: rgb(%1, %2, %3); ";
bgColor = bgColor.arg(Settings::viewerBackgroundColor.red())
.arg(Settings::viewerBackgroundColor.green())
.arg(Settings::viewerBackgroundColor.blue());
QString styleSheet = "QWidget { " + bgColor + " }";
scrollArea->setStyleSheet(styleSheet);
}
phototonic-2.1/ImageViewer.h 0000664 0000000 0000000 00000006437 13251276421 0016134 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef IMAGE_VIEWER_H
#define IMAGE_VIEWER_H
#include
#include
#include "Settings.h"
#include "CropRubberband.h"
#include "MetadataCache.h"
class Phototonic;
class ImageViewer : public QWidget {
Q_OBJECT
public:
bool tempDisableResize;
int mirrorLayout;
QString viewerImageFullPath;
QMenu *ImagePopUpMenu;
QScrollArea *scrollArea;
QLabel *imageInfoLabel;
CropRubberBand *cropRubberBand;
enum ZoomMethods {
Disable = 0,
WidthAndHeight,
Width,
Height,
Disprop
};
enum MirrorLayouts {
LayNone = 0,
LayDual,
LayTriple,
LayQuad,
LayVDual
};
enum Movement {
MoveUp = 0,
MoveDown,
MoveLeft,
MoveRight
};
ImageViewer(QWidget *parent, MetadataCache *metadataCache);
void loadImage(QString imageFileName);
void clearImage();
void resizeImage();
void setCursorHiding(bool hide);
void refresh();
void reload();
int getImageWidthPreCropped();
int getImageHeightPreCropped();
bool isNewImage();
void keyMoveEvent(int direction);
void rotateByExifRotation(QImage &image, QString &imageFullPath);
void setInfo(QString infoString);
void setFeedback(QString feedbackString);
void setBackgroundColor();
public slots:
void monitorCursorState();
void saveImage();
void saveImageAs();
void copyImage();
void pasteImage();
void cropToSelection();
private slots:
void unsetFeedback();
protected:
void resizeEvent(QResizeEvent *event);
void showEvent(QShowEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void contextMenuEvent(QContextMenuEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
Phototonic *phototonic;
QLabel *imageLabel;
QPixmap viewerPixmap;
QImage origImage;
QImage viewerImage;
QImage mirrorImage;
QTimer *mouseMovementTimer;
QMovie *animation;
bool newImage;
bool cursorIsHidden;
bool moveImageLocked;
int mouseX;
int mouseY;
int layoutX;
int layoutY;
bool isAnimation;
QLabel *feedbackLabel;
QPoint cropOrigin;
MetadataCache *metadataCache;
void setMouseMoveData(bool lockMove, int lMouseX, int lMouseY);
void centerImage(QSize &imgSize);
void transform();
void mirror();
void colorize();
};
#endif // IMAGE_VIEWER_H
phototonic-2.1/InfoViewer.cpp 0000664 0000000 0000000 00000007611 13251276421 0016333 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "InfoViewer.h"
#include "ThumbsViewer.h"
InfoView::InfoView(QWidget *parent) : QWidget(parent) {
infoViewerTable = new QTableView();
infoViewerTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
infoViewerTable->verticalHeader()->setVisible(false);
infoViewerTable->verticalHeader()->setDefaultSectionSize(infoViewerTable->verticalHeader()->minimumSectionSize());
infoViewerTable->horizontalHeader()->setVisible(false);
infoViewerTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
infoViewerTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
infoViewerTable->setSelectionBehavior(QAbstractItemView::SelectItems);
infoViewerTable->setTabKeyNavigation(false);
infoViewerTable->setShowGrid(false);
imageInfoModel = new QStandardItemModel(this);
infoViewerTable->setModel(imageInfoModel);
// Menu
QAction *copyAction = new QAction(tr("Copy"), this);
infoViewerTable->connect(copyAction, SIGNAL(triggered()), this, SLOT(copyEntry()));
infoMenu = new QMenu("");
infoMenu->addAction(copyAction);
infoViewerTable->setContextMenuPolicy(Qt::CustomContextMenu);
connect(infoViewerTable, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showInfoViewMenu(QPoint)));
QVBoxLayout *infoViewerLayout = new QVBoxLayout;
// Filter items
filterLineEdit = new QLineEdit;
connect(filterLineEdit, SIGNAL(textChanged(
const QString&)), this, SLOT(filterItems()));
filterLineEdit->setClearButtonEnabled(true);
filterLineEdit->setPlaceholderText(tr("Filter Items"));
infoViewerLayout->addWidget(filterLineEdit);
infoViewerLayout->addWidget(infoViewerTable);
infoViewerLayout->setContentsMargins(2, 2, 2, 2);
infoViewerLayout->setSpacing(2);
setLayout(infoViewerLayout);
}
void InfoView::showInfoViewMenu(QPoint pt) {
selectedEntry = infoViewerTable->indexAt(pt);
if (selectedEntry.isValid()) {
infoMenu->popup(infoViewerTable->viewport()->mapToGlobal(pt));
}
}
void InfoView::clear() {
imageInfoModel->clear();
}
void InfoView::addEntry(QString &key, QString &value) {
if (!filterLineEdit->text().isEmpty() && !key.toLower().contains(filterLineEdit->text().toLower())) {
return;
}
int atRow = imageInfoModel->rowCount();
QStandardItem *itemKey = new QStandardItem(key);
imageInfoModel->insertRow(atRow, itemKey);
if (!value.isEmpty()) {
QStandardItem *itemVal = new QStandardItem(value);
itemVal->setToolTip(value);
imageInfoModel->setItem(atRow, 1, itemVal);
}
}
void InfoView::addTitleEntry(QString title) {
int atRow = imageInfoModel->rowCount();
QStandardItem *itemKey = new QStandardItem(title);
imageInfoModel->insertRow(atRow, itemKey);
QFont boldFont;
boldFont.setBold(true);
itemKey->setData(boldFont, Qt::FontRole);
}
void InfoView::copyEntry() {
if (selectedEntry.isValid()) {
QApplication::clipboard()->setText(imageInfoModel->itemFromIndex(selectedEntry)->toolTip());
}
}
void InfoView::filterItems() {
QItemSelection dummy;
emit updateInfo(dummy);
}
phototonic-2.1/InfoViewer.h 0000664 0000000 0000000 00000002566 13251276421 0016004 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef INFO_VIEWER_H
#define INFO_VIEWER_H
#include
class InfoView : public QWidget {
Q_OBJECT
public:
InfoView(QWidget *parent);
void clear();
void addEntry(QString &key, QString &value);
void addTitleEntry(QString title);
signals:
void updateInfo(QItemSelection dummy);
public slots:
void showInfoViewMenu(QPoint pt);
void copyEntry();
private slots:
void filterItems();
private:
QTableView *infoViewerTable;
QStandardItemModel *imageInfoModel;
QModelIndex selectedEntry;
QMenu *infoMenu;
QLineEdit *filterLineEdit;
};
#endif // INFO_VIEWER_H
phototonic-2.1/MessageBox.cpp 0000664 0000000 0000000 00000010140 13251276421 0016302 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "MessageBox.h"
#include "Phototonic.h"
MessageBox::MessageBox(QWidget *parent) : QMessageBox(parent) {
setWindowIcon(QIcon(":/images/phototonic.png"));
}
void MessageBox::critical(const QString &title, const QString &message) {
setWindowTitle(title);
setText(message);
setIcon(MessageBox::Critical);
exec();
}
void MessageBox::warning(const QString &title, const QString &message) {
setWindowTitle(title);
setText(message);
setIcon(MessageBox::Warning);
exec();
}
void MessageBox::about() {
QString aboutString = "" + QString(VERSION) + "
"
+ tr("Image Viewer and Organizer
")
+ "Qt v" + QT_VERSION_STR
+ "" + tr("Home page")
+ "
"
"Code: | Ofer Kashayov | (oferkv@gmail.com) |
"
" | Christopher Roy Bratusek | (nano@jpberlin.de) |
"
" | Krzysztof Pyrkosz | (pyrkosz@o2.pl) |
"
" | Roman Chistokhodov | (freeslave93@gmail.com) |
"
" | Thomas Lübking | (thomas.luebking@gmail.com) |
"
" | Tung Le | (https://github.com/everbot) |
"
" | Peter Mattern | (https://github.com/pmattern) |
"
"Bosnian: | Dino Duratović | (dinomol@mail.com) |
"
"Croatian: | Dino Duratović | (dinomol@mail.com) |
"
"Czech: | Pavel Fric | (pavelfric@seznam.cz) |
"
"French: | Adrien Daugabel | (adrien.d@mageialinux-online.org) |
"
" | David Geiger | (david.david@mageialinux-online.org) |
"
" | Rémi Verschelde | (akien@mageia.org) |
"
"German: | Jonathan Hooverman | (jonathan.hooverman@gmail.com) |
"
"Polish: | Robert Wojewódzki | (robwoj44@poczta.onet.pl) |
"
" | Krzysztof Pyrkosz | (pyrkosz@o2.pl) |
"
"Portuguese: | Marcos M. Nascimento | (wstlmn@uol.com.br) |
"
"Russian: | Ilya Alexandrovich | (yast4ik@gmail.com) |
"
"Serbian: | Dino Duratović | (dinomol@mail.com) |
"
"Phototonic is licensed under the GNU General Public License version 3
"
"Copyright © 2013-2018 Ofer Kashayov
";
setWindowTitle(tr("About"));
setText(aboutString);
setIconPixmap(QIcon(":/images/phototonic.png").pixmap(64, 64));
exec();
}
phototonic-2.1/MessageBox.h 0000664 0000000 0000000 00000002136 13251276421 0015755 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef MESSAGE_BOX_H
#define MESSAGE_BOX_H
#include
class MessageBox : public QMessageBox {
Q_OBJECT
public:
MessageBox(QWidget *parent);
void critical(const QString &title, const QString &message);
void warning(const QString &title, const QString &message);
void about();
};
#endif // MESSAGE_BOX_H
phototonic-2.1/MetadataCache.cpp 0000664 0000000 0000000 00000007000 13251276421 0016712 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2015 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include
#include "Settings.h"
#include "MetadataCache.h"
void MetadataCache::updateImageTags(QString &imageFileName, QSet tags) {
cache[imageFileName].tags = tags;
}
bool MetadataCache::removeTagFromImage(QString &imageFileName, const QString &tagName) {
return cache[imageFileName].tags.remove(tagName);
}
void MetadataCache::removeImage(QString &imageFileName) {
cache.remove(imageFileName);
}
QSet &MetadataCache::getImageTags(QString &imageFileName) {
return cache[imageFileName].tags;
}
long MetadataCache::getImageOrientation(QString &imageFileName) {
if (cache.contains(imageFileName) || loadImageMetadata(imageFileName)) {
return cache[imageFileName].orientation;
}
return 0;
}
void MetadataCache::setImageTags(const QString &imageFileName, QSet tags) {
ImageMetadata imageMetadata;
imageMetadata.tags = tags;
cache.insert(imageFileName, imageMetadata);
}
void MetadataCache::addTagToImage(QString &imageFileName, QString &tagName) {
if (cache[imageFileName].tags.contains(tagName)) {
return;
}
cache[imageFileName].tags.insert(tagName);
}
void MetadataCache::clear() {
cache.clear();
}
bool MetadataCache::loadImageMetadata(const QString &imageFullPath) {
Exiv2::Image::AutoPtr exifImage;
QSet tags;
long orientation = 0;
try {
exifImage = Exiv2::ImageFactory::open(imageFullPath.toStdString());
exifImage->readMetadata();
} catch (Exiv2::Error &error) {
return false;
}
try {
Exiv2::ExifData &exifData = exifImage->exifData();
if (!exifData.empty()) {
orientation = exifData["Exif.Image.Orientation"].value().toLong();
}
} catch (Exiv2::Error &error) {
qWarning() << "Failed to read Exif metadata";
}
try {
Exiv2::IptcData &iptcData = exifImage->iptcData();
if (!iptcData.empty()) {
QString key;
Exiv2::IptcData::iterator end = iptcData.end();
for (Exiv2::IptcData::iterator iptcIt = iptcData.begin(); iptcIt != end; ++iptcIt) {
if (iptcIt->tagName() == "Keywords") {
QString tagName = QString::fromUtf8(iptcIt->toString().c_str());
tags.insert(tagName);
Settings::knownTags.insert(tagName);
}
}
}
} catch (Exiv2::Error &error) {
qWarning() << "Failed to read Iptc metadata";
}
ImageMetadata imageMetadata;
if (tags.size()) {
imageMetadata.tags = tags;
}
if (orientation) {
imageMetadata.orientation = orientation;
}
if (tags.size() || orientation) {
cache.insert(imageFullPath, imageMetadata);
}
return true;
}
phototonic-2.1/MetadataCache.h 0000664 0000000 0000000 00000003040 13251276421 0016357 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2015 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef META_DATA_CACHE_H
#define META_DATA_CACHE_H
#include
class ImageMetadata {
public:
QSet tags;
long orientation;
};
class MetadataCache {
private:
QMap cache;
public:
void updateImageTags(QString &imageFileName, QSet tags);
void addTagToImage(QString &imageFileName, QString &tagName);
bool removeTagFromImage(QString &imageFileName, const QString &tagName);
void removeImage(QString &imageFileName);
QSet &getImageTags(QString &imageFileName);
void setImageTags(const QString &imageFileName, QSet tags);
void clear();
bool loadImageMetadata(const QString &imageFullPath);
long getImageOrientation(QString &imageFileName);
};
#endif // META_DATA_CACHE_H
phototonic-2.1/Phototonic.cpp 0000664 0000000 0000000 00000411340 13251276421 0016402 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2015 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "DirCompleter.h"
#include "Phototonic.h"
#include "Settings.h"
#include "CopyMoveDialog.h"
#include "ResizeDialog.h"
#include "CropDialog.h"
#include "ColorsDialog.h"
#include "ExternalAppsDialog.h"
#include "ProgressDialog.h"
#include "ImagePreview.h"
#include "FileListWidget.h"
#include "RenameDialog.h"
#include "Trashcan.h"
#include "MessageBox.h"
Phototonic::Phototonic(QStringList argumentsList, int filesStartAt, QWidget *parent) : QMainWindow(parent) {
Settings::appSettings = new QSettings("phototonic", "phototonic");
setDockOptions(QMainWindow::AllowNestedDocks);
readSettings();
createThumbsViewer();
createActions();
createMenus();
createToolBars();
createStatusBar();
createFileSystemDock();
createBookmarksDock();
createImagePreviewDock();
createImageTagsDock();
createImageViewer();
updateExternalApps();
loadShortcuts();
setupDocks();
connect(qApp, SIGNAL(focusChanged(QWidget * , QWidget * )), this, SLOT(updateActions()));
restoreGeometry(Settings::appSettings->value(Settings::optionGeometry).toByteArray());
restoreState(Settings::appSettings->value(Settings::optionWindowState).toByteArray());
defaultApplicationIcon = QIcon(":/images/phototonic.png");
setWindowIcon(defaultApplicationIcon);
stackedLayout = new QStackedLayout;
QWidget *stackedLayoutWidget = new QWidget;
stackedLayout->addWidget(thumbsViewer);
stackedLayout->addWidget(imageViewer);
stackedLayoutWidget->setLayout(stackedLayout);
setCentralWidget(stackedLayoutWidget);
processStartupArguments(argumentsList, filesStartAt);
copyMoveToDialog = nullptr;
colorsDialog = nullptr;
cropDialog = nullptr;
initComplete = true;
thumbsViewer->isBusy = false;
currentHistoryIdx = -1;
needHistoryRecord = true;
interfaceDisabled = false;
refreshThumbs(true);
if (Settings::layoutMode == ThumbViewWidget) {
thumbsViewer->setFocus(Qt::OtherFocusReason);
}
}
void Phototonic::processStartupArguments(QStringList argumentsList, int filesStartAt) {
if (argumentsList.size() > filesStartAt) {
QFileInfo firstArgument(argumentsList.at(filesStartAt));
if (firstArgument.isDir()) {
Settings::currentDirectory = argumentsList.at(filesStartAt);
} else if (argumentsList.size() > filesStartAt + 1) {
loadStartupFileList(argumentsList, filesStartAt);
return;
} else {
Settings::currentDirectory = firstArgument.absolutePath();
QString cliFileName = Settings::currentDirectory + QDir::separator() + firstArgument.fileName();
loadImageFromCliArguments(cliFileName);
QTimer::singleShot(1000, this, SLOT(updateIndexByViewerImage()));
}
} else {
if (Settings::startupDir == Settings::SpecifiedDir) {
Settings::currentDirectory = Settings::specifiedStartDir;
} else if (Settings::startupDir == Settings::RememberLastDir) {
Settings::currentDirectory = Settings::appSettings->value(Settings::optionLastDir).toString();
}
}
selectCurrentViewDir();
}
QIcon &Phototonic::getDefaultWindowIcon() {
return defaultApplicationIcon;
}
void Phototonic::loadStartupFileList(QStringList argumentsList, int filesStartAt) {
Settings::filesList.clear();
for (int i = filesStartAt; i < argumentsList.size(); i++) {
QFile currentFileFullPath(argumentsList[i]);
QFileInfo currentFileInfo(currentFileFullPath);
if (!Settings::filesList.contains(currentFileInfo.absoluteFilePath())) {
Settings::filesList << currentFileInfo.absoluteFilePath();
}
}
fileSystemTree->clearSelection();
fileListWidget->setItemSelected(fileListWidget->itemAt(0, 0), true);
Settings::isFileListLoaded = true;
}
bool Phototonic::event(QEvent *event) {
if (event->type() == QEvent::ActivationChange ||
(Settings::layoutMode == ThumbViewWidget && event->type() == QEvent::MouseButtonRelease)) {
thumbsViewer->loadVisibleThumbs();
}
return QMainWindow::event(event);
}
void Phototonic::createThumbsViewer() {
metadataCache = new MetadataCache;
thumbsViewer = new ThumbsViewer(this, metadataCache);
thumbsViewer->thumbsSortFlags = (QDir::SortFlags) Settings::appSettings->value(
Settings::optionThumbsSortFlags).toInt();
thumbsViewer->thumbsSortFlags |= QDir::IgnoreCase;
connect(thumbsViewer->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
this, SLOT(updateActions()));
imageInfoDock = new QDockWidget(tr("Image Info"), this);
imageInfoDock->setObjectName("Image Info");
imageInfoDock->setWidget(thumbsViewer->infoView);
connect(imageInfoDock->toggleViewAction(), SIGNAL(triggered()), this, SLOT(setImageInfoDockVisibility()));
connect(imageInfoDock, SIGNAL(visibilityChanged(bool)), this, SLOT(setImageInfoDockVisibility()));
}
void Phototonic::addMenuSeparator(QWidget *widget) {
QAction *separator = new QAction(this);
separator->setSeparator(true);
widget->addAction(separator);
}
void Phototonic::createImageViewer() {
imageViewer = new ImageViewer(this, metadataCache);
connect(saveAction, SIGNAL(triggered()), imageViewer, SLOT(saveImage()));
connect(saveAsAction, SIGNAL(triggered()), imageViewer, SLOT(saveImageAs()));
connect(copyImageAction, SIGNAL(triggered()), imageViewer, SLOT(copyImage()));
connect(pasteImageAction, SIGNAL(triggered()), imageViewer, SLOT(pasteImage()));
connect(cropToSelectionAction, SIGNAL(triggered()), imageViewer, SLOT(cropToSelection()));
imageViewer->ImagePopUpMenu = new QMenu();
// Widget actions
imageViewer->addAction(slideShowAction);
imageViewer->addAction(nextImageAction);
imageViewer->addAction(prevImageAction);
imageViewer->addAction(firstImageAction);
imageViewer->addAction(lastImageAction);
imageViewer->addAction(randomImageAction);
imageViewer->addAction(zoomInAction);
imageViewer->addAction(zoomOutAction);
imageViewer->addAction(origZoomAction);
imageViewer->addAction(resetZoomAction);
imageViewer->addAction(rotateRightAction);
imageViewer->addAction(rotateLeftAction);
imageViewer->addAction(freeRotateRightAction);
imageViewer->addAction(freeRotateLeftAction);
imageViewer->addAction(flipHorizontalAction);
imageViewer->addAction(flipVerticalAction);
imageViewer->addAction(cropAction);
imageViewer->addAction(cropToSelectionAction);
imageViewer->addAction(resizeAction);
imageViewer->addAction(saveAction);
imageViewer->addAction(saveAsAction);
imageViewer->addAction(copyImageAction);
imageViewer->addAction(pasteImageAction);
imageViewer->addAction(deleteAction);
imageViewer->addAction(deletePermanentlyAction);
imageViewer->addAction(renameAction);
imageViewer->addAction(CloseImageAction);
imageViewer->addAction(fullScreenAction);
imageViewer->addAction(settingsAction);
imageViewer->addAction(mirrorDisabledAction);
imageViewer->addAction(mirrorDualAction);
imageViewer->addAction(mirrorTripleAction);
imageViewer->addAction(mirrorDualVerticalAction);
imageViewer->addAction(mirrorQuadAction);
imageViewer->addAction(keepTransformAction);
imageViewer->addAction(keepZoomAction);
imageViewer->addAction(refreshAction);
imageViewer->addAction(colorsAction);
imageViewer->addAction(moveRightAction);
imageViewer->addAction(moveLeftAction);
imageViewer->addAction(moveUpAction);
imageViewer->addAction(moveDownAction);
imageViewer->addAction(showClipboardAction);
imageViewer->addAction(copyToAction);
imageViewer->addAction(moveToAction);
imageViewer->addAction(resizeAction);
imageViewer->addAction(viewImageAction);
imageViewer->addAction(exitAction);
imageViewer->addAction(showViewerToolbarAction);
imageViewer->addAction(externalAppsAction);
// Actions
addMenuSeparator(imageViewer->ImagePopUpMenu);
imageViewer->ImagePopUpMenu->addAction(nextImageAction);
imageViewer->ImagePopUpMenu->addAction(prevImageAction);
imageViewer->ImagePopUpMenu->addAction(firstImageAction);
imageViewer->ImagePopUpMenu->addAction(lastImageAction);
imageViewer->ImagePopUpMenu->addAction(randomImageAction);
imageViewer->ImagePopUpMenu->addAction(slideShowAction);
addMenuSeparator(imageViewer->ImagePopUpMenu);
zoomSubMenu = new QMenu(tr("Zoom"));
zoomSubMenuAction = new QAction(tr("Zoom"), this);
zoomSubMenuAction->setIcon(QIcon::fromTheme("edit-find", QIcon(":/images/zoom.png")));
zoomSubMenuAction->setMenu(zoomSubMenu);
imageViewer->ImagePopUpMenu->addAction(zoomSubMenuAction);
zoomSubMenu->addAction(zoomInAction);
zoomSubMenu->addAction(zoomOutAction);
zoomSubMenu->addAction(origZoomAction);
zoomSubMenu->addAction(resetZoomAction);
addMenuSeparator(zoomSubMenu);
zoomSubMenu->addAction(keepZoomAction);
MirroringSubMenu = new QMenu(tr("Mirroring"));
mirrorSubMenuAction = new QAction(tr("Mirroring"), this);
mirrorSubMenuAction->setMenu(MirroringSubMenu);
mirroringActionGroup = new QActionGroup(this);
mirroringActionGroup->addAction(mirrorDisabledAction);
mirroringActionGroup->addAction(mirrorDualAction);
mirroringActionGroup->addAction(mirrorTripleAction);
mirroringActionGroup->addAction(mirrorDualVerticalAction);
mirroringActionGroup->addAction(mirrorQuadAction);
MirroringSubMenu->addActions(mirroringActionGroup->actions());
transformSubMenu = new QMenu(tr("Transform"));
transformSubMenuAction = new QAction(tr("Transform"), this);
transformSubMenuAction->setMenu(transformSubMenu);
imageViewer->ImagePopUpMenu->addAction(resizeAction);
imageViewer->ImagePopUpMenu->addAction(cropToSelectionAction);
imageViewer->ImagePopUpMenu->addAction(transformSubMenuAction);
transformSubMenu->addAction(colorsAction);
transformSubMenu->addAction(rotateRightAction);
transformSubMenu->addAction(rotateLeftAction);
transformSubMenu->addAction(freeRotateRightAction);
transformSubMenu->addAction(freeRotateLeftAction);
transformSubMenu->addAction(flipHorizontalAction);
transformSubMenu->addAction(flipVerticalAction);
transformSubMenu->addAction(cropAction);
addMenuSeparator(transformSubMenu);
transformSubMenu->addAction(keepTransformAction);
imageViewer->ImagePopUpMenu->addAction(mirrorSubMenuAction);
addMenuSeparator(imageViewer->ImagePopUpMenu);
imageViewer->ImagePopUpMenu->addAction(copyToAction);
imageViewer->ImagePopUpMenu->addAction(moveToAction);
imageViewer->ImagePopUpMenu->addAction(saveAction);
imageViewer->ImagePopUpMenu->addAction(saveAsAction);
imageViewer->ImagePopUpMenu->addAction(renameAction);
imageViewer->ImagePopUpMenu->addAction(deleteAction);
imageViewer->ImagePopUpMenu->addAction(deletePermanentlyAction);
imageViewer->ImagePopUpMenu->addAction(openWithMenuAction);
addMenuSeparator(imageViewer->ImagePopUpMenu);
viewSubMenu = new QMenu(tr("View"));
viewSubMenuAction = new QAction(tr("View"), this);
viewSubMenuAction->setMenu(viewSubMenu);
imageViewer->ImagePopUpMenu->addAction(viewSubMenuAction);
viewSubMenu->addAction(fullScreenAction);
viewSubMenu->addAction(showClipboardAction);
viewSubMenu->addAction(showViewerToolbarAction);
viewSubMenu->addAction(refreshAction);
imageViewer->ImagePopUpMenu->addAction(copyImageAction);
imageViewer->ImagePopUpMenu->addAction(pasteImageAction);
imageViewer->ImagePopUpMenu->addAction(CloseImageAction);
imageViewer->ImagePopUpMenu->addAction(exitAction);
addMenuSeparator(imageViewer->ImagePopUpMenu);
imageViewer->ImagePopUpMenu->addAction(settingsAction);
imageViewer->setContextMenuPolicy(Qt::DefaultContextMenu);
Settings::isFullScreen = Settings::appSettings->value(Settings::optionFullScreenMode).toBool();
fullScreenAction->setChecked(Settings::isFullScreen);
thumbsViewer->imagePreview->setImageViewer(imageViewer);
}
void Phototonic::createActions() {
thumbsGoToTopAction = new QAction(tr("Top"), this);
thumbsGoToTopAction->setObjectName("thumbsGoTop");
thumbsGoToTopAction->setIcon(QIcon::fromTheme("go-top", QIcon(":/images/top.png")));
connect(thumbsGoToTopAction, SIGNAL(triggered()), this, SLOT(goTop()));
thumbsGoToBottomAction = new QAction(tr("Bottom"), this);
thumbsGoToBottomAction->setObjectName("thumbsGoBottom");
thumbsGoToBottomAction->setIcon(QIcon::fromTheme("go-bottom", QIcon(":/images/bottom.png")));
connect(thumbsGoToBottomAction, SIGNAL(triggered()), this, SLOT(goBottom()));
CloseImageAction = new QAction(tr("Close Viewer"), this);
CloseImageAction->setObjectName("closeImage");
connect(CloseImageAction, SIGNAL(triggered()), this, SLOT(hideViewer()));
fullScreenAction = new QAction(tr("Full Screen"), this);
fullScreenAction->setObjectName("fullScreen");
fullScreenAction->setCheckable(true);
connect(fullScreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen()));
settingsAction = new QAction(tr("Preferences"), this);
settingsAction->setObjectName("settings");
settingsAction->setIcon(QIcon::fromTheme("preferences-system", QIcon(":/images/settings.png")));
connect(settingsAction, SIGNAL(triggered()), this, SLOT(showSettings()));
exitAction = new QAction(tr("Exit"), this);
exitAction->setObjectName("exit");
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
thumbsZoomInAction = new QAction(tr("Enlarge Thumbnails"), this);
thumbsZoomInAction->setObjectName("thumbsZoomIn");
connect(thumbsZoomInAction, SIGNAL(triggered()), this, SLOT(thumbsZoomIn()));
thumbsZoomInAction->setIcon(QIcon::fromTheme("zoom-in", QIcon(":/images/zoom_in.png")));
if (thumbsViewer->thumbSize == THUMB_SIZE_MAX) {
thumbsZoomInAction->setEnabled(false);
}
thumbsZoomOutAction = new QAction(tr("Shrink Thumbnails"), this);
thumbsZoomOutAction->setObjectName("thumbsZoomOut");
connect(thumbsZoomOutAction, SIGNAL(triggered()), this, SLOT(thumbsZoomOut()));
thumbsZoomOutAction->setIcon(QIcon::fromTheme("zoom-out", QIcon(":/images/zoom_out.png")));
if (thumbsViewer->thumbSize == THUMB_SIZE_MIN) {
thumbsZoomOutAction->setEnabled(false);
}
cutAction = new QAction(tr("Cut"), this);
cutAction->setObjectName("cut");
cutAction->setIcon(QIcon::fromTheme("edit-cut", QIcon(":/images/cut.png")));
connect(cutAction, SIGNAL(triggered()), this, SLOT(cutThumbs()));
cutAction->setEnabled(false);
copyAction = new QAction(tr("Copy"), this);
copyAction->setObjectName("copy");
copyAction->setIcon(QIcon::fromTheme("edit-copy", QIcon(":/images/copy.png")));
connect(copyAction, SIGNAL(triggered()), this, SLOT(copyThumbs()));
copyAction->setEnabled(false);
copyToAction = new QAction(tr("Copy to..."), this);
copyToAction->setObjectName("copyTo");
connect(copyToAction, SIGNAL(triggered()), this, SLOT(copyImagesTo()));
moveToAction = new QAction(tr("Move to..."), this);
moveToAction->setObjectName("moveTo");
connect(moveToAction, SIGNAL(triggered()), this, SLOT(moveImagesTo()));
deleteAction = new QAction(tr("Move to Trash"), this);
deleteAction->setObjectName("moveToTrash");
deleteAction->setIcon(style()->standardIcon(QStyle::SP_TrashIcon));
connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteOperation()));
deletePermanentlyAction = new QAction(tr("Delete"), this);
deletePermanentlyAction->setObjectName("delete");
deletePermanentlyAction->setIcon(QIcon::fromTheme("edit-delete", QIcon(":/images/delete.png")));
connect(deletePermanentlyAction, SIGNAL(triggered()), this, SLOT(deletePermanentlyOperation()));
saveAction = new QAction(tr("Save"), this);
saveAction->setObjectName("save");
saveAction->setIcon(QIcon::fromTheme("document-save", QIcon(":/images/save.png")));
saveAsAction = new QAction(tr("Save As"), this);
saveAsAction->setObjectName("saveAs");
saveAsAction->setIcon(QIcon::fromTheme("document-save-as", QIcon(":/images/save_as.png")));
copyImageAction = new QAction(tr("Copy Image"), this);
copyImageAction->setObjectName("copyImage");
pasteImageAction = new QAction(tr("Paste Image"), this);
pasteImageAction->setObjectName("pasteImage");
renameAction = new QAction(tr("Rename"), this);
renameAction->setObjectName("rename");
connect(renameAction, SIGNAL(triggered()), this, SLOT(rename()));
removeMetadataAction = new QAction(tr("Remove Metadata"), this);
removeMetadataAction->setObjectName("removeMetadata");
connect(removeMetadataAction, SIGNAL(triggered()), this, SLOT(removeMetadata()));
selectAllAction = new QAction(tr("Select All"), this);
selectAllAction->setObjectName("selectAll");
connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAllThumbs()));
aboutAction = new QAction(tr("About"), this);
aboutAction->setObjectName("about");
connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
// Sort actions
sortByNameAction = new QAction(tr("Sort by Name"), this);
sortByNameAction->setObjectName("name");
sortByTimeAction = new QAction(tr("Sort by Time"), this);
sortByTimeAction->setObjectName("time");
sortBySizeAction = new QAction(tr("Sort by Size"), this);
sortBySizeAction->setObjectName("size");
sortByTypeAction = new QAction(tr("Sort by Type"), this);
sortByTypeAction->setObjectName("type");
sortReverseAction = new QAction(tr("Reverse Order"), this);
sortReverseAction->setObjectName("reverse");
sortByNameAction->setCheckable(true);
sortByTimeAction->setCheckable(true);
sortBySizeAction->setCheckable(true);
sortByTypeAction->setCheckable(true);
sortReverseAction->setCheckable(true);
connect(sortByNameAction, SIGNAL(triggered()), this, SLOT(sortThumbnails()));
connect(sortByTimeAction, SIGNAL(triggered()), this, SLOT(sortThumbnails()));
connect(sortBySizeAction, SIGNAL(triggered()), this, SLOT(sortThumbnails()));
connect(sortByTypeAction, SIGNAL(triggered()), this, SLOT(sortThumbnails()));
connect(sortReverseAction, SIGNAL(triggered()), this, SLOT(sortThumbnails()));
if (thumbsViewer->thumbsSortFlags & QDir::Time) {
sortByTimeAction->setChecked(true);
} else if (thumbsViewer->thumbsSortFlags & QDir::Size) {
sortBySizeAction->setChecked(true);
} else if (thumbsViewer->thumbsSortFlags & QDir::Type) {
sortByTypeAction->setChecked(true);
} else {
sortByNameAction->setChecked(true);
}
sortReverseAction->setChecked(thumbsViewer->thumbsSortFlags & QDir::Reversed);
showHiddenFilesAction = new QAction(tr("Show Hidden Files"), this);
showHiddenFilesAction->setObjectName("showHidden");
showHiddenFilesAction->setCheckable(true);
showHiddenFilesAction->setChecked(Settings::showHiddenFiles);
connect(showHiddenFilesAction, SIGNAL(triggered()), this, SLOT(showHiddenFiles()));
smallToolbarIconsAction = new QAction(tr("Small Toolbar Icons"), this);
smallToolbarIconsAction->setObjectName("smallToolbarIcons");
smallToolbarIconsAction->setCheckable(true);
smallToolbarIconsAction->setChecked(Settings::smallToolbarIcons);
connect(smallToolbarIconsAction, SIGNAL(triggered()), this, SLOT(setToolbarIconSize()));
lockDocksAction = new QAction(tr("Hide Dock Title Bars"), this);
lockDocksAction->setObjectName("lockDocks");
lockDocksAction->setCheckable(true);
lockDocksAction->setChecked(Settings::hideDockTitlebars);
connect(lockDocksAction, SIGNAL(triggered()), this, SLOT(lockDocks()));
showViewerToolbarAction = new QAction(tr("Show Toolbar"), this);
showViewerToolbarAction->setObjectName("showViewerToolbars");
showViewerToolbarAction->setCheckable(true);
showViewerToolbarAction->setChecked(Settings::showViewerToolbar);
connect(showViewerToolbarAction, SIGNAL(triggered()), this, SLOT(toggleImageViewerToolbar()));
refreshAction = new QAction(tr("Reload"), this);
refreshAction->setObjectName("refresh");
refreshAction->setIcon(QIcon::fromTheme("view-refresh", QIcon(":/images/refresh.png")));
connect(refreshAction, SIGNAL(triggered()), this, SLOT(reload()));
includeSubDirectoriesAction = new QAction(tr("Include Sub-directories"), this);
includeSubDirectoriesAction->setObjectName("subFolders");
includeSubDirectoriesAction->setIcon(QIcon(":/images/tree.png"));
includeSubDirectoriesAction->setCheckable(true);
connect(includeSubDirectoriesAction, SIGNAL(triggered()), this, SLOT(setIncludeSubDirs()));
pasteAction = new QAction(tr("Paste Here"), this);
pasteAction->setObjectName("paste");
pasteAction->setIcon(QIcon::fromTheme("edit-paste", QIcon(":/images/paste.png")));
connect(pasteAction, SIGNAL(triggered()), this, SLOT(pasteThumbs()));
pasteAction->setEnabled(false);
createDirectoryAction = new QAction(tr("New Directory"), this);
createDirectoryAction->setObjectName("createDir");
connect(createDirectoryAction, SIGNAL(triggered()), this, SLOT(createSubDirectory()));
createDirectoryAction->setIcon(QIcon::fromTheme("folder-new", QIcon(":/images/new_folder.png")));
goBackAction = new QAction(tr("Back"), this);
goBackAction->setObjectName("goBack");
goBackAction->setIcon(QIcon::fromTheme("go-previous", QIcon(":/images/back.png")));
connect(goBackAction, SIGNAL(triggered()), this, SLOT(goBack()));
goBackAction->setEnabled(false);
goFrwdAction = new QAction(tr("Forward"), this);
goFrwdAction->setObjectName("goFrwd");
goFrwdAction->setIcon(QIcon::fromTheme("go-next", QIcon(":/images/next.png")));
connect(goFrwdAction, SIGNAL(triggered()), this, SLOT(goForward()));
goFrwdAction->setEnabled(false);
goUpAction = new QAction(tr("Go Up"), this);
goUpAction->setObjectName("up");
goUpAction->setIcon(QIcon::fromTheme("go-up", QIcon(":/images/up.png")));
connect(goUpAction, SIGNAL(triggered()), this, SLOT(goUp()));
goHomeAction = new QAction(tr("Home"), this);
goHomeAction->setObjectName("home");
connect(goHomeAction, SIGNAL(triggered()), this, SLOT(goHome()));
goHomeAction->setIcon(QIcon::fromTheme("go-home", QIcon(":/images/home.png")));
slideShowAction = new QAction(tr("Slide Show"), this);
slideShowAction->setObjectName("toggleSlideShow");
connect(slideShowAction, SIGNAL(triggered()), this, SLOT(toggleSlideShow()));
slideShowAction->setIcon(QIcon::fromTheme("media-playback-start", QIcon(":/images/play.png")));
nextImageAction = new QAction(tr("Next Image"), this);
nextImageAction->setObjectName("nextImage");
nextImageAction->setIcon(QIcon::fromTheme("go-next", QIcon(":/images/next.png")));
connect(nextImageAction, SIGNAL(triggered()), this, SLOT(loadNextImage()));
prevImageAction = new QAction(tr("Previous Image"), this);
prevImageAction->setObjectName("prevImage");
prevImageAction->setIcon(QIcon::fromTheme("go-previous", QIcon(":/images/back.png")));
connect(prevImageAction, SIGNAL(triggered()), this, SLOT(loadPreviousImage()));
firstImageAction = new QAction(tr("First Image"), this);
firstImageAction->setObjectName("firstImage");
firstImageAction->setIcon(QIcon::fromTheme("go-first", QIcon(":/images/first.png")));
connect(firstImageAction, SIGNAL(triggered()), this, SLOT(loadFirstImage()));
lastImageAction = new QAction(tr("Last Image"), this);
lastImageAction->setObjectName("lastImage");
lastImageAction->setIcon(QIcon::fromTheme("go-last", QIcon(":/images/last.png")));
connect(lastImageAction, SIGNAL(triggered()), this, SLOT(loadLastImage()));
randomImageAction = new QAction(tr("Random Image"), this);
randomImageAction->setObjectName("randomImage");
connect(randomImageAction, SIGNAL(triggered()), this, SLOT(loadRandomImage()));
viewImageAction = new QAction(tr("View Image"), this);
viewImageAction->setObjectName("open");
viewImageAction->setIcon(QIcon::fromTheme("document-open", QIcon(":/images/open.png")));
connect(viewImageAction, SIGNAL(triggered()), this, SLOT(viewImage()));
showClipboardAction = new QAction(tr("Load Clipboard"), this);
showClipboardAction->setObjectName("showClipboard");
showClipboardAction->setIcon(QIcon::fromTheme("insert-image", QIcon(":/images/new.png")));
connect(showClipboardAction, SIGNAL(triggered()), this, SLOT(newImage()));
openWithSubMenu = new QMenu(tr("Open With..."));
openWithMenuAction = new QAction(tr("Open With..."), this);
openWithMenuAction->setObjectName("openWithMenu");
openWithMenuAction->setMenu(openWithSubMenu);
externalAppsAction = new QAction(tr("External Applications"), this);
externalAppsAction->setIcon(QIcon::fromTheme("preferences-other", QIcon(":/images/settings.png")));
externalAppsAction->setObjectName("chooseApp");
connect(externalAppsAction, SIGNAL(triggered()), this, SLOT(chooseExternalApp()));
addBookmarkAction = new QAction(tr("Add Bookmark"), this);
addBookmarkAction->setObjectName("addBookmark");
addBookmarkAction->setIcon(QIcon(":/images/new_bookmark.png"));
connect(addBookmarkAction, SIGNAL(triggered()), this, SLOT(addNewBookmark()));
removeBookmarkAction = new QAction(tr("Delete Bookmark"), this);
removeBookmarkAction->setObjectName("deleteBookmark");
removeBookmarkAction->setIcon(QIcon::fromTheme("edit-delete", QIcon(":/images/delete.png")));
zoomOutAction = new QAction(tr("Zoom Out"), this);
zoomOutAction->setObjectName("zoomOut");
connect(zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut()));
zoomOutAction->setIcon(QIcon::fromTheme("zoom-out", QIcon(":/images/zoom_out.png")));
zoomInAction = new QAction(tr("Zoom In"), this);
zoomInAction->setObjectName("zoomIn");
connect(zoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn()));
zoomInAction->setIcon(QIcon::fromTheme("zoom-in", QIcon(":/images/zoom_out.png")));
resetZoomAction = new QAction(tr("Reset Zoom"), this);
resetZoomAction->setObjectName("resetZoom");
resetZoomAction->setIcon(QIcon::fromTheme("zoom-fit-best", QIcon(":/images/zoom.png")));
connect(resetZoomAction, SIGNAL(triggered()), this, SLOT(resetZoom()));
origZoomAction = new QAction(tr("Original Size"), this);
origZoomAction->setObjectName("origZoom");
origZoomAction->setIcon(QIcon::fromTheme("zoom-original", QIcon(":/images/zoom1.png")));
connect(origZoomAction, SIGNAL(triggered()), this, SLOT(origZoom()));
keepZoomAction = new QAction(tr("Keep Zoom"), this);
keepZoomAction->setObjectName("keepZoom");
keepZoomAction->setCheckable(true);
connect(keepZoomAction, SIGNAL(triggered()), this, SLOT(keepZoom()));
rotateLeftAction = new QAction(tr("Rotate 90 degree CCW"), this);
rotateLeftAction->setObjectName("rotateLeft");
rotateLeftAction->setIcon(QIcon::fromTheme("object-rotate-left", QIcon(":/images/rotate_left.png")));
connect(rotateLeftAction, SIGNAL(triggered()), this, SLOT(rotateLeft()));
rotateRightAction = new QAction(tr("Rotate 90 degree CW"), this);
rotateRightAction->setObjectName("rotateRight");
rotateRightAction->setIcon(QIcon::fromTheme("object-rotate-right", QIcon(":/images/rotate_right.png")));
connect(rotateRightAction, SIGNAL(triggered()), this, SLOT(rotateRight()));
flipHorizontalAction = new QAction(tr("Flip Horizontally"), this);
flipHorizontalAction->setObjectName("flipH");
flipHorizontalAction->setIcon(QIcon::fromTheme("object-flip-horizontal", QIcon(":/images/flipH.png")));
connect(flipHorizontalAction, SIGNAL(triggered()), this, SLOT(flipHorizontal()));
flipVerticalAction = new QAction(tr("Flip Vertically"), this);
flipVerticalAction->setObjectName("flipV");
flipVerticalAction->setIcon(QIcon::fromTheme("object-flip-vertical", QIcon(":/images/flipV.png")));
connect(flipVerticalAction, SIGNAL(triggered()), this, SLOT(flipVertical()));
cropAction = new QAction(tr("Cropping"), this);
cropAction->setObjectName("crop");
cropAction->setIcon(QIcon(":/images/crop.png"));
connect(cropAction, SIGNAL(triggered()), this, SLOT(cropImage()));
cropToSelectionAction = new QAction(tr("Crop to Selection"), this);
cropToSelectionAction->setObjectName("cropToSelection");
cropToSelectionAction->setIcon(QIcon(":/images/crop.png"));
resizeAction = new QAction(tr("Scale Image"), this);
resizeAction->setObjectName("resize");
resizeAction->setIcon(QIcon::fromTheme("transform-scale", QIcon(":/images/scale.png")));
connect(resizeAction, SIGNAL(triggered()), this, SLOT(scaleImage()));
freeRotateLeftAction = new QAction(tr("Rotate 1 degree CCW"), this);
freeRotateLeftAction->setObjectName("freeRotateLeft");
connect(freeRotateLeftAction, SIGNAL(triggered()), this, SLOT(freeRotateLeft()));
freeRotateRightAction = new QAction(tr("Rotate 1 degree CW"), this);
freeRotateRightAction->setObjectName("freeRotateRight");
connect(freeRotateRightAction, SIGNAL(triggered()), this, SLOT(freeRotateRight()));
colorsAction = new QAction(tr("Colors"), this);
colorsAction->setObjectName("colors");
connect(colorsAction, SIGNAL(triggered()), this, SLOT(showColorsDialog()));
colorsAction->setIcon(QIcon(":/images/colors.png"));
mirrorDisabledAction = new QAction(tr("Disable Mirror"), this);
mirrorDisabledAction->setObjectName("mirrorDisabled");
mirrorDualAction = new QAction(tr("Dual Mirror"), this);
mirrorDualAction->setObjectName("mirrorDual");
mirrorTripleAction = new QAction(tr("Triple Mirror"), this);
mirrorTripleAction->setObjectName("mirrorTriple");
mirrorDualVerticalAction = new QAction(tr("Dual Vertical Mirror"), this);
mirrorDualVerticalAction->setObjectName("mirrorVDual");
mirrorQuadAction = new QAction(tr("Quad Mirror"), this);
mirrorQuadAction->setObjectName("mirrorQuad");
mirrorDisabledAction->setCheckable(true);
mirrorDualAction->setCheckable(true);
mirrorTripleAction->setCheckable(true);
mirrorDualVerticalAction->setCheckable(true);
mirrorQuadAction->setCheckable(true);
connect(mirrorDisabledAction, SIGNAL(triggered()), this, SLOT(setMirrorDisabled()));
connect(mirrorDualAction, SIGNAL(triggered()), this, SLOT(setMirrorDual()));
connect(mirrorTripleAction, SIGNAL(triggered()), this, SLOT(setMirrorTriple()));
connect(mirrorDualVerticalAction, SIGNAL(triggered()), this, SLOT(setMirrorVDual()));
connect(mirrorQuadAction, SIGNAL(triggered()), this, SLOT(setMirrorQuad()));
mirrorDisabledAction->setChecked(true);
keepTransformAction = new QAction(tr("Keep Transformations"), this);
keepTransformAction->setObjectName("keepTransform");
keepTransformAction->setCheckable(true);
connect(keepTransformAction, SIGNAL(triggered()), this, SLOT(keepTransformClicked()));
moveLeftAction = new QAction(tr("Move Image Left"), this);
moveLeftAction->setObjectName("moveLeft");
connect(moveLeftAction, SIGNAL(triggered()), this, SLOT(moveLeft()));
moveRightAction = new QAction(tr("Move Image Right"), this);
moveRightAction->setObjectName("moveRight");
connect(moveRightAction, SIGNAL(triggered()), this, SLOT(moveRight()));
moveUpAction = new QAction(tr("Move Image Up"), this);
moveUpAction->setObjectName("moveUp");
connect(moveUpAction, SIGNAL(triggered()), this, SLOT(moveUp()));
moveDownAction = new QAction(tr("Move Image Down"), this);
moveDownAction->setObjectName("moveDown");
connect(moveDownAction, SIGNAL(triggered()), this, SLOT(moveDown()));
invertSelectionAction = new QAction(tr("Invert Selection"), this);
invertSelectionAction->setObjectName("invertSelection");
connect(invertSelectionAction, SIGNAL(triggered()), thumbsViewer, SLOT(invertSelection()));
filterImagesFocusAction = new QAction(tr("Filter by Name"), this);
filterImagesFocusAction->setObjectName("filterImagesFocus");
connect(filterImagesFocusAction, SIGNAL(triggered()), this, SLOT(filterImagesFocus()));
setPathFocusAction = new QAction(tr("Edit Current Path"), this);
setPathFocusAction->setObjectName("setPathFocus");
connect(setPathFocusAction, SIGNAL(triggered()), this, SLOT(setPathFocus()));
}
void Phototonic::createMenus() {
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(includeSubDirectoriesAction);
fileMenu->addAction(createDirectoryAction);
fileMenu->addAction(showClipboardAction);
fileMenu->addAction(addBookmarkAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
editMenu = menuBar()->addMenu(tr("&Edit"));
editMenu->addAction(cutAction);
editMenu->addAction(copyAction);
editMenu->addAction(copyToAction);
editMenu->addAction(moveToAction);
editMenu->addAction(pasteAction);
editMenu->addAction(renameAction);
editMenu->addAction(removeMetadataAction);
editMenu->addAction(deleteAction);
editMenu->addAction(deletePermanentlyAction);
editMenu->addSeparator();
editMenu->addAction(selectAllAction);
editMenu->addAction(invertSelectionAction);
addAction(filterImagesFocusAction);
addAction(setPathFocusAction);
editMenu->addSeparator();
editMenu->addAction(externalAppsAction);
editMenu->addAction(settingsAction);
goMenu = menuBar()->addMenu(tr("&Go"));
goMenu->addAction(goBackAction);
goMenu->addAction(goFrwdAction);
goMenu->addAction(goUpAction);
goMenu->addAction(goHomeAction);
goMenu->addSeparator();
goMenu->addAction(prevImageAction);
goMenu->addAction(nextImageAction);
goMenu->addSeparator();
goMenu->addAction(thumbsGoToTopAction);
goMenu->addAction(thumbsGoToBottomAction);
viewMenu = menuBar()->addMenu(tr("&View"));
viewMenu->addAction(slideShowAction);
viewMenu->addSeparator();
viewMenu->addAction(thumbsZoomInAction);
viewMenu->addAction(thumbsZoomOutAction);
sortMenu = viewMenu->addMenu(tr("Thumbnails Sorting"));
sortTypesGroup = new QActionGroup(this);
sortTypesGroup->addAction(sortByNameAction);
sortTypesGroup->addAction(sortByTimeAction);
sortTypesGroup->addAction(sortBySizeAction);
sortTypesGroup->addAction(sortByTypeAction);
sortMenu->addActions(sortTypesGroup->actions());
sortMenu->addSeparator();
sortMenu->addAction(sortReverseAction);
viewMenu->addSeparator();
viewMenu->addAction(showHiddenFilesAction);
viewMenu->addSeparator();
viewMenu->addAction(refreshAction);
// thumbs viewer context menu
thumbsViewer->addAction(viewImageAction);
thumbsViewer->addAction(openWithMenuAction);
thumbsViewer->addAction(cutAction);
thumbsViewer->addAction(copyAction);
thumbsViewer->addAction(pasteAction);
addMenuSeparator(thumbsViewer);
thumbsViewer->addAction(copyToAction);
thumbsViewer->addAction(moveToAction);
thumbsViewer->addAction(renameAction);
thumbsViewer->addAction(removeMetadataAction);
thumbsViewer->addAction(deleteAction);
thumbsViewer->addAction(deletePermanentlyAction);
addMenuSeparator(thumbsViewer);
thumbsViewer->addAction(selectAllAction);
thumbsViewer->addAction(invertSelectionAction);
thumbsViewer->setContextMenuPolicy(Qt::ActionsContextMenu);
menuBar()->setVisible(true);
}
void Phototonic::createToolBars() {
/* Edit */
editToolBar = addToolBar(tr("Edit Toolbar"));
editToolBar->setObjectName("Edit");
editToolBar->addAction(cutAction);
editToolBar->addAction(copyAction);
editToolBar->addAction(pasteAction);
editToolBar->addAction(deleteAction);
editToolBar->addAction(deletePermanentlyAction);
editToolBar->addAction(showClipboardAction);
connect(editToolBar->toggleViewAction(), SIGNAL(triggered()), this, SLOT(setEditToolBarVisibility()));
/* Navigation */
goToolBar = addToolBar(tr("Navigation Toolbar"));
goToolBar->setObjectName("Navigation");
goToolBar->addAction(goBackAction);
goToolBar->addAction(goFrwdAction);
goToolBar->addAction(goUpAction);
goToolBar->addAction(goHomeAction);
goToolBar->addAction(refreshAction);
/* path bar */
pathLineEdit = new QLineEdit;
pathLineEdit->setCompleter(new DirCompleter(pathLineEdit));
pathLineEdit->setMinimumWidth(200);
pathLineEdit->setMaximumWidth(600);
connect(pathLineEdit, SIGNAL(returnPressed()), this, SLOT(goPathBarDir()));
goToolBar->addWidget(pathLineEdit);
goToolBar->addAction(includeSubDirectoriesAction);
connect(goToolBar->toggleViewAction(), SIGNAL(triggered()), this, SLOT(setGoToolBarVisibility()));
/* View */
viewToolBar = addToolBar(tr("View Toolbar"));
viewToolBar->setObjectName("View");
viewToolBar->addAction(thumbsZoomInAction);
viewToolBar->addAction(thumbsZoomOutAction);
viewToolBar->addAction(slideShowAction);
/* filter bar */
QAction *filterAct = new QAction(tr("Filter"), this);
filterAct->setIcon(QIcon::fromTheme("edit-find", QIcon(":/images/zoom.png")));
connect(filterAct, SIGNAL(triggered()), this, SLOT(setThumbsFilter()));
filterLineEdit = new QLineEdit;
filterLineEdit->setMinimumWidth(100);
filterLineEdit->setMaximumWidth(200);
connect(filterLineEdit, SIGNAL(returnPressed()), this, SLOT(setThumbsFilter()));
connect(filterLineEdit, SIGNAL(textChanged(
const QString&)), this, SLOT(clearThumbsFilter()));
filterLineEdit->setClearButtonEnabled(true);
filterLineEdit->addAction(filterAct, QLineEdit::LeadingPosition);
viewToolBar->addSeparator();
viewToolBar->addWidget(filterLineEdit);
viewToolBar->addAction(settingsAction);
connect(viewToolBar->toggleViewAction(), SIGNAL(triggered()), this, SLOT(setViewToolBarVisibility()));
/* image */
imageToolBar = new QToolBar(tr("Image Toolbar"));
imageToolBar->setObjectName("Image");
imageToolBar->addAction(prevImageAction);
imageToolBar->addAction(nextImageAction);
imageToolBar->addAction(firstImageAction);
imageToolBar->addAction(lastImageAction);
imageToolBar->addAction(slideShowAction);
imageToolBar->addSeparator();
imageToolBar->addAction(saveAction);
imageToolBar->addAction(saveAsAction);
imageToolBar->addAction(deleteAction);
imageToolBar->addAction(deletePermanentlyAction);
imageToolBar->addSeparator();
imageToolBar->addAction(zoomInAction);
imageToolBar->addAction(zoomOutAction);
imageToolBar->addAction(resetZoomAction);
imageToolBar->addAction(origZoomAction);
imageToolBar->addSeparator();
imageToolBar->addAction(resizeAction);
imageToolBar->addAction(rotateRightAction);
imageToolBar->addAction(rotateLeftAction);
imageToolBar->addAction(flipHorizontalAction);
imageToolBar->addAction(flipVerticalAction);
imageToolBar->addAction(cropAction);
imageToolBar->addAction(colorsAction);
imageToolBar->setVisible(false);
connect(imageToolBar->toggleViewAction(), SIGNAL(triggered()), this, SLOT(setImageToolBarVisibility()));
setToolbarIconSize();
}
void Phototonic::setToolbarIconSize() {
if (initComplete) {
Settings::smallToolbarIcons = smallToolbarIconsAction->isChecked();
}
int iconSize = Settings::smallToolbarIcons ? 16 : 24;
QSize iconQSize(iconSize, iconSize);
editToolBar->setIconSize(iconQSize);
goToolBar->setIconSize(iconQSize);
viewToolBar->setIconSize(iconQSize);
imageToolBar->setIconSize(iconQSize);
}
void Phototonic::createStatusBar() {
statusLabel = new QLabel(tr("Initializing..."));
statusBar()->addWidget(statusLabel);
busyMovie = new QMovie(":/images/busy.gif");
busyLabel = new QLabel(this);
busyLabel->setMovie(busyMovie);
statusBar()->addWidget(busyLabel);
busyLabel->setVisible(false);
statusBar()->setStyleSheet("QStatusBar::item { border: 0px solid black }; ");
}
void Phototonic::onFileListSelected() {
if (initComplete && fileListWidget->itemAt(0, 0)->isSelected()) {
Settings::isFileListLoaded = true;
fileSystemTree->clearSelection();
refreshThumbs(true);
}
}
void Phototonic::createFileSystemDock() {
fileSystemDock = new QDockWidget(tr("File System"), this);
fileSystemDock->setObjectName("File System");
fileListWidget = new FileListWidget(fileSystemDock);
connect(fileListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onFileListSelected()));
fileSystemTree = new FileSystemTree(fileSystemDock);
fileSystemTree->addAction(createDirectoryAction);
fileSystemTree->addAction(renameAction);
fileSystemTree->addAction(deleteAction);
fileSystemTree->addAction(deletePermanentlyAction);
addMenuSeparator(fileSystemTree);
fileSystemTree->addAction(pasteAction);
addMenuSeparator(fileSystemTree);
fileSystemTree->addAction(openWithMenuAction);
fileSystemTree->addAction(addBookmarkAction);
fileSystemTree->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(fileSystemTree, SIGNAL(clicked(
const QModelIndex&)), this, SLOT(goSelectedDir(
const QModelIndex &)));
connect(fileSystemTree->fileSystemModel, SIGNAL(rowsRemoved(
const QModelIndex &, int, int)),
this, SLOT(checkDirState(
const QModelIndex &, int, int)));
connect(fileSystemTree, SIGNAL(dropOp(Qt::KeyboardModifiers, bool, QString)),
this, SLOT(dropOp(Qt::KeyboardModifiers, bool, QString)));
fileSystemTree->setCurrentIndex(fileSystemTree->fileSystemModel->index(QDir::currentPath()));
connect(fileSystemTree->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
this, SLOT(updateActions()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
mainLayout->addWidget(fileListWidget);
mainLayout->addWidget(fileSystemTree);
QWidget *fileSystemTreeMainWidget = new QWidget(fileSystemDock);
fileSystemTreeMainWidget->setLayout(mainLayout);
fileSystemDock->setWidget(fileSystemTreeMainWidget);
connect(fileSystemDock->toggleViewAction(), SIGNAL(triggered()), this, SLOT(setFileSystemDockVisibility()));
connect(fileSystemDock, SIGNAL(visibilityChanged(bool)), this, SLOT(setFileSystemDockVisibility()));
addDockWidget(Qt::LeftDockWidgetArea, fileSystemDock);
}
void Phototonic::createBookmarksDock() {
bookmarksDock = new QDockWidget(tr("Bookmarks"), this);
bookmarksDock->setObjectName("Bookmarks");
bookmarks = new BookMarks(bookmarksDock);
bookmarksDock->setWidget(bookmarks);
connect(bookmarksDock->toggleViewAction(), SIGNAL(triggered()), this, SLOT(setBookmarksDockVisibility()));
connect(bookmarksDock, SIGNAL(visibilityChanged(bool)), this, SLOT(setBookmarksDockVisibility()));
connect(bookmarks, SIGNAL(itemClicked(QTreeWidgetItem * , int)),
this, SLOT(bookmarkClicked(QTreeWidgetItem * , int)));
connect(removeBookmarkAction, SIGNAL(triggered()), bookmarks, SLOT(removeBookmark()));
connect(bookmarks, SIGNAL(dropOp(Qt::KeyboardModifiers, bool, QString)),
this, SLOT(dropOp(Qt::KeyboardModifiers, bool, QString)));
addDockWidget(Qt::LeftDockWidgetArea, bookmarksDock);
bookmarks->addAction(pasteAction);
bookmarks->addAction(removeBookmarkAction);
bookmarks->setContextMenuPolicy(Qt::ActionsContextMenu);
}
void Phototonic::createImagePreviewDock() {
imagePreviewDock = new QDockWidget(tr("Preview"), this);
imagePreviewDock->setObjectName("ImagePreview");
imagePreviewDock->setWidget(thumbsViewer->imagePreview);
connect(imagePreviewDock->toggleViewAction(), SIGNAL(triggered()), this, SLOT(setImagePreviewDockVisibility()));
connect(imagePreviewDock, SIGNAL(visibilityChanged(bool)), this, SLOT(setImagePreviewDockVisibility()));
addDockWidget(Qt::RightDockWidgetArea, imagePreviewDock);
}
void Phototonic::createImageTagsDock() {
tagsDock = new QDockWidget(tr("Tags"), this);
tagsDock->setObjectName("Tags");
thumbsViewer->imageTags = new ImageTags(tagsDock, thumbsViewer, metadataCache);
tagsDock->setWidget(thumbsViewer->imageTags);
connect(tagsDock->toggleViewAction(), SIGNAL(triggered()), this, SLOT(setTagsDockVisibility()));
connect(tagsDock, SIGNAL(visibilityChanged(bool)), this, SLOT(setTagsDockVisibility()));
connect(thumbsViewer->imageTags, SIGNAL(reloadThumbs()), this, SLOT(onReloadThumbs()));
connect(thumbsViewer->imageTags->removeTagAction, SIGNAL(triggered()), this, SLOT(deleteOperation()));
}
void Phototonic::sortThumbnails() {
thumbsViewer->thumbsSortFlags = QDir::IgnoreCase;
if (sortByNameAction->isChecked()) {
thumbsViewer->thumbsSortFlags |= QDir::Name;
} else if (sortByTimeAction->isChecked()) {
thumbsViewer->thumbsSortFlags |= QDir::Time;
} else if (sortBySizeAction->isChecked()) {
thumbsViewer->thumbsSortFlags |= QDir::Size;
} else if (sortByTypeAction->isChecked()) {
thumbsViewer->thumbsSortFlags |= QDir::Type;
}
if (sortReverseAction->isChecked()) {
thumbsViewer->thumbsSortFlags |= QDir::Reversed;
}
refreshThumbs(false);
}
void Phototonic::reload() {
if (Settings::layoutMode == ThumbViewWidget) {
refreshThumbs(false);
} else {
imageViewer->reload();
}
}
void Phototonic::setIncludeSubDirs() {
Settings::includeSubDirectories = includeSubDirectoriesAction->isChecked();
refreshThumbs(false);
}
void Phototonic::refreshThumbs(bool scrollToTop) {
thumbsViewer->setNeedToScroll(scrollToTop);
QTimer::singleShot(0, this, SLOT(onReloadThumbs()));
}
void Phototonic::showHiddenFiles() {
Settings::showHiddenFiles = showHiddenFilesAction->isChecked();
fileSystemTree->setModelFlags();
refreshThumbs(false);
}
void Phototonic::toggleImageViewerToolbar() {
imageToolBar->setVisible(showViewerToolbarAction->isChecked());
addToolBar(imageToolBar);
Settings::showViewerToolbar = showViewerToolbarAction->isChecked();
}
void Phototonic::about() {
MessageBox messageBox(this);
messageBox.about();
}
void Phototonic::filterImagesFocus() {
if (Settings::layoutMode == ThumbViewWidget) {
if (!viewToolBar->isVisible()) {
viewToolBar->setVisible(true);
}
setViewToolBarVisibility();
filterLineEdit->setFocus(Qt::OtherFocusReason);
filterLineEdit->selectAll();
}
}
void Phototonic::setPathFocus() {
if (Settings::layoutMode == ThumbViewWidget) {
if (!goToolBar->isVisible()) {
goToolBar->setVisible(true);
}
setGoToolBarVisibility();
pathLineEdit->setFocus(Qt::OtherFocusReason);
pathLineEdit->selectAll();
}
}
void Phototonic::cleanupSender() {
delete QObject::sender();
}
void Phototonic::externalAppError() {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to start external application."));
}
void Phototonic::runExternalApp() {
QString execCommand;
QString selectedFileNames("");
execCommand = Settings::externalApps[((QAction *) sender())->text()];
if (Settings::layoutMode == ImageViewWidget) {
if (imageViewer->isNewImage()) {
showNewImageWarning();
return;
}
execCommand += " \"" + imageViewer->viewerImageFullPath + "\"";
} else {
if (QApplication::focusWidget() == fileSystemTree) {
selectedFileNames += " \"" + getSelectedPath() + "\"";
} else {
QModelIndexList selectedIdxList = thumbsViewer->selectionModel()->selectedIndexes();
if (selectedIdxList.size() < 1) {
setStatus(tr("Invalid selection."));
return;
}
selectedFileNames += " ";
for (int tn = selectedIdxList.size() - 1; tn >= 0; --tn) {
selectedFileNames += "\"" +
thumbsViewer->thumbsViewerModel->item(selectedIdxList[tn].row())->data(
thumbsViewer->FileNameRole).toString();
if (tn)
selectedFileNames += "\" ";
}
}
execCommand += selectedFileNames;
}
QProcess *externalProcess = new QProcess();
connect(externalProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(cleanupSender()));
connect(externalProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(externalAppError()));
externalProcess->start(execCommand);
}
void Phototonic::updateExternalApps() {
int actionNumber = 0;
QMapIterator externalAppsIterator(Settings::externalApps);
QList actionList = openWithSubMenu->actions();
if (!actionList.empty()) {
for (int i = 0; i < actionList.size(); ++i) {
QAction *action = actionList.at(i);
if (action->isSeparator()) {
break;
}
openWithSubMenu->removeAction(action);
imageViewer->removeAction(action);
delete action;
}
openWithSubMenu->clear();
}
while (externalAppsIterator.hasNext()) {
++actionNumber;
externalAppsIterator.next();
QAction *extAppAct = new QAction(externalAppsIterator.key(), this);
if (actionNumber < 10) {
extAppAct->setShortcut(QKeySequence("Alt+" + QString::number(actionNumber)));
}
extAppAct->setIcon(QIcon::fromTheme(externalAppsIterator.key()));
connect(extAppAct, SIGNAL(triggered()), this, SLOT(runExternalApp()));
openWithSubMenu->addAction(extAppAct);
imageViewer->addAction(extAppAct);
}
openWithSubMenu->addSeparator();
openWithSubMenu->addAction(externalAppsAction);
}
void Phototonic::chooseExternalApp() {
ExternalAppsDialog *externalAppsDialog = new ExternalAppsDialog(this);
if (Settings::slideShowActive) {
toggleSlideShow();
}
imageViewer->setCursorHiding(false);
externalAppsDialog->exec();
updateExternalApps();
delete (externalAppsDialog);
if (isFullScreen()) {
imageViewer->setCursorHiding(true);
}
}
void Phototonic::showSettings() {
if (Settings::slideShowActive) {
toggleSlideShow();
}
imageViewer->setCursorHiding(false);
SettingsDialog *settingsDialog = new SettingsDialog(this);
if (settingsDialog->exec()) {
imageViewer->setBackgroundColor();
thumbsViewer->setThumbColors();
thumbsViewer->imagePreview->setBackgroundColor();
Settings::imageZoomFactor = 1.0;
imageViewer->imageInfoLabel->setVisible(Settings::showImageName);
if (Settings::layoutMode == ImageViewWidget) {
imageViewer->reload();
needThumbsRefresh = true;
} else {
refreshThumbs(false);
}
if (!Settings::setWindowIcon) {
setWindowIcon(defaultApplicationIcon);
}
writeSettings();
}
if (isFullScreen()) {
imageViewer->setCursorHiding(true);
}
delete settingsDialog;
}
void Phototonic::toggleFullScreen() {
if (fullScreenAction->isChecked()) {
shouldMaximize = isMaximized();
showFullScreen();
Settings::isFullScreen = true;
imageViewer->setCursorHiding(true);
} else {
showNormal();
if (shouldMaximize) {
showMaximized();
}
imageViewer->setCursorHiding(false);
Settings::isFullScreen = false;
}
}
void Phototonic::selectAllThumbs() {
thumbsViewer->selectAll();
}
void Phototonic::copyOrCutThumbs(bool isCopyOperation) {
Settings::copyCutIndexList = thumbsViewer->selectionModel()->selectedIndexes();
copyCutThumbsCount = Settings::copyCutIndexList.size();
Settings::copyCutFileList.clear();
for (int thumb = 0; thumb < copyCutThumbsCount; ++thumb) {
Settings::copyCutFileList.append(thumbsViewer->thumbsViewerModel->item(Settings::copyCutIndexList[thumb].
row())->data(thumbsViewer->FileNameRole).toString());
}
Settings::isCopyOperation = isCopyOperation;
pasteAction->setEnabled(true);
QString state = QString((Settings::isCopyOperation ? tr("Copied") : tr("Cut")) + " " +
tr("%n image(s) to clipboard", "", copyCutThumbsCount));
setStatus(state);
}
void Phototonic::cutThumbs() {
copyOrCutThumbs(false);
}
void Phototonic::copyThumbs() {
copyOrCutThumbs(true);
}
void Phototonic::copyImagesTo() {
copyOrMoveImages(false);
}
void Phototonic::moveImagesTo() {
copyOrMoveImages(true);
}
void Phototonic::copyOrMoveImages(bool isMoveOperation) {
if (Settings::slideShowActive) {
toggleSlideShow();
}
imageViewer->setCursorHiding(false);
copyMoveToDialog = new CopyMoveToDialog(this, getSelectedPath(), isMoveOperation);
if (copyMoveToDialog->exec()) {
if (Settings::layoutMode == ThumbViewWidget) {
if (copyMoveToDialog->copyOp) {
copyThumbs();
} else {
cutThumbs();
}
pasteThumbs();
} else {
if (imageViewer->isNewImage()) {
showNewImageWarning();
if (isFullScreen()) {
imageViewer->setCursorHiding(true);
}
return;
}
QFileInfo fileInfo = QFileInfo(imageViewer->viewerImageFullPath);
QString fileName = fileInfo.fileName();
QString destFile = copyMoveToDialog->selectedPath + QDir::separator() + fileInfo.fileName();
int result = CopyMoveDialog::copyOrMoveFile(copyMoveToDialog->copyOp, fileName,
imageViewer->viewerImageFullPath,
destFile, copyMoveToDialog->selectedPath);
if (!result) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to copy or move image."));
} else {
if (!copyMoveToDialog->copyOp) {
int currentRow = thumbsViewer->getCurrentRow();
thumbsViewer->thumbsViewerModel->removeRow(currentRow);
loadCurrentImage(currentRow);
}
}
}
}
bookmarks->reloadBookmarks();
delete (copyMoveToDialog);
copyMoveToDialog = 0;
if (isFullScreen()) {
imageViewer->setCursorHiding(true);
}
}
void Phototonic::thumbsZoomIn() {
if (thumbsViewer->thumbSize < THUMB_SIZE_MAX) {
thumbsViewer->thumbSize += THUMB_SIZE_MIN;
thumbsZoomOutAction->setEnabled(true);
if (thumbsViewer->thumbSize == THUMB_SIZE_MAX)
thumbsZoomInAction->setEnabled(false);
refreshThumbs(false);
}
}
void Phototonic::thumbsZoomOut() {
if (thumbsViewer->thumbSize > THUMB_SIZE_MIN) {
thumbsViewer->thumbSize -= THUMB_SIZE_MIN;
thumbsZoomInAction->setEnabled(true);
if (thumbsViewer->thumbSize == THUMB_SIZE_MIN)
thumbsZoomOutAction->setEnabled(false);
refreshThumbs(false);
}
}
void Phototonic::zoomOut() {
if (Settings::imageZoomFactor <= 4.0 && Settings::imageZoomFactor > 0.25) {
Settings::imageZoomFactor -= 0.25;
} else if (Settings::imageZoomFactor <= 8.0 && Settings::imageZoomFactor >= 4.0) {
Settings::imageZoomFactor -= 0.50;
} else if (Settings::imageZoomFactor <= 16.0 && Settings::imageZoomFactor >= 8.0) {
Settings::imageZoomFactor -= 1.0;
} else {
imageViewer->setFeedback(tr("Minimum zoom"));
return;
}
imageViewer->tempDisableResize = false;
imageViewer->resizeImage();
imageViewer->setFeedback(tr("Zoom %1%").arg(QString::number(Settings::imageZoomFactor * 100)));
}
void Phototonic::zoomIn() {
if (Settings::imageZoomFactor < 4.0 && Settings::imageZoomFactor >= 0.25) {
Settings::imageZoomFactor += 0.25;
} else if (Settings::imageZoomFactor < 8.0 && Settings::imageZoomFactor >= 4.0) {
Settings::imageZoomFactor += 0.50;
} else if (Settings::imageZoomFactor < 16.0 && Settings::imageZoomFactor >= 8.0) {
Settings::imageZoomFactor += 1.00;
} else {
imageViewer->setFeedback(tr("Maximum zoom"));
return;
}
imageViewer->tempDisableResize = false;
imageViewer->resizeImage();
imageViewer->setFeedback(tr("Zoom %1%").arg(QString::number(Settings::imageZoomFactor * 100)));
}
void Phototonic::resetZoom() {
Settings::imageZoomFactor = 1.0;
imageViewer->tempDisableResize = false;
imageViewer->resizeImage();
imageViewer->setFeedback(tr("Zoom Reset"));
}
void Phototonic::origZoom() {
Settings::imageZoomFactor = 1.0;
imageViewer->tempDisableResize = true;
imageViewer->resizeImage();
imageViewer->setFeedback(tr("Original Size"));
}
void Phototonic::keepZoom() {
Settings::keepZoomFactor = keepZoomAction->isChecked();
if (Settings::keepZoomFactor) {
imageViewer->setFeedback(tr("Zoom Locked"));
} else {
imageViewer->setFeedback(tr("Zoom Unlocked"));
}
}
void Phototonic::keepTransformClicked() {
Settings::keepTransform = keepTransformAction->isChecked();
if (Settings::keepTransform) {
imageViewer->setFeedback(tr("Transformations Locked"));
if (cropDialog) {
cropDialog->applyCrop(0);
}
} else {
Settings::cropLeftPercent = Settings::cropTopPercent = Settings::cropWidthPercent = Settings::cropHeightPercent = 0;
imageViewer->setFeedback(tr("Transformations Unlocked"));
}
imageViewer->refresh();
}
void Phototonic::rotateLeft() {
Settings::rotation -= 90;
if (Settings::rotation < 0)
Settings::rotation = 270;
imageViewer->refresh();
imageViewer->setFeedback(tr("Rotation %1°").arg(QString::number(Settings::rotation)));
}
void Phototonic::rotateRight() {
Settings::rotation += 90;
if (Settings::rotation > 270)
Settings::rotation = 0;
imageViewer->refresh();
imageViewer->setFeedback(tr("Rotation %1°").arg(QString::number(Settings::rotation)));
}
void Phototonic::flipVertical() {
Settings::flipV = !Settings::flipV;
imageViewer->refresh();
imageViewer->setFeedback(Settings::flipV ? tr("Flipped Vertically") : tr("Unflipped Vertically"));
}
void Phototonic::flipHorizontal() {
Settings::flipH = !Settings::flipH;
imageViewer->refresh();
imageViewer->setFeedback(Settings::flipH ? tr("Flipped Horizontally") : tr("Unflipped Horizontally"));
}
void Phototonic::cropImage() {
if (Settings::slideShowActive) {
toggleSlideShow();
}
if (!cropDialog) {
cropDialog = new CropDialog(this, imageViewer);
connect(cropDialog, SIGNAL(accepted()), this, SLOT(cleanupCropDialog()));
connect(cropDialog, SIGNAL(rejected()), this, SLOT(cleanupCropDialog()));
}
cropDialog->show();
setInterfaceEnabled(false);
cropDialog->applyCrop(0);
}
void Phototonic::scaleImage() {
if (Settings::slideShowActive) {
toggleSlideShow();
}
if (Settings::layoutMode == ThumbViewWidget && thumbsViewer->selectionModel()->selectedIndexes().size() < 1) {
setStatus(tr("No selection"));
return;
}
resizeDialog = new ResizeDialog(this, imageViewer);
connect(resizeDialog, SIGNAL(accepted()), this, SLOT(cleanupResizeDialog()));
connect(resizeDialog, SIGNAL(rejected()), this, SLOT(cleanupResizeDialog()));
resizeDialog->show();
setInterfaceEnabled(false);
}
void Phototonic::freeRotateLeft() {
--Settings::rotation;
if (Settings::rotation < 0)
Settings::rotation = 359;
imageViewer->refresh();
imageViewer->setFeedback(tr("Rotation %1°").arg(QString::number(Settings::rotation)));
}
void Phototonic::freeRotateRight() {
++Settings::rotation;
if (Settings::rotation > 360)
Settings::rotation = 1;
imageViewer->refresh();
imageViewer->setFeedback(tr("Rotation %1°").arg(QString::number(Settings::rotation)));
}
void Phototonic::showColorsDialog() {
if (Settings::slideShowActive) {
toggleSlideShow();
}
if (!colorsDialog) {
colorsDialog = new ColorsDialog(this, imageViewer);
connect(colorsDialog, SIGNAL(accepted()), this, SLOT(cleanupColorsDialog()));
connect(colorsDialog, SIGNAL(rejected()), this, SLOT(cleanupColorsDialog()));
}
Settings::colorsActive = true;
colorsDialog->show();
colorsDialog->applyColors(0);
setInterfaceEnabled(false);
}
void Phototonic::moveRight() {
imageViewer->keyMoveEvent(ImageViewer::MoveRight);
}
void Phototonic::moveLeft() {
imageViewer->keyMoveEvent(ImageViewer::MoveLeft);
}
void Phototonic::moveUp() {
imageViewer->keyMoveEvent(ImageViewer::MoveUp);
}
void Phototonic::moveDown() {
imageViewer->keyMoveEvent(ImageViewer::MoveDown);
}
void Phototonic::setMirrorDisabled() {
imageViewer->mirrorLayout = ImageViewer::LayNone;
imageViewer->refresh();
imageViewer->setFeedback(tr("Mirroring Disabled"));
}
void Phototonic::setMirrorDual() {
imageViewer->mirrorLayout = ImageViewer::LayDual;
imageViewer->refresh();
imageViewer->setFeedback(tr("Mirroring: Dual"));
}
void Phototonic::setMirrorTriple() {
imageViewer->mirrorLayout = ImageViewer::LayTriple;
imageViewer->refresh();
imageViewer->setFeedback(tr("Mirroring: Triple"));
}
void Phototonic::setMirrorVDual() {
imageViewer->mirrorLayout = ImageViewer::LayVDual;
imageViewer->refresh();
imageViewer->setFeedback(tr("Mirroring: Dual Vertical"));
}
void Phototonic::setMirrorQuad() {
imageViewer->mirrorLayout = ImageViewer::LayQuad;
imageViewer->refresh();
imageViewer->setFeedback(tr("Mirroring: Quad"));
}
bool Phototonic::isValidPath(QString &path) {
QDir checkPath(path);
if (!checkPath.exists() || !checkPath.isReadable()) {
return false;
}
return true;
}
void Phototonic::pasteThumbs() {
if (!copyCutThumbsCount) {
return;
}
QString destDir;
if (copyMoveToDialog) {
destDir = copyMoveToDialog->selectedPath;
} else {
if (QApplication::focusWidget() == bookmarks) {
if (bookmarks->currentItem()) {
destDir = bookmarks->currentItem()->toolTip(0);
}
} else {
destDir = getSelectedPath();
}
}
if (!isValidPath(destDir)) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Can not copy or move to ") + destDir);
selectCurrentViewDir();
return;
}
bool pasteInCurrDir = (Settings::currentDirectory == destDir);
QFileInfo fileInfo;
if (!Settings::isCopyOperation && pasteInCurrDir) {
for (int thumb = 0; thumb < Settings::copyCutFileList.size(); ++thumb) {
fileInfo = QFileInfo(Settings::copyCutFileList[thumb]);
if (fileInfo.absolutePath() == destDir) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Can not move to the same directory"));
return;
}
}
}
CopyMoveDialog *copyMoveDialog = new CopyMoveDialog(this);
copyMoveDialog->exec(thumbsViewer, destDir, pasteInCurrDir);
if (pasteInCurrDir) {
for (int thumb = 0; thumb < Settings::copyCutFileList.size(); ++thumb) {
thumbsViewer->addThumb(Settings::copyCutFileList[thumb]);
}
} else {
int row = copyMoveDialog->latestRow;
if (thumbsViewer->thumbsViewerModel->rowCount()) {
if (row >= thumbsViewer->thumbsViewerModel->rowCount()) {
row = thumbsViewer->thumbsViewerModel->rowCount() - 1;
}
thumbsViewer->setCurrentRow(row);
thumbsViewer->selectThumbByRow(row);
}
}
QString state = QString((Settings::isCopyOperation ? tr("Copied") : tr("Moved")) + " " +
tr("%n image(s)", "", copyMoveDialog->nFiles));
setStatus(state);
delete (copyMoveDialog);
selectCurrentViewDir();
copyCutThumbsCount = 0;
Settings::copyCutIndexList.clear();
Settings::copyCutFileList.clear();
pasteAction->setEnabled(false);
thumbsViewer->loadVisibleThumbs();
}
void Phototonic::loadCurrentImage(int currentRow) {
bool wrapImageListTmp = Settings::wrapImageList;
Settings::wrapImageList = false;
if (currentRow == thumbsViewer->thumbsViewerModel->rowCount()) {
thumbsViewer->setCurrentRow(currentRow - 1);
}
if (thumbsViewer->getNextRow() < 0 && currentRow > 0) {
imageViewer->loadImage(thumbsViewer->thumbsViewerModel->item(currentRow - 1)->
data(thumbsViewer->FileNameRole).toString());
} else {
if (thumbsViewer->thumbsViewerModel->rowCount() == 0) {
hideViewer();
refreshThumbs(true);
return;
}
if (currentRow > (thumbsViewer->thumbsViewerModel->rowCount() - 1))
currentRow = thumbsViewer->thumbsViewerModel->rowCount() - 1;
imageViewer->loadImage(thumbsViewer->thumbsViewerModel->item(currentRow)->
data(thumbsViewer->FileNameRole).toString());
}
Settings::wrapImageList = wrapImageListTmp;
thumbsViewer->setImageViewerWindowTitle();
}
void Phototonic::deleteImages(bool trash) {
// Deleting selected thumbnails
if (thumbsViewer->selectionModel()->selectedIndexes().size() < 1) {
setStatus(tr("No selection"));
return;
}
if (Settings::deleteConfirm) {
MessageBox msgBox(this);
msgBox.setText(trash ? tr("Move selected images to the trash?") : tr("Permanently delete selected images?"));
msgBox.setWindowTitle(trash ? tr("Move to Trash") : tr("Delete images"));
msgBox.setIcon(MessageBox::Warning);
msgBox.setStandardButtons(MessageBox::Yes | MessageBox::Cancel);
msgBox.setDefaultButton(MessageBox::Yes);
msgBox.setButtonText(MessageBox::Yes, tr("Yes"));
msgBox.setButtonText(MessageBox::Cancel, tr("Cancel"));
if (msgBox.exec() != MessageBox::Yes) {
return;
}
}
ProgressDialog *progressDialog = new ProgressDialog(this);
progressDialog->show();
int deleteFilesCount = 0;
bool deleteOk;
QList rows;
int row;
QModelIndexList indexesList;
while ((indexesList = thumbsViewer->selectionModel()->selectedIndexes()).size()) {
QString fileNameFullPath = thumbsViewer->thumbsViewerModel->item(
indexesList.first().row())->data(thumbsViewer->FileNameRole).toString();
progressDialog->opLabel->setText("Deleting " + fileNameFullPath);
QString deleteError;
if (trash) {
deleteOk = Trash::moveToTrash(fileNameFullPath, deleteError) == Trash::Success;
} else {
QFile fileToRemove(fileNameFullPath);
deleteOk = fileToRemove.remove();
if (!deleteOk) {
deleteError = fileToRemove.errorString();
}
}
++deleteFilesCount;
if (deleteOk) {
row = indexesList.first().row();
rows << row;
thumbsViewer->thumbsViewerModel->removeRow(row);
} else {
MessageBox msgBox(this);
msgBox.critical(tr("Error"),
(trash ? tr("Failed to move image to the trash.") : tr("Failed to delete image.")) + "\n" +
deleteError);
break;
}
Settings::filesList.removeOne(fileNameFullPath);
if (progressDialog->abortOp) {
break;
}
}
if (thumbsViewer->thumbsViewerModel->rowCount() && rows.count()) {
qSort(rows.begin(), rows.end());
row = rows.at(0);
if (row >= thumbsViewer->thumbsViewerModel->rowCount()) {
row = thumbsViewer->thumbsViewerModel->rowCount() - 1;
}
thumbsViewer->setCurrentRow(row);
thumbsViewer->selectThumbByRow(row);
}
progressDialog->close();
delete (progressDialog);
QString state = QString(tr("Deleted") + " " + tr("%n image(s)", "", deleteFilesCount));
setStatus(state);
}
void Phototonic::deleteFromViewer(bool trash) {
if (imageViewer->isNewImage()) {
showNewImageWarning();
return;
}
if (Settings::slideShowActive) {
toggleSlideShow();
}
imageViewer->setCursorHiding(false);
bool ok;
QFileInfo fileInfo = QFileInfo(imageViewer->viewerImageFullPath);
QString fileName = fileInfo.fileName();
bool deleteConfirmed = true;
if (Settings::deleteConfirm) {
MessageBox msgBox(this);
msgBox.setText(trash ? tr("Move %1 to the trash").arg(fileName) : tr("Permanently delete %1").arg(fileName));
msgBox.setWindowTitle(trash ? tr("Move to Trash") : tr("Delete images"));
msgBox.setIcon(MessageBox::Warning);
msgBox.setStandardButtons(MessageBox::Yes | MessageBox::Cancel);
msgBox.setDefaultButton(MessageBox::Yes);
msgBox.setButtonText(MessageBox::Yes, tr("Yes"));
msgBox.setButtonText(MessageBox::Cancel, tr("Cancel"));
if (msgBox.exec() != MessageBox::Yes) {
deleteConfirmed = false;
}
}
if (deleteConfirmed) {
int currentRow = thumbsViewer->getCurrentRow();
QString trashError;
ok = trash ? (Trash::moveToTrash(imageViewer->viewerImageFullPath, trashError) == Trash::Success)
: QFile::remove(imageViewer->viewerImageFullPath);
if (ok) {
thumbsViewer->thumbsViewerModel->removeRow(currentRow);
imageViewer->setFeedback(tr("Deleted ") + fileName);
} else {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), trash ? trashError : tr("Failed to delete image"));
if (isFullScreen()) {
imageViewer->setCursorHiding(true);
}
return;
}
loadCurrentImage(currentRow);
}
if (isFullScreen()) {
imageViewer->setCursorHiding(true);
}
}
// Main delete operation
void Phototonic::deleteOperation() {
if (QApplication::focusWidget() == thumbsViewer->imageTags->tagsTree) {
thumbsViewer->imageTags->removeTag();
return;
}
if (QApplication::focusWidget() == bookmarks) {
bookmarks->removeBookmark();
return;
}
if (QApplication::focusWidget() == fileSystemTree) {
deleteDirectory(true);
return;
}
if (Settings::layoutMode == ImageViewWidget) {
deleteFromViewer(true);
return;
}
deleteImages(true);
}
void Phototonic::deletePermanentlyOperation() {
if (QApplication::focusWidget() == fileSystemTree) {
deleteDirectory(false);
return;
}
if (Settings::layoutMode == ImageViewWidget) {
deleteFromViewer(false);
return;
}
deleteImages(false);
}
void Phototonic::goTo(QString path) {
Settings::isFileListLoaded = false;
fileListWidget->clearSelection();
thumbsViewer->setNeedToScroll(true);
fileSystemTree->setCurrentIndex(fileSystemTree->fileSystemModel->index(path));
Settings::currentDirectory = path;
refreshThumbs(true);
}
void Phototonic::goSelectedDir(const QModelIndex &idx) {
Settings::isFileListLoaded = false;
fileListWidget->clearSelection();
thumbsViewer->setNeedToScroll(true);
Settings::currentDirectory = getSelectedPath();
refreshThumbs(true);
fileSystemTree->expand(idx);
}
void Phototonic::goPathBarDir() {
thumbsViewer->setNeedToScroll(true);
QDir checkPath(pathLineEdit->text());
if (!checkPath.exists() || !checkPath.isReadable()) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Invalid Path:") + " " + pathLineEdit->text());
pathLineEdit->setText(Settings::currentDirectory);
return;
}
Settings::currentDirectory = pathLineEdit->text();
refreshThumbs(true);
selectCurrentViewDir();
}
void Phototonic::bookmarkClicked(QTreeWidgetItem *item, int col) {
goTo(item->toolTip(col));
}
void Phototonic::setThumbsFilter() {
thumbsViewer->filterString = filterLineEdit->text();
refreshThumbs(true);
}
void Phototonic::clearThumbsFilter() {
if (filterLineEdit->text() == "") {
thumbsViewer->filterString = filterLineEdit->text();
refreshThumbs(true);
}
}
void Phototonic::goBack() {
if (currentHistoryIdx > 0) {
needHistoryRecord = false;
goTo(pathHistoryList.at(--currentHistoryIdx));
goFrwdAction->setEnabled(true);
if (currentHistoryIdx == 0)
goBackAction->setEnabled(false);
}
}
void Phototonic::goForward() {
if (currentHistoryIdx < pathHistoryList.size() - 1) {
needHistoryRecord = false;
goTo(pathHistoryList.at(++currentHistoryIdx));
if (currentHistoryIdx == (pathHistoryList.size() - 1))
goFrwdAction->setEnabled(false);
}
}
void Phototonic::goUp() {
QFileInfo fileInfo = QFileInfo(Settings::currentDirectory);
goTo(fileInfo.dir().absolutePath());
}
void Phototonic::goHome() {
goTo(QDir::homePath());
}
void Phototonic::setCopyCutActions(bool setEnabled) {
cutAction->setEnabled(setEnabled);
copyAction->setEnabled(setEnabled);
}
void Phototonic::updateActions() {
if (QApplication::focusWidget() == thumbsViewer) {
bool hasSelectedItems = thumbsViewer->selectionModel()->selectedIndexes().size() > 0;
setCopyCutActions(hasSelectedItems);
} else if (QApplication::focusWidget() == bookmarks) {
setCopyCutActions(false);
} else if (QApplication::focusWidget() == fileSystemTree) {
setCopyCutActions(false);
} else if (Settings::layoutMode == ImageViewWidget || QApplication::focusWidget() == imageViewer->scrollArea) {
setCopyCutActions(false);
} else {
setCopyCutActions(false);
}
if (Settings::layoutMode == ImageViewWidget && !interfaceDisabled) {
setViewerKeyEventsEnabled(true);
fullScreenAction->setEnabled(true);
CloseImageAction->setEnabled(true);
} else {
if (QApplication::focusWidget() == imageViewer->scrollArea) {
setViewerKeyEventsEnabled(true);
fullScreenAction->setEnabled(false);
CloseImageAction->setEnabled(false);
} else {
setViewerKeyEventsEnabled(false);
fullScreenAction->setEnabled(false);
CloseImageAction->setEnabled(false);
}
}
}
void Phototonic::writeSettings() {
if (Settings::layoutMode == ThumbViewWidget) {
Settings::appSettings->setValue(Settings::optionGeometry, saveGeometry());
Settings::appSettings->setValue(Settings::optionWindowState, saveState());
}
Settings::appSettings->setValue(Settings::optionThumbsSortFlags, (int) thumbsViewer->thumbsSortFlags);
Settings::appSettings->setValue(Settings::optionThumbsZoomLevel, thumbsViewer->thumbSize);
Settings::appSettings->setValue(Settings::optionFullScreenMode, (bool) Settings::isFullScreen);
Settings::appSettings->setValue(Settings::optionViewerBackgroundColor, Settings::viewerBackgroundColor);
Settings::appSettings->setValue(Settings::optionThumbsBackgroundColor, Settings::thumbsBackgroundColor);
Settings::appSettings->setValue(Settings::optionThumbsTextColor, Settings::thumbsTextColor);
Settings::appSettings->setValue(Settings::optionThumbsPagesReadCount, (int) Settings::thumbsPagesReadCount);
Settings::appSettings->setValue(Settings::optionEnableAnimations, (bool) Settings::enableAnimations);
Settings::appSettings->setValue(Settings::optionExifRotationEnabled, (bool) Settings::exifRotationEnabled);
Settings::appSettings->setValue(Settings::optionExifThumbRotationEnabled,
(bool) Settings::exifThumbRotationEnabled);
Settings::appSettings->setValue(Settings::optionReverseMouseBehavior, (bool) Settings::reverseMouseBehavior);
Settings::appSettings->setValue(Settings::optionDeleteConfirm, (bool) Settings::deleteConfirm);
Settings::appSettings->setValue(Settings::optionShowHiddenFiles, (bool) Settings::showHiddenFiles);
Settings::appSettings->setValue(Settings::optionWrapImageList, (bool) Settings::wrapImageList);
Settings::appSettings->setValue(Settings::optionImageZoomFactor, Settings::imageZoomFactor);
Settings::appSettings->setValue(Settings::optionShouldMaximize, (bool) isMaximized());
Settings::appSettings->setValue(Settings::optionDefaultSaveQuality, Settings::defaultSaveQuality);
Settings::appSettings->setValue(Settings::optionSlideShowDelay, Settings::slideShowDelay);
Settings::appSettings->setValue(Settings::optionSlideShowRandom, (bool) Settings::slideShowRandom);
Settings::appSettings->setValue(Settings::optionEditToolBarVisible, (bool) editToolBarVisible);
Settings::appSettings->setValue(Settings::optionGoToolBarVisible, (bool) goToolBarVisible);
Settings::appSettings->setValue(Settings::optionViewToolBarVisible, (bool) viewToolBarVisible);
Settings::appSettings->setValue(Settings::optionImageToolBarVisible, (bool) imageToolBarVisible);
Settings::appSettings->setValue(Settings::optionFileSystemDockVisible, (bool) Settings::fileSystemDockVisible);
Settings::appSettings->setValue(Settings::optionImageInfoDockVisible, (bool) Settings::imageInfoDockVisible);
Settings::appSettings->setValue(Settings::optionBookmarksDockVisible, (bool) Settings::bookmarksDockVisible);
Settings::appSettings->setValue(Settings::optionTagsDockVisible, (bool) Settings::tagsDockVisible);
Settings::appSettings->setValue(Settings::optionImagePreviewDockVisible, (bool) Settings::imagePreviewDockVisible);
Settings::appSettings->setValue(Settings::optionStartupDir, (int) Settings::startupDir);
Settings::appSettings->setValue(Settings::optionSpecifiedStartDir, Settings::specifiedStartDir);
Settings::appSettings->setValue(Settings::optionThumbsBackgroundImage, Settings::thumbsBackgroundImage);
Settings::appSettings->setValue(Settings::optionLastDir,
Settings::startupDir == Settings::RememberLastDir ? Settings::currentDirectory
: "");
Settings::appSettings->setValue(Settings::optionShowImageName, (bool) Settings::showImageName);
Settings::appSettings->setValue(Settings::optionSmallToolbarIcons, (bool) Settings::smallToolbarIcons);
Settings::appSettings->setValue(Settings::optionHideDockTitlebars, (bool) Settings::hideDockTitlebars);
Settings::appSettings->setValue(Settings::optionShowViewerToolbar, (bool) Settings::showViewerToolbar);
Settings::appSettings->setValue(Settings::optionSetWindowIcon, (bool) Settings::setWindowIcon);
/* Action shortcuts */
Settings::appSettings->beginGroup(Settings::optionShortcuts);
QMapIterator shortcutsIterator(Settings::actionKeys);
while (shortcutsIterator.hasNext()) {
shortcutsIterator.next();
Settings::appSettings->setValue(shortcutsIterator.key(), shortcutsIterator.value()->shortcut().toString());
}
Settings::appSettings->endGroup();
/* External apps */
Settings::appSettings->beginGroup(Settings::optionExternalApps);
Settings::appSettings->remove("");
QMapIterator eaIter(Settings::externalApps);
while (eaIter.hasNext()) {
eaIter.next();
Settings::appSettings->setValue(eaIter.key(), eaIter.value());
}
Settings::appSettings->endGroup();
/* save bookmarks */
int idx = 0;
Settings::appSettings->beginGroup(Settings::optionCopyMoveToPaths);
Settings::appSettings->remove("");
QSetIterator pathsIter(Settings::bookmarkPaths);
while (pathsIter.hasNext()) {
Settings::appSettings->setValue("path" + QString::number(++idx), pathsIter.next());
}
Settings::appSettings->endGroup();
/* save known Tags */
idx = 0;
Settings::appSettings->beginGroup(Settings::optionKnownTags);
Settings::appSettings->remove("");
QSetIterator tagsIter(Settings::knownTags);
while (tagsIter.hasNext()) {
Settings::appSettings->setValue("tag" + QString::number(++idx), tagsIter.next());
}
Settings::appSettings->endGroup();
}
void Phototonic::readSettings() {
initComplete = false;
needThumbsRefresh = false;
if (!Settings::appSettings->contains(Settings::optionThumbsZoomLevel)) {
resize(800, 600);
Settings::appSettings->setValue(Settings::optionThumbsSortFlags, (int) 0);
Settings::appSettings->setValue(Settings::optionThumbsZoomLevel, (int) 200);
Settings::appSettings->setValue(Settings::optionFullScreenMode, (bool) false);
Settings::appSettings->setValue(Settings::optionViewerBackgroundColor, QColor(25, 25, 25));
Settings::appSettings->setValue(Settings::optionThumbsBackgroundColor, QColor(200, 200, 200));
Settings::appSettings->setValue(Settings::optionThumbsTextColor, QColor(25, 25, 25));
Settings::appSettings->setValue(Settings::optionThumbsPagesReadCount, (int) 2);
Settings::appSettings->setValue(Settings::optionViewerZoomOutFlags, (int) 1);
Settings::appSettings->setValue(Settings::optionViewerZoomInFlags, (int) 0);
Settings::appSettings->setValue(Settings::optionWrapImageList, (bool) false);
Settings::appSettings->setValue(Settings::optionImageZoomFactor, (float) 1.0);
Settings::appSettings->setValue(Settings::optionDefaultSaveQuality, (int) 90);
Settings::appSettings->setValue(Settings::optionEnableAnimations, (bool) true);
Settings::appSettings->setValue(Settings::optionExifRotationEnabled, (bool) true);
Settings::appSettings->setValue(Settings::optionExifThumbRotationEnabled, (bool) false);
Settings::appSettings->setValue(Settings::optionReverseMouseBehavior, (bool) false);
Settings::appSettings->setValue(Settings::optionDeleteConfirm, (bool) true);
Settings::appSettings->setValue(Settings::optionShowHiddenFiles, (bool) false);
Settings::appSettings->setValue(Settings::optionSlideShowDelay, (int) 5);
Settings::appSettings->setValue(Settings::optionSlideShowRandom, (bool) false);
Settings::appSettings->setValue(Settings::optionEditToolBarVisible, (bool) true);
Settings::appSettings->setValue(Settings::optionGoToolBarVisible, (bool) true);
Settings::appSettings->setValue(Settings::optionViewToolBarVisible, (bool) true);
Settings::appSettings->setValue(Settings::optionImageToolBarVisible, (bool) false);
Settings::appSettings->setValue(Settings::optionFileSystemDockVisible, (bool) true);
Settings::appSettings->setValue(Settings::optionBookmarksDockVisible, (bool) true);
Settings::appSettings->setValue(Settings::optionTagsDockVisible, (bool) true);
Settings::appSettings->setValue(Settings::optionImagePreviewDockVisible, (bool) true);
Settings::appSettings->setValue(Settings::optionImageInfoDockVisible, (bool) true);
Settings::appSettings->setValue(Settings::optionShowImageName, (bool) false);
Settings::appSettings->setValue(Settings::optionSmallToolbarIcons, (bool) false);
Settings::appSettings->setValue(Settings::optionHideDockTitlebars, (bool) false);
Settings::appSettings->setValue(Settings::optionShowViewerToolbar, (bool) false);
Settings::appSettings->setValue(Settings::optionSmallToolbarIcons, (bool) true);
Settings::bookmarkPaths.insert(QDir::homePath());
const QString picturesLocation = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
if (!picturesLocation.isEmpty()) {
Settings::bookmarkPaths.insert(picturesLocation);
}
}
Settings::viewerBackgroundColor = Settings::appSettings->value(
Settings::optionViewerBackgroundColor).value();
Settings::enableAnimations = Settings::appSettings->value(Settings::optionEnableAnimations).toBool();
Settings::exifRotationEnabled = Settings::appSettings->value(Settings::optionExifRotationEnabled).toBool();
Settings::exifThumbRotationEnabled = Settings::appSettings->value(
Settings::optionExifThumbRotationEnabled).toBool();
Settings::reverseMouseBehavior = Settings::appSettings->value(Settings::optionReverseMouseBehavior).toBool();
Settings::deleteConfirm = Settings::appSettings->value(Settings::optionDeleteConfirm).toBool();
Settings::showHiddenFiles = Settings::appSettings->value(Settings::optionShowHiddenFiles).toBool();
Settings::wrapImageList = Settings::appSettings->value(Settings::optionWrapImageList).toBool();
Settings::imageZoomFactor = Settings::appSettings->value(Settings::optionImageZoomFactor).toFloat();
Settings::zoomOutFlags = Settings::appSettings->value(Settings::optionViewerZoomOutFlags).toUInt();
Settings::zoomInFlags = Settings::appSettings->value(Settings::optionViewerZoomInFlags).toUInt();
Settings::rotation = 0;
Settings::keepTransform = false;
shouldMaximize = Settings::appSettings->value(Settings::optionShouldMaximize).toBool();
Settings::flipH = false;
Settings::flipV = false;
Settings::defaultSaveQuality = Settings::appSettings->value(Settings::optionDefaultSaveQuality).toInt();
Settings::slideShowDelay = Settings::appSettings->value(Settings::optionSlideShowDelay).toInt();
Settings::slideShowRandom = Settings::appSettings->value(Settings::optionSlideShowRandom).toBool();
Settings::slideShowActive = false;
editToolBarVisible = Settings::appSettings->value(Settings::optionEditToolBarVisible).toBool();
goToolBarVisible = Settings::appSettings->value(Settings::optionGoToolBarVisible).toBool();
viewToolBarVisible = Settings::appSettings->value(Settings::optionViewToolBarVisible).toBool();
imageToolBarVisible = Settings::appSettings->value(Settings::optionImageToolBarVisible).toBool();
Settings::fileSystemDockVisible = Settings::appSettings->value(Settings::optionFileSystemDockVisible).toBool();
Settings::bookmarksDockVisible = Settings::appSettings->value(Settings::optionBookmarksDockVisible).toBool();
Settings::tagsDockVisible = Settings::appSettings->value(Settings::optionTagsDockVisible).toBool();
Settings::imagePreviewDockVisible = Settings::appSettings->value(Settings::optionImagePreviewDockVisible).toBool();
Settings::imageInfoDockVisible = Settings::appSettings->value(Settings::optionImageInfoDockVisible).toBool();
Settings::startupDir = (Settings::StartupDir) Settings::appSettings->value(Settings::optionStartupDir).toInt();
Settings::specifiedStartDir = Settings::appSettings->value(Settings::optionSpecifiedStartDir).toString();
Settings::thumbsBackgroundImage = Settings::appSettings->value(Settings::optionThumbsBackgroundImage).toString();
Settings::showImageName = Settings::appSettings->value(Settings::optionShowImageName).toBool();
Settings::smallToolbarIcons = Settings::appSettings->value(Settings::optionSmallToolbarIcons).toBool();
Settings::hideDockTitlebars = Settings::appSettings->value(Settings::optionHideDockTitlebars).toBool();
Settings::showViewerToolbar = Settings::appSettings->value(Settings::optionShowViewerToolbar).toBool();
Settings::setWindowIcon = Settings::appSettings->value(Settings::optionSetWindowIcon).toBool();
/* read external apps */
Settings::appSettings->beginGroup(Settings::optionExternalApps);
QStringList extApps = Settings::appSettings->childKeys();
for (int i = 0; i < extApps.size(); ++i) {
Settings::externalApps[extApps.at(i)] = Settings::appSettings->value(extApps.at(i)).toString();
}
Settings::appSettings->endGroup();
/* read bookmarks */
Settings::appSettings->beginGroup(Settings::optionCopyMoveToPaths);
QStringList paths = Settings::appSettings->childKeys();
for (int i = 0; i < paths.size(); ++i) {
Settings::bookmarkPaths.insert(Settings::appSettings->value(paths.at(i)).toString());
}
Settings::appSettings->endGroup();
/* read known tags */
Settings::appSettings->beginGroup(Settings::optionKnownTags);
QStringList tags = Settings::appSettings->childKeys();
for (int i = 0; i < tags.size(); ++i) {
Settings::knownTags.insert(Settings::appSettings->value(tags.at(i)).toString());
}
Settings::appSettings->endGroup();
Settings::isFileListLoaded = false;
}
void Phototonic::setupDocks() {
addDockWidget(Qt::RightDockWidgetArea, imageInfoDock);
addDockWidget(Qt::RightDockWidgetArea, tagsDock);
menuBar()->addMenu(createPopupMenu())->setText(tr("Window"));
menuBar()->addSeparator();
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAction);
fileSystemDockOrigWidget = fileSystemDock->titleBarWidget();
bookmarksDockOrigWidget = bookmarksDock->titleBarWidget();
imagePreviewDockOrigWidget = imagePreviewDock->titleBarWidget();
tagsDockOrigWidget = tagsDock->titleBarWidget();
imageInfoDockOrigWidget = imageInfoDock->titleBarWidget();
fileSystemDockEmptyWidget = new QWidget;
bookmarksDockEmptyWidget = new QWidget;
imagePreviewDockEmptyWidget = new QWidget;
tagsDockEmptyWidget = new QWidget;
imageInfoDockEmptyWidget = new QWidget;
lockDocks();
}
void Phototonic::lockDocks() {
if (initComplete)
Settings::hideDockTitlebars = lockDocksAction->isChecked();
if (Settings::hideDockTitlebars) {
fileSystemDock->setTitleBarWidget(fileSystemDockEmptyWidget);
bookmarksDock->setTitleBarWidget(bookmarksDockEmptyWidget);
imagePreviewDock->setTitleBarWidget(imagePreviewDockEmptyWidget);
tagsDock->setTitleBarWidget(tagsDockEmptyWidget);
imageInfoDock->setTitleBarWidget(imageInfoDockEmptyWidget);
} else {
fileSystemDock->setTitleBarWidget(fileSystemDockOrigWidget);
bookmarksDock->setTitleBarWidget(bookmarksDockOrigWidget);
imagePreviewDock->setTitleBarWidget(imagePreviewDockOrigWidget);
tagsDock->setTitleBarWidget(tagsDockOrigWidget);
imageInfoDock->setTitleBarWidget(imageInfoDockOrigWidget);
}
}
QMenu *Phototonic::createPopupMenu() {
QMenu *extraActsMenu = QMainWindow::createPopupMenu();
extraActsMenu->addSeparator();
extraActsMenu->addAction(smallToolbarIconsAction);
extraActsMenu->addAction(lockDocksAction);
return extraActsMenu;
}
void Phototonic::loadShortcuts() {
// Add customizable key shortcut actions
Settings::actionKeys[thumbsGoToTopAction->objectName()] = thumbsGoToTopAction;
Settings::actionKeys[thumbsGoToBottomAction->objectName()] = thumbsGoToBottomAction;
Settings::actionKeys[CloseImageAction->objectName()] = CloseImageAction;
Settings::actionKeys[fullScreenAction->objectName()] = fullScreenAction;
Settings::actionKeys[settingsAction->objectName()] = settingsAction;
Settings::actionKeys[exitAction->objectName()] = exitAction;
Settings::actionKeys[thumbsZoomInAction->objectName()] = thumbsZoomInAction;
Settings::actionKeys[thumbsZoomOutAction->objectName()] = thumbsZoomOutAction;
Settings::actionKeys[cutAction->objectName()] = cutAction;
Settings::actionKeys[copyAction->objectName()] = copyAction;
Settings::actionKeys[nextImageAction->objectName()] = nextImageAction;
Settings::actionKeys[prevImageAction->objectName()] = prevImageAction;
Settings::actionKeys[deletePermanentlyAction->objectName()] = deletePermanentlyAction;
Settings::actionKeys[deleteAction->objectName()] = deleteAction;
Settings::actionKeys[saveAction->objectName()] = saveAction;
Settings::actionKeys[saveAsAction->objectName()] = saveAsAction;
Settings::actionKeys[keepTransformAction->objectName()] = keepTransformAction;
Settings::actionKeys[keepZoomAction->objectName()] = keepZoomAction;
Settings::actionKeys[showClipboardAction->objectName()] = showClipboardAction;
Settings::actionKeys[copyImageAction->objectName()] = copyImageAction;
Settings::actionKeys[pasteImageAction->objectName()] = pasteImageAction;
Settings::actionKeys[renameAction->objectName()] = renameAction;
Settings::actionKeys[refreshAction->objectName()] = refreshAction;
Settings::actionKeys[pasteAction->objectName()] = pasteAction;
Settings::actionKeys[goBackAction->objectName()] = goBackAction;
Settings::actionKeys[goFrwdAction->objectName()] = goFrwdAction;
Settings::actionKeys[slideShowAction->objectName()] = slideShowAction;
Settings::actionKeys[firstImageAction->objectName()] = firstImageAction;
Settings::actionKeys[lastImageAction->objectName()] = lastImageAction;
Settings::actionKeys[randomImageAction->objectName()] = randomImageAction;
Settings::actionKeys[viewImageAction->objectName()] = viewImageAction;
Settings::actionKeys[zoomOutAction->objectName()] = zoomOutAction;
Settings::actionKeys[zoomInAction->objectName()] = zoomInAction;
Settings::actionKeys[resetZoomAction->objectName()] = resetZoomAction;
Settings::actionKeys[origZoomAction->objectName()] = origZoomAction;
Settings::actionKeys[rotateLeftAction->objectName()] = rotateLeftAction;
Settings::actionKeys[rotateRightAction->objectName()] = rotateRightAction;
Settings::actionKeys[freeRotateLeftAction->objectName()] = freeRotateLeftAction;
Settings::actionKeys[freeRotateRightAction->objectName()] = freeRotateRightAction;
Settings::actionKeys[flipHorizontalAction->objectName()] = flipHorizontalAction;
Settings::actionKeys[flipVerticalAction->objectName()] = flipVerticalAction;
Settings::actionKeys[cropAction->objectName()] = cropAction;
Settings::actionKeys[cropToSelectionAction->objectName()] = cropToSelectionAction;
Settings::actionKeys[colorsAction->objectName()] = colorsAction;
Settings::actionKeys[mirrorDisabledAction->objectName()] = mirrorDisabledAction;
Settings::actionKeys[mirrorDualAction->objectName()] = mirrorDualAction;
Settings::actionKeys[mirrorTripleAction->objectName()] = mirrorTripleAction;
Settings::actionKeys[mirrorDualVerticalAction->objectName()] = mirrorDualVerticalAction;
Settings::actionKeys[mirrorQuadAction->objectName()] = mirrorQuadAction;
Settings::actionKeys[moveDownAction->objectName()] = moveDownAction;
Settings::actionKeys[moveUpAction->objectName()] = moveUpAction;
Settings::actionKeys[moveRightAction->objectName()] = moveRightAction;
Settings::actionKeys[moveLeftAction->objectName()] = moveLeftAction;
Settings::actionKeys[copyToAction->objectName()] = copyToAction;
Settings::actionKeys[moveToAction->objectName()] = moveToAction;
Settings::actionKeys[goUpAction->objectName()] = goUpAction;
Settings::actionKeys[resizeAction->objectName()] = resizeAction;
Settings::actionKeys[filterImagesFocusAction->objectName()] = filterImagesFocusAction;
Settings::actionKeys[setPathFocusAction->objectName()] = setPathFocusAction;
Settings::actionKeys[invertSelectionAction->objectName()] = invertSelectionAction;
Settings::actionKeys[includeSubDirectoriesAction->objectName()] = includeSubDirectoriesAction;
Settings::actionKeys[createDirectoryAction->objectName()] = createDirectoryAction;
Settings::actionKeys[addBookmarkAction->objectName()] = addBookmarkAction;
Settings::actionKeys[removeMetadataAction->objectName()] = removeMetadataAction;
Settings::actionKeys[externalAppsAction->objectName()] = externalAppsAction;
Settings::actionKeys[goHomeAction->objectName()] = goHomeAction;
Settings::actionKeys[sortByNameAction->objectName()] = sortByNameAction;
Settings::actionKeys[sortBySizeAction->objectName()] = sortBySizeAction;
Settings::actionKeys[sortByTimeAction->objectName()] = sortByTimeAction;
Settings::actionKeys[sortByTypeAction->objectName()] = sortByTypeAction;
Settings::actionKeys[sortReverseAction->objectName()] = sortReverseAction;
Settings::actionKeys[showHiddenFilesAction->objectName()] = showHiddenFilesAction;
Settings::actionKeys[showViewerToolbarAction->objectName()] = showViewerToolbarAction;
Settings::appSettings->beginGroup(Settings::optionShortcuts);
QStringList groupKeys = Settings::appSettings->childKeys();
if (groupKeys.size()) {
if (groupKeys.contains(thumbsGoToTopAction->text())) {
QMapIterator key(Settings::actionKeys);
while (key.hasNext()) {
key.next();
if (groupKeys.contains(key.value()->text())) {
key.value()->setShortcut(Settings::appSettings->value(key.value()->text()).toString());
Settings::appSettings->remove(key.value()->text());
Settings::appSettings->setValue(key.key(), key.value()->shortcut().toString());
}
}
} else {
for (int i = 0; i < groupKeys.size(); ++i) {
if (Settings::actionKeys.value(groupKeys.at(i)))
Settings::actionKeys.value(groupKeys.at(i))->setShortcut
(Settings::appSettings->value(groupKeys.at(i)).toString());
}
}
} else {
thumbsGoToTopAction->setShortcut(QKeySequence("Ctrl+Home"));
thumbsGoToBottomAction->setShortcut(QKeySequence("Ctrl+End"));
CloseImageAction->setShortcut(Qt::Key_Escape);
fullScreenAction->setShortcut(QKeySequence("Alt+Return"));
settingsAction->setShortcut(QKeySequence("Ctrl+P"));
exitAction->setShortcut(QKeySequence("Ctrl+Q"));
cutAction->setShortcut(QKeySequence("Ctrl+X"));
copyAction->setShortcut(QKeySequence("Ctrl+C"));
deleteAction->setShortcut(QKeySequence("Del"));
deletePermanentlyAction->setShortcut(QKeySequence("Shift+Del"));
saveAction->setShortcut(QKeySequence("Ctrl+S"));
copyImageAction->setShortcut(QKeySequence("Ctrl+Shift+C"));
pasteImageAction->setShortcut(QKeySequence("Ctrl+Shift+V"));
renameAction->setShortcut(QKeySequence("F2"));
refreshAction->setShortcut(QKeySequence("F5"));
pasteAction->setShortcut(QKeySequence("Ctrl+V"));
goBackAction->setShortcut(QKeySequence("Alt+Left"));
goFrwdAction->setShortcut(QKeySequence("Alt+Right"));
goUpAction->setShortcut(QKeySequence("Alt+Up"));
slideShowAction->setShortcut(QKeySequence("Ctrl+W"));
nextImageAction->setShortcut(QKeySequence("PgDown"));
prevImageAction->setShortcut(QKeySequence("PgUp"));
firstImageAction->setShortcut(QKeySequence("Home"));
lastImageAction->setShortcut(QKeySequence("End"));
randomImageAction->setShortcut(QKeySequence("Ctrl+D"));
viewImageAction->setShortcut(QKeySequence("Return"));
zoomOutAction->setShortcut(QKeySequence("-"));
zoomInAction->setShortcut(QKeySequence("+"));
resetZoomAction->setShortcut(QKeySequence("*"));
origZoomAction->setShortcut(QKeySequence("/"));
rotateLeftAction->setShortcut(QKeySequence("Ctrl+Left"));
rotateRightAction->setShortcut(QKeySequence("Ctrl+Right"));
freeRotateLeftAction->setShortcut(QKeySequence("Ctrl+Shift+Left"));
freeRotateRightAction->setShortcut(QKeySequence("Ctrl+Shift+Right"));
flipHorizontalAction->setShortcut(QKeySequence("Ctrl+Down"));
flipVerticalAction->setShortcut(QKeySequence("Ctrl+Up"));
cropAction->setShortcut(QKeySequence("Ctrl+G"));
cropToSelectionAction->setShortcut(QKeySequence("Ctrl+R"));
colorsAction->setShortcut(QKeySequence("Ctrl+O"));
mirrorDisabledAction->setShortcut(QKeySequence("Ctrl+1"));
mirrorDualAction->setShortcut(QKeySequence("Ctrl+2"));
mirrorTripleAction->setShortcut(QKeySequence("Ctrl+3"));
mirrorDualVerticalAction->setShortcut(QKeySequence("Ctrl+4"));
mirrorQuadAction->setShortcut(QKeySequence("Ctrl+5"));
moveDownAction->setShortcut(QKeySequence("Down"));
moveUpAction->setShortcut(QKeySequence("Up"));
moveLeftAction->setShortcut(QKeySequence("Left"));
moveRightAction->setShortcut(QKeySequence("Right"));
copyToAction->setShortcut(QKeySequence("Ctrl+Y"));
moveToAction->setShortcut(QKeySequence("Ctrl+M"));
resizeAction->setShortcut(QKeySequence("Ctrl+I"));
filterImagesFocusAction->setShortcut(QKeySequence("Ctrl+F"));
setPathFocusAction->setShortcut(QKeySequence("Ctrl+L"));
keepTransformAction->setShortcut(QKeySequence("Ctrl+K"));
showHiddenFilesAction->setShortcut(QKeySequence("Ctrl+H"));
}
Settings::appSettings->endGroup();
}
void Phototonic::closeEvent(QCloseEvent *event) {
thumbsViewer->abort();
writeSettings();
hide();
if (!QApplication::clipboard()->image().isNull()) {
QApplication::clipboard()->clear();
}
event->accept();
}
void Phototonic::setStatus(QString state) {
statusLabel->setText(" " + state + " ");
}
void Phototonic::mouseDoubleClickEvent(QMouseEvent *event) {
if (interfaceDisabled) {
return;
}
if (event->button() == Qt::LeftButton) {
if (Settings::layoutMode == ImageViewWidget) {
if (Settings::reverseMouseBehavior) {
fullScreenAction->setChecked(!(fullScreenAction->isChecked()));
toggleFullScreen();
event->accept();
} else if (CloseImageAction->isEnabled()) {
hideViewer();
event->accept();
}
} else {
if (QApplication::focusWidget() == thumbsViewer->imagePreview->scrollArea) {
viewImage();
}
}
}
}
void Phototonic::mousePressEvent(QMouseEvent *event) {
if (interfaceDisabled) {
return;
}
if (Settings::layoutMode == ImageViewWidget) {
if (event->button() == Qt::MiddleButton) {
if (event->modifiers() == Qt::ShiftModifier) {
origZoom();
event->accept();
return;
}
if (event->modifiers() == Qt::ControlModifier) {
resetZoom();
event->accept();
return;
}
if (Settings::reverseMouseBehavior && CloseImageAction->isEnabled()) {
hideViewer();
event->accept();
} else {
fullScreenAction->setChecked(!(fullScreenAction->isChecked()));
toggleFullScreen();
event->accept();
}
}
} else if (QApplication::focusWidget() == thumbsViewer->imagePreview->scrollArea) {
if (event->button() == Qt::MiddleButton) {
viewImage();
}
}
}
void Phototonic::newImage() {
if (Settings::layoutMode == ThumbViewWidget) {
showViewer();
}
imageViewer->loadImage("");
}
void Phototonic::setDocksVisibility(bool visible) {
fileSystemDock->setVisible(visible ? Settings::fileSystemDockVisible : false);
bookmarksDock->setVisible(visible ? Settings::bookmarksDockVisible : false);
imagePreviewDock->setVisible(visible ? Settings::imagePreviewDockVisible : false);
tagsDock->setVisible(visible ? Settings::tagsDockVisible : false);
imageInfoDock->setVisible(visible ? Settings::imageInfoDockVisible : false);
menuBar()->setVisible(visible);
menuBar()->setDisabled(!visible);
statusBar()->setVisible(visible);
editToolBar->setVisible(visible ? editToolBarVisible : false);
goToolBar->setVisible(visible ? goToolBarVisible : false);
viewToolBar->setVisible(visible ? viewToolBarVisible : false);
imageToolBar->setVisible(visible ? imageToolBarVisible : Settings::showViewerToolbar);
addToolBar(imageToolBar);
setContextMenuPolicy(Qt::PreventContextMenu);
}
void Phototonic::viewImage() {
if (Settings::layoutMode == ImageViewWidget) {
hideViewer();
return;
}
if (QApplication::focusWidget() == fileSystemTree) {
goSelectedDir(fileSystemTree->getCurrentIndex());
return;
} else if (QApplication::focusWidget() == thumbsViewer
|| QApplication::focusWidget() == thumbsViewer->imagePreview->scrollArea
|| QApplication::focusWidget() == imageViewer->scrollArea) {
QModelIndex selectedImageIndex;
QModelIndexList selectedIndexes = thumbsViewer->selectionModel()->selectedIndexes();
if (selectedIndexes.size() > 0) {
selectedImageIndex = selectedIndexes.first();
} else {
if (thumbsViewer->thumbsViewerModel->rowCount() == 0) {
setStatus(tr("No images"));
return;
}
selectedImageIndex = thumbsViewer->thumbsViewerModel->indexFromItem(
thumbsViewer->thumbsViewerModel->item(0));
thumbsViewer->selectionModel()->select(selectedImageIndex, QItemSelectionModel::Toggle);
thumbsViewer->setCurrentRow(0);
}
loadSelectedThumbImage(selectedImageIndex);
return;
} else if (QApplication::focusWidget() == filterLineEdit) {
setThumbsFilter();
return;
} else if (QApplication::focusWidget() == pathLineEdit) {
goPathBarDir();
return;
}
}
void Phototonic::setEditToolBarVisibility() {
editToolBarVisible = editToolBar->isVisible();
}
void Phototonic::setGoToolBarVisibility() {
goToolBarVisible = goToolBar->isVisible();
}
void Phototonic::setViewToolBarVisibility() {
viewToolBarVisible = viewToolBar->isVisible();
}
void Phototonic::setImageToolBarVisibility() {
imageToolBarVisible = imageToolBar->isVisible();
}
void Phototonic::setFileSystemDockVisibility() {
if (Settings::layoutMode != ImageViewWidget) {
Settings::fileSystemDockVisible = fileSystemDock->isVisible();
}
}
void Phototonic::setBookmarksDockVisibility() {
if (Settings::layoutMode != ImageViewWidget) {
Settings::bookmarksDockVisible = bookmarksDock->isVisible();
}
}
void Phototonic::setImagePreviewDockVisibility() {
if (Settings::layoutMode != ImageViewWidget) {
Settings::imagePreviewDockVisible = imagePreviewDock->isVisible();
}
}
void Phototonic::setTagsDockVisibility() {
if (Settings::layoutMode != ImageViewWidget) {
Settings::tagsDockVisible = tagsDock->isVisible();
}
}
void Phototonic::setImageInfoDockVisibility() {
if (Settings::layoutMode != ImageViewWidget) {
Settings::imageInfoDockVisible = imageInfoDock->isVisible();
}
}
void Phototonic::showViewer() {
if (Settings::layoutMode == ThumbViewWidget) {
Settings::layoutMode = ImageViewWidget;
Settings::appSettings->setValue("Geometry", saveGeometry());
Settings::appSettings->setValue("WindowState", saveState());
stackedLayout->setCurrentWidget(imageViewer);
setDocksVisibility(false);
if (Settings::isFullScreen) {
shouldMaximize = isMaximized();
showFullScreen();
imageViewer->setCursorHiding(true);
QApplication::processEvents();
}
imageViewer->setFocus(Qt::OtherFocusReason);
}
}
void Phototonic::showBusyAnimation(bool busy) {
static int busyStatus = 0;
if (busy) {
++busyStatus;
} else {
--busyStatus;
}
if (busyStatus > 0) {
busyMovie->start();
busyLabel->setVisible(true);
} else {
busyLabel->setVisible(false);
busyMovie->stop();
busyStatus = 0;
}
}
void Phototonic::loadSelectedThumbImage(const QModelIndex &idx) {
thumbsViewer->setCurrentRow(idx.row());
showViewer();
imageViewer->loadImage(
thumbsViewer->thumbsViewerModel->item(idx.row())->data(thumbsViewer->FileNameRole).toString());
thumbsViewer->setImageViewerWindowTitle();
}
void Phototonic::loadImageFromCliArguments(QString cliFileName) {
QFile imageFile(cliFileName);
if (!imageFile.exists()) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to open file %1, file not found.").arg(cliFileName));
return;
}
showViewer();
imageViewer->loadImage(cliFileName);
setWindowTitle(cliFileName + " - Phototonic");
}
void Phototonic::toggleSlideShow() {
if (Settings::slideShowActive) {
Settings::slideShowActive = false;
slideShowAction->setText(tr("Slide Show"));
imageViewer->setFeedback(tr("Slide show stopped"));
SlideShowTimer->stop();
delete SlideShowTimer;
slideShowAction->setIcon(QIcon::fromTheme("media-playback-start", QIcon(":/images/play.png")));
} else {
if (thumbsViewer->thumbsViewerModel->rowCount() <= 0) {
return;
}
if (Settings::layoutMode == ThumbViewWidget) {
QModelIndexList indexesList = thumbsViewer->selectionModel()->selectedIndexes();
if (indexesList.size() != 1) {
thumbsViewer->setCurrentRow(0);
} else {
thumbsViewer->setCurrentRow(indexesList.first().row());
}
showViewer();
}
Settings::slideShowActive = true;
SlideShowTimer = new QTimer(this);
connect(SlideShowTimer, SIGNAL(timeout()), this, SLOT(slideShowHandler()));
SlideShowTimer->start(Settings::slideShowDelay * 1000);
slideShowAction->setText(tr("Stop Slide Show"));
imageViewer->setFeedback(tr("Slide show started"));
slideShowAction->setIcon(QIcon::fromTheme("media-playback-stop", QIcon(":/images/stop.png")));
slideShowHandler();
}
}
void Phototonic::slideShowHandler() {
if (Settings::slideShowActive) {
if (Settings::slideShowRandom) {
loadRandomImage();
} else {
int currentRow = thumbsViewer->getCurrentRow();
imageViewer->loadImage(
thumbsViewer->thumbsViewerModel->item(currentRow)->data(thumbsViewer->FileNameRole).toString());
thumbsViewer->setImageViewerWindowTitle();
if (thumbsViewer->getNextRow() > 0) {
thumbsViewer->setCurrentRow(thumbsViewer->getNextRow());
} else {
if (Settings::wrapImageList) {
thumbsViewer->setCurrentRow(0);
} else {
toggleSlideShow();
}
}
}
}
}
void Phototonic::loadNextImage() {
if (thumbsViewer->thumbsViewerModel->rowCount() <= 0) {
return;
}
int nextThumb = thumbsViewer->getNextRow();
if (nextThumb < 0) {
if (Settings::wrapImageList) {
nextThumb = 0;
} else {
return;
}
}
if (Settings::layoutMode == ImageViewWidget) {
imageViewer->loadImage(
thumbsViewer->thumbsViewerModel->item(nextThumb)->data(thumbsViewer->FileNameRole).toString());
}
thumbsViewer->setCurrentRow(nextThumb);
thumbsViewer->setImageViewerWindowTitle();
if (Settings::layoutMode == ThumbViewWidget) {
thumbsViewer->selectThumbByRow(nextThumb);
}
}
void Phototonic::loadPreviousImage() {
if (thumbsViewer->thumbsViewerModel->rowCount() <= 0) {
return;
}
int previousThumb = thumbsViewer->getPrevRow();
if (previousThumb < 0) {
if (Settings::wrapImageList) {
previousThumb = thumbsViewer->getLastRow();
} else {
return;
}
}
if (Settings::layoutMode == ImageViewWidget) {
imageViewer->loadImage(
thumbsViewer->thumbsViewerModel->item(previousThumb)->data(thumbsViewer->FileNameRole).toString());
}
thumbsViewer->setCurrentRow(previousThumb);
thumbsViewer->setImageViewerWindowTitle();
if (Settings::layoutMode == ThumbViewWidget) {
thumbsViewer->selectThumbByRow(previousThumb);
}
}
void Phototonic::loadFirstImage() {
if (thumbsViewer->thumbsViewerModel->rowCount() <= 0) {
return;
}
imageViewer->loadImage(thumbsViewer->thumbsViewerModel->item(0)->data(thumbsViewer->FileNameRole).toString());
thumbsViewer->setCurrentRow(0);
thumbsViewer->setImageViewerWindowTitle();
if (Settings::layoutMode == ThumbViewWidget) {
thumbsViewer->selectThumbByRow(0);
}
}
void Phototonic::loadLastImage() {
if (thumbsViewer->thumbsViewerModel->rowCount() <= 0) {
return;
}
int lastRow = thumbsViewer->getLastRow();
imageViewer->loadImage(thumbsViewer->thumbsViewerModel->item(lastRow)->data(thumbsViewer->FileNameRole).toString());
thumbsViewer->setCurrentRow(lastRow);
thumbsViewer->setImageViewerWindowTitle();
if (Settings::layoutMode == ThumbViewWidget) {
thumbsViewer->selectThumbByRow(lastRow);
}
}
void Phototonic::loadRandomImage() {
if (thumbsViewer->thumbsViewerModel->rowCount() <= 0) {
return;
}
int randomRow = thumbsViewer->getRandomRow();
imageViewer->loadImage(
thumbsViewer->thumbsViewerModel->item(randomRow)->data(thumbsViewer->FileNameRole).toString());
thumbsViewer->setCurrentRow(randomRow);
thumbsViewer->setImageViewerWindowTitle();
if (Settings::layoutMode == ThumbViewWidget) {
thumbsViewer->selectThumbByRow(randomRow);
}
}
void Phototonic::setViewerKeyEventsEnabled(bool enabled) {
moveLeftAction->setEnabled(enabled);
moveRightAction->setEnabled(enabled);
moveUpAction->setEnabled(enabled);
moveDownAction->setEnabled(enabled);
}
void Phototonic::updateIndexByViewerImage() {
if (thumbsViewer->thumbsViewerModel->rowCount() > 0 &&
thumbsViewer->setCurrentIndexByName(imageViewer->viewerImageFullPath)) {
thumbsViewer->selectCurrentIndex();
}
}
void Phototonic::hideViewer() {
if (isFullScreen()) {
showNormal();
if (shouldMaximize) {
showMaximized();
}
imageViewer->setCursorHiding(false);
}
restoreGeometry(Settings::appSettings->value(Settings::optionGeometry).toByteArray());
restoreState(Settings::appSettings->value(Settings::optionWindowState).toByteArray());
Settings::layoutMode = ThumbViewWidget;
stackedLayout->setCurrentWidget(thumbsViewer);
setDocksVisibility(true);
while (QApplication::overrideCursor()) {
QApplication::restoreOverrideCursor();
}
if (Settings::slideShowActive) {
toggleSlideShow();
}
setThumbsViewerWindowTitle();
for (int i = 0; i <= 10 && qApp->hasPendingEvents(); ++i) {
QApplication::processEvents();
}
if (needThumbsRefresh) {
needThumbsRefresh = false;
refreshThumbs(true);
} else {
if (thumbsViewer->thumbsViewerModel->rowCount() > 0) {
if (thumbsViewer->setCurrentIndexByName(imageViewer->viewerImageFullPath)) {
thumbsViewer->selectCurrentIndex();
}
}
thumbsViewer->loadVisibleThumbs();
}
imageViewer->clearImage();
thumbsViewer->setFocus(Qt::OtherFocusReason);
setContextMenuPolicy(Qt::DefaultContextMenu);
}
void Phototonic::goBottom() {
thumbsViewer->scrollToBottom();
}
void Phototonic::goTop() {
thumbsViewer->scrollToTop();
}
void Phototonic::dropOp(Qt::KeyboardModifiers keyMods, bool dirOp, QString copyMoveDirPath) {
QApplication::restoreOverrideCursor();
Settings::isCopyOperation = (keyMods == Qt::ControlModifier);
QString destDir;
if (QObject::sender() == fileSystemTree) {
destDir = getSelectedPath();
} else if (QObject::sender() == bookmarks) {
if (bookmarks->currentItem()) {
destDir = bookmarks->currentItem()->toolTip(0);
} else {
addBookmark(copyMoveDirPath);
return;
}
} else {
// Unknown sender
return;
}
MessageBox msgBox(this);
if (!isValidPath(destDir)) {
msgBox.critical(tr("Error"), tr("Can not move or copy images to this directory."));
selectCurrentViewDir();
return;
}
if (destDir == Settings::currentDirectory) {
msgBox.critical(tr("Error"), tr("Destination directory is the same as the source directory."));
return;
}
if (dirOp) {
QString dirOnly = copyMoveDirPath.right(
copyMoveDirPath.size() - copyMoveDirPath.lastIndexOf(QDir::separator()) - 1);
QString question = tr("Move directory %1 to %2?").arg(dirOnly).arg(destDir);
MessageBox moveDirMessageBox(this);
moveDirMessageBox.setText(question);
moveDirMessageBox.setWindowTitle(tr("Move directory"));
moveDirMessageBox.setIcon(MessageBox::Warning);
moveDirMessageBox.setStandardButtons(MessageBox::Yes | MessageBox::Cancel);
moveDirMessageBox.setDefaultButton(MessageBox::Cancel);
moveDirMessageBox.setButtonText(MessageBox::Yes, tr("Move Directory"));
moveDirMessageBox.setButtonText(MessageBox::Cancel, tr("Cancel"));
int ret = moveDirMessageBox.exec();
if (ret == MessageBox::Yes) {
QFile dir(copyMoveDirPath);
bool moveOk = dir.rename(destDir + QDir::separator() + dirOnly);
if (!moveOk) {
moveDirMessageBox.critical(tr("Error"), tr("Failed to move directory."));
}
setStatus(tr("Directory moved"));
}
} else {
CopyMoveDialog *copyMoveDialog = new CopyMoveDialog(this);
Settings::copyCutIndexList = thumbsViewer->selectionModel()->selectedIndexes();
copyMoveDialog->exec(thumbsViewer, destDir, false);
if (!Settings::isCopyOperation) {
int row = copyMoveDialog->latestRow;
if (thumbsViewer->thumbsViewerModel->rowCount()) {
if (row >= thumbsViewer->thumbsViewerModel->rowCount()) {
row = thumbsViewer->thumbsViewerModel->rowCount() - 1;
}
thumbsViewer->setCurrentRow(row);
thumbsViewer->selectThumbByRow(row);
}
}
QString stateString = QString((Settings::isCopyOperation ? tr("Copied") : tr("Moved")) + " " +
tr("%n image(s)", "", copyMoveDialog->nFiles));
setStatus(stateString);
delete (copyMoveDialog);
}
thumbsViewer->loadVisibleThumbs();
}
void Phototonic::selectCurrentViewDir() {
QModelIndex idx = fileSystemTree->fileSystemModel->index(Settings::currentDirectory);
if (idx.isValid()) {
fileSystemTree->setCurrentIndex(idx);
}
}
void Phototonic::checkDirState(const QModelIndex &, int, int) {
if (!initComplete) {
return;
}
if (thumbsViewer->isBusy) {
thumbsViewer->abort();
}
if (!QDir().exists(Settings::currentDirectory)) {
Settings::currentDirectory.clear();
QTimer::singleShot(0, this, SLOT(onReloadThumbs()));
}
}
void Phototonic::addPathHistoryRecord(QString dir) {
if (!needHistoryRecord) {
needHistoryRecord = true;
return;
}
if (pathHistoryList.size() && dir == pathHistoryList.at(currentHistoryIdx)) {
return;
}
pathHistoryList.insert(++currentHistoryIdx, dir);
// Need to clear irrelevant items from list
if (currentHistoryIdx != pathHistoryList.size() - 1) {
goFrwdAction->setEnabled(false);
for (int i = pathHistoryList.size() - 1; i > currentHistoryIdx; --i) {
pathHistoryList.removeAt(i);
}
}
}
void Phototonic::onReloadThumbs() {
if (thumbsViewer->isBusy || !initComplete) {
thumbsViewer->abort();
QTimer::singleShot(0, this, SLOT(onReloadThumbs()));
return;
}
if (!Settings::isFileListLoaded) {
if (Settings::currentDirectory.isEmpty()) {
Settings::currentDirectory = getSelectedPath();
if (Settings::currentDirectory.isEmpty()) {
return;
}
}
QDir checkPath(Settings::currentDirectory);
if (!checkPath.exists() || !checkPath.isReadable()) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to open directory ") + Settings::currentDirectory);
setStatus(tr("No directory selected"));
return;
}
thumbsViewer->infoView->clear();
thumbsViewer->imagePreview->clear();
if (Settings::setWindowIcon && Settings::layoutMode == Phototonic::ThumbViewWidget) {
setWindowIcon(defaultApplicationIcon);
}
pathLineEdit->setText(Settings::currentDirectory);
addPathHistoryRecord(Settings::currentDirectory);
if (currentHistoryIdx > 0) {
goBackAction->setEnabled(true);
}
}
if (Settings::layoutMode == ThumbViewWidget) {
setThumbsViewerWindowTitle();
}
thumbsViewer->reLoad();
}
void Phototonic::setThumbsViewerWindowTitle() {
if (Settings::isFileListLoaded) {
setWindowTitle(tr("Files List") + " - Phototonic");
} else {
setWindowTitle(Settings::currentDirectory + " - Phototonic");
}
}
void Phototonic::renameDir() {
QModelIndexList selectedDirs = fileSystemTree->selectionModel()->selectedRows();
QFileInfo dirInfo = QFileInfo(fileSystemTree->fileSystemModel->filePath(selectedDirs[0]));
bool renameOk;
QString title = tr("Rename") + " " + dirInfo.completeBaseName();
QString newDirName = QInputDialog::getText(this, title,
tr("New name:"), QLineEdit::Normal, dirInfo.completeBaseName(),
&renameOk);
if (!renameOk) {
selectCurrentViewDir();
return;
}
if (newDirName.isEmpty()) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Invalid name entered."));
selectCurrentViewDir();
return;
}
QFile dir(dirInfo.absoluteFilePath());
QString newFullPathName = dirInfo.absolutePath() + QDir::separator() + newDirName;
renameOk = dir.rename(newFullPathName);
if (!renameOk) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to rename directory."));
selectCurrentViewDir();
return;
}
if (Settings::currentDirectory == dirInfo.absoluteFilePath()) {
fileSystemTree->setCurrentIndex(fileSystemTree->fileSystemModel->index(newFullPathName));
} else {
selectCurrentViewDir();
}
}
void Phototonic::rename() {
if (QApplication::focusWidget() == fileSystemTree) {
renameDir();
return;
}
if (Settings::layoutMode == ImageViewWidget) {
if (imageViewer->isNewImage()) {
showNewImageWarning();
return;
}
if (thumbsViewer->thumbsViewerModel->rowCount() > 0) {
if (thumbsViewer->setCurrentIndexByName(imageViewer->viewerImageFullPath))
thumbsViewer->selectCurrentIndex();
}
}
QString selectedImageFileName = thumbsViewer->getSingleSelectionFilename();
if (selectedImageFileName.isEmpty()) {
setStatus(tr("Invalid selection"));
return;
}
if (Settings::slideShowActive) {
toggleSlideShow();
}
imageViewer->setCursorHiding(false);
QFile currentFileFullPath(selectedImageFileName);
QFileInfo currentFileInfo(currentFileFullPath);
int renameConfirmed;
RenameDialog *renameDialog = new RenameDialog(this);
renameDialog->setModal(true);
renameDialog->setFileName(currentFileInfo.fileName());
renameConfirmed = renameDialog->exec();
QString newFileName = renameDialog->getFileName();
delete (renameDialog);
if (renameConfirmed && newFileName.isEmpty()) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("No name entered."));
renameConfirmed = 0;
}
if (renameConfirmed) {
QString newFileNameFullPath = currentFileInfo.absolutePath() + QDir::separator() + newFileName;
if (currentFileFullPath.rename(newFileNameFullPath)) {
QModelIndexList indexesList = thumbsViewer->selectionModel()->selectedIndexes();
thumbsViewer->thumbsViewerModel->item(indexesList.first().row())->setData(newFileNameFullPath,
thumbsViewer->FileNameRole);
thumbsViewer->thumbsViewerModel->item(indexesList.first().row())->setData(newFileName, Qt::DisplayRole);
imageViewer->setInfo(newFileName);
imageViewer->viewerImageFullPath = newFileNameFullPath;
if (Settings::filesList.contains(currentFileInfo.absoluteFilePath())) {
Settings::filesList.replace(Settings::filesList.indexOf(currentFileInfo.absoluteFilePath()),
newFileNameFullPath);
}
if (Settings::layoutMode == ImageViewWidget) {
thumbsViewer->setImageViewerWindowTitle();
}
} else {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to rename image."));
}
}
if (isFullScreen()) {
imageViewer->setCursorHiding(true);
}
}
void Phototonic::removeMetadata() {
QModelIndexList indexList = thumbsViewer->selectionModel()->selectedIndexes();
QStringList fileList;
copyCutThumbsCount = indexList.size();
for (int thumb = 0; thumb < copyCutThumbsCount; ++thumb) {
fileList.append(thumbsViewer->thumbsViewerModel->item(indexList[thumb].
row())->data(thumbsViewer->FileNameRole).toString());
}
if (fileList.isEmpty()) {
setStatus(tr("Invalid selection"));
return;
}
if (Settings::slideShowActive) {
toggleSlideShow();
}
MessageBox msgBox(this);
msgBox.setText(tr("Permanently remove all Exif metadata from selected images?"));
msgBox.setWindowTitle(tr("Remove Metadata"));
msgBox.setIcon(MessageBox::Warning);
msgBox.setStandardButtons(MessageBox::Yes | MessageBox::Cancel);
msgBox.setDefaultButton(MessageBox::Cancel);
msgBox.setButtonText(MessageBox::Yes, tr("Remove Metadata"));
msgBox.setButtonText(MessageBox::Cancel, tr("Cancel"));
int ret = msgBox.exec();
if (ret == MessageBox::Yes) {
for (int file = 0; file < fileList.size(); ++file) {
Exiv2::Image::AutoPtr image;
try {
image = Exiv2::ImageFactory::open(fileList[file].toStdString());
image->clearMetadata();
image->writeMetadata();
metadataCache->removeImage(fileList[file]);
}
catch (Exiv2::Error &error) {
msgBox.critical(tr("Error"), tr("Failed to remove Exif metadata."));
return;
}
}
QItemSelection dummy;
thumbsViewer->onSelectionChanged(dummy);
QString state = QString(tr("Metadata removed from selected images"));
setStatus(state);
}
}
void Phototonic::deleteDirectory(bool trash) {
bool removeDirectoryOk;
QModelIndexList selectedDirs = fileSystemTree->selectionModel()->selectedRows();
QString deletePath = fileSystemTree->fileSystemModel->filePath(selectedDirs[0]);
QModelIndex idxAbove = fileSystemTree->indexAbove(selectedDirs[0]);
QFileInfo dirInfo = QFileInfo(deletePath);
QString question = (trash ? tr("Move directory %1 to the trash?") : tr(
"Permanently delete the directory %1 and all of its contents?")).arg(
dirInfo.completeBaseName());
MessageBox msgBox(this);
msgBox.setText(question);
msgBox.setWindowTitle(tr("Delete directory"));
msgBox.setIcon(MessageBox::Warning);
msgBox.setStandardButtons(MessageBox::Yes | MessageBox::Cancel);
msgBox.setDefaultButton(MessageBox::Cancel);
msgBox.setButtonText(MessageBox::Yes, trash ? tr("OK") : tr("Delete Directory"));
msgBox.setButtonText(MessageBox::Cancel, tr("Cancel"));
int ret = msgBox.exec();
QString trashError;
if (ret == MessageBox::Yes) {
if (trash) {
removeDirectoryOk = Trash::moveToTrash(deletePath, trashError) == Trash::Success;
} else {
removeDirectoryOk = removeDirectoryOperation(deletePath);
}
} else {
selectCurrentViewDir();
return;
}
if (!removeDirectoryOk) {
msgBox.critical(tr("Error"), trash ? tr("Failed to move directory to the trash: %1").arg(trashError)
: tr("Failed to delete directory."));
selectCurrentViewDir();
return;
}
QString state = QString(tr("Removed \"%1\"").arg(deletePath));
setStatus(state);
if (Settings::currentDirectory == deletePath) {
if (idxAbove.isValid()) {
fileSystemTree->setCurrentIndex(idxAbove);
}
} else {
selectCurrentViewDir();
}
}
void Phototonic::createSubDirectory() {
QModelIndexList selectedDirs = fileSystemTree->selectionModel()->selectedRows();
QFileInfo dirInfo = QFileInfo(fileSystemTree->fileSystemModel->filePath(selectedDirs[0]));
bool ok;
QString newDirName = QInputDialog::getText(this, tr("New Sub directory"),
tr("New directory name:"), QLineEdit::Normal, "", &ok);
if (!ok) {
selectCurrentViewDir();
return;
}
if (newDirName.isEmpty()) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Invalid name entered."));
selectCurrentViewDir();
return;
}
QDir dir(dirInfo.absoluteFilePath());
ok = dir.mkdir(dirInfo.absoluteFilePath() + QDir::separator() + newDirName);
if (!ok) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to create new directory."));
selectCurrentViewDir();
return;
}
setStatus(tr("Created %1").arg(newDirName));
fileSystemTree->expand(selectedDirs[0]);
}
QString Phototonic::getSelectedPath() {
QModelIndexList selectedDirs = fileSystemTree->selectionModel()->selectedRows();
if (selectedDirs.size() && selectedDirs[0].isValid()) {
QFileInfo dirInfo = QFileInfo(fileSystemTree->fileSystemModel->filePath(selectedDirs[0]));
return dirInfo.absoluteFilePath();
} else
return "";
}
void Phototonic::wheelEvent(QWheelEvent *event) {
if (Settings::layoutMode == ImageViewWidget) {
if (event->modifiers() == Qt::ControlModifier) {
if (event->delta() < 0) {
zoomOut();
} else {
zoomIn();
}
} else if (nextImageAction->isEnabled()) {
if (event->delta() < 0) {
loadNextImage();
} else {
loadPreviousImage();
}
}
event->accept();
} else if (event->modifiers() == Qt::ControlModifier && QApplication::focusWidget() == thumbsViewer) {
if (event->delta() < 0) {
thumbsZoomOut();
} else {
thumbsZoomIn();
}
}
}
void Phototonic::showNewImageWarning() {
MessageBox msgBox(this);
msgBox.warning(tr("Warning"), tr("Cannot perform action with temporary image."));
}
bool Phototonic::removeDirectoryOperation(QString dirToDelete) {
bool removeDirOk;
QDir dir(dirToDelete);
Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden |
QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
if (info.isDir()) {
removeDirOk = removeDirectoryOperation(info.absoluteFilePath());
} else {
removeDirOk = QFile::remove(info.absoluteFilePath());
}
if (!removeDirOk) {
return removeDirOk;
}
}
removeDirOk = dir.rmdir(dirToDelete);
return removeDirOk;
}
void Phototonic::cleanupCropDialog() {
setInterfaceEnabled(true);
}
void Phototonic::cleanupResizeDialog() {
delete resizeDialog;
resizeDialog = 0;
setInterfaceEnabled(true);
}
void Phototonic::cleanupColorsDialog() {
Settings::colorsActive = false;
setInterfaceEnabled(true);
}
void Phototonic::setInterfaceEnabled(bool enable) {
// actions
colorsAction->setEnabled(enable);
renameAction->setEnabled(enable);
removeMetadataAction->setEnabled(enable);
cropAction->setEnabled(enable);
resizeAction->setEnabled(enable);
CloseImageAction->setEnabled(enable);
nextImageAction->setEnabled(enable);
prevImageAction->setEnabled(enable);
firstImageAction->setEnabled(enable);
lastImageAction->setEnabled(enable);
randomImageAction->setEnabled(enable);
slideShowAction->setEnabled(enable);
copyToAction->setEnabled(enable);
moveToAction->setEnabled(enable);
deleteAction->setEnabled(enable);
deletePermanentlyAction->setEnabled(enable);
settingsAction->setEnabled(enable);
viewImageAction->setEnabled(enable);
// other
thumbsViewer->setEnabled(enable);
fileSystemTree->setEnabled(enable);
bookmarks->setEnabled(enable);
thumbsViewer->imageTags->setEnabled(enable);
menuBar()->setEnabled(enable);
editToolBar->setEnabled(enable);
goToolBar->setEnabled(enable);
viewToolBar->setEnabled(enable);
interfaceDisabled = !enable;
if (enable) {
if (isFullScreen()) {
imageViewer->setCursorHiding(true);
}
} else {
imageViewer->setCursorHiding(false);
}
}
void Phototonic::addNewBookmark() {
addBookmark(getSelectedPath());
}
void Phototonic::addBookmark(QString path) {
Settings::bookmarkPaths.insert(path);
bookmarks->reloadBookmarks();
}
phototonic-2.1/Phototonic.h 0000664 0000000 0000000 00000024617 13251276421 0016056 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2015 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef PHOTOTONIC_H
#define PHOTOTONIC_H
#include
#include "ImageViewer.h"
#include "ThumbsViewer.h"
#include "SettingsDialog.h"
#include "CopyMoveToDialog.h"
#include "CropDialog.h"
#include "ColorsDialog.h"
#include "ResizeDialog.h"
#include "FileListWidget.h"
#include "FileSystemTree.h"
#include
#define VERSION "Phototonic v2.1"
class Phototonic : public QMainWindow {
Q_OBJECT
public:
int copyCutThumbsCount;
Phototonic(QStringList argumentsList, int filesStartAt, QWidget *parent = 0);
QMenu *createPopupMenu();
void setStatus(QString state);
void showBusyAnimation(bool busy);
QIcon &getDefaultWindowIcon();
enum CentralWidgets {
ThumbViewWidget = 0,
ImageViewWidget
};
protected:
void mouseDoubleClickEvent(QMouseEvent *event);
void closeEvent(QCloseEvent *event);
void mousePressEvent(QMouseEvent *event);
public slots:
bool event(QEvent *event);
void dropOp(Qt::KeyboardModifiers keyMods, bool dirOp, QString copyMoveDirPath);
void showViewer();
void loadSelectedThumbImage(const QModelIndex &idx);
void loadImageFromCliArguments(QString cliFileName);
void hideViewer();
private slots:
void about();
void sortThumbnails();
void reload();
void setIncludeSubDirs();
void showSettings();
void toggleFullScreen();
void updateActions();
void onReloadThumbs();
void renameDir();
void setThumbsViewerWindowTitle();
void rename();
void removeMetadata();
void viewImage();
void newImage();
void addNewBookmark();
void deleteDirectory(bool trash);
void createSubDirectory();
void checkDirState(const QModelIndex &, int, int);
void goSelectedDir(const QModelIndex &currDir);
void bookmarkClicked(QTreeWidgetItem *item, int col);
void goPathBarDir();
void setThumbsFilter();
void clearThumbsFilter();
void goBack();
void goTo(QString path);
void goForward();
void goUp();
void goHome();
void toggleSlideShow();
void slideShowHandler();
void loadNextImage();
void loadPreviousImage();
void loadFirstImage();
void loadLastImage();
void loadRandomImage();
void updateIndexByViewerImage();
void selectAllThumbs();
void deleteOperation();
void deletePermanentlyOperation();
void cutThumbs();
void copyThumbs();
void pasteThumbs();
void thumbsZoomIn();
void thumbsZoomOut();
void zoomIn();
void zoomOut();
void resetZoom();
void origZoom();
void keepZoom();
void keepTransformClicked();
void rotateLeft();
void rotateRight();
void flipVertical();
void cropImage();
void scaleImage();
void freeRotateLeft();
void freeRotateRight();
void showColorsDialog();
void setMirrorDisabled();
void setMirrorDual();
void setMirrorTriple();
void setMirrorVDual();
void setMirrorQuad();
void flipHorizontal();
void moveRight();
void moveLeft();
void moveUp();
void moveDown();
void setDocksVisibility(bool visible);
void goTop();
void goBottom();
void showHiddenFiles();
void toggleImageViewerToolbar();
void setToolbarIconSize();
void chooseExternalApp();
void updateExternalApps();
void runExternalApp();
void cleanupSender();
void externalAppError();
void setEditToolBarVisibility();
void setGoToolBarVisibility();
void setViewToolBarVisibility();
void setImageToolBarVisibility();
void setFileSystemDockVisibility();
void setBookmarksDockVisibility();
void setImagePreviewDockVisibility();
void setTagsDockVisibility();
void setImageInfoDockVisibility();
void lockDocks();
void cleanupCropDialog();
void cleanupResizeDialog();
void cleanupColorsDialog();
void filterImagesFocus();
void setPathFocus();
void copyImagesTo();
void moveImagesTo();
void onFileListSelected();
private:
QMenu *fileMenu;
QMenu *editMenu;
QMenu *goMenu;
QMenu *sortMenu;
QMenu *viewMenu;
QMenu *helpMenu;
QMenu *zoomSubMenu;
QMenu *transformSubMenu;
QMenu *viewSubMenu;
QMenu *MirroringSubMenu;
QMenu *openWithSubMenu;
QToolBar *viewToolBar;
QToolBar *editToolBar;
QToolBar *goToolBar;
QToolBar *imageToolBar;
QAction *exitAction;
QAction *cutAction;
QAction *copyAction;
QAction *copyToAction;
QAction *moveToAction;
QAction *deleteAction;
QAction *deletePermanentlyAction;
QAction *saveAction;
QAction *saveAsAction;
QAction *renameAction;
QAction *removeMetadataAction;
QAction *selectAllAction;
QAction *copyImageAction;
QAction *pasteImageAction;
QAction *showClipboardAction;
QAction *addBookmarkAction;
QAction *removeBookmarkAction;
QActionGroup *sortTypesGroup;
QAction *sortByNameAction;
QAction *sortByTimeAction;
QAction *sortBySizeAction;
QAction *sortByTypeAction;
QAction *sortReverseAction;
QAction *refreshAction;
QAction *includeSubDirectoriesAction;
QAction *fullScreenAction;
QAction *thumbsGoToTopAction;
QAction *thumbsGoToBottomAction;
QAction *CloseImageAction;
QAction *settingsAction;
QAction *thumbsZoomInAction;
QAction *thumbsZoomOutAction;
QAction *zoomSubMenuAction;
QAction *zoomInAction;
QAction *zoomOutAction;
QAction *resetZoomAction;
QAction *origZoomAction;
QAction *keepZoomAction;
QAction *keepTransformAction;
QAction *transformSubMenuAction;
QAction *viewSubMenuAction;
QAction *rotateLeftAction;
QAction *rotateRightAction;
QAction *flipHorizontalAction;
QAction *flipVerticalAction;
QAction *cropAction;
QAction *cropToSelectionAction;
QAction *resizeAction;
QAction *freeRotateLeftAction;
QAction *freeRotateRightAction;
QAction *colorsAction;
QActionGroup *mirroringActionGroup;
QAction *mirrorSubMenuAction;
QAction *mirrorDisabledAction;
QAction *mirrorDualAction;
QAction *mirrorTripleAction;
QAction *mirrorDualVerticalAction;
QAction *mirrorQuadAction;
QAction *moveLeftAction;
QAction *moveRightAction;
QAction *moveUpAction;
QAction *moveDownAction;
QAction *aboutAction;
QAction *showHiddenFilesAction;
QAction *smallToolbarIconsAction;
QAction *lockDocksAction;
QAction *showViewerToolbarAction;
QAction *pasteAction;
QAction *createDirectoryAction;
QAction *goBackAction;
QAction *goFrwdAction;
QAction *goUpAction;
QAction *goHomeAction;
QAction *slideShowAction;
QAction *nextImageAction;
QAction *prevImageAction;
QAction *firstImageAction;
QAction *lastImageAction;
QAction *randomImageAction;
QAction *viewImageAction;
QAction *filterImagesFocusAction;
QAction *setPathFocusAction;
QAction *openWithMenuAction;
QAction *externalAppsAction;
QAction *invertSelectionAction;
QLineEdit *pathLineEdit;
QLineEdit *filterLineEdit;
QLabel *statusLabel;
QDockWidget *fileSystemDock;
QDockWidget *bookmarksDock;
QDockWidget *imagePreviewDock;
QDockWidget *tagsDock;
FileSystemTree *fileSystemTree;
BookMarks *bookmarks;
QDockWidget *imageInfoDock;
ThumbsViewer *thumbsViewer;
ImageViewer *imageViewer;
QList pathHistoryList;
QTimer *SlideShowTimer;
CopyMoveToDialog *copyMoveToDialog;
QWidget *fileSystemDockOrigWidget;
QWidget *bookmarksDockOrigWidget;
QWidget *imagePreviewDockOrigWidget;
QWidget *tagsDockOrigWidget;
QWidget *imageInfoDockOrigWidget;
QWidget *fileSystemDockEmptyWidget;
QWidget *bookmarksDockEmptyWidget;
QWidget *imagePreviewDockEmptyWidget;
QWidget *tagsDockEmptyWidget;
QWidget *imageInfoDockEmptyWidget;
bool interfaceDisabled;
MetadataCache *metadataCache;
FileListWidget *fileListWidget;
QStackedLayout *stackedLayout;
int currentHistoryIdx;
bool needHistoryRecord;
bool initComplete;
bool needThumbsRefresh;
bool shouldMaximize;
bool editToolBarVisible;
bool goToolBarVisible;
bool viewToolBarVisible;
bool imageToolBarVisible;
QMovie *busyMovie;
QLabel *busyLabel;
ResizeDialog *resizeDialog;
ColorsDialog *colorsDialog;
CropDialog *cropDialog;
QIcon defaultApplicationIcon;
void refreshThumbs(bool noScroll);
void loadShortcuts();
void setupDocks();
void deleteImages(bool trash);
void deleteFromViewer(bool trash);
void loadCurrentImage(int currentRow);
void selectCurrentViewDir();
void processStartupArguments(QStringList argumentsList, int filesStartAt);
void loadStartupFileList(QStringList argumentsList, int filesStartAt);
void addMenuSeparator(QWidget *widget);
void createImageViewer();
void createThumbsViewer();
void createActions();
void createMenus();
void createToolBars();
void createStatusBar();
void createFileSystemDock();
void createBookmarksDock();
void createImagePreviewDock();
void createImageTagsDock();
void writeSettings();
void readSettings();
void addPathHistoryRecord(QString dir);
bool isValidPath(QString &path);
QString getSelectedPath();
void setCopyCutActions(bool setEnabled);
void wheelEvent(QWheelEvent *event);
void copyOrCutThumbs(bool copy);
void showNewImageWarning();
bool removeDirectoryOperation(QString dirToDelete);
void setInterfaceEnabled(bool enable);
void addBookmark(QString path);
void copyOrMoveImages(bool move);
void setViewerKeyEventsEnabled(bool enabled);
};
#endif // PHOTOTONIC_H
phototonic-2.1/ProgressDialog.cpp 0000664 0000000 0000000 00000002752 13251276421 0017203 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "ProgressDialog.h"
ProgressDialog::ProgressDialog(QWidget *parent) : QDialog(parent) {
opLabel = new QLabel("");
abortOp = false;
cancelButton = new QPushButton(tr("Cancel"));
cancelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(cancelButton, SIGNAL(clicked()), this, SLOT(abort()));
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(opLabel);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
buttonsLayout->addWidget(cancelButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
mainLayout->addLayout(buttonsLayout, Qt::AlignRight);
setLayout(mainLayout);
}
void ProgressDialog::abort() {
abortOp = true;
}
phototonic-2.1/ProgressDialog.h 0000664 0000000 0000000 00000002225 13251276421 0016643 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef PROGRESS_DIALOG_H
#define PROGRESS_DIALOG_H
#include
#include
#include
#include "Settings.h"
class ProgressDialog : public QDialog {
Q_OBJECT
public slots:
void abort();
public:
QLabel *opLabel;
bool abortOp;
ProgressDialog(QWidget *parent);
private:
QPushButton *cancelButton;
};
#endif // PROGRESS_DIALOG_H
phototonic-2.1/README.md 0000664 0000000 0000000 00000006347 13251276421 0015036 0 ustar 00root root 0000000 0000000 # Phototonic Image Viewer
[](https://travis-ci.org/oferkv/phototonic)
### About
Phototonic is an image viewer and organizer built with Qt and Exiv2, released under GNU General Public License v3.
### Features
+ Support for common image formats and GIF animation
+ Supports tagging images, and filtering images by tags (IPTC)
+ Browse thumbnails recursively down a folder tree
+ Dynamic thumbnails loading
+ Image transformation and color manipulation
+ Display image information and metadata
+ Does not depend on any desktop environment
### Screenshot
### Updates:
##### 11 Mar 2018 - v2.1
+ Rotate preview by Exif rotation
+ Fixed bug in image filtering
+ Bug fixes for multiple UI issues and actions
+ Add shortcuts for all missing actions
##### 28 Feb 2018 - v2.0
+ Move to Trash
+ File List support
+ Bug fixes
##### 15 Jan 2018
+ Back after a long break
+ Code cleanup and removal of useless features
+ Lots of bug fixes
+ Added Remove Image Metadata action
+ Enhanced keyboard settings
+ Enhanced image info
##### 12 Nov 2015 - v1.7.1
+ Changes to the way layouts are being switched, now faster and more efficient
+ Fixed issue with not reading image tags correctly when exif data was missing from image
+ Added Negate option to image tags filtering
+ Docks can now be nested to create more customized layouts
+ Some enhancements to Tags user experience and icons
+ Fixed issue with limited zoom functionality
+ Better error handling when reading corrupted images
+ New translations added
##### 8 Aug 2015 - v1.6.17
+ Image tags improvements and bug fixes
+ Changes to default key mapping
+ Small fixes to image extensions
+ Fixed issue with thumb label appearing after rename when labels are not displayed
+ Improvements to image feedback
+ Some dialog usability fixes
+ Added Negativity settings per color channel
+ Fixed colors manipulations for images with alpha channel and non animated GIF images
+ Other Bug fixes
[Older updates](HISTORY.md)
##### Optional Dependencies
+ qt5-imageformats (TIFF and TGA support)
+ qt5-svg (SVG support)
##### Quick Build Instructions on Linux
```
$ tar -zxvf phototonic.tar.gz
$ cd phototonic
$ qmake
$ make
$ make install
$ sudo make install
```
##### Building on Windows
Building on Windows is only supported with mingw at the moment (the source code is probably compatible with msvc, but this was not tested yet).
First get the exiv2 library. Binary version is available from http://www.exiv2.org/download.html (download mingw version) or build it manually.
Note that Qt libraries must be built against the same major mingw version as exiv2 is built against (i.e. Qt built with mingw 5 and higher won't be compatible with exiv2 built with mingw 4.9).
Currently exiv2 binary package for mingw is built with mingw 4.9 therefore the latest compatible Qt version available in binary is 5.6.3 (available via Qt Maintenance Tool).
If using the binary package from exiv2 website, unpack the `mingw` directory to the root of the repository (only mingw/lib and mingw/include are essential).
Then build phototonic as usual - via qmake + mingw32-make in the console, or via QtCreator (remember to choose the compatible Qt Kit).
phototonic-2.1/RenameDialog.cpp 0000664 0000000 0000000 00000004373 13251276421 0016607 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include
#include
#include
#include
#include "RenameDialog.h"
RenameDialog::RenameDialog(QWidget *parent) : QDialog(parent) {
setWindowTitle(tr("Rename Image"));
QHBoxLayout *buttonsLayout = new QHBoxLayout;
QPushButton *okButton = new QPushButton(tr("Rename"));
connect(okButton, SIGNAL(clicked()), this, SLOT(ok()));
okButton->setDefault(true);
QPushButton *cancelButton = new QPushButton(tr("Cancel"));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(abort()));
buttonsLayout->addWidget(cancelButton, 1, Qt::AlignRight);
buttonsLayout->addWidget(okButton, 0, Qt::AlignRight);
QHBoxLayout *renameLayout = new QHBoxLayout;
QLabel *label = new QLabel(tr("New name: "));
fileNameLineEdit = new QLineEdit();
fileNameLineEdit->setMinimumWidth(200);
renameLayout->addWidget(label);
renameLayout->addWidget(fileNameLineEdit);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(renameLayout);
mainLayout->addLayout(buttonsLayout);
setLayout(mainLayout);
setWindowIcon(QIcon(":/images/phototonic.png"));
setMinimumWidth(480);
}
void RenameDialog::ok() {
accept();
}
void RenameDialog::abort() {
reject();
}
void RenameDialog::setFileName(QString name) {
fileNameLineEdit->setText(name);
fileNameLineEdit->setSelection(0, name.lastIndexOf("."));
}
QString RenameDialog::getFileName() {
return fileNameLineEdit->text();
}
phototonic-2.1/RenameDialog.h 0000664 0000000 0000000 00000002214 13251276421 0016244 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef RENAME_DIALOG_H
#define RENAME_DIALOG_H
#include
#include
class RenameDialog : public QDialog {
Q_OBJECT
public:
RenameDialog(QWidget *parent);
void setFileName(QString name);
QString getFileName();
public slots:
void ok();
void abort();
private:
QLineEdit *fileNameLineEdit;
};
#endif // RENAME_DIALOG_H phototonic-2.1/ResizeDialog.cpp 0000664 0000000 0000000 00000016066 13251276421 0016643 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include
#include
#include
#include
#include "ImageViewer.h"
#include "ResizeDialog.h"
#include "Settings.h"
ResizeDialog::ResizeDialog(QWidget *parent, ImageViewer *imageViewer) : QDialog(parent) {
setWindowTitle(tr("Scale Image"));
setWindowIcon(QIcon::fromTheme("transform-scale", QIcon(":/images/phototonic.png")));
newWidth = newHeight = 0;
if (Settings::dialogLastX) {
move(Settings::dialogLastX, Settings::dialogLastY);
}
this->imageViewer = imageViewer;
width = lastWidth = imageViewer->getImageWidthPreCropped();
height = lastHeight = imageViewer->getImageHeightPreCropped();
QHBoxLayout *buttonsHbox = new QHBoxLayout;
QPushButton *okButton = new QPushButton(tr("Scale"));
connect(okButton, SIGNAL(clicked()), this, SLOT(ok()));
okButton->setDefault(true);
QPushButton *cancelButton = new QPushButton(tr("Cancel"));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(abort()));
buttonsHbox->addWidget(cancelButton, 1, Qt::AlignRight);
buttonsHbox->addWidget(okButton, 0, Qt::AlignRight);
widthSpinBox = new QSpinBox;
widthSpinBox->setRange(0, width * 10);
widthSpinBox->setValue(width);
connect(widthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(adjustSizes()));
heightSpinBox = new QSpinBox;
heightSpinBox->setRange(0, height * 10);
heightSpinBox->setValue(height);
connect(heightSpinBox, SIGNAL(valueChanged(int)), this, SLOT(adjustSizes()));
QGridLayout *mainGbox = new QGridLayout;
QLabel *origSizeLab = new QLabel(tr("Current size:"));
QString imageSizeStr = QString::number(width) + " x " + QString::number(height);
QLabel *origSizePixelsLab = new QLabel(imageSizeStr);
QLabel *widthLab = new QLabel(tr("New Width:"));
QLabel *heightLab = new QLabel(tr("New Height:"));
QLabel *unitsLab = new QLabel(tr("Units:"));
QLabel *newSizeLab = new QLabel(tr("New size:"));
newSizePixelsLabel = new QLabel(imageSizeStr);
pixelsRadioButton = new QRadioButton(tr("Pixels"));
connect(pixelsRadioButton, SIGNAL(clicked()), this, SLOT(setUnits()));
percentRadioButton = new QRadioButton(tr("Percent"));
connect(percentRadioButton, SIGNAL(clicked()), this, SLOT(setUnits()));
pixelsRadioButton->setChecked(true);
pixelUnits = true;
QCheckBox *lockAspectCb = new QCheckBox(tr("Keep aspect ratio"), this);
lockAspectCb->setChecked(true);
connect(lockAspectCb, SIGNAL(clicked()), this, SLOT(setAspectLock()));
keepAspect = true;
QHBoxLayout *radiosHbox = new QHBoxLayout;
radiosHbox->addStretch(1);
radiosHbox->addWidget(pixelsRadioButton);
radiosHbox->addWidget(percentRadioButton);
mainGbox->addWidget(origSizeLab, 2, 2, 1, 1);
mainGbox->addWidget(origSizePixelsLab, 2, 4, 1, 1);
mainGbox->addWidget(widthLab, 6, 2, 1, 1);
mainGbox->addWidget(heightLab, 7, 2, 1, 1);
mainGbox->addWidget(unitsLab, 3, 2, 1, 1);
mainGbox->addWidget(widthSpinBox, 6, 4, 1, 2);
mainGbox->addWidget(heightSpinBox, 7, 4, 1, 2);
mainGbox->addLayout(radiosHbox, 3, 4, 1, 3);
mainGbox->addWidget(lockAspectCb, 5, 2, 1, 3);
mainGbox->addWidget(newSizeLab, 8, 2, 1, 1);
mainGbox->addWidget(newSizePixelsLabel, 8, 4, 1, 1);
mainGbox->setRowStretch(9, 1);
mainGbox->setColumnStretch(3, 1);
QVBoxLayout *mainVbox = new QVBoxLayout;
mainVbox->addLayout(mainGbox);
mainVbox->addLayout(buttonsHbox);
setLayout(mainVbox);
widthSpinBox->setFocus(Qt::OtherFocusReason);
}
void ResizeDialog::setAspectLock() {
keepAspect = ((QCheckBox *) QObject::sender())->isChecked();
adjustSizes();
}
void ResizeDialog::setUnits() {
int newWidth;
int newHeight;
if (pixelsRadioButton->isChecked() && !pixelUnits) {
newWidth = (width * widthSpinBox->value()) / 100;
newHeight = (height * heightSpinBox->value()) / 100;
widthSpinBox->setRange(0, width * 10);
heightSpinBox->setRange(0, height * 10);
pixelUnits = true;
} else {
newWidth = (100 * widthSpinBox->value()) / width;
newHeight = (100 * heightSpinBox->value()) / height;
widthSpinBox->setRange(0, 100 * 10);
heightSpinBox->setRange(0, 100 * 10);
pixelUnits = false;
}
widthSpinBox->setValue(newWidth);
if (!keepAspect) {
heightSpinBox->setValue(newHeight);
}
}
void ResizeDialog::adjustSizes() {
static bool busy = false;
if (busy) {
return;
}
busy = true;
if (keepAspect) {
if (pixelUnits) {
QSize imageSize(width, height);
if (widthSpinBox->value() > lastWidth || heightSpinBox->value() > lastHeight) {
imageSize.scale(widthSpinBox->value(), heightSpinBox->value(), Qt::KeepAspectRatioByExpanding);
} else {
imageSize.scale(widthSpinBox->value(), heightSpinBox->value(), Qt::KeepAspectRatio);
}
widthSpinBox->setValue(imageSize.width());
heightSpinBox->setValue(imageSize.height());
lastWidth = widthSpinBox->value();
lastHeight = heightSpinBox->value();
newWidth = imageSize.width();
newHeight = imageSize.height();
} else {
if (widthSpinBox->value() != lastWidth) {
heightSpinBox->setValue(widthSpinBox->value());
} else {
widthSpinBox->setValue(heightSpinBox->value());
}
lastWidth = widthSpinBox->value();
lastHeight = heightSpinBox->value();
newWidth = (width * widthSpinBox->value()) / 100;
newHeight = (height * heightSpinBox->value()) / 100;
}
} else {
if (pixelUnits) {
newWidth = widthSpinBox->value();
newHeight = heightSpinBox->value();
} else {
newWidth = (width * widthSpinBox->value()) / 100;
newHeight = (height * heightSpinBox->value()) / 100;
}
}
newSizePixelsLabel->setText(QString::number(newWidth) + " x " + QString::number(newHeight));
busy = false;
}
void ResizeDialog::ok() {
if (newWidth || newHeight) {
Settings::scaledWidth = newWidth;
Settings::scaledHeight = newHeight;
imageViewer->refresh();
}
accept();
}
void ResizeDialog::abort() {
reject();
}
phototonic-2.1/ResizeDialog.h 0000664 0000000 0000000 00000002676 13251276421 0016312 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef RESIZE_DIALOG_H
#define RESIZE_DIALOG_H
#include "ImageViewer.h"
class ResizeDialog : public QDialog {
Q_OBJECT
public:
ResizeDialog(QWidget *parent, ImageViewer *imageViewer);
public slots:
void ok();
void abort();
void setAspectLock();
void setUnits();
void adjustSizes();
private:
int width;
int height;
int lastWidth;
int lastHeight;
bool keepAspect;
bool pixelUnits;
int newWidth;
int newHeight;
QSpinBox *widthSpinBox;
QSpinBox *heightSpinBox;
QRadioButton *pixelsRadioButton;
QRadioButton *percentRadioButton;
QLabel *newSizePixelsLabel;
ImageViewer *imageViewer;
};
#endif // RESIZE_DIALOG_H phototonic-2.1/Settings.cpp 0000664 0000000 0000000 00000013120 13251276421 0016046 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "Settings.h"
namespace Settings {
const char optionThumbsSortFlags[] = "optionThumbsSortFlags";
const char optionThumbsZoomLevel[] = "optionThumbsZoomLevel";
const char optionFullScreenMode[] = "optionFullScreenMode";
const char optionViewerBackgroundColor[] = "optionViewerBackgroundColor";
const char optionThumbsBackgroundColor[] = "optionThumbsBackgroundColor";
const char optionThumbsTextColor[] = "optionThumbsTextColor";
const char optionThumbsPagesReadCount[] = "optionThumbsPagesReadCount";
const char optionViewerZoomOutFlags[] = "optionViewerZoomOutFlags";
const char optionViewerZoomInFlags[] = "optionViewerZoomInFlags";
const char optionShowImageName[] = "optionShowImageName";
const char optionEnableAnimations[] = "enableAnimations";
const char optionWrapImageList[] = "wrapImageList";
const char optionExifRotationEnabled[] = "exifRotationEnabled";
const char optionExifThumbRotationEnabled[] = "exifThumbRotationEnabled";
const char optionReverseMouseBehavior[] = "reverseMouseBehavior";
const char optionDeleteConfirm[] = "deleteConfirm";
const char optionShowHiddenFiles[] = "showHiddenFiles";
const char optionImageZoomFactor[] = "imageZoomFactor";
const char optionShouldMaximize[] = "shouldMaximize";
const char optionDefaultSaveQuality[] = "defaultSaveQuality";
const char optionSlideShowDelay[] = "slideShowDelay";
const char optionSlideShowRandom[] = "slideShowRandom";
const char optionEditToolBarVisible[] = "editToolBarVisible";
const char optionGoToolBarVisible[] = "goToolBarVisible";
const char optionViewToolBarVisible[] = "viewToolBarVisible";
const char optionImageToolBarVisible[] = "imageToolBarVisible";
const char optionFileSystemDockVisible[] = "fileSystemDockVisible";
const char optionBookmarksDockVisible[] = "bookmarksDockVisible";
const char optionImagePreviewDockVisible[] = "imagePreviewDockVisible";
const char optionTagsDockVisible[] = "tagsDockVisible";
const char optionImageInfoDockVisible[] = "imageInfoDockVisible";
const char optionSmallToolbarIcons[] = "smallToolbarIcons";
const char optionHideDockTitlebars[] = "hideDockTitlebars";
const char optionStartupDir[] = "startupDir";
const char optionSpecifiedStartDir[] = "specifiedStartDir";
const char optionThumbsBackgroundImage[] = "thumbsBackgroundImage";
const char optionShowViewerToolbar[] = "showViewerToolbar";
const char optionLastDir[] = "lastDir";
const char optionGeometry[] = "Geometry";
const char optionWindowState[] = "WindowState";
const char optionShortcuts[] = "Shortcuts";
const char optionExternalApps[] = "ExternalApps";
const char optionCopyMoveToPaths[] = "CopyMoveToPaths";
const char optionKnownTags[] = "KnownTags";
const char optionSetWindowIcon[] = "setWindowIcon";
QSettings *appSettings;
unsigned int layoutMode;
unsigned int zoomInFlags;
unsigned int zoomOutFlags;
QColor viewerBackgroundColor;
QColor thumbsBackgroundColor;
QColor thumbsTextColor;
unsigned int thumbsPagesReadCount;
bool wrapImageList;
bool enableAnimations;
float imageZoomFactor;
bool keepZoomFactor;
int rotation;
bool keepTransform;
bool flipH;
bool flipV;
int scaledWidth;
int scaledHeight;
int defaultSaveQuality;
int cropLeft;
int cropTop;
int cropWidth;
int cropHeight;
int cropLeftPercent;
int cropTopPercent;
int cropWidthPercent;
int cropHeightPercent;
int slideShowDelay;
bool slideShowRandom;
bool slideShowActive;
QMap actionKeys;
int hueVal;
int saturationVal;
int lightnessVal;
int contrastVal;
int brightVal;
int redVal;
int greenVal;
int blueVal;
bool colorsActive;
bool colorizeEnabled;
bool rNegateEnabled;
bool gNegateEnabled;
bool bNegateEnabled;
bool hueRedChannel;
bool hueGreenChannel;
bool hueBlueChannel;
bool exifRotationEnabled;
bool exifThumbRotationEnabled;
bool includeSubDirectories;
bool showHiddenFiles;
bool showViewerToolbar;
QMap externalApps;
QSet bookmarkPaths;
QSet knownTags;
bool reverseMouseBehavior;
bool deleteConfirm;
QModelIndexList copyCutIndexList;
bool isCopyOperation;
QStringList copyCutFileList;
bool isFullScreen;
int dialogLastX;
int dialogLastY;
StartupDir startupDir;
QString specifiedStartDir;
bool showImageName;
bool smallToolbarIcons;
bool hideDockTitlebars;
bool tagsDockVisible;
bool fileSystemDockVisible;
bool bookmarksDockVisible;
bool imagePreviewDockVisible;
bool imageInfoDockVisible;
QString currentDirectory;
QString thumbsBackgroundImage;
QStringList filesList;
bool isFileListLoaded;
bool setWindowIcon;
}
phototonic-2.1/Settings.h 0000664 0000000 0000000 00000013377 13251276421 0015531 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#define THUMB_SIZE_MIN 25
#define THUMB_SIZE_MAX 450
#include
#include
#include
#include
#include
#include
namespace Settings {
enum StartupDir {
RememberLastDir = 0,
DefaultDir,
SpecifiedDir
};
extern const char optionThumbsSortFlags[];
extern const char optionThumbsZoomLevel[];
extern const char optionFullScreenMode[];
extern const char optionViewerBackgroundColor[];
extern const char optionThumbsBackgroundColor[];
extern const char optionThumbsTextColor[];
extern const char optionThumbsPagesReadCount[];
extern const char optionViewerZoomOutFlags[];
extern const char optionViewerZoomInFlags[];
extern const char optionShowImageName[];
extern const char optionEnableAnimations[];
extern const char optionWrapImageList[];
extern const char optionExifRotationEnabled[];
extern const char optionExifThumbRotationEnabled[];
extern const char optionReverseMouseBehavior[];
extern const char optionDeleteConfirm[];
extern const char optionShowHiddenFiles[];
extern const char optionImageZoomFactor[];
extern const char optionShouldMaximize[];
extern const char optionDefaultSaveQuality[];
extern const char optionSlideShowDelay[];
extern const char optionSlideShowRandom[];
extern const char optionEditToolBarVisible[];
extern const char optionGoToolBarVisible[];
extern const char optionViewToolBarVisible[];
extern const char optionImageToolBarVisible[];
extern const char optionFileSystemDockVisible[];
extern const char optionBookmarksDockVisible[];
extern const char optionImagePreviewDockVisible[];
extern const char optionTagsDockVisible[];
extern const char optionImageInfoDockVisible[];
extern const char optionSmallToolbarIcons[];
extern const char optionHideDockTitlebars[];
extern const char optionStartupDir[];
extern const char optionSpecifiedStartDir[];
extern const char optionThumbsBackgroundImage[];
extern const char optionShowViewerToolbar[];
extern const char optionLastDir[];
extern const char optionGeometry[];
extern const char optionWindowState[];
extern const char optionShortcuts[];
extern const char optionExternalApps[];
extern const char optionCopyMoveToPaths[];
extern const char optionKnownTags[];
extern const char optionSetWindowIcon[];
extern QSettings *appSettings;
extern unsigned int layoutMode;
extern unsigned int zoomInFlags;
extern unsigned int zoomOutFlags;
extern QColor viewerBackgroundColor;
extern QColor thumbsBackgroundColor;
extern QColor thumbsTextColor;
extern unsigned int thumbsPagesReadCount;
extern bool wrapImageList;
extern bool enableAnimations;
extern float imageZoomFactor;
extern bool keepZoomFactor;
extern int rotation;
extern bool keepTransform;
extern bool flipH;
extern bool flipV;
extern int scaledWidth;
extern int scaledHeight;
extern int defaultSaveQuality;
extern int cropLeft;
extern int cropTop;
extern int cropWidth;
extern int cropHeight;
extern int cropLeftPercent;
extern int cropTopPercent;
extern int cropWidthPercent;
extern int cropHeightPercent;
extern int slideShowDelay;
extern bool slideShowRandom;
extern bool slideShowActive;
extern QMap actionKeys;
extern int hueVal;
extern int saturationVal;
extern int lightnessVal;
extern int contrastVal;
extern int brightVal;
extern int redVal;
extern int greenVal;
extern int blueVal;
extern bool colorsActive;
extern bool colorizeEnabled;
extern bool rNegateEnabled;
extern bool gNegateEnabled;
extern bool bNegateEnabled;
extern bool hueRedChannel;
extern bool hueGreenChannel;
extern bool hueBlueChannel;
extern bool exifRotationEnabled;
extern bool exifThumbRotationEnabled;
extern bool includeSubDirectories;
extern bool showHiddenFiles;
extern bool showViewerToolbar;
extern QMap externalApps;
extern QSet bookmarkPaths;
extern QSet knownTags;
extern bool reverseMouseBehavior;
extern bool deleteConfirm;
extern QModelIndexList copyCutIndexList;
extern bool isCopyOperation;
extern QStringList copyCutFileList;
extern bool isFullScreen;
extern int dialogLastX;
extern int dialogLastY;
extern StartupDir startupDir;
extern QString specifiedStartDir;
extern bool showImageName;
extern bool smallToolbarIcons;
extern bool hideDockTitlebars;
extern bool fileSystemDockVisible;
extern bool bookmarksDockVisible;
extern bool imagePreviewDockVisible;
extern bool tagsDockVisible;
extern bool imageInfoDockVisible;
extern QString currentDirectory;
extern QString thumbsBackgroundImage;
extern QStringList filesList;
extern bool isFileListLoaded;
extern bool setWindowIcon;
}
#endif // SETTINGS_H
phototonic-2.1/SettingsDialog.cpp 0000664 0000000 0000000 00000045332 13251276421 0017200 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "SettingsDialog.h"
SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent) {
setWindowTitle(tr("Preferences"));
setWindowIcon(QIcon::fromTheme("preferences-system", QIcon(":/images/phototonic.png")));
// Zoom large images
QGroupBox *fitLargeGroupBox = new QGroupBox(tr("Fit Large Images"));
fitLargeRadios[0] = new QRadioButton(tr("Disable"));
fitLargeRadios[1] = new QRadioButton(tr("By width or height"));
fitLargeRadios[2] = new QRadioButton(tr("By width"));
fitLargeRadios[3] = new QRadioButton(tr("By height"));
fitLargeRadios[4] = new QRadioButton(tr("Stretch disproportionately"));
QVBoxLayout *fitLargeVbox = new QVBoxLayout;
for (int i = 0; i < nZoomRadios; ++i) {
fitLargeVbox->addWidget(fitLargeRadios[i]);
fitLargeRadios[i]->setChecked(false);
}
fitLargeVbox->addStretch(1);
fitLargeGroupBox->setLayout(fitLargeVbox);
fitLargeRadios[Settings::zoomOutFlags]->setChecked(true);
// Zoom small images
QGroupBox *fitSmallGroupBox = new QGroupBox(tr("Fit Small Images"));
fitSmallRadios[0] = new QRadioButton(tr("Disable"));
fitSmallRadios[1] = new QRadioButton(tr("By width or height"));
fitSmallRadios[2] = new QRadioButton(tr("By width"));
fitSmallRadios[3] = new QRadioButton(tr("By height"));
fitSmallRadios[4] = new QRadioButton(tr("Stretch disproportionately"));
QVBoxLayout *fitSmallVbox = new QVBoxLayout;
for (int i = 0; i < nZoomRadios; ++i) {
fitSmallVbox->addWidget(fitSmallRadios[i]);
fitSmallRadios[i]->setChecked(false);
}
fitSmallVbox->addStretch(1);
fitSmallGroupBox->setLayout(fitSmallVbox);
fitSmallRadios[Settings::zoomInFlags]->setChecked(true);
// imageViewer background color
QLabel *backgroundColorLabel = new QLabel(tr("Background color:"));
backgroundColorButton = new QToolButton();
backgroundColorButton->setFixedSize(48, 24);
QHBoxLayout *backgroundColorHBox = new QHBoxLayout;
backgroundColorHBox->addWidget(backgroundColorLabel);
backgroundColorHBox->addWidget(backgroundColorButton);
backgroundColorHBox->addStretch(1);
connect(backgroundColorButton, SIGNAL(clicked()), this, SLOT(pickColor()));
setButtonBgColor(Settings::viewerBackgroundColor, backgroundColorButton);
backgroundColorButton->setAutoFillBackground(true);
imageViewerBackgroundColor = Settings::viewerBackgroundColor;
// Wrap image list
wrapListCheckBox = new QCheckBox(tr("Wrap image list when reaching last or first image"), this);
wrapListCheckBox->setChecked(Settings::wrapImageList);
// Save quality
QLabel *saveQualityLabel = new QLabel(tr("Default quality when saving:"));
saveQualitySpinBox = new QSpinBox;
saveQualitySpinBox->setRange(0, 100);
saveQualitySpinBox->setValue(Settings::defaultSaveQuality);
QHBoxLayout *saveQualityHbox = new QHBoxLayout;
saveQualityHbox->addWidget(saveQualityLabel);
saveQualityHbox->addWidget(saveQualitySpinBox);
saveQualityHbox->addStretch(1);
// Enable animations
enableAnimCheckBox = new QCheckBox(tr("Enable GIF animation"), this);
enableAnimCheckBox->setChecked(Settings::enableAnimations);
// Enable image Exif rotation
enableExifCheckBox = new QCheckBox(tr("Rotate image according to Exif orientation value"), this);
enableExifCheckBox->setChecked(Settings::exifRotationEnabled);
// Image name
showImageNameCheckBox = new QCheckBox(tr("Show image file name in viewer"), this);
showImageNameCheckBox->setChecked(Settings::showImageName);
// Viewer options
QVBoxLayout *viewerOptsBox = new QVBoxLayout;
QHBoxLayout *zoomOptsBox = new QHBoxLayout;
zoomOptsBox->setAlignment(Qt::AlignTop);
zoomOptsBox->addWidget(fitLargeGroupBox);
zoomOptsBox->addWidget(fitSmallGroupBox);
zoomOptsBox->addStretch(1);
viewerOptsBox->addLayout(zoomOptsBox);
viewerOptsBox->addLayout(backgroundColorHBox);
viewerOptsBox->addWidget(enableExifCheckBox);
viewerOptsBox->addWidget(showImageNameCheckBox);
viewerOptsBox->addWidget(wrapListCheckBox);
viewerOptsBox->addWidget(enableAnimCheckBox);
viewerOptsBox->addLayout(saveQualityHbox);
viewerOptsBox->addStretch(1);
// thumbsViewer background color
QLabel *thumbsBackgroundColorLabel = new QLabel(tr("Thumbnails and Preview Background Color:"));
thumbsColorPickerButton = new QToolButton();
thumbsColorPickerButton->setFixedSize(48, 24);
QHBoxLayout *thumbsBackgroundColorLayout = new QHBoxLayout;
thumbsBackgroundColorLayout->addWidget(thumbsBackgroundColorLabel);
thumbsBackgroundColorLayout->addWidget(thumbsColorPickerButton);
thumbsBackgroundColorLayout->addStretch(1);
connect(thumbsColorPickerButton, SIGNAL(clicked()), this, SLOT(pickThumbsColor()));
setButtonBgColor(Settings::thumbsBackgroundColor, thumbsColorPickerButton);
thumbsColorPickerButton->setAutoFillBackground(true);
thumbsBackgroundColor = Settings::thumbsBackgroundColor;
// thumbsViewer text color
QLabel *thumbLabelColorLabel = new QLabel(tr("Label color:"));
thumbsLabelColorButton = new QToolButton();
thumbsLabelColorButton->setFixedSize(48, 24);
QHBoxLayout *thumbsLabelColorLayout = new QHBoxLayout;
thumbsLabelColorLayout->addWidget(thumbLabelColorLabel);
thumbsLabelColorLayout->addWidget(thumbsLabelColorButton);
thumbsLabelColorLayout->addStretch(1);
connect(thumbsLabelColorButton, SIGNAL(clicked()), this, SLOT(pickThumbsTextColor()));
setButtonBgColor(Settings::thumbsTextColor, thumbsLabelColorButton);
thumbsLabelColorButton->setAutoFillBackground(true);
thumbsTextColor = Settings::thumbsTextColor;
// thumbsViewer background image
QLabel *thumbsBackgroundImageLabel = new QLabel(tr("Background image:"));
thumbsBackgroundImageLineEdit = new QLineEdit;
thumbsBackgroundImageLineEdit->setClearButtonEnabled(true);
thumbsBackgroundImageLineEdit->setMinimumWidth(200);
QToolButton *chooseThumbsBackImageButton = new QToolButton();
chooseThumbsBackImageButton->setIcon(QIcon::fromTheme("document-open", QIcon(":/images/open.png")));
chooseThumbsBackImageButton->setFixedSize(26, 26);
chooseThumbsBackImageButton->setIconSize(QSize(16, 16));
connect(chooseThumbsBackImageButton, SIGNAL(clicked()), this, SLOT(pickBackgroundImage()));
QHBoxLayout *thumbsBackgroundImageLayout = new QHBoxLayout;
thumbsBackgroundImageLayout->addWidget(thumbsBackgroundImageLabel);
thumbsBackgroundImageLayout->addWidget(thumbsBackgroundImageLineEdit);
thumbsBackgroundImageLayout->addWidget(chooseThumbsBackImageButton);
thumbsBackgroundImageLayout->addStretch(1);
thumbsBackgroundImageLineEdit->setText(Settings::thumbsBackgroundImage);
// Thumbnail pages to read ahead
QLabel *thumbsPagesReadLabel = new QLabel(tr("Number of thumbnail pages to read ahead:"));
thumbPagesSpinBox = new QSpinBox;
thumbPagesSpinBox->setRange(1, 10);
thumbPagesSpinBox->setValue(Settings::thumbsPagesReadCount);
QHBoxLayout *thumbPagesReadLayout = new QHBoxLayout;
thumbPagesReadLayout->addWidget(thumbsPagesReadLabel);
thumbPagesReadLayout->addWidget(thumbPagesSpinBox);
thumbPagesReadLayout->addStretch(1);
enableThumbExifCheckBox = new QCheckBox(tr("Rotate thumbnail according to Exif orientation value"), this);
enableThumbExifCheckBox->setChecked(Settings::exifThumbRotationEnabled);
// Thumbnail options
QVBoxLayout *thumbsOptsBox = new QVBoxLayout;
thumbsOptsBox->addLayout(thumbsBackgroundColorLayout);
thumbsOptsBox->addLayout(thumbsBackgroundImageLayout);
thumbsOptsBox->addLayout(thumbsLabelColorLayout);
thumbsOptsBox->addWidget(enableThumbExifCheckBox);
thumbsOptsBox->addLayout(thumbPagesReadLayout);
thumbsOptsBox->addStretch(1);
// Mouse settings
reverseMouseCheckBox = new QCheckBox(tr("Swap mouse double-click and middle-click actions"), this);
reverseMouseCheckBox->setChecked(Settings::reverseMouseBehavior);
// Delete confirmation setting
deleteConfirmCheckBox = new QCheckBox(tr("Delete confirmation"), this);
deleteConfirmCheckBox->setChecked(Settings::deleteConfirm);
// Startup directory
QGroupBox *startupDirGroupBox = new QGroupBox(tr("Startup directory if not specified by command line"));
startupDirectoryRadioButtons[Settings::RememberLastDir] = new QRadioButton(tr("Remember last"));
startupDirectoryRadioButtons[Settings::DefaultDir] = new QRadioButton(tr("Default"));
startupDirectoryRadioButtons[Settings::SpecifiedDir] = new QRadioButton(tr("Specify:"));
startupDirLineEdit = new QLineEdit;
startupDirLineEdit->setClearButtonEnabled(true);
startupDirLineEdit->setMinimumWidth(300);
startupDirLineEdit->setMaximumWidth(400);
QToolButton *chooseStartupDirButton = new QToolButton();
chooseStartupDirButton->setIcon(QIcon::fromTheme("document-open", QIcon(":/images/open.png")));
chooseStartupDirButton->setFixedSize(26, 26);
chooseStartupDirButton->setIconSize(QSize(16, 16));
connect(chooseStartupDirButton, SIGNAL(clicked()), this, SLOT(pickStartupDir()));
QHBoxLayout *startupDirectoryLayout = new QHBoxLayout;
startupDirectoryLayout->addWidget(startupDirectoryRadioButtons[2]);
startupDirectoryLayout->addWidget(startupDirLineEdit);
startupDirectoryLayout->addWidget(chooseStartupDirButton);
startupDirectoryLayout->addStretch(1);
QVBoxLayout *startupDirectoryMainLayout = new QVBoxLayout;
for (int i = 0; i < 2; ++i) {
startupDirectoryMainLayout->addWidget(startupDirectoryRadioButtons[i]);
startupDirectoryRadioButtons[i]->setChecked(false);
}
startupDirectoryMainLayout->addLayout(startupDirectoryLayout);
startupDirectoryMainLayout->addStretch(1);
startupDirGroupBox->setLayout(startupDirectoryMainLayout);
if (Settings::startupDir == Settings::SpecifiedDir) {
startupDirectoryRadioButtons[Settings::SpecifiedDir]->setChecked(true);
} else if (Settings::startupDir == Settings::RememberLastDir) {
startupDirectoryRadioButtons[Settings::RememberLastDir]->setChecked(true);
} else {
startupDirectoryRadioButtons[Settings::DefaultDir]->setChecked(true);
}
startupDirLineEdit->setText(Settings::specifiedStartDir);
// Keyboard shortcuts
ShortcutsTable *shortcutsTable = new ShortcutsTable();
shortcutsTable->refreshShortcuts();
QGroupBox *keyboardGroupBox = new QGroupBox(tr("Keyboard"));
QVBoxLayout *keyboardSettingsLayout = new QVBoxLayout;
QHBoxLayout *filterShortcutsLayout = new QHBoxLayout;
QLineEdit *shortcutsFilterLineEdit = new QLineEdit;
shortcutsFilterLineEdit->setClearButtonEnabled(true);
shortcutsFilterLineEdit->setPlaceholderText(tr("Filter Items"));
connect(shortcutsFilterLineEdit, SIGNAL(textChanged(
const QString&)), shortcutsTable, SLOT(setFilter(
const QString&)));
keyboardSettingsLayout->addWidget(new QLabel(tr("Select an entry and press a key to set a new shortcut")));
keyboardSettingsLayout->addWidget(shortcutsFilterLineEdit);
keyboardSettingsLayout->addWidget(shortcutsTable);
keyboardSettingsLayout->addLayout(filterShortcutsLayout);
keyboardGroupBox->setLayout(keyboardSettingsLayout);
// Set window icon
setWindowIconCheckBox = new QCheckBox(tr("Set the application icon according to the current image"), this);
setWindowIconCheckBox->setChecked(Settings::setWindowIcon);
QVBoxLayout *generalSettingsLayout = new QVBoxLayout;
generalSettingsLayout->addWidget(reverseMouseCheckBox);
generalSettingsLayout->addWidget(deleteConfirmCheckBox);
generalSettingsLayout->addWidget(startupDirGroupBox);
// Slide show delay
QLabel *slideDelayLab = new QLabel(tr("Delay between slides in seconds:"));
slideDelaySpinBox = new QSpinBox;
slideDelaySpinBox->setRange(1, 3600);
slideDelaySpinBox->setValue(Settings::slideShowDelay);
QHBoxLayout *slideDelayLayout = new QHBoxLayout;
slideDelayLayout->addWidget(slideDelayLab);
slideDelayLayout->addWidget(slideDelaySpinBox);
slideDelayLayout->addStretch(1);
// Slide show random
slideRandomCheckBox = new QCheckBox(tr("Show random images"), this);
slideRandomCheckBox->setChecked(Settings::slideShowRandom);
// Slide show options
QVBoxLayout *slideshowLayout = new QVBoxLayout;
slideshowLayout->addLayout(slideDelayLayout);
slideshowLayout->addWidget(slideRandomCheckBox);
slideshowLayout->addStretch(1);
QGroupBox *slideshowGroupBox = new QGroupBox(tr("Slide Show"));
slideshowGroupBox->setLayout(slideshowLayout);
generalSettingsLayout->addWidget(slideshowGroupBox);
generalSettingsLayout->addWidget(setWindowIconCheckBox);
generalSettingsLayout->addStretch(1);
/* Confirmation buttons */
QHBoxLayout *confirmSettingsLayout = new QHBoxLayout;
QPushButton *okButton = new QPushButton(tr("OK"));
okButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(okButton, SIGNAL(clicked()), this, SLOT(saveSettings()));
okButton->setDefault(true);
QPushButton *closeButton = new QPushButton(tr("Cancel"));
closeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(closeButton, SIGNAL(clicked()), this, SLOT(abort()));
confirmSettingsLayout->addWidget(closeButton, 1, Qt::AlignRight);
confirmSettingsLayout->addWidget(okButton, 0, Qt::AlignRight);
/* Tabs */
QTabWidget *settingsTabs = new QTabWidget;
QWidget *viewerSettings = new QWidget;
viewerSettings->setLayout(viewerOptsBox);
settingsTabs->addTab(viewerSettings, tr("Viewer"));
QWidget *thumbSettings = new QWidget;
thumbSettings->setLayout(thumbsOptsBox);
settingsTabs->addTab(thumbSettings, tr("Thumbnails"));
QWidget *generalSettings = new QWidget;
generalSettings->setLayout(generalSettingsLayout);
settingsTabs->addTab(generalSettings, tr("General"));
QWidget *keyboardSettings = new QWidget;
keyboardSettings->setLayout(keyboardSettingsLayout);
settingsTabs->addTab(keyboardSettings, tr("Keyboard"));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(settingsTabs);
mainLayout->addLayout(confirmSettingsLayout);
setLayout(mainLayout);
}
void SettingsDialog::saveSettings() {
unsigned int i;
for (i = 0; i < nZoomRadios; ++i) {
if (fitLargeRadios[i]->isChecked()) {
Settings::zoomOutFlags = i;
Settings::appSettings->setValue(Settings::optionViewerZoomOutFlags, (int) Settings::zoomOutFlags);
break;
}
}
for (i = 0; i < nZoomRadios; ++i) {
if (fitSmallRadios[i]->isChecked()) {
Settings::zoomInFlags = i;
Settings::appSettings->setValue(Settings::optionViewerZoomInFlags, (int) Settings::zoomInFlags);
break;
}
}
Settings::viewerBackgroundColor = imageViewerBackgroundColor;
Settings::thumbsBackgroundColor = thumbsBackgroundColor;
Settings::thumbsTextColor = thumbsTextColor;
Settings::thumbsBackgroundImage = thumbsBackgroundImageLineEdit->text();
Settings::thumbsPagesReadCount = (unsigned int) thumbPagesSpinBox->value();
Settings::wrapImageList = wrapListCheckBox->isChecked();
Settings::defaultSaveQuality = saveQualitySpinBox->value();
Settings::slideShowDelay = slideDelaySpinBox->value();
Settings::slideShowRandom = slideRandomCheckBox->isChecked();
Settings::enableAnimations = enableAnimCheckBox->isChecked();
Settings::exifRotationEnabled = enableExifCheckBox->isChecked();
Settings::exifThumbRotationEnabled = enableThumbExifCheckBox->isChecked();
Settings::showImageName = showImageNameCheckBox->isChecked();
Settings::reverseMouseBehavior = reverseMouseCheckBox->isChecked();
Settings::deleteConfirm = deleteConfirmCheckBox->isChecked();
Settings::setWindowIcon = setWindowIconCheckBox->isChecked();
if (startupDirectoryRadioButtons[Settings::RememberLastDir]->isChecked()) {
Settings::startupDir = Settings::RememberLastDir;
} else if (startupDirectoryRadioButtons[Settings::DefaultDir]->isChecked()) {
Settings::startupDir = Settings::DefaultDir;
} else {
Settings::startupDir = Settings::SpecifiedDir;
Settings::specifiedStartDir = startupDirLineEdit->text();
}
accept();
}
void SettingsDialog::abort() {
reject();
}
void SettingsDialog::pickColor() {
QColor userColor = QColorDialog::getColor(Settings::viewerBackgroundColor, this);
if (userColor.isValid()) {
setButtonBgColor(userColor, backgroundColorButton);
imageViewerBackgroundColor = userColor;
}
}
void SettingsDialog::setButtonBgColor(QColor &color, QToolButton *button) {
QString style = "background: rgb(%1, %2, %3);";
style = style.arg(color.red()).arg(color.green()).arg(color.blue());
button->setStyleSheet(style);
}
void SettingsDialog::pickThumbsColor() {
QColor userColor = QColorDialog::getColor(Settings::thumbsBackgroundColor, this);
if (userColor.isValid()) {
setButtonBgColor(userColor, thumbsColorPickerButton);
thumbsBackgroundColor = userColor;
}
}
void SettingsDialog::pickThumbsTextColor() {
QColor userColor = QColorDialog::getColor(Settings::thumbsTextColor, this);
if (userColor.isValid()) {
setButtonBgColor(userColor, thumbsLabelColorButton);
thumbsTextColor = userColor;
}
}
void SettingsDialog::pickStartupDir() {
QString dirName = QFileDialog::getExistingDirectory(this, tr("Choose Startup Directory"), "",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
startupDirLineEdit->setText(dirName);
}
void SettingsDialog::pickBackgroundImage() {
QString dirName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
tr("Images") +
" (*.jpg *.jpeg *.jpe *.png *.bmp *.tiff *.tif *.ppm *.xbm *.xpm)");
thumbsBackgroundImageLineEdit->setText(dirName);
}
phototonic-2.1/SettingsDialog.h 0000664 0000000 0000000 00000004311 13251276421 0016635 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef SETTINGS_DIALOG_H
#define SETTINGS_DIALOG_H
#include
#include "Settings.h"
#include "ShortcutsTable.h"
class SettingsDialog : public QDialog {
Q_OBJECT
public:
static int const nZoomRadios = 5;
SettingsDialog(QWidget *parent);
private slots:
void pickColor();
void pickThumbsColor();
void pickThumbsTextColor();
void pickStartupDir();
void pickBackgroundImage();
public slots:
void abort();
void saveSettings();
private:
QRadioButton *fitLargeRadios[nZoomRadios];
QRadioButton *fitSmallRadios[nZoomRadios];
QToolButton *backgroundColorButton;
QToolButton *thumbsColorPickerButton;
QToolButton *thumbsLabelColorButton;
QSpinBox *thumbPagesSpinBox;
QSpinBox *saveQualitySpinBox;
QColor imageViewerBackgroundColor;
QColor thumbsBackgroundColor;
QColor thumbsTextColor;
QCheckBox *wrapListCheckBox;
QCheckBox *enableAnimCheckBox;
QCheckBox *enableExifCheckBox;
QCheckBox *enableThumbExifCheckBox;
QCheckBox *showImageNameCheckBox;
QCheckBox *reverseMouseCheckBox;
QCheckBox *deleteConfirmCheckBox;
QSpinBox *slideDelaySpinBox;
QCheckBox *slideRandomCheckBox;
QRadioButton *startupDirectoryRadioButtons[3];
QLineEdit *startupDirLineEdit;
QLineEdit *thumbsBackgroundImageLineEdit;
QCheckBox *setWindowIconCheckBox;
void setButtonBgColor(QColor &color, QToolButton *button);
};
#endif // SETTINGS_DIALOG_H
phototonic-2.1/ShortcutsTable.cpp 0000664 0000000 0000000 00000014145 13251276421 0017224 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "ShortcutsTable.h"
#include "Settings.h"
#include "MessageBox.h"
ShortcutsTable::ShortcutsTable() {
keysModel = new QStandardItemModel();
setModel(keysModel);
setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::SingleSelection);
setEditTriggers(QAbstractItemView::NoEditTriggers);
verticalHeader()->hide();
verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
verticalHeader()->setDefaultSectionSize(verticalHeader()->minimumSectionSize());
horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
horizontalHeader()->setHighlightSections(false);
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
setColumnHidden(2, true);
shortcutsMenu = new QMenu("");
clearAction = new QAction(tr("Delete shortcut"), this);
connect(clearAction, SIGNAL(triggered()), this, SLOT(clearSelectedShortcut()));
shortcutsMenu->addAction(clearAction);
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showShortcutPopupMenu(QPoint)));
shortcutsFilter.clear();
}
void ShortcutsTable::addRow(QString action, QString description, QString shortcut) {
keysModel->appendRow(QList() << new QStandardItem(description)
<< new QStandardItem(shortcut)
<< new QStandardItem(action));
}
void ShortcutsTable::keyPressEvent(QKeyEvent *keyEvent) {
if (!this->selectedIndexes().count()) {
return;
}
QString keySequenceText;
QString keyText("");
QString modifierText("");
if (keyEvent->modifiers() & Qt::ShiftModifier)
modifierText += "Shift+";
if (keyEvent->modifiers() & Qt::ControlModifier)
modifierText += "Ctrl+";
if (keyEvent->modifiers() & Qt::AltModifier)
modifierText += "Alt+";
if ((keyEvent->key() >= Qt::Key_Shift && keyEvent->key() <= Qt::Key_ScrollLock)
|| (keyEvent->key() >= Qt::Key_Super_L && keyEvent->key() <= Qt::Key_Direction_R)
|| keyEvent->key() == Qt::Key_AltGr
|| keyEvent->key() < 0) {
return;
}
keyText = QKeySequence(keyEvent->key()).toString();
keySequenceText = modifierText + keyText;
if ((keyEvent->modifiers() & Qt::AltModifier) &&
(keyEvent->key() > Qt::Key_0 && keyEvent->key() <= Qt::Key_Colon)) {
MessageBox msgBox(this);
msgBox.warning(tr("Set shortcut"), tr("%1 is reserved for launching external applications.").arg(keySequenceText));
return;
}
QMapIterator keysIterator(Settings::actionKeys);
bool needToRefreshShortCuts = false;
while (keysIterator.hasNext()) {
keysIterator.next();
QAction tmpAction(this);
tmpAction.setShortcut(keySequenceText);
if (keysIterator.value()->shortcut().toString() == tmpAction.shortcut().toString()) {
if (!confirmOverwriteShortcut(keysIterator.value()->text(), keySequenceText)) {
return;
}
Settings::actionKeys.value(keysIterator.key())->setShortcut(QKeySequence());
needToRefreshShortCuts = true;
}
}
int row = selectedIndexes().first().row();
keysModel->item(row, 1)->setText(keySequenceText);
Settings::actionKeys.value(keysModel->item(row, 2)->text())->setShortcut(QKeySequence(keySequenceText));
if (needToRefreshShortCuts) {
refreshShortcuts();
}
}
bool ShortcutsTable::confirmOverwriteShortcut(QString action, QString shortcut) {
MessageBox msgBox(this);
msgBox.setText(tr("%1 is already assigned to %2, reassign shortcut?").arg(shortcut).arg(action));
msgBox.setWindowTitle(tr("Overwrite Shortcut"));
msgBox.setIcon(MessageBox::Warning);
msgBox.setStandardButtons(MessageBox::Yes | MessageBox::Cancel);
msgBox.setDefaultButton(MessageBox::Cancel);
msgBox.setButtonText(MessageBox::Yes, tr("Yes"));
msgBox.setButtonText(MessageBox::Cancel, tr("Cancel"));
return (msgBox.exec() == MessageBox::Yes);
}
void ShortcutsTable::clearSelectedShortcut() {
if (selectedEntry.isValid()) {
QStandardItemModel *itemsModel = (QStandardItemModel *) model();
itemsModel->item(selectedEntry.row(), 1)->setText("");
Settings::actionKeys.value(itemsModel->item(selectedEntry.row(), 2)->text())->setShortcut(QKeySequence(""));
}
}
void ShortcutsTable::showShortcutPopupMenu(QPoint point) {
selectedEntry = indexAt(point);
if (selectedEntry.isValid())
shortcutsMenu->popup(viewport()->mapToGlobal(point));
}
void ShortcutsTable::setFilter(QString filter) {
this->shortcutsFilter = filter;
refreshShortcuts();
}
void ShortcutsTable::refreshShortcuts() {
keysModel->clear();
keysModel->setHorizontalHeaderItem(0, new QStandardItem(tr("Action")));
keysModel->setHorizontalHeaderItem(1, new QStandardItem(tr("Shortcut")));
QMapIterator it(Settings::actionKeys);
while (it.hasNext()) {
it.next();
if (!shortcutsFilter.isEmpty()
&& !Settings::actionKeys.value(it.key())->text().toLower().contains(shortcutsFilter.toLower())) {
continue;
}
addRow(it.key(), Settings::actionKeys.value(it.key())->text(),
Settings::actionKeys.value(it.key())->shortcut().toString());
}
setColumnHidden(2, true);
}
phototonic-2.1/ShortcutsTable.h 0000664 0000000 0000000 00000002711 13251276421 0016665 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2018 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef SHORTCUTS_TABLE_H
#define SHORTCUTS_TABLE_H
#include
class ShortcutsTable : public QTableView {
Q_OBJECT
public:
ShortcutsTable();
void addRow(QString action, QString description, QString shortcut);
void refreshShortcuts();
public slots:
void setFilter(QString filter);
void showShortcutPopupMenu(QPoint point);
void clearSelectedShortcut();
protected:
void keyPressEvent(QKeyEvent *keyEvent);
private:
bool confirmOverwriteShortcut(QString action, QString shortcut);
QStandardItemModel *keysModel;
QModelIndex selectedEntry;
QMenu *shortcutsMenu;
QAction *clearAction;
QString shortcutsFilter;
};
#endif // SHORTCUTS_TABLE_H
phototonic-2.1/Tags.cpp 0000664 0000000 0000000 00000041643 13251276421 0015157 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2015 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "Tags.h"
#include "Settings.h"
#include "ProgressDialog.h"
#include "MessageBox.h"
ImageTags::ImageTags(QWidget *parent, ThumbsViewer *thumbsViewer, MetadataCache *metadataCache) : QWidget(parent) {
tagsTree = new QTreeWidget;
tagsTree->setColumnCount(2);
tagsTree->setDragEnabled(false);
tagsTree->setSortingEnabled(true);
tagsTree->header()->close();
tagsTree->setSelectionMode(QAbstractItemView::ExtendedSelection);
this->thumbView = thumbsViewer;
this->metadataCache = metadataCache;
negateFilterEnabled = false;
tabs = new QTabBar(this);
tabs->addTab(tr("Selection"));
tabs->addTab(tr("Filter"));
tabs->setTabIcon(0, QIcon(":/images/tag_yellow.png"));
tabs->setTabIcon(1, QIcon(":/images/tag_filter_off.png"));
tabs->setExpanding(false);
connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tabsChanged(int)));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setContentsMargins(0, 3, 0, 0);
mainLayout->setSpacing(0);
mainLayout->addWidget(tabs);
mainLayout->addWidget(tagsTree);
setLayout(mainLayout);
currentDisplayMode = SelectionTagsDisplay;
dirFilteringActive = false;
connect(tagsTree, SIGNAL(itemChanged(QTreeWidgetItem * , int)),
this, SLOT(saveLastChangedTag(QTreeWidgetItem * , int)));
connect(tagsTree, SIGNAL(itemClicked(QTreeWidgetItem * , int)),
this, SLOT(tagClicked(QTreeWidgetItem * , int)));
tagsTree->setContextMenuPolicy(Qt::CustomContextMenu);
connect(tagsTree, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showMenu(QPoint)));
addToSelectionAction = new QAction(tr("Tag"), this);
addToSelectionAction->setIcon(QIcon(":/images/tag_yellow.png"));
connect(addToSelectionAction, SIGNAL(triggered()), this, SLOT(addTagsToSelection()));
removeFromSelectionAction = new QAction(tr("Untag"), this);
connect(removeFromSelectionAction, SIGNAL(triggered()), this, SLOT(removeTagsFromSelection()));
actionAddTag = new QAction(tr("New Tag"), this);
actionAddTag->setIcon(QIcon(":/images/new_tag.png"));
connect(actionAddTag, SIGNAL(triggered()), this, SLOT(addNewTag()));
removeTagAction = new QAction(tr("Delete Tag"), this);
removeTagAction->setIcon(QIcon::fromTheme("edit-delete", QIcon(":/images/delete.png")));
actionClearTagsFilter = new QAction(tr("Clear Filters"), this);
actionClearTagsFilter->setIcon(QIcon(":/images/tag_filter_off.png"));
connect(actionClearTagsFilter, SIGNAL(triggered()), this, SLOT(clearTagFilters()));
negateAction = new QAction(tr("Negate"), this);
negateAction->setCheckable(true);
connect(negateAction, SIGNAL(triggered()), this, SLOT(negateFilter()));
tagsMenu = new QMenu("");
tagsMenu->addAction(addToSelectionAction);
tagsMenu->addAction(removeFromSelectionAction);
tagsMenu->addSeparator();
tagsMenu->addAction(actionAddTag);
tagsMenu->addAction(removeTagAction);
tagsMenu->addSeparator();
tagsMenu->addAction(actionClearTagsFilter);
tagsMenu->addAction(negateAction);
}
void ImageTags::redrawTagTree() {
tagsTree->resizeColumnToContents(0);
tagsTree->sortItems(0, Qt::AscendingOrder);
}
void ImageTags::showMenu(QPoint point) {
QTreeWidgetItem *item = tagsTree->itemAt(point);
addToSelectionAction->setEnabled(item != NULL);
removeFromSelectionAction->setEnabled(item != NULL);
removeTagAction->setEnabled(item != NULL);
tagsMenu->popup(tagsTree->viewport()->mapToGlobal(point));
}
void ImageTags::setTagIcon(QTreeWidgetItem *tagItem, TagIcons icon) {
switch (icon) {
case TagIconDisabled:
tagItem->setIcon(0, QIcon(":/images/tag_grey.png"));
break;
case TagIconEnabled:
tagItem->setIcon(0, QIcon(":/images/tag_yellow.png"));
break;
case TagIconMultiple:
tagItem->setIcon(0, QIcon(":/images/tag_multi.png"));
break;
case TagIconFilterEnabled:
tagItem->setIcon(0, QIcon(":/images/tag_filter_on.png"));
break;
case TagIconFilterDisabled:
tagItem->setIcon(0, QIcon(":/images/tag_filter_off.png"));
break;
case TagIconFilterNegate:
tagItem->setIcon(0, QIcon(":/images/tag_filter_negate.png"));
break;
}
}
void ImageTags::addTag(QString tagName, bool tagChecked) {
QTreeWidgetItem *tagItem = new QTreeWidgetItem();
tagItem->setText(0, tagName);
tagItem->setCheckState(0, tagChecked ? Qt::Checked : Qt::Unchecked);
setTagIcon(tagItem, tagChecked ? TagIconEnabled : TagIconDisabled);
tagsTree->addTopLevelItem(tagItem);
}
bool ImageTags::writeTagsToImage(QString &imageFileName, QSet &newTags) {
QSet imageTags;
Exiv2::Image::AutoPtr exifImage;
try {
exifImage = Exiv2::ImageFactory::open(imageFileName.toStdString());
exifImage->readMetadata();
Exiv2::IptcData newIptcData;
/* copy existing data */
Exiv2::IptcData &iptcData = exifImage->iptcData();
if (!iptcData.empty()) {
QString key;
Exiv2::IptcData::iterator end = iptcData.end();
for (Exiv2::IptcData::iterator iptcIt = iptcData.begin(); iptcIt != end; ++iptcIt) {
if (iptcIt->tagName() != "Keywords") {
newIptcData.add(*iptcIt);
}
}
}
/* add new tags */
QSetIterator newTagsIt(newTags);
while (newTagsIt.hasNext()) {
QString tag = newTagsIt.next();
Exiv2::Value::AutoPtr value = Exiv2::Value::create(Exiv2::string);
value->read(tag.toStdString());
Exiv2::IptcKey key("Iptc.Application2.Keywords");
newIptcData.add(key, value.get());
}
exifImage->setIptcData(newIptcData);
exifImage->writeMetadata();
}
catch (Exiv2::Error &error) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Failed to save tags to ") + imageFileName);
return false;
}
return true;
}
void ImageTags::showSelectedImagesTags() {
static bool busy = false;
if (busy)
return;
busy = true;
QStringList selectedThumbs = thumbView->getSelectedThumbsList();
setActiveViewMode(SelectionTagsDisplay);
int selectedThumbsNum = selectedThumbs.size();
QMap tagsCount;
for (int i = 0; i < selectedThumbsNum; ++i) {
QSetIterator imageTagsIter(metadataCache->getImageTags(selectedThumbs[i]));
while (imageTagsIter.hasNext()) {
QString imageTag = imageTagsIter.next();
tagsCount[imageTag]++;
if (!Settings::knownTags.contains(imageTag)) {
addTag(imageTag, true);
Settings::knownTags.insert(imageTag);
}
}
}
bool imagesTagged = false, imagesTaggedMixed = false;
QTreeWidgetItemIterator it(tagsTree);
while (*it) {
QString tagName = (*it)->text(0);
int tagCountTotal = tagsCount[tagName];
if (selectedThumbsNum == 0) {
(*it)->setCheckState(0, Qt::Unchecked);
(*it)->setFlags((*it)->flags() & ~Qt::ItemIsUserCheckable);
setTagIcon(*it, TagIconDisabled);
} else if (tagCountTotal == selectedThumbsNum) {
(*it)->setCheckState(0, Qt::Checked);
(*it)->setFlags((*it)->flags() | Qt::ItemIsUserCheckable);
setTagIcon(*it, TagIconEnabled);
imagesTagged = true;
} else if (tagCountTotal) {
(*it)->setCheckState(0, Qt::PartiallyChecked);
(*it)->setFlags((*it)->flags() | Qt::ItemIsUserCheckable);
setTagIcon(*it, TagIconMultiple);
imagesTaggedMixed = true;
} else {
(*it)->setCheckState(0, Qt::Unchecked);
(*it)->setFlags((*it)->flags() | Qt::ItemIsUserCheckable);
setTagIcon(*it, TagIconDisabled);
}
++it;
}
if (imagesTagged) {
tabs->setTabIcon(0, QIcon(":/images/tag_yellow.png"));
} else if (imagesTaggedMixed) {
tabs->setTabIcon(0, QIcon(":/images/tag_multi.png"));
} else {
tabs->setTabIcon(0, QIcon(":/images/tag_grey.png"));
}
addToSelectionAction->setEnabled(selectedThumbsNum ? true : false);
removeFromSelectionAction->setEnabled(selectedThumbsNum ? true : false);
redrawTagTree();
busy = false;
}
void ImageTags::showTagsFilter() {
static bool busy = false;
if (busy)
return;
busy = true;
setActiveViewMode(DirectoryTagsDisplay);
QTreeWidgetItemIterator it(tagsTree);
while (*it) {
QString tagName = (*it)->text(0);
(*it)->setFlags((*it)->flags() | Qt::ItemIsUserCheckable);
if (imageFilteringTags.contains(tagName)) {
(*it)->setCheckState(0, Qt::Checked);
setTagIcon(*it, negateFilterEnabled ? TagIconFilterNegate : TagIconFilterEnabled);
} else {
(*it)->setCheckState(0, Qt::Unchecked);
setTagIcon(*it, TagIconFilterDisabled);
}
++it;
}
redrawTagTree();
busy = false;
}
void ImageTags::populateTagsTree() {
tagsTree->clear();
QSetIterator knownTagsIt(Settings::knownTags);
while (knownTagsIt.hasNext()) {
QString tag = knownTagsIt.next();
addTag(tag, false);
}
redrawTagTree();
if (currentDisplayMode == SelectionTagsDisplay) {
showSelectedImagesTags();
} else {
showTagsFilter();
}
}
void ImageTags::setActiveViewMode(TagsDisplayMode mode) {
currentDisplayMode = mode;
actionAddTag->setVisible(currentDisplayMode == SelectionTagsDisplay);
removeTagAction->setVisible(currentDisplayMode == SelectionTagsDisplay);
addToSelectionAction->setVisible(currentDisplayMode == SelectionTagsDisplay);
removeFromSelectionAction->setVisible(currentDisplayMode == SelectionTagsDisplay);
actionClearTagsFilter->setVisible(currentDisplayMode == DirectoryTagsDisplay);
negateAction->setVisible(currentDisplayMode == DirectoryTagsDisplay);
}
bool ImageTags::isImageFilteredOut(QString imageFileName) {
QSet imageTags = metadataCache->getImageTags(imageFileName);
QSetIterator filteredTagsIt(imageFilteringTags);
while (filteredTagsIt.hasNext()) {
if (imageTags.contains(filteredTagsIt.next())) {
return negateFilterEnabled;
}
}
return !negateFilterEnabled;
}
void ImageTags::resetTagsState() {
tagsTree->clear();
metadataCache->clear();
}
QSet ImageTags::getCheckedTags(Qt::CheckState tagState) {
QSet checkedTags;
QTreeWidgetItemIterator it(tagsTree);
while (*it) {
if ((*it)->checkState(0) == tagState) {
checkedTags.insert((*it)->text(0));
}
++it;
}
return checkedTags;
}
void ImageTags::applyTagFiltering() {
imageFilteringTags = getCheckedTags(Qt::Checked);
if (imageFilteringTags.size()) {
dirFilteringActive = true;
if (negateFilterEnabled) {
tabs->setTabIcon(1, QIcon(":/images/tag_filter_negate.png"));
} else {
tabs->setTabIcon(1, QIcon(":/images/tag_filter_on.png"));
}
} else {
dirFilteringActive = false;
tabs->setTabIcon(1, QIcon(":/images/tag_filter_off.png"));
}
emit reloadThumbs();
}
void ImageTags::applyUserAction(QTreeWidgetItem *item) {
QList tagsList;
tagsList << item;
applyUserAction(tagsList);
}
void ImageTags::applyUserAction(QList tagsList) {
int processEventsCounter = 0;
ProgressDialog *progressDialog = new ProgressDialog(this);
progressDialog->show();
QStringList currentSelectedImages = thumbView->getSelectedThumbsList();
for (int currentImage = 0; currentImage < currentSelectedImages.size(); ++currentImage) {
QString imageName = currentSelectedImages[currentImage];
for (int i = tagsList.size() - 1; i > -1; --i) {
Qt::CheckState tagState = tagsList.at(i)->checkState(0);
setTagIcon(tagsList.at(i), (tagState == Qt::Checked ? TagIconEnabled : TagIconDisabled));
QString tagName = tagsList.at(i)->text(0);
if (tagState == Qt::Checked) {
progressDialog->opLabel->setText(tr("Tagging ") + imageName);
metadataCache->addTagToImage(imageName, tagName);
} else {
progressDialog->opLabel->setText(tr("Untagging ") + imageName);
metadataCache->removeTagFromImage(imageName, tagName);
}
}
if (!writeTagsToImage(imageName, metadataCache->getImageTags(imageName))) {
metadataCache->removeImage(imageName);
}
++processEventsCounter;
if (processEventsCounter > 9) {
processEventsCounter = 0;
QApplication::processEvents();
}
if (progressDialog->abortOp) {
break;
}
}
progressDialog->close();
delete (progressDialog);
}
void ImageTags::saveLastChangedTag(QTreeWidgetItem *item, int) {
lastChangedTagItem = item;
}
void ImageTags::tabsChanged(int index) {
if (!index) {
showSelectedImagesTags();
} else {
showTagsFilter();
}
}
void ImageTags::tagClicked(QTreeWidgetItem *item, int) {
if (item == lastChangedTagItem) {
if (currentDisplayMode == DirectoryTagsDisplay) {
applyTagFiltering();
} else {
applyUserAction(item);
}
lastChangedTagItem = 0;
}
}
void ImageTags::removeTagsFromSelection() {
for (int i = tagsTree->selectedItems().size() - 1; i > -1; --i) {
tagsTree->selectedItems().at(i)->setCheckState(0, Qt::Unchecked);
}
applyUserAction(tagsTree->selectedItems());
}
void ImageTags::addTagsToSelection() {
for (int i = tagsTree->selectedItems().size() - 1; i > -1; --i) {
tagsTree->selectedItems().at(i)->setCheckState(0, Qt::Checked);
}
applyUserAction(tagsTree->selectedItems());
}
void ImageTags::clearTagFilters() {
QTreeWidgetItemIterator it(tagsTree);
while (*it) {
(*it)->setCheckState(0, Qt::Unchecked);
++it;
}
imageFilteringTags.clear();
applyTagFiltering();
}
void ImageTags::negateFilter() {
negateFilterEnabled = negateAction->isChecked();
applyTagFiltering();
}
void ImageTags::addNewTag() {
bool ok;
QString title = tr("Add a new tag");
QString newTagName = QInputDialog::getText(this, title, tr("Enter new tag name"),
QLineEdit::Normal, "", &ok);
if (!ok) {
return;
}
if (newTagName.isEmpty()) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("No name entered"));
return;
}
QSetIterator knownTagsIt(Settings::knownTags);
while (knownTagsIt.hasNext()) {
QString tag = knownTagsIt.next();
if (newTagName == tag) {
MessageBox msgBox(this);
msgBox.critical(tr("Error"), tr("Tag ") + newTagName + tr(" already exists"));
return;
}
}
addTag(newTagName, false);
Settings::knownTags.insert(newTagName);
redrawTagTree();
}
void ImageTags::removeTag() {
if (!tagsTree->selectedItems().size()) {
return;
}
MessageBox msgBox(this);
msgBox.setText(tr("Delete selected tags(s)?"));
msgBox.setWindowTitle(tr("Delete tag"));
msgBox.setIcon(MessageBox::Warning);
msgBox.setStandardButtons(MessageBox::Yes | MessageBox::Cancel);
msgBox.setDefaultButton(MessageBox::Cancel);
msgBox.setButtonText(MessageBox::Yes, tr("Yes"));
msgBox.setButtonText(MessageBox::Cancel, tr("Cancel"));
if (msgBox.exec() != MessageBox::Yes) {
return;
}
bool removedTagWasChecked = false;
for (int i = tagsTree->selectedItems().size() - 1; i > -1; --i) {
QString tagName = tagsTree->selectedItems().at(i)->text(0);
Settings::knownTags.remove(tagName);
if (imageFilteringTags.contains(tagName)) {
imageFilteringTags.remove(tagName);
removedTagWasChecked = true;
}
tagsTree->takeTopLevelItem(tagsTree->indexOfTopLevelItem(tagsTree->selectedItems().at(i)));
}
if (removedTagWasChecked) {
applyTagFiltering();
}
}
phototonic-2.1/Tags.h 0000664 0000000 0000000 00000005516 13251276421 0014623 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef TAGS_H
#define TAGS_H
#include
#include
#include "ThumbsViewer.h"
#include "MetadataCache.h"
class ThumbsViewer;
enum TagsDisplayMode {
DirectoryTagsDisplay,
SelectionTagsDisplay
};
enum TagIcons {
TagIconDisabled,
TagIconEnabled,
TagIconMultiple,
TagIconFilterDisabled,
TagIconFilterEnabled,
TagIconFilterNegate
};
class ImageTags : public QWidget {
Q_OBJECT
public:
ImageTags(QWidget *parent, ThumbsViewer *thumbsViewer, MetadataCache *metadataCache);
void addTag(QString tagName, bool tagChecked);
void showTagsFilter();
void showSelectedImagesTags();
void resetTagsState();
bool isImageFilteredOut(QString imagePath);
void removeTag();
void populateTagsTree();
QMenu *tagsMenu;
QTreeWidget *tagsTree;
bool dirFilteringActive;
QAction *removeTagAction;
TagsDisplayMode currentDisplayMode;
private:
bool writeTagsToImage(QString &imageFileName, QSet &tags);
QSet getCheckedTags(Qt::CheckState tagState);
void setTagIcon(QTreeWidgetItem *tagItem, TagIcons icon);
void setActiveViewMode(TagsDisplayMode mode);
void applyUserAction(QTreeWidgetItem *item);
void applyUserAction(QList tagsList);
void redrawTagTree();
QSet imageFilteringTags;
QAction *actionAddTag;
QAction *addToSelectionAction;
QAction *removeFromSelectionAction;
QAction *actionClearTagsFilter;
QAction *negateAction;
QTreeWidgetItem *lastChangedTagItem;
ThumbsViewer *thumbView;
QTabBar *tabs;
MetadataCache *metadataCache;
bool negateFilterEnabled;
private slots:
void tagClicked(QTreeWidgetItem *item, int column);
void saveLastChangedTag(QTreeWidgetItem *item, int column);
void applyTagFiltering();
void showMenu(QPoint point);
void addNewTag();
void addTagsToSelection();
void clearTagFilters();
void negateFilter();
void removeTagsFromSelection();
void tabsChanged(int index);
signals:
void reloadThumbs();
};
#endif // TAGS_H
phototonic-2.1/ThumbsViewer.cpp 0000664 0000000 0000000 00000062067 13251276421 0016710 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013-2014 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include "ThumbsViewer.h"
#include "Phototonic.h"
ThumbsViewer::ThumbsViewer(QWidget *parent, MetadataCache *metadataCache) : QListView(parent) {
this->metadataCache = metadataCache;
Settings::thumbsBackgroundColor = Settings::appSettings->value(
Settings::optionThumbsBackgroundColor).value();
Settings::thumbsTextColor = Settings::appSettings->value(Settings::optionThumbsTextColor).value();
setThumbColors();
Settings::thumbsPagesReadCount = Settings::appSettings->value(Settings::optionThumbsPagesReadCount).toUInt();
thumbSize = Settings::appSettings->value(Settings::optionThumbsZoomLevel).toInt();
currentRow = 0;
setViewMode(QListView::IconMode);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setResizeMode(QListView::Adjust);
setWordWrap(true);
setDragEnabled(true);
setEditTriggers(QAbstractItemView::NoEditTriggers);
setUniformItemSizes(false);
thumbsViewerModel = new QStandardItemModel(this);
thumbsViewerModel->setSortRole(SortRole);
setModel(thumbsViewerModel);
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(loadVisibleThumbs(int)));
connect(this->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
this, SLOT(onSelectionChanged(QItemSelection)));
connect(this, SIGNAL(doubleClicked(
const QModelIndex &)), parent, SLOT(loadSelectedThumbImage(
const QModelIndex &)));
thumbsDir = new QDir();
fileFilters = new QStringList;
emptyImg.load(":/images/no_image.png");
QTime time = QTime::currentTime();
qsrand((uint) time.msec());
phototonic = (Phototonic *) parent;
infoView = new InfoView(this);
connect(infoView, SIGNAL(updateInfo(QItemSelection)), this, SLOT(onSelectionChanged(QItemSelection)));
imagePreview = new ImagePreview(this);
}
void ThumbsViewer::setThumbColors() {
QString backgroundColor = "background: rgb(%1, %2, %3); ";
backgroundColor = backgroundColor.arg(Settings::thumbsBackgroundColor.red())
.arg(Settings::thumbsBackgroundColor.green())
.arg(Settings::thumbsBackgroundColor.blue());
QString styleSheet = "QListView { " + backgroundColor + "background-image: url("
+ Settings::thumbsBackgroundImage
+ "); background-attachment: fixed; }";
setStyleSheet(styleSheet);
QPalette scrollBarOriginalPalette = verticalScrollBar()->palette();
QPalette thumbViewerOriginalPalette = palette();
thumbViewerOriginalPalette.setColor(QPalette::Text, Settings::thumbsTextColor);
setPalette(thumbViewerOriginalPalette);
verticalScrollBar()->setPalette(scrollBarOriginalPalette);
}
void ThumbsViewer::selectCurrentIndex() {
if (currentIndex.isValid() && thumbsViewerModel->rowCount() > 0) {
scrollTo(currentIndex);
setCurrentIndex(currentIndex);
}
}
QString ThumbsViewer::getSingleSelectionFilename() {
if (selectionModel()->selectedIndexes().size() == 1)
return thumbsViewerModel->item(selectionModel()->selectedIndexes().first().row())->data(
FileNameRole).toString();
return ("");
}
int ThumbsViewer::getNextRow() {
if (currentRow == thumbsViewerModel->rowCount() - 1) {
return -1;
}
return currentRow + 1;
}
int ThumbsViewer::getPrevRow() {
if (currentRow == 0) {
return -1;
}
return currentRow - 1;
}
int ThumbsViewer::getLastRow() {
return thumbsViewerModel->rowCount() - 1;
}
int ThumbsViewer::getRandomRow() {
return qrand() % (thumbsViewerModel->rowCount());
}
int ThumbsViewer::getCurrentRow() {
return currentRow;
}
void ThumbsViewer::setCurrentRow(int row) {
if (row >= 0) {
currentRow = row;
} else {
currentRow = 0;
}
}
void ThumbsViewer::setImageViewerWindowTitle() {
QString title = thumbsViewerModel->item(currentRow)->data(Qt::DisplayRole).toString()
+ " - ["
+ QString::number(currentRow + 1)
+ "/"
+ QString::number(thumbsViewerModel->rowCount())
+ "] - Phototonic";
phototonic->setWindowTitle(title);
}
bool ThumbsViewer::setCurrentIndexByName(QString &fileName) {
QModelIndexList indexList = thumbsViewerModel->match(thumbsViewerModel->index(0, 0), FileNameRole, fileName);
if (indexList.size()) {
currentIndex = indexList[0];
setCurrentRow(currentIndex.row());
return true;
}
return false;
}
bool ThumbsViewer::setCurrentIndexByRow(int row) {
QModelIndex idx = thumbsViewerModel->indexFromItem(thumbsViewerModel->item(row));
if (idx.isValid()) {
currentIndex = idx;
setCurrentRow(idx.row());
return true;
}
return false;
}
void ThumbsViewer::updateImageInfoViewer(QString imageFullPath) {
QImageReader imageInfoReader(imageFullPath);
QString key;
QString val;
QFileInfo imageInfo = QFileInfo(imageFullPath);
infoView->addTitleEntry(tr("Image"));
key = tr("File name");
val = imageInfo.fileName();
infoView->addEntry(key, val);
key = tr("Location");
val = imageInfo.path();
infoView->addEntry(key, val);
key = tr("Size");
val = QString::number(imageInfo.size() / 1024.0, 'f', 2) + "K";
infoView->addEntry(key, val);
key = tr("Modified");
val = imageInfo.lastModified().toString(Qt::SystemLocaleShortDate);
infoView->addEntry(key, val);
if (imageInfoReader.size().isValid()) {
key = tr("Format");
val = imageInfoReader.format().toUpper();
infoView->addEntry(key, val);
key = tr("Resolution");
val = QString::number(imageInfoReader.size().width())
+ "x"
+ QString::number(imageInfoReader.size().height());
infoView->addEntry(key, val);
key = tr("Megapixel");
val = QString::number((imageInfoReader.size().width() * imageInfoReader.size().height()) / 1000000.0, 'f',
2);
infoView->addEntry(key, val);
} else {
imageInfoReader.read();
key = tr("Error");
val = imageInfoReader.errorString();
infoView->addEntry(key, val);
}
Exiv2::Image::AutoPtr exifImage;
try {
exifImage = Exiv2::ImageFactory::open(imageFullPath.toStdString());
exifImage->readMetadata();
}
catch (Exiv2::Error &error) {
return;
}
Exiv2::ExifData &exifData = exifImage->exifData();
if (!exifData.empty()) {
Exiv2::ExifData::const_iterator end = exifData.end();
infoView->addTitleEntry("Exif");
for (Exiv2::ExifData::const_iterator md = exifData.begin(); md != end; ++md) {
key = QString::fromUtf8(md->tagName().c_str());
val = QString::fromUtf8(md->print().c_str());
infoView->addEntry(key, val);
}
}
Exiv2::IptcData &iptcData = exifImage->iptcData();
if (!iptcData.empty()) {
Exiv2::IptcData::iterator end = iptcData.end();
infoView->addTitleEntry("IPTC");
for (Exiv2::IptcData::iterator md = iptcData.begin(); md != end; ++md) {
key = QString::fromUtf8(md->tagName().c_str());
val = QString::fromUtf8(md->print().c_str());
infoView->addEntry(key, val);
}
}
Exiv2::XmpData &xmpData = exifImage->xmpData();
if (!xmpData.empty()) {
Exiv2::XmpData::iterator end = xmpData.end();
infoView->addTitleEntry("XMP");
for (Exiv2::XmpData::iterator md = xmpData.begin(); md != end; ++md) {
key = QString::fromUtf8(md->tagName().c_str());
val = QString::fromUtf8(md->print().c_str());
infoView->addEntry(key, val);
}
}
}
void ThumbsViewer::onSelectionChanged(const QItemSelection &) {
infoView->clear();
imagePreview->clear();
if (Settings::setWindowIcon && Settings::layoutMode == Phototonic::ThumbViewWidget) {
phototonic->setWindowIcon(phototonic->getDefaultWindowIcon());
}
QModelIndexList indexesList = selectionModel()->selectedIndexes();
int selectedThumbs = indexesList.size();
if (selectedThumbs == 1) {
int currentRow = indexesList.first().row();
QString thumbFullPath = thumbsViewerModel->item(currentRow)->data(FileNameRole).toString();
setCurrentRow(currentRow);
updateImageInfoViewer(thumbFullPath);
QPixmap imagePreviewPixmap = imagePreview->loadImage(thumbFullPath);
if (Settings::setWindowIcon && Settings::layoutMode == Phototonic::ThumbViewWidget) {
phototonic->setWindowIcon(imagePreviewPixmap.scaled(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE,
Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
}
if (imageTags->currentDisplayMode == SelectionTagsDisplay) {
imageTags->showSelectedImagesTags();
}
if (selectedThumbs >= 1) {
QString statusStr;
statusStr = tr("Selected %1 of %2").arg(QString::number(selectedThumbs))
.arg(tr(" %n image(s)", "", thumbsViewerModel->rowCount()));
phototonic->setStatus(statusStr);
} else if (!selectedThumbs) {
updateThumbsCount();
}
}
QStringList ThumbsViewer::getSelectedThumbsList() {
QModelIndexList indexesList = selectionModel()->selectedIndexes();
QStringList SelectedThumbsPaths;
for (int tn = indexesList.size() - 1; tn >= 0; --tn) {
SelectedThumbsPaths << thumbsViewerModel->item(indexesList[tn].row())->data(FileNameRole).toString();
}
return SelectedThumbsPaths;
}
void ThumbsViewer::startDrag(Qt::DropActions) {
QModelIndexList indexesList = selectionModel()->selectedIndexes();
if (indexesList.isEmpty()) {
return;
}
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QList urls;
for (QModelIndexList::const_iterator it = indexesList.constBegin(),
end = indexesList.constEnd(); it != end; ++it) {
urls << QUrl(thumbsViewerModel->item(it->row())->data(FileNameRole).toString());
}
mimeData->setUrls(urls);
drag->setMimeData(mimeData);
QPixmap pix;
if (indexesList.count() > 1) {
pix = QPixmap(128, 112);
pix.fill(Qt::transparent);
QPainter painter(&pix);
painter.setBrush(Qt::NoBrush);
painter.setPen(QPen(Qt::white, 2));
int x = 0, y = 0, xMax = 0, yMax = 0;
for (int i = 0; i < qMin(5, indexesList.count()); ++i) {
QPixmap pix = thumbsViewerModel->item(indexesList.at(i).row())->icon().pixmap(72);
if (i == 4) {
x = (xMax - pix.width()) / 2;
y = (yMax - pix.height()) / 2;
}
painter.drawPixmap(x, y, pix);
xMax = qMax(xMax, qMin(128, x + pix.width()));
yMax = qMax(yMax, qMin(112, y + pix.height()));
painter.drawRect(x + 1, y + 1, qMin(126, pix.width() - 2), qMin(110, pix.height() - 2));
x = !(x == y) * 56;
y = !y * 40;
}
painter.end();
pix = pix.copy(0, 0, xMax, yMax);
drag->setPixmap(pix);
} else {
pix = thumbsViewerModel->item(indexesList.at(0).row())->icon().pixmap(128);
drag->setPixmap(pix);
}
drag->setHotSpot(QPoint(pix.width() / 2, pix.height() / 2));
drag->exec(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction, Qt::IgnoreAction);
}
void ThumbsViewer::abort() {
isAbortThumbsLoading = true;
}
void ThumbsViewer::loadVisibleThumbs(int scrollBarValue) {
static int lastScrollBarValue = 0;
scrolledForward = (scrollBarValue >= lastScrollBarValue);
lastScrollBarValue = scrollBarValue;
for (;;) {
int firstVisible = getFirstVisibleThumb();
int lastVisible = getLastVisibleThumb();
if (isAbortThumbsLoading || firstVisible < 0 || lastVisible < 0) {
return;
}
if (scrolledForward) {
lastVisible += ((lastVisible - firstVisible) * (Settings::thumbsPagesReadCount + 1));
if (lastVisible >= thumbsViewerModel->rowCount()) {
lastVisible = thumbsViewerModel->rowCount() - 1;
}
} else {
firstVisible -= (lastVisible - firstVisible) * (Settings::thumbsPagesReadCount + 1);
if (firstVisible < 0) {
firstVisible = 0;
}
lastVisible += 10;
if (lastVisible >= thumbsViewerModel->rowCount()) {
lastVisible = thumbsViewerModel->rowCount() - 1;
}
}
if (thumbsRangeFirst == firstVisible && thumbsRangeLast == lastVisible) {
return;
}
thumbsRangeFirst = firstVisible;
thumbsRangeLast = lastVisible;
loadThumbsRange();
if (isAbortThumbsLoading) {
break;
}
}
}
int ThumbsViewer::getFirstVisibleThumb() {
QModelIndex idx;
for (int currThumb = 0; currThumb < thumbsViewerModel->rowCount(); ++currThumb) {
idx = thumbsViewerModel->indexFromItem(thumbsViewerModel->item(currThumb));
if (viewport()->rect().contains(QPoint(0, visualRect(idx).y() + visualRect(idx).height() + 1))) {
return idx.row();
}
}
return -1;
}
int ThumbsViewer::getLastVisibleThumb() {
QModelIndex idx;
for (int currThumb = thumbsViewerModel->rowCount() - 1; currThumb >= 0; --currThumb) {
idx = thumbsViewerModel->indexFromItem(thumbsViewerModel->item(currThumb));
if (viewport()->rect().contains(QPoint(0, visualRect(idx).y() + visualRect(idx).height() + 1))) {
return idx.row();
}
}
return -1;
}
void ThumbsViewer::loadFileList() {
for (int i = 0; i < Settings::filesList.size(); i++) {
addThumb(Settings::filesList[i]);
}
updateThumbsCount();
imageTags->populateTagsTree();
if (thumbFileInfoList.size() && selectionModel()->selectedIndexes().size() == 0) {
selectThumbByRow(0);
}
phototonic->showBusyAnimation(false);
isBusy = false;
}
void ThumbsViewer::reLoad() {
isBusy = true;
phototonic->showBusyAnimation(true);
loadPrepare();
if (Settings::isFileListLoaded) {
loadFileList();
return;
}
applyFilter();
initThumbs();
updateThumbsCount();
loadVisibleThumbs();
if (Settings::includeSubDirectories) {
loadSubDirectories();
}
phototonic->showBusyAnimation(false);
isBusy = false;
}
void ThumbsViewer::loadSubDirectories() {
QDirIterator dirIterator(Settings::currentDirectory, QDirIterator::Subdirectories);
while (dirIterator.hasNext()) {
dirIterator.next();
if (dirIterator.fileInfo().isDir() && dirIterator.fileName() != "." && dirIterator.fileName() != "..") {
thumbsDir->setPath(dirIterator.filePath());
initThumbs();
updateThumbsCount();
loadVisibleThumbs();
if (isAbortThumbsLoading) {
return;
}
}
QApplication::processEvents();
}
QItemSelection dummy;
onSelectionChanged(dummy);
}
void ThumbsViewer::applyFilter() {
fileFilters->clear();
QString textFilter("*");
textFilter += filterString;
*fileFilters << textFilter + "*.bmp"
<< textFilter + "*.cur"
<< textFilter + "*.dds"
<< textFilter + "*.gif"
<< textFilter + "*.icns"
<< textFilter + "*.ico"
<< textFilter + "*.jpeg"
<< textFilter + "*.jpg"
<< textFilter + "*.jp2"
<< textFilter + "*.jpe"
<< textFilter + "*.mng"
<< textFilter + "*.pbm"
<< textFilter + "*.pgm"
<< textFilter + "*.png"
<< textFilter + "*.ppm"
<< textFilter + "*.svg"
<< textFilter + "*.svgz"
<< textFilter + "*.tga"
<< textFilter + "*.tif"
<< textFilter + "*.tiff"
<< textFilter + "*.wbmp"
<< textFilter + "*.webp"
<< textFilter + "*.xbm"
<< textFilter + "*.xpm";
thumbsDir->setNameFilters(*fileFilters);
thumbsDir->setFilter(QDir::Files);
if (Settings::showHiddenFiles) {
thumbsDir->setFilter(thumbsDir->filter() | QDir::Hidden);
}
thumbsDir->setPath(Settings::currentDirectory);
QDir::SortFlags tempThumbsSortFlags = thumbsSortFlags;
if (tempThumbsSortFlags & QDir::Size || tempThumbsSortFlags & QDir::Time) {
tempThumbsSortFlags ^= QDir::Reversed;
}
thumbsDir->setSorting(tempThumbsSortFlags);
}
void ThumbsViewer::loadPrepare() {
thumbsViewerModel->clear();
setIconSize(QSize(thumbSize, thumbSize));
setSpacing(QFontMetrics(font()).height());
if (isNeedToScroll) {
scrollToTop();
}
isAbortThumbsLoading = false;
thumbsRangeFirst = -1;
thumbsRangeLast = -1;
imageTags->resetTagsState();
}
void ThumbsViewer::initThumbs() {
thumbFileInfoList = thumbsDir->entryInfoList();
static QStandardItem *thumbItem;
static int fileIndex;
static QPixmap emptyPixMap;
static QSize hintSize;
int thumbsAddedCounter = 1;
emptyPixMap = QPixmap::fromImage(emptyImg).scaled(thumbSize, thumbSize);
hintSize = QSize(thumbSize, thumbSize + ((int) (QFontMetrics(font()).height() * 1.5)));
for (fileIndex = 0; fileIndex < thumbFileInfoList.size(); ++fileIndex) {
thumbFileInfo = thumbFileInfoList.at(fileIndex);
metadataCache->loadImageMetadata(thumbFileInfo.filePath());
if (imageTags->dirFilteringActive && imageTags->isImageFilteredOut(thumbFileInfo.filePath())) {
continue;
}
thumbItem = new QStandardItem();
thumbItem->setData(false, LoadedRole);
thumbItem->setData(fileIndex, SortRole);
thumbItem->setData(thumbFileInfo.filePath(), FileNameRole);
thumbItem->setTextAlignment(Qt::AlignTop | Qt::AlignHCenter);
thumbItem->setSizeHint(hintSize);
thumbItem->setText(thumbFileInfo.fileName());
thumbsViewerModel->appendRow(thumbItem);
++thumbsAddedCounter;
if (thumbsAddedCounter > 100) {
thumbsAddedCounter = 1;
QApplication::processEvents();
}
}
imageTags->populateTagsTree();
if (thumbFileInfoList.size() && selectionModel()->selectedIndexes().size() == 0) {
selectThumbByRow(0);
}
}
void ThumbsViewer::updateThumbsCount() {
QString state;
if (thumbsViewerModel->rowCount() > 0) {
state = tr("%n image(s)", "", thumbsViewerModel->rowCount());
} else {
state = tr("No images");
}
thumbsDir->setPath(Settings::currentDirectory);
phototonic->setStatus(state);
}
void ThumbsViewer::selectThumbByRow(int row) {
setCurrentIndexByRow(row);
selectCurrentIndex();
}
void ThumbsViewer::loadThumbsRange() {
static bool isInProgress = false;
QImageReader thumbReader;
static QSize currentThumbSize;
static int currentRowCount;
static QString imageFileName;
QImage thumb;
int currThumb;
bool imageReadOk;
if (isInProgress) {
isAbortThumbsLoading = true;
QTimer::singleShot(0, this, SLOT(loadThumbsRange()));
return;
}
isInProgress = true;
currentRowCount = thumbsViewerModel->rowCount();
for (scrolledForward ? currThumb = thumbsRangeFirst : currThumb = thumbsRangeLast;
(scrolledForward ? currThumb <= thumbsRangeLast : currThumb >= thumbsRangeFirst);
scrolledForward ? ++currThumb : --currThumb) {
if (isAbortThumbsLoading || thumbsViewerModel->rowCount() != currentRowCount || currThumb < 0) {
break;
}
if (thumbsViewerModel->item(currThumb)->data(LoadedRole).toBool()) {
continue;
}
imageFileName = thumbsViewerModel->item(currThumb)->data(FileNameRole).toString();
thumbReader.setFileName(imageFileName);
currentThumbSize = thumbReader.size();
imageReadOk = false;
if (currentThumbSize.isValid()) {
if (currentThumbSize.width() > thumbSize || currentThumbSize.height() > thumbSize) {
currentThumbSize.scale(QSize(thumbSize, thumbSize), Qt::KeepAspectRatio);
}
thumbReader.setScaledSize(currentThumbSize);
imageReadOk = thumbReader.read(&thumb);
}
if (imageReadOk) {
if (Settings::exifThumbRotationEnabled) {
imageViewer->rotateByExifRotation(thumb, imageFileName);
currentThumbSize = thumb.size();
currentThumbSize.scale(QSize(thumbSize, thumbSize), Qt::KeepAspectRatio);
}
thumbsViewerModel->item(currThumb)->setIcon(QPixmap::fromImage(thumb));
} else {
thumbsViewerModel->item(currThumb)->setIcon(QIcon::fromTheme("image-missing",
QIcon(":/images/error_image.png")).pixmap(
BAD_IMAGE_SIZE, BAD_IMAGE_SIZE));
currentThumbSize.setHeight(BAD_IMAGE_SIZE);
currentThumbSize.setWidth(BAD_IMAGE_SIZE);
}
thumbsViewerModel->item(currThumb)->setData(true, LoadedRole);
QApplication::processEvents();
}
isInProgress = false;
isAbortThumbsLoading = false;
}
void ThumbsViewer::addThumb(QString &imageFullPath) {
metadataCache->loadImageMetadata(imageFullPath);
if (imageTags->dirFilteringActive && imageTags->isImageFilteredOut(imageFullPath)) {
return;
}
QStandardItem *thumbItem = new QStandardItem();
QImageReader thumbReader;
QSize hintSize;
QSize currThumbSize;
static QImage thumb;
hintSize = QSize(thumbSize, thumbSize + ((int) (QFontMetrics(font()).height() * 1.5)));
thumbFileInfo = QFileInfo(imageFullPath);
thumbItem->setData(true, LoadedRole);
thumbItem->setData(0, SortRole);
thumbItem->setData(thumbFileInfo.filePath(), FileNameRole);
thumbItem->setTextAlignment(Qt::AlignTop | Qt::AlignHCenter);
thumbItem->setData(thumbFileInfo.fileName(), Qt::DisplayRole);
thumbItem->setSizeHint(hintSize);
thumbReader.setFileName(imageFullPath);
currThumbSize = thumbReader.size();
if (currThumbSize.isValid()) {
if (currThumbSize.width() > thumbSize || currThumbSize.height() > thumbSize) {
currThumbSize.scale(QSize(thumbSize, thumbSize), Qt::KeepAspectRatio);
}
thumbReader.setScaledSize(currThumbSize);
thumb = thumbReader.read();
if (Settings::exifThumbRotationEnabled) {
imageViewer->rotateByExifRotation(thumb, imageFullPath);
currThumbSize = thumb.size();
currThumbSize.scale(QSize(thumbSize, thumbSize), Qt::KeepAspectRatio);
}
thumbItem->setIcon(QPixmap::fromImage(thumb));
} else {
thumbItem->setIcon(
QIcon::fromTheme("image-missing", QIcon(":/images/error_image.png")).pixmap(BAD_IMAGE_SIZE,
BAD_IMAGE_SIZE));
currThumbSize.setHeight(BAD_IMAGE_SIZE);
currThumbSize.setWidth(BAD_IMAGE_SIZE);
}
thumbsViewerModel->appendRow(thumbItem);
}
void ThumbsViewer::wheelEvent(QWheelEvent *event) {
if (event->delta() < 0) {
verticalScrollBar()->setValue(verticalScrollBar()->value() + thumbSize);
} else {
verticalScrollBar()->setValue(verticalScrollBar()->value() - thumbSize);
}
}
void ThumbsViewer::mousePressEvent(QMouseEvent *event) {
QListView::mousePressEvent(event);
if (Settings::reverseMouseBehavior && event->button() == Qt::MiddleButton) {
if (selectionModel()->selectedIndexes().size() == 1)
emit(doubleClicked(selectionModel()->selectedIndexes().first()));
}
}
void ThumbsViewer::invertSelection() {
QItemSelection toggleSelection;
QModelIndex firstIndex = thumbsViewerModel->index(0, 0);
QModelIndex lastIndex = thumbsViewerModel->index(thumbsViewerModel->rowCount() - 1, 0);
toggleSelection.select(firstIndex, lastIndex);
selectionModel()->select(toggleSelection, QItemSelectionModel::Toggle);
}
void ThumbsViewer::setNeedToScroll(bool needToScroll) {
this->isNeedToScroll = needToScroll;
}
void ThumbsViewer::setImageViewer(ImageViewer *imageViewer) {
this->imageViewer = imageViewer;
}
phototonic-2.1/ThumbsViewer.h 0000664 0000000 0000000 00000006401 13251276421 0016343 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2013 Ofer Kashayov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef THUMBS_VIEWER_H
#define THUMBS_VIEWER_H
#include
#include
#include "Settings.h"
#include "FileSystemTree.h"
#include "Bookmarks.h"
#include "InfoViewer.h"
#include "Tags.h"
#include "MetadataCache.h"
#include "ImagePreview.h"
class Phototonic;
class ImageViewer;
#define BAD_IMAGE_SIZE 64
#define WINDOW_ICON_SIZE 48
class ImageTags;
class ThumbsViewer : public QListView {
Q_OBJECT
public:
enum UserRoles {
FileNameRole = Qt::UserRole + 1,
SortRole,
LoadedRole
};
ThumbsViewer(QWidget *parent, MetadataCache *metadataCache);
void loadPrepare();
void applyFilter();
void reLoad();
void loadFileList();
void loadSubDirectories();
void setThumbColors();
bool setCurrentIndexByName(QString &fileName);
bool setCurrentIndexByRow(int row);
void setCurrentRow(int row);
void setImageViewerWindowTitle();
void setNeedToScroll(bool needToScroll);
void selectCurrentIndex();
void addThumb(QString &imageFullPath);
void abort();
void selectThumbByRow(int row);
int getNextRow();
int getPrevRow();
int getLastRow();
int getRandomRow();
int getCurrentRow();
QStringList getSelectedThumbsList();
QString getSingleSelectionFilename();
void setImageViewer(ImageViewer *imageViewer);
InfoView *infoView;
ImagePreview *imagePreview;
ImageTags *imageTags;
QDir *thumbsDir;
QStringList *fileFilters;
QStandardItemModel *thumbsViewerModel;
QDir::SortFlags thumbsSortFlags;
int thumbSize;
QString filterString;
bool isBusy;
protected:
void startDrag(Qt::DropActions);
void wheelEvent(QWheelEvent *event);
void mousePressEvent(QMouseEvent *event);
private:
void initThumbs();
int getFirstVisibleThumb();
int getLastVisibleThumb();
void updateThumbsCount();
void updateImageInfoViewer(QString imageFullPath);
QFileInfo thumbFileInfo;
QFileInfoList thumbFileInfoList;
QImage emptyImg;
QModelIndex currentIndex;
Phototonic *phototonic;
MetadataCache *metadataCache;
ImageViewer *imageViewer;
bool isAbortThumbsLoading;
bool isNeedToScroll;
int currentRow;
bool scrolledForward;
int thumbsRangeFirst;
int thumbsRangeLast;
public slots:
void loadVisibleThumbs(int scrollBarValue = 0);
void onSelectionChanged(const QItemSelection &selection);
void invertSelection();
private slots:
void loadThumbsRange();
};
#endif // THUMBS_VIEWER_H
phototonic-2.1/Trashcan.cpp 0000664 0000000 0000000 00000015316 13251276421 0016022 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2018 Roman Chistokhodov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#include
#include "Trashcan.h"
#if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID) && !defined(Q_OS_DARWIN)
// Implementation for freedesktop systems adheres to https://specifications.freedesktop.org/trash-spec/trashspec-latest.html
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static Trash::Result moveToTrashDir(const QString& filePath, const QDir& trashDir, QString& error, const QStorageInfo& nonHomeStorage)
{
const QDir trashInfoDir = QDir(trashDir.filePath("info"));
const QDir trashFilesDir = QDir(trashDir.filePath("files"));
if (trashInfoDir.mkpath(".") && trashFilesDir.mkpath(".")) {
QFileInfo fileInfo(filePath);
QString fileName = fileInfo.fileName();
QString infoFileName = fileName + ".trashinfo";
int fd;
const int flag = O_CREAT | O_WRONLY | O_EXCL;
const int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
for (unsigned int n = 2; trashFilesDir.exists(fileName) ||
((fd = open(trashInfoDir.filePath(infoFileName).toUtf8().data(), flag, mode)) == -1 && errno == EEXIST); ++n) {
fileName = QString("%1.%2.%3").arg(fileInfo.baseName(), QString::number(n), fileInfo.completeSuffix());
infoFileName = fileName + ".trashinfo";
}
if (fd == -1) {
error = strerror(errno);
return Trash::Error;
}
const QString moveHere = trashFilesDir.filePath(fileName);
const QString deletionDate = QDateTime::currentDateTime().toString(Qt::ISODate);
const QString path = nonHomeStorage.isValid() ? QDir(nonHomeStorage.rootPath()).relativeFilePath(filePath) : filePath;
const QString escapedPath = QString::fromUtf8(QUrl::toPercentEncoding(path, "/"));
QFile infoFile;
if (infoFile.open(fd, QIODevice::WriteOnly, QFileDevice::AutoCloseHandle)) {
QTextStream out(&infoFile);
out << "[Trash Info]\nPath=" << escapedPath << "\nDeletionDate=" << deletionDate << '\n';
} else {
error = infoFile.errorString();
return Trash::Error;
}
if (QDir().rename(filePath, moveHere)) {
return Trash::Success;
} else {
error = QString("Could not rename %1 to %2").arg(filePath, moveHere);
return Trash::Error;
}
} else {
error = "Could not set up trash subdirectories";
return Trash::Error;
}
}
Trash::Result Trash::moveToTrash(const QString &path, QString &error, Trash::Options trashOptions)
{
if (path.isEmpty()) {
error = "Path is empty";
return Trash::Error;
}
const QString filePath = QFileInfo(path).absoluteFilePath();
const QStorageInfo filePathStorage(filePath);
if (!filePathStorage.isValid()) {
error = "Could not get device of the file being trashed";
return Trash::Error;
}
const QString homeDataLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
const QDir homeDataDirectory(homeDataLocation);
if (homeDataLocation.isEmpty() || !homeDataDirectory.exists()) {
error = "Could not get home data folder";
return Trash::Error;
}
if (QStorageInfo(homeDataLocation) == filePathStorage || trashOptions == Trash::ForceDeletionToHomeTrash) {
const QDir homeTrashDirectory = QDir(homeDataDirectory.filePath("Trash"));
if (homeTrashDirectory.mkpath(".")) {
return moveToTrashDir(filePath, homeTrashDirectory, error, QStorageInfo());
} else {
error = "Could not ensure that home trash directory exists";
return Trash::Error;
}
} else {
const QDir topdir = QDir(filePathStorage.rootPath());
const QDir topdirTrash = QDir(topdir.filePath(".Trash"));
struct stat trashStat;
if (lstat(topdirTrash.path().toUtf8().data(), &trashStat) == 0) {
// should be a directory, not link, and have sticky bit
if (S_ISDIR(trashStat.st_mode) && !S_ISLNK(trashStat.st_mode) && (trashStat.st_mode & S_ISVTX)) {
const QString subdir = QString::number(getuid());
if (topdirTrash.mkpath(subdir)) {
return moveToTrashDir(filePath, QDir(topdirTrash.filePath(subdir)), error, filePathStorage);
}
}
}
// if we're still here, $topdir/.Trash does not exist or failed some check
QDir topdirUserTrash = QDir(topdir.filePath(QString(".Trash-%1").arg(getuid())));
if (topdirUserTrash.mkpath(".")) {
return moveToTrashDir(filePath, topdirUserTrash, error, filePathStorage);
}
error = "Could not find trash directory for the disk where the file resides";
return Trash::NeedsUserInput;
}
}
#elif defined(Q_OS_WIN)
#include
#include
Trash::Result Trash::moveToTrash(const QString &path, QString &error, Trash::Options trashOptions)
{
Q_UNUSED(trashOptions);
SHFILEOPSTRUCTW fileOp;
ZeroMemory(&fileOp, sizeof(fileOp));
fileOp.wFunc = FO_DELETE;
fileOp.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR | FOF_ALLOWUNDO;
std::wstring wFileName = path.toStdWString();
wFileName.push_back('\0');
wFileName.push_back('\0');
fileOp.pFrom = wFileName.c_str();
int r = SHFileOperation(&fileOp);
if (r != 0) {
// Unfortunately there's no adequate way to get message from SHFileOperation failure
error = QString("SHFileOperation failed with code %1").arg(r);
return Trash::Error;
}
return Trash::Success;
}
#else
Trash::Result Trash::moveToTrash(const QString &path, QString &error, Trash::Options trashOptions)
{
error = "Putting files into trashcan is not supported for this platform yet";
return Trash::Error;
}
#endif
phototonic-2.1/Trashcan.h 0000664 0000000 0000000 00000002230 13251276421 0015456 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2018 Roman Chistokhodov
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic 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 Phototonic. If not, see .
*/
#ifndef TRASHCAN_H
#define TRASHCAN_H
#include
namespace Trash {
typedef enum
{
Success,
Error,
NeedsUserInput
} Result;
typedef enum
{
NoOptions = 0,
ForceDeletionToHomeTrash = 1
} Options;
Trash::Result moveToTrash(const QString &filePath, QString &error, Options trashOptions = NoOptions);
}
#endif // TRASHCAN_H
phototonic-2.1/images/ 0000775 0000000 0000000 00000000000 13251276421 0015012 5 ustar 00root root 0000000 0000000 phototonic-2.1/images/about.png 0000664 0000000 0000000 00000001404 13251276421 0016631 0 ustar 00root root 0000000 0000000 PNG
IHDR a sBIT|d pHYs
B(x tEXtSoftware www.inkscape.org< IDAT8SAHa}꒭zXYf=,R +ujE!QPA[$=x1!Ţp
]MVw\qvjwf>xR_ L ;Dd+蜚F`0Ò$5pMMӾ?e}* Somoou4MbH*QT"]O
B6 "0 >Yg$cLmFFF^TUgll,:|BXk 幹s4Mp9mNSSܼc6qQVq||y8L> f ?zݵ!@aӗ$i@#L&azz:iRԣz˲, ^ G_#HomC___oRyՋ~-8XXXzw:D~ppcii=C {kkUQ6YB!8X]]}zr 1"r@<LQ\.9,90[`5 H$w,PaJ%3ϫr3bOOYL4&&&֊ ~`ΤID:_Y^^N/BI jB
' VHkvo@sc? IENDB` phototonic-2.1/images/back.png 0000664 0000000 0000000 00000000763 13251276421 0016426 0 ustar 00root root 0000000 0000000 PNG
IHDR a sBIT|d pHYs
B(x tEXtSoftware www.inkscape.org< pIDAT8SKq:0<㼬!Iqrn \o67fiA7%/:5rU#f*+MX@D1 :7f~^EHphk"RdYk7\u " l6k-GfA˲\$)E2sDD AպSUx<⪪bJBQ;3mBj2~|uwk"2Aph4Z5MT*
0CHD lhLFc0f^x t!UTq^\t:}
+~D \(roYS*:@@h5y=r IENDB` phototonic-2.1/images/bookmarks.png 0000664 0000000 0000000 00000001117 13251276421 0017510 0 ustar 00root root 0000000 0000000 PNG
IHDR a sBIT|d pHYs
B(x tEXtSoftware www.inkscape.org< IDAT8kSQ5%KJJ@`Pfӊ ((š젠=8)RT(bb4ږmrι!O7{s&U.,HQ=7vAཧuNgS>m
IlHY_=V~zړ+J+}_yS?_@2,Ǵ?|8h
P 0 cVDVn'mM W
B@D9Jj 2plNf#5L%՝g'S{LQ#Ru8M)h}̰x,8$Յh-gܟ qPp*V GP@äQ#Tu`g(OB~