Eneboo - Documentación para desarrolladores
src/qt/tools/designer/designer/connectiondialog.ui.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** ui.h extension file, included from the uic-generated form implementation.
00003 **
00004 ** If you wish to add, delete or rename slots use Qt Designer which will
00005 ** update this file, preserving your code. Create an init() slot in place of
00006 ** a constructor, and a destroy() slot in place of a destructor.
00007 *****************************************************************************/
00008 
00009 #include "mainwindow.h"
00010 #include "formwindow.h"
00011 #include "editfunctionsimpl.h"
00012 
00013 static const char *valid_connection[] = {
00014     "16 14 7 1",
00015     ". c none",
00016     "# c #00c000",
00017     "a c #008000",
00018     "b c #004000",
00019     "c c #000000",
00020     "d c #c0fcc0",
00021     "e c #400000",
00022     "...............d",
00023     "..............d#",
00024     ".............d#a",
00025     "............d#ab",
00026     "...........d#abc",
00027     "..da......d#abc.",
00028     ".d##a....d#abe..",
00029     "cba##a..d#abc...",
00030     ".cba##ad#abe....",
00031     "..eba###abe.....",
00032     "...cba#abc......",
00033     "....cbabc.......",
00034     ".....cec........",
00035     "................"
00036 };
00037 
00038 static const char * invalid_connection[] = {
00039     "17 18 7 1",
00040     "       c None",
00041     ".      c #000000",
00042     "+      c #C3C3C3",
00043     "@      c #FFFFFF",
00044     "#      c #C00000",
00045     "$      c #FFC0C0",
00046     "%      c #FF0000",
00047     "                 ",
00048     "       .         ",
00049     "      ...        ",
00050     "     .+..        ",
00051     "  ...+@+..       ",
00052     "..+@@@+#..       ",
00053     ".@@@@$#%#..      ",
00054     ".@@$$#%##..      ",
00055     " .$%%%##....     ",
00056     " .%%%##.  ..     ",
00057     "  .%#..    ..    ",
00058     "   ..      ..    ",
00059     "            ..   ",
00060     "            ..   ",
00061     "             ..  ",
00062     "             ..  ",
00063     "                 ",
00064     "                 "
00065 };
00066 
00067 static QPixmap *invalidConnection = 0;
00068 static QPixmap *validConnection = 0;
00069 
00070 void ConnectionDialog::init()
00071 {
00072     connect( connectionsTable, SIGNAL( currentChanged( int, int ) ),
00073              this, SLOT( updateEditSlotsButton() ) );
00074     connect( connectionsTable, SIGNAL( resorted() ),
00075              this, SLOT( updateConnectionContainers() ) );
00076     buttonEditSlots->setEnabled( FALSE );
00077 
00078     if ( !invalidConnection ) {
00079         invalidConnection = new QPixmap( invalid_connection );
00080         validConnection = new QPixmap( valid_connection );
00081     }
00082 
00083     QValueList<MetaDataBase::Connection> conns =
00084         MetaDataBase::connections( MainWindow::self->formWindow() );
00085     for ( QValueList<MetaDataBase::Connection>::Iterator it = conns.begin();
00086           it != conns.end(); ++it ) {
00087         ConnectionContainer *c = addConnection( (*it).sender, (*it).receiver,
00088                                                 (*it).signal, (*it).slot );
00089         c->setModified( FALSE );
00090         updateConnectionState( c );
00091     }
00092 
00093     defaultSender = defaultReceiver = 0;
00094     connectionsTable->setCurrentCell( 0, 0 );
00095 }
00096 
00097 void ConnectionDialog::addConnection()
00098 {
00099     addConnection( defaultSender, defaultReceiver, QString::null, QString::null );
00100     ensureConnectionVisible();
00101 }
00102 
00103 ConnectionContainer *ConnectionDialog::addConnection( QObject *sender, QObject *receiver,
00104                                                       const QString &signal,
00105                                                       const QString &slot )
00106 {
00107     connectionsTable->insertRows( connectionsTable->numRows() );
00108 
00109     int row = connectionsTable->numRows() - 1;
00110     SenderItem *se;
00111     SignalItem *si;
00112     ReceiverItem *re;
00113     SlotItem *sl;
00114     connectionsTable->setItem( row, 0,
00115                                ( se = new SenderItem( connectionsTable,
00116                                                       MainWindow::self->formWindow() ) ) );
00117     connectionsTable->setItem( row, 1,
00118                                ( si = new SignalItem( connectionsTable,
00119                                                       MainWindow::self->formWindow() ) ) );
00120     connectionsTable->setItem( row, 2,
00121                                ( re = new ReceiverItem( connectionsTable,
00122                                                         MainWindow::self->formWindow() ) ) );
00123     connectionsTable->setItem( row, 3,
00124                                ( sl = new SlotItem( connectionsTable,
00125                                                     MainWindow::self->formWindow() ) ) );
00126 
00127     si->setSender( se );
00128     re->setSender( se );
00129     sl->setSender( se );
00130     se->setSender( se );
00131 
00132     se->setSignal( si );
00133     re->setSignal( si );
00134     sl->setSignal( si );
00135     si->setSignal( si );
00136 
00137     se->setReceiver( re );
00138     si->setReceiver( re );
00139     sl->setReceiver( re );
00140     re->setReceiver( re );
00141 
00142     se->setSlot( sl );
00143     si->setSlot( sl );
00144     re->setSlot( sl );
00145     sl->setSlot( sl );
00146 
00147     connect( re, SIGNAL( currentReceiverChanged( QObject * ) ),
00148              this, SLOT( updateEditSlotsButton() ) );
00149 
00150     ConnectionContainer *c = new ConnectionContainer( this, se, si, re, sl, row );
00151     connections.append( c );
00152     connect( c, SIGNAL( changed( ConnectionContainer * ) ),
00153              this, SLOT( updateConnectionState( ConnectionContainer * ) ) );
00154 
00155     connectionsTable->setCurrentCell( row, 0 );
00156 
00157     connectionsTable->verticalHeader()->setLabel( row, *invalidConnection, QString::null );
00158 
00159     if ( sender )
00160         se->setSenderEx( sender );
00161     defaultSender = sender;
00162     if ( receiver )
00163         re->setReceiverEx( receiver );
00164     defaultReceiver = receiver;
00165 
00166     if ( !signal.isEmpty() && !slot.isEmpty() ) {
00167         si->setCurrentItem( signal );
00168         sl->signalChanged( signal );
00169         sl->setCurrentItem( slot );
00170     }
00171 
00172     c->setModified( TRUE );
00173     return c;
00174 }
00175 
00176 void ConnectionDialog::updateConnectionState( ConnectionContainer *c )
00177 {
00178     c->repaint();
00179     if ( c->isValid() )
00180         connectionsTable->verticalHeader()->setLabel( c->row(),
00181                                                       *validConnection, QString::null );
00182     else
00183         connectionsTable->verticalHeader()->setLabel( c->row(),
00184                                                       *invalidConnection, QString::null );
00185 }
00186 
00187 
00188 void ConnectionDialog::okClicked()
00189 {
00190     QValueList<MetaDataBase::Connection> oldConnections =
00191         MetaDataBase::connections( MainWindow::self->formWindow() );
00192     QPtrList<Command> newConnectionCmds;
00193     QPtrList<Command> oldConnectionCmds;
00194     for ( ConnectionContainer *c = connections.first(); c; c = connections.next() ) {
00195         MetaDataBase::Connection conn;
00196 
00197         // find sender widget
00198         conn.sender = MainWindow::self->formWindow()->child( c->senderItem()->currentText() );
00199         if ( !conn.sender ) // if no sender widget, find sender action
00200             conn.sender = MainWindow::self->formWindow()->findAction( c->senderItem()->currentText() );
00201 
00202         // find receiver widget
00203         conn.receiver = MainWindow::self->formWindow()->child( c->receiverItem()->currentText() );
00204         if ( !conn.receiver ) // if no receiver widget, find receiver action
00205             conn.receiver = MainWindow::self->formWindow()->findAction( c->receiverItem()->currentText() );
00206 
00207         conn.signal = c->signalItem()->currentText();
00208         conn.slot = c->slotItem()->currentText();
00209         AddConnectionCommand *cmd = new AddConnectionCommand( tr( "Add Signal/Slot "
00210                                                                   "Connection" ),
00211                                                               MainWindow::self->formWindow(),
00212                                                               conn );
00213         newConnectionCmds.append( cmd );
00214     }
00215 
00216 
00217     QValueList<MetaDataBase::Connection> conns =
00218         MetaDataBase::connections( MainWindow::self->formWindow() );
00219     for ( QValueList<MetaDataBase::Connection>::Iterator it = conns.begin();
00220           it != conns.end(); ++it ) {
00221         RemoveConnectionCommand *cmd = new RemoveConnectionCommand( tr( "Remove Signal/Slot "
00222                                                                         "Connection" ),
00223                                                                     MainWindow::self->
00224                                                                     formWindow(), *it );
00225         oldConnectionCmds.append( cmd );
00226     }
00227 
00228     MacroCommand *cmd1 = new MacroCommand( tr( "Add Signal/Slot Connections" ),
00229                                            MainWindow::self->formWindow(),
00230                                            newConnectionCmds );
00231     MacroCommand *cmd2 = new MacroCommand( tr( "Remove Signal/Slot Connections" ),
00232                                            MainWindow::self->formWindow(),
00233                                            oldConnectionCmds );
00234     QPtrList<Command> cmds;
00235     cmds.append( cmd2 );
00236     cmds.append( cmd1 );
00237     MacroCommand *cmd = new MacroCommand( tr( "Edit Signal/Slot Connections" ),
00238                                           MainWindow::self->formWindow(),
00239                                           cmds );
00240     MainWindow::self->formWindow()->commandHistory()->addCommand( cmd );
00241     cmd->execute();
00242 
00243     accept();
00244 }
00245 
00246 
00247 void ConnectionDialog::cancelClicked()
00248 {
00249     reject();
00250 }
00251 
00252 
00253 void ConnectionDialog::deleteClicked()
00254 {
00255     int cr = connectionsTable->currentRow();
00256     connections.remove( cr );
00257     connectionsTable->removeRow( cr );
00258     int i = 0;
00259     for ( ConnectionContainer *c = connections.first(); c; c = connections.next() )
00260         c->setRow( i++ );
00261 }
00262 
00263 
00264 void ConnectionDialog::editSlots()
00265 {
00266     EditFunctions dlg( this, MainWindow::self->formWindow(), TRUE );
00267     dlg.exec();
00268     int currentCol = connectionsTable->currentColumn();
00269     connectionsTable->setCurrentCell( connectionsTable->currentRow(), 0 );
00270     for ( ConnectionContainer *c = connections.first(); c; c = connections.next() ) {
00271         if ( c->receiverItem()->currentText() !=
00272              QString( MainWindow::self->formWindow()->mainContainer()->name() ) )
00273             continue;
00274         c->slotItem()->customSlotsChanged();
00275     }
00276     connectionsTable->setCurrentCell( connectionsTable->currentRow(), currentCol );
00277 }
00278 
00279 void ConnectionDialog::setDefault( QObject *sender, QObject *receiver )
00280 {
00281     defaultSender = sender;
00282     defaultReceiver = receiver;
00283 }
00284 
00285 void ConnectionDialog::updateEditSlotsButton()
00286 {
00287     if ( connectionsTable->currentRow() < 0 ||
00288          connectionsTable->currentRow() > (int)connections.count() - 1 )
00289         return;
00290     ConnectionContainer *c = connections.at( connectionsTable->currentRow() );
00291     if ( !c || !c->receiverItem() )
00292         return;
00293     buttonEditSlots->setEnabled( c->receiverItem()->currentText() ==
00294                                  QString( MainWindow::self->formWindow()->
00295                                           mainContainer()->name() ) );
00296 }
00297 
00298 void ConnectionDialog::updateConnectionContainers()
00299 {
00300     QPtrList<ConnectionContainer> newContainers;
00301     for ( int i = 0; i < connectionsTable->numRows(); ++i ) {
00302         for ( ConnectionContainer *c = connections.first(); c; c = connections.next() ) {
00303             if ( c->senderItem() == connectionsTable->item( i, 0 ) ) {
00304                 newContainers.append( c );
00305                 c->setRow( i );
00306                 updateConnectionState(c);
00307                 break;
00308             }
00309         }
00310     }
00311     connections = newContainers;
00312     updateEditSlotsButton();
00313 }
00314 
00315 void ConnectionDialog::ensureConnectionVisible()
00316 {
00317     connectionsTable->ensureCellVisible( connectionsTable->numRows() - 1, 0 );
00318 }
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'