KPimTextEdit

inserttablewidget.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5
6*/
7
8#include "inserttablewidget.h"
9#include "kpimtextedit_debug.h"
10#include <KLocalizedString>
11#include <QComboBox>
12
13#include <QGridLayout>
14#include <QLabel>
15#include <QSpinBox>
16
17using namespace KPIMTextEdit;
18
19class InsertTableWidget::InsertTableWidgetPrivate
20{
21public:
22 explicit InsertTableWidgetPrivate(InsertTableWidget *qq)
23 : q(qq)
24 {
25 mRows = new QSpinBox;
26 mRows->setMinimum(1);
27 mRows->setValue(2);
28
29 mColumns = new QSpinBox;
30 mColumns->setMinimum(1);
31 mColumns->setValue(2);
32
33 mBorder = new QSpinBox;
34 mBorder->setMinimum(0);
35 mBorder->setValue(1);
36 mBorder->setSuffix(i18n(" px"));
37
38 auto gridLayout = new QGridLayout;
39 gridLayout->setContentsMargins({});
40 gridLayout->addWidget(new QLabel(i18nc("@label:textbox", "Rows:")), 0, 0);
41 gridLayout->addWidget(mRows, 0, 1);
42
43 gridLayout->addWidget(new QLabel(i18nc("@label:textbox", "Columns:")), 1, 0);
44 gridLayout->addWidget(mColumns, 1, 1);
45
46 gridLayout->addWidget(new QLabel(i18nc("@label:textbox", "Border:")), 2, 0);
47 gridLayout->addWidget(mBorder, 2, 1);
48
49 mTypeOfLength = new QComboBox;
50 q->connect(mTypeOfLength, &QComboBox::activated, q, &InsertTableWidget::slotTypeOfLengthChanged);
51 // xgettext: no-c-format
52 mTypeOfLength->addItem(i18n("% of windows"), QTextLength::PercentageLength);
53 mTypeOfLength->addItem(i18n("pixels"), QTextLength::FixedLength);
54 mLength = new QSpinBox;
55 mLength->setMinimum(1);
56 mLength->setMaximum(100);
57 mLength->setValue(100);
58
59 gridLayout->addWidget(new QLabel(i18nc("@label:textbox", "Width:")), 3, 0);
60 gridLayout->addWidget(mLength, 3, 1);
61 gridLayout->addWidget(mTypeOfLength, 3, 2);
62 q->setLayout(gridLayout);
63 }
64
65 QSpinBox *mColumns = nullptr;
66 QSpinBox *mRows = nullptr;
67 QSpinBox *mBorder = nullptr;
68 QSpinBox *mLength = nullptr;
69 QComboBox *mTypeOfLength = nullptr;
70
71 InsertTableWidget *const q;
72};
73
74InsertTableWidget::InsertTableWidget(QWidget *parent)
75 : QWidget(parent)
76 , d(new InsertTableWidgetPrivate(this))
77{
78}
79
80InsertTableWidget::~InsertTableWidget() = default;
81
82void InsertTableWidget::slotTypeOfLengthChanged(int index)
83{
84 switch (index) {
85 case 0:
86 d->mLength->setMaximum(100);
87 d->mLength->setValue(qMin(d->mLength->value(), 100));
88 break;
89 case 1:
90 d->mLength->setMaximum(9999);
91 break;
92 default:
93 qCDebug(KPIMTEXTEDIT_LOG) << " index not defined " << index;
94 break;
95 }
96}
97
98QTextLength::Type InsertTableWidget::typeOfLength() const
99{
100 return static_cast<QTextLength::Type>(d->mTypeOfLength->itemData(d->mTypeOfLength->currentIndex()).toInt());
101}
102
103void InsertTableWidget::setTypeOfLength(QTextLength::Type type)
104{
105 const int index = d->mTypeOfLength->findData(QVariant(type));
106 d->mTypeOfLength->setCurrentIndex(index);
107 slotTypeOfLengthChanged(index);
108}
109
110int InsertTableWidget::length() const
111{
112 return d->mLength->value();
113}
114
115void InsertTableWidget::setLength(int val)
116{
117 d->mLength->setValue(val);
118}
119
120void InsertTableWidget::setColumns(int col)
121{
122 d->mColumns->setValue(col);
123}
124
125void InsertTableWidget::setRows(int rows)
126{
127 d->mRows->setValue(rows);
128}
129
130void InsertTableWidget::setBorder(int border)
131{
132 d->mBorder->setValue(border);
133}
134
135int InsertTableWidget::columns() const
136{
137 return d->mColumns->value();
138}
139
140int InsertTableWidget::rows() const
141{
142 return d->mRows->value();
143}
144
145int InsertTableWidget::border() const
146{
147 return d->mBorder->value();
148}
149
150#include "moc_inserttablewidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void activated(int index)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
void setContentsMargins(const QMargins &margins)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setMaximum(int max)
void setMinimum(int min)
void setSuffix(const QString &suffix)
void setValue(int val)
void setLayout(QLayout *layout)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.