Commit 3724b34313d79e7d1f3ab420599892c8694c1218

Header

Commit diff

examples/examples_config.pri

 
1
2SRC_DIR = $$PWD/../src/
3
4INCLUDEPATH += $$SRC_DIR
5LIBS += -L$$SRC_DIR/../lib -lsif
6
toggle raw diff

examples/simple/main.cpp

 
2020
2121#include <QApplication>
2222
23#include "sif/mainwindow.h"
24
2325int main(int argc, char **argv)
2426{
2527 QApplication app(argc, argv);
2628
27
29 SIF::MainWindow mw;
30 mw.show();
2831
2932 return app.exec();
3033}
toggle raw diff

examples/simple/simple.pro

 
1include($$PWD/../examples_config.pri)
2
13SOURCES += main.cpp
24
35
toggle raw diff

src/sif/aerobutton.cpp

 
55#include <QPainter>
66#include <QApplication>
77
8namespace SIF {
9
10
811struct AeroButton::Private {
912 bool hovered;
1013 bool pressed;
6060AeroButton::AeroButton(QWidget * parent)
6161 : QPushButton(parent), d(new Private)
6262{
63 QPalette pal = palette();
64 pal.setBrush(QPalette::WindowText, Qt::white);
65 pal.setBrush(QPalette::Text, Qt::white);
66 pal.setBrush(QPalette::ButtonText, Qt::white);
67 setPalette(pal);
6368}
6469
6570AeroButton::AeroButton(const QString & text, QWidget * parent)
6671 : QPushButton(text, parent), d(new Private)
6772{
73 QPalette pal = palette();
74 pal.setBrush(QPalette::WindowText, Qt::white);
75 pal.setBrush(QPalette::Text, Qt::white);
76 pal.setBrush(QPalette::ButtonText, Qt::white);
77 setPalette(pal);
6878}
6979
7080AeroButton::AeroButton(const QIcon & icon, const QString & text, QWidget * parent)
7181 : QPushButton(icon, text, parent), d(new Private)
7282{
83 QPalette pal = palette();
84 pal.setBrush(QPalette::WindowText, Qt::white);
85 pal.setBrush(QPalette::Text, Qt::white);
86 pal.setBrush(QPalette::ButtonText, Qt::white);
87 setPalette(pal);
7388}
7489
7590AeroButton::~AeroButton()
7691{
92 delete d;
7793}
7894
7995void AeroButton::setColor(const QColor &color)
130130
131131 QPainter painter(this);
132132 painter.setRenderHint(QPainter::Antialiasing);
133
133
134 painter.save();
135
136 painter.fillRect(rect(), Qt::transparent);
137
134138 //test for state changes
135139 QColor button_color;
136140 if(this->isEnabled())
170170
171171 QBrush brush(gradient);
172172 painter.setBrush(brush);
173 painter.setPen(QPen(QBrush(button_color), 2.0));
173 painter.setPen(QPen(QBrush(button_color), 2.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ));
174174
175175 //main button
176176 QPainterPath painter_path;
182182
183183 //glass highlight
184184 painter.setBrush(QBrush(Qt::white));
185 painter.setPen(QPen(QBrush(Qt::white), 0.01));
185 painter.setPen(QPen(QBrush(Qt::white), 0.01, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
186186 painter.setOpacity(0.30);
187187 painter.drawRect(1, 1, button_rect.width() - 2, (button_rect.height() / 2) - 2);
188188
189 painter.restore();
190
189191 //button text
190192 QString text = this->text();
191193 if(!text.isNull())
192194 {
193195 QFont font = this->font();
196 font.setBold(true);
194197 painter.setFont(font);
195 painter.setPen(Qt::white);
198
199// painter.setPen(Qt::white);
200
196201 painter.setOpacity(1.0);
197202 painter.drawText(0, 0, button_rect.width(), button_rect.height(), Qt::AlignCenter, text);
198203 }
218218 Q_UNUSED(e);
219219
220220 d->hovered = true;
221 this->repaint();
221 this->update();
222222}
223223
224224void AeroButton::leaveEvent(QEvent * e)
226226 Q_UNUSED(e);
227227
228228 d->hovered = false;
229 this->repaint();
229 this->update();
230230}
231231
232232void AeroButton::mousePressEvent(QMouseEvent * e)
233233{
234234 Q_UNUSED(e);
235
236 this->click();
237
235
238236 d->pressed = true;
239 this->repaint();
237 this->update();
238
239 QPushButton::mousePressEvent(e);
240240}
241241
242242void AeroButton::mouseReleaseEvent(QMouseEvent * e)
243243{
244244 Q_UNUSED(e);
245
245
246246 d->pressed = false;
247 this->repaint();
247 this->update();
248
249 QPushButton::mouseReleaseEvent(e);
248250}
249251
250252
253}
toggle raw diff

src/sif/aerobutton.h

 
33
44#include <QPushButton>
55
6class AeroButton : public QPushButton
6namespace SIF {
7
8class AeroButton : public QPushButton // TODO: QAbstractButton ?
79{
810 Q_OBJECT
911
4040 Private *const d;
4141};
4242
43#endif // _AEROBUTTON_
43}
44
45#endif // _AEROBUTTON_H_
46
47
toggle raw diff

src/sif/mainwindow.cpp

 
1717 * Free Software Foundation, Inc., *
1818 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
1919 ***************************************************************************/
20
2021#include "mainwindow.h"
2122
23#include "private/centralwidget.h"
24
2225namespace SIF {
2326
27struct MainWindow::Private {
28 SIFPrivate::CentralWidget *central;
29};
30
2431MainWindow::MainWindow(QWidget *parent)
25 : QMainWindow(parent)
32 : QMainWindow(parent), d(new Private)
2633{
34 d->central = new SIFPrivate::CentralWidget;
35
36
37 setCentralWidget(d->central);
2738}
2839
29
3040MainWindow::~MainWindow()
3141{
42 delete d;
3243}
3344
3445
toggle raw diff

src/sif/mainwindow.h

 
1717 * Free Software Foundation, Inc., *
1818 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
1919 ***************************************************************************/
20
2021#ifndef SIFMAINWINDOW_H
2122#define SIFMAINWINDOW_H
2223
3535 MainWindow(QWidget *parent = 0);
3636 ~MainWindow();
3737
38
38 private:
39 struct Private;
40 Private *const d;
3941};
4042
4143}
toggle raw diff

