KSane

ksaneviewer.h
1/*
2 * SPDX-FileCopyrightText: 2008 Kare Sars <kare dot sars at iki dot fi>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7#ifndef KSANE_VIEWER_H
8#define KSANE_VIEWER_H
9
10#include <QGraphicsView>
11#include <QWheelEvent>
12
13namespace KSaneIface
14{
15
16/*
17 * Preview image viewer that can handle a selection.
18 */
19class KSaneViewer : public QGraphicsView
20{
22public:
23 explicit KSaneViewer(QImage *img, QWidget *parent = nullptr);
24 ~KSaneViewer() override;
25
26 void setQImage(QImage *img);
27 void updateImage();
28 /** Find selections in the picture
29 * \param area this parameter determine the area of the reduced sized image. */
30 void findSelections(float area = 10000.0);
31
32 QSize sizeHint() const override;
33
34 int currentImageHeight() const;
35 int currentImageWidth() const;
36
37public Q_SLOTS:
38
39 void setTLX(float ratio);
40 void setTLY(float ratio);
41 void setBRX(float ratio);
42 void setBRY(float ratio);
43
44 /** This function is used to set a selection without the user setting it.
45 * \note all parameters must be in the range 0.0 -> 1.0.
46 * \param tl_x is the x coordinate of the top left corner 0=0 1=image with.
47 * \param tl_y is the y coordinate of the top left corner 0=0 1=image height.
48 * \param br_x is the x coordinate of the bottom right corner 0=0 1=image with.
49 * \param br_y is the y coordinate of the bottom right corner 0=0 1=image height. */
50 void setSelection(float tl_x, float tl_y, float br_x, float br_y);
51 void clearActiveSelection();
52 void clearSavedSelections();
53 void clearSelections();
54
55 /** This function is used to darken everything except what is inside the given area.
56 * \note all parameters must be in the range 0.0 -> 1.0.
57 * \param tl_x is the x coordinate of the top left corner 0=0 1=image with.
58 * \param tl_y is the y coordinate of the top left corner 0=0 1=image height.
59 * \param br_x is the x coordinate of the bottom right corner 0=0 1=image with.
60 * \param br_y is the y coordinate of the bottom right corner 0=0 1=image height. */
61 void setHighlightArea(float tl_x, float tl_y, float br_x, float br_y);
62
63 /** This function sets the percentage of the highlighted area that is visible. The rest is hidden.
64 * \param percentage is the percentage of the highlighted area that is shown.
65 * \param hideColor is the color to use to hide the highlighted area of the image.*/
66 void setHighlightShown(int percentage, QColor hideColor = Qt::white);
67
68 /** This function removes the highlight area. */
69 void clearHighlight();
70
71 void zoomIn();
72 void zoomOut();
73 void zoomSel();
74 void zoom2Fit();
75
76 int selListSize();
77 /* This function returns the active visible selection in index 0 and after that the "saved" ones */
78 bool selectionAt(int index, float &tl_x, float &tl_y, float &br_x, float &br_y);
79
80 void setMultiselectionEnabled(bool enabled);
81
83 void newSelection(float tl_x, float tl_y, float br_x, float br_y);
84
85protected:
86 void wheelEvent(QWheelEvent *e) override;
87 void mousePressEvent(QMouseEvent *e) override;
88 void mouseReleaseEvent(QMouseEvent *e) override;
89 void mouseMoveEvent(QMouseEvent *e) override;
90 void drawBackground(QPainter *painter, const QRectF &rect) override;
91
92private:
93 void updateSelVisibility();
94 void updateHighlight();
95 bool activeSelection(float &tl_x, float &tl_y, float &br_x, float &br_y);
96 void refineSelections(int pixelMargin);
97
98 // fromRow is the row to start the iterations from. fromRow can be grater than toRow.
99 // rowStart is the x1 coordinate of the row
100 // all parameters are corrected to be valid pixel indexes,
101 // but start must be < end
102 int refineRow(int fromRow, int toRow, int rowStart, int rowEnd);
103 int refineColumn(int fromCol, int toCol, int colStart, int colEnd);
104
105 QPointF scenePos(QMouseEvent *e) const;
106
107 struct Private;
108 Private *const d;
109
110};
111
112} // NameSpace KSaneIface
113
114#endif
115
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 12:00:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.