~artmello/gallery-app/gallery-app-fix_crash_adding_files

« back to all changes in this revision

Viewing changes to src/photo/photo-edit-state.h

  • Committer: Ugo Riboni
  • Date: 2014-11-25 16:24:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1175.
  • Revision ID: ugo.riboni@canonical.com-20141125162412-lfop177fz2cd89ik
Remove the edit state and edit database classes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2012 Canonical Ltd
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authors:
17
 
 * Charles Lindsay <chaz@yorba.org>
18
 
 */
19
 
 
20
 
#ifndef GALLERY_PHOTO_EDIT_STATE_H_
21
 
#define GALLERY_PHOTO_EDIT_STATE_H_
22
 
 
23
 
// util
24
 
#include "orientation.h"
25
 
 
26
 
#include <QRect>
27
 
#include <QVector4D>
28
 
 
29
 
/*!
30
 
 * \brief The PhotoEditState class
31
 
 *
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.
35
 
 */
36
 
class PhotoEditState
37
 
{
38
 
public:
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;
42
 
 
43
 
    Orientation orientation_;
44
 
    QRect crop_rectangle_;
45
 
    bool is_enhanced_;
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_;
50
 
 
51
 
    PhotoEditState() : orientation_(ORIGINAL_ORIENTATION), crop_rectangle_(),
52
 
        is_enhanced_(false), exposureCompensation_(0.0) {
53
 
    }
54
 
 
55
 
    bool isOriginal() const {
56
 
        return (orientation_ < MIN_ORIENTATION && !crop_rectangle_.isValid() &&
57
 
                !is_enhanced_ && exposureCompensation_ == 0.0 &&
58
 
                colorBalance_.isNull());
59
 
    }
60
 
 
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
64
 
    // new_orientation.
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);
72
 
        return new_state;
73
 
    }
74
 
 
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_);
81
 
    }
82
 
    bool operator!=(const PhotoEditState& other) { return !(*this == other); }
83
 
 
84
 
private:
85
 
    QRect rotateCropRectangle(Orientation newOrientation,
86
 
                                int imageWidth, int imageHeight) const;
87
 
};
88
 
 
89
 
#endif