| |   |
| 23 | 23 | #include <QIcon> |
| 24 | 24 | |
| 25 | 25 | #include "sif/mainwindow.h" |
| 26 | #include "sif/view.h" |
| 26 | 27 | |
| 27 | 28 | int main(int argc, char **argv) |
| 28 | 29 | { |
| 29 | 30 | QApplication app(argc, argv); |
| 31 | app.setApplicationName("Example 1"); |
| 30 | 32 | |
| 31 | 33 | SIF::MainWindow mw; |
| 32 | 34 | |
| 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")); |
| 37 | 37 | |
| 38 | 38 | mw.show(); |
| 39 | 39 | |
| toggle raw diff |
--- a/examples/simple/main.cpp
+++ b/examples/simple/main.cpp
@@ -23,17 +23,17 @@
#include <QIcon>
#include "sif/mainwindow.h"
+#include "sif/view.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
+ app.setApplicationName("Example 1");
SIF::MainWindow mw;
- mw.addPage("Page 1", new QLabel("La pagina 1"));
- mw.addPage("Page 2", new QLabel("La pagina 2"));
- mw.addPage(QIcon("/usr/share/icons/gnome/48x48/apps/openofficeorg23-base.png"), "Page 2", new QLabel("La pagina 3"));
- mw.addPage(QIcon("/usr/share/icons/crystalsvg/128x128/apps/tux.png"), QString(), new QLabel("La pagina 4"));
+ mw.addPage("Page 1", new QLabel("A page"));
+ mw.addPage("Page 2", new QLabel("Another page"));
mw.show();
|
| |   |
| 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 | |
| 36 | int 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 |
--- /dev/null
+++ b/examples/view/main.cpp
@@ -0,0 +1,73 @@
+/***************************************************************************
+ * Copyright (C) 2008 by David Cuadrado *
+ * krawek@gmail.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include <QApplication>
+#include <QLabel>
+#include <QIcon>
+#include <QCalendarWidget>
+#include <QTableWidget>
+#include <QTextEdit>
+#include <QDial>
+#include <QGraphicsView>
+#include <QGraphicsScene>
+#include <QGraphicsRectItem>
+#include <QGraphicsEllipseItem>
+
+#include "sif/mainwindow.h"
+#include "sif/view.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ app.setApplicationName("Example 2");
+
+ SIF::MainWindow mw;
+ QObject::connect(&mw, SIGNAL(titleClicked()), qApp, SLOT(aboutQt()));
+
+ SIF::View *view1 = new SIF::View;
+ view1->addPage("Calendar", new QCalendarWidget);
+ view1->addPage("Table", new QTableWidget(10, 10));
+
+ mw.addPage("Data", view1);
+
+
+ SIF::View *view2 = new SIF::View;
+ view2->addPage("Editor", new QTextEdit("An editor"));
+ view2->addPage("Dial", new QDial);
+
+ QGraphicsView *qgv = new QGraphicsView;
+ qgv->setRenderHints(QPainter::Antialiasing);
+ QGraphicsScene *scene = new QGraphicsScene;
+
+ scene->addRect(QRect(25, 150, 100, 100))->setBrush(Qt::red);
+ scene->addEllipse(QRect(100, 20, 40, 100))->setBrush(Qt::blue);
+
+ qgv->setScene(scene);
+ view2->addPage("Graphics", qgv);
+
+
+ mw.addPage("View", view2);
+
+
+ mw.show();
+
+ return app.exec();
+}
+ |
| |   |
| 21 | 21 | #include "centralwidget.h" |
| 22 | 22 | |
| 23 | 23 | #include "headerwidget.h" |
| 24 | #include "footerwidget.h" |
| 24 | 25 | #include "stackedwidget.h" |
| 25 | 26 | #include "aerobutton.h" |
| 26 | 27 | |
| … | … | |
| 33 | 33 | : QWidget(parent) |
| 34 | 34 | { |
| 35 | 35 | QVBoxLayout *layout = new QVBoxLayout(this); |
| 36 | layout->setSpacing(3); |
| 36 | 37 | layout->setMargin(0); |
| 37 | 38 | |
| 38 | 39 | m_header = new HeaderWidget; |
| 39 | 40 | m_stack = new StackedWidget; |
| 41 | m_footer = new FooterWidget(m_header); |
| 42 | { |
| 43 | m_footer->setMinimumHeight(30); |
| 44 | |
| 45 | } |
| 40 | 46 | |
| 41 | 47 | layout->addWidget(m_header); |
| 42 | 48 | layout->addWidget(m_stack); |
| 43 | | |
| 44 | | |
| 49 | layout->addWidget(m_footer); |
| 45 | 50 | } |
| 46 | 51 | |
| 47 | 52 | |
| … | … | |
| 74 | 74 | connect(button, SIGNAL(clicked()), this, SLOT(onButtonClicked())); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | HeaderWidget *CentralWidget::header() const |
| 78 | { |
| 79 | return m_header; |
| 80 | } |
| 81 | |
| 82 | StackedWidget *CentralWidget::stack() const |
| 83 | { |
| 84 | return m_stack; |
| 85 | } |
| 86 | |
| 87 | |
| 77 | 88 | void CentralWidget::onButtonClicked() |
| 78 | 89 | { |
| 79 | 90 | QAbstractButton *button = qobject_cast<QAbstractButton *>(sender()); |
| toggle raw diff |
--- a/src/sif/private/centralwidget.cpp
+++ b/src/sif/private/centralwidget.cpp
@@ -21,6 +21,7 @@
#include "centralwidget.h"
#include "headerwidget.h"
+#include "footerwidget.h"
#include "stackedwidget.h"
#include "aerobutton.h"
@@ -32,15 +33,20 @@ CentralWidget::CentralWidget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->setSpacing(3);
layout->setMargin(0);
m_header = new HeaderWidget;
m_stack = new StackedWidget;
+ m_footer = new FooterWidget(m_header);
+ {
+ m_footer->setMinimumHeight(30);
+
+ }
layout->addWidget(m_header);
layout->addWidget(m_stack);
-
-
+ layout->addWidget(m_footer);
}
@@ -68,6 +74,17 @@ void CentralWidget::addPage(const QIcon &icon, const QString &title, QWidget *w)
connect(button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}
+HeaderWidget *CentralWidget::header() const
+{
+ return m_header;
+}
+
+StackedWidget *CentralWidget::stack() const
+{
+ return m_stack;
+}
+
+
void CentralWidget::onButtonClicked()
{
QAbstractButton *button = qobject_cast<QAbstractButton *>(sender()); |
| |   |
| 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 | |
| 24 | namespace SIFPrivate { |
| 25 | |
| 26 | FooterWidget::FooterWidget(HeaderWidget *header, QWidget *parent) |
| 27 | : QWidget(parent), m_header(header) |
| 28 | { |
| 29 | setAutoFillBackground(true); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | FooterWidget::~FooterWidget() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | void FooterWidget::setBackground(const QBrush &background) |
| 38 | { |
| 39 | QPalette palette = this->palette(); |
| 40 | palette.setBrush(QPalette::Window, background); |
| 41 | |
| 42 | setPalette(palette); |
| 43 | } |
| 44 | |
| 45 | void 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 |
--- /dev/null
+++ b/src/sif/private/footerwidget.cpp
@@ -0,0 +1,65 @@
+/***************************************************************************
+ * Copyright (C) 2008 by David Cuadrado *
+ * krawek@gmail.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "footerwidget.h"
+#include "headerwidget.h"
+
+namespace SIFPrivate {
+
+FooterWidget::FooterWidget(HeaderWidget *header, QWidget *parent)
+ : QWidget(parent), m_header(header)
+{
+ setAutoFillBackground(true);
+}
+
+
+FooterWidget::~FooterWidget()
+{
+}
+
+void FooterWidget::setBackground(const QBrush &background)
+{
+ QPalette palette = this->palette();
+ palette.setBrush(QPalette::Window, background);
+
+ setPalette(palette);
+}
+
+void FooterWidget::resizeEvent(QResizeEvent *e)
+{
+ QWidget::resizeEvent(e);
+
+ QRect br = rect();
+ QLinearGradient gradient(0, 0, 0, br.height());
+
+ gradient.setColorAt(0.0, m_header->borderColor());
+ gradient.setColorAt(0.1, m_header->shadowColor());
+
+
+ gradient.setColorAt(0.5, m_header->borderColor());
+ gradient.setColorAt(0.55, m_header->borderColor());
+
+ gradient.setColorAt(0.9, m_header->shadowColor());
+ gradient.setColorAt(1.0, m_header->borderColor());
+
+ setBackground(gradient);
+}
+
+} |
| |   |
| 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 | |
| 25 | namespace SIFPrivate { |
| 26 | class HeaderWidget; |
| 27 | |
| 28 | /** |
| 29 | @author David Cuadrado <krawek@gmail.com> |
| 30 | */ |
| 31 | class 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 |
--- /dev/null
+++ b/src/sif/private/footerwidget.h
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * Copyright (C) 2008 by David Cuadrado *
+ * krawek@gmail.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef SIFPRIVATEFOOTERWIDGET_H
+#define SIFPRIVATEFOOTERWIDGET_H
+
+#include <QWidget>
+
+namespace SIFPrivate {
+class HeaderWidget;
+
+/**
+ @author David Cuadrado <krawek@gmail.com>
+*/
+class FooterWidget : public QWidget
+{
+ Q_OBJECT;
+ public:
+ FooterWidget(HeaderWidget *header, QWidget *parent = 0);
+ ~FooterWidget();
+
+ void setBackground(const QBrush &background);
+
+ protected:
+ void resizeEvent(QResizeEvent *e);
+
+ private:
+ HeaderWidget *m_header;
+};
+
+}
+
+#endif |
| |   |
| 26 | 26 | |
| 27 | 27 | #include <QLinearGradient> |
| 28 | 28 | #include <QHBoxLayout> |
| 29 | #include <QApplication> |
| 29 | 30 | |
| 30 | 31 | namespace SIFPrivate { |
| 31 | 32 | |
| … | … | |
| 35 | 35 | { |
| 36 | 36 | QHBoxLayout *layout = new QHBoxLayout(this); |
| 37 | 37 | |
| 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>"); |
| 39 | 45 | m_title->setIndent(20); |
| 40 | 46 | setFontColor(Qt::gray); |
| 41 | 47 | |
| 42 | 48 | m_buttonArea = new ButtonArea; |
| 43 | 49 | |
| 44 | 50 | layout->addWidget(m_title); |
| 45 | | layout->addStretch(1); |
| 46 | 51 | layout->addWidget(m_buttonArea); |
| 47 | 52 | |
| 48 | 53 | setAutoFillBackground(true); |
| … | … | |
| 87 | 87 | m_title->setPalette(palette); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | void HeaderWidget::setBorderColor(const QColor &color) |
| 91 | { |
| 92 | m_border = color; |
| 93 | } |
| 94 | |
| 95 | QColor HeaderWidget::borderColor() const |
| 96 | { |
| 97 | return m_border; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void HeaderWidget::setShadowColor(const QColor &color) |
| 102 | { |
| 103 | m_shadow = color; |
| 104 | } |
| 105 | |
| 106 | QColor HeaderWidget::shadowColor() const |
| 107 | { |
| 108 | return m_shadow; |
| 109 | } |
| 110 | |
| 111 | |
| 90 | 112 | SIF::AeroButton *HeaderWidget::addButton(const QString &title, const QIcon &icon) |
| 91 | 113 | { |
| 92 | 114 | SIF::AeroButton *button = m_buttonArea->addButton(title, icon); |
| toggle raw diff |
--- a/src/sif/private/headerwidget.cpp
+++ b/src/sif/private/headerwidget.cpp
@@ -26,6 +26,7 @@
#include <QLinearGradient>
#include <QHBoxLayout>
+#include <QApplication>
namespace SIFPrivate {
@@ -34,14 +35,19 @@ HeaderWidget::HeaderWidget(QWidget *parent)
{
QHBoxLayout *layout = new QHBoxLayout(this);
- m_title = new ClickableLabel("<H1>SIF</H1>");
+ QString title = qApp->applicationName();
+ if(title.isEmpty())
+ {
+ title = tr("Application");
+ }
+
+ m_title = new ClickableLabel("<H1>"+title+"</H1>");
m_title->setIndent(20);
setFontColor(Qt::gray);
m_buttonArea = new ButtonArea;
layout->addWidget(m_title);
- layout->addStretch(1);
layout->addWidget(m_buttonArea);
setAutoFillBackground(true);
@@ -81,6 +87,28 @@ void HeaderWidget::setFontColor(const QColor &color)
m_title->setPalette(palette);
}
+void HeaderWidget::setBorderColor(const QColor &color)
+{
+ m_border = color;
+}
+
+QColor HeaderWidget::borderColor() const
+{
+ return m_border;
+}
+
+
+void HeaderWidget::setShadowColor(const QColor &color)
+{
+ m_shadow = color;
+}
+
+QColor HeaderWidget::shadowColor() const
+{
+ return m_shadow;
+}
+
+
SIF::AeroButton *HeaderWidget::addButton(const QString &title, const QIcon &icon)
{
SIF::AeroButton *button = m_buttonArea->addButton(title, icon); |
| |   |
| 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 | |
| 30 | namespace SIF { |
| 31 | |
| 32 | class 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 | |
| 54 | List::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 | |
| 64 | List::~List() |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | void 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 | |
| 104 | void 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 | |
| 115 | void List::resizeEvent(QResizeEvent *e) |
| 116 | { |
| 117 | QListWidget::resizeEvent(e); |
| 118 | } |
| 119 | |
| 120 | void 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 | |
| 150 | struct View::Private { |
| 151 | List *list; |
| 152 | QStackedWidget *stack; |
| 153 | }; |
| 154 | |
| 155 | View::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 | |
| 173 | View::~View() |
| 174 | { |
| 175 | delete d; |
| 176 | } |
| 177 | |
| 178 | void View::addPage(const QString &title, QWidget *w) |
| 179 | { |
| 180 | d->list->addWidget(title, QIcon(), w); |
| 181 | } |
| 182 | |
| 183 | void 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 |
--- /dev/null
+++ b/src/sif/view.cpp
@@ -0,0 +1,191 @@
+/***************************************************************************
+ * Copyright (C) 2008 by David Cuadrado *
+ * krawek@gmail.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "view.h"
+
+#include <QListWidget>
+#include <QHBoxLayout>
+#include <QStackedWidget>
+#include <QLabel>
+#include <QPainter>
+#include <QtDebug>
+
+namespace SIF {
+
+class List : public QListWidget
+{
+ Q_OBJECT;
+ public:
+ List(View *view, QStackedWidget *stack);
+ ~List();
+
+ void addWidget(const QString &title, const QIcon &icon, QWidget *w);
+
+ private slots:
+ void onCurrentItemChanged(QListWidgetItem *item, QListWidgetItem *);
+
+ protected:
+ void resizeEvent(QResizeEvent *e);
+ void rowsInserted(const QModelIndex &parent, int start, int end);
+
+ private:
+ View *m_view;
+ QStackedWidget *m_stack;
+ QHash<QListWidgetItem *, QWidget *> m_widgets;
+};
+
+List::List(View *view, QStackedWidget *stack) : m_view(view), m_stack(stack)
+{
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setMaximumWidth(128);
+ setIconSize(QSize(48, 48));
+ setAlternatingRowColors(true);
+
+ connect(this, SIGNAL(currentItemChanged( QListWidgetItem*,QListWidgetItem* )), this, SLOT(onCurrentItemChanged(QListWidgetItem *, QListWidgetItem*)));
+}
+
+List::~List()
+{
+}
+
+void List::addWidget(const QString &title, const QIcon &icon, QWidget *w)
+{
+ QListWidgetItem *item = new QListWidgetItem(title);
+
+ if(!icon.isNull())
+ {
+ item->setIcon(icon);
+ }
+ else
+ {
+ QPixmap px(48, 48);
+ px.fill(Qt::transparent);
+ QPainter painter(&px);
+ painter.setRenderHints(QPainter::Antialiasing);
+
+ painter.setPen(Qt::NoPen);
+
+ QRadialGradient brush(px.rect().center(), px.rect().width()/2 - 10);
+ brush.setColorAt(0.0, Qt::gray);
+ brush.setColorAt(1.0, Qt::black);
+
+ painter.setBrush(brush);
+ painter.drawEllipse(px.rect().adjusted(10, 10, -10, -10) );
+
+ painter.end();
+
+ item->setIcon(px);
+ }
+
+ this->addItem(item);
+
+ m_stack->addWidget(w);
+
+ m_widgets.insert(item, w);
+}
+
+void List::onCurrentItemChanged(QListWidgetItem *item, QListWidgetItem *)
+{
+ if(item)
+ {
+ if(m_widgets.contains(item))
+ {
+ m_stack->setCurrentWidget(m_widgets[item]);
+ }
+ }
+}
+
+void List::resizeEvent(QResizeEvent *e)
+{
+ QListWidget::resizeEvent(e);
+}
+
+void List::rowsInserted(const QModelIndex &parent, int start, int end)
+{
+ int size = 0;
+
+
+ for(int i = start; i <= end; i++)
+ {
+ QListWidgetItem *it = item(i);
+
+ if(it)
+ {
+ QFontMetrics fm(it->font());
+
+ int tmp = fm.width(it->text()) + iconSize().width() + 30;
+
+ if(tmp > size)
+ {
+ size = tmp;
+ }
+ }
+ }
+
+ if(size > maximumWidth())
+ {
+ setMaximumWidth(size);
+ }
+
+ QListWidget::rowsInserted(parent, start, end);
+}
+
+struct View::Private {
+ List *list;
+ QStackedWidget *stack;
+};
+
+View::View(QWidget *parent)
+ : QWidget(parent), d(new Private)
+{
+ QHBoxLayout *layout = new QHBoxLayout(this);
+ layout->setMargin(3);
+
+ d->stack = new QStackedWidget;
+ d->list = new List(this, d->stack);
+
+ d->list->setResizeMode(QListView::Fixed);
+
+
+
+ layout->addWidget(d->list);
+ layout->addWidget(d->stack);
+}
+
+
+View::~View()
+{
+ delete d;
+}
+
+void View::addPage(const QString &title, QWidget *w)
+{
+ d->list->addWidget(title, QIcon(), w);
+}
+
+void View::addPage(const QIcon &icon, const QString &title, QWidget *w)
+{
+ d->list->addWidget(title, icon, w);
+}
+
+}
+
+
+#include "view.moc" |