Warning, file /sdk/cervisia/patchoptiondialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  Copyright (C) 2004 Christian Loose <christian.loose@kdemail.net>
0003  *
0004  * This program is free software; you can redistribute it and/or modify
0005  * it under the terms of the GNU General Public License as published by
0006  * the Free Software Foundation; either version 2 of the License, or
0007  * (at your option) any later version.
0008  *
0009  * This program is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  * GNU General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU General Public License
0015  * along with this program; if not, write to the Free Software
0016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0017  */
0018 
0019 #include "patchoptiondialog.h"
0020 
0021 using Cervisia::PatchOptionDialog;
0022 
0023 #include <KHelpClient>
0024 #include <KLocalizedString>
0025 
0026 #include <QButtonGroup>
0027 #include <QDialogButtonBox>
0028 #include <QHBoxLayout>
0029 #include <QPushButton>
0030 #include <QSpinBox>
0031 #include <QVBoxLayout>
0032 #include <qcheckbox.h>
0033 #include <qgroupbox.h>
0034 #include <qlabel.h>
0035 #include <qlayout.h>
0036 #include <qradiobutton.h>
0037 
0038 PatchOptionDialog::PatchOptionDialog(QWidget *parent)
0039     : QDialog(parent)
0040 {
0041     setModal(false);
0042 
0043     auto mainLayout = new QVBoxLayout;
0044     setLayout(mainLayout);
0045 
0046     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
0047     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0048     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0049     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
0050     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
0051     connect(buttonBox, &QDialogButtonBox::helpRequested, this, &PatchOptionDialog::slotHelp);
0052 
0053     { // format
0054         m_formatBtnGroup = new QButtonGroup(this);
0055 
0056         connect(m_formatBtnGroup, SIGNAL(buttonClicked(int)), this, SLOT(formatChanged(int)));
0057 
0058         m_formatBtnGroup->addButton(new QRadioButton(i18n("Context")), 0);
0059         m_formatBtnGroup->addButton(new QRadioButton(i18n("Normal")), 1);
0060         auto unifiedFormatBtn = new QRadioButton(i18n("Unified"));
0061         unifiedFormatBtn->setChecked(true);
0062         m_formatBtnGroup->addButton(unifiedFormatBtn, 2);
0063 
0064         auto box = new QGroupBox(i18n("Output Format"));
0065         mainLayout->addWidget(box);
0066         auto v = new QVBoxLayout(box);
0067         v->addWidget(m_formatBtnGroup->button(0));
0068         v->addWidget(m_formatBtnGroup->button(1));
0069         v->addWidget(m_formatBtnGroup->button(2));
0070 
0071         mainLayout->addWidget(box);
0072     }
0073 
0074     auto contextLinesLbl = new QLabel(i18n("&Number of context lines:"));
0075     m_contextLines = new QSpinBox;
0076     m_contextLines->setValue(3);
0077     mainLayout->addWidget(m_contextLines);
0078     m_contextLines->setRange(2, 65535);
0079     contextLinesLbl->setBuddy(m_contextLines);
0080 
0081     QBoxLayout *contextLinesLayout = new QHBoxLayout();
0082     mainLayout->addLayout(contextLinesLayout);
0083     contextLinesLayout->addWidget(contextLinesLbl);
0084     contextLinesLayout->addWidget(m_contextLines);
0085 
0086     { // ignore options
0087         auto group = new QButtonGroup(this);
0088         group->setExclusive(false);
0089 
0090         m_blankLineChk = new QCheckBox(i18n("Ignore added or removed empty lines"));
0091         m_spaceChangeChk = new QCheckBox(i18n("Ignore changes in the amount of whitespace"));
0092         m_allSpaceChk = new QCheckBox(i18n("Ignore all whitespace"));
0093         m_caseChangesChk = new QCheckBox(i18n("Ignore changes in case"));
0094 
0095         group->addButton(m_blankLineChk);
0096         group->addButton(m_spaceChangeChk);
0097         group->addButton(m_allSpaceChk);
0098         group->addButton(m_caseChangesChk);
0099 
0100         auto box = new QGroupBox(i18n("Ignore Options"));
0101         mainLayout->addWidget(box);
0102         auto v = new QVBoxLayout(box);
0103         v->addWidget(m_blankLineChk);
0104         v->addWidget(m_spaceChangeChk);
0105         v->addWidget(m_allSpaceChk);
0106         v->addWidget(m_caseChangesChk);
0107 
0108         mainLayout->addWidget(box);
0109     }
0110 
0111     mainLayout->addWidget(buttonBox);
0112 }
0113 
0114 PatchOptionDialog::~PatchOptionDialog() = default;
0115 
0116 void PatchOptionDialog::slotHelp()
0117 {
0118     KHelpClient::invokeHelp(QLatin1String("creatingpatches"));
0119 }
0120 
0121 QString PatchOptionDialog::diffOptions() const
0122 {
0123     QString options;
0124 
0125     if (m_blankLineChk->isChecked())
0126         options += " -B ";
0127 
0128     if (m_spaceChangeChk->isChecked())
0129         options += " -b ";
0130 
0131     if (m_allSpaceChk->isChecked())
0132         options += " -w ";
0133 
0134     if (m_caseChangesChk->isChecked())
0135         options += " -i ";
0136 
0137     return options;
0138 }
0139 
0140 QString PatchOptionDialog::formatOption() const
0141 {
0142     switch (m_formatBtnGroup->checkedId()) {
0143     case 0:
0144         return "-C " + QString::number(m_contextLines->value());
0145     case 1:
0146         return "";
0147     case 2:
0148         return "-U " + QString::number(m_contextLines->value());
0149     }
0150 
0151     return "";
0152 }
0153 
0154 void PatchOptionDialog::formatChanged(int buttonId)
0155 {
0156     bool enabled = (buttonId == 0 || buttonId == 2);
0157     m_contextLines->setEnabled(enabled);
0158 }