//_______________________________________________________ bool ShadowHelper::acceptWidget( QWidget* widget ) const { // flags if( widget->property( PropertyNames::netWMSkipShadow ).toBool() ) return false; if( widget->property( PropertyNames::netWMForceShadow ).toBool() ) return true; // menus if( isMenu( widget ) ) return true; // combobox dropdown lists if( widget->inherits( "QComboBoxPrivateContainer" ) ) return true; // tooltips if( isToolTip( widget ) && !widget->inherits( "Plasma::ToolTip" ) ) { return true; } // detached widgets if( isDockWidget( widget ) || isToolBar( widget ) ) { return true; } // reject return false; }
bool WindowManager::canDrag(QWidget *widget, QWidget *child, const QPoint &position) { // retrieve child at given position and check cursor again if (child && Qt::ArrowCursor!=child->cursor().shape()) { return false; } /* check against children from which drag should never be enabled, even if mousePress/Move has been passed to the parent */ if (child && (qobject_cast<QComboBox*>(child) || qobject_cast<QProgressBar*>(child))) { return false; } // tool buttons if (QToolButton *toolButton = qobject_cast<QToolButton*>(widget)) { if (dragMode() < WM_DRAG_ALL && !isToolBar(widget->parentWidget())) { return false; } return toolButton->autoRaise() && !toolButton->isEnabled(); } // check menubar if (QMenuBar *menuBar = qobject_cast<QMenuBar*>(widget)) { // check if there is an active action if (menuBar->activeAction() && menuBar->activeAction()->isEnabled()) { return false; } // check if action at position exists and is enabled if (QAction *action = menuBar->actionAt(position)) { if (action->isSeparator()) { return true; } if (action->isEnabled()) { return false; } } // return true in all other cases return true; } bool toolbar=isToolBar(widget); if (dragMode() < WM_DRAG_MENU_AND_TOOLBAR && toolbar) { return false; } /* in MINIMAL mode, anything that has not been already accepted and does not come from a toolbar is rejected */ if (dragMode() < WM_DRAG_ALL) { return toolbar; } /* following checks are relevant only for WD_FULL mode */ // tabbar. Make sure no tab is under the cursor if (QTabBar *tabBar = qobject_cast<QTabBar*>(widget)) { return -1==tabBar->tabAt(position); } /* check groupboxes prevent drag if unchecking grouboxes */ if (QGroupBox *groupBox = qobject_cast<QGroupBox*>(widget)) { // non checkable group boxes are always ok if (!groupBox->isCheckable()) { return true; } // gather options to retrieve checkbox subcontrol rect QStyleOptionGroupBox opt; opt.initFrom(groupBox); if (groupBox->isFlat()) { opt.features |= QStyleOptionFrameV2::Flat; } opt.lineWidth = 1; opt.midLineWidth = 0; opt.text = groupBox->title(); opt.textAlignment = groupBox->alignment(); opt.subControls = (QStyle::SC_GroupBoxFrame | QStyle::SC_GroupBoxCheckBox); if (!groupBox->title().isEmpty()) { opt.subControls |= QStyle::SC_GroupBoxLabel; } opt.state |= (groupBox->isChecked() ? QStyle::State_On : QStyle::State_Off); // check against groupbox checkbox if (groupBox->style()->subControlRect(QStyle::CC_GroupBox, &opt, QStyle::SC_GroupBoxCheckBox, groupBox).contains(position)) { return false; } // check against groupbox label if (!groupBox->title().isEmpty() && groupBox->style()->subControlRect(QStyle::CC_GroupBox, &opt, QStyle::SC_GroupBoxLabel, groupBox).contains(position)) { return false; } return true; } // labels if (QLabel *label = qobject_cast<QLabel*>(widget)) { if (label->textInteractionFlags().testFlag(Qt::TextSelectableByMouse)) { return false; } } // abstract item views QAbstractItemView *itemView(NULL); if ((itemView = qobject_cast<QListView*>(widget->parentWidget())) || (itemView = qobject_cast<QTreeView*>(widget->parentWidget()))) { if (widget == itemView->viewport()) { // QListView if (QFrame::NoFrame!=itemView->frameShape()) { return false; } else if (QAbstractItemView::NoSelection!=itemView->selectionMode() && QAbstractItemView::SingleSelection!=itemView->selectionMode() && itemView->model() && itemView->model()->rowCount()) { return false; } else if (itemView->model() && itemView->indexAt(position).isValid()) { return false; } } } else if ((itemView = qobject_cast<QAbstractItemView*>(widget->parentWidget()))) { if (widget == itemView->viewport()) { // QAbstractItemView if (QFrame::NoFrame!=itemView->frameShape()) { return false; } else if (itemView->indexAt(position).isValid()) { return false; } } } return true; }
bool WindowManager::isDragable(QWidget *widget) { // check widget if (!widget) { return false; } // accepted default types if ((qobject_cast<QDialog*>(widget) && widget->isWindow()) || (qobject_cast<QMainWindow*>(widget) && widget->isWindow()) || qobject_cast<QGroupBox*>(widget)) { return true; } // more accepted types, provided they are not dock widget titles if ((qobject_cast<QMenuBar*>(widget) || qobject_cast<QTabBar*>(widget) || qobject_cast<QStatusBar*>(widget) || isToolBar(widget)) && !isDockWidgetTitle(widget)) { return true; } // flat toolbuttons if (QToolButton *toolButton = qobject_cast<QToolButton*>(widget)) { if (toolButton->autoRaise()) { return true; } } // viewports /* one needs to check that 1/ the widget parent is a scrollarea 2/ it matches its parent viewport 3/ the parent is not blacklisted */ if (QListView *listView = qobject_cast<QListView*>(widget->parentWidget())) { if (listView->viewport() == widget && !isBlackListed(listView)) { return true; } } if (QTreeView *treeView = qobject_cast<QTreeView*>(widget->parentWidget())) { if (treeView->viewport() == widget && !isBlackListed(treeView)) { return true; } } /* catch labels in status bars. this is because of kstatusbar who captures buttonPress/release events */ if (QLabel *label = qobject_cast<QLabel*>(widget)) { if (label->textInteractionFlags().testFlag(Qt::TextSelectableByMouse)) { return false; } QWidget *parent = label->parentWidget(); while (parent) { if (qobject_cast<QStatusBar*>(parent)) { return true; } parent = parent->parentWidget(); } } return false; }