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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#include "WINDOW_BleuNuit.h"
#include <QDesktopWidget>
#include <QPainter>
WINDOW_BleuNuit::WINDOW_BleuNuit(QWidget * parent)
:QWidget(parent),
m_MainLayout(this),
m_TitleBar(this),
m_SizeGrip(this),
m_Cache(NULL),
m_taille(QSize(512,512))
{
connect(this, SIGNAL(WindowTitleChanged()),&m_TitleBar,SLOT(UpdateWindowTitle()));
resize(m_taille.width(),m_taille.height());
setWindowTitle(tr("test"));
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
/*MainLayout*/
m_MainLayout.setMargin(0);
m_MainLayout.setSpacing(0);
m_MainLayout.addWidget(&m_TitleBar,0,0,1,1);
m_MainLayout.setRowStretch(1,1);
setLayout(&m_MainLayout);
}
WINDOW_BleuNuit::WINDOW_BleuNuit(QString title,QWidget * parent)
:QWidget(parent),
m_MainLayout(this),
m_TitleBar(this),
m_SizeGrip(this),
m_Cache(NULL),
m_taille(QSize(512,512))
{
connect(this ,SIGNAL(WindowTitleChanged()) ,&m_TitleBar ,SLOT(UpdateWindowTitle()));
connect(&m_TitleBar ,SIGNAL(Signal_Quit()) ,this ,SLOT(Quit()));
resize(m_taille.width(),m_taille.height());
setWindowTitle(title);
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
/*MainLayout*/
m_MainLayout.setMargin(0);
m_MainLayout.setSpacing(0);
m_MainLayout.addWidget(&m_TitleBar,0,0,1,1);
m_MainLayout.setRowStretch(1,1);
setLayout(&m_MainLayout);
}
WINDOW_BleuNuit::~WINDOW_BleuNuit()
{
delete m_Cache;
}
void WINDOW_BleuNuit::Quit()
{
close();
}
void WINDOW_BleuNuit::showEvent(QShowEvent *event)
{
Q_UNUSED(event);
CenterOnScreen();
}
void WINDOW_BleuNuit::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
if(m_Cache != NULL)
{
QPainter painter(this);
painter.drawPixmap(0, 0, *m_Cache);
}
}
void WINDOW_BleuNuit::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
if(m_Cache != NULL) delete m_Cache;
m_Cache = new QPixmap(size());
m_Cache->fill(Qt::transparent);
QPainter painter(m_Cache);
QColor darkBlue ( 23, 23, 34);
QColor lightBlue(177, 177, 203);
/********** Window's background **********/
QPolygon background;
background << QPoint( 0, 16)
<< QPoint( 16, 0)
<< QPoint(width() - 1, 0)
<< QPoint(width() - 1, height() - 33)
<< QPoint(width() - 17, height() - 17)
<< QPoint( 272, height() - 17)
<< QPoint( 256, height() - 1)
<< QPoint( 16, height() - 1)
<< QPoint( 16, 272)
<< QPoint( 0, 256);
painter.setPen (QPen (darkBlue));
painter.setBrush(QBrush(darkBlue));
painter.drawPolygon(background);
/*****************************************/
/********** Window's frame **********/
QPolygon frame;
frame << QPoint( 4, 20)
<< QPoint( 20, 4)
<< QPoint(width() - 4, 4)
<< QPoint(width() - 4, height() - 37)
<< QPoint(width() - 20, height() - 21)
<< QPoint( 268, height() - 21)
<< QPoint( 252, height() - 5)
<< QPoint( 20, height() - 5)
<< QPoint( 20, 268)
<< QPoint( 4, 252);
painter.setPen (QPen(lightBlue));
painter.setBrush(Qt::NoBrush );
painter.drawPolygon(frame);
/*****************************************/
m_SizeGrip.move (width() - 32, height() - 49);
m_SizeGrip.resize( 32, 32);
}
void WINDOW_BleuNuit::setWindowTitle(const QString &title)
{
QWidget::setWindowTitle(title);
emit WindowTitleChanged();
}
void WINDOW_BleuNuit::CenterOnScreen()
{
QDesktopWidget screen;
QRect screenGeom = screen.screenGeometry(this);
int screenCenterX = screenGeom.center().x();
int screenCenterY = screenGeom.center().y();
move(screenCenterX - width () / 2,
screenCenterY - height() / 2);
} |
Partager