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

📄 qwerty-main-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
    if ( code &gt;= Codec )        t.<a href="qtextstream.html#db3d00">setCodec</a>( codecList-&gt;at(code-Codec) );    else if ( code == Uni )        t.<a href="qtextstream.html#2c5ab2">setEncoding</a>( QTextStream::Unicode );    else if ( code == MBug )        t.<a href="qtextstream.html#2c5ab2">setEncoding</a>( QTextStream::UnicodeReverse );    else if ( code == Lat1 )        t.<a href="qtextstream.html#2c5ab2">setEncoding</a>( QTextStream::Latin1 );    else if ( code == Guess ) {        <a href="qfile.html">QFile</a> f(fileName);        f.<a href="qfile.html#255995">open</a>(IO_ReadOnly);        char buffer[256];        int l = 256;        l=f.<a href="qfile.html#8c8ccc">readBlock</a>(buffer,l);        <a href="qtextcodec.html">QTextCodec</a>* codec = QTextCodec::codecForContent(buffer, l);        if ( codec ) {            <a href="qmessagebox.html#66b7c8">QMessageBox::information</a>(this,"Encoding",QString("Codec: ")+codec-&gt;<a href="qtextcodec.html#150a9d">name</a>());            t.<a href="qtextstream.html#db3d00">setCodec</a>( codec );        }    }    e-&gt;setText( t.<a href="qtextstream.html#4696a5">read</a>() );    f.<a href="qfile.html#64e640">close</a>();    e-&gt;setAutoUpdate( TRUE );    e-&gt;repaint();    <a href="qwidget.html#d6a291">setCaption</a>( fileName );    changed = FALSE;}void <a name="5"></a>Editor::openAsEncoding( int code ){#ifndef QT_NO_FILEDIALOG    //storing filename (proper save) is left as an exercise...    <a href="qstring.html">QString</a> fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );    if ( !fn.<a href="qstring.html#c62623">isEmpty</a>() )        (void) load( fn, code );#endif}bool <a name="6"></a>Editor::save(){#ifndef QT_NO_FILEDIALOG    //storing filename (proper save) is left as an exercise...    <a href="qstring.html">QString</a> fn = QFileDialog::getSaveFileName( QString::null, QString::null, this );    if ( !fn.<a href="qstring.html#c62623">isEmpty</a>() )        return saveAs( fn );    return FALSE;#endif}void <a name="7"></a>Editor::saveAsEncoding( int code ){#ifndef QT_NO_FILEDIALOG    //storing filename (proper save) is left as an exercise...    <a href="qstring.html">QString</a> fn = QFileDialog::getSaveFileName( QString::null, QString::null, this );    if ( !fn.<a href="qstring.html#c62623">isEmpty</a>() )        (void) saveAs( fn, code );#endif}void <a name="8"></a>Editor::addEncoding(){#ifndef QT_NO_FILEDIALOG        <a href="qstring.html">QString</a> fn = QFileDialog::getOpenFileName( QString::null, "*.map", this );    if ( !fn.<a href="qstring.html#c62623">isEmpty</a>() ) {        <a href="qfile.html">QFile</a> f(fn);        if (f.<a href="qfile.html#255995">open</a>(IO_ReadOnly)) {            if (<a href="qtextcodec.html#f4b1ee">QTextCodec::loadCharmap</a>(&amp;f)) {                <a href=#1>rebuildCodecList</a>();            } else {                <a href="qmessagebox.html#63edba">QMessageBox::warning</a>(0,"Charmap error",                    "The file did not contain a valid charmap.\n\n"                    "A charmap file should look like this:\n"                       "  &lt;code_set_name&gt; thename\n"                       "  &lt;escape_char&gt; /\n"                       "  % alias thealias\n"                       "  CHARMAP\n"                       "  &lt;tokenname&gt; /x12 &lt;U3456&gt;\n"                       "  &lt;tokenname&gt; /xAB/x12 &lt;U0023&gt;\n"                       "  ...\n"                       "  END CHARMAP\n"                );            }        }    }#endif}bool <a name="9"></a>Editor::saveAs( const QString&amp; fileName, int code ){    <a href="qfile.html">QFile</a> f( fileName );    if ( no_writing || !f.<a href="qfile.html#255995">open</a>( IO_WriteOnly ) ) {        <a href="qmessagebox.html#63edba">QMessageBox::warning</a>(this,"I/O Error",                    <a href="qstring.html">QString</a>("The file could not be opened.\n\n")                        +fileName);        return FALSE;    }    <a href="qtextstream.html">QTextStream</a> t(&amp;f);    if ( code &gt;= Codec )        t.<a href="qtextstream.html#db3d00">setCodec</a>( codecList-&gt;at(code-Codec) );    else if ( code == Uni )        t.<a href="qtextstream.html#2c5ab2">setEncoding</a>( QTextStream::Unicode );    else if ( code == MBug )        t.<a href="qtextstream.html#2c5ab2">setEncoding</a>( QTextStream::UnicodeReverse );    else if ( code == Lat1 )        t.<a href="qtextstream.html#2c5ab2">setEncoding</a>( QTextStream::Latin1 );    t &lt;&lt; e-&gt;text();    f.<a href="qfile.html#64e640">close</a>();    <a href="qwidget.html#d6a291">setCaption</a>( fileName );    changed = FALSE;    return TRUE;}void <a name="10"></a>Editor::print(){#ifndef QT_NO_PRINTER    if ( printer.setup(this) ) {                // opens printer dialog        printer.setFullPage(TRUE);              // we'll set our own margins        <a href="qpainter.html">QPainter</a> p;        p.<a href="qpainter.html#02ed5d">begin</a>( &amp;printer );                    // paint on printer        p.<a href="qpainter.html#998df2">setFont</a>( e-&gt;font() );        <a href="qfontmetrics.html">QFontMetrics</a> fm = p.<a href="qpainter.html#73b2e5">fontMetrics</a>();        <a href="qpaintdevicemetrics.html">QPaintDeviceMetrics</a> metrics( &amp;printer ); // need width/height                                                 // of printer surface        const int MARGIN = metrics.<a href="qpaintdevicemetrics.html#a15e9e">logicalDpiX</a>() / 2; // half-inch margin        int yPos        = MARGIN;               // y position for each line        for( int i = 0 ; i &lt; e-&gt;numLines() ; i++ ) {            if ( printer.aborted() )                break;            if ( yPos + fm.<a href="qfontmetrics.html#e6e380">lineSpacing</a>() &gt; metrics.<a href="qpaintdevicemetrics.html#d4fedb">height</a>() - MARGIN ) {                // no more room on this page                if ( !printer.newPage() )          // start new page                    break;                           // some error                yPos = MARGIN;                   // back to top of page            }            p.<a href="qpainter.html#0f088f">drawText</a>( MARGIN, yPos, metrics.<a href="qpaintdevicemetrics.html#95eb7b">width</a>() - 2*MARGIN,                        fm.<a href="qfontmetrics.html#e6e380">lineSpacing</a>(), ExpandTabs, e-&gt;textLine( i ) );            yPos += fm.<a href="qfontmetrics.html#e6e380">lineSpacing</a>();        }        p.<a href="qpainter.html#365784">end</a>();                                // send job to printer    }#endif}void <a name="11"></a>Editor::resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> * ){    if ( e &amp;&amp; m )        e-&gt;setGeometry( 0, m-&gt;height(), <a href="qwidget.html#2edab1">width</a>(), <a href="qwidget.html#e3c588">height</a>() - m-&gt;height() );}void <a name="12"></a>Editor::closeEvent( <a href="qcloseevent.html">QCloseEvent</a> *event ){    event-&gt;<a href="qcloseevent.html#7cf66f">accept</a>();    if ( changed ) { // the text has been changed        switch ( <a href="qmessagebox.html#63edba">QMessageBox::warning</a>( this, "Qwerty",                                        "Save changes to Document?",                                        <a href="qobject.html#2418a9">tr</a>("&amp;Yes"),                                        <a href="qobject.html#2418a9">tr</a>("&amp;No"),                                        <a href="qobject.html#2418a9">tr</a>("Cancel"),                                        0, 2) ) {        case 0: // yes            if ( save() )                event-&gt;<a href="qcloseevent.html#7cf66f">accept</a>();            else                event-&gt;<a href="qcloseevent.html#ee1736">ignore</a>();            break;        case 1: // no            event-&gt;<a href="qcloseevent.html#7cf66f">accept</a>();            break;        default: // cancel            event-&gt;<a href="qcloseevent.html#ee1736">ignore</a>();            break;        }    }}void <a name="13"></a>Editor::toUpper(){    e-&gt;setText(e-&gt;text().upper());}void <a name="14"></a>Editor::toLower(){    e-&gt;setText(e-&gt;text().lower());}void <a name="15"></a>Editor::textChanged(){    changed = TRUE;}</pre>  <hr>  Main:<pre>/****************************************************************************** &#36;Id&#58; qt/examples/qwerty/main.cpp   2.3.8   edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of an example program for Qt.  This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include &lt;<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>&gt;#include "qwerty.h"int main( int argc, char **argv ){    <a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv );    bool small =  qApp-&gt;desktop()-&gt;size().width() &lt; 450                   || qApp-&gt;desktop()-&gt;size().height() &lt; 450;    int i;    for ( i= argc &lt;= 1 ? 0 : 1; i&lt;argc; i++ ) {        Editor *e = new Editor;        e-&gt;<a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>("Qt Example - QWERTY");        if ( i &gt; 0 )            e-&gt;load( argv[i] );        if ( small ) {            e-&gt;<a name="showMaximized"></a><a href="qwidget.html#b6e000">showMaximized</a>();        } else {            e-&gt;<a name="resize"></a><a href="qwidget.html#8fcbbe">resize</a>( 400, 400 );            e-&gt;<a name="show"></a><a href="qwidget.html#200ee5">show</a>();        }    }    a.<a name="connect"></a><a href="qobject.html#fbde73">connect</a>( &amp;a, SIGNAL(lastWindowClosed()), &amp;a, SLOT(quit()) );    return a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();}</pre><p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright 

⌨️ 快捷键说明

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