
--- GScribo/GScribo.pro | 8 +- GScribo/GScribo.pro.user | 36 ++++---- GScribo/icon.cpp | 26 +++++ GScribo/icon.h | 21 ++++ GScribo/itemdelegate.cpp | 26 ----- GScribo/itemdelegate.h | 17 ---- GScribo/listmodel.cpp | 50 +++------- GScribo/listmodel.h | 11 +-- GScribo/mainwindow.cpp | 97 ------------------- GScribo/mainwindow.h | 52 ---------- GScribo/pageswidget.cpp | 30 ++---- GScribo/pageswidget.h | 19 ++--- GScribo/ui_mainwindow.h | 73 ++++++++++++++ MVC/MVC.pro.user | 32 +++--- MVC/itemdelegate.cpp | 4 +- MVC/ui_mainwindow.h | 70 ++++++++++++++ gmvc/gmodel.cpp | 162 ++++++++++++++++++++++++++++++++ gmvc/gmodel.h | 34 +++++++ MVC/MVC.pro => gmvc/gmvc.pro | 12 +- MVC/MVC.pro.user => gmvc/gmvc.pro.user | 46 +++++----- {MVC => gmvc}/main.cpp | 0 gmvc/mainwindow.cpp | 51 ++++++++++ gmvc/mainwindow.h | 28 ++++++ {MVC => gmvc}/mainwindow.ui | 0 gmvc/model.cpp | 37 +++++++ gmvc/model.h | 20 ++++ 26 files changed, 627 insertions(+), 335 deletions(-) create mode 100644 GScribo/icon.cpp create mode 100644 GScribo/icon.h delete mode 100644 GScribo/itemdelegate.cpp delete mode 100644 GScribo/itemdelegate.h delete mode 100644 GScribo/mainwindow.cpp delete mode 100644 GScribo/mainwindow.h create mode 100644 GScribo/ui_mainwindow.h create mode 100644 MVC/ui_mainwindow.h create mode 100644 gmvc/gmodel.cpp create mode 100644 gmvc/gmodel.h copy MVC/MVC.pro => gmvc/gmvc.pro (59%) copy MVC/MVC.pro.user => gmvc/gmvc.pro.user (87%) copy {MVC => gmvc}/main.cpp (100%) create mode 100644 gmvc/mainwindow.cpp create mode 100644 gmvc/mainwindow.h copy {MVC => gmvc}/mainwindow.ui (100%) create mode 100644 gmvc/model.cpp create mode 100644 gmvc/model.h diff --git a/GScribo/GScribo.pro b/GScribo/GScribo.pro index 7930307..57041dc 100644 --- a/GScribo/GScribo.pro +++ b/GScribo/GScribo.pro @@ -18,12 +18,12 @@ SOURCES += main.cpp \ scene.cpp \ selection.cpp \ pageswidget.cpp \ - itemdelegate.cpp \ - listmodel.cpp + listmodel.cpp \ + icon.cpp HEADERS += mainwindow.h \ scene.h \ selection.h \ pageswidget.h \ - itemdelegate.h \ - listmodel.h + listmodel.h \ + icon.h FORMS += mainwindow.ui diff --git a/GScribo/GScribo.pro.user b/GScribo/GScribo.pro.user index 92e91c7..13a97a6 100644 --- a/GScribo/GScribo.pro.user +++ b/GScribo/GScribo.pro.user @@ -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-sncykruQ0C,guid=e454b1a02a95fc6454d7a56d0067ee2b</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-0VAN4sEd5T,guid=75a5318e040070f8fcb70ccf006944fa</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-8ccgXN</value> - <value type="QString">GNOME_KEYRING_PID=30769</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-nVYZaO</value> + <value type="QString">GNOME_KEYRING_PID=27939</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> @@ -95,16 +95,16 @@ <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=30844</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gtQAz30778/agent.30778</value> + <value type="QString">SSH_AGENT_PID=28014</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-yzfMR27948/agent.27948</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=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">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:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmBDX0QW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358858991.561353-1070905078</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358946750.592912-119709926</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,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-sncykruQ0C,guid=e454b1a02a95fc6454d7a56d0067ee2b</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-0VAN4sEd5T,guid=75a5318e040070f8fcb70ccf006944fa</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-8ccgXN</value> - <value type="QString">GNOME_KEYRING_PID=30769</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-nVYZaO</value> + <value type="QString">GNOME_KEYRING_PID=27939</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> @@ -147,16 +147,16 @@ <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=30844</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gtQAz30778/agent.30778</value> + <value type="QString">SSH_AGENT_PID=28014</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-yzfMR27948/agent.27948</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=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">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:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmBDX0QW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358858991.561353-1070905078</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358946750.592912-119709926</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/icon.cpp b/GScribo/icon.cpp new file mode 100644 index 0000000..5aca60f --- /dev/null +++ b/GScribo/icon.cpp @@ -0,0 +1,26 @@ +#include "icon.h" + +Icon::Icon(const QPixmap &pixmap) : + QIcon(pixmap) +{ +} + +QString Icon::path() const +{ + return filename; +} + +QPixmap * Icon::pixmap() +{ + return pix; +} + +void Icon::setPath(QString path) +{ + filename = path; +} + +void Icon::setPixmap(QPixmap *pixmap) +{ + pix = pixmap; +} diff --git a/GScribo/icon.h b/GScribo/icon.h new file mode 100644 index 0000000..ebedbe7 --- /dev/null +++ b/GScribo/icon.h @@ -0,0 +1,21 @@ +#ifndef ICON_H +#define ICON_H + +#include <QIcon> + +class Icon : + QIcon +{ + public: + explicit Icon(const QPixmap& pixmap); + QString path() const; + QPixmap * pixmap(); + void setPath(QString path); + void setPixmap(QPixmap *pixmap); + + private: + QString filename; + QPixmap *pix; +}; + +#endif // ICON_H diff --git a/GScribo/itemdelegate.cpp b/GScribo/itemdelegate.cpp deleted file mode 100644 index 60f8cd3..0000000 --- a/GScribo/itemdelegate.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#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 deleted file mode 100644 index 1864ccf..0000000 --- a/GScribo/itemdelegate.h +++ /dev/null @@ -1,17 +0,0 @@ -#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 index 4bbe802..de0087a 100644 --- a/GScribo/listmodel.cpp +++ b/GScribo/listmodel.cpp @@ -1,52 +1,30 @@ #include "listmodel.h" -ListModel::ListModel(QStringList stringList, QObject *parent): +ListModel::ListModel(QObject *parent): QAbstractListModel(parent) { - this->stringList = stringList; } -ListModel::~ListModel() +int ListModel::rowCount(const QModelIndex&) const { + return pixmaps.size(); } -int ListModel::rowCount(const QModelIndex &/*parent*/) const +QVariant ListModel::data(const QModelIndex& index, int role) 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 + if(!index.isValid()) 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); -} + if(role == Qt::DecorationRole) + return QIcon(pixmaps.value(index.row()).scaled(QSize(200, 200), Qt::KeepAspectRatio, Qt::SmoothTransformation)); -/*Qt::ItemFlags ListModel::flags(const QModelIndex &index) const -{ - if(!index.isValid()) - return Qt::ItemIsEnabled; - else - return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; + return QVariant(); } -bool ListModel::setData(const QModelIndex &index, const QVariant &value, int role) +void ListModel::addPixmap(const QPixmap& pixmap) { - if(index.isValid() && role == Qt::DisplayRole) - { - stringList.replace(index.row(), value.toString()); - emit dataChanged(index, index); - return true; - } - else - return false; -}*/ + int row = pixmaps.size(); + beginInsertRows(QModelIndex(), row, row); + pixmaps.insert(row, pixmap); + endInsertRows(); +} diff --git a/GScribo/listmodel.h b/GScribo/listmodel.h index c7f061f..03469b5 100644 --- a/GScribo/listmodel.h +++ b/GScribo/listmodel.h @@ -2,7 +2,7 @@ #define LISTMODEL_H #include <QAbstractListModel> -#include <QLabel> +#include <QIcon> #include <QList> class ListModel: @@ -11,16 +11,13 @@ class ListModel: Q_OBJECT public: - explicit ListModel(QStringList stringList, QObject *parent = 0); - ~ListModel(); + explicit ListModel(QObject *parent = 0); 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);*/ + void addPixmap(const QPixmap& pixmap); private: - QStringList stringList; + QList<QPixmap> pixmaps; }; #endif // LISTMODEL_H diff --git a/GScribo/mainwindow.cpp b/GScribo/mainwindow.cpp deleted file mode 100644 index 4b68fbe..0000000 --- a/GScribo/mainwindow.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - - initGraphicsRegion(); - initTextRegion(); - initTablePage(); - initToolBar(); -} - -MainWindow::~MainWindow() -{ - delete dockText; - delete dockPages; - delete scene; - delete graphicsView; - delete textEdit; - delete ui; -} - -void MainWindow::initGraphicsRegion() -{ - graphicsView = new QGraphicsView; - // Cache backgroud to speed up its repaint. - graphicsView->setCacheMode(QGraphicsView::CacheBackground); - graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); - - scene = new Scene(); - // Disable scroll bar extend with a non-null rectangle. - scene->setSceneRect(0, 0, 0, 1); - graphicsView->setScene(scene); - - setCentralWidget(graphicsView); -} - -void MainWindow::initTablePage() -{ - dockPages = new QDockWidget(tr("Pages")); - dockPages->setAllowedAreas(Qt::AllDockWidgetAreas); - dockPages->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable); - - pagesWidget = new PagesWidget; - dockPages->setWidget(pagesWidget); - - addDockWidget(Qt::LeftDockWidgetArea, dockPages); -} - -void MainWindow::initTextRegion() -{ - dockText = new QDockWidget(tr("Previsualization")); - dockText->setAllowedAreas(Qt::AllDockWidgetAreas); - dockText->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); - - textEdit = new QPlainTextEdit; - dockText->setWidget(textEdit); - - addDockWidget(Qt::RightDockWidgetArea, dockText); - //dockText->hide(); -} - -void MainWindow::initToolBar() -{ - QAction *open = ui->mainToolBar->addAction(tr("Open")); - connect(open, SIGNAL(triggered()), this, SLOT(onOpen())); -} - -void MainWindow::onOpen() -{ - QString path = QFileDialog::getOpenFileName(this); - if(path != "") - { - QPixmap pixmap(path); - - scene->setSceneRect(pixmap.rect()); - scene->setBackgroundBrush(QBrush(pixmap)); - - pagesWidget->addPicture(path, pixmap); - } -} - -void MainWindow::changeEvent(QEvent *e) -{ - QMainWindow::changeEvent(e); - switch (e->type()) - { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} diff --git a/GScribo/mainwindow.h b/GScribo/mainwindow.h deleted file mode 100644 index b5355f1..0000000 --- a/GScribo/mainwindow.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include <QMainWindow> -#include <QHBoxLayout> -#include <QDockWidget> -#include <QGraphicsView> -#include <QGLWidget> -#include <QPlainTextEdit> -#include <QGroupBox> -#include <QFileDialog> - -#include "scene.h" -#include "pageswidget.h" - -namespace Ui -{ - class MainWindow; -} - -class MainWindow: - public QMainWindow -{ - Q_OBJECT - - public: - MainWindow(QWidget *parent = 0); - ~MainWindow(); - - protected: - void changeEvent(QEvent *e); - - private: - void initGraphicsRegion(); - void initTextRegion(); - void initToolBar(); - void initTablePage(); - - Ui::MainWindow *ui; - QDockWidget *dockText; - QDockWidget *dockPages; - Scene *scene; - QGraphicsView *graphicsView; - QPlainTextEdit *textEdit; - PagesWidget *pagesWidget; - QString imagePath; - - private slots: - void onOpen(); -}; - -#endif // MAINWINDOW_H diff --git a/GScribo/pageswidget.cpp b/GScribo/pageswidget.cpp index ed34d84..1652062 100644 --- a/GScribo/pageswidget.cpp +++ b/GScribo/pageswidget.cpp @@ -1,27 +1,19 @@ #include "pageswidget.h" PagesWidget::PagesWidget(QWidget *parent): - QWidget(parent) + QListView(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; - model = new ListModel(l); - listView = new QListView(this); - listView->setItemDelegate(new ItemDelegate()); - listView->setModel(model); - listView->update(model->index(0, 0)); - listView->show(); + setUniformItemSizes(true); + setViewMode(QListView::IconMode); + setIconSize(QSize(200, 200)); + setFlow(QListView::TopToBottom); + setMovement(QListView::Static); + setSpacing(10); + setWrapping(false); + setModel(&model); } -PagesWidget::~PagesWidget() +void PagesWidget::addPixmap(const QString& filename, const QPixmap &pixmap) { - delete filenames; - delete listView; -} - -void PagesWidget::addPicture(const QString& filename, const QPixmap& pixmap) -{ - *filenames << filename; - + model.addPixmap(pixmap); } diff --git a/GScribo/pageswidget.h b/GScribo/pageswidget.h index 805deff..fade0d6 100644 --- a/GScribo/pageswidget.h +++ b/GScribo/pageswidget.h @@ -2,29 +2,24 @@ #define PAGESWIDGET_H #include <QWidget> -#include <QScrollArea> -#include <QVBoxLayout> -#include <QListWidget> -#include <QStandardItemModel> -#include <QLabel> +#include <QListView> +#include <QPainter> +#include <QPushButton> +#include <QScrollBar> -#include "itemdelegate.h" #include "listmodel.h" class PagesWidget: - public QWidget + public QListView { Q_OBJECT public: explicit PagesWidget(QWidget *parent = 0); - ~PagesWidget(); - void addPicture(const QString& filename, const QPixmap& pixmap); + void addPixmap(const QString& filename, const QPixmap& pixmap); private: - QListView *listView; - ListModel *model; - QStringList *filenames; + ListModel model; }; #endif // PAGESWIDGET_H diff --git a/GScribo/ui_mainwindow.h b/GScribo/ui_mainwindow.h new file mode 100644 index 0000000..7ba54a5 --- /dev/null +++ b/GScribo/ui_mainwindow.h @@ -0,0 +1,73 @@ +/******************************************************************************** +** Form generated from reading UI file 'mainwindow.ui' +** +** Created: Wed Jan 23 15:39:30 2013 +** by: Qt User Interface Compiler version 4.6.3 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_MAINWINDOW_H +#define UI_MAINWINDOW_H + +#include <QtCore/QVariant> +#include <QtGui/QAction> +#include <QtGui/QApplication> +#include <QtGui/QButtonGroup> +#include <QtGui/QHeaderView> +#include <QtGui/QMainWindow> +#include <QtGui/QMenuBar> +#include <QtGui/QStatusBar> +#include <QtGui/QToolBar> +#include <QtGui/QWidget> + +QT_BEGIN_NAMESPACE + +class Ui_MainWindow +{ +public: + QWidget *centralWidget; + QMenuBar *menuBar; + QToolBar *mainToolBar; + QStatusBar *statusBar; + + void setupUi(QMainWindow *MainWindow) + { + if (MainWindow->objectName().isEmpty()) + MainWindow->setObjectName(QString::fromUtf8("MainWindow")); + MainWindow->resize(671, 436); + centralWidget = new QWidget(MainWindow); + centralWidget->setObjectName(QString::fromUtf8("centralWidget")); + centralWidget->setEnabled(true); + MainWindow->setCentralWidget(centralWidget); + menuBar = new QMenuBar(MainWindow); + menuBar->setObjectName(QString::fromUtf8("menuBar")); + menuBar->setGeometry(QRect(0, 0, 671, 23)); + MainWindow->setMenuBar(menuBar); + mainToolBar = new QToolBar(MainWindow); + mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); + mainToolBar->setFloatable(false); + MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar); + statusBar = new QStatusBar(MainWindow); + statusBar->setObjectName(QString::fromUtf8("statusBar")); + MainWindow->setStatusBar(statusBar); + + retranslateUi(MainWindow); + + QMetaObject::connectSlotsByName(MainWindow); + } // setupUi + + void retranslateUi(QMainWindow *MainWindow) + { + MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8)); + } // retranslateUi + +}; + +namespace Ui { + class MainWindow: public Ui_MainWindow {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_MAINWINDOW_H diff --git a/MVC/MVC.pro.user b/MVC/MVC.pro.user index c8ef164..1c6e9ba 100644 --- a/MVC/MVC.pro.user +++ b/MVC/MVC.pro.user @@ -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-sncykruQ0C,guid=e454b1a02a95fc6454d7a56d0067ee2b</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-iL4mXwl7ak,guid=7e9603aab929b1f1fce663d30068f708</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-8ccgXN</value> - <value type="QString">GNOME_KEYRING_PID=30769</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-kN7FtK</value> + <value type="QString">GNOME_KEYRING_PID=25582</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> @@ -95,16 +95,16 @@ <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=30844</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gtQAz30778/agent.30778</value> + <value type="QString">SSH_AGENT_PID=25657</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-RiFAp25591/agent.25591</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:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm3KFZQW</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:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmJKU1QW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358858991.561353-1070905078</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358926796.562496-56304996</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,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-sncykruQ0C,guid=e454b1a02a95fc6454d7a56d0067ee2b</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-iL4mXwl7ak,guid=7e9603aab929b1f1fce663d30068f708</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-8ccgXN</value> - <value type="QString">GNOME_KEYRING_PID=30769</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-kN7FtK</value> + <value type="QString">GNOME_KEYRING_PID=25582</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> @@ -147,16 +147,16 @@ <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=30844</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gtQAz30778/agent.30778</value> + <value type="QString">SSH_AGENT_PID=25657</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-RiFAp25591/agent.25591</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:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm3KFZQW</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:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmJKU1QW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358858991.561353-1070905078</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358926796.562496-56304996</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/MVC/itemdelegate.cpp b/MVC/itemdelegate.cpp index c241e1e..5f67a91 100644 --- a/MVC/itemdelegate.cpp +++ b/MVC/itemdelegate.cpp @@ -7,7 +7,7 @@ ItemDelegate::ItemDelegate(QWidget *parent): void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - QString path = index.model()->data(index, Qt::DecorationRole).toString(); + QString path = index.data(Qt::DecorationRole).toString(); QPixmap pixmap(path); painter->drawPixmap(0, index.row() * 210, 200, 200, pixmap); @@ -15,5 +15,5 @@ void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - return QSize(200, 200); + return QSize(200, 400); } diff --git a/MVC/ui_mainwindow.h b/MVC/ui_mainwindow.h new file mode 100644 index 0000000..48f2cce --- /dev/null +++ b/MVC/ui_mainwindow.h @@ -0,0 +1,70 @@ +/******************************************************************************** +** Form generated from reading UI file 'mainwindow.ui' +** +** Created: Wed Jan 23 08:52:24 2013 +** by: Qt User Interface Compiler version 4.6.3 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_MAINWINDOW_H +#define UI_MAINWINDOW_H + +#include <QtCore/QVariant> +#include <QtGui/QAction> +#include <QtGui/QApplication> +#include <QtGui/QButtonGroup> +#include <QtGui/QHeaderView> +#include <QtGui/QMainWindow> +#include <QtGui/QMenuBar> +#include <QtGui/QStatusBar> +#include <QtGui/QToolBar> +#include <QtGui/QWidget> + +QT_BEGIN_NAMESPACE + +class Ui_MainWindow +{ +public: + QMenuBar *menuBar; + QToolBar *mainToolBar; + QWidget *centralWidget; + QStatusBar *statusBar; + + void setupUi(QMainWindow *MainWindow) + { + if (MainWindow->objectName().isEmpty()) + MainWindow->setObjectName(QString::fromUtf8("MainWindow")); + MainWindow->resize(600, 400); + menuBar = new QMenuBar(MainWindow); + menuBar->setObjectName(QString::fromUtf8("menuBar")); + MainWindow->setMenuBar(menuBar); + mainToolBar = new QToolBar(MainWindow); + mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); + MainWindow->addToolBar(mainToolBar); + centralWidget = new QWidget(MainWindow); + centralWidget->setObjectName(QString::fromUtf8("centralWidget")); + MainWindow->setCentralWidget(centralWidget); + statusBar = new QStatusBar(MainWindow); + statusBar->setObjectName(QString::fromUtf8("statusBar")); + MainWindow->setStatusBar(statusBar); + + retranslateUi(MainWindow); + + QMetaObject::connectSlotsByName(MainWindow); + } // setupUi + + void retranslateUi(QMainWindow *MainWindow) + { + MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8)); + } // retranslateUi + +}; + +namespace Ui { + class MainWindow: public Ui_MainWindow {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_MAINWINDOW_H diff --git a/gmvc/gmodel.cpp b/gmvc/gmodel.cpp new file mode 100644 index 0000000..38a2aa3 --- /dev/null +++ b/gmvc/gmodel.cpp @@ -0,0 +1,162 @@ +#include "gmodel.h" + +gModel::gModel(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QVariant gModel::data(const QModelIndex &index, int role) const + { + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DecorationRole) + return QIcon(pixmaps.value(index.row()).scaled(60, 60, + Qt::KeepAspectRatio, Qt::SmoothTransformation)); + /*else if (role == Qt::UserRole) + return pixmaps.value(index.row()); + else if (role == Qt::UserRole + 1) + return locations.value(index.row());*/ + + return QVariant(); + } + + void gModel::addPiece(const QPixmap &pixmap, const QPoint &location) + { + /*int row; + if (int(2.0*qrand()/(RAND_MAX+1.0)) == 1) + row = 0; + else + row = pixmaps.size();*/ + int row = pixmaps.size(); + + beginInsertRows(QModelIndex(), row, row); + pixmaps.insert(row, pixmap); + //locations.insert(row, location); + endInsertRows(); + } + + /*Qt::ItemFlags gModel::flags(const QModelIndex &index) const + { + if (index.isValid()) + return (Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled); + + return Qt::ItemIsDropEnabled; + }*/ + + /*bool gModel::removeRows(int row, int count, const QModelIndex &parent) + { + if (parent.isValid()) + return false; + + if (row >= pixmaps.size() || row + count <= 0) + return false; + + int beginRow = qMax(0, row); + int endRow = qMin(row + count - 1, pixmaps.size() - 1); + + beginRemoveRows(parent, beginRow, endRow); + + while (beginRow <= endRow) { + pixmaps.removeAt(beginRow); + locations.removeAt(beginRow); + ++beginRow; + } + + endRemoveRows(); + return true; + }*/ + + /*QStringList gModel::mimeTypes() const + { + QStringList types; + types << "image/x-puzzle-piece"; + return types; + }*/ + + /*QMimeData *gModel::mimeData(const QModelIndexList &indexes) const + { + QMimeData *mimeData = new QMimeData(); + QByteArray encodedData; + + QDataStream stream(&encodedData, QIODevice::WriteOnly); + + foreach (QModelIndex index, indexes) { + if (index.isValid()) { + QPixmap pixmap = qVariantValue<QPixmap>(data(index, Qt::UserRole)); + QPoint location = data(index, Qt::UserRole+1).toPoint(); + stream << pixmap << location; + } + } + + mimeData->setData("image/x-puzzle-piece", encodedData); + return mimeData; + }*/ + + /*bool gModel::dropMimeData(const QMimeData *data, Qt::DropAction action, + int row, int column, const QModelIndex &parent) + { + if (!data->hasFormat("image/x-puzzle-piece")) + return false; + + if (action == Qt::IgnoreAction) + return true; + + if (column > 0) + return false; + + int endRow; + + if (!parent.isValid()) { + if (row < 0) + endRow = pixmaps.size(); + else + endRow = qMin(row, pixmaps.size()); + } else + endRow = parent.row(); + + QByteArray encodedData = data->data("image/x-puzzle-piece"); + QDataStream stream(&encodedData, QIODevice::ReadOnly); + + while (!stream.atEnd()) { + QPixmap pixmap; + QPoint location; + stream >> pixmap >> location; + + beginInsertRows(QModelIndex(), endRow, endRow); + pixmaps.insert(endRow, pixmap); + locations.insert(endRow, location); + endInsertRows(); + + ++endRow; + } + + return true; + }*/ + + int gModel::rowCount(const QModelIndex &parent) const + { + if (parent.isValid()) + return 0; + else + return pixmaps.size(); + } + + /*Qt::DropActions gModel::supportedDropActions() const + { + return Qt::CopyAction | Qt::MoveAction; + }*/ + +/* void gModel::addPieces(const QPixmap& pixmap) + { + beginRemoveRows(QModelIndex(), 0, 24); + pixmaps.clear(); + locations.clear(); + endRemoveRows(); + for (int y = 0; y < 5; ++y) { + for (int x = 0; x < 5; ++x) { + QPixmap pieceImage = pixmap.copy(x*80, y*80, 80, 80); + addPiece(pieceImage, QPoint(x, y)); + } + } + }*/ diff --git a/gmvc/gmodel.h b/gmvc/gmodel.h new file mode 100644 index 0000000..3e5a787 --- /dev/null +++ b/gmvc/gmodel.h @@ -0,0 +1,34 @@ +#ifndef GMODEL_H +#define GMODEL_H + +#include <QAbstractListModel> +#include <QPixmap> +#include <QIcon> +#include <QMimeData> + +class gModel : + public QAbstractListModel +{ + public: + gModel(QObject *parent = 0); + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + //Qt::ItemFlags flags(const QModelIndex &index) const; + //bool removeRows(int row, int count, const QModelIndex &parent); + + //bool dropMimeData(const QMimeData *data, Qt::DropAction action, + // int row, int column, const QModelIndex &parent); + //QMimeData *mimeData(const QModelIndexList &indexes) const; + //QStringList mimeTypes() const; + int rowCount(const QModelIndex &parent) const; + //Qt::DropActions supportedDropActions() const; + + void addPiece(const QPixmap &pixmap, const QPoint &location); + //void addPieces(const QPixmap& pixmap); + + private: + QList<QPoint> locations; + QList<QPixmap> pixmaps; +}; + +#endif // GMODEL_H diff --git a/MVC/MVC.pro b/gmvc/gmvc.pro similarity index 59% copy from MVC/MVC.pro copy to gmvc/gmvc.pro index 1a4d48c..81e49e5 100644 --- a/MVC/MVC.pro +++ b/gmvc/gmvc.pro @@ -1,13 +1,13 @@ # ------------------------------------------------- -# Project created by QtCreator 2013-01-22T16:00:23 +# Project created by QtCreator 2013-01-23T09:31:00 # ------------------------------------------------- -TARGET = MVC +TARGET = gmvc TEMPLATE = app SOURCES += main.cpp \ mainwindow.cpp \ - itemdelegate.cpp \ - listmodel.cpp + model.cpp \ + gmodel.cpp HEADERS += mainwindow.h \ - listmodel.h \ - itemdelegate.h + model.h \ + gmodel.h FORMS += mainwindow.ui diff --git a/MVC/MVC.pro.user b/gmvc/gmvc.pro.user similarity index 87% copy from MVC/MVC.pro.user copy to gmvc/gmvc.pro.user index c8ef164..4a75b91 100644 --- a/MVC/MVC.pro.user +++ b/gmvc/gmvc.pro.user @@ -10,11 +10,11 @@ </data> <data> <variable>RunConfiguration0-ProFile</variable> - <value type="QString">MVC.pro</value> + <value type="QString">gmvc.pro</value> </data> <data> <variable>RunConfiguration0-RunConfiguration.name</variable> - <value type="QString">MVC</value> + <value type="QString">gmvc</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-sncykruQ0C,guid=e454b1a02a95fc6454d7a56d0067ee2b</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-0VAN4sEd5T,guid=75a5318e040070f8fcb70ccf006944fa</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-8ccgXN</value> - <value type="QString">GNOME_KEYRING_PID=30769</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-nVYZaO</value> + <value type="QString">GNOME_KEYRING_PID=27939</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/MVC</value> + <value type="QString">PWD=/lrde/home/stage/froger_a/qt/gmvc</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=30844</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gtQAz30778/agent.30778</value> + <value type="QString">SSH_AGENT_PID=28014</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-yzfMR27948/agent.27948</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:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm3KFZQW</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:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmBDX0QW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358858991.561353-1070905078</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358946750.592912-119709926</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/MVC/MVC.pro</value> + <value type="QString">/amd/nfs/volume1/home/stage/froger_a/qt/gmvc/gmvc.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/MVC</value> + <value key="abstractProcess.workingDirectory" type="QString">/amd/nfs/volume1/home/stage/froger_a/qt/gmvc</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-sncykruQ0C,guid=e454b1a02a95fc6454d7a56d0067ee2b</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-0VAN4sEd5T,guid=75a5318e040070f8fcb70ccf006944fa</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-8ccgXN</value> - <value type="QString">GNOME_KEYRING_PID=30769</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-nVYZaO</value> + <value type="QString">GNOME_KEYRING_PID=27939</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/MVC</value> + <value type="QString">PWD=/lrde/home/stage/froger_a/qt/gmvc</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=30844</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gtQAz30778/agent.30778</value> + <value type="QString">SSH_AGENT_PID=28014</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-yzfMR27948/agent.27948</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:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm3KFZQW</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:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmBDX0QW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358858991.561353-1070905078</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358946750.592912-119709926</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/MVC</value> + <value key="abstractProcess.workingDirectory" type="QString">/amd/nfs/volume1/home/stage/froger_a/qt/gmvc</value> </valuemap> </data> <data> diff --git a/MVC/main.cpp b/gmvc/main.cpp similarity index 100% copy from MVC/main.cpp copy to gmvc/main.cpp diff --git a/gmvc/mainwindow.cpp b/gmvc/mainwindow.cpp new file mode 100644 index 0000000..d046226 --- /dev/null +++ b/gmvc/mainwindow.cpp @@ -0,0 +1,51 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + QListView *view = new QListView(); + view->setViewMode(QListView::IconMode); + view->setIconSize(QSize(100, 100)); + view->setMovement(QListView::Static); + view->setFlow(QListView::TopToBottom); + //view->setGridSize(QSize(300, 100)); + view->setSpacing(9); + + QList<QPixmap> pixmaps; + QStringList paths; + paths << "/lrde/home/stage/froger_a/ppm/mp00032c.ppm" << "/lrde/home/stage/froger_a/ppm/mp00042.ppm" << "/lrde/home/stage/froger_a/ppm/mp00076.ppm"; + QString path; + Model *model = new Model(this); + foreach(path, paths) + { + QPixmap pixmap(path); + model->addPixmap(pixmap); + } + + view->setModel(model); + //setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); + + setCentralWidget(view); +} + +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/gmvc/mainwindow.h b/gmvc/mainwindow.h new file mode 100644 index 0000000..822c275 --- /dev/null +++ b/gmvc/mainwindow.h @@ -0,0 +1,28 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <QHBoxLayout> +#include <QListView> + +#include "gmodel.h" +#include "model.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/gmvc/mainwindow.ui similarity index 100% copy from MVC/mainwindow.ui copy to gmvc/mainwindow.ui diff --git a/gmvc/model.cpp b/gmvc/model.cpp new file mode 100644 index 0000000..eb20cf8 --- /dev/null +++ b/gmvc/model.cpp @@ -0,0 +1,37 @@ +#include "model.h" + +Model::Model(QObject *parent) : + QAbstractListModel(parent) +{ + this->pixmaps = pixmaps; +} + +int Model::rowCount(const QModelIndex& parent) const +{ + if (parent.isValid()) + return 0; + else + return pixmaps.size();; +} + +QVariant Model::data(const QModelIndex& index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + if(role == Qt::DecorationRole) + return QIcon(pixmaps.value(index.row()).scaled(300, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + + if(role == Qt::UserRole) + return pixmaps.value(index.row()); + + return QVariant(); +} + +void Model::addPixmap(const QPixmap& pixmap) +{ + int row = pixmaps.size(); + beginInsertRows(QModelIndex(), row, row); + pixmaps.insert(row, pixmap); + endInsertRows(); +} diff --git a/gmvc/model.h b/gmvc/model.h new file mode 100644 index 0000000..f2247f4 --- /dev/null +++ b/gmvc/model.h @@ -0,0 +1,20 @@ +#ifndef MODEL_H +#define MODEL_H + +#include <QAbstractListModel> +#include <QIcon> + +class Model : + public QAbstractListModel +{ + public: + explicit Model(QObject *parent = 0); + QVariant data(const QModelIndex &index, int role) const; + int rowCount(const QModelIndex &parent) const; + void addPixmap(const QPixmap& pixmap); + + private: + QList<QPixmap> pixmaps; +}; + +#endif // MODEL_H -- 1.7.2.5