File indexing completed on 2024-05-05 05:21:41
0001 /* 0002 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 0006 */ 0007 0008 #include "inserttablewidget.h" 0009 #include "kpimtextedit_debug.h" 0010 #include <KLocalizedString> 0011 #include <QComboBox> 0012 0013 #include <QGridLayout> 0014 #include <QLabel> 0015 #include <QSpinBox> 0016 0017 using namespace KPIMTextEdit; 0018 0019 class InsertTableWidget::InsertTableWidgetPrivate 0020 { 0021 public: 0022 explicit InsertTableWidgetPrivate(InsertTableWidget *qq) 0023 : q(qq) 0024 { 0025 mRows = new QSpinBox; 0026 mRows->setMinimum(1); 0027 mRows->setValue(2); 0028 0029 mColumns = new QSpinBox; 0030 mColumns->setMinimum(1); 0031 mColumns->setValue(2); 0032 0033 mBorder = new QSpinBox; 0034 mBorder->setMinimum(0); 0035 mBorder->setValue(1); 0036 mBorder->setSuffix(i18n(" px")); 0037 0038 auto gridLayout = new QGridLayout; 0039 gridLayout->setContentsMargins({}); 0040 gridLayout->addWidget(new QLabel(i18n("Rows:")), 0, 0); 0041 gridLayout->addWidget(mRows, 0, 1); 0042 0043 gridLayout->addWidget(new QLabel(i18n("Columns:")), 1, 0); 0044 gridLayout->addWidget(mColumns, 1, 1); 0045 0046 gridLayout->addWidget(new QLabel(i18n("Border:")), 2, 0); 0047 gridLayout->addWidget(mBorder, 2, 1); 0048 0049 mTypeOfLength = new QComboBox; 0050 q->connect(mTypeOfLength, &QComboBox::activated, q, &InsertTableWidget::slotTypeOfLengthChanged); 0051 // xgettext: no-c-format 0052 mTypeOfLength->addItem(i18n("% of windows"), QTextLength::PercentageLength); 0053 mTypeOfLength->addItem(i18n("pixels"), QTextLength::FixedLength); 0054 mLength = new QSpinBox; 0055 mLength->setMinimum(1); 0056 mLength->setMaximum(100); 0057 mLength->setValue(100); 0058 0059 gridLayout->addWidget(new QLabel(i18n("Width:")), 3, 0); 0060 gridLayout->addWidget(mLength, 3, 1); 0061 gridLayout->addWidget(mTypeOfLength, 3, 2); 0062 q->setLayout(gridLayout); 0063 } 0064 0065 QSpinBox *mColumns = nullptr; 0066 QSpinBox *mRows = nullptr; 0067 QSpinBox *mBorder = nullptr; 0068 QSpinBox *mLength = nullptr; 0069 QComboBox *mTypeOfLength = nullptr; 0070 0071 InsertTableWidget *const q; 0072 }; 0073 0074 InsertTableWidget::InsertTableWidget(QWidget *parent) 0075 : QWidget(parent) 0076 , d(new InsertTableWidgetPrivate(this)) 0077 { 0078 } 0079 0080 InsertTableWidget::~InsertTableWidget() = default; 0081 0082 void InsertTableWidget::slotTypeOfLengthChanged(int index) 0083 { 0084 switch (index) { 0085 case 0: 0086 d->mLength->setMaximum(100); 0087 d->mLength->setValue(qMin(d->mLength->value(), 100)); 0088 break; 0089 case 1: 0090 d->mLength->setMaximum(9999); 0091 break; 0092 default: 0093 qCDebug(KPIMTEXTEDIT_LOG) << " index not defined " << index; 0094 break; 0095 } 0096 } 0097 0098 QTextLength::Type InsertTableWidget::typeOfLength() const 0099 { 0100 return static_cast<QTextLength::Type>(d->mTypeOfLength->itemData(d->mTypeOfLength->currentIndex()).toInt()); 0101 } 0102 0103 void InsertTableWidget::setTypeOfLength(QTextLength::Type type) 0104 { 0105 const int index = d->mTypeOfLength->findData(QVariant(type)); 0106 d->mTypeOfLength->setCurrentIndex(index); 0107 slotTypeOfLengthChanged(index); 0108 } 0109 0110 int InsertTableWidget::length() const 0111 { 0112 return d->mLength->value(); 0113 } 0114 0115 void InsertTableWidget::setLength(int val) 0116 { 0117 d->mLength->setValue(val); 0118 } 0119 0120 void InsertTableWidget::setColumns(int col) 0121 { 0122 d->mColumns->setValue(col); 0123 } 0124 0125 void InsertTableWidget::setRows(int rows) 0126 { 0127 d->mRows->setValue(rows); 0128 } 0129 0130 void InsertTableWidget::setBorder(int border) 0131 { 0132 d->mBorder->setValue(border); 0133 } 0134 0135 int InsertTableWidget::columns() const 0136 { 0137 return d->mColumns->value(); 0138 } 0139 0140 int InsertTableWidget::rows() const 0141 { 0142 return d->mRows->value(); 0143 } 0144 0145 int InsertTableWidget::border() const 0146 { 0147 return d->mBorder->value(); 0148 } 0149 0150 #include "moc_inserttablewidget.cpp"