2
* Copyright (C) 2012 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Charles Lindsay <chaz@yorba.org>
20
#ifndef GALLERY_PHOTO_EDIT_STATE_H_
21
#define GALLERY_PHOTO_EDIT_STATE_H_
24
#include "orientation.h"
30
* \brief The PhotoEditState class
32
* Edits that can be applied to a photo. The default-constructed
33
* PhotoEditState is considered the "original" edit state, which we use to mean
34
* that the photo has no edits applied to it.
39
// An orientation outside the range [MIN_ORIENTATION,MAX_ORIENTATION] (also,
40
// must match the DB's default orientation).
41
static const Orientation ORIGINAL_ORIENTATION = (Orientation)0;
43
Orientation orientation_;
44
QRect crop_rectangle_;
46
qreal exposureCompensation_;
47
/// The color balance parameters are stored here in the order:
48
/// brightness (x), contrast(y), saturation(z), hue(w)
49
QVector4D colorBalance_;
51
PhotoEditState() : orientation_(ORIGINAL_ORIENTATION), crop_rectangle_(),
52
is_enhanced_(false), exposureCompensation_(0.0) {
55
bool isOriginal() const {
56
return (orientation_ < MIN_ORIENTATION && !crop_rectangle_.isValid() &&
57
!is_enhanced_ && exposureCompensation_ == 0.0 &&
58
colorBalance_.isNull());
61
// Returns a new PhotoEditState the same as this one but rotated. Needed
62
// because rotating the crop_rectangle isn't trivial. Note that image_width/
63
// height must be specified in this PhotoEditState's orientation, not the
65
PhotoEditState rotate(Orientation newOrientation,
66
int imageWidth, int imageHeight) const {
67
PhotoEditState new_state = *this;
68
new_state.orientation_ = newOrientation;
69
if (crop_rectangle_.isValid())
70
new_state.crop_rectangle_ =
71
rotateCropRectangle(newOrientation, imageWidth, imageHeight);
75
bool operator==(const PhotoEditState& other) {
76
return (orientation_ == other.orientation_ &&
77
crop_rectangle_ == other.crop_rectangle_ &&
78
is_enhanced_ == other.is_enhanced_ &&
79
exposureCompensation_ == other.exposureCompensation_ &&
80
colorBalance_ == other.colorBalance_);
82
bool operator!=(const PhotoEditState& other) { return !(*this == other); }
85
QRect rotateCropRectangle(Orientation newOrientation,
86
int imageWidth, int imageHeight) const;