QwtScaleDiv ScaleEngine::divideScale(double x1, double x2, int maxMajSteps, int maxMinSteps, double stepSize) const { QwtScaleEngine *engine; if (!hasBreak()){ engine = newScaleEngine(); QwtScaleDiv div = engine->divideScale(x1, x2, maxMajSteps, maxMinSteps, stepSize); delete engine; return div; } double lb = d_break_left; double rb = d_break_right; double step1 = d_step_before; double step2 = d_step_after; if (x1 > x2){ lb = d_break_right; rb = d_break_left; step1 = d_step_after; step2 = d_step_before; if (d_log10_scale_after) engine = new QwtLog10ScaleEngine(); else engine = new QwtLinearScaleEngine(); } else engine = newScaleEngine(); int max_min_intervals = d_minor_ticks_before; if (d_minor_ticks_before == 1) max_min_intervals = 3; if (d_minor_ticks_before > 1) max_min_intervals = d_minor_ticks_before + 1; QwtScaleDiv div1 = engine->divideScale(x1, lb, maxMajSteps/2, max_min_intervals, step1); max_min_intervals = d_minor_ticks_after; if (d_minor_ticks_after == 1) max_min_intervals = 3; if (d_minor_ticks_after > 1) max_min_intervals = d_minor_ticks_after + 1; delete engine; if (testAttribute(QwtScaleEngine::Inverted)) engine = newScaleEngine(); else if (d_log10_scale_after) engine = new QwtLog10ScaleEngine(); else engine = new QwtLinearScaleEngine(); QwtScaleDiv div2 = engine->divideScale(rb, x2, maxMajSteps/2, max_min_intervals, step2); QwtValueList ticks[QwtScaleDiv::NTickTypes]; ticks[QwtScaleDiv::MinorTick] = div1.ticks(QwtScaleDiv::MinorTick) + div2.ticks(QwtScaleDiv::MinorTick); ticks[QwtScaleDiv::MediumTick] = div1.ticks(QwtScaleDiv::MediumTick) + div2.ticks(QwtScaleDiv::MediumTick); ticks[QwtScaleDiv::MajorTick] = div1.ticks(QwtScaleDiv::MajorTick) + div2.ticks(QwtScaleDiv::MajorTick); delete engine; return QwtScaleDiv(x1, x2, ticks); }
void NifBlockEditor::add( NifEditBox * box ) { editors.append( box ); if ( layouts.count() == 1 && testAttribute( Qt::WA_DeleteOnClose ) ) layouts.top()->insertWidget( layouts.top()->count() - 1, box ); else layouts.top()->addWidget( box ); }
/*! \reimp */ void QFontDialog::setVisible(bool visible) { if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden) != visible) return; Q_D(QFontDialog); if (d->canBeNativeDialog()) d->setNativeDialogVisible(visible); if (d->nativeDialogInUse) { // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below // updates the state correctly, but skips showing the non-native version: setAttribute(Qt::WA_DontShowOnScreen, true); } else { d->nativeDialogInUse = false; setAttribute(Qt::WA_DontShowOnScreen, false); } QDialog::setVisible(visible); }
void QWidget::destroy(bool destroyWindow, bool destroySubWindows) { Q_D(QWidget); d->aboutToDestroy(); if (!isWindow() && parentWidget()) parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry())); d->deactivateWidgetCleanup(); if (testAttribute(Qt::WA_WState_Created)) { setAttribute(Qt::WA_WState_Created, false); QObjectList childObjects = children(); for (int i = 0; i < childObjects.size(); ++i) { QObject *obj = childObjects.at(i); if (obj->isWidgetType()) static_cast<QWidget*>(obj)->destroy(destroySubWindows, destroySubWindows); } releaseMouse(); if (qt_pressGrab == this) qt_pressGrab = 0; if (keyboardGrb == this) releaseKeyboard(); if (testAttribute(Qt::WA_ShowModal)) // just be sure we leave modal QApplicationPrivate::leaveModal(this); else if ((windowType() == Qt::Popup)) qApp->d_func()->closePopup(this); #ifndef QT_NO_IM if (d->ic) { delete d->ic; d->ic =0; } else { // release previous focus information participating with // preedit preservation of qic -- while we still have a winId QInputContext *qic = QApplicationPrivate::inputContext; if (qic) qic->widgetDestroyed(this); } #endif //QT_NO_IM if ((windowType() == Qt::Desktop)) { } else { if (parentWidget() && parentWidget()->testAttribute(Qt::WA_WState_Created)) { d->hide_sys(); } if (destroyWindow && isWindow()) { if (d->extra && d->extra->topextra && d->extra->topextra->backingStore) d->extra->topextra->backingStore->windowSurface->setGeometry(QRect()); qwsDisplay()->destroyRegion(internalWinId()); } } QT_TRY { d->setWinId(0); } QT_CATCH (const std::bad_alloc &) { // swallow - destructors must not throw } } }
void QWidget::setWindowState(Qt::WindowStates newstate) { Q_D(QWidget); Qt::WindowStates oldstate = windowState(); if (oldstate == newstate) return; if (isWindow() && !testAttribute(Qt::WA_WState_Created)) create(); data->window_state = newstate; data->in_set_window_state = 1; bool needShow = false; Qt::WindowStates newEffectiveState = effectiveState(newstate); Qt::WindowStates oldEffectiveState = effectiveState(oldstate); if (isWindow() && newEffectiveState != oldEffectiveState) { d->createTLExtra(); if (oldEffectiveState == Qt::WindowNoState) { //normal d->topData()->normalGeometry = geometry(); } else if (oldEffectiveState == Qt::WindowFullScreen) { setParent(0, d->topData()->savedFlags); needShow = true; } else if (oldEffectiveState == Qt::WindowMinimized) { needShow = true; } if (newEffectiveState == Qt::WindowMinimized) { //### not ideal... hide(); needShow = false; } else if (newEffectiveState == Qt::WindowFullScreen) { d->topData()->savedFlags = windowFlags(); setParent(0, Qt::FramelessWindowHint | (windowFlags() & Qt::WindowStaysOnTopHint)); d->setFullScreenSize_helper(); raise(); needShow = true; } else if (newEffectiveState == Qt::WindowMaximized) { createWinId(); d->setMaxWindowState_helper(); } else { //normal QRect r = d->topData()->normalGeometry; if (r.width() >= 0) { d->topData()->normalGeometry = QRect(0,0,-1,-1); setGeometry(r); } } } data->in_set_window_state = 0; if (needShow) show(); if (newstate & Qt::WindowActive) activateWindow(); QWindowStateChangeEvent e(oldstate); QApplication::sendEvent(this, &e); }
void PreviewReportWindow::exec() { bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose,false); setAttribute(Qt::WA_ShowModal,true); show(); m_eventLoop.exec(); if (deleteOnClose) delete this; }
void QWidget::grabMouse() { if (!qt_nograb()) { if (mouseGrb) mouseGrb->releaseMouse(); Q_ASSERT(testAttribute(Qt::WA_WState_Created)); SetCapture(internalWinId()); mouseGrb = this; } }
void BoxContent::paintEvent(QPaintEvent *e) { Painter p(this); if (testAttribute(Qt::WA_OpaquePaintEvent)) { for (auto rect : e->region().rects()) { p.fillRect(rect, st::boxBg); } } }
/*! Align and divide an interval \param maxNumSteps Max. number of steps \param x1 First limit of the interval (In/Out) \param x2 Second limit of the interval (In/Out) \param stepSize Step size (Out) \sa QwtScaleEngine::setAttribute() */ void QwtLog10ScaleEngine::autoScale(int maxNumSteps, double &x1, double &x2, double &stepSize) const { if ( x1 > x2 ) qSwap(x1, x2); QwtDoubleInterval interval(x1 / pow(10.0, lowerMargin()), x2 * pow(10.0, upperMargin()) ); double logRef = 1.0; if (reference() > LOG_MIN / 2) logRef = qwtMin(reference(), LOG_MAX / 2); if (testAttribute(QwtScaleEngine::Symmetric)) { const double delta = qwtMax(interval.maxValue() / logRef, logRef / interval.minValue()); interval.setInterval(logRef / delta, logRef * delta); } if (testAttribute(QwtScaleEngine::IncludeReference)) interval = interval.extend(logRef); interval = interval.limited(LOG_MIN, LOG_MAX); if (interval.width() == 0.0) interval = buildInterval(interval.minValue()); stepSize = divideInterval(log10(interval).width(), qwtMax(maxNumSteps, 1)); if ( stepSize < 1.0 ) stepSize = 1.0; if (!testAttribute(QwtScaleEngine::Floating)) interval = align(interval, stepSize); x1 = interval.minValue(); x2 = interval.maxValue(); if (testAttribute(QwtScaleEngine::Inverted)) { qSwap(x1, x2); stepSize = -stepSize; } }
/*! En/Disable the trough The slider can be cutomized by showing a trough for the handle. \param on When true, the groove is visible \sa hasTrough(), setGroove() */ void QwtSlider::setTrough( bool on ) { if ( d_data->hasTrough != on ) { d_data->hasTrough = on; if ( testAttribute( Qt::WA_WState_Polished ) ) layoutSlider( true ); } }
/*! En/Disable the groove The slider can be cutomized by showing a groove for the handle. \param on When true, the groove is visible \sa hasGroove(), setThrough() */ void QwtSlider::setGroove( bool on ) { if ( d_data->hasGroove != on ) { d_data->hasGroove = on; if ( testAttribute( Qt::WA_WState_Polished ) ) layoutSlider( true ); } }
/*! \brief Change the position of the scale \param scalePosition Position of the scale. \sa ScalePosition, scalePosition() */ void QwtThermo::setScalePosition( ScalePosition scalePosition ) { if ( d_data->scalePosition == scalePosition ) return; d_data->scalePosition = scalePosition; if ( testAttribute( Qt::WA_WState_Polished ) ) layoutThermo( true ); }
/*! \brief Set the slider's handle size When the size is empty the slider handle will be painted with a default size depending on its orientation() and backgroundStyle(). \param size New size \sa handleSize() */ void QwtSlider::setHandleSize( const QSize &size ) { if ( size != d_data->handleSize ) { d_data->handleSize = size; if ( testAttribute( Qt::WA_WState_Polished ) ) layoutSlider( true ); } }
QDialog::DialogCode QIMainDialog::exec(bool fApplicationModal /* = true */) { /* Check for the recursive run: */ AssertMsgReturn(!m_pEventLoop, ("QIMainDialog::exec() is called recursively!\n"), QDialog::Rejected); /* Reset the result code: */ setResult(QDialog::Rejected); /* Should we delete ourself on close in theory? */ const bool fOldDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose); /* For the exec() time, set this attribute to 'false': */ setAttribute(Qt::WA_DeleteOnClose, false); /* Which is the current window-modality? */ const Qt::WindowModality oldModality = windowModality(); /* For the exec() time, set this attribute to 'window-modal' or 'application-modal': */ setWindowModality(!fApplicationModal ? Qt::WindowModal : Qt::ApplicationModal); /* Show ourself: */ show(); /* Create a local event-loop: */ { QEventLoop eventLoop; m_pEventLoop = &eventLoop; /* Guard ourself for the case * we destroyed ourself in our event-loop: */ QPointer<QIMainDialog> guard = this; /* Start the blocking event-loop: */ eventLoop.exec(); /* Are we still valid? */ if (guard.isNull()) return QDialog::Rejected; m_pEventLoop = 0; } /* Save the result code early (we can delete ourself on close): */ const QDialog::DialogCode enmResultCode = result(); /* Return old modality: */ setWindowModality(oldModality); /* Reset attribute to previous value: */ setAttribute(Qt::WA_DeleteOnClose, fOldDeleteOnClose); /* Delete ourself if we should do that on close: */ if (fOldDeleteOnClose) delete this; /* Return the result code: */ return enmResultCode; }
void QWidget::grabMouse(const QCursor &cursor) { if (!qt_nograb()) { if (mouseGrb) mouseGrb->releaseMouse(); Q_ASSERT(testAttribute(Qt::WA_WState_Created)); SetCapture(internalWinId()); mouseGrbCur = new QCursor(cursor); SetCursor(mouseGrbCur->handle()); mouseGrb = this; } }
/*! Handles QEvent::StyleChange and QEvent::FontChange events \param event Change event */ void QwtSlider::changeEvent( QEvent *event ) { if ( event->type() == QEvent::StyleChange || event->type() == QEvent::FontChange ) { if ( testAttribute( Qt::WA_WState_Polished ) ) layoutSlider( true ); } QwtAbstractSlider::changeEvent( event ); }
void MediaView::showPhoto(PhotoData *photo) { _photo = photo; MTP::clearLoaderPriorities(); _photo->full->load(); _full = false; _current = QPixmap(); _w = photo->full->width(); _down = OverNone; int h = photo->full->height(); switch (cScale()) { case dbisOneAndQuarter: _w = qRound(float64(_w) * 1.25 - 0.01); h = qRound(float64(h) * 1.25 - 0.01); break; case dbisOneAndHalf: _w = qRound(float64(_w) * 1.5 - 0.01); h = qRound(float64(h) * 1.5 - 0.01); break; case dbisTwo: _w *= 2; h *= 2; break; } if (_w > _maxWidth) { h = qRound(h * _maxWidth / float64(_w)); _w = _maxWidth; } if (h > _maxHeight) { _w = qRound(_w * _maxHeight / float64(h)); h = _maxHeight; } _x = _avail.x() + (_avail.width() - _w) / 2; _y = _avail.y() + (_avail.height() - h) / 2; _from = App::user(_photo->user); updateControls(); if (isHidden()) { moveToScreen(); #ifdef Q_OS_WIN bool wm = testAttribute(Qt::WA_Mapped), wv = testAttribute(Qt::WA_WState_Visible); if (!wm) setAttribute(Qt::WA_Mapped, true); if (!wv) setAttribute(Qt::WA_WState_Visible, true); update(); QEvent e(QEvent::UpdateRequest); event(&e); if (!wm) setAttribute(Qt::WA_Mapped, false); if (!wv) setAttribute(Qt::WA_WState_Visible, false); #endif show(); } }
void QcCanvas::setBackground( const QColor &c ) { if(_bkg == c) return; _bkg = c; setAttribute( Qt::WA_OpaquePaintEvent, c.isValid() && c.alpha() == 255 ); setAttribute( Qt::WA_TranslucentBackground, c.isValid() ); if( !testAttribute(Qt::WA_WState_InPaintEvent) ) update(); }
/*! \brief Change the position of the scale \param scalePosition Position of the scale. \sa ScalePosition, scalePosition() */ void QwtSlider::setScalePosition( ScalePosition scalePosition ) { if ( d_data->scalePosition == scalePosition ) return; d_data->scalePosition = scalePosition; scaleDraw()->setAlignment( qwtScaleDrawAlignment( d_data->orientation, scalePosition ) ); if ( testAttribute( Qt::WA_WState_Polished ) ) layoutSlider( true ); }
void GtkFileDialog::setVisible(bool visible) { if (visible) { if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) { return; } } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) { return; } if (visible) { showHelper(windowFlags(), windowModality(), parentWidget() ? parentWidget()->windowHandle() : nullptr); } else { hideHelper(); } // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below // updates the state correctly, but skips showing the non-native version: setAttribute(Qt::WA_DontShowOnScreen); QDialog::setVisible(visible); }
int GtkFileDialog::exec() { d->setModality(windowModality()); bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose, false); bool wasShowModal = testAttribute(Qt::WA_ShowModal); setAttribute(Qt::WA_ShowModal, true); setResult(0); show(); QPointer<QDialog> guard = this; d->exec(); if (guard.isNull()) return QDialog::Rejected; setAttribute(Qt::WA_ShowModal, wasShowModal); return result(); }
/*! \brief Change the spacing between trough and scale A spacing of 0 means, that the backbone of the scale is covered by the trough. The default setting is 4 pixels. \param spacing Number of pixels \sa spacing(); */ void QwtSlider::setSpacing( int spacing ) { if ( spacing <= 0 ) spacing = 0; if ( spacing != d_data->spacing ) { d_data->spacing = spacing; if ( testAttribute( Qt::WA_WState_Polished ) ) layoutSlider( true ); } }
/*! \brief Change the slider's border width The border width is used for drawing the slider handle and the trough. \param width Border width \sa borderWidth() */ void QwtSlider::setBorderWidth( int width ) { if ( width < 0 ) width = 0; if ( width != d_data->borderWidth ) { d_data->borderWidth = width; if ( testAttribute( Qt::WA_WState_Polished ) ) layoutSlider( true ); } }
/*! \brief Set the orientation. \param orientation Allowed values are Qt::Horizontal and Qt::Vertical. \sa orientation(), scalePosition() */ void QwtSlider::setOrientation( Qt::Orientation orientation ) { if ( orientation == d_data->orientation ) return; d_data->orientation = orientation; scaleDraw()->setAlignment( qwtScaleDrawAlignment( orientation, d_data->scalePosition ) ); if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) ) { QSizePolicy sp = sizePolicy(); sp.transpose(); setSizePolicy( sp ); setAttribute( Qt::WA_WState_OwnSizePolicy, false ); } if ( testAttribute( Qt::WA_WState_Polished ) ) layoutSlider( true ); }
/*! Render the legend into a given rectangle. \param painter Painter \param rect Bounding rectangle \param fillBackground When true, fill rect with the widget background \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself */ void QwtLegend::renderLegend( QPainter *painter, const QRectF &rect, bool fillBackground ) const { if ( d_data->itemMap.isEmpty() ) return; if ( fillBackground ) { if ( autoFillBackground() || testAttribute( Qt::WA_StyledBackground ) ) { QwtPainter::drawBackgound( painter, rect, this ); } } const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() ); if ( legendLayout == NULL ) return; int left, right, top, bottom; getContentsMargins( &left, &top, &right, &bottom ); QRect layoutRect; layoutRect.setLeft( qCeil( rect.left() ) + left ); layoutRect.setTop( qCeil( rect.top() ) + top ); layoutRect.setRight( qFloor( rect.right() ) - right ); layoutRect.setBottom( qFloor( rect.bottom() ) - bottom ); uint numCols = legendLayout->columnsForWidth( layoutRect.width() ); QList<QRect> itemRects = legendLayout->layoutItems( layoutRect, numCols ); int index = 0; for ( int i = 0; i < legendLayout->count(); i++ ) { QLayoutItem *item = legendLayout->itemAt( i ); QWidget *w = item->widget(); if ( w ) { painter->save(); painter->setClipRect( itemRects[index], Qt::IntersectClip ); renderItem( painter, w, itemRects[index], fillBackground ); index++; painter->restore(); } } }
/*! \brief Set a scale draw For changing the labels of the scales, it is necessary to derive from QwtScaleDraw and overload QwtScaleDraw::label(). \param scaleDraw ScaleDraw object, that has to be created with new and will be deleted in ~QwtSlider() or the next call of setScaleDraw(). \sa scaleDraw() */ void QwtSlider::setScaleDraw( QwtScaleDraw *scaleDraw ) { const QwtScaleDraw *previousScaleDraw = this->scaleDraw(); if ( scaleDraw == NULL || scaleDraw == previousScaleDraw ) return; if ( previousScaleDraw ) scaleDraw->setAlignment( previousScaleDraw->alignment() ); setAbstractScaleDraw( scaleDraw ); if ( testAttribute( Qt::WA_WState_Polished ) ) layoutSlider( true ); }
bool QSystemTrayIconSys::trayMessageW(DWORD msg) { NOTIFYICONDATAW tnd; memset(&tnd, 0, notifyIconSizeW); tnd.uID = q_uNOTIFYICONID; tnd.cbSize = notifyIconSizeW; tnd.hWnd = winId(); Q_ASSERT(testAttribute(Qt::WA_WState_Created)); if (msg != NIM_DELETE) { setIconContentsW(tnd); } return ptrShell_NotifyIcon(msg, &tnd); }
/*! Paint event \param event Paint event \sa QwtPlot::drawCanvas() */ void QwtPlotGLCanvas::paintEvent( QPaintEvent *event ) { Q_UNUSED( event ); QPainter painter( this ); drawBackground( &painter ); drawItems( &painter ); if ( !testAttribute( Qt::WA_StyledBackground ) ) { if ( frameWidth() > 0 ) drawBorder( &painter ); } }
void NifBlockEditor::pushLayout( QBoxLayout * lay, const QString & name ) { if ( name.isEmpty() ) { if ( layouts.count() == 1 && testAttribute( Qt::WA_DeleteOnClose ) ) layouts.top()->insertLayout( layouts.top()->count() - 1, lay ); else layouts.top()->addLayout( lay ); layouts.push( lay ); } else { QGroupBox * group = new QGroupBox; group->setTitle( name ); group->setLayout( lay ); if ( layouts.count() == 1 && testAttribute( Qt::WA_DeleteOnClose ) ) layouts.top()->insertWidget( layouts.top()->count() - 1, group ); else layouts.top()->addWidget( group ); layouts.push( lay ); } }
void QcCanvas::paintEvent( QPaintEvent *e ) { if( _paint && _repaintNeeded ) { if( _resize ) { _pixmap = QPixmap( size() ); _resize = false; _clearOnce = true; } if( _clearOnRefresh || _clearOnce ) { _pixmap.fill( QColor(0,0,0,0) ); _clearOnce = false; } bool opaque_before = testAttribute(Qt::WA_OpaquePaintEvent); QPainter pixPainter( &_pixmap ); Q_EMIT( painting(&pixPainter) ); _repaintNeeded = false; bool opaque_after = testAttribute(Qt::WA_OpaquePaintEvent); if( opaque_before && !opaque_after ) { repaint(); return; } } QPainter p(this); QPalette plt(palette()); if( _bkg.isValid() ) p.fillRect( e->rect(), _bkg ); if( _paint ) p.drawPixmap( e->rect(), _pixmap, e->rect() ); }