-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcustomborderstorage.cpp
More file actions
103 lines (89 loc) · 2.57 KB
/
customborderstorage.cpp
File metadata and controls
103 lines (89 loc) · 2.57 KB
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
#include "customborderstorage.h"
#ifdef Q_WS_X11
# include <QX11Info>
#endif
#include <QApplication>
#include "custombordercontainer_p.h"
CustomBorderStorage::CustomBorderStorage(const QString &AStorage, const QString &ASubStorage, QObject *AParent) : FileStorage(AStorage,ASubStorage,AParent)
{
}
CustomBorderStorage::~CustomBorderStorage()
{
}
CustomBorderContainer * CustomBorderStorage::addBorder(QWidget *widget, const QString &key)
{
if (isBordersAvail() && isBordersEnabled() && widget->isWindow() && !isBordered(widget))
{
CustomBorderContainerPrivate * style = borderStyleCache.value(key, NULL);
if (!style)
{
QString fileKey = fileCacheKey(key);
if (!fileKey.isEmpty())
{
QString filename = fileFullName(key);
if (!filename.isEmpty())
{
style = new CustomBorderContainerPrivate(NULL);
style->parseFile(filename);
borderStyleCache.insert(key, style);
}
}
}
if (style)
{
CustomBorderContainer * container = new CustomBorderContainer(*style);
container->setWidget(widget);
borderCache.insert(widget, container);
return container;
}
}
return NULL;
}
void CustomBorderStorage::removeBorder(QWidget *widget)
{
CustomBorderContainer * container = borderCache.value(widget, NULL);
if (container)
{
container->releaseWidget();
borderCache.remove(widget);
container->deleteLater();
}
}
bool CustomBorderStorage::isBordersAvail()
{
#ifdef Q_WS_X11
return QX11Info::isCompositingManagerRunning();
#endif
return true;
}
bool CustomBorderStorage::isBordersEnabled()
{
return bordersEnabled;
}
void CustomBorderStorage::setBordersEnabled(bool enabled)
{
bordersEnabled = enabled;
}
bool CustomBorderStorage::isBordered(QWidget *widget)
{
return widgetBorder(widget)!=NULL;
}
CustomBorderContainer * CustomBorderStorage::widgetBorder(QWidget *widget)
{
return qobject_cast<CustomBorderContainer *>(widget->window());
}
CustomBorderStorage * CustomBorderStorage::staticStorage(const QString & storage)
{
CustomBorderStorage * _storage = staticStorages.value(storage, NULL);
if (!_storage)
{
_storage = new CustomBorderStorage(storage, STORAGE_SHARED_DIR, qApp);
staticStorages.insert(storage, _storage);
}
return _storage;
}
// static vars
bool CustomBorderStorage::bordersEnabled = false;
QHash<QString, CustomBorderContainerPrivate *> CustomBorderStorage::borderStyleCache;
QHash<QWidget *, CustomBorderContainer *> CustomBorderStorage::borderCache;
QHash<QString, CustomBorderStorage *> CustomBorderStorage::staticStorages;