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

📄 glade2ui.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/************************************************************************** Converts a Glade .glade file into a .ui file.**** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.**** This file is part of Qt Designer.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "glade2ui.h"#include <qapplication.h>#include <qfile.h>#include <qimage.h>#include <qprogressdialog.h>#include <qmessagebox.h>#include <qrect.h>#include <qregexp.h>#include <qsizepolicy.h>#include <ctype.h>static const struct {    const char *gtkName;    const char *qtName;} classNames[] = {    { "Custom", "Custom" },    { "GnomeAbout", "QDialog" },    { "GnomeApp", "QMainWindow" },    { "GnomeCanvas", "QLabel" },    { "GnomeColorPicker", "QComboBox" },    { "GnomeDateEdit", "QDateTimeEdit" },    { "GnomeDialog", "QDialog" },    { "GnomeFontPicker", "QComboBox" },    { "GnomeIconSelection", "QIconView" },    { "GnomePixmap", "QLabel" },    { "GnomePropertyBox", "QDialog" },    { "GtkAccelLabel", "QLabel" },    { "GtkAspectFrame", "QFrame" },    { "GtkButton", "QPushButton" },    { "GtkCList", "QListView" },    { "GtkCTree", "QListView" },    { "GtkCheckButton", "QCheckBox" },    { "GtkCombo", "QComboBox" },    { "GtkDial", "QDial" },    { "GtkDialog", "QDialog" },    { "GtkEntry", "QLineEdit" },    { "GtkFixed", "QLayoutWidget" },    { "GtkFrame", "QFrame" },    { "GtkHPaned", "QSplitter" },    { "GtkHScale", "QSlider" },    { "GtkHScrollbar", "QScrollBar" },    { "GtkHSeparator", "Line" },    { "GtkHandleBox", "QFrame" },    { "GtkImage", "QLabel" },    { "GtkLabel", "QLabel" },    { "GtkList", "QListBox" },    { "GtkNotebook", "QTabWidget" },    { "GtkOptionMenu", "QComboBox" },    { "GtkPixmap", "QLabel" },    { "GtkPreview", "QLabel" },    { "GtkProgressBar", "QProgressBar" },    { "GtkRadioButton", "QRadioButton" },    { "GtkSpinButton", "QSpinBox" },    { "GtkStatusbar", "QStatusBar" },    { "GtkText", "QTextEdit" },    { "GtkToggleButton", "QPushButton" },    { "GtkTree", "QListView" },    { "GtkVPaned", "QSplitter" },    { "GtkVScale", "QSlider" },    { "GtkVScrollbar", "QScrollBar" },    { "GtkVSeparator", "Line" },    { "Placeholder", "QLabel" },    { 0, 0 }};static const struct {    const char *name;    const char *menuText;} stockMenuItems[] = {    { "ABOUT", "&About" },    { "CLEAR", "C&lear" },    { "CLOSE", "&Close" },    { "CLOSE_WINDOW", "&Close This Window" },    { "COPY", "&Copy" },    { "CUT", "C&ut" },    { "END_GAME", "&End Game" },    { "EXIT", "E&xit" },    { "FIND", "&Find..." },    { "FIND_AGAIN", "Find &Again" },    { "HINT", "&Hint" },    { "NEW", "&New" },    { "NEW_GAME", "&New Game" },    { "NEW_WINDOW", "Create New &Window" },    { "OPEN", "&Open..." },    { "PASTE", "&Paste" },    { "PAUSE_GAME", "&Pause Game" },    { "PREFERENCES", "&Preferences..." },    { "PRINT", "&Print" },    { "PRINT_SETUP", "Print S&etup..." },    { "PROPERTIES", "&Properties..." },    { "REDO", "&Redo" },    { "REDO_MOVE", "&Redo Move" },    { "REPLACE", "&Replace..." },    { "RESTART_GAME", "&Restart Game" },    { "REVERT", "&Revert" },    { "SAVE", "&Save" },    { "SAVE_AS", "Save &As..." },    { "SCORES", "&Scores..." },    { "SELECT_ALL", "&Select All" },    { "UNDO", "&Undo" },    { "UNDO_MOVE", "&Undo Move" },    { 0, 0 }};static const struct {    const char *gtkName;    int qtValue;} keys[] = {    { "BackSpace", Qt::Key_BackSpace },    { "Delete", Qt::Key_Delete },    { "Down", Qt::Key_Down },    { "End", Qt::Key_End },    { "Escape", Qt::Key_Escape },    { "F1", Qt::Key_F1 },    { "F10", Qt::Key_F10 },    { "F11", Qt::Key_F11 },    { "F12", Qt::Key_F12 },    { "F2", Qt::Key_F2 },    { "F3", Qt::Key_F3 },    { "F4", Qt::Key_F4 },    { "F5", Qt::Key_F5 },    { "F6", Qt::Key_F6 },    { "F7", Qt::Key_F7 },    { "F8", Qt::Key_F8 },    { "F9", Qt::Key_F9 },    { "Home", Qt::Key_Home },    { "Insert", Qt::Key_Insert },    { "KP_Enter", Qt::Key_Enter },    { "Left", Qt::Key_Left },    { "Page_Down", Qt::Key_PageDown },    { "Page_Up", Qt::Key_PageUp },    { "Return", Qt::Key_Return },    { "Right", Qt::Key_Right },    { "Tab", Qt::Key_Tab },    { "Up", Qt::Key_Up },    { "space", Qt::Key_Space },    { 0, 0 }};static QString nonMenuText( const QString& menuText ){    QString t;    int len = (int) menuText.length();    if ( menuText.endsWith(QString("...")) )	len -= 3;    for ( int i = 0; i < len; i++ ) {	if ( menuText[i] != QChar('&') )	    t += menuText[i];    }    return t;}/*  Some GTK dialog use hyphens in variable names. Let's take no chance.*/static QString fixedName( const QString& name ){    const char *latin1 = name.latin1();    QString fixed;    int i = 0;    while ( latin1 != 0 && latin1[i] != '\0' ) {	if ( isalnum(latin1[i]) )	    fixed += name[i];	else	    fixed += QChar( '_' );	i++;    }    return fixed;}/*  Returns an hexadecimal rendering of a block of memory.*/static QString hexed( const char *data, int length ){    QString t;    for ( int i = 0; i < length; i++ ) {	QString x;	x.sprintf( "%.2x", (uchar) data[i] );	t += x;    }    return t;}static bool isTrue( const QString& val ){    return val.lower() == QString( "true" );}static AttributeMap attribute( const QString& name, const QString& val ){    AttributeMap attr;    attr.insert( name, val );    return attr;}static QString entitize( const QString& str ){    QString t = str;    t.replace( '&', QString("&amp;") );    t.replace( '>', QString("&gt;") );    t.replace( '<', QString("&lt;") );    t.replace( '"', QString("&quot;") );    t.replace( '\'', QString("&apos;") );    return t;}Glade2Ui::Glade2Ui(){    int i = 0;    while ( classNames[i].gtkName != 0 ) {	yyClassNameMap.insert( QString(classNames[i].gtkName),			       QString(classNames[i].qtName) );	i++;    }    i = 0;    while ( stockMenuItems[i].name != 0 ) {	yyStockMap.insert( QString(stockMenuItems[i].name),			   QString(stockMenuItems[i].menuText) );	i++;    }    i = 0;    while ( keys[i].gtkName != 0 ) {	yyKeyMap.insert( QString(keys[i].gtkName), keys[i].qtValue );	i++;    }}QString Glade2Ui::imageName( const QString& fileName ){    return *yyImages.insert( fileName, QString("image%1").arg(yyImages.count()),			     FALSE );}QString Glade2Ui::opening( const QString& tag, const AttributeMap& attr ){    QString t = QChar( '<' ) + tag;    AttributeMap::ConstIterator a = attr.begin();    while ( a != attr.end() ) {	t += QChar( ' ' ) + a.key() + QString( "=\"" ) + entitize( *a ) +	     QChar( '"' );	++a;    }    t += QChar( '>' );    return t;}QString Glade2Ui::closing( const QString& tag ){    return opening( QChar('/') + tag );}QString Glade2Ui::atom( const QString& tag, const AttributeMap& attr ){    QString t = opening( tag, attr );    t.insert( t.length() - 1, QChar('/') );    return t;}void Glade2Ui::error( const QString& message ){    if ( numErrors++ == 0 )	QMessageBox::warning( 0, yyFileName, message );}void Glade2Ui::syntaxError(){    error( QString("Sorry, I met a random syntax error. I did what I could, but"		   " that was not enough."		   "<p>You might want to write to"		   " <tt>qt-bugs@trolltech.com</tt> about this incident.") );}QString Glade2Ui::getTextValue( const QDomNode& node ){    if ( node.childNodes().count() > 1 ) {	syntaxError();	return QString::null;    }    if ( node.childNodes().count() == 0 )	return QString::null;    QDomText t = node.firstChild().toText();    if ( t.isNull() ) {	syntaxError();	return QString::null;    }    return t.data().stripWhiteSpace();}void Glade2Ui::emitHeader(){    yyOut += QString( "<!DOCTYPE UI><UI version=\"3.0\" stdsetdef=\"1\">\n" );}void Glade2Ui::emitFooter(){    yyOut += QString( "</UI>\n" );}void Glade2Ui::emitSimpleValue( const QString& tag, const QString& value,				const AttributeMap& attr ){    yyOut += yyIndentStr + opening( tag, attr ) + entitize( value ) +	     closing( tag ) + QChar( '\n' );}void Glade2Ui::emitOpening( const QString& tag, const AttributeMap& attr ){    yyOut += yyIndentStr + opening( tag, attr ) + QChar( '\n' );    yyIndentStr += QString( "    " );}void Glade2Ui::emitClosing( const QString& tag ){    yyIndentStr.truncate( yyIndentStr.length() - 4 );    yyOut += yyIndentStr + closing( tag ) + QChar( '\n' );}void Glade2Ui::emitAtom( const QString& tag, const AttributeMap& attr ){    yyOut += yyIndentStr + atom( tag, attr ) + QChar( '\n' );}void Glade2Ui::emitVariant( const QVariant& val, const QString& stringType ){    if ( val.isValid() ) {	switch ( val.type() ) {	case QVariant::String:	    emitSimpleValue( stringType, val.toString() );	    break;	case QVariant::CString:	    emitSimpleValue( QString("cstring"), val.toString() );	    break;	case QVariant::Bool:	    emitSimpleValue( QString("bool"),			     QString(val.toBool() ? "true" : "false") );	    break;	case QVariant::Int:	case QVariant::UInt:	    emitSimpleValue( QString("number"), val.toString() );	    break;	case QVariant::Rect:	    emitOpening( QString("rect") );	    emitSimpleValue( QString("x"), QString::number(val.toRect().x()) );	    emitSimpleValue( QString("y"), QString::number(val.toRect().y()) );	    emitSimpleValue( QString("width"),			     QString::number(val.toRect().width()) );	    emitSimpleValue( QString("height"),			     QString::number(val.toRect().height()) );	    emitClosing( QString("rect") );	    break;	case QVariant::Size:	    emitOpening( QString("size") );	    emitSimpleValue( QString("width"),			     QString::number(val.toSize().width()) );	    emitSimpleValue( QString("height"),			     QString::number(val.toSize().height()) );	    emitClosing( QString("size") );	    break;	case QVariant::SizePolicy:	    emitOpening( QString("sizepolicy") );	    emitSimpleValue( QString("hsizetype"),			     QString::number((int) val.toSizePolicy()						      .horData()) );	    emitSimpleValue( QString("vsizetype"),			     QString::number((int) val.toSizePolicy()						      .verData()) );	    emitClosing( QString("sizepolicy") );	    break;	default:	    emitSimpleValue( QString("fnord"), QString::null );	}    }}void Glade2Ui::emitProperty( const QString& prop, const QVariant& val,			     const QString& stringType ){    emitOpening( QString("property"), attribute(QString("name"), prop) );    emitVariant( val, stringType );    emitClosing( QString("property") );}void Glade2Ui::emitFontProperty( const QString& prop, int pointSize, bool bold ){    emitOpening( QString("property"), attribute(QString("name"), prop) );    emitOpening( QString("font") );    emitSimpleValue( QString("pointsize"), QString::number(pointSize) );    if ( bold )	emitSimpleValue( QString("bold"), QString("1") );    emitClosing( QString("font") );    emitClosing( QString("property") );}void Glade2Ui::emitAttribute( const QString& prop, const QVariant& val,			      const QString& stringType ){    emitOpening( QString("attribute"), attribute(QString("name"), prop) );    emitVariant( val, stringType );    emitClosing( QString("attribute") );}static QString accelerate( const QString& gtkLabel ){    QString qtLabel = gtkLabel;

⌨️ 快捷键说明

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