System notice: In light of the Debian OpenSSL security issue we've regenerated the server keys. See this thread for instructions and the new key fingerprints.

Blob of src/sif/private/headerwidget.cpp (raw blob data)

1 /***************************************************************************
2 * Copyright (C) 2008 by David Cuadrado *
3 * krawek@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
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 }