Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 andreas 1
/*
101 andreas 2
 * Copyright (C) 2020 to 2022 by Andreas Theofilu <andreas@theosys.at>
5 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#include <QTextObject>
20
#include <QLabel>
21
#include <QImage>
22
#include <QWidget>
41 andreas 23
#include <QPropertyAnimation>
21 andreas 24
#include <QtMultimedia/QMediaPlayer>
25
#include <QtMultimediaWidgets/QVideoWidget>
5 andreas 26
#include "tobject.h"
27
#include "terror.h"
28
 
29
TObject::TObject()
30
{
31
    DECL_TRACER("TObject::TObject()");
32
}
33
 
34
TObject::~TObject()
35
{
36
    DECL_TRACER("TObject::~TObject()");
37
 
89 andreas 38
    clear();
39
}
40
 
41
void TObject::clear(bool force)
42
{
43
    DECL_TRACER("TObject::clear()");
44
 
5 andreas 45
    OBJECT_t *obj = mObject;
46
 
47
    while (obj)
48
    {
49
        OBJECT_t *next = obj->next;
89 andreas 50
 
51
        if (!force)
52
            dropContent(obj);
53
 
5 andreas 54
        delete obj;
55
        obj = next;
56
    }
89 andreas 57
 
58
    mObject = nullptr;
5 andreas 59
}
60
 
14 andreas 61
void TObject::dropContent(OBJECT_t* obj)
62
{
63
    DECL_TRACER("TObject::dropContent(OBJECT_t* obj)");
64
 
89 andreas 65
    try
14 andreas 66
    {
89 andreas 67
        switch (obj->type)
68
        {
69
            case OBJ_TEXT:
70
            case OBJ_INPUT:
71
                if (obj->object.multitext)
72
                {
73
    //                delete obj->object.text;
74
                    obj->object.multitext = nullptr;
75
                }
14 andreas 76
 
89 andreas 77
                if (obj->object.linetext)
78
                    obj->object.linetext = nullptr;
51 andreas 79
 
89 andreas 80
                obj->wid = 0;
81
            break;
51 andreas 82
 
89 andreas 83
            case OBJ_BUTTON:
84
                if (obj->object.label)
85
                {
86
    //                delete obj->object.label;
87
                    obj->object.label = nullptr;
88
                }
89
            break;
90
 
91
            case OBJ_PAGE:
92
            case OBJ_SUBPAGE:
93
                if (obj->object.widget)
94
                {
95
                    delete obj->object.widget;
96
                    obj->object.widget = nullptr;
96 andreas 97
                }
89 andreas 98
                break;
14 andreas 99
 
89 andreas 100
            case OBJ_VIDEO:
101
                if (obj->object.vwidget)
102
                {
103
                    delete obj->object.vwidget;
14 andreas 104
 
89 andreas 105
                    if (obj->player)
106
                        delete obj->player;
21 andreas 107
 
89 andreas 108
                    obj->object.vwidget = nullptr;
109
                    obj->player = nullptr;
110
                }
21 andreas 111
 
89 andreas 112
            default:
113
                break;
114
        }
14 andreas 115
    }
89 andreas 116
    catch (std::exception& e)
117
    {
118
        MSG_ERROR("Error freeing an object: " << e.what());
119
    }
14 andreas 120
}
121
 
5 andreas 122
TObject::OBJECT_t *TObject::addObject()
123
{
124
    DECL_TRACER("TObject::addObject()");
125
 
126
    OBJECT_t *obj = new OBJECT_t;
127
    obj->next = nullptr;
21 andreas 128
    obj->object.vwidget = nullptr;
129
    obj->player = nullptr;
6 andreas 130
    obj->object.label = nullptr;
51 andreas 131
    obj->object.multitext = nullptr;
132
    obj->object.linetext = nullptr;
6 andreas 133
    obj->object.widget = nullptr;
5 andreas 134
 
135
    if (!mObject)
136
        mObject = obj;
137
    else
138
    {
139
        OBJECT_t *p = mObject;
140
 
141
        while (p->next)
142
            p = p->next;
143
 
144
        p->next = obj;
145
    }
146
 
147
    return obj;
148
}
149
 
150
TObject::OBJECT_t *TObject::findObject(ulong handle)
151
{
152
    DECL_TRACER("TObject::findObject(ulong handle)");
153
 
154
    OBJECT_t *obj = mObject;
155
 
156
    while (obj)
157
    {
158
        if (obj->handle == handle)
159
            return obj;
160
 
161
        obj = obj->next;
162
    }
163
 
164
    return nullptr;
165
}
166
 
51 andreas 167
TObject::OBJECT_t * TObject::findObject(WId id)
168
{
169
    DECL_TRACER("TObject::findObject(WId id)");
170
 
171
    OBJECT_t *obj = mObject;
172
 
173
    while (obj)
174
    {
175
        if (obj->wid == id)
176
            return obj;
177
 
178
        obj = obj->next;
179
    }
180
 
181
    return nullptr;
182
}
183
 
11 andreas 184
TObject::OBJECT_t *TObject::findFirstChild(ulong handle)
185
{
186
    DECL_TRACER("TObject::findFirstChild(ulong handle)");
187
 
188
    OBJECT_t *obj = mObject;
189
 
190
    while (obj)
191
    {
13 andreas 192
        if (obj->handle != (handle & 0xffff0000) && (obj->handle & 0xffff0000) == (handle & 0xffff0000))
11 andreas 193
            return obj;
194
 
195
        obj = obj->next;
196
    }
197
 
198
    return nullptr;
199
}
200
 
201
TObject::OBJECT_t *TObject::findNextChild(ulong handle)
202
{
203
    DECL_TRACER("TObject::findNextChild(ulong handle)");
204
 
205
    OBJECT_t *obj = mObject;
206
    bool next = false;
207
 
208
    while (obj)
209
    {
210
        if (next && (obj->handle & 0xffff0000) == (handle & 0xffff0000))
211
            return obj;
212
 
213
        if (obj->handle == handle)
214
            next = true;
215
 
216
        obj = obj->next;
217
    }
218
 
219
    return nullptr;
220
}
221
 
42 andreas 222
TObject::OBJECT_t * TObject::getMarkedRemove()
223
{
224
    DECL_TRACER("TObject::getMarkedRemove()");
51 andreas 225
 
42 andreas 226
    OBJECT_t *obj = mObject;
51 andreas 227
 
42 andreas 228
    while (obj)
229
    {
230
        if (obj->remove)
231
            return obj;
51 andreas 232
 
42 andreas 233
        obj = obj->next;
234
    }
51 andreas 235
 
42 andreas 236
    return nullptr;
237
}
238
 
239
TObject::OBJECT_t * TObject::getNextMarkedRemove(TObject::OBJECT_t* object)
240
{
241
    DECL_TRACER("TObject::getNextMarkedRemove(TObject::OBJECT_t* obj)");
51 andreas 242
 
42 andreas 243
    OBJECT_t *obj = nullptr;
51 andreas 244
 
42 andreas 245
    if (!object || !object->next)
246
        return nullptr;
51 andreas 247
 
42 andreas 248
    obj = object->next;
51 andreas 249
 
42 andreas 250
    while (obj)
251
    {
252
        if (obj->remove)
253
            return obj;
51 andreas 254
 
42 andreas 255
        obj = obj->next;
256
    }
51 andreas 257
 
42 andreas 258
    return nullptr;
259
}
260
 
5 andreas 261
void TObject::removeObject(ulong handle)
262
{
263
    DECL_TRACER("TObject::removeObject(ulong handle)");
264
 
265
    OBJECT_t *obj = mObject;
266
    OBJECT_t *prev = nullptr;
267
 
268
    while (obj)
269
    {
270
        if (obj->handle == handle)
271
        {
272
            if (!prev)
273
            {
274
                mObject = obj->next;
275
                delete obj;
276
            }
277
            else
278
            {
279
                prev->next = obj->next;
280
                delete obj;
281
            }
282
 
283
            return;
284
        }
285
 
286
        prev = obj;
287
        obj = obj->next;
288
    }
289
}
290
 
11 andreas 291
void TObject::removeAllChilds(ulong handle)
292
{
293
    DECL_TRACER("TObject::removeAllChilds(ulong handle)");
294
 
14 andreas 295
    OBJECT_t *obj = mObject;
296
    OBJECT_t *prev = nullptr;
11 andreas 297
 
298
    while (obj)
299
    {
14 andreas 300
        if ((obj->handle & 0xffff0000) == (handle & 0xffff0000) && obj->handle != (handle & 0xffff0000))
301
        {
302
            if (!prev)
303
            {
304
                mObject = obj->next;
305
                delete obj;
306
                obj = mObject;
307
                continue;
308
            }
309
            else
310
            {
311
                prev->next = obj->next;
312
                delete obj;
313
                obj = prev;
314
            }
315
        }
316
 
317
        prev = obj;
318
        obj = obj->next;
11 andreas 319
    }
320
}
14 andreas 321
 
322
std::string TObject::objectToString(TObject::OBJECT_TYPE o)
323
{
324
    switch(o)
325
    {
326
        case OBJ_BUTTON:  return "BUTTON"; break;
327
        case OBJ_INPUT:   return "INPUT"; break;
328
        case OBJ_NONE:    return "undefined"; break;
329
        case OBJ_PAGE:    return "PAGE"; break;
330
        case OBJ_SUBPAGE: return "SUBPAGE"; break;
331
        case OBJ_TEXT:    return "TEXT"; break;
21 andreas 332
        case OBJ_VIDEO:   return "VIDEO"; break;
14 andreas 333
    }
78 andreas 334
 
335
    return std::string();   // Should not happen but is needed to satisfy the compiler.
14 andreas 336
}