// Return ColourScalePoint corresponding to label under mouse (if any) ColourScalePoint* TColourScaleEditor::labelUnderMouse(QPoint pos) { // 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); // 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()); QRect textRect = style()->itemTextRect(fontMetrics(), masterTextRect, Qt::AlignRight | Qt::AlignVCenter, true, numberText); if (textRect.contains(pos)) return csp; } } return NULL; }
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()); } }
void QsvTextOperationsWidget::showBottomWidget(QWidget* w) { if (w == NULL) { if (m_replace && m_replace->isVisible()) w = m_replace; else if (m_search && m_search->isVisible()) w = m_search; else if (m_gotoLine && m_gotoLine->isVisible()) w = m_gotoLine; } if (!w) return; QRect r; QWidget *parent = qobject_cast<QWidget*>(this->parent()); // I must admit this line looks ugly, but I am open to suggestions if (parent->inherits("QAbstractScrollArea")) parent = ((QAbstractScrollArea*) (parent))->viewport(); r = parent->rect(); w->adjustSize(); r.adjust(10, 0, -10, 0); r.setHeight(w->height()); r.moveBottom(parent->rect().height()-10); r.moveLeft(parent->pos().x() + 10); w->setGeometry(r); w->show(); }
QRect CurveTracker::trackerRect( const QFont &font ) const { QRect r = QwtPlotPicker::trackerRect( font ); // align r to the first curve const QwtPlotItemList curves = plot()->itemList( QwtPlotItem::Rtti_PlotCurve ); if ( curves.size() > 0 ) { QPointF pos = invTransform( trackerPosition() ); const QLineF line = curveLineAt( static_cast<const QwtPlotCurve *>( curves[0] ), pos.x() ); if ( !line.isNull() ) { const double curveY = line.pointAt( ( pos.x() - line.p1().x() ) / line.dx() ).y(); pos.setY( curveY ); pos = transform( pos ); r.moveBottom( pos.y() ); } } return r; }
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()); }
// 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(); }
void DkPongPort::movePlayer(QRect& player, int velocity) { if (player.top() + velocity < 0) player.moveTop(0); else if (player.bottom() + velocity > height()) player.moveBottom(height()); else player.moveTop(player.top() + velocity); }
void TreeFinder::relocate() { QRect r = rect(); QRect br = parentWidget()->rect(); r.moveBottom(br.bottom()); r.setWidth(br.width() + 2); r.translate(-1, -offset()); setGeometry(r); raise(); }
QRect WinSnippingArea::getFullScreenRect() const { QRect fullScreenRect = QDesktopWidget().rect(); auto screenCount = QDesktopWidget().screenCount(); for(int i = 0; i < screenCount; i++) { auto screenRect = QDesktopWidget().screenGeometry(i); if(screenRect.x() < fullScreenRect.x()) { fullScreenRect.moveLeft(screenRect.x()); } if(screenRect.y() < fullScreenRect.y()) { fullScreenRect.moveBottom(screenRect.y()); } } return fullScreenRect; }
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(); }
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()); } }
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); } }
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 QSRectClass::moveBottom(QSEnv *env) { QRect *r = rect(env); if (env->numArgs() != 1) { env->throwError(QString::fromLatin1("Rect.moveBottom() called with %1 arguments. 1 argument expected."). arg(env->numArgs())); return; } if (!env->arg(0).isNumber()) { env->throwError(QString::fromLatin1("Rect.moveBottom() called with an argument of type %1. " "Type Number is expeced"). arg(env->arg(0).typeName())); return; } r->moveBottom(env->arg(0).toInteger()); }
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 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; }
void MainWindow::timerEvent(QTimerEvent*) { mate.moveToNextFrame(); mate.act(); move(pos() + mate.movement()); if(geometry().bottom() > screenRect.bottom()) { QRect newGeometry = geometry(); newGeometry.moveBottom(screenRect.bottom()); setGeometry(newGeometry); mate.meetGround(); } else if(!mate.isCaptured() && geometry().bottom() < screenRect.bottom()) { mate.startFalling(); } if(getProb(PORTAL_PROB)) { move(getRandomPos(screenRect, Mate::spriteSize())); mate.startFalling(); } update(); }
void ConvertEffectsTest::addText_middleBottomEdge() { QImage result(testImg); effects.setImage(&result); info.textPos = QPoint(50, 100); info.textUnitPair.first = Percent; info.textUnitPair.second = Percent; info.textFont.setFamily("DejaVu Sans"); info.textFont.setPointSize(20); info.textString = "test string"; info.textPosModifier = MiddleBottomEdge; info.textColor = Qt::green; info.textOpacity = 0.5; info.textRotation = 0; info.textFrame = false; effects.addText(); QImage expected(testImg); QPoint middleBottomPoint(expected.width()/2, expected.height()); QFontMetrics fontMetrics(info.textFont, &expected); QRect rect = fontMetrics.boundingRect(info.textString); const int dx = 5; const int dy = 1; rect.adjust(-dx, -dy, dx, dy); rect.moveCenter(middleBottomPoint); rect.moveBottom(middleBottomPoint.y()); QPainter p(&expected); p.setPen(info.textColor); p.setFont(info.textFont); p.setOpacity(info.textOpacity); p.drawText(rect, Qt::AlignCenter, info.textString); result.save(QDir::tempPath() + "/sir_test_addText_middleBottomEdge_result.bmp"); expected.save(QDir::tempPath() + "/sir_test_addText_middleBottomEdge_expected.bmp"); QCOMPARE(result, expected); }
/*! 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 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; }
void PluginItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { Q_ASSERT( index.isValid() ); QRect rect = option.rect; QStyle *style = QApplication::style(); painter->save(); // Drawing the background QStyleOption background = option; style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter ); painter->translate( rect.topLeft() ); // rect is now represented in item coordinates rect.moveTopLeft( QPoint( 0, 0 ) ); // The point at the top left of the available drawing area. QPoint topLeft( 0, 0 ); // The point at the top right of the available drawing area. QPoint topRight( rect.topRight() ); QRect nameRect = rect; // Painting the checkbox QStyleOptionButton checkBox = checkboxOption( option, index, topLeft.x(), Qt::AlignLeft ); painter->save(); style->drawControl( QStyle::CE_CheckBox, &checkBox, painter ); painter->restore(); nameRect.setLeft( checkBox.rect.right() + 1 ); // Painting the About Button QStyleOptionButton button = buttonOption( option, index, PluginItemDelegate::About, topRight.x(), Qt::AlignRight ); style->drawControl( QStyle::CE_PushButton, &button, painter ); topRight -= QPoint( button.rect.width(), 0 ); // Painting the Configure Button if ( index.data( RenderPluginModel::ConfigurationDialogAvailable ).toBool() ) { QStyleOptionButton button = buttonOption( option, index, PluginItemDelegate::Configure, topRight.x(), Qt::AlignRight ); style->drawControl( QStyle::CE_PushButton, &button, painter ); topRight -= QPoint( button.rect.width(), 0 ); nameRect.setRight( button.rect.left() -1 ); } // Painting the Icon const QIcon icon = index.data( Qt::DecorationRole ).value<QIcon>(); const QPixmap iconPixmap = icon.pixmap(16, 16); nameRect.moveBottom( nameRect.bottom()+5 ); style->drawItemPixmap( painter, nameRect, Qt::AlignLeft, iconPixmap ); nameRect.setLeft( nameRect.left() + 16 + 5 ); nameRect.moveBottom( nameRect.bottom()-5 ); // Painting the Name string QString name = index.data( Qt::DisplayRole ).toString(); style->drawItemText( painter, nameRect, Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, name ); painter->restore(); }
void slideTop2BottomWidget(QWidget *top, QWidget *bottom, int delay) { bottom->show(); top->show(); bottom->resize(top->size()); QRect topStart = QRect(0, 0, top->width(), top->height()); QRect topEnd = topStart; topEnd.moveTo(0, top->height()); QPropertyAnimation *animation = new QPropertyAnimation(top, "geometry"); animation->setDuration(delay); animation->setEasingCurve(QEasingCurve::InOutCubic); animation->setStartValue(topStart); animation->setEndValue(topEnd); animation->start(); animation->connect(animation, &QPropertyAnimation::finished, animation, &QPropertyAnimation::deleteLater); animation->connect(animation, &QPropertyAnimation::finished, top, &QWidget::hide); QRect bottomStart = QRect(0, -top->height(), bottom->width(), bottom->height()); QRect bottomEnd = bottomStart; bottomEnd.moveBottom(top->height() - 1); QPropertyAnimation *animation2 = new QPropertyAnimation(bottom, "geometry"); animation2->setEasingCurve(QEasingCurve::InOutCubic); animation2->setDuration(delay); animation2->setStartValue(bottomStart); animation2->setEndValue(bottomEnd); animation2->start(); animation2->connect(animation2, &QPropertyAnimation::finished, animation2, &QPropertyAnimation::deleteLater); auto bottomOpacity = new QGraphicsOpacityEffect(bottom); bottom->setGraphicsEffect(bottomOpacity); bottomOpacity->setOpacity(0); QPropertyAnimation *animation3 = new QPropertyAnimation(bottomOpacity, "opacity"); animation3->setEasingCurve(QEasingCurve::InCubic); animation3->setDuration(delay); animation3->setStartValue(0); animation3->setEndValue(1); animation3->start(); animation3->connect(animation3, &QPropertyAnimation::finished, animation3, &QPropertyAnimation::deleteLater); animation3->connect(animation3, &QPropertyAnimation::finished, bottom, [ = ]() { bottom->setGraphicsEffect(nullptr); }); auto topOpacity = new QGraphicsOpacityEffect(top); top->setGraphicsEffect(topOpacity); topOpacity->setOpacity(0.99); QPropertyAnimation *animation4 = new QPropertyAnimation(topOpacity, "opacity"); animation4->setEasingCurve(QEasingCurve::InCubic); animation4->setDuration(delay); animation4->setStartValue(0.99); animation4->setEndValue(0); animation4->start(); animation4->connect(animation4, &QPropertyAnimation::finished, animation4, &QPropertyAnimation::deleteLater); animation4->connect(animation4, &QPropertyAnimation::finished, bottom, [ = ]() { top->setGraphicsEffect(nullptr); }); }
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 K3b::FillStatusDisplay::slotMenuButtonClicked() { QRect alignedMenu = style()->alignedRect( layoutDirection(), Qt::AlignRight, d->popup->sizeHint(), d->buttonMenu->frameGeometry() ); alignedMenu.moveBottom( d->buttonMenu->frameGeometry().top() - 1 ); slotPopupMenu( mapToGlobal( alignedMenu.topLeft() ) ); }
void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { QString title = VLCModel::getMeta( index, COLUMN_TITLE ); QString duration = VLCModel::getMeta( index, COLUMN_DURATION ); if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration ); QString artist = VLCModel::getMeta( index, COLUMN_ARTIST ); QString album = VLCModel::getMeta( index, COLUMN_ALBUM ); QString trackNum = VLCModel::getMeta( index, COLUMN_TRACK_NUMBER ); QString artistAlbum = artist; if( !album.isEmpty() ) { if( !artist.isEmpty() ) artistAlbum += ": "; artistAlbum += album; if( !trackNum.isEmpty() ) artistAlbum += QString( " [#%1]" ).arg( trackNum ); } QPixmap artPix = VLCModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) ); //Draw selection rectangle and current playing item indication paintBackground( painter, option, index ); QRect artRect( artPix.rect() ); artRect.moveCenter( QPoint( artRect.center().x() + 3, option.rect.center().y() ) ); //Draw album art painter->drawPixmap( artRect, artPix ); //Start drawing text painter->save(); if( option.state & QStyle::State_Selected ) painter->setPen( option.palette.color( QPalette::HighlightedText ) ); QTextOption textOpt( Qt::AlignVCenter | Qt::AlignLeft ); textOpt.setWrapMode( QTextOption::NoWrap ); QFont f( index.data( Qt::FontRole ).value<QFont>() ); //Draw title info f.setItalic( true ); f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) ); f.setBold( index.data( PLModel::IsCurrentRole ).toBool() ); painter->setFont( f ); QFontMetrics fm( painter->fontMetrics() ); QRect textRect = option.rect.adjusted( LISTVIEW_ART_SIZE + 10, 0, -10, 0 ); if( !artistAlbum.isEmpty() ) { textRect.setHeight( fm.height() ); textRect.moveBottom( option.rect.center().y() - 2 ); } //Draw children indicator if( !index.data( PLModel::IsLeafNodeRole ).toBool() ) { QPixmap dirPix = QPixmap( ":/type/node" ); painter->drawPixmap( QPoint( textRect.x(), textRect.center().y() - dirPix.height() / 2 ), dirPix ); textRect.setLeft( textRect.x() + dirPix.width() + 5 ); } painter->drawText( textRect, fm.elidedText( title, Qt::ElideRight, textRect.width() ), textOpt ); // Draw artist and album info if( !artistAlbum.isEmpty() ) { f.setItalic( false ); painter->setFont( f ); fm = painter->fontMetrics(); textRect.moveTop( textRect.bottom() + 4 ); textRect.setLeft( textRect.x() + 20 ); painter->drawText( textRect, fm.elidedText( artistAlbum, Qt::ElideRight, textRect.width() ), textOpt ); } painter->restore(); }