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
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/***************************************************************************
* recedge.cc
*
* Wed May 21 13:23:00 CEST 2014
* Copyright 2005 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
/*
* This file is part of MIaV.
*
* MIaV 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.
*
* MIaV 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 MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "recedge.h"
#include <QPalette>
#include <QPaintEvent>
#include <QPainter>
#include <QGridLayout>
#define GREY 160
#define SIZE 10
RecEdge::RecEdge()
{
idle = true;
level = 0.0;
QGridLayout *g = new QGridLayout();
ul = new QLabel(); // upper left
ul->setFixedSize(SIZE, SIZE);
ul->setAutoFillBackground(true);
um = new QLabel(); // upper mid
um->setFixedHeight(SIZE);
um->setAutoFillBackground(true);
ur = new QLabel(); // upper right
ur->setFixedSize(SIZE, SIZE);
ur->setAutoFillBackground(true);
ml = new QLabel(); // left mid
ml->setFixedWidth(SIZE);
ml->setAutoFillBackground(true);
mr = new QLabel(); // right mid
mr->setFixedWidth(SIZE);
mr->setAutoFillBackground(true);
bl = new QLabel(); // bottom left
bl->setFixedSize(SIZE, SIZE);
bl->setAutoFillBackground(true);
bm = new QLabel(); // bottom mid
bm->setFixedHeight(SIZE);
bm->setAutoFillBackground(true);
br = new QLabel(); // bottom right
br->setFixedSize(SIZE, SIZE);
br->setAutoFillBackground(true);
g->addWidget(ul, 0,0, 1,1);
g->addWidget(um, 0,1, 1,1);
g->addWidget(ur, 0,2, 1,1);
g->addWidget(ml, 1,0, 1,1);
g->addWidget(mr, 1,2, 1,1);
g->addWidget(bl, 2,0, 1,1);
g->addWidget(bm, 2,1, 1,1);
g->addWidget(br, 2,2, 1,1);
g->setContentsMargins(0,0,0,0);
g->setSpacing(0);
setContentsMargins(0,0,0,0);
setLayout(g);
}
void RecEdge::updateEdge()
{
QLabel *lbls[] = {ul, um, ur, ml, mr, bl, bm, br, NULL};
int i = 0;
while(lbls[i]) {
QPalette pal = lbls[i]->palette();
if(idle) {
pal.setColor(QPalette::Window, QColor(GREY, GREY, GREY));
} else {
pal.setColor(QPalette::Window,
QColor((int) ((255 - GREY) * level + GREY),
(int) (GREY - (GREY * level)),
(int) (GREY - (GREY * level))));
}
lbls[i]->setPalette(pal);
i++;
}
}
void RecEdge::setInnerWidget(QWidget *inner)
{
QGridLayout *g = (QGridLayout*)layout();
g->addWidget(inner, 1, 1, 1, 1);
}
void RecEdge::setLevel(float l)
{
idle = false;
level = l;
updateEdge();
}
void RecEdge::setIdle(bool i)
{
if(i) {
QPalette pal = palette();
pal.setColor(QPalette::Window, QColor(GREY, GREY, GREY));
setPalette(pal);
}
idle = i;
updateEdge();
}
void RecEdge::paintEvent(QPaintEvent *event)
{
}
|