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

📄 showimg-main-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
📖 第 1 页 / 共 3 页
字号:
    } else if ( item == fd ) {        conversion_flags = conversion_flags &amp; ~Dither_Mask | DiffuseDither;    } else if ( item == bd ) {        conversion_flags = conversion_flags &amp; ~Dither_Mask | OrderedDither;    } else if ( item == td ) {        conversion_flags = conversion_flags &amp; ~Dither_Mask | ThresholdDither;    } else if ( item == ta ) {        conversion_flags = conversion_flags &amp; ~AlphaDither_Mask | ThresholdAlphaDither;    } else if ( item == fa ) {        conversion_flags = conversion_flags &amp; ~AlphaDither_Mask | DiffuseAlphaDither;    } else if ( item == ba ) {        conversion_flags = conversion_flags &amp; ~AlphaDither_Mask | OrderedAlphaDither;    } else if ( item == ad ) {        conversion_flags = conversion_flags &amp; ~DitherMode_Mask | PreferDither;    } else if ( item == dd ) {        conversion_flags = conversion_flags &amp; ~DitherMode_Mask | AvoidDither;    }    if ( ocf != conversion_flags ) {        <a href=#370>setMenuItemFlags</a>();        // And reconvert...        <a href=#377>reconvertImage</a>();        <a href="qwidget.html#7569b1">repaint</a>(image.hasAlphaBuffer());        // show image in widget    }}/*  Set the options menu to reflect the conversion_flags value.*/void <a name="370"></a>ImageViewer::setMenuItemFlags(){    // File    bool valid_image = pm.size() != QSize( 0, 0 );    file-&gt;setItemEnabled( si, valid_image );    file-&gt;setItemEnabled( sp, valid_image );    // Edit    edit-&gt;setItemEnabled( t1, image.depth() != 1 );    edit-&gt;setItemEnabled( t8, image.depth() != 8 );    edit-&gt;setItemEnabled( t32, image.depth() != 32 );    // Options    bool may_need_color_dithering =            !valid_image        || image.depth() == 32 &amp;&amp; <a href="qpixmap.html#e194ad">QPixmap::defaultDepth</a>() &lt; 24;    bool may_need_dithering = may_need_color_dithering         || image.depth() &gt; 1 &amp;&amp; options-&gt;isItemChecked(mo)         || image.depth() &gt; 1 &amp;&amp; <a href="qpixmap.html#e194ad">QPixmap::defaultDepth</a>() == 1;    bool has_alpha_mask = !valid_image || image.hasAlphaBuffer();    options-&gt;setItemEnabled( fd, may_need_dithering );    options-&gt;setItemEnabled( bd, may_need_dithering );    options-&gt;setItemEnabled( td, may_need_dithering );    options-&gt;setItemEnabled( ta, has_alpha_mask );    options-&gt;setItemEnabled( fa, has_alpha_mask );    options-&gt;setItemEnabled( ba, has_alpha_mask );    options-&gt;setItemEnabled( ad, may_need_color_dithering );    options-&gt;setItemEnabled( dd, may_need_color_dithering );    options-&gt;setItemChecked( ac, (conversion_flags &amp; ColorMode_Mask) == AutoColor );    options-&gt;setItemChecked( co, (conversion_flags &amp; ColorMode_Mask) == ColorOnly );    options-&gt;setItemChecked( mo, (conversion_flags &amp; ColorMode_Mask) == MonoOnly );    options-&gt;setItemChecked( fd, (conversion_flags &amp; Dither_Mask) == DiffuseDither );    options-&gt;setItemChecked( bd, (conversion_flags &amp; Dither_Mask) == OrderedDither );    options-&gt;setItemChecked( td, (conversion_flags &amp; Dither_Mask) == ThresholdDither );    options-&gt;setItemChecked( ta, (conversion_flags &amp; AlphaDither_Mask) == ThresholdAlphaDither );    options-&gt;setItemChecked( fa, (conversion_flags &amp; AlphaDither_Mask) == DiffuseAlphaDither );    options-&gt;setItemChecked( ba, (conversion_flags &amp; AlphaDither_Mask) == OrderedAlphaDither );    options-&gt;setItemChecked( ad, (conversion_flags &amp; DitherMode_Mask) == PreferDither );    options-&gt;setItemChecked( dd, (conversion_flags &amp; DitherMode_Mask) == AvoidDither );}void <a name="371"></a>ImageViewer::updateStatus(){    if ( pm.size() == QSize( 0, 0 ) ) {        if ( filename )            status-&gt;setText("Could not load image");        else            status-&gt;setText("No image - select Open from File menu.");    } else {        <a href="qstring.html">QString</a> message, moremsg;        message.<a href="qstring.html#926f67">sprintf</a>("%dx%d", image.width(), image.height());        if ( pm.size() != pmScaled.size() ) {            moremsg.sprintf(" [%dx%d]", pmScaled.width(),                pmScaled.height());            message += moremsg;        }        moremsg.sprintf(", %d bits ", image.depth());        message += moremsg;        if (image.valid(pickx,picky)) {            moremsg.sprintf("(%d,%d)=#%0*x ",                          pickx, picky,                          image.hasAlphaBuffer() ? 8 : 6,                          image.pixel(pickx,picky));            message += moremsg;        }        if ( image.numColors() &gt; 0 ) {            if (image.valid(pickx,picky)) {                moremsg.sprintf(", %d/%d colors", image.pixelIndex(pickx,picky),                    image.numColors());            } else {                moremsg.sprintf(", %d colors", image.numColors());            }            message += moremsg;        }        if ( image.hasAlphaBuffer() ) {            if ( image.depth() == 8 ) {                int i;                bool alpha[256];                int nalpha=0;                for (i=0; i&lt;256; i++)                    alpha[i] = FALSE;                for (i=0; i&lt;image.numColors(); i++) {                    int alevel = image.color(i) &gt;&gt; 24;                    if (!alpha[alevel]) {                        alpha[alevel] = TRUE;                        nalpha++;                    }                }                moremsg.sprintf(", %d alpha levels", nalpha);            } else {                // Too many pixels to bother counting.                moremsg = ", 8-bit alpha channel";            }            message += moremsg;        }        status-&gt;setText(message);    }}/*  This function saves the image.*/void <a name="372"></a>ImageViewer::saveImage( int item ){    const char* fmt = saveimage-&gt;text(item);    <a href="qstring.html">QString</a> savefilename = QFileDialog::getSaveFileName(QString::null, QString::null,                                        this, filename);    if ( !savefilename.<a href="qstring.html#c62623">isEmpty</a>() )        if ( !image.save( savefilename, fmt ) )            <a href="qmessagebox.html#63edba">QMessageBox::warning</a>( this, "Save failed", "Error saving file" );}/*  This function saves the converted image.*/void <a name="373"></a>ImageViewer::savePixmap( int item ){    const char* fmt = savepixmap-&gt;text(item);    <a href="qstring.html">QString</a> savefilename = QFileDialog::getSaveFileName(QString::null,                                        QString::null, this, filename);    if ( !savefilename.<a href="qstring.html#c62623">isEmpty</a>() )        if ( !pmScaled.save( savefilename, fmt ) )            <a href="qmessagebox.html#63edba">QMessageBox::warning</a>( this, "Save failed", "Error saving file" );}void <a name="374"></a>ImageViewer::newWindow(){    ImageViewer* that = new ImageViewer(0, "new window", WDestructiveClose);    that-&gt;options-&gt;setItemChecked( that-&gt;cc, <a href=#380>useColorContext</a>() );    that-&gt;<a href="qwidget.html#200ee5">show</a>();}/*  This function is the slot for processing the Open menu item.*/void <a name="375"></a>ImageViewer::openFile(){    <a href="qstring.html">QString</a> newfilename = QFileDialog::getOpenFileName();    if ( !newfilename.<a href="qstring.html#c62623">isEmpty</a>() ) {        <a href=#376>loadImage</a>( newfilename ) ;        <a href="qwidget.html#7569b1">repaint</a>();                      // show image in widget    }}/*  This function loads an image from a file and resizes the widget to  exactly fit the image size. If the file was not found or the image  format was unknown it will resize the widget to fit the errorText  message (see above) displayed in the current font.  Returns TRUE if the image was successfully loaded.*/bool <a name="376"></a>ImageViewer::loadImage( const char *fileName ){    filename = fileName;    bool ok = FALSE;    if ( filename ) {        <a href="qapplication.html#07e1f1">QApplication::setOverrideCursor</a>( waitCursor ); // this might take time        ok = image.load(filename, 0);        pickx = -1;        clickx = -1;        if ( ok )            ok = reconvertImage();        if ( ok ) {            <a href="qwidget.html#d6a291">setCaption</a>( filename );                     // set window caption            int w = pm.width();            int h = pm.height();            const int reasonable_width = 128;            if ( w &lt; reasonable_width ) {                // Integer scale up to something reasonable                int multiply = ( reasonable_width + w - 1 ) / w;                w *= multiply;                h *= multiply;            }            h += menubar-&gt;heightForWidth(w) + status-&gt;height();            <a href="qwidget.html#8fcbbe">resize</a>( w, h );                             // we resize to fit image        } else {            pm.resize(0,0);                             // couldn't load image            <a href="qwidget.html#a66a88">update</a>();        }        <a href="qapplication.html#655095">QApplication::restoreOverrideCursor</a>();  // restore original cursor    }    <a href=#371>updateStatus</a>();    <a href=#370>setMenuItemFlags</a>();    return ok;}bool <a name="377"></a>ImageViewer::reconvertImage(){    bool success = FALSE;    if ( image.isNull() ) return FALSE;    if ( alloc_context ) {        <a href="qcolor.html#cc0257">QColor::destroyAllocContext</a>( alloc_context );        alloc_context = 0;    }    if ( useColorContext() ) {        alloc_context = QColor::enterAllocContext();        // Clear the image to hide flickering palette        <a href="qpainter.html">QPainter</a> painter(this);        painter.<a href="qpainter.html#bd5570">eraseRect</a>(0, menubar-&gt;heightForWidth( <a href="qwidget.html#2edab1">width</a>() ), <a href="qwidget.html#2edab1">width</a>(), <a href="qwidget.html#e3c588">height</a>());    }    <a href="qapplication.html#07e1f1">QApplication::setOverrideCursor</a>( waitCursor ); // this might take time    if ( pm.convertFromImage(image, conversion_flags) )    {        pmScaled = QPixmap();        <a href=#381>scale</a>();        <a href="qwidget.html#8fcbbe">resize</a>( width(), <a href="qwidget.html#e3c588">height</a>() );        success = TRUE;                         // load successful    } else {        pm.resize(0,0);                         // couldn't load image    }    <a href=#371>updateStatus</a>();    <a href=#370>setMenuItemFlags</a>();    <a href="qapplication.html#655095">QApplication::restoreOverrideCursor</a>();      // restore original cursor    if ( useColorContext() )        <a href="qcolor.html#30fe87">QColor::leaveAllocContext</a>();    return success;                             // TRUE if loaded OK}bool <a name="378"></a>ImageViewer::unscaled() const{    return options-&gt;isItemChecked(ns);}bool <a name="379"></a>ImageViewer::smooth() const{    return options-&gt;isItemChecked(ss);}bool <a name="380"></a>ImageViewer::useColorContext() const{    return options-&gt;isItemChecked(cc);}/*  This functions scales the pixmap in the member variable "pm" to fit the  widget size and  puts the resulting pixmap in the member variable "pmScaled".*/void <a name="381"></a>ImageViewer::scale(){    int h = height() - menubar-&gt;heightForWidth( <a href="qwidget.html#2edab1">width</a>() ) - status-&gt;height();    if ( image.isNull() ) return;    <a href="qapplication.html#07e1f1">QApplication::setOverrideCursor</a>( waitCursor ); // this might take time    if ( width() == pm.width() &amp;&amp; h == pm.height() || unscaled() )    {                                           // no need to scale if widget        pmScaled = pm;                          // size equals pixmap size    } else {        if (smooth()) {            pmScaled.convertFromImage(image.smoothScale(<a href="qwidget.html#2edab1">width</a>(), h),                conversion_flags);

⌨️ 快捷键说明

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