void PopupMenuEditor::mouseMoveEvent( QMouseEvent * e ) { if ( e->state() & Qt::LeftButton ) { if ( ( e->pos() - mousePressPos ).manhattanLength() > 3 ) { draggedItem = itemAt( mousePressPos.y() ); if ( draggedItem == &addItem ) { draggedItem = createItem(); RenameActionCommand cmd( "Rename Item", formWnd, draggedItem->action(), this, "Unnamed" ); cmd.execute(); // FIXME: start rename after drop } else if ( draggedItem == &addSeparator ) { draggedItem = createItem( new QSeparatorAction( 0 ) ); draggedItem->setSeparator( TRUE ); } PopupMenuEditorItemPtrDrag * d = new PopupMenuEditorItemPtrDrag( draggedItem, this ); hideSubMenu(); draggedItem->setVisible( FALSE ); resizeToContents(); // If the item is dropped in the same list, // we will have two instances of the same pointer // in the list. We use node instead. int idx = itemList.find( draggedItem ); QLNode * node = itemList.currentNode(); d->dragCopy(); // dragevents and stuff happens if ( draggedItem ) { // item was not dropped draggedItem->setVisible( TRUE ); draggedItem = 0; if ( hasFocus() ) { hideSubMenu(); resizeToContents(); showSubMenu(); } } else { // item was dropped itemList.takeNode( node )->setVisible( TRUE ); if ( currentIndex > 0 && currentIndex > idx ) --currentIndex; // the drop might happen in another menu, so we'll resize // and show the submenu there } } } }
CardItem *TableZone::takeCard(int position, int cardId, bool canResize) { CardItem *result = CardZone::takeCard(position, cardId); if (canResize) resizeToContents(); return result; }
void TabbedPane::resizeToContentsRecursive() { for (int i = 0; i < (int)tabs.size(); ++i) { tabs[i].second->resizeToContentsRecursive(); tabs[i].first->resizeToContents(); } resizeToContents(); }
void RadioButton::setText( const std::string &text ) { Widget::setText(text); resizeCaption(); if(isAutosizing()) { resizeToContents(); } textAreaMan.makeTextLines(getFont(),getText(),wordWrappedLines,wordWrapRect.getWidth()); }
void FileOrganiserWidget::collapsedFolder(const QModelIndex &pFolderIndex) { // The folder is being expanded, so update its icon to reflect its new state mModel->itemFromIndex(pFolderIndex)->setIcon(QIcon(CollapsedFolderIcon)); // Resize the widget, just to be on the safe side resizeToContents(); }
void PopupMenuEditor::dropEvent( QDropEvent * e ) { if ( !( e->provides( "qt/popupmenueditoritemptr" ) || e->provides( "application/x-designer-actions" ) || e->provides( "application/x-designer-actiongroup" ) ) ) return; // Hide the sub menu of the current item, but do it later if ( currentIndex < (int)itemList.count() ) { PopupMenuEditor *s = itemList.at( currentIndex )->s; QTimer::singleShot( 0, s, SLOT( hide() ) ); } draggedItem = 0; PopupMenuEditorItem * i = 0; if ( e->provides( "qt/popupmenueditoritemptr" ) ) { PopupMenuEditorItemPtrDrag::decode( e, &i ); } else { if ( e->provides( "application/x-designer-actiongroup" ) ) { QActionGroup * g = ::qt_cast<QDesignerActionGroup*>(ActionDrag::action()); if ( g->usesDropDown() ) { i = new PopupMenuEditorItem( g, this ); QString n = QString( g->name() ) + "Item"; formWindow()->unify( i, n, FALSE ); i->setName( n ); QObjectList *l = g->queryList( "QAction", 0, FALSE, FALSE ); QObjectListIterator it( *l ); for ( ; it.current(); ++it ) { g = ::qt_cast<QActionGroup*>(it.current()); if ( g ) i->s->insert( g ); else i->s->insert( (QAction*)it.current() ); } delete l; } else { dropInPlace( g, e->pos().y() ); } } else if ( e->provides( "application/x-designer-actions" ) ) { QAction *a = ::qt_cast<QDesignerAction*>(ActionDrag::action()); i = new PopupMenuEditorItem( a, this ); } } if ( i ) { dropInPlace( i, e->pos().y() ); QTimer::singleShot( 0, this, SLOT( resizeToContents() ) ); } QTimer::singleShot( 0, this, SLOT( showSubMenu() ) ); QTimer::singleShot( 0, this, SLOT( setFocus() ) ); dropLine->hide(); e->accept(); }
void RadioButton::setRadioButtonRadius( int size ) { if(size < 0) { size = 0; } radioButtonRadius = size; positionRadioButton(); if(isAutosizing()) { resizeToContents(); } }
void RadioButton::setSidePadding(int padding) { sidePadding = padding; positionRadioButton(); if(isAutosizing()) { resizeToContents(); } textAreaMan.makeTextLines(getFont(),getText(), wordWrappedLines,wordWrapRect.getWidth()); }
// This function has no undo. It is only here to remove an item when its action was // removed from the action editor. // Use removeItem to put the command on the command stack. void PopupMenuEditor::remove( int index ) { int idx = ( index == -1 ? currentIndex : index ); PopupMenuEditorItem * i = itemList.at( idx ); if ( i && i->isRemovable() ) { itemList.remove( idx ); int n = itemList.count() + 1; if ( currentIndex >= n ) currentIndex = itemList.count() + 1; emit removed( i->action() ); resizeToContents(); } }
void FolderView::setModel(QAbstractItemModel *model) { setSortingEnabled(false); QTableView::setModel(model); //model->setReadOnly(false); //model->setFilter(QDir::Drives | QDir::AllDirs | QDir::NoDotAndDotDot); setSortingEnabled(true); QTimer::singleShot(200, this, SLOT(resizeToContents())); }
void TableZone::reorganizeCards() { QList<ArrowItem *> arrowsToUpdate; // Calculate card stack widths so mapping functions work properly computeCardStackWidths(); for (int i = 0; i < cards.size(); ++i) { QPoint gridPoint = cards[i]->getGridPos(); if (gridPoint.x() == -1) continue; QPointF mapPoint = mapFromGrid(gridPoint); qreal x = mapPoint.x(); qreal y = mapPoint.y(); int numberAttachedCards = cards[i]->getAttachedCards().size(); qreal actualX = x + numberAttachedCards * STACKED_CARD_OFFSET_X; qreal actualY = y; if (numberAttachedCards) actualY += 15; cards[i]->setPos(actualX, actualY); cards[i]->setRealZValue((actualY + CARD_HEIGHT) * 100000 + (actualX + 1) * 100); QListIterator<CardItem *> attachedCardIterator(cards[i]->getAttachedCards()); int j = 0; while (attachedCardIterator.hasNext()) { ++j; CardItem *attachedCard = attachedCardIterator.next(); qreal childX = actualX - j * STACKED_CARD_OFFSET_X; qreal childY = y + 5; attachedCard->setPos(childX, childY); attachedCard->setRealZValue((childY + CARD_HEIGHT) * 100000 + (childX + 1) * 100); arrowsToUpdate.append(attachedCard->getArrowsFrom()); arrowsToUpdate.append(attachedCard->getArrowsTo()); } arrowsToUpdate.append(cards[i]->getArrowsFrom()); arrowsToUpdate.append(cards[i]->getArrowsTo()); } QSetIterator<ArrowItem *> arrowIterator(QSet<ArrowItem *>::fromList(arrowsToUpdate)); while (arrowIterator.hasNext()) arrowIterator.next()->updatePath(); resizeToContents(); update(); }
void PopupMenuEditor::mouseDoubleClickEvent( QMouseEvent * ) { setFocusAt( mousePressPos ); if ( currentItem() == &addSeparator ) { PopupMenuEditorItem * i = createItem( new QSeparatorAction( 0 ) ); i->setSeparator( TRUE ); return; } if ( currentField == 0 ) { choosePixmap(); resizeToContents(); } else if ( currentField == 1 ) { showLineEdit(); } }
void PopupMenuEditor::removeItem( int index ) { int idx = ( index == -1 ? currentIndex : index ); if ( idx < (int)itemList.count() ) { RemoveActionFromPopupCommand * cmd = new RemoveActionFromPopupCommand( "Remove Item", formWnd, this, idx ); formWnd->commandHistory()->addCommand( cmd ); cmd->execute(); if ( itemList.count() == 0 && parentMenu ) parentMenu->update(); resizeToContents(); } }
void PopupMenuEditor::leaveEditMode( QKeyEvent * e ) { setFocus(); lineEdit->hide(); PopupMenuEditorItem * i = 0; if ( e && e->key() == Qt::Key_Escape ) { update(); return; } if ( currentIndex >= (int)itemList.count() ) { // new item was created QAction * a = formWnd->mainWindow()->actioneditor()->newActionEx(); QString actionText = lineEdit->text(); actionText.replace("&&", "&"); QString menuText = lineEdit->text(); a->setText( actionText ); a->setMenuText( menuText ); i = createItem( a ); QString n = constructName( i ); formWindow()->unify( a, n, TRUE ); a->setName( n ); MetaDataBase::addEntry( a ); MetaDataBase::setPropertyChanged( a, "menuText", TRUE ); ActionEditor *ae = (ActionEditor*)formWindow()->mainWindow()->child( 0, "ActionEditor" ); if ( ae ) ae->updateActionName( a ); } else { i = itemList.at( currentIndex ); RenameActionCommand * cmd = new RenameActionCommand( "Rename Item", formWnd, i->action(), this, lineEdit->text() ); formWnd->commandHistory()->addCommand( cmd ); cmd->execute(); } resizeToContents(); if ( !i ) return; if ( i->isSeparator() ) hideSubMenu(); else showSubMenu(); }
void RadioButton::setAutosizing( bool autosizing ) { autosizingCheckbox = autosizing; if(isAutosizing()) { resizeToContents(); } for(std::vector<RadioButtonListener*>::iterator it = radioButtonListeners.begin(); it != radioButtonListeners.end(); ++it) { if((*it)) (*it)->isAutosizingChanged(this,autosizing); } }
bool PopupMenuEditor::qt_invoke( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->slotOffset() ) { case 0: cut(); break; case 1: copy(); break; case 2: paste(); break; case 3: remove((int)static_QUType_int.get(_o+1)); break; case 4: remove((QAction*)static_QUType_ptr.get(_o+1)); break; case 5: resizeToContents(); break; case 6: showSubMenu(); break; case 7: hideSubMenu(); break; case 8: focusOnSubMenu(); break; default: return QWidget::qt_invoke( _id, _o ); } return TRUE; }
void FileOrganiserWidget::deleteItems() { // Remove all the selected items QModelIndexList selectedIndexes = selectionModel()->selectedIndexes(); if (selectedIndexes.isEmpty()) // Nothing to delete, so... return; // Delete the items one by one, making sure that we update our list of items // every time (this is because the row value of the remaining selected items // may become different after deleting an item) while (!selectedIndexes.isEmpty()) { // Remove the file from our file manager, should the index refer to a // file item // Note: it doesn't matter whether or not the file has already been // removed, since if that's the case then nothing will be done... QModelIndex crtIndex = selectedIndexes.first(); QStandardItem *crtItem = mModel->itemFromIndex(crtIndex); if (crtItem && !crtItem->data(Item::Folder).toBool()) mFileManager->unmanage(crtItem->data(Item::Path).toString()); // Remove the item from the model itself mModel->removeRow(crtIndex.row(), crtIndex.parent()); // Update our list of selected indexes selectedIndexes = selectionModel()->selectedIndexes(); } // Collapse any folder that doesn't contain any file/folder anymore collapseEmptyFolders(mModel->invisibleRootItem()); // Resize the widget to its contents in case its width was too wide (and // therefore required a horizontal scrollbar), but is now fine resizeToContents(); }
void RadioButton::setTextAlignment( AreaAlignmentEnum alignment ) { textAlignment = alignment; positionRadioButton(); if(isAutosizing()) { resizeToContents(); } textAreaMan.makeTextLines(getFont(),getText(), wordWrappedLines,wordWrapRect.getWidth()); for(std::vector<RadioButtonListener*>::iterator it = radioButtonListeners.begin(); it != radioButtonListeners.end(); ++it) { if((*it)) (*it)->textAlignmentChanged(this,alignment); } }
void FileOrganiserWidget::newFolder() { if (!canCreateNewFolder()) // The conditions are not met to create a new folder, so... return; // Either create a folder item below the current folder item or below the // root item, depending on the situation QModelIndexList selectedIndexes = selectionModel()->selectedIndexes(); int selectedIndexesCount = selectedIndexes.count(); QStandardItem *crtItem = !selectedIndexesCount? mModel->invisibleRootItem(): mModel->itemFromIndex(selectedIndexes.first()); QStandardItem *newFolderItem = new QStandardItem(QIcon(CollapsedFolderIcon), newFolderName(crtItem)); newFolderItem->setData(true, Item::Folder); crtItem->appendRow(newFolderItem); // Some post-processing, but only if no other item is currently being edited if (!isEditing()) { // Expand the current index (so that we can see the new folder) // Note: this is only relevant in the case of a folder item being // currently selected (i.e. it's not the root folder item) if (selectedIndexesCount) setExpanded(crtItem->index(), true); // Offer the user to edit the newly added folder item edit(newFolderItem->index()); } // Resize the widget, just to be on the safe side resizeToContents(); }
void PopupMenuEditor::insert( PopupMenuEditorItem * item, int index ) { if ( !item ) return; if ( index == -1 ) { itemList.append( item ); if ( isVisible() ) currentIndex = itemList.count() - 1; } else { itemList.insert( index, item ); if ( isVisible() ) currentIndex = index; } item->m = this; if (item->s) item->s->parentMenu = this; resizeToContents(); if ( isVisible() && parentMenu ) parentMenu->update(); // draw arrow in parent menu emit inserted( item->action() ); }
void PopupMenuEditor::setAccelerator( int key, Qt::ButtonState state, int index ) { // FIXME: make this a command int idx = ( index == -1 ? currentIndex : index ); if ( key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt || key == Qt::Key_Meta || key == Qt::Key_unknown ) return; // ignore these keys when they are pressed PopupMenuEditorItem * i = 0; if ( idx >= (int)itemList.count() ) i = createItem(); else i = itemList.at( idx ); int shift = ( state & Qt::ShiftButton ? Qt::SHIFT : 0 ); int ctrl = ( state & Qt::ControlButton ? Qt::CTRL : 0 ); int alt = ( state & Qt::AltButton ? Qt::ALT : 0 ); int meta = ( state & Qt::MetaButton ? Qt::META : 0 ); QAction * a = i->action(); QKeySequence ks = a->accel(); int keys[4] = { ks[0], ks[1], ks[2], ks[3] }; int n = 0; while ( n < 4 && ks[n++] ); n--; if ( n < 4 ) keys[n] = key | shift | ctrl | alt | meta; a->setAccel( QKeySequence( keys[0], keys[1], keys[2], keys[3] ) ); MetaDataBase::setPropertyChanged( a, "accel", TRUE ); resizeToContents(); }
void PopupMenuEditor::clearCurrentField() { if ( currentIndex >= (int)itemList.count() ) return; // currentIndex is addItem or addSeparator PopupMenuEditorItem * i = currentItem(); hideSubMenu(); if ( i->isSeparator() ) return; if ( currentField == 0 ) { QIconSet icons( 0 ); SetActionIconsCommand * cmd = new SetActionIconsCommand( "Remove icon", formWnd, i->action(), this, icons ); formWnd->commandHistory()->addCommand( cmd ); cmd->execute(); } else if ( currentField == 2 ) { i->action()->setAccel( 0 ); } resizeToContents(); showSubMenu(); return; }
QExpandingLineEdit::QExpandingLineEdit(QWidget *parent) : QLineEdit(parent), originalWidth(-1), widgetOwnsGeometry(false) { connect(this, SIGNAL(textChanged(QString)), this, SLOT(resizeToContents())); updateMinimumWidth(); }
void FileOrganiserWidget::moveItem(QStandardItem *pItem, QStandardItem *pDropItem, const QAbstractItemView::DropIndicatorPosition &pDropPosition) { if (!pDropItem) // pDropItem is not valid, so... return; // Move pItem above/on/below pDropItem, depending on the drop position, but // first, determine the item that will own pItem QStandardItem *crtParentItem = pItem->parent()? pItem->parent(): mModel->invisibleRootItem(); QStandardItem *newParentItem = parentItem(pDropItem, pDropPosition); // Second, check whether the (file) item points to a file which is already // owned by newParentItem bool fileAlreadyOwned = false; if (!pItem->data(Item::Folder).toBool()) // The current item is a file item, so retrieve its file name and check // whether it's already owned by newParentItem fileAlreadyOwned = ownedBy(pItem->data(Item::Path).toString(), newParentItem); // Third, move pItem to newParentItem and this to the right place, depending // on the value of pDropPosition and only if the destination doesn't already // have that item (should it be a file item, since folder items are always // moved) if (!fileAlreadyOwned || (crtParentItem == newParentItem)) { // Either newParentItem doesn't already own an item which points to the // same file as pItem or pItem's current parent is the same as // newParentItem in which case it means that we want to move the item // within its current location // First, check whether the item is a folder and, if so, whether it's // expanded (and the same with any (in)direct child folder it may // contain) backupExpandedInformation(pItem); // Second, move the item (and any of its children) dropItems(pDropItem, pDropPosition, newParentItem, crtParentItem->takeRow(pItem->row())); // Third, re-expand folders, if necessary restoreExpandedInformation(pItem); // Fourth, resize the widget, just in case the new location of the // item(s) requires more space than is visible resizeToContents(); } else { // A (file) item pointing to the same file is already owned by // newParentItem, so just remove the item rather than move it crtParentItem->removeRow(pItem->row()); } }
void FileOrganiserWidget::addFile(const QString &pFileName, QStandardItem *pDropItem, const QAbstractItemView::DropIndicatorPosition &pDropPosition) { if (!pDropItem) // pDropItem is not valid, so... return; // Check that we are indeed dealing with a file QFileInfo fileInfo = pFileName; if (!fileInfo.isFile()) // We are not dealing with a file, so... return; // Check whether we are dropping a symbolic link QString fileName = pFileName; if (fileInfo.isSymLink()) // We are dropping a symbolic link, so retrieve its target fileName = fileInfo.symLinkTarget(); // Check whether the file exists if (QFileInfo(fileName).exists()) { // The target file exists, so add it above/on/below pDropItem, depending // on the drop position and only if the file isn't already present // First, determine the item that will own the file QStandardItem *newParentItem = parentItem(pDropItem, pDropPosition); // Second, if the file is not already owned, then add it to // newParentItem and this to the right place, depending on the value of // pDropPosition if (!ownedBy(fileName, newParentItem)) { QStandardItem *newFileItem = new QStandardItem(QIcon(FileIcon), QFileInfo(fileName).fileName()); newFileItem->setData(fileName, Item::Path); dropItem(pDropItem, pDropPosition, newParentItem, newFileItem); // Add the file to our file manager // Note: it doesn't matter whether or not the file is already being // monitored, since if that's the case then the current // instance will be ignored mFileManager->manage(fileName); // Resize the widget, just in case the new file takes more space // than is visible resizeToContents(); } else { // The file is already owned by newParentItem, so just repaint the // widget to make sure that the dragging & dropping overlay // disappears repaint(); } } }
void PopupMenuEditor::show() { resizeToContents(); QWidget::show(); }
void TableZone::reorganizeCards() { QList<ArrowItem *> arrowsToUpdate; // Calculate table grid distortion so that the mapping functions work properly QMap<int, int> gridPointStackCount; for (int i = 0; i < cards.size(); ++i) { const QPoint &gridPoint = cards[i]->getGridPos(); if (gridPoint.x() == -1) continue; const int key = gridPoint.x() / 3 + gridPoint.y() * 1000; gridPointStackCount.insert(key, gridPointStackCount.value(key, 0) + 1); } gridPointWidth.clear(); for (int i = 0; i < cards.size(); ++i) { const QPoint &gridPoint = cards[i]->getGridPos(); if (gridPoint.x() == -1) continue; const int key = gridPoint.x() / 3 + gridPoint.y() * 1000; const int stackCount = gridPointStackCount.value(key, 0); if (stackCount == 1) gridPointWidth.insert(key, CARD_WIDTH * (1 + cards[i]->getAttachedCards().size() / 3.0)); else gridPointWidth.insert(key, CARD_WIDTH * (1 + (stackCount - 1) / 3.0)); } for (int i = 0; i < cards.size(); ++i) { QPoint gridPoint = cards[i]->getGridPos(); if (gridPoint.x() == -1) continue; QPointF mapPoint = mapFromGrid(gridPoint); qreal x = mapPoint.x(); qreal y = mapPoint.y(); int numberAttachedCards = cards[i]->getAttachedCards().size(); qreal actualX = x + numberAttachedCards * CARD_WIDTH / 3.0; qreal actualY = y; if (numberAttachedCards) actualY += 15; cards[i]->setPos(actualX, actualY); cards[i]->setRealZValue((actualY + CARD_HEIGHT) * 100000 + (actualX + 1) * 100); QListIterator<CardItem *> attachedCardIterator(cards[i]->getAttachedCards()); int j = 0; while (attachedCardIterator.hasNext()) { ++j; CardItem *attachedCard = attachedCardIterator.next(); qreal childX = actualX - j * CARD_WIDTH / 3.0; qreal childY = y + 5; attachedCard->setPos(childX, childY); attachedCard->setRealZValue((childY + CARD_HEIGHT) * 100000 + (childX + 1) * 100); arrowsToUpdate.append(attachedCard->getArrowsFrom()); arrowsToUpdate.append(attachedCard->getArrowsTo()); } arrowsToUpdate.append(cards[i]->getArrowsFrom()); arrowsToUpdate.append(cards[i]->getArrowsTo()); } QSetIterator<ArrowItem *> arrowIterator(QSet<ArrowItem *>::fromList(arrowsToUpdate)); while (arrowIterator.hasNext()) arrowIterator.next()->updatePath(); resizeToContents(); update(); }
void KFindTreeView::endSearch() { resizeToContents(); }