QBitmap Slider::drawMaxValue() { QFontMetrics fm(this->font()); QString st; if (direction == 0) st.setNum(maxValue,'f',precision); else if (direction == 1) st.setNum(minValue,'f',precision); QPainter painter; int _x,_y; QBitmap res; if (orientation == 0) { res.resize(width()/2,(height()-20)/2); res.fill(Qt::color0); painter.begin(&res); painter.setPen(Qt::color1); painter.setBrush(Qt::color1); painter.setFont(this->font()); _x = res.width()-fm.width(st)-10; _y = fm.height(); painter.drawText(_x,_y,st); } else if (orientation == 1) { res.resize((width()-20)/2,height()/2); res.fill(Qt::color0); painter.begin(&res); painter.setPen(Qt::color1); painter.setBrush(Qt::color1); painter.setFont(this->font()); _x = res.width()-fm.width(st); _y = res.height()-10; painter.drawText(_x,_y,st); } painter.end(); return res; }
void QCursor::setBitmap( const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY ) { if ( !initialized ) initialize(); if ( bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size() ) { #if defined(QT_CHECK_NULL) qWarning( "QCursor: Cannot create bitmap cursor; invalid bitmap(s)" ); #endif QCursor *c = &cursorTable[arrowCursorIdx]; c->data->ref(); data = c->data; return; } data = new QCursorData; Q_CHECK_PTR( data ); data->bm = new QBitmap( bitmap ); data->bmm = new QBitmap( mask ); data->hcurs = 0; data->cshape = BitmapCursor; data->hx = hotX >= 0 ? hotX : bitmap.width()/2; data->hy = hotY >= 0 ? hotY : bitmap.height()/2; data->fg.red = 0 << 8; data->fg.green = 0 << 8; data->fg.blue = 0 << 8; data->bg.red = 255 << 8; data->bg.green = 255 << 8; data->bg.blue = 255 << 8; update(); // Xcursor's backward compatibility hack needs the cursor to be created // right after the bitmaps are created and filled with data }
//---------------------------------------------init void ModuleWidget::init() { m_pUi = new Ui::ModuleWidgetUI(); m_pUi->setupUi(this); m_pUi->m_pModuleName->setText(QString(m_pModule->getRuntimeModuleID().c_str())); setAcceptDrops(true); m_aTimer.start(TIMER_UNIT); //interval the timer is invoked connectModuleSignals(); //call virtual method //QObject::connect(m_pUi->m_pRunButton, SIGNAL(pressed()), this, SLOT(onRunButton())); //QObject::connect(m_pUi->m_pResetButton, SIGNAL(pressed()), this, SLOT(onResetButton())); QObject::connect(&m_aTimer, SIGNAL(timeout()), this, SLOT(onTimer())); initInputs(); initOutputs(); setContextMenuPolicy(Qt::CustomContextMenu); static QBitmap aMask; if(aMask.width() == 0) //create the mask only once { aMask = QBitmap(size()); aMask.clear(); QPainter aPainter(&aMask); aPainter.setBrush(QBrush(Qt::SolidPattern)); aPainter.drawEllipse(QPoint(width()/2, height()/2), width()/2, width()/2); } setMask(aMask); }
void QCursor::setBitmap( const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY ) { if ( !initialized ) initialize(); if ( bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size() ) { #if defined(QT_CHECK_NULL) qWarning( "QCursor: Cannot create bitmap cursor; invalid bitmap(s)" ); #endif QCursor *c = &cursorTable[arrowCursorIdx]; c->data->ref(); data = c->data; return; } data = new QCursorData; Q_CHECK_PTR( data ); data->bm = new QBitmap( bitmap ); data->bmm = new QBitmap( mask ); data->cshape = BitmapCursor; data->id = nextCursorId++; data->hx = hotX >= 0 ? hotX : bitmap.width()/2; data->hy = hotY >= 0 ? hotY : bitmap.height()/2; QPaintDevice::qwsDisplay()->defineCursor(data->id, *data->bm, *data->bmm, data->hx, data->hy); }
Splash::Splash(const QString& imagePath) : QWidget(0, Qt::SplashScreen | Qt::X11BypassWindowManagerHint) { cachedPixmap = QPixmap(imagePath); if (!cachedPixmap.mask().isNull()) { QBitmap mask(cachedPixmap.size()); mask.fill(Qt::color0); QBitmap pixMask = cachedPixmap.mask(); QPainter p(&mask); p.drawPixmap((mask.width() - pixMask.width())/2, (mask.height() - pixMask.height())/2, pixMask); setMask(mask); } else setMask(QBitmap()); QWidget *d = QApplication::desktop()->screen(); move( (d->width() - cachedPixmap.width ()) / 2, (d->height() - cachedPixmap.height()) / 2 ); resize( cachedPixmap.size() ); setFocusPolicy( Qt::NoFocus ); show(); update(); QTimer::singleShot( SPLASH_DURATION, this, SLOT(hide()) ); }
QBitmap basicSegmentation::xand(QBitmap am, QBitmap bm) { int x, y, ap, bp; QImage a = am.toImage(); QImage b = bm.toImage(); QImage r = QImage(am.width(), am.height(), QImage::Format_Mono); for(x=0; x < am.width(); x++) { for(y=0;y < am.height(); y++) { ap=qRed(a.pixel(x,y)); bp=qRed(b.pixel(x,y)); if(ap == 0 && bp == 0){ r.setPixel(x, y, Qt::color0); } else { r.setPixel(x, y, Qt::color1); } } } return(QBitmap::fromImage(r)); }
void QPixmap::setMask( const QBitmap &newmask ) { const QPixmap *tmp = &newmask; // dec cxx bug if ( (data == tmp->data) || ( newmask.handle() && newmask.handle() == handle() ) ) { QPixmap m = tmp->copy( TRUE ); setMask( *((QBitmap*)&m) ); data->selfmask = TRUE; // mask == pixmap return; } if ( newmask.isNull() ) { // reset the mask if (data->mask) { detach(); data->selfmask = FALSE; delete data->mask; data->mask = 0; } return; } detach(); data->selfmask = FALSE; if ( newmask.width() != width() || newmask.height() != height() ) { #if defined(QT_CHECK_RANGE) qWarning( "QPixmap::setMask: The pixmap and the mask must have " "the same size" ); #endif return; } #if defined(Q_WS_MAC) || (defined(Q_WS_X11) && !defined(QT_NO_XFTFREETYPE)) // when setting the mask, we get rid of the alpha channel completely delete data->alphapm; data->alphapm = 0; #endif // Q_WS_X11 && !QT_NO_XFTFREETYPE delete data->mask; QBitmap* newmaskcopy; if ( newmask.mask() ) newmaskcopy = (QBitmap*)new QPixmap( tmp->copy( TRUE ) ); else newmaskcopy = new QBitmap( newmask ); #ifdef Q_WS_X11 newmaskcopy->x11SetScreen( x11Screen() ); #endif data->mask = newmaskcopy; }
/*! \internal A static function for reading the sprite files containing pixmaps for displaying animated elements seen in the game. */ void KSprite::loadSprites() { QString sprites_prefix = IMG_BACKGROUND; int sep = sprites_prefix.lastIndexOf("/"); sprites_prefix.truncate(sep); int i = 0; QString file_name; QString base = sprites_prefix + '/'; while (animations_[i].id_) { QList<QPixmap> p; if (animations_[i].frames_) { for (int j=0; j<animations_[i].frames_; ++j) { QString s(animations_[i].path_); file_name = base + s.arg(j,4,10,QLatin1Char('0')); QPixmap pixmap(file_name); p.insert(j,pixmap); } } else { file_name = base + QString(animations_[i].path_); QPixmap pixmap(file_name); p.insert(0,pixmap); } QList<Frame> frameshape; for (int f = 0; f < p.size(); ++f) { QPixmap pixmap = p.at(f); Frame frame; frame.pixmap = pixmap; QPainterPath path; QBitmap m = pixmap.mask(); if (m.width()) path.addRegion(QRegion(m)); else path.addRegion(QRect(pixmap.rect())); frame.shape = path; frame.boundingRect = path.controlPointRect(); frameshape << frame; } shapemap_.insert(animations_[i].id_,frameshape); i++; } spritesLoaded_ = true; }
QIntMatrix basicSegmentation::find(QBitmap mask, int minsize) { int y, x, a, l, t, eqI, eqTI, eqV, w, h, eqMaxI=1, newID = 2; bool done; QIntMatrix r(mask.width(), mask.height()); QImage im = mask.toImage(); QVector<int> u, eq, counts; w = mask.width(); h = mask.height(); for(y = 0; y < h; y++) { for(x = 0; x < w; x++) { a = qRed(im.pixel(x, y)); if(a == 0) { r.set(x, y, 1); } else { r.set(x, y, 0); } } } eq = QVector<int>(2); counts = QVector<int>(2); for(y = 1; y < (h - 1); y++) { for(x = 1; x < (w - 1); x++) { a = r.at(x, y-1); l = r.at(x-1, y); t = r.at(x, y); if (t == 1) { if (a == l && a > 1) { r.set(x, y, a); if(a > (counts.size()-1)) { counts.resize(a+1); } counts[a]++; } else if (a != l && a > 1 && l > 1) { r.set(x, y, mathmin(a, l)); if(mathmin(a, l) > (counts.size()-1)) { counts.resize(mathmin(a, l)+1); } counts[mathmin(a, l)]++; eqI = mathmax(a,l); eqV = mathmin(a,l); done = false; while (!done) { if (eqI > eqMaxI) { eq.resize(eqI+1); eqMaxI = eqI; } if ((eq.at(eqI) > 1)) { if (eqV != eq.at(eqI)) { eqTI = eqI; eqI = mathmax(eqV, eq.at(eqTI)); eqV = mathmin(eqV, eq.at(eqTI)); eq[eqTI] = eqV; } else { eq[eqI] = eqV; done = true; } } else { eq[eqI] = eqV; done = true; } } } else if (mathmax(a,l) > 1) { r.set(x, y, mathmax(a, l)); if(mathmax(a, l) > (counts.size()-1)) { counts.resize(mathmax(a, l)+1); } counts[mathmax(a, l)]++; } else { r.set(x, y, newID++); counts.resize(newID+1); counts[newID]=1; } } else { r.set(x, y, 0); } } } //clean up edges r.replace(1, 0); //resolve equivalent ids if(eqMaxI > 1) { resolveEq(&r, eq, counts, minsize); } return(r); }
QBitmap basicSegmentation::nonMergeDilate(QBitmap mm, int count) { int x, y, p, p1, p2, p3, p4, p5, p6, p7, p8, n; QIntMatrix mx(mm.width(), mm.height()); QVector<int> values; QIntMatrix source = find(mm, 50); for(n=0; n < count; n++) { for(x=0; x < mm.width(); x++) { mx.set(x, 0, 0); mx.set(x, 1, 0); mx.set(x, mm.height()-1, 0); mx.set(x, mm.height()-2, 0); } for(y=0;y < mm.height(); y++) { mx.set(0, y, 0); mx.set(1, y, 0); mx.set(mm.width()-1, y, 0); mx.set(mm.width()-2, y, 0); } for(x=2; x < (mm.width()-2); x++) { for(y=2;y < (mm.height()-2); y++) { p=source.at(x,y); if(values.size() > 0) { values.clear(); } if(p == 0){ p1 = source.at(x-1, y); if (p1 > 0) values << p1; p2 = source.at(x+1, y); if (p2 > 0) values << p2; p3 = source.at(x, y-1); if (p3 > 0) values << p3; p4 = source.at(x, y+1); if (p4> 0) values << p4; p5 = source.at(x-2, y); if (p5 > 0) values << p5; p6 = source.at(x+2, y); if (p6 > 0) values << p6; p7 = source.at(x, y-2); if (p7 > 0) values << p7; p8 = source.at(x, y+2); if (p8 > 0) values << p8; if(uniqueValues(values) > 1) { mx.set(x, y, 0); } else { mx.set(x,y, qMax(qMax(p1, p2), qMax(p3, p4))); } } else { mx.set(x, y, p); } } } for(x=0; x < mm.width(); x++) { for(y=0;y < mm.height(); y++) { source.set(x,y, mx.at(x, y)); } } //source = mx; } QImage r = QImage(mx.width, mx.height, QImage::Format_Mono); for(x=0; x < mx.width; x++) { for(y=0;y < mx.height; y++) { if(mx.at(x, y) > 0) { r.setPixel(x, y, Qt::color0); } else { r.setPixel(x, y, Qt::color1); } } } QBitmap rb = QBitmap::fromImage(r); return(rb); }
DropTarget::DropTarget(MainWindow * mw) : QWidget(0, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint), parentWidget(mw), animTimer(0), showInformation(false) { KWindowSystem::setState(winId(), NET::SkipTaskbar); QRect screenGeo = qApp->desktop()->screenGeometry(Settings::dropPosition()); if ((screenGeo.x() + screenGeo.width() >= Settings::dropPosition().x() && screenGeo.y() + screenGeo.height() >= Settings::dropPosition().y()) && Settings::dropPosition().y() >= 0 && Settings::dropPosition().x() >= 0) position = QPoint(Settings::dropPosition()); else position = QPoint(screenGeo.x() + screenGeo.width() / 2, screenGeo.y() + screenGeo.height() / 2); setFixedSize(TARGET_SIZE, TARGET_SIZE); if(Settings::dropSticky()) KWindowSystem::setState(winId(), KWindowSystem::Sticky); cachedPixmap = DesktopIcon("kget", TARGET_SIZE); if (!cachedPixmap.mask().isNull()) { QBitmap mask(size()); mask.fill(Qt::color0); QBitmap pixMask = cachedPixmap.mask(); QPainter p(&mask); p.drawPixmap((mask.width() - pixMask.width())/2, (mask.height() - pixMask.height())/2, pixMask); setMask(mask); } else setMask(QBitmap()); // popup menu for right mouse button popupMenu = new KMenu(this); popupMenu->addTitle(mw->windowTitle()); QAction * downloadAction = mw->actionCollection()->action("start_all_download"); popupMenu->addAction( downloadAction ); connect( downloadAction, SIGNAL(toggled(bool)), this, SLOT(slotStartStopToggled(bool)) ); popupMenu->addSeparator(); pop_show = popupMenu->addAction( QString(), this, SLOT(toggleMinimizeRestore()) ); popupMenu->addAction(parentWidget->actionCollection()->action("show_drop_target")); pop_sticky = popupMenu->addAction(i18nc("fix position for droptarget", "Sticky"), this, SLOT(toggleSticky())); pop_sticky->setCheckable(true); pop_sticky->setChecked(Settings::dropSticky()); popupMenu->addSeparator(); popupMenu->addAction( mw->actionCollection()->action("preferences") ); QAction *quitAction = new QAction(this); quitAction->setText(i18n("Quit KGet")); quitAction->setIcon(KIcon("system-shutdown")); connect(quitAction, SIGNAL(triggered()), mw, SLOT(slotQuit())); popupMenu->addAction(quitAction); isdragging = false; // Enable dropping setAcceptDrops(true); if ( Settings::showDropTarget() && Settings::firstRun() ) { showInformation = true; } animTimer = new QTimer(this); popupTimer = new QTimer(this); setMouseTracking(true); connect(KGet::model(), SIGNAL(transfersChangedEvent(QMap<TransferHandler*,Transfer::ChangesFlags>)), this, SLOT(slotToolTipUpdate())); connect(popupTimer, SIGNAL(timeout()), this, SLOT(slotToolTipTimer())); }