KPimTextEdit

tablecellformatdialog.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 "tablecellformatdialog.h"
9
10#include <KColorButton>
11#include <KLocalizedString>
12#include <KSeparator>
13#include <QComboBox>
14
15#include <QCheckBox>
16#include <QDialogButtonBox>
17#include <QLabel>
18#include <QVBoxLayout>
19
20using namespace KPIMTextEdit;
21
22class TableCellFormatDialog::TableCellFormatDialogPrivate
23{
24public:
25 explicit TableCellFormatDialogPrivate(TableCellFormatDialog *qq)
26 : q(qq)
27 {
28 q->setWindowTitle(i18nc("@title:window", "Cell Format"));
29 auto mainLayout = new QVBoxLayout;
30 q->setLayout(mainLayout);
31
32 auto hbox = new QHBoxLayout;
33 auto lab = new QLabel(i18nc("@label:textbox", "Vertical Alignment:"));
34 hbox->addWidget(lab);
35 verticalAlignment = new QComboBox;
36 verticalAlignment->addItem(i18n("Top"), QTextCharFormat::AlignTop);
37 verticalAlignment->addItem(i18n("Middle"), QTextCharFormat::AlignMiddle);
38 verticalAlignment->addItem(i18n("Bottom"), QTextCharFormat::AlignBottom);
39
40 hbox->addWidget(verticalAlignment);
41 mainLayout->addLayout(hbox);
42
43 auto sep = new KSeparator;
44 mainLayout->addWidget(sep);
45
46 hbox = new QHBoxLayout;
47 useBackgroundColor = new QCheckBox(i18nc("@option:check", "Background Color:"));
48 hbox->addWidget(useBackgroundColor);
49 backgroundColor = new KColorButton;
50 backgroundColor->setDefaultColor(Qt::white);
51 hbox->addWidget(backgroundColor);
52 mainLayout->addLayout(hbox);
53
54 sep = new KSeparator;
55 mainLayout->addWidget(sep);
56 backgroundColor->setEnabled(false);
57 q->connect(useBackgroundColor, &QCheckBox::toggled, backgroundColor, &KColorButton::setEnabled);
58
60 buttonBox->button(QDialogButtonBox::Ok)->setShortcut(Qt::CTRL | Qt::Key_Return);
63
64 mainLayout->addWidget(buttonBox);
65 }
66
67 QCheckBox *useBackgroundColor = nullptr;
68
69 KColorButton *backgroundColor = nullptr;
70 QComboBox *verticalAlignment = nullptr;
71 TableCellFormatDialog *const q;
72};
73
74TableCellFormatDialog::TableCellFormatDialog(QWidget *parent)
75 : QDialog(parent)
76 , d(new TableCellFormatDialogPrivate(this))
77{
78}
79
80TableCellFormatDialog::~TableCellFormatDialog() = default;
81
82QColor TableCellFormatDialog::tableCellBackgroundColor() const
83{
84 return d->backgroundColor->color();
85}
86
87void TableCellFormatDialog::setTableCellBackgroundColor(const QColor &col)
88{
89 d->backgroundColor->setColor(col);
90 d->useBackgroundColor->setChecked(true);
91}
92
93QTextCharFormat::VerticalAlignment TableCellFormatDialog::verticalAlignment() const
94{
95 return static_cast<QTextCharFormat::VerticalAlignment>(d->verticalAlignment->itemData(d->verticalAlignment->currentIndex()).toInt());
96}
97
98void TableCellFormatDialog::setVerticalAlignment(QTextCharFormat::VerticalAlignment vertical)
99{
100 d->verticalAlignment->setCurrentIndex(d->verticalAlignment->findData(QVariant(vertical)));
101}
102
103bool TableCellFormatDialog::useBackgroundColor() const
104{
105 return d->useBackgroundColor->isChecked();
106}
107
108#include "moc_tablecellformatdialog.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)
Key_Return
void setEnabled(bool)
void setLayout(QLayout *layout)
void setWindowTitle(const QString &)
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.