/* -*- 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 #include #include #include #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) { }