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 "tableformatdialog.h"
22#include "inserttabledialog.h"
23
24#include <KLocalizedString>
25#include <KComboBox>
26#include <KSeparator>
27#include <KColorButton>
28
29#include <QVBoxLayout>
30#include <QHBoxLayout>
31#include <QSpinBox>
32#include <QLabel>
33#include <QCheckBox>
34
35using namespace KPIMTextEdit;
36
37class TableFormatDialog::TableFormatDialogPrivate
38{
39 public:
40 TableFormatDialogPrivate( TableFormatDialog *qq )
41 :q( qq )
42 {
43 q->setCaption( i18n( "Table Format" ) );
44 q->setButtons( Ok|Cancel );
45 QWidget *page = new QWidget( q );
46 q->setMainWidget( page );
47 QVBoxLayout *lay = new QVBoxLayout( page );
48 tableWidget = new InsertTableWidget;
49 lay->addWidget( tableWidget );
50
51 KSeparator *sep = new KSeparator;
52 lay->addWidget( sep );
53
54 QHBoxLayout *hbox = new QHBoxLayout;
55 QLabel *lab = new QLabel( i18n( "Spacing:" ) );
56 hbox->addWidget( lab );
57 spacing = new QSpinBox;
58 spacing->setMinimum( 0 );
59 hbox->addWidget( spacing );
60 lab = new QLabel( i18n( "pixels between cells" ) );
61 hbox->addWidget( lab );
62 lay->addLayout( hbox );
63
64 hbox = new QHBoxLayout;
65 lab = new QLabel( i18n( "Padding:" ) );
66 hbox->addWidget( lab );
67 padding = new QSpinBox;
68 padding->setMinimum( 0 );
69 hbox->addWidget( padding );
70 lab = new QLabel( i18n( "pixels between cell border and content" ) );
71 hbox->addWidget( lab );
72 lay->addLayout( hbox );
73
74 sep = new KSeparator;
75 lay->addWidget( sep );
76
77 alignment = new KComboBox;
78 alignment->addItem( i18n( "Left" ), Qt::AlignLeft );
79 alignment->addItem( i18n( "Right" ), Qt::AlignRight );
80 alignment->addItem( i18n( "Center" ), Qt::AlignHCenter );
81 alignment->addItem( i18n( "Justify" ), Qt::AlignJustify );
82
83 hbox = new QHBoxLayout;
84 lab = new QLabel( i18n( "Table Alignment:" ) );
85 hbox->addWidget( lab );
86 hbox->addWidget( alignment );
87
88 lay->addLayout( hbox );
89
90 sep = new KSeparator;
91 lay->addWidget( sep );
92
93 hbox = new QHBoxLayout;
94 useBackgroundColor = new QCheckBox( i18n( "Background Color:" ) );
95
96 hbox->addWidget( useBackgroundColor );
97 backgroundColor = new KColorButton;
98 backgroundColor->setDefaultColor(Qt::white);
99 hbox->addWidget( backgroundColor );
100 lay->addLayout(hbox);
101
102 sep = new KSeparator;
103 lay->addWidget( sep );
104 backgroundColor->setEnabled(false);
105 q->connect( useBackgroundColor, SIGNAL(toggled(bool)),
106 backgroundColor, SLOT(setEnabled(bool)) );
107
108 }
109
110 QCheckBox *useBackgroundColor;
111 KColorButton *backgroundColor;
112 KComboBox *alignment;
113 QSpinBox *spacing;
114 QSpinBox *padding;
115 KPIMTextEdit::InsertTableWidget *tableWidget;
116 TableFormatDialog *q;
117};
118
119TableFormatDialog::TableFormatDialog( QWidget *parent )
120 : KDialog( parent ), d( new TableFormatDialogPrivate( this ) )
121{
122}
123
124TableFormatDialog::~TableFormatDialog()
125{
126 delete d;
127}
128
129int TableFormatDialog::columns() const
130{
131 return d->tableWidget->columns();
132}
133
134int TableFormatDialog::rows() const
135{
136 return d->tableWidget->rows();
137}
138
139int TableFormatDialog::border() const
140{
141 return d->tableWidget->border();
142}
143
144void TableFormatDialog::setColumns( int col )
145{
146 d->tableWidget->setColumns( col );
147}
148
149void TableFormatDialog::setRows( int row )
150{
151 d->tableWidget->setRows( row );
152}
153
154void TableFormatDialog::setBorder( int border )
155{
156 d->tableWidget->setBorder( border );
157}
158
159int TableFormatDialog::padding() const
160{
161 return d->padding->value();
162}
163
164void TableFormatDialog::setPadding( int value )
165{
166 d->padding->setValue( value );
167}
168
169int TableFormatDialog::spacing() const
170{
171 return d->spacing->value();
172}
173
174void TableFormatDialog::setSpacing( int value )
175{
176 d->spacing->setValue( value );
177}
178
179void TableFormatDialog::setAlignment( Qt::Alignment alignment )
180{
181 d->alignment->setCurrentIndex( d->alignment->findData( QVariant( alignment ) ) );
182}
183
184Qt::Alignment TableFormatDialog::alignment() const
185{
186 return ( Qt::Alignment )d->alignment->itemData( d->alignment->currentIndex () ).toInt();
187}
188
189QTextLength::Type TableFormatDialog::typeOfLength() const
190{
191 return d->tableWidget->typeOfLength();
192}
193
194int TableFormatDialog::length() const
195{
196 return d->tableWidget->length();
197}
198
199void TableFormatDialog::setLength( int val )
200{
201 d->tableWidget->setLength( val );
202}
203
204void TableFormatDialog::setTypeOfLength( QTextLength::Type type )
205{
206 d->tableWidget->setTypeOfLength( type );
207}
208
209QColor TableFormatDialog::tableBackgroundColor() const
210{
211 return d->backgroundColor->color();
212}
213
214void TableFormatDialog::setTableBackgroundColor( const QColor &col )
215{
216 d->backgroundColor->setColor( col );
217 d->useBackgroundColor->setChecked( true );
218}
219
220bool TableFormatDialog::useBackgroundColor() const
221{
222 return d->useBackgroundColor->isChecked();
223}
224
225