Vec2i minSize(int tilesetH, int maxAtlasSize) { int width = atAreaW; int height = atAreaH; const int tsArea = tilesetW * tilesetH; /* Expand vertically */ while (freeArea(width, height) < tsArea && height < maxAtlasSize) height += 32; if (freeArea(width, height) >= tsArea && height <= maxAtlasSize) return Vec2i(width, height); /* Expand horizontally */ while (freeArea(width, height) < tsArea && width < maxAtlasSize) width += tsLaneW; if (freeArea(width, height) >= tsArea && width <= maxAtlasSize) return Vec2i(width, height); return Vec2i(-1, -1); }
bool ToolBarEventFilter::handleDropEvent(QDropEvent *event) { const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData()); if (!d) return false; if (d->actionList().isEmpty()) { event->ignore(); hideDragIndicator(); return true; } QAction *action = d->actionList().first(); const ActionList actions = m_toolBar->actions(); if (!action || actions.contains(action)) { event->ignore(); hideDragIndicator(); return true; } // Try to find action to 'insert before'. Click on action or in free area, else ignore. QAction *beforeAction = 0; const QPoint pos = event->pos(); const int index = actionIndexAt(m_toolBar, pos, m_toolBar->orientation()); if (index != -1) { beforeAction = actions.at(index); } else { if (!freeArea(m_toolBar).contains(pos)) { event->ignore(); hideDragIndicator(); return true; } } event->acceptProposedAction(); QDesignerFormWindowInterface *fw = formWindow(); InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw); cmd->init(m_toolBar, action, beforeAction); fw->commandHistory()->push(cmd); hideDragIndicator(); return true; }