| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "headerwidget.h" |
| 22 |
#include "buttonarea.h" |
| 23 |
#include "clickablelabel.h" |
| 24 |
|
| 25 |
#include "aerobutton.h" |
| 26 |
#include "mainwindow.h" |
| 27 |
|
| 28 |
#include <QLinearGradient> |
| 29 |
#include <QHBoxLayout> |
| 30 |
#include <QApplication> |
| 31 |
#include <QMouseEvent> |
| 32 |
|
| 33 |
namespace SIFPrivate { |
| 34 |
|
| 35 |
HeaderWidget::HeaderWidget(QWidget *parent) |
| 36 |
: QWidget(parent), m_border(Qt::black), m_shadow(Qt::darkGray), m_dragging(false) |
| 37 |
{ |
| 38 |
QHBoxLayout *layout = new QHBoxLayout(this); |
| 39 |
|
| 40 |
QString title = qApp->applicationName(); |
| 41 |
if(title.isEmpty()) |
| 42 |
{ |
| 43 |
title = tr("Application"); |
| 44 |
} |
| 45 |
|
| 46 |
m_title = new ClickableLabel("<H1>"+title+"</H1>"); |
| 47 |
m_title->setIndent(20); |
| 48 |
setFontColor(Qt::gray); |
| 49 |
|
| 50 |
m_buttonArea = new ButtonArea; |
| 51 |
|
| 52 |
layout->addWidget(m_title); |
| 53 |
layout->addStretch(2); |
| 54 |
layout->addWidget(m_buttonArea); |
| 55 |
|
| 56 |
setAutoFillBackground(true); |
| 57 |
|
| 58 |
connect(m_title, SIGNAL(clicked()), this, SIGNAL(titleClicked())); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
HeaderWidget::~HeaderWidget() |
| 63 |
{ |
| 64 |
} |
| 65 |
|
| 66 |
void HeaderWidget::setTitle(const QString &title) |
| 67 |
{ |
| 68 |
m_title->setText(title); |
| 69 |
} |
| 70 |
|
| 71 |
void HeaderWidget::setTitle(const QPixmap &title) |
| 72 |
{ |
| 73 |
m_title->setPixmap(title); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
void HeaderWidget::setBackground(const QBrush &background) |
| 78 |
{ |
| 79 |
QPalette palette = this->palette(); |
| 80 |
palette.setBrush(QPalette::Window, background); |
| 81 |
|
| 82 |
setPalette(palette); |
| 83 |
} |
| 84 |
|
| 85 |
void HeaderWidget::setFontColor(const QColor &color) |
| 86 |
{ |
| 87 |
QPalette palette = m_title->palette(); |
| 88 |
palette.setBrush(QPalette::WindowText, color); |
| 89 |
|
| 90 |
m_title->setPalette(palette); |
| 91 |
} |
| 92 |
|
| 93 |
void HeaderWidget::setBorderColor(const QColor &color) |
| 94 |
{ |
| 95 |
m_border = color; |
| 96 |
} |
| 97 |
|
| 98 |
QColor HeaderWidget::borderColor() const |
| 99 |
{ |
| 100 |
return m_border; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
void HeaderWidget::setShadowColor(const QColor &color) |
| 105 |
{ |
| 106 |
m_shadow = color; |
| 107 |
} |
| 108 |
|
| 109 |
QColor HeaderWidget::shadowColor() const |
| 110 |
{ |
| 111 |
return m_shadow; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
SIF::AeroButton *HeaderWidget::addButton(const QString &title, const QIcon &icon) |
| 116 |
{ |
| 117 |
SIF::AeroButton *button = m_buttonArea->addButton(title, icon); |
| 118 |
|
| 119 |
|
| 120 |
return button; |
| 121 |
} |
| 122 |
|
| 123 |
void HeaderWidget::resizeEvent(QResizeEvent *e) |
| 124 |
{ |
| 125 |
QWidget::resizeEvent(e); |
| 126 |
|
| 127 |
QRect br = rect(); |
| 128 |
QLinearGradient gradient(0, 0, 0, br.height()); |
| 129 |
|
| 130 |
gradient.setColorAt(0.0, m_border); |
| 131 |
gradient.setColorAt(0.1, m_shadow); |
| 132 |
|
| 133 |
|
| 134 |
gradient.setColorAt(0.5, m_border); |
| 135 |
gradient.setColorAt(0.55, m_border); |
| 136 |
|
| 137 |
gradient.setColorAt(0.9, m_shadow); |
| 138 |
gradient.setColorAt(1.0, m_border); |
| 139 |
|
| 140 |
setBackground(gradient); |
| 141 |
} |
| 142 |
|
| 143 |
void HeaderWidget::mousePressEvent(QMouseEvent *e) |
| 144 |
{ |
| 145 |
if (e->button() == Qt::LeftButton) |
| 146 |
{ |
| 147 |
SIF::MainWindow *mw = qobject_cast<SIF::MainWindow *>(qApp->activeWindow()); |
| 148 |
|
| 149 |
if(mw) |
| 150 |
{ |
| 151 |
m_dragging = true; |
| 152 |
m_dragPosition = e->globalPos() - mw->frameGeometry().topLeft(); |
| 153 |
e->accept(); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
QWidget::mousePressEvent(e); |
| 158 |
} |
| 159 |
|
| 160 |
void HeaderWidget::mouseMoveEvent(QMouseEvent *e) |
| 161 |
{ |
| 162 |
if(m_dragging && e->buttons() & Qt::LeftButton) |
| 163 |
{ |
| 164 |
SIF::MainWindow *mw = qobject_cast<SIF::MainWindow *>(qApp->activeWindow()); |
| 165 |
|
| 166 |
if(mw) |
| 167 |
{ |
| 168 |
mw->move(e->globalPos() - m_dragPosition); |
| 169 |
e->accept(); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
QWidget::mousePressEvent(e); |
| 174 |
} |
| 175 |
|
| 176 |
void HeaderWidget::mouseReleaseEvent(QMouseEvent *e) |
| 177 |
{ |
| 178 |
m_dragging = false; |
| 179 |
QWidget::mouseReleaseEvent(e); |
| 180 |
} |
| 181 |
|
| 182 |
} |