1 /*
2  * Cantata
3  *
4  * Copyright (c) 2011-2020 Craig Drummond <craig.p.drummond@gmail.com>
5  *
6  * ----
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; see the file COPYING.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #include <QFormLayout>
25 #include <QLabel>
26 #include <QStyle>
27 #include "support/icon.h"
28 #include "lyricsdialog.h"
29 
LyricsDialog(const Song & s,QWidget * parent)30 LyricsDialog::LyricsDialog(const Song &s, QWidget *parent)
31     : Dialog(parent)
32     , prev(s)
33 {
34     QWidget *mw=new QWidget(this);
35     QGridLayout *mainLayout=new QGridLayout(mw);
36     QWidget *wid = new QWidget(mw);
37     QFormLayout *layout = new QFormLayout(wid);
38     int row=0;
39     QLabel *lbl=new QLabel(tr("If Cantata has failed to find lyrics, or has found the wrong ones, "
40                                 "use this dialog to enter new search details. For example, the current "
41                                 "song may actually be a cover-version - if so, then searching for "
42                                 "lyrics by the original artist might help.\n\nIf this search does find "
43                                 "new lyrics, these will still be associated with the original song title "
44                                 "and artist as displayed in Cantata."), mw);
45     lbl->setWordWrap(true);
46     QLabel *icn=new QLabel(mw);
47     icn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
48     int iconSize=Icon::dlgIconSize();
49     icn->setFixedSize(iconSize, iconSize);
50     icn->setPixmap(style()->standardIcon(QStyle::SP_MessageBoxInformation).pixmap(iconSize, iconSize));
51     mainLayout->setMargin(0);
52     layout->setMargin(0);
53     mainLayout->addWidget(icn, 0, 0, 1, 1);
54     mainLayout->addWidget(lbl, 0, 1, 1, 1);
55     mainLayout->addItem(new QSpacerItem(8, 4, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 0);
56     mainLayout->addWidget(wid, 2, 0, 1, 2);
57     titleEntry = new LineEdit(wid);
58     artistEntry = new LineEdit(wid);
59 
60     layout->setWidget(row, QFormLayout::LabelRole, new QLabel(tr("Title:"), wid));
61     layout->setWidget(row++, QFormLayout::FieldRole, titleEntry);
62     layout->setWidget(row, QFormLayout::LabelRole, new QLabel(tr("Artist:"), wid));
63     layout->setWidget(row++, QFormLayout::FieldRole, artistEntry);
64     setCaption(tr("Search For Lyrics"));
65     setMainWidget(mw);
66     setButtons(Ok|Cancel);
67     enableButton(Ok, false);
68     connect(titleEntry, SIGNAL(textChanged(const QString &)), SLOT(changed()));
69     connect(artistEntry, SIGNAL(textChanged(const QString &)), SLOT(changed()));
70     titleEntry->setFocus();
71     titleEntry->setText(s.title);
72     artistEntry->setText(s.artist);
73 }
74 
song() const75 Song LyricsDialog::song() const
76 {
77     Song s=prev;
78     s.artist=artistEntry->text().trimmed();
79     s.title=titleEntry->text().trimmed();
80     return s;
81 }
82 
changed()83 void LyricsDialog::changed()
84 {
85     Song s=song();
86     enableButton(Ok, !s.artist.isEmpty() && !s.title.isEmpty() && (s.artist!=prev.artist || s.title!=prev.title));
87 }
88 
89 #include "moc_lyricsdialog.cpp"
90