defuze.me
Client
|
00001 /************************************************************************** 00002 ** defuze.me Epitech Innovative Project 00003 ** 00004 ** Copyright 2010-2011 00005 ** Athena Calmettes - Jocelyn De La Rosa - Francois Gaillard 00006 ** Adrien Jarthon - Alexandre Moore - Luc Peres - Arnaud Sellier 00007 ** 00008 ** All rights reserved. 00009 **************************************************************************/ 00010 00011 #include "playerlabel.hpp" 00012 #include <QPaintEvent> 00013 00014 using namespace Player; 00015 00016 PlayerLabel::PlayerLabel(QWidget *parent) : 00017 QWidget(parent), 00018 letterPolygonA(4), textPolygonA(4), 00019 letterPolygonB(4), textPolygonB(4) 00020 { 00021 right = false; 00022 letterPolygonA.setPoint(0, 0, 0); 00023 letterPolygonA.setPoint(1, 30, 0); 00024 letterPolygonA.setPoint(2, 20, 20); 00025 letterPolygonA.setPoint(3, 0, 20); 00026 textPolygonA.setPoint(0, 30, 0); 00027 textPolygonA.setPoint(1, 100, 0); 00028 textPolygonA.setPoint(2, 90, 20); 00029 textPolygonA.setPoint(3, 20, 20); 00030 00031 letterPolygonB.setPoint(0, 0, 0); 00032 letterPolygonB.setPoint(1, -30, 0); 00033 letterPolygonB.setPoint(2, -20, 20); 00034 letterPolygonB.setPoint(3, 0, 20); 00035 textPolygonB.setPoint(0, -30, 0); 00036 textPolygonB.setPoint(1, -100, 0); 00037 textPolygonB.setPoint(2, -90, 20); 00038 textPolygonB.setPoint(3, -20, 20); 00039 text = "hey"; 00040 color = QColor(255, 255, 255, 30); 00041 } 00042 00043 void PlayerLabel::setRight() 00044 { 00045 right = true; 00046 } 00047 00048 QColor PlayerLabel::currentColor() 00049 { 00050 return QColor(255, 0, 128, 80); 00051 } 00052 00053 QColor PlayerLabel::nextColor() 00054 { 00055 return QColor(128, 255, 0, 80); 00056 } 00057 00058 00059 void PlayerLabel::setCurrent() 00060 { 00061 text = "Current"; 00062 color = currentColor(); 00063 update(); 00064 } 00065 00066 void PlayerLabel::setNext() 00067 { 00068 text = "Next"; 00069 color = nextColor(); 00070 update(); 00071 } 00072 00073 00074 void PlayerLabel::paintEvent(QPaintEvent*) 00075 { 00076 painter.begin(this); 00077 QRect zone = rect(); 00078 QPolygon letterZone; 00079 QPolygon textZone; 00080 QPen p; 00081 00082 p = painter.pen(); 00083 painter.setRenderHint(QPainter::Antialiasing); 00084 painter.setPen(Qt::NoPen); 00085 painter.setBrush(QBrush(color)); 00086 if (right) 00087 letterZone = letterPolygonB.translated(zone.topRight()); 00088 else 00089 letterZone = letterPolygonA.translated(zone.topLeft()); 00090 painter.drawConvexPolygon(letterZone); 00091 00092 painter.setBrush(QBrush(QColor(0, 0, 0, 60))); 00093 if (right) 00094 textZone = textPolygonB.translated(zone.topRight()); 00095 else 00096 textZone = textPolygonA.translated(zone.topLeft()); 00097 painter.drawConvexPolygon(textZone); 00098 painter.setPen(QColor(255, 255, 255)); 00099 painter.drawText(textZone.boundingRect(), Qt::AlignCenter, text); 00100 if (right) 00101 painter.drawText(letterZone.boundingRect().translated(5, 0), Qt::AlignCenter, "B"); 00102 else 00103 painter.drawText(letterZone.boundingRect().translated(-5, 0), Qt::AlignCenter, "A"); 00104 00105 painter.end(); 00106 }