Commit fba2626e authored by Julien Wintz's avatar Julien Wintz
Browse files

Adding proof of concept view manager framework.

parent 168e6f54
......@@ -4,9 +4,9 @@
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Mon Jul 20 22:21:50 2009 (+0200)
## Version: $Id$
## Last-Updated: Fri Apr 27 20:56:07 2012 (+0200)
## Last-Updated: Wed May 16 09:36:54 2012 (+0200)
## By: Julien Wintz
## Update #: 248
## Update #: 251
######################################################################
##
### Commentary:
......@@ -43,7 +43,11 @@ set(${PROJECT_NAME}_HEADERS
dtkSplitter.h
dtkSwitch.h
dtkTagCloud.h
dtkTextEditor.h)
dtkTextEditor.h
dtkViewManager.h
dtkViewLayout.h
dtkViewLayoutItem.h
dtkViewList.h)
set(${PROJECT_NAME}_HEADERS_MOC
dtkAboutBox.h
......@@ -64,7 +68,11 @@ set(${PROJECT_NAME}_HEADERS_MOC
dtkSplitter.h
dtkTagCloud.h
dtkSwitch.h
dtkTextEditor.h)
dtkTextEditor.h
dtkViewManager.h
dtkViewLayout.h
dtkViewLayoutItem.h
dtkViewList.h)
set(${PROJECT_NAME}_SOURCES
dtkAboutBox.cpp
......@@ -85,7 +93,11 @@ set(${PROJECT_NAME}_SOURCES
dtkSplitter.cpp
dtkSwitch.cpp
dtkTagCloud.cpp
dtkTextEditor.cpp)
dtkTextEditor.cpp
dtkViewManager.cpp
dtkViewLayout.cpp
dtkViewLayoutItem.cpp
dtkViewList.cpp)
if(APPLE)
set(${PROJECT_NAME}_SOURCES
......
/* dtkViewLayout.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Wed May 16 09:38:22 2012 (+0200)
* Version: $Id$
* Last-Updated: Wed May 16 09:38:25 2012 (+0200)
* By: Julien Wintz
* Update #: 2
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include "dtkViewLayout.h"
#include "dtkViewLayoutItem.h"
class dtkViewLayoutPrivate
{
public:
dtkViewLayoutItem *root;
};
dtkViewLayout::dtkViewLayout(QWidget *parent) : QFrame(parent), d(new dtkViewLayoutPrivate)
{
d->root = new dtkViewLayoutItem;
d->root->setParent(this);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(d->root);
}
dtkViewLayout::~dtkViewLayout(void)
{
delete d;
d = NULL;
}
/* dtkViewLayout.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Wed May 16 09:38:08 2012 (+0200)
* Version: $Id$
* Last-Updated: Wed May 16 09:38:11 2012 (+0200)
* By: Julien Wintz
* Update #: 2
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKVIEWLAYOUT_H
#define DTKVIEWLAYOUT_H
#include <QtGui>
class dtkViewLayoutPrivate;
class dtkViewLayout : public QFrame
{
Q_OBJECT
public:
dtkViewLayout(QWidget *parent = 0);
~dtkViewLayout(void);
private:
dtkViewLayoutPrivate *d;
};
#endif // DTKVIEWLAYOUT_H
/* dtkViewLayoutItem.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Wed May 16 09:38:45 2012 (+0200)
* Version: $Id$
* Last-Updated: Wed May 16 09:38:48 2012 (+0200)
* By: Julien Wintz
* Update #: 2
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include "dtkViewLayout.h"
#include "dtkViewLayoutItem.h"
#include <QtGui>
typedef QList<dtkViewLayoutItem *> dtkViewLayoutItemList;
class dtkViewLayoutItemPrivate
{
public:
void split(void);
public:
dtkViewLayoutItem *root;
dtkViewLayoutItem *parent;
public:
dtkViewLayoutItem *a;
dtkViewLayoutItem *b;
public:
QLabel *proxy;
QWidget *view;
public:
QSplitter *splitter;
public:
QPushButton *close;
QPushButton *horzt;
QPushButton *vertc;
public:
QFrame *footer;
public:
dtkViewLayoutItem *q;
};
void dtkViewLayoutItemPrivate::split(void)
{
if(this->a && this->b)
return;
this->proxy->hide();
if(!this->a)
this->a = new dtkViewLayoutItem(q);
if(!this->b)
this->b = new dtkViewLayoutItem(q);
this->splitter->addWidget(a);
this->splitter->addWidget(b);
q->setCurrent(NULL);
}
dtkViewLayoutItem::dtkViewLayoutItem(dtkViewLayoutItem *parent) : QFrame(parent), d(new dtkViewLayoutItemPrivate)
{
d->parent = parent;
if(!d->parent)
d->root = this;
else
d->root = d->parent->d->root;
d->a = NULL;
d->b = NULL;
d->q = this;
d->view = NULL;
d->proxy = new QLabel("Drop a view here", this);
d->proxy->setAlignment(Qt::AlignCenter);
d->proxy->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
d->proxy->setStyleSheet("background: #aaaaaa; color: #dddddd;");
d->splitter = new QSplitter(this);
d->splitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
d->splitter->addWidget(d->proxy);
d->horzt = new QPushButton("Horzt", this);
d->vertc = new QPushButton("Vertc", this);
d->close = new QPushButton("Close", this);
d->close->setEnabled(d->root != this);
QHBoxLayout *footer_layout = new QHBoxLayout;
footer_layout->addWidget(d->close);
footer_layout->addWidget(d->horzt);
footer_layout->addWidget(d->vertc);
d->footer = new QFrame(this);
d->footer->setLayout(footer_layout);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(d->splitter);
layout->addWidget(d->footer);
this->setAcceptDrops(true);
this->setFocusPolicy(Qt::StrongFocus);
connect(d->close, SIGNAL(clicked()), this, SLOT(close()));
connect(d->horzt, SIGNAL(clicked()), this, SLOT(horzt()));
connect(d->vertc, SIGNAL(clicked()), this, SLOT(vertc()));
}
dtkViewLayoutItem::~dtkViewLayoutItem(void)
{
qDebug() << __func__;
delete d;
d = NULL;
}
void dtkViewLayoutItem::setCurrent(dtkViewLayoutItem *item)
{
if(item == this)
d->footer->setStyleSheet(".QFrame { background: blue; }");
else
d->footer->setStyleSheet(".QFrame { background: none; }");
if (d->a)
d->a->setCurrent(item);
if (d->b)
d->b->setCurrent(item);
this->update();
}
void dtkViewLayoutItem::remove(dtkViewLayoutItem *item)
{
if(item == d->a) {
delete d->a;
d->a = NULL;
}
if(item == d->b) {
delete d->b;
d->b = NULL;
}
if(!d->a && !d->b)
d->proxy->show();
d->close->setEnabled(d->root != this);
}
void dtkViewLayoutItem::focusInEvent(QFocusEvent *)
{
if(d->a || d->b)
return;
d->root->setCurrent(this);
}
void dtkViewLayoutItem::focusOutEvent(QFocusEvent *)
{
}
void dtkViewLayoutItem::dragEnterEvent(QDragEnterEvent *event)
{
event->acceptProposedAction();
}
void dtkViewLayoutItem::dragMoveEvent(QDragMoveEvent *event)
{
event->acceptProposedAction();
}
void dtkViewLayoutItem::dragLeaveEvent(QDragLeaveEvent *event)
{
event->accept();
}
void dtkViewLayoutItem::dropEvent(QDropEvent *event)
{
Q_UNUSED(event);
if(d->a && d->b)
return;
d->proxy->hide();
// dtkAbstractViewFactory::instance()->create();
d->view = new QFrame(this);
d->view->setStyleSheet("background: black;");
// --
d->splitter->addWidget(d->view);
d->close->setEnabled(true);
d->horzt->setEnabled(false);
d->vertc->setEnabled(false);
}
void dtkViewLayoutItem::close(void)
{
if (d->view) {
d->view->hide();
d->view = NULL;
d->proxy->show();
d->horzt->setEnabled(true);
d->vertc->setEnabled(true);
return;
}
if(!d->parent)
return;
d->parent->remove(this);
}
void dtkViewLayoutItem::horzt(void)
{
d->splitter->setOrientation(Qt::Horizontal);
d->split();
}
void dtkViewLayoutItem::vertc(void)
{
d->splitter->setOrientation(Qt::Vertical);
d->split();
}
/* dtkViewLayoutItem.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Wed May 16 09:38:35 2012 (+0200)
* Version: $Id$
* Last-Updated: Wed May 16 09:38:39 2012 (+0200)
* By: Julien Wintz
* Update #: 2
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKVIEWLAYOUTITEM_H
#define DTKVIEWLAYOUTITEM_H
#include <QFrame>
class dtkViewLayout;
class dtkViewLayoutItemPrivate;
class dtkViewLayoutItem : public QFrame
{
Q_OBJECT
public:
dtkViewLayoutItem(dtkViewLayoutItem *parent = 0);
~dtkViewLayoutItem(void);
public:
void setCurrent(dtkViewLayoutItem *item);
protected slots:
void close(void);
void horzt(void);
void vertc(void);
protected:
void remove(dtkViewLayoutItem *item);
protected:
void focusInEvent(QFocusEvent *);
void focusOutEvent(QFocusEvent *);
protected:
void dragEnterEvent(QDragEnterEvent *);
void dragMoveEvent(QDragMoveEvent *);
void dragLeaveEvent(QDragLeaveEvent *);
void dropEvent(QDropEvent *);
private:
friend class dtkViewLayoutItemPrivate;
private:
dtkViewLayoutItemPrivate *d;
};
#endif
/* dtkViewList.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Wed May 16 09:39:06 2012 (+0200)
* Version: $Id$
* Last-Updated: Wed May 16 09:39:14 2012 (+0200)
* By: Julien Wintz
* Update #: 3
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include "dtkViewList.h"
class dtkViewListPrivate
{
public:
};
dtkViewList::dtkViewList(QWidget *parent) : QListWidget(parent), d(new dtkViewListPrivate)
{
this->setAttribute(Qt::WA_MacShowFocusRect, false);
this->setDragEnabled(true);
this->setFrameStyle(QFrame::NoFrame);
this->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
this->addItem("view 1");
this->addItem("view 2");
this->addItem("view 3");
this->addItem("view 4");
}
dtkViewList::~dtkViewList(void)
{
delete d;
d = NULL;
};
/* dtkViewList.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Wed May 16 09:38:55 2012 (+0200)
* Version: $Id$
* Last-Updated: Wed May 16 09:38:58 2012 (+0200)
* By: Julien Wintz
* Update #: 2
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKVIEWLIST_H
#define DTKVIEWLIST_H
#include <QtGui>
class dtkViewListPrivate;
class dtkViewList : public QListWidget
{
Q_OBJECT
public:
dtkViewList(QWidget *parent = 0);
~dtkViewList(void);
private:
dtkViewListPrivate *d;
};
#endif // DTKVIEWLIST_H
/* dtkViewManager.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Wed May 16 09:37:54 2012 (+0200)
* Version: $Id$
* Last-Updated: Wed May 16 09:37:57 2012 (+0200)
* By: Julien Wintz
* Update #: 2
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include "dtkViewList.h"
#include "dtkViewLayout.h"
#include "dtkViewManager.h"
#include <QtGui>
class dtkViewManagerPrivate
{
public:
dtkViewList *list;
dtkViewLayout *layout;
};
dtkViewManager::dtkViewManager(QWidget *parent) : QFrame(parent), d(new dtkViewManagerPrivate)
{
d->list = new dtkViewList(this);
d->layout = new dtkViewLayout(this);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(d->list);
layout->addWidget(d->layout);
}
dtkViewManager::~dtkViewManager(void)
{
delete d;
d = NULL;
}
/* dtkViewManager.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Wed May 16 09:37:32 2012 (+0200)
* Version: $Id$
* Last-Updated: Wed May 16 09:37:36 2012 (+0200)
* By: Julien Wintz
* Update #: 2
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKVIEWMANAGER_H
#define DTKVIEWMANAGER_H
#include <QFrame>
class dtkViewManagerPrivate;
class dtkViewManager : public QFrame
{
Q_OBJECT
public:
dtkViewManager(QWidget *parent = 0);
~dtkViewManager(void);
private:
dtkViewManagerPrivate *d;
};
#endif
<