Eneboo - Documentación para desarrolladores
src/qt/tools/designer/designer/configtoolboxdialog.ui.h
Ir a la documentación de este archivo.
00001 /**********************************************************************
00002 ** Copyright (C) 2005-2007 Trolltech ASA.  All rights reserved.
00003 **
00004 ** This file is part of Qt Designer.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00012 ** licenses may use this file in accordance with the Qt Commercial License
00013 ** Agreement provided with the Software.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00019 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00020 **   information about Qt Commercial License Agreements.
00021 **
00022 ** Contact info@trolltech.com if any conditions of this licensing are
00023 ** not clear to you.
00024 **
00025 **********************************************************************/
00026 
00027 #include "mainwindow.h"
00028 #include "widgetaction.h"
00029 #include "listviewdnd.h"
00030 #include <qlistview.h>
00031 
00032 void ConfigToolboxDialog::init()
00033 {
00034     listViewTools->setSorting( -1 );
00035     listViewCommon->setSorting( -1 );
00036 
00037     ListViewDnd *toolsDnd = new ListViewDnd( listViewTools );
00038     toolsDnd->setDragMode( ListViewDnd::External | ListViewDnd::NullDrop | ListViewDnd::Flat );
00039 
00040     ListViewDnd *commonDnd = new ListViewDnd( listViewCommon );
00041     commonDnd->setDragMode( ListViewDnd::Both | ListViewDnd::Move | ListViewDnd::Flat );
00042 
00043     QObject::connect( toolsDnd, SIGNAL( dropped( QListViewItem * ) ),
00044                         commonDnd, SLOT( confirmDrop( QListViewItem * ) ) );
00045     QObject::connect( commonDnd, SIGNAL( dropped( QListViewItem * ) ),
00046                         commonDnd, SLOT( confirmDrop( QListViewItem * ) ) );
00047 
00048     QDict<QListViewItem> groups;
00049     QAction *a;
00050     for ( a = MainWindow::self->toolActions.last();
00051           a;
00052           a = MainWindow::self->toolActions.prev() ) {
00053         QString grp = ( (WidgetAction*)a )->group();
00054         QListViewItem *parent = groups.find( grp );
00055         if ( !parent ) {
00056             parent = new QListViewItem( listViewTools );
00057             parent->setText( 0, grp );
00058             parent->setOpen( TRUE );
00059             groups.insert( grp, parent );
00060         }
00061         QListViewItem *i = new QListViewItem( parent );
00062         i->setText( 0, a->text() );
00063         i->setPixmap( 0, a->iconSet().pixmap() );
00064     }
00065     for ( a = MainWindow::self->commonWidgetsPage.last(); a;
00066     a = MainWindow::self->commonWidgetsPage.prev() ) {
00067         QListViewItem *i = new QListViewItem( listViewCommon );
00068         i->setText( 0, a->text() );
00069         i->setPixmap( 0, a->iconSet().pixmap() );
00070     }
00071 
00072 }
00073 
00074 
00075 void ConfigToolboxDialog::addTool()
00076 {
00077     QListView *src = listViewTools;
00078 
00079     bool addKids = FALSE;
00080     QListViewItem *nextSibling = 0;
00081     QListViewItem *nextParent = 0;
00082     QListViewItemIterator it = src->firstChild();
00083     for ( ; *it; it++ ) {
00084         // Hit the nextSibling, turn of child processing
00085         if ( (*it) == nextSibling )
00086             addKids = FALSE;
00087 
00088         if ( (*it)->isSelected() ) {
00089             if ( (*it)->childCount() == 0 ) {
00090                 // Selected, no children
00091                 QListViewItem *i = new QListViewItem( listViewCommon, listViewCommon->lastItem() );
00092                 i->setText( 0, (*it)->text(0) );
00093                 i->setPixmap( 0, *((*it)->pixmap(0)) );
00094                 listViewCommon->setCurrentItem( i );
00095                 listViewCommon->ensureItemVisible( i );
00096             } else if ( !addKids ) {
00097                 // Children processing not set, so set it
00098                 // Also find the item were we shall quit
00099                 // processing children...if any such item
00100                 addKids = TRUE;
00101                 nextSibling = (*it)->nextSibling();
00102                 nextParent = (*it)->parent();
00103                 while ( nextParent && !nextSibling ) {
00104                     nextSibling = nextParent->nextSibling();
00105                     nextParent = nextParent->parent();
00106                 }
00107             }
00108         } else if ( ((*it)->childCount() == 0) && addKids ) {
00109             // Leaf node, and we _do_ process children
00110             QListViewItem *i = new QListViewItem( listViewCommon, listViewCommon->lastItem() );
00111             i->setText( 0, (*it)->text(0) );
00112             i->setPixmap( 0, *((*it)->pixmap(0)) );
00113             listViewCommon->setCurrentItem( i );
00114             listViewCommon->ensureItemVisible( i );
00115         }
00116     }
00117 }
00118 
00119 
00120 void ConfigToolboxDialog::removeTool()
00121 {
00122     QListViewItemIterator it = listViewCommon->firstChild();
00123     while ( *it ) {
00124         if ( (*it)->isSelected() )
00125             delete (*it);
00126         else
00127             it++;
00128     }
00129 }
00130 
00131 
00132 void ConfigToolboxDialog::moveToolUp()
00133 {
00134     QListViewItem *next = 0;
00135     QListViewItem *item = listViewCommon->firstChild();
00136     for ( int i = 0; i < listViewCommon->childCount(); ++i ) {
00137         next = item->itemBelow();
00138         if ( item->isSelected() && (i > 0) && !item->itemAbove()->isSelected() )
00139             item->itemAbove()->moveItem( item );
00140         item = next;
00141     }
00142 }
00143 
00144 
00145 void ConfigToolboxDialog::moveToolDown()
00146 {
00147     int count = listViewCommon->childCount();
00148     QListViewItem *next = 0;
00149     QListViewItem *item = listViewCommon->lastItem();
00150     for ( int i = 0; i < count; ++i ) {
00151         next = item->itemAbove();
00152         if ( item->isSelected() && (i > 0) && !item->itemBelow()->isSelected() )
00153             item->moveItem( item->itemBelow() );
00154         item = next;
00155     }
00156 
00157  //   QListViewItem *item = listViewCommon->firstChild();
00158  //   for ( int i = 0; i < listViewCommon->childCount(); ++i ) {
00159         //if ( item == listViewCommon->currentItem() ) {
00160         //    item->moveItem( item->itemBelow() );
00161         //    currentCommonToolChanged( item );
00162         //    break;
00163         //}
00164         //item = item->itemBelow();
00165  //   }
00166 }
00167 
00168 
00169 void ConfigToolboxDialog::currentToolChanged( QListViewItem *i )
00170 {
00171     bool canAdd = FALSE;
00172     QListViewItemIterator it = listViewTools->firstChild();
00173     for ( ; *it; it++ ) {
00174         if ( (*it)->isSelected() ) {
00175             canAdd = TRUE;
00176             break;
00177         }
00178     }
00179     buttonAdd->setEnabled( canAdd || ( i && i->isSelected() ) );
00180 }
00181 
00182 
00183 void ConfigToolboxDialog::currentCommonToolChanged( QListViewItem *i )
00184 {
00185     buttonUp->setEnabled( (bool) (i && i->itemAbove()) );
00186     buttonDown->setEnabled( (bool) (i && i->itemBelow()) );
00187 
00188     bool canRemove = FALSE;
00189     QListViewItemIterator it = listViewCommon->firstChild();
00190     for ( ; *it; it++ ) {
00191         if ( (*it)->isSelected() ) {
00192             canRemove = TRUE;
00193             break;
00194         }
00195     }
00196     buttonRemove->setEnabled( canRemove || ( i && i->isSelected() ) );
00197 }
00198 
00199 
00200 void ConfigToolboxDialog::ok()
00201 {
00202     MainWindow::self->commonWidgetsPage.clear();
00203     QListViewItem *item = listViewCommon->firstChild();
00204     for ( int j = 0; j < listViewCommon->childCount(); item = item->itemBelow(), ++j ) {
00205         QAction *a = 0;
00206         for ( a = MainWindow::self->toolActions.last();
00207             a;
00208             a = MainWindow::self->toolActions.prev() ) {
00209             if ( a->text() == item->text( 0 ) )
00210                 break;
00211         }
00212         if ( a )
00213             MainWindow::self->commonWidgetsPage.insert( j, a );
00214     }
00215 }
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'