void QWidget::updateRequestedRegion( const QPoint &gpos ) { if ( !isTopLevel() ) { if ( !testWState( WState_Visible ) || testWState(WState_ForceHide) ) { req_region = QRegion(); } else { req_region = QRect(gpos,crect.size()); if ( extra && !extra->mask.isNull() ) { QRegion maskr = extra->mask; maskr.translate( gpos.x(), gpos.y() ); req_region &= maskr; } req_region = qt_screen->mapToDevice( req_region, QSize(qt_screen->width(), qt_screen->height()) ); } } const QObjectList *c = children(); if ( c ) { QObjectListIt it(*c); QObject* ch; while ((ch=it.current())) { ++it; if ( ch->isWidgetType() && !((QWidget*)ch)->isTopLevel() ) { QWidget *w = (QWidget *)ch; w->updateRequestedRegion( gpos + w->pos() ); } } } }
/*! Change the alignment \param alignment New alignment \sa QwtScaleWidget::alignment */ void QwtScaleWidget::setAlignment(QwtScaleDraw::Alignment alignment) { #if QT_VERSION >= 0x040000 if ( !testAttribute(Qt::WA_WState_OwnSizePolicy) ) #else if ( !testWState( WState_OwnSizePolicy ) ) #endif { QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); if ( d_data->scaleDraw->orientation() == Qt::Vertical ) policy.transpose(); setSizePolicy(policy); #if QT_VERSION >= 0x040000 setAttribute(Qt::WA_WState_OwnSizePolicy, false); #else clearWState( WState_OwnSizePolicy ); #endif } if (d_data->scaleDraw) d_data->scaleDraw->setAlignment(alignment); layoutScale(); }
/*! \brief Set the wheel's orientation. \param o Orientation. Allowed values are Qt::Horizontal and Qt::Vertical. Defaults to Qt::Horizontal. \sa QwtAbstractSlider::orientation() */ void QwtWheel::setOrientation(Qt::Orientation o) { if ( orientation() == o ) return; #if QT_VERSION >= 0x040000 if ( !testAttribute(Qt::WA_WState_OwnSizePolicy) ) #else if ( !testWState( WState_OwnSizePolicy ) ) #endif { QSizePolicy sp = sizePolicy(); sp.transpose(); setSizePolicy(sp); #if QT_VERSION >= 0x040000 setAttribute(Qt::WA_WState_OwnSizePolicy, false); #else clearWState( WState_OwnSizePolicy ); #endif } QwtAbstractSlider::setOrientation(o); layoutWheel(); }
QSplitterLayoutStruct *QSplitter::addWidget( QWidget *w, bool first ) { QSplitterLayoutStruct *s; QSplitterHandle *newHandle = 0; if ( data->list.count() > 0 ) { s = new QSplitterLayoutStruct; s->mode = KeepSize; newHandle = new QSplitterHandle( orientation(), this ); s->wid = newHandle; newHandle->setId(data->list.count()); s->isSplitter = TRUE; s->sizer = pick( newHandle->sizeHint() ); if ( first ) data->list.insert( 0, s ); else data->list.append( s ); } s = new QSplitterLayoutStruct; s->mode = Stretch; s->wid = w; if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) s->sizer = pick( w->sizeHint() ); else s->sizer = pick( w->size() ); s->isSplitter = FALSE; if ( first ) data->list.insert( 0, s ); else data->list.append( s ); if ( newHandle && isVisible() ) newHandle->show(); //will trigger sending of post events return s; }
void QWidget::setAcceptDrops( bool on ) { if ( testWState(WState_DND) != on ) { if ( 1/*XXX qt_xdnd_enable( this, on )*/ ) { if ( on ) setWState(WState_DND); else clearWState(WState_DND); } } }
QValueList<int> QSplitter::sizes() const { if ( !testWState(WState_Polished) ) { QWidget* that = (QWidget*) this; that->polish(); } QValueList<int> list; QSplitterLayoutStruct *s = data->list.first(); while ( s ) { if ( !s->isSplitter ) list.append( s->sizer ); s = data->list.next(); } return list; }
/*! \brief Set the thermometer orientation and the scale position. The scale position NoScale disables the scale. \param o orientation. Possible values are Qt::Horizontal and Qt::Vertical. The default value is Qt::Vertical. \param s Position of the scale. The default value is NoScale. A valid combination of scale position and orientation is enforced: - a horizontal thermometer can have the scale positions TopScale, BottomScale or NoScale; - a vertical thermometer can have the scale positions LeftScale, RightScale or NoScale; - an invalid scale position will default to NoScale. \sa QwtThermo::setScalePosition() */ void QwtThermo::setOrientation(Qt::Orientation o, ScalePos s) { if ( o == d_data->orientation && s == d_data->scalePos ) return; switch(o) { case Qt::Horizontal: { if ((s == NoScale) || (s == BottomScale) || (s == TopScale)) d_data->scalePos = s; else d_data->scalePos = NoScale; break; } case Qt::Vertical: { if ((s == NoScale) || (s == LeftScale) || (s == RightScale)) d_data->scalePos = s; else d_data->scalePos = NoScale; break; } } if ( o != d_data->orientation ) { #if QT_VERSION >= 0x040000 if ( !testAttribute(Qt::WA_WState_OwnSizePolicy) ) #else if ( !testWState( WState_OwnSizePolicy ) ) #endif { QSizePolicy sp = sizePolicy(); sp.transpose(); setSizePolicy(sp); #if QT_VERSION >= 0x040000 setAttribute(Qt::WA_WState_OwnSizePolicy, false); #else clearWState( WState_OwnSizePolicy ); #endif } } d_data->orientation = o; layoutThermo(); }
void QFrame::setFrameStyle( int style ) { if ( !testWState( WState_OwnSizePolicy ) ) { switch ( style & MShape ) { case HLine: setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ); break; case VLine: setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum ); break; default: if ( (fstyle & MShape) == HLine || (fstyle & MShape) == VLine) setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); } clearWState( WState_OwnSizePolicy ); } fstyle = (short)style; updateFrameWidth( TRUE ); }
void QWidget::destroy( bool destroyWindow, bool destroySubWindows ) { deactivateWidgetCleanup(); if ( testWState(WState_Created) ) { clearWState( WState_Created ); if ( children() ) { QObjectListIt it(*children()); register QObject *obj; while ( (obj=it.current()) ) { // destroy all widget children ++it; if ( obj->isWidgetType() ) ((QWidget*)obj)->destroy(destroySubWindows, destroySubWindows); } } releaseMouse(); if ( qt_pressGrab == this ) qt_pressGrab = 0; #ifndef QT_NO_QWS_MANAGER if (QWSManager::grabbedMouse() == this) { if ( extra && extra->topextra && extra->topextra->qwsManager ) { extra->topextra->qwsManager->releaseGrab(); } } #endif if ( keyboardGrb == this ) releaseKeyboard(); if ( testWFlags(WShowModal) ) // just be sure we leave modal qt_leave_modal( this ); else if ( testWFlags(WType_Popup) ) qApp->closePopup( this ); if ( testWFlags(WType_Desktop) ) { } else { if ( parentWidget() && parentWidget()->testWState(WState_Created) ) { hideWindow(); } if ( destroyWindow && isTopLevel() ) qwsDisplay()->destroyRegion( winId() ); } setWinId( 0 ); } }
/*! \brief Set the orientation. \param o Orientation. Allowed values are Qt::Horizontal and Qt::Vertical. If the new orientation and the old scale position are an invalid combination, the scale position will be set to QwtSlider::NoScale. \sa QwtAbstractSlider::orientation() */ void QwtSlider::setOrientation(Qt::Orientation o) { if ( o == orientation() ) return; if (o == Qt::Horizontal) { if ((d_data->scalePos == LeftScale) || (d_data->scalePos == RightScale)) d_data->scalePos = NoScale; } else // if (o == Qt::Vertical) { if ((d_data->scalePos == BottomScale) || (d_data->scalePos == TopScale)) d_data->scalePos = NoScale; } #if QT_VERSION >= 0x040000 if ( !testAttribute(Qt::WA_WState_OwnSizePolicy) ) #else if ( !testWState( WState_OwnSizePolicy ) ) #endif { QSizePolicy sp = sizePolicy(); sp.transpose(); setSizePolicy(sp); #if QT_VERSION >= 0x040000 setAttribute(Qt::WA_WState_OwnSizePolicy, false); #else clearWState( WState_OwnSizePolicy ); #endif } QwtAbstractSlider::setOrientation(o); layoutSlider(); }
void QWidget::reparentSys( QWidget *parent, WFlags f, const QPoint &p, bool showIt ) { QWidget* oldtlw = topLevelWidget(); #ifndef QT_NO_CURSOR QCursor oldcurs; bool setcurs=testWState(WState_OwnCursor); if ( setcurs ) { oldcurs = cursor(); unsetCursor(); } #endif WId old_winid = winid; if ( testWFlags(WType_Desktop) ) old_winid = 0; if ( !isTopLevel() && parentWidget() && parentWidget()->testWState(WState_Created) ) hideWindow(); setWinId( 0 ); if ( parentObj != parent ) { QWidget *oldparent = parentWidget(); if ( oldparent ) { // remove from parent oldparent->removeChild( this ); oldparent->setChildrenAllocatedDirty(); oldparent->paintable_region_dirty = TRUE; } if ( parent ) { // insert into new parent parent->insertChild( this ); parent->setChildrenAllocatedDirty(); parent->paintable_region_dirty = TRUE; } } bool enable = isEnabled(); // remember status FocusPolicy fp = focusPolicy(); QSize s = size(); //QPixmap *bgp = (QPixmap *)backgroundPixmap(); //QColor bgc = bg_col; // save colors #ifndef QT_NO_WIDGET_TOPEXTRA QString capt= caption(); #endif widget_flags = f; clearWState( WState_Created | WState_Visible | WState_ForceHide ); create(); if ( isTopLevel() || (!parent || parent->isVisible() ) ) setWState( WState_ForceHide ); // new widgets do not show up in already visible parents /* if ( bgp ) XSetWindowBackgroundPixmap( dpy, winid, bgp->handle() ); else XSetWindowBackground( dpy, winid, bgc.pixel() ); */ setGeometry( p.x(), p.y(), s.width(), s.height() ); setEnabled( enable ); setFocusPolicy( fp ); #ifndef QT_NO_WIDGET_TOPEXTRA if ( !capt.isNull() ) { extra->topextra->caption = QString::null; setCaption( capt ); } #endif if ( showIt ) show(); if ( (int)old_winid > 0 ) qwsDisplay()->destroyRegion( old_winid ); #ifndef QT_NO_CURSOR if ( setcurs ) { setCursor(oldcurs); } #endif reparentFocusWidgets( oldtlw ); // fix focus chains }
void QWidget::create( WId window, bool initializeWindow, bool /*destroyOldWindow*/) { if ( testWState(WState_Created) && window == 0 ) return; setWState( WState_Created ); // set created flag if ( !parentWidget() || parentWidget()->isDesktop() ) setWFlags( WType_TopLevel ); // top-level widget alloc_region_index = -1; alloc_region_revision = -1; isSettingGeometry = FALSE; overlapping_children = -1; bool topLevel = testWFlags(WType_TopLevel); bool popup = testWFlags(WType_Popup); bool dialog = testWFlags(WType_Dialog); bool desktop = testWFlags(WType_Desktop); WId id; QWSDisplay* dpy = qwsDisplay(); if ( !window ) // always initialize initializeWindow = TRUE; if ( popup ) { setWFlags(WStyle_Tool); // a popup is a tool window setWFlags(WStyle_StaysOnTop); // a popup stays on top } if ( topLevel && parentWidget() ) { // if our parent has WStyle_StaysOnTop, so must we QWidget *ptl = parentWidget()->topLevelWidget(); if ( ptl && ptl->testWFlags( WStyle_StaysOnTop ) ) setWFlags(WStyle_StaysOnTop); } int sw = dpy->width(); int sh = dpy->height(); if ( dialog || popup || desktop ) { // these are top-level, too topLevel = TRUE; setWFlags( WType_TopLevel ); } if ( desktop ) { // desktop widget dialog = popup = FALSE; // force these flags off crect.setRect( 0, 0, sw, sh ); } else if ( topLevel ) { // calc pos/size from screen crect.setRect( 0, 0, sw/2, 4*sh/10 ); } else { // child widget crect.setRect( 0, 0, 100, 30 ); } if ( window ) { // override the old window id = window; setWinId( window ); } else if ( desktop ) { // desktop widget id = (WId)-2; // id = root window QWidget *otherDesktop = find( id ); // is there another desktop? if ( otherDesktop && otherDesktop->testWFlags(WPaintDesktop) ) { otherDesktop->setWinId( 0 ); // remove id from widget mapper setWinId( id ); // make sure otherDesktop is otherDesktop->setWinId( id ); // found first } else { setWinId( id ); } } else { id = topLevel ? dpy->takeId() : takeLocalId(); setWinId( id ); // set widget id/handle + hd } if ( !topLevel ) { if ( !testWFlags(WStyle_Customize) ) setWFlags( WStyle_NormalBorder | WStyle_Title | WStyle_MinMax | WStyle_SysMenu ); } else if ( !(desktop || popup) ) { if ( testWFlags(WStyle_Customize) ) { // customize top-level widget if ( testWFlags(WStyle_NormalBorder) ) { // XXX ... } else { if ( !testWFlags(WStyle_DialogBorder) ) { // XXX ... } } if ( testWFlags(WStyle_Tool) ) { // XXX ... } } else { // normal top-level widget setWFlags( WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WStyle_MinMax ); } } alloc_region_dirty=FALSE; paintable_region_dirty=FALSE; if ( !initializeWindow ) { // do no initialization } else if ( popup ) { // popup widget } else if ( topLevel && !desktop ) { // top-level widget QWidget *p = parentWidget(); // real parent if (p) p = p->topLevelWidget(); if ( testWFlags(WStyle_DialogBorder) || testWFlags(WStyle_StaysOnTop) || testWFlags(WStyle_Dialog) || testWFlags(WStyle_Tool) ) { // XXX ... } // find the real client leader, i.e. a toplevel without parent while ( p && p->parentWidget()) { p = p->parentWidget()->topLevelWidget(); } // XXX ... } if ( initializeWindow ) { } setWState( WState_MouseTracking ); setMouseTracking( FALSE ); // also sets event mask if ( desktop ) { setWState( WState_Visible ); } else if ( topLevel ) { // set X cursor //QCursor *oc = QApplication::overrideCursor(); if ( initializeWindow ) { //XXX XDefineCursor( dpy, winid, oc ? oc->handle() : cursor().handle() ); } setWState( WState_OwnCursor ); #ifndef QT_NO_WIDGET_TOPEXTRA qwsDisplay()->nameRegion( winId(), name(""), caption() ); #else qwsDisplay()->nameRegion( winId(), name(""), QString::null ); #endif } if ( topLevel ) { #if !defined(QT_NO_WIDGET_TOPEXTRA) && !defined(QT_NO_QWS_MANAGER) createTLExtra(); #endif #ifndef QT_NO_QWS_MANAGER if ( testWFlags(WStyle_DialogBorder) || testWFlags(WStyle_NormalBorder)) { // get size of wm decoration QRegion r = QApplication::qwsDecoration().region(this, crect); QRect br( r.boundingRect() ); crect.moveBy( crect.x()-br.x(), crect.y()-br.y() ); extra->topextra->fleft = crect.x()-br.x(); extra->topextra->ftop = crect.y()-br.y(); extra->topextra->fright = br.right()-crect.right(); extra->topextra->fbottom = br.bottom()-crect.bottom(); topData()->qwsManager = new QWSManager(this); } else if ( topData()->qwsManager ) { delete topData()->qwsManager; topData()->qwsManager = 0; crect.moveBy( -extra->topextra->fleft, -extra->topextra->ftop ); extra->topextra->fleft = extra->topextra->ftop = extra->topextra->fright = extra->topextra->fbottom = 0; } #endif // declare the widget's object name as window role qt_fbdpy->addProperty(id,QT_QWS_PROPERTY_WINDOWNAME); qt_fbdpy->setProperty(id,QT_QWS_PROPERTY_WINDOWNAME,0,name()); // If we are session managed, inform the window manager about it if ( extra && !extra->mask.isNull() ) { req_region = extra->mask; req_region.translate(crect.x(),crect.y()); req_region &= crect; //??? this is optional } else { req_region = crect; } req_region = qt_screen->mapToDevice( req_region, QSize(qt_screen->width(), qt_screen->height()) ); } else { if ( extra && extra->topextra ) { // already allocated due to reparent? extra->topextra->fleft = 0; extra->topextra->ftop = 0; extra->topextra->fright = 0; extra->topextra->fbottom = 0; } //updateRequestedRegion( mapToGlobal(QPoint(0,0)) ); } }
bool QWidget::acceptDrops() const { return testWState(WState_DND); }
void QWidget::scroll( int dx, int dy, const QRect& r ) { if ( testWState( WState_BlockUpdates ) && !children() ) return; bool valid_rect = r.isValid(); QRect sr = valid_rect?r:rect(); int x1, y1, x2, y2, w=sr.width(), h=sr.height(); if ( dx > 0 ) { x1 = sr.x(); x2 = x1+dx; w -= dx; } else { x2 = sr.x(); x1 = x2-dx; w += dx; } if ( dy > 0 ) { y1 = sr.y(); y2 = y1+dy; h -= dy; } else { y2 = sr.y(); y1 = y2-dy; h += dy; } if ( dx == 0 && dy == 0 ) return; QSize s( qt_screen->width(), qt_screen->height() ); QRegion alloc = valid_rect ? paintableRegion() : allocatedRegion(); QRegion dAlloc = alloc; QPoint td1 = qt_screen->mapToDevice( QPoint(0,0), s ); QPoint td2 = qt_screen->mapToDevice( QPoint(dx,dy), s ); dAlloc.translate( td2.x()-td1.x(), td2.y()-td1.y() ); QRegion scrollRegion( alloc & dAlloc ); if ( w > 0 && h > 0 ) { QGfx * mygfx=graphicsContext( FALSE ); mygfx->setClipDeviceRegion( scrollRegion ); mygfx->scroll(x2,y2,w,h,x1,y1); delete mygfx; } paintable_region_dirty = TRUE; QPoint gpos = mapToGlobal( QPoint() ); if ( !valid_rect && children() ) { // scroll children setChildrenAllocatedDirty(); QPoint pd( dx, dy ); QObjectListIt it(*children()); register QObject *object; while ( it ) { // move all children object = it.current(); if ( object->isWidgetType() ) { QWidget *w = (QWidget *)object; QPoint oldp = w->pos(); QRect r( w->pos() + pd, w->size() ); w->crect = r; w->updateRequestedRegion( gpos + w->pos() ); QMoveEvent e( r.topLeft(), oldp ); QApplication::sendEvent( w, &e ); } ++it; } } QSize ds( qt_screen->deviceWidth(), qt_screen->deviceHeight() ); scrollRegion = qt_screen->mapFromDevice( scrollRegion, ds ); scrollRegion.translate( -gpos.x(), -gpos.y() ); QRegion update( sr ); update -= scrollRegion; if ( dx ) { int x = x2 == sr.x() ? sr.x()+w : sr.x(); update |= QRect( x, sr.y(), QABS(dx), sr.height() ); } if ( dy ) { int y = y2 == sr.y() ? sr.y()+h : sr.y(); update |= QRect( sr.x(), y, sr.width(), QABS(dy) ); } repaint( update, !testWFlags(WRepaintNoErase) ); if ( !valid_rect && children() ) paint_children( this, update, FALSE ); }