1 /***************************************************************************
2 **                                                                        **
3 **  Polyphone, a soundfont editor                                         **
4 **  Copyright (C) 2013-2019 Davy Triponney                                **
5 **                                                                        **
6 **  This program is free software: you can redistribute it and/or modify  **
7 **  it under the terms of the GNU General Public License as published by  **
8 **  the Free Software Foundation, either version 3 of the License, or     **
9 **  (at your option) any later version.                                   **
10 **                                                                        **
11 **  This program is distributed in the hope that it will be useful,       **
12 **  but WITHOUT ANY WARRANTY; without even the implied warranty of        **
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          **
14 **  GNU General Public License for more details.                          **
15 **                                                                        **
16 **  You should have received a copy of the GNU General Public License     **
17 **  along with this program. If not, see http://www.gnu.org/licenses/.    **
18 **                                                                        **
19 ****************************************************************************
20 **           Author: Davy Triponney                                       **
21 **  Website/Contact: https://www.polyphone-soundfonts.com                 **
22 **             Date: 01.01.2013                                           **
23 ***************************************************************************/
24 
25 #include "soundfonteditorcenter.h"
26 #include "ui_soundfonteditorcenter.h"
27 #include "contextmanager.h"
28 #include "soundfontdetails.h"
29 
30 SoundfontEditorCenter::SoundfontEditorCenter(QWidget *parent) :
31     QWidget(parent),
32     ui(new Ui::SoundfontEditorCenter)
33 {
34     ui->setupUi(this);
35 
36     // Colors
37     QColor highlighted = ContextManager::theme()->getColor(ThemeManager::HIGHLIGHTED_BACKGROUND);
38     QColor highlightedText = ContextManager::theme()->getColor(ThemeManager::HIGHLIGHTED_TEXT);
39     QColor border = this->palette().dark().color();
40     QColor highlightedHover = ContextManager::theme()->getColor(ThemeManager::HIGHLIGHTED_BACKGROUND, ThemeManager::HOVERED);
41 
42     // Style
43     QString styleSheetTitle = "QLabel { background-color:" + highlighted.name() +
44             "; color: " + highlightedText.name() + ";border-radius: 2px; padding: 0 5px; }";
45     ui->labelDescription->setStyleSheet(styleSheetTitle);
46     ui->frameEditDownload->setStyleSheet("QFrame{background-color:" + highlighted.name() +
47                                          "; color: " + highlightedText.name() + ";border:0;border-radius: 2px; }");
48     ui->pushAddFile->setStyleSheet("QPushButton{border: 0; border-left: 1px solid " + border.name() + "; padding:0 5px 0 5px;" +
49                                    "color:" + highlightedText.name() + ";border-top-right-radius:2px;border-bottom-right-radius:2px}" +
50                                    "QPushButton:hover{background-color:" + highlightedHover.name() + "}");
51     ui->pushAddFile->setIcon(ContextManager::theme()->getColoredSvg(":/icons/document-new.svg", QSize(12, 12), ThemeManager::ColorType::HIGHLIGHTED_TEXT));
52 }
53 
54 SoundfontEditorCenter::~SoundfontEditorCenter()
55 {
56     delete ui;
57 }
58 
59 void SoundfontEditorCenter::initialize(SoundfontDetails *details)
60 {
61     ui->editorDescription->initialize(details->getDescription());
62     ui->editorFiles->initialize(details->getDownloads());
63 }
64 
65 void SoundfontEditorCenter::on_pushAddFile_clicked()
66 {
67     ui->editorFiles->addFile();
68 }
69 
70 QString SoundfontEditorCenter::getEditingError()
71 {
72     // At least one file must be uploaded
73     if (ui->editorFiles->fileCount() == 0)
74         return tr("At least one file must be uploaded.");
75 
76     return "";
77 }
78 
79 void SoundfontEditorCenter::fillArguments(QMap<QString, QString> &arguments)
80 {
81     arguments["details"] = ui->editorDescription->getPlainText();
82     ui->editorFiles->fillArguments(arguments);
83 }
84 
85 QMap<QString, QString> SoundfontEditorCenter::getFileArguments()
86 {
87     return ui->editorFiles->getFileArguments();
88 }
89