tabstopdialog.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20#include <tqlayout.h>
21#include <tqcheckbox.h>
22#include <tqtooltip.h>
23
24#include <kiconloader.h>
25#include <kdebug.h>
26#include <tdelocale.h>
27#include <kpushbutton.h>
28
29#include "form.h"
30#include "objecttreeview.h"
31
32#include "tabstopdialog.h"
33
34using namespace KFormDesigner;
35
39
40TabStopDialog::TabStopDialog(TQWidget *parent)
41: KDialogBase(parent, "tabstop_dialog", true, i18n("Edit Tab Order"), Ok|Cancel, Ok, false)
42{
43 TQFrame *frame = makeMainWidget();
44 TQGridLayout *l = new TQGridLayout(frame, 2, 2, 0, 6);
45 m_treeview = new ObjectTreeView(frame, "tabstops_treeview", true);
46 m_treeview->setItemsMovable(true);
47 m_treeview->setDragEnabled(true);
48 m_treeview->setDropVisualizer(true);
49 m_treeview->setAcceptDrops(true);
50 m_treeview->setFocus();
51 l->addWidget(m_treeview, 0, 0);
52
53 m_treeview->m_form = 0;
54 connect(m_treeview, TQ_SIGNAL(currentChanged(TQListViewItem*)), this, TQ_SLOT(updateButtons(TQListViewItem*)));
55 connect(m_treeview, TQ_SIGNAL(moved(TQListViewItem*, TQListViewItem*, TQListViewItem*)), this, TQ_SLOT(updateButtons(TQListViewItem*)));
56
58 l->addLayout(vbox, 0, 1);
59 m_btnUp = new KPushButton(SmallIconSet("1uparrow"), i18n("Move Up"), frame);
60 TQToolTip::add( m_btnUp, i18n("Move widget up") );
61 vbox->addWidget(m_btnUp);
62 connect(m_btnUp, TQ_SIGNAL(clicked()), this, TQ_SLOT(moveItemUp()));
63
64 m_btnDown = new KPushButton(SmallIconSet("1downarrow"), i18n("Move Down"), frame);
65 TQToolTip::add( m_btnDown, i18n("Move widget down") );
66 vbox->addWidget(m_btnDown);
67 connect(m_btnDown, TQ_SIGNAL(clicked()), this, TQ_SLOT(moveItemDown()));
68 vbox->addStretch();
69
70 m_check = new TQCheckBox(i18n("Handle tab order automatically"), frame, "tabstops_check");
71 connect(m_check, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotRadioClicked(bool)));
72 l->addMultiCellWidget(m_check, 1, 1, 0, 1);
73
74 updateGeometry();
75 setInitialSize(TQSize(500+m_btnUp->width(), TQMAX(400,m_treeview->height())));
76}
77
78TabStopDialog::~TabStopDialog()
79{
80}
81
82int TabStopDialog::exec(Form *form)
83{
84 m_treeview->clear();
85 m_treeview->m_form = form;
86
87 if(form->autoTabStops())
88 form->autoAssignTabStops();
89 form->updateTabStopsOrder();
90 ObjectTreeListIterator it( form->tabStopsIterator() );
91 it.toLast();
92 for(;it.current(); --it)
93 new ObjectTreeViewItem(m_treeview, it.current());
94
95 m_check->setChecked(form->autoTabStops());
96
97 if (m_treeview->firstChild()) {
98 m_treeview->setCurrentItem(m_treeview->firstChild());
99 m_treeview->setSelected(m_treeview->firstChild(), true);
100 }
101
102 if (TQDialog::Rejected == KDialogBase::exec())
103 return TQDialog::Rejected;
104
105 //accepted
106 form->setAutoTabStops(m_check->isChecked());
107 if(form->autoTabStops())
108 {
109 form->autoAssignTabStops();
110 return TQDialog::Accepted;
111 }
112
113 //add items to the order list
114 form->tabStops()->clear();
115 ObjectTreeViewItem *item = (ObjectTreeViewItem*)m_treeview->firstChild();
116 while(item)
117 {
118 ObjectTreeItem *tree = item->objectTree();
119 if(tree)
120 form->tabStops()->append(tree);
121 item = (ObjectTreeViewItem*)item->nextSibling();
122 }
123 return TQDialog::Accepted;
124}
125
126void
127TabStopDialog::moveItemUp()
128{
129 if (!m_treeview->selectedItem())
130 return;
131 TQListViewItem *before = m_treeview->selectedItem()->itemAbove();
132 before->moveItem(m_treeview->selectedItem());
133 updateButtons(m_treeview->selectedItem());
134}
135
136void
137TabStopDialog::moveItemDown()
138{
139 TQListViewItem *item = m_treeview->selectedItem();
140 if (!item)
141 return;
142 item->moveItem( item->nextSibling());
143 updateButtons(item);
144}
145
146void
147TabStopDialog::updateButtons(TQListViewItem *item)
148{
149 m_btnUp->setEnabled( item && (item->itemAbove() && m_treeview->isEnabled()
150 /*&& (item->itemAbove()->parent() == item->parent()))*/ ));
151 m_btnDown->setEnabled( item && item->nextSibling() && m_treeview->isEnabled() );
152}
153
154void
155TabStopDialog::slotRadioClicked(bool isOn)
156{
157 m_treeview->setEnabled(!isOn);
158 updateButtons( m_treeview->selectedItem() );
159}
160
161bool
162TabStopDialog::autoTabStops() const
163{
164 return m_check->isChecked();
165}
166
167#include "tabstopdialog.moc"
168
A simple class representing a form.
Definition form.h:136
bool autoTabStops() const
Definition form.h:279
void setAutoTabStops(bool autoTab)
Definition form.h:286
void autoAssignTabStops()
Definition form.cpp:507
void updateTabStopsOrder()
Definition form.cpp:480
ObjectTreeList * tabStops() const
Definition form.h:267
An item representing a widget Holds the properties of a widget (classname, name, parent,...
Definition objecttree.h:59
An item in ObjectTreeView associated with an ObjectTreeItem.
ObjectTreeItem * objectTree() const
A graphical view of Form's ObjectTree. This is a TDEListView which represents an item for each widget...
TQPtrListIterator< ObjectTreeItem > ObjectTreeListIterator
An iterator for ObjectTreeList.
Definition objecttree.h:45
type * findParent(TQObject *o, const char *className, TQObject *&prevPrev)