Skip to content
TrackDetails.cpp 3.76 KiB
Newer Older
/*
 * 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"
    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);
    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));
    albumCover->setMaximumSize(Wt::WLength(200,Wt::WLength::Pixel),Wt::WLength(200,Wt::WLength::Pixel));
    albumCover->addStyleClass("img-rounded");
    mainLayout->addSpacing(Wt::WLength(10, Wt::WLength::Pixel));
    mainLayout->addSpacing(Wt::WLength(10, Wt::WLength::Pixel));
    trackTitle->decorationStyle().setTextDecoration(Wt::WCssDecorationStyle::Underline);
    trackTitle->decorationStyle().font().setSize(Wt::WFont::Size::Large);
    trackTitle->decorationStyle().font().setWeight(Wt::WFont::Weight::Bold);
    metaLayout->addWidget(trackTitle,2);
    metaLayout->addWidget(trackAlbum,1,Wt::AlignmentFlag::AlignBottom);
    metaLayout->addWidget(trackArtist,1,Wt::AlignmentFlag::AlignBottom);
}

void TrackDetails::updateWithTrackDetails(AudioTrack track)
{
    this->animateHide(Wt::WAnimation(Wt::WAnimation::Fade));
    trackTitle->setText(track.trackName);
    trackArtist->setText(track.trackArtistName);
    trackAlbum->setText(track.trackAlbumName);
    trackFingerprint = track.trackFingerprint;
    trackGenre = track.trackGenre;
    
    //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));

void TrackDetails::changeBackgroundColor(Wt::WColor color)
{
    this->decorationStyle().setBackgroundColor(color);
}

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;
    return track;
}