⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glade2ui.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    qtLabel.replace( '&', QString("&&") );    // close but not quite right    qtLabel.replace( QChar('_'), QChar('&') );    return qtLabel;}static QString decelerate( const QString& gtkLabel ){    QString qtLabel = gtkLabel;    // ditto    qtLabel.replace( '_', QString::null );    return qtLabel;}/*  Converting a GTK widget to a corresponding Qt widget is sometimes  hard. For example, a GtkScrolledWindow should sometimes be converted  into a QTextView, a QTextEdit, a QListView or whatever. What we do  is pretty hackish, but it mostly works.*/QString Glade2Ui::gtk2qtClass( const QString& gtkClass,			       const QValueList<QDomElement>& childWidgets ){    QRegExp gnomeXEntry( QString("Gnome(File|Number|Pixmap)?Entry") );    QString qtClass;    if ( gtkClass == QString("GtkScrolledWindow") ) {	if ( childWidgets.count() == 1 ) {	    QString g;	    bool editable = FALSE;	    bool showTitles = TRUE;	    QDomNode n = childWidgets.first().firstChild();	    while ( !n.isNull() ) {		QString tagName = n.toElement().tagName();		if ( tagName == QString("class") ) {		    g = getTextValue( n );		} else if ( tagName == QString("editable") ) {		    editable = isTrue( getTextValue(n) );		} else if ( tagName.startsWith(QString("show_tit")) ) {		    showTitles = isTrue( getTextValue(n) );		}		n = n.nextSibling();	    }	    if ( g == QString("GnomeCanvas") ||		 g == QString("GtkDrawingArea") ) {		qtClass = QString( "QLabel" );	    } else if ( g == QString("GnomeIconList") ) {		qtClass = QString( "QIconView" );	    } else if ( g == QString("GtkCList") ) {		if ( showTitles )		    qtClass = QString( "QListView" );		else		    qtClass = QString( "QListBox" );	    } else if ( g == QString("GtkCTree") ) {		qtClass = QString( "QListView" );	    } else if ( g == QString("GtkList") ) {		qtClass = QString( "QListBox" );	    } else if ( g == QString("GtkText") ) {		if ( editable )		    qtClass = QString( "QTextEdit" );		else		    qtClass = QString( "QTextView" );	    } else if ( g == QString("GtkTree") ) {		qtClass = QString( "QListView" );	    }	    // else too bad (qtClass is empty)	}    } else if ( gtkClass == QString("GtkWindow") ) {	qtClass = QString( "QDialog" );	if ( childWidgets.count() == 1 ) {	    QString g;	    QDomNode n = childWidgets.first().firstChild();	    while ( !n.isNull() ) {		QString tagName = n.toElement().tagName();		if ( tagName == QString("class") )		    g = getTextValue( n );		n = n.nextSibling();	    }	    if ( g == QString("GnomeDruid") )		qtClass = QString( "QWizard" );	}    /*      GnomeEntry and friends are a wrapper around a GtkEntry. We only      want the GtkEntry child.    */    } else if ( !gnomeXEntry.exactMatch(gtkClass) &&		gtkClass != QString("GtkAlignment") &&		gtkClass != QString("GtkEventBox") ) {	qtClass = yyClassNameMap[gtkClass];	if ( qtClass.isEmpty() )	    qtClass = QString( "Unknown" );    }    return qtClass;}static QString gtk2qtScrollBarMode( const QString& scrollbarPolicy ){    if ( scrollbarPolicy.endsWith(QString("_NEVER")) ) {	return QString( "AlwaysOff" );    } else if ( scrollbarPolicy.endsWith(QString("_ALWAYS")) ) {	return QString( "AlwaysOn" );    } else {	return QString( "Auto" );    }}static QString gtk2qtSelectionMode( const QString& selectionMode ){    if ( selectionMode.endsWith(QString("_MULTIPLE")) )	return QString( "Multi" );    else if ( selectionMode.endsWith(QString("_EXTENDED")) )	return QString( "Extended" );    else	return QString( "Single" );}int Glade2Ui::matchAccelOnActivate( const QDomElement& accel ){    QString key;    QString modifiers;    QDomNode n = accel.firstChild();    while ( !n.isNull() ) {	QString tagName = n.toElement().tagName();	if ( tagName == QString("key") ) {	    key = getTextValue( n );	    if ( !key.startsWith(QString("GDK_")) )		return 0;	} else if ( tagName == QString("modifiers") ) {	    modifiers = getTextValue( n );	} else if ( tagName == QString("signal") ) {	    if ( getTextValue(n) != QString("activate") )		return 0;	}	n = n.nextSibling();    }    int flags = 0;    if ( key.length() == 5 ) {	flags = key[4].upper().latin1();    } else if ( yyKeyMap.contains(key.mid(4)) ) {	flags = yyKeyMap[key.mid(4)];    } else {	return 0;    }    if ( modifiers.contains(QString("_CONTROL_")) )	flags |= Qt::CTRL;    if ( modifiers.contains(QString("_SHIFT_")) )	flags |= Qt::SHIFT;    if ( modifiers.contains(QString("_MOD1_")) )	flags |= Qt::ALT;    return flags;}void Glade2Ui::emitGtkMenu( const QDomElement& menu ){    QRegExp gnomeuiinfoMenuXItem( QString("GNOMEUIINFO_MENU_(.+)_ITEM") );    QDomNode n = menu.firstChild();    while ( !n.isNull() ) {	QString tagName = n.toElement().tagName();	if ( tagName == QString("widget") ) {	    QString activateHandler;	    QString gtkClass;	    QString icon;	    QString label;	    QString name;	    QString stockItem;	    QString tooltip;	    int qtAccel = 0;	    QDomNode child = n.firstChild();	    while ( !child.isNull() ) {		QString childTagName = child.toElement().tagName();		if ( childTagName == QString("accelerator") ) {		    qtAccel = matchAccelOnActivate( child.toElement() );		} else if ( childTagName == QString("class") ) {		    gtkClass = getTextValue( child );		} else if ( childTagName == QString("icon") ) {		    icon = getTextValue( child );		} else if ( childTagName == QString("label") ) {		    label = getTextValue( child );		} else if ( childTagName == QString("name") ) {		    name = getTextValue( child );		} else if ( childTagName == QString("signal") ) {		    QString signalName;		    QString signalHandler;		    QDomNode grandchild = child.firstChild();		    while ( !grandchild.isNull() ) {			QString grandchildTagName =				grandchild.toElement().tagName();			if ( grandchildTagName == QString("handler") ) {			    signalHandler = getTextValue( grandchild );			} else if ( grandchildTagName == QString("name") ) {			    signalName = getTextValue( grandchild );			}			grandchild = grandchild.nextSibling();		    }		    if ( signalName == QString("activate") )			activateHandler = signalHandler;		} else if ( childTagName == QString("stock_item") ) {		    stockItem = getTextValue( child );		} else if ( childTagName == QString("tooltip") ) {		    tooltip = getTextValue( child );		}		child = child.nextSibling();	    }	    if ( label.length() + stockItem.length() == 0 ) {		emitAtom( QString("separator") );	    } else {		if ( name.isEmpty() )		    name = QString( "action%1" ).arg( uniqueAction++ );		emitAtom( QString("action"), attribute(QString("name"), name) );		if ( !activateHandler.isEmpty() ) {		    QString slot = activateHandler + QString( "()" );		    GladeConnection c;		    c.sender = name;		    c.signal = QString( "activated()" );		    c.slot = slot;		    yyConnections.push_back( c );		    yySlots.insert( slot, QString("public") );		}		QString x;		GladeAction a;		if ( gnomeuiinfoMenuXItem.exactMatch(stockItem) ) {		    x = gnomeuiinfoMenuXItem.cap( 1 );		    a.menuText = yyStockMap[x];		    if ( x == QString("EXIT") && qtAccel == 0 )			qtAccel = Qt::CTRL + Qt::Key_Q;		} else {		    a.menuText = accelerate( label );		}		a.text = nonMenuText( a.menuText );		a.toolTip = tooltip;		a.accel = qtAccel;		a.iconSet = icon;		yyActions.insert( name, a );		if ( !x.isEmpty() )		    yyStockItemActions.insert( x, name );	    }	}	n = n.nextSibling();    }}void Glade2Ui::emitGtkMenuBarChildWidgets(	const QValueList<QDomElement>& childWidgets ){    QRegExp gnomeuiinfoMenuXTree( QString("GNOMEUIINFO_MENU_(.+)_TREE") );    emitOpening( QString("menubar") );    emitProperty( QString("name"),		  QString("MenuBar%1").arg(uniqueMenuBar++).latin1() );    QValueList<QDomElement>::ConstIterator c = childWidgets.begin();    while ( c != childWidgets.end() ) {	QValueList<QDomElement> grandchildWidgets;	QString gtkClass;	QString label;	QString name;	QString stockItem;	QDomNode n = (*c).firstChild();	while ( !n.isNull() ) {	    QString tagName = n.toElement().tagName();	    if ( tagName == QString("class") ) {		gtkClass = getTextValue( n );	    } else if ( tagName == QString("label") ) {		label = getTextValue( n );	    } else if ( tagName == QString("name") ) {		name = getTextValue( n );	    } else if ( tagName == QString("stock_item") ) {		stockItem = getTextValue( n );	    } else if ( tagName == QString("widget") ) {		grandchildWidgets.push_back( n.toElement() );	    }	    n = n.nextSibling();	}	if ( gtkClass == QString("GtkMenuItem") &&	     grandchildWidgets.count() == 1 ) {	    QString text;	    if ( gnomeuiinfoMenuXTree.exactMatch(stockItem) ) {		text = gnomeuiinfoMenuXTree.cap( 1 );		if ( text == QString("Files") )		    text = QString( "Fi&les" );		else		    text = QChar( '&' ) + text.left( 1 ) +			   text.mid( 1 ).lower();	    } else {		text = accelerate( label );	    }	    AttributeMap attr;	    attr.insert( QString("name"), name );	    attr.insert( QString("text"), text );	    emitOpening( QString("item"), attr );	    emitGtkMenu( grandchildWidgets.first() );	    emitClosing( QString("item") );	}	++c;    }    emitClosing( QString("menubar") );}void Glade2Ui::emitGtkToolbarChildWidgets(	const QValueList<QDomElement>& childWidgets ){    QRegExp gnomeStockPixmapX( QString("GNOME_STOCK_PIXMAP_(.+)") );    emitOpening( QString("toolbar"), attribute(QString("dock"), QString("2")) );    emitProperty( QString("name"),		  QString("ToolBar%1").arg(uniqueToolBar++).latin1() );    QValueList<QDomElement>::ConstIterator c = childWidgets.begin();    while ( c != childWidgets.end() ) {	QString childName;	QString icon;	QString label;	QString name;	QString stockPixmap;	QString tooltip;	QDomNode n = (*c).firstChild();	while ( !n.isNull() ) {	    QString tagName = n.toElement().tagName();	    if ( tagName == QString("child_name") ) {		childName = getTextValue( n );	    } else if ( tagName == QString("icon") ) {		icon = getTextValue( n );	    } else if ( tagName == QString("label") ) {		label = getTextValue( n );	    } else if ( tagName == QString("name") ) {		name = getTextValue( n );	    } else if ( tagName == QString("stock_pixmap") ) {		stockPixmap = getTextValue( n );	    } else if ( tagName == QString("tooltip") ) {		tooltip = getTextValue( n );	    }	    n = n.nextSibling();	}	if ( childName == QString("Toolbar:button") ) {	    QString actionName;	    GladeAction a;	    a.menuText = label;	    a.text = label;	    a.accel = 0;	    a.iconSet = icon;	    if ( gnomeStockPixmapX.exactMatch(stockPixmap) ) {		QString x = gnomeStockPixmapX.cap( 1 );		actionName = yyStockItemActions[x];	    }	    if ( actionName.isEmpty() ) {		if ( name.isEmpty() )		    actionName = QString( "action%1" ).arg( uniqueAction++ );		else		    actionName = QString( "action_%1" ).arg( name );		yyActions.insert( actionName, a );	    }	    if ( !tooltip.isEmpty() )		yyActions[actionName].toolTip = tooltip;	    emitAtom( QString("action"), attribute(QString("name"),						   actionName) );	} else {	    emitAtom( QString("separator") );	}	++c;    }    emitClosing( QString("toolbar") );}void Glade2Ui::emitPushButton( const QString& text, const QString& name ){    emitOpening( QString("widget"),		 attribute(QString("class"), QString("QPushButton")) );    emitProperty( QString("name"), name.latin1() );    emitProperty( QString("text"), text );    if ( name.contains(QString("ok")) > 0 ) {	emitProperty( QString("default"), QVariant(TRUE, 0) );    } else if ( name.contains(QString("help")) > 0 ) {	emitProperty( QString("accel"), (int) Qt::Key_F1 );    }    emitClosing( QString("widget") );}void Glade2Ui::attach( AttributeMap *attr, int leftAttach, int rightAttach,		       int topAttach, int bottomAttach ){    if ( leftAttach >= 0 ) {	attr->insert( QString("row"), QString::number(topAttach) );	attr->insert( QString("column"), QString::number(leftAttach) );	if ( bottomAttach - topAttach != 1 )	    attr->insert( QString("rowspan"),			 QString::number(bottomAttach - topAttach) );	if ( rightAttach - leftAttach != 1 )	    attr->insert( QString("colspan"),			 QString::number(rightAttach - leftAttach) );    }}void Glade2Ui::emitSpacer( const QString& orientation, int leftAttach,			   int rightAttach, int topAttach, int bottomAttach ){    AttributeMap attr;    attach( &attr, leftAttach, rightAttach, topAttach, bottomAttach );    emitOpening( QString("spacer"), attr );    emitProperty( QString("name"),		  QString("Spacer%1").arg(uniqueSpacer++).latin1() );    emitProperty( QString("orientation"), orientation, QString("enum") );    emitProperty( QString("sizeType"), QString("Expanding"),		  QString("enum") );    emitClosing( QString("spacer") );}void Glade2Ui::emitPixmap( const QString& imageName, int leftAttach,			   int rightAttach, int topAttach, int bottomAttach ){    emitOpeningWidget( QString("QLabel"), leftAttach, rightAttach, topAttach,		       bottomAttach );    emitProperty( QString("sizePolicy"),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -