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

📄 showimg-main-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - showimg/main.cpp example file</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }--></style></head><body bgcolor="#ffffff"><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b>  <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align=center>Show Image</h1><br clear="all">  This example reads and displays an image in any supported image  format (GIF, BMP, PPM, XMP etc.)  <hr>  Header file: <pre>/****************************************************************************** &#36;Id&#58; qt/examples/showimg/showimg.h   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.*******************************************************************************/#ifndef SHOWIMG_H#define SHOWIMG_H#include &lt;<a href="qwidget-h.html">qwidget.h</a>&gt;#include &lt;<a href="qimage-h.html">qimage.h</a>&gt;class QLabel;class QMenuBar;class QPopupMenu;class ImageViewer : public QWidget{    Q_OBJECTpublic:    ImageViewer( <a href="qwidget.html">QWidget</a> *parent=0, const char *name=0, int wFlags=0 );    ~ImageViewer();    bool        loadImage( const char *fileName );protected:    void        paintEvent( <a href="qpaintevent.html">QPaintEvent</a> * );    void        resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> * );    void        mousePressEvent( <a href="qmouseevent.html">QMouseEvent</a> * );    void        mouseReleaseEvent( <a href="qmouseevent.html">QMouseEvent</a> * );    void        mouseMoveEvent( <a href="qmouseevent.html">QMouseEvent</a> * );private:    void        scale();    int         conversion_flags;    bool        smooth() const;    bool        unscaled() const;    bool        useColorContext() const;    int         alloc_context;    bool        convertEvent( <a href="qmouseevent.html">QMouseEvent</a>* e, int&amp; x, int&amp; y );    const char* filename;    <a href="qimage.html">QImage</a>      image;                  // the loaded image    <a href="qpixmap.html">QPixmap</a>     pm;                     // the converted pixmap    <a href="qpixmap.html">QPixmap</a>     pmScaled;               // the scaled pixmap    <a href="qmenubar.html">QMenuBar</a>   *menubar;    <a href="qpopupmenu.html">QPopupMenu</a>  *file;    <a href="qpopupmenu.html">QPopupMenu</a>   *saveimage;    <a href="qpopupmenu.html">QPopupMenu</a>   *savepixmap;    <a href="qpopupmenu.html">QPopupMenu</a>  *edit;    <a href="qpopupmenu.html">QPopupMenu</a>  *options;    <a href="qwidget.html">QWidget</a>    *helpmsg;    <a href="qlabel.html">QLabel</a>     *status;    int         si, sp, ac, co, mo, fd, bd, // Menu item ids                td, ta, ba, fa, au, ad, dd,                ns, us, ss, cc, t1, t8, t32;    void        updateStatus();    void        setMenuItemFlags();    bool        reconvertImage();    int         pickx, picky;    int         clickx, clicky;    bool        may_be_other;    static ImageViewer* other;    void        setImage(const QImage&amp; newimage);private slots:    void        to1Bit();    void        to8Bit();    void        to32Bit();    void        toBitDepth(int);    void        copy();    void        paste();    void        hFlip();    void        vFlip();    void        rot180();    void        editText();    void        newWindow();    void        openFile();    void        saveImage(int);    void        savePixmap(int);    void        giveHelp();    void        doOption(int);    void        copyFrom(ImageViewer*);};#endif // SHOWIMG_H</pre>  <hr>  Implementation: <pre>/****************************************************************************** &#36;Id&#58; qt/examples/showimg/showimg.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 "showimg.h"#include "imagetexteditor.h"#include &lt;<a href="qmenubar-h.html">qmenubar.h</a>&gt;#include &lt;<a href="qfiledialog-h.html">qfiledialog.h</a>&gt;#include &lt;<a href="qmessagebox-h.html">qmessagebox.h</a>&gt;#include &lt;<a href="qpopupmenu-h.html">qpopupmenu.h</a>&gt;#include &lt;<a href="qlabel-h.html">qlabel.h</a>&gt;#include &lt;<a href="qpainter-h.html">qpainter.h</a>&gt;#include &lt;qkeycode.h&gt;#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;#include &lt;<a href="qclipboard-h.html">qclipboard.h</a>&gt;/*  In the constructor, we just pass the standard parameters on to  <a href="qwidget.html">QWidget</a>.  The menu uses a single slot to simplify the process of adding  more items to the options menu.*/ImageViewer::ImageViewer( <a href="qwidget.html">QWidget</a> *parent, const char *name, int wFlags )    : <a href="qwidget.html">QWidget</a>( parent, name, wFlags ),      conversion_flags( PreferDither ),      filename( 0 ),      helpmsg( 0 ){    pickx = -1;    picky = -1;    clickx = -1;    clicky = -1;    alloc_context = 0;    menubar = new <a href="qmenubar.html">QMenuBar</a>(this);    menubar-&gt;setSeparator( QMenuBar::InWindowsStyle );    <a href="qstrlist.html">QStrList</a> fmt = QImage::outputFormats();    saveimage = new <a href="qpopupmenu.html">QPopupMenu</a>();    savepixmap = new <a href="qpopupmenu.html">QPopupMenu</a>();    for (const char* f = fmt.<a href="qlist.html#e625f9">first</a>(); f; f = fmt.<a href="qlist.html#f95ddd">next</a>()) {        saveimage-&gt;insertItem( f );        savepixmap-&gt;insertItem( f );    }    <a href="qobject.html#fbde73">connect</a>( saveimage, SIGNAL(activated(int)), this, SLOT(<a href=#372>saveImage</a>(int)) );    <a href="qobject.html#fbde73">connect</a>( savepixmap, SIGNAL(activated(int)), this, SLOT(<a href=#373>savePixmap</a>(int)) );    file = new <a href="qpopupmenu.html">QPopupMenu</a>();    menubar-&gt;insertItem( "&amp;File", file );    file-&gt;insertItem( "&amp;New window", this,  SLOT(<a href=#374>newWindow</a>()), CTRL+Key_N );    file-&gt;insertItem( "&amp;Open...", this,  SLOT(<a href=#375>openFile</a>()), CTRL+Key_O );    si = file-&gt;insertItem( "Save image", saveimage );    sp = file-&gt;insertItem( "Save pixmap", savepixmap );    file-&gt;insertSeparator();    file-&gt;insertItem( "E&amp;xit", qApp,  SLOT(quit()), CTRL+Key_Q );    edit =  new <a href="qpopupmenu.html">QPopupMenu</a>();    menubar-&gt;insertItem( "&amp;Edit", edit );    edit-&gt;insertItem("&amp;Copy", this, SLOT(<a href=#394>copy</a>()), CTRL+Key_C);    edit-&gt;insertItem("&amp;Paste", this, SLOT(<a href=#395>paste</a>()), CTRL+Key_V);    edit-&gt;insertSeparator();    edit-&gt;insertItem("&amp;Horizontal flip", this, SLOT(<a href=#391>hFlip</a>()), ALT+Key_H);    edit-&gt;insertItem("&amp;Vertical flip", this, SLOT(<a href=#392>vFlip</a>()), ALT+Key_V);    edit-&gt;insertItem("&amp;Rotate 180", this, SLOT(<a href=#393>rot180</a>()), ALT+Key_R);    edit-&gt;insertSeparator();    edit-&gt;insertItem("&amp;Text...", this, SLOT(<a href=#397>editText</a>()));    edit-&gt;insertSeparator();    t1 = edit-&gt;insertItem( "Convert to &amp;1 bit", this, SLOT(<a href=#398>to1Bit</a>()) );    t8 = edit-&gt;insertItem( "Convert to &amp;8 bit", this, SLOT(<a href=#399>to8Bit</a>()) );    t32 = edit-&gt;insertItem( "Convert to &amp;32 bit", this, SLOT(<a href=#400>to32Bit</a>()) );    options =  new <a href="qpopupmenu.html">QPopupMenu</a>();    menubar-&gt;insertItem( "&amp;Options", options );    ac = options-&gt;insertItem( "AutoColor" );    co = options-&gt;insertItem( "ColorOnly" );    mo = options-&gt;insertItem( "MonoOnly" );    options-&gt;insertSeparator();    fd = options-&gt;insertItem( "DiffuseDither" );    bd = options-&gt;insertItem( "OrderedDither" );    td = options-&gt;insertItem( "ThresholdDither" );    options-&gt;insertSeparator();    ta = options-&gt;insertItem( "ThresholdAlphaDither" );    ba = options-&gt;insertItem( "OrderedAlphaDither" );    fa = options-&gt;insertItem( "DiffuseAlphaDither" );    options-&gt;insertSeparator();    ad = options-&gt;insertItem( "PreferDither" );    dd = options-&gt;insertItem( "AvoidDither" );    options-&gt;insertSeparator();    ns = options-&gt;insertItem( "No scaling" );    us = options-&gt;insertItem( "Normal scaling" );    ss = options-&gt;insertItem( "Smooth scaling" );    options-&gt;insertSeparator();    cc = options-&gt;insertItem( "Use color context" );    if ( <a href="qapplication.html#fdf8ca">QApplication::colorSpec</a>() == QApplication::ManyColor )        options-&gt;setItemEnabled( cc, FALSE );    options-&gt;setCheckable( TRUE );    <a href=#370>setMenuItemFlags</a>();    menubar-&gt;insertSeparator();    <a href="qpopupmenu.html">QPopupMenu</a>* help = new <a href="qpopupmenu.html">QPopupMenu</a>();    menubar-&gt;insertItem( "&amp;Help", help );    help-&gt;<a href="qmenudata.html#deddb9">insertItem</a>( "Help!", this, SLOT(<a href=#388>giveHelp</a>()), CTRL+Key_H );    <a href="qobject.html#fbde73">connect</a>( options, SIGNAL(activated(int)), this, SLOT(<a href=#369>doOption</a>(int)) );    status = new <a href="qlabel.html">QLabel</a>(this);    status-&gt;setFrameStyle( QFrame::WinPanel | QFrame::Sunken );    status-&gt;setFixedHeight( <a href="qwidget.html#386569">fontMetrics</a>().height() + 4 );    <a href="qwidget.html#36406c">setMouseTracking</a>( TRUE );}ImageViewer::~ImageViewer(){    if ( alloc_context )        <a href="qcolor.html#cc0257">QColor::destroyAllocContext</a>( alloc_context );    if ( other == this )        other = 0;}/*  This function modifies the conversion_flags when an options menu item  is selected, then ensures all menu items are up to date, and reconverts  the image if possibly necessary.*/void <a name="369"></a>ImageViewer::doOption(int item){    if ( item == cc ) {        // Toggle        bool newbool = !options-&gt;isItemChecked(item);        options-&gt;setItemChecked(item, newbool);        // And reconvert...        <a href=#377>reconvertImage</a>();        <a href="qwidget.html#7569b1">repaint</a>(image.hasAlphaBuffer());        // show image in widget        return;    }    if ( options-&gt;isItemChecked( item ) ) return; // They are all radio buttons    if ( item == ns || item == us || item == ss ) {        options-&gt;setItemChecked( ns, item == ns );        options-&gt;setItemChecked( us, item == us );        options-&gt;setItemChecked( ss, item == ss );        <a href=#377>reconvertImage</a>();        <a href="qwidget.html#7569b1">repaint</a>(image.hasAlphaBuffer() || unscaled() ); // show image in widget        return;    }    int ocf = conversion_flags;    if ( item == ac ) {        conversion_flags = conversion_flags &amp; ~ColorMode_Mask | AutoColor;    } else if ( item == co ) {        conversion_flags = conversion_flags &amp; ~ColorMode_Mask | ColorOnly;    } else if ( item == mo ) {        conversion_flags = conversion_flags &amp; ~ColorMode_Mask | MonoOnly;

⌨️ 快捷键说明

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