• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

ark

  • sources
  • kde-4.14
  • kdeutils
  • ark
  • part
archiveview.cpp
Go to the documentation of this file.
1 /*
2  * ark -- archiver for the KDE project
3  *
4  * Copyright (C) 2008-2009 Harald Hvaal <haraldhv (at@at) stud.ntnu.no>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  */
21 
22 #include "archiveview.h"
23 
24 #include <KDebug>
25 #include <KGlobalSettings>
26 
27 #include <QApplication>
28 #include <QDragEnterEvent>
29 #include <QDragMoveEvent>
30 #include <QMouseEvent>
31 
32 ArchiveView::ArchiveView(QWidget *parent)
33  : QTreeView(parent)
34  , m_mouseButtons(Qt::NoButton)
35 {
36  connect(this, SIGNAL(pressed(QModelIndex)),
37  SLOT(updateMouseButtons()));
38  connect(this, SIGNAL(clicked(QModelIndex)),
39  SLOT(slotClicked(QModelIndex)));
40  connect(this, SIGNAL(doubleClicked(QModelIndex)),
41  SLOT(slotDoubleClicked(QModelIndex)));
42 }
43 
44 // FIXME: this is a workaround taken from Dolphin until QTBUG-1067 is resolved
45 void ArchiveView::updateMouseButtons()
46 {
47  m_mouseButtons = QApplication::mouseButtons();
48 }
49 
50 void ArchiveView::slotClicked(const QModelIndex& index)
51 {
52  if (KGlobalSettings::singleClick()) {
53  if (m_mouseButtons != Qt::LeftButton) { // FIXME: see QTBUG-1067
54  return;
55  }
56 
57  // If the user is pressing shift or control, more than one item is being selected
58  const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
59  if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) {
60  return;
61  }
62 
63  emit itemTriggered(index);
64  }
65 }
66 
67 void ArchiveView::slotDoubleClicked(const QModelIndex& index)
68 {
69  if (!KGlobalSettings::singleClick()) {
70  emit itemTriggered(index);
71  }
72 }
73 
74 void ArchiveView::setModel(QAbstractItemModel *model)
75 {
76  kDebug();
77  QTreeView::setModel(model);
78  setSelectionMode(QAbstractItemView::ExtendedSelection);
79  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
80  setAlternatingRowColors(true);
81  setAnimated(true);
82  setAllColumnsShowFocus(true);
83  setSortingEnabled(true);
84 
85  //drag and drop
86  setDragEnabled(true);
87  setAcceptDrops(true);
88  setDropIndicatorShown(true);
89  setDragDropMode(QAbstractItemView::DragDrop);
90 }
91 
92 void ArchiveView::startDrag(Qt::DropActions supportedActions)
93 {
94  //only start the drag if it's over the filename column. this allows dragging selection in
95  //tree/detail view
96  if (currentIndex().column() != 0) {
97  return;
98  }
99 
100  kDebug() << "Singling out the current selection...";
101  selectionModel()->setCurrentIndex(currentIndex(), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
102  QTreeView::startDrag(supportedActions);
103 }
104 
105 
106 void ArchiveView::dragEnterEvent(QDragEnterEvent * event)
107 {
108  //TODO: if no model, trigger some mechanism to create one automatically!
109  kDebug() << event;
110 
111  if (event->source() == this) {
112  //we don't support internal drops yet.
113  return;
114  }
115 
116  QTreeView::dragEnterEvent(event);
117 }
118 
119 void ArchiveView::dropEvent(QDropEvent * event)
120 {
121  kDebug() << event;
122 
123  if (event->source() == this) {
124  //we don't support internal drops yet.
125  return;
126  }
127 
128  QTreeView::dropEvent(event);
129 }
130 
131 void ArchiveView::dragMoveEvent(QDragMoveEvent * event)
132 {
133  if (event->source() == this) {
134  //we don't support internal drops yet.
135  return;
136  }
137 
138  QTreeView::dragMoveEvent(event);
139  if (event->mimeData()->hasFormat(QLatin1String("text/uri-list"))) {
140  event->acceptProposedAction();
141  }
142 }
QAbstractItemView::doubleClicked
void doubleClicked(const QModelIndex &index)
QApplication::mouseButtons
Qt::MouseButtons mouseButtons()
QModelIndex
ArchiveView::itemTriggered
void itemTriggered(const QModelIndex &index)
QDropEvent::source
QWidget * source() const
QWidget
ArchiveView::dragEnterEvent
virtual void dragEnterEvent(class QDragEnterEvent *event)
Definition: archiveview.cpp:106
QTreeView::dragMoveEvent
virtual void dragMoveEvent(QDragMoveEvent *event)
QAbstractItemView::setAlternatingRowColors
void setAlternatingRowColors(bool enable)
QDropEvent::mimeData
const QMimeData * mimeData() const
QApplication::keyboardModifiers
Qt::KeyboardModifiers keyboardModifiers()
QAbstractItemView::setSelectionMode
void setSelectionMode(QAbstractItemView::SelectionMode mode)
archiveview.h
ArchiveView::slotDoubleClicked
void slotDoubleClicked(const QModelIndex &index)
Definition: archiveview.cpp:67
QAbstractItemView::selectionModel
QItemSelectionModel * selectionModel() const
QDragMoveEvent
QMimeData::hasFormat
virtual bool hasFormat(const QString &mimeType) const
QAbstractItemView::setDragDropMode
void setDragDropMode(DragDropMode behavior)
QTreeView::setAnimated
void setAnimated(bool enable)
ArchiveView::startDrag
virtual void startDrag(Qt::DropActions supportedActions)
Definition: archiveview.cpp:92
QAbstractItemView::pressed
void pressed(const QModelIndex &index)
QDropEvent
QAbstractItemView::startDrag
virtual void startDrag(QFlags< Qt::DropAction > supportedActions)
ArchiveView::dragMoveEvent
virtual void dragMoveEvent(class QDragMoveEvent *event)
Definition: archiveview.cpp:131
QAbstractItemView::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *event)
QTreeView::setAllColumnsShowFocus
void setAllColumnsShowFocus(bool enable)
QWidget::setSizePolicy
void setSizePolicy(QSizePolicy)
ArchiveView::ArchiveView
ArchiveView(QWidget *parent=0)
Definition: archiveview.cpp:32
QWidget::setAcceptDrops
void setAcceptDrops(bool on)
ArchiveView::dropEvent
virtual void dropEvent(class QDropEvent *event)
Definition: archiveview.cpp:119
QAbstractItemView::event
virtual bool event(QEvent *event)
QTreeView::setSortingEnabled
void setSortingEnabled(bool enable)
QDragEnterEvent
QLatin1String
QTreeView
Qt::DropActions
typedef DropActions
QTreeView::setModel
virtual void setModel(QAbstractItemModel *model)
QAbstractItemView::dropEvent
virtual void dropEvent(QDropEvent *event)
ArchiveView::slotClicked
void slotClicked(const QModelIndex &index)
Definition: archiveview.cpp:50
QAbstractItemModel
ArchiveView::setModel
void setModel(QAbstractItemModel *model)
Definition: archiveview.cpp:74
QAbstractItemView::clicked
void clicked(const QModelIndex &index)
QItemSelectionModel::setCurrentIndex
void setCurrentIndex(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
QAbstractItemView::currentIndex
QModelIndex currentIndex() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QAbstractItemView::setDropIndicatorShown
void setDropIndicatorShown(bool enable)
QAbstractItemView::setDragEnabled
void setDragEnabled(bool enable)
Qt::KeyboardModifiers
typedef KeyboardModifiers
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ark

Skip menu "ark"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal