#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);
}
DolphinDetailsView::~DolphinDetailsView()
-{}
+{
+}
bool DolphinDetailsView::event(QEvent* 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();
}
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
+ if (m_rubberBand != 0) {
+ m_rubberBand->hide();
+ }
}
void DolphinDetailsView::dropEvent(QDropEvent* event)
}
}
+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()) {
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"
#include <libdolphin_export.h>
class DolphinController;
+class QRubberBand;
/**
* @brief Represents the details view which shows the name, size,
virtual bool event(QEvent* event);
virtual QStyleOptionViewItem viewOptions() const;
virtual void contextMenuEvent(QContextMenuEvent* event);
+ virtual void mousePressEvent(QMouseEvent* event);
+ virtual void mouseMoveEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dropEvent(QDropEvent* event);
*/
void slotEntered(const QModelIndex& index);
+ /**
+ * Updates the geometry of the rubberband dependent from the current
+ * mouse position and the starting origin \a m_origin.
+ */
+ void updateRubberBandGeometry();
+
void zoomIn();
void zoomOut();
*/
void updateDecorationSize();
+ /** Return the upper left position in pixels of the viewport content. */
+ QPoint contentsPos() const;
+
private:
DolphinController* m_controller;
QStyleOptionViewItem m_viewOptions;
+
+ QRubberBand* m_rubberBand;
+ QPoint m_origin;
};
#endif