File indexing completed on 2024-05-05 17:15:09
0001 /*************************************************************************** 0002 date : Dec 06 2005 0003 version : 0.12 0004 copyright : (C) 2005 by Holger Danielsson 0005 email : holger.danielsson@t-online.de 0006 ***************************************************************************/ 0007 0008 /*************************************************************************** 0009 * * 0010 * This program is free software; you can redistribute it and/or modify * 0011 * it under the terms of the GNU General Public License as published by * 0012 * the Free Software Foundation; either version 2 of the License, or * 0013 * (at your option) any later version. * 0014 * * 0015 ***************************************************************************/ 0016 0017 #include "dialogs/floatdialog.h" 0018 #include "kiledebug.h" 0019 #include "editorextension.h" 0020 #include <QRegExp> 0021 #include <QDialogButtonBox> 0022 #include <KLocalizedString> 0023 #include <KConfigGroup> 0024 0025 0026 namespace KileDialog 0027 { 0028 0029 FloatEnvironmentDialog::FloatEnvironmentDialog(KConfig *config, KileInfo *ki, 0030 QWidget *parent) 0031 : Wizard(config, parent), m_ki(ki) 0032 { 0033 QWidget *page = new QWidget(this); 0034 QVBoxLayout *mainLayout = new QVBoxLayout; 0035 setLayout(mainLayout); 0036 mainLayout->addWidget(page); 0037 0038 m_FloatDialog.setupUi(page); 0039 0040 m_prefix = "fig:"; 0041 m_FloatDialog.m_edLabel->setText(m_prefix); 0042 0043 slotEnvironmentClicked(); 0044 setFocusProxy(m_FloatDialog.m_edCaption); 0045 0046 mainLayout->addWidget(buttonBox()); 0047 connect(buttonBox(), &QDialogButtonBox::accepted, this, &QDialog::accept); 0048 connect(buttonBox(), &QDialogButtonBox::rejected, this, &QDialog::reject); 0049 connect(m_FloatDialog.m_rbFigure, &QRadioButton::clicked, this, &FloatEnvironmentDialog::slotEnvironmentClicked); 0050 connect(m_FloatDialog.m_rbTable, &QRadioButton::clicked, this, &FloatEnvironmentDialog::slotEnvironmentClicked); 0051 connect(this, &QDialog::accepted, this, &FloatEnvironmentDialog::slotAccepted); 0052 } 0053 0054 ////////////////////////////// determine the whole tag ////////////////////////////// 0055 0056 void FloatEnvironmentDialog::slotAccepted() 0057 { 0058 QString envname = (m_FloatDialog.m_rbFigure->isChecked()) ? "figure" : "table"; 0059 QString indent = m_ki->editorExtension()->autoIndentEnvironment(); 0060 0061 QString position; 0062 if (m_FloatDialog.m_cbHere->isChecked()) 0063 position += 'h'; 0064 if (m_FloatDialog.m_cbTop->isChecked()) 0065 position += 't'; 0066 if (m_FloatDialog.m_cbBottom->isChecked()) 0067 position += 'b'; 0068 if (m_FloatDialog.m_cbPage->isChecked()) 0069 position += 'p'; 0070 0071 m_td.tagBegin = "\\begin{" + envname + '}'; 0072 if (!position.isEmpty()) { 0073 m_td.tagBegin += '[' + position + ']'; 0074 } 0075 m_td.tagBegin += '\n'; 0076 0077 int row = 1; 0078 if (m_FloatDialog.m_cbCenter->isChecked()) { 0079 m_td.tagBegin += indent + "\\centering\n"; 0080 row = 2; 0081 } 0082 0083 m_td.tagEnd = indent + '\n'; 0084 0085 QString caption = m_FloatDialog.m_edCaption->text(); 0086 if (! caption.isEmpty()) 0087 m_td.tagEnd += indent + "\\caption{" + caption + "}\n"; 0088 0089 QString label = m_FloatDialog.m_edLabel->text(); 0090 if (!label.isEmpty() && label != m_prefix) 0091 m_td.tagEnd += indent + "\\label{" + label + "}\n"; 0092 0093 m_td.tagEnd += "\\end{" + envname + "}\n"; 0094 0095 m_td.dy = row; 0096 m_td.dx = indent.length(); 0097 } 0098 0099 void FloatEnvironmentDialog::slotEnvironmentClicked() 0100 { 0101 KILE_DEBUG_MAIN << "entering"; 0102 QString caption, oldprefix; 0103 0104 if (m_FloatDialog.m_rbFigure->isChecked()) { 0105 caption = i18n("Figure Environment"); 0106 oldprefix = "^tab:"; 0107 m_prefix = "fig:"; 0108 } else { 0109 caption = i18n("Table Environment"); 0110 oldprefix = "^fig:"; 0111 m_prefix = "tab:"; 0112 } 0113 0114 setWindowTitle(caption); 0115 QString s = m_FloatDialog.m_edLabel->text(); 0116 s.replace(QRegExp(oldprefix), m_prefix); 0117 m_FloatDialog.m_edLabel->setText(s); 0118 } 0119 0120 }