2010-05-09 22:18:05 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
Clementine 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "radioviewcontainer.h"
|
|
|
|
#include "radiomodel.h"
|
|
|
|
#include "radioservice.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "ui_radioviewcontainer.h"
|
|
|
|
#include "core/mergedproxymodel.h"
|
2010-05-09 22:18:05 +02:00
|
|
|
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <QTimeLine>
|
|
|
|
|
2010-06-09 17:38:00 +02:00
|
|
|
const int RadioViewContainer::kAnimationDuration = 500;
|
|
|
|
|
2010-05-09 22:18:05 +02:00
|
|
|
RadioViewContainer::RadioViewContainer(QWidget *parent)
|
|
|
|
: QWidget(parent),
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_(new Ui_RadioViewContainer),
|
2010-05-09 22:18:05 +02:00
|
|
|
model_(NULL),
|
|
|
|
current_service_(NULL),
|
2010-06-09 17:38:00 +02:00
|
|
|
current_header_(NULL)
|
2010-05-09 22:18:05 +02:00
|
|
|
{
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->setupUi(this);
|
2010-05-09 22:18:05 +02:00
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
connect(ui_->tree, SIGNAL(collapsed(QModelIndex)), SLOT(Collapsed(QModelIndex)));
|
|
|
|
connect(ui_->tree, SIGNAL(expanded(QModelIndex)), SLOT(Expanded(QModelIndex)));
|
|
|
|
}
|
|
|
|
|
|
|
|
RadioViewContainer::~RadioViewContainer() {
|
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
|
|
|
RadioView* RadioViewContainer::tree() const {
|
|
|
|
return ui_->tree;
|
2010-05-09 22:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RadioViewContainer::SetModel(RadioModel* model) {
|
|
|
|
model_ = model;
|
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->tree->setModel(model->merged_model());
|
2010-05-09 22:18:05 +02:00
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
connect(ui_->tree->selectionModel(),
|
2010-05-09 22:18:05 +02:00
|
|
|
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
|
|
|
SLOT(CurrentIndexChanged(QModelIndex)));
|
|
|
|
}
|
|
|
|
|
2010-06-09 17:38:00 +02:00
|
|
|
void RadioViewContainer::ServiceChanged(const QModelIndex& index) {
|
2010-05-09 22:18:05 +02:00
|
|
|
RadioItem* item = model_->IndexToItem(
|
|
|
|
model_->merged_model()->FindSourceParent(index));
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
2010-06-09 17:38:00 +02:00
|
|
|
RadioService* service = item->service;
|
|
|
|
if (!service || service == current_service_)
|
|
|
|
return;
|
|
|
|
current_service_ = service;
|
|
|
|
|
|
|
|
QWidget* header = service->HeaderWidget();
|
|
|
|
if (header && !headers_.contains(header)) {
|
|
|
|
header->setParent(ui_->header_container);
|
|
|
|
header->setMaximumHeight(0);
|
|
|
|
ui_->header_container->layout()->addWidget(header);
|
|
|
|
header->show();
|
|
|
|
|
|
|
|
HeaderData d;
|
|
|
|
d.visible_ = false;
|
|
|
|
d.animation_ = new QTimeLine(kAnimationDuration, this);
|
|
|
|
d.animation_->setFrameRange(0, header->sizeHint().height());
|
|
|
|
connect(d.animation_, SIGNAL(frameChanged(int)), SLOT(SetHeaderHeight(int)));
|
|
|
|
|
|
|
|
headers_.insert(header, d);
|
2010-05-09 23:16:54 +02:00
|
|
|
}
|
2010-06-09 17:38:00 +02:00
|
|
|
|
|
|
|
SetHeaderVisible(current_header_, false);
|
|
|
|
current_header_ = header;
|
|
|
|
SetHeaderVisible(current_header_, true);
|
2010-05-09 23:16:54 +02:00
|
|
|
}
|
2010-05-09 22:18:05 +02:00
|
|
|
|
2010-05-09 23:16:54 +02:00
|
|
|
void RadioViewContainer::CurrentIndexChanged(const QModelIndex& index) {
|
|
|
|
ServiceChanged(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioViewContainer::Collapsed(const QModelIndex& index) {
|
|
|
|
if (model_->merged_model()->mapToSource(index).model() == model_) {
|
2010-06-09 17:38:00 +02:00
|
|
|
SetHeaderVisible(current_header_, false);
|
2010-05-09 23:16:54 +02:00
|
|
|
current_service_ = NULL;
|
2010-06-09 17:38:00 +02:00
|
|
|
current_header_ = NULL;
|
2010-05-09 23:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-09 22:18:05 +02:00
|
|
|
|
2010-05-09 23:16:54 +02:00
|
|
|
void RadioViewContainer::Expanded(const QModelIndex& index) {
|
|
|
|
ServiceChanged(index);
|
2010-05-09 22:18:05 +02:00
|
|
|
}
|
|
|
|
|
2010-06-09 17:38:00 +02:00
|
|
|
void RadioViewContainer::SetHeaderVisible(QWidget* header, bool visible) {
|
|
|
|
if (!header)
|
|
|
|
return;
|
|
|
|
|
|
|
|
HeaderData& d = headers_[header];
|
|
|
|
if (d.visible_ == visible)
|
2010-05-09 22:18:05 +02:00
|
|
|
return;
|
2010-06-09 17:38:00 +02:00
|
|
|
d.visible_ = visible;
|
2010-05-09 22:18:05 +02:00
|
|
|
|
2010-06-09 17:38:00 +02:00
|
|
|
d.animation_->setDirection(visible ? QTimeLine::Forward : QTimeLine::Backward);
|
|
|
|
d.animation_->start();
|
2010-05-09 22:18:05 +02:00
|
|
|
}
|
|
|
|
|
2010-06-09 17:38:00 +02:00
|
|
|
void RadioViewContainer::SetHeaderHeight(int height) {
|
|
|
|
QTimeLine* animation = qobject_cast<QTimeLine*>(sender());
|
|
|
|
QWidget* header = NULL;
|
|
|
|
foreach (QWidget* h, headers_.keys()) {
|
|
|
|
if (headers_[h].animation_ == animation) {
|
|
|
|
header = h;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (header)
|
|
|
|
header->setMaximumHeight(height);
|
2010-05-09 22:18:05 +02:00
|
|
|
}
|