This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
ImageModel.h
94 lines (76 loc) · 3.04 KB
/
ImageModel.h
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
/*
Copyright (C) 2010 Casey Link <[email protected]>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef IMAGEMODEL_H
#define IMAGEMODEL_H
#include <QAbstractTableModel>
#include <QImage>
class QBitArray;
class ImageModel : public QAbstractTableModel
{
Q_OBJECT
public:
enum ImageRoles {
IsCurrentDebugRole = Qt::UserRole,
ContiguousBlocksRole
};
explicit ImageModel( QObject *parent = 0 );
virtual ~ImageModel();
/**
* Sets the image to expose via the model
* If codel size is not specified, then the model guesses.
*/
void setImage( const QImage &image, int codel_size = -1 );
/**
* Sets the current image to a new image.
* All pixels are filled white.
* @param w width of the new image
* @param h height of the new image
*/
void newImage( int w, int h );
QImage image() const;
/**
* Insert the image at the specified x,y coord
*/
void insertImage( const QImage &image, int x, int y);
void scaleImage( const QSize & size );
QSize imageSize() const;
void setDebuggedPixel( int x, int y );
void setBreakpoint( int x, int y );
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole );
static QImage autoScale(const QImage& _image, int codel_size);
signals:
void pixelChanged( int x, int y, QRgb color );
public slots:
/*! This is a very bad hack.
headerData() needs to know the current pixel size (IN THE VIEW!) in order
to return a correct SizeHint, otherwise things get screwy.
Note: this pixel information is only used by headerData to return a SizeHint
It does not affect the backend image data at all
*/
void slotPixelSizeChange( int size );
private:
void emitNeighborsChanged( int row, int col );
QString statusString( QModelIndex index ) const;
quint64 contiguousBlocks( int x, int y ) const;
QImage mImage;
int mPixelSize;
QPoint mDebugPixel;
};
#endif // IMAGEMODEL_H