diff options
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | itemviews-ng.pro | 16 | ||||
-rw-r--r-- | src/experimental/qgraphicsscrollbar.cpp (renamed from src/qgraphicsscrollbar.cpp) | 0 | ||||
-rw-r--r-- | src/experimental/qgraphicsscrollbar.h (renamed from src/qgraphicsscrollbar.h) | 0 | ||||
-rw-r--r-- | src/experimental/qgraphicsscrollbar_p.h (renamed from src/qgraphicsscrollbar_p.h) | 0 | ||||
-rw-r--r-- | src/qdataroles_p.h | 1 | ||||
-rw-r--r-- | src/qgraphicslistview.cpp | 46 | ||||
-rw-r--r-- | src/qgraphicslistview_p.h | 3 | ||||
-rw-r--r-- | src/qgraphicstreeview.cpp | 28 | ||||
-rw-r--r-- | src/qlistcontroller.cpp | 6 | ||||
-rw-r--r-- | src/qtablewidgetng.cpp | 144 | ||||
-rw-r--r-- | src/qtablewidgetng.h | 9 | ||||
-rw-r--r-- | src/qtablewidgetng_p.h | 7 | ||||
-rw-r--r-- | src/qtreecontroller.cpp | 14 | ||||
-rw-r--r-- | src/qtreecontroller.h | 2 | ||||
-rw-r--r-- | src/qtreewidgetng.cpp | 182 | ||||
-rw-r--r-- | src/qtreewidgetng.h | 10 | ||||
-rw-r--r-- | src/qtreewidgetng_p.h | 11 | ||||
-rw-r--r-- | src/src.pro | 7 |
19 files changed, 244 insertions, 244 deletions
@@ -5,7 +5,5 @@ To test the examples just type: qmake make -Then you will find the examples in the bin/ directory. - Online API docs can be found at http://labs.trolltech.com/docs/Projects/itemviews-ng/ diff --git a/itemviews-ng.pro b/itemviews-ng.pro index f0fc255..432768d 100644 --- a/itemviews-ng.pro +++ b/itemviews-ng.pro @@ -1,6 +1,18 @@ TEMPLATE = subdirs CONFIG += ordered SUBDIRS = src \ - tests \ - examples \ + tests \ + examples \ + +# installation paths +libraries.path = $$[QT_INSTALL_LIBS] +libraries.files = $$OUT_PWD/lib/* +# tests.path = +# tests.files = $$OUT_PWD/tests/* +# examples.path = +# examples.files = $$OUT_PWD/examples/* + +INSTALLS = libraries \ +# tests \ +# examples \ diff --git a/src/qgraphicsscrollbar.cpp b/src/experimental/qgraphicsscrollbar.cpp index f1fd0a3..f1fd0a3 100644 --- a/src/qgraphicsscrollbar.cpp +++ b/src/experimental/qgraphicsscrollbar.cpp diff --git a/src/qgraphicsscrollbar.h b/src/experimental/qgraphicsscrollbar.h index 0c8dad6..0c8dad6 100644 --- a/src/qgraphicsscrollbar.h +++ b/src/experimental/qgraphicsscrollbar.h diff --git a/src/qgraphicsscrollbar_p.h b/src/experimental/qgraphicsscrollbar_p.h index 650dfd0..650dfd0 100644 --- a/src/qgraphicsscrollbar_p.h +++ b/src/experimental/qgraphicsscrollbar_p.h diff --git a/src/qdataroles_p.h b/src/qdataroles_p.h index f792524..3f862ec 100644 --- a/src/qdataroles_p.h +++ b/src/qdataroles_p.h @@ -45,6 +45,7 @@ class QtDataRoles : private QObject Q_OBJECT Q_ENUMS(ItemDataRole) public: + // ### copy/paste from Qt namespace enum ItemDataRole { DisplayRole = 0, DecorationRole = 1, diff --git a/src/qgraphicslistview.cpp b/src/qgraphicslistview.cpp index 162d691..46fcd32 100644 --- a/src/qgraphicslistview.cpp +++ b/src/qgraphicslistview.cpp @@ -370,7 +370,7 @@ void QtGraphicsListViewItemCreatorBase::recycle(QGraphicsObject *item) QtGraphicsListViewPrivate::QtGraphicsListViewPrivate() : q_ptr(0), controller(0), model(0), selectionManager(0), orientation(Qt::Horizontal), textElideMode(Qt::ElideMiddle), - highlight(0), firstIndex(0), offset(0), transform(0), + highlight(0), firstIndex(0), offset(0), #if CACHING_ENABLED cachedIndexOffset(0), cachedCoordinateOffset(0), #endif @@ -550,13 +550,13 @@ QVariant QtGraphicsListViewPrivate::cachedData(int index, const QByteArray &role { // ### structure this list so the most used items are added first static const QList<QByteArray> roles = (QList<QByteArray>() - << "FontRole" - << "TextAlignmentRole" - << "ForegroundRole" - << "CheckStateRole" - << "DecorationRole" - << "DisplayRole" - << "SizeHintRole"); + << "FontRole" + << "TextAlignmentRole" + << "ForegroundRole" + << "CheckStateRole" + << "DecorationRole" + << "DisplayRole" + << "SizeHintRole"); if (index != cachedDataIndex && model) { cachedDataHash = model->data(index, roles); cachedDataIndex = index; @@ -628,7 +628,6 @@ QtGraphicsListView::QtGraphicsListView(Qt::Orientation orientation, QGraphicsWid //setFlag(QGraphicsItem::ItemClipsChildrenToShape); d->q_ptr = this; d->orientation = orientation; - d->transform = new QtGraphicsTransform(this); } /*! @@ -641,7 +640,6 @@ QtGraphicsListView::QtGraphicsListView(QtGraphicsListViewPrivate &dd, Qt::Orient //setFlag(QGraphicsItem::ItemClipsChildrenToShape); d->q_ptr = this; d->orientation = orientation; - d->transform = new QtGraphicsTransform(this); } /*! @@ -921,8 +919,8 @@ void QtGraphicsListView::doLayout() const QRectF area = geometry(); const QSizeF constraint = (d->orientation == Qt::Horizontal - ? QSizeF(-1, size().height()) - : QSizeF(size().width(), -1)); + ? QSizeF(-1, size().height()) + : QSizeF(size().width(), -1)); const int count = d->model ? d->model->count() : 0; const bool vertical = (d->orientation == Qt::Vertical); const qreal areaStart = (vertical ? area.y() : area.x()); @@ -931,11 +929,12 @@ void QtGraphicsListView::doLayout() qreal coordinate = -d->offset; int index = d->firstIndex; - qDebug() << "coordinate" << coordinate; - qDebug() << "index" << index; + //qDebug() << "---------------------------"; + //qDebug() << "coordinate" << coordinate; + //qDebug() << "index" << index; // find the visible items; caching helps us skip this most of the time - if (coordinate <= 0 && !d->items.isEmpty()) { // ### disabled + if (coordinate < 0 && !d->items.isEmpty()) { #if CACHING_ENABLED // optimization: use the cached index and offset as starting points // The cached values are offsets from the start of the _contents_ @@ -943,14 +942,14 @@ void QtGraphicsListView::doLayout() index += d->cachedIndexOffset; coordinate += d->cachedCoordinateOffset; - qDebug() << "cachedIndexOffset" << d->cachedIndexOffset; - qDebug() << "index" << index; + //qDebug() << "cached index offset" << d->cachedIndexOffset; + //qDebug() << "cached coordinate offset" << d->cachedCoordinateOffset; #endif - //index = d->items.first().first; - //coordinate = d->items.first().second->pos().y(); // ### vertical only + //qDebug() << "actual item offset" << d->items.first().second->pos().y(); + //qDebug() << "actual item index" << d->items.first().first; // the visible area starts at coordinate == 0 - if (coordinate < 0) { // the cached offset was above or to the left of the visible area + if (coordinate < 0) { // the cached offset was above or to the left of the visible area while (index < count) { const QSizeF hint = d->itemSize(index); const qreal size = vertical ? hint.height() : hint.width(); @@ -960,6 +959,7 @@ void QtGraphicsListView::doLayout() ++index; } } else if (coordinate > 0) { // the cached offset was below or to the right + //qDebug() << "ABOVE"; while (index >= 0 && coordinate > 0) { const QSizeF hint = d->itemSize(index); const qreal size = vertical ? hint.height() : hint.width(); @@ -968,8 +968,10 @@ void QtGraphicsListView::doLayout() } } #if CACHING_ENABLED - d->cachedIndexOffset = index - d->firstIndex; - d->cachedCoordinateOffset = coordinate + d->offset; + //qDebug() << "new cached index offset" << (index - d->firstIndex); + //qDebug() << "new cached coordinate offset" << (coordinate + d->offset); + d->cachedIndexOffset = index - d->firstIndex; + d->cachedCoordinateOffset = coordinate + d->offset; #endif } diff --git a/src/qgraphicslistview_p.h b/src/qgraphicslistview_p.h index af5fdc2..1fb9e15 100644 --- a/src/qgraphicslistview_p.h +++ b/src/qgraphicslistview_p.h @@ -40,7 +40,7 @@ #include <qtimer.h> #include <qhash.h> -#define CACHING_ENABLED 0 +#define CACHING_ENABLED 1 QT_BEGIN_NAMESPACE @@ -117,7 +117,6 @@ public: mutable QHash<QByteArray, QVariant> cachedDataHash; mutable int cachedDataIndex; - QGraphicsItem *transform; // non-visible transform node QList<QPair<int, QGraphicsObject*> > items; QtGraphicsListViewItemCreatorBase *creator; QBasicTimer layoutTimer; diff --git a/src/qgraphicstreeview.cpp b/src/qgraphicstreeview.cpp index a039b22..63618a0 100644 --- a/src/qgraphicstreeview.cpp +++ b/src/qgraphicstreeview.cpp @@ -228,17 +228,17 @@ void QtGraphicsTreeViewItem::initStyleOption(QStyleOptionViewItemV4 *option, int value = d->view->d_func()->cachedData(d->it, column, "DecorationRole"); if (value.isValid()) { option->features |= QStyleOptionViewItemV2::HasDecoration; - switch (value.type()) { - case QVariant::Icon: - option->icon = qvariant_cast<QIcon>(value); - break; - case QVariant::Color: { - QPixmap pixmap(option->decorationSize); - pixmap.fill(qvariant_cast<QColor>(value)); - option->icon = QIcon(pixmap); } - default: + switch (value.type()) { + case QVariant::Icon: + option->icon = qvariant_cast<QIcon>(value); break; - } + case QVariant::Color: { + QPixmap pixmap(option->decorationSize); + pixmap.fill(qvariant_cast<QColor>(value)); + option->icon = QIcon(pixmap); } + default: + break; + } } // DisplayRole @@ -919,8 +919,8 @@ void QtGraphicsTreeView::setModel(QtTreeModelBase *model) return; if (d->model) { disconnect(d->model, SIGNAL(destroyed()), this, SLOT(_q_modelDestroyed())); - disconnect(d->model, SIGNAL(itemsChanged(const QtTreeModelBase::iterator_base&,int,const QList<int>&)), - this, SLOT(_q_itemsChanged(const QtTreeModelBase::iterator_base&,int,const QList<int>&))); + disconnect(d->model, SIGNAL(itemsChanged(const QtTreeModelBase::iterator_base&,int,const QList<QByteArray>&)), + this, SLOT(_q_itemsChanged(const QtTreeModelBase::iterator_base&,int,const QList<QByteArray>&))); disconnect(d->model, SIGNAL(itemsInserted(const QtTreeModelBase::iterator_base&,int)), this, SLOT(_q_itemsInserted(const QtTreeModelBase::iterator_base&,int))); disconnect(d->model, SIGNAL(itemsRemoved(const QtTreeModelBase::iterator_base&,int)), @@ -929,8 +929,8 @@ void QtGraphicsTreeView::setModel(QtTreeModelBase *model) d->model = model; if (d->model) { connect(d->model, SIGNAL(destroyed()), this, SLOT(_q_modelDestroyed())); - connect(d->model, SIGNAL(itemsChanged(const QtTreeModelBase::iterator_base&,int,const QList<int>&)), - this, SLOT(_q_itemsChanged(const QtTreeModelBase::iterator_base&,int,const QList<int>&))); + connect(d->model, SIGNAL(itemsChanged(const QtTreeModelBase::iterator_base&,int,const QList<QByteArray>&)), + this, SLOT(_q_itemsChanged(const QtTreeModelBase::iterator_base&,int,const QList<QByteArray>&))); connect(d->model, SIGNAL(itemsInserted(const QtTreeModelBase::iterator_base&,int)), this, SLOT(_q_itemsInserted(const QtTreeModelBase::iterator_base&,int))); connect(d->model, SIGNAL(itemsRemoved(const QtTreeModelBase::iterator_base&,int)), diff --git a/src/qlistcontroller.cpp b/src/qlistcontroller.cpp index 126ed72..ae2d2a8 100644 --- a/src/qlistcontroller.cpp +++ b/src/qlistcontroller.cpp @@ -48,7 +48,7 @@ QtListControllerPrivate::QtListControllerPrivate() behavior(QtListController::SingleSelection), animation(0), firstIndex(0), - scrollPerItem(true), + scrollPerItem(false), // ### for now wheelEnabled(true) { } @@ -409,11 +409,11 @@ void QtListController::setScrollValue(qreal value) if (d->view->firstIndex() == index) return; //d->animateFirstIndex(index); - d->view->setFirstIndex(index); + d->view->setFirstIndex(qMax(0, index)); // ### workaround for QScrollBar bug } else { if (d->view->offset() == value) return; - d->view->setOffset(value); + d->view->setOffset(qMax(0., value)); // ### workaround for QScrollBar bug } emit scrollValueChanged(value); } diff --git a/src/qtablewidgetng.cpp b/src/qtablewidgetng.cpp index ffe9d26..9f6e74e 100644 --- a/src/qtablewidgetng.cpp +++ b/src/qtablewidgetng.cpp @@ -29,17 +29,14 @@ #include "qtabledefaultmodel.h" #include "qgraphicstableview.h" #include "qgraphicsheader.h" -#include "qgraphicsscrollbar.h" #include <qdebug.h> +#include <qscrollbar.h> QT_BEGIN_NAMESPACE QtTableWidgetNGPrivate::QtTableWidgetNGPrivate() - : controller(0), - verticalScrollbar(0), - horizontalScrollbar(0), - q_ptr(0) + : controller(0), q_ptr(0) { } @@ -98,6 +95,26 @@ void QtTableWidgetNGPrivate::_q_hideView() controller->view()->hide(); } +void QtTableWidgetNGPrivate::_q_updateGeometries() +{ + Q_Q(QtTableWidgetNG); + + QScrollBar *vertical = q->verticalScrollBar(); + QScrollBar *horizontal = q->horizontalScrollBar(); + + qreal maximum = 0; + + vertical->setPageStep(controller->verticalPageStepValue(&maximum)); + vertical->setMaximum(maximum); + + horizontal->setPageStep(controller->horizontalPageStepValue(&maximum)); + horizontal->setMaximum(maximum); + + QRect rect = q->viewport()->geometry(); + controller->view()->setGeometry(QRect(0, 0, rect.width(), rect.height())); + controller->view()->doLayout(); +} + void QtTableWidgetNGPrivate::_q_modelChanged(QtTableModelInterface *current, QtTableModelInterface *previous) { Q_UNUSED(current); @@ -127,106 +144,30 @@ void QtTableWidgetNGPrivate::_q_controllerChanged(QtTableController *current, Qt q, SLOT(_q_modelChanged(QtTableModelInterface*,QtTableModelInterface*))); QObject::disconnect(previous, SIGNAL(selectionManagerChanged(QtTableSelectionManager*,QtTableSelectionManager*)), q, SLOT(_q_selectionManagerChanged(QtTableSelectionManager*,QtTableSelectionManager*))); - //QObject::disconnect(previous, SIGNAL(verticalScrollValueChanged(qreal)), - // verticalScrollbar, SLOT(setValue(qreal))); - QObject::disconnect(verticalScrollbar, SIGNAL(valueChanged(qreal)), - previous, SLOT(setVerticalScrollValue(qreal))); - //QObject::disconnect(previous, SIGNAL(horizontalScrollValueChanged(qreal)), - // horizontalScrollbar, SLOT(setValue(qreal))); - QObject::disconnect(horizontalScrollbar, SIGNAL(valueChanged(qreal)), - previous, SLOT(setHorizontalScrollValue(qreal))); + QObject::disconnect(q->verticalScrollBar(), SIGNAL(valueChanged(int)), + previous, SLOT(setVerticalScrollValue(int))); + QObject::disconnect(q->horizontalScrollBar(), SIGNAL(valueChanged(int)), + previous, SLOT(setHorizontalScrollValue(int))); } if (current) { QObject::connect(current, SIGNAL(modelChanged(QtTableModelInterface*,QtTableModelInterface*)), q, SLOT(_q_modelChanged(QtTableModelInterface*,QtTableModelInterface*))); QObject::connect(current, SIGNAL(selectionManagerChanged(QtTableSelectionManager*,QtTableSelectionManager*)), q, SLOT(_q_selectionManagerChanged(QtTableSelectionManager*,QtTableSelectionManager*))); - //QObject::connect(previous, SIGNAL(verticalScrollValueChanged(qreal)), - // verticalScrollbar, SLOT(setValue(qreal))); - QObject::connect(verticalScrollbar, SIGNAL(valueChanged(qreal)), - current, SLOT(setVerticalScrollValue(qreal))); - //QObject::connect(previous, SIGNAL(horizontalScrollValueChanged(qreal)), - // horizontalScrollbar, SLOT(setValue(qreal))); - QObject::connect(horizontalScrollbar, SIGNAL(valueChanged(qreal)), - current, SLOT(setHorizontalScrollValue(qreal))); + QObject::connect(q->verticalScrollBar(), SIGNAL(valueChanged(int)), + current, SLOT(setVerticalScrollValue(int))); + QObject::connect(q->horizontalScrollBar(), SIGNAL(valueChanged(int)), + current, SLOT(setHorizontalScrollValue(int))); } _q_modelChanged(current ? current->model() : 0, previous ? previous->model() : 0); _q_selectionManagerChanged(current ? current->selectionManager() : 0, previous ? previous->selectionManager() : 0); _q_viewChanged(current ? current->view() : 0, previous ? previous->view() : 0); } -void QtTableWidgetNGPrivate::updateElementsLayout(const QSizeF &size) -{ - Q_Q(QtTableWidgetNG); - Q_ASSERT(controller); - - QtGraphicsHeader *horizontalHeader = controller->horizontalHeader(); - QtGraphicsHeader *verticalHeader = controller->verticalHeader(); - - if (horizontalHeader && horizontalHeader->scene() == 0) - q->scene()->addItem(horizontalHeader); - if (verticalHeader && verticalHeader->scene() == 0) - q->scene()->addItem(verticalHeader); - - qreal x = (verticalHeader ? verticalHeader->perpendicularSize() : 0); - qreal y = (horizontalHeader ? horizontalHeader->perpendicularSize() : 0); - qreal w = (verticalScrollbar ? verticalScrollbar->effectiveSizeHint(Qt::PreferredSize).width() : 0); - qreal h = (horizontalScrollbar ? horizontalScrollbar->effectiveSizeHint(Qt::PreferredSize).height() : 0); - - QRectF center(x, y, size.width() - w - x, size.height() - h - y); - - if (verticalScrollbar) - verticalScrollbar->setGeometry(QRectF(center.right(), 0, w, y + center.height())); - if (horizontalScrollbar) - horizontalScrollbar->setGeometry(QRectF(0, center.bottom(), x + center.width(), h)); - - controller->view()->setGeometry(center); // so updateScrollRanges knows the max first row - - updateScrollRanges(); - - if (verticalScrollbar && !verticalScrollbar->isVisible()) - center.adjust(0, 0, w, 0); - if (horizontalScrollbar && !horizontalScrollbar->isVisible()) - center.adjust(0, 0, 0, h); - - if (verticalHeader) - verticalHeader->setGeometry(QRectF(0, y, x, center.height())); - if (horizontalHeader) - horizontalHeader->setGeometry(QRectF(x, 0, center.width(), y)); - - controller->view()->setGeometry(center); // if the scrollbar visibilities changed -} - -void QtTableWidgetNGPrivate::updateScrollRanges() -{ - if (verticalScrollbar) { - qreal maximum = 0; - verticalScrollbar->setPageStep(controller->verticalPageStepValue(&maximum)); - verticalScrollbar->setMaximum(maximum); - verticalScrollbar->setVisible(verticalScrollbar->minimum() != verticalScrollbar->maximum()); - verticalScrollbar->update(); - } - if (horizontalScrollbar) { - qreal maximum = 0; - horizontalScrollbar->setPageStep(controller->horizontalPageStepValue(&maximum)); - horizontalScrollbar->setMaximum(maximum); - horizontalScrollbar->setVisible(horizontalScrollbar->minimum() != horizontalScrollbar->maximum()); - horizontalScrollbar->update(); - } -} - void QtTableWidgetNGPrivate::initialize(int rows, int columns) { Q_Q(QtTableWidgetNG); q->setScene(new QGraphicsScene(q)); - // horizontal scrollbar - horizontalScrollbar = new QtGraphicsScrollBar(Qt::Horizontal); - horizontalScrollbar->setFlag(QGraphicsItem::ItemClipsToShape, true); - q->scene()->addItem(horizontalScrollbar); - // vertical scrollbar - verticalScrollbar = new QtGraphicsScrollBar(Qt::Vertical); - verticalScrollbar->setFlag(QGraphicsItem::ItemClipsToShape, true); - q->scene()->addItem(verticalScrollbar); // other parts if (!controller) controller = new QtTableController(q); @@ -239,7 +180,6 @@ void QtTableWidgetNGPrivate::initialize(int rows, int columns) controller->view()->setParent(controller); controller->view()->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); } - _q_controllerChanged(controller, 0); } @@ -291,13 +231,29 @@ QtTableDefaultModel *QtTableWidgetNG::defaultModel() const /*! */ +void QtTableWidgetNG::showEvent(QShowEvent *event) +{ + Q_D(QtTableWidgetNG); + d->_q_updateGeometries(); + QGraphicsView::showEvent(event); +} + +/*! + */ void QtTableWidgetNG::resizeEvent(QResizeEvent *event) { Q_D(QtTableWidgetNG); - QGraphicsView::resizeEvent(event); - QRect r = viewport()->geometry(); - scene()->setSceneRect(0, 0, r.width(), r.height()); - d->updateElementsLayout(r.size()); + d->_q_updateGeometries(); + QAbstractScrollArea::resizeEvent(event); +} + +/*! + */ +void QtTableWidgetNG::scrollContentsBy(int dx, int dy) +{ + Q_UNUSED(dx); + Q_UNUSED(dy); + // do nothing } QT_END_NAMESPACE diff --git a/src/qtablewidgetng.h b/src/qtablewidgetng.h index 73eccd1..de79186 100644 --- a/src/qtablewidgetng.h +++ b/src/qtablewidgetng.h @@ -53,8 +53,11 @@ public: QtTableDefaultModel *defaultModel() const; protected: + void showEvent(QShowEvent *event); void resizeEvent(QResizeEvent *event); + void scrollContentsBy(int dx, int dy); + protected: QtTableWidgetNGPrivate *d_ptr; @@ -70,8 +73,10 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_columnsMoved(int from, int to, int count)) Q_PRIVATE_SLOT(d_func(), void _q_showView()) Q_PRIVATE_SLOT(d_func(), void _q_hideView()) - Q_PRIVATE_SLOT(d_func(), void _q_modelChanged(QtTableModelInterface *current, QtTableModelInterface *previous)) - Q_PRIVATE_SLOT(d_func(), void _q_selectionManagerChanged(QtTableSelectionManager *current, QtTableSelectionManager *previous)) + Q_PRIVATE_SLOT(d_func(), void _q_updateGeometries()) +// Q_PRIVATE_SLOT(d_func(), void _q_modelChanged(QtTableModelInterface *current, QtTableModelInterface *previous)) +// Q_PRIVATE_SLOT(d_func(), void _q_selectionManagerChanged(QtTableSelectionManager *current, QtTableSelectionManager *previous)) +// Q_PRIVATE_SLOT(d_func(), void _q_viewChanged(QtGraphicsTableView *current, QtGraphicsTableView *previous)) }; QT_END_NAMESPACE diff --git a/src/qtablewidgetng_p.h b/src/qtablewidgetng_p.h index 38a9288..abd8203 100644 --- a/src/qtablewidgetng_p.h +++ b/src/qtablewidgetng_p.h @@ -59,20 +59,15 @@ public: void _q_columnsMoved(int from, int to, int count); void _q_showView(); void _q_hideView(); + void _q_updateGeometries(); void _q_controllerChanged(QtTableController *current, QtTableController *previous); void _q_viewChanged(QtGraphicsTableView *current, QtGraphicsTableView *previous); void _q_modelChanged(QtTableModelInterface *current, QtTableModelInterface *previous); void _q_selectionManagerChanged(QtTableSelectionManager *current, QtTableSelectionManager *previous); - void updateElementsLayout(const QSizeF &size); - void updateScrollRanges(); - void initialize(int rows = 0, int columns = 0); QtTableController *controller; - QtGraphicsScrollBar *verticalScrollbar; - QtGraphicsScrollBar *horizontalScrollbar; - QtTableWidgetNG *q_ptr; }; diff --git a/src/qtreecontroller.cpp b/src/qtreecontroller.cpp index c7bdd51..ccb37a4 100644 --- a/src/qtreecontroller.cpp +++ b/src/qtreecontroller.cpp @@ -338,6 +338,13 @@ void QtTreeController::setVerticalScrollValue(qreal value) /*! */ +void QtTreeController::setVerticalScrollValue(int value) +{ + setVerticalScrollValue(qreal(value)); +} + +/*! + */ qreal QtTreeController::horizontalScrollValue() const { Q_D(const QtTreeController); @@ -350,6 +357,13 @@ qreal QtTreeController::horizontalScrollValue() const /*! */ +void QtTreeController::setHorizontalScrollValue(int value) +{ + setHorizontalScrollValue(qreal(value)); +} + +/*! + */ void QtTreeController::setHorizontalScrollValue(qreal value) { Q_D(QtTreeController); diff --git a/src/qtreecontroller.h b/src/qtreecontroller.h index f891d06..3194361 100644 --- a/src/qtreecontroller.h +++ b/src/qtreecontroller.h @@ -107,6 +107,8 @@ Q_SIGNALS: public Q_SLOTS: void setVerticalScrollValue(qreal value); void setHorizontalScrollValue(qreal value); + void setVerticalScrollValue(int value); + void setHorizontalScrollValue(int value); protected: QtTreeController(QtTreeControllerPrivate &, QObject *parent = 0); diff --git a/src/qtreewidgetng.cpp b/src/qtreewidgetng.cpp index e44e4d5..009bd38 100644 --- a/src/qtreewidgetng.cpp +++ b/src/qtreewidgetng.cpp @@ -28,7 +28,8 @@ #include "qtreeselectionmanager.h" #include "qtreecontroller.h" #include "qgraphicsheader.h" -#include "qgraphicsscrollbar.h" + +#include <qscrollbar.h> QT_BEGIN_NAMESPACE @@ -36,7 +37,7 @@ QT_BEGIN_NAMESPACE \internal */ QtTreeWidgetNGPrivate::QtTreeWidgetNGPrivate() - : controller(0), header(0), verticalScrollbar(0), horizontalScrollbar(0), q_ptr(0) + : controller(0), header(0), q_ptr(0) { } @@ -125,17 +126,65 @@ void QtTreeWidgetNGPrivate::_q_hideView() /*! \internal */ -void QtTreeWidgetNGPrivate::_q_verticalScrollValueChanged(qreal value) +void QtTreeWidgetNGPrivate::_q_updateGeometries() { - controller->view()->setFirstIndex(int(value)); + Q_Q(QtTreeWidgetNG); + + // ### take header into account + QRect rect = q->viewport()->geometry(); + q->setSceneRect(QRect(0, 0, rect.width(), rect.height())); + + qreal y = header ? /*header->preferredHeight()*/22 : 0; + if (header) + header->setGeometry(QRect(0, 0, rect.width(), y)); + + controller->view()->setGeometry(QRect(0, y, rect.width(), rect.height() - y)); + controller->view()->doLayout(); + + // ### check scrollbar policy + QScrollBar *vertical = q->verticalScrollBar(); + QScrollBar *horizontal = q->horizontalScrollBar(); + + int maximum = 0; + int maximumFirst = controller->view()->maximumFirstIndex(&maximum); + vertical->setMaximum(maximum); + vertical->setPageStep(maximum - maximumFirst); + + maximum = controller->header() ? controller->header()->sectionCount() : 0; + maximumFirst = controller->header() ? controller->header()->maximumFirstSection() : 0; + horizontal->setMaximum(maximum); + horizontal->setPageStep(maximum - maximumFirst); } /*! \internal */ -void QtTreeWidgetNGPrivate::_q_horizontalScrollValueChanged(qreal value) +void QtTreeWidgetNGPrivate::_q_firstIndexChanged(int index) { - Q_UNUSED(value); + Q_Q(QtTreeWidgetNG); + if (q->verticalScrollBar()->value() != index) + q->verticalScrollBar()->setValue(index); +} + +/*! + \internal + */ +void QtTreeWidgetNGPrivate::_q_firstSectionChanged(int section) +{ + Q_Q(QtTreeWidgetNG); + if (q->horizontalScrollBar()->value() != section) + q->horizontalScrollBar()->setValue(section); +} + +/*! + \internal + */ +void QtTreeWidgetNGPrivate::_q_offsetChanged(qreal offset) +{ + Q_Q(QtTreeWidgetNG); + int value = int(offset); + if (q->verticalScrollBar()->value() != value) + q->verticalScrollBar()->setValue(value); } /*! @@ -187,11 +236,27 @@ void QtTreeWidgetNGPrivate::_q_controllerChanged(QtTreeController *current, QtTr Q_Q(QtTreeWidgetNG); if (previous) { QObject::disconnect(previous, SIGNAL(modelChanged(QtTreeModelBase*,QtTreeModelBase*)), - q, SLOT(_q_modelChanged(QtTreeModelBase*,QtTreeModelBase*))); + q, SLOT(_q_modelChanged(QtTreeModelBase*,QtTreeModelBase*))); + QObject::disconnect(previous, SIGNAL(selectionManagerChanged(QtTreeSelectionManager*,QtTreeSelectionManager)), + q, SLOT(_q_selectionManagerChanged(QtTreeSelectionManager*, QtTreeSelectionManager*))); + QObject::disconnect(previous, SIGNAL(viewChanged(QtGraphicsTreeView*, QtGraphicsTreeView*)), + q, SLOT(_q_viewChanged(QtGraphicsTreeView*, QtGraphicsTreeView*))); + QObject::disconnect(q->verticalScrollBar(), SIGNAL(valueChanged(int)), + previous, SLOT(setVerticalScrollValue(int))); + QObject::disconnect(q->horizontalScrollBar(), SIGNAL(valueChanged(int)), + previous, SLOT(setHorizontalScrollValue(int))); } if (current) { QObject::connect(current, SIGNAL(modelChanged(QtTreeModelBase*,QtTreeModelBase*)), - q, SLOT(_q_modelChanged(QtTreeModelBase*,QtTreeModelBase*))); + q, SLOT(_q_modelChanged(QtTreeModelBase*,QtTreeModelBase*))); + QObject::connect(current, SIGNAL(selectionManagerChanged(QtTreeSelectionManager*,QtTreeSelectionManager*)), + q, SLOT(_q_selectionManagerChanged(QtTreeSelectionManager*, QtTreeSelectionManager*))); + QObject::connect(current, SIGNAL(viewChanged(QtGraphicsTreeView*, QtGraphicsTreeView*)), + q, SLOT(_q_viewChanged(QtGraphicsTreeView*, QtGraphicsTreeView*))); + QObject::connect(q->verticalScrollBar(), SIGNAL(valueChanged(int)), + current, SLOT(setVerticalScrollValue(int))); + QObject::connect(q->horizontalScrollBar(), SIGNAL(valueChanged(int)), + current, SLOT(setHorizontalScrollValue(int))); } _q_viewChanged(current ? current->view() : 0, previous ? previous->view() : 0); _q_headerChanged(current ? current->header() : 0, previous ? previous->header() : 0); @@ -214,78 +279,11 @@ void QtTreeWidgetNGPrivate::_q_headerChanged(QtGraphicsHeader *current, QtGraphi /*! \internal */ -void QtTreeWidgetNGPrivate::updateElementsLayout(const QSizeF &size) -{ - qreal x = 0; - qreal y = (header ? header->perpendicularSize() : 0); - qreal w = (verticalScrollbar ? verticalScrollbar->effectiveSizeHint(Qt::PreferredSize).width() : 0); - qreal h = (horizontalScrollbar ? horizontalScrollbar->effectiveSizeHint(Qt::PreferredSize).height() : 0); - - QRectF center(x, y, size.width() - w - x, size.height() - h - y); - - if (verticalScrollbar) - verticalScrollbar->setGeometry(QRectF(center.right(), 0, w, y + center.height())); - if (horizontalScrollbar) - horizontalScrollbar->setGeometry(QRectF(0, center.bottom(), w + center.width(), h)); - - controller->view()->setGeometry(center); // so updateScrollRanges knows the max first row - - updateScrollRanges(); - - if (verticalScrollbar && !verticalScrollbar->isVisible()) - center.adjust(0, 0, w, 0); - if (horizontalScrollbar && !horizontalScrollbar->isVisible()) - center.adjust(0, 0, 0, h); - - if (header) - header->setGeometry(QRectF(x, 0, center.width(), y)); - - controller->view()->setGeometry(center); // if the scrollbar visibilities changed -} - -/*! - \internal - */ -void QtTreeWidgetNGPrivate::updateScrollRanges() -{ - if (verticalScrollbar) { - int maximumIndex = 0; // get this at the same time as maximumFirstIndex - int maximumFirstIndex = controller->view()->maximumFirstIndex(&maximumIndex); - verticalScrollbar->setMaximum(maximumFirstIndex); - verticalScrollbar->setPageStep(maximumIndex - maximumFirstIndex); - verticalScrollbar->setVisible(verticalScrollbar->minimum() != verticalScrollbar->maximum()); - verticalScrollbar->update(); - } - if (horizontalScrollbar) { - int columnCount = controller->header() ? controller->header()->sectionCount() : 0; - int maximumFirstColumn = controller->header() ? controller->header()->maximumFirstSection() : 0; - horizontalScrollbar->setMaximum(maximumFirstColumn); - horizontalScrollbar->setPageStep(columnCount - maximumFirstColumn); - horizontalScrollbar->setVisible(horizontalScrollbar->minimum() != horizontalScrollbar->maximum()); - horizontalScrollbar->update(); - } -} - -/*! - \internal - */ void QtTreeWidgetNGPrivate::initialize() { Q_Q(QtTreeWidgetNG); + q->setViewportMargins(0, 0, 0, 0); q->setScene(new QGraphicsScene(q)); - - verticalScrollbar = new QtGraphicsScrollBar(Qt::Vertical); - verticalScrollbar->setZValue(10000); - q->scene()->addItem(verticalScrollbar); - QObject::connect(verticalScrollbar, SIGNAL(valueChanged(qreal)), - q, SLOT(_q_verticalScrollValueChanged(qreal))); - - horizontalScrollbar = new QtGraphicsScrollBar(Qt::Horizontal); - horizontalScrollbar->setZValue(10000); - q->scene()->addItem(horizontalScrollbar); - QObject::connect(horizontalScrollbar, SIGNAL(valueChanged(qreal)), - q, SLOT(_q_horizontalScrollValueChanged(qreal))); - if (!controller) controller = new QtTreeController; if (!controller->model()) @@ -296,12 +294,11 @@ void QtTreeWidgetNGPrivate::initialize() controller->setView(new QtGraphicsTreeView); controller->view()->setParent(controller); } - if (!header) { header = new QtGraphicsHeader; controller->setHeader(header); } - + //controller->setWheelEnabled(false); _q_controllerChanged(controller, 0); } @@ -323,8 +320,10 @@ QtTreeWidgetNG::QtTreeWidgetNG(QtTreeController *controller, QWidget *parent) : QGraphicsView(parent), d_ptr(new QtTreeWidgetNGPrivate) { Q_D(QtTreeWidgetNG); + Q_ASSERT(controller); d->q_ptr = this; d->controller = controller; + controller->setParent(this); d->initialize(); } @@ -356,15 +355,22 @@ QtTreeDefaultModel *QtTreeWidgetNG::defaultModel() const } /*! + */ +void QtTreeWidgetNG::showEvent(QShowEvent *event) +{ + Q_D(QtTreeWidgetNG); + d->_q_updateGeometries(); + QGraphicsView::showEvent(event); +} + +/*! \reimp */ void QtTreeWidgetNG::resizeEvent(QResizeEvent *event) { Q_D(QtTreeWidgetNG); - QGraphicsView::resizeEvent(event); - QRect r = viewport()->geometry(); - scene()->setSceneRect(0, 0, r.width(), r.height()); - d->updateElementsLayout(r.size()); + d->_q_updateGeometries(); + QAbstractScrollArea::resizeEvent(event); } /*! @@ -374,13 +380,23 @@ void QtTreeWidgetNG::timerEvent(QTimerEvent *event) { Q_D(QtTreeWidgetNG); if (event->timerId() == d->timer.timerId()) { - d->updateScrollRanges(); + //d->updateScrollRanges(); d->controller->view()->update(); d->timer.stop(); } QGraphicsView::timerEvent(event); } +/*! + \reimp + */ +void QtTreeWidgetNG::scrollContentsBy(int dx, int dy) +{ + Q_UNUSED(dx); + Q_UNUSED(dy); + // do nothing +} + QT_END_NAMESPACE #include "moc_qtreewidgetng.cpp" diff --git a/src/qtreewidgetng.h b/src/qtreewidgetng.h index 20c7ab3..4786f67 100644 --- a/src/qtreewidgetng.h +++ b/src/qtreewidgetng.h @@ -53,9 +53,12 @@ public: QtTreeDefaultModel *defaultModel() const; protected: + void showEvent(QShowEvent *event); void resizeEvent(QResizeEvent *event); void timerEvent(QTimerEvent *event); + void scrollContentsBy(int dx, int dy); + protected: QtTreeWidgetNGPrivate *d_ptr; @@ -69,9 +72,12 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_itemsMoved(QtTreeModelIterator &from, QtTreeModelIterator &to, int count)) Q_PRIVATE_SLOT(d_func(), void _q_showView()) Q_PRIVATE_SLOT(d_func(), void _q_hideView()) - Q_PRIVATE_SLOT(d_func(), void _q_verticalScrollValueChanged(qreal value)) - Q_PRIVATE_SLOT(d_func(), void _q_horizontalScrollValueChanged(qreal value)) + Q_PRIVATE_SLOT(d_func(), void _q_updateGeometries()) Q_PRIVATE_SLOT(d_func(), void _q_modelChanged(QtTreeModelBase *current, QtTreeModelBase *previous)) + Q_PRIVATE_SLOT(d_func(), void _q_selectionManagerChanged(QtTreeSelectionManager *current, QtTreeSelectionManager *previous)) + Q_PRIVATE_SLOT(d_func(), void _q_viewChanged(QtGraphicsTreeView *current, QtGraphicsTreeView *previous)) + Q_PRIVATE_SLOT(d_func(), void _q_firstIndexChanged(int index)) + Q_PRIVATE_SLOT(d_func(), void _q_firstSectionChanged(int section)) }; QT_END_NAMESPACE diff --git a/src/qtreewidgetng_p.h b/src/qtreewidgetng_p.h index 67f0db9..be3d6df 100644 --- a/src/qtreewidgetng_p.h +++ b/src/qtreewidgetng_p.h @@ -59,10 +59,10 @@ public: void _q_itemsMoved(QtTreeModelBase::iterator_base &from, QtTreeModelBase::iterator_base &to, int count); void _q_showView(); void _q_hideView(); - void _q_verticalScrollValueChanged(qreal value); - void _q_horizontalScrollValueChanged(qreal value); + void _q_updateGeometries(); - void _q_firstSectionChanged(int visualIndex); + void _q_firstIndexChanged(int index); + void _q_firstSectionChanged(int section); void _q_offsetChanged(qreal offset); void _q_modelChanged(QtTreeModelBase *current, QtTreeModelBase *previous); @@ -71,16 +71,11 @@ public: void _q_viewChanged(QtGraphicsTreeView *current, QtGraphicsTreeView *previous); void _q_headerChanged(QtGraphicsHeader *current, QtGraphicsHeader *previous); void _q_controllerChanged(QtTreeController *current, QtTreeController *previous); - - void updateElementsLayout(const QSizeF &size); - void updateScrollRanges(); void initialize(); QtTreeController *controller; QtGraphicsHeader *header; - QtGraphicsScrollBar *verticalScrollbar; - QtGraphicsScrollBar *horizontalScrollbar; QBasicTimer timer; diff --git a/src/src.pro b/src/src.pro index d0139f8..758fa46 100644 --- a/src/src.pro +++ b/src/src.pro @@ -2,9 +2,8 @@ TEMPLATE = lib TARGET = itemviews-ng DESTDIR = $$OUT_PWD/../lib DEFINES += QT_BUILD_ITEMVIEWS_LIB -HEADERS += qitemviewsglobal.h \ - qgraphicsscrollbar.h \ - qgraphicsscrollbar_p.h \ +HEADERS += \ + qitemviewsglobal.h \ qgraphicsheader.h \ qgraphicsheader_p.h \ qlistcontroller.h \ @@ -59,7 +58,7 @@ HEADERS += qitemviewsglobal.h \ # experimental/qprintertableview.h \ # experimental/qprintertableview_p.h \ -SOURCES += qgraphicsscrollbar.cpp \ +SOURCES += \ qgraphicsheader.cpp \ qgraphicslistview.cpp \ qlistcontroller.cpp \ |