| 1 |
/* |
| 2 |
This file is part of Icecream. |
| 3 |
|
| 4 |
Copyright (c) 2003 Frerich Raabe <[email protected]> |
| 5 |
Copyright (c) 2003,2004 Stephan Kulow <[email protected]> |
| 6 |
Copyright (c) 2004, 2005 Andre Wöbbeking <[email protected]> |
| 7 |
Copyright (c) 2012 Kevin Funk <[email protected]> |
| 8 |
|
| 9 |
This program is free software; you can redistribute it and/or modify |
| 10 |
it under the terms of the GNU General Public License as published by |
| 11 |
the Free Software Foundation; either version 2 of the License, or |
| 12 |
(at your option) any later version. |
| 13 |
|
| 14 |
This program is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
GNU General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License along |
| 20 |
with this program; if not, write to the Free Software Foundation, Inc., |
| 21 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "joblistview.h" |
| 25 |
|
| 26 |
#include "models/joblistmodel.h" |
| 27 |
|
| 28 |
#include <QDebug> |
| 29 |
#include <QHeaderView> |
| 30 |
|
| 31 |
JobListView::JobListView(QWidget *parent) |
| 32 |
: QTreeView(parent) |
| 33 |
{ |
| 34 |
setAllColumnsShowFocus(true); |
| 35 |
setRootIsDecorated(false); |
| 36 |
setSortingEnabled(true); |
| 37 |
setWindowTitle(tr("Jobs")); |
| 38 |
} |
| 39 |
|
| 40 |
JobListModel *JobListView::jobListModel() const |
| 41 |
{ |
| 42 |
return qobject_cast<JobListModel *>(model()); |
| 43 |
} |
| 44 |
|
| 45 |
void JobListView::setModel(QAbstractItemModel *model) |
| 46 |
{ |
| 47 |
QTreeView::setModel(model); |
| 48 |
if (model) { |
| 49 |
sortByColumn(JobListModel::JobColumnID, Qt::AscendingOrder); |
| 50 |
header()->setStretchLastSection(false); |
| 51 |
header()->setSectionResizeMode(JobListModel::JobColumnFilename, QHeaderView::Stretch); |
| 52 |
header()->setSectionResizeMode(JobListModel::JobColumnClient, QHeaderView::ResizeToContents); |
| 53 |
header()->setSectionResizeMode(JobListModel::JobColumnServer, QHeaderView::ResizeToContents); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
bool JobListView::isClientColumnVisible() const |
| 58 |
{ |
| 59 |
return !isColumnHidden(JobListModel::JobColumnClient); |
| 60 |
} |
| 61 |
|
| 62 |
void JobListView::setClientColumnVisible(bool visible) |
| 63 |
{ |
| 64 |
if (visible == isClientColumnVisible()) { |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
if (visible) { |
| 69 |
setColumnHidden(JobListModel::JobColumnClient, false); |
| 70 |
resizeColumnToContents(JobListModel::JobColumnClient); |
| 71 |
} else { |
| 72 |
setColumnHidden(JobListModel::JobColumnClient, true); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
bool JobListView::isServerColumnVisible() const |
| 77 |
{ |
| 78 |
return !isColumnHidden(JobListModel::JobColumnServer); |
| 79 |
} |
| 80 |
|
| 81 |
void JobListView::setServerColumnVisible(bool visible) |
| 82 |
{ |
| 83 |
if (visible == isServerColumnVisible()) { |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
if (visible) { |
| 88 |
setColumnHidden(JobListModel::JobColumnServer, false); |
| 89 |
resizeColumnToContents(JobListModel::JobColumnServer); |
| 90 |
} else { |
| 91 |
setColumnHidden(JobListModel::JobColumnServer, true); |
| 92 |
} |
| 93 |
} |