26 #include <QHeaderView>
27 #include <QSignalMapper>
28 #include <QHBoxLayout>
35 setRootIsDecorated(
false);
37 setAllColumnsShowFocus(
true);
38 header()->setDefaultAlignment(Qt::AlignCenter);
39 header()->setMinimumSectionSize(80);
40 header()->setContextMenuPolicy(Qt::CustomContextMenu);
41 header()->setClickable(
true);
42 m_headerMenu =
new KMenu(header());
44 setSelectionMode(QAbstractItemView::ExtendedSelection);
47 setDropIndicatorShown(
true);
48 setEditTriggers(QAbstractItemView::NoEditTriggers);
49 setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
50 setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
52 connect(header(), SIGNAL(customContextMenuRequested(QPoint)),
53 SLOT(slotShowHeaderMenu(QPoint)));
54 connect(header(), SIGNAL(sectionCountChanged(
int,
int)),
this, SLOT(populateHeaderActions()));
55 connect(header(), SIGNAL(sectionMoved(
int,
int,
int)),
this, SLOT(slotSectionMoved(
int,
int,
int)));
56 connect(header(), SIGNAL(sectionResized(
int,
int,
int)),
this, SLOT(slotSaveHeader()));
57 connect(
this, SIGNAL(doubleClicked(QModelIndex)),
59 connect(
this, SIGNAL(collapsed(QModelIndex)),
71 QTreeView::setModel(model);
72 int nGroups = model->rowCount(QModelIndex());
74 for(
int i = 0; i < nGroups; i++)
76 kDebug(5001) <<
"openEditor for row " << i;
81 if (loadedState.isEmpty()) {
82 setColumnWidth(0 , 230);
84 header()->restoreState(loadedState);
88 header()->setRootIndex(QModelIndex());
90 populateHeaderActions();
92 connect(model, SIGNAL(rowsRemoved(QModelIndex,
int,
int)), SLOT (toggleMainGroup()));
95 void TransfersView::dropEvent(QDropEvent * event)
97 QModelIndex dropIndex = indexAt(event->pos());
98 QTreeView::dropEvent(event);
100 setExpanded(dropIndex,
true);
103 void TransfersView::rowsInserted(
const QModelIndex & parent,
int start,
int end)
105 kDebug(5001) <<
"TransfersView::rowsInserted";
107 if(!parent.isValid())
109 kDebug(5001) <<
"parent is not valid " << start <<
" " << end;
111 for(
int i = start; i <= end; i++)
113 kDebug(5001) <<
"openEditor for row " << i;
118 QTreeView::rowsInserted(parent, start, end);
120 setExpanded(parent,
true);
124 void TransfersView::populateHeaderActions()
126 m_headerMenu->clear();
127 m_headerMenu->addTitle(i18n(
"Select columns"));
129 QSignalMapper *columnMapper =
new QSignalMapper(
this);
130 connect(columnMapper, SIGNAL(mapped(
int)), SLOT(slotHideSection(
int)));
133 QVector<KAction*> orderedMenuItems(header()->count());
134 for (
int i = 0; i < header()->count(); ++i) {
135 KAction *action =
new KAction(
this);
136 action->setText(model()->headerData(i, Qt::Horizontal).toString());
137 action->setCheckable(
true);
138 action->setChecked(!header()->isSectionHidden(i));
139 orderedMenuItems[header()->visualIndex(i)] = action;
141 connect(action, SIGNAL(toggled(
bool)), columnMapper, SLOT(map()));
142 columnMapper->setMapping(action, i);
146 for (
int i = 0; i < orderedMenuItems.count(); ++i) {
147 m_headerMenu->addAction(orderedMenuItems[i]);
151 void TransfersView::slotHideSection(
int logicalIndex)
153 const bool hide = !header()->isSectionHidden(logicalIndex);
154 header()->setSectionHidden(logicalIndex, hide);
158 void TransfersView::slotSectionMoved(
int logicalIndex,
int oldVisualIndex,
int newVisualIndex)
160 Q_UNUSED(logicalIndex)
165 QList<QAction*> actions = m_headerMenu->actions();
167 QAction *before = actions.last();
168 if (newVisualIndex + 1 < actions.count()) {
169 if (newVisualIndex > oldVisualIndex) {
170 before = actions[newVisualIndex + 1];
172 before = actions[newVisualIndex];
176 QAction *action = actions[oldVisualIndex];
177 m_headerMenu->removeAction(action);
178 m_headerMenu->insertAction(before, action);
182 void TransfersView::slotSaveHeader()
193 QTreeView::dragMoveEvent(event);
198 if (!index.isValid())
208 if(!item->
isGroup() && index.column() == 0) {
209 if(!view_delegate->isExtended(index)) {
211 QWidget *widget = getDetailsWidgetForTransfer(handler);
213 m_editingIndexes.append(index);
214 view_delegate->extendItem(widget, index);
217 m_editingIndexes.removeAll(index);
218 view_delegate->contractItem(index);
222 new KRun(static_cast<TransferModelItem*>(item)->transferHandler()->dest(),
this);
228 if (!index.isValid())
240 QList<TransferHandler *> transfers = groupHandler->
transfers();
243 kDebug(5001) <<
"Transfer = " << transfer->
source().prettyUrl();
244 view_delegate->contractItem(
KGet::model()->itemFromTransferHandler(transfer)->index());
249 void TransfersView::toggleMainGroup()
252 int nGroups = model()->rowCount(QModelIndex());
255 setRootIndex(model()->index(0, 0, QModelIndex()));
258 setRootIndex(QModelIndex());
260 header()->setRootIndex(QModelIndex());
272 void TransfersView::slotShowHeaderMenu(
const QPoint &point)
274 m_headerMenu->popup(header()->mapToGlobal(point));
281 if(transferIndex.isValid()) {
282 view_delegate->contractItem(transferIndex);
283 m_editingIndexes.removeAll(transferIndex);
285 view_delegate->contractAll();
286 m_editingIndexes.clear();
290 void TransfersView::selectionChanged(
const QItemSelection & selected,
const QItemSelection & deselected)
293 if (!selected.indexes().isEmpty()) {
295 KGet::actionCollection()->action(
"transfer_show_details")->setChecked(view_delegate->isExtended(selected.indexes().first()));
298 QTreeView::selectionChanged(selected, deselected);
309 view_delegate->contractAll();
310 m_editingIndexes.clear();
315 QGroupBox *groupBox =
new QGroupBox(i18n(
"Transfer Details"));
317 QVBoxLayout *layout =
new QVBoxLayout(groupBox);
319 layout->addWidget(detailsWidget);
324 #include "transfersview.moc"
The job is stopped, but this also indicates that it stopped because an error occurred.
void closeExpandableDetails(const QModelIndex &index=QModelIndex())
GroupModelItem * asGroup()
void setModel(QAbstractItemModel *model)
void slotItemCollapsed(const QModelIndex &index)
void dragMoveEvent(QDragMoveEvent *event)
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
ModelItem * itemFromIndex(const QModelIndex &index) const
static QWidget * detailsWidget(TransferHandler *transfer)
static TransferTreeModel * model()
const KUrl & source() const
static KActionCollection * actionCollection()
TransferGroupHandler * groupHandler()
void slotItemActivated(const QModelIndex &index)
const QList< TransferHandler * > transfers()
TransferModelItem * asTransfer()
static void setHeaderState(const QString &v)
Set HeaderState.
TransfersView(QWidget *parent=0)
static QString headerState()
Get HeaderState.
TransferHandler * transferHandler()