void Array3DEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform) { gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::GetInstance(); int border = renderingHelper->instructionsListBorder; const int functionTextHeight = 20; //Draw header rectangle wxRect headerRect(x, y, width, functionTextHeight); renderingHelper->DrawNiceRectangle(dc, headerRect); //Name dc.SetFont( renderingHelper->GetNiceFont().Bold() ); dc.SetTextForeground(wxColour(0,0,0)); wxString caption = _("Iterate through ") + (GetArrayName() != "" ? GetArrayName() : _("(Not defined)")) + _(" on XYZ"); dc.DrawText( caption, x + 4, y + 3 ); //Draw conditions rectangle wxRect rect(x, y+functionTextHeight, renderingHelper->GetConditionsColumnWidth()+border, GetRenderedHeight(width, platform)-functionTextHeight); renderingHelper->DrawNiceRectangle(dc, rect); //Draw actions and conditions renderingHelper->DrawConditionsList(conditions, dc, x+border, y+functionTextHeight+border, renderingHelper->GetConditionsColumnWidth()-border, this, areas, selection, platform); renderingHelper->DrawActionsList(actions, dc, x+renderingHelper->GetConditionsColumnWidth()+border, y+functionTextHeight+border, width-renderingHelper->GetConditionsColumnWidth()-border*2, this, areas, selection, platform); }
/** * Render the event in the bitmap */ void ForEachEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform) { #if !defined(GD_NO_WX_GUI) gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get(); int border = renderingHelper->instructionsListBorder; const int forEachTextHeight = 20; //Draw header rectangle wxRect headerRect(x, y, width, forEachTextHeight); renderingHelper->DrawNiceRectangle(dc, headerRect); //For Each text dc.SetFont( renderingHelper->GetNiceFont().Bold() ); dc.SetTextForeground(wxColour(0,0,0)); dc.DrawText( _("For each object") + " " + objectsToPick.GetPlainString() + _(", repeat :"), x + 4, y + 3 ); //Draw conditions rectangle wxRect rect(x, y+forEachTextHeight, renderingHelper->GetConditionsColumnWidth()+border, GetRenderedHeight(width, platform)-forEachTextHeight); renderingHelper->DrawNiceRectangle(dc, rect); //Draw actions and conditions renderingHelper->DrawConditionsList(conditions, dc, x+border, y+forEachTextHeight+border, renderingHelper->GetConditionsColumnWidth()-border, this, areas, selection, platform); renderingHelper->DrawActionsList(actions, dc, x+renderingHelper->GetConditionsColumnWidth()+border, y+forEachTextHeight+border, width-renderingHelper->GetConditionsColumnWidth()-border*2, this, areas, selection, platform); #endif }
/** * @brief Entity::drawHeader * @param painter */ void Entity::drawHeader(QPainter *painter) { painter->save(); QColor color = typeColor(); // Fill background QLinearGradient gradient(0, -height() / 2, 0, -height() / 2 + minimumHeight ); gradient.setColorAt(0, color); gradient.setColorAt(1, Qt::white); QRectF headerRect(-width() / 2, -height() / 2, width(), minimumHeight); painter->fillRect(headerRect, QBrush(gradient)); // Draw frame painter->setPen(color); painter->drawRect(headerRect); // Add element name painter->setPen(Qt::black); painter->setRenderHint(QPainter::TextAntialiasing); QString name(cutText(G_ASSERT(m_Type)->name(), painter->fontMetrics(), width())); painter->drawText(headerRect, Qt::AlignCenter, name); painter->restore(); }
void VRFSystemMiniView::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { painter->setRenderHint(QPainter::Antialiasing, true); painter->setBrush(Qt::NoBrush); painter->setPen(QPen(Qt::black,1,Qt::SolidLine, Qt::RoundCap)); painter->drawRect(boundingRect()); painter->setPen(QPen(Qt::black,2,Qt::SolidLine, Qt::RoundCap)); QRectF _headerRect = headerRect(); painter->drawRect(_headerRect); painter->drawText(QRectF(_headerRect.x() + 5, _headerRect.y() + 5, _headerRect.width() - 10, _headerRect.height() - 10),Qt::AlignVCenter | Qt::AlignLeft,m_name); QRectF _contentRect = contentRect(); double x = _contentRect.x() + 5; double y = _contentRect.y() + 12; painter->drawPixmap(x,y,m_vrfOutdoorPix); x = x + m_vrfOutdoorPix.width() + 2; painter->drawPixmap(x,y,m_vrfTransferPix); x = x + m_vrfTerminalPix.width() + 2; painter->drawPixmap(x,y,m_vrfTerminalPix); x = x + m_vrfTerminalPix.width() + 2; QFont font = painter->font(); font.setPointSize(24); font.setWeight(QFont::Bold); painter->setFont(font); painter->drawText(QRectF(x,y,m_length,m_length / 2.0),Qt::AlignCenter,QString::number(m_terminals)); font.setPointSize(12); font.setWeight(QFont::Normal); painter->setFont(font); painter->drawText(QRectF(x,y + m_length / 2.0,m_length,m_length / 2.0),Qt::AlignCenter,QString("Terminals")); x = x + m_length; painter->drawPixmap(x,y,m_vrfZonePix); x = x + m_vrfZonePix.width(); font.setPointSize(24); font.setWeight(QFont::Bold); painter->setFont(font); painter->drawText(QRectF(x,y,m_length,m_length / 2.0),Qt::AlignCenter,QString::number(m_zones)); font.setPointSize(12); font.setWeight(QFont::Normal); painter->setFont(font); painter->drawText(QRectF(x,y + m_length / 2.0,m_length,m_length / 2.0),Qt::AlignCenter,QString("Zones")); x = x + m_length; }
/** * Render the event in the bitmap */ void WhileEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform) { #if !defined(GD_NO_WX_GUI) gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get(); int border = renderingHelper->instructionsListBorder; const int repeatHeight = 20; //Draw header rectangle int whileConditionsHeight = renderingHelper->GetRenderedConditionsListHeight(whileConditions, width-80-border*2, platform)+border*2; if (!infiniteLoopWarning && whileConditionsHeight < 32 ) whileConditionsHeight = 32; wxRect headerRect(x, y, width, whileConditionsHeight+repeatHeight); renderingHelper->DrawNiceRectangle(dc, headerRect); //While text dc.SetFont( renderingHelper->GetNiceFont().Bold() ); if ( !IsDisabled() ) dc.SetTextForeground( wxColour( 0, 0, 0 ) ); else dc.SetTextForeground( wxColour( 160, 160, 160 ) ); dc.DrawText( _("While :"), x+5, y+5 ); //Draw icon if infinite loop warning is deactivated. if (!infiniteLoopWarning) { if ( gd::CommonBitmapProvider::Get()->noProtection.IsOk() ) dc.DrawBitmap(gd::CommonBitmapProvider::Get()->noProtection, wxPoint(x+5,y+5+18), /*useMask=*/true); } //Draw "while conditions" renderingHelper->DrawConditionsList(whileConditions, dc, x+80+border, y+border, width-80-border*2, this, areas, selection, platform); dc.SetFont( renderingHelper->GetNiceFont().Bold() ); if ( !IsDisabled() ) dc.SetTextForeground( wxColour( 0, 0, 0 ) ); else dc.SetTextForeground( wxColour( 160, 160, 160 ) ); dc.DrawText( _("Repeat :"), x+4, y+whileConditionsHeight+3); whileConditionsHeight += repeatHeight; //Draw conditions rectangle wxRect rect(x, y+whileConditionsHeight, renderingHelper->GetConditionsColumnWidth()+border, GetRenderedHeight(width, platform)-whileConditionsHeight); renderingHelper->DrawNiceRectangle(dc, rect); renderingHelper->DrawConditionsList(conditions, dc, x+border, y+whileConditionsHeight+border, renderingHelper->GetConditionsColumnWidth()-border, this, areas, selection, platform); renderingHelper->DrawActionsList(actions, dc, x+renderingHelper->GetConditionsColumnWidth()+border, y+whileConditionsHeight+border, width-renderingHelper->GetConditionsColumnWidth()-border*2, this, areas, selection, platform); #endif }
void TAbstractWindow::_draw(TRenderTarget& target) { if (needsRedraw == true) { TRenderTarget& localTarget = renderImage.getRenderTarget(); localTarget.clear(_currentColor()); if (image.drawingObject != nullptr) { if (image.image != nullptr) { sf::Sprite* sprite = image.drawingObject.get(); if (sprite != nullptr) { sprite->setColor(_currentColor()); } } localTarget.draw(*image.drawingObject); } if (HasHeader() == true) { sf::RectangleShape headerRect( sf::Vector2f(size.x, headerHeight) ); headerRect.setFillColor(_currentHeaderColor()); localTarget.draw(headerRect); } if (headerText->GetText().empty() == false) { headerText->Draw(localTarget); } renderImage.createDrawingObject(); needsRedraw = false; } const TCoordinate position = GetScreenPosition(); renderImage.getDrawingObject().setPosition(position.x, position.y); target.draw(renderImage.getDrawingObject()); #if defined(_DEBUG) if (Debug::show_frames() == true) { sf::RectangleShape boundingRect( sf::Vector2f(size.x, size.y) ); boundingRect.setFillColor(sf::Color(0, 0, 0, 0)); boundingRect.setOutlineColor(sf::Color(0, 255 - 55 * mouseOver, 0, 128)); boundingRect.setOutlineThickness(2.f); boundingRect.setPosition(position.x, position.y); target.draw(boundingRect); sf::Text rectText = TFont().CreateText(String::toWide(name)); rectText.setPosition(position.x, position.y); target.draw(rectText); } #endif // _DEBUG }
void LabeledSection::mouseDoubleClickEvent(QMouseEvent* pEvent) { if (pEvent != NULL) { const QPoint& pos = pEvent->pos(); if (mpSectionWidget != NULL) { QPoint headerPos = mpTextLabel->pos(); int headerWidth = width() - headerPos.x(); int headerHeight = mpTextLabel->height(); QRect headerRect(headerPos.x(), headerPos.y(), headerWidth, headerHeight); if (headerRect.contains(pos) == true) { mpSectionWidget->setVisible(mpSectionWidget->isHidden()); } } } QWidget::mouseDoubleClickEvent(pEvent); }
void MainWindow::paintEvent(QPaintEvent*) { const QPoint start(width()/2, 0); const QPoint finalStop(width()/2, height()); QLinearGradient gradient(start, finalStop); const QColor qtGreen(102, 176, 54); gradient.setColorAt(0, qtGreen.dark()); gradient.setColorAt(0.5, qtGreen); gradient.setColorAt(1, qtGreen.dark()); QPainter p(this); p.fillRect(0, 0, width(), height(), gradient); QFont headerFont("Sans Serif", 12, QFont::Bold); QFont normalFont("Sans Serif", 9, QFont::Normal); // draw it twice for shadow effect p.setFont(headerFont); QRect headerRect(1, 1, width(), 25); p.setPen(Qt::black); p.drawText(headerRect, Qt::AlignCenter, m_station.name()); headerRect.moveTopLeft(QPoint(0, 0)); p.setPen(Qt::white); p.drawText(headerRect, Qt::AlignCenter, m_station.name()); p.setFont(normalFont); int pos = 40; for (int i = 0; i < m_times.count() && i < 9; ++i) { p.setPen(Qt::black); p.drawText(51, pos + 1, m_times.at(i).time()); p.drawText(101, pos + 1, m_times.at(i).direction()); p.setPen(Qt::white); p.drawText(50, pos, m_times.at(i).time()); p.drawText(100, pos, m_times.at(i).direction()); pos += 18; } }
wxJigsawShape::wxJigsawShapeHitTest wxJigsawShape::HitTest(wxDC & dc, wxPoint pos, wxJigsawShapeHitTestInfo & info, double scale, bool bDebug) { wxJigsawShapeHitTest res = wxJS_HITTEST_NONE; wxSize headerSize = GetHeaderSize(dc, scale); wxRect headerRect(GetPosition(), headerSize); wxSize size = GetSize(dc, scale); wxRect dockingRectTop = wxRect(m_Position.x, m_Position.y-wxJigsawShape::HotSpotHeight/2, headerSize.GetWidth(), wxJigsawShape::HotSpotHeight); wxRect dockingRectBottom = wxRect(m_Position.x, m_Position.y-wxJigsawShape::HotSpotHeight/2+size.GetHeight(), headerSize.GetWidth(), wxJigsawShape::HotSpotHeight); if(dockingRectTop.Contains(pos) && m_HasNotch && !GetParent()) { res = wxJS_HITTEST_NOTCH_DOCKING_AREA; } else if(dockingRectBottom.Contains(pos) && m_HasBump && !GetParent()) { res = wxJS_HITTEST_BUMP_DOCKING_AREA; } else if(headerRect.Contains(pos)) { do { int paramRectOffset = GetParametersOffset(scale); wxRect labelRect(GetPosition().x, GetPosition().y, paramRectOffset, headerSize.GetHeight()); if(labelRect.Contains(pos) || m_InputParameters.GetCount() == 0) { res = wxJS_HITTEST_MOVINGAREA; break; } wxRect paramRect(GetPosition(), headerSize); paramRect.Offset(paramRectOffset, 0); bool bFound = false; int paramIndex = 0; for(wxJigsawInputParameters::Node * node = m_InputParameters.GetFirst(); node; node = node->GetNext(), paramIndex++) { wxJigsawInputParameter * param = node->GetData(); paramRect.SetSize(param->GetSize()); paramRect.SetTop((headerRect.GetHeight() - paramRect.GetHeight())/2 + headerRect.GetTop()); switch(param->HitTest(pos, paramRect, bDebug)) { case wxJigsawInputParameter::wxJSP_HITETST_LABEL: res = wxJS_HITTEST_MOVINGAREA; bFound = true; break; case wxJigsawInputParameter::wxJSP_HITTEST_SLOT: info.SetInputParameterIndex(paramIndex); info.SetInputParameterStyle(param->GetStyle()); res = wxJS_HITTEST_SLOT; bFound = true; break; case wxJigsawInputParameter::wxJSP_HITTEST_SHAPE: res = param->GetShape()->HitTest(dc, pos, info, scale, bDebug); bFound = true; break; default: break; } if(bFound) break; paramRect.Offset(paramRect.GetWidth() + wxJigsawInputParameter::ParameterSpacing, 0); } if(!bFound) { res = wxJS_HITTEST_MOVINGAREA; } } while(false); } else if(m_HasCShape) { do { wxRect verticalCShapeRect( GetPosition().x, GetPosition().y + headerSize.GetHeight()/2, wxJigsawShape::CShapeThickness, size.GetHeight()-headerSize.GetHeight()/2); wxRect horizontalCShapeRect( GetPosition().x, GetPosition().y + size.GetHeight() - wxJigsawShape::CShapeThickness, GetHeaderSize(dc, scale).GetWidth(), wxJigsawShape::CShapeThickness); if(m_Children.IsEmpty()) { wxRect cShapeRect(verticalCShapeRect.GetRight(), headerRect.GetBottom(), headerRect.GetWidth()-verticalCShapeRect.GetWidth(), horizontalCShapeRect.GetTop()-headerRect.GetBottom()); if(cShapeRect.Contains(pos)) { res = wxJS_HITTEST_C_SHAPE_BUMP; } } else { wxRect cShapeRect( verticalCShapeRect.GetRight(), headerRect.GetBottom()-wxJigsawShape::ConnectorSize.GetHeight(), wxJigsawShape::ConnectorSize.GetWidth(), 10/*2 * wxJigsawShape::ConnectorSize.GetHeight()*/); int oldWidth(cShapeRect.GetWidth()); int childIndex = 0; for(wxJigsawShapeList::Node * node = m_Children.GetFirst(); node; node = node->GetNext(), childIndex++) { wxJigsawShape * child = node->GetData(); if(!child) continue; wxSize childSize = child->GetSize(); cShapeRect.SetWidth(wxMax(childSize.GetWidth(), oldWidth)); if(cShapeRect.Contains(pos)) { res = wxJS_HITTEST_CHILD_INSERTION_AREA; info.SetChildIndex(childIndex); break; } oldWidth = cShapeRect.GetWidth(); cShapeRect.Offset(0, childSize.GetHeight()); } if(!res == wxJS_HITTEST_NONE) break; if(cShapeRect.Contains(pos)) { res = wxJS_HITTEST_C_SHAPE_NOTCH; info.SetChildIndex(childIndex); break; } if(res != wxJS_HITTEST_NONE) break; for(wxJigsawShapeList::Node * node = m_Children.GetFirst(); node; node = node->GetNext()) { wxJigsawShape * child = node->GetData(); if(!child) continue; res = child->HitTest(dc, pos, info, scale); if(res != wxJS_HITTEST_NONE) break; } if(res != wxJS_HITTEST_NONE) break; } // C-Shape background if(verticalCShapeRect.Contains(pos)) { res = wxJS_HITTEST_MOVINGAREA; break; } if(horizontalCShapeRect.Contains(pos)) { res = wxJS_HITTEST_MOVINGAREA; break; } } while(false); } info.SetResult(res); // If point belongs to some meaningful area of a shape (and does not belong to // shape's child or to input parameter)... if((res != wxJS_HITTEST_NONE) && !info.GetShape()) { info.SetShape(this); info.SetMousePos(pos); } return res; }
QDomElement DetailSection::xml(QDomDocument doc, QList<Container *> &usedItems, QMap<QString, bool> &querys, QList<Section*> sectionPool) { QDomElement node = doc.createElement("Section"); node.setAttribute("id",sectionType()); node.setAttribute("size",(int)rect().height()); node.setAttribute("name",m_SectionName); node.setAttribute("SqlGlobal",m_SqlGlobal); node.setAttribute("SqlInterno",m_SqlInterno); node.setAttribute("ClausulaInterna",m_ClausulaInterna); node.setAttribute("haveSqlInterno",m_header || m_foot); node.setAttribute("colored",m_colorear); node.setAttribute("color1",ColorString(m_color1)); node.setAttribute("alternative",m_use2Colors); node.setAttribute("color2",ColorString(m_color2)); QPointF br(rect().bottomRight().x(),rect().bottomRight().y()); QPointF tl(rect().topLeft().x(),rect().topLeft().y()); if(m_header) { QDomElement headerNode = doc.createElement("Header"); headerNode.setAttribute("size",m_headerSize); QRectF aux(tl,QPointF(br.x(),tl.y()+m_headerSize)); QRectF headerRect(mapRectToScene(aux)); QList<QGraphicsItem*>items =this->scene()->items(headerRect); QListIterator<QGraphicsItem*> it(items); while (it.hasNext()) { QGraphicsItem* c = it.next(); Container* cont = qgraphicsitem_cast<Container*>(c); if(cont) { if(!usedItems.contains(cont)) { headerNode.appendChild(cont->xml(doc,marginPoint(),sectionPool)); usedItems.append(cont); } } } node.appendChild(headerNode); } QDomElement bodyNode = doc.createElement("Body"); bodyNode.setAttribute("size",this->rect().height() - m_headerSize - m_footSize); QRectF bodyRect(mapToScene(QPointF(tl.x(),tl.y()+m_headerSize)),mapToScene(QPointF(br.x(),br.y()-m_footSize))); QList<QGraphicsItem*>items =this->scene()->items(bodyRect); QListIterator<QGraphicsItem*> it(items); while (it.hasNext()) { QGraphicsItem* c = it.next(); Container* cont = qgraphicsitem_cast<Container*>(c); if(cont) { if(!usedItems.contains(cont)) { bodyNode.appendChild(cont->xml(doc,mapToScene(QPointF(tl.x(),tl.y()+m_headerSize)),sectionPool)); usedItems.append(cont); } } } node.appendChild(bodyNode); if(m_foot) { QDomElement footNode = doc.createElement("Foot"); footNode.setAttribute("size",m_footSize); QRectF footRect(mapToScene(QPointF(tl.x(),br.y()-m_footSize+1)),mapToScene(QPointF(br))); QList<QGraphicsItem*>items =this->scene()->items(footRect); QListIterator<QGraphicsItem*> it(items); while (it.hasNext()) { QGraphicsItem* c = it.next(); Container* cont = qgraphicsitem_cast<Container*>(c); if(cont) { if(!usedItems.contains(cont)) { footNode.appendChild(cont->xml(doc,mapToScene(QPointF(tl.x(),br.y()-m_footSize)),sectionPool)); usedItems.append(cont); } } } node.appendChild(footNode); } return node; }
void TextPrinter::paintPage(QPainter *painter, QTextDocument *document, int pagenum) { QRectF rect; double onepoint = painter->device()->logicalDpiY() / 72.0; // header if (headersize_ > 0) { rect = headerRect(painter->device()); if (headerrule_ > 0.0) { painter->save(); // allow space between rule and header painter->translate(0, onepoint + (headerrule_ * onepoint / 2.0)); painter->setPen(QPen(Qt::black, headerrule_ * onepoint)); painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->restore(); } // replace page variables QString header = headertext_; header.replace("&page;", QString::number(pagenum)); if (dateformat_.isEmpty()) { header.replace("&date;", QDate::currentDate().toString()); } else { header.replace("&date;", QDate::currentDate().toString(dateformat_)); } painter->save(); painter->translate(rect.left(), rect.top()); QRectF clip(0, 0, rect.width(), rect.height()); QTextDocument doc; doc.setUseDesignMetrics(true); doc.setHtml(header); doc.documentLayout()->setPaintDevice(painter->device()); doc.setPageSize(rect.size()); // align text to bottom double newtop = clip.bottom() - doc.size().height(); clip.setHeight(doc.size().height()); painter->translate(0, newtop); doc.drawContents(painter, clip); painter->restore(); } // footer if (footersize_ > 0) { rect = footerRect(painter->device()); if (footerrule_ > 0.0) { painter->save(); // allow space between rule and footer painter->translate(0, -onepoint + (-footerrule_ * onepoint / 2.0)); painter->setPen(QPen(Qt::black, footerrule_ * onepoint)); painter->drawLine(rect.topLeft(), rect.topRight()); painter->restore(); } // replace page variables QString footer = footertext_; footer.replace("&page;", QString::number(pagenum)); if (dateformat_.isEmpty()) { footer.replace("&date;", QDate::currentDate().toString()); } else { footer.replace("&date;", QDate::currentDate().toString(dateformat_)); } painter->save(); painter->translate(rect.left(), rect.top()); QRectF clip(0, 0, rect.width(), rect.height()); QTextDocument doc; doc.setUseDesignMetrics(true); doc.setHtml(footer); doc.documentLayout()->setPaintDevice(painter->device()); doc.setPageSize(rect.size()); doc.drawContents(painter, clip); painter->restore(); } // content painter->save(); rect = contentRect(painter->device()); painter->translate(rect.left(), rect.top() - (pagenum-1) * rect.height()); QRectF clip(0, (pagenum-1) * rect.height(), rect.width(), rect.height()); document->drawContents(painter, clip); painter->restore(); }
void QReportBand::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); int salt = (int)bandType() + 1; QColor c; // QColor c = QColor::fromRgb( // salt *40, // 100 + salt *30, // 180 + salt *10); switch(bandType()){ case ReportHeader: c = Qt::darkBlue; break; case PageHeader: c = Qt::darkGreen; break; case GroupHeader: c = Qt::darkBlue; break; case Data: c = Qt::darkMagenta; break; case EmptyData: c = Qt::blue; break; case GroupFooter: c = Qt::darkYellow; break; case PageFooter: c = Qt::darkRed; break; case ReportFooter: c = Qt::darkCyan; break; default: qDebug() << "f**k"; } QRect headerRect(0, 0, this->size().width(), _headerHeight); painter->setPen(QPen(c)); painter->drawRect(this->boundingRect()); painter->drawLine(0, _headerHeight, this->size().width(), _headerHeight); QBrush bg(QColor(240, 240, 240, 128)); painter->setBrush(bg); painter->drawRect(this->boundingRect()); //draw header QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, _headerHeight)); linearGrad.setColorAt(0, Qt::white); linearGrad.setColorAt(1, c.lighter(300)); QBrush brush(linearGrad); painter->setBrush(brush); painter->drawRect(headerRect); painter->setPen(Qt::black); headerRect.setLeft(15); painter->drawText(headerRect, header(), Qt::AlignLeft | Qt::AlignVCenter); }
void DrawStartPage(WindowInfo& win, HDC hdc, FileHistory& fileHistory, COLORREF colorRange[2]) { HPEN penBorder = CreatePen(PS_SOLID, DOCLIST_SEPARATOR_DY, WIN_COL_BLACK); HPEN penThumbBorder = CreatePen(PS_SOLID, DOCLIST_THUMBNAIL_BORDER_W, WIN_COL_BLACK); HPEN penLinkLine = CreatePen(PS_SOLID, 1, COL_BLUE_LINK); ScopedFont fontSumatraTxt(GetSimpleFont(hdc, L"MS Shell Dlg", 24)); ScopedFont fontLeftTxt(GetSimpleFont(hdc, L"MS Shell Dlg", 14)); HGDIOBJ origFont = SelectObject(hdc, fontSumatraTxt); /* Just to remember the orig font */ ClientRect rc(win.hwndCanvas); FillRect(hdc, &rc.ToRECT(), gBrushLogoBg); SelectObject(hdc, gBrushLogoBg); SelectObject(hdc, penBorder); bool isRtl = IsUIRightToLeft(); /* render title */ RectI titleBox = RectI(PointI(0, 0), CalcSumatraVersionSize(hdc)); titleBox.x = rc.dx - titleBox.dx - 3; DrawSumatraVersion(hdc, titleBox); PaintLine(hdc, RectI(0, titleBox.dy, rc.dx, 0)); /* render recent files list */ SelectObject(hdc, penThumbBorder); SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, WIN_COL_BLACK); rc.y += titleBox.dy; rc.dy -= titleBox.dy; FillRect(hdc, &rc.ToRECT(), gBrushAboutBg); rc.dy -= DOCLIST_BOTTOM_BOX_DY; Vec<DisplayState *> list; fileHistory.GetFrequencyOrder(list); int width = limitValue((rc.dx - DOCLIST_MARGIN_LEFT - DOCLIST_MARGIN_RIGHT + DOCLIST_MARGIN_BETWEEN_X) / (THUMBNAIL_DX + DOCLIST_MARGIN_BETWEEN_X), 1, DOCLIST_MAX_THUMBNAILS_X); int height = min((rc.dy - DOCLIST_MARGIN_TOP - DOCLIST_MARGIN_BOTTOM + DOCLIST_MARGIN_BETWEEN_Y) / (THUMBNAIL_DY + DOCLIST_MARGIN_BETWEEN_Y), FILE_HISTORY_MAX_FREQUENT / width); PointI offset(rc.x + DOCLIST_MARGIN_LEFT + (rc.dx - width * THUMBNAIL_DX - (width - 1) * DOCLIST_MARGIN_BETWEEN_X - DOCLIST_MARGIN_LEFT - DOCLIST_MARGIN_RIGHT) / 2, rc.y + DOCLIST_MARGIN_TOP); if (offset.x < ABOUT_INNER_PADDING) offset.x = ABOUT_INNER_PADDING; else if (list.Count() == 0) offset.x = DOCLIST_MARGIN_LEFT; SelectObject(hdc, fontSumatraTxt); SIZE txtSize; const WCHAR *txt = _TR("Frequently Read"); GetTextExtentPoint32(hdc, txt, (int)str::Len(txt), &txtSize); RectI headerRect(offset.x, rc.y + (DOCLIST_MARGIN_TOP - txtSize.cy) / 2, txtSize.cx, txtSize.cy); if (isRtl) headerRect.x = rc.dx - offset.x - headerRect.dx; DrawText(hdc, txt, -1, &headerRect.ToRECT(), (isRtl ? DT_RTLREADING : DT_LEFT) | DT_NOPREFIX); SelectObject(hdc, fontLeftTxt); SelectObject(hdc, GetStockBrush(NULL_BRUSH)); win.staticLinks.Reset(); for (int h = 0; h < height; h++) { for (int w = 0; w < width; w++) { if (h * width + w >= (int)list.Count()) { // display the "Open a document" link right below the last row height = w > 0 ? h + 1 : h; break; } DisplayState *state = list.At(h * width + w); RectI page(offset.x + w * (int)(THUMBNAIL_DX + DOCLIST_MARGIN_BETWEEN_X * win.uiDPIFactor), offset.y + h * (int)(THUMBNAIL_DY + DOCLIST_MARGIN_BETWEEN_Y * win.uiDPIFactor), THUMBNAIL_DX, THUMBNAIL_DY); if (isRtl) page.x = rc.dx - page.x - page.dx; bool loadOk = true; if (!state->thumbnail) loadOk = LoadThumbnail(*state); if (loadOk && state->thumbnail) { SizeI thumbSize = state->thumbnail->Size(); if (thumbSize.dx != THUMBNAIL_DX || thumbSize.dy != THUMBNAIL_DY) { page.dy = thumbSize.dy * THUMBNAIL_DX / thumbSize.dx; page.y += THUMBNAIL_DY - page.dy; } HRGN clip = CreateRoundRectRgn(page.x, page.y, page.x + page.dx, page.y + page.dy, 10, 10); SelectClipRgn(hdc, clip); RenderedBitmap *clone = state->thumbnail->Clone(); UpdateBitmapColorRange(clone->GetBitmap(), colorRange); clone->StretchDIBits(hdc, page); SelectClipRgn(hdc, NULL); DeleteObject(clip); delete clone; } RoundRect(hdc, page.x, page.y, page.x + page.dx, page.y + page.dy, 10, 10); int iconSpace = (int)(20 * win.uiDPIFactor); RectI rect(page.x + iconSpace, page.y + page.dy + 3, page.dx - iconSpace, iconSpace); if (isRtl) rect.x -= iconSpace; DrawText(hdc, path::GetBaseName(state->filePath), -1, &rect.ToRECT(), DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX | (isRtl ? DT_RIGHT : DT_LEFT)); SHFILEINFO sfi; HIMAGELIST himl = (HIMAGELIST)SHGetFileInfo(state->filePath, 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES); ImageList_Draw(himl, sfi.iIcon, hdc, isRtl ? page.x + page.dx - (int)(16 * win.uiDPIFactor) : page.x, rect.y, ILD_TRANSPARENT); win.staticLinks.Append(StaticLinkInfo(rect.Union(page), state->filePath, state->filePath)); } } /* render bottom links */ rc.y += DOCLIST_MARGIN_TOP + height * THUMBNAIL_DY + (height - 1) * DOCLIST_MARGIN_BETWEEN_Y + DOCLIST_MARGIN_BOTTOM; rc.dy = DOCLIST_BOTTOM_BOX_DY; SetTextColor(hdc, COL_BLUE_LINK); SelectObject(hdc, penLinkLine); HIMAGELIST himl = (HIMAGELIST)SendMessage(win.hwndToolbar, TB_GETIMAGELIST, 0, 0); RectI rectIcon(offset.x, rc.y, 0, 0); ImageList_GetIconSize(himl, &rectIcon.dx, &rectIcon.dy); rectIcon.y += (rc.dy - rectIcon.dy) / 2; if (isRtl) rectIcon.x = rc.dx - offset.x - rectIcon.dx; ImageList_Draw(himl, 0 /* index of Open icon */, hdc, rectIcon.x, rectIcon.y, ILD_NORMAL); txt = _TR("Open a document..."); GetTextExtentPoint32(hdc, txt, (int)str::Len(txt), &txtSize); RectI rect(offset.x + rectIcon.dx + 3, rc.y + (rc.dy - txtSize.cy) / 2, txtSize.cx, txtSize.cy); if (isRtl) rect.x = rectIcon.x - rect.dx - 3; DrawText(hdc, txt, -1, &rect.ToRECT(), isRtl ? DT_RTLREADING : DT_LEFT); PaintLine(hdc, RectI(rect.x, rect.y + rect.dy, rect.dx, 0)); // make the click target larger rect = rect.Union(rectIcon); rect.Inflate(10, 10); win.staticLinks.Append(StaticLinkInfo(rect, SLINK_OPEN_FILE)); rect = DrawBottomRightLink(win.hwndCanvas, hdc, _TR("Hide frequently read")); win.staticLinks.Append(StaticLinkInfo(rect, SLINK_LIST_HIDE)); SelectObject(hdc, origFont); DeleteObject(penBorder); DeleteObject(penThumbBorder); DeleteObject(penLinkLine); }