void slideWindow (const QRect &rcEnd, bool bAnimate) { BOOL fFullDragOn; // Only slide the window if the user has FullDrag turned on SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &fFullDragOn, 0); // Get the current window position RECT rcWnd; GetWindowRect(pMain->winId(), &rcWnd); QRect rcStart; rcStart.setCoords(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom); if (bAnimate && fFullDragOn && (rcStart != rcEnd)) { static_cast<MainWindow*>(pMain)->m_bNoResize = true; // Get our starting and ending time. DWORD dwTimeStart = GetTickCount(); DWORD dwTimeEnd = dwTimeStart + SLIDE_INTERVAL; DWORD dwTime; while ((dwTime = ::GetTickCount()) < dwTimeEnd) { int delta = (int)(dwTime - dwTimeStart); QRect rc = rcStart; rc.setLeft(rcStart.left() + (rcEnd.left() - rcEnd.left()) * delta / SLIDE_INTERVAL); rc.setTop(rcStart.top() + (rcEnd.top() - rcEnd.top()) * delta / SLIDE_INTERVAL); rc.setWidth(rcStart.width() + (rcEnd.width() - rcEnd.width()) * delta / SLIDE_INTERVAL); rc.setHeight(rcStart.height() + (rcEnd.height() - rcEnd.height()) * delta / SLIDE_INTERVAL); SetWindowPos(pMain->winId(), NULL, rc.left(), rc.top(), rc.width(), rc.height(), SWP_NOZORDER | SWP_NOACTIVATE | SWP_DRAWFRAME); UpdateWindow(pMain->winId()); } static_cast<MainWindow*>(pMain)->m_bNoResize = false; } Event e(EventInTaskManager, (void*)(dock->getState() == ABE_FLOAT)); e.process(); SetWindowPos(pMain->winId(), NULL, rcEnd.left(), rcEnd.top(), rcEnd.width(), rcEnd.height(), SWP_NOZORDER | SWP_NOACTIVATE | SWP_DRAWFRAME); UpdateWindow(pMain->winId()); }
bool TextLabel::calculateScrollCoords(const QRect &meterRect, QRect &textRect, QPoint &next, int x, int y) { if (scrollType == ScrollBackAndForth && (scrollSpeed.x() != 0 && textSize.width() < getWidth() || scrollSpeed.y() != 0 && textSize.height() < getHeight())) return true; x += scrollPos.x(); y += scrollPos.y(); if (pauseCounter < 1) { scrollPos += scrollSpeed; // -1 | 0 | 1 QPoint direction(scrollSpeed.x() / abs((scrollSpeed.x() == 0) ? 1 : scrollSpeed.x()), scrollSpeed.y() / abs((scrollSpeed.y() == 0) ? 1 : scrollSpeed.y())); next = QPoint(-1 * direction.x() * (scrollGap + textSize.width()), -1 * direction.y() * (scrollGap + textSize.height())); textRect.setCoords(x, y, x + textSize.width(), y + textSize.height()); if (scrollType == ScrollBackAndForth) { if (direction.x() < 0 && textRect.right() <= meterRect.right() || direction.x() > 0 && textRect.left() >= meterRect.left()) { scrollSpeed.setX(scrollSpeed.x() * -1); pauseCounter = scrollPause; } if (direction.y() < 0 && textRect.bottom() <= meterRect.bottom() || direction.y() > 0 && textRect.top() >= meterRect.top()) { scrollSpeed.setY(scrollSpeed.y() * -1); pauseCounter = scrollPause; } } else if (!textRect.intersects(meterRect)) { if (scrollType == ScrollNormal) scrollPos += next; else if (scrollType == ScrollOnePass) return false; } } else --pauseCounter; return true; }
void Storage::triggerBoundBox( const QPoint &aNewPos, const QPoint &anOldPos, Rect &aNewRect ) { QRect tmp; tmp.setCoords( anOldPos.x(), anOldPos.y(), aNewPos.x(), aNewPos.y() ); aNewRect.setCoordinates(tmp); state_ = NewSelection; repaint_needed_ = 1; }
void Storage::triggerEllipse( const QPoint &aNewPos, const QPoint &anOldPos, Ellipse &aNewEll ) { QRect tmp; tmp.setCoords( anOldPos.x(), anOldPos.y(), aNewPos.x(), aNewPos.y() ); aNewEll.setCoordinates(tmp); state_ = NewSelection; repaint_needed_ = 1; }
void DlgParameterImp::showEvent(QShowEvent* ) { ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences"); hGrp = hGrp->GetGroup("ParameterEditor"); std::string buf = hGrp->GetASCII("Geometry", ""); if (!buf.empty()) { int x1, y1, x2, y2; char sep; std::stringstream str(buf); str >> sep >> x1 >> sep >> y1 >> sep >> x2 >> sep >> y2; QRect rect; rect.setCoords(x1, y1, x2, y2); this->setGeometry(rect); }
QRect Selection::extendToMergedAreas(const QRect& _area) const { if (!d->activeSheet) return _area; QRect area = normalized(_area); Cell cell(d->activeSheet, area.left(), area.top()); if (Region::Range(area).isColumn() || Region::Range(area).isRow()) { return area; } else if (!(cell.isPartOfMerged()) && (cell.mergedXCells() + 1) >= area.width() && (cell.mergedYCells() + 1) >= area.height()) { /* if just a single cell is selected, we need to merge even when the obscuring isn't forced. But only if this is the cell that is doing the obscuring -- we still want to be able to click on a cell that is being obscured. */ area.setWidth(cell.mergedXCells() + 1); area.setHeight(cell.mergedYCells() + 1); } else { int top = area.top(); int left = area.left(); int bottom = area.bottom(); int right = area.right(); for (int x = area.left(); x <= area.right(); x++) for (int y = area.top(); y <= area.bottom(); y++) { cell = Cell(d->activeSheet, x, y); if (cell.doesMergeCells()) { right = qMax(right, cell.mergedXCells() + x); bottom = qMax(bottom, cell.mergedYCells() + y); } else if (cell.isPartOfMerged()) { cell = cell.masterCell(); left = qMin(left, cell.column()); top = qMin(top, cell.row()); bottom = qMax(bottom, cell.row() + cell.mergedYCells()); right = qMax(right, cell.column() + cell.mergedXCells()); } } area.setCoords(left, top, right, bottom); } return area; }
void RectAnimation::updateCurrentTime(int currentTime) { qreal progress = m_easing.valueForProgress( currentTime / qreal(m_dura) ); QRect now; now.setCoords(interpolateInteger(m_start.left(), m_end.left(), progress), interpolateInteger(m_start.top(), m_end.top(), progress), interpolateInteger(m_start.right(), m_end.right(), progress), interpolateInteger(m_start.bottom(), m_end.bottom(), progress)); bool changed = (now != m_current); if (changed) m_current = now; if (state() == Stopped) return; if (m_object) m_object->setRect(m_current); }
int Ckeyb::KeyClick(QPoint pts) { // calculate all distance betwwen pts and keys centers // Keep the nearest int nearestIndex = -1; int smallerDistance = 99999; for (int i=0;i<Keys.size();i++) { QRect r = Keys.at(i).Rect; r.setCoords(r.x()*mainwindow->zoom/100,r.y()*mainwindow->zoom/100,(r.x()+r.width())*mainwindow->zoom/100,(r.y()+r.height())*mainwindow->zoom/100); int tmpDistance = 0; if ( r.contains(pts) ) { tmpDistance = 0; } else { tmpDistance = (r.center()-pts).manhattanLength(); } if (tmpDistance == smallerDistance) { // compare key size and keep the smallest QRect r1 = Keys.at(nearestIndex).Rect; if (r.width()*r.height() < r1.width()*r1.height()) { nearestIndex = i; } } else if (tmpDistance < smallerDistance) { smallerDistance = tmpDistance; nearestIndex= i; } } if ((smallerDistance < (30*mainwindow->zoom/100)) && (nearestIndex>=0)) { if (!pPC->closed) { return Keys.at(nearestIndex).ScanCode; } else { if (Keys.at(nearestIndex).ScanCode == K_CLOSE) return Keys.at(nearestIndex).ScanCode; } } return(0); }
QRect IconDelegate::_GetSybolRectForGray(const QStyleOptionViewItem &option) const { QRect rectForSybol; QPoint pointRectTopLeft = option.rect.topLeft(); int nPointRectHeightHalf = option.rect.height() / 2; int nWith = DEF_VALUE_INT_SYBOL_Circle_Radius; QPoint pointRectMid; pointRectMid.setX(pointRectTopLeft.x() + option.rect.width() / 8); pointRectMid.setY(pointRectTopLeft.y() + nPointRectHeightHalf); rectForSybol.setCoords(pointRectMid.x() - nWith, pointRectMid.y() - nWith, pointRectMid.x() + nWith, pointRectMid.y() + nWith); return rectForSybol; }
bool DrawEngine::xDrawTUHelper( QPainter* pcPainter, ComTU* pcTU ) { int iSubTUNum = pcTU->getTUs().size(); if( iSubTUNum != 0 ) { for(int i = 0; i < iSubTUNum; i++ ) { xDrawTUHelper(pcPainter, pcTU->getTUs().at(i)); } } else { QRect cScaledTUArea; cScaledTUArea.setCoords( pcTU->getX(), pcTU->getY(), (pcTU->getX()+pcTU->getSize())-1, (pcTU->getY()+pcTU->getSize())-1 ); xScaleRect(&cScaledTUArea,&cScaledTUArea); m_cFilterLoader.drawTU(pcPainter, pcTU, m_dScale, &cScaledTUArea); } return true; }
void StyleHelper::drawListViewItemThumb(QPainter* p, const QRect& rc, int nBadgeType, const QString& title, const QString& lead, const QString& abs, bool bFocused, bool bSelected) { QRect rcd(rc); QFont fontTitle; int nFontHeight = Utils::StyleHelper::fontHead(fontTitle); if (!title.isEmpty()) { QRect rcTitle = Utils::StyleHelper::drawBadgeIcon(p, rcd, nFontHeight, nBadgeType, bFocused, bSelected); rcTitle.setCoords(rcTitle.right(), rcTitle.y(), rcd.right(), rcd.bottom()); QString strTitle(title); QColor colorTitle = Utils::StyleHelper::listViewItemTitle(bSelected, bFocused); rcTitle = Utils::StyleHelper::drawText(p, rcTitle, strTitle, 1, Qt::AlignVCenter, colorTitle, fontTitle); rcd.adjust(0, rcTitle.height() + margin(), 0, 0); } QFont fontThumb; nFontHeight = Utils::StyleHelper::fontNormal(fontThumb); QRect rcLead; if (!lead.isEmpty()) { QString strInfo(lead); QColor colorDate = Utils::StyleHelper::listViewItemLead(bSelected, bFocused); rcLead = Utils::StyleHelper::drawText(p, rcd, strInfo, 1, Qt::AlignVCenter, colorDate, fontThumb); } if (!abs.isEmpty()) { QString strText(abs); QRect rcLine1(rcd.adjusted(rcLead.width(), 0, 0, 0)); QColor colorSummary = Utils::StyleHelper::listViewItemSummary(bSelected, bFocused); rcLine1 = Utils::StyleHelper::drawText(p, rcLine1, strText, 1, Qt::AlignVCenter, colorSummary, fontThumb, false); if (!strText.isEmpty()) { QRect rcLine2(rcd.adjusted(0, rcLine1.height(), 0, 0)); rcLine2 = Utils::StyleHelper::drawText(p, rcLine2, strText, 2, Qt::AlignVCenter, colorSummary, fontThumb); } } }
void ossimQtRoiRectAnnotator::paintAnnotation( QPainter* p, int clipx, int clipy, int clipw, int cliph ) { if ( !p || (thePoints.size() != 2) ) { return; } ossimIrect clipRect(clipx, clipy, clipx + (clipw - 1), clipy + (cliph - 1)); if (clipRect.intersects(getRoiRect())) { QRect r; r.setCoords(thePoints[0].x, thePoints[0].y, thePoints[1].x, thePoints[1].y); p->setPen(thePenColor); p->drawRect(r); } }
void CustRegister::registerHeader(QPainter *p) { QRect rect; QString tmpSt; QBrush bbrush; p->setFont(QFont("helvetica", 10, QFont::Normal)); // p->drawRect(40, 150, 525, 15); bbrush.setStyle(SolidPattern); bbrush.setColor(black); p->setBackgroundMode(OpaqueMode); p->setPen(white); rect.setCoords(20, 150, 80, 165); p->fillRect(rect, bbrush); p->drawText(rect, AlignCenter, "Trans Date"); rect.setCoords(80, 150, 140, 165); p->fillRect(rect, bbrush); p->drawText(rect, AlignCenter, "Due Date"); p->drawLine(80, 150, 80, 165); rect.setCoords(140, 150, 200, 165); p->fillRect(rect, bbrush); p->drawText(rect, AlignCenter, "Login ID"); p->drawLine(140, 150, 140, 165); rect.setCoords(200, 150, 420, 165); p->fillRect(rect, bbrush); p->drawText(rect, AlignCenter, "Description"); p->drawLine(200, 150, 200, 165); rect.setCoords(420, 150, 480, 165); p->fillRect(rect, bbrush); p->drawText(rect, AlignCenter, "Amount"); p->drawLine(420, 150, 420, 165); rect.setCoords(480, 150, 540, 165); p->fillRect(rect, bbrush); p->drawText(rect, AlignCenter, "Balance"); p->drawLine(480, 150, 480, 165); // Reset our pen back to a transparent background and black letters. p->setBackgroundMode(TransparentMode); p->setPen(black); }
void k9MP4Title::bCropClicked() { KDialog dialog(this); dialog.setWindowTitle(KDialog::makeStandardCaption(i18n("Crop detection"))); k9CropSelect cropSelect(&dialog); QRect r; r.setCoords(Ui_prefMPEG4.sbLeft->value(),Ui_prefMPEG4.sbTop->value(),Ui_prefMPEG4.sbRight->value(),Ui_prefMPEG4.sbBottom->value()); cropSelect.setRect(r); cropSelect.setMinimumWidth(600); cropSelect.setMinimumHeight(400); dialog.setMainWidget(&cropSelect); cropSelect.open(m_dvd,m_titleEncOpt->getTitle(),1); if (dialog.exec()== QDialog::Accepted) { QRect r= cropSelect.getRect(); Ui_prefMPEG4.sbTop->setValue(r.top()); Ui_prefMPEG4.sbLeft->setValue(r.left()); Ui_prefMPEG4.sbRight->setValue(r.right()); Ui_prefMPEG4.sbBottom->setValue(r.bottom()); if (m_titleEncOpt) { m_titleEncOpt->getCrop()->setCoords(r.left(),r.top(),r.right(),r.bottom()); } } }
static void getBarRect(UINT state, QRect &rc, RECT *rcWnd = NULL) { RECT rcWork; SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0); rc.setCoords(0, rcWork.top, GetSystemMetrics(SM_CXSCREEN), rcWork.bottom); appBarMessage(ABM_QUERYPOS, state, FALSE, &rc); int w; if (rcWnd){ w = rcWnd->right - rcWnd->left; }else{ GetWindowRect(pMain->winId(), &rcWork); w = rcWork.right - rcWork.left; } switch (state){ case ABE_LEFT: rc.setRight(rc.left() + w); break; case ABE_RIGHT: rc.setLeft(rc.right() - w); break; } }
bool DrawEngine::xDrawCU( QPainter* pcPainter, ComCU* pcCU ) { if( pcCU->getSCUs().empty() ) { /// draw CU QRect cScaledCUArea; cScaledCUArea.setCoords( pcCU->getX(), pcCU->getY(), (pcCU->getX()+pcCU->getSize())-1, (pcCU->getY()+pcCU->getSize())-1 ); xScaleRect(&cScaledCUArea,&cScaledCUArea); m_cFilterLoader.drawCU(pcPainter, pcCU, m_dScale, &cScaledCUArea); } else { for(int iSub = 0; iSub < 4; iSub++) { xDrawCU ( pcPainter, pcCU->getSCUs().at(iSub) ); } } return true; }
void KCRowHeader::mouseReleaseEvent(QMouseEvent * _ev) { if (!m_cellToolIsActive) return; m_pView->disableAutoScroll(); if (m_lSize) m_lSize->hide(); m_bMousePressed = false; if (!m_pView->koDocument()->isReadWrite()) return; register KCSheet * const sheet = m_pView->activeSheet(); if (!sheet) return; double ev_PosY = m_pView->zoomHandler()->unzoomItY(_ev->pos().y()) + m_pCanvas->yOffset(); if (m_bResize) { // Remove size indicator painted by paintSizeIndicator if (m_rubberband) { delete m_rubberband; m_rubberband = 0; } int start = m_iResizedRow; int end = m_iResizedRow; QRect rect; rect.setCoords(1, m_iResizedRow, KS_colMax, m_iResizedRow); if (m_pView->selection()->isRowSelected()) { if (m_pView->selection()->contains(QPoint(1, m_iResizedRow))) { start = m_pView->selection()->lastRange().top(); end = m_pView->selection()->lastRange().bottom(); rect = m_pView->selection()->lastRange(); } } double height = 0.0; double y = sheet->rowPosition(m_iResizedRow); if (ev_PosY - y <= 0.0) height = 0.0; else height = ev_PosY - y; if (height != 0.0) { ResizeRowManipulator* command = new ResizeRowManipulator(); command->setSheet(sheet); command->setSize(height); command->add(KCRegion(rect, sheet)); if (!command->execute()) delete command; } else { // hide HideShowManipulator* command = new HideShowManipulator(); command->setSheet(sheet); command->setManipulateRows(true); command->add(KCRegion(rect, sheet)); if (!command->execute()) delete command; } delete m_lSize; m_lSize = 0; } else if (m_bSelection) { QRect rect = m_pView->selection()->lastRange(); // TODO: please don't remove. Right now it's useless, but it's for a future feature // Norbert bool m_frozen = false; if (m_frozen) { kDebug(36001) << "selected: T" << rect.top() << " B" << rect.bottom(); int i; QList<int> hiddenRows; for (i = rect.top(); i <= rect.bottom(); ++i) { if (sheet->rowFormat(i)->isHidden()) { hiddenRows.append(i); } } if (hiddenRows.count() > 0) { if (m_pView->selection()->isColumnSelected()) { KMessageBox::error(this, i18n("Area is too large.")); return; } HideShowManipulator* command = new HideShowManipulator(); command->setSheet(sheet); command->setManipulateRows(true); command->setReverse(true); command->add(*m_pView->selection()); command->execute(); } } } m_bSelection = false; m_bResize = false; }
void MyScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { //changes position of cursorImage depends on cursor position m_cursor.setX(event->scenePos().x()); m_cursor.setY(event->scenePos().y()); //if shift rectangle is visible set rectangle else set cursor image if(m_shiftRect->isVisible()){ //rectangle size increase or decrease by cursor image size // if image is 40x40 the size of rectangle increase/decrease by size 40 //size increase by steps int intRemainder = ((int(m_cursor.x()) - int(m_shiftLeftCorner.x())) % int(m_cursorImage->rect().width())); if(m_cursor.x()>m_shiftLeftCorner.x()) m_cursor.setX((int(m_cursor.x()) - intRemainder)+m_cursorImage->rect().width()); else m_cursor.setX((int(m_cursor.x()) - intRemainder)-m_cursorImage->rect().width()); intRemainder =(int(int(m_cursor.y()) - int(m_shiftLeftCorner.y())) % int(m_cursorImage->rect().height())); if(m_cursor.y()>m_shiftLeftCorner.y()) m_cursor.setY((int(m_cursor.y()) - intRemainder)+m_cursorImage->rect().height()); else m_cursor.setY((int(m_cursor.y()) - intRemainder)-m_cursorImage->rect().height()); //control if curosr isnt out of screen if(m_cursor.x()>m_sceneWidth) m_cursor.setX(m_cursor.x()-m_cursorImage->rect().width()); else if(m_cursor.x()<0) m_cursor.setX(m_cursor.x()+m_cursorImage->rect().width()); if(m_cursor.y()>600) m_cursor.setY(m_cursor.y()-m_cursorImage->rect().height()); else if(m_cursor.y()<0) m_cursor.setY(m_cursor.y()+m_cursorImage->rect().height()); //set rectangle rights points QRect rectangle; if(m_shiftLeftCorner.x() < m_cursor.x()){ if(m_shiftLeftCorner.y() < m_cursor.y()) rectangle.setCoords(m_shiftLeftCorner.x(),m_shiftLeftCorner.y(),m_cursor.x(), m_cursor.y()); else rectangle.setCoords(m_shiftLeftCorner.x(),m_cursor.y(),m_cursor.x(), m_shiftLeftCorner.y()); } else{ if(m_shiftLeftCorner.y() < m_cursor.y()) rectangle.setCoords(m_cursor.x(),m_shiftLeftCorner.y(),m_shiftLeftCorner.x(), m_cursor.y()); else rectangle.setCoords(m_cursor.x(),m_cursor.y(),m_shiftLeftCorner.x(), m_shiftLeftCorner.y()); } m_shiftRect->setRect(rectangle); } else{ //if shift rectangle is invisible set cursor image //move by steps if((int(m_cursor.x()) % m_pixle) != 0) m_cursor.setX(int(m_cursor.x()) - (int(m_cursor.x()) % m_pixle)); if((int(m_cursor.y()) % m_pixle) != 0) m_cursor.setY(int(m_cursor.y()) - (int(m_cursor.y()) % m_pixle)); //picture cant get out of screen if(m_cursor.x()<0) m_cursor.setX(0); if(m_cursor.y()<0) m_cursor.setY(0); if((m_cursor.x())+m_cursorImage->rect().width()>m_sceneWidth) m_cursor.setX(m_sceneWidth-m_cursorImage->rect().width()); if((m_cursor.y())+m_cursorImage->rect().height()>600) m_cursor.setY(600-m_cursorImage->rect().height()); m_cursorImage->setPos(m_cursor); } }
void RadialMap::Map::paint(unsigned int scaleFactor) { if (scaleFactor == 0) //just in case scaleFactor = 1; QPainter paint; QRect rect = m_rect; int step = m_ringBreadth; int excess = -1; //scale the pixmap, or do intelligent distribution of excess to prevent nasty resizing if (scaleFactor > 1) { int x1, y1, x2, y2; rect.getCoords(&x1, &y1, &x2, &y2); x1 *= scaleFactor; y1 *= scaleFactor; x2 *= scaleFactor; y2 *= scaleFactor; rect.setCoords(x1, y1, x2, y2); step *= scaleFactor; QPixmap::operator=(QPixmap(this->size() * (int)scaleFactor)); } else if (m_ringBreadth != MAX_RING_BREADTH && m_ringBreadth != MIN_RING_BREADTH) { excess = rect.width() % m_ringBreadth; ++step; } //**** best option you can think of is to make the circles slightly less perfect, // ** i.e. slightly eliptic when resizing inbetween paint.begin(this); fill(); //erase background for (int x = m_visibleDepth; x >= 0; --x) { int width = rect.width() / 2; //clever geometric trick to find largest angle that will give biggest arrow head int a_max = int(acos((double)width / double((width + 5) * scaleFactor)) * (180 * 16 / M_PI)); for (ConstIterator<Segment> it = m_signature[x].constIterator(); it != m_signature[x].end(); ++it) { //draw the pie segments, most of this code is concerned with drawing the little //arrows on the ends of segments when they have hidden files paint.setPen((*it)->pen()); if ((*it)->hasHiddenChildren()) { //draw arrow head to indicate undisplayed files/directories QPolygon pts(3); QPoint pos, cpos = rect.center(); int a[3] = {static_cast<int>((*it)->start()), static_cast<int>((*it)->length()), 0 }; a[2] = a[0] + (a[1] / 2); //assign to halfway between if (a[1] > a_max) { a[1] = a_max; a[0] = a[2] - a_max / 2; } a[1] += a[0]; for (int i = 0, radius = width; i < 3; ++i) { double ra = M_PI / (180 * 16) * a[i], sinra, cosra; if (i == 2) radius += 5 * scaleFactor; #if 0 sincos(ra, &sinra, &cosra); #endif sinra = sin(ra); cosra = cos(ra); pos.rx() = cpos.x() + static_cast<int>(cosra * radius); pos.ry() = cpos.y() - static_cast<int>(sinra * radius); pts.setPoint(i, pos); } paint.setBrush((*it)->pen()); paint.drawPolygon(pts); } paint.setBrush((*it)->brush()); paint.drawPie(rect, (*it)->start(), (*it)->length()); if ((*it)->hasHiddenChildren()) { //**** code is bloated! paint.save(); QPen pen = paint.pen(); int width = 2 * scaleFactor; pen.setWidth(width); paint.setPen(pen); QRect rect2 = rect; width /= 2; rect2.adjust(width, width, -width, -width); paint.drawArc(rect2, (*it)->start(), (*it)->length()); paint.restore(); } } if (excess >= 0) { //excess allows us to resize more smoothly (still crud tho) if (excess < 2) //only decrease rect by more if even number of excesses left --step; excess -= 2; } rect.adjust(step, step, -step, -step); } // if( excess > 0 ) rect.adjust( excess, excess, 0, 0 ); //ugly paint.setPen(COLOR_GREY); paint.setBrush(Qt::white); paint.drawEllipse(rect); if (scaleFactor > 1) { //have to end in order to smoothscale() paint.end(); int x1, y1, x2, y2; rect.getCoords(&x1, &y1, &x2, &y2); x1 /= scaleFactor; y1 /= scaleFactor; x2 /= scaleFactor; y2 /= scaleFactor; rect.setCoords(x1, y1, x2, y2); QImage img = this->toImage(); img = img.scaled(this->size() / (int)scaleFactor, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); this->QPixmap::operator=(fromImage(img, Qt::AutoColor)); paint.begin(this); paint.setPen(COLOR_GREY); paint.setBrush(Qt::white); } paint.drawText(rect, Qt::AlignCenter, m_centerText); m_innerRadius = rect.width() / 2; //rect.width should be multiple of 2 paint.end(); }
void ImageInfo::rotate( int degrees, RotationMode mode ) { // ensure positive degrees: degrees += 360; degrees = degrees % 360; if ( degrees == 0 ) return; m_dirty = true; m_angle = ( m_angle + degrees ) % 360; if (degrees == 90 or degrees == 270) { m_size.transpose(); } // the AnnotationDialog manages this by itself and sets RotateImageInfoOnly: if ( mode == RotateImageInfoAndAreas ) { for ( auto& areasOfCategory : m_taggedAreas ) { for ( auto& area : areasOfCategory ) { QRect rotatedArea; // parameter order for QRect::setCoords: // setCoords( left, top, right, bottom ) // keep in mind that _size is already transposed switch (degrees) { case 90: rotatedArea.setCoords( m_size.width() - area.bottom(), area.left(), m_size.width() - area.top(), area.right() ); break; case 180: rotatedArea.setCoords( m_size.width() - area.right(), m_size.height() - area.bottom(), m_size.width() - area.left(), m_size.height() - area.top() ); break; case 270: rotatedArea.setCoords( area.top(), m_size.height() - area.right(), area.bottom(), m_size.height() - area.left() ); break; default: // degrees==0; "odd" values won't happen. rotatedArea = area; break; } // update _taggedAreas[category][tag]: area = rotatedArea; } } } saveChangesIfNotDelayed(); }
void PlastikClient::paintEvent(QPaintEvent *e) { QRegion region = e->region(); PlastikHandler *handler = Handler(); if(oldCaption != caption()) clearCaptionPixmaps(); bool active = isActive(); bool toolWindow = isToolWindow(); QPainter painter(widget()); // often needed coordinates QRect r = widget()->rect(); int r_w = r.width(); // int r_h = r.height(); int r_x, r_y, r_x2, r_y2; r.coords(&r_x, &r_y, &r_x2, &r_y2); const int borderLeft = layoutMetric(LM_BorderLeft); const int borderRight = layoutMetric(LM_BorderRight); const int borderBottom = layoutMetric(LM_BorderBottom); const int titleHeight = layoutMetric(LM_TitleHeight); const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop); const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom); const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft); const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight); const int borderBottomTop = r_y2 - borderBottom + 1; const int borderLeftRight = r_x + borderLeft - 1; const int borderRightLeft = r_x2 - borderRight + 1; const int titleEdgeBottomBottom = r_y + titleEdgeTop + titleHeight + titleEdgeBottom - 1; const int sideHeight = borderBottomTop - titleEdgeBottomBottom - 1; QRect Rtitle = QRect(r_x + titleEdgeLeft + buttonsLeftWidth(), r_y + titleEdgeTop, r_x2 - titleEdgeRight - buttonsRightWidth() - (r_x + titleEdgeLeft + buttonsLeftWidth()), titleEdgeBottomBottom - (r_y + titleEdgeTop)); QRect tempRect; // topSpacer if(titleEdgeTop > 0) { tempRect.setRect(r_x + 2, r_y, r_w - 2 * 2, titleEdgeTop); if(tempRect.isValid() && region.contains(tempRect)) { painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarTileTop, active, toolWindow)); } } // leftTitleSpacer int titleMarginLeft = 0; int titleMarginRight = 0; if(titleEdgeLeft > 0) { tempRect.setRect(r_x, r_y, borderLeft, titleEdgeTop + titleHeight + titleEdgeBottom); if(tempRect.isValid() && region.contains(tempRect)) { painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarLeft, active, toolWindow)); titleMarginLeft = borderLeft; } } // rightTitleSpacer if(titleEdgeRight > 0) { tempRect.setRect(borderRightLeft, r_y, borderRight, titleEdgeTop + titleHeight + titleEdgeBottom); if(tempRect.isValid() && region.contains(tempRect)) { painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarRight, active, toolWindow)); titleMarginRight = borderRight; } } // titleSpacer const QPixmap &caption = captionPixmap(); if(Rtitle.width() > 0) { m_captionRect = captionRect(); // also update m_captionRect! if(m_captionRect.isValid() && region.contains(m_captionRect)) { painter.drawTiledPixmap(m_captionRect, caption); } // left to the title tempRect.setRect(r_x + titleMarginLeft, m_captionRect.top(), m_captionRect.left() - (r_x + titleMarginLeft), m_captionRect.height()); if(tempRect.isValid() && region.contains(tempRect)) { painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarTile, active, toolWindow)); } // right to the title tempRect.setRect(m_captionRect.right() + 1, m_captionRect.top(), (r_x2 - titleMarginRight) - m_captionRect.right(), m_captionRect.height()); if(tempRect.isValid() && region.contains(tempRect)) { painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarTile, active, toolWindow)); } } // leftSpacer if(borderLeft > 0 && sideHeight > 0) { tempRect.setCoords(r_x, titleEdgeBottomBottom + 1, borderLeftRight, borderBottomTop - 1); if(tempRect.isValid() && region.contains(tempRect)) { painter.drawTiledPixmap(tempRect, handler->pixmap(BorderLeftTile, active, toolWindow)); } } // rightSpacer if(borderRight > 0 && sideHeight > 0) { tempRect.setCoords(borderRightLeft, titleEdgeBottomBottom + 1, r_x2, borderBottomTop - 1); if(tempRect.isValid() && region.contains(tempRect)) { painter.drawTiledPixmap(tempRect, handler->pixmap(BorderRightTile, active, toolWindow)); } } // bottomSpacer if(borderBottom > 0) { int l = r_x; int r = r_x2; tempRect.setRect(r_x, borderBottomTop, borderLeft, borderBottom); if(tempRect.isValid() && region.contains(tempRect)) { painter.drawTiledPixmap(tempRect, handler->pixmap(BorderBottomLeft, active, toolWindow)); l = tempRect.right() + 1; } tempRect.setRect(borderRightLeft, borderBottomTop, borderLeft, borderBottom); if(tempRect.isValid() && region.contains(tempRect)) { painter.drawTiledPixmap(tempRect, handler->pixmap(BorderBottomRight, active, toolWindow)); r = tempRect.left() - 1; } tempRect.setCoords(l, borderBottomTop, r, r_y2); if(tempRect.isValid() && region.contains(tempRect)) { painter.drawTiledPixmap(tempRect, handler->pixmap(BorderBottomTile, active, toolWindow)); } } }
void PrintTreeWidget::printHeader(QPainter *p) { QDate theDate; QTime theTime; QRect rect; QBrush bbrush; QString tmpSt; char tmpstr[1024]; int xPos = prLeftMargin; float headerPcts[20]; float colWidths[20]; float totWidth = 0; int numCols; theDate = QDate::currentDate(); theTime = QTime::currentTime(); // p->rotate(55); // Draw our Company Name header and the date at the top of the page p->setFont(QFont("helvetica", 10, QFont::Bold)); rect.setCoords(prLeftMargin, 30, 399, 60); p->drawText(rect, Qt::AlignLeft, cfgVal("CompanyName")); sprintf(tmpstr, "%s %s", (const char *) theDate.toString(), (const char *) theTime.toString()); rect.setCoords(400, 30, prLeftMargin+540, 60); p->drawText(rect, Qt::AlignRight, tmpstr); // Now, draw the report title, centered on the page. // If we have a date range for the report, shrink down the title by 12 // pixels so we can display the dates on the page. If not, give the // title the full height. if (showDateLine) { p->setFont(QFont("helvetica", 18, QFont::Bold)); rect.setCoords(0, 40, 611, 95); p->drawText(rect, Qt::AlignCenter|Qt::AlignVCenter, myTitle); p->setFont(QFont("helvetica", 8, QFont::Normal)); rect.setCoords(0, 96, 611, 112); p->drawText(rect, Qt::AlignCenter|Qt::AlignVCenter, myDateLine); } else { p->setFont(QFont("helvetica", 18, QFont::Bold)); rect.setCoords(0, 40, 611, 112); p->drawText(rect, Qt::AlignCenter|Qt::AlignVCenter, myTitle); } // Now, calculate the column widths. // We'll take the strlens and convert them into pixel values // based on the percentage of the total. That way, our report will // always be the full width of the page. numCols = myTree->columnCount(); if (!numCols) return; if (numCols > 20) numCols = 20; // Get the width of each header item. QTreeWidgetItem *hdr = myTree->headerItem(); for (int i = 0; i < numCols; i++) { colWidths[i] = hdr->text(i).length(); } // Now, get the longest item for each of the keys. QTreeWidgetItem *curItem; for (int j = 0; j < myTree->topLevelItemCount(); j++) { curItem = myTree->topLevelItem(j); for (int i = 0; i < numCols; i++) { if (curItem->text(i).length() > colWidths[i]) { colWidths[i] = curItem->text(i).length(); } } } // Now, add up the widths. for (int i = 0; i < numCols; i++) { totWidth += colWidths[i]; } // Now, get our percentages. for (int i = 0; i < numCols; i++) { headerPcts[i] = colWidths[i] / totWidth * 540; sprintf(tmpstr, "%f", rint(headerPcts[i])); prColWidths[i] = atoi(tmpstr); // 1" margin // fprintf(stderr, "Column %d width = %f (%f) = %d pixels.\n", i, colWidths[i], headerPcts[i], prColWidths[i]); } // Now, draw the titles. //xPos = 36; xPos = prLeftMargin; p->setFont(QFont("helvetica", 8, QFont::Normal)); for (int i = 0; i < numCols; i++) { rect.setCoords(xPos+1, 113, xPos + prColWidths[i] - 1, 129); bbrush.setStyle(Qt::SolidPattern); bbrush.setColor(Qt::black); //p->setBackgroundMode(OpaqueMode); p->setPen(Qt::white); p->fillRect(rect, bbrush); p->drawText(rect, Qt::AlignCenter|Qt::AlignVCenter, myTree->headerItem()->text(i)); xPos += prColWidths[i]; } // Reset our pen p->setBackgroundMode(Qt::TransparentMode); p->setPen(Qt::black); }
void CollReport::printReport(long CustID) { QDate theDate; QPrinter prn(QPrinter::PrinterResolution); QPainter p; QRect rect; ADBTable cust; ADBTable cont; ADB DB; QString tmpSt; QDate tmpDate1; char tmpStr[1024]; char tStr[1024]; int yPos; int pageNo = 1; float Balance = 0.00; float EndingBalance; CustomersDB CDB; AddressesDB addrDB; char transFont[1024]; strcpy(transFont, "b&h lucida"); CDB.get(CustID); addrDB.get(REF_CUSTOMER, CustID, "Billing"); theDate = QDate::currentDate(); sprintf(tStr, "/tmp/collreport-%09ld.ps", CustID); // prn.setPrintProgram("ghostview"); //prn.setPrinterName("PostScript"); //prn.setOutputFileName(tStr); prn.setOutputToFile(false); prn.setPageSize(QPrinter::Letter); prn.setFullPage(true); prn.setDocName("Collections Report"); prn.setCreator("Total Accountability"); p.begin(&prn); EndingBalance = DB.sumFloat("select SUM(Amount) from AcctsRecv where CustomerID = %ld", CustID); // Put the Blarg header and contact information on the page. printHeader(&p, &CDB, &addrDB, EndingBalance); // Put the register header on the page. registerHeader(&p); // Now, get the register information from the database. DB.query("select TransDate, DueDate, LoginID, Memo, Amount from AcctsRecv where CustomerID = %ld order by TransDate, LoginID", CustID); yPos = 165; p.setFont(QFont(transFont, 8, QFont::Normal)); QFontMetrics fm(p.fontMetrics()); while (DB.getrow()) { //int Lines = (int) (strlen(DB.curRow["Memo"]) / 52) + 1; //int RowHeight = 15 * Lines; int Lines = (int) (fm.width(DB.curRow["Memo"]) / (descriptionX2 - descriptionX1 - 2)) + 1; int RowHeight = (fm.height()+2) * Lines; // Check to see if we have enough room on the page left for this // line. if (yPos+RowHeight >= 740) { printFooter(&p, pageNo++); prn.newPage(); printHeader(&p, &CDB, &addrDB, EndingBalance); registerHeader(&p); yPos = 165; p.setFont(QFont(transFont, 8, QFont::Normal)); } // The transaction date. myDatetoQDate(DB.curRow["TransDate"], &tmpDate1); sprintf(tmpStr, "%02d/%02d/%02d", tmpDate1.month(), tmpDate1.day(), tmpDate1.year()%100); rect.setCoords(transDateX1, yPos, transDateX2, yPos + RowHeight-1); p.drawRect(rect); p.drawText(rect, Qt::AlignVCenter|Qt::AlignHCenter, tmpStr); // The Due Date myDatetoQDate(DB.curRow["DueDate"], &tmpDate1); sprintf(tmpStr, "%02d/%02d/%02d", tmpDate1.month(), tmpDate1.day(), tmpDate1.year()%100); rect.setCoords(dueDateX1, yPos, dueDateX2, yPos + RowHeight-1); p.drawRect(rect); p.drawText(rect, Qt::AlignVCenter|Qt::AlignHCenter, tmpStr); // The Login ID /* rect.setCoords(140, yPos, 199, yPos + RowHeight); p.drawRect(rect); p.drawText(rect, Qt::AlignVCenter|Qt::AlignHCenter, DB.curRow["LoginID"]); */ // The description... //fprintf(stderr, "descriptionX1 = %d, descriptionX2 = %d\n", descriptionX1, descriptionX2); //fprintf(stderr, "description = '%s'\n", DB.curRow["Memo"]); rect.setCoords(descriptionX1, yPos, descriptionX2, yPos + RowHeight-1); p.drawRect(rect); rect.setCoords(descriptionX1+1, yPos, descriptionX2, yPos + RowHeight); p.drawText(rect, Qt::WordBreak|Qt::AlignLeft|Qt::AlignVCenter, DB.curRow["Memo"]); // The amount. rect.setCoords(amountX1, yPos, amountX2, yPos + RowHeight-1); p.drawRect(rect); p.drawText(rect, Qt::AlignRight|Qt::AlignVCenter, DB.curRow["Amount"]); // The balance. Balance += atof(DB.curRow["Amount"]); sprintf(tStr, "%.2f", Balance); if (Balance == 0.0) strcpy(tStr, "0.00"); rect.setCoords(balanceX1, yPos, balanceX2, yPos + RowHeight-1); p.drawRect(rect); p.drawText(rect, Qt::AlignRight|Qt::AlignVCenter, tStr); yPos += RowHeight; } // Put the footer on the page. printFooter(&p, pageNo); // prn.newPage(); // p.drawText(300, 600, "Page 2"); p.end(); }
void CollReport::printHeader(QPainter *p, CustomersDB *cust, AddressesDB *cont, float Balance) { QDate theDate; QRect rect; QString tmpSt; int yPos; int pOfs = 36; long CustID = cust->getLong("CustomerID"); theDate = QDate::currentDate(); char addrFont[1024]; char infoFont[1024]; strcpy(addrFont, "b&h lucida"); strcpy(infoFont, "b&h lucida"); // p->rotate(55); yPos = pOfs; p->setFont(QFont(addrFont, 10, QFont::Bold)); p->drawText(10, yPos, "Blarg! Online Services, Inc."); p->setFont(QFont(addrFont, 10, QFont::Normal)); yPos += 10; p->drawText(10, yPos, "PO Box 1827"); yPos += 10; p->drawText(10, yPos, "Bellevue, WA 98009-1827"); yPos += 10; p->drawText(10, yPos, "Phone: 425.818.6500"); yPos += 10; p->drawText(10, yPos, "Fax: 425.401.9741"); rect.setCoords(450, pOfs, 600, pOfs+15); p->setFont(QFont(addrFont, 14, QFont::Bold)); p->drawText(rect, Qt::AlignCenter, "Collections Report"); rect.setCoords(450, pOfs+15, 600, pOfs+25); p->setFont(QFont(addrFont, 10, QFont::Normal)); p->drawText(rect, Qt::AlignCenter, theDate.toString()); p->drawLine( 0, 78, 692, 78); p->setFont(QFont(addrFont, 10, QFont::Normal)); p->drawText( 20, 90, "Customer:"); yPos = 90; if (strlen(cust->getStr("FullName"))) { p->drawText( 70, yPos, cust->getStr("FullName")); yPos += 10; } if (strlen(cust->getStr("ContactName"))) { p->drawText( 70, yPos, cust->getStr("ContactName")); yPos += 10; } if (strlen(cont->Address1)) { p->drawText( 70, yPos, cont->Address1); yPos += 10; } if (strlen(cont->Address2)) { p->drawText( 70, yPos, cont->Address2); yPos += 10; } tmpSt = cont->City; tmpSt.append(", "); tmpSt.append(cont->State); tmpSt.append(" "); tmpSt.append(cont->ZIP); p->drawText( 70,yPos, tmpSt); yPos += 10; p->setFont(QFont(infoFont, 10, QFont::Normal)); rect.setCoords(350,80,450, 93); p->drawText(rect, Qt::AlignRight|Qt::AlignVCenter, "Customer ID:"); rect.setCoords(460,80,600, 93); p->drawText(rect, Qt::AlignLeft|Qt::AlignVCenter, cust->getStr("CustomerID")); rect.setCoords(350,90,450,103); p->drawText(rect, Qt::AlignRight|Qt::AlignVCenter, "Unpaid Balance:"); rect.setCoords(460,90,600, 103); tmpSt.sprintf("$%.2f", Balance); p->setFont(QFont(infoFont, 10, QFont::Bold)); p->drawText(rect, Qt::AlignLeft|Qt::AlignVCenter, tmpSt); p->setFont(QFont(infoFont, 10, QFont::Normal)); // FIXME: This should list all available phone numbers rect.setCoords(350,100,450,113); p->drawText(rect, Qt::AlignRight|Qt::AlignVCenter, "Day Phone:"); rect.setCoords(460,100,600,113); //PDB.get(REF_CUSTOMER, CustID, "Daytime"); //p->drawText(rect, Qt::AlignLeft|Qt::AlignVCenter, PDB.PhoneNumber); rect.setCoords(350,110,450,123); p->drawText(rect, Qt::AlignRight|Qt::AlignVCenter, "Eve Phone:"); //PDB.get(REF_CUSTOMER, CustID, "Evening"); rect.setCoords(460,110,600,123); //p->drawText(rect, Qt::AlignLeft|Qt::AlignVCenter, PDB.PhoneNumber); }
void KniftyClient::paintEvent(QPaintEvent*) { if (!KniftyHandler::initialized()) return; if (captionBufferDirty) update_captionBuffer(); bool active = isActive(); QPainter painter(widget()); QRegion mask; QColor border3 = KniftyHandler::bordersBlendColor() ? options()->colorGroup(KDecoration::ColorTitleBlend, active).background() : widget()->colorGroup().background(); QColor border1 = border3.dark(155); // dark QColor border2 = border3.dark(112); // shadowed QColor titleBorder3 = KniftyHandler::useTitleColor() ? options()->colorGroup(KDecoration::ColorTitleBar, active).background() : widget()->colorGroup().background(); QColor titleBorder1 = titleBorder3.dark(155); // dark... QColor titleBorder4 = hsvRelative(titleBorder3, 0, 0, 70); // light QColor deco1 = options()->colorGroup(KDecoration::ColorTitleBlend, active).background(); QRect topRect(topSpacer_->geometry()); QRect titleRect(titleSpacer_->geometry()); QRect leftTitleRect(leftTitleSpacer_->geometry()); QRect rightTitleRect(rightTitleSpacer_->geometry()); QRect decoRect(decoSpacer_->geometry()); QRect leftRect(leftSpacer_->geometry()); QRect rightRect(rightSpacer_->geometry()); QRect bottomRect(bottomSpacer_->geometry()); QRect tempRect; // topSpacer if(topRect.height() > 0) { painter.setPen(titleBorder1 ); painter.drawLine(topRect.left()+4, topRect.top(), topRect.right()-4, topRect.top() ); painter.drawLine(topRect.left()+2, topRect.top()+1, topRect.left()+2+2, topRect.top()+1 ); painter.drawLine(topRect.right()-2-2, topRect.top()+1, topRect.right()-2, topRect.top()+1 ); painter.setPen(titleBorder4 ); painter.drawLine(topRect.left()+4, topRect.top()+1, topRect.right()-4, topRect.top()+1 ); } // leftTitleSpacer if(leftTitleRect.width() > 0) { painter.setPen(titleBorder1 ); painter.drawLine(leftTitleRect.left(), leftTitleRect.top()+2, leftTitleRect.left(), leftTitleRect.bottom() ); painter.drawLine(leftTitleRect.left()+1, leftTitleRect.top(), leftTitleRect.left()+1, leftTitleRect.top()+2 ); mask = QRegion(leftTitleRect); mask -= QRegion(leftTitleRect.left(), leftTitleRect.top(), 1, leftTitleRect.height() ); mask -= QRegion(leftTitleRect.left()+1, leftTitleRect.top(), 1, 2 ); painter.setClipRegion(mask); painter.setClipping(true); painter.drawTiledPixmap(leftTitleRect, active ? *aTitleBarTile : *iTitleBarTile ); painter.setClipping(false); } // Space under the left button group painter.drawTiledPixmap(leftTitleRect.right()+1, titleRect.top(), (titleRect.left()-1)-leftTitleRect.right(), titleRect.height(), active ? *aTitleBarTile : *iTitleBarTile ); // rightTitleSpacer if(rightTitleRect.width() > 0) { painter.setPen(titleBorder1 ); painter.drawLine(rightTitleRect.right(), rightTitleRect.top()+2, rightTitleRect.right(), rightTitleRect.bottom() ); painter.drawLine(rightTitleRect.right()-1, rightTitleRect.top(), rightTitleRect.right()-1, rightTitleRect.top()+2 ); mask = QRegion(rightTitleRect); mask -= QRegion(rightTitleRect.right(), rightTitleRect.top(), 1, leftTitleRect.height() ); mask -= QRegion(rightTitleRect.right()-1, rightTitleRect.top(), 1, 2 ); painter.setClipRegion(mask); painter.setClipping(true); painter.drawTiledPixmap(rightTitleRect, active ? *aTitleBarTile : *iTitleBarTile ); painter.setClipping(false); } // Space under the right button group painter.drawTiledPixmap(titleRect.right()+1, titleRect.top(), (rightTitleRect.left()-1)-titleRect.right(), titleRect.height(), active ? *aTitleBarTile : *iTitleBarTile ); // titleSpacer QPixmap *titleBfrPtr = active ? aCaptionBuffer : iCaptionBuffer; if(titleRect.width() > 0 && titleBfrPtr != 0) { const int titleMargin = 5; // 5 px betwee title and buttons int tX, tW; switch (KniftyHandler::titleAlign()) { // AlignCenter case Qt::AlignHCenter: tX = (titleBfrPtr->width() > titleRect.width()-2*titleMargin) ? (titleRect.left()+titleMargin) : titleRect.left()+(titleRect.width()- titleBfrPtr->width() )/2; tW = (titleBfrPtr->width() > titleRect.width()-2*titleMargin) ? (titleRect.width()-2*titleMargin) : titleBfrPtr->width(); break; // AlignRight case Qt::AlignRight: tX = (titleBfrPtr->width() > titleRect.width()-2*titleMargin) ? (titleRect.left()+titleMargin) : titleRect.right()-titleMargin-titleBfrPtr->width(); tW = (titleBfrPtr->width() > titleRect.width()-2*titleMargin) ? (titleRect.width()-2*titleMargin) : titleBfrPtr->width(); break; // AlignLeft default: tX = (titleRect.left()+titleMargin); tW = (titleBfrPtr->width() > titleRect.width()-2*titleMargin) ? (titleRect.width()-2*titleMargin) : titleBfrPtr->width(); } if(tW > 0) { painter.drawTiledPixmap(tX, titleRect.top(), tW, titleRect.height(), *titleBfrPtr); } painter.drawTiledPixmap(titleRect.left(), titleRect.top(), tX-titleRect.left(), titleRect.height(), active ? *aTitleBarTile : *iTitleBarTile); painter.drawTiledPixmap(tX+tW, titleRect.top(), titleRect.right()-(tX+tW)+1, titleRect.height(), active ? *aTitleBarTile : *iTitleBarTile); } titleBfrPtr = 0; // decoSpacer if(decoRect.height() > 0) { painter.setPen(titleBorder1 ); painter.drawLine(decoRect.left(), decoRect.top(), decoRect.left(), decoRect.bottom() ); painter.drawLine(decoRect.right(), decoRect.top(), decoRect.right(), decoRect.bottom() ); painter.setPen(deco1 ); painter.drawLine(decoRect.left()+1, decoRect.bottom(), decoRect.right()-1, decoRect.bottom() ); // if(!KniftyHandler::useTitleColor() && !KniftyHandler::bordersBlendColor()) // { painter.setPen(hsvRelative(deco1, 0, -10, +20) ); // } painter.drawLine(decoRect.left()+1, decoRect.top(), decoRect.right()-1, decoRect.top() ); } if(leftRect.height() == 1 && rightRect.height() == 1) // the window is shaded... hopefully { // let's orient on the bottomSpacer which should have the prper x coords... painter.setPen(border1 ); painter.drawPoint(bottomRect.left(), leftRect.top() ); painter.drawPoint(bottomRect.right(), rightRect.top() ); painter.setPen(border3 ); painter.drawLine(bottomRect.left()+1, leftRect.top(), bottomRect.right()-1, rightRect.top() ); } else { // leftSpacer if(leftRect.width() > 0 && leftRect.height() > 0) { painter.setPen(border1 ); painter.drawLine(leftRect.left(), leftRect.top(), leftRect.left(), leftRect.bottom() ); tempRect.setCoords(leftRect.left()+1, leftRect.top(), leftRect.right(), leftRect.bottom() ); painter.fillRect(tempRect, border3 ); } // rightSpacer if(rightRect.width() > 0 && rightRect.height() > 0) { painter.setPen(border1 ); painter.drawLine(rightRect.right(), rightRect.top(), rightRect.right(), rightRect.bottom() ); tempRect.setCoords(rightRect.left(), rightRect.top(), rightRect.right()-1, rightRect.bottom() ); painter.fillRect(tempRect, border3 ); } } // bottomSpacer if(bottomRect.height() > 0) { painter.setPen(border1 ); painter.drawLine(bottomRect.left()+1, bottomRect.bottom(), bottomRect.right()-1, bottomRect.bottom() ); painter.drawLine(bottomRect.left(), bottomRect.top(), bottomRect.left(), bottomRect.bottom()-1 ); painter.drawLine(bottomRect.right(), bottomRect.top(), bottomRect.right(), bottomRect.bottom()-1 ); painter.setPen(border2 ); painter.drawLine(bottomRect.left()+1, bottomRect.bottom()-1, bottomRect.right()-1, bottomRect.bottom()-1 ); tempRect.setCoords(bottomRect.left()+1, bottomRect.top(), bottomRect.right()-1, bottomRect.bottom()-2); painter.fillRect(tempRect, border3 ); } }
QRect& glViewRect::GetTileNumbers() { QRect r; r.setCoords(x_start, y_start, x_end, y_end); return r; }
void KCColumnHeader::mouseReleaseEvent(QMouseEvent * _ev) { if (!m_cellToolIsActive) return; m_pView->disableAutoScroll(); if (m_lSize) m_lSize->hide(); m_bMousePressed = false; if (!m_pView->koDocument()->isReadWrite()) return; register KCSheet * const sheet = m_pView->activeSheet(); if (!sheet) return; if (m_bResize) { double dWidth = m_pView->zoomHandler()->unzoomItX(width()); double ev_PosX; // Remove size indicator painted by paintSizeIndicator if (m_rubberband) { delete m_rubberband; m_rubberband = 0; } int start = m_iResizedColumn; int end = m_iResizedColumn; QRect rect; rect.setCoords(m_iResizedColumn, 1, m_iResizedColumn, KS_rowMax); if (m_pView->selection()->isColumnSelected()) { if (m_pView->selection()->contains(QPoint(m_iResizedColumn, 1))) { start = m_pView->selection()->lastRange().left(); end = m_pView->selection()->lastRange().right(); rect = m_pView->selection()->lastRange(); } } double width = 0.0; double x; if (sheet->layoutDirection() == Qt::RightToLeft) ev_PosX = dWidth - m_pView->zoomHandler()->unzoomItX(_ev->pos().x()) + m_pCanvas->xOffset(); else ev_PosX = m_pView->zoomHandler()->unzoomItX(_ev->pos().x()) + m_pCanvas->xOffset(); x = sheet->columnPosition(m_iResizedColumn); if (ev_PosX - x <= 0.0) width = 0.0; else width = ev_PosX - x; if (width != 0.0) { KCResizeColumnManipulator* command = new KCResizeColumnManipulator(); command->setSheet(sheet); command->setSize(width); command->add(KCRegion(rect, sheet)); if (!command->execute()) delete command; } else { // hide HideShowManipulator* command = new HideShowManipulator(); command->setSheet(sheet); command->setManipulateColumns(true); command->add(KCRegion(rect, sheet)); if (!command->execute()) delete command; } delete m_lSize; m_lSize = 0; } else if (m_bSelection) { QRect rect = m_pView->selection()->lastRange(); // TODO: please don't remove. Right now it's useless, but it's for a future feature // Norbert bool m_frozen = false; if (m_frozen) { kDebug(36001) << "selected: L" << rect.left() << " R" << rect.right(); int i; QList<int> hiddenCols; for (i = rect.left(); i <= rect.right(); ++i) { if (sheet->columnFormat(i)->isHidden()) { hiddenCols.append(i); } } if (hiddenCols.count() > 0) { if (m_pView->selection()->isRowSelected()) { KMessageBox::error(this, i18n("Area is too large.")); return; } HideShowManipulator* command = new HideShowManipulator(); command->setSheet(sheet); command->setManipulateColumns(true); command->setReverse(true); command->add(*m_pView->selection()); command->execute(); } } } m_bSelection = false; m_bResize = false; }
QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const { Q_D(const QMacPrintEngine); QVariant ret; if (!d->session && d->valueCache.contains(key)) return *d->valueCache.find(key); switch (key) { case PPK_CollateCopies: ret = false; break; case PPK_ColorMode: ret = QPrinter::Color; break; case PPK_Creator: break; case PPK_DocumentName: break; case PPK_FullPage: ret = d->fullPage; break; case PPK_NumberOfCopies: ret = 1; break; case PPK_Orientation: PMOrientation orientation; PMGetOrientation(d->format, &orientation); ret = orientation == kPMPortrait ? QPrinter::Portrait : QPrinter::Landscape; break; case PPK_OutputFileName: ret = d->outputFilename; break; case PPK_PageOrder: break; case PPK_PaperSource: break; case PPK_PageRect: { // PageRect is returned in device pixels QRect r; PMRect macrect, macpaper; qreal hRatio = d->resolution.hRes / 72; qreal vRatio = d->resolution.vRes / 72; if (d->hasCustomPaperSize) { r = QRect(0, 0, qRound(d->customSize.width() * hRatio), qRound(d->customSize.height() * vRatio)); if (d->hasCustomPageMargins) { r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio), -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio)); } else { QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList(); r.adjust(qRound(margins.at(0).toDouble() * hRatio), qRound(margins.at(1).toDouble() * vRatio), -qRound(margins.at(2).toDouble() * hRatio), -qRound(margins.at(3).toDouble()) * vRatio); } } else if (PMGetAdjustedPageRect(d->format, ¯ect) == noErr && PMGetAdjustedPaperRect(d->format, &macpaper) == noErr) { if (d->fullPage || d->hasCustomPageMargins) { r.setCoords(int(macpaper.left * hRatio), int(macpaper.top * vRatio), int(macpaper.right * hRatio), int(macpaper.bottom * vRatio)); r.translate(-r.x(), -r.y()); if (d->hasCustomPageMargins) { r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio), -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio)); } } else { r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio), int(macrect.right * hRatio), int(macrect.bottom * vRatio)); r.translate(int(-macpaper.left * hRatio), int(-macpaper.top * vRatio)); } } ret = r; break; } case PPK_PaperSize: ret = d->paperSize(); break; case PPK_PaperRect: { QRect r; PMRect macrect; if (d->hasCustomPaperSize) { r = QRect(0, 0, qRound(d->customSize.width()), qRound(d->customSize.height())); } else if (PMGetAdjustedPaperRect(d->format, ¯ect) == noErr) { qreal hRatio = d->resolution.hRes / 72; qreal vRatio = d->resolution.vRes / 72; r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio), int(macrect.right * hRatio), int(macrect.bottom * vRatio)); r.translate(-r.x(), -r.y()); } ret = r; break; } case PPK_PrinterName: { CFIndex currIndex; PMPrinter unused; QCFType<CFArrayRef> printerList; OSStatus status = PMSessionCreatePrinterList(d->session, &printerList, &currIndex, &unused); if (status != noErr) qWarning("QMacPrintEngine::printerName: Problem getting list of printers: %ld", long(status)); if (currIndex != -1 && printerList && currIndex < CFArrayGetCount(printerList)) { const CFStringRef name = static_cast<CFStringRef>(CFArrayGetValueAtIndex(printerList, currIndex)); if (name) ret = QCFString::toQString(name); } break; } case PPK_Resolution: { ret = d->resolution.hRes; break; } case PPK_SupportedResolutions: ret = d->supportedResolutions(); break; case PPK_CustomPaperSize: ret = d->customSize; break; case PPK_PageMargins: { QList<QVariant> margins; if (d->hasCustomPageMargins) { margins << d->leftMargin << d->topMargin << d->rightMargin << d->bottomMargin; } else { PMPaperMargins paperMargins; PMPaper paper; PMGetPageFormatPaper(d->format, &paper); PMPaperGetMargins(paper, &paperMargins); margins << paperMargins.left << paperMargins.top << paperMargins.right << paperMargins.bottom; } ret = margins; break; } default: break; } return ret; }
void CCompass::Draw(QPainter *p_pPainter, QPoint *p_pCenter) { QBrush BkBrush, Brush[2], TextBrush; QPen Pen; QRect DrawRect; QColor Color; QPoint Points[3], TickPoints[24]; QFont Font; short i, Offset = 5, FontPixelSize = 15, TextWidth; char tstr[128]; double dCompassPosition; for(i = 0; i < 24; i += 2) { TickPoints[i].setX(p_pCenter->x() + 0); TickPoints[i].setY(p_pCenter->y() - m_nRadius); TickPoints[i + 1].setX(p_pCenter->x() + 0); TickPoints[i + 1].setY(p_pCenter->y() - m_nRadius + 2 * Offset + ((!(i % 3)) ? Offset : 0)); } DrawRect.setCoords(p_pCenter->x() - m_nRadius, p_pCenter->y() - m_nRadius, p_pCenter->x() + m_nRadius, p_pCenter->y() + m_nRadius); BkBrush = QBrush(QColor(255, 0, 0, 128)); TextBrush = QBrush(QColor(255, 255, 0, 255)); Brush[0] = QBrush(QColor(255, 0, 0, 255)); Brush[1] = QBrush(QColor(255, 255, 255, 255)); Pen = QPen(Qt::black); Pen.setWidth(1); Pen.setStyle(Qt::NoPen); p_pPainter->setPen(Pen); BkBrush.setStyle(Qt::SolidPattern); p_pPainter->setBrush(BkBrush); p_pPainter->drawEllipse(DrawRect.center(), m_nRadius - Offset, m_nRadius - Offset); BkBrush.setStyle(Qt::NoBrush); p_pPainter->setBrush(BkBrush); Pen.setStyle(Qt::SolidLine); p_pPainter->setPen(Pen); p_pPainter->drawEllipse(DrawRect.center(), m_nRadius, m_nRadius); for(i = 0; i < 12; i ++) RotatePoints(&(TickPoints[i * 2]), 2, p_pCenter, 30 * i); p_pPainter->drawLines(TickPoints, 12); Pen.setStyle(Qt::NoPen); p_pPainter->setPen(Pen); p_pPainter->setBrush(Brush[0]); Points[0].setX(p_pCenter->x() + Offset); Points[0].setY(p_pCenter->y()); Points[1].setX(p_pCenter->x() - Offset); Points[1].setY(p_pCenter->y()); Points[2].setX(p_pCenter->x()); Points[2].setY(p_pCenter->y() - m_nRadius + Offset); dCompassPosition = 360.0 - m_dHeading_deg; if(dCompassPosition < 0) dCompassPosition += 360; RotatePoints(Points, 3, p_pCenter, dCompassPosition); p_pPainter->drawConvexPolygon(Points, 3); p_pPainter->setBrush(Brush[1]); Points[0].setX(p_pCenter->x() + Offset); Points[0].setY(p_pCenter->y()); Points[1].setX(p_pCenter->x() - Offset); Points[1].setY(p_pCenter->y()); Points[2].setX(p_pCenter->x()); Points[2].setY(p_pCenter->y() + m_nRadius - Offset); RotatePoints(Points, 3, p_pCenter, dCompassPosition); p_pPainter->drawConvexPolygon(Points, 3); Pen.setColor(Qt::black); Pen.setStyle(Qt::SolidLine); p_pPainter->setPen(Pen); p_pPainter->setBrush(TextBrush); Font.setPixelSize(FontPixelSize); p_pPainter->setFont(Font); sprintf_s(tstr, sizeof(tstr), "%.0lf", m_dHeading_deg); QFontMetrics FontMetrics(Font); TextWidth = FontMetrics.width(tstr) + 4; DrawRect.setCoords(p_pCenter->x() - TextWidth / 2, p_pCenter->y() - FontPixelSize / 2, p_pCenter->x() + TextWidth / 2, p_pCenter->y() + FontPixelSize / 2 + 2); p_pPainter->drawRect(DrawRect); p_pPainter->drawText(DrawRect, Qt::AlignCenter, QString::fromLocal8Bit(tstr)); }
void TerrainProfileGraph::drawAxes(double yMin, double yMax, double yScale, double xMax, QRect &out_field) { QBrush axesBrush(_axesColor); // Create min/max text items QGraphicsSimpleTextItem* yMinText = new QGraphicsSimpleTextItem(QString::number(yMin)); yMinText->setBrush(axesBrush); yMinText->setFont(_graphFont); QGraphicsSimpleTextItem* yMaxText = new QGraphicsSimpleTextItem(QString::number(yMax)); yMaxText->setBrush(axesBrush); yMaxText->setFont(_graphFont); QGraphicsSimpleTextItem* xMaxText = new QGraphicsSimpleTextItem(QString::number(xMax)); xMaxText->setBrush(axesBrush); xMaxText->setFont(_graphFont); // Calculate positioning offsets and set out_field to actual graph bounds double fontHalfHeight = yMinText->boundingRect().height() / 2.0; int textSpacing = 8; int xOffset = (int)osg::maximum(yMinText->boundingRect().width(), yMaxText->boundingRect().width()) + textSpacing; int yOffset = (int)xMaxText->boundingRect().height() + textSpacing; int xAxisY = _graphHeight - yOffset; out_field.setCoords(xOffset, (int)fontHalfHeight, _graphWidth, xAxisY); // Draw background rectangle _scene->addRect(out_field, QPen(Qt::NoPen), QBrush(_fieldColor))->setZValue(FIELD_Z); // Add min/max text items to the scene yMinText->setPos(xOffset - textSpacing - yMinText->boundingRect().width(), xAxisY - fontHalfHeight); yMinText->setZValue(AXES_Z); _scene->addItem(yMinText); yMaxText->setPos(xOffset - textSpacing - yMaxText->boundingRect().width(), 0); yMaxText->setZValue(AXES_Z); _scene->addItem(yMaxText); xMaxText->setPos(_graphWidth - xMaxText->boundingRect().width(), _graphHeight - xMaxText->boundingRect().height()); xMaxText->setZValue(AXES_Z); _scene->addItem(xMaxText); // Draw the main axes and x-axis end cap _scene->addLine(xOffset, fontHalfHeight, xOffset, xAxisY + 5, _axesPen)->setZValue(AXES_Z); _scene->addLine(xOffset - 5, xAxisY, _graphWidth, xAxisY, _axesPen)->setZValue(AXES_Z); _scene->addLine(_graphWidth, xAxisY - 5, _graphWidth, xAxisY + 5, _axesPen)->setZValue(AXES_Z); // Draw horizontal graph lines double yGraphScale = (yScale / (yMax - yMin)) * out_field.height(); double graphLineY = xAxisY - yGraphScale; for (double y = yMin + yScale; y <= yMax; y += yScale) { _scene->addLine(xOffset - 5, graphLineY, _graphWidth, graphLineY, _axesPen)->setZValue(AXES_Z);; if (y != yMax) { QGraphicsSimpleTextItem* yText = new QGraphicsSimpleTextItem(QString::number(y)); yText->setBrush(axesBrush); yText->setFont(_graphFont); yText->setPos(xOffset - textSpacing - yText->boundingRect().width(), graphLineY - fontHalfHeight); yText->setZValue(AXES_Z); _scene->addItem(yText); } graphLineY -= yGraphScale; } }