kexi

tabstopdialog.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 #include <qlayout.h>
00021 #include <qcheckbox.h>
00022 #include <qtooltip.h>
00023 
00024 #include <kiconloader.h>
00025 #include <kdebug.h>
00026 #include <klocale.h>
00027 #include <kpushbutton.h>
00028 
00029 #include "form.h"
00030 #include "objecttreeview.h"
00031 
00032 #include "tabstopdialog.h"
00033 
00034 using namespace KFormDesigner;
00035 
00039 
00040 TabStopDialog::TabStopDialog(QWidget *parent)
00041 : KDialogBase(parent, "tabstop_dialog", true, i18n("Edit Tab Order"), Ok|Cancel, Ok, false)
00042 {
00043     QFrame *frame = makeMainWidget();
00044     QGridLayout *l = new QGridLayout(frame, 2, 2, 0, 6);
00045     m_treeview = new ObjectTreeView(frame, "tabstops_treeview", true);
00046     m_treeview->setItemsMovable(true);
00047     m_treeview->setDragEnabled(true);
00048     m_treeview->setDropVisualizer(true);
00049     m_treeview->setAcceptDrops(true);
00050     m_treeview->setFocus();
00051     l->addWidget(m_treeview, 0, 0);
00052 
00053     m_treeview->m_form = 0;
00054     connect(m_treeview, SIGNAL(currentChanged(QListViewItem*)), this, SLOT(updateButtons(QListViewItem*)));
00055     connect(m_treeview, SIGNAL(moved(QListViewItem*, QListViewItem*, QListViewItem*)), this, SLOT(updateButtons(QListViewItem*)));
00056 
00057     QVBoxLayout *vbox = new QVBoxLayout();
00058     l->addLayout(vbox, 0, 1);
00059     m_btnUp = new KPushButton(SmallIconSet("1uparrow"), i18n("Move Up"), frame);
00060     QToolTip::add( m_btnUp, i18n("Move widget up") );
00061     vbox->addWidget(m_btnUp);
00062     connect(m_btnUp, SIGNAL(clicked()), this, SLOT(moveItemUp()));
00063 
00064     m_btnDown = new KPushButton(SmallIconSet("1downarrow"), i18n("Move Down"), frame);
00065     QToolTip::add( m_btnDown, i18n("Move widget down") );
00066     vbox->addWidget(m_btnDown);
00067     connect(m_btnDown, SIGNAL(clicked()), this, SLOT(moveItemDown()));
00068     vbox->addStretch();
00069 
00070     m_check = new QCheckBox(i18n("Handle tab order automatically"), frame, "tabstops_check");
00071     connect(m_check, SIGNAL(toggled(bool)), this, SLOT(slotRadioClicked(bool)));
00072     l->addMultiCellWidget(m_check, 1, 1, 0, 1);
00073 
00074     updateGeometry();
00075     setInitialSize(QSize(500+m_btnUp->width(), QMAX(400,m_treeview->height())));
00076 }
00077 
00078 TabStopDialog::~TabStopDialog()
00079 {
00080 }
00081 
00082 int TabStopDialog::exec(Form *form)
00083 {
00084     m_treeview->clear();
00085     m_treeview->m_form = form;
00086 
00087     if(form->autoTabStops())
00088         form->autoAssignTabStops();
00089     form->updateTabStopsOrder();
00090     ObjectTreeListIterator it( form->tabStopsIterator() );
00091     it.toLast();
00092     for(;it.current(); --it)
00093         new ObjectTreeViewItem(m_treeview, it.current());
00094 
00095     m_check->setChecked(form->autoTabStops());
00096 
00097     if (m_treeview->firstChild()) {
00098         m_treeview->setCurrentItem(m_treeview->firstChild());
00099         m_treeview->setSelected(m_treeview->firstChild(), true);
00100     }
00101 
00102     if (QDialog::Rejected == KDialogBase::exec())
00103         return QDialog::Rejected;
00104 
00105     //accepted
00106     form->setAutoTabStops(m_check->isChecked());
00107     if(form->autoTabStops())
00108     {
00109         form->autoAssignTabStops();
00110         return QDialog::Accepted;
00111     }
00112 
00113     //add items to the order list
00114     form->tabStops()->clear();
00115     ObjectTreeViewItem *item = (ObjectTreeViewItem*)m_treeview->firstChild();
00116     while(item)
00117     {
00118         ObjectTreeItem *tree = item->objectTree();
00119         if(tree)
00120             form->tabStops()->append(tree);
00121         item = (ObjectTreeViewItem*)item->nextSibling();
00122     }
00123     return QDialog::Accepted;
00124 }
00125 
00126 void
00127 TabStopDialog::moveItemUp()
00128 {
00129     if (!m_treeview->selectedItem())
00130         return;
00131     QListViewItem *before = m_treeview->selectedItem()->itemAbove();
00132     before->moveItem(m_treeview->selectedItem());
00133     updateButtons(m_treeview->selectedItem());
00134 }
00135 
00136 void
00137 TabStopDialog::moveItemDown()
00138 {
00139     QListViewItem *item = m_treeview->selectedItem();
00140     if (!item)
00141         return;
00142     item->moveItem( item->nextSibling());
00143     updateButtons(item);
00144 }
00145 
00146 void
00147 TabStopDialog::updateButtons(QListViewItem *item)
00148 {
00149     m_btnUp->setEnabled( item && (item->itemAbove() && m_treeview->isEnabled()
00150     /*&& (item->itemAbove()->parent() == item->parent()))*/ ));
00151     m_btnDown->setEnabled( item && item->nextSibling() && m_treeview->isEnabled() );
00152 }
00153 
00154 void
00155 TabStopDialog::slotRadioClicked(bool isOn)
00156 {
00157     m_treeview->setEnabled(!isOn);
00158     updateButtons( m_treeview->selectedItem() );
00159 }
00160 
00161 bool
00162 TabStopDialog::autoTabStops() const
00163 {
00164     return m_check->isChecked();
00165 }
00166 
00167 #include "tabstopdialog.moc"
00168 
KDE Home | KDE Accessibility Home | Description of Access Keys