src/sif/private/buttonarea.cpp

 
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 "buttonarea.h"
22
23#include <QHBoxLayout>
24
25#include "aerobutton.h"
26
27namespace SIFPrivate {
28
29ButtonArea::ButtonArea(QWidget *parent)
30 : QWidget(parent)
31{
32 QHBoxLayout *layout = new QHBoxLayout(this);
33
34 SIF::AeroButton *b1 = new SIF::AeroButton("Button 1");
35 b1->setRoundness(10);
36
37 SIF::AeroButton *b2 = new SIF::AeroButton("Button 2");
38 b2->setRoundness(10);
39
40 SIF::AeroButton *b3 = new SIF::AeroButton("Button 3");
41 b3->setRoundness(10);
42
43 layout->addWidget(b1);
44 layout->addWidget(b2);
45 layout->addWidget(b3);
46}
47
48
49ButtonArea::~ButtonArea()
50{
51}
52
53
54}
toggle raw diff

src/sif/private/buttonarea.h

 
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#ifndef SIFPRIVATEBUTTONAREA_H
21#define SIFPRIVATEBUTTONAREA_H
22
23#include <QWidget>
24
25namespace SIFPrivate {
26
27/**
28 @author David Cuadrado <krawek@gmail.com>
29*/
30class ButtonArea : public QWidget
31{
32 Q_OBJECT;
33 public:
34 ButtonArea(QWidget *parent = 0);
35 ~ButtonArea();
36
37 private:
38
39};
40
41}
42
43#endif
toggle raw diff

src/sif/private/centralwidget.cpp

 
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 "centralwidget.h"
22
23#include "headerwidget.h"
24#include "stackedwidget.h"
25
26#include <QVBoxLayout>
27
28namespace SIFPrivate {
29
30CentralWidget::CentralWidget(QWidget *parent)
31 : QWidget(parent)
32{
33 QVBoxLayout *layout = new QVBoxLayout(this);
34 layout->setMargin(0);
35
36 m_header = new HeaderWidget;
37 m_stack = new StackedWidget;
38
39 layout->addWidget(m_header);
40 layout->addWidget(m_stack);
41
42
43}
44
45
46CentralWidget::~CentralWidget()
47{
48}
49
50
51}
toggle raw diff

