1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/* ============================================================
*
* This file is a part of digiKam project
* http://www.digikam.org
*
* Date : 2004-12-09
* Description : image selection widget used by ratio crop tool.
*
* Copyright (C) 2007 by Jaromir Malenko <malenko at email.cz>
* Copyright (C) 2008 by Roberto Castagnola <roberto dot castagnola at gmail dot com>
* Copyright (C) 2004-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, 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.
*
* ============================================================ */
#ifndef IMAGESELECTIONWIDGET_H
#define IMAGESELECTIONWIDGET_H
// TQt includes.
#include <tqwidget.h>
#include <tqrect.h>
#include <tqcolor.h>
namespace Digikam
{
class ImageIface;
}
namespace DigikamImagesPluginCore
{
class ImageSelectionWidgetPriv;
class ImageSelectionWidget : public TQWidget
{
TQ_OBJECT
public:
enum RatioAspect // Constrained Aspect Ratio list.
{
RATIOCUSTOM=0, // Custom aspect ratio.
RATIO01X01, // 1:1
RATIO02x03, // 2:3
RATIO03X04, // 3:4
RATIO04X05, // 4:5
RATIO05x07, // 5:7
RATIO07x10, // 7:10
RATIOGOLDEN, // Golden ratio : 1:1.618
RATIONONE // No aspect ratio.
};
enum Orient
{
Landscape = 0,
Portrait
};
enum CenterType
{
CenterWidth = 0, // Center selection to the center of image width.
CenterHeight, // Center selection to the center of image height.
CenterImage // Center selection to the center of image.
};
// Proportion : Golden Ratio and Rule of Thirds. More information at this url:
// http://photoinf.com/General/Robert_Berdan/Composition_and_the_Elements_of_Visual_Design.htm
enum GuideLineType
{
RulesOfThirds = 0, // Line guides position to 1/3 width and height.
DiagonalMethod, // Diagonal Method to improve composition.
HarmoniousTriangles, // Harmonious Triangle to improve composition.
GoldenMean, // Guides tools using Phi ratio (1.618).
GuideNone // No guide line.
};
public:
ImageSelectionWidget(int width, int height, TQWidget *parent=0,
int widthRatioValue=1, int heightRatioValue=1,
int aspectRatio=RATIO01X01, int orient=Landscape,
int guideLinesType=GuideNone);
~ImageSelectionWidget();
void setCenterSelection(int centerType=CenterImage);
void setSelectionX(int x);
void setSelectionY(int y);
void setSelectionWidth(int w);
void setSelectionHeight(int h);
void setSelectionOrientation(int orient);
void setPreciseCrop(bool precise);
void setAutoOrientation(bool orientation);
void setSelectionAspectRatioType(int aspectRatioType);
void setSelectionAspectRatioValue(int widthRatioValue, int heightRatioValue);
void setGoldenGuideTypes(bool drawGoldenSection, bool drawGoldenSpiralSection,
bool drawGoldenSpiral, bool drawGoldenTriangle,
bool flipHorGoldenGuide, bool flipVerGoldenGuide);
int getOriginalImageWidth();
int getOriginalImageHeight();
TQRect getRegionSelection();
int getMinWidthRange();
int getMinHeightRange();
int getMaxWidthRange();
int getMaxHeightRange();
int getWidthStep();
int getHeightStep();
bool preciseCropAvailable();
void resetSelection();
void maxAspectSelection();
Digikam::ImageIface* imageIface();
public slots:
void slotGuideLines(int guideLinesType);
void slotChangeGuideColor(const TQColor &color);
void slotChangeGuideSize(int size);
signals:
void signalSelectionMoved( TQRect rect );
void signalSelectionChanged( TQRect rect );
void signalSelectionOrientationChanged( int newOrientation );
protected:
void paintEvent( TQPaintEvent *e );
void mousePressEvent ( TQMouseEvent * e );
void mouseReleaseEvent ( TQMouseEvent * e );
void mouseMoveEvent ( TQMouseEvent * e );
void resizeEvent(TQResizeEvent * e);
private:
// Recalculate the target selection position and emit 'signalSelectionMoved'.
void regionSelectionMoved();
void regionSelectionChanged();
TQPoint convertPoint(const TQPoint pm, bool localToReal=true);
TQPoint convertPoint(int x, int y, bool localToReal=true);
void normalizeRegion();
void reverseRatioValues();
int computePreciseSize(int size, int step);
void applyAspectRatio(bool useHeight, bool repaintWidget=true);
void updatePixmap();
TQPoint opposite();
float distance(TQPoint a, TQPoint b);
void placeSelection(TQPoint pm, bool symetric, TQPoint center);
void setCursorResizing();
private:
ImageSelectionWidgetPriv* d;
};
} // NameSpace DigikamImagesPluginCore
#endif /* IMAGESELECTIONWIDGET_H */
|