/
fmpreviewlist.h
141 lines (115 loc) · 4.11 KB
/
fmpreviewlist.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
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
/***************************************************************************
* Copyright (C) 2007 by Pierre Marchand *
* pierre@oep-h.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 of the License, 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. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef FMPREVIEWLIST_H
#define FMPREVIEWLIST_H
#include <QListView>
#include <QAbstractListModel>
#include <QIconEngine>
#include <QPixmap>
#include <QPoint>
#include <QPen>
#include <QPainterPath>
class FontItem;
class MainViewWidget;
class QListView;
// Rather than fighting against Qt to not resize our icons, draw them ourselves.
class FMPreviewIconEngine : public QIconEngine
{
public:
enum Activation{
NotActivated,
Activated,
PartlyActivated
};
FMPreviewIconEngine();
~FMPreviewIconEngine();
void paint ( QPainter * painter, const QRect & rect, QIcon::Mode mode, QIcon::State state );
void addPixmap ( const QPixmap & pixmap, QIcon::Mode mode, QIcon::State state );
void setActivation(Activation a){activatedFont = a;}
virtual QIconEngine *clone() const; // TODO Implement this function
private:
QPixmap m_p;
Activation activatedFont;
static bool initState;
static QPen pen;
static QVector<QRgb> m_selPalette;
static QRgb activatedColor;
static QRgb deactivatedColor;
static QRgb partlyActivatedColor;
QVector<QRgb> actualSelPalette(const QVector<QRgb>& orig);
};
class FMPreviewView : public QListView
{
Q_OBJECT
public:
FMPreviewView(QWidget * parent = 0);
~FMPreviewView(){}
int getUsedWidth() const{return usedWidth;}
// n = 1 for a single column layout (list); n = 2 for multi columns layout
void setNumCol(int n){columns = n;}
bool moveTo(const QString& fname); // fname can be the begining of a fancy name
protected:
void resizeEvent ( QResizeEvent * event );
QPoint startDragPoint;
bool dragFlag;
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
private:
int usedWidth;
int columns;
public slots:
void updateLayout();
void setCurrentFont(const QString& name);
signals:
void widthChanged(int);
void keyPressed(QString);
};
class FMPreviewModel : public QAbstractListModel
{
Q_OBJECT
public:
enum PreviewItemRole{
PathRole = Qt::UserRole + 1
};
FMPreviewModel ( QObject * pa , FMPreviewView * wPa, QList<FontItem*> db = QList<FontItem*>());
//returns a preview
QVariant data ( const QModelIndex &index, int role = Qt::DisplayRole ) const;
//returns flags for items
Qt::ItemFlags flags ( const QModelIndex &index ) const;
//returns the number of items
int rowCount ( const QModelIndex &parent ) const;
void resetBase(QList<FontItem*> db);
QList<FontItem*> getBase();
void setFamilyMode(bool f){familyMode =f;}
void setSpecString(const QString& s){specString = s;}
bool getFamilyMode() const{return familyMode;}
private:
FMPreviewView *m_view;
QList<FontItem*> base;
QString specString;
QString styleTooltipName;
QString styleTooltipTags;
QString styleTooltipPath;
bool familyMode;
public slots:
void dataChanged();
};
#endif