src/sif/private/centralwidget.h

 
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#ifndef SIFPRIVATECENTRALWIDGET_H
21#define SIFPRIVATECENTRALWIDGET_H
22
23#include <QWidget>
24
25namespace SIFPrivate {
26
27class HeaderWidget;
28class StackedWidget;
29
30/**
31 @author David Cuadrado <krawek@gmail.com>
32*/
33class CentralWidget : public QWidget
34{
35 Q_OBJECT;
36 public:
37 CentralWidget(QWidget *parent = 0);
38 ~CentralWidget();
39
40 private:
41 HeaderWidget *m_header;
42 StackedWidget *m_stack;
43};
44
45}
46
47#endif
toggle raw diff

src/sif/private/clickablelabel.cpp

 
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#include "clickablelabel.h"
21
22namespace SIFPrivate {
23
24ClickableLabel::ClickableLabel(QWidget *parent)
25 : QLabel(parent)
26{
27 setCursor(Qt::PointingHandCursor);
28}
29
30ClickableLabel::ClickableLabel(const QString &text, QWidget *parent) : QLabel(text, parent)
31{
32 setCursor(Qt::PointingHandCursor);
33}
34
35ClickableLabel::~ClickableLabel()
36{
37}
38
39void ClickableLabel::mouseReleaseEvent(QMouseEvent *e)
40{
41 QLabel::mouseReleaseEvent(e);
42 emit clicked();
43}
44
45}
toggle raw diff

src/sif/private/clickablelabel.h

 
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#ifndef SIFPRIVATECLICKABLELABEL_H
21#define SIFPRIVATECLICKABLELABEL_H
22
23#include <QLabel>
24
25namespace SIFPrivate {
26
27/**
28 @author David Cuadrado <krawek@gmail.com>
29*/
30class ClickableLabel : public QLabel
31{
32 Q_OBJECT;
33 public:
34 ClickableLabel(QWidget *parent = 0);
35 ClickableLabel(const QString &text, QWidget *parent = 0);
36 ~ClickableLabel();
37
38 signals:
39 void clicked();
40
41 protected:
42 void mouseReleaseEvent(QMouseEvent *e);
43};
44
45}
46
47#endif
toggle raw diff

src/sif/private/headerwidget.cpp

 
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 <QLinearGradient>
26#include <QHBoxLayout>
27
28namespace SIFPrivate {
29
30HeaderWidget::HeaderWidget(QWidget *parent)
31 : QWidget(parent), m_border(Qt::black), m_shadow(Qt::darkGray)
32{
33 QHBoxLayout *layout = new QHBoxLayout(this);
34
35 m_title = new ClickableLabel("<H1>SIF</H1>");
36 m_title->setIndent(20);
37 setFontColor(Qt::gray);
38
39 m_buttonArea = new ButtonArea;
40
41 layout->addWidget(m_title);
42 layout->addStretch(1);
43 layout->addWidget(m_buttonArea);
44
45 setAutoFillBackground(true);
46
47 connect(m_title, SIGNAL(clicked()), this, SIGNAL(titleClicked()));
48}
49
50
51HeaderWidget::~HeaderWidget()
52{
53}
54
55void HeaderWidget::setTitle(const QString &title)
56{
57 m_title->setText(title);
58}
59
60void HeaderWidget::setTitle(const QPixmap &title)
61{
62 m_title->setPixmap(title);
63}
64
65
66void HeaderWidget::setBackground(const QBrush &background)
67{
68 QPalette palette = this->palette();
69 palette.setBrush(QPalette::Window, background);
70
71 setPalette(palette);
72}
73
74void HeaderWidget::setFontColor(const QColor &color)
75{
76 QPalette palette = m_title->palette();
77 palette.setBrush(QPalette::WindowText, color);
78
79 m_title->setPalette(palette);
80}
81
82void HeaderWidget::resizeEvent(QResizeEvent *e)
83{
84 QWidget::resizeEvent(e);
85
86 QRect br = rect();
87 QLinearGradient gradient(0, 0, 0, br.height());
88
89 gradient.setColorAt(0.0, m_border);
90 gradient.setColorAt(0.1, m_shadow);
91
92
93 gradient.setColorAt(0.5, m_border);
94 gradient.setColorAt(0.55, m_border);
95
96 gradient.setColorAt(0.9, m_shadow);
97 gradient.setColorAt(1.0, m_border);
98
99 setBackground(gradient);
100}
101
102}
toggle raw diff