┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/kitemlistcontainer.cpp
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2012-04-21 21:28:16 +0200
committerPeter Penz <[email protected]>2012-04-21 21:32:42 +0200
commitae4d11d918938fd9087f2035dac247969c1f2313 (patch)
tree0303667797c81814b46b9ed5ed20b48ef31f2d71 /src/kitemviews/kitemlistcontainer.cpp
parent47d7cdffdd2d2c04067a5088eaeff67add53dde3 (diff)
Prepare view-engine for non-KFileItem usecase
Up to now the view-engine only provided a model-implementation that supports file-items. The view-engine always had been designed to be able to work with any kind of model, so now a KStandardItemModel is available. The plan is to convert the places panel to the new view-engine. It should be no problem to fix this until the feature freeze - in the worst case the places-panel code could be reverted while still keeping the KStandardItemModel changes.
Diffstat (limited to 'src/kitemviews/kitemlistcontainer.cpp')
-rw-r--r--src/kitemviews/kitemlistcontainer.cpp84
1 files changed, 48 insertions, 36 deletions
diff --git a/src/kitemviews/kitemlistcontainer.cpp b/src/kitemviews/kitemlistcontainer.cpp
index 5a485b62c..5500851c8 100644
--- a/src/kitemviews/kitemlistcontainer.cpp
+++ b/src/kitemviews/kitemlistcontainer.cpp
@@ -67,8 +67,6 @@ void KItemListContainerViewport::wheelEvent(QWheelEvent* event)
event->ignore();
}
-
-
KItemListContainer::KItemListContainer(KItemListController* controller, QWidget* parent) :
QAbstractScrollArea(parent),
m_controller(controller),
@@ -77,20 +75,32 @@ KItemListContainer::KItemListContainer(KItemListController* controller, QWidget*
{
Q_ASSERT(controller);
controller->setParent(this);
- initialize();
-}
-KItemListContainer::KItemListContainer(QWidget* parent) :
- QAbstractScrollArea(parent),
- m_controller(0),
- m_horizontalSmoothScroller(0),
- m_verticalSmoothScroller(0)
-{
- initialize();
+ QGraphicsView* graphicsView = new KItemListContainerViewport(new QGraphicsScene(this), this);
+ setViewport(graphicsView);
+
+ m_horizontalSmoothScroller = new KItemListSmoothScroller(horizontalScrollBar(), this);
+ m_verticalSmoothScroller = new KItemListSmoothScroller(verticalScrollBar(), this);
+
+ if (controller->model()) {
+ slotModelChanged(controller->model(), 0);
+ }
+ if (controller->view()) {
+ slotViewChanged(controller->view(), 0);
+ }
+
+ connect(controller, SIGNAL(modelChanged(KItemModelBase*,KItemModelBase*)),
+ this, SLOT(slotModelChanged(KItemModelBase*,KItemModelBase*)));
+ connect(controller, SIGNAL(viewChanged(KItemListView*,KItemListView*)),
+ this, SLOT(slotViewChanged(KItemListView*,KItemListView*)));
}
KItemListContainer::~KItemListContainer()
{
+ // Don't rely on the QObject-order to delete the controller, otherwise
+ // the QGraphicsScene might get deleted before the view.
+ delete m_controller;
+ m_controller = 0;
}
KItemListController* KItemListContainer::controller() const
@@ -98,6 +108,33 @@ KItemListController* KItemListContainer::controller() const
return m_controller;
}
+void KItemListContainer::setEnabledFrame(bool enable)
+{
+ QGraphicsView* graphicsView = qobject_cast<QGraphicsView*>(viewport());
+ if (enable) {
+ setFrameShape(QFrame::StyledPanel);
+ graphicsView->setPalette(palette());
+ graphicsView->viewport()->setAutoFillBackground(true);
+ } else {
+ setFrameShape(QFrame::NoFrame);
+ // Make the background of the container transparent and apply the window-text color
+ // to the text color, so that enough contrast is given for all color
+ // schemes
+ QPalette p = graphicsView->palette();
+ p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText));
+ p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText));
+ p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText));
+ graphicsView->setPalette(p);
+ graphicsView->viewport()->setAutoFillBackground(false);
+ }
+}
+
+bool KItemListContainer::enabledFrame() const
+{
+ const QGraphicsView* graphicsView = qobject_cast<QGraphicsView*>(viewport());
+ return graphicsView->autoFillBackground();
+}
+
void KItemListContainer::keyPressEvent(QKeyEvent* event)
{
// TODO: We should find a better way to handle the key press events in the view.
@@ -355,29 +392,4 @@ void KItemListContainer::updateScrollOffsetScrollBarPolicy()
}
}
-void KItemListContainer::initialize()
-{
- if (m_controller) {
- if (m_controller->model()) {
- slotModelChanged(m_controller->model(), 0);
- }
- if (m_controller->view()) {
- slotViewChanged(m_controller->view(), 0);
- }
- } else {
- m_controller = new KItemListController(this);
- }
-
- connect(m_controller, SIGNAL(modelChanged(KItemModelBase*,KItemModelBase*)),
- this, SLOT(slotModelChanged(KItemModelBase*,KItemModelBase*)));
- connect(m_controller, SIGNAL(viewChanged(KItemListView*,KItemListView*)),
- this, SLOT(slotViewChanged(KItemListView*,KItemListView*)));
-
- QGraphicsView* graphicsView = new KItemListContainerViewport(new QGraphicsScene(this), this);
- setViewport(graphicsView);
-
- m_horizontalSmoothScroller = new KItemListSmoothScroller(horizontalScrollBar(), this);
- m_verticalSmoothScroller = new KItemListSmoothScroller(verticalScrollBar(), this);
-}
-
#include "kitemlistcontainer.moc"