void Popup::realign() { QRect rect; rect.setSize(sizeHint()); switch (mAnchor) { case Qt::TopLeftCorner: rect.moveTopLeft(mPos); break; case Qt::TopRightCorner: rect.moveTopRight(mPos); break; case Qt::BottomLeftCorner: rect.moveBottomLeft(mPos); break; case Qt::BottomRightCorner: rect.moveBottomRight(mPos); break; } QRect screen = QApplication::desktop()->availableGeometry(mPos); if (rect.right() > screen.right()) rect.moveRight(screen.right()); if (rect.bottom() > screen.bottom()) rect.moveBottom(screen.bottom()); move(rect.topLeft()); }
void MainWindowPlugin::correctWindowPosition() const { QRect windowRect = FMainWindowBorder ? FMainWindowBorder->geometry() : FMainWindow->geometry(); if (FMainWindowBorder) { // correcting rect windowRect.setLeft(windowRect.left() - FMainWindowBorder->leftBorderWidth()); windowRect.setRight(windowRect.right() + FMainWindowBorder->rightBorderWidth()); windowRect.setTop(windowRect.top() - FMainWindowBorder->topBorderWidth()); windowRect.setBottom(windowRect.bottom() + FMainWindowBorder->bottomBorderWidth()); } QRect screenRect = qApp->desktop()->availableGeometry(qApp->desktop()->screenNumber(windowRect.topLeft())); if (!screenRect.isEmpty() && !screenRect.adjusted(10,10,-10,-10).intersects(windowRect)) { if (windowRect.right() <= screenRect.left()) windowRect.moveLeft(screenRect.left()); else if (windowRect.left() >= screenRect.right()) windowRect.moveRight(screenRect.right()); if (windowRect.top() >= screenRect.bottom()) windowRect.moveBottom(screenRect.bottom()); else if (windowRect.bottom() <= screenRect.top()) windowRect.moveTop(screenRect.top()); if (FMainWindowBorder) { // correcting rect back windowRect.setLeft(windowRect.left() + FMainWindowBorder->leftBorderWidth()); windowRect.setRight(windowRect.right() - FMainWindowBorder->rightBorderWidth()); windowRect.setTop(windowRect.top() + FMainWindowBorder->topBorderWidth()); windowRect.setBottom(windowRect.bottom() - FMainWindowBorder->bottomBorderWidth()); } mainWindowTopWidget()->move(windowRect.topLeft()); } }
// Paint event callback void TColourScaleEditor::paintEvent(QPaintEvent *event) { QPainter painter(this); // Get the size of the textrect we need QRect masterTextRect = style()->itemTextRect(fontMetrics(), QRect(), Qt::AlignRight | Qt::AlignVCenter, true, QString::number(-0.123456, 'e', 6)); int margin = masterTextRect.height()*0.5; masterTextRect.setLeft(margin); masterTextRect.setRight(width() - gradientBarWidth_ - 3*margin - handleRadius_*2); // Set up the basic handle style option QStyleOption handleOption; handleOption.rect.setRight(width()-margin); handleOption.rect.setLeft(width()-margin-handleRadius_*2); handleOption.rect.setHeight(masterTextRect.height()); // Draw gradient bar QBrush brush(gradient_); QPen pen(Qt::black); QRect gradientRect; gradientRect.setHeight(height()-2*margin); gradientRect.setWidth(gradientBarWidth_); gradientRect.moveTop(margin); gradientRect.moveRight(width() - 2*margin - handleRadius_*2); painter.setBrush(brush); painter.setPen(pen); painter.drawRect(gradientRect); // Define regions gradientBarRegion_ = QRegion(gradientRect); // -- Handle and label region spans top to bottom of the widget (i.e. excluding margins) handleRegion_ = QRegion(QRect(width() - margin - 2*handleRadius_, 0, 2*handleRadius_, height())); labelRegion_ = QRegion(QRect(0, 0, width() - gradientRect.right() - margin, height())); // Draw text and line elements if (colourScale_.nPoints() > 0) { double zero = colourScale_.firstPoint()->value(); double span = colourScale_.lastPoint()->value() - zero; for (ColourScalePoint* csp = colourScale_.firstPoint(); csp != NULL; csp = csp->next) { int y = (1.0 - (csp->value() - zero) / span) * (height() - 2*margin) + margin; QString numberText = QString::number(csp->value(), 'e', 6); masterTextRect.moveBottom(y + 0.5*masterTextRect.height()); painter.setPen(palette().text().color()); style()->drawItemText(&painter, masterTextRect, Qt::AlignRight | Qt::AlignVCenter, palette(), true, numberText); painter.drawLine(gradientRect.left()-margin, y, gradientRect.right()+margin, y); // Draw handle for this point handleOption.rect.moveBottom(y + 0.5*masterTextRect.height()); if (csp == currentColourScalePoint_) handleOption.state = QStyle::State_Enabled; else if (csp == hoverColourScalePoint_) handleOption.state = QStyle::State_MouseOver; else handleOption.state = 0; drawHandle(handleOption, painter); } } painter.end(); }
//----------------------------------------------------------------------------- QRect ctkCheckablePushButtonPrivate::checkboxRect()const { Q_Q(const ctkCheckablePushButton); QRect rect; QStyleOptionButton opt; q->initStyleOption(&opt); QSize indicatorSize = QSize(q->style()->pixelMetric(QStyle::PM_IndicatorWidth, &opt, q), q->style()->pixelMetric(QStyle::PM_IndicatorHeight, &opt, q)); int buttonHeight = opt.rect.height(); uint tf = this->TextAlignment; if (q->style()->styleHint(QStyle::SH_UnderlineShortcut, &opt, q)) { tf |= Qt::TextShowMnemonic; } else { tf |= Qt::TextHideMnemonic; } int textWidth = opt.fontMetrics.boundingRect(opt.rect, tf, opt.text).width(); int indicatorSpacing = q->style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, &opt, q); int buttonMargin = q->style()->pixelMetric(QStyle::PM_ButtonMargin, &opt, q); if (this->IndicatorAlignment & Qt::AlignLeft) { rect = QRect((buttonHeight - indicatorSize.width()) / 2, (buttonHeight - indicatorSize.height()) / 2, indicatorSize.width(), indicatorSize.height()); } else if (this->IndicatorAlignment & Qt::AlignHCenter) { int w = indicatorSize.width(); if (!opt.text.isEmpty() && (this->TextAlignment & Qt::AlignHCenter)) { w += textWidth + indicatorSpacing; } rect = QRect(opt.rect.x()+ opt.rect.width() /2 - w / 2, (buttonHeight - indicatorSize.height()) / 2, indicatorSize.width(), indicatorSize.height()); if (this->TextAlignment & Qt::AlignLeft && rect.left() < opt.rect.x() + buttonMargin + textWidth) { rect.moveLeft(opt.rect.x() + buttonMargin + textWidth); } else if (this->TextAlignment & Qt::AlignRight && rect.right() > opt.rect.right() - buttonMargin - textWidth) { rect.moveRight(opt.rect.right() - buttonMargin - textWidth); } } else if (this->IndicatorAlignment & Qt::AlignRight) { rect = QRect(opt.rect.width() - (buttonHeight - indicatorSize.width()) / 2 - indicatorSize.width(), (buttonHeight - indicatorSize.height()) / 2, indicatorSize.width(), indicatorSize.height()); } return rect; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuGridCrossQwtPlot::updateInfoBoxLayout() { RimGridCrossPlot* crossPlot = dynamic_cast<RimGridCrossPlot*>(ownerPlotDefinition()); if (!crossPlot) return; bool showInfo = false; if (crossPlot->showInfoBox()) { QStringList curveInfoTexts; for (auto dataSet : crossPlot->dataSets()) { QString curveInfoText = dataSet->infoText(); if (dataSet->isChecked() && !curveInfoText.isEmpty()) { curveInfoTexts += curveInfoText; } } QStringList infoText; if (curveInfoTexts.size() > 1) { infoText += QString("<ol style=\"margin-top: 0px; margin-left: 15px; -qt-list-indent:0;\">"); for (QString curveInfoText : curveInfoTexts) { infoText += QString("<li>%1</li>").arg(curveInfoText); } infoText += QString("</ol>"); } else if (curveInfoTexts.size() > 0) { infoText += curveInfoTexts.front(); } if (!infoText.empty()) { m_infoBox->label()->setText(infoText.join("\n")); QFont font = m_infoBox->font(); font.setPointSize(crossPlot->legendFontSize()); m_infoBox->setFont(font); m_infoBox->adjustSize(); QRect infoRect = m_infoBox->frameGeometry(); QRect canvasRect = canvas()->frameGeometry(); infoRect.moveTop(canvasRect.top() + 4); infoRect.moveRight(canvasRect.right() - 4); m_infoBox->move(infoRect.topLeft()); showInfo = true; } } if (showInfo) { m_infoBox->show(); } else { m_infoBox->hide(); } }
QRect Palapeli::CollectionDelegate::thumbnailRect (const QRect& baseRect) const { QRect thumbnailBaseRect (QPoint(Metrics::Padding + baseRect.left(), 0), Palapeli::PuzzleMetadata::ThumbnailBaseSize); thumbnailBaseRect.moveCenter (QPoint(thumbnailBaseRect.center().x(), baseRect.center().y())); if (QApplication::isRightToLeft()) { thumbnailBaseRect.moveRight (baseRect.right() - Metrics::Padding); } return thumbnailBaseRect; }
void ProgramEdit::resizeEvent(QResizeEvent *event) { int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); QRect btnRect = QRect(QPoint(0,0), QSize(rect().height(), rect().height())); btnRect.moveCenter(rect().center()); btnRect.moveRight(rect().right()); btnRect.adjust(frameWidth + 4, frameWidth + 4 , -frameWidth - 4, -frameWidth - 4); mBtn->setGeometry(btnRect); }
void SpinMirror::setFrame() { // Paint the left hand frame of the main spinbox. // Use the part to the left of the edit field, plus a slice at // the left of the edit field stretched for the rest of the width. // This avoids possibly grabbing text and displaying it in the // spin button area. QGraphicsScene* c = scene(); QStyleOptionSpinBox option; option.initFrom(mMainSpinbox); QRect r = spinBoxEditFieldRect(mMainSpinbox, option); bool rtl = QApplication::isRightToLeft(); QPixmap p; if (mMirrored) { int x = rtl ? 0 : mMainSpinbox->width() - width(); p = grabWidget(mMainSpinbox, QRect(x, 0, width(), height())); } else { // Grab a single pixel wide vertical slice through the main spinbox, between the // frame and edit field. bool oxygen = mMainSpinbox->style()->inherits("Oxygen::Style"); // KDE >= 4.4 Oxygen style bool oxygen1 = mMainSpinbox->style()->inherits("OxygenStyle"); // KDE <= 4.3 Oxygen style int editOffsetY = oxygen ? 5 : oxygen1 ? 6 : 2; // offset to edit field int editOffsetX = (oxygen || oxygen1) ? 4 : 2; // offset to edit field int x = rtl ? r.right() - editOffsetX : r.left() + editOffsetX; p = grabWidget(mMainSpinbox, QRect(x, 0, 1, height())); // Blot out edit field stuff from the middle of the slice QPixmap dot = grabWidget(mMainSpinbox, QRect(x, editOffsetY, 1, 1)); QPainter painter(&p); painter.drawTiledPixmap(0, editOffsetY, 1, height() - 2*editOffsetY, dot, 0, 0); painter.end(); // Horizontally fill the mirror widget with the vertical slice p = p.scaled(size()); // Grab the left hand border of the main spinbox, and draw it into the mirror widget. QRect endr = rect(); if (rtl) { int mr = mMainSpinbox->width() - 1; endr.setWidth(mr - r.right() + editOffsetX); endr.moveRight(mr); } else endr.setWidth(r.left() + editOffsetX); x = rtl ? width() - endr.width() : 0; mMainSpinbox->render(&p, QPoint(x, 0), endr, QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask); } c->setBackgroundBrush(p); }
void RsaToolbox::shake(QWidget *widget) { QRect startPosition = widget->geometry(); startPosition.moveRight(startPosition.right() + 10); QEasingCurve curve(QEasingCurve::OutElastic); curve.setAmplitude(2); curve.setPeriod(0.3); QPropertyAnimation *animation = new QPropertyAnimation(widget, "geometry"); animation->setStartValue(startPosition); animation->setEndValue(widget->geometry()); animation->setDuration(500); animation->setEasingCurve(curve); animation->start(); }
int drawFieldAndValue(QPainter *painter, QFont font, QString htmlField, QString htmlFieldValue, QRect rect){ QRect rightRect = rect; rightRect.moveRight(rect.right() - rect.width()*(1 - FIELD_NAME_RIGHTSPACE_RATIO)); int fieldNameFontSize = fontSize4Width( crudeHtmlFragmentToPlainText(htmlField), rightRect.size(), font); QString txt = htmlFontSizeFormat(htmlField, fieldNameFontSize) + " " + htmlFieldValue; bool breakLine = (fieldNameFontSize < FIELD_NAME_FONT_STANDARDSIZE); if(painter){ drawHtmlLine(painter, font, rect, txt, breakLine); } return fieldNameFontSize + UI_FIELD_FONT_MARGIN; }
static void slideInto(const QRect& region, QRect& obj) { if (obj.left() < region.left()) { obj.moveLeft(region.left()); } if (obj.right() > region.right()) { obj.moveRight(region.right()); } if (obj.bottom() > region.bottom()) { obj.moveBottom(region.bottom()); } if (obj.top() < region.top()) { obj.moveTop(region.top()); } }
static QRect adjustToDesktop( const QRect& r ) { QRect desk = QApplication::desktop()->availableGeometry(); QRect ret = r; if ( ret.top()<desk.top() ) ret.moveTop( desk.top() ); if ( ret.left()<desk.left() ) ret.moveLeft( desk.left() ); if ( ret.bottom()>desk.bottom() ) ret.moveBottom( desk.bottom() ); if ( ret.right()>desk.right() ) ret.moveRight( desk.right() ); return ret.normalized(); }
void KDEIntegrationTray::showNotes(bool active, const QPoint &pos) { Q_UNUSED(active) Menu menu; menu.addAction(actNew); menu.addSeparator(); QSettings s; QList<NoteListItem> notes = NoteManager::instance()->noteList( s.value("ui.menu-notes-amount", 15).toInt()); for (int i=0; i<notes.count(); i++) { menu.addAction(NoteManager::instance()->storage(notes[i].storageId)->noteIcon(), Utils::cuttedDots(notes[i].title, 48).replace('&', "&&") )->setData(i); } menu.show(); qtnote->activateWidget(&menu); QRect dr = QApplication::desktop()->availableGeometry(QCursor::pos()); QRect mr = menu.geometry(); mr.setSize(menu.sizeHint()); QPoint mp = pos - QPoint(mr.width() / 2, 0); if (pos.y() < dr.height()/2) { // icon at top-left mr.moveTopLeft(mp); } else { // icons at bottom-left mr.moveBottomLeft(mp); } // and now align to available desktop geometry if (mr.right() > dr.right()) { mr.moveRight(dr.right()); } if (mr.bottom() > dr.bottom()) { mr.moveBottom(dr.bottom()); } if (mr.left() < dr.left()) { mr.moveLeft(dr.left()); } if (mr.top() < dr.top()) { mr.moveTop(dr.top()); } QAction *act = menu.exec(mr.topLeft()); if (act && act != actNew) { NoteListItem ¬e = notes[act->data().toInt()]; emit showNoteTriggered(note.storageId, note.id); } }
QRect Style::subElementRect ( SubElement element, const QStyleOption * option, const QWidget * widget ) const { if (shouldNotHandle(widget)) { return QProxyStyle::subElementRect(element, option, widget); } switch(element) { // NOTE: Assuming horizontal tab bar direction case QStyle::SE_TabBarTabRightButton: { QRect r; r.setSize(QSize(16, 16)); r.moveCenter(option->rect.center()); r.moveRight(option->rect.right() + 1 - 5); return r; } case QStyle::SE_TabBarTabLeftButton: { QRect r; r.setSize(QSize(16, 16)); r.moveCenter(option->rect.center()); r.moveLeft(option->rect.left() + 5); return r; } case QStyle::SE_TabBarTabText: { const QStyleOptionTabV3 *tabOption = static_cast<const QStyleOptionTabV3*>(option); int lMargin = 5; if (tabOption->leftButtonSize.width() > 0) lMargin += tabOption->leftButtonSize.width() + 4; if (!tabOption->icon.isNull()) lMargin += tabOption->iconSize.width() + 4; int rMargin = 5; if (tabOption->rightButtonSize.width() > 0) rMargin += tabOption->rightButtonSize.width() + 4; QRect r = option->rect; r.adjust( lMargin, 0, -rMargin, 0 ); return r; } default: return QProxyStyle::subElementRect(element, option, widget); } }
void RestrainWidgetToScreen(QWidget * w) { QRect screenRect = QApplication::desktop()->availableGeometry(w); QRect wRect = w->frameGeometry(); /* std::cout<<"fg left: "<<w->frameGeometry().left(); std::cout<<" fg right: "<<w->frameGeometry().right(); std::cout<<" fg top: "<<w->frameGeometry().top(); std::cout<<" fg bottom: "<<w->frameGeometry().bottom()<<std::endl; std::cout<<"scr left: "<<screenRect.left(); std::cout<<" scr right: "<<screenRect.right(); std::cout<<" scr top: "<<screenRect.top(); std::cout<<" scr bottom: "<<screenRect.bottom()<<std::endl; */ //make sure the window fits the screen if(screenRect.width() < wRect.width()){ wRect.setWidth(screenRect.width()); } if(screenRect.height() < wRect.height()){ wRect.setHeight(screenRect.height()); } //shuffle the window so it is fully visible if(screenRect.left() > wRect.left()){ wRect.moveLeft(screenRect.left()); } if(screenRect.right() < wRect.right()){ wRect.moveRight(screenRect.right()); } if(screenRect.bottom() < wRect.bottom()){ wRect.moveBottom(screenRect.bottom()); } if(screenRect.top() > wRect.top()){ wRect.moveTop(screenRect.top()); } w->resize(wRect.size()); w->move(wRect.topLeft()); /* std::cout<<"fg left: "<<w->frameGeometry().left(); std::cout<<" fg right: "<<w->frameGeometry().right(); std::cout<<" fg top: "<<w->frameGeometry().top(); std::cout<<" fg bottom: "<<w->frameGeometry().bottom()<<std::endl; */ }
void LineEditWidget::showPopup() { _popup->adjustSize(); _popup->move(mapToGlobal(QPoint(width() - _popup->geometry().width(), height()))); QSize size = qApp->desktop()->size(); QRect rect = _popup->geometry(); // if widget is beyond edge of display if(rect.right() > size.width()) { rect.moveRight(size.width()); } if(rect.bottom() > size.height()) { rect.moveBottom(size.height()); } _popup->move(rect.topLeft()); _popup->show(); }
void QSRectClass::moveRight(QSEnv *env) { QRect *r = rect(env); if (env->numArgs() != 1) { env->throwError(QString::fromLatin1("Rect.moveRight() called with %1 arguments. 1 argument expected."). arg(env->numArgs())); return; } if (!env->arg(0).isNumber()) { env->throwError(QString::fromLatin1("Rect.moveRight() called with an argument of type %1. " "Type Number is expeced"). arg(env->arg(0).typeName())); return; } r->moveRight(env->arg(0).toInteger()); }
void QSplitterPrivate::setGeo(QSplitterLayoutStruct *sls, int p, int s, bool allowCollapse) { Q_Q(QSplitter); QWidget *w = sls->widget; QRect r; QRect contents = q->contentsRect(); if (orient == Qt::Horizontal) { r.setRect(p, contents.y(), s, contents.height()); } else { r.setRect(contents.x(), p, contents.width(), s); } sls->rect = r; int minSize = pick(qSmartMinSize(w)); if (orient == Qt::Horizontal && q->isRightToLeft()) r.moveRight(contents.width() - r.left()); if (allowCollapse) sls->collapsed = s <= 0 && minSize > 0 && !w->isHidden(); // Hide the child widget, but without calling hide() so that // the splitter handle is still shown. if (sls->collapsed) r.moveTopLeft(QPoint(-r.width()-1, -r.height()-1)); w->setGeometry(r); if (!sls->handle->isHidden()) { QSplitterHandle *h = sls->handle; QSize hs = h->sizeHint(); int left, top, right, bottom; h->getContentsMargins(&left, &top, &right, &bottom); if (orient==Qt::Horizontal) { if (q->isRightToLeft()) p = contents.width() - p + hs.width(); h->setGeometry(p-hs.width() - left, contents.y(), hs.width() + left + right, contents.height()); } else { h->setGeometry(contents.x(), p-hs.height() - top, contents.width(), hs.height() + top + bottom); } } }
void TimeZoneWidget::paintEvent(QPaintEvent*) { const int width = this->width(); const int height = this->height(); QFontMetrics fontMetrics(font); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setFont(font); // Draw background painter.drawImage(0, 0, background); // Draw zone image painter.drawImage(0, 0, currentZoneImage); // Draw pin QPoint point = getLocationPosition(currentLocation.longitude, currentLocation.latitude); painter.drawImage(point.x() - pin.width()/2, point.y() - pin.height()/2, pin); // Draw text and box const int textWidth = fontMetrics.width(currentLocation.zone); const int textHeight = fontMetrics.height(); QRect rect = QRect(point.x() - textWidth/2 - 5, point.y() - textHeight - 8, textWidth + 10, textHeight - 2); if (rect.x() <= 5) rect.moveLeft(5); if (rect.right() >= width-5) rect.moveRight(width - 5); if (rect.y() <= 5) rect.moveTop(5); if (rect.y() >= height-5) rect.moveBottom(height-5); painter.setPen(QPen()); // no pen painter.setBrush(QColor(40, 40, 40)); painter.drawRoundedRect(rect, 3, 3); painter.setPen(Qt::white); painter.drawText(rect.x() + 5, rect.bottom() - 4, currentLocation.zone); painter.end(); }
QRect WidgetManager::alignRect(const QRect &ARect, const QRect &ABoundary, Qt::Alignment AAlign) { QRect rect = ARect; if (AAlign>0 && !ARect.isEmpty() && !ABoundary.isEmpty()) { if ((AAlign & Qt::AlignLeft) == Qt::AlignLeft) rect.moveLeft(ABoundary.left()); else if ((AAlign & Qt::AlignRight) == Qt::AlignRight) rect.moveRight(ABoundary.right()); else if ((AAlign & Qt::AlignHCenter) == Qt::AlignHCenter) rect.moveLeft((ABoundary.width()-ARect.width())/2); if ((AAlign & Qt::AlignTop) == Qt::AlignTop) rect.moveTop(ABoundary.top()); else if ((AAlign & Qt::AlignBottom) == Qt::AlignBottom) rect.moveBottom(ABoundary.bottom()); else if ((AAlign & Qt::AlignVCenter) == Qt::AlignVCenter) rect.moveTop((ABoundary.height() - ARect.height())/2); } return rect; }
QRect PluginItemDelegate::alignRect( QRect object, QRect frame, int position, Qt::AlignmentFlag alignment ) const { QRect rect = object; rect.setTopLeft( QPoint( 0, 0 ) ); // Moves the object to the middle of the item. if ( rect.height() < frame.height() ) { rect.moveTop( ( frame.height() - rect.height() ) / 2 ); } if ( alignment & Qt::AlignLeft ) { rect.moveLeft( position ); } else if ( alignment & Qt::AlignRight ) { rect.moveRight( position ); } return rect; }
void slideRight2LeftWidget(QWidget *left, QWidget *right, int delay) { right->show(); left->show(); right->resize(left->size()); QRect leftStart = QRect(0, 0, left->width(), left->height()); QRect leftEnd = leftStart; leftEnd.moveLeft(-left->width()); QPropertyAnimation *animation = new QPropertyAnimation(left, "geometry"); animation->setDuration(delay); animation->setEasingCurve(QEasingCurve::InOutCubic); animation->setStartValue(leftStart); animation->setEndValue(leftEnd); animation->start(); QRect rightStart = QRect(left->width(), 0, right->width(), right->height()); QRect rightEnd = rightStart; rightEnd.moveRight(left->width() - 1); QPropertyAnimation *animation2 = new QPropertyAnimation(right, "geometry"); animation2->setEasingCurve(QEasingCurve::InOutCubic); animation2->setDuration(delay); animation2->setStartValue(rightStart); animation2->setEndValue(rightEnd); animation2->start(); animation->connect(animation, &QPropertyAnimation::finished, animation, &QPropertyAnimation::deleteLater); animation2->connect(animation2, &QPropertyAnimation::finished, animation2, &QPropertyAnimation::deleteLater); animation2->connect(animation2, &QPropertyAnimation::finished, left, &QWidget::hide); }
/*! Calculate the geometry of the legend on the canvas \param canvasRect Geometry of the canvas \return Geometry of the legend */ QRect QwtPlotLegendItem::geometry( const QRectF &canvasRect ) const { QRect rect; rect.setSize( d_data->layout->sizeHint() ); int margin = d_data->borderDistance; if ( d_data->alignment & Qt::AlignHCenter ) { int x = qRound( canvasRect.center().x() ); rect.moveCenter( QPoint( x, rect.center().y() ) ); } else if ( d_data->alignment & Qt::AlignRight ) { rect.moveRight( qFloor( canvasRect.right() - margin ) ); } else { rect.moveLeft( qCeil( canvasRect.left() + margin ) ); } if ( d_data->alignment & Qt::AlignVCenter ) { int y = qRound( canvasRect.center().y() ); rect.moveCenter( QPoint( rect.center().x(), y ) ); } else if ( d_data->alignment & Qt::AlignBottom ) { rect.moveBottom( qFloor( canvasRect.bottom() - margin ) ); } else { rect.moveTop( qCeil( canvasRect.top() + margin ) ); } return rect; }
QRect WidgetManager::correctWindowGeometry(const QRect &AGeometry, QWidget *AWindow) { QRect newGeometry = AGeometry; QRect screenRect = qApp->desktop()->availableGeometry(qApp->desktop()->screenNumber(AGeometry.topLeft())); CustomBorderContainer *border = AWindow!=NULL ? CustomBorderStorage::widgetBorder(AWindow) : NULL; if (border) { newGeometry.setLeft(newGeometry.left() + border->leftBorderWidth()); newGeometry.setRight(newGeometry.right() - border->rightBorderWidth()); newGeometry.setTop(newGeometry.top() + border->topBorderWidth()); newGeometry.setBottom(newGeometry.bottom() - border->bottomBorderWidth()); } if (!screenRect.isEmpty() && !screenRect.contains(newGeometry)) { if (newGeometry.left() < screenRect.left()) newGeometry.moveLeft(screenRect.left()); else if (newGeometry.right() > screenRect.right()) newGeometry.moveRight(screenRect.right()); if (newGeometry.top() < screenRect.top()) newGeometry.moveTop(screenRect.top()); else if (newGeometry.bottom() > screenRect.bottom()) newGeometry.moveBottom(screenRect.bottom()); } if (border) { newGeometry.setLeft(newGeometry.left() - border->leftBorderWidth()); newGeometry.setRight(newGeometry.right() + border->rightBorderWidth()); newGeometry.setTop(newGeometry.top() - border->topBorderWidth()); newGeometry.setBottom(newGeometry.bottom() + border->bottomBorderWidth()); } return newGeometry; }
void QToolBarAreaLayout::apply(bool animate) { QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(mainWindow->layout()); Q_ASSERT(layout != 0); Qt::LayoutDirection dir = mainWindow->layoutDirection(); for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; for (int j = 0; j < dock.lines.count(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines.at(j); if (line.skip()) continue; for (int k = 0; k < line.toolBarItems.count(); ++k) { const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); if (item.skip() || item.gap) continue; QRect r; if (visible) { if (line.o == Qt::Horizontal) { r.setTop(line.rect.top()); r.setBottom(line.rect.bottom()); r.setLeft(line.rect.left() + item.pos); r.setRight(line.rect.left() + item.pos + item.size - 1); } else { r.setLeft(line.rect.left()); r.setRight(line.rect.right()); r.setTop(line.rect.top() + item.pos); r.setBottom(line.rect.top() + item.pos + item.size - 1); } } QWidget *widget = item.widgetItem->widget(); if (QToolBar *toolBar = qobject_cast<QToolBar*>(widget)) { QToolBarLayout *tbl = qobject_cast<QToolBarLayout*>(toolBar->layout()); if (tbl->expanded) { QPoint tr = r.topRight(); QSize size = tbl->expandedSize(r.size()); r.setSize(size); r.moveTopRight(tr); if (r.bottom() > rect.bottom()) r.moveBottom(rect.bottom()); if (r.right() > rect.right()) r.moveRight(rect.right()); if (r.left() < 0) r.moveLeft(0); if (r.top() < 0) r.moveTop(0); } } QRect geo = r; if (visible && dock.o == Qt::Horizontal) geo = QStyle::visualRect(dir, line.rect, geo); layout->widgetAnimator->animate(widget, geo, animate); } } } }
void DeckButtonsLayout::setGeometry( const QRect& _r ) { QLayout::setGeometry( _r ); int left; int top; int right; int bottom; getContentsMargins( &left, &top, &right, &bottom ); const QRect r = _r.adjusted( left, top, right, bottom ); const QAbstractButton* button = backwardButton ? backwardButton : forwardButton; qreal factor = 1; if ( !button ) { if ( RoundButton ) { const int min = qMin( r.height(), r.width() ); QRect rect = QRect( QPoint(), QSize( min, min ) ); rect.moveCenter( r.center() ); RoundButton->setGeometry( rect ); } return; } else if ( backwardButton && forwardButton ) { factor = (qreal)r.width() /(qreal)( button->sizeHint().width() *2 ); } else if ( RoundButton ) { factor = (qreal)r.width() /(qreal)( button->sizeHint().width() +( RoundButton->sizeHint().width() /2 ) ); } else { factor = (qreal)r.width() /(qreal)( button->sizeHint().width() ); } if ( RoundButton ) { int height = (qreal)RoundButton->sizeHint().height() *factor; while ( height > r.height() ) { factor -= 0.1; height = (qreal)RoundButton->sizeHint().height() *factor; } QRect rect( QPoint(), QSize( height, height ) ); rect.moveCenter( r.center() ); if ( backwardButton && forwardButton ) { // nothing to do } else if ( backwardButton ) { rect.moveRight( r.right() ); } else if ( forwardButton ) { rect.moveLeft( r.left() ); } RoundButton->setGeometry( rect ); } else { int height = (qreal)button->sizeHint().height() *factor; while ( height > r.height() ) { factor -= 0.1; height = (qreal)button->sizeHint().height() *factor; } } const QSize bs = QSize( (qreal)button->sizeHint().width() *factor, (qreal)button->sizeHint().height() *factor ); if ( backwardButton ) { QRect gr = RoundButton ? QRect( QPoint(), RoundButton->size() ) : r; QRect rect = QRect( QPoint(), bs ); if ( RoundButton ) { gr.moveTopLeft( RoundButton->pos() ); } rect.moveCenter( gr.center() ); rect.moveRight( gr.center().x() +1 ); backwardButton->setGeometry( rect ); } if ( forwardButton ) { QRect gr = RoundButton ? QRect( QPoint(), RoundButton->size() ) : r; QRect rect = QRect( QPoint(), bs ); if ( RoundButton ) { gr.moveTopLeft( RoundButton->pos() ); } rect.moveCenter( gr.center() ); rect.moveLeft( gr.center().x() ); forwardButton->setGeometry( rect ); } if ( RoundButton ) { RoundButton->raise(); } }
void Palapeli::CollectionDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QRect baseRect = option.rect; // Total space available for item. // Calculate item's column number in list-view. Add 1 in odd-numbered rows. int nItemsPerRow = qMax (m_viewport->width() / baseRect.width(), 1); int oddColumn = index.row() % nItemsPerRow; oddColumn = oddColumn + ((index.row() / nItemsPerRow) % 2); // Draw background of item. QColor bkgColor; if (option.state & QStyle::State_Selected) { bkgColor = option.palette.color (QPalette::Highlight); } else if (oddColumn % 2) { // The shading alternates along each row in the list view and // each odd-numbered row starts with a shaded item, so we have // a checkerboard pattern, regardless of whether nItemsPerRow // is odd or even (see the above calculation). bkgColor = option.palette.color (QPalette::AlternateBase); } else { bkgColor = option.palette.color (QPalette::Base); } painter->fillRect (option.rect, bkgColor); // Draw thumbnail. QRect thumbnailBaseRect = this->thumbnailRect (baseRect); const QPixmap thumbnail = index.data (Palapeli::Collection::ThumbnailRole) .value<QPixmap>(); QRect thumbnailRect (thumbnailBaseRect.topLeft(), thumbnail.size()); thumbnailRect.translate ( // Center inside thumbnailBaseRect. (thumbnailBaseRect.width() - thumbnailRect.width()) / 2, (thumbnailBaseRect.height() - thumbnailRect.height()) / 2); painter->drawPixmap (thumbnailRect.topLeft(), thumbnail); // Calculate the maximum space available for text lines. QRect textBaseRect (baseRect); textBaseRect.setWidth (baseRect.width() - thumbnailBaseRect.width() - 2*Metrics::Padding); if (option.direction == Qt::RightToLeft) { textBaseRect.moveRight (thumbnailBaseRect.left() - Metrics::Padding); textBaseRect.adjust (Metrics::Padding, Metrics::Padding, 0, -Metrics::Padding); } else { textBaseRect.moveLeft (thumbnailBaseRect.right() + Metrics::Padding); textBaseRect.adjust (0, Metrics::Padding, -Metrics::Padding, -Metrics::Padding); } // Find the contents and sizes for the text lines. QStringList texts; QList<QFont> fonts; { QString name = index.data(Palapeli::Collection::NameRole).toString(); const int pieceCount = index.data (Palapeli::Collection::PieceCountRole) .toInt(); if (name.isEmpty()) { name = i18n("[No name]"); } if (pieceCount > 0) { name = ki18ncp ( "Puzzle description, %2 = name string, %1 = piece count", "%2 (%1 piece)", "%2 (%1 pieces)") .subs(pieceCount).subs(name).toString(); } texts << name; QFont theFont (painter->font()); theFont.setBold(true); fonts << theFont; }{ QString comment = index.data (Palapeli::Collection::CommentRole) .toString(); if (!comment.isEmpty()) { texts << comment; fonts << painter->font(); } }{ QString author = index.data (Palapeli::Collection::AuthorRole) .toString(); if (!author.isEmpty()) { const QString authorString = ki18nc ( "Author attribution, e.g. \"by Jack\"", "by %1") .subs(author).toString(); texts << authorString; QFont theFont (painter->font()); theFont.setItalic(true); fonts << theFont; } } QList<QRect> textRects; int totalTextHeight = 0; QRect maxRect (QPoint(0, 0), textBaseRect.size()); for (int i = 0; i < texts.count(); ++i) { QFontMetrics fm(fonts[i]); textRects << fm.boundingRect (maxRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, texts[i]); totalTextHeight += textRects[i].height(); } // Vertically center however many text lines there are. textBaseRect.setHeight (totalTextHeight); textBaseRect.moveTop (baseRect.top() + (baseRect.height() - textBaseRect.height()) / 2); // Draw the text lines. QRect currentTextRect (textBaseRect); painter->save(); for (int i = 0; i < texts.count(); ++i) { painter->setFont(fonts[i]); const QRect& textRect = textRects[i]; currentTextRect.setHeight(textRect.height()); painter->drawText (currentTextRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, texts[i]); currentTextRect.moveTop (currentTextRect.bottom()); } painter->restore(); }
void KateArgumentHintTree::updateGeometry(QRect geom) { //Avoid recursive calls of updateGeometry static bool updatingGeometry = false; if( updatingGeometry ) return; updatingGeometry = true; if( model()->rowCount(QModelIndex()) == 0 ) { /* kDebug( 13035 ) << "KateArgumentHintTree:: empty model";*/ hide(); setGeometry(geom); updatingGeometry = false; return; } int bottom = geom.bottom(); int totalWidth = resizeColumns(); int totalHeight = 0; for(int a = 0; a < model()->rowCount( QModelIndex() ); ++a) { QModelIndex index(model()->index(a, 0)); totalHeight += rowHeight(index); for(int b = 0; b < model()->rowCount(index); ++b) { QModelIndex childIndex = index.child(b, 0); totalHeight += rowHeight(childIndex); } } totalHeight += frameWidth()*2; QRect topRect = visualRect(model()->index(0, 0)); QRect contentRect = visualRect(model()->index(model()->rowCount(QModelIndex())-1, 0)); geom.setHeight(totalHeight); geom.moveBottom(bottom); // if( totalWidth > geom.width() ) geom.setWidth(totalWidth); bool enableScrollBars = false; //Resize and move so it fits the screen horizontally int maxWidth = (QApplication::desktop()->screenGeometry(m_parent->view()).width()*3)/4; if( geom.width() > maxWidth ) { geom.setWidth(maxWidth); geom.setHeight(geom.height() + horizontalScrollBar()->height() +2); geom.moveBottom(bottom); enableScrollBars = true; } if (geom.right() > QApplication::desktop()->screenGeometry(m_parent->view()).right()) geom.moveRight( QApplication::desktop()->screenGeometry(m_parent->view()).right() ); if( geom.left() < QApplication::desktop()->screenGeometry(m_parent->view()).left() ) geom.moveLeft(QApplication::desktop()->screenGeometry(m_parent->view()).left()); //Resize and move so it fits the screen vertically bool resized = false; if( geom.top() < QApplication::desktop()->screenGeometry(this).top() ) { int offset = QApplication::desktop()->screenGeometry(this).top() - geom.top(); geom.setBottom( geom.bottom() - offset ); geom.moveTo(geom.left(), QApplication::desktop()->screenGeometry(this).top()); resized = true; } if(geom != geometry()) { setUpdatesEnabled(false); setAnimated(false); setHorizontalScrollBarPolicy( enableScrollBars ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff ); /* kDebug( 13035 ) << "KateArgumentHintTree::updateGeometry: updating geometry to " << geom;*/ setGeometry(geom); if( resized && currentIndex().isValid() ) scrollTo(currentIndex()); setUpdatesEnabled(true); } updatingGeometry = false; }