File indexing completed on 2024-05-05 11:56:01

0001 /*
0002     This program is free software; you can redistribute it and/or
0003     modify it under the terms of the GNU General Public License
0004     as published by the Free Software Foundation; either version 2
0005     of the License, or (at your option) any later version.
0006 
0007     This program is distributed in the hope that it will be useful,
0008     but WITHOUT ANY WARRANTY; without even the implied warranty of
0009     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0010     GNU General Public License for more details.
0011 
0012     You should have received a copy of the GNU General Public License
0013     along with this program; if not, write to the Free Software
0014     Foundation, Inc., 51 Franklin Street, Fifth Floor,
0015     Boston, MA  02110-1301, USA.
0016 
0017     ---
0018     Copyright (C) 2020-2022 Alexander Semke <alexander.semke@web.de>
0019  */
0020 
0021 #include "backendsettingswidget.h"
0022 #include "qthelpconfig.h"
0023 
0024 #include <QFile>
0025 #include <QHBoxLayout>
0026 #include <QTabWidget>
0027 
0028 #include <KUrlRequester>
0029 
0030 BackendSettingsWidget::BackendSettingsWidget(QWidget* parent, const QString& id) : QWidget(parent), m_id(id)
0031 {
0032 
0033 }
0034 
0035 void BackendSettingsWidget::tabChanged(int index) {
0036     if (!m_tabWidget || !m_tabDocumentation)
0037         return;
0038 
0039     //if the documentation tab was selected and there is not doc widget available yet, create it
0040     if (m_tabWidget->widget(index) == m_tabDocumentation)
0041     {
0042         if (!m_docWidget)
0043         {
0044             m_docWidget = new QtHelpConfig(m_id);
0045             auto hboxLayout = new QHBoxLayout(m_tabDocumentation);
0046             hboxLayout->addWidget(m_docWidget);
0047         }
0048     }
0049 }
0050 
0051 void BackendSettingsWidget::fileNameChanged(const QString& fileName) {
0052     if (!m_urlRequester)
0053         return;
0054 
0055     bool invalid = (!fileName.isEmpty() && !QFile::exists(fileName));
0056     if (invalid) {
0057         QPalette p;                                                                                                                                            \
0058         if (qGray(p.color(QPalette::Base).rgb()) > 160) /* light */                                                                                            \
0059             m_urlRequester->setStyleSheet(QLatin1String("background: rgb(255, 200, 200);"));                                                                             \
0060         else /* dark */                                                                                                                                        \
0061             m_urlRequester->setStyleSheet(QLatin1String("background: rgb(128, 0, 0);"));
0062     }
0063     else
0064         m_urlRequester->setStyleSheet(QString());
0065 }