-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcontainer.cpp
More file actions
131 lines (108 loc) · 3.18 KB
/
container.cpp
File metadata and controls
131 lines (108 loc) · 3.18 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
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
/*
* Copyright (C) 2016 Dmitry Morozov <dmorozov@outlook.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.
*/
#include <QMouseEvent>
#include "container.h"
#include "layout.h"
#include "skin.h"
#include "mainwindow.h"
#include <QDebug>
Container::Container(const QXmlStreamAttributes &attributes, QWidget *parent) : QWidget(parent)
{
QString name, value;
Q_FOREACH (const QXmlStreamAttribute &i, attributes) {
name = i.name().toString().toLower();
value = i.value().toString();
if (!setProperty(qPrintable(name), QVariant(value))) {
if (dynamicPropertyNames().contains(qPrintable(name))) {
qWarning("%s: unknown property '%s'", Q_FUNC_INFO, qUtf8Printable(name));
setProperty(qPrintable(name), QVariant());
}
qWarning("%s: failed to set '%s' to '%s'", Q_FUNC_INFO, qUtf8Printable(name), qUtf8Printable(value));
}
}
setAttribute(Qt::WA_TranslucentBackground);
}
bool Container::defaultVisible() const
{ return m_defaultVisible; }
int Container::defaultX() const
{ return m_xDefault; }
int Container::defaultY() const
{ return m_yDefault; }
void Container::setDefaultX(int x)
{
move(x, y());
}
void Container::setDefaultY(int y)
{
move(x(), y);
}
void Container::setDefaultVisible(bool enable)
{
setVisible(enable);
qDebug() << Q_FUNC_INFO << enable;
}
Layout *Container::layout() const
{
return m_layout;
}
int Container::setLayout(const QString &id)
{
Layout *lo = findChild<Layout *>(id.toLower());
if (lo == Q_NULLPTR)
return -1;
if (m_layout != Q_NULLPTR)
m_layout->hide();
m_layout = lo;
setMask(lo->mask());
lo->show();
adjustSize();
if (this->id() == "main") {
MainWindow *mw = qobject_cast<MainWindow *>(this->parent());
mw->setContainer(this);
}
return 0;
}
#if 0
void Container::updateMask()
{
QRegion mask;
for (auto child : findChildren<GuiObject *>("widgetname"))
mask += child->mask();
setMask(mask);
}
#endif
#if 0
void Container::mousePressEvent(QMouseEvent *event)
{
//if (m_id == "main")
//QWidget::mousePressEvent(event);
//else
qDebug("%s: '%s' PRESSED", Q_FUNC_INFO, qUtf8Printable(property("id").toString()));
m_oldPos = event->globalPos();
}
void Container::mouseMoveEvent(QMouseEvent *event)
{
const QPoint delta = event->globalPos() - m_oldPos;
QWidget::move(x() + delta.x(), y() + delta.y());
m_oldPos = event->globalPos();
}
void Container::mouseReleaseEvent(QMouseEvent *event)
{
}
#endif
#if 0
void Container::childEvent(QChildEvent *event)
{
if (event->type() == QEvent::ChildPolished && event->child()->isWidgetType()) {
GuiObject *child = qobject_cast<GuiObject *>(event->child());
//qDebug("'%s': '%s' polished", qUtf8Printable(property("id").toString()), qUtf8Printable(child->property("id").toString()));
setMask(mask() + child->mask().translated(child->x(), child->y()));
}
}
#endif