MPlainWindow::MPlainWindow(const MAbstractInputMethodHost *newHost, QWidget *parent) : MWindow(parent) , host(newHost) { if (m_instance) qFatal("There can be only one instance of MPlainWindow"); m_instance = this; // This *does not* prevent plugins from activating multitouch through // QGraphicsItem::setAcceptTouchEvents, as the first (enabling) call to // that method *will* set the WA_AcceptTouchEvents attribute on all // attached viewports (this was probably done in Qt to add some // convenience for sloppy programmers). // // Setting this attribute explicitely here is supposed to guard against // changes in above mentioned (undocumented!) "convenience", as this is // what the documentation suggests [1]. // // [1] http://doc.trolltech.com/4.6/qtouchevent.html#enabling-touch-events if (MGConfItem(MultitouchSettings).value().toBool()) { setAttribute(Qt::WA_AcceptTouchEvents); } ungrabGesture(Qt::TapAndHoldGesture); ungrabGesture(Qt::PinchGesture); ungrabGesture(Qt::PanGesture); ungrabGesture(Qt::SwipeGesture); ungrabGesture(Qt::TapGesture); }
/*! \brief Constructor Configures scroll area settings and resets internal stares of widget. Gets the width of device. \param parent The parent of scroll area widget */ CalenDayContentScrollArea::CalenDayContentScrollArea(QGraphicsItem *parent) : HbScrollArea(parent), mPanDayDirection(ECalenPanNotSet), mIsMoving(false), mMoveDirection(ECalenScrollNoDayChange), mDisallowedDirection(ECalenScrollNoDayChange) { #ifdef CALENDAYVIEW_PANNING_ENABLED grabGesture(Qt::PanGesture); ungrabGesture(Qt::SwipeGesture); #else grabGesture(Qt::SwipeGesture); ungrabGesture(Qt::PanGesture); #endif // Get the width of content area and orientation of screen mContentWidth = CalenDayUtils::instance()->contentWidth(); mOrientation = CalenDayUtils::instance()->orientation(); // Fix the width of scroll area setMinimumWidth(mContentWidth); setMaximumWidth(mContentWidth); // Connect to main window's orientationChanged SIGNAL to handle orientation // switching connect(CalenDayUtils::instance()->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(orientationChanged(Qt::Orientation))); }
MBanner::MBanner() : MSceneWindow(new MSceneWindowPrivate, new MBannerModel, MSceneWindow::Banner) { ungrabGesture(Qt::PanGesture); ungrabGesture(Qt::TapGesture); ungrabGesture(Qt::TapAndHoldGesture); ungrabGesture(Qt::PinchGesture); ungrabGesture(Qt::SwipeGesture); }
/*! Updates child graphics items to represent current state and content. \note It is a good habit to reuse child items as much as possible as this improves performance, especially when item recycling is used. Most of the HbAbstractViewItem derived classes inside Hb library are optimised for performance. Layout files are loaded only if child items are created or deleted. Loading layout files is triggered by calling HbWidget::repolish(). Classes deriving from HbAbstractViewItem outside Hb, should either always call explicitly repolish() or if they are also optimised for performance only when child items are created or deleted in the custom view item. Here is an example of custom view item that reuses its child items. The custom view item does not create or delete child items. \snippet{ultimatecodesnippet/customlistviewitem.cpp,2} \sa HbWidget::polish() */ void HbAbstractViewItem::updateChildItems() { HB_SDD(HbAbstractViewItem); int itemType = d->modelItemType(); if (itemType != d->mModelItemType) { d->mModelItemType = itemType; d->mItemsChanged = true; d->themingPending = true; } /* Summary of background and frame handling: d->mBackground is read from Qt::BackgroundRole of model d->mBackgroundItem is created from d-mBackground (Qt::BackgroundRole), if this is HbIcon or QBrush. If d->mBackgroundItem does not exist, d->mFrame is created from d-mBackground (Qt::BackgroundRole), if this is HbFrameBackground otherwise it either is created from sd->mDefaultFrame, not created at all or from system default. */ // background QVariant currentBackground = d->mIndex.data(Qt::BackgroundRole); if (currentBackground != d->mBackground) { d->mBackground = currentBackground; if (currentBackground.canConvert<HbIcon>() || currentBackground.canConvert<QBrush>()) { if (!d->mBackgroundItem) { d->mItemsChanged = true; d->mBackgroundItem = style()->createPrimitive(HbStyle::P_ItemViewItem_background, this); delete d->mFrame; d->mFrame = 0; } } else if (currentBackground.canConvert<HbFrameBackground>()) { if (!d->mFrame) { d->mItemsChanged = true; d->mFrame = style()->createPrimitive(HbStyle::P_ItemViewItem_frame, this); delete d->mBackgroundItem; d->mBackgroundItem = 0; } } else if (d->mBackgroundItem) { d->mItemsChanged = true; delete d->mBackgroundItem; d->mBackgroundItem = 0; } } // frame if (!d->mBackgroundItem) { if ( d->mModelItemType == Hb::ParentItem || d->mModelItemType == Hb::SeparatorItem || ( d->mModelItemType == Hb::StandardItem && ( d->mBackground.canConvert<HbFrameBackground>() || sd->mDefaultFrame.frameGraphicsName().length() > 0 || sd->mDefaultFrame.isNull()))) { if (!d->mFrame) { d->mItemsChanged = true; d->mFrame = style()->createPrimitive(HbStyle::P_ItemViewItem_frame, this); } } else if (d->mFrame) { d->mItemsChanged = true; delete d->mFrame; d->mFrame = 0; } } GraphicsItemFlags itemFlags = flags(); Qt::ItemFlags indexFlags = d->mIndex.flags(); if ((indexFlags & Qt::ItemIsEnabled) && sd->mItemView && sd->mItemView->isEnabled()) { if (!(itemFlags & QGraphicsItem::ItemIsFocusable)) { itemFlags |= QGraphicsItem::ItemIsFocusable; setFocusPolicy(sd->mPrototype->focusPolicy()); setProperty("state", "normal"); grabGesture(Qt::TapGesture); } } else { if (itemFlags & QGraphicsItem::ItemIsFocusable) { itemFlags &= ~QGraphicsItem::ItemIsFocusable; setFocusPolicy(Qt::NoFocus); setProperty("state", "disabled"); ungrabGesture(Qt::TapGesture); } } // selection HbAbstractItemView::SelectionMode selectionMode = HbAbstractItemView::NoSelection; if (sd->mItemView) { selectionMode = sd->mItemView->selectionMode(); } bool previousSelectable = itemFlags & QGraphicsItem::ItemIsSelectable; bool itemSelectable = false; if (indexFlags & Qt::ItemIsSelectable && selectionMode != HbAbstractItemView::NoSelection && indexFlags & Qt::ItemIsEnabled) { itemFlags |= QGraphicsItem::ItemIsSelectable; itemSelectable = true; } else { itemFlags &= ~QGraphicsItem::ItemIsSelectable; } if (previousSelectable != itemSelectable) { if (itemSelectable) { if (!d->mSelectionItem) { d->mItemsChanged = true; d->mSelectionItem = style()->createPrimitive(HbStyle::P_ItemViewItem_selection, this); } } else { d->mItemsChanged = true; delete d->mSelectionItem; d->mSelectionItem = 0; } } setFlags(itemFlags); // multiselection area if ( itemSelectable && selectionMode == HbAbstractItemView::MultiSelection) { if (!d->mMultiSelectionTouchArea) { d->mItemsChanged = true; d->mMultiSelectionTouchArea = style()->createPrimitive(HbStyle::P_ItemViewItem_touchmultiselection, this); } } else if (d->mMultiSelectionTouchArea) { d->mItemsChanged = true; delete d->mMultiSelectionTouchArea; d->mMultiSelectionTouchArea = 0; } // items visibility or items content has really changed updatePrimitives(); if (!d->mContentChangedSupported || d->mItemsChanged) { updateGeometry(); // ensures that sizehint is calculated again in case items have been created or deleted d->mRepolishRequested = true; // handle QEvent::Polish & QEvent::LayoutRequest event itself in ::sizeHint() as our performance is slightly better // (saving a layoutrequest and going event loop through twice) if (sd->mItemView && sd->mItemView->isScrolling()) { d->mHandlingRepolishSynchronously = true; } repolish(); d->mHandlingRepolishSynchronously = false; } d->mItemsChanged = false; }
/*! \fn void CSizeGrip::mousePressEvent(QMouseEvent * event) Receives the mouse press events for the widget, and primes the resize operation. The mouse press event is passed in the \a event parameter. */ void CSizeGrip::mousePressEvent(QMouseEvent * e) { ungrabGesture(Qt::TapAndHoldGesture); if (e->button() != Qt::LeftButton) { QWidget::mousePressEvent(e); return; } QWidget *tlw = qt_sizegrip_topLevelWidget(); p = e->globalPos(); gotMousePress = true; r = tlw->geometry(); #ifdef Q_WS_X11 #if QT_VERSION >= 0x050000 // Use a native X11 sizegrip for "real" top-level windows if supported. if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint) && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.message_type = ATOM(_NET_WM_MOVERESIZE); xev.xclient.display = X11->display; xev.xclient.window = tlw->winId(); xev.xclient.format = 32; xev.xclient.data.l[0] = e->globalPos().x(); xev.xclient.data.l[1] = e->globalPos().y(); if (atBottom()) xev.xclient.data.l[2] = atLeft() ? 6 : 4; // bottomleft/bottomright else xev.xclient.data.l[2] = atLeft() ? 0 : 2; // topleft/topright xev.xclient.data.l[3] = Button1; xev.xclient.data.l[4] = 0; XUngrabPointer(X11->display, X11->time); XSendEvent(X11->display, QX11Info::appRootWindow(x11Info().screen()), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); return; } #endif #endif // Q_WS_X11 #ifdef Q_WS_WIN #if QT_VERSION >= 0x050000 if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { uint orientation = 0; if (atBottom()) orientation = atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT; else orientation = atLeft() ? SZ_SIZETOPLEFT : SZ_SIZETOPRIGHT; ReleaseCapture(); PostMessage(tlw->winId(), WM_SYSCOMMAND, orientation, 0); return; } #endif #endif // Q_WS_WIN // Find available desktop/workspace geometry. QRect availableGeometry; bool hasVerticalSizeConstraint = true; bool hasHorizontalSizeConstraint = true; if (tlw->isWindow()) availableGeometry = QApplication::desktop()->availableGeometry(tlw); else { const QWidget *tlwParent = tlw->parentWidget(); // Check if tlw is inside QAbstractScrollArea/QScrollArea. // If that's the case tlw->parentWidget() will return the viewport // and tlw->parentWidget()->parentWidget() will return the scroll area. #ifndef QT_NO_SCROLLAREA QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(tlwParent->parentWidget()); if (scrollArea) { hasHorizontalSizeConstraint = scrollArea->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; hasVerticalSizeConstraint = scrollArea->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; } #endif // QT_NO_SCROLLAREA availableGeometry = tlwParent->contentsRect(); } // Find frame geometries, title bar height, and decoration sizes. const QRect frameGeometry = tlw->frameGeometry(); const int titleBarHeight = qMax(tlw->geometry().y() - frameGeometry.y(), 0); const int bottomDecoration = qMax(frameGeometry.height() - tlw->height() - titleBarHeight, 0); const int leftRightDecoration = qMax((frameGeometry.width() - tlw->width()) / 2, 0); // Determine dyMax depending on whether the sizegrip is at the bottom // of the widget or not. if (atBottom()) { if (hasVerticalSizeConstraint) dyMax = availableGeometry.bottom() - r.bottom() - bottomDecoration; else dyMax = INT_MAX; } else { if (hasVerticalSizeConstraint) dyMax = availableGeometry.y() - r.y() + titleBarHeight; else dyMax = -INT_MAX; } // In RTL mode, the size grip is to the left; find dxMax from the desktop/workspace // geometry, the size grip geometry and the width of the decoration. if (atLeft()) { if (hasHorizontalSizeConstraint) dxMax = availableGeometry.x() - r.x() + leftRightDecoration; else dxMax = -INT_MAX; } else { if (hasHorizontalSizeConstraint) dxMax = availableGeometry.right() - r.right() - leftRightDecoration; else dxMax = INT_MAX; } }
EmulatedCardWindow::~EmulatedCardWindow() { ungrabGesture(Qt::TapGesture); delete m_keyboardButton; delete m_gestureStrip; delete m_statusBar; }