File indexing completed on 2024-05-12 09:48:33
0001 /* 0002 SPDX-FileCopyrightText: 2001-2009 Otto Bruggeman <bruggie@gmail.com> 0003 SPDX-FileCopyrightText: 2001-2003 John Firebaugh <jfirebaugh@kde.org> 0004 SPDX-FileCopyrightText: 2007 Kevin Kofler <kevin.kofler@chello.at> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "kompareprefdlg.h" 0010 0011 #include <QTabWidget> 0012 #include <QPushButton> 0013 0014 #include <KLocalizedString> 0015 #include <KHelpClient> 0016 #include <KStandardGuiItem> 0017 0018 #include "diffpage.h" 0019 #include "viewpage.h" 0020 0021 // implementation 0022 0023 KomparePrefDlg::KomparePrefDlg(ViewSettings* viewSets, DiffSettings* diffSets) : KPageDialog(nullptr) 0024 { 0025 setFaceType(KPageDialog::List); 0026 setWindowTitle(i18nc("@title:window", "Preferences")); 0027 setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Reset | QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel); 0028 setModal(true); 0029 0030 KGuiItem::assign(button(QDialogButtonBox::Reset), KStandardGuiItem::defaults()); 0031 0032 // ok i need some stuff in that pref dlg... 0033 //setIconListAllVisible(true); 0034 0035 m_viewPage = new ViewPage(); 0036 KPageWidgetItem* item = addPage(m_viewPage, i18nc("@title:tab", "View")); 0037 item->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-theme"))); 0038 item->setHeader(i18nc("@title", "View Settings")); 0039 m_viewPage->setSettings(viewSets); 0040 0041 m_diffPage = new DiffPage(); 0042 item = addPage(m_diffPage, i18nc("@title:tab", "Diff")); 0043 item->setIcon(QIcon::fromTheme(QStringLiteral("text-x-patch"))); 0044 item->setHeader(i18nc("@title", "Diff Settings")); 0045 m_diffPage->setSettings(diffSets); 0046 0047 // frame = addVBoxPage(i18n(""), i18n(""), UserIcon("")); 0048 0049 connect(button(QDialogButtonBox::Reset), &QPushButton::clicked, this, &KomparePrefDlg::slotDefault); 0050 connect(button(QDialogButtonBox::Help), &QPushButton::clicked, this, &KomparePrefDlg::slotHelp); 0051 connect(button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &KomparePrefDlg::slotApply); 0052 connect(button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &KomparePrefDlg::slotOk); 0053 connect(button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &KomparePrefDlg::slotCancel); 0054 0055 adjustSize(); 0056 } 0057 0058 KomparePrefDlg::~KomparePrefDlg() 0059 { 0060 0061 } 0062 0063 /** No descriptions */ 0064 void KomparePrefDlg::slotDefault() 0065 { 0066 // restore all defaults in the options... 0067 m_viewPage->setDefaults(); 0068 m_diffPage->setDefaults(); 0069 } 0070 0071 /** No descriptions */ 0072 void KomparePrefDlg::slotHelp() 0073 { 0074 // figure out the current active page 0075 QWidget* currentpage = currentPage()->widget(); 0076 if (dynamic_cast<ViewPage*>(currentpage)) 0077 { 0078 // figure out the active tab 0079 int currentTab = static_cast<ViewPage*>(currentpage)->m_tabWidget->currentIndex(); 0080 switch (currentTab) 0081 { 0082 case 0: 0083 KHelpClient::invokeHelp(QStringLiteral("appearance")); 0084 break; 0085 case 1: 0086 KHelpClient::invokeHelp(QStringLiteral("fonts")); 0087 break; 0088 default: 0089 KHelpClient::invokeHelp(QStringLiteral("view-settings")); 0090 } 0091 } 0092 else if (dynamic_cast<DiffPage*>(currentpage)) 0093 { 0094 // figure out the active tab 0095 int currentTab = static_cast<DiffPage*>(currentpage)->m_tabWidget->currentIndex(); 0096 switch (currentTab) 0097 { 0098 case 0: 0099 KHelpClient::invokeHelp(QStringLiteral("diff")); 0100 break; 0101 case 1: 0102 KHelpClient::invokeHelp(QStringLiteral("diff-format")); 0103 break; 0104 case 2: 0105 KHelpClient::invokeHelp(QStringLiteral("options")); 0106 break; 0107 case 3: 0108 KHelpClient::invokeHelp(QStringLiteral("exclude")); 0109 break; 0110 default: 0111 KHelpClient::invokeHelp(QStringLiteral("diff-settings")); 0112 } 0113 } 0114 else // Fallback since we had not added the code for the page/tab or forgotten about it 0115 KHelpClient::invokeHelp(QStringLiteral("configure-preferences")); 0116 } 0117 0118 /** No descriptions */ 0119 void KomparePrefDlg::slotApply() 0120 { 0121 // well apply the settings that are currently selected 0122 m_viewPage->apply(); 0123 m_diffPage->apply(); 0124 0125 Q_EMIT configChanged(); 0126 } 0127 0128 /** No descriptions */ 0129 void KomparePrefDlg::slotOk() 0130 { 0131 // Apply the settings that are currently selected 0132 m_viewPage->apply(); 0133 m_diffPage->apply(); 0134 0135 //accept(); 0136 } 0137 0138 /** No descriptions */ 0139 void KomparePrefDlg::slotCancel() 0140 { 0141 // discard the current settings and use the present ones 0142 m_viewPage->restore(); 0143 m_diffPage->restore(); 0144 0145 //reject(); 0146 } 0147 0148 #include "moc_kompareprefdlg.cpp"