File indexing completed on 2024-05-19 04:59:22
0001 /* ============================================================ 0002 * VerticalTabs plugin for Falkon 0003 * Copyright (C) 2018 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "verticaltabssettings.h" 0019 #include "ui_verticaltabssettings.h" 0020 #include "verticaltabsplugin.h" 0021 0022 #include <QDir> 0023 #include <QFileDialog> 0024 0025 VerticalTabsSettings::VerticalTabsSettings(VerticalTabsPlugin *plugin, QWidget *parent) 0026 : QDialog(parent) 0027 , ui(new Ui::VerticalTabsSettings) 0028 , m_plugin(plugin) 0029 { 0030 setAttribute(Qt::WA_DeleteOnClose); 0031 ui->setupUi(this); 0032 0033 ui->tabListView->setChecked(m_plugin->viewType() == VerticalTabsPlugin::TabListView); 0034 ui->tabTreeView->setChecked(m_plugin->viewType() == VerticalTabsPlugin::TabTreeView); 0035 ui->appendChild->setChecked(m_plugin->addChildBehavior() == VerticalTabsPlugin::AppendChild); 0036 ui->prependChild->setChecked(m_plugin->addChildBehavior() == VerticalTabsPlugin::PrependChild); 0037 ui->replaceTabBar->setChecked(m_plugin->replaceTabBar()); 0038 0039 loadThemes(); 0040 0041 connect(ui->theme, SIGNAL(activated(int)), this, SLOT(themeValueChanged(int))); 0042 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0043 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [this]() { 0044 m_plugin->setViewType(ui->tabListView->isChecked() ? VerticalTabsPlugin::TabListView : VerticalTabsPlugin::TabTreeView); 0045 m_plugin->setAddChildBehavior(ui->appendChild->isChecked() ? VerticalTabsPlugin::AppendChild : VerticalTabsPlugin::PrependChild); 0046 m_plugin->setReplaceTabBar(ui->replaceTabBar->isChecked()); 0047 m_plugin->setTheme(ui->theme->currentData().toString()); 0048 accept(); 0049 }); 0050 } 0051 0052 VerticalTabsSettings::~VerticalTabsSettings() 0053 { 0054 delete ui; 0055 } 0056 0057 void VerticalTabsSettings::themeValueChanged(int index) 0058 { 0059 const int customIndex = ui->theme->count() - 1; 0060 if (index == customIndex) { 0061 const QString path = QFileDialog::getOpenFileName(this, tr("Theme file"), QDir::homePath(), {QSL("*.css")}); 0062 if (path.isEmpty()) { 0063 loadThemes(); 0064 } else { 0065 ui->theme->setToolTip(path); 0066 ui->theme->setItemData(customIndex, path); 0067 } 0068 } else { 0069 ui->theme->setToolTip(QString()); 0070 } 0071 } 0072 0073 void VerticalTabsSettings::loadThemes() 0074 { 0075 ui->theme->clear(); 0076 bool found = false; 0077 const auto files = QDir(QSL(":verticaltabs/data/themes")).entryInfoList({QSL("*.css")}); 0078 for (const QFileInfo &file : files) { 0079 ui->theme->addItem(file.baseName(), file.absoluteFilePath()); 0080 if (file.absoluteFilePath() == m_plugin->theme()) { 0081 ui->theme->setCurrentIndex(ui->theme->count() - 1); 0082 found = true; 0083 } 0084 } 0085 ui->theme->setToolTip(m_plugin->theme()); 0086 ui->theme->addItem(tr("Custom..."), found ? QString() : m_plugin->theme()); 0087 if (!found) { 0088 ui->theme->setCurrentIndex(ui->theme->count() - 1); 0089 } 0090 }