1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2008-09-09
7  * Description : a presentation tool.
8  *
9  * Copyright (C) 2008      by Valerio Fuoglio <valerio dot fuoglio at gmail dot com>
10  * Copyright (C) 2012-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #include "presentation_captionpage.h"
25 
26 // Qt includes
27 
28 #include <QFont>
29 #include <QFontDialog>
30 #include <QPalette>
31 
32 // Local includes
33 
34 #include "presentationcontainer.h"
35 
36 namespace DigikamGenericPresentationPlugin
37 {
38 
PresentationCaptionPage(QWidget * const parent,PresentationContainer * const sharedData)39 PresentationCaptionPage::PresentationCaptionPage(QWidget* const parent,
40                                                  PresentationContainer* const sharedData)
41     : QWidget(parent)
42 {
43     setupUi(this);
44 
45     m_sharedData = sharedData;
46     m_fontSampleLbl->setText(i18n("This is a comment sample..."));
47     m_fontSampleLbl->setAutoFillBackground(true);
48 }
49 
~PresentationCaptionPage()50 PresentationCaptionPage::~PresentationCaptionPage()
51 {
52 }
53 
readSettings()54 void PresentationCaptionPage::readSettings()
55 {
56     connect(m_commentsFontColor, SIGNAL(signalColorSelected(QColor)),
57             this, SLOT(slotCommentsFontColorChanged()));
58 
59     connect(m_commentsBgColor, SIGNAL(signalColorSelected(QColor)),
60             this, SLOT(slotCommentsBgColorChanged()));
61 
62     connect(m_fontselectBtn, SIGNAL(clicked()),
63             this, SLOT(slotOpenFontDialog()));
64 
65     m_commentsLinesLengthSpinBox->setValue(m_sharedData->commentsLinesLength);
66     m_commentsFontColor->setColor(QColor(m_sharedData->commentsFontColor));
67     m_commentsBgColor->setColor(QColor(m_sharedData->commentsBgColor));
68     m_commentsDrawOutlineCheckBox->setChecked(m_sharedData->commentsDrawOutline);
69     m_fontSampleLbl->setFont(*(m_sharedData->captionFont));
70     m_commentsBgTransparency->setValue(m_sharedData->bgOpacity);
71 
72     slotCommentsBgColorChanged();
73     slotCommentsFontColorChanged();
74 }
75 
saveSettings()76 void PresentationCaptionPage::saveSettings()
77 {
78     delete m_sharedData->captionFont;
79     m_sharedData->captionFont         = new QFont(m_fontSampleLbl->font());
80     QColor fontColor                  = QColor(m_commentsFontColor->color());
81     m_sharedData->commentsFontColor   = fontColor.rgb();
82     QColor bgColor                    = QColor(m_commentsBgColor->color());
83     m_sharedData->commentsBgColor     = bgColor.rgb();
84     m_sharedData->commentsDrawOutline = m_commentsDrawOutlineCheckBox->isChecked();
85     m_sharedData->commentsLinesLength = m_commentsLinesLengthSpinBox->value();
86     m_sharedData->bgOpacity           = m_commentsBgTransparency->value();
87 }
88 
slotCommentsBgColorChanged()89 void PresentationCaptionPage::slotCommentsBgColorChanged()
90 {
91     QPalette palette = m_fontSampleLbl->palette();
92     palette.setColor(m_fontSampleLbl->backgroundRole(), m_commentsBgColor->color());
93     m_fontSampleLbl->setPalette(palette);
94 }
95 
slotCommentsFontColorChanged()96 void PresentationCaptionPage::slotCommentsFontColorChanged()
97 {
98     QPalette palette = m_fontSampleLbl->palette();
99     palette.setColor(m_fontSampleLbl->foregroundRole(), m_commentsFontColor->color());
100     m_fontSampleLbl->setPalette(palette);
101 }
102 
slotOpenFontDialog()103 void PresentationCaptionPage::slotOpenFontDialog()
104 {
105     bool ok = false;
106     QFont f = QFontDialog::getFont(&ok, *(m_sharedData->captionFont), this);
107 
108     if (ok)
109     {
110         m_fontSampleLbl->setFont(f);
111     }
112 }
113 
114 } // namespace DigikamGenericPresentationPlugin
115