void SensorWidget::newSection() { painter.drawLine(paintRect.left(), paintRectField1.top(), paintRect.width(), paintRectField1.top()); paintRectField0.moveTop(paintRectField0.top() + 1); paintRectField1.moveTop(paintRectField1.top() + 1); fillBackground = false; }
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); }
QRect MyAvatar::stringToScaledCrop(QString s, QSize scaled, QSize original, int angle, bool rotate) { QStringList result = s.split("-"); if (result.size() != 4) return QRect(); if (!scaled.isValid()) return QRect(); qreal scale = 1.0; if (angle % 2 == 0) { scale = (qreal) scaled.width() / (qreal) original.width(); } else { scale = (qreal) scaled.height() / (qreal) original.width(); } QRect crop = QRect(result.at(0).toInt(), result.at(1).toInt(), result.at(2).toInt(), result.at(3).toInt()); if (rotate) { int tmp; switch (angle) { case A_90: tmp = crop.x(); crop.moveLeft(original.height() - crop.y() - crop.height()); crop.moveTop(tmp); break; case A_180: crop.moveLeft(original.width() - crop.x() - crop.width()); crop.moveTop(original.height() - crop.y() - crop.height()); break; case A_270: tmp = crop.y(); crop.moveTop(original.width() - crop.x() - crop.width()); crop.moveLeft(tmp); break; } } crop.moveLeft(qRound(crop.x() * scale)); crop.moveTop(qRound(crop.y() * scale)); crop.setWidth(qRound(crop.width() * scale)); crop.setHeight(qRound(crop.height() * scale)); /* qDebug() << "stringToScaledCrop: string:" << s << "crop:" << crop << "scale:" << scale << "orgW:" << original.width() << "orgH:" << original.height() << "scaledW:" << scaled.width() << "scaledH:" << scaled.height() << "angle:" << angle; */ return crop; }
QString MyAvatar::scaledCropToString(QRect crop, QSize scaled, QSize original, int angle, bool rotate) { if (crop.isNull() || (crop.x() == 0 && crop.y() == 0 && crop.size() == scaled)) return QString::null; qreal scale = 1.0; if (angle % 2 == 0) { scale = (qreal) original.width() / (qreal) scaled.width(); } else { scale = (qreal) original.width() / (qreal) scaled.height(); } if (rotate) { int tmp; switch (angle) { case A_90: tmp = crop.x(); crop.moveLeft(crop.y()); crop.moveTop(scaled.width() - crop.width() - tmp); break; case A_180: crop.moveLeft(scaled.width() - crop.width() - crop.x()); crop.moveTop(scaled.height() - crop.height() - crop.y()); break; case A_270: tmp = crop.y(); crop.moveTop(crop.x()); crop.moveLeft(scaled.height() - crop.height() - tmp); break; } } crop.moveLeft(qRound(crop.x() * scale)); crop.moveTop(qRound(crop.y() * scale)); crop.setWidth(qRound(crop.width() * scale)); crop.setHeight(qRound(crop.height() * scale)); QString s = QString("%1-%2-%3-%4").arg(QString::number(crop.x()), QString::number(crop.y()), QString::number(crop.width()), QString::number(crop.height())); /* qDebug() << "scaledCropToString: string:" << s << "crop:" << crop << "scale:" << scale << "orgW:" << original.width() << "orgH:" << original.height() << "scaledW:" << scaled.width() << "scaledH:" << scaled.height() << "angle:" << angle; */ return s; }
void print(const char* name, const char* value1, const char* value2) { if(fillBackground) { painter.setPen(noPen); painter.drawRect(paintRect.left(), paintRectField1.top(), paintRect.width(), paintRectField1.height()); painter.setPen(fontPen); } painter.drawText(paintRectField0, Qt::TextSingleLine | Qt::AlignVCenter, name); painter.drawText(paintRectField1, Qt::TextSingleLine | Qt::AlignVCenter | Qt::AlignRight, value1); painter.drawText(paintRectField2, Qt::TextSingleLine | Qt::AlignVCenter | Qt::AlignRight, value2); paintRectField0.moveTop(paintRectField0.top() + lineSpacing); paintRectField1.moveTop(paintRectField1.top() + lineSpacing); paintRectField2.moveTop(paintRectField2.top() + lineSpacing); }
void SensorWidget::print(const QString& name, const QString& value) { if(fillBackground) { painter.setPen(noPen); painter.drawRect(paintRect.left(), paintRectField1.top(), paintRect.width(), paintRectField1.height()); painter.setPen(fontPen); } painter.drawText(paintRectField0, Qt::TextSingleLine | Qt::AlignVCenter, name); painter.drawText(paintRectField1, Qt::TextSingleLine | Qt::AlignVCenter | Qt::AlignRight, value); paintRectField0.moveTop(paintRectField0.top() + lineSpacing); paintRectField1.moveTop(paintRectField1.top() + lineSpacing); fillBackground = !fillBackground; }
void SelectableEntry::updateSize() { QFontMetrics metrics(m_ui->text->font()); int textWidth = metrics.width(m_ui->text->text()) + 2; int textHeight = metrics.height(); QRect topRect = m_ui->topLine->geometry(); topRect.setWidth(textWidth); m_ui->topLine->setGeometry(topRect); QRect textRect = m_ui->text->geometry(); textRect.setWidth(textWidth); textRect.setHeight(textHeight); m_ui->text->setGeometry(textRect); /* Calculate vertical displacement between the top line and the text label (as defined in the SelectableEntry.ui file), and use that same displacement between the text label and the bottom line. We always (?) use uppercase labels, which means we have to exclude the font's descent from our calculations. */ int delta_y = textRect.top() - topRect.bottom() + 1; QRect bottomRect = m_ui->bottomLine->geometry(); bottomRect.setWidth(textWidth); bottomRect.moveTop(textRect.bottom() + delta_y - metrics.descent()); m_ui->bottomLine->setGeometry(bottomRect); this->setFixedWidth(textWidth); this->setFixedHeight(bottomRect.bottom() + 1); }
void StatusLineEdit::paintEvent(QPaintEvent *event) { if(hasFocus()) { QLineEdit::paintEvent(event); } else { QStylePainter painter(this); if(underMouse()) { QStyleOptionButton opt; opt.initFrom(this); opt.state &= ~QStyle::State_HasFocus; painter.drawControl(QStyle::CE_PushButton, opt); } painter.setPen(palette().color(QPalette::Text)); QRect textRect = rect(); textRect.moveLeft(4); textRect.moveTop(1); if(text().isEmpty()) { painter.setPen(palette().color(QPalette::Dark)); QFont font = painter.font(); font.setItalic(true); painter.setFont(font); painter.drawText(textRect, Qt::AlignVCenter | Qt::TextSingleLine, tr("Description...")); } else { painter.drawText(textRect, Qt::AlignVCenter | Qt::TextSingleLine, painter.fontMetrics().elidedText(text(), Qt::ElideRight, width() - 4)); } } }
void AvatarPainter::doPaint(QPainter *painter, const QSize &size) { QPixmap displayAvatar; QPixmap croppedAvatar = cropped(); if (croppedAvatar.height() > size.height() || croppedAvatar.width() > size.width()) displayAvatar = croppedAvatar.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); else displayAvatar = croppedAvatar; QRect displayRect = displayAvatar.rect(); displayRect.moveTop((size.height() - displayRect.height()) / 2); displayRect.moveLeft((size.width() - displayRect.width()) / 2); // grey out offline contacts' avatar displayAvatar = greyOut() ? QIcon(displayAvatar).pixmap(displayAvatar.size(), QIcon::Disabled) : displayAvatar; int radius = 3; QPainterPath displayRectPath; displayRectPath.addRoundedRect(displayRect, radius, radius); painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); painter->setClipPath(displayRectPath); painter->drawPixmap(displayRect, displayAvatar); painter->setClipping(false); // draw avatar border if (Configuration->avatarBorder()) painter->drawRoundedRect(displayRect, radius, radius); }
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()); } }
QRect subElementRect(SubElement element, const QStyleOption* option, const QWidget* widget) const { QRect result = defaultStyle()->subElementRect(element, option, widget); switch (element) { case SE_TabWidgetTabBar: { const YaTabWidget* tw = dynamic_cast<const YaTabWidget*>(widget); if (tw) { QSize sh = tw->tabSizeHint(); QRect r = tw->tabRect(); result.setLeft(r.left()); result.setWidth(qMin(r.right(), sh.width())); result.setHeight(sh.height() - (widget->height() - r.height())); #ifdef CUSTOM_SHADOW result.moveTop(result.top() - Ya::VisualUtil::windowShadowSize()); #endif } return result; } case SE_TabWidgetTabContents: #ifdef CUSTOM_SHADOW return result.adjusted(Ya::VisualUtil::windowShadowSize() - 4, Ya::VisualUtil::windowShadowSize() + 2, -Ya::VisualUtil::windowShadowSize() + 4, -Ya::VisualUtil::windowShadowSize()); #else return result.adjusted(-4, 2, 4, 0); #endif default: return result; } }
void QConsolePrivate::setScrollValue (int value) { if (value == m_consoleRect.top ()) return; SMALL_RECT r; HANDLE hStdOut = m_stdOut; if (value + m_consoleRect.height () > m_bufferSize.height ()) value = m_bufferSize.height () - m_consoleRect.height (); r.Left = m_consoleRect.left (); r.Top = value; r.Right = m_consoleRect.right (); r.Bottom = value + m_consoleRect.height () - 1; log ("Scrolling window: (%d, %d) -> (%d, %d) [%d x %d]\n", r.Left, r.Top, r.Right, r.Bottom, r.Right - r.Left + 1, r.Bottom - r.Top + 1); if (SetConsoleWindowInfo (hStdOut, TRUE, &r)) { m_consoleRect.moveTop (value); updateConsoleView (); } }
QRect KWaitStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget) const { QRect rect; switch (control) { default: { rect = QPlastiqueStyle::subControlRect(control, option, subControl, widget); break; } #if QT_VERSION >= 0x040100 case CC_GroupBox: { if (const QStyleOptionGroupBox *group = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) { switch (subControl) { default: rect = QPlastiqueStyle::subControlRect(control, option, subControl, widget); break; #if QT_VERSION >= 0x040100 case SC_GroupBoxContents: rect = QPlastiqueStyle::subControlRect(control, option, subControl, widget); if (group->text.length() < 4) { rect.adjust(0, 4, 0, 0); } else { rect.adjust(0, -10, 0, 0); } break; #endif case SC_GroupBoxFrame: rect = group->rect; break; case SC_GroupBoxLabel: QPixmap titleLeft = cached(":dwaitstyle/images/title_cap_left.png", option->palette.color(QPalette::Background)); QPixmap titleRight = cached(":dwaitstyle/images/title_cap_right.png", option->palette.color(QPalette::Background)); QPixmap titleStretch = cached(":dwaitstyle/images/title_stretch.png", option->palette.color(QPalette::Background)); int txt_width = group->fontMetrics.width(group->text) + 20; rect = QRect(group->rect.center().x() - txt_width/2 + titleLeft.width(), 0, txt_width - titleLeft.width() - titleRight.width(), titleStretch.height()); break; } } break; } #endif } if (control == CC_Slider && subControl == SC_SliderHandle) { rect.setWidth(13); rect.setHeight(27); } else if (control == CC_Slider && subControl == SC_SliderGroove) { rect.setHeight(9); rect.moveTop(27/2 - 9/2); } return rect; }
void QVistaHelper::mouseMoveEvent(QMouseEvent *event) { if (wizard->windowState() & Qt::WindowMaximized) { event->ignore(); return; } QRect rect = wizard->geometry(); if (pressed) { switch (change) { case resizeTop: { const int dy = event->pos().y() - pressedPos.y(); if ((dy > 0 && rect.height() > wizard->minimumHeight()) || (dy < 0 && rect.height() < wizard->maximumHeight())) rect.setTop(rect.top() + dy); } break; case movePosition: { QPoint newPos = event->pos() - pressedPos; rect.moveLeft(rect.left() + newPos.x()); rect.moveTop(rect.top() + newPos.y()); break; } default: break; } wizard->setGeometry(rect); } else if (vistaState() == VistaAero) { setMouseCursor(event->pos()); } event->ignore(); }
void QConsolePrivate::updateConsoleSize (bool sync) { QFontMetrics fm (m_consoleView->font()); QSize winSize = m_consoleView->size (); m_charSize.rwidth () = fm.averageCharWidth(); m_charSize.rheight () = fm.lineSpacing (); m_consoleRect.setWidth (int(double(winSize.width ()) / double(fm.averageCharWidth()))); m_consoleRect.setHeight (int(double(winSize.height ()) / double(fm.lineSpacing ()))); m_bufferSize.rwidth () = m_consoleRect.width (); m_bufferSize.rheight () = qMax (m_bufferSize.height (), m_consoleRect.height ()); m_consoleRect.moveLeft (0); if (m_consoleRect.bottom () >= m_bufferSize.height ()) m_consoleRect.moveTop (m_bufferSize.height () - m_consoleRect.height ()); log ("Console resized:\n"); log (" widget size: %d x %d\n", winSize.width (), winSize.height ()); log (" buffer size: %d x %d\n", m_bufferSize.width (), m_bufferSize.height ()); log (" window: (%d, %d) -> (%d, %d) [%d x %d]\n", m_consoleRect.left (), m_consoleRect.top (), m_consoleRect.right (), m_consoleRect.bottom (), m_consoleRect.width (), m_consoleRect.height ()); if (sync) syncConsoleParameters (); updateScrollBar (); }
void SoundViewerWidget::paintEvent(QPaintEvent *event) { (void)event; QPainter painter(this); painter.fillRect(rect(), Qt::transparent); QRect temp = rect(); temp.moveTop(METER_HEIGHT); painter.drawTiledPixmap(temp, pixmap); // draw note if (this->note >= 0 && this->note < 12 * NUM_OCTAVES) { int octave = this->note / 12; int nn = this->note % 12; int adjust = 7 * KEY_WIDTH * octave; QRect noteRect = keyRect[nn].adjusted(adjust, METER_HEIGHT, adjust, METER_HEIGHT); painter.fillRect(noteRect, colors[this->channel]); } // draw volume int meterLength = rect().width() / 2; int left = (this->volume * this->panL) * meterLength; int right = (this->volume * this->panR) * meterLength; painter.fillRect(QRect(meterLength, 0, -left, METER_HEIGHT - METER_MARGIN), colors[this->channel]); painter.fillRect(QRect(meterLength, 0, right, METER_HEIGHT - METER_MARGIN), colors[this->channel]); }
// 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 drawBottomHtmlLine(QPainter *painter, const QFont font, QRect rect, QString text){ QRect r = rect; QFontInfo fi(font); int height = fi.pixelSize(); r.moveTop(r.bottom() - height); drawHtmlLine(painter, font, r, text) ; }
void NavDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyledItemDelegate::paint(painter, option, index); QRect iconRect = option.rect; iconRect.moveLeft(iconRect.right() - 56); iconRect.moveTop(iconRect.top() + (iconRect.height() - 48) / 2); iconRect.setSize(QSize(48, 48)); painter->drawImage(iconRect, QImage("/usr/share/icons/hicolor/48x48/hildon/general_forward.png")); }
/*! Takes a screen shot of \link target\endlink, and returns true if the screen shot is successfully saved to \link fileName\endlink. */ bool QchScreenShot::grab() { Q_D(QchScreenShot); d->pixmap = QPixmap(); QObject *obj = target(); if (obj) { if (obj->isWidgetType()) { QWidget *widget = qobject_cast<QWidget*>(obj); if (widget) { d->pixmap = QPixmap::grabWidget(widget, targetX(), targetY(), targetWidth(), targetHeight()); } } else if (QGraphicsObject *go = qobject_cast<QGraphicsObject*>(obj)) { QRect rect = go->boundingRect().toRect(); rect.moveLeft(qMax(0, targetX())); rect.moveTop(qMax(0, targetY())); rect.setWidth(qBound(1, targetWidth(), rect.width())); rect.setHeight(qBound(1, targetHeight(), rect.height())); QStyleOptionGraphicsItem styleOption; styleOption.rect = rect; d->pixmap = QPixmap(rect.size()); d->pixmap.fill(Qt::transparent); QPainter painter(&d->pixmap); go->paint(&painter, &styleOption); } else { qmlInfo(this) << tr("Target must be a visual item."); return false; } } else { d->pixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), targetX(), targetY(), targetWidth(), targetHeight()); } if (!d->pixmap.isNull()) { QString name = d->getFileName(); if (!name.isEmpty()) { setFileName(name); if ((width() > 0) && (height() > 0)) { d->pixmap = d->pixmap.scaled(width(), height(), Qt::IgnoreAspectRatio, smooth() ? Qt::SmoothTransformation : Qt::FastTransformation); } return d->pixmap.save(name); } } return false; }
const QRect GameUI::getPlayerColorRect() const { int wigwid = this->size().width(); int imgwid = m_playertextblack.width(); QRect rect = m_playertextblack.rect(); rect.moveLeft((wigwid-imgwid)/2); rect.moveTop(90); qDebug() << rect; return rect; }
void Dialog::realign() { QRect desktop; if (mMonitor) // Show on the specified monitor. desktop = LxQt::xfitMan().availableGeometry(mMonitor - 1); else // Follow the mouse. desktop = LxQt::xfitMan().availableGeometry(QCursor::pos()); QRect rect = this->geometry(); rect.moveCenter(desktop.center()); if (mShowOnTop) rect.moveTop(desktop.top()); else rect.moveTop(desktop.center().y() - ui->panel->sizeHint().height()); setGeometry(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(); } }
//Primary/private function void NativeWindowSystem::arrangeWindows(NativeWindowObject *primary, QString type, bool primaryonly){ if(type.isEmpty()){ type = "center"; } if(primary==0){ //Get the currently active window and treat that as the primary for(int i=0; i<NWindows.length(); i++){ if(NWindows[i]->property(NativeWindowObject::Active).toBool()){ primary = NWindows[i]; } } if(primary==0 && !NWindows.isEmpty()){ primary = NWindows[0]; } //just use the first one in the list } //Now get the current screen that the mouse cursor is over (and valid area) QScreen *screen = screenUnderMouse(); if(screen==0){ return; } //should never happen (theoretically) QRect desktopArea = screen->availableGeometry(); //qDebug() << "Arrange Windows:" << primary->geometry() << type << primaryonly << desktopArea; //Now start filtering out all the windows that need to be ignored int wkspace = primary->property(NativeWindowObject::Workspace).toInt(); QList<NativeWindowObject*> winlist = NWindows; for(int i=0; i<winlist.length(); i++){ if(winlist[i]->property(NativeWindowObject::Workspace).toInt()!=wkspace || !winlist[i]->property(NativeWindowObject::Visible).toBool() || desktopArea.intersected(winlist[i]->geometry()).isNull() ){ //window is outside of the desired area or invisible - ignore it winlist.removeAt(i); i--; } } if(!winlist.contains(primary)){ winlist << primary; } //could be doing this on a window right before it is shown else if(primaryonly){ winlist.removeAll(primary); winlist << primary; } //move primary window to last //QRegion used; for(int i=0; i<winlist.length(); i++){ if(primaryonly && winlist[i]!=primary){ continue; } //skip this window //Now loop over the windows and arrange them as needed QRect geom = winlist[i]->geometry(); //verify that the window is contained by the desktop area if(geom.width()>desktopArea.width()){ geom.setWidth(desktopArea.width()); } if(geom.height()>desktopArea.height()){ geom.setHeight(desktopArea.height()); } //Now apply the proper placement routine if(type=="center"){ QPoint ct = desktopArea.center(); winlist[i]->setGeometryNow( QRect( ct.x()-(geom.width()/2), ct.y()-(geom.height()/2), geom.width(), geom.height()) ); }else if(type=="snap"){ }else if(type=="single_max"){ winlist[i]->setGeometryNow( QRect( desktopArea.x(), desktopArea.y(), desktopArea.width(), desktopArea.height()) ); }else if(type=="under-mouse"){ QPoint ct = QCursor::pos(); geom = QRect(ct.x()-(geom.width()/2), ct.y()-(geom.height()/2), geom.width(), geom.height() ); //Now verify that the top of the window is still contained within the desktop area if(geom.y() < desktopArea.y() ){ geom.moveTop(desktopArea.y()); } winlist[i]->setGeometryNow(geom); } //qDebug() << " - New Geometry:" << winlist[i]->geometry(); } //end loop over winlist }
void TabTreeView::updateIndex(const QModelIndex &index) { QRect rect = visualRect(index); if (!rect.isValid()) { return; } // Need to update a little above/under to account for negative margins rect.moveTop(rect.y() - rect.height() / 2); rect.setHeight(rect.height() * 2); viewport()->update(rect); }
/* Returns rectangle of monitor pt is on, both rect and pt are in Window's window coordinates */ PRectangle Window::GetMonitorRect(Point pt) { QPoint originGlobal = window(wid)->mapToGlobal(QPoint(0, 0)); QPoint posGlobal = window(wid)->mapToGlobal(QPoint(pt.x, pt.y)); QDesktopWidget *desktop = QApplication::desktop(); QRect rectScreen = desktop->availableGeometry(posGlobal); rectScreen.moveLeft(-originGlobal.x()); rectScreen.moveTop(-originGlobal.y()); return PRectangle(rectScreen.left(), rectScreen.top(), rectScreen.right(), rectScreen.bottom()); }
void Dialog::realign() { QRect desktop; int screen = mMonitor; if (mMonitor < 0 || mMonitor > QApplication::desktop()->screenCount() - 1) screen = QApplication::desktop()->screenNumber(QCursor::pos()); desktop = QApplication::desktop()->availableGeometry(screen).intersected(KWindowSystem::workArea(screen)); QRect rect = this->geometry(); rect.moveCenter(desktop.center()); if (mShowOnTop) rect.moveTop(desktop.top()); else rect.moveTop(desktop.center().y() - ui->panel->sizeHint().height()); setGeometry(rect); }
void DeclarativeWidgetExtension::setY(int value) { QWidget *widget = extendedWidget(); if (value == widget->y()) return; QRect geometry = widget->geometry(); geometry.moveTop(value); widget->setGeometry(geometry); }
void RosterBoxItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align) { if(!v_rt){ QListViewItem::paintCell(p, cg, column, width, align); return; } p->save(); QListView* lv = listView(); if ( isSelected() != v_selected || lv->isActiveWindow() != v_active) setup(); int r = lv->itemMargin(); const QBrush *paper; // setup (colors, sizes, ...) if ( isSelected() ) { paper = &cg.brush( QColorGroup::Highlight ); } else{ const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode( lv->viewport()->backgroundMode() ); paper = &cg.brush( crole ); } const QPixmap * px = pixmap( column ); QRect pxrect; int pxw = 0; int pxh = 0; if(px) { pxw = px->width(); pxh = px->height(); pxrect = QRect(r, (height() - pxh)/2, pxw, pxh); r += pxw + lv->itemMargin(); } if(px) pxrect.moveTop( (height() - pxh)/2 ); // start drawing QRect rtrect(r, (height() - v_rt->height())/2, v_widthUsed, v_rt->height()); v_rt->draw(p, rtrect.left(), rtrect.top(), rtrect, cg, paper); QRegion clip(0, 0, width, height()); clip -= rtrect; p->setClipRegion(clip, QPainter::CoordPainter); p->fillRect( 0, 0, width, height(), *paper ); if(px) p->drawPixmap(pxrect, *px); p->restore(); }
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; }