// edge id: 0 = left; 1 = right; 2 = bottom; 3 = top void Rectangles::createLines(unsigned rectangleIndex, Edge edgeID) { // line's center glm::vec2 linePosition = glm::vec2(0.0f, 0.0f); if (edgeID == Edge::LEFT || edgeID == Edge::RIGHT) { // vertical edge if (edgeID == Edge::LEFT) { // left edge linePosition.x = rectangles[rectangleIndex].getLeft(); } else { // right edge linePosition.x = rectangles[rectangleIndex].getRight(); } createVerticalLine(rectangleIndex, linePosition); } else { // horizontal edge if (edgeID == Edge::BOTTOM) { // bottom edge linePosition.y = rectangles[rectangleIndex].getBottom(); } else { // top edge linePosition.y = rectangles[rectangleIndex].getTop(); } createHorizontalLine(rectangleIndex, linePosition); } }
OutputItemHeaderWidget::OutputItemHeaderWidget( OutputItemContentWidget *outputItemContentWidget, bool multipleResults, bool tabbedResults, bool firstItem, bool lastItem, QWidget *parent) : QFrame(parent), _maxButton(nullptr), _dockUndockButton(nullptr), _maximized(false), _multipleResults(multipleResults), _firstItem(firstItem), _lastItem(lastItem), _orientation(Qt::Vertical) { setContentsMargins(5, 0, 0, 0); auto const* outputWidget = qobject_cast<OutputWidget*>(outputItemContentWidget->parentWidget()); _orientation = outputWidget->getOrientation(); // Text mode button _textButton = new QPushButton(this); _textButton->setIcon(GuiRegistry::instance().textIcon()); _textButton->setToolTip("View results in text mode"); _textButton->setFixedSize(24, 24); _textButton->setFlat(true); _textButton->setCheckable(true); // Tree mode button _treeButton = new QPushButton(this); _treeButton->hide(); _treeButton->setIcon(GuiRegistry::instance().treeIcon()); _treeButton->setToolTip("View results in tree mode"); _treeButton->setFixedSize(24, 24); _treeButton->setFlat(true); _treeButton->setCheckable(true); _treeButton->setChecked(true); // Table mode button _tableButton = new QPushButton(this); _tableButton->hide(); _tableButton->setIcon(GuiRegistry::instance().tableIcon()); _tableButton->setToolTip("View results in table mode"); _tableButton->setFixedSize(24, 24); _tableButton->setFlat(true); _tableButton->setCheckable(true); _tableButton->setChecked(true); // Custom mode button _customButton = new QPushButton(this); _customButton->hide(); _customButton->setIcon(GuiRegistry::instance().customIcon()); _customButton->setToolTip("View results in custom UI"); _customButton->setFixedSize(24, 24); _customButton->setFlat(true); _customButton->setCheckable(true); // Create maximize button only if there are multiple results if (_multipleResults && !tabbedResults) { _maxButton = new QPushButton; _maxButton->setIcon(GuiRegistry::instance().maximizeIcon()); _maxButton->setToolTip("Maximize this output result (double-click on result's header)"); _maxButton->setFixedSize(18, 18); _maxButton->setFlat(true); VERIFY(connect(_maxButton, SIGNAL(clicked()), this, SLOT(maximizeMinimizePart()))); } auto dockWidget = qobject_cast<QueryWidget::CustomDockWidget*>(outputItemContentWidget->parentWidget()->parentWidget()); auto queryWidget = dockWidget->getParentQueryWidget(); _dockUndockButton = new QPushButton; _dockUndockButton->setFixedSize(18, 18); _dockUndockButton->setFlat(true); _dockUndockButton->setHidden(true); applyDockUndockSettings(!dockWidget->isFloating()); VERIFY(connect(_dockUndockButton, SIGNAL(clicked()), queryWidget, SLOT(dockUndock()))); VERIFY(connect(_textButton, SIGNAL(clicked()), outputItemContentWidget, SLOT(showText()))); VERIFY(connect(_treeButton, SIGNAL(clicked()), outputItemContentWidget, SLOT(showTree()))); VERIFY(connect(_tableButton, SIGNAL(clicked()), outputItemContentWidget, SLOT(showTable()))); VERIFY(connect(_customButton, SIGNAL(clicked()), outputItemContentWidget, SLOT(showCustom()))); _collectionIndicator = new Indicator(GuiRegistry::instance().collectionIcon()); _timeIndicator = new Indicator(GuiRegistry::instance().timeIcon()); _paging = new PagingWidget(); _collectionIndicator->hide(); _timeIndicator->hide(); _paging->hide(); QHBoxLayout *layout = new QHBoxLayout(); #ifdef __APPLE__ layout->setContentsMargins(2, 8, 5, 1); #else layout->setContentsMargins(2, 0, 5, 1); #endif layout->setSpacing(0); layout->addWidget(_collectionIndicator); layout->addWidget(_timeIndicator); QSpacerItem *hSpacer = new QSpacerItem(2000, 24, QSizePolicy::Preferred, QSizePolicy::Minimum); layout->addSpacerItem(hSpacer); layout->addWidget(_paging); layout->addWidget(createVerticalLine()); layout->addSpacing(2); if (outputItemContentWidget->isCustomModeSupported()) { layout->addWidget(_customButton, 0, Qt::AlignRight); _customButton->show(); } if (outputItemContentWidget->isTreeModeSupported()) { layout->addWidget(_treeButton, 0, Qt::AlignRight); _treeButton->show(); } if (outputItemContentWidget->isTableModeSupported()) { layout->addWidget(_tableButton, 0, Qt::AlignRight); _tableButton->show(); } if (outputItemContentWidget->isTextModeSupported()) layout->addWidget(_textButton, 0, Qt::AlignRight); if (_multipleResults) layout->addWidget(_maxButton, 0, Qt::AlignRight); layout->addSpacing(3); _verticalLine = createVerticalLine(); _verticalLine->setHidden(true); layout->addWidget(_verticalLine); layout->addWidget(_dockUndockButton); setLayout(layout); // Update dock/undock button visibility if (_multipleResults) updateDockButtonOnToggleOrientation(); else { _verticalLine->setVisible(true); _dockUndockButton->setVisible(true); } if(tabbedResults) setStyleSheet("background-color: white"); }
/*! Check if the right edge of moving rect is snappable to the incative rect's left or right edge. The inactive rect's edge is only chosen if it is a better fit for horizontal snapping. */ void HsSnapToLines::compareRightSideOfMovingRectForSnapping() { checkInactiveRectLieAboveOrBelowOfMovingRect(); checkInactiveRectVerticalEdgesInRange(mMovingRect.right()); //calculate the distance of inactive rect's left edge and container rect's left edge qreal differenceContainerLeftEdgeToInactiveRectLeftEdge = mInactiveRectToCompare.left() - mContainerRect.left(); //calculate the distance of inactive rect's right edge and container rect's right edge qreal differenceContainerRightEdgeToInactiveRectRightEdge = mContainerRect.right() - mInactiveRectToCompare.right(); qreal xSnapGapAdjustment = 0.0; mDistanceVerticalEdges = 0.0; mMinDistancePosition = 0.0; //If only one edge of inactive rect is in snappable range, save that position if ((mLeftInRange && !mRightInRange) || !mLeftInRange && mRightInRange) { if (mLeftInRange) { mMinDistancePosition = mInactiveRectToCompare.left(); mDistanceVerticalEdges = mVerticalEdgeToLeftOfInactiveRect; xSnapGapAdjustment = mSnapGap; } else { mMinDistancePosition = mInactiveRectToCompare.right(); mDistanceVerticalEdges = mVerticalEdgeToRightOfInactiveRect; xSnapGapAdjustment = 0.0; } } //else both edges of inactive rect are in range, check which is a better fit else if (mLeftInRange && mRightInRange) { //if right edge of moving rect to the right of the inactive rect is closer than the right edge of moving rect to the left of inactive rect if (mVerticalEdgeToRightOfInactiveRect < mVerticalEdgeToLeftOfInactiveRect) { mMinDistancePosition = mInactiveRectToCompare.right(); mDistanceVerticalEdges = mVerticalEdgeToRightOfInactiveRect; xSnapGapAdjustment = 0.0; mLeftInRange = false; } //if the right edge of moving rect to right of inactive rect is at the same distance as the right edge of moving rect to the left of inactive rect else if (mVerticalEdgeToRightOfInactiveRect == mVerticalEdgeToLeftOfInactiveRect) { //if inactive rect lies towards the right of container rect, then the right edge is priortized as the selected edge for outside snapping if (differenceContainerRightEdgeToInactiveRectRightEdge < differenceContainerLeftEdgeToInactiveRectLeftEdge ) { mMinDistancePosition = mInactiveRectToCompare.right(); mDistanceVerticalEdges = mVerticalEdgeToRightOfInactiveRect; xSnapGapAdjustment = 0.0; mLeftInRange = false; } //else left of the inactive rect lies more close to the left or middle of the container rect, and hence prioritize it else { mMinDistancePosition = mInactiveRectToCompare.left(); mDistanceVerticalEdges = mVerticalEdgeToLeftOfInactiveRect; xSnapGapAdjustment = mSnapGap; mRightInRange = false; } } //else right edge of moving rect to the left of the inactive rect is closer than the right edge of moving rect to the right of the incoming rect else{ mMinDistancePosition = mInactiveRectToCompare.left(); mDistanceVerticalEdges = mVerticalEdgeToLeftOfInactiveRect; xSnapGapAdjustment = mSnapGap; mRightInRange = false; } } //Check if this inactive rect is better fit than the previous selected rect checkInactiveRectBetterFitForHorizontalSnapping(differenceContainerRightEdgeToInactiveRectRightEdge, differenceContainerLeftEdgeToInactiveRectLeftEdge); if (mIsBetterFitHorizontalSnap) { qreal proposedLeftOfActiveRect = mMinDistancePosition - mActiveRectWidth - xSnapGapAdjustment; if (qBound(mContainerRect.left(), proposedLeftOfActiveRect, mContainerRect.right()) == proposedLeftOfActiveRect) { mHorizontalSnapFound = true; mHorizontalSnapPosition = proposedLeftOfActiveRect; mMinVerticalEdgesDistance = mDistanceVerticalEdges; mVerticalDistanceFromSelectedRect = mVerticalDistance; //Save the new distance of the Chosen Rectangle's right edge from Container's right edge mContainerVerticalEdgeDistance = differenceContainerRightEdgeToInactiveRectRightEdge; createVerticalLine(); } } }
OutputItemHeaderWidget::OutputItemHeaderWidget(OutputItemContentWidget *output, QWidget *parent) : QFrame(parent), _maximized(false) { setContentsMargins(5,0,0,0); // Maximize button _maxButton = new QPushButton; _maxButton->setIcon(GuiRegistry::instance().maximizeIcon()); _maxButton->setToolTip("Maximize or restore back this output result. You also can double-click on result's header."); _maxButton->setFixedSize(18, 18); _maxButton->setFlat(true); VERIFY(connect(_maxButton, SIGNAL(clicked()), this, SLOT(maximizePart()))); // Text mode button _textButton = new QPushButton(this); _textButton->setIcon(GuiRegistry::instance().textIcon()); _textButton->setToolTip("View results in text mode"); _textButton->setFixedSize(24, 24); _textButton->setFlat(true); _textButton->setCheckable(true); // Tree mode button _treeButton = new QPushButton(this); _treeButton->hide(); _treeButton->setIcon(GuiRegistry::instance().treeIcon()); _treeButton->setToolTip("View results in tree mode"); _treeButton->setFixedSize(24, 24); _treeButton->setFlat(true); _treeButton->setCheckable(true); _treeButton->setChecked(true); // Table mode button _tableButton = new QPushButton(this); _tableButton->hide(); _tableButton->setIcon(GuiRegistry::instance().tableIcon()); _tableButton->setToolTip("View results in table mode"); _tableButton->setFixedSize(24, 24); _tableButton->setFlat(true); _tableButton->setCheckable(true); _tableButton->setChecked(true); // Custom mode button _customButton = new QPushButton(this); _customButton->hide(); _customButton->setIcon(GuiRegistry::instance().customIcon()); _customButton->setToolTip("View results in custom UI"); _customButton->setFixedSize(24, 24); _customButton->setFlat(true); _customButton->setCheckable(true); VERIFY(connect(_textButton, SIGNAL(clicked()), output, SLOT(showText()))); VERIFY(connect(_treeButton, SIGNAL(clicked()), output, SLOT(showTree()))); VERIFY(connect(_tableButton, SIGNAL(clicked()), output, SLOT(showTable()))); VERIFY(connect(_customButton, SIGNAL(clicked()), output, SLOT(showCustom()))); _collectionIndicator = new Indicator(GuiRegistry::instance().collectionIcon()); _timeIndicator = new Indicator(GuiRegistry::instance().timeIcon()); _paging = new PagingWidget(); _collectionIndicator->hide(); _timeIndicator->hide(); _paging->hide(); QHBoxLayout *layout = new QHBoxLayout(); layout->setContentsMargins(2, 0, 5, 1); layout->setSpacing(0); layout->addWidget(_collectionIndicator); layout->addWidget(_timeIndicator); QSpacerItem *hSpacer = new QSpacerItem(2000, 24, QSizePolicy::Preferred, QSizePolicy::Minimum); layout->addSpacerItem(hSpacer); layout->addWidget(_paging); layout->addWidget(createVerticalLine()); layout->addSpacing(2); if (output->isCustomModeSupported()) { layout->addWidget(_customButton, 0, Qt::AlignRight); _customButton->show(); } if (output->isTreeModeSupported()) { layout->addWidget(_treeButton, 0, Qt::AlignRight); _treeButton->show(); } if (output->isTableModeSupported()) { layout->addWidget(_tableButton, 0, Qt::AlignRight); _tableButton->show(); } if (output->isTextModeSupported()) layout->addWidget(_textButton, 0, Qt::AlignRight); layout->addSpacing(3); layout->addWidget(createVerticalLine()); layout->addWidget(_maxButton, 0, Qt::AlignRight); setLayout(layout); }