-
Notifications
You must be signed in to change notification settings - Fork 1
/
rmapoptions.cpp
executable file
·81 lines (65 loc) · 2.91 KB
/
rmapoptions.cpp
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
#include "rmapoptions.h"
#include <QFontDatabase>
#include <QStringList>
#include <QDebug>
//--------------------------------------------------------------------------------------
RMapOptions &RMapOptions::instance()
{
static RMapOptions opt;
return opt;
}
//--------------------------------------------------------------------------------------
RMapOptions::RMapOptions()
{}
// методы для работы со шрифтами
//--------------------------------------------------------------------------------------
bool RMapOptions::addFont(int font_id, const QString &path, int weight, int height)
{
int id = QFontDatabase::addApplicationFont(path);
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont font(family);
font.setPixelSize(height);
font.setHintingPreference(QFont::PreferFullHinting);
font.setStyleStrategy(QFont::PreferAntialias);
m_fontsMap.insert(font_id, RFontDescriptor(font_id, path, weight, height, font));
return true;
}
//--------------------------------------------------------------------------------------
const RFontDescriptor &RMapOptions::getFontDescriptorById(int id) const
{
QMap<int, RFontDescriptor>::const_iterator it = m_fontsMap.find(id);
return it == m_fontsMap.end() ? m_emptyFont : *it;
}
//--------------------------------------------------------------------------------------
const QMap<int, RFontDescriptor> &RMapOptions::fontsMap() const
{ return m_fontsMap; }
//--------------------------------------------------------------------------------------
const RFontDescriptor &RMapOptions::emptyFont() const
{ return m_emptyFont; }
// методы для работы с картинками
//--------------------------------------------------------------------------------------
bool RMapOptions::addImage(int image_id, const QString &path, int width, int height)
{
QImage image(0, 0, QImage::Format_ARGB32_Premultiplied);
image.load(path);
m_imageMap.insert(image_id, RImageDescriptor(image_id, width, height, path, image));
return true;
}
//--------------------------------------------------------------------------------------
const RImageDescriptor &RMapOptions::getImageDescriptorById(int id) const
{
QMap<int, RImageDescriptor>::const_iterator it = m_imageMap.find(id);
return it == m_imageMap.end() ? m_emptyImage : *it;
}
//--------------------------------------------------------------------------------------
const QMap<int, RImageDescriptor> &RMapOptions::imageMap() const
{ return m_imageMap; }
//--------------------------------------------------------------------------------------
const RImageDescriptor &RMapOptions::emptyImage() const
{ return m_emptyImage; }
//--------------------------------------------------------------------------------------
void RMapOptions::clearAll()
{
m_fontsMap.clear();
m_imageMap.clear();
}