void ContextWidget::showEvent(QShowEvent *e) { setWide(width()>minWidth && !alwaysCollapsed); if (backdropType) { updateBackdrop(); } QWidget::showEvent(e); }
ContextWidget::ContextWidget(QWidget *parent) : QWidget(parent) , job(0) , alwaysCollapsed(false) , backdropType(PlayQueueView::BI_Cover) , darkBackground(false) , useFanArt(0!=constFanArtApiKey.latin1()) , albumCoverBackdrop(false) , oldIsAlbumCoverBackdrop(false) , fadeValue(1.0) , isWide(false) , stack(0) , onlineContext(0) , splitter(0) , viewSelector(0) { QHBoxLayout *layout=new QHBoxLayout(this); mainStack=new QStackedWidget(this); standardContext=new QWidget(mainStack); mainStack->addWidget(standardContext); layout->setMargin(0); layout->addWidget(mainStack); animator.setPropertyName("fade"); animator.setTargetObject(this); appLinkColor=QApplication::palette().color(QPalette::Link); artist = new ArtistView(standardContext); album = new AlbumView(standardContext); song = new SongView(standardContext); minWidth=album->picSize().width()*2.5; artist->addEventFilter(this); album->addEventFilter(this); song->addEventFilter(this); connect(artist, SIGNAL(findArtist(QString)), this, SIGNAL(findArtist(QString))); connect(artist, SIGNAL(findAlbum(QString,QString)), this, SIGNAL(findAlbum(QString,QString))); connect(album, SIGNAL(playSong(QString)), this, SIGNAL(playSong(QString))); readConfig(); setZoom(); setWide(true); #ifndef SCALE_CONTEXT_BGND QDesktopWidget *dw=QApplication::desktop(); if (dw) { QSize geo=dw->availableGeometry(this).size()-QSize(32, 64); minBackdropSize=geo; minBackdropSize.setWidth(((int)(minBackdropSize.width()/32))*32); minBackdropSize.setHeight(((int)(minBackdropSize.height()/32))*32); maxBackdropSize=QSize(geo.width()*1.25, geo.height()*1.25); } else { minBackdropSize=QSize(Utils::scaleForDpi(1024*3), Utils::scaleForDpi(768*3); maxBackdropSize=QSize(minBackdropSize.width()*2, minBackdropSize.height()*2); } #endif }
void ContextWidget::resizeEvent(QResizeEvent *e) { if (isVisible()) { setWide(width()>minWidth && !alwaysCollapsed); } #ifdef SCALE_CONTEXT_BGND resizeBackdrop(); #endif QWidget::resizeEvent(e); }
void ContextWidget::readConfig() { int origOpacity=backdropOpacity; int origBlur=backdropBlur; QString origCustomBackdropFile=customBackdropFile; int origType=backdropType; backdropType=Settings::self()->contextBackdrop(); backdropOpacity=Settings::self()->contextBackdropOpacity(); backdropBlur=Settings::self()->contextBackdropBlur(); customBackdropFile=Settings::self()->contextBackdropFile(); switch (backdropType) { case PlayQueueView::BI_None: if (origType!=backdropType && isVisible() && !currentArtist.isEmpty()) { updateBackdrop(true); QWidget::update(); } break; case PlayQueueView::BI_Cover: if (origType!=backdropType || backdropOpacity!=origOpacity || backdropBlur!=origBlur) { if (isVisible() && !currentArtist.isEmpty()) { updateBackdrop(true); QWidget::update(); } } break; case PlayQueueView::BI_Custom: if (origType!=backdropType || backdropOpacity!=origOpacity || backdropBlur!=origBlur || origCustomBackdropFile!=customBackdropFile) { updateImage(QImage(customBackdropFile), false); } break; } useDarkBackground(Settings::self()->contextDarkBackground()); WikipediaEngine::setIntroOnly(Settings::self()->wikipediaIntroOnly()); bool wasCollpased=stack && stack->isVisible(); alwaysCollapsed=Settings::self()->contextAlwaysCollapsed(); if (alwaysCollapsed && !wasCollpased) { setWide(false); } }
void takeDamage(int dam) { // we've been hit with `dam' units of energy. int s = GET_SHIELD_ENERGY; uchar i, j, m; for (i = 1; i < 11; ++i) { // shake the ship for (j = 0; j < 200; ++j) setWide(i & 1); } // absorption of shields dam -= s; if (dam <= 0) { // if some left, give back to shields SET_SHIELD_ENERGY(-dam); messageCode(MSG_CODE_SHIELDS_OK); } else { // residual damage goes to operations int di[L_COUNT-2]; int dv; int dm; if (s > 0) { SET_SHIELD_ENERGY(0); messageCode(MSG_CODE_SHIELDS_GONE); alertsound(); } /* allocate the damage randomly to each operation (not shields). * generate n-1 random numbers (mod dam+1). * take the smallest and allocate this damage (will be <= dam) * then take the next smallest and allocate this much minus previous * give any remaining amount to the last */ dm = dam + 1; // generate n-1 partitions of the damage value for (i = 0; i < L_COUNT-2; ++i) { uint r = rand16(); uint q = r/(uint)dm; di[i] = r - q*dm; } dm = 0; for (i = 1; i < L_COUNT-1; ++i) { // find min partition m = 0; for (j = 1; j < L_COUNT-2; ++j) if (di[j] < di[m]) m = j; // take damage to operations i dv = (di[m] - dm) >> 3; // amount of operational units dm = di[m]; subop(i, dv); di[m] = 0x7fff; } // remainder of total damage and last partition to last operation subop(L_COUNT-1, dam - dm); } }