Commit d641ed57ce4ffb6e4382dce80aa1465bfc476a17

Finished initial support for pages and views

Commit diff

examples/examples.pro

 
11TEMPLATE = subdirs
22
3SUBDIRS += simple
3SUBDIRS += simple \
4 view
45
toggle raw diff

examples/simple/main.cpp

 
2323#include <QIcon>
2424
2525#include "sif/mainwindow.h"
26#include "sif/view.h"
2627
2728int main(int argc, char **argv)
2829{
2930 QApplication app(argc, argv);
31 app.setApplicationName("Example 1");
3032
3133 SIF::MainWindow mw;
3234
33 mw.addPage("Page 1", new QLabel("La pagina 1"));
34 mw.addPage("Page 2", new QLabel("La pagina 2"));
35 mw.addPage(QIcon("/usr/share/icons/gnome/48x48/apps/openofficeorg23-base.png"), "Page 2", new QLabel("La pagina 3"));
36 mw.addPage(QIcon("/usr/share/icons/crystalsvg/128x128/apps/tux.png"), QString(), new QLabel("La pagina 4"));
35 mw.addPage("Page 1", new QLabel("A page"));
36 mw.addPage("Page 2", new QLabel("Another page"));
3737
3838 mw.show();
3939
toggle raw diff

examples/view/main.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 <QApplication>
22#include <QLabel>
23#include <QIcon>
24#include <QCalendarWidget>
25#include <QTableWidget>
26#include <QTextEdit>
27#include <QDial>
28#include <QGraphicsView>
29#include <QGraphicsScene>
30#include <QGraphicsRectItem>
31#include <QGraphicsEllipseItem>
32
33#include "sif/mainwindow.h"
34#include "sif/view.h"
35
36int main(int argc, char **argv)
37{
38 QApplication app(argc, argv);
39 app.setApplicationName("Example 2");
40
41 SIF::MainWindow mw;
42 QObject::connect(&mw, SIGNAL(titleClicked()), qApp, SLOT(aboutQt()));
43
44 SIF::View *view1 = new SIF::View;
45 view1->addPage("Calendar", new QCalendarWidget);
46 view1->addPage("Table", new QTableWidget(10, 10));
47
48 mw.addPage("Data", view1);
49
50
51 SIF::View *view2 = new SIF::View;
52 view2->addPage("Editor", new QTextEdit("An editor"));
53 view2->addPage("Dial", new QDial);
54
55 QGraphicsView *qgv = new QGraphicsView;
56 qgv->setRenderHints(QPainter::Antialiasing);
57 QGraphicsScene *scene = new QGraphicsScene;
58
59 scene->addRect(QRect(25, 150, 100, 100))->setBrush(Qt::red);
60 scene->addEllipse(QRect(100, 20, 40, 100))->setBrush(Qt::blue);
61
62 qgv->setScene(scene);
63 view2->addPage("Graphics", qgv);
64
65
66 mw.addPage("View", view2);
67
68
69 mw.show();
70
71 return app.exec();
72}
73
toggle raw diff

examples/view/view.pro

 
1
2include($$PWD/../examples_config.pri)
3
4SOURCES += main.cpp
5
toggle raw diff

src/sif/aerobutton.cpp

 
3838 pal.setBrush(QPalette::Text, Qt::white);
3939 pal.setBrush(QPalette::ButtonText, Qt::white);
4040 q->setPalette(pal);
41
42 q->setCheckable(1);
4341}
4442
4543QRect AeroButton::Private::calculateIconPosition(const QRect &button_rect, const QSize &icon_size)
toggle raw diff

