42b527a Add listview implementation tentative. With custiom delegate item and custom model.

--- GScribo/GScribo.pro | 8 ++- GScribo/GScribo.pro.user | 40 ++++++++-------- GScribo/itemdelegate.cpp | 26 ++++++++++ GScribo/itemdelegate.h | 17 ++++++ GScribo/listmodel.cpp | 52 ++++++++++++++++++++ GScribo/listmodel.h | 26 ++++++++++ GScribo/mainwindow.cpp | 2 +- GScribo/mainwindow.h | 3 +- GScribo/pageswidget.cpp | 23 ++++----- GScribo/pageswidget.h | 9 ++- MVC/MVC.pro | 13 +++++ TestInterface/GScribo.pro.user => MVC/MVC.pro.user | 46 +++++++++--------- MVC/itemdelegate.cpp | 19 +++++++ MVC/itemdelegate.h | 17 ++++++ MVC/listmodel.cpp | 32 ++++++++++++ MVC/listmodel.h | 24 +++++++++ {NotePad => MVC}/main.cpp | 6 +- MVC/mainwindow.cpp | 40 +++++++++++++++ MVC/mainwindow.h | 30 +++++++++++ MVC/mainwindow.ui | 24 +++++++++ 20 files changed, 391 insertions(+), 66 deletions(-) create mode 100644 GScribo/itemdelegate.cpp create mode 100644 GScribo/itemdelegate.h create mode 100644 GScribo/listmodel.cpp create mode 100644 GScribo/listmodel.h create mode 100644 MVC/MVC.pro copy TestInterface/GScribo.pro.user => MVC/MVC.pro.user (87%) create mode 100644 MVC/itemdelegate.cpp create mode 100644 MVC/itemdelegate.h create mode 100644 MVC/listmodel.cpp create mode 100644 MVC/listmodel.h copy {NotePad => MVC}/main.cpp (60%) create mode 100644 MVC/mainwindow.cpp create mode 100644 MVC/mainwindow.h create mode 100644 MVC/mainwindow.ui diff --git a/GScribo/GScribo.pro b/GScribo/GScribo.pro index ad4abe0..7930307 100644 --- a/GScribo/GScribo.pro +++ b/GScribo/GScribo.pro @@ -17,9 +17,13 @@ SOURCES += main.cpp \ mainwindow.cpp \ scene.cpp \ selection.cpp \ - pageswidget.cpp + pageswidget.cpp \ + itemdelegate.cpp \ + listmodel.cpp HEADERS += mainwindow.h \ scene.h \ selection.h \ - pageswidget.h + pageswidget.h \ + itemdelegate.h \ + listmodel.h FORMS += mainwindow.ui diff --git a/GScribo/GScribo.pro.user b/GScribo/GScribo.pro.user index 6f863ff..92e91c7 100644 --- a/GScribo/GScribo.pro.user +++ b/GScribo/GScribo.pro.user @@ -76,35 +76,35 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Si71aPButo,guid=4a5769b30d2b16bfbff191ee00669e72</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-sncykruQ0C,guid=e454b1a02a95fc6454d7a56d0067ee2b</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-xqG91k</value> - <value type="QString">GNOME_KEYRING_PID=24747</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-8ccgXN</value> + <value type="QString">GNOME_KEYRING_PID=30769</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> <value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value> <value type="QString">LOGNAME=froger_a</value> - <value type="QString">OLDPWD=/lrde/home/stage/froger_a</value> + <value type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</value> <value type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games</value> <value type="QString">PWD=/lrde/home/stage/froger_a/qt/GScribo</value> <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=24822</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-ViaPN24756/agent.24756</value> + <value type="QString">SSH_AGENT_PID=30844</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gtQAz30778/agent.30778</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> - <value type="QString">WINDOWID=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdmDMHCRW</value> + <value type="QString">WINDOWID=12582948</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm3KFZQW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358773046.159332-2135577617</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358858991.561353-1070905078</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> @@ -128,35 +128,35 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Si71aPButo,guid=4a5769b30d2b16bfbff191ee00669e72</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-sncykruQ0C,guid=e454b1a02a95fc6454d7a56d0067ee2b</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-xqG91k</value> - <value type="QString">GNOME_KEYRING_PID=24747</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-8ccgXN</value> + <value type="QString">GNOME_KEYRING_PID=30769</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> <value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value> <value type="QString">LOGNAME=froger_a</value> - <value type="QString">OLDPWD=/lrde/home/stage/froger_a</value> + <value type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</value> <value type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games</value> <value type="QString">PWD=/lrde/home/stage/froger_a/qt/GScribo</value> <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=24822</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-ViaPN24756/agent.24756</value> + <value type="QString">SSH_AGENT_PID=30844</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gtQAz30778/agent.30778</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> - <value type="QString">WINDOWID=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdmDMHCRW</value> + <value type="QString">WINDOWID=12582948</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm3KFZQW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358773046.159332-2135577617</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358858991.561353-1070905078</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> diff --git a/GScribo/itemdelegate.cpp b/GScribo/itemdelegate.cpp new file mode 100644 index 0000000..60f8cd3 --- /dev/null +++ b/GScribo/itemdelegate.cpp @@ -0,0 +1,26 @@ +#include "itemdelegate.h" + +ItemDelegate::ItemDelegate(QWidget *parent): + QItemDelegate(parent) +{ +} + +QWidget * ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex&) const +{ + QLabel *label = new QLabel(parent); + label->setMinimumSize(100, 100); + + return label; +} + +void ItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +{ + QLabel *label = static_cast<QLabel *>(editor); + QPixmap pixmap = index.model()->data(index, Qt::DecorationRole).value<QPixmap>(); + label->setPixmap(pixmap); +} + +void ItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const +{ + editor->setGeometry(option.rect); +} diff --git a/GScribo/itemdelegate.h b/GScribo/itemdelegate.h new file mode 100644 index 0000000..1864ccf --- /dev/null +++ b/GScribo/itemdelegate.h @@ -0,0 +1,17 @@ +#ifndef ITEMDELEGATE_H +#define ITEMDELEGATE_H + +#include <QItemDelegate> +#include <QLabel> + +class ItemDelegate: + public QItemDelegate +{ + public: + explicit ItemDelegate(QWidget *parent = 0); + QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const; +}; + +#endif // ITEMDELEGATE_H diff --git a/GScribo/listmodel.cpp b/GScribo/listmodel.cpp new file mode 100644 index 0000000..4bbe802 --- /dev/null +++ b/GScribo/listmodel.cpp @@ -0,0 +1,52 @@ +#include "listmodel.h" + +ListModel::ListModel(QStringList stringList, QObject *parent): + QAbstractListModel(parent) +{ + this->stringList = stringList; +} + +ListModel::~ListModel() +{ +} + +int ListModel::rowCount(const QModelIndex &/*parent*/) const +{ + return stringList.count(); +} + +QVariant ListModel::data(const QModelIndex &index, int role) const +{ + if(index.isValid() && stringList.size() < index.row() && (role == Qt::DisplayRole || role == Qt::EditRole)) + return stringList.at(index.row()); + else + return QVariant(); +} + +QVariant ListModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(role == Qt::DisplayRole && orientation == Qt::Horizontal) + return QVariant(); + else + return QString("Row %1").arg(section); +} + +/*Qt::ItemFlags ListModel::flags(const QModelIndex &index) const +{ + if(!index.isValid()) + return Qt::ItemIsEnabled; + else + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; +} + +bool ListModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if(index.isValid() && role == Qt::DisplayRole) + { + stringList.replace(index.row(), value.toString()); + emit dataChanged(index, index); + return true; + } + else + return false; +}*/ diff --git a/GScribo/listmodel.h b/GScribo/listmodel.h new file mode 100644 index 0000000..c7f061f --- /dev/null +++ b/GScribo/listmodel.h @@ -0,0 +1,26 @@ +#ifndef LISTMODEL_H +#define LISTMODEL_H + +#include <QAbstractListModel> +#include <QLabel> +#include <QList> + +class ListModel: + public QAbstractListModel +{ + Q_OBJECT + + public: + explicit ListModel(QStringList stringList, QObject *parent = 0); + ~ListModel(); + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role = Qt::DecorationRole) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DecorationRole) const; + /*Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DecorationRole);*/ + + private: + QStringList stringList; +}; + +#endif // LISTMODEL_H diff --git a/GScribo/mainwindow.cpp b/GScribo/mainwindow.cpp index 4ef2aa1..4b68fbe 100644 --- a/GScribo/mainwindow.cpp +++ b/GScribo/mainwindow.cpp @@ -60,7 +60,7 @@ void MainWindow::initTextRegion() dockText->setWidget(textEdit); addDockWidget(Qt::RightDockWidgetArea, dockText); - dockText->hide(); + //dockText->hide(); } void MainWindow::initToolBar() diff --git a/GScribo/mainwindow.h b/GScribo/mainwindow.h index aa80b72..b5355f1 100644 --- a/GScribo/mainwindow.h +++ b/GScribo/mainwindow.h @@ -18,7 +18,8 @@ namespace Ui class MainWindow; } -class MainWindow : public QMainWindow +class MainWindow: + public QMainWindow { Q_OBJECT diff --git a/GScribo/pageswidget.cpp b/GScribo/pageswidget.cpp index 2f23d9d..ed34d84 100644 --- a/GScribo/pageswidget.cpp +++ b/GScribo/pageswidget.cpp @@ -3,28 +3,25 @@ PagesWidget::PagesWidget(QWidget *parent): QWidget(parent) { + QStringList l; + l << "/lrde/home/stage/froger_a/ppm/mp00032c.ppm" << "/lrde/home/stage/froger_a/ppm/mp00042.ppm" << "/lrde/home/stage/froger_a/ppm/mp00076.ppm"; filenames = new QStringList; - scrollArea = new QScrollArea(this); - scrollArea->setGeometry(0, 0, 1000, 1000); - layout = new QHBoxLayout; - QWidget *widget = new QWidget; - widget->setLayout(layout); - scrollArea->setWidget(widget); + model = new ListModel(l); + listView = new QListView(this); + listView->setItemDelegate(new ItemDelegate()); + listView->setModel(model); + listView->update(model->index(0, 0)); + listView->show(); } PagesWidget::~PagesWidget() { delete filenames; - delete layout; - delete scrollArea; + delete listView; } void PagesWidget::addPicture(const QString& filename, const QPixmap& pixmap) { *filenames << filename; - QPixmap pix = pixmap.scaled(100, 100, Qt::IgnoreAspectRatio); - QLabel *label = new QLabel(this); - label->setPixmap(pix); - layout->addWidget(label, 0, Qt::AlignHCenter | Qt::AlignTop); - scrollArea->update(scrollArea->geometry()); + } diff --git a/GScribo/pageswidget.h b/GScribo/pageswidget.h index 3747d20..805deff 100644 --- a/GScribo/pageswidget.h +++ b/GScribo/pageswidget.h @@ -5,8 +5,12 @@ #include <QScrollArea> #include <QVBoxLayout> #include <QListWidget> +#include <QStandardItemModel> #include <QLabel> +#include "itemdelegate.h" +#include "listmodel.h" + class PagesWidget: public QWidget { @@ -14,13 +18,12 @@ class PagesWidget: public: explicit PagesWidget(QWidget *parent = 0); - explicit PagesWidget(QWidgetPrivate &d, QWidget *parent = 0); ~PagesWidget(); void addPicture(const QString& filename, const QPixmap& pixmap); private: - QScrollArea *scrollArea; - QHBoxLayout *layout; + QListView *listView; + ListModel *model; QStringList *filenames; }; diff --git a/MVC/MVC.pro b/MVC/MVC.pro new file mode 100644 index 0000000..1a4d48c --- /dev/null +++ b/MVC/MVC.pro @@ -0,0 +1,13 @@ +# ------------------------------------------------- +# Project created by QtCreator 2013-01-22T16:00:23 +# ------------------------------------------------- +TARGET = MVC +TEMPLATE = app +SOURCES += main.cpp \ + mainwindow.cpp \ + itemdelegate.cpp \ + listmodel.cpp +HEADERS += mainwindow.h \ + listmodel.h \ + itemdelegate.h +FORMS += mainwindow.ui diff --git a/TestInterface/GScribo.pro.user b/MVC/MVC.pro.user similarity index 87% copy from TestInterface/GScribo.pro.user copy to MVC/MVC.pro.user index 4b00d43..c8ef164 100644 --- a/TestInterface/GScribo.pro.user +++ b/MVC/MVC.pro.user @@ -10,11 +10,11 @@ </data> <data> <variable>RunConfiguration0-ProFile</variable> - <value type="QString">GScribo.pro</value> + <value type="QString">MVC.pro</value> </data> <data> <variable>RunConfiguration0-RunConfiguration.name</variable> - <value type="QString">GScribo</value> + <value type="QString">MVC</value> </data> <data> <variable>RunConfiguration0-UseDyldImageSuffix</variable> @@ -76,14 +76,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-dwXmVzGpRA,guid=2e4bb3ce70c39fa5e5288771006655e3</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-sncykruQ0C,guid=e454b1a02a95fc6454d7a56d0067ee2b</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-9aAGCJ</value> - <value type="QString">GNOME_KEYRING_PID=19876</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-8ccgXN</value> + <value type="QString">GNOME_KEYRING_PID=30769</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> @@ -91,20 +91,20 @@ <value type="QString">LOGNAME=froger_a</value> <value type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</value> <value type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games</value> - <value type="QString">PWD=/lrde/home/stage/froger_a/qt/GScribo</value> + <value type="QString">PWD=/lrde/home/stage/froger_a/qt/MVC</value> <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=19951</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-kVrax19885/agent.19885</value> + <value type="QString">SSH_AGENT_PID=30844</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gtQAz30778/agent.30778</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> <value type="QString">WINDOWID=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm0ICXQW</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm3KFZQW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358754471.558659-246518931</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358858991.561353-1070905078</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> @@ -112,7 +112,7 @@ <value type="QString">_=/usr/bin/qtcreator</value> </valuelist> <valuelist key="abstractProcess.arguments" type="QVariantList"> - <value type="QString">/amd/nfs/volume1/home/stage/froger_a/qt/GScribo/GScribo.pro</value> + <value type="QString">/amd/nfs/volume1/home/stage/froger_a/qt/MVC/MVC.pro</value> <value type="QString">-spec</value> <value type="QString">linux-g++</value> <value type="QString">-r</value> @@ -120,7 +120,7 @@ </valuelist> <value key="abstractProcess.command" type="QString">/usr/bin/qmake-qt4</value> <value key="abstractProcess.enabled" type="bool">false</value> - <value key="abstractProcess.workingDirectory" type="QString">/amd/nfs/volume1/home/stage/froger_a/qt/GScribo</value> + <value key="abstractProcess.workingDirectory" type="QString">/amd/nfs/volume1/home/stage/froger_a/qt/MVC</value> </valuemap> </data> <data> @@ -128,14 +128,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-dwXmVzGpRA,guid=2e4bb3ce70c39fa5e5288771006655e3</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-sncykruQ0C,guid=e454b1a02a95fc6454d7a56d0067ee2b</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-9aAGCJ</value> - <value type="QString">GNOME_KEYRING_PID=19876</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-8ccgXN</value> + <value type="QString">GNOME_KEYRING_PID=30769</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> @@ -143,20 +143,20 @@ <value type="QString">LOGNAME=froger_a</value> <value type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</value> <value type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games</value> - <value type="QString">PWD=/lrde/home/stage/froger_a/qt/GScribo</value> + <value type="QString">PWD=/lrde/home/stage/froger_a/qt/MVC</value> <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=19951</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-kVrax19885/agent.19885</value> + <value type="QString">SSH_AGENT_PID=30844</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gtQAz30778/agent.30778</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> <value type="QString">WINDOWID=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm0ICXQW</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm3KFZQW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358754471.558659-246518931</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358858991.561353-1070905078</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> @@ -169,7 +169,7 @@ </valuelist> <value key="abstractProcess.command" type="QString">/usr/bin/make</value> <value key="abstractProcess.enabled" type="bool">true</value> - <value key="abstractProcess.workingDirectory" type="QString">/amd/nfs/volume1/home/stage/froger_a/qt/GScribo</value> + <value key="abstractProcess.workingDirectory" type="QString">/amd/nfs/volume1/home/stage/froger_a/qt/MVC</value> </valuemap> </data> <data> diff --git a/MVC/itemdelegate.cpp b/MVC/itemdelegate.cpp new file mode 100644 index 0000000..c241e1e --- /dev/null +++ b/MVC/itemdelegate.cpp @@ -0,0 +1,19 @@ +#include "itemdelegate.h" + +ItemDelegate::ItemDelegate(QWidget *parent): + QAbstractItemDelegate(parent) +{ +} + +void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QString path = index.model()->data(index, Qt::DecorationRole).toString(); + QPixmap pixmap(path); + + painter->drawPixmap(0, index.row() * 210, 200, 200, pixmap); +} + +QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + return QSize(200, 200); +} diff --git a/MVC/itemdelegate.h b/MVC/itemdelegate.h new file mode 100644 index 0000000..1c653d5 --- /dev/null +++ b/MVC/itemdelegate.h @@ -0,0 +1,17 @@ +#ifndef ITEMDELEGATE_H +#define ITEMDELEGATE_H + +#include <QItemDelegate> +#include <QLabel> +#include <QPainter> + +class ItemDelegate: + public QAbstractItemDelegate +{ + public: + explicit ItemDelegate(QWidget *parent = 0); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; +}; + +#endif // ITEMDELEGATE_H diff --git a/MVC/listmodel.cpp b/MVC/listmodel.cpp new file mode 100644 index 0000000..709853e --- /dev/null +++ b/MVC/listmodel.cpp @@ -0,0 +1,32 @@ +#include "listmodel.h" + +ListModel::ListModel(QStringList list, QObject *parent): + QAbstractListModel(parent) +{ + this->list = list; +} + +ListModel::~ListModel() +{ +} + +int ListModel::rowCount(const QModelIndex &/*parent*/) const +{ + return list.count(); +} + +QVariant ListModel::data(const QModelIndex &index, int role) const +{ + if(index.isValid() && index.row() < list.size() && role == Qt::DecorationRole) + return list.at(index.row()); + else + return QVariant(); +} + +QVariant ListModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(role != Qt::DecorationRole && orientation == Qt::Horizontal) + return QVariant(); + else + return QString("Row %1").arg(section); +} diff --git a/MVC/listmodel.h b/MVC/listmodel.h new file mode 100644 index 0000000..35ae99c --- /dev/null +++ b/MVC/listmodel.h @@ -0,0 +1,24 @@ +#ifndef LISTMODEL_H +#define LISTMODEL_H + +#include <QAbstractListModel> +#include <QLabel> +#include <QList> + +class ListModel: + public QAbstractListModel +{ + Q_OBJECT + + public: + explicit ListModel(QStringList list, QObject *parent = 0); + ~ListModel(); + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DecorationRole) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DecorationRole) const; + + private: + QStringList list; +}; + +#endif // LISTMODEL_H diff --git a/NotePad/main.cpp b/MVC/main.cpp similarity index 60% copy from NotePad/main.cpp copy to MVC/main.cpp index 137c3a4..ab61e7c 100644 --- a/NotePad/main.cpp +++ b/MVC/main.cpp @@ -1,11 +1,11 @@ #include <QtGui/QApplication> -#include "notepad.h" +#include "mainwindow.h" int main(int argc, char *argv[]) { + QApplication::setGraphicsSystem("raster"); QApplication a(argc, argv); - NotePad w; + MainWindow w; w.show(); - return a.exec(); } diff --git a/MVC/mainwindow.cpp b/MVC/mainwindow.cpp new file mode 100644 index 0000000..72bf823 --- /dev/null +++ b/MVC/mainwindow.cpp @@ -0,0 +1,40 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + QStringList list; + list << "/lrde/home/stage/froger_a/ppm/mp00032c.ppm" << "/lrde/home/stage/froger_a/ppm/mp00042.ppm" << "/lrde/home/stage/froger_a/ppm/mp00076.ppm"; + + QAbstractItemModel *model = new ListModel(list); + + ItemDelegate *delegate = new ItemDelegate(); + + QListView *view = new QListView; + view->setModel(model); + view->setItemDelegate(delegate); + setCentralWidget(view); + view->show(); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::changeEvent(QEvent *e) +{ + QMainWindow::changeEvent(e); + switch (e->type()) + { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} diff --git a/MVC/mainwindow.h b/MVC/mainwindow.h new file mode 100644 index 0000000..8bf225d --- /dev/null +++ b/MVC/mainwindow.h @@ -0,0 +1,30 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <QListView> + +#include "itemdelegate.h" +#include "listmodel.h" + +namespace Ui +{ + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + + public: + MainWindow(QWidget *parent = 0); + ~MainWindow(); + + protected: + void changeEvent(QEvent *e); + + private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/MVC/mainwindow.ui b/MVC/mainwindow.ui new file mode 100644 index 0000000..97c03be --- /dev/null +++ b/MVC/mainwindow.ui @@ -0,0 +1,24 @@ +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>400</height> + </rect> + </property> + <property name="windowTitle" > + <string>MainWindow</string> + </property> + <widget class="QMenuBar" name="menuBar" /> + <widget class="QToolBar" name="mainToolBar" /> + <widget class="QWidget" name="centralWidget" /> + <widget class="QStatusBar" name="statusBar" /> + </widget> + <layoutDefault spacing="6" margin="11" /> + <pixmapfunction></pixmapfunction> + <resources/> + <connections/> +</ui> -- 1.7.2.5
participants (1)
-
Antoine Froger