1/*
2 Copyright (c) 2012 Montel Laurent <montel@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18
19*/
20
21#include "tablecellformatdialog.h"
22
23#include <KColorButton>
24#include <KComboBox>
25#include <KLocalizedString>
26#include <KSeparator>
27
28#include <QCheckBox>
29#include <QLabel>
30#include <QVBoxLayout>
31
32using namespace KPIMTextEdit;
33
34class TableCellFormatDialog::TableCellFormatDialogPrivate
35{
36 public:
37 TableCellFormatDialogPrivate( TableCellFormatDialog *qq )
38 : q( qq )
39 {
40 q->setCaption( i18n( "Cell Format" ) );
41 q->setButtons( Ok|Cancel );
42 QWidget *page = new QWidget( q );
43 q->setMainWidget( page );
44 QVBoxLayout *lay = new QVBoxLayout( page );
45
46 QHBoxLayout *hbox = new QHBoxLayout;
47 QLabel *lab = new QLabel( i18n( "Vertical Alignment:" ) );
48 hbox->addWidget(lab);
49 verticalAlignment = new KComboBox;
50 verticalAlignment->addItem( i18n( "Top" ), QTextCharFormat::AlignTop );
51 verticalAlignment->addItem( i18n( "Middle" ), QTextCharFormat::AlignMiddle );
52 verticalAlignment->addItem( i18n( "Bottom" ), QTextCharFormat::AlignBottom );
53
54 hbox->addWidget( verticalAlignment );
55 lay->addLayout( hbox );
56
57 KSeparator *sep = new KSeparator;
58 lay->addWidget( sep );
59
60 hbox = new QHBoxLayout;
61 useBackgroundColor = new QCheckBox( i18n( "Background Color:" ) );
62 hbox->addWidget( useBackgroundColor );
63 backgroundColor = new KColorButton;
64 backgroundColor->setDefaultColor( Qt::white );
65 hbox->addWidget( backgroundColor );
66 lay->addLayout(hbox);
67
68 sep = new KSeparator;
69 lay->addWidget( sep );
70 backgroundColor->setEnabled( false );
71 q->connect( useBackgroundColor, SIGNAL(toggled(bool)),
72 backgroundColor, SLOT(setEnabled(bool)) );
73 }
74 QCheckBox *useBackgroundColor;
75
76 KColorButton *backgroundColor;
77 KComboBox *verticalAlignment;
78 TableCellFormatDialog *q;
79};
80
81TableCellFormatDialog::TableCellFormatDialog( QWidget *parent )
82 : KDialog( parent ), d( new TableCellFormatDialogPrivate( this ) )
83{
84}
85
86TableCellFormatDialog::~TableCellFormatDialog()
87{
88 delete d;
89}
90
91QColor TableCellFormatDialog::tableCellBackgroundColor() const
92{
93 return d->backgroundColor->color();
94}
95
96void TableCellFormatDialog::setTableCellBackgroundColor( const QColor &col )
97{
98 d->backgroundColor->setColor( col );
99 d->useBackgroundColor->setChecked( true );
100}
101
102QTextCharFormat::VerticalAlignment TableCellFormatDialog::verticalAlignment() const
103{
104 return
105 ( QTextCharFormat::VerticalAlignment )d->verticalAlignment->itemData(
106 d->verticalAlignment->currentIndex () ).toInt();
107}
108
109void TableCellFormatDialog::setVerticalAlignment( QTextCharFormat::VerticalAlignment vertical )
110{
111 d->verticalAlignment->setCurrentIndex( d->verticalAlignment->findData( QVariant( vertical ) ) );
112}
113
114bool TableCellFormatDialog::useBackgroundColor() const
115{
116 return d->useBackgroundColor->isChecked();
117}
118