Falkon Develop
Cross-platform Qt-based web browser
verticaltabssettings.cpp
Go to the documentation of this file.
1/* ============================================================
2* VerticalTabs plugin for Falkon
3* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
19#include "ui_verticaltabssettings.h"
20#include "verticaltabsplugin.h"
21
22#include <QDir>
23#include <QFileDialog>
24
26 : QDialog(parent)
27 , ui(new Ui::VerticalTabsSettings)
28 , m_plugin(plugin)
29{
30 setAttribute(Qt::WA_DeleteOnClose);
31 ui->setupUi(this);
32
33 ui->tabListView->setChecked(m_plugin->viewType() == VerticalTabsPlugin::TabListView);
34 ui->tabTreeView->setChecked(m_plugin->viewType() == VerticalTabsPlugin::TabTreeView);
35 ui->appendChild->setChecked(m_plugin->addChildBehavior() == VerticalTabsPlugin::AppendChild);
36 ui->prependChild->setChecked(m_plugin->addChildBehavior() == VerticalTabsPlugin::PrependChild);
37 ui->replaceTabBar->setChecked(m_plugin->replaceTabBar());
38
39 loadThemes();
40
41 connect(ui->theme, SIGNAL(activated(int)), this, SLOT(themeValueChanged(int)));
42 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
43 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [this]() {
44 m_plugin->setViewType(ui->tabListView->isChecked() ? VerticalTabsPlugin::TabListView : VerticalTabsPlugin::TabTreeView);
45 m_plugin->setAddChildBehavior(ui->appendChild->isChecked() ? VerticalTabsPlugin::AppendChild : VerticalTabsPlugin::PrependChild);
46 m_plugin->setReplaceTabBar(ui->replaceTabBar->isChecked());
47 m_plugin->setTheme(ui->theme->currentData().toString());
48 accept();
49 });
50}
51
53{
54 delete ui;
55}
56
57void VerticalTabsSettings::themeValueChanged(int index)
58{
59 const int customIndex = ui->theme->count() - 1;
60 if (index == customIndex) {
61 const QString path = QFileDialog::getOpenFileName(this, tr("Theme file"), QDir::homePath(), {QSL("*.css")});
62 if (path.isEmpty()) {
63 loadThemes();
64 } else {
65 ui->theme->setToolTip(path);
66 ui->theme->setItemData(customIndex, path);
67 }
68 } else {
69 ui->theme->setToolTip(QString());
70 }
71}
72
73void VerticalTabsSettings::loadThemes()
74{
75 ui->theme->clear();
76 bool found = false;
77 const auto files = QDir(QSL(":verticaltabs/data/themes")).entryInfoList({QSL("*.css")});
78 for (const QFileInfo &file : files) {
79 ui->theme->addItem(file.baseName(), file.absoluteFilePath());
80 if (file.absoluteFilePath() == m_plugin->theme()) {
81 ui->theme->setCurrentIndex(ui->theme->count() - 1);
82 found = true;
83 }
84 }
85 ui->theme->setToolTip(m_plugin->theme());
86 ui->theme->addItem(tr("Custom..."), found ? QString() : m_plugin->theme());
87 if (!found) {
88 ui->theme->setCurrentIndex(ui->theme->count() - 1);
89 }
90}
AddChildBehavior addChildBehavior() const
ViewType viewType() const
VerticalTabsSettings(VerticalTabsPlugin *plugin, QWidget *parent=nullptr)
#define QSL(x)
Definition: qzcommon.h:40