summaryrefslogtreecommitdiffstats
path: root/kexi/formeditor/tabstopdialog.cpp
blob: 6de89b717d5db722209e71a083d9b3cddcbaa082 (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
/* This file is part of the KDE project
   Copyright (C) 2004 Cedric Pasteur <[email protected]>
   Copyright (C) 2005 Jaroslaw Staniek <[email protected]>

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

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/
#include <tqlayout.h>
#include <tqcheckbox.h>
#include <tqtooltip.h>

#include <kiconloader.h>
#include <kdebug.h>
#include <klocale.h>
#include <kpushbutton.h>

#include "form.h"
#include "objecttreeview.h"

#include "tabstopdialog.h"

using namespace KFormDesigner;

//////////////////////////////////////////////////////////////////////////////////
//////////  The Tab Stop Dialog to edit tab order  ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////

TabStopDialog::TabStopDialog(TQWidget *tqparent)
: KDialogBase(tqparent, "tabstop_dialog", true, i18n("Edit Tab Order"), Ok|Cancel, Ok, false)
{
	TQFrame *frame = makeMainWidget();
	TQGridLayout *l = new TQGridLayout(frame, 2, 2, 0, 6);
	m_treeview = new ObjectTreeView(frame, "tabstops_treeview", true);
	m_treeview->setItemsMovable(true);
	m_treeview->setDragEnabled(true);
	m_treeview->setDropVisualizer(true);
	m_treeview->setAcceptDrops(true);
	m_treeview->setFocus();
	l->addWidget(m_treeview, 0, 0);

	m_treeview->m_form = 0;
	connect(m_treeview, TQT_SIGNAL(currentChanged(TQListViewItem*)), this, TQT_SLOT(updateButtons(TQListViewItem*)));
	connect(m_treeview, TQT_SIGNAL(moved(TQListViewItem*, TQListViewItem*, TQListViewItem*)), this, TQT_SLOT(updateButtons(TQListViewItem*)));

	TQVBoxLayout *vbox = new TQVBoxLayout();
	l->addLayout(vbox, 0, 1);
	m_btnUp = new KPushButton(SmallIconSet("1uparrow"), i18n("Move Up"), frame);
	TQToolTip::add( m_btnUp, i18n("Move widget up") );
	vbox->addWidget(m_btnUp);
	connect(m_btnUp, TQT_SIGNAL(clicked()), this, TQT_SLOT(moveItemUp()));

	m_btnDown = new KPushButton(SmallIconSet("1downarrow"), i18n("Move Down"), frame);
	TQToolTip::add( m_btnDown, i18n("Move widget down") );
	vbox->addWidget(m_btnDown);
	connect(m_btnDown, TQT_SIGNAL(clicked()), this, TQT_SLOT(moveItemDown()));
	vbox->addStretch();

	m_check = new TQCheckBox(i18n("Handle tab order automatically"), frame, "tabstops_check");
	connect(m_check, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotRadioClicked(bool)));
	l->addMultiCellWidget(m_check, 1, 1, 0, 1);

	updateGeometry();
	setInitialSize(TQSize(500+m_btnUp->width(), TQMAX(400,m_treeview->height())));
}

TabStopDialog::~TabStopDialog()
{
}

int TabStopDialog::exec(Form *form)
{
	m_treeview->clear();
	m_treeview->m_form = form;

	if(form->autoTabStops())
		form->autoAssignTabStops();
	form->updateTabStopsOrder();
	ObjectTreeListIterator it( form->tabStopsIterator() );
	it.toLast();
	for(;it.current(); --it)
		new ObjectTreeViewItem(m_treeview, it.current());

	m_check->setChecked(form->autoTabStops());

	if (m_treeview->firstChild()) {
		m_treeview->setCurrentItem(m_treeview->firstChild());
		m_treeview->setSelected(m_treeview->firstChild(), true);
	}

	if (TQDialog::Rejected == KDialogBase::exec())
		return TQDialog::Rejected;

	//accepted
	form->setAutoTabStops(m_check->isChecked());
	if(form->autoTabStops())
	{
		form->autoAssignTabStops();
		return TQDialog::Accepted;
	}

	//add items to the order list
	form->tabStops()->clear();
	ObjectTreeViewItem *item = (ObjectTreeViewItem*)m_treeview->firstChild();
	while(item)
	{
		ObjectTreeItem *tree = item->objectTree();
		if(tree)
			form->tabStops()->append(tree);
		item = (ObjectTreeViewItem*)item->nextSibling();
	}
	return TQDialog::Accepted;
}

void
TabStopDialog::moveItemUp()
{
	if (!m_treeview->selectedItem())
		return;
	TQListViewItem *before = m_treeview->selectedItem()->itemAbove();
	before->moveItem(m_treeview->selectedItem());
	updateButtons(m_treeview->selectedItem());
}

void
TabStopDialog::moveItemDown()
{
	TQListViewItem *item = m_treeview->selectedItem();
	if (!item)
		return;
	item->moveItem( item->nextSibling());
	updateButtons(item);
}

void
TabStopDialog::updateButtons(TQListViewItem *item)
{
	m_btnUp->setEnabled( item && (item->itemAbove() && m_treeview->isEnabled()
	/*&& (item->itemAbove()->tqparent() == item->tqparent()))*/ ));
	m_btnDown->setEnabled( item && item->nextSibling() && m_treeview->isEnabled() );
}

void
TabStopDialog::slotRadioClicked(bool isOn)
{
	m_treeview->setEnabled(!isOn);
	updateButtons( m_treeview->selectedItem() );
}

bool
TabStopDialog::autoTabStops() const
{
	return m_check->isChecked();
}

#include "tabstopdialog.moc"