aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui/covereditor.cpp
blob: 07241ffc9a565492df5966863cab32d53b443f1c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/***************************************************************************
 *   Copyright (C) 2018 by Ilya Kotov                                      *
 *   forkotov02@ya.ru                                                      *
 *                                                                         *
 *   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 <QVBoxLayout>
#include "coverviewer_p.h"
#include "covereditor_p.h"

CoverEditor::CoverEditor(MetaDataModel *model, const QString &coverPath, QWidget *parent) :
    QWidget(parent)
{
    m_ui.setupUi(this);
    m_model = model;
    m_coverPath = coverPath;
    m_editable = m_model && (m_model->dialogHints() & MetaDataModel::IS_COVER_EDITABLE) && !m_model->isReadOnly();

    m_ui.sourceComboBox->addItem(tr("External file"));
    m_ui.sourceComboBox->addItem(tr("Tag"));

    m_viewer = new CoverViewer(this);
    QVBoxLayout *layout = new QVBoxLayout();
    layout->addWidget(m_viewer);
    m_ui.frame->setLayout(layout);

    if(m_model && !m_model->cover().isNull())
        m_ui.sourceComboBox->setCurrentIndex(1);
    else
        m_ui.sourceComboBox->setCurrentIndex(0);

    on_sourceComboBox_activated(m_ui.sourceComboBox->currentIndex());

    if(!m_model || m_coverPath.isEmpty() || (!m_editable && m_model->cover().isNull()))
        m_ui.sourceComboBox->setEnabled(false);
}

bool CoverEditor::isEditable() const
{
    return m_editable;
}

void CoverEditor::on_sourceComboBox_activated(int index)
{
    if(index == 0)
    {
        m_viewer->setPixmap(QPixmap(m_coverPath));
        m_ui.loadButton->setEnabled(false);
        m_ui.deleteButton->setEnabled(false);
        m_ui.saveAsButton->setEnabled(m_viewer->hasPixmap());
    }
    else if(index == 1)
    {
        m_viewer->setPixmap(m_model->cover());
        m_ui.loadButton->setEnabled(m_editable);
        m_ui.deleteButton->setEnabled(m_editable && m_viewer->hasPixmap());
        m_ui.saveAsButton->setEnabled(m_viewer->hasPixmap());
    }
}

void CoverEditor::on_loadButton_clicked()
{

}

void CoverEditor::on_deleteButton_clicked()
{

}

void CoverEditor::on_saveAsButton_clicked()
{
    m_viewer->saveAs();
}