void MovableTableWidget::paintEvent(QPaintEvent *e) { QTableWidget::paintEvent(e); if (!viewport()->paintingActive() && m_lineRow != -1 && columnCount() > 0 && rowCount() > 0) { int lineY = (m_lineRow < rowCount() ? visualItemRect(item(m_lineRow, 0)).top()-1 : visualItemRect(item(rowCount()-1, 0)).bottom()+1); int lineX = visualItemRect(item(0, columnCount()-1)).right(); QPainter* painter = new QPainter(this->viewport()); painter->setPen(QPen(QBrush(Qt::black), 3)); painter->drawLine(QPoint(0, lineY), QPoint(lineX, lineY)); painter->end(); } }
void ExtendedTableWidget::dragMoveEvent(QDragMoveEvent *event) { if (event->proposedAction() & (Qt::CopyAction | Qt::MoveAction)) { event->acceptProposedAction(); } QTableWidgetItem *item = itemAt(event->pos()); if (item) { if (PhoneNumber::phone_re().exactMatch(item->text())) { event->accept(visualItemRect(item)); } else { event->ignore(visualItemRect(item)); } } else { event->ignore(); } }
void dragTarget::mouseMoveEvent ( QMouseEvent *event ) //gestisce il trascinamento all'interno della lista stessa { if ( event -> buttons() == Qt::LeftButton && itemAt ( event -> pos() ) != NULL ) //se è iniziato un trascinamento con il tasto destro inizio a creare il mime { QTreeWidgetItem *current = itemAt(event -> pos()); showIndicator(visualItemRect(current).bottom()); if( this -> selectedItems().size() != 0 ) { int size = this -> selectedItems().size(); QList<QTreeWidgetItem*> selectedItems = this -> selectedItems(); for(int i = 0; i < size; i++) this -> setItemSelected(selectedItems[i], false); //deseleziona tutti gli altri elementi... evita un crash //NON SUPPORTIAMO ANCORA IL TRASCINAMENTO MULTIPLO } QDrag *drag = new QDrag ( this ); QMimeData * mimeData = new QMimeData; //QList<QTreeWidgetItem*> selectedItems = this -> selectedItems(); QTreeWidgetItem *toDrag = itemAt ( event -> pos() ); currentItem = toDrag; this -> setItemSelected ( toDrag, true ); drag -> setPixmap ( ( toDrag -> icon ( 0 ) ).pixmap ( 32,32 ) ); //recupero l'icona mimeData -> setImageData ( ( toDrag -> icon ( 0 ) ).pixmap ( 32,32 ) ); QString filePath = toDrag -> text ( 1 ) + toDrag -> text ( 0 ); //ricostruisco il percorso filePath.append ( "!*mimetosend:"+toDrag -> text ( 2 ) ); QByteArray mimeToSend = filePath.toAscii(); mimeData -> setData ( "aku/newarchive-fromHere",mimeToSend ); drag -> setMimeData ( mimeData ); drag -> exec ( Qt::MoveAction ); } else { hideIndicator(); event -> ignore(); return; } }
void lmcUserTreeWidget::dragMoveEvent(QDragMoveEvent* event) { QTreeWidget::dragMoveEvent(event); QTreeWidgetItem* item = itemAt(event->pos()); bool accept = false; if(dragUser) { if(item && dynamic_cast<lmcUserTreeWidgetGroupItem*>(item) && visualItemRect(item).contains(event->pos(), true)) accept = true; } else if(dragGroup) { if(!item || (dynamic_cast<lmcUserTreeWidgetGroupItem*>(item) && !visualItemRect(item).contains(event->pos(), true))) accept = true; } accept ? event->accept() : event->ignore(); }
void OptionListWidget::arrangeIcons() { int maxWidth = 0; setWrapping(false); QListWidgetItem* ic; int startY = 5; for (int cc = 0; cc < count(); ++cc) { ic = item(cc); QRect ir = visualItemRect(ic); maxWidth = qMax(ir.width(), maxWidth); } setMaximumWidth(maxWidth+16); setResizeMode(QListView::Fixed); #ifdef _WIN32 int scrollBarWidth = 0; QList<QScrollBar*> scrollBars = findChildren<QScrollBar*>(); for (int cc = 0; cc < scrollBars.count(); ++cc) { if (scrollBars.at(cc)->orientation() == Qt::Vertical) { scrollBarWidth = scrollBars.at(cc)->height(); break; } } #else int scrollBarWidth = maxWidth; #endif int startX = qMax((viewport()->width() - scrollBarWidth) / 2, 0); for (int cc = 0; cc < count(); ++cc) { ic = item(cc); QRect ir = visualItemRect(ic); #ifdef _WIN32 setPositionForIndex(QPoint(qMax(startX - ir.width() / 2, 0), startY), indexFromItem(ic)); #else int moveW = (maxWidth - ir.width()) / 2; setPositionForIndex(QPoint(moveW + startX, startY), indexFromItem(ic)); #endif startY += ir.height()+5; } }
void wavrImagePicker::mouseMoveEvent(QMouseEvent* e) { QTableWidget::mouseMoveEvent(e); QTableWidgetItem* currentItem = itemAt(e->pos()); if(currentItem != hoverItem) { hoverItem = currentItem; if(hoverItem) update(visualItemRect(hoverItem)); } }
void wavrImagePicker::paintEvent(QPaintEvent* e) { QTableWidget::paintEvent(e); // If mouse is hovered over an item, draw a border around it if(hoverItem) { QStyleOptionFrame opt; opt.rect = visualItemRect(hoverItem); opt.rect.adjust(0, 1, -2, -1); QPainter painter(viewport()); style()->drawPrimitive(QStyle::PE_FrameButtonBevel, &opt, &painter); } }
void lmcUserTreeWidget::mouseReleaseEvent(QMouseEvent* event) { QTreeWidget::mouseReleaseEvent(event); QPoint pos = event->pos(); lmcUserTreeWidgetItem* item = (lmcUserTreeWidgetItem*)itemAt(pos); if(item && checkable() && item->checkBoxRect(visualItemRect(item)).contains(pos)) { // toggle checkstate if(item->checkState(0) == Qt::Checked) item->setCheckState(0, Qt::Unchecked); else item->setCheckState(0, Qt::Checked); } }
QRect KCompletionBox::calculateGeometry() const { QRect visualRect; if (count() == 0 || !(visualRect = visualItemRect(item(0))).isValid()) return QRect(); int x = 0, y = 0; int ih = visualRect.height(); int h = qMin( 15 * ih, (int) count() * ih ) + 2*frameWidth(); int w = (d->m_parent) ? d->m_parent->width() : KListWidget::minimumSizeHint().width(); w = qMax( KListWidget::minimumSizeHint().width(), w ); //### M.O.: Qt4 doesn't actually honor SC_ComboBoxListBoxPopup ??? #if 0 //If we're inside a combox, Qt by default makes the dropdown // as wide as the combo, and gives the style a chance // to adjust it. Do that here as well, for consistency const QObject* combo; if ( d->m_parent && (combo = d->m_parent->parent() ) && qobject_cast<QComboBox*>(combo) ) { const QComboBox* cb = static_cast<const QComboBox*>(combo); //Expand to the combo width w = qMax( w, cb->width() ); QPoint parentCorner = d->m_parent->mapToGlobal(QPoint(0, 0)); QPoint comboCorner = cb->mapToGlobal(QPoint(0, 0)); //We need to adjust our horizontal position to also be WRT to the combo x += comboCorner.x() - parentCorner.x(); //The same with vertical one y += cb->height() - d->m_parent->height() + comboCorner.y() - parentCorner.y(); //Ask the style to refine this a bit QRect styleAdj = style().querySubControlMetrics(QStyle::CC_ComboBox, cb, QStyle::SC_ComboBoxListBoxPopup, QStyleOption(x, y, w, h)); //QCommonStyle returns QRect() by default, so this is what we get if the //style doesn't implement this if (!styleAdj.isNull()) return styleAdj; } #endif return QRect(x, y, w, h); }
void lmcUserTreeWidget::contextMenuEvent(QContextMenuEvent* event) { QTreeWidget::contextMenuEvent(event); QTreeWidgetItem* item = itemAt(event->pos()); QPoint pos = event->globalPos(); if(item && event->reason() != QContextMenuEvent::Mouse) { QRect itemRect = visualItemRect(item); pos = itemRect.bottomLeft(); pos.ry() += itemRect.height(); pos = mapToGlobal(pos); } emit itemContextMenu(item, pos); }
bool BasketTreeListView::event(QEvent *e) { if (e->type() == QEvent::ToolTip) { QHelpEvent *he = static_cast<QHelpEvent *>(e); QTreeWidgetItem *item = itemAt(he->pos()); BasketListViewItem* bitem = dynamic_cast<BasketListViewItem*>(item); if (bitem && bitem->isAbbreviated()) { QRect rect = visualItemRect(bitem); QToolTip::showText(rect.topLeft(), bitem->basket()->basketName(), viewport(), rect); } return true; } return QTreeWidget::event(e); }
// returns the selected item whose checkbox lies under 'pos' // returns 0 if not selected, no item at pos, or does not fit inside checkbox bool QMultiSelectWidget::isCheckBoxUnderPosition(const QPoint &pos) { QListWidgetItem* item = itemAt(pos); if (item) { // with the help of styles, check if checkbox rect contains 'pos' QStyleOptionButton opt; opt.QStyleOption::operator=(viewOptions()); opt.rect = visualItemRect(item); QRect r = style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt); // assure that the item is also selected if (r.contains(pos)) { return true; } } return false; }
QListWidgetItem* PluginListWidget::selectedCheckStateItem(const QPoint& pos){ QListWidgetItem* item = itemAt(pos); if (item) { // with the help of styles, check if checkbox rect contains 'pos' QStyleOptionButton opt; opt.QStyleOption::operator=(viewOptions()); opt.rect = visualItemRect(item); QRect r = style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt); // assure that the item is also selected if (selectedItems().contains(item) && r.contains(pos)) { return item; } } return 0; }
int MovableTableWidget::dropRow(QPoint pos) { int result = rowAt(pos.y()); if (result == -1) { result = rowCount(); } else if (columnCount() > 0) { QRect itemRect = visualItemRect(item(result, 0)); if (itemRect.bottom() - pos.y() < pos.y() - itemRect.top()) { result++; } } return result; }
void PageLayoutsWidget::arrangeIcons() { QListWidgetItem* ic; int startY = 5; int startX = 5; setResizeMode(QListView::Fixed); int maxSizeY = 0; for (int cc = 0; cc < count(); ++cc) { ic = item(cc); QRect ir = visualItemRect(ic); setPositionForIndex(QPoint(startX, startY), indexFromItem(ic)); startX += ir.width()+5; maxSizeY = qMax(maxSizeY, ir.height()); } maxX = startX; maxY = maxSizeY+10; }
void ListView::showPopup(QTreeWidgetItem *item, QPoint p) { if (item == NULL) return; ProcessMenuParam *mp = getMenu(item); if (mp == NULL) return; if (p.isNull()){ QRect rc = visualItemRect(item); p = QPoint(rc.x() + rc.width() / 2, rc.y() + rc.height() / 2); p = viewport()->mapToGlobal(p); } mp->key = 0; Event eMenu(EventProcessMenu, mp); QMenu *menu = (QMenu*)eMenu.process(); if (menu){ setCurrentItem(item); menu->popup(p); } }
void GomVodTreeView::mouseMoveEvent(QMouseEvent * event) { auto item = itemAt(event->pos()); for(auto & topItem : topLevelItems_) for(auto subitem : topItem->children()) { bool showSpoilers = subitem == item; if(showSpoilers) { auto rect = fontMetrics().boundingRect( visualItemRect(item), Qt::AlignVCenter, subitem->text(0)); rect.setWidth(500); showSpoilers &= rect.contains(event->pos()); } subitem->setSpoilerShown(showSpoilers); } QTreeWidget::mouseMoveEvent(event); }
bool TreeWidget::viewportEvent(QEvent* event) { if (event->type() == QEvent::ToolTip) { QHelpEvent* he = static_cast<QHelpEvent*>(event); TreeItem* item = static_cast<TreeItem*>(itemAt(he->pos())); if (item && !item->parentItem() && !item->toolTip(0).isEmpty()) { QStyleOptionViewItem opt = viewOptions(); opt.icon = item->icon(0); opt.rect = visualItemRect(item); opt.features |= QStyleOptionViewItem::HasDecoration; QRect rect = style()->subElementRect(QStyle::SE_ItemViewItemDecoration, &opt, this); if (rect.contains(he->pos())) { #if QT_VERSION >= 0x050200 QToolTip::showText(he->globalPos(), item->toolTip(0), this, rect, 1250); #else QToolTip::showText(he->globalPos(), item->toolTip(0), this, rect); #endif } } return true; } return QTreeWidget::viewportEvent(event); }
void My_Layers::mousePressEvent(QMouseEvent *e) { QPoint point = e->pos(); //Verifico che point sia dentro una casella della tabella QRect visible_area = visualItemRect(item(rowCount()-1,0)); if (point.y() > visible_area.bottom()) return; if (e->button() == Qt::LeftButton) { int col = columnAt(point.x()); switch(tipo_tabella) { case 'V': switch(col) { case 0: break; case 1: toogle_select(row(itemAt(point))); break; case 2: toogle_show(row(itemAt(point))); break; } break; case 'P': if(col == 1) toogle_print(row(itemAt(point))); break; case 'G': if(col == 1) toogle_gerber(row(itemAt(point))); break; } } }
void CWizDocumentListView::startDrag(Qt::DropActions supportedActions) { Q_UNUSED(supportedActions); CWizStdStringArray arrayGUID; QList<QListWidgetItem*> items = selectedItems(); foreach (QListWidgetItem* it, items) { if (CWizDocumentListViewItem* item = dynamic_cast<CWizDocumentListViewItem*>(it)) { // not support drag group document currently if (item->document().strKbGUID != m_dbMgr.db().kbGUID()) return; arrayGUID.push_back((item->document().strGUID)); } } if (arrayGUID.empty()) return; CString strGUIDs; ::WizStringArrayToText(arrayGUID, strGUIDs, ";"); QDrag* drag = new QDrag(this); QMimeData* mimeData = new QMimeData(); mimeData->setData(WIZNOTE_MIMEFORMAT_DOCUMENTS, strGUIDs.toUtf8()); drag->setMimeData(mimeData); // FIXME: need deal with more then 1 drag event! if (items.size() == 1) { QRect rect = visualItemRect(items[0]); drag->setPixmap(QPixmap::grabWindow(winId(), rect.x(), rect.y(), rect.width(), rect.height())); } drag->exec(); }
QSize My_Layers::right_size() { QRect r = visualItemRect(item(LAYER_DATA_PCB_COUNT - 1, 0)); return QSize(r.left(), r.bottom() + 4); //Di solito lo spessore della griglia è di 4 pixel di margine }
void KeepassGroupView::dragMoveEvent(QDragMoveEvent* event){ if(DragType==EntryDrag){ entryDragMoveEvent(event); return; } if(DragItem){ GroupViewItem* Item=(GroupViewItem*)itemAt(event->pos()); if(!Item){ if(LastHoverItem){ LastHoverItem->setBackgroundColor(0,QApplication::palette().color(QPalette::Base)); LastHoverItem=NULL; } if(InsLinePos!=-1){ int RemoveLine=InsLinePos; InsLinePos=-1; viewport()->update(QRegion(0,RemoveLine-2,viewport()->width(),4)); } event->acceptProposedAction(); return; } if(Item==DragItem || Item==SearchResultItem){ event->ignore(); return; } if(!db->isParent(DragItem->GroupHandle,Item->GroupHandle)){ QRect ItemRect=visualItemRect(Item); if(event->pos().y()>ItemRect.y()+2 && event->pos().y()<ItemRect.y()+ItemRect.height()-2){ if(InsLinePos!=-1){ int RemoveLine=InsLinePos; InsLinePos=-1; viewport()->update(QRegion(0,RemoveLine-2,viewport()->width(),4)); } if(LastHoverItem != Item){ if(LastHoverItem){ LastHoverItem->setBackgroundColor(0,QApplication::palette().color(QPalette::Base)); } Item->setBackgroundColor(0,QApplication::palette().color(QPalette::Highlight)); LastHoverItem=Item; } } else{ if(LastHoverItem){ LastHoverItem->setBackgroundColor(0,QApplication::palette().color(QPalette::Base)); LastHoverItem=NULL; } if(InsLinePos!=-1){ int RemoveLine=InsLinePos; InsLinePos=-1; viewport()->update(QRegion(0,RemoveLine-2,viewport()->width(),4)); } if(event->pos().y()>ItemRect.y()+2){ InsLinePos=ItemRect.y()+ItemRect.height(); } else{ InsLinePos=ItemRect.y(); } InsLineStart=ItemRect.x(); viewport()->update(QRegion(0,InsLinePos-2,viewport()->width(),4)); } event->acceptProposedAction(); return; } } event->ignore(); }
void KeepassGroupView::dropEvent( QDropEvent * event ){ if(LastHoverItem){ LastHoverItem->setBackgroundColor(0,QApplication::palette().color(QPalette::Base)); LastHoverItem->setForeground(0,QBrush(QApplication::palette().color(QPalette::Text))); } if(DragType==EntryDrag){ entryDropEvent(event); return; } if(InsLinePos!=-1){ int RemoveLine=InsLinePos; InsLinePos=-1; viewport()->update(QRegion(0,RemoveLine-2,viewport()->width(),4)); } GroupViewItem* Item=(GroupViewItem*)itemAt(event->pos()); if(!Item){ qDebug("Append at the end"); db->moveGroup(DragItem->GroupHandle,NULL,-1); if(DragItem->parent()){ DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem)); } else{ takeTopLevelItem(indexOfTopLevelItem(DragItem)); } insertTopLevelItem(topLevelItemCount(),DragItem); if(topLevelItemCount()>1){ if(topLevelItem(topLevelItemCount()-2)==SearchResultItem){ takeTopLevelItem(topLevelItemCount()-2); insertTopLevelItem(topLevelItemCount(),SearchResultItem); } } emit fileModified(); } else{ if (DragItem->GroupHandle==Item->GroupHandle) return; QRect ItemRect=visualItemRect(Item); if(event->pos().y()>ItemRect.y()+2 && event->pos().y()<ItemRect.y()+ItemRect.height()-2){ qDebug("Append as child of '%s'",((char*)Item->text(0).toUtf8().data())); db->moveGroup(DragItem->GroupHandle,Item->GroupHandle,-1); if(DragItem->parent()){ DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem)); } else{ takeTopLevelItem(indexOfTopLevelItem(DragItem)); } Item->insertChild(Item->childCount(),DragItem); emit fileModified(); } else{ if(event->pos().y()>ItemRect.y()+2){ qDebug("Insert behind sibling '%s'",((char*)Item->text(0).toUtf8().data())); if(DragItem->parent()){ DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem)); } else{ takeTopLevelItem(indexOfTopLevelItem(DragItem)); } if(Item->parent()){ int index=Item->parent()->indexOfChild(Item)+1; db->moveGroup(DragItem->GroupHandle,((GroupViewItem*)Item->parent())->GroupHandle,index); Item->parent()->insertChild(index,DragItem); } else{ int index=indexOfTopLevelItem(Item)+1; db->moveGroup(DragItem->GroupHandle,NULL,index); insertTopLevelItem(index,DragItem); } emit fileModified(); } else{ qDebug("Insert before sibling '%s'",((char*)Item->text(0).toUtf8().data())); if(DragItem->parent()){ DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem)); } else{ takeTopLevelItem(indexOfTopLevelItem(DragItem)); } if(Item->parent()){ int index=Item->parent()->indexOfChild(Item); db->moveGroup(DragItem->GroupHandle,((GroupViewItem*)Item->parent())->GroupHandle,index); Item->parent()->insertChild(index,DragItem); } else{ int index=indexOfTopLevelItem(Item); db->moveGroup(DragItem->GroupHandle,NULL,index); insertTopLevelItem(index,DragItem); } emit fileModified(); } } } }
void TraceWidget::sideBarPaintEvent(QPaintEvent * event) { // don't paint anything if there are no cycles if (cycle_.first < 0 || cycle_.second < 0) return; QPainter painter(cbar_); QRect rct, first_rct, last_rct; int first_id = -1, last_id = -1; for (int i = 0; i < count(); ++i) { rct = visualItemRect(item(i)); if (rct.top() > event->rect().bottom()) break; if (rct.bottom() <= event->rect().top()) continue; if (i >= cycle_.second && i <= cycle_.first) { if (first_id == -1) { first_id = i; first_rct = rct; } last_id = i; last_rct = rct; } } // draw nothing if (first_id == -1) return; QList<QPolygon> lines; QPolygon line; // start of the cycle if (last_id == cycle_.first) { const int base_off = last_rct.top() + (last_rct.height() - cycleBaseSize) / 2; const int line_off = last_rct.top() + last_rct.height() / 2; line.push_back(QPoint(cycleBarWidth - 2, base_off)); line.push_back(QPoint(cycleBarWidth - 2, base_off + cycleBaseSize)); lines.append(line); line.clear(); line.push_back(QPoint(cycleBarWidth - 2, line_off)); line.push_back(QPoint(cycleLeftOffset, line_off)); } else { line.push_back(QPoint(cycleLeftOffset, last_rct.bottom())); } const int line_off = first_rct.top() + first_rct.height() / 2; // end if (first_id == cycle_.second) { line.push_back(QPoint(cycleLeftOffset, line_off)); line.push_back(QPoint(cycleBarWidth - 2, line_off)); lines.append(line); // arrow line.clear(); line.push_back(QPoint(cycleBarWidth - 4, line_off - 2)); line.push_back(QPoint(cycleBarWidth - 2, line_off)); line.push_back(QPoint(cycleBarWidth - 4, line_off + 2)); lines.append(line); } else { line.push_back(QPoint(cycleLeftOffset, first_rct.top())); lines.append(line); } QPen pen; painter.setPen(pen); foreach(QPolygon itr, lines) { painter.drawPolyline(itr); }
void dragTarget::dragMoveEvent ( QDragMoveEvent *event ) { if ( event -> mouseButtons() == Qt::LeftButton ) { //eseguiamo lo scrollDown se ci troviamo alla fine della lista if(event -> pos().y() >viewport() -> height() - 50 && event -> pos().y() <viewport() -> height()) //se ci troviamo alla fine della lista iniziamo le operazioni di scroll automatico { tempScroll = itemAt(event -> pos()); connect(scrollDownTimer, SIGNAL(timeout()), this, SLOT(scrollDown())); scrollDownTimer -> start(100); } else { disconnect(scrollDownTimer, SIGNAL(timeout()), this, SLOT(scrollDown())); scrollDownTimer -> stop(); } //eseguiamo lo scrollUp se ci troviamo all'inizio della lista if(event -> pos().y() < viewport() -> y() + 20 && event -> pos().y() > 0) //se ci troviamo all'inizio della lista iniziamo le operazioni di scroll automatico { tempScroll = itemAt(event -> pos()); connect(scrollUpTimer, SIGNAL(timeout()), this, SLOT(scrollUp())); scrollUpTimer -> start(100); } else { disconnect(scrollUpTimer, SIGNAL(timeout()), this, SLOT(scrollUp())); scrollUpTimer -> stop(); } if(itemAt(event -> pos()) != NULL) { QTreeWidgetItem *current = itemAt(event -> pos() ); showIndicator(visualItemRect(current).bottom()); if(indicatorToRestore != NULL && itemAt(event -> pos()) != indicatorToRestore) { delete indicatorToRestore; indicatorToRestore = NULL; } } else { if(indicatorToRestore != NULL) delete indicatorToRestore; indicatorToRestore = new QTreeWidgetItem(this); scrollToItem(indicatorToRestore); showIndicator(visualItemRect(topLevelItem(topLevelItemCount()-1)).bottom()); } //------------------------------------------iniziano le operazioni di allocazione-----------------------------------------------------------------------------// QList<QTreeWidgetItem*> selectedItems = this -> selectedItems(); //mi serve per accertarmi che l'utente non voglia trascinare un file sul file stesso if ( selectedItems.size() == 0 ) //se non ci sono elementi selezionati { //*******************************************************************// if ( itemAt ( event -> pos() ) != NULL && itemAt ( event -> pos() ) -> text ( 2 ) == "inode/directory" ) //se voglio trascinare su un altro elemento che è una cartella, acconsento, TODO ma solo se la cartella non contiene già un elemento uguale { subLevel = true; padre = itemAt ( event -> pos() ); event -> acceptProposedAction(); } else { if ( itemAt ( event -> pos() ) != NULL && itemAt ( event -> pos() ) -> text ( 2 ) !="inode/directory" ) { if(itemAt( event -> pos() ) -> text(0) == "") { //possiamo trascinare sull'indicatore subLevel = false; event -> acceptProposedAction(); } else event -> ignore();//se voglio trascinare su un elemento che non è una cartella, nego } else //se voglio semplicemente trascinare un nuovo elemento acconsento { subLevel = false; event -> acceptProposedAction(); } } //*************************************************************// } //fine dell'if selectedItems.size() else //se ci sono elementi selezionati mi accerto di non trascinare su me stesso e di non trascinarmi in un mio figlio { if ( itemAt ( event -> pos() ) != NULL && itemAt ( event -> pos() ) -> text ( 2 ) == "inode/directory" && itemAt ( event -> pos() ) != selectedItems[0] ) //se voglio trascinare su un elemento che è una cartella e non è l'elemento stesso { QString nomeFile; //recupero il nome file dell'elemento per accertarmi di non trascinarmi in un mio figlio //QStringList formati = event -> mimeData() -> formats(); if(event -> mimeData()->hasFormat("aku/newarchive")) nomeFile = event -> mimeData()->data ( "aku/newarchive" ); else nomeFile = event -> mimeData()->data("aku/newarchive-fromHere"); QStringList path = nomeFile.split ( QDir().separator() ); int target = path[path.size()-1].indexOf ( "!*mimetosend:" ); path[path.size()-1].remove ( target, path[path.size()-1].length() ); QString temp = path[path.size()-1]; //nome del parent (directory) bool checkHasSameParent = hasSameParent ( itemAt ( event -> pos() ), temp ); //con questo evito di trascinare un parent in un suo figlio if ( checkHasSameParent == false ) { subLevel = true; padre = itemAt ( event -> pos() ); event -> acceptProposedAction(); } else { event -> ignore(); ///return; } /****************************************************************************************/ // devo controllare di non trascinare su uno stesso parent.. perchè è inutile e rende instabile tutto :-D bool allowAllocation = true; for ( int i = 0; i < itemAt ( event -> pos() ) -> childCount(); i++ ) //se l'elemento di destinazione ha tra i suoi figli uno con lo stesso nome di quello che sto trascinando allora nego il trascinamento { if ( itemAt ( event -> pos() ) -> child ( i )->text ( 0 ) == temp ) allowAllocation = false; //se non ha un child con lo stesso nome permettiamo l'allocazione } if ( allowAllocation == true ) { subLevel = true; padre = itemAt ( event -> pos() ); event -> acceptProposedAction(); } else { event -> ignore(); ///return; } /****************************************************************************************/ } else //altrimenti { if ( itemAt ( event -> pos() ) == NULL ) //se il cursore non si trova su nessun elemento vuol dire che posso allocare nella lista { subLevel = false; event -> acceptProposedAction(); } else { if(itemAt( event -> pos() ) -> text(0) == "") { //possiamo trascinare sull'indicatore subLevel = false; event -> acceptProposedAction(); } else { event -> ignore(); // altrimenti ignoro ///return; } } } } } else //se non è iniziato il trascinamento col tasto sinistro chiudo { event -> ignore(); return; } }
void QvisPlotListBox::clickHandler(const QPoint &clickLocation, bool rightClick, bool doubleClicked, Qt::KeyboardModifiers modifiers) { QPoint itemClickLocation(clickLocation); int action = -1, opId = -1; bool bs = signalsBlocked(); QvisPlotListBoxItem *actionItem = 0; // Walk through all of the items, checking if we've clicked in each one. for (int i = 0; i < count(); ++i) { QListWidgetItem *current = item(i); QvisPlotListBoxItem *item2 = (QvisPlotListBoxItem *)current; int y = visualItemRect(current).y(); int h = visualItemRect(current).height(); if (clickLocation.y() >= y && clickLocation.y() < (y + h)) { if(!rightClick && (modifiers & (Qt::ControlModifier | Qt::MetaModifier)) > 0) { // If we're using Ctrl or Meta + mouse click then switch // the item to its reverse selection. blockSignals(false); current->setSelected(!current->isSelected()); blockSignals(bs); } else { // If the item is not selected, select it. blockSignals(false); current->setSelected(true); blockSignals(bs); // Reduce the y location of the click location to be local // to the item itemClickLocation.setY(clickLocation.y() - y); // Handle the click. if (action == -1) { action = item2->clicked(itemClickLocation, doubleClicked, opId); if(action >= 0 && action <= 7) actionItem = item2; } } } else if(rightClick || doubleClicked) { blockSignals(false); current->setSelected(false); blockSignals(bs); } } switch(action) { case 0: // expand clicked emit itemExpansionChanged(); reset(); break; case 1: // subset clicked emit activateSubsetWindow(); break; case 2: // plot clicked emit activatePlotWindow(opId); break; case 3: // operator clicked emit activateOperatorWindow(opId); break; case 4: // promote clicked emit promoteOperator(opId); break; case 5: // demote clicked emit demoteOperator(opId); break; case 6: // delete clicked emit removeOperator(opId); break; case 7: // selection clicked emit activateSelectionsWindow(actionItem->GetSelectionName()); break; default: if(rightClick) { emit itemSelectionChanged(); } break; } }
void CBookmarkIndex::dropEvent( QDropEvent* event ) { qDebug() << "CBookmarkIndex::dropEvent"; //setState(QAbstractItemView::NoState); // Try to prevent annoying timed autocollapsing. Remember to disconnect before return. QObject::connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*))); QTreeWidgetItem* item = itemAt(event->pos()); QTreeWidgetItem* parentItem = 0; int indexUnderParent = 0; // Find the place where the drag is dropped if (item) { qDebug() << "there was item"; QRect rect = visualItemRect(item); bool isFolder = dynamic_cast<BtBookmarkFolder*>(item); bool isBookmark = dynamic_cast<BtBookmarkItem*>(item); if (isFolder) { // item is a folder qDebug() << "item was folder"; if (event->pos().y() > rect.bottom() - (2* rect.height() / 3) ) { parentItem = item; } else { parentItem = item->parent(); if (!parentItem) { parentItem = invisibleRootItem(); } qDebug() << "item:" << item << "parent:" << parentItem; indexUnderParent = parentItem->indexOfChild(item); // before the current folder } } else { if (isBookmark) { // item is a bookmark qDebug() << "item was bookmark"; parentItem = item->parent(); if (!parentItem) { parentItem = invisibleRootItem(); } indexUnderParent = parentItem->indexOfChild(item); // before the current bookmark if (event->pos().y() > rect.bottom() - rect.height() / 2) { indexUnderParent++; // after the current bookmark } } else { // item is the extra item parentItem = item->parent(); if (!parentItem) { parentItem = invisibleRootItem(); } indexUnderParent = parentItem->indexOfChild(item); // before the current bookmark } } } else { // no item under event point: drop to the end qDebug() << "there was no item"; parentItem = invisibleRootItem(); indexUnderParent = parentItem->childCount() - 1; } if ( event->source() == this ) { qDebug() << "dropping internal drag"; event->accept(); bool bookmarksOnly = true; bool targetIncluded = false; bool moreThanOneFolder = false; QList<QTreeWidgetItem*> newItems = addItemsToDropTree(parentItem, bookmarksOnly, targetIncluded, moreThanOneFolder); if (moreThanOneFolder) { QToolTip::showText(QCursor::pos(), tr("Can drop only bookmarks or one folder")); QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*))); return; } if (targetIncluded) { QToolTip::showText(QCursor::pos(), tr("Can't drop folder into the folder itself or into its subfolder")); QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*))); return; } // Ask whether to copy or move with a popup menu QMenu* dropPopupMenu = new QMenu(this); QAction* copy = dropPopupMenu->addAction(tr("Copy")); QAction* move = dropPopupMenu->addAction(tr("Move")); QAction* dropAction = dropPopupMenu->exec(QCursor::pos()); if (dropAction == copy) { qDebug() << "copy"; parentItem->insertChildren(indexUnderParent, newItems); // Need this here because the "move" case goes through // "deleteEntries" which has a save call. needToSaveBookmarks(); } else { if (dropAction == move) { qDebug() << "move"; parentItem->insertChildren(indexUnderParent, newItems); deleteEntries(false); } else { QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*))); return; // user canceled } } }
void CBookmarkIndex::paintEvent(QPaintEvent* event) { namespace DU = util::directory; static QPixmap pix; static int halfPixHeight; static bool arrowInitialized = false; // Initialize the static variables, including the arrow pixmap if (!arrowInitialized) { arrowInitialized = true; int arrowSize = util::tool::mWidth(this, 1); QString fileName; if (DU::getIconDir().exists("pointing_arrow.svg")) { fileName = DU::getIconDir().filePath("pointing_arrow.svg"); } else { if (DU::getIconDir().exists("pointing_arrow.png")) { fileName = DU::getIconDir().filePath("pointing_arrow.png"); } else { qWarning() << "Picture file pointing_arrow.svg or .png not found!"; } } pix = QPixmap(fileName); pix = pix.scaled(arrowSize, arrowSize, Qt::KeepAspectRatioByExpanding); halfPixHeight = pix.height() / 2; } // Do the normal painting first QTreeWidget::paintEvent(event); // Paint the arrow if the drag is going on if (QAbstractItemView::DraggingState == state()) { bool rtol = QApplication::isRightToLeft(); QPainter painter(this->viewport()); QTreeWidgetItem* item = itemAt(m_dragMovementPosition); bool isFolder = dynamic_cast<BtBookmarkFolder*>(item); bool isBookmark = dynamic_cast<BtBookmarkItem*>(item); // Find the place for the arrow QRect rect = visualItemRect(item); int xCoord = rtol ? rect.right() : rect.left(); int yCoord; if (isFolder) { if (m_dragMovementPosition.y() > rect.bottom() - (2* rect.height() / 3) ) { yCoord = rect.bottom() - halfPixHeight; // bottom xCoord = rtol ? (xCoord - indentation()) : (xCoord + indentation()); } else { yCoord = rect.top() - halfPixHeight - 1; // top } } else { if (isBookmark) { if (m_dragMovementPosition.y() > rect.bottom() - rect.height() / 2) { yCoord = rect.bottom() - halfPixHeight; // bottom } else { yCoord = rect.top() - halfPixHeight - 1; // top } } else { if (item) { // the extra item yCoord = rect.top() - halfPixHeight - 1; } else { // empty area rect = visualItemRect(m_extraItem); yCoord = rect.top() - halfPixHeight - 1; xCoord = rtol ? rect.right() : rect.left(); } } } painter.drawPixmap(xCoord, yCoord, pix); } }
QSize SizedListWidget::sizeHint() const { const int extraHeight = 8; return QSize(width(), count() * visualItemRect(item(0)).height() + extraHeight); }
bool KrTreeWidget::event(QEvent * event) { switch (event->type()) { // HACK: QT 4 Context menu key isn't handled properly case QEvent::ContextMenu: { QContextMenuEvent* ce = (QContextMenuEvent*) event; if (ce->reason() == QContextMenuEvent::Mouse) { QPoint pos = viewport()->mapFromGlobal(ce->globalPos()); QTreeWidgetItem * item = itemAt(pos); int column = columnAt(pos.x()); emit itemRightClicked(item, ce->globalPos(), column); return true; } else { if (currentItem()) { QRect r = visualItemRect(currentItem()); QPoint p = viewport()->mapToGlobal(QPoint(r.x() + 5, r.y() + 5)); emit itemRightClicked(currentItem(), p, currentColumn()); return true; } } } break; case QEvent::KeyPress: { // HACK: QT 4 Ctrl+A bug fix: Ctrl+A doesn't work if QTreeWidget contains parent / child items // Insert doesn't change the selections for multi selection modes QKeyEvent* ke = (QKeyEvent*) event; switch (ke->key()) { case Qt::Key_Insert: { if (ke->modifiers() != 0) break; QAbstractItemView::SelectionMode mode = selectionMode(); if (mode != QAbstractItemView::ContiguousSelection && mode != QAbstractItemView::ExtendedSelection && mode != QAbstractItemView::MultiSelection) break; ke->accept(); if (currentItem() == 0) return true; currentItem()->setSelected(!currentItem()->isSelected()); return true; } case Qt::Key_A: if (ke->modifiers() == Qt::ControlModifier) { QAbstractItemView::SelectionMode mode = selectionMode(); if (mode == QAbstractItemView::ContiguousSelection || mode == QAbstractItemView::ExtendedSelection || mode == QAbstractItemView::MultiSelection) { selectAll(); ke->accept(); return true; } } break; default: break; } } break; case QEvent::Resize: { QResizeEvent * re = (QResizeEvent *)event; if (!_inResize && re->oldSize() != re->size()) { if (_stretchingColumn != -1 && columnCount()) { QList< int > columnsSizes; int oldSize = 0; for (int i = 0; i != header()->count(); i++) { columnsSizes.append(header()->sectionSize(i)); oldSize += header()->sectionSize(i); } bool res = QTreeWidget::event(event); int newSize = viewport()->width(); int delta = newSize - oldSize; if (delta) { _inResize = true; for (int i = 0; i != header()->count(); i++) { if (i == _stretchingColumn) { int newNs = columnsSizes[ i ] + delta; if (newNs < 8) newNs = 8; header()->resizeSection(i, newNs); } else if (header()->sectionSize(i) != columnsSizes[ i ]) { header()->resizeSection(i, columnsSizes[ i ]); } } _inResize = false; } return res; } } break; } case QEvent::ToolTip: { QHelpEvent *he = static_cast<QHelpEvent*>(event); if (viewport()) { QPoint pos = viewport()->mapFromGlobal(he->globalPos()); QTreeWidgetItem * item = itemAt(pos); int column = columnAt(pos.x()); if (item) { if (!item->toolTip(column).isEmpty()) break; QString tip = item->text(column); int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; int requiredWidth = QFontMetrics(font()).width(tip) + 2 * textMargin; if (column == 0 && indentation()) { int level = 0; QTreeWidgetItem *parent = item; while ((parent = parent->parent())) level++; if (rootIsDecorated()) level++; requiredWidth += level * indentation(); } QIcon icon = item->icon(column); if (!icon.isNull()) { QStyleOptionViewItem opts = viewOptions(); QSize iconSize = icon.actualSize(opts.decorationSize); requiredWidth += iconSize.width(); int pixmapMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, this) + 1; requiredWidth += 2 * pixmapMargin; } if (!tip.isEmpty() && (columnWidth(column) < requiredWidth)) QToolTip::showText(he->globalPos(), tip, this); return true; } } } break; default: break; } return QTreeWidget::event(event); }