summaryrefslogtreecommitdiffstats
path: root/src/kile/floatdialog.cpp
blob: 4b49c3cc9b5df129dfffb1f09a39adecbed82789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/***************************************************************************
    date                 : Dec 06 2005
    version              : 0.12
    copyright            : (C) 2005 by Holger Danielsson
    email                : holger.danielsson@t-online.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "floatdialog.h"

#include <tqlayout.h>
#include <tqbuttongroup.h>
#include <tqregexp.h>

#include <klocale.h>
#include "kiledebug.h"

#include "kileedit.h"

namespace KileDialog 
{

FloatEnvironmentDialog::FloatEnvironmentDialog(KConfig *config, KileInfo *ki, TQWidget *tqparent) 
	: Wizard(config,tqparent), m_ki(ki)
{
	TQWidget *page = new TQWidget(this);
	setMainWidget(page);
		
	TQGridLayout *grid = new TQGridLayout(page, 6,2, 8,8);
   
	// environment groupbox
	TQButtonGroup *egroup = new TQButtonGroup( i18n("Environment"),page);
	egroup->setColumnLayout(0, Qt::Vertical );
	egroup->tqlayout()->setSpacing( 6 );
	egroup->tqlayout()->setMargin( 11 );
	TQGridLayout *egrouptqlayout = new TQGridLayout( egroup->tqlayout() );
	egrouptqlayout->tqsetAlignment( TQt::AlignTop );

	m_rbFigure = new TQRadioButton(i18n("&Figure"), egroup);
	m_rbTable = new TQRadioButton(i18n("T&able"), egroup);
	
	egrouptqlayout->addWidget( m_rbFigure, 0,0 );
	egrouptqlayout->addWidget( m_rbTable, 0,1 );

	// position groupbox
	TQButtonGroup *pgroup = new TQButtonGroup( i18n("Position"),page);
	pgroup->setColumnLayout(0, Qt::Vertical );
	pgroup->tqlayout()->setSpacing( 6 );
	pgroup->tqlayout()->setMargin( 11 );
	TQGridLayout *pgrouptqlayout = new TQGridLayout( pgroup->tqlayout() );
	pgrouptqlayout->tqsetAlignment( TQt::AlignTop );

	TQLabel *label1 = new TQLabel(i18n("Here exact:"), pgroup);
	TQLabel *label2 = new TQLabel(i18n("Top of page:"), pgroup);
	TQLabel *label3 = new TQLabel(i18n("Bottom of page:"), pgroup);
	TQLabel *label4 = new TQLabel(i18n("Extra page:"), pgroup);
	m_cbHere = new TQCheckBox(pgroup);
	m_cbTop = new TQCheckBox(pgroup);
	m_cbBottom = new TQCheckBox(pgroup);
	m_cbPage = new TQCheckBox(pgroup);
	
	pgrouptqlayout->addWidget( label1, 0,0 );
	pgrouptqlayout->addWidget( label2, 1,0 );
	pgrouptqlayout->addWidget( label3, 0,2 );
	pgrouptqlayout->addWidget( label4, 1,2 );
	pgrouptqlayout->addWidget( m_cbHere, 0,1 );
	pgrouptqlayout->addWidget( m_cbTop, 1,1 );
	pgrouptqlayout->addWidget( m_cbBottom, 0,3 );
	pgrouptqlayout->addWidget( m_cbPage, 1,3 );
	
	// center environment
	TQLabel *label5 = new TQLabel(i18n("Center:"),page);
	m_cbCenter = new TQCheckBox(page);
	
	// Caption
	TQLabel *label6 = new TQLabel(i18n("Ca&ption:"),page);
	m_edCaption = new KLineEdit("",page);
	m_edCaption->setMinimumWidth(300);
	label6->setBuddy(m_edCaption);
	
	// Label
	TQLabel *label7 = new TQLabel(i18n("&Label:"),page);
	m_edLabel = new KLineEdit("",page);
	m_edLabel->setMinimumWidth(300);
	label7->setBuddy(m_edLabel);
	
	
	// add widgets
	grid->addMultiCellWidget( egroup, 0,0,0,1 );
	grid->addMultiCellWidget( pgroup, 1,1,0,1 );
	grid->addWidget(label5,2,0);
	grid->addWidget(label6,3,0);
	grid->addWidget(label7,4,0);
	grid->addWidget(m_cbCenter,2,1);
	grid->addWidget(m_edCaption,3,1);
	grid->addWidget(m_edLabel,4,1);
	
	// default values
	m_cbCenter->setChecked(true);
	m_cbHere->setChecked(true);
	m_cbTop->setChecked(true);
	m_cbPage->setChecked(true);
	m_rbFigure->setChecked(true);
	m_prefix = "fig:";
	m_edLabel->setText(m_prefix);
	slotEnvironmentClicked();
	
	grid->setRowStretch(5,1);
	setFocusProxy( m_edCaption );
	
	// signals and slots
	connect(m_rbFigure, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotEnvironmentClicked()));
	connect(m_rbTable, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotEnvironmentClicked()));
	
}

////////////////////////////// determine the whole tag //////////////////////////////

void FloatEnvironmentDialog::slotOk()
{
	TQString envname = ( m_rbFigure->isChecked() ) ? "figure" : "table";
	TQString indent = m_ki->editorExtension()->autoIndentEnvironment();
	
	TQString position;
	if ( m_cbHere->isChecked() )
		position += 'h';
	if ( m_cbTop->isChecked() )
		position += 't';
	if ( m_cbBottom->isChecked() )
		position += 'b';
	if ( m_cbPage->isChecked() )
		position += 'p';
	
	m_td.tagBegin = "\\begin{" + envname + '}';
	if ( !position.isEmpty() )
		m_td.tagBegin += '[' + position + ']';
	m_td.tagBegin += '\n';
	
	int row = 1;
	if ( m_cbCenter->isChecked() ) {
		m_td.tagBegin += indent + "\\centering\n";
		row = 2;
	}
	
	m_td.tagEnd = indent + '\n';

	TQString caption = m_edCaption->text();
	if ( ! caption.isEmpty() ) 
		m_td.tagEnd += indent  + "\\caption{" + caption + "}\n";

	TQString label = m_edLabel->text();
	if ( !label.isEmpty() && label!=m_prefix ) 
		m_td.tagEnd += indent + "\\label{" + label + "}\n";
		
	m_td.tagEnd += "\\end{" + envname + "}\n";
	
	m_td.dy=row; 
	m_td.dx=indent.length();

	accept();
}

void FloatEnvironmentDialog::slotEnvironmentClicked()
{
	TQString caption,oldprefix;
	
	if ( m_rbFigure->isChecked() ) {
		caption = i18n("Figure Environment");
		oldprefix = "^tab:";
		m_prefix = "fig:";
	} else {
		caption = i18n("Table Environment");
		oldprefix = "^fig:";
		m_prefix = "tab:";
	}
		
	setCaption(caption);
	TQString s = m_edLabel->text();
	s.replace( TQRegExp(oldprefix),m_prefix);
	m_edLabel->setText(s);
	
}

}

#include "floatdialog.moc"