KPimTextEdit

tableformatdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5
6*/
7
8#include "tableformatdialog.h"
9#include "inserttablewidget.h"
10
11#include <KColorButton>
12#include <KLocalizedString>
13#include <KSeparator>
14#include <QComboBox>
15
16#include <QCheckBox>
17#include <QDialogButtonBox>
18#include <QHBoxLayout>
19#include <QLabel>
20#include <QSpinBox>
21#include <QVBoxLayout>
22
23using namespace KPIMTextEdit;
24
25class TableFormatDialog::TableFormatDialogPrivate
26{
27public:
28 explicit TableFormatDialogPrivate(TableFormatDialog *qq)
29 : q(qq)
30 {
31 q->setWindowTitle(i18nc("@title:window", "Table Format"));
32 auto mainLayout = new QVBoxLayout(q);
33
34 auto page = new QWidget(q);
35 auto lay = new QVBoxLayout(page);
36 lay->setContentsMargins({});
37 tableWidget = new InsertTableWidget;
38 lay->addWidget(tableWidget);
39
40 auto sep = new KSeparator;
41 lay->addWidget(sep);
42
43 auto hbox = new QHBoxLayout;
44 auto lab = new QLabel(i18nc("@label:textbox", "Spacing:"));
45 hbox->addWidget(lab);
46 spacing = new QSpinBox;
47 spacing->setMinimum(0);
48 hbox->addWidget(spacing);
49 lab = new QLabel(i18nc("@label:textbox", "pixels between cells"));
50 hbox->addWidget(lab);
51 lay->addLayout(hbox);
52
53 hbox = new QHBoxLayout;
54 lab = new QLabel(i18nc("@label:textbox", "Padding:"));
55 hbox->addWidget(lab);
56 padding = new QSpinBox;
57 padding->setMinimum(0);
58 hbox->addWidget(padding);
59 lab = new QLabel(i18nc("@label:textbox", "pixels between cell border and content"));
60 hbox->addWidget(lab);
61 lay->addLayout(hbox);
62
63 sep = new KSeparator;
64 lay->addWidget(sep);
65
66 alignment = new QComboBox;
67 alignment->addItem(i18n("Left"), Qt::AlignLeft);
68 alignment->addItem(i18n("Right"), Qt::AlignRight);
69 alignment->addItem(i18n("Center"), Qt::AlignHCenter);
70 alignment->addItem(i18n("Justify"), Qt::AlignJustify);
71
72 hbox = new QHBoxLayout;
73 lab = new QLabel(i18nc("@label:textbox", "Table Alignment:"));
74 hbox->addWidget(lab);
75 hbox->addWidget(alignment);
76
77 lay->addLayout(hbox);
78
79 sep = new KSeparator;
80 lay->addWidget(sep);
81
82 hbox = new QHBoxLayout;
83 useBackgroundColor = new QCheckBox(i18nc("@option:check", "Background Color:"));
84
85 hbox->addWidget(useBackgroundColor);
86 backgroundColor = new KColorButton;
87 backgroundColor->setDefaultColor(Qt::white);
88 hbox->addWidget(backgroundColor);
89 lay->addLayout(hbox);
90
91 sep = new KSeparator;
92 lay->addWidget(sep);
93 backgroundColor->setEnabled(false);
94 q->connect(useBackgroundColor, &QCheckBox::toggled, backgroundColor, &KColorButton::setEnabled);
98
99 mainLayout->addWidget(page);
100 mainLayout->addWidget(buttonBox);
101 }
102
103 QCheckBox *useBackgroundColor = nullptr;
104 KColorButton *backgroundColor = nullptr;
105 QComboBox *alignment = nullptr;
106 QSpinBox *spacing = nullptr;
107 QSpinBox *padding = nullptr;
108 KPIMTextEdit::InsertTableWidget *tableWidget = nullptr;
109 TableFormatDialog *const q;
110};
111
112TableFormatDialog::TableFormatDialog(QWidget *parent)
113 : QDialog(parent)
114 , d(new TableFormatDialogPrivate(this))
115{
116}
117
118TableFormatDialog::~TableFormatDialog() = default;
119
120int TableFormatDialog::columns() const
121{
122 return d->tableWidget->columns();
123}
124
125int TableFormatDialog::rows() const
126{
127 return d->tableWidget->rows();
128}
129
130int TableFormatDialog::border() const
131{
132 return d->tableWidget->border();
133}
134
135void TableFormatDialog::setColumns(int col)
136{
137 d->tableWidget->setColumns(col);
138}
139
140void TableFormatDialog::setRows(int row)
141{
142 d->tableWidget->setRows(row);
143}
144
145void TableFormatDialog::setBorder(int border)
146{
147 d->tableWidget->setBorder(border);
148}
149
150int TableFormatDialog::padding() const
151{
152 return d->padding->value();
153}
154
155void TableFormatDialog::setPadding(int value)
156{
157 d->padding->setValue(value);
158}
159
160int TableFormatDialog::spacing() const
161{
162 return d->spacing->value();
163}
164
165void TableFormatDialog::setSpacing(int value)
166{
167 d->spacing->setValue(value);
168}
169
170void TableFormatDialog::setAlignment(Qt::Alignment alignment)
171{
172 d->alignment->setCurrentIndex(d->alignment->findData(QVariant(alignment)));
173}
174
175Qt::Alignment TableFormatDialog::alignment() const
176{
177 return static_cast<Qt::Alignment>(d->alignment->itemData(d->alignment->currentIndex()).toInt());
178}
179
180QTextLength::Type TableFormatDialog::typeOfLength() const
181{
182 return d->tableWidget->typeOfLength();
183}
184
185int TableFormatDialog::length() const
186{
187 return d->tableWidget->length();
188}
189
190void TableFormatDialog::setLength(int val)
191{
192 d->tableWidget->setLength(val);
193}
194
195void TableFormatDialog::setTypeOfLength(QTextLength::Type type)
196{
197 d->tableWidget->setTypeOfLength(type);
198}
199
200QColor TableFormatDialog::tableBackgroundColor() const
201{
202 return d->backgroundColor->color();
203}
204
205void TableFormatDialog::setTableBackgroundColor(const QColor &col)
206{
207 d->backgroundColor->setColor(col);
208 d->useBackgroundColor->setChecked(true);
209}
210
211bool TableFormatDialog::useBackgroundColor() const
212{
213 return d->useBackgroundColor->isChecked();
214}
215
216#include "moc_tableformatdialog.cpp"
void setDefaultColor(const QColor &c)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void toggled(bool checked)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
virtual void accept()
virtual void reject()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setMinimum(int min)
AlignLeft
QWidget(QWidget *parent, Qt::WindowFlags f)
void setEnabled(bool)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:55:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.