# HG changeset patch # User John Kern # Date 1283535493 25200 # Node ID b9716e8867f1d46fcb7ba98c19463ebac1ae7386 # Parent b56d7e26863459496ede3218f40427f7afbd4544 checking in example; variations on List Widgets diff -r b56d7e268634 -r b9716e8867f1 ListElements/EasyStreet/EasyStreet.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/EasyStreet/EasyStreet.pro Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-08-31T11:46:44 +# +#------------------------------------------------- + +QT += core gui + +TARGET = EasyStreet +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp + +HEADERS += mainwindow.h + +FORMS += mainwindow.ui + +CONFIG += mobility +MOBILITY = + +symbian { + TARGET.UID3 = 0xe534ca73 + # TARGET.CAPABILITY += + TARGET.EPOCSTACKSIZE = 0x14000 + TARGET.EPOCHEAPSIZE = 0x020000 0x800000 +} diff -r b56d7e268634 -r b9716e8867f1 ListElements/EasyStreet/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/EasyStreet/main.cpp Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,17 @@ +#include +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + +#if defined(Q_WS_S60) + w.showMaximized(); +#else + w.show(); +#endif + + return a.exec(); +} diff -r b56d7e268634 -r b9716e8867f1 ListElements/EasyStreet/mainwindow.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/EasyStreet/mainwindow.cpp Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,31 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + birds << "Avocet" << "Sparrow" << "Crow" << "Sea gull" << "Kookaburra"; + birdList = new QListWidget; + setCentralWidget(birdList); + birdList->addItems(birds); + connect(birdList, SIGNAL(itemClicked ( QListWidgetItem * )), + this, SLOT(displayBird(QListWidgetItem *))); +} + +void MainWindow::displayBird ( QListWidgetItem * item ) +{ + QMessageBox::information(this,"picked", item->text()); +} + +//void MainWindow::on_birdList_itemClicked(QListWidgetItem *item) +//{ +// QMessageBox::information(this, "long", item->text()); +//} + +MainWindow::~MainWindow() +{ + delete ui; +} diff -r b56d7e268634 -r b9716e8867f1 ListElements/EasyStreet/mainwindow.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/EasyStreet/mainwindow.h Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,30 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + +public slots: + void displayBird( QListWidgetItem * item ); + // void on_birdList_itemClicked(QListWidgetItem * ); +private: + QStringList birds; + QListWidget *birdList; + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff -r b56d7e268634 -r b9716e8867f1 ListElements/EasyStreet/mainwindow.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/EasyStreet/mainwindow.ui Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,32 @@ + + + MainWindow + + + + 0 + 0 + 360 + 640 + + + + MainWindow + + + + + + 0 + 0 + 371 + 601 + + + + + + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/assets.qrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/assets.qrc Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,16 @@ + + + images/Taurus.svg + images/Aries.svg + images/Cancer.svg + images/Gemini.svg + images/Leo.svg + images/Scorpio.svg + images/Aquarius.svg + images/Capricorn.svg + images/Libra.svg + images/Pisces.svg + images/Sagittarius.svg + images/Virgo.svg + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Aquarius.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Aquarius.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Aries.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Aries.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Cancer.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Cancer.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Capricorn.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Capricorn.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Gemini.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Gemini.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Leo.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Leo.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Libra.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Libra.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Pisces.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Pisces.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Sagittarius.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Sagittarius.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Scorpio.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Scorpio.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Taurus.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Taurus.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/images/Virgo.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/images/Virgo.svg Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,28 @@ + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/listElements.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/listElements.pro Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,40 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-08-30T10:49:36 +# +#------------------------------------------------- + +QT += core gui svg + +TARGET = test242 +TEMPLATE = app + + +SOURCES += main.cpp\ + zodiacsign.cpp \ + mainwindow.cpp \ + zodiacmodel.cpp \ + zodiacdelegate.cpp + + +HEADERS += mainwindow.h \ + zodiacsign.h \ + zodiacmodel.h \ + zodiacdelegate.h + +FORMS += mainwindow.ui + +CONFIG += mobility +MOBILITY = + +symbian { + TARGET.UID3 = 0xe5e9fbec + # TARGET.CAPABILITY += + TARGET.EPOCSTACKSIZE = 0x14000 + TARGET.EPOCHEAPSIZE = 0x020000 0x800000 +} + +RESOURCES += \ + assets.qrc + +include(../modeltest-0.2/modeltest.pri) diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/main.cpp Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,16 @@ +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.setWindowTitle("Zodiac"); +#if defined(Q_WS_S60) + w.showMaximized(); +#else + w.show(); +#endif + + return a.exec(); +} diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/mainwindow.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/mainwindow.cpp Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,27 @@ +#include + +#include + +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "zodiacmodel.h" +#include "zodiacdelegate.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); +// int heightMain = this->height(); +// int heightBar = menuBar()->height(); + ZodiacModel *zModel = new ZodiacModel(this); +// ModelTest *m = new ModelTest(zModel, this); + ui->listView->setModel(zModel); + ZodiacDelegate *delegate = new ZodiacDelegate(this); + ui->listView->setItemDelegate(delegate); +} + +MainWindow::~MainWindow() +{ + delete ui; +} diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/mainwindow.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/mainwindow.h Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,24 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +#include "zodiacsign.h" + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/mainwindow.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/mainwindow.ui Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,56 @@ + + + MainWindow + + + + 0 + 0 + 360 + 640 + + + + MainWindow + + + + + + 0 + 0 + 361 + 411 + + + + QFrame::Panel + + + QFrame::Raised + + + 4 + + + + + 10 + 10 + 341 + 391 + + + + + 14 + + + + + + + + + + diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/zodiacdelegate.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/zodiacdelegate.cpp Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,41 @@ +#include +#include + + +#include "zodiacdelegate.h" + +void ZodiacDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + painter->save(); + painter->setPen(Qt::red); + painter->setBrush(Qt::yellow); + painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); + + if (option.state & QStyle::State_Selected) { + painter->fillRect(option.rect, option.palette.highlight()); + } + + // draw the svg image. + int xOffset = 10; + int yOffset = 5; + int height = 15; + int width = 15; + QRectF imgRect(option.rect.x()+xOffset,option.rect.y()+yOffset,width,height); + QString svgFile(index.model()->data(index,Qt::DecorationRole).toString()); + QSvgRenderer renderer(svgFile); + renderer.render(painter,imgRect); + + // write the name + int xOffsetText = 55; + QRect rect(option.rect.x()+xOffsetText,option.rect.y(),option.rect.width(), option.rect.height()); + painter->drawText(rect,Qt::AlignVCenter, + index.model()->data(index,Qt::DisplayRole).toString()); + + // just for debugging + QPoint point(option.rect.x()+xOffsetText,option.rect.y()); + painter->drawLine(point+QPoint(-5,0),point+QPoint(5,0)); + painter->drawLine(point+QPoint(0,-5),point+QPoint(0,5)); + + painter->restore(); +} diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/zodiacdelegate.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/zodiacdelegate.h Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,21 @@ +#ifndef ZODIACDELEGATE_H +#define ZODIACDELEGATE_H + +#include +#include +#include +#include + + +class ZodiacDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + explicit ZodiacDelegate(QObject *parent=0):QStyledItemDelegate(parent) {} + + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + +}; + +#endif // ZODIACDELEGATE_H diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/zodiacmodel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/zodiacmodel.cpp Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,131 @@ +#include +#include +#include +#include +#include + +#include "zodiacmodel.h" +#include "zodiacsign.h" + +ZodiacModel::ZodiacModel(QObject *parent) : + QAbstractListModel(parent) +{ + // color names must match SVG standard names http://www.w3.org/TR/SVG/types.html#ColorKeywords + this->signs.push_front( new ZodiacSign("Aries", + ":/images/Aries.svg", + QColor("red"), + QDate(2010,3,20), + QDate(2010,4,20))); + + this->signs.push_front( new ZodiacSign("Taurus", + ":/images/Taurus.svg", + QColor("green"), + QDate(2010,4,20), + QDate(2010,5,21))); + + this->signs.push_front( new ZodiacSign("Gemini", + ":/images/Gemini.svg", + QColor("orange"), + QDate(2010,5,21), + QDate(2010,6,21))); + this->signs.push_front( new ZodiacSign("Cancer", + ":/images/Cancer.svg", + QColor("violet"), + QDate(2010,6,21), + QDate(2010,7,22))); + this->signs.push_front( new ZodiacSign("Leo", + ":/images/Leo.svg", + QColor("yellow"), + QDate(2010,7,22), + QDate(2010,8,23))); + this->signs.push_front( new ZodiacSign("Virgo", + ":/images/Virgo.svg", + QColor("white"), + QDate(2010,8,23), + QDate(2010,9,23))); + + this->signs.push_front( new ZodiacSign("Libra", + ":/images/Libra.svg", + QColor("green"), + QDate(2010,9,23), + QDate(2010,10,23))); + + this->signs.push_front( new ZodiacSign("Scorpio", + ":/images/Scorpio.svg", + QColor("maroon"), + QDate(2010,10,23), + QDate(2010,11,22))); + this->signs.push_front( new ZodiacSign("Sagittarius", + ":/images/Sagittarius.svg", + QColor("blue"), + QDate(2010,11,22), + QDate(2010,12,22))); + this->signs.push_front( new ZodiacSign("Capricorn", + ":/images/Capricorn.svg", + QColor("indigo"), + QDate(2010,12,22), + QDate(2010,1,20))); + this->signs.push_front( new ZodiacSign("Aquarius", + ":/images/Aquarius.svg", + QColor("violet"), + QDate(2010,1,20), + QDate(2010,2,18))); + this->signs.push_front( new ZodiacSign("Pisces", + ":/images/Pisces.svg", + QColor("indigo"), + QDate(2010,1,20), + QDate(2010,2,18))); + +} + +int ZodiacModel::rowCount (const QModelIndex &index) const +{ + return this->signs.count(); +} + +QVariant ZodiacModel::data(const QModelIndex &index, int role)const +{ + QVariant rc; + + if (!index.isValid() || index.row() >= this->signs.size()) { + return rc; + } + switch (role) + { + case Qt::DisplayRole: + { + rc = QVariant(this->signs.at(index.row())->getName()); + break; + } + case Qt::BackgroundRole: + { + // a QBrush consists of a style, color, gradient and texture. + rc = QVariant(QBrush(this->signs.at(index.row())->getColor())); + // TODO: Doesn't the gradient require a rectangle and the Model shouldn't know + // anything about the UI. Strange. +// QLinearGradient gradient; +// gradient.setColorAt(0, QColor(0,136,181)); +// gradient.setColorAt(0.2, QColor(181,231,247)); +// gradient.setColorAt(1, QColor(0,136,181)); + + break; + } + case Qt::TextColorRole: + { + QString name = this->signs.at(index.row())->getName(); + if (name == "Leo" || name == "Virgo") + { + // white text on a white or yellow background doesn't work. Let's change it. + rc = QVariant(QColor("silver")); + } + break; + } + case Qt::DecorationRole: + { + rc = QVariant(this->signs.at(index.row())->getImage()); + } + default: + break; + } + return rc; +} diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/zodiacmodel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/zodiacmodel.h Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,25 @@ +#ifndef ZODIACMODEL_H +#define ZODIACMODEL_H + +#include +#include + +#include "zodiacsign.h" + +class ZodiacModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit ZodiacModel(QObject *parent = 0); + + int rowCount (const QModelIndex &index = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role)const; +signals: + +public slots: + +private: + QList signs; +}; + +#endif // ZODIACMODEL_H diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/zodiacsign.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/zodiacsign.cpp Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,16 @@ +#include "zodiacsign.h" + + + +ZodiacSign::ZodiacSign(QString aName, + QString aUrl, + QColor aColor, + QDate aStart, + QDate aEnd): name(aName), + image(aUrl), + color(aColor), + start(aStart), + end(aEnd) +{ + +} diff -r b56d7e268634 -r b9716e8867f1 ListElements/ModelViewList/zodiacsign.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ListElements/ModelViewList/zodiacsign.h Fri Sep 03 10:38:13 2010 -0700 @@ -0,0 +1,32 @@ +#ifndef ZODIACSIGN_H +#define ZODIACSIGN_H + +#include +#include +#include + + +class ZodiacSign : public QObject +{ + Q_OBJECT +public: + explicit ZodiacSign(QString name, + QString sign, + QColor color, + QDate start, + QDate end); + QString getName() { return name;} + QString getImage() { return image; } + QColor getColor() {return color; } + QDate getStart() {return start; } + QDate getEnd() {return end; } + +private: + QString name; + QString image; + QColor color; + QDate start; + QDate end; +}; + +#endif // ZODIACSIGN_H