1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4     Rosegarden
5     A MIDI and audio sequencer and musical notation editor.
6     Copyright 2000-2021 the Rosegarden development team.
7 
8     Other copyrights also apply to some parts of this work.  Please
9     see the AUTHORS file and individual file headers for details.
10 
11     This program is free software; you can redistribute it and/or
12     modify it under the terms of the GNU General Public License as
13     published by the Free Software Foundation; either version 2 of the
14     License, or (at your option) any later version.  See the file
15     COPYING included with this distribution for more information.
16 */
17 
18 
19 #include "CommentsPopupDialog.h"
20 
21 #include "document/RosegardenDocument.h"
22 #include "document/MetadataHelper.h"
23 
24 #include <QVBoxLayout>
25 #include <QCheckBox>
26 #include <QDialogButtonBox>
27 #include <QPushButton>
28 #include <QPlainTextEdit>
29 #include <QLocale>
30 
31 namespace Rosegarden
32 {
33 
CommentsPopupDialog(RosegardenDocument * doc,QWidget * parent)34 CommentsPopupDialog::CommentsPopupDialog(RosegardenDocument *doc,
35                                          QWidget *parent):
36     QDialog(parent),
37     m_doc(doc)
38 {
39     setModal(false);
40     setAttribute(Qt::WA_DeleteOnClose);
41 
42     MetadataHelper mh(doc);
43 
44     // Only create the dialog if asked for
45     if (!mh.popupWanted()) return;
46 
47     QString fileName = doc->getAbsFilePath();
48     setWindowTitle(tr("Notes about %1").arg(fileName));
49 
50     QVBoxLayout *mainLayout = new QVBoxLayout;
51     setLayout(mainLayout);
52 
53     QPlainTextEdit *textEdit = new QPlainTextEdit(this);
54     mainLayout->addWidget(textEdit);
55     QPalette palette = textEdit->palette();
56     palette.setColor(QPalette::Base, QColor(0xD0, 0xD0, 0xD0));
57     textEdit->setPalette(palette);
58     textEdit->setMinimumSize(600, 500);  // About the size of the edit widget
59     textEdit->setReadOnly(true);
60     textEdit->setBackgroundVisible(true);
61     textEdit->setToolTip(tr("<qt>This is a short description of the current "
62                             "composition</qt>"));
63 
64     // Read the comments from the document metadata
65     MetadataHelper::CommentsMap comments = mh.getComments();
66 
67     // Get local language
68     QLocale locale;
69     QString lang = locale.name().split('_').at(0);
70 
71     // Display translated text if any
72     QString page = "";
73     if (comments.find(lang) != comments.end()) page = lang;
74     textEdit->setPlainText(comments[page].text);
75 
76     QWidget *hb = new QWidget;
77     mainLayout->addWidget(hb);
78 
79     QHBoxLayout *bottomLayout = new QHBoxLayout;
80     hb->setLayout(bottomLayout);
81 
82     QCheckBox *checkBox = new QCheckBox;
83     bottomLayout->addWidget(checkBox);
84     checkBox->setText(tr("Show next time"));
85     checkBox->setToolTip(tr("<qt>If checked, these notes will pop up the next"
86                             "time the document is loaded</qt>"));
87     checkBox->setChecked(true);
88     connect(checkBox, &QCheckBox::stateChanged,
89             this, &CommentsPopupDialog::slotCheckChanged);
90 
91     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
92     bottomLayout->addWidget(buttonBox);
93 
94     QPushButton *closeButton = buttonBox->button(QDialogButtonBox::Close);
95     closeButton->setDefault(false);
96     closeButton->setAutoDefault(false);
97 
98     connect(parent, SIGNAL(documentAboutToChange()), this, SLOT(close()));
99     connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
100 
101     show();
102 }
103 
104 void
slotCheckChanged(int state)105 CommentsPopupDialog::slotCheckChanged(int state)
106 {
107     MetadataHelper mh(m_doc);
108     mh.setPopupWanted(state != Qt::Unchecked);
109 }
110 
111 }
112 
113