┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/dolphindetailsview.cpp
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2007-05-31 16:14:47 +0000
committerPeter Penz <[email protected]>2007-05-31 16:14:47 +0000
commit8d0e873f670cab8e7bc8df902abed6ebc17dd09d (patch)
treedf69760063202d89f516e369c81bb64bce8e8b57 /src/dolphindetailsview.cpp
parent83cda27db7d749946deee2defe8428a99a188011 (diff)
Provide a rubberband for the Details View when selecting items. This assures a consistent behavior with the Icons View and the selection style of other file managers (in opposite to QListView it is not possible in QTreeView to show a rubberband automatically within Qt 4.3 :-().
svn path=/trunk/KDE/kdebase/apps/; revision=670181
Diffstat (limited to 'src/dolphindetailsview.cpp')
-rw-r--r--src/dolphindetailsview.cpp72
1 files changed, 69 insertions, 3 deletions
diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp
index 87fa85165..2bb145cc4 100644
--- a/src/dolphindetailsview.cpp
+++ b/src/dolphindetailsview.cpp
@@ -30,11 +30,15 @@
#include <kdirmodel.h>
#include <kfileitemdelegate.h>
-#include <QtGui/QHeaderView>
+#include <QHeaderView>
+#include <QRubberBand>
+#include <QScrollBar>
DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* controller) :
QTreeView(parent),
- m_controller(controller)
+ m_controller(controller),
+ m_rubberBand(0),
+ m_origin()
{
Q_ASSERT(controller != 0);
@@ -94,7 +98,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
}
DolphinDetailsView::~DolphinDetailsView()
-{}
+{
+}
bool DolphinDetailsView::event(QEvent* event)
{
@@ -145,9 +150,39 @@ void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
m_controller->triggerContextMenuRequest(event->pos());
}
+void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
+{
+ QTreeView::mousePressEvent(event);
+
+ if (event->button() == Qt::LeftButton) {
+ // initialize rubberband for the selection
+ if (m_rubberBand == 0) {
+ m_rubberBand = new QRubberBand(QRubberBand::Rectangle, viewport());
+ }
+
+ const QPoint pos(contentsPos());
+ m_origin = event->pos();
+ m_origin.setX(m_origin.x() + pos.x());
+ m_origin.setY(m_origin.y() + pos.y());
+ updateRubberBandGeometry();
+ m_rubberBand->show();
+ }
+}
+
+void DolphinDetailsView::mouseMoveEvent(QMouseEvent* event)
+{
+ QTreeView::mouseMoveEvent(event);
+ if (m_rubberBand != 0) {
+ updateRubberBandGeometry();
+ }
+}
+
void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
{
QTreeView::mouseReleaseEvent(event);
+ if (m_rubberBand != 0) {
+ m_rubberBand->hide();
+ }
m_controller->triggerActivation();
}
@@ -156,6 +191,9 @@ void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
+ if (m_rubberBand != 0) {
+ m_rubberBand->hide();
+ }
}
void DolphinDetailsView::dropEvent(QDropEvent* event)
@@ -204,6 +242,16 @@ void DolphinDetailsView::slotEntered(const QModelIndex& index)
}
}
+void DolphinDetailsView::updateRubberBandGeometry()
+{
+ if (m_rubberBand != 0) {
+ const QPoint pos(contentsPos());
+ const QPoint origin(m_origin.x() - pos.x(), m_origin.y() - pos.y());
+ const QPoint dest(viewport()->mapFromGlobal(QCursor::pos()));
+ m_rubberBand->setGeometry(QRect(origin, dest).normalized());
+ }
+}
+
void DolphinDetailsView::zoomIn()
{
if (isZoomInPossible()) {
@@ -256,4 +304,22 @@ void DolphinDetailsView::updateDecorationSize()
doItemsLayout();
}
+QPoint DolphinDetailsView::contentsPos() const
+{
+ // implementation note: the horizonal position is ignored currently, as no
+ // horizontal scrolling is done anyway during a selection
+ const QScrollBar* scrollbar = verticalScrollBar();
+ Q_ASSERT(scrollbar != 0);
+
+ const int maxHeight = maximumViewportSize().height();
+ const int height = scrollbar->maximum() - scrollbar->minimum() + 1;
+ const int visibleHeight = model()->rowCount() + 1 - height;
+ if (visibleHeight <= 0) {
+ return QPoint(0, 0);
+ }
+
+ const int y = scrollbar->sliderPosition() * maxHeight / visibleHeight;
+ return QPoint(0, y);
+}
+
#include "dolphindetailsview.moc"