src/sif/mainwindow.cpp

 
2121#include "mainwindow.h"
2222
2323#include "private/centralwidget.h"
24#include "private/headerwidget.h"
2425
2526namespace SIF {
2627
3434{
3535 d->central = new SIFPrivate::CentralWidget;
3636
37 connect(d->central->header(), SIGNAL(titleClicked()), this, SIGNAL(titleClicked()));
3738
3839 setCentralWidget(d->central);
3940}
toggle raw diff

src/sif/mainwindow.h

 
3737
3838 void addPage(const QString &title, QWidget *w);
3939 void addPage(const QIcon &icon, const QString &title, QWidget *w);
40
41 signals:
42 void titleClicked();
4043
4144 private:
4245 struct Private;
toggle raw diff

src/sif/private/buttonarea.cpp

 
5252SIF::AeroButton *ButtonArea::addButton(const QString &title, const QIcon &icon)
5353{
5454 SIF::AeroButton *button = new SIF::AeroButton(icon, title);
55 button->setCheckable(true);
5556 button->setIconSize(QSize(48, 48));
5657
5758 m_layout->addWidget(button);
toggle raw diff

src/sif/private/centralwidget.cpp

 
2121#include "centralwidget.h"
2222
2323#include "headerwidget.h"
24#include "footerwidget.h"
2425#include "stackedwidget.h"
2526#include "aerobutton.h"
2627
3333 : QWidget(parent)
3434{
3535 QVBoxLayout *layout = new QVBoxLayout(this);
36 layout->setSpacing(3);
3637 layout->setMargin(0);
3738
3839 m_header = new HeaderWidget;
3940 m_stack = new StackedWidget;
41 m_footer = new FooterWidget(m_header);
42 {
43 m_footer->setMinimumHeight(30);
44
45 }
4046
4147 layout->addWidget(m_header);
4248 layout->addWidget(m_stack);
43
44
49 layout->addWidget(m_footer);
4550}
4651
4752
7474 connect(button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
7575}
7676
77HeaderWidget *CentralWidget::header() const
78{
79 return m_header;
80}
81
82StackedWidget *CentralWidget::stack() const
83{
84 return m_stack;
85}
86
87
7788void CentralWidget::onButtonClicked()
7889{
7990 QAbstractButton *button = qobject_cast<QAbstractButton *>(sender());
toggle raw diff

src/sif/private/centralwidget.h

 
2828namespace SIFPrivate {
2929
3030class HeaderWidget;
31class FooterWidget;
3132class StackedWidget;
3233
3334/**
4444 void addPage(const QString &title, QWidget *w);
4545 void addPage(const QIcon &icon, const QString &title, QWidget *w);
4646
47 HeaderWidget *header() const;
48 StackedWidget *stack() const;
49
4750 private slots:
4851 void onButtonClicked();
4952
5053 private:
5154 HeaderWidget *m_header;
5255 StackedWidget *m_stack;
56 FooterWidget *m_footer;
5357
5458 QHash<QAbstractButton *, QWidget *> m_pages;
5559};
toggle raw diff

src/sif/private/footerwidget.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 "footerwidget.h"
22#include "headerwidget.h"
23
24namespace SIFPrivate {
25
26FooterWidget::FooterWidget(HeaderWidget *header, QWidget *parent)
27 : QWidget(parent), m_header(header)
28{
29 setAutoFillBackground(true);
30}
31
32
33FooterWidget::~FooterWidget()
34{
35}
36
37void FooterWidget::setBackground(const QBrush &background)
38{
39 QPalette palette = this->palette();
40 palette.setBrush(QPalette::Window, background);
41
42 setPalette(palette);
43}
44
45void FooterWidget::resizeEvent(QResizeEvent *e)
46{
47 QWidget::resizeEvent(e);
48
49 QRect br = rect();
50 QLinearGradient gradient(0, 0, 0, br.height());
51
52 gradient.setColorAt(0.0, m_header->borderColor());
53 gradient.setColorAt(0.1, m_header->shadowColor());
54
55
56 gradient.setColorAt(0.5, m_header->borderColor());
57 gradient.setColorAt(0.55, m_header->borderColor());
58
59 gradient.setColorAt(0.9, m_header->shadowColor());
60 gradient.setColorAt(1.0, m_header->borderColor());
61
62 setBackground(gradient);
63}
64
65}
toggle raw diff

src/sif/private/footerwidget.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 SIFPRIVATEFOOTERWIDGET_H
21#define SIFPRIVATEFOOTERWIDGET_H
22
23#include <QWidget>
24
25namespace SIFPrivate {
26class HeaderWidget;
27
28/**
29 @author David Cuadrado <krawek@gmail.com>
30*/
31class FooterWidget : public QWidget
32{
33 Q_OBJECT;
34 public:
35 FooterWidget(HeaderWidget *header, QWidget *parent = 0);
36 ~FooterWidget();
37
38 void setBackground(const QBrush &background);
39
40 protected:
41 void resizeEvent(QResizeEvent *e);
42
43 private:
44 HeaderWidget *m_header;
45};
46
47}
48
49#endif
toggle raw diff

src/sif/private/headerwidget.cpp

 
2626
2727#include <QLinearGradient>
2828#include <QHBoxLayout>
29#include <QApplication>
2930
3031namespace SIFPrivate {
3132
3535{
3636 QHBoxLayout *layout = new QHBoxLayout(this);
3737
38 m_title = new ClickableLabel("<H1>SIF</H1>");
38 QString title = qApp->applicationName();
39 if(title.isEmpty())
40 {
41 title = tr("Application");
42 }
43
44 m_title = new ClickableLabel("<H1>"+title+"</H1>");
3945 m_title->setIndent(20);
4046 setFontColor(Qt::gray);
4147
4248 m_buttonArea = new ButtonArea;
4349
4450 layout->addWidget(m_title);
45 layout->addStretch(1);
4651 layout->addWidget(m_buttonArea);
4752
4853 setAutoFillBackground(true);
8787 m_title->setPalette(palette);
8888}
8989
90void HeaderWidget::setBorderColor(const QColor &color)
91{
92 m_border = color;
93}
94
95QColor HeaderWidget::borderColor() const
96{
97 return m_border;
98}
99
100
101void HeaderWidget::setShadowColor(const QColor &color)
102{
103 m_shadow = color;
104}
105
106QColor HeaderWidget::shadowColor() const
107{
108 return m_shadow;
109}
110
111
90112SIF::AeroButton *HeaderWidget::addButton(const QString &title, const QIcon &icon)
91113{
92114 SIF::AeroButton *button = m_buttonArea->addButton(title, icon);
toggle raw diff

src/sif/private/headerwidget.h

 
4949
5050 void setFontColor(const QColor &color);
5151
52 void setBorderColor(const QColor &color);
53 QColor borderColor() const;
54
55 void setShadowColor(const QColor &color);
56 QColor shadowColor() const;
57
5258 SIF::AeroButton *addButton(const QString &title, const QIcon &icon = QIcon());
5359
5460 signals:
toggle raw diff

src/sif/sif.pro

 
1616private/headerwidget.h \
1717private/centralwidget.h \
1818private/buttonarea.h \
19private/clickablelabel.h
19private/clickablelabel.h \
20 view.h \
21private/footerwidget.h
2022
2123SOURCES += mainwindow.cpp \
2224aerobutton.cpp \
2626private/headerwidget.cpp \
2727private/centralwidget.cpp \
2828private/buttonarea.cpp \
29private/clickablelabel.cpp
29private/clickablelabel.cpp \
30 view.cpp \
31private/footerwidget.cpp
3032
3133
3234TEMPLATE = lib
toggle raw diff

src/sif/view.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 "view.h"
22
23#include <QListWidget>
24#include <QHBoxLayout>
25#include <QStackedWidget>
26#include <QLabel>
27#include <QPainter>
28#include <QtDebug>
29
30namespace SIF {
31
32class List : public QListWidget
33{
34 Q_OBJECT;
35 public:
36 List(View *view, QStackedWidget *stack);
37 ~List();
38
39 void addWidget(const QString &title, const QIcon &icon, QWidget *w);
40
41 private slots:
42 void onCurrentItemChanged(QListWidgetItem *item, QListWidgetItem *);
43
44 protected:
45 void resizeEvent(QResizeEvent *e);
46 void rowsInserted(const QModelIndex &parent, int start, int end);
47
48 private:
49 View *m_view;
50 QStackedWidget *m_stack;
51 QHash<QListWidgetItem *, QWidget *> m_widgets;
52};
53
54List::List(View *view, QStackedWidget *stack) : m_view(view), m_stack(stack)
55{
56 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
57 setMaximumWidth(128);
58 setIconSize(QSize(48, 48));
59 setAlternatingRowColors(true);
60
61 connect(this, SIGNAL(currentItemChanged( QListWidgetItem*,QListWidgetItem* )), this, SLOT(onCurrentItemChanged(QListWidgetItem *, QListWidgetItem*)));
62}
63
64List::~List()
65{
66}
67
68void List::addWidget(const QString &title, const QIcon &icon, QWidget *w)
69{
70 QListWidgetItem *item = new QListWidgetItem(title);
71
72 if(!icon.isNull())
73 {
74 item->setIcon(icon);
75 }
76 else
77 {
78 QPixmap px(48, 48);
79 px.fill(Qt::transparent);
80 QPainter painter(&px);
81 painter.setRenderHints(QPainter::Antialiasing);
82
83 painter.setPen(Qt::NoPen);
84
85 QRadialGradient brush(px.rect().center(), px.rect().width()/2 - 10);
86 brush.setColorAt(0.0, Qt::gray);
87 brush.setColorAt(1.0, Qt::black);
88
89 painter.setBrush(brush);
90 painter.drawEllipse(px.rect().adjusted(10, 10, -10, -10) );
91
92 painter.end();
93
94 item->setIcon(px);
95 }
96
97 this->addItem(item);
98
99 m_stack->addWidget(w);
100
101 m_widgets.insert(item, w);
102}
103
104void List::onCurrentItemChanged(QListWidgetItem *item, QListWidgetItem *)
105{
106 if(item)
107 {
108 if(m_widgets.contains(item))
109 {
110 m_stack->setCurrentWidget(m_widgets[item]);
111 }
112 }
113}
114
115void List::resizeEvent(QResizeEvent *e)
116{
117 QListWidget::resizeEvent(e);
118}
119
120void List::rowsInserted(const QModelIndex &parent, int start, int end)
121{
122 int size = 0;
123
124
125 for(int i = start; i <= end; i++)
126 {
127 QListWidgetItem *it = item(i);
128
129 if(it)
130 {
131 QFontMetrics fm(it->font());
132
133 int tmp = fm.width(it->text()) + iconSize().width() + 30;
134
135 if(tmp > size)
136 {
137 size = tmp;
138 }
139 }
140 }
141
142 if(size > maximumWidth())
143 {
144 setMaximumWidth(size);
145 }
146
147 QListWidget::rowsInserted(parent, start, end);
148}
149
150struct View::Private {
151 List *list;
152 QStackedWidget *stack;
153};
154
155View::View(QWidget *parent)
156 : QWidget(parent), d(new Private)
157{
158 QHBoxLayout *layout = new QHBoxLayout(this);
159 layout->setMargin(3);
160
161 d->stack = new QStackedWidget;
162 d->list = new List(this, d->stack);
163
164 d->list->setResizeMode(QListView::Fixed);
165
166
167
168 layout->addWidget(d->list);
169 layout->addWidget(d->stack);
170}
171
172
173View::~View()
174{
175 delete d;
176}
177
178void View::addPage(const QString &title, QWidget *w)
179{
180 d->list->addWidget(title, QIcon(), w);
181}
182
183void View::addPage(const QIcon &icon, const QString &title, QWidget *w)
184{
185 d->list->addWidget(title, icon, w);
186}
187
188}
189
190
191#include "view.moc"
toggle raw diff

src/sif/view.h

 
1/********************************