Newer
Older
Kevin Whitaker
committed
/*
* Copyright (C) 2017 Kevin Whitaker <eyecreate@gmail.com>
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "TrackDetails.h"
Kevin Whitaker
committed
#include <Wt/WLength>
Kevin Whitaker
committed
#include <Wt/WCssDecorationStyle>
Kevin Whitaker
committed
TrackDetails::TrackDetails()
{
this->setMaximumSize(Wt::WLength::Auto,Wt::WLength(200, Wt::WLength::Pixel));
this->addStyleClass("panel");
this->addStyleClass("panel-default");
this->setMargin(Wt::WLength(0,Wt::WLength::Pixel),Wt::Side::Bottom);
Kevin Whitaker
committed
mainLayout = new Wt::WHBoxLayout();
this->setLayout(mainLayout);
metaLayout = new Wt::WVBoxLayout();
coverData = new Wt::WMemoryResource();
albumCover = new Wt::WImage();
albumCover->setMinimumSize(Wt::WLength(75,Wt::WLength::Pixel),Wt::WLength(75,Wt::WLength::Pixel));
Kevin Whitaker
committed
albumCover->setMaximumSize(Wt::WLength(200,Wt::WLength::Pixel),Wt::WLength(200,Wt::WLength::Pixel));
albumCover->addStyleClass("img-rounded");
Kevin Whitaker
committed
mainLayout->addWidget(albumCover);
mainLayout->addSpacing(Wt::WLength(10, Wt::WLength::Pixel));
Kevin Whitaker
committed
mainLayout->addLayout(metaLayout);
mainLayout->addSpacing(Wt::WLength(10, Wt::WLength::Pixel));
Kevin Whitaker
committed
trackTitle = new Wt::WText();
trackTitle->setWordWrap(false);
Kevin Whitaker
committed
trackTitle->decorationStyle().setTextDecoration(Wt::WCssDecorationStyle::Underline);
trackTitle->decorationStyle().font().setSize(Wt::WFont::Size::Large);
trackTitle->decorationStyle().font().setWeight(Wt::WFont::Weight::Bold);
Kevin Whitaker
committed
trackArtist = new Wt::WText();
trackArtist->setWordWrap(false);
Kevin Whitaker
committed
trackAlbum = new Wt::WText();
trackAlbum->setWordWrap(false);
Kevin Whitaker
committed
metaLayout->addWidget(trackTitle,2);
metaLayout->addWidget(trackAlbum,1,Wt::AlignmentFlag::AlignBottom);
metaLayout->addWidget(trackArtist,1,Wt::AlignmentFlag::AlignBottom);
Kevin Whitaker
committed
}
Kevin Whitaker
committed
TrackDetails::~TrackDetails()
{
mainLayout->clear();
delete coverData;
}
Kevin Whitaker
committed
void TrackDetails::updateWithTrackDetails(AudioTrack track)
{
this->animateHide(Wt::WAnimation(Wt::WAnimation::Fade));
Kevin Whitaker
committed
trackTitle->setText(track.trackName);
trackArtist->setText(track.trackArtistName);
trackAlbum->setText(track.trackAlbumName);
trackFingerprint = track.trackFingerprint;
trackGenre = track.trackGenre;
Kevin Whitaker
committed
trackPath = track.trackPath;
Kevin Whitaker
committed
//Set image to data from track obj.
coverData = new Wt::WMemoryResource(track.coverMimeType);
coverData->setData((unsigned char*)track.coverArt.data(),std::stoi(std::to_string(track.coverArt.size())));
albumCover->setResource(coverData);
this->animateShow(Wt::WAnimation(Wt::WAnimation::Fade,Wt::WAnimation::TimingFunction::EaseIn, 500));
Kevin Whitaker
committed
}
void TrackDetails::changeBackgroundColor(Wt::WColor color)
{
this->decorationStyle().setBackgroundColor(color);
}
Kevin Whitaker
committed
bool TrackDetails::trackMatches(AudioTrack track)
{
if(track.trackName == trackTitle->text() && track.trackArtistName == trackArtist->text() && track.trackAlbumName == trackAlbum->text())
{
return true;
}
return false;
}
AudioTrack TrackDetails::extractTrackFromDetails()
{
AudioTrack track;
track.trackName = trackTitle->text().toUTF8();
track.trackArtistName = trackArtist->text().toUTF8();
track.trackAlbumName = trackAlbum->text().toUTF8();
track.trackGenre = trackGenre;
track.trackFingerprint = trackFingerprint;
Kevin Whitaker
committed
track.trackPath = trackPath;
return track;
}