void MyImage::setImage(QImage &image) { setDefaultSize(image.size()); if(m_cache){ QPixmap *temp_pixmap = new QPixmap(QPixmap::fromImage(image)); pixmapCache.insert(m_source.toString(), temp_pixmap); } QSize temp_size = m_sourceSize; if(temp_size==QSize(0,0)){ temp_size = m_defaultSize; }else if(temp_size.width()==0){ temp_size.setWidth((double)temp_size.height()/m_defaultSize.height()*m_defaultSize.width()); }else if(temp_size.height()==0){ temp_size.setHeight((double)temp_size.width()/m_defaultSize.width()*m_defaultSize.height()); } if(m_defaultSize!=temp_size) image = image.scaled(temp_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); if(m_grayscale){//如果为黑白 chromaticToGrayscale(image);//转换为黑白图 } if(pixmap!=NULL) delete pixmap; pixmap = new QPixmap(QPixmap::fromImage(image)); QString str = m_maskSource.toLocalFile(); if(str==""){ str = m_maskSource.toString(); } if(str!=""){ if( str.mid (0, 3) == "qrc") str = str.mid (3, str.count ()-3); QBitmap bitmap(str); if(!bitmap.isNull()){ int max_width = bitmap.width(); int max_height = bitmap.height(); max_width = pixmap->width()>max_width?pixmap->width():max_width; max_height = pixmap->height()>max_height?pixmap->height():max_height; QPixmap temp_pixmap = pixmap->scaled(max_width, max_height); temp_pixmap.setMask (bitmap.scaled(temp_pixmap.size())); *pixmap = temp_pixmap.scaled(image.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } } setImplicitWidth(image.width()); setImplicitHeight(image.height()); update(); setStatus(Ready); emit loadReady(); }
void JSObject::onFinished(QNetworkReply *re) { if(re->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200){ mResult =QString::fromUtf8(re->readAll()); mState = false; if(re->request().attribute(QNetworkRequest::User).toInt() == FOW){ emit loadReady(); }else if(re->request().attribute(QNetworkRequest::User).toInt() == PARS){ emit parsReady(); } }else { mState = true; } }
DemoGLWidget::DemoGLWidget(QWidget *parent) : QGLWidget(parent), entity1(0), entity2(0), entity3(0), entity4(0), critter(0) { setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_NoSystemBackground); setAutoBufferSwap(false); #ifndef Q_WS_QWS setMinimumSize(300, 250); #endif frames = 0; randomTarget(); drawTitle = true; titleFading = false; titleOcapacity = 1.0; loadedInstruments = 0; totalInstruments = 8; waitForClick = false; // Init FBO /* makeCurrent(); if (QGLFramebufferObject::hasOpenGLFramebufferBlit()) { QGLFramebufferObjectFormat format; format.setSamples(4); format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); render_fbo = new QGLFramebufferObject(512, 512, format); texture_fbo = new QGLFramebufferObject(512, 512); } else { render_fbo = new QGLFramebufferObject(1024, 1024); texture_fbo = render_fbo; } */ /* fbo->width = WIDTH; fbo->height = HEIGHT; Utils::InitFBO(fbo); */ // Init shaders /* QGLShader *vshader2 = new QGLShader(QGLShader::Vertex); const char *vsrc2 = "void main(void) \n" "{" " gl_Position = ftransform();" " gl_TexCoord[0] = gl_MultiTexCoord0;" "}"; vshader2->compileSourceCode(vsrc2); QGLShader *fshader2 = new QGLShader(QGLShader::Fragment); const char *fsrc2 = "uniform int Width, Height;" "uniform int Dist;" "uniform mat3 Kernel;" "uniform sampler2D Tex0; \n" "void main (void)" "{" " int i, j;" " vec2 coord;" " float contrib = 0.0;" " vec4 sum = vec4(0.0);" " // 3x3 convolution matrix" " for(i = -1; i <= 1; i++) " " for(j = -1; j <= 1; j++) {" " coord = gl_TexCoord[0].st + vec2(float(i) * (1.0/float(Width)) * float(Dist), float(j) * (1.0/float(Height)) * float(Dist));" " sum += Kernel[i+1][j+1] * texture2D(Tex0, coord.xy);" " contrib += Kernel[i+1][j+1];" " }" " gl_FragColor = sum/contrib;" "}"; fshader2->compileSourceCode(fsrc2); program.addShader(vshader2); program.addShader(fshader2); program.link(); */ // Play music if(USE_SOUND) { //qDebug("Rendering music..."); //synth_init(); //qDebug("Rendered"); //synth_play(); loader = new SynthLoadThread(); loader->start(QThread::HighestPriority); connect(loader, SIGNAL(finished()), this, SLOT(loadReady())); } }
bool BulkLoad::bulkLoadBody() { if (m_cancel) { emit updateJob(JobList::BulkLoad, JobList::Cancelled, job->seq); return false; } emit updateJob(JobList::BulkLoad, JobList::Running, job->seq); NewsGroup* ng = job->ng; HeaderList* hl = job->headerList; mphDeletionsList = 0; sphDeletionsList = 0; DBC *dbcp = 0; MultiPartHeader mph; SinglePartHeader sph; HeaderBase* hb = 0; memset(&ckey, 0, sizeof(ckey)); memset(&cdata, 0, sizeof(cdata)); cdata.data = (void *) dataBuffer; cdata.ulen = HEADER_BULK_BUFFER_LENGTH; cdata.flags = DB_DBT_USERMEM; ckey.data = (void *) keyBuffer; ckey.ulen = HEADER_BULK_BUFFER_LENGTH; ckey.flags = DB_DBT_USERMEM; size_t retklen, retdlen; void *retkey = 0, *retdata = 0; int ret, t_ret; void *p = 0; quint64 count=0; QTime start = QTime::currentTime(); qDebug() << "Loading started: " << start.toString(); /* Acquire a cursor for the database. */ if ((ret = ng->getDb()->get_DB()->cursor(ng->getDb()->get_DB(), NULL, &dbcp, DB_CURSOR_BULK)) != 0) { ng->getDb()->err(ret, "DB->cursor"); return false; } quint32 numIgnored = 0; bool mphFound = false; for (;;) { /* * Acquire the next set of key/data pairs. This code * does not handle single key/data pairs that won't fit * in a BUFFER_LENGTH size buffer, instead returning * DB_BUFFER_SMALL to our caller. */ if ((ret = dbcp->get(dbcp, &ckey, &cdata, DB_MULTIPLE_KEY | DB_NEXT)) != 0) { if (ret != DB_NOTFOUND) ng->getDb()->err(ret, "DBcursor->get"); break; } for (DB_MULTIPLE_INIT(p, &cdata);;) { DB_MULTIPLE_KEY_NEXT(p, &cdata, retkey, retklen, retdata, retdlen); if (p == NULL) break; if (retdlen){;} // MD TODO compiler .... unused variable if (*((char *)retdata) == 'm') { MultiPartHeader::getMultiPartHeader((unsigned int)retklen, (char *)retkey, (char *)retdata, &mph); hb = (HeaderBase*)&mph; mphFound = true; } else if (*((char *)retdata) == 's') { SinglePartHeader::getSinglePartHeader((unsigned int)retklen, (char *)retkey, (char *)retdata, &sph); hb = (HeaderBase*)&sph; mphFound = false; // qDebug() << "Single index = " << sph.getIndex(); } else { // What have we found ????? qDebug() << "Found unexpected identifier for header : " << (char)*((char *)retdata); continue; } if (hb->getStatus() & HeaderBase::MarkedForDeletion) { // ignore this header, garbage collection will remove it ... ++numIgnored; ++count; // ... but still count it as bulk delete will reduce the count if (numIgnored == 1) { // These two will be freed by bulk delete mphDeletionsList = new QList<QString>; sphDeletionsList = new QList<QString>; } if (mphFound) mphDeletionsList->append(hb->getIndex()); else sphDeletionsList->append(hb->getIndex()); continue; } if (m_cancel) break; hl->headerTreeModel->setupTopLevelItem(hb); ++count; if (count % 50 == 0) { QString labelText = tr("Loaded ") + QString("%L1").arg(count) + " of " + QString("%L1").arg(ng->getTotal()) + " articles."; emit progress(job->seq, count, labelText); QCoreApplication::processEvents(); } } if (m_cancel) break; } if ((t_ret = dbcp->close(dbcp)) != 0) { ng->getDb()->err(ret, "DBcursor->close"); if (ret == 0) ret = t_ret; } emit loadReady(job->seq); QString labelText = tr("Loaded ") + QString("%L1").arg(count) + " of " + QString("%L1").arg(ng->getTotal()) + " articles."; emit progress(job->seq, count, labelText); QCoreApplication::processEvents(); if (!m_cancel) { quint64 totalArticles = ng->getTotal(); if (totalArticles != count || ng->unread() > count) { qint64 difference = count - totalArticles; // may be negative quint64 unread = (quint64)qMax((qint64)(ng->unread() + difference), (qint64)0); if (unread > count) unread = count; ng->setTotal(count); ng->setUnread(unread); emit updateArticleCounts(ng); } } qDebug() << "Loading finished. Seconds: " << start.secsTo(QTime::currentTime()); qDebug() << "Ignored " << numIgnored << " articles"; qDebug() << "Loaded " << count << " articles"; if (mphDeletionsList) // need bulk deletion emit addBulkJob(JobList::BulkDelete, ng, hl, mphDeletionsList, sphDeletionsList); if (m_cancel) { emit updateJob(JobList::BulkLoad, JobList::Cancelled, job->seq); return false; } emit updateJob(JobList::BulkLoad, JobList::Finished_Ok, job->seq); return true; }