blob: a4bae05a7f13263d79ef1b118c93d8af342af8db (
plain)
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
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#ifndef CHARTABLEMODEL_H
#define CHARTABLEMODEL_H
#include <QAbstractTableModel>
#include <QStringList>
#include "scribusapi.h"
class ScribusDoc;
class ScFace;
class QItemSelectionModel;
//! \brief A special type for character classes
typedef QList<uint> CharClassDef;
/*! \brief A model (MVC) to handle unicode characters map.
It's a backend for CharTableView - its GUI representation.
\warning: CharTableModel and CharTableView are designed for 1:1 relations!
\author Petr Vanek <petr@scribus.info>
*/
class SCRIBUS_API CharTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
CharTableModel(QObject *parent = 0, int cols = 4, ScribusDoc * doc = 0, const QString & font = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
//! \brief Get a graphics representation/pixmap of the glyph
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
void setFontInUse(QString font);
//! \brief Font in use. It's used in model's view.
ScFace fontFace();
void setCharacters(CharClassDef ch);
void setCharactersAndFonts(CharClassDef ch, QStringList fonts);
void addCharacter(QString ch);
CharClassDef characters() {
return m_characters;
};
QStringList fonts() { return m_fonts; }
//! \brief called to erase glyph at index from table.
bool removeCharacter(int index);
void setDoc(ScribusDoc *doc);
void setViewWidth(int w) {
m_viewWidth = w;
};
public slots:
/*! \brief appends an unicode char into m_characters list.
\param s a QString with numerical representation of the character.
\param base an optional parameter containing base of the numerical converion. See QString::toInt() documentation.
The base parameter is used mainly in normal code - not in slot calls.
If user adds an already existing glyph it's rejected and the original
one is selected (see selectionChanged()).
*/
void appendUnicode(const QString & s, uint base = 16);
signals:
/*! \brief Inform its view about internal selection changes.
It's emitted everytime user adds an existing glyph to the
CharClassDef list. */
void selectionChanged(QItemSelectionModel * model);
//! \brief Emitted when there is a new row
void rowAppended();
private:
ScribusDoc *m_doc;
//! \brief Number of the columns for model
int m_cols;
//! \brief View's width to compute pixmap sizes.
int m_viewWidth;
QString m_fontInUse;
CharClassDef m_characters;
QStringList m_fonts;
//! \brief Internal selection handling. See selectionChanged().
QItemSelectionModel * m_selectionModel;
/*! \brief All drag'n'drop actions are handled in this model only
See Qt4 docs "Using Drag and Drop with Item Views" for more info.
*/
Qt::ItemFlags flags(const QModelIndex &index) const;
Qt::DropActions supportedDropActions() const;
QStringList mimeTypes() const;
QMimeData * mimeData(const QModelIndexList &indexes) const;
bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent);
};
#endif
|