/*
 * Copyright 2010  Jonas Emanuel Müller <zanoi@zanoi.net>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of 
 * the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "episodeview.h"
#include "episodeviewdelegate.h"
#include "episodemodel.h"
#include "episodeproxymodel.h"

#include <QSqlRelationalDelegate>
#include <QHeaderView>

namespace Videocatcher {

EpisodeView::EpisodeView(QWidget *parent) : QTableView(parent)
{

}

void EpisodeView::setEpisodeModel(EpisodeProxyModel *episodeModel)
{
    setModel(episodeModel);
    setItemDelegate(new QSqlRelationalDelegate(this));
    setItemDelegateForColumn(Episode_Status, new EpisodeViewDelegate(this));
    setItemDelegateForColumn(Episode_Video_Size, new EpisodeViewDelegate(this));
    setItemDelegateForColumn(Episode_Date_Published, new EpisodeViewDelegate(this));
    setSelectionMode(QAbstractItemView::SingleSelection);
    setSelectionBehavior(QAbstractItemView::SelectRows);
    setEditTriggers(QAbstractItemView::NoEditTriggers);
    horizontalHeader()->setStretchLastSection(true);
    setColumnHidden(Episode_Id, true);
    setColumnHidden(Episode_Channel_Id, true);
    setColumnHidden(Episode_Video_Url, true);
    setColumnHidden(Episode_Video_Path, true);
    setColumnHidden(Episode_Video_Size, true);
    setColumnHidden(Episode_Description, true);
 
    setShowGrid(false);
    verticalHeader()->hide();
    setAlternatingRowColors(true);
    
    setSortingEnabled(true);
    sortByColumn(Episode_Date_Published, Qt::DescendingOrder);
}

} //namespace Videocatcher
